00001
00002
00003
00004
00005
00006 #include <iostream>
00007 #include <TApplication.h>
00008 #include <TGClient.h>
00009 #include <TGButton.h>
00010 #include <TGFrame.h>
00011 #include <TGLayout.h>
00012 #include <TGWindow.h>
00013 #include <TGLabel.h>
00014 #include <TString.h>
00015 #include <TGMenu.h>
00016
00017
00018
00019 enum EMenuIds {
00020 ID_1,
00021 ID_2,
00022 ID_3,
00023 ID_4,
00024 ID_5
00025 };
00026
00027 class IDList {
00028 private:
00029 Int_t nID ;
00030 public:
00031 IDList() : nID(0) {}
00032 ~IDList() {}
00033 Int_t GetUnID(void) { return ++nID ; }
00034 } ;
00035
00036
00037 class SplitButtonTest : public TGMainFrame {
00038
00039 private:
00040 TGSplitButton *fMButton;
00041 TGPopupMenu *fPopMenu;
00042
00043 IDList IDs ;
00044
00045 public:
00046 SplitButtonTest(const TGWindow *p, UInt_t w, UInt_t h) ;
00047 virtual ~SplitButtonTest() ;
00048
00049 void DoExit() ;
00050 void DoSplit(Bool_t split) ;
00051 void DoEnable(Bool_t on) ;
00052 void HandleMenu(Int_t id) ;
00053
00054 ClassDef(SplitButtonTest, 0)
00055 };
00056
00057 SplitButtonTest::SplitButtonTest(const TGWindow *p, UInt_t w, UInt_t h)
00058 : TGMainFrame(p, w, h)
00059 {
00060 SetCleanup(kDeepCleanup) ;
00061
00062 Connect("CloseWindow()", "SplitButtonTest", this, "DoExit()") ;
00063 DontCallClose() ;
00064
00065 TGVerticalFrame *fVL = new TGVerticalFrame(this, 100, 100) ;
00066 TGHorizontalFrame *fHL = new TGHorizontalFrame(fVL, 100, 40) ;
00067
00068
00069 fPopMenu = new TGPopupMenu(gClient->GetRoot());
00070 fPopMenu->AddEntry("Button &1", ID_1);
00071 fPopMenu->AddEntry("Button &2", ID_2);
00072 fPopMenu->DisableEntry(ID_2);
00073 fPopMenu->AddEntry("Button &3", ID_3);
00074 fPopMenu->AddSeparator();
00075
00076
00077 fMButton = new TGSplitButton(fHL, new TGHotString("Button &Options"),
00078 fPopMenu, IDs.GetUnID());
00079
00080
00081 fPopMenu->AddEntry("En&try with really really long name", ID_4);
00082 fPopMenu->AddEntry("&Exit", ID_5);
00083
00084
00085
00086 fMButton->Connect("ItemClicked(Int_t)", "SplitButtonTest", this,
00087 "HandleMenu(Int_t)");
00088
00089 TGCheckButton *fCButton = new TGCheckButton(fHL, new TGHotString("Split"),
00090 IDs.GetUnID());
00091 fCButton->SetState(kButtonDown);
00092 fCButton->Connect("Toggled(Bool_t)", "SplitButtonTest", this, "DoSplit(Bool_t)");
00093
00094
00095 fHL->AddFrame(fCButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
00096 0, 10, 0, 0)) ;
00097 TGCheckButton *fEButton = new TGCheckButton(fHL, new TGHotString("Enable"),
00098 IDs.GetUnID());
00099 fEButton->SetState(kButtonDown);
00100 fEButton->Connect("Toggled(Bool_t)", "SplitButtonTest", this, "DoEnable(Bool_t)");
00101
00102
00103 fHL->AddFrame(fEButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
00104 0, 10, 0, 0)) ;
00105 fHL->AddFrame(fMButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
00106 fVL->AddFrame(fHL, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)) ;
00107 AddFrame(fVL, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)) ;
00108
00109 SetWindowName("SplitButton Test") ;
00110 MapSubwindows() ;
00111 Resize(GetDefaultSize()) ;
00112 MapWindow() ;
00113
00114 } ;
00115
00116 SplitButtonTest::~SplitButtonTest()
00117 {
00118
00119 Cleanup() ;
00120 }
00121
00122 void SplitButtonTest::DoExit()
00123 {
00124
00125
00126
00127
00128
00129
00130 gApplication->Terminate();
00131 }
00132
00133 void SplitButtonTest::DoSplit(Bool_t split)
00134 {
00135 fMButton->SetSplit(split);
00136 }
00137
00138 void SplitButtonTest::DoEnable(Bool_t on)
00139 {
00140 if (on)
00141 fMButton->SetState(kButtonUp);
00142 else
00143 fMButton->SetState(kButtonDisabled);
00144 }
00145
00146 void SplitButtonTest::HandleMenu(Int_t id)
00147 {
00148
00149
00150
00151
00152 switch (id) {
00153 case ID_1:
00154 std::cout << "Button 1 was activated" << std::endl;
00155 break;
00156 case ID_2:
00157 std::cout << "Button 2 was activated" << std::endl;
00158 break;
00159 case ID_3:
00160 std::cout << "Button 3 was activated" << std::endl;
00161 break;
00162 case ID_4:
00163 std::cout << "Button with a really really long name was activated"
00164 << std::endl;
00165 break;
00166 case ID_5:
00167 DoExit();
00168 break;
00169 }
00170 }
00171 void splitbuttonTest()
00172 {
00173 new SplitButtonTest(gClient->GetRoot(),100,100);
00174 }
00175