Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
buttonTest.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro gives an example of how to set/change text button attributes.
4/// To run it do either:
5/// ~~~
6/// .x buttonTest.C
7/// .x buttonTest.C++
8/// ~~~
9///
10/// \macro_code
11///
12/// \author Valeriy Onuchin 17/07/2007
13
14#include <TGButton.h>
15#include <TGButtonGroup.h>
16#include <TGLabel.h>
17#include <TGNumberEntry.h>
18#include <TG3DLine.h>
19#include <TApplication.h>
20
21
22
23//////////// auxilary class ///////////////////////////////////////////////////
24class TextMargin : public TGHorizontalFrame {
25
26protected:
27 TGNumberEntry *fEntry;
28
29public:
30 TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p)
31 {
32 fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
34 TGLabel *label = new TGLabel(this, name);
35 AddFrame(label, new TGLayoutHints(kLHintsLeft, 10));
36 }
37 TGTextEntry *GetEntry() const { return fEntry->GetNumberEntry(); }
38
39 ClassDef(TextMargin, 0)
40};
41
42////////////////////////////////////////////////////////////////////////////////
43class ButtonWindow : public TGMainFrame {
44
45protected:
46 TGTextButton *fButton; // button being tested
47
48public:
49 ButtonWindow();
50 void DoHPosition(Int_t);
51 void DoVPosition(Int_t);
52 void DoLeftMargin(char*);
53 void DoRightMargin(char*);
54 void DoTopMargin(char*);
55 void DoBottomMargin(char*);
56
57 ClassDef(ButtonWindow, 0)
58};
59
60
61//______________________________________________________________________________
62ButtonWindow::ButtonWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
63{
64 // Main test window.
65
66 SetCleanup(kDeepCleanup);
67
68 // Controls on right
69 TGVerticalFrame *controls = new TGVerticalFrame(this);
70 AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY,
71 5, 5, 5, 5));
72
73 // Separator
74 TGVertical3DLine *separator = new TGVertical3DLine(this);
75 AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));
76
77 // Contents
78 TGHorizontalFrame *contents = new TGHorizontalFrame(this);
79 AddFrame(contents, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,5,5));
80
81 // The button for test
82 fButton = new TGTextButton(contents,
83 "&This button has a multi-line label\nand shows features\n"
84 "available in the button classes");
85 fButton->Resize(300, 200);
86 fButton->ChangeOptions(fButton->GetOptions() | kFixedSize);
87 fButton->SetToolTipText("The assigned tooltip\ncan be multi-line also",200);
89 20, 20, 20, 20));
90
91 TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
92 group->SetTitlePos(TGGroupFrame::kCenter);
93 TGCheckButton *disable = new TGCheckButton(group, "Switch state\nEnable/Disable");
94 disable->SetOn();
95 disable->Connect("Toggled(Bool_t)", "TGButton", fButton, "SetEnabled(Bool_t)");
96 group->AddFrame(disable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
98
99
100 // control horizontal position of the text
101 TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
103 new TGRadioButton(horizontal, "Center", kTextCenterX);
104 new TGRadioButton(horizontal, "Left", kTextLeft);
105 new TGRadioButton(horizontal, "Right", kTextRight);
106 horizontal->SetButton(kTextCenterX);
107 horizontal->Connect("Pressed(Int_t)", "ButtonWindow", this,
108 "DoHPosition(Int_t)");
109 controls->AddFrame(horizontal, new TGLayoutHints(kLHintsExpandX));
110
111
112 // control vertical position of the text
113 TGButtonGroup *vertical = new TGButtonGroup(controls, "Vertical Position");
115 new TGRadioButton(vertical, "Center", kTextCenterY);
116 new TGRadioButton(vertical, "Top", kTextTop);
117 new TGRadioButton(vertical, "Bottom", kTextBottom);
118 vertical->SetButton(kTextCenterY);
119 vertical->Connect("Pressed(Int_t)", "ButtonWindow", this,
120 "DoVPosition(Int_t)");
121 controls->AddFrame(vertical, new TGLayoutHints(kLHintsExpandX));
122
123
124 // control margins of the text
125 TGGroupFrame *margins = new TGGroupFrame(controls, "Text Margins");
127
128 TextMargin *left = new TextMargin(margins, "Left");
129 margins->AddFrame(left, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
130 left->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
131 this, "DoLeftMargin(char*)");
132
133 TextMargin *right = new TextMargin(margins, "Right");
134 margins->AddFrame(right, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
135 right->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
136 this, "DoRightMargin(char*)");
137
138 TextMargin *top = new TextMargin(margins, "Top");
139 margins->AddFrame(top, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
140 top->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
141 this, "DoTopMargin(char*)");
142
143 TextMargin *bottom = new TextMargin(margins, "Bottom");
144 margins->AddFrame(bottom, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
145 bottom->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow",
146 this, "DoBottomMargin(char*)");
147
148 controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));
149
150 TGTextButton *quit = new TGTextButton(controls, "Quit");
152 0, 0, 0, 5));
153 quit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
154
155 Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
156 DontCallClose();
157
159 Resize();
160
161 SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), 1000, 1000, 0 ,0);
162 SetWindowName("Button Test");
163 MapRaised();
164}
165
166//______________________________________________________________________________
167void ButtonWindow::DoHPosition(Int_t id)
168{
169 // Horizontal position handler.
170
171 Int_t tj = fButton->GetTextJustify();
172 tj &= ~kTextCenterX;
173 tj &= ~kTextLeft;
174 tj &= ~kTextRight;
175 tj |= id;
176 fButton->SetTextJustify(tj);
177}
178
179//______________________________________________________________________________
180void ButtonWindow::DoVPosition(Int_t id)
181{
182 // Vertical position handler.
183
184 Int_t tj = fButton->GetTextJustify();
185
186 tj &= ~kTextCenterY;
187 tj &= ~kTextTop;
188 tj &= ~kTextBottom;
189 tj |= id;
190 fButton->SetTextJustify(tj);
191}
192
193//______________________________________________________________________________
194void ButtonWindow::DoLeftMargin(char *val)
195{
196 // Set left text margin.
197
198 fButton->SetLeftMargin(atoi(val));
199 gClient->NeedRedraw(fButton);
200}
201
202//______________________________________________________________________________
203void ButtonWindow::DoRightMargin(char *val)
204{
205 // Set right text margin.
206
207 fButton->SetRightMargin(atoi(val));
208 gClient->NeedRedraw(fButton);
209}
210
211//______________________________________________________________________________
212void ButtonWindow::DoTopMargin(char *val)
213{
214 // Set top text margin.
215
216 fButton->SetTopMargin(atoi(val));
217 gClient->NeedRedraw(fButton);
218}
219
220//______________________________________________________________________________
221void ButtonWindow::DoBottomMargin(char *val)
222{
223 // Set bottom text margin.
224
225 fButton->SetBottomMargin(atoi(val));
226 gClient->NeedRedraw(fButton);
227}
228
229
230////////////////////////////////////////////////////////////////////////////////
231void buttonTest()
232{
233 // Main program.
234
235 new ButtonWindow();
236}
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kFixedSize
Definition GuiTypes.h:390
int Int_t
Definition RtypesCore.h:45
#define ClassDef(name, id)
Definition Rtypes.h:337
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:156
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsExpandX
Definition TGLayout.h:30
@ kTextCenterX
Definition TGWidget.h:25
@ kTextLeft
Definition TGWidget.h:23
@ kTextBottom
Definition TGWidget.h:27
@ kTextTop
Definition TGWidget.h:26
@ kTextRight
Definition TGWidget.h:24
@ kTextCenterY
Definition TGWidget.h:28
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t SetWMSizeHints
char name[80]
Definition TGX11.cxx:110
Organizes TGButton widgets in a group.
virtual void SetButton(Int_t id, Bool_t down=kTRUE)
Sets the button with id to be on/down, and if this is an exclusive group, all other button in the gro...
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition TGButton.h:120
Selects different options.
Definition TGButton.h:264
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
A composite frame with a border and a title.
Definition TGFrame.h:522
virtual void SetTitlePos(ETitlePos pos=kLeft)
Definition TGFrame.h:564
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class handles GUI labels.
Definition TGLabel.h:24
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
TGNumberEntry is a number entry input widget with up/down buttons.
TGNumberEntryField * GetNumberEntry() const
Get the number entry field.
@ kNESInteger
Style of number entry field.
Selects different options.
Definition TGButton.h:321
Yield an action as soon as it is clicked.
Definition TGButton.h:142
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
A vertical 3D line is a line that can be used to separate groups of widgets.
Definition TG3DLine.h:33
A composite frame that layout their children in vertical way.
Definition TGFrame.h:374
ROOT GUI Window base class.
Definition TGWindow.h:23
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:869