Logo ROOT   6.10/09
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 "TGuiFactory.h"
82 #include "TList.h"
83 #include "TStyle.h"
84 
85 
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Default constructor.
90 
92 {
93  fControlBarImp = 0;
94  fOrientation = 0;
95  fButtons = 0;
96  fNoroc = 1;
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 /// Normal constructor.
101 
102 TControlBar::TControlBar(const char *orientation, const char *title)
103  : TControlBarButton(title, "", "", "button")
104 {
105  SetOrientation( orientation );
106  Initialize(-999, -999);
107 }
108 
109 ////////////////////////////////////////////////////////////////////////////////
110 /// Normal constructor.
111 
112 TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y)
113  : TControlBarButton(title, "", "", "button")
114 {
115  Int_t xs = (Int_t)(x*gStyle->GetScreenFactor());
116  Int_t ys = (Int_t)(y*gStyle->GetScreenFactor());
117  SetOrientation( orientation );
118  Initialize(xs, ys);
119 }
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Destructor.
123 
125 {
126  delete fControlBarImp;
127 
128  if( fButtons )
129  fButtons->Delete();
130 
131  fButtons = 0;
132  fControlBarImp = 0;
133 }
134 
135 ////////////////////////////////////////////////////////////////////////////////
136 /// Add button.
137 
139 {
140  AddButton( &button );
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Add button.
145 
147 {
148  if( fButtons && button )
149  fButtons->Add( button );
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Add button.
154 
155 void TControlBar::AddButton(const char *label, const char *action, const char *hint, const char *type)
156 {
157  TControlBarButton *button = new TControlBarButton( label, action, hint, type );
158  AddButton( button );
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 /// Add control bar.
163 
165 {
166  AddControlBar( &controlBar );
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// Add control bar.
171 
173 {
174  if( fButtons && controlBar )
175  fButtons->Add( controlBar );
176 }
177 
178 ////////////////////////////////////////////////////////////////////////////////
179 /// Add separator.
180 
182 {
183 }
184 
185 ////////////////////////////////////////////////////////////////////////////////
186 /// Create control bar.
187 
189 {
190  if( fControlBarImp ) {
192  }
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// Hide control bar.
197 
199 {
200  if( fControlBarImp ) {
201  fControlBarImp->Hide();
202  }
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Initialize control bar.
207 
209 {
210  // Load and initialize graphics libraries if
211  // TApplication::NeedGraphicsLibs() has been called by a
212  // library static initializer.
213  if (gApplication)
215 
216  if (x == -999) {
218  } else {
220  }
221 
222  fButtons = new TList();
223  fNoroc = 1;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Sets new font for control bar buttons, e.g.:
228 /// ~~~ {.cpp}
229 /// root > .x tutorials/demos.C
230 /// root > bar->SetFont("-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-iso8859-1")
231 /// ~~~
232 
233 void TControlBar::SetFont(const char *fontName)
234 {
235  fControlBarImp->SetFont(fontName);
236 }
237 
238 ////////////////////////////////////////////////////////////////////////////////
239 /// Sets text color for control bar buttons, e.g.:
240 /// ~~~ {.cpp}
241 /// root > .x tutorials/demos.C
242 /// root > bar->SetTextColor("red")
243 /// ~~~
244 
245 void TControlBar::SetTextColor(const char *colorName)
246 {
247  fControlBarImp->SetTextColor(colorName);
248 }
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Sets a state for control bar button 'label'; possible states are
252 /// 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,
253 ///
254 /// e.g.:
255 /// ~~~ {.cpp}
256 /// root > .x tutorials/demos.C
257 /// ~~~
258 /// to disable the button 'first' do:
259 /// ~~~ {.cpp}
260 /// root > bar->SetButtonState("first", 3)
261 /// ~~~
262 /// to enable the button 'first' do:
263 /// ~~~ {.cpp}
264 /// root > bar->SetButtonState("first", 0)
265 /// ~~~
266 
267 void TControlBar::SetButtonState(const char *label, Int_t state)
268 {
269  if (state > 3) {
270  Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
271  return;
272  }
273  fControlBarImp->SetButtonState(label, state);
274 }
275 
276 
277  ///////////////////////////////////////////////////////////////////////////////
278  /// Sets the width in pixels for control bar button.
279 
281 {
283 }
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// Set control bar orientation.
287 
288 void TControlBar::SetOrientation(const char *o)
289 {
291 
292  if( *o ) {
293  if( !strcasecmp( o, "vertical" ) )
295  else if( !strcasecmp( o, "horizontal" ) )
297  else
298  Error( "SetOrientation", "Unknown orientation: '%s' !\n\t\t(choice of: %s, %s)",
299  o, "vertical", "horizontal" );
300  }
301 }
302 
303 ////////////////////////////////////////////////////////////////////////////////
304 /// Set control bar orientation.
305 
307 {
309 
310  if( ( o == kVertical ) || ( o == kHorizontal ) )
311  fOrientation = o;
312  else
313  Error( "SetOrientation", "Unknown orientation: %d !\n\t\t(choice of: %d, %d)",
314  o, kVertical, kHorizontal );
315 }
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 /// Show control bar.
319 
321 {
322  if( fControlBarImp )
323  fControlBarImp->Show();
324 }
325 
326 ////////////////////////////////////////////////////////////////////////////////
327 /// Returns a pointer to the last clicked control bar button;
328 /// null if no button was clicked yet
329 
331 {
332  if (!fControlBarImp->GetClicked())
333  Printf("None of the control bar buttons is clicked yet");
334  return fControlBarImp->GetClicked();
335 }
void Show()
Show control bar.
virtual TControlBarButton * GetClicked()
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void AddButton(TControlBarButton *button)
Add button.
TControlBar()
Default constructor.
Definition: TControlBar.cxx:91
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition: TControlBar.h:22
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:409
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
void SetFont(const char *fontName)
Sets new font for control bar buttons, e.g.
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
virtual void SetTextColor(const char *)
virtual void Show()
Int_t fOrientation
orientation
Definition: TControlBar.h:33
TControlBarButton()
Default control bar button ctor.
int Int_t
Definition: RtypesCore.h:41
virtual ~TControlBar()
Destructor.
R__EXTERN TApplication * gApplication
Definition: TApplication.h:165
Float_t GetScreenFactor() const
Definition: TStyle.h:240
Double_t x[n]
Definition: legend1.C:17
virtual void SetButtonWidth(UInt_t)
virtual void SetFont(const char *)
R__EXTERN TGuiFactory * gGuiFactory
Definition: TGuiFactory.h:66
void SetButtonWidth(UInt_t width)
Sets the width in pixels for control bar button.
TControlBarButton * GetClicked() const
Returns a pointer to the last clicked control bar button; null if no button was clicked yet...
TControlBarImp * fControlBarImp
system specific implementation
Definition: TControlBar.h:32
A doubly linked list.
Definition: TList.h:43
void Initialize(Int_t x, Int_t y)
Initialize control bar.
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
virtual void Create()
virtual void Create()
Create control bar.
#define Printf
Definition: TGeoToOCC.h:18
void InitializeGraphics()
Initialize the graphics environment.
virtual void Hide()
#define ClassImp(name)
Definition: Rtypes.h:336
int type
Definition: TGX11.cxx:120
void AddControlBar(TControlBar *controlBar)
Add control bar.
Double_t y[n]
Definition: legend1.C:17
void Hide()
Hide control bar.
virtual void Add(TObject *obj)
Definition: TList.h:77
void SetOrientation(const char *o)
Set control bar orientation.
void AddSeparator()
Add separator.
void SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button 'label'; possible states are 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,.
This class defines the control bar buttons.
virtual TControlBarImp * CreateControlBarImp(TControlBar *c, const char *title)
Create a batch version of TControlBarImp.
Definition: TGuiFactory.cxx:96
Int_t fNoroc
number of rows or columns
Definition: TControlBar.h:35
virtual void SetButtonState(const char *, Int_t)
TList * fButtons
list of buttons
Definition: TControlBar.h:34