ubit
uchoice.hpp
1 /************************************************************************
2  *
3  * uchoice.hpp: item chooser in a list
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 _uchoice_hpp_
18 #define _uchoice_hpp_ 1
19 #include <ubit/uattr.hpp>
20 namespace ubit {
21 
30  class UChoice : public UAttr {
31  public:
32  UCLASS(UChoice)
33 
34  UChoice();
36 
37  virtual ~UChoice();
38 
39  virtual void clearSelection();
41 
42  virtual UBox* getSelectedItem() const;
44 
45  virtual UBox* setSelectedItem(UBox&);
47 
48  virtual UBox* setSelectedItem(UBox*);
50 
51  virtual int getSelectedIndex() const;
58  virtual UBox* setSelectedIndex(int N);
66  virtual UBox* getSelectableItem(int N) const;
73  virtual UBox* getSelectableItem(const UStr& s, bool ignore_case = true) const;
80  struct IsSelectable {
81  virtual bool operator()(const UBox*) const;
82  virtual ~IsSelectable() {}
83  };
84 
85  virtual void setSelectionRule(IsSelectable&);
92  virtual void update();
93 
94  // - - - impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 #ifndef NO_DOC
96  virtual void putProp(UUpdateContext*, UElem&);
97  virtual void addingTo(UChild&, UElem& parent);
98  virtual void removingFrom(UChild&, UElem& parent);
99  // NB: removingFrom() requires a destructor to be defined
100 
101  /*
102  enum {
103  NO_SELECTION, SINGLE_SELECTION,
104  SINGLE_INTERVAL_SELECTION, MULTIPLE_INTERVAL_SELECTION
105  };
106 
107  virtual int getSelectionMode() const {return sel_mode;}
108  virtual void setSelectionMode(int m) {sel_mode = v;}
109  **< gets/sets the current selection mode.
110  * no effect with the current version: always in SINGLE_SELECTION mode.
111 
112  enum {SELECT_ON_DISARM = 1<<0, SELECT_ON_ARM = 1<<1, SELECT_ON_DRAG = 1<<2};
113 
114  virtual int getSelectionStyle() const {return sel_style;}
115 
116  virtual void setSelectionStyle(int);{sel_style = v;}
117  **< gets/sets the current selection style.
118  * the selection style is an ORed combination of
119  * SELECT_ON_DISARM, SELECT_ON_ARM, SELECT_ON_DRAG
120  */
121  protected:
122  uptr<UCall> callbacks;
123  uptr<UBox> container;
124  uptr<UElem> last_browsing_group;
125  uptr<UElem> sel_items;
126  IsSelectable*is_selectable;
127  //short sel_mode, sel_style;
128  virtual void mouseCB(UInputEvent&);
129  virtual void actionCB(UInputEvent*);
130  virtual void changeCB(UInputEvent*);
131  virtual void changed(bool update = true);
132  virtual UBox* setSelectedItemImpl(UBox* item, UInputEvent*);
133  virtual UBox* getSelectedItemImpl() const;
134 #endif
135  };
136 
137  inline UChoice& uchoice() {return *new UChoice;}
139 
140  /* ==================================================== [Elc] ======= */
153  class URadioSelect : public UAttr {
154  public:
155  UCLASS(URadioSelect)
156 
157  URadioSelect();
159 
160  URadioSelect(UInt& index);
162 
163  virtual ~URadioSelect();
164 
165  virtual void setCanUnselectMode(bool);
166  virtual bool isCanUnselectMode() const;
168 
169  virtual void clearSelection();
171 
172  virtual UElem* getSelectedItem() const;
174 
175  virtual void setSelectedItem(UElem&);
177 
178  UInt& index() const {return *pindex;}
179  virtual int getSelectedIndex() const;
181 
182  virtual void setSelectedIndex(int n);
183  virtual void setSelectedIndex(const UInt& n);
185 
186  virtual void update();
187 
188  // - - impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
189 #ifndef NO_DOC
190  virtual void changed(bool update = true);
191  virtual void changed(UElem* target);
199  virtual void putProp(UUpdateContext*, UElem&);
200  virtual void addingTo(UChild&, UElem& parent);
201  virtual void removingFrom(UChild&, UElem& parent);
202  // NB: removingFrom() requires a destructor to be defined
203 
204  protected:
205  bool can_unselect_mode;
206  uptr<UInt> pindex;
207  uptr<UCall> pselect_callback;
208  void itemChanged(UInputEvent&);
209  void setIndexImpl();
210  void _selectItem(UElem*);
211 #endif
212  };
213 
214  inline URadioSelect& uradioSelect() {return *new URadioSelect();}
216 
217 }
218 #endif
Base class for attributes.
Definition: uattr.hpp:97
virtual void update()
updates parents graphics.
Definition: uchoice.cpp:83
Box container.
Definition: ubox.hpp:64
virtual void removingFrom(UChild &, UElem &parent)
called when this object is removed from a parent (SEE DETAILS IF YOU REDEFINE THIS METHOD)...
Definition: uchoice.cpp:72
UChoice()
create a new UChoice object;
Definition: uchoice.cpp:36
virtual UBox * setSelectedItem(UBox &)
selects and returns this item if it is in the list, returns null otherwise.
Makes the children of a widget (exclusively) selectable.
Definition: uchoice.hpp:30
virtual void clearSelection()
deselects the selected object.
Definition: uchoice.cpp:206
virtual int getSelectedIndex() const
returns the index of the selection; returns -1 if there is no selection.
Definition: uchoice.cpp:222
virtual void setSelectionRule(IsSelectable &)
define which objects can be selected in the list.
Definition: uchoice.cpp:34
lightweight general purpose container.
Definition: uelem.hpp:44
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
virtual UBox * getSelectableItem(int N) const
returns the Nth selectable object.
virtual UBox * getSelectedItem() const
returns the current selection; returns null if there is no selection.
Definition: uchoice.cpp:212
virtual void putProp(UUpdateContext *, UElem &)
[impl] changes corresponding value in the UUpdateContext
Definition: uchoice.cpp:87
Active Integer.
Definition: unumber.hpp:48
Definition: uupdatecontext.hpp:32
Definition: uhardfont.hpp:31
virtual void addingTo(UChild &, UElem &parent)
called when this object is added to a parent.
Definition: uchoice.cpp:52
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
virtual void changed(bool update=true)
[impl] called when object&#39;s content is changed.
Definition: uchoice.cpp:265
Makes widgets (exclusively) selectable.
Definition: uchoice.hpp:153
virtual UBox * setSelectedIndex(int N)
selects the Nth selectable object in the list.
Definition: uchoice.cpp:202
Ubit String.
Definition: ustr.hpp:72
Definition: uchoice.hpp:80
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23