00001
00002
00003
00004
00005
00006 #include <TApplication.h>
00007 #include <TGClient.h>
00008 #include <TGButton.h>
00009 #include <TGFrame.h>
00010 #include <TGLayout.h>
00011 #include <TGWindow.h>
00012 #include <TGLabel.h>
00013 #include <TString.h>
00014 #include <TGButtonGroup.h>
00015
00016 class IDList {
00017
00018 private:
00019 Int_t nID;
00020
00021 public:
00022 IDList() : nID(0) {}
00023 ~IDList() {}
00024 Int_t GetUnID(void) { return ++nID; }
00025 };
00026
00027 class MyButtonTest : public TGMainFrame {
00028
00029 private:
00030 TGTextButton *fExit;
00031 TGVButtonGroup *fButtonGroup;
00032 TGCheckButton *fCheckb[4];
00033 TGRadioButton *fRadiob[2];
00034 IDList IDs;
00035
00036 public:
00037 MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h);
00038 virtual ~MyButtonTest();
00039
00040 void DoExit(void);
00041 void SetGroupEnabled(Bool_t);
00042
00043 ClassDef(MyButtonTest, 0)
00044 };
00045
00046 MyButtonTest::MyButtonTest(const TGWindow *p, UInt_t w, UInt_t h)
00047 : TGMainFrame(p, w, h)
00048 {
00049 SetCleanup(kDeepCleanup);
00050
00051 Connect("CloseWindow()", "MyButtonTest", this, "DoExit()");
00052 DontCallClose();
00053
00054 TGHorizontalFrame *fHL2 = new TGHorizontalFrame(this, 70, 100);
00055 fCheckb[0] = new TGCheckButton(fHL2, new TGHotString("Enable BG"),
00056 IDs.GetUnID());
00057 fCheckb[0]->SetToolTipText("Enable/Disable the button group");
00058 fHL2->AddFrame(fCheckb[0], new TGLayoutHints(kLHintsCenterX|kLHintsCenterY,
00059 1, 1, 1, 1));
00060 fButtonGroup = new TGVButtonGroup(fHL2, "My Button Group");
00061 fCheckb[1] = new TGCheckButton(fButtonGroup, new TGHotString("CB 2"),
00062 IDs.GetUnID());
00063 fCheckb[2] = new TGCheckButton(fButtonGroup, new TGHotString("CB 3"),
00064 IDs.GetUnID());
00065 fCheckb[3] = new TGCheckButton(fButtonGroup, new TGHotString("CB 4"),
00066 IDs.GetUnID());
00067 fRadiob[0] = new TGRadioButton(fButtonGroup, new TGHotString("RB 1"),
00068 IDs.GetUnID());
00069 fRadiob[1] = new TGRadioButton(fButtonGroup, new TGHotString("RB 2"),
00070 IDs.GetUnID());
00071 fButtonGroup->Show();
00072
00073 fHL2->AddFrame(fButtonGroup, new TGLayoutHints(kLHintsCenterX|kLHintsCenterY,
00074 1, 1, 1, 1));
00075 AddFrame(fHL2);
00076
00077 fCheckb[0]->Connect("Toggled(Bool_t)", "MyButtonTest", this,
00078 "SetGroupEnabled(Bool_t)");
00079
00080 TGHorizontalFrame *fHL3 = new TGHorizontalFrame(this, 70, 100, kFixedWidth);
00081 fExit = new TGTextButton(fHL3, "&Exit", IDs.GetUnID());
00082 fExit->Connect("Clicked()", "MyButtonTest", this, "DoExit()");
00083 fHL3->AddFrame(fExit, new TGLayoutHints(kLHintsExpandX));
00084 AddFrame(fHL3, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,1,1,1,1));
00085
00086
00087 fCheckb[0]->SetOn();
00088 fButtonGroup->SetState(kTRUE);
00089
00090 SetWindowName("My Button Group");
00091 MapSubwindows();
00092 Resize(GetDefaultSize());
00093 MapWindow();
00094
00095 fButtonGroup->SetRadioButtonExclusive(kTRUE);
00096 fRadiob[1]->SetOn();
00097 };
00098
00099 MyButtonTest::~MyButtonTest()
00100 {
00101
00102 Cleanup();
00103 }
00104
00105 void MyButtonTest::DoExit()
00106 {
00107
00108
00109
00110
00111
00112
00113 gApplication->Terminate();
00114 }
00115
00116 void MyButtonTest::SetGroupEnabled(Bool_t on)
00117 {
00118 fButtonGroup->SetState(on);
00119 }
00120
00121 void buttongroupState()
00122 {
00123 new MyButtonTest(gClient->GetRoot(),100,100);
00124 }
00125