Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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:

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGListBox.h>
#include <TList.h>
class MyMainFrame : public TGMainFrame {
private:
TGListBox *fListBox;
TList *fSelected;
public:
~MyMainFrame() override;
void DoExit();
void DoSelect();
void HandleButtons();
void PrintSelected();
};
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 | kLHintsExpandX | kLHintsExpandY, 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)
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");
// 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);
}
@ kFixedWidth
Definition GuiTypes.h:387
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
R__EXTERN TApplication * gApplication
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gClient
Definition TGClient.h:157
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
R__EXTERN void * gTQSender
Definition TQObject.h:46
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
A button abstract base class.
Definition TGButton.h:68
Selects different options.
Definition TGButton.h:264
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
A listbox is a box, possibly with scrollbar, containing entries.
Definition TGListBox.h:221
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:399
Yield an action as soon as it is clicked.
Definition TGButton.h:142
ROOT GUI Window base class.
Definition TGWindow.h:23
A doubly linked list.
Definition TList.h:38
Author
Ilka Antcheva 1/12/2006

Definition in file listBox.C.