This macro gives an example of how to create a list box and how to set and use its multiple selection feature.
private:
public:
virtual ~MyMainFrame();
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);
5, 5, 5, 5));
fCheckMulti =
new TGCheckButton(
this,
"&Mutliple selection", 10);
5, 5, 5, 5));
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);
}
#define ClassDef(name, id)
R__EXTERN TApplication * gApplication
R__EXTERN void * gTQSender
void Printf(const char *fmt,...)
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
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.