revert between 56095 -> 55830 in arch
[AROS.git] / workbench / utilities / More / req.c
blob1761a2750df305a9a8b12e54ed0e9383454bf772
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/memory.h>
7 #include <dos/dos.h>
8 #include <intuition/intuition.h>
9 #include <intuition/imageclass.h>
10 #include <intuition/gadgetclass.h>
11 #include <libraries/gadtools.h>
12 #include <graphics/gfx.h>
13 #include <utility/hooks.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/intuition.h>
18 #include <proto/graphics.h>
19 #include <proto/gadtools.h>
20 #include <proto/alib.h>
21 #include <proto/utility.h>
23 #include <string.h>
25 #include "global.h"
26 #include "req.h"
28 #define CATCOMP_NUMBERS
29 #include "strings.h"
31 #define DEBUG 0
32 #include <aros/debug.h>
34 /****************************************************************************************/
37 #define BORDER_SPACING_X 4
38 #define BORDER_SPACING_Y 4
40 #define GAD_SPACING_X 8
41 #define GAD_SPACING_Y 4
43 #define GAD_EXTRA_WIDTH 16
44 #define GAD_EXTRA_HEIGHT 6
46 enum {GAD_FIND_TEXT = 1,
47 GAD_FIND_OK,
48 GAD_FIND_CANCEL};
50 enum {GAD_GOTO_STRING = 1,
51 GAD_GOTO_OK,
52 GAD_GOTO_CANCEL};
54 /****************************************************************************************/
57 static struct RastPort temprp;
58 static struct Window *gotowin, *findwin;
59 static struct Gadget *gotogad, *findgad, *gad, *gotogadlist, *findgadlist;
60 static struct NewGadget ng;
61 static WORD fontwidth, fontheight;
63 static char searchtext[256];
65 /****************************************************************************************/
67 static BOOL Init(void)
69 fontwidth = dri->dri_Font->tf_XSize;
70 fontheight = dri->dri_Font->tf_YSize;
72 InitRastPort(&temprp);
73 SetFont(&temprp, dri->dri_Font);
75 memset(&ng, 0, sizeof(ng));
76 ng.ng_VisualInfo = vi;
78 return TRUE;
81 /****************************************************************************************/
84 void CleanupRequesters(void)
86 if (gotowin) Kill_Goto_Requester();
87 if (findwin) Kill_Find_Requester();
90 /****************************************************************************************/
93 void Make_Goto_Requester(void)
95 WORD winwidth, winheight, gadwidth, gadheight;
96 WORD strwidth, w;
98 if (gotowin || !Init()) return;
100 gad = CreateContext(&gotogadlist);
102 gadheight = fontheight + GAD_EXTRA_HEIGHT;
104 winheight = scr->WBorTop + fontheight + 1 +
105 scr->WBorBottom +
106 BORDER_SPACING_Y * 2 +
107 gadheight * 2 +
108 GAD_SPACING_Y;
110 gadwidth = TextLength(&temprp, MSG(MSG_OK), strlen(MSG(MSG_OK)));
111 w = TextLength(&temprp, MSG(MSG_CANCEL), strlen(MSG(MSG_CANCEL)));
112 if (w > gadwidth) gadwidth = w;
114 gadwidth += GAD_EXTRA_WIDTH;
116 strwidth = gadwidth * 2 + GAD_SPACING_X;
118 winwidth = scr->WBorLeft +
119 scr->WBorRight +
120 BORDER_SPACING_X * 2 +
121 strwidth;
123 ng.ng_LeftEdge = scr->WBorLeft + BORDER_SPACING_X;
124 ng.ng_TopEdge = scr->WBorTop + fontheight + 1 + BORDER_SPACING_Y;
125 ng.ng_Width = strwidth;
126 ng.ng_Height = gadheight;
127 ng.ng_GadgetID = GAD_GOTO_STRING;
128 ng.ng_Flags = PLACETEXT_IN;
130 gotogad = CreateGadget(INTEGER_KIND, gad, &ng, GTIN_MaxChars, 8,
131 STRINGA_Justification, GACT_STRINGCENTER,
132 TAG_DONE);
134 ng.ng_TopEdge += gadheight + GAD_SPACING_Y;
135 ng.ng_Width = gadwidth;
136 ng.ng_GadgetText = MSG(MSG_OK);
137 ng.ng_GadgetID = GAD_GOTO_OK;
139 gad = CreateGadgetA(BUTTON_KIND, gotogad, &ng, 0);
141 ng.ng_LeftEdge += gadwidth + GAD_SPACING_X;
142 ng.ng_GadgetText = MSG(MSG_CANCEL);
143 ng.ng_GadgetID = GAD_GOTO_CANCEL;
145 gad = CreateGadgetA(BUTTON_KIND, gad, &ng, 0);
147 if (!gad)
149 FreeGadgets(gotogadlist);
150 gotogadlist = 0;
151 } else {
152 gotowin = OpenWindowTags(0, WA_CustomScreen, (IPTR)scr,
153 WA_Left, scr->MouseX - (winwidth / 2),
154 WA_Top, scr->MouseY - (winheight / 2),
155 WA_Width, winwidth,
156 WA_Height, winheight,
157 WA_AutoAdjust, TRUE,
158 WA_Title, (IPTR)MSG(MSG_JUMP_TITLE),
159 WA_CloseGadget, TRUE,
160 WA_DepthGadget, TRUE,
161 WA_DragBar, TRUE,
162 WA_Activate, TRUE,
163 WA_SimpleRefresh, TRUE,
164 WA_IDCMP, IDCMP_CLOSEWINDOW |
165 IDCMP_REFRESHWINDOW |
166 IDCMP_VANILLAKEY |
167 BUTTONIDCMP |
168 INTEGERIDCMP,
169 WA_Gadgets, (IPTR)gotogadlist,
170 TAG_DONE);
172 if (!gotowin)
174 FreeGadgets(gotogadlist);gotogadlist = 0;
175 } else {
176 gotomask = 1L << gotowin->UserPort->mp_SigBit;
177 GT_RefreshWindow(gotowin, 0);
178 ActivateGadget(gotogad, gotowin, 0);
183 /****************************************************************************************/
185 BOOL Handle_Goto_Requester(LONG *line)
187 struct IntuiMessage *msg;
188 IPTR l;
189 BOOL killreq = FALSE, rc = FALSE;
191 while ((msg = GT_GetIMsg(gotowin->UserPort)))
193 switch (msg->Class)
195 case IDCMP_REFRESHWINDOW:
196 GT_BeginRefresh(gotowin);
197 GT_EndRefresh(gotowin, TRUE);
198 break;
200 case IDCMP_CLOSEWINDOW:
201 killreq = TRUE;
202 break;
204 case IDCMP_GADGETUP:
205 switch (((struct Gadget *)msg->IAddress)->GadgetID)
207 case GAD_GOTO_CANCEL:
208 killreq = TRUE;
209 break;
211 case GAD_GOTO_STRING:
212 case GAD_GOTO_OK:
213 GT_GetGadgetAttrs(gotogad, gotowin, 0, GTIN_Number, (IPTR)&l,
214 TAG_DONE);
215 rc = TRUE;
216 break;
218 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
219 break;
221 case IDCMP_VANILLAKEY:
222 switch(ToUpper(msg->Code))
224 case 27:
225 killreq = TRUE;
226 break;
228 case 9:
229 case 'G':
230 ActivateGadget(gotogad, gotowin, 0);
231 break;
233 } /* switch(msg->Code) */
234 break;
236 } /* switch (msg->Class) */
237 GT_ReplyIMsg(msg);
239 } /* while ((msg = GT_GetIMsg(gotowin))) */
241 if (killreq) Kill_Goto_Requester();
243 if (rc) *line = l;
245 return rc;
248 /****************************************************************************************/
250 void Kill_Goto_Requester(void)
252 if (gotowin)
254 CloseWindow(gotowin);gotowin = 0;gotomask = 0;
257 if (gotogadlist)
259 FreeGadgets(gotogadlist);gotogadlist = 0;
263 /****************************************************************************************/
265 void Make_Find_Requester(void)
267 WORD winwidth, winheight, gadwidth, gadheight;
268 WORD strwidth, w;
270 if (findwin || !Init()) return;
272 gad = CreateContext(&findgadlist);
274 gadheight = fontheight + GAD_EXTRA_HEIGHT;
276 winheight = scr->WBorTop + fontheight + 1 +
277 scr->WBorBottom +
278 BORDER_SPACING_Y * 2 +
279 gadheight * 2 +
280 GAD_SPACING_Y;
282 gadwidth = TextLength(&temprp, MSG(MSG_OK), strlen(MSG(MSG_OK)));
283 w = TextLength(&temprp, MSG(MSG_CANCEL), strlen(MSG(MSG_CANCEL)));
284 if (w > gadwidth) gadwidth = w;
286 gadwidth += GAD_EXTRA_WIDTH;
288 strwidth = gadwidth * 2 + GAD_SPACING_X;
290 if (strwidth < 250) strwidth = 250;
292 winwidth = scr->WBorLeft +
293 scr->WBorRight +
294 BORDER_SPACING_X * 2 +
295 strwidth;
297 ng.ng_LeftEdge = scr->WBorLeft + BORDER_SPACING_X;
298 ng.ng_TopEdge = scr->WBorTop + fontheight + 1 + BORDER_SPACING_Y;
299 ng.ng_Width = strwidth;
300 ng.ng_Height = gadheight;
301 ng.ng_GadgetID = GAD_FIND_TEXT;
302 ng.ng_Flags = PLACETEXT_IN;
304 findgad = CreateGadget(STRING_KIND, gad, &ng, GTST_MaxChars, 256,
305 TAG_DONE);
307 ng.ng_TopEdge += gadheight + GAD_SPACING_Y;
308 ng.ng_Width = gadwidth;
309 ng.ng_GadgetText = MSG(MSG_OK);
310 ng.ng_GadgetID = GAD_FIND_OK;
312 gad = CreateGadgetA(BUTTON_KIND, findgad, &ng, 0);
314 ng.ng_LeftEdge = winwidth - scr->WBorRight - BORDER_SPACING_X - gadwidth;
315 ng.ng_GadgetText = MSG(MSG_CANCEL);
316 ng.ng_GadgetID = GAD_FIND_CANCEL;
318 gad = CreateGadgetA(BUTTON_KIND, gad, &ng, 0);
320 if (!gad)
322 FreeGadgets(findgadlist);
323 findgadlist = 0;
324 } else {
325 findwin = OpenWindowTags(0, WA_CustomScreen, (IPTR)scr,
326 WA_Left, scr->MouseX - (winwidth / 2),
327 WA_Top, scr->MouseY - (winheight / 2),
328 WA_Width, winwidth,
329 WA_Height, winheight,
330 WA_AutoAdjust, TRUE,
331 WA_Title, (IPTR)MSG(MSG_FIND_TITLE),
332 WA_CloseGadget, TRUE,
333 WA_DepthGadget, TRUE,
334 WA_DragBar, TRUE,
335 WA_Activate, TRUE,
336 WA_SimpleRefresh, TRUE,
337 WA_IDCMP, IDCMP_CLOSEWINDOW |
338 IDCMP_REFRESHWINDOW |
339 IDCMP_VANILLAKEY |
340 BUTTONIDCMP |
341 INTEGERIDCMP,
342 WA_Gadgets, (IPTR)findgadlist,
343 TAG_DONE);
345 if (!findwin)
347 FreeGadgets(findgadlist);findgadlist = 0;
348 } else {
349 findmask = 1L << findwin->UserPort->mp_SigBit;
350 GT_RefreshWindow(findwin, 0);
351 ActivateGadget(findgad, findwin, 0);
356 /****************************************************************************************/
358 WORD Handle_Find_Requester(char **text)
360 struct IntuiMessage *msg;
361 char *sp;
362 BOOL killreq = FALSE, rc = 0;
364 while ((msg = GT_GetIMsg(findwin->UserPort)))
366 switch (msg->Class)
368 case IDCMP_REFRESHWINDOW:
369 GT_BeginRefresh(findwin);
370 GT_EndRefresh(findwin, TRUE);
371 break;
373 case IDCMP_CLOSEWINDOW:
374 killreq = TRUE;
375 break;
377 case IDCMP_GADGETUP:
378 switch (((struct Gadget *)msg->IAddress)->GadgetID)
380 case GAD_FIND_CANCEL:
381 killreq = TRUE;
382 break;
384 case GAD_FIND_TEXT:
385 case GAD_FIND_OK:
386 GT_GetGadgetAttrs(findgad, findwin, 0, GTST_String, (IPTR)&sp,
387 TAG_DONE);
388 strcpy(searchtext, sp);
390 rc = TRUE;
391 break;
393 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
394 break;
396 case IDCMP_VANILLAKEY:
397 switch(ToUpper(msg->Code))
399 case 27:
400 killreq = TRUE;
401 break;
403 case 9:
404 case 'S':
405 case 'F':
406 ActivateGadget(findgad, findwin, 0);
407 break;
409 case 13:
410 case 'N':
411 rc = SEARCH_NEXT;
412 break;
414 case 'P':
415 rc = SEARCH_PREV;
416 break;
418 } /* switch(msg->Code) */
419 break;
421 } /* switch (msg->Class) */
422 GT_ReplyIMsg(msg);
424 } /* while ((msg = GT_GetIMsg(findwin))) */
426 if (killreq) Kill_Find_Requester();
428 if (rc) *text = searchtext;
430 return rc;
433 /****************************************************************************************/
435 void Kill_Find_Requester(void)
437 if (findwin)
439 CloseWindow(findwin);findwin = 0;findmask = 0;
442 if (findgadlist)
444 FreeGadgets(findgadlist);findgadlist = 0;
448 /****************************************************************************************/