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 visualisation/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 visualisation/graphics/canvas.C",
41 "Canvas and Pad Management");
42 bar.AddButton("formula1", ".x visualisation/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 visualisation/graphs/gr001_simple.C",
51 "Examples of a simple graph");
52 bar.AddButton("tornado", ".x visualisation/graphics/tornado.C",
53 "Examples of 3-D PolyMarkers");
54 bar.AddButton("shapes", ".x legacy/g3d/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
85
86////////////////////////////////////////////////////////////////////////////////
87/// Default constructor.
88
92
93////////////////////////////////////////////////////////////////////////////////
94/// Normal constructor.
95
96TControlBar::TControlBar(const char *orientation, const char *title)
97 : TControlBarButton(title, "", "", "button")
98{
100 Initialize(-999, -999);
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Normal constructor.
105
106TControlBar::TControlBar(const char *orientation, const char *title, Int_t x, Int_t y)
107 : TControlBarButton(title, "", "", "button")
108{
112 Initialize(xs, ys);
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Destructor.
117
119{
120 delete fControlBarImp;
121
122 if( fButtons )
123 fButtons->Delete();
124
125 fButtons = nullptr;
126 fControlBarImp = nullptr;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Add button.
131
136
137////////////////////////////////////////////////////////////////////////////////
138/// Add button.
139
145
146////////////////////////////////////////////////////////////////////////////////
147/// Add button.
148
149void TControlBar::AddButton(const char *label, const char *action, const char *hint, const char *type)
150{
152 AddButton( button );
153}
154
155////////////////////////////////////////////////////////////////////////////////
156/// Add control bar.
157
162
163////////////////////////////////////////////////////////////////////////////////
164/// Add control bar.
165
171
172////////////////////////////////////////////////////////////////////////////////
173/// Add separator.
174
178
179////////////////////////////////////////////////////////////////////////////////
180/// Create control bar.
181
183{
184 if( fControlBarImp ) {
186 }
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Hide control bar.
191
193{
194 if( fControlBarImp ) {
196 }
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// Initialize control bar.
201
203{
204 // Load and initialize graphics libraries if
205 // TApplication::NeedGraphicsLibs() has been called by a
206 // library static initializer.
207 if (gApplication)
208 gApplication->InitializeGraphics(gROOT->IsWebDisplay());
209
210 auto factory = gROOT->IsWebDisplay() ? gBatchGuiFactory : gGuiFactory;
211
212 if (x == -999) {
213 fControlBarImp = factory->CreateControlBarImp( this, GetName() );
214 } else {
215 fControlBarImp = factory->CreateControlBarImp( this, GetName(), x, y );
216 }
217
218 fButtons = new TList();
219 fNoroc = 1;
220}
221
222////////////////////////////////////////////////////////////////////////////////
223/// Sets new font for control bar buttons, e.g.:
224/// ~~~ {.cpp}
225/// root > .x tutorials/demos.C
226/// root > bar->SetFont("-adobe-helvetica-bold-r-*-*-24-*-*-*-*-*-iso8859-1")
227/// ~~~
228
233
234////////////////////////////////////////////////////////////////////////////////
235/// Sets text color for control bar buttons, e.g.:
236/// ~~~ {.cpp}
237/// root > .x tutorials/demos.C
238/// root > bar->SetTextColor("red")
239/// ~~~
240
245
246////////////////////////////////////////////////////////////////////////////////
247/// Sets a state for control bar button 'label'; possible states are
248/// 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,
249///
250/// e.g.:
251/// ~~~ {.cpp}
252/// root > .x tutorials/demos.C
253/// ~~~
254/// to disable the button 'first' do:
255/// ~~~ {.cpp}
256/// root > bar->SetButtonState("first", 3)
257/// ~~~
258/// to enable the button 'first' do:
259/// ~~~ {.cpp}
260/// root > bar->SetButtonState("first", 0)
261/// ~~~
262
263void TControlBar::SetButtonState(const char *label, Int_t state)
264{
265 if (state > 3) {
266 Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
267 return;
268 }
269 fControlBarImp->SetButtonState(label, state);
270}
271
272
273 ///////////////////////////////////////////////////////////////////////////////
274 /// Sets the width in pixels for control bar button.
275
280
281////////////////////////////////////////////////////////////////////////////////
282/// Set control bar orientation.
283
285{
287
288 if( *o ) {
289 if( !strcasecmp( o, "vertical" ) )
291 else if( !strcasecmp( o, "horizontal" ) )
293 else
294 Error( "SetOrientation", "Unknown orientation: '%s' !\n\t\t(choice of: %s, %s)",
295 o, "vertical", "horizontal" );
296 }
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Set control bar orientation.
301
303{
305
306 if( ( o == kVertical ) || ( o == kHorizontal ) )
307 fOrientation = o;
308 else
309 Error( "SetOrientation", "Unknown orientation: %d !\n\t\t(choice of: %d, %d)",
311}
312
313////////////////////////////////////////////////////////////////////////////////
314/// Show control bar.
315
317{
318 if( fControlBarImp )
320}
321
322////////////////////////////////////////////////////////////////////////////////
323/// Returns a pointer to the last clicked control bar button;
324/// null if no button was clicked yet
325
327{
329 Printf("None of the control bar buttons is clicked yet");
330 return fControlBarImp->GetClicked();
331}
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:411
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2509
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
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:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:467
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
Float_t GetScreenFactor() const
Definition TStyle.h:258
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17