7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
14 * Revision 42.5 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.4 2003/01/18 19:10:00 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.3 2000/08/09 11:45:57 chodorowski
21 * Removed a lot of #ifdefs that disabled the AROS_LIB* macros when not building on AROS. This is now handled in contrib/bgui/include/bgui_compilerspecific.h.
23 * Revision 42.2 2000/05/15 19:27:02 stegerg
24 * another hundreds of REG() macro replacements in func headers/protos.
26 * Revision 42.1 2000/05/14 23:32:48 stegerg
27 * changed over 200 function headers which all use register
28 * parameters (oh boy ...), because the simple REG() macro
29 * doesn't work with AROS. And there are still hundreds
30 * of headers left to be fixed :(
32 * Many of these functions would also work with stack
33 * params, but since i have fixed every single one
34 * I encountered up to now, I guess will have to do
35 * the same for the rest.
37 * Revision 42.0 2000/05/09 22:10:03 mlemos
38 * Bumped to revision 42.0 before handing BGUI to AROS team
40 * Revision 41.11 2000/05/09 19:54:59 mlemos
41 * Merged with the branch Manuel_Lemos_fixes.
43 * Revision 41.10 1998/02/25 21:12:59 mlemos
46 * Revision 1.1 1998/02/25 17:09:37 mlemos
52 #include "include/classdefs.h"
58 struct bguiRequest
*ihd_Request
; /* Requester structure. */
59 Object
*ihd_ReturnObj
; /* Return key object. */
60 ULONG ihd_MaxID
; /* Maximum gadget ID. */
64 * Parse a button label.
66 STATIC ASM UBYTE
*GetButtonName( REG(a0
) UBYTE
*source
, REG(a1
) UBYTE
*uc
, REG(d0
) ULONG uchar
)
71 * Search for the end-of-string or
72 * the seperator character.
74 while (*source
&& *source
!= '|')
77 * Look up the character
82 uc
[0] = tolower(source
[1]);
88 * When we reached a seperator we
89 * truncate the gadget string and
90 * return a pointer to the next
100 * The end, finito, ende, einde....
106 * Create the button group.
108 STATIC Object
*CreateButtonGroup( UBYTE
*gstring
, ULONG xen
, UBYTE uchar
, ULONG
*maxid
, Object
**retobj
)
110 Object
*master
, *button
;
111 UBYTE
*ptr
, underscore
[ 2 ];
112 UWORD id
= 2, style
= FS_NORMAL
;
113 BOOL sing
= FALSE
, got_def
= FALSE
;
118 if (!strchr( gstring
, '|'))
122 * Create a horizontal master group.
124 if ((master
= BGUI_NewObject(BGUI_GROUP_GADGET
, GROUP_Spacing
, GRSPACE_WIDE
, GROUP_EqualWidth
, TRUE
, TAG_END
)))
127 * Add a spacing object for single
132 if (!AsmDoMethod(master
, GRM_ADDSPACEMEMBER
, DEFAULT_WEIGHT
))
137 * Loop to get all the gadgets
140 while ((ptr
= gstring
))
143 * Get a pointer to the next
146 gstring
= GetButtonName( gstring
, &underscore
[ 0 ], uchar
);
151 if ((*ptr
== '*') && (!got_def
))
161 if ((button
= BGUI_NewObject(BGUI_BUTTON_GADGET
, LAB_Label
, ptr
, LAB_Style
, style
, LAB_Underscore
, uchar
,
162 GA_ID
, id
++, BT_Key
, underscore
, xen
? FRM_Type
: TAG_IGNORE
, FRTYPE_XEN_BUTTON
, TAG_DONE
)))
165 * Pick this button if it's the first
166 * created or the default button.
168 if ((id
== 3) || (style
== FSF_BOLD
))
172 * Add it to the master group.
174 if ( ! AsmDoMethod( master
, GRM_ADDMEMBER
, button
, LGO_FixMinHeight
, TRUE
, TAG_END
))
181 * Button creation failed.
184 DisposeObject( master
);
194 * Save the maximum gadget ID.
199 * Add a spacing object for single
204 if (!AsmDoMethod(master
, GRM_ADDSPACEMEMBER
, DEFAULT_WEIGHT
))
209 * The last (right most) button get's
210 * 0 as it's ID to keep compatible with
211 * intuition's EasyRequest().
213 DoSetMethod(button
, NULL
, GA_ID
, 1, TAG_END
);
216 * Return the master group.
224 * Requester IDCMP hook.
226 //STATIC SAVEDS ASM VOID ReqHookFunc(REG(a0) struct Hook *hook, REG(a2) Object *window, REG(a1) struct IntuiMessage *msg)
227 STATIC SAVEDS ASM
REGFUNC3(IPTR
, ReqHookFunc
,
228 REGPARAM(A0
, struct Hook
*, hook
),
229 REGPARAM(A2
, Object
*, window
),
230 REGPARAM(A1
, struct IntuiMessage
*, msg
))
232 IHD
*ihd
= (IHD
*)hook
->h_Data
;
236 * Which key was pressed?
244 if (msg
->Qualifier
& IEQUALIFIER_LCOMMAND
)
245 id
= (ihd
->ihd_MaxID
== 1) ? 1 : 2;
252 if (msg
->Qualifier
& IEQUALIFIER_LCOMMAND
)
261 if (ihd
->ihd_Request
->br_Flags
& BREQF_FAST_KEYS
)
262 id
= (ihd
->ihd_MaxID
== 1) ? 1 : GADGET(ihd
->ihd_ReturnObj
)->GadgetID
;
269 if (ihd
->ihd_Request
->br_Flags
& BREQF_FAST_KEYS
)
273 if (id
) AsmDoMethod(window
, WM_REPORT_ID
, id
, 0);
278 static struct Hook ReqHook
= { { NULL
, NULL
}, (HOOKFUNC
)ReqHookFunc
, NULL
, NULL
};
281 * Put up a BGUI requester.
285 AROS_LH3(ULONG
, BGUI_RequestA
,
286 AROS_LHA(struct Window
*, win
, A0
),
287 AROS_LHA(struct bguiRequest
*, es
, A1
),
288 AROS_LHA(IPTR
*, args
, A2
),
289 struct Library
*, BGUIBase
, 7, BGUI
)
291 makeproto SAVEDS ASM ULONG
BGUI_RequestA(REG(a0
) struct Window
*win
, REG(a1
) struct bguiRequest
*es
, REG(a2
) IPTR
*args
)
297 struct Screen
*screen
;
302 ULONG id
, maxid
= 0, rc
= ~0;
305 BOOL cw
= FALSE
, running
= TRUE
;
308 * Center on the window?
310 if (( es
->br_Flags
& BREQF_CENTERWINDOW
) && win
)
316 screen
= win
? win
->WScreen
: es
->br_Screen
;
319 * We need these strings.
321 if (es
->br_TextFormat
&& es
->br_GadgetFormat
)
324 * Allocate private copy of the gadget string.
326 if ((gstr
= (UBYTE
*)BGUI_AllocPoolMem(strlen(es
->br_GadgetFormat
) + 1)))
329 * Copy the gadget string.
331 strcpy(gstr
, es
->br_GadgetFormat
);
334 * Figure out requester title.
336 if (es
->br_Title
) wdt
= es
->br_Title
;
339 if (win
&& win
->Title
) wdt
= win
->Title
;
343 wdt
= LOCSTR(MSG_BGUI_REQUESTA_TITLE
);
348 * Create a window object.
350 window
= WindowObject
,
351 WINDOW_Position
, es
->br_ReqPos
,
352 cw
? WINDOW_PosRelBox
: TAG_IGNORE
, IBOX( &win
->LeftEdge
),
354 WINDOW_CloseGadget
, FALSE
,
355 WINDOW_SizeGadget
, FALSE
,
356 WINDOW_RMBTrap
, TRUE
,
357 WINDOW_SmartRefresh
, TRUE
,
358 WINDOW_Font
, es
->br_TextAttr
,
359 WINDOW_IDCMP
, IDCMP_RAWKEY
,
360 WINDOW_IDCMPHookBits
, IDCMP_RAWKEY
,
361 WINDOW_IDCMPHook
, &ReqHook
,
362 WINDOW_NoBufferRP
, TRUE
,
363 WINDOW_AutoAspect
, es
->br_Flags
& BREQF_AUTO_ASPECT
? TRUE
: FALSE
,
364 WINDOW_AutoKeyLabel
, TRUE
,
366 screen
? WINDOW_Screen
: TAG_IGNORE
, screen
,
369 VGroupObject
, NormalHOffset
, NormalVOffset
, NormalSpacing
,
370 es
->br_Flags
& BREQF_NO_PATTERN
? TAG_IGNORE
: GROUP_BackFill
, SHINE_RASTER
,
373 FRM_Type
, FRTYPE_BUTTON
,
375 INFO_TextFormat
, es
->br_TextFormat
,
376 INFO_FixTextWidth
, TRUE
,
377 INFO_FixTextHeight
, TRUE
,
379 INFO_HorizOffset
, 10,
384 CreateButtonGroup(gstr
, es
->br_Flags
& BREQF_XEN_BUTTONS
, es
->br_Underscore
, &maxid
, &ihd
.ihd_ReturnObj
),
385 LGO_FixMinHeight
, TRUE
,
395 ihd
.ihd_Request
= es
;
396 ihd
.ihd_MaxID
= maxid
;
397 ReqHook
.h_Data
= ( APTR
)&ihd
;
400 * Open the window and wait
401 * for a gadget click.
403 if ((wptr
= (struct Window
*)AsmDoMethod(window
, WM_OPEN
)))
406 * Lock parent window?
408 if ((es
->br_Flags
& BREQF_LOCKWINDOW
) && win
)
409 rlock
= BGUI_LockWindow(win
);
412 * Pick up signal bit.
414 Get_Attr(window
, WINDOW_SigMask
, &signal
);
419 while((id
= (ULONG
)AsmDoMethod( window
, WM_HANDLEIDCMP
)) != WMHI_NOMORE
)
424 if (id
>= 1 && id
<= maxid
)
431 AsmDoMethod(window
, WM_CLOSE
);
432 BGUI_UnlockWindow(rlock
);
434 DisposeObject(window
);
436 BGUI_FreePoolMem(gstr
);