uprop.hpp

00001 /* ==================================================== ======== ======= *
00002  *
00003  *  uprop.hpp: objects' properties
00004  *  Ubit Project
00005  *  Part of the Ubit Toolkit: A Brick Construction Game Model for Creating GUIs
00006  *  (C) 1999-2006 EricLecolinet / ENST Paris / http://www.enst.fr/~elc/ubit
00007  *
00008  * ***********************************************************************
00009  * COPYRIGHT NOTICE : 
00010  * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY AND WITHOUT EVEN THE 
00011  * IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 
00012  * YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU 
00013  * GENERAL PUBLIC LICENSE AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION; 
00014  * EITHER VERSION 2 OF THE LICENSE, OR (AT YOUR OPTION) ANY LATER VERSION.
00015  * SEE FILES 'COPYRIGHT' AND 'COPYING' FOR MORE DETAILS.
00016  * ***********************************************************************
00017  * ==================================================== [(c)Elc] ======= *
00018  * ==================================================== ======== ======= */
00019 
00020 #ifndef _uprop_hpp_
00021 #define _uprop_hpp_
00022 //pragma ident  "@(#)uprop.hpp  ubit:05.05.00"
00023 #include <ubit/unumber.hpp>
00024 namespace ubit {
00025 
00026 /* ==================================================== ===== ======= */
00102 class UProp: public UBrick {
00103 public:
00104   UBIT_ATTR_CLASS(UProp,UBrick)  
00105   
00106   UProp(UMask b_modes = 0);
00107   virtual ~UProp();
00108 
00109   virtual class UProp* propCast() {return this;}
00111 
00112   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00113   
00114   virtual unsigned short getNodeType() const {return ATTRIBUTE_NODE;}
00116 
00117   virtual const UStr* getNodeName() const {return &getClassName();}
00119 
00120   virtual const UStr* getNodeValue() const {return getValue();}
00122 
00123   virtual const UStr* getName() const {return &getClassName();}
00125   
00126   virtual const UStr* getValue() const;
00128     
00129   virtual void setValue(const UStr&);
00130 
00131   virtual void initNode(UDoc*, UGroup* parent) {}
00133 
00134   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00135 
00136   virtual UProp& onChange(UCall&);
00141   virtual void changed(bool update = true);
00147   virtual void update() {}
00149   
00150   virtual void putProp(UContext*, UControl*) {}
00152 
00153 protected:
00154   friend class UBox;
00155   uptr<UStr> pvalue;
00156 };
00157 
00158 /* ==================================================== [(c)Elc] ======= */
00159 /* ==================================================== ======== ======= */
00164 class UProps : public UProp {
00165 public:
00166   UBIT_ATTR_CLASS(UProps, UProp)
00167 
00168   void addProp(UProp&);
00169   void addProp(const UStr& name, const UStr& value);
00170   
00171   UStr* getProp(const UStr&, bool ignore_case = true);
00172   
00173   virtual void update();
00174   virtual void putProp(UContext*, UControl*);  
00175 };
00176 
00177 /* ==================================================== ===== ======= */
00178 /* Tool Tip.
00179 */
00180 class UTip: public UProp {
00181 public:
00182   UBIT_ATTR_CLASS(UTip, UProp)
00183 
00184   UTip(const char* label = null);
00191   UTip(const UArgs& arglist);
00202   friend UTip& utip(const char* label = null) {return *new UTip(label);}
00203   friend UTip& utip(const UArgs& arglist) {return *new UTip(arglist);}
00204 
00205   virtual ~UTip();
00206     
00207   //UStr& value() {return *pvalue;}
00208   /* returns the string value.
00209     * - example: UTip t; t.value() = "Do it"; UStr s = t.value(); 
00210     * - value() can be shared, but can't be deleted!
00211     */
00212   
00213   virtual UTip& set(const char* label);
00214   virtual UTip& set(const UArgs& arglist);
00215 
00216   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00217 #ifndef NO_DOC
00218   virtual void addingTo(UChild* self, UGroup *parent);
00219   virtual void removingFrom(UChild* self, UGroup *parent);
00220   //NB: removingFrom() impose un destructeur
00221   uptr<UBrick> content;
00222 #endif
00223 };
00224 
00225 /* ==================================================== [Elc] ======= */
00226 /* ==================================================== ===== ======= */
00238 class UBackground : public UProp {
00239 public:
00240   UBIT_ATTR_CLASS(UBackground, UProp)
00241 
00242   static UBackground none, inherit,
00243   metal, velin, white, black, grey, lightgrey, darkgrey, navy, lightblue, blue, 
00244   red, green, yellow, orange, wheat, teal;
00246   
00247   ~UBackground();
00248 
00249   UBackground();
00251 
00252   UBackground(const UBackground&);
00254  
00255   UBackground(UColor&);
00257     
00258   UBackground(UIma&);  
00260     
00261   friend UBackground& ubackground(UBackground& b) {return *new UBackground(b);}
00262   friend UBackground& ubackground(UColor& c) {return *new UBackground(c);}
00263   friend UBackground& ubackground(UIma& i) {return *new UBackground(i);}
00265   
00266   UBackground& operator=(const UBackground&);
00267   
00268   bool operator==(const UBackground&);
00269     
00270   virtual UBackground& setColor(UColor&);
00272     
00273   virtual UBackground& setIma(UIma&, bool tiling = true);
00275   virtual UBackground& setTiling(bool);
00277 
00278   operator UColor&();
00280   
00281   const UColor* getColor() const;
00282   UColor* getColor();
00284   
00285   const UIma* getIma() const;
00286   UIma* getIma();
00288 
00289   bool isTiled() const;
00291 
00292   virtual void update();
00293   virtual void putProp(UContext*, UControl*);
00294 
00295   friend UBackground& ubgcolor(int r, int g, int b);
00297 
00298   void set(UColor& c) {setColor(c);}
00300 
00301   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00302 #ifndef NO_DOC
00303   UBackground(UColor&, UMask);
00304   UBackground(UIma&, UMask);
00305 protected:
00306   uptr<UBrick> pval;
00307   bool tiling;
00308 #endif
00309 };
00310 
00311 /* ==================================================== ===== ======= */
00316 class UAlpha : public UProp {
00317 public:
00318   UBIT_ATTR_CLASS(UAlpha, UProp)
00319 
00320   UAlpha(float = 1.0);
00327   friend UAlpha& ualpha(float v = 1.0) {return *new UAlpha(v);}
00329   
00330   operator float() const {return val;}
00332   
00333   UAlpha& operator=(float v)         {return set(v);}
00334   UAlpha& operator=(const UFloat& v) {return set(v);}
00335   UAlpha& operator=(const UAlpha& v) {return set(v.val);}
00336   virtual UAlpha& set(float);  
00338   
00339   bool operator==(float v)         const {return val == v;}  
00340   bool operator==(const UFloat& v) const {return val == v;}  
00341   bool operator==(const UAlpha& v) const {return val == v.val;}
00342   
00343   virtual void update();
00344   virtual void putProp(UContext*, UControl*);
00345   
00346 private:
00347   float val;
00348 };
00349 
00350 /* ==================================================== [Elc] ======= */
00351 /* ==================================================== ===== ======= */
00355 class UFlagdef : public UProp {
00356 public:
00357   UBIT_ATTR_CLASS(UFlagdef, UProp)
00358 
00359   UFlagdef();
00360   UFlagdef(const UFlag&);
00362 
00363   friend UFlagdef& uflagdef();
00364   friend UFlagdef& uflagdef(const UFlag& f);
00366   
00367   UFlagdef& operator=(const UFlag& f) {return set(f);} 
00368   virtual UFlagdef& set(const UFlag&);
00369   virtual UFlagdef& clear();
00370   
00371   const UFlag* getFlag() const {return flag;}
00372   
00373   virtual void update();
00374   virtual void putProp(UContext*, UControl*);
00375 
00376   // - - - impl - - - - -- - - - - - - - - - - - - - - - - - - - - - - -
00377 #ifndef NO_DOC
00378 protected:
00379   const UFlag* flag;
00380 #endif
00381 };
00382 
00383 /* ==================================================== ===== ======= */
00387 class UPropdef : public UFlagdef {
00388 public:
00389   UBIT_ATTR_CLASS(UPropdef, UProp)
00390 
00391   UPropdef();
00392   UPropdef(const UFlag&);
00393   UPropdef(const UFlag&, UProp&);
00395 
00396   friend UPropdef& upropdef();
00397   friend UPropdef& upropdef(const class UFlag& f, UProp&);
00399 
00400   virtual UPropdef& set(const UFlag&);
00401   virtual UPropdef& set(UProp&);
00402   virtual UPropdef& set(const UFlag&, UProp&);
00403   virtual UPropdef& clear();
00404 
00405   UProp* getProp() const {return prop;}
00406   virtual void putProp(UContext*, UControl*);
00407 
00408 private:
00409   uptr<UProp> prop;
00410 };
00411 
00412 /* ==================================================== ===== ======= */
00416 class UPropval : public UProp {
00417 public:
00418   UBIT_ATTR_CLASS(UPropval, UProp)
00419 
00420   UPropval();
00421   UPropval(const UFlag&);
00422   friend UPropval& upropval(const class UFlag& f);
00423 
00424   const UFlag* getFlag() const {return flag;}
00425 
00426   virtual void update();
00427   virtual void putProp(UContext*, UControl*);
00428 
00429 private:
00430   const UFlag* flag;
00431 };
00432 
00433 /* ==================================================== ===== ======= */
00434 /* Window Title.
00435 */
00436 class UTitle: public UProp {
00437 public:
00438   UBIT_ATTR_CLASS(UTitle, UProp)
00439 
00440   UTitle(const char* = "");
00441   UTitle(const UStr&);
00447   friend UTitle& utitle(const char*_s) {return *new UTitle(_s);}
00448   friend UTitle& utitle(const UStr&_s) {return *new UTitle(_s);}
00449   
00450   UStr& value() {return *pvalue;}
00451   /* returns the value.
00452     * - example: UTitle t; t.value() = "Main Win"; UStr s = t.value();
00453     * - value() can be shared (but can't be deleted!)
00454     */
00455   
00456   virtual void update();
00457 
00458   // - impl. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00459 #ifndef NO_DOC
00460 private:
00461     //uptr<UStr> pvalue;
00462     bool changed;
00463 #endif
00464 };
00465 
00466 }
00467 #endif
00468 /* ==================================================== [TheEnd] ======= */
00469 /* ==================================================== [(c)Elc] ======= */

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