define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / rom / intuition / buildeasyrequestargs_morphos.c
blob0ca3deabb6e9afa98abcc46a4ad3fed2f0d2bb03
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #define DEBUG_BUILDEASYREQUEST(x) ;
9 /**********************************************************************************************/
11 #include <stdio.h>
12 #include <stdarg.h>
13 #include <strings.h>
14 #include <clib/macros.h>
15 #include <aros/asmcall.h>
16 #include <proto/exec.h>
17 #include <proto/intuition.h>
18 #include <proto/graphics.h>
19 #include <exec/memory.h>
20 #include <intuition/gadgetclass.h>
21 #include <intuition/imageclass.h>
22 #include <intuition/screens.h>
23 #include <graphics/rastport.h>
24 #include <graphics/gfxmacros.h>
25 #include <utility/tagitem.h>
26 #include "intuition_intern.h"
27 #include "requesters.h"
29 /**********************************************************************************************/
31 static STRPTR *buildeasyreq_makelabels(struct IntRequestUserData *requserdata,STRPTR labeltext,ULONG *args,struct IntuitionBase *IntuitionBase);
32 static int charsinstring(STRPTR string, char c);
34 /*****************************************************************************
36 NAME */
37 #include <proto/intuition.h>
38 #include <exec/types.h>
39 #include <intuition/intuition.h>
41 AROS_LH4(struct Window *, BuildEasyRequestArgs,
43 /* SYNOPSIS */
44 AROS_LHA(struct Window *, RefWindow, A0),
45 AROS_LHA(struct EasyStruct *, easyStruct, A1),
46 AROS_LHA(ULONG , IDCMP, D0),
47 AROS_LHA(APTR , Args, A3),
49 /* LOCATION */
50 struct IntuitionBase *, IntuitionBase, 99, Intuition)
52 /* FUNCTION
53 Opens a requester, which provides one or more choices. The control is
54 returned to the application after the requester was opened. It is
55 handled by subsequent calls to SysReqHandler() and closed by calling
56 FreeSysRequest().
58 INPUTS
59 RefWindow - A reference window. If NULL, the requester opens on
60 the default public screen.
61 easyStruct - The EasyStruct structure (<intuition/intuition.h>),
62 which describes the requester.
63 IDCMP - IDCMP flags, which should satisfy the requester, too. This is
64 useful for requesters, which want to listen to disk changes,
65 etc. Note that this is not a pointer to the flags as in
66 EasyRequestArgs().
67 Args - The arguments for easyStruct->es_TextFormat.
69 RESULT
70 Returns a pointer to the requester. Use this pointer only for calls
71 to SysReqHandler() and FreeSysRequest().
73 NOTES
75 EXAMPLE
77 BUGS
79 SEE ALSO
80 EasyRequestArgs(), SysReqHandler(), FreeSysRequest()
82 INTERNALS
84 HISTORY
86 *****************************************************************************/
88 AROS_LIBFUNC_INIT
90 struct Screen *scr = NULL, *lockedscr = NULL;
91 struct Window *req;
92 //struct Gadget *gadgets;
93 STRPTR reqtitle;
94 struct IntRequestUserData *requserdata;
95 APTR nextarg = Args;
97 DEBUG_BUILDEASYREQUEST(dprintf("intrequest_buildeasyrequest: window 0x%lx easystruct 0x%lx IDCMPFlags 0x%lx args 0x%lx\n",
98 (ULONG) RefWindow,
99 (ULONG) easyStruct,
100 IDCMP,
101 (ULONG) Args));
103 if (!easyStruct)
104 return FALSE;
106 DEBUG_BUILDEASYREQUEST(dprintf("intrequest_buildeasyrequest: easy title <%s> Format <%s> Gadgets <%s>\n",
107 easyStruct->es_Title,
108 easyStruct->es_TextFormat,
109 easyStruct->es_GadgetFormat));
111 /* get requester title */
112 reqtitle = easyStruct->es_Title;
113 if ((!reqtitle) && (RefWindow))
114 reqtitle = RefWindow->Title;
116 if (!reqtitle) reqtitle = "System Request"; /* stegerg: should be localized */
118 /* get screen and screendrawinfo */
119 if (RefWindow)
120 scr = RefWindow->WScreen;
122 if (!scr)
124 struct Process *proc = (struct Process *)FindTask(0);
125 if (proc->pr_Task.tc_Node.ln_Type == NT_PROCESS)
127 if (proc->pr_WindowPtr && (proc->pr_WindowPtr != (struct Window *)~0)) scr = ((struct Window *)(proc->pr_WindowPtr))->WScreen;
132 if (!scr)
134 scr = LockPubScreen(NULL);
135 if (!scr)
136 return FALSE;
137 lockedscr = scr;
140 requserdata = AllocVec(sizeof (struct IntRequestUserData),MEMF_PUBLIC|MEMF_CLEAR);
141 if (!requserdata) goto fail;
143 requserdata->ReqScreen = scr;
145 requserdata->Text = intrequest_createitext(requserdata,easyStruct->es_TextFormat,&nextarg,IntuitionBase);
146 if (!requserdata->Text) goto fail;
148 /* create everything */
149 requserdata->GadgetLabels = buildeasyreq_makelabels(requserdata,
150 easyStruct->es_GadgetFormat,nextarg,
151 IntuitionBase);
152 if (!requserdata->GadgetLabels) goto fail;
154 requserdata->ReqGadgets = AllocVec(requserdata->NumGadgets * (sizeof (struct RequesterGadget)),MEMF_PUBLIC);
155 if (!requserdata->ReqGadgets) goto fail;
157 intrequest_initeasyreq(requserdata,(struct ExtEasyStruct *)easyStruct,IntuitionBase);
158 intrequest_layoutrequester(requserdata,IntuitionBase);
159 if (!requserdata->wwidth) goto fail;
161 if (!(intrequest_creategadgets(requserdata,IntuitionBase))) goto fail;
164 struct TagItem win_tags[] =
166 { WA_Width , requserdata->wwidth },
167 { WA_Height , requserdata->wheight },
168 { WA_Left , (scr->Width/2) - (requserdata->wwidth/2) },
169 { WA_Top , (scr->Height/2) - (requserdata->wheight/2) },
170 { WA_IDCMP , IDCMP_GADGETUP | IDCMP_RAWKEY | (IDCMP & ~IDCMP_VANILLAKEY) | IDCMP_REFRESHWINDOW},
171 { WA_Gadgets , (IPTR)requserdata->Gadgets },
172 { WA_Title , (IPTR)reqtitle },
173 { (lockedscr ? WA_PubScreen : WA_CustomScreen), (IPTR)scr },
174 { WA_Flags , WFLG_DRAGBAR |
175 WFLG_DEPTHGADGET |
176 WFLG_ACTIVATE |
177 WFLG_SIMPLE_REFRESH |
178 WFLG_RMBTRAP },
179 { WA_SkinInfo , NULL },
180 { (requserdata->backfilldata.image) ? WA_BackFill : TAG_IGNORE, (ULONG)&requserdata->backfillhook},
181 {TAG_DONE }
184 req = OpenWindowTagList(NULL, win_tags);
187 if (req)
190 if (lockedscr) UnlockPubScreen(NULL, lockedscr);
192 req->UserData = (BYTE *)requserdata;
193 requserdata->IDCMP = IDCMP;
194 requserdata->ReqWindow = req;
196 intrequest_drawrequester(requserdata,IntuitionBase);
198 return req;
201 fail:
203 if (requserdata)
205 intrequest_freegadgets(requserdata->Gadgets,IntuitionBase);
206 intrequest_freelabels(requserdata->GadgetLabels, IntuitionBase);
207 if (requserdata->dri) FreeScreenDrawInfo(requserdata->ReqScreen,(struct DrawInfo *)requserdata->dri);
208 if (requserdata->freeitext) intrequest_freeitext(requserdata->Text,IntuitionBase);
209 if (requserdata->ReqGadgets) FreeVec(requserdata->ReqGadgets);
210 if (requserdata->backfilldata.image) int_FreeCustomImage(TYPE_REQUESTERCLASS,requserdata->dri,IntuitionBase);
211 if (requserdata->Logo) int_FreeCustomImage(TYPE_REQUESTERCLASS,requserdata->dri,IntuitionBase);
212 FreeVec(requserdata);
214 if (lockedscr) UnlockPubScreen(NULL, lockedscr);
216 return NULL;
218 AROS_LIBFUNC_EXIT
220 } /* BuildEasyRequestArgs */
222 /**********************************************************************************************/
224 UWORD BgPattern[2] = { 0xAAAA, 0x5555 };
226 /**********************************************************************************************/
228 /* create an array of gadgetlabels */
229 static STRPTR *buildeasyreq_makelabels(struct IntRequestUserData *requserdata,
230 STRPTR labeltext,
231 ULONG *args,
232 struct IntuitionBase *IntuitionBase)
234 STRPTR *gadgetlabels;
235 STRPTR label;
236 int currentgadget;
237 struct RawInfo RawInfo;
238 UBYTE *rawbuf;
240 /* copy label-string */
241 RawInfo.Len = 0;
242 RawInfo.Lines = 1;
243 RawDoFmt(labeltext, args, (VOID_FUNC)AROS_ASMSYMNAME(RequesterCountChar), &RawInfo);
245 label = AllocVec(RawInfo.Len, MEMF_PUBLIC);
246 if (!label)
248 return NULL;
250 rawbuf = label;
251 RawDoFmt(labeltext, args, (VOID_FUNC)AROS_ASMSYMNAME(RequesterPutChar), &rawbuf);
253 /* make room for pointer-array */
254 requserdata->NumGadgets = charsinstring(label, '|') + 1;
255 gadgetlabels = AllocVec((requserdata->NumGadgets + 1) * sizeof(STRPTR), MEMF_PUBLIC);
256 if (!gadgetlabels)
258 FreeVec(label);
259 return NULL;
261 gadgetlabels[requserdata->NumGadgets] = NULL;
263 /* set up the pointers and insert null-bytes */
264 for (currentgadget = 0; currentgadget < requserdata->NumGadgets; currentgadget++)
266 gadgetlabels[currentgadget] = label;
267 if (currentgadget != (requserdata->NumGadgets - 1))
269 while (label[0] != '|')
270 label++;
271 label[0] = '\0';
272 label++;
276 return gadgetlabels;
279 /**********************************************************************************************/
281 static int charsinstring(STRPTR string, char c)
283 int count = 0;
285 while (string[0])
287 if (string[0] == c)
288 count++;
289 string++;
291 return count;
294 /**********************************************************************************************/