grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / gadtools / freegadgets.c
blobcb92df240b6061909c4d022fcb387f5035a63857
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include "gadtools_intern.h"
11 /*********************************************************************
13 NAME */
14 #include <proto/gadtools.h>
15 #include <intuition/intuition.h>
17 AROS_LH1(VOID, FreeGadgets,
19 /* SYNOPSIS */
20 AROS_LHA(struct Gadget *, glist, A0),
22 /* LOCATION */
23 struct Library *, GadToolsBase, 6, GadTools)
25 /* FUNCTION
26 Frees all gadtools gadgets in a linked list of gadgets.
28 INPUTS
29 glist - pointer to the first gadget to be freed, may be NULL.
31 RESULT
33 NOTES
35 EXAMPLE
37 BUGS
39 SEE ALSO
40 CreateGadgetA()
42 INTERNALS
44 HISTORY
46 ***************************************************************************/
48 AROS_LIBFUNC_INIT
50 struct Gadget *lastgad = NULL, *nextgad = NULL;
52 DEBUG_FREEGADGETS(dprintf("FreeGadgets: glist 0x%lx\n", glist));
54 if (!glist)
55 return;
57 for (; glist; glist = nextgad)
59 nextgad = glist->NextGadget;
60 if (glist->GadgetType & GTYP_GADTOOLS)
62 if ((glist->GadgetType & GTYP_GTYPEMASK) == GTYP_CUSTOMGADGET)
64 DEBUG_FREEGADGETS(dprintf("FreeGadgets: free gadget 0x%lx\n", glist));
66 /* must check this, because arrowclass uses GA_LabelImage! */
67 if ((glist->Flags & GFLG_LABELMASK) == GFLG_LABELITEXT)
69 freeitext(GTB(GadToolsBase), glist->GadgetText);
71 DisposeObject(glist);
73 } /* if ((glist->GadgetType & GTYP_GTYPEMASK) == GTYP_CUSTOMGADGET) */
74 else
76 struct GT_ContextGadget *contextgad = (struct GT_ContextGadget *)glist;
77 struct GT_GenericGadget *genericgad = (struct GT_GenericGadget *)glist;
79 if ( (contextgad->magic == CONTEXT_MAGIC) &&
80 (contextgad->magic2 == CONTEXT_MAGIC2) )
82 /* This is a GadTools Context Gadget */
84 if (contextgad->gtmsg_used)
86 /* App is calling FreeGadgets() while still holding unreplied GT Messages.
87 Delay killing of context gad because the gtmsg is embedded in it.
88 Kill will happen in GT_PostFilterImsg() */
90 DEBUG_FREEGADGETS(dprintf("FreeGadgets: delaying freeing of context 0x%lx\n", glist));
92 contextgad->killme = TRUE;
94 else
96 DEBUG_FREEGADGETS(dprintf("FreeGadgets: free context 0x%lx\n", glist));
97 FreeMem(glist, sizeof(struct GT_ContextGadget));
100 else if ( (genericgad->magic == GENERIC_MAGIC) &&
101 (genericgad->magic2 == GENERIC_MAGIC2) )
103 /* This is a GadTools Generic Kind Gadget */
105 DEBUG_FREEGADGETS(dprintf("FreeGadgets: free generic 0x%lx\n", glist));
106 freeitext(GTB(GadToolsBase), ((struct GT_GenericGadget *)glist)->itext);
107 FreeMem(glist, sizeof(struct GT_GenericGadget));
109 else
111 DEBUG_FREEGADGETS(dprintf("FreeGadgets: bad gadget 0x%lx\n", glist));
114 } /* if ((glist->GadgetType & GTYP_GTYPEMASK) == GTYP_CUSTOMGADGET) else ... */
116 } /* if (glist->GadgetType & GTYP_GADTOOLS) */
117 else
119 DEBUG_FREEGADGETS(dprintf("FreeGadgets: skip non-gadtools 0x%lx\n", glist));
120 if (lastgad != NULL)
121 lastgad->NextGadget = glist;
122 lastgad = glist;
125 } /* for (; glist; glist = nextgad) */
127 if (lastgad != NULL)
128 lastgad->NextGadget = NULL;
130 DEBUG_FREEGADGETS(dprintf("FreeGadgets: done\n"));
132 AROS_LIBFUNC_EXIT
133 } /* FreeGadgets */