Logo ROOT  
Reference Guide
TGComboBox.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: Fons Rademakers 13/01/98
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGComboBox
13 #define ROOT_TGComboBox
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TGComboBox, TGComboBoxPopup //
19 // //
20 // A combobox (also known as a drop down listbox) allows the selection //
21 // of one item out of a list of items. The selected item is visible in //
22 // a little window. To view the list of possible items one has to click //
23 // on a button on the right of the little window. This will drop down //
24 // a listbox. After selecting an item from the listbox the box will //
25 // disappear and the newly selected item will be shown in the little //
26 // window. //
27 // //
28 // The TGComboBox is user callable. The TGComboBoxPopup is a service //
29 // class of the combobox. //
30 // //
31 // Selecting an item in the combobox will generate the event: //
32 // kC_COMMAND, kCM_COMBOBOX, combobox id, item id. //
33 // //
34 //////////////////////////////////////////////////////////////////////////
35 
36 #include "TGListBox.h"
37 
38 class TGScrollBarElement;
39 class TGTextEntry;
40 
42 
43 protected:
46 
47 private:
48  TGComboBoxPopup(const TGComboBoxPopup&); // Not implemented
49  TGComboBoxPopup& operator=(const TGComboBoxPopup&); // Not implemented
50 
51 public:
52  TGComboBoxPopup(const TGWindow *p = 0, UInt_t w = 1, UInt_t h = 1,
53  UInt_t options = kVerticalFrame,
54  Pixel_t back = GetWhitePixel());
55 
56  virtual Bool_t HandleButton(Event_t *);
58 
59  void SetListBox(TGListBox *lb) { fListBox = lb; }
60  void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h);
61  void EndPopup();
62 
63  ClassDef(TGComboBoxPopup,0) // Combobox popup window
64 };
65 
66 
67 class TGComboBox : public TGCompositeFrame, public TGWidget {
68 
69 private:
70  TGComboBox(const TGComboBox&); // Not implemented
71  TGComboBox& operator=(const TGComboBox&); // Not implemented
72 
73 protected:
74  TGLBEntry *fSelEntry; // selected item frame
75  TGTextEntry *fTextEntry; // text entry
76  TGScrollBarElement *fDDButton; // button controlling drop down of popup
77  TGComboBoxPopup *fComboFrame; // popup containing a listbox
78  TGListBox *fListBox; // the listbox with text items
79  const TGPicture *fBpic; // down arrow picture used in fDDButton
80  TGLayoutHints *fLhs; // layout hints for selected item frame
81  TGLayoutHints *fLhb; // layout hints for fDDButton
82  TGLayoutHints *fLhdd; // layout hints for fListBox
83 
84  virtual void Init();
85 
86 public:
87  TGComboBox(const TGWindow *p = 0, Int_t id = -1,
89  Pixel_t back = GetWhitePixel());
90  TGComboBox(const TGWindow *p, const char *text, Int_t id = -1,
92  Pixel_t back = GetWhitePixel());
93 
94  virtual ~TGComboBox();
95 
96  virtual void DrawBorder();
97  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
98 
99  virtual Bool_t HandleButton(Event_t *event);
100  virtual Bool_t HandleDoubleClick(Event_t *event);
101  virtual Bool_t HandleMotion(Event_t *event);
102  virtual Bool_t HandleSelection(Event_t *event);
103  virtual Bool_t HandleSelectionRequest(Event_t *event);
104  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
105 
106  virtual void AddEntry(TGString *s, Int_t id)
107  { fListBox->AddEntry(s, id); Resize(); }
108  virtual void AddEntry(const char *s, Int_t id)
109  { fListBox->AddEntry(s, id); Resize(); }
110  virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
111  { fListBox->AddEntry(lbe, lhints); Resize(); }
112  virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID)
113  { fListBox->InsertEntry(s, id, afterID); Resize(); }
114  virtual void InsertEntry(const char *s, Int_t id, Int_t afterID)
115  { fListBox->InsertEntry(s, id, afterID); Resize(); }
116  virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID)
117  { fListBox->InsertEntry(lbe, lhints, afterID); Resize(); }
118  virtual void NewEntry(const char *s = "Entry")
119  { fListBox->NewEntry(s); Resize(); } //*MENU*
120  virtual void RemoveEntry(Int_t id = -1); //*MENU*
121  virtual void RemoveAll(); //*MENU*
122  virtual void Layout();
123  virtual Bool_t IsTextInputEnabled() const { return (fTextEntry != 0); }
124  virtual void EnableTextInput(Bool_t on); //*TOGGLE* *GETTER=IsTextInputEnabled
125  virtual void RemoveEntries(Int_t from_ID, Int_t to_ID)
126  { fListBox->RemoveEntries(from_ID, to_ID); }
127  virtual Int_t GetNumberOfEntries() const
128  { return fListBox->GetNumberOfEntries(); }
129 
130  virtual TGListBox *GetListBox() const { return fListBox; }
131  virtual TGTextEntry *GetTextEntry() const { return fTextEntry; }
132  virtual TGLBEntry *FindEntry(const char *s) const;
133  virtual void Select(Int_t id, Bool_t emit = kTRUE);
134  virtual Int_t GetSelected() const { return fListBox->GetSelected(); }
135  virtual TGLBEntry *GetSelectedEntry() const
136  { return fListBox->GetSelectedEntry(); }
137  virtual void SetTopEntry(TGLBEntry *e, TGLayoutHints *lh);
138  virtual void SetEnabled(Bool_t on = kTRUE); //*TOGGLE* *GETTER=IsEnabled
139  virtual Bool_t IsEnabled() const { return fDDButton->IsEnabled(); }
140  virtual void SortByName(Bool_t ascend = kTRUE)
141  { fListBox->SortByName(ascend); } //*MENU*icon=bld_sortup.png*
142 
143  virtual void Selected(Int_t widgetId, Int_t id); // *SIGNAL*
144  virtual void Selected(Int_t id) { Emit("Selected(Int_t)", id); } // *SIGNAL*
145  virtual void Selected(const char *txt) { Emit("Selected(char*)", txt); } // *SIGNAL*
146  virtual void ReturnPressed(); // *SIGNAL*
147  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
148 
149  ClassDef(TGComboBox,0) // Combo box widget
150 };
151 
152 
153 //////////////////////////////////////////////////////////////////////////
154 // //
155 // The TGLineStyleComboBox user callable and it creates //
156 // a combobox for selecting the line style. //
157 // //
158 //////////////////////////////////////////////////////////////////////////
159 
161 
162 public:
163  TGLineStyleComboBox(const TGWindow *p = 0, Int_t id = -1,
165  Pixel_t back = GetWhitePixel());
166 
167  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
168 
169  ClassDef(TGLineStyleComboBox, 0) // Line style combobox widget
170 
171 };
172 
173 
174 //////////////////////////////////////////////////////////////////////////
175 // //
176 // The TGLineWidthComboBox user callable and it creates //
177 // a combobox for selecting the line width. //
178 // //
179 //////////////////////////////////////////////////////////////////////////
180 
181 
183 
184 public:
185  TGLineWidthComboBox(const TGWindow *p = 0, Int_t id = -1,
187  Pixel_t back = GetWhitePixel(), Bool_t none=kFALSE);
188 
189  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
190 
191  ClassDef(TGLineWidthComboBox, 0) // Line width combobox widget
192 
193 
194 };
195 
196 
197 //////////////////////////////////////////////////////////////////////////
198 // //
199 // The TGFontTypeComboBox is user callable and it creates //
200 // a combobox for selecting the font. //
201 // //
202 //////////////////////////////////////////////////////////////////////////
203 
204 const Int_t kMaxFonts = 20;
205 
207 
208 protected:
210 
211 public:
212  TGFontTypeComboBox(const TGWindow *p = 0, Int_t id = -1,
214  Pixel_t bask = GetWhitePixel());
215  virtual ~TGFontTypeComboBox();
216 
217  ClassDef(TGFontTypeComboBox, 0) // Font type combobox widget
218 };
219 
220 #endif
kMaxFonts
const Int_t kMaxFonts
Definition: TGComboBox.h:204
TGListBox::NewEntry
virtual void NewEntry(const char *s="Entry")
method used to add entry via context menu
Definition: TGListBox.cxx:1309
TGComboBox::SortByName
virtual void SortByName(Bool_t ascend=kTRUE)
Definition: TGComboBox.h:140
TGComboBoxPopup::TGComboBoxPopup
TGComboBoxPopup(const TGComboBoxPopup &)
TGListBox
Definition: TGListBox.h:288
TGComboBox::InsertEntry
virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID)
Definition: TGComboBox.h:116
TGComboBox::GetSelectedEntry
virtual TGLBEntry * GetSelectedEntry() const
Definition: TGComboBox.h:135
TGComboBox::AddEntry
virtual void AddEntry(const char *s, Int_t id)
Definition: TGComboBox.h:108
TGWindow
Definition: TGWindow.h:31
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
e
#define e(i)
Definition: RSha256.hxx:121
TGComboBox::GetNumberOfEntries
virtual Int_t GetNumberOfEntries() const
Definition: TGComboBox.h:127
TGComboBox::Init
virtual void Init()
Initiate the internal classes of a combo box.
Definition: TGComboBox.cxx:286
TGFontTypeComboBox
Definition: TGComboBox.h:206
TGComboBox::HandleSelectionRequest
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle selection request in text entry.
Definition: TGComboBox.cxx:572
TGPicture
Definition: TGPicture.h:36
TGDimension
Definition: TGDimension.h:27
TGFontTypeComboBox::~TGFontTypeComboBox
virtual ~TGFontTypeComboBox()
Text font combo box dtor.
Definition: TGComboBox.cxx:878
TGComboBox::ProcessMessage
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
Process messages generated by the listbox and forward messages to the combobox message handling windo...
Definition: TGComboBox.cxx:582
Pixel_t
ULong_t Pixel_t
Definition: GuiTypes.h:39
TGComboBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:106
TGFontTypeComboBox::TGFontTypeComboBox
TGFontTypeComboBox(const TGWindow *p=0, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t bask=GetWhitePixel())
Create a text font combo box.
Definition: TGComboBox.cxx:844
TGFrame::fWidth
UInt_t fWidth
Definition: TGFrame.h:112
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
FontStruct_t
Handle_t FontStruct_t
Definition: GuiTypes.h:38
TGComboBox::fSelEntry
TGLBEntry * fSelEntry
Definition: TGComboBox.h:74
TGScrollBarElement
Definition: TGScrollBar.h:48
TGComboBoxPopup::KeyPressed
void KeyPressed(TGFrame *, UInt_t, UInt_t)
Slot handling the key press events.
Definition: TGComboBox.cxx:195
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
TGComboBox::GetTextEntry
virtual TGTextEntry * GetTextEntry() const
Definition: TGComboBox.h:131
Int_t
int Int_t
Definition: RtypesCore.h:45
TGWidget
Definition: TGWidget.h:55
TGComboBox::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle pointer motion in text entry.
Definition: TGComboBox.cxx:556
TGComboBox::fLhdd
TGLayoutHints * fLhdd
Definition: TGComboBox.h:82
TGComboBox::Select
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:451
x
Double_t x[n]
Definition: legend1.C:17
TGListBox::GetSelectedEntry
virtual TGLBEntry * GetSelectedEntry() const
Definition: TGListBox.h:355
TGLineWidthComboBox::TGLineWidthComboBox
TGLineWidthComboBox(const TGWindow *p=0, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel(), Bool_t none=kFALSE)
Create a line width combo box.
Definition: TGComboBox.cxx:785
TGListBox::InsertEntry
virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID)
Insert entry with specified string and id behind the entry with afterID.
Definition: TGListBox.cxx:1287
TGComboBox::HandleDoubleClick
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click in text entry.
Definition: TGComboBox.cxx:548
TGFrame
Definition: TGFrame.h:105
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
kDoubleBorder
@ kDoubleBorder
Definition: GuiTypes.h:385
text
TText * text
Definition: entrylist_figure1.C:10
bool
TGComboBoxPopup::fSelected
TGLBEntry * fSelected
Definition: TGComboBox.h:45
TGComboBox::InsertEntry
virtual void InsertEntry(const char *s, Int_t id, Int_t afterID)
Definition: TGComboBox.h:114
TGComboBox::~TGComboBox
virtual ~TGComboBox()
Delete a combo box widget.
Definition: TGComboBox.cxx:263
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TGComboBox::FindEntry
virtual TGLBEntry * FindEntry(const char *s) const
Find entry by name.
Definition: TGComboBox.cxx:422
kSunkenFrame
@ kSunkenFrame
Definition: GuiTypes.h:383
TGListBox::RemoveEntries
virtual void RemoveEntries(Int_t from_ID, Int_t to_ID)
Remove a range of entries defined by from_ID and to_ID.
Definition: TGListBox.cxx:1362
TGComboBox::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in the combo box.
Definition: TGComboBox.cxx:475
TGComboBox::fLhb
TGLayoutHints * fLhb
Definition: TGComboBox.h:81
TGComboBox::fBpic
const TGPicture * fBpic
Definition: TGComboBox.h:79
TGComboBox::Selected
virtual void Selected(Int_t widgetId, Int_t id)
Emit signal.
Definition: TGComboBox.cxx:626
h
#define h(i)
Definition: RSha256.hxx:124
TGFontTypeComboBox::fFonts
FontStruct_t fFonts[kMaxFonts]
Definition: TGComboBox.h:209
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:590
TGTextEntry
Definition: TGTextEntry.h:39
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGComboBox::DrawBorder
virtual void DrawBorder()
Draw border of combo box widget.
Definition: TGComboBox.cxx:338
TGComboBox::fListBox
TGListBox * fListBox
Definition: TGComboBox.h:78
Long_t
long Long_t
Definition: RtypesCore.h:54
TGComboBox::Layout
virtual void Layout()
layout combobox
Definition: TGComboBox.cxx:535
TGLayoutHints
Definition: TGLayout.h:57
TGComboBox::RemoveEntries
virtual void RemoveEntries(Int_t from_ID, Int_t to_ID)
Definition: TGComboBox.h:125
TGListBox::GetSelected
virtual Int_t GetSelected() const
Return id of selected listbox item.
Definition: TGListBox.cxx:1524
TGComboBoxPopup::HandleButton
virtual Bool_t HandleButton(Event_t *)
Handle mouse button event in combo box popup.
Definition: TGComboBox.cxx:86
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGComboBox::GetListBox
virtual TGListBox * GetListBox() const
Definition: TGComboBox.h:130
y
Double_t y[n]
Definition: legend1.C:17
TGListBox.h
TGComboBox::IsTextInputEnabled
virtual Bool_t IsTextInputEnabled() const
Definition: TGComboBox.h:123
TGComboBox::fTextEntry
TGTextEntry * fTextEntry
Definition: TGComboBox.h:75
TGLBEntry
Definition: TGListBox.h:51
TGComboBoxPopup::PlacePopup
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
Popup combo box popup window at the specified place.
Definition: TGComboBox.cxx:132
TGComboBox::SetTopEntry
virtual void SetTopEntry(TGLBEntry *e, TGLayoutHints *lh)
Set a new combo box value (normally update of text string in fSelEntry is done via fSelEntry::Update(...
Definition: TGComboBox.cxx:433
TGLineStyleComboBox
Definition: TGComboBox.h:160
TGLineWidthComboBox::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a line width combo box widget as a C++ statement(s).
Definition: TGComboBox.cxx:809
unsigned int
TGComboBox
Definition: TGComboBox.h:67
TGComboBoxPopup::operator=
TGComboBoxPopup & operator=(const TGComboBoxPopup &)
TGComboBox::EnableTextInput
virtual void EnableTextInput(Bool_t on)
Switch text input or readonly mode of combobox (not perfect yet).
Definition: TGComboBox.cxx:362
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGComboBox::GetSelected
virtual Int_t GetSelected() const
Definition: TGComboBox.h:134
TGListBox::GetNumberOfEntries
virtual Int_t GetNumberOfEntries() const
Definition: TGListBox.h:330
TGComboBoxPopup::EndPopup
void EndPopup()
Ungrab pointer and unmap popup window.
Definition: TGComboBox.cxx:108
TGComboBox::fLhs
TGLayoutHints * fLhs
Definition: TGComboBox.h:80
TGComboBox::NewEntry
virtual void NewEntry(const char *s="Entry")
Definition: TGComboBox.h:118
TGComboBox::Selected
virtual void Selected(Int_t id)
Definition: TGComboBox.h:144
TGLineStyleComboBox::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a line style combo box widget as a C++ statement(s).
Definition: TGComboBox.cxx:767
TGListBox::SortByName
virtual void SortByName(Bool_t ascend=kTRUE)
Sort entries by name.
Definition: TGListBox.cxx:1514
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
Event_t
Definition: GuiTypes.h:173
TGComboBox::RemoveEntry
virtual void RemoveEntry(Int_t id=-1)
Remove entry. If id == -1, the currently selected entry is removed.
Definition: TGComboBox.cxx:516
TGComboBox::AddEntry
virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
Definition: TGComboBox.h:110
TGFrame::GetWhitePixel
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:694
TGScrollBarElement::IsEnabled
virtual Bool_t IsEnabled() const
Definition: TGScrollBar.h:73
TGComboBox::SavePrimitive
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a combo box widget as a C++ statement(s) on output stream out.
Definition: TGComboBox.cxx:699
TGComboBox::fComboFrame
TGComboBoxPopup * fComboFrame
Definition: TGComboBox.h:77
TGComboBoxPopup
Definition: TGComboBox.h:41
TGComboBoxPopup::fListBox
TGListBox * fListBox
Definition: TGComboBox.h:44
TGComboBox::Selected
virtual void Selected(const char *txt)
Definition: TGComboBox.h:145
TGFrame::fHeight
UInt_t fHeight
Definition: TGFrame.h:113
TGComboBox::RemoveAll
virtual void RemoveAll()
Remove all entries from combo box.
Definition: TGComboBox.cxx:683
TGComboBox::operator=
TGComboBox & operator=(const TGComboBox &)
TGListBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Add entry with specified string and id to listbox.
Definition: TGListBox.cxx:1212
TGCompositeFrame
Definition: TGFrame.h:324
TGLineStyleComboBox::TGLineStyleComboBox
TGLineStyleComboBox(const TGWindow *p=0, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel())
Create a line style combo box.
Definition: TGComboBox.cxx:746
TGComboBox::fDDButton
TGScrollBarElement * fDDButton
Definition: TGComboBox.h:76
TGComboBox::IsEnabled
virtual Bool_t IsEnabled() const
Definition: TGComboBox.h:139
TGComboBox::TGComboBox
TGComboBox(const TGComboBox &)
TGString
Definition: TGString.h:30
TGLineWidthComboBox
Definition: TGComboBox.h:182
TGComboBoxPopup::SetListBox
void SetListBox(TGListBox *lb)
Definition: TGComboBox.h:59
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TGComboBox::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGComboBox.h:97
TGComboBox::HandleSelection
virtual Bool_t HandleSelection(Event_t *event)
Handle selection in text entry.
Definition: TGComboBox.cxx:564
int
TGComboBox::InsertEntry
virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID)
Definition: TGComboBox.h:112
TGComboBox::ReturnPressed
virtual void ReturnPressed()
Add new entry to combo box when return key pressed inside text entry ReturnPressed signal is emitted.
Definition: TGComboBox.cxx:656
TGComboBox::SetEnabled
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
Definition: TGComboBox.cxx:639