New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / intuition / removeglist.c
blob52cea75bf6c99c06cfaf803c2c437521f281d8a4
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/layers.h>
8 #include "intuition_intern.h"
9 #include "inputhandler_actions.h"
10 #include "inputhandler.h"
11 #include <intuition/gadgetclass.h>
13 struct RemoveGListActionMsg
15 struct IntuiActionMsg msg;
16 struct Window *window;
17 struct Gadget *gadget;
18 LONG numGad;
19 UWORD count;
20 BOOL success;
23 static VOID int_removeglist(struct RemoveGListActionMsg *msg,
24 struct IntuitionBase *IntuitionBase);
26 /*****************************************************************************
28 NAME */
29 #include <intuition/intuition.h>
30 #include <proto/intuition.h>
32 AROS_LH3(UWORD, RemoveGList,
34 /* SYNOPSIS */
35 AROS_LHA(struct Window *, remPtr, A0),
36 AROS_LHA(struct Gadget *, gadget, A1),
37 AROS_LHA(LONG , numGad, D0),
39 /* LOCATION */
40 struct IntuitionBase *, IntuitionBase, 74, Intuition)
42 /* FUNCTION
44 INPUTS
46 RESULT
48 NOTES
50 EXAMPLE
52 BUGS
54 SEE ALSO
56 INTERNALS
58 HISTORY
60 *****************************************************************************/
62 AROS_LIBFUNC_INIT
63 AROS_LIBBASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
65 struct Gadget *pred;
66 struct Gadget *last;
67 struct IIHData *iihdata;
68 LONG numGad2;
69 UWORD count;
70 BOOL done = TRUE;
72 EXTENDWORD(numGad);
74 DEBUG_REMOVEGLIST(dprintf("RemoveGList: Window 0x%lx Gadgets 0x%lx Num %ld\n",
75 remPtr, gadget, numGad));
77 if (!numGad) return ~0;
78 if (!gadget) return ~0;
79 if (!remPtr) return ~0;
81 #ifdef USEGADGETLOCK
82 LOCKGADGET
83 #else
84 LOCKWINDOWLAYERS(remPtr);
85 #endif
87 iihdata = (struct IIHData *)GetPrivIBase(IntuitionBase)->InputHandler->is_Data;
88 pred = (struct Gadget *)&remPtr->FirstGadget;
89 count = 0;
90 numGad2 = numGad;
92 while (pred->NextGadget && pred->NextGadget != gadget)
94 pred = pred->NextGadget;
95 count ++;
98 if (pred->NextGadget)
100 /* Check if one of the gadgets to be removed is the active gadget.
101 If it is, then make it inactive! */
104 for (last = gadget; last && numGad2--; last = last->NextGadget)
106 if ((iihdata->ActiveGadget == last) || (iihdata->ActiveSysGadget == last))
108 done = FALSE;
109 break;
113 if (done)
115 for (last = gadget; last->NextGadget && --numGad; last = last->NextGadget) ;
117 pred->NextGadget = last->NextGadget;
119 /* stegerg: don't do this. DOpus for example relies on gadget->NextGadget
120 not being touched */
121 /* Emm: but the autodocs say it is done for V36 ??? */
122 #if 0
123 last->NextGadget = NULL;
124 #endif
128 } /* if (pred->NextGadget) */
129 else
131 count = ~0;
134 #ifdef USEGADGETLOCK
135 UNLOCKGADGET
136 #else
137 UNLOCKWINDOWLAYERS(remPtr);
138 #endif
140 /* We tried to remove the active gadget. This must be delayed until LMB
141 * is released.
143 if (!done)
145 struct RemoveGListActionMsg msg;
147 msg.window = remPtr;
148 msg.gadget = gadget;
149 msg.numGad = numGad;
153 DEBUG_REMOVEGLIST(dprintf("RemoveGList: trying to remove the active gadget.\n"));
154 DoSyncAction((APTR)int_removeglist, &msg.msg, IntuitionBase);
156 while (!msg.success);
158 count = msg.count;
161 DEBUG_REMOVEGLIST(dprintf("RemoveGList: removed %ld gadgets\n",count));
163 return count;
165 AROS_LIBFUNC_EXIT
167 } /* RemoveGList */
169 static VOID int_removeglist(struct RemoveGListActionMsg *msg,
170 struct IntuitionBase *IntuitionBase)
172 struct Window *remPtr = msg->window;
173 struct Gadget *gadget = msg->gadget;
174 LONG numGad = msg->numGad;
175 struct Gadget *pred;
176 struct Gadget *last;
177 struct IIHData *iihdata;
178 LONG numGad2;
179 UWORD count;
181 DEBUG_REMOVEGLIST(dprintf("IntRemoveGList: Window 0x%lx Gadgets 0x%lx Num %ld\n",
182 remPtr, gadget, numGad));
184 iihdata = (struct IIHData *)GetPrivIBase(IntuitionBase)->InputHandler->is_Data;
186 /* Don't remove the gadget until the LMB is released. */
187 if (iihdata->ActQualifier & IEQUALIFIER_LEFTBUTTON)
189 DEBUG_REMOVEGLIST(dprintf("IntRemoveGList: LMB down\n"));
190 msg->success = FALSE;
191 return;
194 #ifdef USEGADGETLOCK
195 LOCKGADGET
196 #else
197 LOCKWINDOWLAYERS(remPtr);
198 #endif
200 pred = (struct Gadget *)&remPtr->FirstGadget;
202 count = 0;
203 numGad2 = numGad;
205 while (pred->NextGadget && pred->NextGadget != gadget)
207 pred = pred->NextGadget;
208 count ++;
211 if (pred->NextGadget)
213 /* Check if one of the gadgets to be removed is the active gadget.
214 If it is, then make it inactive! If we got here, one of them was
215 the active gadget at the time of RemoveGList, but this may have
216 changed. */
218 for (last = gadget; last && numGad2--; last = last->NextGadget)
220 if ((iihdata->ActiveGadget == last) || (iihdata->ActiveSysGadget == last))
222 switch(last->GadgetType & GTYP_GTYPEMASK)
224 case GTYP_CUSTOMGADGET:
226 struct gpGoInactive gpgi;
228 gpgi.MethodID = GM_GOINACTIVE;
229 gpgi.gpgi_GInfo = NULL;
230 gpgi.gpgi_Abort = 1;
232 DoGadgetMethodA(last, remPtr, NULL, (Msg)&gpgi);
234 if (SYSGADGET_ACTIVE)
236 if (IS_BOOPSI_GADGET(iihdata->ActiveSysGadget))
238 DoGadgetMethodA(iihdata->ActiveSysGadget, remPtr, NULL, (Msg)&gpgi);
240 iihdata->ActiveSysGadget = NULL;
243 break;
247 last->Activation &= ~GACT_ACTIVEGADGET;
248 iihdata->ActiveGadget = NULL;
252 for (last = gadget; last->NextGadget && --numGad; last = last->NextGadget) ;
254 pred->NextGadget = last->NextGadget;
256 /* stegerg: don't do this. DOpus for example relies on gadget->NextGadget
257 not being touched */
258 /* Emm: but the autodocs say it is done for V36 ??? */
259 #if 0
260 last->NextGadget = NULL;
261 #endif
263 } /* if (pred->NextGadget) */
264 else
266 count = ~0;
269 #ifdef USEGADGETLOCK
270 UNLOCKGADGET
271 #else
272 UNLOCKWINDOWLAYERS(remPtr);
273 #endif
275 DEBUG_REMOVEGLIST(dprintf("IntRemoveGList: done\n"));
277 msg->count = count;
278 msg->success = TRUE;