Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15A Control Bar is a fully user configurable tool which provides fast
16access to frequently used operations. The user can choose between
17buttons and drawn buttons (let's say icons) and assign to them their
18own actions (let's say ROOT or C++ commands).
19
20The macro below shows an example of control bar.
21To execute an item, click with the left mouse button.
22To see the HELP of a button, click on the right mouse button.
23
24You have access to the last clicked button via the method
25GetClicked(). For example, bar->GetClicked()->GetName()
26will 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{
95 fOrientation = 0;
96 fButtons = 0;
97 fNoroc = 1;
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Normal constructor.
102
103TControlBar::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
113TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y)
114 : TControlBarButton(title, "", "", "button")
115{
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
156void 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 ) {
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
234void 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
246void 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
268void 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
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)",
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Show control bar.
320
322{
323 if( fControlBarImp )
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Returns a pointer to the last clicked control bar button;
329/// null if no button was clicked yet
330
332{
334 Printf("None of the control bar buttons is clicked yet");
335 return fControlBarImp->GetClicked();
336}
int Int_t
Definition RtypesCore.h:45
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TApplication * gApplication
include TDocParser_001 C image html pict1_TDocParser_001 png width
int type
Definition TGX11.cxx:121
R__EXTERN TGuiFactory * gGuiFactory
Definition TGuiFactory.h:66
void Printf(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
void InitializeGraphics()
Initialize the graphics environment.
This class defines the control bar buttons.
TControlBarButton()
Default control bar button ctor.
virtual void SetButtonWidth(UInt_t)
virtual void SetTextColor(const char *)
virtual void SetButtonState(const char *, Int_t)
virtual void SetFont(const char *)
virtual void Create()
virtual TControlBarButton * GetClicked()
virtual void Show()
virtual void Hide()
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
void SetFont(const char *fontName)
Sets new font for control bar buttons, e.g.:
TList * fButtons
list of buttons
Definition TControlBar.h:38
void Show()
Show control bar.
Int_t fOrientation
orientation
Definition TControlBar.h:37
void AddSeparator()
Add separator.
Int_t fNoroc
number of rows or columns
Definition TControlBar.h:39
void Initialize(Int_t x, Int_t y)
Initialize control bar.
TControlBarButton * GetClicked() const
Returns a pointer to the last clicked control bar button; null if no button was clicked yet.
void AddControlBar(TControlBar *controlBar)
Add control bar.
virtual ~TControlBar()
Destructor.
TControlBarImp * fControlBarImp
system specific implementation
Definition TControlBar.h:36
void SetOrientation(const char *o)
Set control bar orientation.
void SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button 'label'; possible states are 0-kButtonUp, 1-kButtonDown,...
void SetButtonWidth(UInt_t width)
Sets the width in pixels for control bar button.
virtual void Create()
Create control bar.
void AddButton(TControlBarButton *button)
Add button.
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.:
TControlBar()
Default constructor.
void Hide()
Hide control bar.
virtual TControlBarImp * CreateControlBarImp(TControlBar *c, const char *title)
Create a batch version of TControlBarImp.
A doubly linked list.
Definition TList.h:44
virtual void Add(TObject *obj)
Definition TList.h:87
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:893
Float_t GetScreenFactor() const
Definition TStyle.h:247
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17