A simple example that shows the usage of a TGSplitButton.
The checkbutton is used to change the split state of the button.
#include <iostream>
enum EMenuIds {
ID_1,
ID_2,
ID_3,
ID_4,
ID_5
};
class IDList {
private:
public:
IDList() : nID(0) {}
~IDList() {}
Int_t GetUnID(
void) {
return ++nID; }
};
private:
TGSplitButton *fMButton;
TGPopupMenu *fPopMenu;
IDList IDs;
public:
~SplitButtonTest() override;
void DoExit();
void HandleMenu(
Int_t id);
};
{
Connect("CloseWindow()", "SplitButtonTest", this, "DoExit()");
DontCallClose();
fPopMenu->AddEntry("Button &1", ID_1);
fPopMenu->AddEntry("Button &2", ID_2);
fPopMenu->DisableEntry(ID_2);
fPopMenu->AddEntry("Button &3", ID_3);
fPopMenu->AddSeparator();
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)");
fCButton->
Connect(
"Toggled(Bool_t)",
"SplitButtonTest",
this,
"DoSplit(Bool_t)");
fEButton->
Connect(
"Toggled(Bool_t)",
"SplitButtonTest",
this,
"DoEnable(Bool_t)");
SetWindowName("SplitButton Test");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
};
SplitButtonTest::~SplitButtonTest()
{
Cleanup();
}
void SplitButtonTest::DoExit()
{
}
void SplitButtonTest::DoSplit(
Bool_t split)
{
fMButton->SetSplit(split);
}
void SplitButtonTest::DoEnable(
Bool_t on)
{
if (on)
else
}
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);
}
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
#define ClassDefOverride(name, id)
externTApplication * gApplication
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
A composite frame that layout their children in horizontal way.
TGHotString is a string with a "hot" character underlined.
This class describes layout hints used by the layout classes.
Defines top level windows that interact with the system Window Manager.
A composite frame that layout their children in vertical way.
ROOT GUI Window base class.
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.