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-2021, 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 #include "TGListBox.h"
17 
18 class TGScrollBarElement;
19 class TGTextEntry;
20 
22 
23 protected:
26 
27 private:
28  TGComboBoxPopup(const TGComboBoxPopup&) = delete;
30 
31 public:
32  TGComboBoxPopup(const TGWindow *p = nullptr, UInt_t w = 1, UInt_t h = 1,
33  UInt_t options = kVerticalFrame,
34  Pixel_t back = GetWhitePixel());
35 
36  virtual Bool_t HandleButton(Event_t *);
38 
39  void SetListBox(TGListBox *lb) { fListBox = lb; }
40  void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h);
41  void EndPopup();
42 
43  ClassDef(TGComboBoxPopup,0) // Combobox popup window
44 };
45 
46 
47 class TGComboBox : public TGCompositeFrame, public TGWidget {
48 
49 private:
50  TGComboBox(const TGComboBox&) = delete;
51  TGComboBox& operator=(const TGComboBox&) = delete;
52 
53 protected:
54  TGLBEntry *fSelEntry; ///< selected item frame
55  TGTextEntry *fTextEntry; ///< text entry
56  TGScrollBarElement *fDDButton; ///< button controlling drop down of popup
57  TGComboBoxPopup *fComboFrame; ///< popup containing a listbox
58  TGListBox *fListBox; ///< the listbox with text items
59  const TGPicture *fBpic; ///< down arrow picture used in fDDButton
60  TGLayoutHints *fLhs; ///< layout hints for selected item frame
61  TGLayoutHints *fLhb; ///< layout hints for fDDButton
62  TGLayoutHints *fLhdd; ///< layout hints for fListBox
63 
64  virtual void Init();
65 
66 public:
67  TGComboBox(const TGWindow *p = nullptr, Int_t id = -1,
69  Pixel_t back = GetWhitePixel());
70  TGComboBox(const TGWindow *p, const char *text, Int_t id = -1,
72  Pixel_t back = GetWhitePixel());
73 
74  virtual ~TGComboBox();
75 
76  virtual void DrawBorder();
77  virtual TGDimension GetDefaultSize() const { return TGDimension(fWidth, fHeight); }
78 
79  virtual Bool_t HandleButton(Event_t *event);
80  virtual Bool_t HandleDoubleClick(Event_t *event);
81  virtual Bool_t HandleMotion(Event_t *event);
82  virtual Bool_t HandleSelection(Event_t *event);
83  virtual Bool_t HandleSelectionRequest(Event_t *event);
84  virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
85 
86  virtual void AddEntry(TGString *s, Int_t id)
87  { fListBox->AddEntry(s, id); Resize(); }
88  virtual void AddEntry(const char *s, Int_t id)
89  { fListBox->AddEntry(s, id); Resize(); }
90  virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
91  { fListBox->AddEntry(lbe, lhints); Resize(); }
92  virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID)
93  { fListBox->InsertEntry(s, id, afterID); Resize(); }
94  virtual void InsertEntry(const char *s, Int_t id, Int_t afterID)
95  { fListBox->InsertEntry(s, id, afterID); Resize(); }
96  virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID)
97  { fListBox->InsertEntry(lbe, lhints, afterID); Resize(); }
98  virtual void NewEntry(const char *s = "Entry")
99  { fListBox->NewEntry(s); Resize(); } //*MENU*
100  virtual void RemoveEntry(Int_t id = -1); //*MENU*
101  virtual void RemoveAll(); //*MENU*
102  virtual void Layout();
103  virtual Bool_t IsTextInputEnabled() const { return (fTextEntry != 0); }
104  virtual void EnableTextInput(Bool_t on); //*TOGGLE* *GETTER=IsTextInputEnabled
105  virtual void RemoveEntries(Int_t from_ID, Int_t to_ID)
106  { fListBox->RemoveEntries(from_ID, to_ID); }
107  virtual Int_t GetNumberOfEntries() const
108  { return fListBox->GetNumberOfEntries(); }
109 
110  virtual TGListBox *GetListBox() const { return fListBox; }
111  virtual TGTextEntry *GetTextEntry() const { return fTextEntry; }
112  virtual TGLBEntry *FindEntry(const char *s) const;
113  virtual void Select(Int_t id, Bool_t emit = kTRUE);
114  virtual Int_t GetSelected() const { return fListBox->GetSelected(); }
115  virtual TGLBEntry *GetSelectedEntry() const
116  { return fListBox->GetSelectedEntry(); }
117  virtual void SetTopEntry(TGLBEntry *e, TGLayoutHints *lh);
118  virtual void SetEnabled(Bool_t on = kTRUE); //*TOGGLE* *GETTER=IsEnabled
119  virtual Bool_t IsEnabled() const { return fDDButton->IsEnabled(); }
120  virtual void SortByName(Bool_t ascend = kTRUE)
121  { fListBox->SortByName(ascend); } //*MENU*icon=bld_sortup.png*
122 
123  virtual void Selected(Int_t widgetId, Int_t id); // *SIGNAL*
124  virtual void Selected(Int_t id) { Emit("Selected(Int_t)", id); } // *SIGNAL*
125  virtual void Selected(const char *txt) { Emit("Selected(char*)", txt); } // *SIGNAL*
126  virtual void Changed() { Emit("Changed()"); } // *SIGNAL*
127  virtual void ReturnPressed(); // *SIGNAL*
128  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
129 
130  ClassDef(TGComboBox,0) // Combo box widget
131 };
132 
133 
134 /** \class TGLineStyleComboBox
135 The TGLineStyleComboBox user callable and it creates
136 a combobox for selecting the line style.
137 */
138 
140 
141 public:
142  TGLineStyleComboBox(const TGWindow *p = nullptr, Int_t id = -1,
144  Pixel_t back = GetWhitePixel());
145 
146  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
147 
148  ClassDef(TGLineStyleComboBox, 0) // Line style combobox widget
149 };
150 
151 
152 /** \class TGLineWidthComboBox
153 The TGLineWidthComboBox user callable and it creates
154 a combobox for selecting the line width.
155 */
156 
158 
159 public:
160  TGLineWidthComboBox(const TGWindow *p = 0, Int_t id = -1,
162  Pixel_t back = GetWhitePixel(), Bool_t none=kFALSE);
163 
164  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
165 
166  ClassDef(TGLineWidthComboBox, 0) // Line width combobox widget
167 };
168 
169 
170 /** \class TGFontTypeComboBox
171 The TGFontTypeComboBox is user callable and it creates
172 a combobox for selecting the font.
173 */
174 
175 const Int_t kMaxFonts = 20;
176 
178 
179 protected:
181 
182 public:
183  TGFontTypeComboBox(const TGWindow *p = 0, Int_t id = -1,
185  Pixel_t bask = GetWhitePixel());
186  virtual ~TGFontTypeComboBox();
187 
188  ClassDef(TGFontTypeComboBox, 0) // Font type combobox widget
189 };
190 
191 #endif
kMaxFonts
const Int_t kMaxFonts
Definition: TGComboBox.h:175
TGListBox::NewEntry
virtual void NewEntry(const char *s="Entry")
method used to add entry via context menu
Definition: TGListBox.cxx:1293
TGComboBox::SortByName
virtual void SortByName(Bool_t ascend=kTRUE)
Definition: TGComboBox.h:120
TGListBox
A TGListBox widget.
Definition: TGListBox.h:269
TGComboBox::InsertEntry
virtual void InsertEntry(TGLBEntry *lbe, TGLayoutHints *lhints, Int_t afterID)
Definition: TGComboBox.h:96
TGComboBox::GetSelectedEntry
virtual TGLBEntry * GetSelectedEntry() const
Definition: TGComboBox.h:115
TGComboBox::AddEntry
virtual void AddEntry(const char *s, Int_t id)
Definition: TGComboBox.h:88
TGWindow
ROOT GUI Window base class.
Definition: TGWindow.h:23
TGComboBox::operator=
TGComboBox & operator=(const TGComboBox &)=delete
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:100
e
#define e(i)
Definition: RSha256.hxx:103
TGComboBox::GetNumberOfEntries
virtual Int_t GetNumberOfEntries() const
Definition: TGComboBox.h:107
TGComboBox::Init
virtual void Init()
Initiate the internal classes of a combo box.
Definition: TGComboBox.cxx:291
TGFontTypeComboBox
The TGFontTypeComboBox is user callable and it creates a combobox for selecting the font.
Definition: TGComboBox.h:177
TGComboBox::HandleSelectionRequest
virtual Bool_t HandleSelectionRequest(Event_t *event)
Handle selection request in text entry.
Definition: TGComboBox.cxx:578
TGPicture
The TGPicture class implements pictures and icons used in the different GUI elements and widgets.
Definition: TGPicture.h:25
TGDimension
Definition: TGDimension.h:18
Option_t
const char Option_t
Definition: RtypesCore.h:66
TGFontTypeComboBox::~TGFontTypeComboBox
virtual ~TGFontTypeComboBox()
Text font combo box dtor.
Definition: TGComboBox.cxx:885
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:588
Pixel_t
ULong_t Pixel_t
Pixel value.
Definition: GuiTypes.h:40
TGComboBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Definition: TGComboBox.h:86
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:851
TGFrame::fWidth
UInt_t fWidth
frame width
Definition: TGFrame.h:87
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
FontStruct_t
Handle_t FontStruct_t
Pointer to font structure.
Definition: GuiTypes.h:39
TGComboBox::fSelEntry
TGLBEntry * fSelEntry
selected item frame
Definition: TGComboBox.h:54
TGScrollBarElement
Definition: TGScrollBar.h:29
TGComboBoxPopup::KeyPressed
void KeyPressed(TGFrame *, UInt_t, UInt_t)
Slot handling the key press events.
Definition: TGComboBox.cxx:200
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TGComboBox::GetTextEntry
virtual TGTextEntry * GetTextEntry() const
Definition: TGComboBox.h:111
Int_t
int Int_t
Definition: RtypesCore.h:45
TGWidget
The widget base class.
Definition: TGWidget.h:43
TGComboBox::HandleMotion
virtual Bool_t HandleMotion(Event_t *event)
Handle pointer motion in text entry.
Definition: TGComboBox.cxx:562
TGComboBox::fLhdd
TGLayoutHints * fLhdd
layout hints for fListBox
Definition: TGComboBox.h:62
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:456
x
Double_t x[n]
Definition: legend1.C:17
TGListBox::GetSelectedEntry
virtual TGLBEntry * GetSelectedEntry() const
Definition: TGListBox.h:336
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:792
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:1271
TGComboBox::HandleDoubleClick
virtual Bool_t HandleDoubleClick(Event_t *event)
Handle double click in text entry.
Definition: TGComboBox.cxx:554
TGFrame
Definition: TGFrame.h:80
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:25
TGComboBox::InsertEntry
virtual void InsertEntry(const char *s, Int_t id, Int_t afterID)
Definition: TGComboBox.h:94
TGComboBox::~TGComboBox
virtual ~TGComboBox()
Delete a combo box widget.
Definition: TGComboBox.cxx:268
TGComboBox::FindEntry
virtual TGLBEntry * FindEntry(const char *s) const
Find entry by name.
Definition: TGComboBox.cxx:427
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:1346
TGComboBox::HandleButton
virtual Bool_t HandleButton(Event_t *event)
Handle mouse button events in the combo box.
Definition: TGComboBox.cxx:481
TGComboBox::fLhb
TGLayoutHints * fLhb
layout hints for fDDButton
Definition: TGComboBox.h:61
TGComboBoxPopup::operator=
TGComboBoxPopup & operator=(const TGComboBoxPopup &)=delete
TGComboBox::fBpic
const TGPicture * fBpic
down arrow picture used in fDDButton
Definition: TGComboBox.h:59
TGComboBox::Selected
virtual void Selected(Int_t widgetId, Int_t id)
Emit signal, done only when selected entry changed.
Definition: TGComboBox.cxx:633
h
#define h(i)
Definition: RSha256.hxx:106
TGFontTypeComboBox::fFonts
FontStruct_t fFonts[kMaxFonts]
Definition: TGComboBox.h:180
TGFrame::Resize
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:605
TGTextEntry
A TGTextEntry is a one line text input widget.
Definition: TGTextEntry.h:24
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:101
TGComboBox::DrawBorder
virtual void DrawBorder()
Draw border of combo box widget.
Definition: TGComboBox.cxx:343
TGComboBox::fListBox
TGListBox * fListBox
the listbox with text items
Definition: TGComboBox.h:58
Long_t
long Long_t
Definition: RtypesCore.h:54
TGComboBox::Layout
virtual void Layout()
layout combobox
Definition: TGComboBox.cxx:541
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition: TGLayout.h:50
TGComboBox::RemoveEntries
virtual void RemoveEntries(Int_t from_ID, Int_t to_ID)
Definition: TGComboBox.h:105
TGListBox::GetSelected
virtual Int_t GetSelected() const
Return id of selected listbox item.
Definition: TGListBox.cxx:1508
TGComboBoxPopup::HandleButton
virtual Bool_t HandleButton(Event_t *)
Handle mouse button event in combo box popup.
Definition: TGComboBox.cxx:91
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGComboBox::GetListBox
virtual TGListBox * GetListBox() const
Definition: TGComboBox.h:110
y
Double_t y[n]
Definition: legend1.C:17
TGListBox.h
TGComboBox::IsTextInputEnabled
virtual Bool_t IsTextInputEnabled() const
Definition: TGComboBox.h:103
TGComboBox::fTextEntry
TGTextEntry * fTextEntry
text entry
Definition: TGComboBox.h:55
TGLBEntry
Basic listbox entries.
Definition: TGListBox.h:32
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:137
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:438
TGLineStyleComboBox
The TGLineStyleComboBox user callable and it creates a combobox for selecting the line style.
Definition: TGComboBox.h:139
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:816
unsigned int
TGComboBox
A combobox (also known as a drop down listbox) allows the selection of one item out of a list of item...
Definition: TGComboBox.h:47
TGComboBox::EnableTextInput
virtual void EnableTextInput(Bool_t on)
Switch text input or readonly mode of combobox (not perfect yet).
Definition: TGComboBox.cxx:367
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TGComboBox::GetSelected
virtual Int_t GetSelected() const
Definition: TGComboBox.h:114
TGListBox::GetNumberOfEntries
virtual Int_t GetNumberOfEntries() const
Definition: TGListBox.h:311
TGComboBoxPopup::EndPopup
void EndPopup()
Ungrab pointer and unmap popup window.
Definition: TGComboBox.cxx:113
TGComboBox::Changed
virtual void Changed()
Definition: TGComboBox.h:126
TGComboBox::fLhs
TGLayoutHints * fLhs
layout hints for selected item frame
Definition: TGComboBox.h:60
TGComboBox::NewEntry
virtual void NewEntry(const char *s="Entry")
Definition: TGComboBox.h:98
TGComboBoxPopup::TGComboBoxPopup
TGComboBoxPopup(const TGComboBoxPopup &)=delete
TGLineStyleComboBox::TGLineStyleComboBox
TGLineStyleComboBox(const TGWindow *p=nullptr, Int_t id=-1, UInt_t options=kHorizontalFrame|kSunkenFrame|kDoubleBorder, Pixel_t back=GetWhitePixel())
Create a line style combo box.
Definition: TGComboBox.cxx:753
TGComboBox::Selected
virtual void Selected(Int_t id)
Definition: TGComboBox.h:124
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:774
TGListBox::SortByName
virtual void SortByName(Bool_t ascend=kTRUE)
Sort entries by name.
Definition: TGListBox.cxx:1498
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
Event_t
Event structure.
Definition: GuiTypes.h:174
TGComboBox::RemoveEntry
virtual void RemoveEntry(Int_t id=-1)
Remove entry. If id == -1, the currently selected entry is removed.
Definition: TGComboBox.cxx:522
TGComboBox::AddEntry
virtual void AddEntry(TGLBEntry *lbe, TGLayoutHints *lhints)
Definition: TGComboBox.h:90
TGFrame::GetWhitePixel
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:709
TGScrollBarElement::IsEnabled
virtual Bool_t IsEnabled() const
Definition: TGScrollBar.h:54
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:706
TGComboBox::fComboFrame
TGComboBoxPopup * fComboFrame
popup containing a listbox
Definition: TGComboBox.h:57
TGComboBoxPopup
A service class of the combobox.
Definition: TGComboBox.h:21
TGComboBoxPopup::fListBox
TGListBox * fListBox
Definition: TGComboBox.h:24
TGComboBox::Selected
virtual void Selected(const char *txt)
Definition: TGComboBox.h:125
TGFrame::fHeight
UInt_t fHeight
frame height
Definition: TGFrame.h:88
TGComboBox::RemoveAll
virtual void RemoveAll()
Remove all entries from combo box.
Definition: TGComboBox.cxx:690
TGListBox::AddEntry
virtual void AddEntry(TGString *s, Int_t id)
Add entry with specified string and id to listbox.
Definition: TGListBox.cxx:1196
TGCompositeFrame
The base class for composite widgets (menu bars, list boxes, etc.).
Definition: TGFrame.h:287
TGComboBox::fDDButton
TGScrollBarElement * fDDButton
button controlling drop down of popup
Definition: TGComboBox.h:56
TGComboBox::IsEnabled
virtual Bool_t IsEnabled() const
Definition: TGComboBox.h:119
TGString
TGString wraps a TString and adds some graphics routines like drawing, size of string on screen depen...
Definition: TGString.h:20
TGLineWidthComboBox
The TGLineWidthComboBox user callable and it creates a combobox for selecting the line width.
Definition: TGComboBox.h:157
TGComboBoxPopup::SetListBox
void SetListBox(TGListBox *lb)
Definition: TGComboBox.h:39
TQObject::Emit
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
TGComboBox::TGComboBox
TGComboBox(const TGComboBox &)=delete
TGComboBox::GetDefaultSize
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGComboBox.h:77
TGComboBox::HandleSelection
virtual Bool_t HandleSelection(Event_t *event)
Handle selection in text entry.
Definition: TGComboBox.cxx:570
int
TGComboBox::InsertEntry
virtual void InsertEntry(TGString *s, Int_t id, Int_t afterID)
Definition: TGComboBox.h:92
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:663
TGComboBox::SetEnabled
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
Definition: TGComboBox.cxx:646