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>
26 #define CATCOMP_NUMBERS
30 #include <aros/debug.h>
32 /****************************************************************************************/
35 #define BORDER_SPACING_X 4
36 #define BORDER_SPACING_Y 4
38 #define GAD_SPACING_X 8
39 #define GAD_SPACING_Y 4
41 #define GAD_EXTRA_WIDTH 16
42 #define GAD_EXTRA_HEIGHT 6
44 enum {GAD_FIND_TEXT
= 1,
48 enum {GAD_GOTO_STRING
= 1,
52 /****************************************************************************************/
55 static struct RastPort temprp
;
56 static struct Window
*gotowin
, *findwin
;
57 static struct Gadget
*gotogad
, *findgad
, *gad
, *gotogadlist
, *findgadlist
;
58 static struct NewGadget ng
;
59 static WORD fontwidth
, fontheight
;
61 static char searchtext
[256];
63 /****************************************************************************************/
65 static BOOL
Init(void)
67 fontwidth
= dri
->dri_Font
->tf_XSize
;
68 fontheight
= dri
->dri_Font
->tf_YSize
;
70 InitRastPort(&temprp
);
71 SetFont(&temprp
, dri
->dri_Font
);
73 memset(&ng
, 0, sizeof(ng
));
74 ng
.ng_VisualInfo
= vi
;
79 /****************************************************************************************/
82 void CleanupRequesters(void)
84 if (gotowin
) Kill_Goto_Requester();
85 if (findwin
) Kill_Find_Requester();
88 /****************************************************************************************/
91 void Make_Goto_Requester(void)
93 WORD winwidth
, winheight
, gadwidth
, gadheight
;
96 if (gotowin
|| !Init()) return;
98 gad
= CreateContext(&gotogadlist
);
100 gadheight
= fontheight
+ GAD_EXTRA_HEIGHT
;
102 winheight
= scr
->WBorTop
+ fontheight
+ 1 +
104 BORDER_SPACING_Y
* 2 +
108 gadwidth
= TextLength(&temprp
, MSG(MSG_OK
), strlen(MSG(MSG_OK
)));
109 w
= TextLength(&temprp
, MSG(MSG_CANCEL
), strlen(MSG(MSG_CANCEL
)));
110 if (w
> gadwidth
) gadwidth
= w
;
112 gadwidth
+= GAD_EXTRA_WIDTH
;
114 strwidth
= gadwidth
* 2 + GAD_SPACING_X
;
116 winwidth
= scr
->WBorLeft
+
118 BORDER_SPACING_X
* 2 +
121 ng
.ng_LeftEdge
= scr
->WBorLeft
+ BORDER_SPACING_X
;
122 ng
.ng_TopEdge
= scr
->WBorTop
+ fontheight
+ 1 + BORDER_SPACING_Y
;
123 ng
.ng_Width
= strwidth
;
124 ng
.ng_Height
= gadheight
;
125 ng
.ng_GadgetID
= GAD_GOTO_STRING
;
126 ng
.ng_Flags
= PLACETEXT_IN
;
128 gotogad
= CreateGadget(INTEGER_KIND
, gad
, &ng
, GTIN_MaxChars
, 8,
129 STRINGA_Justification
, GACT_STRINGCENTER
,
132 ng
.ng_TopEdge
+= gadheight
+ GAD_SPACING_Y
;
133 ng
.ng_Width
= gadwidth
;
134 ng
.ng_GadgetText
= MSG(MSG_OK
);
135 ng
.ng_GadgetID
= GAD_GOTO_OK
;
137 gad
= CreateGadgetA(BUTTON_KIND
, gotogad
, &ng
, 0);
139 ng
.ng_LeftEdge
+= gadwidth
+ GAD_SPACING_X
;
140 ng
.ng_GadgetText
= MSG(MSG_CANCEL
);
141 ng
.ng_GadgetID
= GAD_GOTO_CANCEL
;
143 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, 0);
147 FreeGadgets(gotogadlist
);
150 gotowin
= OpenWindowTags(0, WA_CustomScreen
, (IPTR
)scr
,
151 WA_Left
, scr
->MouseX
- (winwidth
/ 2),
152 WA_Top
, scr
->MouseY
- (winheight
/ 2),
154 WA_Height
, winheight
,
156 WA_Title
, (IPTR
)MSG(MSG_JUMP_TITLE
),
157 WA_CloseGadget
, TRUE
,
158 WA_DepthGadget
, TRUE
,
161 WA_SimpleRefresh
, TRUE
,
162 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
163 IDCMP_REFRESHWINDOW
|
167 WA_Gadgets
, (IPTR
)gotogadlist
,
172 FreeGadgets(gotogadlist
);gotogadlist
= 0;
174 gotomask
= 1L << gotowin
->UserPort
->mp_SigBit
;
175 GT_RefreshWindow(gotowin
, 0);
176 ActivateGadget(gotogad
, gotowin
, 0);
181 /****************************************************************************************/
183 BOOL
Handle_Goto_Requester(LONG
*line
)
185 struct IntuiMessage
*msg
;
187 BOOL killreq
= FALSE
, rc
= FALSE
;
189 while ((msg
= GT_GetIMsg(gotowin
->UserPort
)))
193 case IDCMP_REFRESHWINDOW
:
194 GT_BeginRefresh(gotowin
);
195 GT_EndRefresh(gotowin
, TRUE
);
198 case IDCMP_CLOSEWINDOW
:
203 switch (((struct Gadget
*)msg
->IAddress
)->GadgetID
)
205 case GAD_GOTO_CANCEL
:
209 case GAD_GOTO_STRING
:
211 GT_GetGadgetAttrs(gotogad
, gotowin
, 0, GTIN_Number
, (IPTR
)&l
,
216 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
219 case IDCMP_VANILLAKEY
:
220 switch(ToUpper(msg
->Code
))
228 ActivateGadget(gotogad
, gotowin
, 0);
231 } /* switch(msg->Code) */
234 } /* switch (msg->Class) */
237 } /* while ((msg = GT_GetIMsg(gotowin))) */
239 if (killreq
) Kill_Goto_Requester();
246 /****************************************************************************************/
248 void Kill_Goto_Requester(void)
252 CloseWindow(gotowin
);gotowin
= 0;gotomask
= 0;
257 FreeGadgets(gotogadlist
);gotogadlist
= 0;
261 /****************************************************************************************/
263 void Make_Find_Requester(void)
265 WORD winwidth
, winheight
, gadwidth
, gadheight
;
268 if (findwin
|| !Init()) return;
270 gad
= CreateContext(&findgadlist
);
272 gadheight
= fontheight
+ GAD_EXTRA_HEIGHT
;
274 winheight
= scr
->WBorTop
+ fontheight
+ 1 +
276 BORDER_SPACING_Y
* 2 +
280 gadwidth
= TextLength(&temprp
, MSG(MSG_OK
), strlen(MSG(MSG_OK
)));
281 w
= TextLength(&temprp
, MSG(MSG_CANCEL
), strlen(MSG(MSG_CANCEL
)));
282 if (w
> gadwidth
) gadwidth
= w
;
284 gadwidth
+= GAD_EXTRA_WIDTH
;
286 strwidth
= gadwidth
* 2 + GAD_SPACING_X
;
288 if (strwidth
< 250) strwidth
= 250;
290 winwidth
= scr
->WBorLeft
+
292 BORDER_SPACING_X
* 2 +
295 ng
.ng_LeftEdge
= scr
->WBorLeft
+ BORDER_SPACING_X
;
296 ng
.ng_TopEdge
= scr
->WBorTop
+ fontheight
+ 1 + BORDER_SPACING_Y
;
297 ng
.ng_Width
= strwidth
;
298 ng
.ng_Height
= gadheight
;
299 ng
.ng_GadgetID
= GAD_FIND_TEXT
;
300 ng
.ng_Flags
= PLACETEXT_IN
;
302 findgad
= CreateGadget(STRING_KIND
, gad
, &ng
, GTST_MaxChars
, 256,
305 ng
.ng_TopEdge
+= gadheight
+ GAD_SPACING_Y
;
306 ng
.ng_Width
= gadwidth
;
307 ng
.ng_GadgetText
= MSG(MSG_OK
);
308 ng
.ng_GadgetID
= GAD_FIND_OK
;
310 gad
= CreateGadgetA(BUTTON_KIND
, findgad
, &ng
, 0);
312 ng
.ng_LeftEdge
= winwidth
- scr
->WBorRight
- BORDER_SPACING_X
- gadwidth
;
313 ng
.ng_GadgetText
= MSG(MSG_CANCEL
);
314 ng
.ng_GadgetID
= GAD_FIND_CANCEL
;
316 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, 0);
320 FreeGadgets(findgadlist
);
323 findwin
= OpenWindowTags(0, WA_CustomScreen
, (IPTR
)scr
,
324 WA_Left
, scr
->MouseX
- (winwidth
/ 2),
325 WA_Top
, scr
->MouseY
- (winheight
/ 2),
327 WA_Height
, winheight
,
329 WA_Title
, (IPTR
)MSG(MSG_FIND_TITLE
),
330 WA_CloseGadget
, TRUE
,
331 WA_DepthGadget
, TRUE
,
334 WA_SimpleRefresh
, TRUE
,
335 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
336 IDCMP_REFRESHWINDOW
|
340 WA_Gadgets
, (IPTR
)findgadlist
,
345 FreeGadgets(findgadlist
);findgadlist
= 0;
347 findmask
= 1L << findwin
->UserPort
->mp_SigBit
;
348 GT_RefreshWindow(findwin
, 0);
349 ActivateGadget(findgad
, findwin
, 0);
354 /****************************************************************************************/
356 WORD
Handle_Find_Requester(char **text
)
358 struct IntuiMessage
*msg
;
360 BOOL killreq
= FALSE
, rc
= 0;
362 while ((msg
= GT_GetIMsg(findwin
->UserPort
)))
366 case IDCMP_REFRESHWINDOW
:
367 GT_BeginRefresh(findwin
);
368 GT_EndRefresh(findwin
, TRUE
);
371 case IDCMP_CLOSEWINDOW
:
376 switch (((struct Gadget
*)msg
->IAddress
)->GadgetID
)
378 case GAD_FIND_CANCEL
:
384 GT_GetGadgetAttrs(findgad
, findwin
, 0, GTST_String
, (IPTR
)&sp
,
386 strcpy(searchtext
, sp
);
391 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
394 case IDCMP_VANILLAKEY
:
395 switch(ToUpper(msg
->Code
))
404 ActivateGadget(findgad
, findwin
, 0);
416 } /* switch(msg->Code) */
419 } /* switch (msg->Class) */
422 } /* while ((msg = GT_GetIMsg(findwin))) */
424 if (killreq
) Kill_Find_Requester();
426 if (rc
) *text
= searchtext
;
431 /****************************************************************************************/
433 void Kill_Find_Requester(void)
437 CloseWindow(findwin
);findwin
= 0;findmask
= 0;
442 FreeGadgets(findgadlist
);findgadlist
= 0;
446 /****************************************************************************************/