fix properties
[AROS.git] / rom / intuition / dogadgetmethoda.c
blob832e6b34f43dfb7183f873ad870c8590d159bfa1
1 /*
2 Copyright © 1995-2007, 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 HISTORY
81 29-10-95 digulla automatically created from
82 intuition_lib.fd and clib/intuition_protos.h
83 25-10-96 calid submitted the code
85 *****************************************************************************/
87 AROS_LIBFUNC_INIT
89 struct GadgetInfo *gi = &GetPrivIBase(IntuitionBase)->DoGadgetMethodGI;
90 struct RastPort *rp = &GetPrivIBase(IntuitionBase)->DoGadgetMethodRP;
91 IPTR ret = 0;
93 DEBUG_DOGADGETMETHOD(dprintf("DoGadgetMethod[%x]: Gad %p Win %p Req %p Method %ld (0x%lx)\n",
94 gi, gad, win, req, msg->MethodID, msg->MethodID));
96 if (!win && req) win = req->RWindow;
98 if (gad && (((gad->GadgetType & GTYP_GTYPEMASK) == GTYP_CUSTOMGADGET) || (gad->GadgetType & 0x100))) /* OS routines work with NULL objects */
101 /* Protect DoMethodA against race conditions between app task
102 and input.device task (which executes Intuitions Inputhandler) */
104 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->GadgetLock);
106 //jDc: SetupGInfo fails when there's no window (but it also clears gadgetinfo!)
107 SetupGInfo(gi, win, req, gad, IntuitionBase);
109 if (gi->gi_RastPort)
111 InitRastPort(rp);
112 rp->Layer = gi->gi_RastPort->Layer;
113 rp->BitMap = gi->gi_RastPort->BitMap;
114 gi->gi_RastPort = rp;
115 SetFont(rp, gi->gi_DrInfo->dri_Font);
118 switch (msg->MethodID)
120 case OM_NEW:
121 case OM_SET:
122 case OM_NOTIFY:
123 case OM_UPDATE:
124 ((struct opSet *)msg)->ops_GInfo = gi;
125 ret = Custom_DoMethodA(gad, msg);
126 break;
128 case GM_LAYOUT:
129 ((struct gpLayout *)msg)->gpl_GInfo = gi;
130 ret = Custom_DoMethodA(gad, msg);
131 break;
133 case GM_RENDER:
135 struct RastPort *rport;
137 /* Allocate a clone rastport derived from the GadgetInfo
138 * whose layer clipping information has been nulled out...
140 rport = ObtainGIRPort(gi);
142 if (rport)
144 #if 0 /* stegerg: CHECKME!!!! */
145 //init intuition's global dogadmethod rp with obtained data
146 CopyMem(rport,rp,sizeof (struct RastPort));
148 if (gi->gi_DrInfo)
150 SetFont(rp, gi->gi_DrInfo->dri_Font);
153 ((struct gpRender *)msg)->gpr_RPort = rp;
154 ((struct gpRender *)msg)->gpr_GInfo = gi;
155 #else
156 if (gi->gi_DrInfo)
158 SetFont(rport, gi->gi_DrInfo->dri_Font);
161 ((struct gpRender *)msg)->gpr_RPort = rport;
162 ((struct gpRender *)msg)->gpr_GInfo = gi;
164 #endif
166 ret = Custom_DoMethodA(gad, msg);
168 ReleaseGIRPort(rport);
171 break;
173 default:
174 ((struct gpRender *)msg)->gpr_GInfo = gi;
175 ret = Custom_DoMethodA (gad, msg);
176 break;
178 } /* switch (msg->MethodID) */
180 if (gi->gi_DrInfo) FreeScreenDrawInfo (gi->gi_Screen, gi->gi_DrInfo );
182 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->GadgetLock);
184 } /* if (gad) */
186 DEBUG_DOGADGETMETHOD(dprintf("DoGadgetMethod[%x]: Return 0x%lx\n", gi, ret));
188 return( (ULONG)ret );
190 AROS_LIBFUNC_EXIT
192 } /* DoGadgetMethodA */