ugroup.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  ugroup.hpp : Logical "grouping" container.
00004  *  Ubit Project
00005  *  Author: Eric Lecolinet
00006  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00007  *  (C) 1999-2006 EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00008  *
00009  * ***********************************************************************
00010  * COPYRIGHT NOTICE : 
00011  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00012  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00013  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00014  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00015  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00016  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00017  * ***********************************************************************
00018  * ==================================================== [(c)Elc] ======= *
00019  * ==================================================== ======== ======= */
00020 
00021 #ifndef _ugroup_hpp_
00022 #define _ugroup_hpp_
00023 //pragma ident  "@(#)ugroup.hpp ubit:05.05.00"
00024 #include <ubit/ucontrol.hpp>
00025 #include <ubit/uargs.hpp>
00026 #include <ubit/ustr.hpp>
00027 namespace ubit {
00028 
00029 /* ==================================================== ======== ======= */
00047 class UGroup: public UControl {
00048 public:
00049   UBIT_ELEMENT_CLASS(UGroup, UControl)
00057   static UStyle* createStyle();
00062   const UStyle& getStyle(UContext*) const;
00067   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00068 
00069   UGroup(const UArgs& = UArgs::none);
00071 
00072   friend UGroup& ugroup(const UArgs& a = UArgs::none) {return *new UGroup(a);}
00077   virtual ~UGroup();
00083   virtual UGroup* groupCast() {return this;}
00085   
00086   virtual unsigned short getNodeType() const {return ELEMENT_NODE;}
00088   
00089   virtual const UStr* getNodeName() const;
00091     
00092   virtual const UStr* getNodeValue() const {return null;}
00093 
00094   //virtual const UStr* getName() const; // ambigu avec subclasses
00095 
00096   virtual void initNode(UDoc* context) {}
00098 
00099   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00100   // parents: see the UBrick superclass.
00101   
00102   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00103   // children
00104 
00105   virtual bool isParentOf(const UBrick& possible_child) const;
00107     
00108   virtual UGroup& addlist(const UArgs& child_list);
00117   virtual UChildIter add(const UChild&);
00123   virtual UChildIter add(const UChild&, int position);
00124   /* inserts an object (deriving from UBrick) before this position in the child list.
00125     * the position is an integer (0 is the position of the first child).
00126     * Returns an iterator that points to the inserted object.
00127     * Note that the same object can be added several times to the same parent.
00128     */
00129   
00130   virtual UChildIter add(const UChild&, UChildIter position);
00131   /* inserts an object (deriving from UBrick) before this position in the child list.
00132     * the position is a Child Iterator (@see: cbegin()).
00133     * Returns an iterator that points to the inserted object.
00134     * Note that the same object can be added several times to the same parent.
00135     */
00136   
00137   virtual UChildIter remove(UBrick&, bool auto_delete = true);
00150   virtual UChildIter removeNC(UBrick&, bool auto_delete = true);
00156   virtual UChildIter remove(int position, bool auto_delete = true);
00162   virtual UChildIter remove(UChildIter position, bool auto_delete = true);
00167   virtual void removeAll(bool auto_delete = true);
00172   UChildIter cbegin() const {return children().begin();}
00184   UChildIter cend() const {return children().end();}
00186   
00187   UChildReverseIter crbegin() const {return children().rbegin();}
00189   UChildReverseIter crend() const {return children().rend();}
00191   
00192   virtual UChildren& children() const {return _children;}
00197   UChildIter child(int position) const {return children().at(position);}
00199 
00200   UBrick* getChild(int position) const;
00202       
00203   virtual UStr retrieveText(bool recursive = true) const;
00204   virtual void retrieveText(UStr& to, bool recursive = true) const;
00210   // - - - - attributes - - - - - - - - - - -- - - - - - - - - - - - - - - -
00211   
00212   virtual void addAttr(const UChild& attribute);
00219   virtual void removeAttr(UBrick& attribute, bool auto_delete = true);
00224   virtual void removeAttrNC(UBrick& attr, bool auto_delete = true);
00225     
00226   virtual void removeAllAttrs(bool auto_del = true);
00231   UChildIter abegin() const {return attributes().begin();}
00232   
00233   UChildIter aend() const {return attributes().end();}
00234   
00235   virtual UChildren& attributes() const {return _attributes;}
00236   // doc inherited from UBrick.
00237   
00238   virtual const UStr* getAttr(const UStr& name, bool ignore_case = true) const;
00240   
00241   virtual const UProp* getAttrNode(const UStr& name, bool ignore_case = true) const;
00243 
00244   virtual UProp* getAttrNode(const UStr& name, bool ignore_case = true);
00246 
00247   virtual UProp* setAttrNode(UProp*);
00249 
00250   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00251   
00252   virtual void repaint() {update(UUpdate::paint);}
00258   virtual void update() {update(UUpdate::layoutAndPaint);}
00264   virtual void update(const UUpdate&);
00270   UGroup& autoUpdate(bool state) {UBrick::autoUpdate(state); return *this;}
00272   
00273   virtual void show(bool = true);
00279   void hide() {show(false);}
00281   
00282   virtual void close(int status = 0);
00290   virtual void closeWin(int status = 0);
00295   static void closeWinCB(UEvent&, int status);
00296   
00297   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00298   // implementation
00299   
00300   virtual const UStr* getTextSeparator() const;
00302     
00303   enum {REMOVE_FROM_PARENTS=-1};
00304 
00305   virtual UChildIter addImpl(UChildren&, const UChild&, UChildIter, 
00306                              bool update, bool* should_update);
00308 
00309   virtual UChildIter removeImpl(UChildren&, UChildIter, int rem_mode,
00310                                 bool update, bool* should_update);
00312       
00313   virtual bool fire(UEvent&, const UOn&) const;
00315 
00316   virtual int getRelatedViews(std::vector<UView*>&) const;
00318 
00319   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00320 
00321 #ifndef NO_DOC 
00322   friend class UBrick;
00323   friend class UWin;
00324 
00325   bool isBrowsingGroup() {return (cmodes & UMode::CAN_BROWSE_CHILDREN) != 0;}
00326   virtual UGroup* getBrowsingGroup() {return (cmodes & UMode::CAN_BROWSE_CHILDREN) ? this : null;}
00328 
00329   virtual void highlight(bool state) {};
00330   virtual void initView(UChild* selflink, UView *ancestor_view);
00331   virtual void initChildViews(UGroup*, UChild *childlink);
00332   virtual void updateView(UEvent&, UView*, const UUpdate&);
00334   
00335 protected:
00336   mutable UChildren _children;
00337   virtual void  destructs();
00338   virtual void  deleteRelatedViews(UView* parview, UChild*);
00339   virtual void  deleteRelatedViews2(UView* parview);
00340   virtual int   getTextLength(bool recursive) const;
00341   virtual char* getTextData(char *ptr, bool recursive) const;
00342 #endif
00343 };
00344 
00345 }
00346 #endif
00347 /* ==================================================== [TheEnd] ======= */
00348 /* ==================================================== [-c-Elc] ======= */

Generated on Mon Jan 29 00:20:39 2007 for Ubit by  doxygen 1.4.7