home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / intuition / dogadgetmethoda.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  6KB  |  240 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: dogadgetmethoda.c,v 1.4 1997/01/27 00:36:37 ldp Exp $
  4.     $Log: dogadgetmethoda.c,v $
  5.     Revision 1.4  1997/01/27 00:36:37  ldp
  6.     Polish
  7.  
  8.     Revision 1.3  1996/12/10 14:00:01  aros
  9.     Moved #include into first column to allow makedepend to see it.
  10.  
  11.     Revision 1.2  1996/11/08 11:28:00  aros
  12.     All OS function use now Amiga types
  13.  
  14.     Moved intuition-driver protos to intuition_intern.h
  15.  
  16.     Revision 1.1  1996/10/25 14:17:54  aros
  17.     New functions
  18.  
  19.  
  20.     Desc: Implementation of DoGadgetMethodA
  21.     Lang: english
  22. */
  23. #include <exec/memory.h>
  24. #include <intuition/classusr.h>
  25. #include <intuition/gadgetclass.h>
  26. #include <intuition/cghooks.h>
  27. #include <proto/alib.h>
  28. #include <proto/exec.h>
  29. #include <proto/graphics.h>
  30. #include <proto/intuition.h>
  31. #include "intuition_intern.h"
  32.  
  33. /*****************************************************************************
  34.  
  35.     NAME */
  36. #include <intuition/intuition.h>
  37. #include <proto/intuition.h>
  38.  
  39.     AROS_LH4(IPTR, DoGadgetMethodA,
  40.  
  41. /*  SYNOPSIS */
  42.     AROS_LHA(struct Gadget    *, gad, A0),
  43.     AROS_LHA(struct Window    *, win, A1),
  44.     AROS_LHA(struct Requester *, req, A2),
  45.     AROS_LHA(Msg               , msg, A3),
  46.  
  47. /*  LOCATION */
  48.     struct IntuitionBase *, IntuitionBase, 135, Intuition)
  49.  
  50. /*  FUNCTION
  51.     Invokes a boopsi method on a object with a GadgetInfo derived from
  52.     the supplied window or requester parameter.
  53.  
  54.     INPUTS
  55.     gad - The gadget to work on
  56.     win - The window which contains the gadget or the requester with
  57.         the gadgets.
  58.     req - If the gadget is in a requester, you must specify that one,
  59.         too.
  60.     message - Send this message to the gadget.
  61.  
  62.     RESULT
  63.     The result depends on the contents of the message sent to the
  64.     gadget.
  65.  
  66.     NOTES
  67.  
  68.     EXAMPLE
  69.  
  70.     BUGS
  71.  
  72.     SEE ALSO
  73.  
  74.     INTERNALS
  75.     I have derived from a simular function from ClassAct where I have
  76.     to "fake" the function which is not implemented under OS 2.04.
  77.     There are likely a few differences between this routine and the
  78.     real code, but this gets the job done.
  79.  
  80.     One thing to note, the Amiga Rom routinecauses some form of
  81.     (layer?) locking. I presume the point of the lock is to avoid
  82.     removing the gadget from the window durring a refresh, or to avoid
  83.     resizing the window durring refresh, etc.
  84.  
  85.     This locking is fairly obvious within Workbench itself. When
  86.     refreshing most any boopsi gadget(s) via RefreshGList() and you try
  87.     to drag a Workbench icon you will get stuck in a layer lock.
  88.     Workbench has a deadlock timer and is smart enough to release the
  89.     lock and abort the drag. With this routine below this locking does
  90.     not occur. Some might call it a good thing, however the issue
  91.     should be revisited once more of Intuition has been implemented -
  92.     if it hasn't been already?!. :)
  93.  
  94.     HISTORY
  95.     29-10-95    digulla automatically created from
  96.                 intuition_lib.fd and clib/intuition_protos.h
  97.     25-10-96    calid   submitted the code
  98.  
  99. *****************************************************************************/
  100. {
  101.     AROS_LIBFUNC_INIT
  102.     AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  103.     IPTR ret = 0;
  104.  
  105.     if (gad) /* OS routines work with NULL objects */
  106.     {
  107.     struct GadgetInfo *gi = (struct GadgetInfo *)AllocMem(sizeof(struct GadgetInfo), MEMF_PUBLIC|MEMF_CLEAR);
  108.  
  109.     if (gi)
  110.     {
  111.         struct Window *tw;
  112.  
  113.         if (req)
  114.         {
  115.         gi->gi_Requester = req;
  116.         tw = req->RWindow;
  117.         }
  118.         else
  119.         {
  120.         gi->gi_Requester = NULL;
  121.         tw = win;
  122.         } /* if */
  123.  
  124.         if (tw)
  125.         {
  126.         /* Initialize the GadgetInfo data. */
  127.         gi->gi_Window          = tw;
  128.         gi->gi_Screen          = tw->WScreen;
  129.         gi->gi_RastPort       = tw->RPort;
  130.         gi->gi_Layer          = tw->WLayer;
  131.         gi->gi_Pens.DetailPen = tw->DetailPen;
  132.         gi->gi_Pens.BlockPen  = tw->BlockPen;
  133.         gi->gi_DrInfo          = GetScreenDrawInfo (gi->gi_Screen);
  134.  
  135.         switch (gad->GadgetType & GTYP_GTYPEMASK)
  136.         {
  137.         case GTYP_SCRGADGET:
  138.             gi->gi_Window     = NULL;
  139.             gi->gi_Domain.Left     = 0;
  140.             gi->gi_Domain.Top     = 0;
  141.             gi->gi_Domain.Width  = tw->WScreen->Width;
  142.             gi->gi_Domain.Height = tw->WScreen->Height;
  143.  
  144.             break;
  145.  
  146.         case GTYP_GZZGADGET:
  147.             gi->gi_Domain.Left     = tw->BorderLeft;
  148.             gi->gi_Domain.Top     = tw->BorderTop;
  149.             gi->gi_Domain.Width  = tw->Width  - tw->BorderLeft - tw->BorderRight;
  150.             gi->gi_Domain.Height = tw->Height - tw->BorderTop  - tw->BorderBottom;
  151.  
  152.             break;
  153.  
  154.         case GTYP_REQGADGET:
  155.             gi->gi_Domain.Left     = req->LeftEdge;
  156.             gi->gi_Domain.Top     = req->TopEdge;
  157.             gi->gi_Domain.Width  = req->Width;
  158.             gi->gi_Domain.Height = req->Height;
  159.  
  160.             break;
  161.  
  162.         default:
  163.             gi->gi_Domain.Left     = 0;
  164.             gi->gi_Domain.Top     = 0;
  165.             gi->gi_Domain.Width  = tw->Width;
  166.             gi->gi_Domain.Height = tw->Height;
  167.  
  168.             break;
  169.  
  170.         } /* switch (gadgettype) */
  171.         } /* if (tw) */
  172.     } /* if (gi) */
  173.  
  174.     switch (msg->MethodID)
  175.     {
  176.     case OM_NEW:
  177.     case OM_SET:
  178.     case OM_NOTIFY:
  179.     case OM_UPDATE:
  180.         ((struct opSet *)msg)->ops_GInfo = gi;
  181.         ret = DoMethodA((Object *)gad, msg);
  182.         break;
  183.  
  184.     case GM_LAYOUT:
  185.         if (gi)
  186.         {
  187.         ((struct gpLayout *)msg)->gpl_GInfo = gi;
  188.  
  189.         ret = DoMethodA((Object *)gad, msg);
  190.         } /* if */
  191.         break;
  192.  
  193.     case GM_RENDER:
  194.         if (gi)
  195.         {
  196.         struct RastPort *rp;
  197.  
  198.         /* Allocate a clone rastport derived from the GadgetInfo
  199.          * whose layer clipping information has been nulled out...
  200.          */
  201.         rp = ObtainGIRPort(gi);
  202.  
  203.         if (rp)
  204.         {
  205.             if (gi->gi_DrInfo)
  206.             {
  207.             SetFont(rp, gi->gi_DrInfo->dri_Font);
  208.             } /* if */
  209.  
  210.             ((struct gpRender *)msg)->gpr_RPort = rp;
  211.             ((struct gpRender *)msg)->gpr_GInfo = gi;
  212.  
  213.             ret = DoMethodA((Object *)gad, msg);
  214.  
  215.             ReleaseGIRPort(rp);
  216.         } /* if */
  217.         } /* if */
  218.         break;
  219.  
  220.     default:
  221.         ((struct gpRender *)msg)->gpr_GInfo = gi;
  222.  
  223.         ret = DoMethodA ((Object *)gad, msg);
  224.         break;
  225.  
  226.     } /* switch */
  227.  
  228.     if (gi)
  229.     {
  230.         if (gi->gi_DrInfo)
  231.         FreeScreenDrawInfo (gi->gi_Screen, gi->gi_DrInfo );
  232.  
  233.         FreeMem ((APTR)gi, sizeof(struct GadgetInfo));
  234.     } /* if */
  235.     } /* if */
  236.  
  237.     return( (ULONG)ret );
  238.     AROS_LIBFUNC_EXIT
  239. } /* DoGadgetMethodA */
  240.