Logo ROOT  
Reference Guide
listBox.C File Reference

Detailed Description

This macro gives an example of how to create a list box and how to set and use its multiple selection feature. To run it do either:

.x listBox.C
.x listBox.C++
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGListBox.h>
#include <TList.h>
class MyMainFrame : public TGMainFrame {
private:
TGListBox *fListBox;
TGCheckButton *fCheckMulti;
TList *fSelected;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
void DoExit();
void DoSelect();
void HandleButtons();
void PrintSelected();
ClassDef(MyMainFrame, 0)
};
void MyMainFrame::DoSelect()
{
Printf("Slot DoSelect()");
}
void MyMainFrame::DoExit()
{
Printf("Slot DoExit()");
}
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
// Create main frame
fListBox = new TGListBox(this, 89);
fSelected = new TList;
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);
AddFrame(fListBox, new TGLayoutHints(kLHintsTop | kLHintsLeft |
5, 5, 5, 5));
fCheckMulti = new TGCheckButton(this, "&Mutliple selection", 10);
AddFrame(fCheckMulti, new TGLayoutHints(kLHintsTop | kLHintsLeft,
5, 5, 5, 5));
fCheckMulti->Connect("Clicked()", "MyMainFrame", this, "HandleButtons()");
// Create a horizontal frame containing button(s)
TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 150, 20, kFixedWidth);
TGTextButton *show = new TGTextButton(hframe, "&Show");
show->SetToolTipText("Click here to print the selection you made");
show->Connect("Pressed()", "MyMainFrame", this, "PrintSelected()");
hframe->AddFrame(show, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
TGTextButton *exit = new TGTextButton(hframe, "&Exit ");
exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
hframe->AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
// Set a name to the main frame
SetWindowName("List Box");
MapSubwindows();
// Initialize the layout algorithm via Resize()
Resize(GetDefaultSize());
// Map main frame
MapWindow();
fListBox->Select(1);
}
MyMainFrame::~MyMainFrame()
{
// Clean up main frame...
Cleanup();
if (fSelected) {
fSelected->Delete();
delete fSelected;
}
}
void MyMainFrame::HandleButtons()
{
// Handle check button.
id = btn->WidgetId();
printf("HandleButton: id = %d\n", id);
if (id == 10)
fListBox->SetMultipleSelections(fCheckMulti->GetState());
}
void MyMainFrame::PrintSelected()
{
// Writes selected entries in TList if multiselection.
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()
{
// Popup the GUI...
new MyMainFrame(gClient->GetRoot(), 200, 200);
}
Author
Ilka Antcheva 1/12/2006

Definition in file listBox.C.

TGButton::SetToolTipText
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:398
TGListBox
Definition: TGListBox.h:288
TGWindow
Definition: TGWindow.h:31
kFixedWidth
@ kFixedWidth
Definition: GuiTypes.h:387
TGMainFrame
Definition: TGFrame.h:444
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
TGListBox::SetMultipleSelections
virtual void SetMultipleSelections(Bool_t multi=kTRUE)
Definition: TGListBox.h:326
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGListBox::Resize
virtual void Resize(UInt_t w, UInt_t h)
Resize the listbox widget.
Definition: TGListBox.cxx:1420
TGTextButton
Definition: TGButton.h:142
gTQSender
R__EXTERN void * gTQSender
Definition: TQObject.h:44
Int_t
int Int_t
Definition: RtypesCore.h:45
TList.h
TGHorizontalFrame
Definition: TGFrame.h:423
id
XFontStruct * id
Definition: TGX11.cxx:109
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
TGCheckButton
Definition: TGButton.h:264
h
#define h(i)
Definition: RSha256.hxx:124
TGWidget::WidgetId
Int_t WidgetId() const
Definition: TGWidget.h:80
TGListBox::GetMultipleSelections
virtual Bool_t GetMultipleSelections() const
Definition: TGListBox.h:328
TGLayoutHints
Definition: TGLayout.h:57
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
TGListBox::GetSelected
virtual Int_t GetSelected() const
Return id of selected listbox item.
Definition: TGListBox.cxx:1524
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TApplication::Terminate
virtual void Terminate(Int_t status=0)
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
TGClient.h
TGListBox.h
Printf
void Printf(const char *fmt,...)
TGListBox::Select
virtual TGLBEntry * Select(Int_t id, Bool_t sel=kTRUE)
Definition: TGListBox.h:351
TGListBox::GetSelectedEntries
virtual void GetSelectedEntries(TList *selected)
Adds all selected entries (TGLBEntry) of the list box into the list selected.
Definition: TGListBox.cxx:1534
TQObject::Connect
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.
Definition: TQObject.cxx:864
TGButton::GetState
virtual EButtonState GetState() const
Definition: TGButton.h:112
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGButton
Definition: TGButton.h:68
TGListBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Add entry with specified string and id to listbox.
Definition: TGListBox.cxx:1212
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TList
Definition: TList.h:44