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 ///////////////////////////////////////////////////
24 class TextMargin : public TGHorizontalFrame {
25 
26 protected:
27  TGNumberEntry *fEntry;
28 
29 public:
30  TextMargin(const TGWindow *p, const char *name) : TGHorizontalFrame(p)
31  {
32  fEntry = new TGNumberEntry(this, 0, 6, -1, TGNumberFormat::kNESInteger);
33  AddFrame(fEntry, new TGLayoutHints(kLHintsLeft));
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 ////////////////////////////////////////////////////////////////////////////////
43 class ButtonWindow : public TGMainFrame {
44 
45 protected:
46  TGTextButton *fButton; // button being tested
47 
48 public:
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 //______________________________________________________________________________
62 ButtonWindow::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);
88  contents->AddFrame(fButton, new TGLayoutHints(kLHintsCenterX|kLHintsCenterY,
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));
97  controls->AddFrame(group, new TGLayoutHints(kLHintsExpandX));
98 
99 
100  // control horizontal position of the text
101  TGButtonGroup *horizontal = new TGButtonGroup(controls, "Horizontal Position");
102  horizontal->SetTitlePos(TGGroupFrame::kCenter);
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");
151  controls->AddFrame(quit, new TGLayoutHints(kLHintsBottom | kLHintsExpandX,
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 //______________________________________________________________________________
167 void 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 //______________________________________________________________________________
180 void 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 //______________________________________________________________________________
194 void ButtonWindow::DoLeftMargin(char *val)
195 {
196  // Set left text margin.
197 
198  fButton->SetLeftMargin(atoi(val));
199  gClient->NeedRedraw(fButton);
200 }
201 
202 //______________________________________________________________________________
203 void ButtonWindow::DoRightMargin(char *val)
204 {
205  // Set right text margin.
206 
207  fButton->SetRightMargin(atoi(val));
208  gClient->NeedRedraw(fButton);
209 }
210 
211 //______________________________________________________________________________
212 void ButtonWindow::DoTopMargin(char *val)
213 {
214  // Set top text margin.
215 
216  fButton->SetTopMargin(atoi(val));
217  gClient->NeedRedraw(fButton);
218 }
219 
220 //______________________________________________________________________________
221 void ButtonWindow::DoBottomMargin(char *val)
222 {
223  // Set bottom text margin.
224 
225  fButton->SetBottomMargin(atoi(val));
226  gClient->NeedRedraw(fButton);
227 }
228 
229 
230 ////////////////////////////////////////////////////////////////////////////////
231 void buttonTest()
232 {
233  // Main program.
234 
235  new ButtonWindow();
236 }
ROOT::TMetaUtils::propNames::separator
static const std::string separator("@@@")
TGButtonGroup::SetButton
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...
Definition: TGButtonGroup.cxx:335
TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:32
kTextTop
@ kTextTop
Definition: TGWidget.h:36
TGMainFrame
Definition: TGFrame.h:443
TGGroupFrame::SetTitlePos
virtual void SetTitlePos(ETitlePos pos=kLeft)
Definition: TGFrame.h:628
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:31
TGLabel
Definition: TGLabel.h:32
TGTextButton
Definition: TGButton.h:142
Int_t
int Int_t
Definition: RtypesCore.h:45
kTextCenterX
@ kTextCenterX
Definition: TGWidget.h:35
TGVertical3DLine
Definition: TG3DLine.h:44
TGButtonGroup
Definition: TGButtonGroup.h:28
TGHorizontalFrame
Definition: TGFrame.h:422
kTextCenterY
@ kTextCenterY
Definition: TGWidget.h:38
TGNumberEntry::GetNumberEntry
TGNumberEntryField * GetNumberEntry() const
Definition: TGNumberEntry.h:269
id
XFontStruct * id
Definition: TGX11.cxx:109
gClient
#define gClient
Definition: TGClient.h:166
kTextLeft
@ kTextLeft
Definition: TGWidget.h:33
kLHintsBottom
@ kLHintsBottom
Definition: TGLayout.h:36
TApplication.h
TGCheckButton
Definition: TGButton.h:264
group
Definition: TWinNTSystem.h:59
TG3DLine.h
kLHintsCenterY
@ kLHintsCenterY
Definition: TGLayout.h:35
TGRadioButton
Definition: TGButton.h:322
TGVerticalFrame
Definition: TGFrame.h:411
TGTextEntry
Definition: TGTextEntry.h:39
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:33
TGLayoutHints
Definition: TGLayout.h:57
TGGroupFrame
Definition: TGFrame.h:586
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGButtonGroup.h
kFixedSize
@ kFixedSize
Definition: GuiTypes.h:390
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:38
kTextBottom
@ kTextBottom
Definition: TGWidget.h:37
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGLabel.h
TQObject::Connect
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
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
name
char name[80]
Definition: TGX11.cxx:110
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:50
TGButton::SetOn
virtual void SetOn(Bool_t on=kTRUE, Bool_t emit=kFALSE)
Definition: TGButton.h:120
TGGroupFrame::kCenter
@ kCenter
Definition: TGFrame.h:605
TGNumberEntry.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
kTextRight
@ kTextRight
Definition: TGWidget.h:34
TGNumberEntry
Definition: TGNumberEntry.h:157
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TGNumberFormat::kNESInteger
@ kNESInteger
Definition: TGNumberEntry.h:34