home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Extensions / APPSource.lha / APlusPlus / libsource / BoopsiGadget.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  4.6 KB  |  164 lines

  1. /******************************************************************************
  2.  **
  3.  **   C++ Class Library for the Amiga⌐ system software.
  4.  **
  5.  **   Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  6.  **   All Rights Reserved.
  7.  **
  8.  **   $Source: apphome:RCS/libsource/BoopsiGadget.cxx,v $
  9.  **   $Revision: 1.13 $
  10.  **   $Date: 1994/08/02 17:48:52 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15. extern "C" {
  16. #ifdef __GNUG__
  17. #include <inline/intuition.h>
  18. #endif
  19.  
  20. #ifdef __SASC
  21. #include <proto/intuition.h>
  22. #endif
  23. }
  24. #include <APlusPlus/intuition/BoopsiGadget.h>
  25. #include <APlusPlus/intuition/IntuiMessageC.h>
  26. #include <APlusPlus/intuition/GWindow.h>
  27.  
  28.  
  29. static const char rcs_id[] = "$Id: BoopsiGadget.cxx,v 1.13 1994/08/02 17:48:52 Armin_Vogt Exp Armin_Vogt $";
  30.  
  31. //runtime type inquiry support
  32. intui_typeinfo(BoopsiGadget, derived(from(GadgetCV)), rcs_id)
  33.  
  34.  
  35. BoopsiGadget::BoopsiGadget(GraphicObject* owner,
  36.                            UBYTE* pubClass,
  37.                            AttrList& attrs) : GadgetCV(owner,attrs)
  38. {
  39.    create(NULL,pubClass,attrs);
  40. }
  41.  
  42. BoopsiGadget::BoopsiGadget(GraphicObject* owner,
  43.                            Class* privClass,
  44.                            AttrList& attrs) : GadgetCV(owner,attrs)
  45. {
  46.    create(privClass,NULL,attrs);
  47. }
  48.  
  49. void BoopsiGadget::create(Class* privClass,UBYTE* pubClass,const AttrList& attrs)
  50. {
  51.    if (Ok())
  52.    {
  53.       privateClass = privClass;
  54.       publicClass  = pubClass;
  55.  
  56.       // add the tags that specify the dimensions to the Boopsigadget
  57.       // and some default attributes..
  58.       applyDefaultAttrs( attrs, AttrList(
  59.          GA_Left,0, GA_Top,0, GA_Width,0, GA_Height,0,
  60.          ICA_TARGET, ICTARGET_IDCMP,
  61.          TAG_END));
  62.  
  63.       // make sure all events get 'heared'
  64.       getHomeWindow()->modifyIDCMP(CLASS_IDCMPUPDATE|CLASS_GADGETDOWN|CLASS_GADGETUP);
  65.  
  66.       setIOType(IOTYPE_BOOPSIGADGET);
  67.    }
  68.    _dprintf("Boopsigadget %lx initialised. status = %s\n",(APTR)this,(Ok()?"OK":"ERROR") );
  69.    _dprintf("status = %ld\n",status());
  70. }
  71.  
  72.  
  73. APTR BoopsiGadget::redrawSelf(GWindow* homeWindow,ULONG& returnType)
  74. {
  75.    _dprintf("Boopsigadget::redrawSelf()\n");
  76.  
  77.    GadgetCV::redrawSelf(homeWindow,returnType);
  78.  
  79.    // destroy old Boopsigadget
  80.    if (gadgetPtr()!=NULL)
  81.    {
  82.       _dprintf("DisposeObject()\n");
  83.       DisposeObject(gadgetPtr());
  84.       _dprintf("\tdone\n");
  85.    }
  86.  
  87.    // copy GraphicObject rectangle to gadget taglist
  88.    intuiAttrs().updateAttrs(AttrList(GA_Left,iLeft(),GA_Top,iTop(),GA_Width,iWidth(),GA_Height,iHeight(),TAG_END));
  89.  
  90.    // create new Boopsigadget
  91.    if ( storeGadget((struct Gadget*)NewObjectA(privateClass,publicClass,intuiAttrs()) ) )
  92.    {
  93.       gadgetPtr()->NextGadget = NULL; // important for AddGList() in GWindow::On_NEWSIZE()
  94.       returnType = IOTYPE_BOOPSIGADGET;
  95.    }
  96.    else
  97.    {
  98.       returnType = NULL;
  99.       _ierror(BOOPSIGADGET_NEWOBJECT_FAILED);
  100.    }
  101.  
  102.    _dprintf("\tdone\n");
  103.    return gadgetPtr();
  104. }
  105.  
  106. void BoopsiGadget::callback(const IntuiMessageC* imsg)
  107.    /* Boopsigadgets receive IDCMPUPDATE messages in case they have ICA_TARGET set to ICTARGET_IDCMP.
  108.       Each IDCMPUPDATE message contains a taglist of changed attributes in the IAddress field.
  109.       This taglist is used to change the IntuiObject attribute tags, spreading changes through the
  110.       ITransponder in the process.
  111.    */
  112. {
  113.    if (imsg && imsg->getIAddress())
  114.    {
  115.         _dprintf("BoopsiGadget::callback\n");
  116.  
  117.       switch(imsg->getClass())
  118.       {
  119.          case CLASS_IDCMPUPDATE :
  120.             setAttrs( AttrList((struct TagItem*)imsg->getIAddress()) );
  121.             break;
  122.       }
  123.    }
  124.    else _dprintf("BoopsiGadget::callback() received imsg==null!!\n");
  125. }
  126.  
  127. ULONG BoopsiGadget::setAttributes(AttrList& attrs)
  128. {
  129.    if (notificationLoop()) return 0L;
  130.  
  131.    _dprintf("BoopsiGadget(%lx)::setAttributes()\n",(APTR)this);
  132.  
  133.    if (gadgetPtr())
  134.    {
  135.       SetGadgetAttrsA(gadgetPtr(),(struct Window*)getHomeWindow()->windowPtr(),NULL,attrs);
  136.    }
  137.  
  138.    return GadgetCV::setAttributes(attrs);
  139. }
  140.  
  141. ULONG BoopsiGadget::getAttribute(Tag attrID,ULONG& dataStore)
  142.    /* read a specific BOOPSI attribute. If the attribute is recognized by the BOOPSI object
  143.       0L is being returned and dataStore is undefined, otherwise the attribute's value is
  144.       stored in dataStore, a reference to a ULONG variable.
  145.    */
  146. {
  147.    if (gadgetPtr() && GetAttr(attrID,gadgetPtr(),&dataStore))
  148.       return dataStore;
  149.    else
  150.       return GadgetCV::getAttribute(attrID,dataStore);
  151. }
  152.  
  153. BoopsiGadget::~BoopsiGadget()
  154.    /* Dispose the Boopsi object.
  155.    */
  156. {
  157.    _dprintf("BoopsiGadget::~\n");
  158.    if (gadgetPtr()!=NULL)
  159.    {  _dprintf("DisposeObject()\n");
  160.       DisposeObject(gadgetPtr());
  161.    }
  162.    _dprintf("done\n");
  163. }
  164.