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
29
30////////////////////////////////////////////////////////////////////////////////
31/// Create a ROOT native GUI controlbar.
32
34 : TGMainFrame(gClient->GetRoot(), 10, 10), TControlBarImp(c)
35{
36 fWidgets = 0;
37 fXpos = x;
38 fYpos = y;
39 fBwidth = 0;
40 fClicked = 0;
42
43 // if controlbar orientation is horizontal change layout manager
44 if (c && c->GetOrientation() == TControlBar::kHorizontal) {
46 fL1 = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1);
47 } else
49
50 SetWindowName(title);
51 SetIconName(title);
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Delete the control bar implementation.
56
62
63////////////////////////////////////////////////////////////////////////////////
64/// Create the control bar. Loop over all buttons defined in the
65/// TControlBar and create the buttons.
66
68{
69 fWidgets = new TList;
70 TGButton *b = 0;
71
74
75 while ((button = (TControlBarButton *) next())) {
76
77 switch (button->GetType()) {
78
80 Warning("Create", "separators not yet supported");
81 break;
82
84 Warning("Create", "picture buttons not yet supported");
85 break;
86
88 {
89 b = new TGTextButton(this, button->GetName());
90 b->SetToolTipText(button->GetTitle());
91 b->SetUserData(button);
92 AddFrame(b, fL1);
93 fWidgets->Add(b);
95 fBwidth = b->GetDefaultWidth(); //do not cut the label
96 }
97 break;
98 }
99 }
100
103
107
108 if (fXpos != -999) {
109 Move(fXpos, fYpos);
111 }
114 else
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Show controlbar. If not yet created create it first.
120
122{
123 if (!fWidgets) Create();
124
125 MapRaised();
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Hide controlbar.
130
132{
133 UnmapWindow();
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// Handle controlbar button messages.
138
149
150////////////////////////////////////////////////////////////////////////////////
151/// Really delete the control bar and the this GUI.
152
154{
155 delete fControlBar; // will in turn delete this object
156}
157
158////////////////////////////////////////////////////////////////////////////////
159/// Called when closed via window manager action.
160
162{
163 DeleteWindow(); // but do it slightly delayed here
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// sets new font for control bar buttons
168
170{
171 TIter next(fWidgets);
172
173 TObject *obj;
174
175 while ((obj=next())) {
176 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
177
178 ((TGTextButton *)obj)->SetFont(fontName);
179 }
180 Resize();
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// sets new font for control bar buttons
185
186void TRootControlBar::SetButtonState(const char *label, Int_t state)
187{
188 TIter next(fWidgets);
189
190 TObject *obj;
191
192 while ((obj=next())) {
193 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
194
195 if (!strcmp(((TGTextButton *)obj)->GetTitle(), label)) {
196 switch (state) {
197 case 0: {
198 ((TGTextButton *)obj)->SetState(kButtonUp);
199 break;
200 }
201 case 1: {
202 ((TGTextButton *)obj)->SetState(kButtonDown);
203 break;
204 }
205 case 2: {
206 ((TGTextButton *)obj)->SetState(kButtonEngaged);
207 break;
208 }
209 case 3: {
210 ((TGTextButton *)obj)->SetState(kButtonDisabled);
211 break;
212 }
213 default: {
214 Error("SetButtonState", "not valid button state (expecting 0, 1, 2 or 3)");
215 break;
216 }
217 }
218 }
219 }
220 Resize();
221}
222
223////////////////////////////////////////////////////////////////////////////////
224/// sets text color for control bar buttons, e.g.:
225/// root > .x tutorials/demos.C
226/// root > bar->SetTextColor("red")
227
229{
230 Pixel_t color;
231 gClient->GetColorByName(colorName, color);
232
233 if (!fWidgets) Create();
234
235 TIter next(fWidgets);
236
237 TObject *obj;
238
239 while ((obj=next())) {
240 if (!obj->InheritsFrom(TGTextButton::Class())) continue;
241
242 ((TGTextButton *)obj)->SetTextColor(color);
243 }
244 Resize();
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Set button width in pixels.
249
@ 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
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
@ 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:157
@ 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:318
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
UInt_t GetDefaultWidth() const override
Definition TGFrame.h:314
void MapSubwindows() override
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1156
void SetCleanup(Int_t mode=kLocalCleanup) override
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1064
void ChangeOptions(UInt_t options) override
Change composite frame options. Options is an OR of the EFrameTypes.
Definition TGFrame.cxx:1035
void Resize(UInt_t w=0, UInt_t h=0) override
Resize the frame.
Definition TGFrame.cxx:597
void Move(Int_t x, Int_t y) override
Move frame.
Definition TGFrame.cxx:585
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:268
virtual UInt_t GetOptions() const
Definition TGFrame.h:199
void UnmapWindow() override
unmap window
Definition TGFrame.h:208
UInt_t GetHeight() const
Definition TGFrame.h:227
void MapRaised() override
map raised
Definition TGFrame.h:207
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:399
void SetIconName(const char *name)
Set window icon name. This is typically done via the window manager.
Definition TGFrame.cxx:1793
void SetWMSize(UInt_t w, UInt_t h)
Give the window manager a window size hint.
Definition TGFrame.cxx:1885
void SetWindowName(const char *name=nullptr) override
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1780
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:543
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:501
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