add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / asl / specialreq.c
blob55583c78460491302ae476ccaf61aa5b02d0c56c
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Special requesters needed for things like Delete in File Requester.
6 Lang: english
7 */
10 #include <proto/exec.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/graphics.h>
14 #include <exec/memory.h>
15 #include <dos/dos.h>
16 #include <intuition/screens.h>
17 #include <intuition/gadgetclass.h>
18 #include <graphics/gfx.h>
19 #include <string.h>
21 #include "asl_intern.h"
22 #include "layout.h"
23 #include "specialreq.h"
25 #if USE_SHARED_COOLIMAGES
26 #include <libraries/coolimages.h>
27 #include <proto/coolimages.h>
28 #else
29 #include "coolimages.h"
30 #endif
32 #define SDEBUG 0
33 #define DEBUG 0
35 #include <aros/debug.h>
37 /*****************************************************************************************/
39 #define OK_ID 1
40 #define CANCEL_ID 2
41 #define STRING_ID 3
43 /*****************************************************************************************/
45 STRPTR REQ_String(STRPTR title, STRPTR stringtext, STRPTR oktext, STRPTR canceltext,
46 struct LayoutData *ld, struct AslBase_intern *AslBase)
48 struct Window *win;
49 struct Hook edithook;
50 Object *okbutton = NULL;
51 Object *cancelbutton = NULL;
52 Object *textstring = NULL;
53 WORD x, x2, y, y2, winwidth, winheight;
54 WORD buttonwidth, buttonheight;
55 #if USE_SHARED_COOLIMAGES
56 const struct CoolImage *useimg = NULL;
57 const struct CoolImage *cancelimg = NULL;
59 #define cool_useimage (*useimg)
60 #define cool_cancelimage (*cancelimg)
62 #endif
64 STRPTR retval = NULL;
66 /* Init */
68 #if USE_SHARED_COOLIMAGES
69 #if SPECIALREQ_COOL_BUTTONS
70 if (CoolImagesBase)
72 useimg = COOL_ObtainImageA(COOL_USEIMAGE_ID, NULL);
73 cancelimg = COOL_ObtainImageA(COOL_CANCELIMAGE_ID, NULL);
75 #endif
76 #endif
78 if (!stringtext) stringtext = "";
80 edithook.h_Entry = (APTR)AROS_ASMSYMNAME(StringEditFunc);
81 edithook.h_SubEntry = NULL;
82 edithook.h_Data = AslBase;
84 /* Calc. button width */
86 x = TextLength(&ld->ld_DummyRP, oktext, strlen(oktext));
88 #if USE_SHARED_COOLIMAGES
89 if (useimg)
90 #endif
91 #if SPECIALREQ_COOL_BUTTONS
92 if (ld->ld_TrueColor)
94 x += IMAGEBUTTONEXTRAWIDTH + cool_useimage.width;
96 #endif
98 x2 = TextLength(&ld->ld_DummyRP, canceltext, strlen(canceltext));
100 #if USE_SHARED_COOLIMAGES
101 if (cancelimg)
102 #endif
103 #if SPECIALREQ_COOL_BUTTONS
104 if (ld->ld_TrueColor)
106 x2 += IMAGEBUTTONEXTRAWIDTH + cool_cancelimage.width;
108 #endif
110 buttonwidth = BUTTONEXTRAWIDTH + ((x2 > x) ? x2 : x);
112 /* Calc. button height */
114 #if SPECIALREQ_COOL_BUTTONS
115 y = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
116 if (ld->ld_TrueColor)
118 y2 = IMAGEBUTTONEXTRAHEIGHT + DEF_COOLIMAGEHEIGHT;
120 else
122 y2 = 0;
124 buttonheight = (y > y2) ? y : y2;
125 #else
126 buttonheight = BUTTONEXTRAHEIGHT + ld->ld_Font->tf_YSize;
127 #endif
129 /* calc. win size */
131 winwidth = OUTERSPACINGX * 2 +
132 buttonwidth * 3;
134 winheight = OUTERSPACINGY * 2 + buttonheight * 2 + GADGETSPACINGY;
136 x = ld->ld_WBorLeft + OUTERSPACINGX;
137 y = ld->ld_WBorTop + OUTERSPACINGY + buttonheight + GADGETSPACINGY;
139 /* Make button gadgets */
142 struct TagItem button_tags[] =
144 {GA_Text , (IPTR)oktext },
145 {TAG_IGNORE , 0 },
146 {GA_ID , OK_ID },
147 {TAG_IGNORE , 0 },
148 {GA_UserData , (IPTR)ld },
149 {GA_Left , x },
150 {GA_Top , y },
151 {GA_Width , buttonwidth },
152 {GA_Height , buttonheight },
153 {GA_Image , 0 }, /* 0 means we want a frame */
154 {GA_RelVerify , TRUE },
155 {TAG_DONE }
158 #if USE_SHARED_COOLIMAGES
159 if (useimg)
161 button_tags[3].ti_Tag = ASLBT_CoolImage;
162 button_tags[3].ti_Data = (IPTR)useimg;
164 #else
165 button_tags[3].ti_Tag = ASLBT_CoolImage;
166 button_tags[3].ti_Data = (IPTR)&cool_useimage;
167 #endif
169 okbutton = NewObjectA(AslBase->aslbuttonclass, NULL, button_tags);
171 button_tags[0].ti_Data = (IPTR)canceltext;
172 if (okbutton) button_tags[1].ti_Tag = GA_Previous;
173 button_tags[1].ti_Data = (IPTR)okbutton;
174 button_tags[2].ti_Data = CANCEL_ID;
176 #if USE_SHARED_COOLIMAGES
177 if (!cancelimg)
179 button_tags[3].ti_Tag = TAG_IGNORE;
181 else
183 button_tags[3].ti_Data = (IPTR)cancelimg;
185 #else
186 button_tags[3].ti_Data = (IPTR)&cool_cancelimage;
187 #endif
189 button_tags[5].ti_Data += buttonwidth * 2;
191 cancelbutton = NewObjectA(AslBase->aslbuttonclass, NULL, button_tags);
193 if (okbutton && cancelbutton)
195 /* Make String Gadget */
197 struct TagItem string_tags[] =
199 {GA_Previous , (IPTR)cancelbutton },
200 {GA_ID , STRING_ID },
201 {GA_Left , x },
202 {GA_Top , y - buttonheight - GADGETSPACINGY },
203 {GA_Width , winwidth - OUTERSPACINGX * 2 },
204 {GA_Height , buttonheight },
205 {GA_RelVerify , TRUE },
206 {GA_UserData , (IPTR)ld },
207 {STRINGA_MaxChars , 256 },
208 {STRINGA_TextVal , (IPTR)stringtext },
209 {STRINGA_BufferPos , strlen(stringtext) },
210 {STRINGA_EditHook , (IPTR)&edithook },
211 {TAG_DONE }
214 textstring = NewObjectA(AslBase->aslstringclass, NULL, string_tags);
215 if (textstring)
217 x = ld->ld_Window->LeftEdge +
218 ld->ld_Window->Width / 2 -
219 (winwidth + ld->ld_WBorLeft + ld->ld_WBorRight) / 2;
221 y = ld->ld_Window->TopEdge +
222 ld->ld_Window->Height / 2 -
223 (winheight + ld->ld_WBorTop + ld->ld_WBorBottom) / 2;
225 win = OpenWindowTags(NULL, WA_CustomScreen, (IPTR)ld->ld_Screen,
226 WA_Left , x ,
227 WA_Top , y ,
228 WA_InnerWidth , winwidth ,
229 WA_InnerHeight , winheight ,
230 WA_AutoAdjust , TRUE ,
231 WA_Title , (IPTR)title ,
232 WA_CloseGadget , TRUE ,
233 WA_DragBar , TRUE ,
234 WA_DepthGadget , TRUE ,
235 WA_Activate , TRUE ,
236 WA_SimpleRefresh , TRUE ,
237 WA_NoCareRefresh , TRUE ,
238 WA_RMBTrap , TRUE ,
239 WA_IDCMP , IDCMP_CLOSEWINDOW |
240 IDCMP_GADGETUP |
241 IDCMP_VANILLAKEY |
242 IDCMP_RAWKEY ,
243 WA_Gadgets , (IPTR)okbutton ,
244 TAG_DONE);
246 if (win)
248 BOOL quitme = FALSE, doit = FALSE;
250 ActivateGadget((struct Gadget *)textstring, win, NULL);
252 while(!quitme && !doit)
254 struct IntuiMessage *msg;
256 WaitPort(win->UserPort);
257 while((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
259 switch(msg->Class)
261 case IDCMP_CLOSEWINDOW:
262 quitme = TRUE;
263 break;
265 case IDCMP_GADGETUP:
266 switch(((struct Gadget *)msg->IAddress)->GadgetID)
268 case OK_ID:
269 doit = TRUE;
270 break;
272 case CANCEL_ID:
273 quitme = TRUE;
274 break;
276 case STRING_ID:
277 switch(msg->Code)
279 case 0:
280 doit = TRUE;
281 break;
283 case 27:
284 quitme = TRUE;
285 break;
288 break;
290 } /* switch(((struct Gadget *)msg->IAddress)->GadgetID) */
291 break;
293 case IDCMP_VANILLAKEY:
294 switch(msg->Code)
296 case 27:
297 quitme = TRUE;
298 break;
300 case 9:
301 ActivateGadget((struct Gadget *)textstring, win, NULL);
302 break;
305 break;
307 } /* switch(msg->Class) */
308 ReplyMsg((struct Message *)msg);
310 } /* while((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
312 } /* while(!quitme && !doit) */
314 if (doit)
316 STRPTR text;
317 LONG len;
319 GetAttr(STRINGA_TextVal, textstring, (IPTR *)&text);
321 len = strlen(text);
322 if (len > 0)
324 retval = VecPooledCloneString(text, NULL, ld->ld_IntReq->ir_MemPool, AslBase);
325 if (retval) strcpy(retval, text);
328 } /* if (doit) */
330 RemoveGadget(win, (struct Gadget *)okbutton);
331 RemoveGadget(win, (struct Gadget *)cancelbutton);
332 RemoveGadget(win, (struct Gadget *)textstring);
334 CloseWindow(win);
336 } /* if (win) */
338 DisposeObject(textstring);
340 } /* if (textstring) */
342 } /* if (okbutton && cancelbutton) */
344 if (okbutton) DisposeObject(okbutton);
345 if (cancelbutton) DisposeObject(cancelbutton);
347 } /**/
349 return retval;
353 /*****************************************************************************************/