2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <proto/exec.h>
9 #include "gadtools_intern.h"
11 /*********************************************************************
14 #include <proto/gadtools.h>
15 #include <intuition/intuition.h>
17 AROS_LH1(VOID
, FreeGadgets
,
20 AROS_LHA(struct Gadget
*, glist
, A0
),
23 struct Library
*, GadToolsBase
, 6, GadTools
)
26 Frees all gadtools gadgets in a linked list of gadgets.
29 glist - pointer to the first gadget to be freed, may be NULL.
46 ***************************************************************************/
50 struct Gadget
*lastgad
= NULL
, *nextgad
= NULL
;
52 DEBUG_FREEGADGETS(dprintf("FreeGadgets: glist 0x%lx\n", glist
));
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
);
73 } /* if ((glist->GadgetType & GTYP_GTYPEMASK) == GTYP_CUSTOMGADGET) */
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
;
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
));
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) */
119 DEBUG_FREEGADGETS(dprintf("FreeGadgets: skip non-gadtools 0x%lx\n", glist
));
121 lastgad
->NextGadget
= glist
;
125 } /* for (; glist; glist = nextgad) */
128 lastgad
->NextGadget
= NULL
;
130 DEBUG_FREEGADGETS(dprintf("FreeGadgets: done\n"));