Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootControlBar.cxx
Go to the documentation of this file.
1// @(#)root/gui:$Id$
2// Author: Fons Rademakers 22/02/98
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
13/** \class TRootControlBar
14 \ingroup guiwidgets
15
16This class provides an interface to the GUI dependent functions of
17the TControlBar class. A control bar is a horizontal or vertical bar
18with a number of buttons (text or picture buttons).
19
20*/
21
22
23#include "TRootControlBar.h"
24#include "TControlBar.h"
25#include "TList.h"
26#include "TGButton.h"
27
28
30
31////////////////////////////////////////////////////////////////////////////////
32/// Create a ROOT native GUI controlbar.
33
35 : TGMainFrame(gClient->GetRoot(), 10, 10), TControlBarImp(c)
36{
37 fWidgets = 0;
38 fXpos = x;
39 fYpos = y;
40 fBwidth = 0;
41 fClicked = 0;
43
44 // if controlbar orientation is horizontal change layout manager
45 if (c && c->GetOrientation() == TControlBar::kHorizontal) {
47 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1);
48 } else
50
51 SetWindowName(title);
52 SetIconName(title);
53}
54
55////////////////////////////////////////////////////////////////////////////////
56/// Delete the control bar implementation.
57
59{
60 delete fWidgets;
61 fWidgets = 0;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Create the control bar. Loop over all buttons defined in the
66/// TControlBar and create the buttons.
67
69{
70 fWidgets = new TList;
71 TGButton *b = 0;
72
75
76 while ((button = (TControlBarButton *) next())) {
77
78 switch (button->GetType()) {
79
81 Warning("Create", "separators not yet supported");
82 break;
83
85 Warning("Create", "picture buttons not yet supported");
86 break;
87
89 {
90 b = new TGTextButton(this, button->GetName());
91 b->SetToolTipText(button->GetTitle());
92 b->SetUserData(button);
93 AddFrame(b, fL1);
94 fWidgets->Add(b);
95 if (fBwidth < b->GetDefaultWidth())
96 fBwidth = b->GetDefaultWidth(); //do not cut the label
97 }
98 break;
99 }
100 }
101
104
108
109 if (fXpos != -999) {
110 Move(fXpos, fYpos);
112 }
115 else
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Show controlbar. If not yet created create it first.
121
123{
124 if (!fWidgets) Create();
125
126 MapRaised();
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Hide controlbar.
131
133{
134 UnmapWindow();
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Handle controlbar button messages.
139
141{
143
144 if (button) {
146 button->Action();
147 }
148 return kTRUE;
149}
150
151////////////////////////////////////////////////////////////////////////////////
152/// Really delete the control bar and the this GUI.
153
155{
156 delete fControlBar; // will in turn delete this object
157}
158
159////////////////////////////////////////////////////////////////////////////////
160/// Called when closed via window manager action.
161
163{
164 DeleteWindow(); // but do it slightly delayed here
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// sets new font for control bar buttons
169
170void TRootControlBar::SetFont(const char *fontName)
171{
172 TIter next(fWidgets);
173
174 TObject *obj;
175
176 while ((obj=next())) {
177 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
178
179 ((TGTextButton *)obj)->SetFont(fontName);
180 }
181 Resize();
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// sets new font for control bar buttons
186
187void TRootControlBar::SetButtonState(const char *label, Int_t state)
188{
189 TIter next(fWidgets);
190
191 TObject *obj;
192
193 while ((obj=next())) {
194 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
195
196 if (!strcmp(((TGTextButton *)obj)->GetTitle(), label)) {
197 switch (state) {
198 case 0: {
199 ((TGTextButton *)obj)->SetState(kButtonUp);
200 break;
201 }
202 case 1: {
203 ((TGTextButton *)obj)->SetState(kButtonDown);
204 break;
205 }
206 case 2: {
207 ((TGTextButton *)obj)->SetState(kButtonEngaged);
208 break;
209 }
210 case 3: {
211 ((TGTextButton *)obj)->SetState(kButtonDisabled);
212 break;
213 }
214 default: {
215 Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
216 break;
217 }
218 }
219 }
220 }
221 Resize();
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// sets text color for control bar buttons, e.g.:
226/// root > .x tutorials/demos.C
227/// root > bar->SetTextColor("red")
228
229void TRootControlBar::SetTextColor(const char *colorName)
230{
231 Pixel_t color;
232 gClient->GetColorByName(colorName, color);
233
234 if (!fWidgets) Create();
235
236 TIter next(fWidgets);
237
238 TObject *obj;
239
240 while ((obj=next())) {
241 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
242
243 ((TGTextButton *)obj)->SetTextColor(color);
244 }
245 Resize();
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Set button width in pixels.
250
252{
253 fBwidth = width;
254}
@ kHorizontalFrame
Definition GuiTypes.h:382
ULong_t Pixel_t
Pixel value.
Definition GuiTypes.h:40
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
long Longptr_t
Definition RtypesCore.h:82
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
@ kButtonEngaged
Definition TGButton.h:55
#define gClient
Definition TGClient.h:156
@ kMWMDecorResizeH
Definition TGFrame.h:65
@ kMWMFuncAll
Definition TGFrame.h:49
@ kMWMFuncResize
Definition TGFrame.h:50
@ kMWMDecorAll
Definition TGFrame.h:63
@ kMWMFuncMaximize
Definition TGFrame.h:53
@ kMWMInputModeless
Definition TGFrame.h:57
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetMWMHints
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void SetWMPosition
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 button
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
This class defines the control bar buttons.
ABC describing GUI independent control bar.
TControlBar * fControlBar
TControlBarButton * fClicked
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
TList * GetListOfButtons() const
Definition TControlBar.h:57
A button abstract base class.
Definition TGButton.h:68
TGDimension GetDefaultSize() const override
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:316
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:312
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1164
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1072
void ChangeOptions(UInt_t options) override
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1043
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:605
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:593
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:276
virtual UInt_t GetOptions() const
Definition TGFrame.h:197
void UnmapWindow() override
unmap window
Definition TGFrame.h:206
UInt_t GetHeight() const
Definition TGFrame.h:225
void MapRaised() override
map raised
Definition TGFrame.h:205
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1801
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1893
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1788
Yield an action as soon as it is clicked.
Definition TGButton.h:142
static TClass * Class()
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
This class provides an interface to the GUI dependent functions of the TControlBar class.
void Show() override
Show controlbar. If not yet created create it first.
void SetFont(const char *fontName) override
sets new font for control bar buttons
Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override
Handle controlbar button messages.
void SetTextColor(const char *colorName) override
sets text color for control bar buttons, e.g.: root > .x tutorials/demos.C root > bar->SetTextColor("...
void ReallyDelete() override
Really delete the control bar and the this GUI.
UInt_t fBwidth
button width in pixels
void CloseWindow() override
Called when closed via window manager action.
void SetButtonWidth(UInt_t width) override
Set button width in pixels.
void SetButtonState(const char *label, Int_t state=0) override
sets new font for control bar buttons
void Hide() override
Hide controlbar.
TRootControlBar(TControlBar *c=nullptr, const char *title="ROOT Control Bar", Int_t x=-999, Int_t y=-999)
Create a ROOT native GUI controlbar.
TList * fWidgets
list of TGTextButton or TGPictureButtons
void Create() override
Create the control bar.
~TRootControlBar() override
Delete the control bar implementation.
TGLayoutHints * fL1
button layout hints
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17