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 ~MyButtonTest() override;
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) : TGMainFrame(p, w, h)
50{
51 SetCleanup(kDeepCleanup);
52
53 Connect("CloseWindow()", "MyButtonTest", this, "DoExit()");
54 DontCallClose();
55
56 TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
57 fCheckb[0] = new TGCheckButton(fHL2, new TGHotString("Enable BG"), IDs.GetUnID());
58 fCheckb[0]->SetToolTipText("Enable/Disable the button group");
59 fHL2->AddFrame(fCheckb[0], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
60 fButtonGroup = new TGVButtonGroup(fHL2, "My Button Group");
61 fCheckb[1] = new TGCheckButton(fButtonGroup, new TGHotString("CB 2"), IDs.GetUnID());
62 fCheckb[2] = new TGCheckButton(fButtonGroup, new TGHotString("CB 3"), IDs.GetUnID());
63 fCheckb[3] = new TGCheckButton(fButtonGroup, new TGHotString("CB 4"), IDs.GetUnID());
64 fRadiob[0] = new TGRadioButton(fButtonGroup, new TGHotString("RB 1"), IDs.GetUnID());
65 fRadiob[1] = new TGRadioButton(fButtonGroup, new TGHotString("RB 2"), IDs.GetUnID());
66 fButtonGroup->Show();
67
68 fHL2->AddFrame(fButtonGroup, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
69 AddFrame(fHL2);
70
71 fCheckb[0]->Connect("Toggled(Bool_t)", "MyButtonTest", this, "SetGroupEnabled(Bool_t)");
72
73 TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 100, kFixedWidth);
74 fExit = new TGTextButton(fHL3, "&Exit", IDs.GetUnID());
75 fExit->Connect("Clicked()", "MyButtonTest", this, "DoExit()");
76 fHL3->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX));
77 AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
78
79 // Default state
80 fCheckb[0]->SetOn();
81 fButtonGroup->SetState(kTRUE);
82
83 SetWindowName("My Button Group");
85 Resize(GetDefaultSize());
86 MapWindow();
87
88 fButtonGroup->SetRadioButtonExclusive(kTRUE);
89 fRadiob[1]->SetOn();
90};
91
92MyButtonTest::~MyButtonTest()
93{
94 // Destructor.
95 Cleanup();
96}
97
98void MyButtonTest::DoExit()
99{
100 // Exit this application via the Exit button or Window Manager.
101 // Use one of the both lines according to your needs.
102 // Please note to re-run this macro in the same ROOT session,
103 // you have to compile it to get signals/slots 'on place'.
104
105 // DeleteWindow(); // to stay in the ROOT session
106 gApplication->Terminate(); // to exit and close the ROOT session
107}
108
109void MyButtonTest::SetGroupEnabled(Bool_t on)
110{
111 fButtonGroup->SetState(on);
112}
113
114void buttongroupState()
115{
116 new MyButtonTest(gClient->GetRoot(), 100, 100);
117}
@ kFixedWidth
Definition GuiTypes.h:387
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassDef(name, id)
Definition Rtypes.h:342
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:157
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsCenterY
Definition TGLayout.h:28
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
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 that layout their children in horizontal way.
Definition TGFrame.h:385
TGHotString is a string with a "hot" character underlined.
Definition TGString.h:42
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
Selects different options.
Definition TGButton.h:321
Yield an action as soon as it is clicked.
Definition TGButton.h:142
Organizes TGButton widgets in a group with one vertical column.
ROOT GUI Window base class.
Definition TGWindow.h:23