home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Extensions / APPSource.lha / APlusPlus / libsource / GWindow.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  8.7 KB  |  259 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/GWindow.cxx,v $
  9.  **   $Revision: 1.12 $
  10.  **   $Date: 1994/08/02 17:51:53 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. extern "C" {
  17. #ifdef __GNUG__
  18. #include <inline/intuition.h>
  19. #include <inline/gadtools.h>
  20. #endif
  21.  
  22. #ifdef __SASC
  23. #include <proto/intuition.h>
  24. #include <proto/gadtools.h>
  25. #endif
  26. }
  27. #include <APlusPlus/intuition/GWindow.h>
  28. #include <APlusPlus/intuition/GadgetCV.h>
  29. #include <APlusPlus/intuition/IntuiMessageC.h>
  30.  
  31.  
  32. static const char rcs_id[] = "$Id: GWindow.cxx,v 1.12 1994/08/02 17:51:53 Armin_Vogt Exp Armin_Vogt $";
  33.  
  34.  
  35. // runtime type inquiry support
  36. intui_typeinfo(GWindow, derived(from(WindowCV)), rcs_id)
  37.  
  38.  
  39. /*************************************************************************************************
  40.       GWindow methods
  41.  *************************************************************************************************/
  42. #include <graphics/GfxBase.h>
  43. extern struct GfxBase* GfxBase;
  44.  
  45. GWindow::GWindow(IntuiObject* owner,AttrList& attrs)
  46.    : WindowCV(owner,attrs), DrawArea(this),
  47.      screenFont(windowPtr()->WScreen->Font), defaultFont(GfxBase->DefaultFont)
  48. {
  49.    if (!Ok()) return;   // WindowCV creation failed
  50.  
  51.    setIOType(IOTYPE_GWINDOW);
  52.  
  53.    activeGadget = defaultGadget = NULL;
  54.    firstUserGad = GT_context = GT_last = NULL;
  55.    modifyIDCMP(CLASS_GADGETDOWN|CLASS_GADGETUP|CLASS_NEWSIZE|CLASS_CLOSEWINDOW
  56.       |CLASS_SIZEVERIFY//|CLASS_REFRESHWINDOW
  57.       |CLASS_IDCMPUPDATE|CLASS_MOUSEMOVE);
  58.    _dprintf("GWindow:create() done.\n");
  59. }
  60.  
  61. GWindow::~GWindow()
  62. {
  63.    RemoveGList(window(),firstUserGad,-1);  // remove the entire user gadget list from the window
  64.  
  65.    FreeGadgets(GT_context);        // free GadTools gadgets
  66.    _dprintf("~GWindow\n");
  67. }
  68.  
  69. void GWindow::handleIntuiMsg(const IntuiMessageC* imsg)
  70. {
  71.    switch (imsg->getClass())
  72.    {
  73.       case CLASS_GADGETDOWN :
  74.          GWindow::On_GADGETDOWN(imsg);
  75.          break;
  76.       case CLASS_GADGETUP :
  77.          GWindow::On_GADGETUP(imsg);
  78.          break;
  79.       case CLASS_SIZEVERIFY:
  80.          GWindow::On_SIZEVERIFY(imsg);
  81.          break;
  82.       case CLASS_NEWSIZE :
  83.          GWindow::On_NEWSIZE(imsg);
  84.          break;
  85.       case CLASS_REFRESHWINDOW :
  86.          GWindow::On_REFRESHWINDOW(imsg);
  87.          break;
  88.  
  89.       default :
  90.       /* All messages except GADGETUP and GADGETDOWN run towards the Active Gadget.
  91.        * If there is no gadget active, the default will be used. If there is no
  92.        * default, nothing will happen, the message will be replied without further
  93.        * consideration.
  94.        */
  95.       {
  96.          _dprintf("default_IMsgCallback()..\n");
  97.  
  98.          GadgetCV* gadObj;
  99.  
  100.          // try to get the sending object: this is only possible with GadTools gadgets.
  101.          if (NULL != (gadObj = imsg->decodeGadgetCV()))
  102.          {
  103.             activeGadget = gadObj;
  104.             gadObj->callback(imsg);
  105.          }
  106.          else  // ATTENTION! : active or default gadget may have been deleted
  107.             if (APPOK(activeGadget)) activeGadget->callback(imsg);
  108.                else { activeGadget = NULL; if (APPOK(defaultGadget)) defaultGadget->callback(imsg);
  109.                   else defaultGadget = NULL; }
  110.       }
  111.       break;
  112.    }
  113. }
  114.  
  115. void GWindow::On_GADGETDOWN(const IntuiMessageC* imsg)
  116.    /* Is invoked on every GADGTEDOWN message from the window's IDCMP.
  117.       GADGETDOWN is ALWAYS triggered by a gadget and can be classed with one definite
  118.       GadgetCV-derived object.
  119.    */
  120. {
  121.    GadgetCV* gadObj;
  122.    if (NULL != (gadObj = imsg->decodeGadgetCV()))
  123.    {
  124.       if (activeGadget && activeGadget != gadObj)  // Active Gadget changes
  125.       {
  126.          defaultGadget = activeGadget;    // default gadget will become active after active has resigned
  127.          IntuiMessageC tmp(CLASS_GADGETUP);
  128.          defaultGadget->callback(&tmp);
  129.       }
  130.       activeGadget = gadObj;           // become last active gadget
  131.       _dprintf("active gadget status=%ld\n",gadObj->status());
  132.       gadObj->callback(imsg);          // deliver message to the gadget
  133.    }
  134. }
  135.  
  136. void GWindow::On_GADGETUP(const IntuiMessageC* imsg)
  137.    /* Is invoked on every GADGETUP message from the window's IDCMP.
  138.       GADGETUP is ALWAYS triggered by a gadget and can be classed with one definite
  139.       GadgetCV-derived object.
  140.    */
  141. {
  142.    GadgetCV* gadObj;
  143.    if (NULL != (gadObj = imsg->decodeGadgetCV()))
  144.    {
  145.       activeGadget = defaultGadget;    // previously active gadget becomes active again
  146.       gadObj->callback(imsg);          // 'gadObj' may force staying the active gadget here
  147.       if (activeGadget)
  148.          if (gadObj != activeGadget)      // if active switched to default tell default about it with GADGETDOWN
  149.          {
  150.             IntuiMessageC tmp(CLASS_GADGETDOWN);
  151.             activeGadget->callback(&tmp);
  152.          }
  153.          else defaultGadget = NULL;
  154.    }
  155. }
  156.  
  157. void GWindow::setActiveGadget(GadgetCV* newActive)
  158. {
  159.    activeGadget = newActive;
  160. }
  161.  
  162. void GWindow::On_SIZEVERIFY(const IntuiMessageC* imsg)
  163. {
  164.    _dprintf("GWindow::On_SIZEVERIFY\n");
  165.    RemoveGList(window(),firstUserGad,-1);  // remove the entire user gadget list from the window
  166.    firstUserGad = NULL;
  167.    // removing all gadgets here prevents them from being refreshed after window resizing.
  168. }
  169.  
  170. void GWindow::On_NEWSIZE(const IntuiMessageC* imsg)
  171.    /* Build up the window display: collect all gadgets from childs and 'send' redrawSelf
  172.       messages to them after having them resized.
  173.    */
  174. {
  175.    WindowCV::newsize(imsg);
  176.  
  177.    RemoveGList(window(),firstUserGad,-1);  // remove the entire user gadget list from the window
  178.    firstUserGad = NULL;          // pointer to the begin of the list of user defined gadgets
  179.  
  180.    // set clipping to inner window box 
  181.    clearRegion();
  182.    orRectRegion(-leftB(),-topB(),iWidth()+rightB()-1,iHeight()+bottomB()-1);  
  183.    setStdClip();
  184.    
  185.    // clear the inner window box
  186.    setAPen(0);setOPen(0);setDrMd(JAM2);
  187.    rectFill(-leftB(),-topB(),iWidth()+rightB()-1,iHeight()+bottomB()-1);   
  188.    
  189.    struct Gadget* old_GT_context = GT_context;
  190.    // save old context (with all GadTools gadgets) for later freeing
  191.  
  192.    if (!CreateContext(>_context)) { _ierror(OUT_OF_MEMORY); return; }
  193.  
  194.    GT_last = GT_context;   // initialise the list of GadTools gadgets.
  195.  
  196.    _dprintf("adjust child..\n");
  197.    adjustChilds();
  198.    _dprintf("done\n");
  199.  
  200.    ULONG type;    // reference argument for redrawSelf gets the return type of redrawSelf.
  201.    GadgetCV::redrawSelfHomeWindow = this;
  202.    GraphicObject::redrawSelf(this,type);  // redraw the window i.e. draw border
  203.  
  204.    adjustStdClip();  // confine clipping to inner GraphicObject dimensions
  205.    
  206.    IOBrowser iobjs(this);
  207.  
  208.    struct Gadget* gadgets;
  209.    GraphicObject* gob;
  210.    
  211.    while (NULL != (gob = (GraphicObject*)iobjs.getNext(class_type_id(GadgetCV))) )
  212.    {
  213.       _dprintf("got one GadgetCV object.\n");
  214.       if (NULL != (gadgets = (struct Gadget*)gob->redrawSelf(this,type)))
  215.          if (type == IOTYPE_GTGADGET) // GT gadgets are linked seperately.
  216.          {
  217.             /** GadTools gadgets are a linked list of gadgets,
  218.              ** the last gadget is returned by CreateGadget() and subsequently by redrawSelf().
  219.              **/
  220.             GT_last = gadgets;      // trace the end of the GadTools gadgets list.
  221.             if (GT_last) GT_last->NextGadget = NULL;   // make it safe
  222.             _dprintf("GT gadget found\n");
  223.          }
  224.          else if (type == IOTYPE_BOOPSIGADGET || type == IOTYPE_STDGADGET)
  225.          {
  226.             if (firstUserGad==NULL) firstUserGad = gadgets;
  227.             if (gadgets)
  228.                AddGList(window(),gadgets,(UWORD)-1,(UWORD)-1,NULL);
  229.                // add the resized gadget(s) to the window
  230.             _dprintf("Non GT gadget at %lx found\n",gadgets);
  231.          }
  232.    }
  233.    GadgetCV::redrawSelfHomeWindow = NULL;
  234.  
  235.    FreeGadgets(old_GT_context);
  236.    // free all GadTools gadgets. They shall have been recreated in resizeSelf().
  237.  
  238.    // now GT_context points to the head of the separately collected GadTools gadgets.
  239.    if (!firstUserGad)
  240.       firstUserGad = GT_context; // no other than GadTools gadgets created.
  241.  
  242.    AddGList(window(),GT_context,(UWORD)-1,(UWORD)-1,NULL); // append GadTools gadgets at the end
  243.       _dprintf("AddGList done\n");
  244.    RefreshGadgets(firstUserGad,window(),NULL);
  245.       _dprintf("RefreshGadgets done\n");
  246.    GT_RefreshWindow(window(),NULL);
  247.       _dprintf("everything FINE.\n");
  248.    _dprintf("NEWSIZE done.\n");
  249. }
  250.  
  251. void GWindow::On_REFRESHWINDOW(const IntuiMessageC* imsg)
  252.    /* The minimal refresh routine for GadTools contains the activation of the
  253.       Intuition-intern refreshing.
  254.    */
  255. {
  256.    GT_BeginRefresh(window());
  257.    GT_EndRefresh(window(),TRUE);
  258. }
  259.