added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / intuition / removeglist.c
blobf702b5fdce21a7cf7d5b2d06bbc663c6b8f319d6
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 <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
64 struct Gadget *pred;
65 struct Gadget *last;
66 struct IIHData *iihdata;
67 LONG numGad2;
68 UWORD count;
69 BOOL done = TRUE;
71 EXTENDWORD(numGad);
73 DEBUG_REMOVEGLIST(dprintf("RemoveGList: Window 0x%lx Gadgets 0x%lx Num %ld\n",
74 remPtr, gadget, numGad));
76 if (!numGad) return ~0;
77 if (!gadget) return ~0;
78 if (!remPtr) return ~0;
80 #ifdef USEGADGETLOCK
81 LOCKGADGET
82 #else
83 LOCKWINDOWLAYERS(remPtr);
84 #endif
86 iihdata = (struct IIHData *)GetPrivIBase(IntuitionBase)->InputHandler->is_Data;
87 pred = (struct Gadget *)&remPtr->FirstGadget;
88 count = 0;
89 numGad2 = numGad;
91 while (pred->NextGadget && pred->NextGadget != gadget)
93 pred = pred->NextGadget;
94 count ++;
97 if (pred->NextGadget)
99 /* Check if one of the gadgets to be removed is the active gadget.
100 If it is, then make it inactive! */
103 for (last = gadget; last && numGad2--; last = last->NextGadget)
105 if ((iihdata->ActiveGadget == last) || (iihdata->ActiveSysGadget == last))
107 done = FALSE;
108 break;
112 if (done)
114 for (last = gadget; last->NextGadget && --numGad; last = last->NextGadget) ;
116 pred->NextGadget = last->NextGadget;
118 /* stegerg: don't do this. DOpus for example relies on gadget->NextGadget
119 not being touched */
120 /* Emm: but the autodocs say it is done for V36 ??? */
121 #if 0
122 last->NextGadget = NULL;
123 #endif
127 } /* if (pred->NextGadget) */
128 else
130 count = ~0;
133 #ifdef USEGADGETLOCK
134 UNLOCKGADGET
135 #else
136 UNLOCKWINDOWLAYERS(remPtr);
137 #endif
139 /* We tried to remove the active gadget. This must be delayed until LMB
140 * is released.
142 if (!done)
144 struct RemoveGListActionMsg msg;
146 msg.window = remPtr;
147 msg.gadget = gadget;
148 msg.numGad = numGad;
152 DEBUG_REMOVEGLIST(dprintf("RemoveGList: trying to remove the active gadget.\n"));
153 DoSyncAction((APTR)int_removeglist, &msg.msg, IntuitionBase);
155 while (!msg.success);
157 count = msg.count;
160 DEBUG_REMOVEGLIST(dprintf("RemoveGList: removed %ld gadgets\n",count));
162 return count;
164 AROS_LIBFUNC_EXIT
166 } /* RemoveGList */
168 static VOID int_removeglist(struct RemoveGListActionMsg *msg,
169 struct IntuitionBase *IntuitionBase)
171 struct Window *remPtr = msg->window;
172 struct Gadget *gadget = msg->gadget;
173 LONG numGad = msg->numGad;
174 struct Gadget *pred;
175 struct Gadget *last;
176 struct IIHData *iihdata;
177 LONG numGad2;
178 UWORD count;
180 DEBUG_REMOVEGLIST(dprintf("IntRemoveGList: Window 0x%lx Gadgets 0x%lx Num %ld\n",
181 remPtr, gadget, numGad));
183 iihdata = (struct IIHData *)GetPrivIBase(IntuitionBase)->InputHandler->is_Data;
185 /* Don't remove the gadget until the LMB is released. */
186 if (iihdata->ActQualifier & IEQUALIFIER_LEFTBUTTON)
188 DEBUG_REMOVEGLIST(dprintf("IntRemoveGList: LMB down\n"));
189 msg->success = FALSE;
190 return;
193 #ifdef USEGADGETLOCK
194 LOCKGADGET
195 #else
196 LOCKWINDOWLAYERS(remPtr);
197 #endif
199 pred = (struct Gadget *)&remPtr->FirstGadget;
201 count = 0;
202 numGad2 = numGad;
204 while (pred->NextGadget && pred->NextGadget != gadget)
206 pred = pred->NextGadget;
207 count ++;
210 if (pred->NextGadget)
212 /* Check if one of the gadgets to be removed is the active gadget.
213 If it is, then make it inactive! If we got here, one of them was
214 the active gadget at the time of RemoveGList, but this may have
215 changed. */
217 for (last = gadget; last && numGad2--; last = last->NextGadget)
219 if ((iihdata->ActiveGadget == last) || (iihdata->ActiveSysGadget == last))
221 switch(last->GadgetType & GTYP_GTYPEMASK)
223 case GTYP_CUSTOMGADGET:
225 struct gpGoInactive gpgi;
227 gpgi.MethodID = GM_GOINACTIVE;
228 gpgi.gpgi_GInfo = NULL;
229 gpgi.gpgi_Abort = 1;
231 DoGadgetMethodA(last, remPtr, NULL, (Msg)&gpgi);
233 if (SYSGADGET_ACTIVE)
235 if (IS_BOOPSI_GADGET(iihdata->ActiveSysGadget))
237 DoGadgetMethodA(iihdata->ActiveSysGadget, remPtr, NULL, (Msg)&gpgi);
239 iihdata->ActiveSysGadget = NULL;
242 break;
246 last->Activation &= ~GACT_ACTIVEGADGET;
247 iihdata->ActiveGadget = NULL;
251 for (last = gadget; last->NextGadget && --numGad; last = last->NextGadget) ;
253 pred->NextGadget = last->NextGadget;
255 /* stegerg: don't do this. DOpus for example relies on gadget->NextGadget
256 not being touched */
257 /* Emm: but the autodocs say it is done for V36 ??? */
258 #if 0
259 last->NextGadget = NULL;
260 #endif
262 } /* if (pred->NextGadget) */
263 else
265 count = ~0;
268 #ifdef USEGADGETLOCK
269 UNLOCKGADGET
270 #else
271 UNLOCKWINDOWLAYERS(remPtr);
272 #endif
274 DEBUG_REMOVEGLIST(dprintf("IntRemoveGList: done\n"));
276 msg->count = count;
277 msg->success = TRUE;