#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TString.h>
#include <TGButtonGroup.h>
class IDList {
private:
Int_t nID;
public:
IDList() : nID(0) {}
~IDList() {}
Int_t GetUnID(void) { return ++nID; }
};
class MyButtonTest : public TGMainFrame {
private:
TGTextButton *fExit;
TGVButtonGroup *fButtonGroup;
TGCheckButton *fCheckb[4];
TGRadioButton *fRadiob[2];
IDList IDs;
public:
MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyButtonTest();
void DoExit(void);
void SetGroupEnabled(Bool_t);
ClassDef(MyButtonTest, 0)
};
MyButtonTest::MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup);
Connect("CloseWindow()", "MyButtonTest", this, "DoExit()");
DontCallClose();
TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
fCheckb[0] = new TGCheckButton(fHL2, new TGHotString("Enable BG"), IDs.GetUnID());
fCheckb[0]->SetToolTipText("Enable/Disable the button group");
fHL2->AddFrame(fCheckb[0], new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
fButtonGroup = new TGVButtonGroup(fHL2, "My Button Group");
fCheckb[1] = new TGCheckButton(fButtonGroup, new TGHotString("CB 2"), IDs.GetUnID());
fCheckb[2] = new TGCheckButton(fButtonGroup, new TGHotString("CB 3"), IDs.GetUnID());
fCheckb[3] = new TGCheckButton(fButtonGroup, new TGHotString("CB 4"), IDs.GetUnID());
fRadiob[0] = new TGRadioButton(fButtonGroup, new TGHotString("RB 1"), IDs.GetUnID());
fRadiob[1] = new TGRadioButton(fButtonGroup, new TGHotString("RB 2"), IDs.GetUnID());
fButtonGroup->Show();
fHL2->AddFrame(fButtonGroup, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
AddFrame(fHL2);
fCheckb[0]->Connect("Toggled(Bool_t)", "MyButtonTest", this, "SetGroupEnabled(Bool_t)");
TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 100, kFixedWidth);
fExit = new TGTextButton(fHL3, "&Exit", IDs.GetUnID());
fExit->Connect("Clicked()", "MyButtonTest", this, "DoExit()");
fHL3->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX));
AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 1, 1, 1, 1));
fCheckb[0]->SetOn();
fButtonGroup->SetState(kTRUE);
SetWindowName("My Button Group");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
fButtonGroup->SetRadioButtonExclusive(kTRUE);
fRadiob[1]->SetOn();
};
MyButtonTest::~MyButtonTest()
{
Cleanup();
}
void MyButtonTest::DoExit()
{
gApplication->Terminate();
}
void MyButtonTest::SetGroupEnabled(Bool_t on)
{
fButtonGroup->SetState(on);
}
void buttongroupState()
{
new MyButtonTest(gClient->GetRoot(),100,100);
}
|
|