ubit
uinteractors.hpp
1 /************************************************************************
2  *
3  * uinteractors.hpp: most common interactors
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 _uinteractors_hpp_
18 #define _uinteractors_hpp_ 1
19 #include <ubit/ustr.hpp>
20 #include <ubit/uedit.hpp>
21 #include <ubit/ubox.hpp>
22 namespace ubit {
23 
24  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27  class USepar: public UBox {
28  public:
29  UCLASS(USepar)
30  static UStyle* createStyle();
31 
32  USepar();
36  };
37 
38 
39  inline USepar& usepar() {return *new USepar();}
41 
42 
43  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70  class ULabel: public UBox {
71  public:
72  UCLASS(ULabel)
73  static UStyle* createStyle();
74 
75  ULabel(UArgs arglist = UArgs::none) : UBox(arglist) {}
77 
78  ULabel(int nbchars, UArgs arglist = UArgs::none);
80  };
81 
82 
83  inline ULabel& ulabel(UArgs arglist = UArgs::none)
84  {return *new ULabel(arglist);}
86 
87  inline ULabel& ulabel(int nbchars, UArgs arglist = UArgs::none)
88  {return *new ULabel(nbchars, arglist);}
90 
91 
92  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
163  class UTextfield: public UBox {
164  public:
165  UCLASS(UTextfield)
166  static UStyle* createStyle();
167 
168  UTextfield(UArgs arglist = UArgs::none);
170 
171  UTextfield(int nbchars, UArgs arglist = UArgs::none);
176  virtual bool isEditable() const;
177 
178  virtual UTextfield& setEditable(bool state = true);
179 
180  UEdit& edit();
182 
183  };
184 
185  inline UTextfield& utextfield(UArgs arglist = UArgs::none)
186  {return *new UTextfield(arglist);}
188 
189  inline UTextfield& utextfield(int nbchars, UArgs arglist = UArgs::none)
190  {return *new UTextfield(nbchars, arglist);}
192 
193 
194  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199  class UTextarea: public UTextfield {
200  public:
201  UCLASS(UTextarea)
202  static UStyle* createStyle();
203 
204  UTextarea(UArgs arglist = UArgs::none) : UTextfield(arglist) {}
206  };
207 
208  inline UTextarea& utextarea(UArgs arglist = UArgs::none)
209  {return *new UTextarea(arglist);}
211 
212 
213  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
266  class UButton: public UBox {
267  public:
268  UCLASS(UButton)
269  static UStyle* createStyle();
270  enum ButtonType {AUTO, NORMAL, MENU, BAR, TAB};
271 
272  UButton(UArgs arglist = UArgs::none);
274 
275  UButton(int button_style, UArgs arglist = UArgs::none);
277 
278  private:
279  friend class UButtonStyle;
280  unsigned char button_type;
281  };
282 
283  inline UButton& ubutton(UArgs arglist = UArgs::none) {return *new UButton(arglist);}
285 
286  UButton& uflatbutton(UArgs arglist = UArgs::none);
288 
289  UButton& utabbutton(UArgs arglist = UArgs::none);
291 
292 
293  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
303  class UItem: public UBox {
304  public:
305  UCLASS(UItem)
306  static UStyle* createStyle();
307 
310  };
311 
312  inline UItem& uitem(UArgs a = UArgs::none) {return *new UItem(a);}
314 
315 
316  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
320  class URadiobutton: public UButton {
321  public:
322  UCLASS(URadiobutton)
323  static UStyle* createStyle();
324 
325  URadiobutton(UArgs arglist = UArgs::none);
327  };
328 
329  inline URadiobutton& uradiobutton(UArgs a = UArgs::none) {return *new URadiobutton(a);}
331 
332  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
346  class UCheckbox: public UButton {
347  public:
348  UCLASS(UCheckbox)
349  static UStyle* createStyle();
350 
351  UCheckbox(UArgs arglist = UArgs::none);
353 
354  UCheckbox& select(bool state = true) {return setSelected(state);}
356 
357  virtual UCheckbox& setSelected(bool state = true, bool call_callbacks = true)
358  {UElem::setSelected(state, call_callbacks); return *this;}
363  bool isSelected() const {return emodes.IS_SELECTED;}
364  };
365 
366  inline UCheckbox& ucheckbox(UArgs arglist = UArgs::none) {return *new UCheckbox(arglist);}
368 
369 
370  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
375  class ULinkbutton: public UButton {
376  public:
377  UCLASS(ULinkbutton)
378  static UStyle* createStyle();
379 
381 
382  virtual UStr getHRef() const;// {UStr val; getAttrValue(val,"href"); return val;} // pas tres efficace!
383  };
384 
385  inline ULinkbutton& ulinkbutton(UArgs a = UArgs::none) {return *new ULinkbutton(a);}
387 
388 
389  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
397  class USpinbox : public UBox {
398  public:
399  UCLASS(USpinbox)
400  static UStyle* createStyle();
401 
404 
405  USpinbox(UInt& value, UArgs = UArgs::none);
407 
408  virtual int getValue() const {return *pvalue;}
410 
411  virtual void setValue(int);
416  UInt& value() {return *pvalue;}
422  int getIncrement() const {return increment;}
424 
425  virtual void setIncrement(int);
427 
428  UStr& str() {return *pstr;}
433  protected:
434  virtual void constructs(const UArgs& a);
435  virtual void updateValue(int dir);
436  virtual void changed();
437 
438  private:
439  uptr<UInt> pvalue;
440  uptr<UStr> pstr;
441  uptr<UTextfield> ptextfield;
442  int increment;
443  };
444 
445  inline USpinbox& uspinbox(UArgs a = UArgs::none) {return *new USpinbox(a);}
447 
448 }
449 #endif
450 
ULabel(UArgs arglist=UArgs::none)
create a new label.
Definition: uinteractors.hpp:75
UStr & str()
return internal string model of the text.
Definition: uinteractors.hpp:428
UInt & value()
returns the internal value model.
Definition: uinteractors.hpp:416
Box container.
Definition: ubox.hpp:64
Link Button gadget.
Definition: uinteractors.hpp:375
Button widget.
Definition: uinteractors.hpp:266
Textarea widget: multiple line editor.
Definition: uinteractors.hpp:199
Radio Button gadget.
Definition: uinteractors.hpp:320
Item Button widget (a kind of button that is used in UListbox(es)).
Definition: uinteractors.hpp:303
Text editing and caret controller.
Definition: uedit.hpp:30
Separator gadget: horizontal or vertical separator for menus and boxes.
Definition: uinteractors.hpp:27
Definition: uinteractors.cpp:165
Spinbox gadget.
Definition: uinteractors.hpp:397
UCheckbox & select(bool state=true)
shortcut for setSelected(bool state = true).
Definition: uinteractors.hpp:354
Textfield widget: single line editor.
Definition: uinteractors.hpp:163
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
virtual UElem & setSelected(bool state=true, bool call_callbacks=true)
specifies whether this object is selected.
Definition: uelem.cpp:896
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
Active Integer.
Definition: unumber.hpp:48
Definition: uhardfont.hpp:31
static const UArgs none
the empty arglist.
Definition: uargs.hpp:45
UTextarea(UArgs arglist=UArgs::none)
creates a new text area (
Definition: uinteractors.hpp:204
int getIncrement() const
returns the increment value.
Definition: uinteractors.hpp:422
virtual int getValue() const
returns the current value.
Definition: uinteractors.hpp:408
Checkbox gadget.
Definition: uinteractors.hpp:346
Label widget: can display any combination of text, images, and other widgets.
Definition: uinteractors.hpp:70
USepar()
create a new separator.
Definition: uinteractors.cpp:62
virtual UCheckbox & setSelected(bool state=true, bool call_callbacks=true)
specifies whether this object is selected.
Definition: uinteractors.hpp:357
Compiled Object Style.
Definition: ustyle.hpp:44
Ubit String.
Definition: ustr.hpp:72