Don't call InvertPixelArray with negative width and/or height.
[tangerine.git] / workbench / libs / muimaster / mui_request.c
blob92acb53842e0ae2fd4272445bfa7cc7e732fc82e
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
8 #ifdef __AROS__
9 #include <proto/alib.h>
10 #else
11 #include <clib/alib_protos.h>
12 #endif
13 #include <proto/exec.h>
14 #include <proto/intuition.h>
15 #include <proto/muimaster.h>
17 #include "mui.h"
18 #include "support.h"
19 #include "muimaster_intern.h"
21 extern struct Library *MUIMasterBase;
23 #ifdef __AROS__
24 AROS_UFH2S(void, cpy_func,
25 AROS_UFHA(UBYTE, chr, D0),
26 AROS_UFHA(STRPTR *, strPtrPtr, A3))
28 AROS_USERFUNC_INIT
30 *(*strPtrPtr)++ = chr;
32 AROS_USERFUNC_EXIT
35 AROS_UFH2S(void, len_func,
36 AROS_UFHA(UBYTE, chr, D0),
37 AROS_UFHA(LONG *, lenPtr, A3))
39 AROS_USERFUNC_INIT
41 (*lenPtr)++;
43 AROS_USERFUNC_EXIT
45 #endif
47 /*****************************************************************************
49 NAME */
50 AROS_LH7(LONG, MUI_RequestA,
52 /* SYNOPSIS */
53 AROS_LHA(APTR, app, D0),
54 AROS_LHA(APTR, win, D1),
55 AROS_LHA(LONGBITS, flags, D2),
56 AROS_LHA(CONST_STRPTR, title, A0),
57 AROS_LHA(CONST_STRPTR, gadgets, A1),
58 AROS_LHA(CONST_STRPTR, format, A2),
59 AROS_LHA(APTR, params, A3),
61 /* LOCATION */
62 struct Library *, MUIMasterBase, 7, MUIMaster)
64 /* FUNCTION
66 INPUTS
68 RESULT
70 NOTES
72 EXAMPLE
74 BUGS
76 SEE ALSO
78 INTERNALS
80 *****************************************************************************/
82 AROS_LIBFUNC_INIT
83 AROS_LIBBASE_EXT_DECL(struct Library *,MUIMasterBase)
85 LONG result;
86 char *reqtxt;
87 LONG reqtxt_len;
88 #ifndef __AROS__
89 static const ULONG len_func = 0x52934e75; /* addq.l #1,(A3) ; rts */
90 static const ULONG cpy_func = 0x16c04e75; /* move.b d0,(a3)+ ; rts */
91 #endif
93 Object *req_wnd;
94 Object *req_group;
95 Object *req_but[32]; /* more than 32 buttongadgets within a requester shouldn`t happen */
97 if (!app)
99 struct EasyStruct es;
100 es.es_StructSize = sizeof(struct EasyStruct);
101 es.es_Flags = 0;
102 es.es_Title = title;
103 es.es_TextFormat = format;
104 es.es_GadgetFormat = gadgets;
105 return EasyRequestArgs(NULL,&es,NULL,params);
108 #ifdef __AROS__
109 reqtxt_len = 0;
110 RawDoFmt(format,params,(VOID_FUNC)AROS_ASMSYMNAME(len_func),&reqtxt_len);
111 #else
112 reqtxt_len = 0;
113 RawDoFmt(format,params,(void(*)())&len_func,&reqtxt_len);
114 #endif
116 if (!(reqtxt = AllocVec(reqtxt_len+1,0))) return 0; /* Return cancel if something failed */
118 #ifdef __AROS__
120 char *reqtxtptr = reqtxt;
122 RawDoFmt(format,params,(VOID_FUNC)AROS_ASMSYMNAME(cpy_func),&reqtxtptr);
124 #else
125 RawDoFmt(format,params,(void(*)())&cpy_func,reqtxt);
126 #endif
128 if (title == NULL && app != NULL)
130 title = (CONST_STRPTR) XGET(app, MUIA_Application_Title);
133 req_wnd = WindowObject,
134 MUIA_Window_Title, title,
135 MUIA_Window_RefWindow, win,
136 MUIA_Window_LeftEdge, MUIV_Window_LeftEdge_Centered,
137 MUIA_Window_TopEdge, MUIV_Window_TopEdge_Centered,
138 MUIA_Window_CloseGadget, FALSE,
139 MUIA_Window_SizeGadget, FALSE,
140 WindowContents, VGroup,
141 MUIA_Background, MUII_RequesterBack,
142 Child, HGroup,
143 Child, TextObject,
144 TextFrame,
145 MUIA_InnerBottom, 8,
146 MUIA_InnerLeft, 8,
147 MUIA_InnerRight, 8,
148 MUIA_InnerTop, 8,
149 MUIA_Background, MUII_TextBack,
150 MUIA_Text_SetMax, TRUE,
151 MUIA_Text_Contents, reqtxt,
152 End,
153 End,
154 Child, VSpace(2),
155 Child, req_group = HGroup, End,
156 End,
157 End;
159 FreeVec(reqtxt);
161 result = 0;
163 if (req_wnd)
165 char *gadgs = StrDup(gadgets);
166 if (gadgs)
168 char *current = gadgs;
169 int active = -1;
170 int num_gads = 0;
171 LONG isopen;
173 // set(app, MUIA_Application_Sleep, TRUE);
174 DoMethod(app, OM_ADDMEMBER, (IPTR)req_wnd);
176 while(current)
178 char *next = strchr(current,'|');
179 if (next) *next++ = 0;
181 if (current[0] == '*')
183 current++;
184 active = num_gads;
187 if (!(req_but[num_gads] = SimpleButton(current)))
188 break;
189 num_gads++;
190 current = next;
193 FreeVec(gadgs);
194 DoMethod(req_group, MUIM_Group_InitChange);
196 /* if this is only one button lets add it separatly */
197 if (num_gads == 1)
199 DoMethod(req_group, OM_ADDMEMBER, (IPTR)HSpace(0));
200 DoMethod(req_group, OM_ADDMEMBER, (IPTR)req_but[0]);
201 DoMethod(req_group, OM_ADDMEMBER, (IPTR)HSpace(0));
202 DoMethod(req_but[0], MUIM_Notify, MUIA_Pressed, FALSE,
203 (IPTR)app, 2, MUIM_Application_ReturnID, 2);
205 else
207 int j;
209 for(j = 0; j < num_gads; j++)
211 if (j > 0)
213 DoMethod(req_group, OM_ADDMEMBER, (IPTR)HSpace(0));
215 DoMethod(req_group, OM_ADDMEMBER, (IPTR)req_but[j]);
216 DoMethod(req_but[j], MUIM_Notify, MUIA_Pressed, FALSE,
217 (IPTR)app, 2, MUIM_Application_ReturnID,
218 (j+2 <= num_gads) ? j+2 : 1);
219 set(req_but[j], MUIA_CycleChain, 1);
222 DoMethod(req_group, MUIM_Group_ExitChange);
224 /* now activate that button with a starting "*" */
225 if(active != -1) set(req_wnd, MUIA_Window_ActiveObject, (IPTR) req_but[active]);
227 /* lets collect the waiting returnIDs now */
228 // COLLECT_RETURNIDS;
230 set(req_wnd, MUIA_Window_Open, TRUE);
231 get(req_wnd, MUIA_Window_Open, &isopen);
233 if (isopen)
235 ULONG sigs = 0;
236 result = -1;
238 while (result == -1)
240 ULONG ret = DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs);
242 /* if a button was hit, lets get outda here. */
243 if (ret > 0 && ret <= num_gads+1)
245 result = ret-1;
246 break;
249 if (sigs) sigs = Wait(sigs);
253 /* now lets reissue the collected returnIDs again */
254 // REISSUE_RETURNIDS;
256 // set(app, MUIA_Application_Sleep, FALSE);
259 DoMethod(app, OM_REMMEMBER, (IPTR)req_wnd);
260 MUI_DisposeObject(req_wnd);
262 return result;
264 AROS_LIBFUNC_EXIT
266 } /* MUIA_RequestA */