Icons for Radium and Shellplayer.
[AROS-Contrib.git] / bgui / dgm.c
blobb8a17f5ff37e9a8f1efa22eaac639e8199e4103c
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * dgm.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.6 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.5 2003/01/18 19:09:56 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.4 2000/08/09 11:45:57 chodorowski
21 * Removed a lot of #ifdefs that disabled the AROS_LIB* macros when not building on AROS. This is now handled in contrib/bgui/include/bgui_compilerspecific.h.
23 * Revision 42.3 2000/05/29 00:40:23 bergers
24 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
26 * Revision 42.2 2000/05/15 19:27:01 stegerg
27 * another hundreds of REG() macro replacements in func headers/protos.
29 * Revision 42.1 2000/05/14 23:32:47 stegerg
30 * changed over 200 function headers which all use register
31 * parameters (oh boy ...), because the simple REG() macro
32 * doesn't work with AROS. And there are still hundreds
33 * of headers left to be fixed :(
35 * Many of these functions would also work with stack
36 * params, but since i have fixed every single one
37 * I encountered up to now, I guess will have to do
38 * the same for the rest.
40 * Revision 42.0 2000/05/09 22:08:48 mlemos
41 * Bumped to revision 42.0 before handing BGUI to AROS team
43 * Revision 41.11 2000/05/09 19:54:10 mlemos
44 * Merged with the branch Manuel_Lemos_fixes.
46 * Revision 41.10 1998/02/25 21:11:55 mlemos
47 * Bumping to 41.10
49 * Revision 1.1 1998/02/25 17:08:03 mlemos
50 * Ian sources
55 /// Class definitions.
56 #include "include/classdefs.h"
58 typedef struct {
59 Object *dd_Target; /* Target object. */
60 struct Window *dd_Window; /* Target window. */
61 struct InputEvent ie;
62 } DD;
63 ///
64 /// OM_SET
65 METHOD(DGMClassSet, struct opSet *, ops)
67 DD *dd = INST_DATA(cl, obj);
68 struct TagItem *tag;
69 struct TagItem *tstate = ops->ops_AttrList;
70 struct IntuiMessage *imsg;
71 IPTR *ptr = NULL;
72 IPTR *res = NULL;
73 BOOL domethod = FALSE;
76 * Scan tags.
78 while ((tag = NextTagItem(&tstate)))
80 switch (tag->ti_Tag)
82 case DGM_Result:
84 * Pickup result storage. We return the result
85 * in a pointer passed to us to avoid the system
86 * glitch (or is it a real bug?).
88 res = ( IPTR * )tag->ti_Data;
89 break;
91 case DGM_Object:
93 * Pickup target object.
95 dd->dd_Target = (Object *)tag->ti_Data;
96 break;
98 case DGM_IntuiMsg:
99 if ((imsg = (struct IntuiMessage *)(tag->ti_Data)))
101 dd->dd_Window = imsg->IDCMPWindow;
103 dd->ie.ie_NextEvent = NULL;
104 dd->ie.ie_Class = IECLASS_RAWMOUSE;
105 dd->ie.ie_Code = imsg->Code;
106 dd->ie.ie_Qualifier = imsg->Qualifier;
107 dd->ie.ie_X = imsg->MouseX;
108 dd->ie.ie_Y = imsg->MouseY;
110 break;
112 case DGM_DoMethod:
113 domethod = TRUE;
116 * Get a pointer to the message.
118 ptr = (IPTR *)tag->ti_Data;
121 * What kind of method?
123 switch (*ptr)
125 case OM_NEW:
126 case OM_SET:
127 case OM_UPDATE:
128 case OM_NOTIFY:
130 * These get the GadgetInfo as the
131 * third long-word.
133 ptr[2] = (IPTR)ops->ops_GInfo;
134 break;
136 default:
138 * All the rest get it at the
139 * second long-word.
141 ptr[1] = (IPTR)ops->ops_GInfo;
142 break;
144 break;
149 * Blast off method.
151 if (domethod)
153 if (dd->dd_Target)
155 *res = AsmDoMethodA(dd->dd_Target, (Msg)ptr);
157 * Return result for compatibility reasons.
160 return (IPTR)(*res);
162 return (IPTR)1;
164 METHOD_END
166 /// BGUI_DoGadgetMethod(obj, win, req)
168 * Emulate the OS 3.0 DoGadgetMethod call.
170 makeproto ULONG myDoGadgetMethod(Object *obj, struct Window *win, struct Requester *req, IPTR methodid, ... )
172 AROS_SLOWSTACKMETHODS_PRE(methodid)
173 retval = BGUI_DoGadgetMethodA(obj, win, req, AROS_SLOWSTACKMETHODS_ARG(methodid));
174 AROS_SLOWSTACKMETHODS_POST
178 * Emulate the intuition DoGadgetMethod() call.
180 #ifdef __AROS__
181 //makearosproto
182 AROS_LH4(ULONG, BGUI_DoGadgetMethodA,
183 AROS_LHA(Object *, obj, A0),
184 AROS_LHA(struct Window *, win, A1),
185 AROS_LHA(struct Requester *, req, A2),
186 AROS_LHA(Msg, msg, A3),
187 struct Library *, BGUIBase, 11, BGUI)
188 #else
189 makeproto SAVEDS ASM ULONG BGUI_DoGadgetMethodA( REG(a0) Object *obj, REG(a1) struct Window *win, REG(a2) struct Requester *req, REG(a3) Msg msg )
190 #endif
192 AROS_LIBFUNC_INIT
194 Object *dgm;
195 IPTR rc;
198 * Valid window?
200 if (win)
203 * Create DGMClass object.
205 if ((dgm = BGUI_NewObjectA(BGUI_DGM_OBJECT, NULL)))
208 * Send of method to the target. We simple pass the DGMClass
209 * a pointer to the result storage, the target object and the
210 * method to send and the class takes care of the rest :)
212 SetGadgetAttrs((struct Gadget *)dgm, win, req, DGM_Result, &rc, DGM_Object, obj, DGM_DoMethod, msg, TAG_END);
215 * Dispose of the object.
217 AsmDoMethod(dgm, OM_DISPOSE);
220 * Return result.
222 return rc;
227 * Fall back to the AsmDoMethod() call if
228 * an important argument is missing.
230 return (ULONG)AsmDoMethodA(obj, msg);
232 AROS_LIBFUNC_EXIT
235 /// GM_GOACTIVE, GM_HANDLEINPUT
236 METHOD(DGMClassGoActive, struct gpInput *, gpi2)
238 DD *dd = INST_DATA(cl, obj);
239 struct gpInput gpi = *gpi2;
240 struct IBox *bounds = NULL;
241 IPTR rc = 0;
242 Object *target = dd->dd_Target;
244 if (target)
246 if (gpi.MethodID == GM_GOACTIVE)
247 gpi.gpi_IEvent = &dd->ie;
249 Get_Attr(target, BT_HitBox, (IPTR *)&bounds);
250 if (bounds)
252 gpi.gpi_Mouse.X = gpi.gpi_GInfo->gi_Window->MouseX - bounds->Left;
253 gpi.gpi_Mouse.Y = gpi.gpi_GInfo->gi_Window->MouseY - bounds->Top;
257 * Forward the message to the target.
259 SetGadgetAttrs((struct Gadget *)obj, dd->dd_Window, NULL,
260 DGM_Result, &rc, DGM_Object, target, DGM_DoMethod, &gpi, TAG_END);
262 return rc;
264 METHOD_END
266 /// GM_GOINACTIVE
267 METHOD(DGMClassGoInactive, Msg, msg)
269 DD *dd = INST_DATA(cl, obj);
270 IPTR rc = 0;
271 ULONG id;
272 IPTR mouseact = 0, report = FALSE;
273 Object *win = NULL, *target;
275 if ((target = dd->dd_Target))
277 Get_Attr(target, BT_ReportID, &report);
278 Get_Attr(target, BT_ParentWindow, (IPTR *)&win);
279 Get_Attr(target, BT_MouseActivation, &mouseact);
281 * Forward the message to the target.
283 SetGadgetAttrs((struct Gadget *)obj, dd->dd_Window, NULL,
284 DGM_Result, &rc, DGM_Object, target, DGM_DoMethod, msg, TAG_END);
286 if (win && report)
288 id = GADGET(target)->GadgetID;
289 if (dd->ie.ie_Code == IECODE_RBUTTON)
291 AsmDoMethod(win, WM_REPORT_ID, id | WMHI_RMB, 0);
293 if (dd->ie.ie_Code == IECODE_MBUTTON)
295 AsmDoMethod(win, WM_REPORT_ID, id | WMHI_MMB, 0);
299 return rc;
301 METHOD_END
303 /// Class initialization.
305 * Class function table.
307 STATIC DPFUNC ClassFunc[] = {
308 { OM_SET, DGMClassSet },
309 { GM_GOACTIVE, DGMClassGoActive },
310 { GM_HANDLEINPUT, DGMClassGoActive },
311 { GM_GOINACTIVE, DGMClassGoInactive },
312 { DF_END, NULL }
316 * Simple class initialization.
318 makeproto Class *InitDGMClass(void)
320 return BGUI_MakeClass(CLASS_SuperClassID, GadgetClass,
321 CLASS_ObjectSize, sizeof(DD),
322 CLASS_DFTable, ClassFunc,
323 TAG_DONE);
328 * I have created this class for two main reasons:
330 * 1) OS 2.04 compatibility. This way we _always_ get a system build
331 * GadgetInfo structure no matter what OS we run on since the
332 * SetGadgetAttrs() call has been available since V36 (OS 2.0)
333 * of the system.
335 * 2) I am having trouble with the OS 3.0 DoGadgetMethod() call which
336 * does not always returns the result of the called method. Don't
337 * ask why, it just doesn't.
339 * With the aid of this class I get compatibility from OS 2.04 and up
340 * and I work around what seems to be an OS bug while doing it. The only
341 * bad thing may be the (slight) overhead.