Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
listBox.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro gives an example of how to create a list box and how to set and use its multiple selection feature.
4/// To run it do either:
5/// ~~~
6/// .x listBox.C
7/// .x listBox.C++
8/// ~~~
9///
10/// \macro_code
11///
12/// \author Ilka Antcheva 1/12/2006
13
14#include <TApplication.h>
15#include <TGClient.h>
16#include <TGButton.h>
17#include <TGListBox.h>
18#include <TList.h>
19
20class MyMainFrame : public TGMainFrame {
21
22private:
23 TGListBox *fListBox;
25 TList *fSelected;
26
27public:
29 ~MyMainFrame() override;
30 void DoExit();
31 void DoSelect();
32 void HandleButtons();
33 void PrintSelected();
34
36};
37
38void MyMainFrame::DoSelect()
39{
40 Printf("Slot DoSelect()");
41}
42
43void MyMainFrame::DoExit()
44{
45 Printf("Slot DoExit()");
47}
48
49MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
50{
51 // Create main frame
52
53 fListBox = new TGListBox(this, 89);
54 fSelected = new TList;
55 char tmp[20];
56 for (int i = 0; i < 20; ++i) {
57 sprintf(tmp, "Entry %i", i + 1);
58 fListBox->AddEntry(tmp, i + 1);
59 }
60 fListBox->Resize(100, 150);
61 AddFrame(fListBox, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
62
63 fCheckMulti = new TGCheckButton(this, "&Mutliple selection", 10);
64 AddFrame(fCheckMulti, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
65 fCheckMulti->Connect("Clicked()", "MyMainFrame", this, "HandleButtons()");
66 // Create a horizontal frame containing button(s)
68 TGTextButton *show = new TGTextButton(hframe, "&Show");
69 show->SetToolTipText("Click here to print the selection you made");
70 show->Connect("Pressed()", "MyMainFrame", this, "PrintSelected()");
71 hframe->AddFrame(show, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
72 TGTextButton *exit = new TGTextButton(hframe, "&Exit ");
73 exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
74 hframe->AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
75 AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
76
77 // Set a name to the main frame
78 SetWindowName("List Box");
80
81 // Initialize the layout algorithm via Resize()
82 Resize(GetDefaultSize());
83
84 // Map main frame
85 MapWindow();
86 fListBox->Select(1);
87}
88
89MyMainFrame::~MyMainFrame()
90{
91 // Clean up main frame...
92 Cleanup();
93 if (fSelected) {
94 fSelected->Delete();
95 delete fSelected;
96 }
97}
98
99void MyMainFrame::HandleButtons()
100{
101 // Handle check button.
102 Int_t id;
104 id = btn->WidgetId();
105
106 printf("HandleButton: id = %d\n", id);
107
108 if (id == 10)
109 fListBox->SetMultipleSelections(fCheckMulti->GetState());
110}
111
112void MyMainFrame::PrintSelected()
113{
114 // Writes selected entries in TList if multiselection.
115
116 fSelected->Clear();
117
118 if (fListBox->GetMultipleSelections()) {
119 Printf("Selected entries are:\n");
120 fListBox->GetSelectedEntries(fSelected);
121 fSelected->ls();
122 } else {
123 Printf("Selected entries is: %d\n", fListBox->GetSelected());
124 }
125}
126
127void listBox()
128{
129 // Popup the GUI...
130 new MyMainFrame(gClient->GetRoot(), 200, 200);
131}
@ 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