Check for SYS/GL during library init. Reason is that
[AROS.git] / rom / intuition / dogadgetmethoda.c
blobd54799d30ea13e044d80f03950656a416cc4dad1
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <exec/memory.h>
8 #include <intuition/classusr.h>
9 #include <intuition/gadgetclass.h>
10 #include <intuition/cghooks.h>
11 #include <proto/alib.h>
12 #include <proto/exec.h>
13 #include <proto/graphics.h>
14 #include <proto/layers.h>
15 #include <proto/intuition.h>
16 #include "intuition_intern.h"
17 #include "gadgets.h"
19 /*****************************************************************************
21 NAME */
22 #include <intuition/intuition.h>
23 #include <proto/intuition.h>
25 AROS_LH4(IPTR, DoGadgetMethodA,
27 /* SYNOPSIS */
28 AROS_LHA(struct Gadget *, gad, A0),
29 AROS_LHA(struct Window *, win, A1),
30 AROS_LHA(struct Requester *, req, A2),
31 AROS_LHA(Msg , msg, A3),
33 /* LOCATION */
34 struct IntuitionBase *, IntuitionBase, 135, Intuition)
36 /* FUNCTION
37 Invokes a BOOPSI method on an object with a GadgetInfo derived from
38 the supplied window or requester parameter.
40 INPUTS
41 gad - The gadget to work on
42 win - The window which contains the gadget or the requester with
43 the gadgets.
44 req - If the gadget is in a requester, you must specify that one,
45 too.
46 message - Send this message to the gadget.
48 RESULT
49 The result depends on the contents of the message sent to the
50 gadget.
52 NOTES
54 EXAMPLE
56 BUGS
58 SEE ALSO
60 INTERNALS
61 I have derived from a simular function from ClassAct where I have
62 to "fake" the function which is not implemented under OS 2.04.
63 There are likely a few differences between this routine and the
64 real code, but this gets the job done.
66 One thing to note, the Amiga Rom routine causes some form of
67 (layer?) locking. I presume the point of the lock is to avoid
68 removing the gadget from the window during a refresh, or to avoid
69 resizing the window during refresh, etc.
71 This locking is fairly obvious within Workbench itself. When
72 refreshing most any boopsi gadget(s) via RefreshGList() and you try
73 to drag a Workbench icon you will get stuck in a layer lock.
74 Workbench has a deadlock timer and is smart enough to release the
75 lock and abort the drag. With this routine below this locking does
76 not occur. Some might call it a good thing, however the issue
77 should be revisited once more of Intuition has been implemented -
78 if it hasn't been already?!. :)
80 *****************************************************************************/
82 AROS_LIBFUNC_INIT
84 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
85 struct GadgetInfo *gi = &GetPrivIBase(IntuitionBase)->DoGadgetMethodGI;
86 struct RastPort *rp = &GetPrivIBase(IntuitionBase)->DoGadgetMethodRP;
87 IPTR ret = 0;
89 DEBUG_DOGADGETMETHOD(dprintf("DoGadgetMethod[%x]: Gad %p Win %p Req %p Method %ld (0x%lx)\n",
90 gi, gad, win, req, msg->MethodID, msg->MethodID));
92 if (!win && req) win = req->RWindow;
94 if (gad && (((gad->GadgetType & GTYP_GTYPEMASK) == GTYP_CUSTOMGADGET) || (gad->GadgetType & 0x100))) /* OS routines work with NULL objects */
97 /* Protect DoMethodA against race conditions between app task
98 and input.device task (which executes Intuitions Inputhandler) */
100 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->GadgetLock);
102 //jDc: SetupGInfo fails when there's no window (but it also clears gadgetinfo!)
103 SetupGInfo(gi, win, req, gad, IntuitionBase);
105 if (gi->gi_RastPort)
107 InitRastPort(rp);
108 rp->Layer = gi->gi_RastPort->Layer;
109 rp->BitMap = gi->gi_RastPort->BitMap;
110 gi->gi_RastPort = rp;
111 SetFont(rp, gi->gi_DrInfo->dri_Font);
114 switch (msg->MethodID)
116 case OM_NEW:
117 case OM_SET:
118 case OM_NOTIFY:
119 case OM_UPDATE:
120 ((struct opSet *)msg)->ops_GInfo = gi;
121 ret = Custom_DoMethodA(IntuitionBase, gad, msg);
122 break;
124 case GM_LAYOUT:
125 ((struct gpLayout *)msg)->gpl_GInfo = gi;
126 ret = Custom_DoMethodA(IntuitionBase, gad, msg);
127 break;
129 case GM_RENDER:
131 struct RastPort *rport;
133 /* Allocate a clone rastport derived from the GadgetInfo
134 * whose layer clipping information has been nulled out...
136 rport = ObtainGIRPort(gi);
138 if (rport)
140 #if 0 /* stegerg: CHECKME!!!! */
141 //init intuition's global dogadmethod rp with obtained data
142 CopyMem(rport,rp,sizeof (struct RastPort));
144 if (gi->gi_DrInfo)
146 SetFont(rp, gi->gi_DrInfo->dri_Font);
149 ((struct gpRender *)msg)->gpr_RPort = rp;
150 ((struct gpRender *)msg)->gpr_GInfo = gi;
151 #else
152 if (gi->gi_DrInfo)
154 SetFont(rport, gi->gi_DrInfo->dri_Font);
157 ((struct gpRender *)msg)->gpr_RPort = rport;
158 ((struct gpRender *)msg)->gpr_GInfo = gi;
160 #endif
162 ret = Custom_DoMethodA(IntuitionBase, gad, msg);
164 ReleaseGIRPort(rport);
167 break;
169 default:
170 ((struct gpRender *)msg)->gpr_GInfo = gi;
171 ret = Custom_DoMethodA (IntuitionBase, gad, msg);
172 break;
174 } /* switch (msg->MethodID) */
176 if (gi->gi_DrInfo) FreeScreenDrawInfo (gi->gi_Screen, gi->gi_DrInfo );
178 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->GadgetLock);
180 } /* if (gad) */
182 DEBUG_DOGADGETMETHOD(dprintf("DoGadgetMethod[%x]: Return 0x%lx\n", gi, ret));
184 return( (ULONG)ret );
186 AROS_LIBFUNC_EXIT
188 } /* DoGadgetMethodA */