2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: gadtools.library function CreateGadgetA()
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 /*********************************************************************
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
,
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
),
33 struct Library
*, GadToolsBase
, 5, GadTools
)
36 Creates a gadtools gadget.
40 kind - Kind of gadget. See <libraries/gadtools.h> for a list of
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>.
49 A pointer to a gadget or NULL to indicate an error.
58 CreateContext(), FreeGadgets(), <libraries/gadtools.h>
64 ***************************************************************************/
68 struct Gadget
*gad
= NULL
;
69 struct TagItem stdgadtags
[] =
75 {GA_IntuiText
, (IPTR
)NULL
},
76 {GA_LabelPlace
, (IPTR
)GV_LabelPlace_In
},
77 {GA_Previous
, (IPTR
)NULL
},
79 {GA_DrawInfo
, (IPTR
)NULL
},
80 {GA_UserData
, (IPTR
)NULL
},
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
)
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
)
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"));
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
;
166 gad
= makebutton(GTB(GadToolsBase
),
168 VI(ng
->ng_VisualInfo
),
173 gad
= makecheckbox(GTB(GadToolsBase
),
175 VI(ng
->ng_VisualInfo
),
180 gad
= makecycle(GTB(GadToolsBase
),
182 VI(ng
->ng_VisualInfo
),
188 gad
= makemx(GTB(GadToolsBase
),
190 VI(ng
->ng_VisualInfo
),
196 gad
= makepalette(GTB(GadToolsBase
),
198 VI(ng
->ng_VisualInfo
),
203 gad
= maketext(GTB(GadToolsBase
),
205 VI(ng
->ng_VisualInfo
),
211 gad
= makenumber(GTB(GadToolsBase
),
213 VI(ng
->ng_VisualInfo
),
219 gad
= makeslider(GTB(GadToolsBase
),
221 VI(ng
->ng_VisualInfo
),
228 gad
= makescroller(GTB(GadToolsBase
),
230 VI(ng
->ng_VisualInfo
),
235 gad
= makestring(GTB(GadToolsBase
),
237 VI(ng
->ng_VisualInfo
),
243 gad
= makeinteger(GTB(GadToolsBase
),
245 VI(ng
->ng_VisualInfo
),
251 gad
= makelistview(GTB(GadToolsBase
),
253 VI(ng
->ng_VisualInfo
),
259 gad
= makegeneric(GTB(GadToolsBase
),
261 VI(ng
->ng_VisualInfo
),
271 struct Gadget
*gad2
= gad
;
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
;
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
));
293 previous
->NextGadget
= NULL
;
294 FreeVec((APTR
)stdgadtags
[TAG_IText
].ti_Data
);
297 DEBUG_CREATEGADGETA(dprintf("CreateGadgetA: Return 0x%x\n", gad
));
302 } /* CreateGadgetA */