2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
7 #define DEBUG_BUILDEASYREQUEST(x) ;
9 /**********************************************************************************************/
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 /*****************************************************************************
37 #include <proto/intuition.h>
38 #include <exec/types.h>
39 #include <intuition/intuition.h>
41 AROS_LH4(struct Window
*, BuildEasyRequestArgs
,
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
),
50 struct IntuitionBase
*, IntuitionBase
, 99, Intuition
)
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
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
67 Args - The arguments for easyStruct->es_TextFormat.
70 Returns a pointer to the requester. Use this pointer only for calls
71 to SysReqHandler() and FreeSysRequest().
80 EasyRequestArgs(), SysReqHandler(), FreeSysRequest()
86 *****************************************************************************/
90 struct Screen
*scr
= NULL
, *lockedscr
= NULL
;
92 //struct Gadget *gadgets;
94 struct IntRequestUserData
*requserdata
;
97 DEBUG_BUILDEASYREQUEST(dprintf("intrequest_buildeasyrequest: window 0x%lx easystruct 0x%lx IDCMPFlags 0x%lx args 0x%lx\n",
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 */
120 scr
= RefWindow
->WScreen
;
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
;
134 scr
= LockPubScreen(NULL
);
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
,
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
|
177 WFLG_SIMPLE_REFRESH
|
179 { WA_SkinInfo
, NULL
},
180 { (requserdata
->backfilldata
.image
) ? WA_BackFill
: TAG_IGNORE
, (ULONG
)&requserdata
->backfillhook
},
184 req
= OpenWindowTagList(NULL
, win_tags
);
190 if (lockedscr
) UnlockPubScreen(NULL
, lockedscr
);
192 req
->UserData
= (BYTE
*)requserdata
;
193 requserdata
->IDCMP
= IDCMP
;
194 requserdata
->ReqWindow
= req
;
196 intrequest_drawrequester(requserdata
,IntuitionBase
);
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
);
220 } /* BuildEasyRequestArgs */
222 /**********************************************************************************************/
224 UWORD BgPattern
[2] = { 0xAAAA, 0x5555 };
226 /**********************************************************************************************/
228 /* create an array of gadgetlabels */
229 static STRPTR
*buildeasyreq_makelabels(struct IntRequestUserData
*requserdata
,
232 struct IntuitionBase
*IntuitionBase
)
234 STRPTR
*gadgetlabels
;
237 struct RawInfo RawInfo
;
240 /* copy label-string */
243 RawDoFmt(labeltext
, args
, (VOID_FUNC
)AROS_ASMSYMNAME(RequesterCountChar
), &RawInfo
);
245 label
= AllocVec(RawInfo
.Len
, MEMF_PUBLIC
);
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
);
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] != '|')
279 /**********************************************************************************************/
281 static int charsinstring(STRPTR string
, char c
)
294 /**********************************************************************************************/