Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootControlBar.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 22/02/98
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13/** \class TRootControlBar
14 \ingroup guiwidgets
15
16This class provides an interface to the GUI dependent functions of
17the TControlBar class. A control bar is a horizontal or vertical bar
18with a number of buttons (text or picture buttons).
19
20*/
21
22
23#include "TRootControlBar.h"
24#include "TControlBar.h"
25#include "TList.h"
26#include "TGButton.h"
27
28
30
31////////////////////////////////////////////////////////////////////////////////
32/// Create a ROOT native GUI controlbar.
33
35 : TGMainFrame(gClient->GetRoot(), 10, 10), TControlBarImp(c)
36{
37 fWidgets = 0;
38 fXpos = x;
39 fYpos = y;
40 fBwidth = 0;
41 fClicked = 0;
43
44 // if controlbar orientation is horizontal change layout manager
45 if (c && c->GetOrientation() == TControlBar::kHorizontal) {
47 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1);
48 } else
50
51 SetWindowName(title);
52 SetIconName(title);
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Delete the control bar implementation.
57
59{
60 delete fWidgets;
61 fWidgets = 0;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Create the control bar. Loop over all buttons defined in the
66/// TControlBar and create the buttons.
67
69{
70 fWidgets = new TList;
71 TGButton *b = 0;
72
73 TControlBarButton *button;
75
76 while ((button = (TControlBarButton *) next())) {
77
78 switch (button->GetType()) {
79
81 Warning("Create", "separators not yet supported");
82 break;
83
85 Warning("Create", "picture buttons not yet supported");
86 break;
87
89 {
90 b = new TGTextButton(this, button->GetName());
91 b->SetToolTipText(button->GetTitle());
92 b->SetUserData(button);
93 AddFrame(b, fL1);
94 fWidgets->Add(b);
95 if (fBwidth < b->GetDefaultWidth())
96 fBwidth = b->GetDefaultWidth(); //do not cut the label
97 }
98 break;
99 }
100 }
101
104
108
109 if (fXpos != -999) {
110 Move(fXpos, fYpos);
112 }
115 else
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Show controlbar. If not yet created create it first.
121
123{
124 if (!fWidgets) Create();
125
126 MapRaised();
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Hide controlbar.
131
133{
134 UnmapWindow();
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Handle controlbar button messages.
139
141{
142 TControlBarButton *button = (TControlBarButton *) parm2;
143
144 if (button) {
145 fClicked = button;
146 button->Action();
147 }
148 return kTRUE;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Really delete the control bar and the this GUI.
153
155{
156 delete fControlBar; // will in turn delete this object
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Called when closed via window manager action.
161
163{
164 DeleteWindow(); // but do it slightly delayed here
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// sets new font for control bar buttons
169
170void TRootControlBar::SetFont(const char *fontName)
171{
172 TIter next(fWidgets);
173
174 TObject *obj;
175
176 while ((obj=next())) {
177 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
178
179 ((TGTextButton *)obj)->SetFont(fontName);
180 }
181 Resize();
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// sets new font for control bar buttons
186
187void TRootControlBar::SetButtonState(const char *label, Int_t state)
188{
189 TIter next(fWidgets);
190
191 TObject *obj;
192
193 while ((obj=next())) {
194 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
195
196 if (!strcmp(((TGTextButton *)obj)->GetTitle(), label)) {
197 switch (state) {
198 case 0: {
199 ((TGTextButton *)obj)->SetState(kButtonUp);
200 break;
201 }
202 case 1: {
203 ((TGTextButton *)obj)->SetState(kButtonDown);
204 break;
205 }
206 case 2: {
207 ((TGTextButton *)obj)->SetState(kButtonEngaged);
208 break;
209 }
210 case 3: {
211 ((TGTextButton *)obj)->SetState(kButtonDisabled);
212 break;
213 }
214 default: {
215 Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
216 break;
217 }
218 }
219 }
220 }
221 Resize();
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// sets text color for control bar buttons, e.g.:
226/// root > .x tutorials/demos.C
227/// root > bar->SetTextColor("red")
228
229void TRootControlBar::SetTextColor(const char *colorName)
230{
231 Pixel_t color;
232 gClient->GetColorByName(colorName, color);
233
234 if (!fWidgets) Create();
235
236 TIter next(fWidgets);
237
238 TObject *obj;
239
240 while ((obj=next())) {
241 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
242
243 ((TGTextButton *)obj)->SetTextColor(color);
244 }
245 Resize();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Set button width in pixels.
250
252{
253 fBwidth = width;
254}
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
long Longptr_t
Definition RtypesCore.h:82
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
include TDocParser_001 C image html pict1_TDocParser_001 png width
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
@ kButtonEngaged
Definition TGButton.h:55
#define gClient
Definition TGClient.h:157
@ kMWMDecorResizeH
Definition TGFrame.h:65
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorAll
Definition TGFrame.h:63
@ kMWMFuncMaximize
Definition TGFrame.h:53
@ kMWMInputModeless
Definition TGFrame.h:57
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
This class defines the control bar buttons.
virtual Int_t GetType() const
virtual void Action()
Execute control bar button command.
ABC describing GUI independent control bar.
TControlBar * fControlBar
TControlBarButton * fClicked
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
TList * GetListOfButtons() const
Definition TControlBar.h:57
A button abstract base class.
Definition TGButton.h:68
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
virtual UInt_t GetDefaultWidth() const
Definition TGFrame.h:312
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1043
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:316
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
virtual void MapRaised()
map raised
Definition TGFrame.h:205
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:276
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition TGFrame.cxx:593
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:605
UInt_t GetHeight() const
Definition TGFrame.h:225
virtual void UnmapWindow()
unmap window
Definition TGFrame.h:206
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:398
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1801
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1891
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition TGFrame.cxx:1879
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition TGFrame.cxx:1866
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:515
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:473
This class provides an interface to the GUI dependent functions of the TControlBar class.
void ReallyDelete()
Really delete the control bar and the this GUI.
void Hide()
Hide controlbar.
virtual ~TRootControlBar()
Delete the control bar implementation.
void SetTextColor(const char *colorName)
sets text color for control bar buttons, e.g.: root > .x tutorials/demos.C root > bar->SetTextColor("...
UInt_t fBwidth
button width in pixels
void Show()
Show controlbar. If not yet created create it first.
void Create()
Create the control bar.
void SetButtonWidth(UInt_t width)
Set button width in pixels.
void SetFont(const char *fontName)
sets new font for control bar buttons
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2)
Handle controlbar button messages.
TRootControlBar(TControlBar *c=nullptr, const char *title="ROOT Control Bar", Int_t x=-999, Int_t y=-999)
Create a ROOT native GUI controlbar.
void CloseWindow()
Called when closed via window manager action.
TList * fWidgets
list of TGTextButton or TGPictureButtons
void SetButtonState(const char *label, Int_t state=0)
sets new font for control bar buttons
TGLayoutHints * fL1
button layout hints
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17