2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 #include <exec/memory.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>
28 #define CATCOMP_NUMBERS
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,
50 enum {GAD_GOTO_STRING
= 1,
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
;
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
;
98 if (gotowin
|| !Init()) return;
100 gad
= CreateContext(&gotogadlist
);
102 gadheight
= fontheight
+ GAD_EXTRA_HEIGHT
;
104 winheight
= scr
->WBorTop
+ fontheight
+ 1 +
106 BORDER_SPACING_Y
* 2 +
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
+
120 BORDER_SPACING_X
* 2 +
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
,
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);
149 FreeGadgets(gotogadlist
);
152 gotowin
= OpenWindowTags(0, WA_CustomScreen
, (IPTR
)scr
,
153 WA_Left
, scr
->MouseX
- (winwidth
/ 2),
154 WA_Top
, scr
->MouseY
- (winheight
/ 2),
156 WA_Height
, winheight
,
158 WA_Title
, (IPTR
)MSG(MSG_JUMP_TITLE
),
159 WA_CloseGadget
, TRUE
,
160 WA_DepthGadget
, TRUE
,
163 WA_SimpleRefresh
, TRUE
,
164 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
165 IDCMP_REFRESHWINDOW
|
169 WA_Gadgets
, (IPTR
)gotogadlist
,
174 FreeGadgets(gotogadlist
);gotogadlist
= 0;
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
;
189 BOOL killreq
= FALSE
, rc
= FALSE
;
191 while ((msg
= GT_GetIMsg(gotowin
->UserPort
)))
195 case IDCMP_REFRESHWINDOW
:
196 GT_BeginRefresh(gotowin
);
197 GT_EndRefresh(gotowin
, TRUE
);
200 case IDCMP_CLOSEWINDOW
:
205 switch (((struct Gadget
*)msg
->IAddress
)->GadgetID
)
207 case GAD_GOTO_CANCEL
:
211 case GAD_GOTO_STRING
:
213 GT_GetGadgetAttrs(gotogad
, gotowin
, 0, GTIN_Number
, (IPTR
)&l
,
218 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
221 case IDCMP_VANILLAKEY
:
222 switch(ToUpper(msg
->Code
))
230 ActivateGadget(gotogad
, gotowin
, 0);
233 } /* switch(msg->Code) */
236 } /* switch (msg->Class) */
239 } /* while ((msg = GT_GetIMsg(gotowin))) */
241 if (killreq
) Kill_Goto_Requester();
248 /****************************************************************************************/
250 void Kill_Goto_Requester(void)
254 CloseWindow(gotowin
);gotowin
= 0;gotomask
= 0;
259 FreeGadgets(gotogadlist
);gotogadlist
= 0;
263 /****************************************************************************************/
265 void Make_Find_Requester(void)
267 WORD winwidth
, winheight
, gadwidth
, gadheight
;
270 if (findwin
|| !Init()) return;
272 gad
= CreateContext(&findgadlist
);
274 gadheight
= fontheight
+ GAD_EXTRA_HEIGHT
;
276 winheight
= scr
->WBorTop
+ fontheight
+ 1 +
278 BORDER_SPACING_Y
* 2 +
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
+
294 BORDER_SPACING_X
* 2 +
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,
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);
322 FreeGadgets(findgadlist
);
325 findwin
= OpenWindowTags(0, WA_CustomScreen
, (IPTR
)scr
,
326 WA_Left
, scr
->MouseX
- (winwidth
/ 2),
327 WA_Top
, scr
->MouseY
- (winheight
/ 2),
329 WA_Height
, winheight
,
331 WA_Title
, (IPTR
)MSG(MSG_FIND_TITLE
),
332 WA_CloseGadget
, TRUE
,
333 WA_DepthGadget
, TRUE
,
336 WA_SimpleRefresh
, TRUE
,
337 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
338 IDCMP_REFRESHWINDOW
|
342 WA_Gadgets
, (IPTR
)findgadlist
,
347 FreeGadgets(findgadlist
);findgadlist
= 0;
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
;
362 BOOL killreq
= FALSE
, rc
= 0;
364 while ((msg
= GT_GetIMsg(findwin
->UserPort
)))
368 case IDCMP_REFRESHWINDOW
:
369 GT_BeginRefresh(findwin
);
370 GT_EndRefresh(findwin
, TRUE
);
373 case IDCMP_CLOSEWINDOW
:
378 switch (((struct Gadget
*)msg
->IAddress
)->GadgetID
)
380 case GAD_FIND_CANCEL
:
386 GT_GetGadgetAttrs(findgad
, findwin
, 0, GTST_String
, (IPTR
)&sp
,
388 strcpy(searchtext
, sp
);
393 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
396 case IDCMP_VANILLAKEY
:
397 switch(ToUpper(msg
->Code
))
406 ActivateGadget(findgad
, findwin
, 0);
418 } /* switch(msg->Code) */
421 } /* switch (msg->Class) */
424 } /* while ((msg = GT_GetIMsg(findwin))) */
426 if (killreq
) Kill_Find_Requester();
428 if (rc
) *text
= searchtext
;
433 /****************************************************************************************/
435 void Kill_Find_Requester(void)
439 CloseWindow(findwin
);findwin
= 0;findmask
= 0;
444 FreeGadgets(findgadlist
);findgadlist
= 0;
448 /****************************************************************************************/