Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
buttongroupState.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// A simple example that shows the enabled and disabled state of a button group with radio and check buttons.
4///
5/// \macro_code
6///
7/// \author Roel Aaij 4/07/2007
8
9#include <TApplication.h>
10#include <TGClient.h>
11#include <TGButton.h>
12#include <TGFrame.h>
13#include <TGLayout.h>
14#include <TGWindow.h>
15#include <TGLabel.h>
16#include <TString.h>
17#include <TGButtonGroup.h>
18
19class IDList {
20
21private:
22 Int_t nID; // creates unique widget's IDs
23
24public:
25 IDList() : nID(0) {}
26 ~IDList() {}
27 Int_t GetUnID(void) { return ++nID; }
28};
29
30class MyButtonTest : public TGMainFrame {
31
32private:
33 TGTextButton *fExit; // Exit text button
34 TGVButtonGroup *fButtonGroup; // Button group
35 TGCheckButton *fCheckb[4]; // Check buttons
36 TGRadioButton *fRadiob[2]; // Radio buttons
37 IDList IDs; // Widget IDs generator
38
39public:
40 MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h);
41 virtual ~MyButtonTest();
42
43 void DoExit(void);
44 void SetGroupEnabled(Bool_t);
45
46 ClassDef(MyButtonTest, 0)
47};
48
49MyButtonTest::MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h)
50 : TGMainFrame(p, w, h)
51{
52 SetCleanup(kDeepCleanup);
53
54 Connect("CloseWindow()", "MyButtonTest", this, "DoExit()");
55 DontCallClose();
56
57 TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
58 fCheckb[0] = new TGCheckButton(fHL2, new TGHotString("Enable BG"),
59 IDs.GetUnID());
60 fCheckb[0]->SetToolTipText("Enable/Disable the button group");
62 1, 1, 1, 1));
63 fButtonGroup = new TGVButtonGroup(fHL2, "My Button Group");
64 fCheckb[1] = new TGCheckButton(fButtonGroup, new TGHotString("CB 2"),
65 IDs.GetUnID());
66 fCheckb[2] = new TGCheckButton(fButtonGroup, new TGHotString("CB 3"),
67 IDs.GetUnID());
68 fCheckb[3] = new TGCheckButton(fButtonGroup, new TGHotString("CB 4"),
69 IDs.GetUnID());
70 fRadiob[0] = new TGRadioButton(fButtonGroup, new TGHotString("RB 1"),
71 IDs.GetUnID());
72 fRadiob[1] = new TGRadioButton(fButtonGroup, new TGHotString("RB 2"),
73 IDs.GetUnID());
74 fButtonGroup->Show();
75
77 1, 1, 1, 1));
78 AddFrame(fHL2);
79
80 fCheckb[0]->Connect("Toggled(Bool_t)", "MyButtonTest", this,
81 "SetGroupEnabled(Bool_t)");
82
83 TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 100, kFixedWidth);
84 fExit = new TGTextButton(fHL3, "&Exit", IDs.GetUnID());
85 fExit->Connect("Clicked()", "MyButtonTest", this, "DoExit()");
86 fHL3->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX));
87 AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,1,1,1,1));
88
89 //Default state
90 fCheckb[0]->SetOn();
91 fButtonGroup->SetState(kTRUE);
92
93 SetWindowName("My Button Group");
94 MapSubwindows();
95 Resize(GetDefaultSize());
96 MapWindow();
97
98 fButtonGroup->SetRadioButtonExclusive(kTRUE);
99 fRadiob[1]->SetOn();
100};
101
102MyButtonTest::~MyButtonTest()
103{
104 // Destructor.
105 Cleanup();
106}
107
108void MyButtonTest::DoExit()
109{
110 // Exit this application via the Exit button or Window Manager.
111 // Use one of the both lines according to your needs.
112 // Please note to re-run this macro in the same ROOT session,
113 // you have to compile it to get signals/slots 'on place'.
114
115 //DeleteWindow(); // to stay in the ROOT session
116 gApplication->Terminate(); // to exit and close the ROOT session
117}
118
119void MyButtonTest::SetGroupEnabled(Bool_t on)
120{
121 fButtonGroup->SetState(on);
122}
123
124void buttongroupState()
125{
126 new MyButtonTest(gClient->GetRoot(),100,100);
127}
128
@ kFixedWidth
Definition GuiTypes.h:387
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
bool Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassDef(name, id)
Definition Rtypes.h:325
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:166
@ kDeepCleanup
Definition TGFrame.h:50
@ kLHintsCenterY
Definition TGLayout.h:35
@ kLHintsCenterX
Definition TGLayout.h:32
@ kLHintsExpandX
Definition TGLayout.h:37
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1102