ubit
unode.hpp
1 /************************************************************************
2  *
3  * unode.hpp: base class for objects that can be added to 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 _unode_hpp_
18 #define _unode_hpp_ 1
19 #include <ubit/udefs.hpp>
20 #include <ubit/uobject.hpp>
21 #include <ubit/uchild.hpp>
22 #include <ubit/uparent.hpp>
23 namespace ubit {
24 
38 class UNode : public UObject {
39  UNode(const UNode&);
41 
42  UNode& operator=(const UNode&);
44 
45 public:
47  //UCLASS("unode", UNode, null)
48  UCLASS(UNode)
49 
50 
51  enum NodeType {
52  ELEMENT_NODE = 1,
53  ATTRIBUTE_NODE = 2,
54  TEXT_NODE = 3,
55  CDATA_SECTION_NODE = 4,
56  ENTITY_REFERENCE_NODE = 5,
57  ENTITY_NODE = 6,
58  PROCESSING_INSTRUCTION_NODE = 7,
59  COMMENT_NODE = 8,
60  DOCUMENT_NODE = 9,
61  DOCUMENT_TYPE_NODE = 10,
62  DOCUMENT_FRAGMENT_NODE = 11,
63  NOTATION_NODE = 12
64  };
65 
67  enum DisplayType {
68  WINLIST=-1, UNDISPLAYBLE=0, ATTRIBUTE, DATA, INLINE, BLOCK, BORDER, HARDWIN, SOFTWIN
69  };
70 
71 protected:
72  explicit UNode();
74 
75  virtual ~UNode() {destructs();}
77 
78 public:
79  virtual int getNodeType() const {return 0;}
81 
82  virtual const UStr& getNodeName() const;
84 
85  virtual UStr getNodeValue() const;
87 
88  virtual int getDisplayType() const {return UNDISPLAYBLE;}
89  virtual int isDisplayable() const {return getDisplayType() > 0;}
90 
91  virtual UNode* toNode() {return this;}
92  virtual const UNode* toNode() const {return this;}
93 
94  // - - - parents - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 
96  virtual bool isChildOf(const UElem& parent, bool indirect = true) const;
101  UParentIter pbegin() const {return parents().begin();}
113  UParentIter pend() const {return parents().end();}
115 
116  virtual UParents& parents() const {return _parents;}
118 
119  virtual UElem* getParent(int pos = 0) const;
128  virtual bool hasSceneGraphParent() const; // redifined from UObject
134  template <class CC>
135  CC* findParent() const {
136  for (UParentIter p = pbegin(); p != pend(); ++p) {
137  if (dynamic_cast<CC*>(*p)) {return (CC*)*p;}
138  else return ((UNode*)(*p))->findParent<CC>();
139  }
140  return null;
141  }
143 
144  virtual int getBoxParents(std::vector<UBox*>& parvect) const;
146 
147  virtual UBox* getParent(const UView*) const;
152  virtual UView* getParentView(const UView*) const;
157  virtual UBox* getParent(const UInputEvent&) const;
158 
159 
160  virtual UView* getParentView(const UInputEvent&) const;
161  /* returns the direct or *indirect* UBox parent (resp. parent's view) that contains this event.
162  * intermediate UElem parents are ignored (ie. traversed) by this function.
163  */
164 
165  virtual void removeFromParents(bool update_parents = true);
173  // - - - misc. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
174 
175  friend UChild operator/(const UCond&, UNode&);
193  friend UChild operator/(const UCond&, UNode*);
195 
196  virtual bool fire(UEvent&) const;
198 
199  virtual UNode& removeAllAttrs(bool autodel = true);
201 
202  virtual void update() {}
204 
205  bool isAutoUpdate() const {return !omodes.DONT_AUTO_UPDATE;}
207 
208  UNode& setAutoUpdate(bool state = true);
218 protected:
219  virtual void addingTo(UChild&, UElem& parent) {}
221 
222  virtual void removingFrom(UChild&, UElem& parent) {}
232  virtual void destructs();
234 
235  // - - - Impl - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
236 #ifndef NO_DOC
237 public:
238  void fireParents(const UCond& c, UNode* n) const {_parents.fireParents(c,n);}
239 
240  void updateAutoParents(const UUpdate& m) {_parents.updateAutoParents(m);}
241  virtual void addChangeCall(UCall&);
242  virtual UElem* getSubGroup() const {return null;}
243 
244  void _addAttr(const UChild& attribute);
246 
247  UChildIter _abegin() const {return _attributes.begin();}
249 
250  UChildIter _aend() const {return _attributes.end();}
252 
253 protected:
254  friend class UChild;
255  friend class UArgs;
256  friend class UParents;
257  friend class UElem;
258  mutable UParents _parents;
259  mutable UChildren _attributes; // attributes (including callbacks)
260 #endif
261 };
262 
263 }
264 #endif
virtual void update()
updates object graphics.
Definition: unode.hpp:202
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
Parent list.
Definition: uparent.hpp:57
Definition: uparent.hpp:39
Box container.
Definition: ubox.hpp:64
Base class of objects that can be added to the UBIT scene graph (SEE DETAILS!).
Definition: unode.hpp:38
Ubit Event class.
Definition: uevent.hpp:30
CC * findParent() const
< this object has at least one parent in the scene graph.
Definition: unode.hpp:135
UNode & setAutoUpdate(bool state=true)
changes the update policy of this object when its is modified.
Definition: unode.cpp:40
virtual bool fire(UEvent &) const
fires callback functions that match this event.
Definition: unode.cpp:270
virtual UParents & parents() const
returns the list of direct parents (
Definition: unode.hpp:116
Base class for Ubit conditions.
Definition: ucond.hpp:29
DisplayType
Ubit display types.
Definition: unode.hpp:67
UNode()
constructor, can anly be called by subclasses because UNode is abstract.
Definition: unode.cpp:34
virtual UElem * getParent(int pos=0) const
returns the Nth direct parent.
virtual int getBoxParents(std::vector< UBox *> &parvect) const
retrieves direct and indirect parents that are boxes.
Definition: unode.cpp:151
specifies how to update UElem, UBox, UWin objects and subclasses.
Definition: uupdate.hpp:25
NodeType
redefines Class() and getClass() methods (
Definition: unode.hpp:51
UChildIter _aend() const
[impl] to be removed @.
Definition: unode.hpp:250
virtual UNode * toNode()
dynamic cast: returns this object if it derives from UNode and null otherwise.
Definition: unode.hpp:91
void fireParents(const UCond &c, UNode *n)
fire parents callbacks that match this event.
Definition: unode.cpp:386
virtual const UStr & getNodeName() const
return the XML node name.
Definition: unode.cpp:36
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
Child (or attribute) list.
Definition: uchild.hpp:79
virtual ~UNode()
destructor, note that children are recursively destroyed except if pointed elsewhere ( ...
Definition: unode.hpp:75
base class of callback objects for firing functions or methods.
Definition: ucall.hpp:144
virtual UView * getParentView(const UView *) const
returns the direct or indirect parent&#39;s view that contains this view.
Argument list (for passing arguments to constructor or add functions).
Definition: uargs.hpp:43
friend UChild operator/(const UCond &, UNode &)
conditional expression for callback functions and conditionnal objects.
void _addAttr(const UChild &attribute)
[impl] to be removed @.
Definition: unode.cpp:83
virtual void destructs()
unlinks the object from its parents and destroys its children.
Definition: unode.cpp:56
Box View.
Definition: uview.hpp:65
UParentIter pend() const
returns an iterator to the end of the parent list (
Definition: unode.hpp:113
Definition: uhardfont.hpp:31
Base class for UMouseEvent and UKeyEvent Note that this class inherits from class UModifier that defi...
Definition: uevent.hpp:75
virtual int getNodeType() const
returns the XML node type.
Definition: unode.hpp:79
void updateAutoParents(const UUpdate &)
removes the first element that is pointing to this child.
Definition: unode.cpp:378
UParentIter pbegin() const
returns an iterator to the beginning of the list of direct parents.
Definition: unode.hpp:101
virtual bool isChildOf(const UElem &parent, bool indirect=true) const
returns true if this object a child of &#39;parent&#39;.
Definition: unode.cpp:249
virtual void removeFromParents(bool update_parents=true)
[impl] removes this object from all direct parents.
Definition: unode.cpp:202
UChildIter _abegin() const
[impl] to be removed @.
Definition: unode.hpp:247
bool isAutoUpdate() const
return current update policy: see setAutoUpdate().
Definition: unode.hpp:205
virtual UNode & removeAllAttrs(bool autodel=true)
removes all attributes (if any, redefined by subclasses).
Definition: unode.cpp:101
virtual UStr getNodeValue() const
return the XML node value.
Definition: unode.cpp:38
virtual const UNode * toNode() const
dynamic cast: returns this object if it derives from UNode and null otherwise.
Definition: unode.hpp:92
Ubit String.
Definition: ustr.hpp:72
Base class of most Ubit objects (SEE DETAILS!).
Definition: uobject.hpp:113
[impl] Internal implementation of a child node.
Definition: uchild.hpp:23