ubit
uattr.hpp
1 /************************************************************************
2  *
3  * uattr.hpp: Base class for the attributes of the Scene Graph
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 _uattr_hpp_
18 #define _uattr_hpp_ 1
19 #include <ubit/unumber.hpp>
20 namespace ubit {
21 
97  class UAttr: public UNode {
98  public:
99  //UCLASS("#attr", UAttr, null)
100  UCLASS(UAttr)
101 
102  UAttr();
103  UAttr(UConst);
104  virtual ~UAttr();
105 
106  virtual UAttr* toAttr() {return this;}
107  virtual const UAttr* toAttr() const {return this;}
108 
109  virtual int getDisplayType() const {return ATTRIBUTE;}
110  virtual int getNodeType() const {return ATTRIBUTE_NODE;}
111 
112  virtual const UStr& getNodeName() const {return getClassName();}
114 
115  virtual UStr getNodeValue() const;
117 
118  virtual const UStr& getName() const {return getClassName();}
120 
121  virtual bool getValue(UStr& value) const;
127  virtual void setValue(const UStr& value) {}
132  virtual void initNode(UDoc*, UElem* parent) {}
134 
135  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136 
137  virtual UAttr& onChange(UCall&);
142  UAttr& setConst() {UObject::setConst(); return *this;}
143 
144  virtual void update() {}
146 
147  // - - - Impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148 
149  virtual void changed(bool update = true);
155  virtual void putProp(UUpdateContext*, UElem&) {}
157 
158  protected:
159  friend class UBox;
160  };
161 
162 
163  // ==================================================== Ubit Toolkit =========
167  class UAttrList : public UAttr {
168  public:
169  //UCLASS("#attrlist", UAttrList, new UAttrList)
170  UCLASS(UAttrList)
171 
172  void addAttr(UAttr&);
173  void addAttr(const UStr& name, const UStr& value);
174 
175  UStr* getAttr(const UStr&, bool ignore_case = true);
176 
177  template <class AttrClass>
178  AttrClass* getAttr() const {AttrClass* a; _attributes.findClass(a); return a;}
183  template <class AttrClass>
184  AttrClass& obtainAttr() const {AttrClass* a; _attributes.findClass(a); return a ? *a : *new AttrClass;}
189  virtual void update();
190  virtual void putProp(UUpdateContext*, UElem&);
191  };
192 
193 
194  // ==================================================== Ubit Toolkit =========
197  class UTip: public UAttr {
198  public:
199  UCLASS(UTip)
200 
201  UTip(const char* label = null);
208  UTip(const UArgs& arglist);
219  virtual ~UTip();
220 
221  //UStr& value() {return *pvalue;}
222  // returns the string value.
223 
224  virtual UTip& set(const char* label);
225  virtual UTip& set(const UArgs& arglist);
226 
227  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
228 #ifndef NO_DOC
229  virtual void addingTo(UChild&, UElem& parent);
230  virtual void removingFrom(UChild&, UElem& parent);
231  //NB: removingFrom() impose un destructeur
232  uptr<UNode> content;
233 #endif
234  };
235 
236  inline UTip& utip(const char* label = null) {return *new UTip(label);}
238 
239  inline UTip& utip(const UArgs& args) {return *new UTip(args);}
241 
242 
243 
246  class UTitle: public UAttr {
247  public:
248  UCLASS(UTitle)
249 
250  UTitle(const char* = "");
255  UTitle(const UStr&);
260  UStr& value() {return *pstring;}
266  virtual void update();
267 
268  // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
269 #ifndef NO_DOC
270  private:
271  uptr<UStr> pstring;
272  //bool changed;
273 #endif
274  };
275 
276 
277  inline UTitle& utitle(const char*_s) {return *new UTitle(_s);}
278  inline UTitle& utitle(const UStr&_s) {return *new UTitle(_s);}
279 
280 }
281 #endif
Base class for attributes.
Definition: uattr.hpp:97
virtual void removingFrom(UChild &, UElem &parent)
called when this object is removed from a parent (SEE DETAILS IF YOU REDEFINE THIS METHOD)...
Definition: unode.hpp:222
virtual UStr getNodeValue() const
returns the value of this attribute (calls getValue()).
Definition: uattr.cpp:39
Definition: uobject.hpp:282
Box container.
Definition: ubox.hpp:64
Box tool tip.
Definition: uattr.hpp:197
Base class of objects that can be added to the UBIT scene graph (SEE DETAILS!).
Definition: unode.hpp:38
const UStr & getClassName() const
returns getClass().getName().
Definition: uobject.cpp:53
virtual UAttr * toAttr()
dynamic cast: returns this object if it derives from UAttr and null otherwise.
Definition: uattr.hpp:106
Window Title.
Definition: uattr.hpp:246
virtual void initNode(UDoc *, UElem *parent)
called when the document is created.
Definition: uattr.hpp:132
virtual bool getValue(UStr &value) const
gets the value of this attribute.
Definition: uattr.cpp:43
UObject & setConst()
specifies that the content of this object cannot be modified.
Definition: uobject.cpp:161
Attribute list.
Definition: uattr.hpp:167
virtual int getNodeType() const
returns the XML node type.
Definition: uattr.hpp:110
Generic Document.
Definition: udoc.hpp:122
AttrClass * getAttr() const
returns the attribute that derives from AttrClass.
Definition: uattr.hpp:178
virtual void addingTo(UChild &, UElem &parent)
called when this object is added to a parent.
Definition: unode.hpp:219
lightweight general purpose container.
Definition: uelem.hpp:44
Smart Pointer for UObject instances (.
Definition: uobject.hpp:365
base class of callback objects for firing functions or methods.
Definition: ucall.hpp:144
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
AttrClass & obtainAttr() const
returns the attribute that derives from AttrClass.
Definition: uattr.hpp:184
virtual void putProp(UUpdateContext *, UElem &)
[impl] changes corresponding value in the UUpdateContext
Definition: uattr.hpp:155
virtual void changed(bool update=true)
[impl] called when object&#39;s content is changed.
Definition: uattr.cpp:53
virtual const UStr & getNodeName() const
returns the name of this attribute (calls getName()).
Definition: uattr.hpp:112
Definition: uupdatecontext.hpp:32
Definition: uhardfont.hpp:31
virtual UAttr & onChange(UCall &)
adds a callback that is fired when the value of the property is modified.
Definition: uattr.cpp:48
virtual const UStr & getName() const
returns the name of this attribute.
Definition: uattr.hpp:118
virtual void setValue(const UStr &value)
changes the value of this attribute does nothing if not applicable for a given subclass.
Definition: uattr.hpp:127
virtual const UAttr * toAttr() const
dynamic cast: returns this object if it derives from UAttr and null otherwise.
Definition: uattr.hpp:107
virtual void update()
updates parents graphics.
Definition: uattr.hpp:144
Ubit String.
Definition: ustr.hpp:72
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23