Hi
I have the following macro for a simple listbox.
#include <TROOT.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TGLabel.h>
#include <TGComboBox.h>
#include <TGListBox.h>
#include <RQ_OBJECT.h>
class MainFrame
{
RQ_OBJECT("MainFrame")
private:
TGMainFrame *fMain;
TGCompositeFrame *fF1;
TGListBox *fListBox;
TGLayoutHints *fL1,*fL2;
TGCheckButton *fCheckMulti;
public:
MainFrame(const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MainFrame();
void MultiSelect();
};
MainFrame::MainFrame(const TGWindow *p,UInt_t w,UInt_t h)
{
fMain = new TGMainFrame(p,w,h);
fMain->SetWindowName("ListBox");
fMain->ChangeOptions((fMain->GetOptions() & ~kVerticalFrame) | kHorizontalFrame);
fF1 = new TGCompositeFrame(fMain, 100, 20, kVerticalFrame);
//define frames/text/button layout
fL1 = new TGLayoutHints(kLHintsTop | kLHintsLeft,20,20,20,20);
fL2 = new TGLayoutHints(kLHintsTop | kLHintsLeft,20,20,30,20);
fF1->AddFrame(new TGLabel(fF1, new TGString("List of Fruits")),
new TGLayoutHints(kLHintsTop | kLHintsLeft,20,20,0,5));
fF1->AddFrame(fListBox = new TGListBox(fF1, 1));
fListBox->AddEntry("- Apples", 100);
fListBox->AddEntry("- Oranges", 101);
fListBox->AddEntry("- Strawbery", 102);
fListBox->AddEntry("- Grapes", 103);
fListBox->AddEntry("- Melon", 104);
fListBox->AddEntry("- Olive", 105);
fListBox->AddEntry("- Guava", 106);
fListBox->AddEntry("- Peach", 107);
fListBox->AddEntry("- Mango", 108);
fListBox->AddEntry("- Lemon", 109);
fListBox->Resize(100, 100);
fF1->AddFrame(fCheckMulti = new TGCheckButton(fMain, "&Multi-Selectable", 10), fL2);
fCheckMulti->Connect("Clicked()", "MainFrame", this, "MultiSelect()");
fMain->AddFrame(fF1,fL1);
fMain->MapSubwindows();
fMain->Resize(140,200);
fMain->MapWindow();
}
MainFrame::~MainFrame()
{
fMain->Cleanup();
delete fMain;
}
void MainFrame::MultiSelect()
{
fListBox->SetMultipleSelections(fCheckMulti->GetState());
}
void listbox()
{
new MainFrame(gClient->GetRoot(), 200, 100);
}
I’m stuck with how to display on the console(using std::cout) the listbox entries that are selected. That is I want to output them every time they are selected. The only solution that I can think of is by making a series of if…else statements that go through all the entries checking whether they are selected, but I want to avoid that.
Any suggestions of how I can tackle this?
Cheers