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>
25 #define CATCOMP_NUMBERS
34 #include <aros/debug.h>
36 /****************************************************************************************/
39 #define BORDER_SPACING_X 4
40 #define BORDER_SPACING_Y 4
42 #define GAD_SPACING_X 8
43 #define GAD_SPACING_Y 4
45 #define GAD_EXTRA_WIDTH 16
46 #define GAD_EXTRA_HEIGHT 6
48 enum {GAD_FIND_TEXT
= 1,
52 enum {GAD_GOTO_STRING
= 1,
56 /****************************************************************************************/
59 static struct RastPort temprp
;
60 static struct Window
*gotowin
, *findwin
;
61 static struct Gadget
*gotogad
, *findgad
, *gad
, *gotogadlist
, *findgadlist
;
62 static struct NewGadget ng
;
63 static WORD fontwidth
, fontheight
;
65 static char searchtext
[256];
67 /****************************************************************************************/
69 static BOOL
Init(void)
71 fontwidth
= dri
->dri_Font
->tf_XSize
;
72 fontheight
= dri
->dri_Font
->tf_YSize
;
74 InitRastPort(&temprp
);
75 SetFont(&temprp
, dri
->dri_Font
);
77 memset(&ng
, 0, sizeof(ng
));
78 ng
.ng_VisualInfo
= vi
;
83 /****************************************************************************************/
86 void CleanupRequesters(void)
88 if (gotowin
) Kill_Goto_Requester();
89 if (findwin
) Kill_Find_Requester();
92 /****************************************************************************************/
95 void Make_Goto_Requester(void)
97 WORD winwidth
, winheight
, gadwidth
, gadheight
;
100 if (gotowin
|| !Init()) return;
102 gad
= CreateContext(&gotogadlist
);
104 gadheight
= fontheight
+ GAD_EXTRA_HEIGHT
;
106 winheight
= scr
->WBorTop
+ fontheight
+ 1 +
108 BORDER_SPACING_Y
* 2 +
112 gadwidth
= TextLength(&temprp
, MSG(MSG_OK
), strlen(MSG(MSG_OK
)));
113 w
= TextLength(&temprp
, MSG(MSG_CANCEL
), strlen(MSG(MSG_CANCEL
)));
114 if (w
> gadwidth
) gadwidth
= w
;
116 gadwidth
+= GAD_EXTRA_WIDTH
;
118 strwidth
= gadwidth
* 2 + GAD_SPACING_X
;
120 winwidth
= scr
->WBorLeft
+
122 BORDER_SPACING_X
* 2 +
125 ng
.ng_LeftEdge
= scr
->WBorLeft
+ BORDER_SPACING_X
;
126 ng
.ng_TopEdge
= scr
->WBorTop
+ fontheight
+ 1 + BORDER_SPACING_Y
;
127 ng
.ng_Width
= strwidth
;
128 ng
.ng_Height
= gadheight
;
129 ng
.ng_GadgetID
= GAD_GOTO_STRING
;
130 ng
.ng_Flags
= PLACETEXT_IN
;
132 gotogad
= CreateGadget(INTEGER_KIND
, gad
, &ng
, GTIN_MaxChars
, 8,
133 STRINGA_Justification
, GACT_STRINGCENTER
,
136 ng
.ng_TopEdge
+= gadheight
+ GAD_SPACING_Y
;
137 ng
.ng_Width
= gadwidth
;
138 ng
.ng_GadgetText
= MSG(MSG_OK
);
139 ng
.ng_GadgetID
= GAD_GOTO_OK
;
141 gad
= CreateGadgetA(BUTTON_KIND
, gotogad
, &ng
, 0);
143 ng
.ng_LeftEdge
+= gadwidth
+ GAD_SPACING_X
;
144 ng
.ng_GadgetText
= MSG(MSG_CANCEL
);
145 ng
.ng_GadgetID
= GAD_GOTO_CANCEL
;
147 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, 0);
151 FreeGadgets(gotogadlist
);
154 gotowin
= OpenWindowTags(0, WA_CustomScreen
, (IPTR
)scr
,
155 WA_Left
, scr
->MouseX
- (winwidth
/ 2),
156 WA_Top
, scr
->MouseY
- (winheight
/ 2),
158 WA_Height
, winheight
,
160 WA_Title
, (IPTR
)MSG(MSG_JUMP_TITLE
),
161 WA_CloseGadget
, TRUE
,
162 WA_DepthGadget
, TRUE
,
165 WA_SimpleRefresh
, TRUE
,
166 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
167 IDCMP_REFRESHWINDOW
|
171 WA_Gadgets
, (IPTR
)gotogadlist
,
176 FreeGadgets(gotogadlist
);gotogadlist
= 0;
178 gotomask
= 1L << gotowin
->UserPort
->mp_SigBit
;
179 GT_RefreshWindow(gotowin
, 0);
180 ActivateGadget(gotogad
, gotowin
, 0);
185 /****************************************************************************************/
187 BOOL
Handle_Goto_Requester(LONG
*line
)
189 struct IntuiMessage
*msg
;
191 BOOL killreq
= FALSE
, rc
= FALSE
;
193 while ((msg
= GT_GetIMsg(gotowin
->UserPort
)))
197 case IDCMP_REFRESHWINDOW
:
198 GT_BeginRefresh(gotowin
);
199 GT_EndRefresh(gotowin
, TRUE
);
202 case IDCMP_CLOSEWINDOW
:
207 switch (((struct Gadget
*)msg
->IAddress
)->GadgetID
)
209 case GAD_GOTO_CANCEL
:
213 case GAD_GOTO_STRING
:
215 GT_GetGadgetAttrs(gotogad
, gotowin
, 0, GTIN_Number
, (IPTR
)&l
,
220 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
223 case IDCMP_VANILLAKEY
:
224 switch(toupper(msg
->Code
))
232 ActivateGadget(gotogad
, gotowin
, 0);
235 } /* switch(msg->Code) */
238 } /* switch (msg->Class) */
241 } /* while ((msg = GT_GetIMsg(gotowin))) */
243 if (killreq
) Kill_Goto_Requester();
250 /****************************************************************************************/
252 void Kill_Goto_Requester(void)
256 CloseWindow(gotowin
);gotowin
= 0;gotomask
= 0;
261 FreeGadgets(gotogadlist
);gotogadlist
= 0;
265 /****************************************************************************************/
267 void Make_Find_Requester(void)
269 WORD winwidth
, winheight
, gadwidth
, gadheight
;
272 if (findwin
|| !Init()) return;
274 gad
= CreateContext(&findgadlist
);
276 gadheight
= fontheight
+ GAD_EXTRA_HEIGHT
;
278 winheight
= scr
->WBorTop
+ fontheight
+ 1 +
280 BORDER_SPACING_Y
* 2 +
284 gadwidth
= TextLength(&temprp
, MSG(MSG_OK
), strlen(MSG(MSG_OK
)));
285 w
= TextLength(&temprp
, MSG(MSG_CANCEL
), strlen(MSG(MSG_CANCEL
)));
286 if (w
> gadwidth
) gadwidth
= w
;
288 gadwidth
+= GAD_EXTRA_WIDTH
;
290 strwidth
= gadwidth
* 2 + GAD_SPACING_X
;
292 if (strwidth
< 250) strwidth
= 250;
294 winwidth
= scr
->WBorLeft
+
296 BORDER_SPACING_X
* 2 +
299 ng
.ng_LeftEdge
= scr
->WBorLeft
+ BORDER_SPACING_X
;
300 ng
.ng_TopEdge
= scr
->WBorTop
+ fontheight
+ 1 + BORDER_SPACING_Y
;
301 ng
.ng_Width
= strwidth
;
302 ng
.ng_Height
= gadheight
;
303 ng
.ng_GadgetID
= GAD_FIND_TEXT
;
304 ng
.ng_Flags
= PLACETEXT_IN
;
306 findgad
= CreateGadget(STRING_KIND
, gad
, &ng
, GTST_MaxChars
, 256,
309 ng
.ng_TopEdge
+= gadheight
+ GAD_SPACING_Y
;
310 ng
.ng_Width
= gadwidth
;
311 ng
.ng_GadgetText
= MSG(MSG_OK
);
312 ng
.ng_GadgetID
= GAD_FIND_OK
;
314 gad
= CreateGadgetA(BUTTON_KIND
, findgad
, &ng
, 0);
316 ng
.ng_LeftEdge
= winwidth
- scr
->WBorRight
- BORDER_SPACING_X
- gadwidth
;
317 ng
.ng_GadgetText
= MSG(MSG_CANCEL
);
318 ng
.ng_GadgetID
= GAD_FIND_CANCEL
;
320 gad
= CreateGadgetA(BUTTON_KIND
, gad
, &ng
, 0);
324 FreeGadgets(findgadlist
);
327 findwin
= OpenWindowTags(0, WA_CustomScreen
, (IPTR
)scr
,
328 WA_Left
, scr
->MouseX
- (winwidth
/ 2),
329 WA_Top
, scr
->MouseY
- (winheight
/ 2),
331 WA_Height
, winheight
,
333 WA_Title
, (IPTR
)MSG(MSG_FIND_TITLE
),
334 WA_CloseGadget
, TRUE
,
335 WA_DepthGadget
, TRUE
,
338 WA_SimpleRefresh
, TRUE
,
339 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
340 IDCMP_REFRESHWINDOW
|
344 WA_Gadgets
, (IPTR
)findgadlist
,
349 FreeGadgets(findgadlist
);findgadlist
= 0;
351 findmask
= 1L << findwin
->UserPort
->mp_SigBit
;
352 GT_RefreshWindow(findwin
, 0);
353 ActivateGadget(findgad
, findwin
, 0);
358 /****************************************************************************************/
360 WORD
Handle_Find_Requester(char **text
)
362 struct IntuiMessage
*msg
;
364 BOOL killreq
= FALSE
, rc
= 0;
366 while ((msg
= GT_GetIMsg(findwin
->UserPort
)))
370 case IDCMP_REFRESHWINDOW
:
371 GT_BeginRefresh(findwin
);
372 GT_EndRefresh(findwin
, TRUE
);
375 case IDCMP_CLOSEWINDOW
:
380 switch (((struct Gadget
*)msg
->IAddress
)->GadgetID
)
382 case GAD_FIND_CANCEL
:
388 GT_GetGadgetAttrs(findgad
, findwin
, 0, GTST_String
, (IPTR
)&sp
,
390 strcpy(searchtext
, sp
);
395 } /* switch (((struct Gadget *)msg->IAddress)->GadgetID) */
398 case IDCMP_VANILLAKEY
:
399 switch(toupper(msg
->Code
))
408 ActivateGadget(findgad
, findwin
, 0);
420 } /* switch(msg->Code) */
423 } /* switch (msg->Class) */
426 } /* while ((msg = GT_GetIMsg(findwin))) */
428 if (killreq
) Kill_Find_Requester();
430 if (rc
) *text
= searchtext
;
435 /****************************************************************************************/
437 void Kill_Find_Requester(void)
441 CloseWindow(findwin
);findwin
= 0;findmask
= 0;
446 FreeGadgets(findgadlist
);findgadlist
= 0;
450 /****************************************************************************************/