Logo ROOT  
Reference Guide
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 
16 This class provides an interface to the GUI dependent functions of
17 the TControlBar class. A control bar is a horizontal or vertical bar
18 with 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
49  fL1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 1, 1, 1, 1);
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 
102  MapSubwindows();
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 
170 void 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 
187 void 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 
229 void 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 }
TControlBarImp
ABC describing GUI independent control bar.
Definition: TControlBarImp.h:30
TGCompositeFrame::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:316
c
#define c(i)
Definition: RSha256.hxx:101
TRootControlBar::SetFont
void SetFont(const char *fontName)
sets new font for control bar buttons
Definition: TRootControlBar.cxx:170
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:225
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
TRootControlBar::Show
void Show()
Show controlbar. If not yet created create it first.
Definition: TRootControlBar.cxx:122
TGMainFrame
Defines top level windows that interact with the system Window Manager.
Definition: TGFrame.h:398
TControlBarButton::GetType
virtual Int_t GetType() const
Definition: TControlBarButton.h:33
TRootControlBar::CloseWindow
void CloseWindow()
Called when closed via window manager action.
Definition: TRootControlBar.cxx:162
TControlBar::kHorizontal
@ kHorizontal
Definition: TControlBar.h:42
TControlBarButton::kSeparator
@ kSeparator
Definition: TControlBarButton.h:24
TGMainFrame::SetIconName
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1777
TControlBarImp::fClicked
TControlBarButton * fClicked
Definition: TControlBarImp.h:36
TRootControlBar::fWidgets
TList * fWidgets
list of TGTextButton or TGPictureButtons
Definition: TRootControlBar.h:26
TRootControlBar::TRootControlBar
TRootControlBar(TControlBar *c=nullptr, const char *title="ROOT Control Bar", Int_t x=-999, Int_t y=-999)
Create a ROOT native GUI controlbar.
Definition: TRootControlBar.cxx:34
kButtonDown
@ kButtonDown
Definition: TGButton.h:54
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:27
Pixel_t
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:893
TControlBar.h
kButtonUp
@ kButtonUp
Definition: TGButton.h:53
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TGTextButton
Yield an action as soon as it is clicked.
Definition: TGButton.h:142
x
Double_t x[n]
Definition: legend1.C:17
TControlBarImp::fYpos
Int_t fYpos
Definition: TControlBarImp.h:35
TList.h
TGMainFrame::SetWindowName
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1764
TControlBarImp::fControlBar
TControlBar * fControlBar
Definition: TControlBarImp.h:33
TRootControlBar.h
TRootControlBar::SetTextColor
void SetTextColor(const char *colorName)
sets text color for control bar buttons, e.g.
Definition: TRootControlBar.cxx:229
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
TControlBarButton::kDrawnButton
@ kDrawnButton
Definition: TControlBarButton.h:24
TRootControlBar::ReallyDelete
void ReallyDelete()
Really delete the control bar and the this GUI.
Definition: TRootControlBar.cxx:154
TObject::InheritsFrom
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:445
b
#define b(i)
Definition: RSha256.hxx:100
TControlBar
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition: TControlBar.h:26
TRootControlBar::Create
void Create()
Create the control bar.
Definition: TRootControlBar.cxx:68
bool
TGFrame::GetOptions
virtual UInt_t GetOptions() const
Definition: TGFrame.h:197
kMWMInputModeless
@ kMWMInputModeless
Definition: TGFrame.h:57
kMWMDecorResizeH
@ kMWMDecorResizeH
Definition: TGFrame.h:65
gClient
#define gClient
Definition: TGClient.h:157
TGFrame::DeleteWindow
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:276
TGCompositeFrame::ChangeOptions
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1043
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:28
TRootControlBar::~TRootControlBar
virtual ~TRootControlBar()
Delete the control bar implementation.
Definition: TRootControlBar.cxx:58
TGCompositeFrame::MapSubwindows
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1164
kButtonEngaged
@ kButtonEngaged
Definition: TGButton.h:55
TRootControlBar::Hide
void Hide()
Hide controlbar.
Definition: TRootControlBar.cxx:132
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
TRootControlBar::ProcessMessage
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Handle controlbar button messages.
Definition: TRootControlBar.cxx:140
TRootControlBar::fL1
TGLayoutHints * fL1
button layout hints
Definition: TRootControlBar.h:27
Long_t
long Long_t
Definition: RtypesCore.h:54
TRootControlBar::SetButtonState
void SetButtonState(const char *label, Int_t state=0)
sets new font for control bar buttons
Definition: TRootControlBar.cxx:187
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
TGFrame::MapRaised
virtual void MapRaised()
map raised
Definition: TGFrame.h:205
y
Double_t y[n]
Definition: legend1.C:17
TRootControlBar
This class provides an interface to the GUI dependent functions of the TControlBar class.
Definition: TRootControlBar.h:23
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:879
unsigned int
TRootControlBar::fBwidth
UInt_t fBwidth
button width in pixels
Definition: TRootControlBar.h:28
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TRootControlBar::SetButtonWidth
void SetButtonWidth(UInt_t width)
Set button width in pixels.
Definition: TRootControlBar.cxx:251
TControlBarButton::Action
virtual void Action()
Execute control bar button command.
Definition: TControlBarButton.cxx:55
TGMainFrame::SetWMSize
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition: TGFrame.cxx:1867
TGFrame::UnmapWindow
virtual void UnmapWindow()
unmap window
Definition: TGFrame.h:206
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TGFrame::Move
virtual void Move(Int_t x, Int_t y)
Move frame.
Definition: TGFrame.cxx:593
TGMainFrame::SetMWMHints
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
Set decoration style for MWM-compatible wm (mwm, ncdwm, fvwm?).
Definition: TGFrame.cxx:1842
kMWMFuncAll
@ kMWMFuncAll
Definition: TGFrame.h:49
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TGButton.h
kMWMDecorAll
@ kMWMDecorAll
Definition: TGFrame.h:63
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:42
TIter
Definition: TCollection.h:233
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:30
TGCompositeFrame::SetCleanup
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1072
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
kMWMFuncResize
@ kMWMFuncResize
Definition: TGFrame.h:50
TGButton
A button abstract base class.
Definition: TGButton.h:68
TGCompositeFrame::GetDefaultWidth
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:312
kMWMFuncMaximize
@ kMWMFuncMaximize
Definition: TGFrame.h:53
Class
void Class()
Definition: Class.C:29
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1117
TControlBarImp::fXpos
Int_t fXpos
Definition: TControlBarImp.h:34
TControlBar::GetListOfButtons
TList * GetListOfButtons() const
Definition: TControlBar.h:57
TControlBarButton::kButton
@ kButton
Definition: TControlBarButton.h:24
TControlBarButton
This class defines the control bar buttons.
Definition: TControlBarButton.h:17
kButtonDisabled
@ kButtonDisabled
Definition: TGButton.h:56
TList
A doubly linked list.
Definition: TList.h:44
TGMainFrame::SetWMPosition
void SetWMPosition(Int_t x, Int_t y)
Give the window manager a window position hint.
Definition: TGFrame.cxx:1855
int