Logo ROOT  
Reference Guide
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
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
158 MapSubwindows();
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:43
#define ClassDef(name, id)
Definition: Rtypes.h:322
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
#define gClient
Definition: TGClient.h:166
@ kDeepCleanup
Definition: TGFrame.h:51
@ kLHintsRight
Definition: TGLayout.h:33
@ kLHintsExpandY
Definition: TGLayout.h:38
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsCenterY
Definition: TGLayout.h:35
@ kLHintsCenterX
Definition: TGLayout.h:32
@ kLHintsBottom
Definition: TGLayout.h:36
@ kLHintsExpandX
Definition: TGLayout.h:37
@ kTextCenterX
Definition: TGWidget.h:36
@ kTextLeft
Definition: TGWidget.h:34
@ kTextBottom
Definition: TGWidget.h:38
@ kTextTop
Definition: TGWidget.h:37
@ kTextRight
Definition: TGWidget.h:35
@ kTextCenterY
Definition: TGWidget.h:39
XFontStruct * id
Definition: TGX11.cxx:108
char name[80]
Definition: TGX11.cxx:109
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
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1101
virtual void SetTitlePos(ETitlePos pos=kLeft)
Definition: TGFrame.h:629
TGNumberEntryField * GetNumberEntry() const
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:866
static const std::string separator("@@@")