home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / aplusplus-1.01-src.lha / src / amiga / aplusplus-1.01 / include / aplusplus / intuition / IntuiObject.h < prev    next >
C/C++ Source or Header  |  1994-05-09  |  10KB  |  251 lines

  1. #ifndef APP_IntuiObject_H
  2. #define APP_IntuiObject_H
  3. /******************************************************************************
  4.  **
  5.  **    C++ Class Library for the Amiga© system software.
  6.  **
  7.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  8.  **    All Rights Reserved.
  9.  **
  10.  **    $VER: apphome:APlusPlus/intuition/IntuiObject.h 1.04 (04.05.94) $
  11.  **    
  12.  ******************************************************************************/
  13.  
  14. extern "C" {
  15. #include <intuition/intuition.h>
  16. #include <utility/tagitem.h>
  17. }
  18. #include <APlusPlus/environment/APPObject.h>
  19. #include <APlusPlus/environment/MapArray.h>
  20. #include <APlusPlus/exec/List.h>
  21. #include <APlusPlus/intuition/ITransponder.h>
  22. #include <APlusPlus/utility/AttrList.h>
  23.  
  24.  
  25. /******************************************************************************************
  26.       « IntuiObject class »    virtual base class
  27.  
  28.    base class for all graphical user interface classes. This class provides a mechanism
  29.    to trace dependecies between the objects in an Intuition-based user interface.
  30.  
  31.    All IntuiObjects have one owner that is to be supplied with the constructor call and
  32.    can have a list of dependent IntuiObjects themselves. That makes it easy to track all
  33.    IntuiObjects within one application. So, only the base object has to be deleted to 
  34.     cause the deletion of its dependent objects.
  35.  
  36.    Furthermore, the position of an object within the dependency tree has an effect on
  37.    some IntuiObject-derived objects (e.g. positioning within a window).
  38.    For further details look at the description of the GraphicObject class.
  39.  
  40.     The implementation builds the dependency tree from MinListC lists: every object
  41.     has its double-linked list of dependent objects.
  42.  
  43.    IntuiObject derived classes will get their specifications via an Attribute Tag list 
  44.     which is defined in the AttrList class.
  45.    
  46.    IntuiObjects can be declared to get the actual value for an attribute from an actual 
  47.    value of one attribute of another IntuiObject. This dependency can be declared by 
  48.    usage of setAttributes() or in the constructor's attribute list:
  49.  
  50.         objA = new GT_Scroller(...,AttrList(...,GTSC_Top,1,...),...);
  51.         objB = new BoopsiGadget(...,AttrList(..,CONSTRAINT(PGA_Top,objA,GTSC_Top),...));
  52.     
  53.     objA's "GTSC_Top" initialises obj's "PGA_Top"
  54.  ******************************************************************************************/
  55. class IOBrowser;
  56. class IntuiRoot;
  57.  
  58. class IntuiObject : public MinNodeC, private APPObject, public MinListC
  59. {
  60.    friend IntuiRoot;
  61.    friend IOBrowser;
  62.    friend ostream& operator << (ostream& OS,IntuiObject *iob);
  63.    private:
  64.       APTR                  iObject;   // address of the shadowed Intuition object
  65.       ITransponder    *iTransponder;   // notification interconnection
  66.       AttrList                 attrList;   // Taglist with create attributes
  67.       BOOL setAttributesIsRecurrent;   // helps determine if there is a loop in the ITransponder dependenies
  68.         MapArray                   cTable;    // constraints table
  69.         LONG reserved1;
  70.  
  71.         void processAttrs(AttrList& attrs);        
  72.         
  73.         LONG newConstraint(Tag onChangedTag,IntuiObject *notifyThis,Tag mapToTag);
  74.         // returns the actual value for the 'mapToTag' attribute of the 'notifyThis' IntuiObject
  75.         void releaseObject(IntuiObject *obj);    // remove all notify dependencies to 'obj'
  76.         void changedAttrs(AttrList& attrs);
  77.         
  78.    protected:
  79.       // The type of the Intuition object addressed in iObject is stored in APPObject
  80.  
  81.       /** if no owner is given (owner == NULL) the object is attached to the base object.
  82.        ** However, this might cause some classes not to work proper,
  83.        ** (e.g. a gadget must have a window or something similar as its (maybe indirect) owner)
  84.        ** others are most times only dependent of the base object (e.g. the window classes).
  85.        **/
  86.       IntuiObject(IntuiObject *,const AttrList&);     // add to the owner's list
  87.  
  88.       BOOL notificationLoop() { return setAttributesIsRecurrent; }
  89.         // check within setAttributes() for a notification loop
  90.         
  91.       void setIOType(LONG type) { setID( ID() | type); }
  92.         // imprint the class id after successful initialisation within the constructor
  93.         
  94.       APTR& IObject() { return iObject; }
  95.  
  96.       AttrList &intuiAttrs() { return attrList; }
  97.       // access to the attribute taglist for the class implementor.
  98.  
  99.       void setAttrs(AttrList& attrs) { IntuiObject::setAttributes(attrs); }
  100.         // alter attribute values including notification triggering
  101.       
  102.         APPObject::setError;
  103.         // if the constructor fails an error code ought to be set instead of the class id
  104.         
  105.    public:
  106.       virtual ~IntuiObject();                      // remove from the owner's list
  107.  
  108.       /** Note for the class implementor: YOU MUST CALL setAttributes() with the received taglist
  109.        ** for your class' base class when you have sought information from the attributes.
  110.        ** The attribute tags will be updated and notification will be triggered NOT BEFORE 
  111.        ** the taglist propagation arrives at IntuiObject::setAttributes().
  112.        ** Your setAttributes() method MUST NOT alter the taglist if you want the attribute 
  113.          ** values to be applied.
  114.          ** The notification system is capable of inhibiting 'setAttributes()' loops.
  115.          ** Note that the loop is broken not before the setAttributes() call reaches the 
  116.          ** IntuiObject base class! To prevent derived classes from getting the recursive 
  117.          ** setAttributes() call each class' setAttributes() method must check with
  118.          ** 'BOOL notificationLoop()' and return immediately on TRUE return value.
  119.        **/
  120.       virtual ULONG setAttributes(AttrList& );   
  121.         // each IntuiObject may implement class specific action
  122.         
  123.       virtual ULONG getAttribute(Tag tagValue,ULONG& tagData);
  124.         // accessing the attributes taglist for the class user.
  125.         
  126.       APTR object() { return iObject; }        // read only public version
  127.       
  128.       IntuiObject *findOwner() { return (IntuiObject*)findList(); } 
  129.         // find the owner of this object
  130.       IntuiObject *findRootOfKind(LONG basetype);  
  131.         // get the first object upwards searching in the tree..        
  132.       IntuiObject *findRootOfType(LONG type);      
  133.         // ..that is kindOf() or isType() of the given ID.
  134.         
  135.       ULONG getIOType() { return ID()&0x0000ffff; }
  136.             
  137.       BOOL isKindOf(LONG basetype) { return ((ID()&basetype)==basetype); }
  138.       // (BOOL)(((LONG)ID()&bt)) is always 0 for bt>2^16-1 !!!
  139.       BOOL isKindOfIntuiObject() { return isKindOf(INTUIOBJECT_CLASS); }   
  140.         // check unknown APPObjects      
  141.         BOOL isType(LONG type)  { return (ID()==(INTUIOBJECT_CLASS|type)); }
  142.       
  143.       APPObject::Ok;       // check for validity
  144.       APPObject::isClass;  // compares with ID()
  145.       APPObject::error;
  146.       APPObject::status;
  147.  
  148.         static IntuiObject *confirm(IntuiObject *iob) { return iob; }
  149. };
  150.  
  151. class IOBrowser
  152. {
  153.    private:
  154.       #define IOBSTACKSIZE 50
  155.       IntuiObject *stack[IOBSTACKSIZE];
  156.       int   sp;
  157.  
  158.       void push(IntuiObject *iob)
  159.       { if (sp<IOBSTACKSIZE) stack[sp++] = iob; else cerr << "IOBrowser: stack overflow\n"; }
  160.  
  161.       IntuiObject *pop()
  162.       { return sp<=0?NULL:stack[--sp]; }
  163.  
  164.    public:
  165.       IOBrowser(IntuiObject *start);
  166.  
  167.       IntuiObject *getNext(LONG type);
  168. };
  169.  
  170. ostream& operator << (ostream& OS,struct TagItem *taglist);
  171.  
  172.  
  173. #define OWNER_NULL   ((IntuiObject*)NULL)
  174. #define OWNER_ROOT   OWNER_NULL
  175.    /* Use for attaching IntuiObjects to the root. Note that this is incompatible with
  176.         most GraphicObjects which need a WindowCV object.
  177.     */
  178.  
  179. #define IOB_Dummy          (TAG_USER|0x10)
  180.  
  181.  
  182. #define IOB_CnstSource        (IOB_Dummy+1)
  183. #define IOB_CnstTag            (IOB_Dummy+2)
  184.     /* Some tags for constraint definition. Do not use these but instead use the define below.
  185.     */
  186.  
  187. #define CONSTRAINT(tag,sourceObj,sourceTag) IOB_CnstSource,IntuiObject::confirm(sourceObj),IOB_CnstTag,sourceTag,tag,0
  188.     /* macro to define an attribute constraint between two IntuiObjects within an attribute tag list.        
  189.     */
  190.  
  191. #define IOB_ITransponder    (IOB_Dummy+3)
  192.     /* Do not use this tag immediately.
  193.     */
  194. #define ITRANSPONDER(itp)    IOB_ITransponder,ITransponder::confirm(itp)
  195.     /* macro to attach an ITransponder object to the IntuiObject.
  196.     */
  197.     
  198.      
  199. //------------- errors --------------