This macro gives an example of how to create a list box and how to set and use its multiple selection feature.
private:
public:
~MyMainFrame() override;
void DoExit();
void DoSelect();
void HandleButtons();
void PrintSelected();
};
void MyMainFrame::DoSelect()
{
}
void MyMainFrame::DoExit()
{
}
{
char tmp[20];
for (int i = 0; i < 20; ++i) {
sprintf(tmp, "Entry %i", i + 1);
fListBox->AddEntry(tmp, i + 1);
}
fListBox->Resize(100, 150);
fCheckMulti =
new TGCheckButton(
this,
"&Mutliple selection", 10);
fCheckMulti->Connect("Clicked()", "MyMainFrame", this, "HandleButtons()");
show->
Connect(
"Pressed()",
"MyMainFrame",
this,
"PrintSelected()");
exit->
Connect(
"Pressed()",
"MyMainFrame",
this,
"DoExit()");
SetWindowName("List Box");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
fListBox->Select(1);
}
MyMainFrame::~MyMainFrame()
{
Cleanup();
if (fSelected) {
fSelected->Delete();
delete fSelected;
}
}
void MyMainFrame::HandleButtons()
{
printf("HandleButton: id = %d\n", id);
if (id == 10)
fListBox->SetMultipleSelections(fCheckMulti->GetState());
}
void MyMainFrame::PrintSelected()
{
fSelected->Clear();
if (fListBox->GetMultipleSelections()) {
Printf(
"Selected entries are:\n");
fListBox->GetSelectedEntries(fSelected);
fSelected->ls();
} else {
Printf(
"Selected entries is: %d\n", fListBox->GetSelected());
}
}
void listBox()
{
new MyMainFrame(
gClient->GetRoot(), 200, 200);
}
int Int_t
Signed integer 4 bytes (int).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
#define ClassDefOverride(name, id)
externTApplication * gApplication
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
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.
This class describes layout hints used by the layout classes.
A listbox is a box, possibly with scrollbar, containing entries.
Defines top level windows that interact with the system Window Manager.
Yield an action as soon as it is clicked.
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.