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//////////// auxilary class ///////////////////////////////////////////////////
22class TextMargin : public TGHorizontalFrame {
23
24protected:
25 TGNumberEntry *fEntry;
26
27public:
28 TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p)
29 {
30 fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
32 TGLabel *label = new TGLabel(this, name);
33 AddFrame(label, new TGLayoutHints(kLHintsLeft, 10));
34 }
35 TGTextEntry *GetEntry() const { return fEntry->GetNumberEntry(); }
36
37 ClassDef(TextMargin, 0)
38};
39
40////////////////////////////////////////////////////////////////////////////////
41class ButtonWindow : public TGMainFrame {
42
43protected:
44 TGTextButton *fButton; // button being tested
45
46public:
47 ButtonWindow();
48 void DoHPosition(Int_t);
49 void DoVPosition(Int_t);
50 void DoLeftMargin(char *);
51 void DoRightMargin(char *);
52 void DoTopMargin(char *);
53 void DoBottomMargin(char *);
54
55 ClassDef(ButtonWindow, 0)
56};
57
58//______________________________________________________________________________
59ButtonWindow::ButtonWindow() : TGMainFrame(gClient->GetRoot(), 10, 10, kHorizontalFrame)
60{
61 // Main test window.
62
63 SetCleanup(kDeepCleanup);
64
65 // Controls on right
66 TGVerticalFrame *controls = new TGVerticalFrame(this);
67 AddFrame(controls, new TGLayoutHints(kLHintsRight | kLHintsExpandY, 5, 5, 5, 5));
68
69 // Separator
70 TGVertical3DLine *separator = new TGVertical3DLine(this);
71 AddFrame(separator, new TGLayoutHints(kLHintsRight | kLHintsExpandY));
72
73 // Contents
74 TGHorizontalFrame *contents = new TGHorizontalFrame(this);
75 AddFrame(contents, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5));
76
77 // The button for test
78 fButton = new TGTextButton(contents, "&This button has a multi-line label\nand shows features\n"
79 "available in the button classes");
80 fButton->Resize(300, 200);
81 fButton->ChangeOptions(fButton->GetOptions() | kFixedSize);
82 fButton->SetToolTipText("The assigned tooltip\ncan be multi-line also", 200);
83 contents->AddFrame(fButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 20, 20, 20, 20));
84
85 TGGroupFrame *group = new TGGroupFrame(controls, "Enable/Disable");
86 group->SetTitlePos(TGGroupFrame::kCenter);
87 TGCheckButton *disable = new TGCheckButton(group, "Switch state\nEnable/Disable");
88 disable->SetOn();
89 disable->Connect("Toggled(Bool_t)", "TGButton", fButton, "SetEnabled(Bool_t)");
90 group->AddFrame(disable, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
92
93 // control horizontal position of the text
94 TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
96 new TGRadioButton(horizontal, "Center", kTextCenterX);
97 new TGRadioButton(horizontal, "Left", kTextLeft);
98 new TGRadioButton(horizontal, "Right", kTextRight);
99 horizontal->SetButton(kTextCenterX);
100 horizontal->Connect("Pressed(Int_t)", "ButtonWindow", this, "DoHPosition(Int_t)");
101 controls->AddFrame(horizontal, new TGLayoutHints(kLHintsExpandX));
102
103 // control vertical position of the text
104 TGButtonGroup *vertical = new TGButtonGroup(controls, "Vertical Position");
106 new TGRadioButton(vertical, "Center", kTextCenterY);
107 new TGRadioButton(vertical, "Top", kTextTop);
108 new TGRadioButton(vertical, "Bottom", kTextBottom);
109 vertical->SetButton(kTextCenterY);
110 vertical->Connect("Pressed(Int_t)", "ButtonWindow", this, "DoVPosition(Int_t)");
111 controls->AddFrame(vertical, new TGLayoutHints(kLHintsExpandX));
112
113 // control margins of the text
114 TGGroupFrame *margins = new TGGroupFrame(controls, "Text Margins");
116
117 TextMargin *left = new TextMargin(margins, "Left");
118 margins->AddFrame(left, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
119 left->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoLeftMargin(char*)");
120
121 TextMargin *right = new TextMargin(margins, "Right");
122 margins->AddFrame(right, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
123 right->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoRightMargin(char*)");
124
125 TextMargin *top = new TextMargin(margins, "Top");
126 margins->AddFrame(top, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
127 top->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoTopMargin(char*)");
128
129 TextMargin *bottom = new TextMargin(margins, "Bottom");
130 margins->AddFrame(bottom, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
131 bottom->GetEntry()->Connect("TextChanged(char*)", "ButtonWindow", this, "DoBottomMargin(char*)");
132
133 controls->AddFrame(margins, new TGLayoutHints(kLHintsExpandX));
134
135 TGTextButton *quit = new TGTextButton(controls, "Quit");
136 controls->AddFrame(quit, new TGLayoutHints(kLHintsBottom | kLHintsExpandX, 0, 0, 0, 5));
137 quit->Connect("Pressed()", "TApplication", gApplication, "Terminate()");
138
139 Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
140 DontCallClose();
141
143 Resize();
144
145 SetWMSizeHints(GetDefaultWidth(), GetDefaultHeight(), 1000, 1000, 0, 0);
146 SetWindowName("Button Test");
147 MapRaised();
148}
149
150//______________________________________________________________________________
151void ButtonWindow::DoHPosition(Int_t id)
152{
153 // Horizontal position handler.
154
155 Int_t tj = fButton->GetTextJustify();
156 tj &= ~kTextCenterX;
157 tj &= ~kTextLeft;
158 tj &= ~kTextRight;
159 tj |= id;
160 fButton->SetTextJustify(tj);
161}
162
163//______________________________________________________________________________
164void ButtonWindow::DoVPosition(Int_t id)
165{
166 // Vertical position handler.
167
168 Int_t tj = fButton->GetTextJustify();
169
170 tj &= ~kTextCenterY;
171 tj &= ~kTextTop;
172 tj &= ~kTextBottom;
173 tj |= id;
174 fButton->SetTextJustify(tj);
175}
176
177//______________________________________________________________________________
178void ButtonWindow::DoLeftMargin(char *val)
179{
180 // Set left text margin.
181
182 fButton->SetLeftMargin(atoi(val));
183 gClient->NeedRedraw(fButton);
184}
185
186//______________________________________________________________________________
187void ButtonWindow::DoRightMargin(char *val)
188{
189 // Set right text margin.
190
191 fButton->SetRightMargin(atoi(val));
192 gClient->NeedRedraw(fButton);
193}
194
195//______________________________________________________________________________
196void ButtonWindow::DoTopMargin(char *val)
197{
198 // Set top text margin.
199
200 fButton->SetTopMargin(atoi(val));
201 gClient->NeedRedraw(fButton);
202}
203
204//______________________________________________________________________________
205void ButtonWindow::DoBottomMargin(char *val)
206{
207 // Set bottom text margin.
208
209 fButton->SetBottomMargin(atoi(val));
210 gClient->NeedRedraw(fButton);
211}
212
213////////////////////////////////////////////////////////////////////////////////
214void buttonTest()
215{
216 // Main program.
217
218 new ButtonWindow();
219}
@ kHorizontalFrame
Definition GuiTypes.h:382
@ kFixedSize
Definition GuiTypes.h:390
int Int_t
Definition RtypesCore.h:45
#define ClassDef(name, id)
Definition Rtypes.h:342
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:157
@ 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