Logo ROOT  
Reference Guide
TControlBar.cxx
Go to the documentation of this file.
1 // @(#)root/gpad:$Id$
2 // Author: Nenad Buncic 20/02/96
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 /** \class TControlBar
13 \ingroup gpad
14 
15 A Control Bar is a fully user configurable tool which provides fast
16 access to frequently used operations. The user can choose between
17 buttons and drawn buttons (let's say icons) and assign to them their
18 own actions (let's say ROOT or C++ commands).
19 
20 The macro below shows an example of control bar.
21 To execute an item, click with the left mouse button.
22 To see the HELP of a button, click on the right mouse button.
23 
24 You have access to the last clicked button via the method
25 GetClicked(). For example, bar->GetClicked()->GetName()
26 will return the name of the last clicked button.
27 
28 ~~~ {.cpp}
29 {
30  gROOT->Reset("a");
31  TControlBar bar("vertical");
32  bar.AddButton("Help to run demos",".x demoshelp.C",
33  "Explains how to run the demos");
34  bar.AddButton("framework", ".x framework.C",
35  "An Example of Object Oriented User Interface");
36  bar.AddButton("hsimple", ".x hsimple.C",
37  "An Example Creating Histograms/Ntuples on File");
38  bar.AddButton("hsum", ".x hsum.C",
39  "Filling histograms and some graphics options");
40  bar.AddButton("canvas", ".x canvas.C",
41  "Canvas and Pad Management");
42  bar.AddButton("formula1", ".x formula1.C",
43  "Simple Formula and Functions");
44  bar.AddButton("fillrandom", ".x fillrandom.C",
45  "Histograms with Random Numbers from a Function");
46  bar.AddButton("fit1", ".x fit1.C",
47  "A Simple Fitting Example");
48  bar.AddButton("h1draw", ".x h1draw.C",
49  "Drawing Options for 1D Histograms");
50  bar.AddButton("graph", ".x graph.C",
51  "Examples of a simple graph");
52  bar.AddButton("tornado", ".x tornado.C",
53  "Examples of 3-D PolyMarkers");
54  bar.AddButton("shapes", ".x shapes.C",
55  "The Geometry Shapes");
56  bar.AddButton("atlasna49", ".x atlasna49.C",
57  "Creating and Viewing Geometries");
58  bar.AddButton("file_layout", ".x file.C",
59  "The ROOT file format");
60  bar.AddButton("tree_layout", ".x tree.C",
61  "The Tree Data Structure");
62  bar.AddButton("ntuple1", ".x ntuple1.C",
63  "Ntuples and Selections");
64  bar.AddButton("run benchmarks", ".x benchmarks.C",
65  "Runs all the ROOT benchmarks");
66  bar.AddButton("rootmarks", ".x rootmarks.C",
67  "Prints an estimated ROOTMARKS for your machine");
68  bar.AddButton("edit_hsimple", ".!ved hsimple.C &",
69  "Invokes the text editor on file hsimple.C");
70  bar.AddButton("Close Bar", "gROOT.Reset(\"a\")",
71  "Close ControlBar");
72  bar.Show();
73  gROOT->SaveContext();
74 }
75 ~~~
76 \image html gpad_controlbar.png
77 */
78 
79 #include "TApplication.h"
80 #include "TControlBar.h"
81 #include "TControlBarImp.h"
82 #include "TGuiFactory.h"
83 #include "TList.h"
84 #include "TStyle.h"
85 
86 
88 
89 ////////////////////////////////////////////////////////////////////////////////
90 /// Default constructor.
91 
93 {
94  fControlBarImp = 0;
95  fOrientation = 0;
96  fButtons = 0;
97  fNoroc = 1;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Normal constructor.
102 
103 TControlBar::TControlBar(const char *orientation, const char *title)
104  : TControlBarButton(title, "", "", "button")
105 {
106  SetOrientation( orientation );
107  Initialize(-999, -999);
108 }
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 /// Normal constructor.
112 
113 TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y)
114  : TControlBarButton(title, "", "", "button")
115 {
116  Int_t xs = (Int_t)(x*gStyle->GetScreenFactor());
117  Int_t ys = (Int_t)(y*gStyle->GetScreenFactor());
118  SetOrientation( orientation );
119  Initialize(xs, ys);
120 }
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Destructor.
124 
126 {
127  delete fControlBarImp;
128 
129  if( fButtons )
130  fButtons->Delete();
131 
132  fButtons = 0;
133  fControlBarImp = 0;
134 }
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 /// Add button.
138 
140 {
141  AddButton( &button );
142 }
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Add button.
146 
148 {
149  if( fButtons && button )
150  fButtons->Add( button );
151 }
152 
153 ////////////////////////////////////////////////////////////////////////////////
154 /// Add button.
155 
156 void TControlBar::AddButton(const char *label, const char *action, const char *hint, const char *type)
157 {
158  TControlBarButton *button = new TControlBarButton( label, action, hint, type );
159  AddButton( button );
160 }
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 /// Add control bar.
164 
166 {
167  AddControlBar( &controlBar );
168 }
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 /// Add control bar.
172 
174 {
175  if( fButtons && controlBar )
176  fButtons->Add( controlBar );
177 }
178 
179 ////////////////////////////////////////////////////////////////////////////////
180 /// Add separator.
181 
183 {
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// Create control bar.
188 
190 {
191  if( fControlBarImp ) {
193  }
194 }
195 
196 ////////////////////////////////////////////////////////////////////////////////
197 /// Hide control bar.
198 
200 {
201  if( fControlBarImp ) {
202  fControlBarImp->Hide();
203  }
204 }
205 
206 ////////////////////////////////////////////////////////////////////////////////
207 /// Initialize control bar.
208 
210 {
211  // Load and initialize graphics libraries if
212  // TApplication::NeedGraphicsLibs() has been called by a
213  // library static initializer.
214  if (gApplication)
216 
217  if (x == -999) {
219  } else {
221  }
222 
223  fButtons = new TList();
224  fNoroc = 1;
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 /// Sets new font for control bar buttons, e.g.:
229 /// ~~~ {.cpp}
230 /// root > .x tutorials/demos.C
231 /// root > bar->SetFont("-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-iso8859-1")
232 /// ~~~
233 
234 void TControlBar::SetFont(const char *fontName)
235 {
236  fControlBarImp->SetFont(fontName);
237 }
238 
239 ////////////////////////////////////////////////////////////////////////////////
240 /// Sets text color for control bar buttons, e.g.:
241 /// ~~~ {.cpp}
242 /// root > .x tutorials/demos.C
243 /// root > bar->SetTextColor("red")
244 /// ~~~
245 
246 void TControlBar::SetTextColor(const char *colorName)
247 {
248  fControlBarImp->SetTextColor(colorName);
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 /// Sets a state for control bar button 'label'; possible states are
253 /// 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,
254 ///
255 /// e.g.:
256 /// ~~~ {.cpp}
257 /// root > .x tutorials/demos.C
258 /// ~~~
259 /// to disable the button 'first' do:
260 /// ~~~ {.cpp}
261 /// root > bar->SetButtonState("first", 3)
262 /// ~~~
263 /// to enable the button 'first' do:
264 /// ~~~ {.cpp}
265 /// root > bar->SetButtonState("first", 0)
266 /// ~~~
267 
268 void TControlBar::SetButtonState(const char *label, Int_t state)
269 {
270  if (state > 3) {
271  Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
272  return;
273  }
274  fControlBarImp->SetButtonState(label, state);
275 }
276 
277 
278  ///////////////////////////////////////////////////////////////////////////////
279  /// Sets the width in pixels for control bar button.
280 
282 {
284 }
285 
286 ////////////////////////////////////////////////////////////////////////////////
287 /// Set control bar orientation.
288 
289 void TControlBar::SetOrientation(const char *o)
290 {
292 
293  if( *o ) {
294  if( !strcasecmp( o, "vertical" ) )
296  else if( !strcasecmp( o, "horizontal" ) )
298  else
299  Error( "SetOrientation", "Unknown orientation: '%s' !\n\t\t(choice of: %s, %s)",
300  o, "vertical", "horizontal" );
301  }
302 }
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 /// Set control bar orientation.
306 
308 {
310 
311  if( ( o == kVertical ) || ( o == kHorizontal ) )
312  fOrientation = o;
313  else
314  Error( "SetOrientation", "Unknown orientation: %d !\n\t\t(choice of: %d, %d)",
315  o, kVertical, kHorizontal );
316 }
317 
318 ////////////////////////////////////////////////////////////////////////////////
319 /// Show control bar.
320 
322 {
323  if( fControlBarImp )
324  fControlBarImp->Show();
325 }
326 
327 ////////////////////////////////////////////////////////////////////////////////
328 /// Returns a pointer to the last clicked control bar button;
329 /// null if no button was clicked yet
330 
332 {
333  if (!fControlBarImp->GetClicked())
334  Printf("None of the control bar buttons is clicked yet");
335  return fControlBarImp->GetClicked();
336 }
TControlBar::fNoroc
Int_t fNoroc
number of rows or columns
Definition: TControlBar.h:39
TControlBar::AddSeparator
void AddSeparator()
Add separator.
Definition: TControlBar.cxx:182
TControlBarImp::SetButtonState
virtual void SetButtonState(const char *, Int_t)
Definition: TControlBarImp.h:51
TControlBar::Show
void Show()
Show control bar.
Definition: TControlBar.cxx:321
TControlBar::AddButton
void AddButton(TControlBarButton *button)
Add button.
Definition: TControlBar.cxx:147
TControlBar::~TControlBar
virtual ~TControlBar()
Destructor.
Definition: TControlBar.cxx:125
TControlBar::SetTextColor
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
Definition: TControlBar.cxx:246
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
TControlBarButton::TControlBarButton
TControlBarButton()
Default control bar button ctor.
Definition: TControlBarButton.cxx:36
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TControlBar::TControlBar
TControlBar()
Default constructor.
Definition: TControlBar.cxx:92
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TApplication::InitializeGraphics
void InitializeGraphics()
Initialize the graphics environment.
Definition: TApplication.cxx:260
TControlBar.h
TControlBar::kHorizontal
@ kHorizontal
Definition: TControlBar.h:42
width
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
TStyle.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TControlBarImp::SetTextColor
virtual void SetTextColor(const char *)
Definition: TControlBarImp.h:50
x
Double_t x[n]
Definition: legend1.C:17
TControlBarImp.h
TList.h
TControlBar::fControlBarImp
TControlBarImp * fControlBarImp
system specific implementation
Definition: TControlBar.h:36
TControlBar::fOrientation
Int_t fOrientation
orientation
Definition: TControlBar.h:37
TControlBar
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition: TControlBar.h:26
TControlBarImp::SetButtonWidth
virtual void SetButtonWidth(UInt_t)
Definition: TControlBarImp.h:52
TApplication.h
TControlBar::Initialize
void Initialize(Int_t x, Int_t y)
Initialize control bar.
Definition: TControlBar.cxx:209
TControlBar::Create
virtual void Create()
Create control bar.
Definition: TControlBar.cxx:189
TStyle::GetScreenFactor
Float_t GetScreenFactor() const
Definition: TStyle.h:247
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TControlBarImp::SetFont
virtual void SetFont(const char *)
Definition: TControlBarImp.h:49
TControlBarImp::Create
virtual void Create()
Definition: TControlBarImp.h:46
TControlBarImp::GetClicked
virtual TControlBarButton * GetClicked()
Definition: TControlBarImp.h:44
gGuiFactory
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TControlBarImp::Hide
virtual void Hide()
Definition: TControlBarImp.h:47
TControlBar::SetButtonWidth
void SetButtonWidth(UInt_t width)
Sets the width in pixels for control bar button.
Definition: TControlBar.cxx:281
y
Double_t y[n]
Definition: legend1.C:17
TControlBar::Hide
void Hide()
Hide control bar.
Definition: TControlBar.cxx:199
TControlBar::GetClicked
TControlBarButton * GetClicked() const
Returns a pointer to the last clicked control bar button; null if no button was clicked yet.
Definition: TControlBar.cxx:331
unsigned int
Printf
void Printf(const char *fmt,...)
TControlBar::kVertical
@ kVertical
Definition: TControlBar.h:42
TList::Add
virtual void Add(TObject *obj)
Definition: TList.h:87
TGuiFactory::CreateControlBarImp
virtual TControlBarImp * CreateControlBarImp(TControlBar *c, const char *title)
Create a batch version of TControlBarImp.
Definition: TGuiFactory.cxx:96
TControlBar::SetButtonState
void SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button 'label'; possible states are 0-kButtonUp, 1-kButtonDown,...
Definition: TControlBar.cxx:268
TControlBar::fButtons
TList * fButtons
list of buttons
Definition: TControlBar.h:38
TControlBarImp::Show
virtual void Show()
Definition: TControlBarImp.h:48
TNamed::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
type
int type
Definition: TGX11.cxx:121
TControlBar::SetOrientation
void SetOrientation(const char *o)
Set control bar orientation.
Definition: TControlBar.cxx:289
TControlBar::AddControlBar
void AddControlBar(TControlBar *controlBar)
Add control bar.
Definition: TControlBar.cxx:173
TGuiFactory.h
TControlBarButton
This class defines the control bar buttons.
Definition: TControlBarButton.h:17
TControlBar::SetFont
void SetFont(const char *fontName)
Sets new font for control bar buttons, e.g.
Definition: TControlBar.cxx:234
TList
A doubly linked list.
Definition: TList.h:44
int