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 // //
14 // TRootControlBar //
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 #include "TRootControlBar.h"
23 #include "TControlBar.h"
24 #include "TList.h"
25 #include "TGButton.h"
26 
27 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// Create a ROOT native GUI controlbar.
32 
34  : TGMainFrame(gClient->GetRoot(), 10, 10), TControlBarImp(c)
35 {
36  fWidgets = 0;
37  fXpos = x;
38  fYpos = y;
39  fBwidth = 0;
40  fClicked = 0;
42 
43  // if controlbar orientation is horizontal change layout manager
44  if (c && c->GetOrientation() == TControlBar::kHorizontal) {
46  fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1);
47  } else
48  fL1 = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 1, 1, 1, 1);
49 
50  SetWindowName(title);
51  SetIconName(title);
52 }
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 /// Delete the control bar implementation.
56 
58 {
59  delete fWidgets;
60  fWidgets = 0;
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 /// Create the control bar. Loop over all buttons defined in the
65 /// TControlBar and create the buttons.
66 
68 {
69  fWidgets = new TList;
70  TGButton *b = 0;
71 
72  TControlBarButton *button;
74 
75  while ((button = (TControlBarButton *) next())) {
76 
77  switch (button->GetType()) {
78 
80  Warning("Create", "separators not yet supported");
81  break;
82 
84  Warning("Create", "picture buttons not yet supported");
85  break;
86 
88  {
89  b = new TGTextButton(this, button->GetName());
90  b->SetToolTipText(button->GetTitle());
91  b->SetUserData(button);
92  AddFrame(b, fL1);
93  fWidgets->Add(b);
94  if (fBwidth < b->GetDefaultWidth())
95  fBwidth = b->GetDefaultWidth(); //do not cut the label
96  }
97  break;
98  }
99  }
100 
101  MapSubwindows();
103 
107 
108  if (fXpos != -999) {
109  Move(fXpos, fYpos);
111  }
114  else
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// Show controlbar. If not yet created create it first.
120 
122 {
123  if (!fWidgets) Create();
124 
125  MapRaised();
126 }
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 /// Hide controlbar.
130 
132 {
133  UnmapWindow();
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// Handle controlbar button messages.
138 
140 {
141  TControlBarButton *button = (TControlBarButton *) parm2;
142 
143  if (button) {
144  fClicked = button;
145  button->Action();
146  }
147  return kTRUE;
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// Really delete the control bar and the this GUI.
152 
154 {
155  delete fControlBar; // will in turn delete this object
156 }
157 
158 ////////////////////////////////////////////////////////////////////////////////
159 /// Called when closed via window manager action.
160 
162 {
163  DeleteWindow(); // but do it slightly delayed here
164 }
165 
166 ////////////////////////////////////////////////////////////////////////////////
167 /// sets new font for control bar buttons
168 
169 void TRootControlBar::SetFont(const char *fontName)
170 {
171  TIter next(fWidgets);
172 
173  TObject *obj;
174 
175  while ((obj=next())) {
176  if (!obj->InheritsFrom(TGTextButton::Class())) continue;
177 
178  ((TGTextButton *)obj)->SetFont(fontName);
179  }
180  Resize();
181 }
182 
183 ////////////////////////////////////////////////////////////////////////////////
184 /// sets new font for control bar buttons
185 
186 void TRootControlBar::SetButtonState(const char *label, Int_t state)
187 {
188  TIter next(fWidgets);
189 
190  TObject *obj;
191 
192  while ((obj=next())) {
193  if (!obj->InheritsFrom(TGTextButton::Class())) continue;
194 
195  if (!strcmp(((TGTextButton *)obj)->GetTitle(), label)) {
196  switch (state) {
197  case 0: {
198  ((TGTextButton *)obj)->SetState(kButtonUp);
199  break;
200  }
201  case 1: {
202  ((TGTextButton *)obj)->SetState(kButtonDown);
203  break;
204  }
205  case 2: {
206  ((TGTextButton *)obj)->SetState(kButtonEngaged);
207  break;
208  }
209  case 3: {
210  ((TGTextButton *)obj)->SetState(kButtonDisabled);
211  break;
212  }
213  default: {
214  Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
215  break;
216  }
217  }
218  }
219  }
220  Resize();
221 }
222 
223 ////////////////////////////////////////////////////////////////////////////////
224 /// sets text color for control bar buttons, e.g.:
225 /// root > .x tutorials/demos.C
226 /// root > bar->SetTextColor("red")
227 
228 void TRootControlBar::SetTextColor(const char *colorName)
229 {
230  Pixel_t color;
231  gClient->GetColorByName(colorName, color);
232 
233  if (!fWidgets) Create();
234 
235  TIter next(fWidgets);
236 
237  TObject *obj;
238 
239  while ((obj=next())) {
240  if (!obj->InheritsFrom(TGTextButton::Class())) continue;
241 
242  ((TGTextButton *)obj)->SetTextColor(color);
243  }
244  Resize();
245 }
246 
247 ////////////////////////////////////////////////////////////////////////////////
248 /// Set button width in pixels.
249 
251 {
252  fBwidth = width;
253 }
TControlBarImp
Definition: TControlBarImp.h:30
TGCompositeFrame::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:353
c
#define c(i)
Definition: RSha256.hxx:119
TRootControlBar::SetFont
void SetFont(const char *fontName)
sets new font for control bar buttons
Definition: TRootControlBar.cxx:169
TGFrame::GetHeight
UInt_t GetHeight() const
Definition: TGFrame.h:250
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TRootControlBar::Show
void Show()
Show controlbar. If not yet created create it first.
Definition: TRootControlBar.cxx:121
TGMainFrame
Definition: TGFrame.h:444
TControlBarButton::GetType
virtual Int_t GetType() const
Definition: TControlBarButton.h:39
TRootControlBar::CloseWindow
void CloseWindow()
Called when closed via window manager action.
Definition: TRootControlBar.cxx:161
TGMainFrame::SetIconName
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition: TGFrame.cxx:1762
TControlBarImp::fClicked
TControlBarButton * fClicked
Definition: TControlBarImp.h:36
TRootControlBar::fWidgets
TList * fWidgets
Definition: TRootControlBar.h:36
kButtonDown
@ kButtonDown
Definition: TGButton.h:60
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TNamed::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:54
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TControlBar.h
TControlBar::kHorizontal
@ kHorizontal
Definition: TControlBar.h:42
kButtonUp
@ kButtonUp
Definition: TGButton.h:59
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TGTextButton
Definition: TGButton.h:142
TControlBarButton::kSeparator
@ kSeparator
Definition: TControlBarButton.h:30
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:1749
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:228
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
TRootControlBar::ReallyDelete
void ReallyDelete()
Really delete the control bar and the this GUI.
Definition: TRootControlBar.cxx:153
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:118
TControlBar
Definition: TControlBar.h:26
TControlBarButton::kButton
@ kButton
Definition: TControlBarButton.h:30
TRootControlBar::Create
void Create()
Create the control bar.
Definition: TRootControlBar.cxx:67
bool
TGFrame::GetOptions
virtual UInt_t GetOptions() const
Definition: TGFrame.h:222
kMWMInputModeless
@ kMWMInputModeless
Definition: TGFrame.h:66
kMWMDecorResizeH
@ kMWMDecorResizeH
Definition: TGFrame.h:74
gClient
#define gClient
Definition: TGClient.h:166
TGFrame::DeleteWindow
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:261
TGCompositeFrame::ChangeOptions
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1028
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:41
TRootControlBar::~TRootControlBar
virtual ~TRootControlBar()
Delete the control bar implementation.
Definition: TRootControlBar.cxx:57
TGCompositeFrame::MapSubwindows
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1149
kButtonEngaged
@ kButtonEngaged
Definition: TGButton.h:61
TRootControlBar::Hide
void Hide()
Hide controlbar.
Definition: TRootControlBar.cxx:131
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TRootControlBar::ProcessMessage
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Handle controlbar button messages.
Definition: TRootControlBar.cxx:139
TRootControlBar::fL1
TGLayoutHints * fL1
Definition: TRootControlBar.h:37
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:186
TGLayoutHints
Definition: TGLayout.h:57
TGFrame::MapRaised
virtual void MapRaised()
map raised
Definition: TGFrame.h:230
y
Double_t y[n]
Definition: legend1.C:17
TRootControlBar
Definition: TRootControlBar.h:33
TObject::Warning
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:876
unsigned int
TRootControlBar::fBwidth
UInt_t fBwidth
Definition: TRootControlBar.h:38
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TRootControlBar::SetButtonWidth
void SetButtonWidth(UInt_t width)
Set button width in pixels.
Definition: TRootControlBar.cxx:250
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:1852
TGFrame::UnmapWindow
virtual void UnmapWindow()
unmap window
Definition: TGFrame.h:231
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:578
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:1827
kMWMFuncAll
@ kMWMFuncAll
Definition: TGFrame.h:58
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TObject
Definition: TObject.h:37
TGButton.h
kMWMDecorAll
@ kMWMDecorAll
Definition: TGFrame.h:72
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:51
TControlBarButton::kDrawnButton
@ kDrawnButton
Definition: TControlBarButton.h:30
TIter
Definition: TCollection.h:233
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGCompositeFrame::SetCleanup
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1057
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:53
TRootControlBar::TRootControlBar
TRootControlBar(TControlBar *c=0, const char *title="ROOT Control Bar", Int_t x=-999, Int_t y=-999)
Create a ROOT native GUI controlbar.
Definition: TRootControlBar.cxx:33
kMWMFuncResize
@ kMWMFuncResize
Definition: TGFrame.h:59
TGButton
Definition: TGButton.h:68
TGCompositeFrame::GetDefaultWidth
virtual UInt_t GetDefaultWidth() const
Definition: TGFrame.h:349
kMWMFuncMaximize
@ kMWMFuncMaximize
Definition: TGFrame.h:62
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:1102
TControlBarImp::fXpos
Int_t fXpos
Definition: TControlBarImp.h:34
TControlBar::GetListOfButtons
TList * GetListOfButtons() const
Definition: TControlBar.h:57
TControlBarButton
Definition: TControlBarButton.h:17
kButtonDisabled
@ kButtonDisabled
Definition: TGButton.h:62
TList
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:1840
int