grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / gadtools / creategadgeta.c
blob9ba6d358e93d6165e8fc95951f3afa37ab209183
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: gadtools.library function CreateGadgetA()
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include <exec/memory.h>
10 #include <proto/intuition.h>
11 #include <intuition/gadgetclass.h>
12 #include <proto/utility.h>
13 #include "gadtools_intern.h"
15 /*********************************************************************
17 NAME */
18 #include <proto/gadtools.h>
19 #include <exec/types.h>
20 #include <intuition/intuition.h>
21 #include <utility/tagitem.h>
22 #include <libraries/gadtools.h>
24 AROS_LH4(struct Gadget *, CreateGadgetA,
26 /* SYNOPSIS */
27 AROS_LHA(ULONG, kind, D0),
28 AROS_LHA(struct Gadget *, previous, A0),
29 AROS_LHA(struct NewGadget *, ng, A1),
30 AROS_LHA(struct TagItem *, taglist, A2),
32 /* LOCATION */
33 struct Library *, GadToolsBase, 5, GadTools)
35 /* FUNCTION
36 Creates a gadtools gadget.
38 INPUTS
40 kind - Kind of gadget. See <libraries/gadtools.h> for a list of
41 all possible kinds.
42 previous - Pointer to the previous gadget in gadget-list. Create the
43 first "gadget" with CreateContext(). This may be NULL, in
44 which case CreateGadgetA() fails.
45 ng - Pointer to struct NewGadget. See <libraries/gadtools.h>.
46 taglist - Additional tags. See <libraries/gadtools.h>.
48 RESULT
49 A pointer to a gadget or NULL to indicate an error.
51 NOTES
53 EXAMPLE
55 BUGS
57 SEE ALSO
58 CreateContext(), FreeGadgets(), <libraries/gadtools.h>
60 INTERNALS
62 HISTORY
64 ***************************************************************************/
66 AROS_LIBFUNC_INIT
68 struct Gadget *gad = NULL;
69 struct TagItem stdgadtags[] =
71 {GA_Left , 0L },
72 {GA_Top , 0L },
73 {GA_Width , 0L },
74 {GA_Height , 0L },
75 {GA_IntuiText , (IPTR)NULL },
76 {GA_LabelPlace , (IPTR)GV_LabelPlace_In},
77 {GA_Previous , (IPTR)NULL },
78 {GA_ID , 0L },
79 {GA_DrawInfo , (IPTR)NULL },
80 {GA_UserData , (IPTR)NULL },
81 {TAG_DONE }
84 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: Kind %d Prev 0x%lx NewGadget 0x%lx TagList 0x%lx\n",
85 kind, previous, ng, taglist));
87 if (previous == NULL || ng == NULL || ng->ng_VisualInfo == NULL)
88 return (NULL);
90 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: previous->NextGadget 0x%lx\n",
91 previous->NextGadget));
93 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: Left %d Top %d Width %d Height %d Text 0x%lx <%s>\n",
94 ng->ng_LeftEdge, ng->ng_TopEdge,
95 ng->ng_Width, ng->ng_Height,
96 ng->ng_GadgetText, ng->ng_GadgetText ? ng->ng_GadgetText : "NULL"));
97 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: TextAttr 0x%lx ID %d Flags 0x%08lx VisualInfo 0x%x UserData 0x%x\n",
98 ng->ng_TextAttr, ng->ng_GadgetID,
99 ng->ng_Flags, ng->ng_VisualInfo, ng->ng_UserData));
101 DEBUG_CREATEGADGETA(if (taglist)
103 struct TagItem *tag;
104 APTR state = taglist;
105 while (tag = NextTagItem(&state))
107 dprintf("\t%08lx %08lx\n", tag->ti_Tag,tag->ti_Data);
111 /* Emm: The makeXXX() functions expect this, and with 'normal' object creation,
112 * this is always true. However, with Triton previous->NextGadget is trashed
113 * after a window resize. What Triton does is somewhat questionable, but
114 * setting this pointer doesn't hurt, so...
117 previous->NextGadget = NULL;
119 /* Set the default label place according to the gadget type. */
121 if (kind == LISTVIEW_KIND)
122 stdgadtags[TAG_LabelPlace].ti_Data = GV_LabelPlace_Above;
123 else if (kind != BUTTON_KIND)
124 stdgadtags[TAG_LabelPlace].ti_Data = GV_LabelPlace_Left;
126 stdgadtags[TAG_Left].ti_Data = ng->ng_LeftEdge;
127 stdgadtags[TAG_Top].ti_Data = ng->ng_TopEdge;
128 stdgadtags[TAG_Width].ti_Data = ng->ng_Width;
129 stdgadtags[TAG_Height].ti_Data = ng->ng_Height;
131 if (ng->ng_GadgetText)
133 ULONG old_ng_flags = ng->ng_Flags;
135 if (kind == BUTTON_KIND) ng->ng_Flags &= ~NG_HIGHLABEL;
136 stdgadtags[TAG_IText].ti_Data = (IPTR)makeitext(GTB(GadToolsBase), ng, taglist);
137 if (kind == BUTTON_KIND) ng->ng_Flags = old_ng_flags;
139 if (!stdgadtags[TAG_IText].ti_Data)
141 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: can't make label\n"));
142 return (NULL);
144 } else {
145 stdgadtags[TAG_IText].ti_Tag = TAG_IGNORE;
148 stdgadtags[TAG_Previous].ti_Data = (IPTR)previous;
149 stdgadtags[TAG_ID].ti_Data = ng->ng_GadgetID;
150 stdgadtags[TAG_DrawInfo].ti_Data = (IPTR)(VI(ng->ng_VisualInfo)->vi_dri);
151 stdgadtags[TAG_UserData].ti_Data = (IPTR)ng->ng_UserData;
153 /* Calculate label placement.*/
154 if ((ng->ng_Flags & PLACETEXT_LEFT))
155 stdgadtags[TAG_LabelPlace].ti_Data = GV_LabelPlace_Left;
156 else if ((ng->ng_Flags & PLACETEXT_RIGHT))
157 stdgadtags[TAG_LabelPlace].ti_Data = GV_LabelPlace_Right;
158 else if ((ng->ng_Flags & PLACETEXT_ABOVE))
159 stdgadtags[TAG_LabelPlace].ti_Data = GV_LabelPlace_Above;
160 else if ((ng->ng_Flags & PLACETEXT_BELOW))
161 stdgadtags[TAG_LabelPlace].ti_Data = GV_LabelPlace_Below;
163 switch(kind)
165 case BUTTON_KIND:
166 gad = makebutton(GTB(GadToolsBase),
167 stdgadtags,
168 VI(ng->ng_VisualInfo),
169 taglist);
170 break;
172 case CHECKBOX_KIND:
173 gad = makecheckbox(GTB(GadToolsBase),
174 stdgadtags,
175 VI(ng->ng_VisualInfo),
176 taglist);
177 break;
179 case CYCLE_KIND:
180 gad = makecycle(GTB(GadToolsBase),
181 stdgadtags,
182 VI(ng->ng_VisualInfo),
183 ng->ng_TextAttr,
184 taglist);
185 break;
187 case MX_KIND:
188 gad = makemx(GTB(GadToolsBase),
189 stdgadtags,
190 VI(ng->ng_VisualInfo),
191 ng->ng_TextAttr,
192 taglist);
193 break;
195 case PALETTE_KIND:
196 gad = makepalette(GTB(GadToolsBase),
197 stdgadtags,
198 VI(ng->ng_VisualInfo),
199 taglist);
200 break;
202 case TEXT_KIND:
203 gad = maketext(GTB(GadToolsBase),
204 stdgadtags,
205 VI(ng->ng_VisualInfo),
206 ng->ng_TextAttr,
207 taglist);
208 break;
210 case NUMBER_KIND:
211 gad = makenumber(GTB(GadToolsBase),
212 stdgadtags,
213 VI(ng->ng_VisualInfo),
214 ng->ng_TextAttr,
215 taglist);
216 break;
218 case SLIDER_KIND:
219 gad = makeslider(GTB(GadToolsBase),
220 stdgadtags,
221 VI(ng->ng_VisualInfo),
222 ng->ng_TextAttr,
223 taglist);
225 break;
227 case SCROLLER_KIND:
228 gad = makescroller(GTB(GadToolsBase),
229 stdgadtags,
230 VI(ng->ng_VisualInfo),
231 taglist);
232 break;
234 case STRING_KIND:
235 gad = makestring(GTB(GadToolsBase),
236 stdgadtags,
237 VI(ng->ng_VisualInfo),
238 ng->ng_TextAttr,
239 taglist);
240 break;
242 case INTEGER_KIND:
243 gad = makeinteger(GTB(GadToolsBase),
244 stdgadtags,
245 VI(ng->ng_VisualInfo),
246 ng->ng_TextAttr,
247 taglist);
248 break;
250 case LISTVIEW_KIND:
251 gad = makelistview(GTB(GadToolsBase),
252 stdgadtags,
253 VI(ng->ng_VisualInfo),
254 ng->ng_TextAttr,
255 taglist);
256 break;
258 case GENERIC_KIND:
259 gad = makegeneric(GTB(GadToolsBase),
260 stdgadtags,
261 VI(ng->ng_VisualInfo),
262 ng->ng_TextAttr,
263 taglist);
264 break;
266 } /* switch(kind) */
268 if (gad)
270 #if 0
271 struct Gadget *gad2 = gad;
272 while (gad2)
274 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: created gadget 0x%lx\n", gad2));
275 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: mark GTYPE_GADTOOLS, GadgetID %ld UserData 0x%lx\n",gad->GadgetID,gad->UserData));
276 gad2->GadgetType |= GTYP_GADTOOLS;
277 gad2 = gad2->NextGadget;
279 #endif
282 * Scan through all childgadgets and the return the last one, so we return
283 * a ptr with no NextGadget which would collide with our triton fix above
285 while (gad->NextGadget)
287 gad = gad->NextGadget;
289 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: return gadget 0x%lx\n", gad));
291 else
293 previous->NextGadget = NULL;
294 FreeVec((APTR)stdgadtags[TAG_IText].ti_Data);
297 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: Return 0x%x\n", gad));
299 return (gad);
300 AROS_LIBFUNC_EXIT
302 } /* CreateGadgetA */