This should solve an error which made the nightly build fail with:
[AROS-Contrib.git] / bgui / aslreqclass.c
blobaf7cc014194ce034cf74e64d735f3a5410d1485a
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * aslreqclass.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
15 #include "include/classdefs.h"
17 #ifdef __AROS__
18 extern struct Library * AslBase;
19 #endif
21 /// Class definitions.
23 * Object instance data.
25 typedef struct ad_ {
26 APTR ad_Requester; /* Requester */
27 ULONG ad_Type; /* Requester type */
28 WORD ad_Left; /* Requester left */
29 WORD ad_Top; /* Requester top */
30 UWORD ad_Width; /* Requester width */
31 UWORD ad_Height; /* Requester height */
32 struct TagItem *ad_ASLTags; /* Copy of ASL tags */
33 } AD;
35 #define AD_ENTRY(tag, offset, flags) PACK_ENTRY(ASLREQ_TAGSTART, tag, ad_, offset, flags)
36 #define AD_FLAG(tag, flag) PACK_LONGBIT(ASLREQ_TAGSTART, tag, ad_, ad_Flags, PKCTRL_BIT, flag)
38 static ULONG AslPackTable[] =
40 PACK_STARTTABLE(ASLREQ_TAGSTART),
42 AD_ENTRY(ASLREQ_Requester, ad_Requester, PKCTRL_ULONG),
43 AD_ENTRY(ASLREQ_Type, ad_Type, PKCTRL_ULONG),
44 AD_ENTRY(ASLREQ_Left, ad_Left, PKCTRL_WORD),
45 AD_ENTRY(ASLREQ_Top, ad_Top, PKCTRL_WORD),
46 AD_ENTRY(ASLREQ_Width, ad_Width, PKCTRL_UWORD),
47 AD_ENTRY(ASLREQ_Height, ad_Height, PKCTRL_UWORD),
49 PACK_ENDTABLE
51 ///
53 /// OM_NEW
55 * Create a shiny new object.
57 METHOD(AslReqClassNew, struct opSet *, ops)
59 AD *ad;
60 ULONG rc;
63 * First we let the superclass
64 * create the object.
66 if (rc = AsmDoSuperMethodA(cl, obj, (Msg)ops))
69 * Get us the instance data.
71 ad = INST_DATA(cl, rc);
74 * Setup the defaults.
76 ad->ad_Left = 30;
77 ad->ad_Top = 20;
78 ad->ad_Width = 320;
79 ad->ad_Height = 180;
80 ad->ad_ASLTags = CloneTagItems(NULL);
83 * Setup user attributes.
85 if (AsmCoerceMethod(cl, (Object *)rc, OM_SET, ops, NULL) != ASLREQ_OK)
88 * Failure.
90 AsmCoerceMethod(cl, (Object *)rc, OM_DISPOSE);
91 rc = 0;
94 return rc;
96 METHOD_END
97 ///
98 /// OM_DISPOSE
100 * They want us gone.
102 METHOD(AslReqClassDispose, Msg, msg)
104 AD *ad = INST_DATA(cl, obj);
107 * Free requester, if it still exists somehow.
109 FreeAslRequest(ad->ad_Requester);
112 * Free tag copy.
114 FreeTagItems(ad->ad_ASLTags);
117 * The superclass does the rest.
119 return AsmDoSuperMethodA(cl, obj, msg);
121 METHOD_END
123 /// OM_SET, OM_UPDATE
125 * Change one or more of the object
126 * it's attributes.
128 METHOD(AslReqClassSetUpdate, struct opSet *, ops)
130 AD *ad = INST_DATA(cl, obj);
131 struct TagItem *tstate, *tags, *tag;
132 ULONG attr, data;
133 BOOL asl = FALSE;
136 * Filter out values in old taglist that will be replaced,
137 * and values in new taglist that are not ASL tags.
138 * Process the non-ASL tags before disposal.
140 tstate = tags = CloneTagItems(ops->ops_AttrList);
142 while (tag = NextTagItem(&tstate))
144 attr = tag->ti_Tag;
145 data = tag->ti_Data;
147 if ((attr >= ASL_TB) && (attr < ASL_TB + 0x10000))
149 asl = TRUE;
151 else
153 switch (attr)
155 case ASLREQ_Bounds:
156 *((struct IBox *)&ad->ad_Left) = *((struct IBox *)data);
157 break;
158 default:
160 * Try to process it.
162 BGUI_PackStructureTag((UBYTE *)ad, AslPackTable, attr, data);
163 break;
166 * Kill it.
168 tag->ti_Tag = TAG_IGNORE;
173 * Merge the old with the new.
175 if (asl)
177 tag = BGUI_MergeTagItems(ad->ad_ASLTags, tags);
178 FreeTagItems(ad->ad_ASLTags);
179 ad->ad_ASLTags = BGUI_CleanTagItems(tag, 1);
182 FreeTagItems(tags);
184 return ASLREQ_OK;
186 METHOD_END
188 /// OM_GET
190 * Give one of the attributes.
192 METHOD(AslReqClassGet, struct opGet *, opg)
194 AD *ad = INST_DATA(cl, obj);
195 struct TagItem *tag;
196 ULONG rc, attr = opg->opg_AttrID, *store = opg->opg_Storage;
198 if (tag = FindTagItem(attr, ad->ad_ASLTags))
200 *store = tag->ti_Data;
201 rc = 1;
203 else
205 rc = BGUI_UnpackStructureTag((UBYTE *)ad, AslPackTable, attr, store);
206 if (!rc) rc = AsmDoSuperMethodA(cl, obj, (Msg)opg);
208 return rc;
210 METHOD_END
212 /// ASLM_ALLOCREQUEST
214 * Allocate requester.
216 METHOD(AslReqClassAllocRequest, Msg, msg)
218 AD *ad = INST_DATA(cl, obj);
220 ad->ad_Requester = AllocAslRequestTags(ad->ad_Type,
221 ASL_LeftEdge, ad->ad_Left, ASL_TopEdge, ad->ad_Top,
222 ASL_Width, ad->ad_Width, ASL_Height, ad->ad_Height,
223 TAG_DONE);
225 return (ULONG)ad->ad_Requester;
227 METHOD_END
229 /// ASLM_REQUEST
231 * Show requester.
233 METHOD(AslReqClassRequest, Msg, msg)
235 AD *ad = INST_DATA(cl, obj);
236 ULONG rc = 0;
238 if (ad->ad_Requester)
240 rc = AslRequest(ad->ad_Requester, ad->ad_ASLTags);
242 return rc;
244 METHOD_END
246 /// ASLM_FREEREQUEST
248 * Free requester.
250 METHOD(AslReqClassFreeRequest, Msg, msg)
252 AD *ad = INST_DATA(cl, obj);
254 FreeAslRequest(ad->ad_Requester);
255 ad->ad_Requester = NULL;
257 return 1;
259 METHOD_END
262 /// Class initialization.
264 * Function table.
266 STATIC DPFUNC ClassFunc[] = {
267 OM_NEW, (FUNCPTR)AslReqClassNew,
268 OM_SET, (FUNCPTR)AslReqClassSetUpdate,
269 OM_UPDATE, (FUNCPTR)AslReqClassSetUpdate,
270 OM_GET, (FUNCPTR)AslReqClassGet,
271 OM_DISPOSE, (FUNCPTR)AslReqClassDispose,
272 ASLM_ALLOCREQUEST, (FUNCPTR)AslReqClassAllocRequest,
273 ASLM_REQUEST, (FUNCPTR)AslReqClassRequest,
274 ASLM_FREEREQUEST, (FUNCPTR)AslReqClassFreeRequest,
275 DF_END, NULL
279 * Simple class initialization.
281 makeproto Class *InitAslReqClass(void)
283 return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_ROOT_OBJECT,
284 CLASS_ObjectSize, sizeof(AD),
285 CLASS_DFTable, ClassFunc,
286 TAG_DONE);