ubit
ulistbox.hpp
1 /************************************************************************
2  *
3  * ulistbox.hpp
4  * Ubit GUI Toolkit - Version 6
5  * (C) 2009 | Eric Lecolinet | TELECOM ParisTech | http://www.enst.fr/~elc/ubit
6  *
7  * ***********************************************************************
8  * COPYRIGHT NOTICE :
9  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE
10  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
11  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU
12  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION;
13  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
14  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
15  * ***********************************************************************/
16 
17 #ifndef _ulistbox_hpp_
18 #define _ulistbox_hpp_ 1
19 #include <ubit/uinteractors.hpp>
20 #include <ubit/uchoice.hpp>
21 namespace ubit {
22 
28  class URadiobox: public UBox {
29  public:
30  UCLASS(URadiobox)
31 
32  URadiobox(const UArgs& args = UArgs::none);
34 
35  virtual UBox* getSelectedItem() const;
37 
38  virtual int getSelectedIndex() const;
40 
41  virtual URadiobox& setSelectedItem(UBox& item);
43 
44  virtual URadiobox& setSelectedItem(UBox* item);
46 
47  virtual URadiobox& setSelectedIndex(int n);
49 
50  URadiobox& select(UBox& item) {return setSelectedItem(item);}
52 
53  URadiobox& select(int n) {return setSelectedIndex(n);}
55 
56  UChoice& choice() {return *pchoice;}
58 
59  const UChoice& choice() const {return *pchoice;}
61 
62  protected:
63  uptr<UChoice> pchoice;
64  };
65 
66  inline URadiobox& uradiobox(UArgs args = UArgs::none) {return *new URadiobox(args);}
68 
69 
70  /* ==================================================== ===== ======= */
117  class UListbox: public URadiobox {
118  public:
119  UCLASS(UListbox)
120 
121  UListbox(const UArgs& args = UArgs::none);
123 
124  static UStyle* createStyle();
125 
126  bool isTransparent() const {return transp_style;}
127  UListbox& setTransparent(bool s = true) {transp_style = s; return *this;}
128 
129 
130  UListbox& setSelectedItem(UBox& item);
132 
133  UListbox& setSelectedIndex(int n);
135 
136  UListbox& select(UBox& item) {return setSelectedItem(item);}
138 
139  UListbox& select(int n) {return setSelectedIndex(n);}
141 
142 
143  virtual UListbox& addItem(const UStr& string);
144  virtual UListbox& addItem(UStr& string, bool duplicate);
157  virtual UListbox& addItems(const UStr& strings, const UStr& separ = ",");
158  virtual UListbox& addItems(const UArgs& prefix, const UStr& strings, const UStr& separ = ",");
168  virtual UListbox& addItems(const char* items[]);
169  virtual UListbox& addItems(const std::vector<UStr*>& items, bool duplicate = true);
170  virtual UListbox& addItems(const UArgs& prefix, const char* items[]);
171  virtual UListbox& addItems(const UArgs& prefix, const std::vector<UStr*>& items,
172  bool duplicate = true);
179  protected:
180  bool transp_style;
181  };
182 
183  inline UListbox& ulistbox(UArgs args = UArgs::none) {return *new UListbox(args);}
185 
186 
187  /* ==================================================== ===== ======= */
213  class UCombobox : public UTextfield {
214  public:
215  UCLASS(UCombobox)
216 
217  UCombobox();
218 
219  UCombobox(UListbox&, const UArgs& = UArgs::none);
220  /* creates a new Combo Box widget (see also shortcut function ucombobox()).
221  * arguments:
222  * - 1st arg: the UListbox that is displayed in the menu
223  * - 2nd arg: a standard arglist (callback specs should be added here)
224  */
225 
226  bool isTextMode() const {return text_only;};
227  UCombobox& setTextMode(bool = true);
229 
230  UListbox& list() {return *plist;}
231  class UChoice& choice();
232  UElem& entry() {return *pentry;}
233  UMenu& menu() {return *pmenu;}
235 
236  static UStyle* createStyle();
237 
238  protected:
239  virtual void changedCB(UEvent&); //UElemEvent
240  virtual void actionCB(UEvent&); //UElemEvent
241  virtual void openMenuCB(UInputEvent&);
242  virtual void syncText();
243 
244  private:
245  uptr<UListbox> plist;
246  uptr<UElem> pentry;
247  uptr<class UMenu> pmenu;
248  bool text_only;
249 
250  //UCombobox(const UArgs& = UArgs::none);
251  void constructs(const UArgs&);
252  };
253 
254 
255  inline UCombobox& ucombobox(UListbox& l, UArgs a = UArgs::none) {return *new UCombobox(l,a);}
257 
258 }
259 #endif
260 
Radiobox container: makes buttons (and items, checkboxes, etc) contained in this box exclusive...
Definition: ulistbox.hpp:28
UMenu & menu()
gives access to combobox subcomponents.
Definition: ulistbox.hpp:233
Box container.
Definition: ubox.hpp:64
virtual URadiobox & setSelectedIndex(int n)
selects the Nth item; selects the last selectable item if n = -1.
Definition: ulistbox.cpp:49
Ubit Event class.
Definition: uevent.hpp:30
virtual UBox * getSelectedItem() const
returns the selected item; null if there is no selected item.
Definition: ulistbox.cpp:31
Makes the children of a widget (exclusively) selectable.
Definition: uchoice.hpp:30
virtual int getSelectedIndex() const
returns the index of the selected item; -1 if there is no selected item.
Definition: ulistbox.cpp:35
URadiobox & select(int n)
selects the Nth item (synonym for setSelectedIndex()).
Definition: ulistbox.hpp:53
lightweight general purpose container.
Definition: uelem.hpp:44
List widget: enforces a list layout and makes buttons (and items, checkboxes, etc) contained in this ...
Definition: ulistbox.hpp:117
Textfield widget: single line editor.
Definition: uinteractors.hpp:163
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
URadiobox & select(UBox &item)
selects this item (synonym for setSelectedItem()).
Definition: ulistbox.hpp:50
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
UMenu: pulldown and cascaded menux.
Definition: umenu.hpp:64
UListbox & select(int n)
selects the Nth item (synonym for setSelectedIndex()).
Definition: ulistbox.hpp:139
static UStyle * createStyle()
static function that returns the style of this class (see details!).
Definition: ubox.cpp:50
Definition: uhardfont.hpp:31
const UChoice & choice() const
returns the internal UChoice object that controls the selection.
Definition: ulistbox.hpp:59
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
static const UArgs none
the empty arglist.
Definition: uargs.hpp:45
virtual URadiobox & setSelectedItem(UBox &item)
selects this item.
Combo box gadget.
Definition: ulistbox.hpp:213
UListbox & select(UBox &item)
selects this item (synonym for setSelectedItem()).
Definition: ulistbox.hpp:136
Compiled Object Style.
Definition: ustyle.hpp:44
UChoice & choice()
returns the internal UChoice object that controls the selection.
Definition: ulistbox.hpp:56
URadiobox(const UArgs &args=UArgs::none)
creates a new Radiobox widget (see also shortcut function uradiobox()).
Definition: ulistbox.cpp:25
Ubit String.
Definition: ustr.hpp:72