#include <iostream>
#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 <TGMenu.h>
enum EMenuIds {
ID_1,
ID_2,
ID_3,
ID_4,
ID_5
};
class IDList {
private:
Int_t nID ;
public:
IDList() : nID(0) {}
~IDList() {}
Int_t GetUnID(void) { return ++nID ; }
} ;
class SplitButtonTest : public TGMainFrame {
private:
TGSplitButton *fMButton;
TGPopupMenu *fPopMenu;
IDList IDs ;
public:
SplitButtonTest(const TGWindow *p, UInt_t w, UInt_t h) ;
virtual ~SplitButtonTest() ;
void DoExit() ;
void DoSplit(Bool_t split) ;
void DoEnable(Bool_t on) ;
void HandleMenu(Int_t id) ;
ClassDef(SplitButtonTest, 0)
};
SplitButtonTest::SplitButtonTest(const TGWindow *p, UInt_t w, UInt_t h)
: TGMainFrame(p, w, h)
{
SetCleanup(kDeepCleanup) ;
Connect("CloseWindow()", "SplitButtonTest", this, "DoExit()") ;
DontCallClose() ;
TGVerticalFrame *fVL = new TGVerticalFrame(this, 100, 100) ;
TGHorizontalFrame *fHL = new TGHorizontalFrame(fVL, 100, 40) ;
fPopMenu = new TGPopupMenu(gClient->GetRoot());
fPopMenu->AddEntry("Button &1", ID_1);
fPopMenu->AddEntry("Button &2", ID_2);
fPopMenu->DisableEntry(ID_2);
fPopMenu->AddEntry("Button &3", ID_3);
fPopMenu->AddSeparator();
fMButton = new TGSplitButton(fHL, new TGHotString("Button &Options"),
fPopMenu, IDs.GetUnID());
fPopMenu->AddEntry("En&try with really really long name", ID_4);
fPopMenu->AddEntry("&Exit", ID_5);
fMButton->Connect("ItemClicked(Int_t)", "SplitButtonTest", this,
"HandleMenu(Int_t)");
TGCheckButton *fCButton = new TGCheckButton(fHL, new TGHotString("Split"),
IDs.GetUnID());
fCButton->SetState(kButtonDown);
fCButton->Connect("Toggled(Bool_t)", "SplitButtonTest", this, "DoSplit(Bool_t)");
fHL->AddFrame(fCButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
0, 10, 0, 0)) ;
TGCheckButton *fEButton = new TGCheckButton(fHL, new TGHotString("Enable"),
IDs.GetUnID());
fEButton->SetState(kButtonDown);
fEButton->Connect("Toggled(Bool_t)", "SplitButtonTest", this, "DoEnable(Bool_t)");
fHL->AddFrame(fEButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,
0, 10, 0, 0)) ;
fHL->AddFrame(fMButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));
fVL->AddFrame(fHL, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)) ;
AddFrame(fVL, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY)) ;
SetWindowName("SplitButton Test") ;
MapSubwindows() ;
Resize(GetDefaultSize()) ;
MapWindow() ;
} ;
SplitButtonTest::~SplitButtonTest()
{
Cleanup() ;
}
void SplitButtonTest::DoExit()
{
gApplication->Terminate();
}
void SplitButtonTest::DoSplit(Bool_t split)
{
fMButton->SetSplit(split);
}
void SplitButtonTest::DoEnable(Bool_t on)
{
if (on)
fMButton->SetState(kButtonUp);
else
fMButton->SetState(kButtonDisabled);
}
void SplitButtonTest::HandleMenu(Int_t id)
{
switch (id) {
case ID_1:
std::cout << "Button 1 was activated" << std::endl;
break;
case ID_2:
std::cout << "Button 2 was activated" << std::endl;
break;
case ID_3:
std::cout << "Button 3 was activated" << std::endl;
break;
case ID_4:
std::cout << "Button with a really really long name was activated"
<< std::endl;
break;
case ID_5:
DoExit();
break;
}
}
void splitbuttonTest()
{
new SplitButtonTest(gClient->GetRoot(),100,100);
}
|
|