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 // run macro from tutorials directory of ROOT!
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 graphics/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 hist/hsum.C",
39 "Filling histograms and some graphics options");
40 bar.AddButton("canvas", ".x graphics/canvas.C",
41 "Canvas and Pad Management");
42 bar.AddButton("formula1", ".x graphics/formula1.C",
43 "Simple Formula and Functions");
44 bar.AddButton("fillrandom", ".x hist/fillrandom.C",
45 "Histograms with Random Numbers from a Function");
46 bar.AddButton("fit1", ".x fit/fit1.C",
47 "A Simple Fitting Example");
48 bar.AddButton("draw2dopt", ".x hist/draw2dopt.C",
49 "Drawing Options for 2D Histograms");
50 bar.AddButton("graph", ".x graphs/graph.C",
51 "Examples of a simple graph");
52 bar.AddButton("tornado", ".x graphics/tornado.C",
53 "Examples of 3-D PolyMarkers");
54 bar.AddButton("shapes", ".x geom/shapes.C",
55 "The Geometry Shapes");
56 bar.AddButton("file_layout", ".x io/file.C",
57 "The ROOT file format");
58 bar.AddButton("tree_layout", ".x tree/tree.C",
59 "The Tree Data Structure");
60 bar.AddButton("ntuple1", ".x tree/ntuple1.C",
61 "Ntuples and Selections");
62 bar.AddButton("run benchmarks", ".x legacy/benchmarks.C",
63 "Runs all the ROOT benchmarks");
64 bar.AddButton("rootmarks", ".x legacy/rootmarks.C",
65 "Prints an estimated ROOTMARKS for your machine");
66 bar.AddButton("edit_hsimple", ".!vi hsimple.C &",
67 "Invokes the text editor on file hsimple.C");
68 bar.AddButton("Close Bar", "bar.Hide()",
69 "Close ControlBar");
70 bar.Show();
71}
72~~~
73\image html gpad_controlbar.png
74*/
75
76#include "TApplication.h"
77#include "TControlBar.h"
78#include "TControlBarImp.h"
79#include "TGuiFactory.h"
80#include "TList.h"
81#include "TStyle.h"
82#include "TROOT.h"
83
84
86
87////////////////////////////////////////////////////////////////////////////////
88/// Default constructor.
89
91{
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Normal constructor.
96
97TControlBar::TControlBar(const char *orientation, const char *title)
98 : TControlBarButton(title, "", "", "button")
99{
100 SetOrientation( orientation );
101 Initialize(-999, -999);
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Normal constructor.
106
107TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y)
108 : TControlBarButton(title, "", "", "button")
109{
112 SetOrientation( orientation );
113 Initialize(xs, ys);
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Destructor.
118
120{
121 delete fControlBarImp;
122
123 if( fButtons )
124 fButtons->Delete();
125
126 fButtons = nullptr;
127 fControlBarImp = nullptr;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Add button.
132
134{
135 AddButton( &button );
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Add button.
140
142{
143 if( fButtons && button )
144 fButtons->Add( button );
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Add button.
149
150void TControlBar::AddButton(const char *label, const char *action, const char *hint, const char *type)
151{
152 TControlBarButton *button = new TControlBarButton( label, action, hint, type );
153 AddButton( button );
154}
155
156////////////////////////////////////////////////////////////////////////////////
157/// Add control bar.
158
160{
161 AddControlBar( &controlBar );
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Add control bar.
166
168{
169 if( fButtons && controlBar )
170 fButtons->Add( controlBar );
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Add separator.
175
177{
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Create control bar.
182
184{
185 if( fControlBarImp ) {
187 }
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// Hide control bar.
192
194{
195 if( fControlBarImp ) {
197 }
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Initialize control bar.
202
204{
205 // Load and initialize graphics libraries if
206 // TApplication::NeedGraphicsLibs() has been called by a
207 // library static initializer.
208 if (gApplication)
209 gApplication->InitializeGraphics(gROOT->IsWebDisplay());
210
211 auto factory = gROOT->IsWebDisplay() ? gBatchGuiFactory : gGuiFactory;
212
213 if (x == -999) {
214 fControlBarImp = factory->CreateControlBarImp( this, GetName() );
215 } else {
216 fControlBarImp = factory->CreateControlBarImp( this, GetName(), x, y );
217 }
218
219 fButtons = new TList();
220 fNoroc = 1;
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// Sets new font for control bar buttons, e.g.:
225/// ~~~ {.cpp}
226/// root > .x tutorials/demos.C
227/// root > bar->SetFont("-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-iso8859-1")
228/// ~~~
229
230void TControlBar::SetFont(const char *fontName)
231{
232 fControlBarImp->SetFont(fontName);
233}
234
235////////////////////////////////////////////////////////////////////////////////
236/// Sets text color for control bar buttons, e.g.:
237/// ~~~ {.cpp}
238/// root > .x tutorials/demos.C
239/// root > bar->SetTextColor("red")
240/// ~~~
241
242void TControlBar::SetTextColor(const char *colorName)
243{
244 fControlBarImp->SetTextColor(colorName);
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Sets a state for control bar button 'label'; possible states are
249/// 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,
250///
251/// e.g.:
252/// ~~~ {.cpp}
253/// root > .x tutorials/demos.C
254/// ~~~
255/// to disable the button 'first' do:
256/// ~~~ {.cpp}
257/// root > bar->SetButtonState("first", 3)
258/// ~~~
259/// to enable the button 'first' do:
260/// ~~~ {.cpp}
261/// root > bar->SetButtonState("first", 0)
262/// ~~~
263
264void TControlBar::SetButtonState(const char *label, Int_t state)
265{
266 if (state > 3) {
267 Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
268 return;
269 }
270 fControlBarImp->SetButtonState(label, state);
271}
272
273
274 ///////////////////////////////////////////////////////////////////////////////
275 /// Sets the width in pixels for control bar button.
276
278{
280}
281
282////////////////////////////////////////////////////////////////////////////////
283/// Set control bar orientation.
284
286{
288
289 if( *o ) {
290 if( !strcasecmp( o, "vertical" ) )
292 else if( !strcasecmp( o, "horizontal" ) )
294 else
295 Error( "SetOrientation", "Unknown orientation: '%s' !\n\t\t(choice of: %s, %s)",
296 o, "vertical", "horizontal" );
297 }
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Set control bar orientation.
302
304{
306
307 if( ( o == kVertical ) || ( o == kHorizontal ) )
308 fOrientation = o;
309 else
310 Error( "SetOrientation", "Unknown orientation: %d !\n\t\t(choice of: %d, %d)",
312}
313
314////////////////////////////////////////////////////////////////////////////////
315/// Show control bar.
316
318{
319 if( fControlBarImp )
321}
322
323////////////////////////////////////////////////////////////////////////////////
324/// Returns a pointer to the last clicked control bar button;
325/// null if no button was clicked yet
326
328{
330 Printf("None of the control bar buttons is clicked yet");
331 return fControlBarImp->GetClicked();
332}
int Int_t
Definition RtypesCore.h:45
#define ClassImp(name)
Definition Rtypes.h:377
R__EXTERN TApplication * gApplication
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t button
R__EXTERN TGuiFactory * gBatchGuiFactory
Definition TGuiFactory.h:67
R__EXTERN TGuiFactory * gGuiFactory
Definition TGuiFactory.h:66
#define gROOT
Definition TROOT.h:406
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
void InitializeGraphics(Bool_t only_web=kFALSE)
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.
TControlBarImp * fControlBarImp
system specific implementation
Definition TControlBar.h:36
~TControlBar() override
Destructor.
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.
void Create() override
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.
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:83
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
Float_t GetScreenFactor() const
Definition TStyle.h:254
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17