disable the unrecognized nls flag
[AROS-Contrib.git] / bgui / misc.c
bloba4ae264257d4f26c094e3210e45824cc39d1707b
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * misc.c
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.
13 * $Log$
14 * Revision 42.4 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.3 2003/01/18 19:09:59 chodorowski
18 * Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
20 * Revision 42.2 2000/05/29 00:40:24 bergers
21 * Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
23 * Revision 42.1 2000/05/14 23:32:48 stegerg
24 * changed over 200 function headers which all use register
25 * parameters (oh boy ...), because the simple REG() macro
26 * doesn't work with AROS. And there are still hundreds
27 * of headers left to be fixed :(
29 * Many of these functions would also work with stack
30 * params, but since i have fixed every single one
31 * I encountered up to now, I guess will have to do
32 * the same for the rest.
34 * Revision 42.0 2000/05/09 22:09:42 mlemos
35 * Bumped to revision 42.0 before handing BGUI to AROS team
37 * Revision 41.11 2000/05/09 19:54:46 mlemos
38 * Merged with the branch Manuel_Lemos_fixes.
40 * Revision 41.10.2.4 1998/12/07 03:07:08 mlemos
41 * Replaced OpenFont and CloseFont calls by the respective BGUI debug macros.
43 * Revision 41.10.2.3 1998/11/23 14:59:16 mlemos
44 * Fixed mistaken initialization of allocated buffer.
46 * Revision 41.10.2.2 1998/11/16 20:11:04 mlemos
47 * Added missing brackets in the previous changes.
49 * Revision 41.10.2.1 1998/11/16 19:59:24 mlemos
50 * Replaced AllocVec and FreeVec calls by BGUI_AllocPoolMem and
51 * BGUI_FreePoolMem calls respectively.
53 * Revision 41.10 1998/02/25 21:12:40 mlemos
54 * Bumping to 41.10
56 * Revision 1.1 1998/02/25 17:09:07 mlemos
57 * Ian sources
62 #ifdef __AROS__
63 #include "include/bgui_macros.h"
64 #endif
66 #include "include/classdefs.h"
68 makeproto struct TextAttr Topaz80 =
70 "topaz.font",
71 TOPAZ_EIGHTY,
72 FS_NORMAL,
73 FPF_ROMFONT
76 makeproto ASM LONG max(REG(d0) LONG a, REG(d1) LONG b)
77 { return (a > b) ? a : b; }
79 makeproto ASM LONG min(REG(d0) LONG a, REG(d1) LONG b)
80 { return (a < b) ? a : b; }
82 makeproto ASM LONG abs(REG(d0) LONG a)
83 { return (a > 0) ? a :-a; }
85 makeproto ASM LONG range(REG(d0) LONG c, REG(d1) LONG a, REG(d2) LONG b)
87 if (c < a) return a;
88 if (c > b) return b;
89 return c;
93 * Count the number of labels in an array.
95 makeproto ASM ULONG CountLabels(REG(a0) UBYTE **labels)
97 int n = 0;
99 while (labels[n]) n++;
101 return (ULONG)(n - 1);
105 * See if a point is in a box.
107 makeproto ASM BOOL PointInBox(REG(a0) struct IBox *box, REG(d0) WORD x, REG(d1) WORD y)
109 x -= box->Left;
110 y -= box->Top;
112 return (BOOL)((x >= 0) && (y >= 0) && (x < box->Width) && (y < box->Height));
116 * Scale a width and height.
118 makeproto VOID Scale(struct RastPort *rp, UWORD *width, UWORD *height, UWORD dwidth, UWORD dheight, struct TextAttr *font)
120 struct TextFont *tf;
121 int open = FALSE;
122 ULONG fw, fh;
125 * Setup the font.
127 if (font)
129 if ((tf = BGUI_OpenFont(font)))
130 open = TRUE;
132 else
134 tf = rp->Font;
138 * Get font size.
140 if (tf->tf_Flags & FPF_PROPORTIONAL)
142 fw = (tf->tf_Modulo << 3) / (tf->tf_HiChar - tf->tf_LoChar);
144 else
146 fw = tf->tf_XSize;
148 fh = tf->tf_YSize;
151 * Close font.
153 if (open) BGUI_CloseFont(tf);
156 * Scale size;
158 *height = fh + (dheight - 8);
159 *width = fw + (dwidth - 8);
163 * Map a RAW key to an ansi character.
165 makeproto WORD MapKey(UWORD code, UWORD qualifier, APTR *iaddress)
167 struct InputEvent ie = { NULL };
168 UBYTE chr;
170 ie.ie_Class = IECLASS_RAWKEY;
171 ie.ie_Code = code;
172 ie.ie_Qualifier = qualifier;
173 ie.ie_EventAddress = *iaddress;
175 if ( MapRawKey( &ie, &chr, 1, NULL ) != 1 )
176 return( ~0 );
178 return( chr );
182 * Show online-help requester.
184 makeproto ASM VOID ShowHelpReq( REG(a0) struct Window *win, REG(a1) UBYTE *text )
186 struct bguiRequest req = { };
188 InitLocale();
190 req.br_Title = LOCSTR( MSG_BGUI_HELP_TITLE );
191 req.br_GadgetFormat = LOCSTR( MSG_BGUI_HELP_CONTINUE );
192 req.br_TextFormat = text;
193 req.br_Flags = BREQF_CENTERWINDOW | BREQF_LOCKWINDOW | BREQF_AUTO_ASPECT;
195 BGUI_RequestA( win, &req, NULL );
200 * Re-allocate and format a buffer.
202 makeproto ASM UBYTE *DoBuffer(REG(a0) UBYTE *text, REG(a1) UBYTE **buf_ptr, REG(a2) ULONG *buf_len, REG(a3) RAWARG args)
204 ULONG len;
207 * Find out the formatted string length.
209 len = CompStrlenF( text, args );
212 * Longer than the current buffer?
214 if ( len > *buf_len ) {
216 * Deallocate old buffer.
218 if ( *buf_ptr )
219 BGUI_FreePoolMem( *buf_ptr );
221 * And allocate a new one.
223 if ( (*buf_ptr = ( UBYTE * )BGUI_AllocPoolMem( len ))) {
225 * Setup new buffer length.
227 **buf_ptr = '\0';
228 *buf_len = len;
230 else {
232 * Screw up.
234 *buf_len = 0;
235 return( text );
239 * Format the string.
241 DoSPrintF( *buf_ptr, text, args );
242 return( *buf_ptr );
246 * Set on multiple object.
248 makeproto VOID DoMultiSet(Tag tag, IPTR data, ULONG count, Object *obj1, ...)
250 ULONG i;
251 va_list ap;
252 va_start(ap, obj1);
254 for (i = 0; i < count; i++, obj1 = va_arg(ap, Object *))
255 if (obj1) DoSetMethodNG(obj1, tag, data, TAG_END);
257 va_end(ap);
261 * Set a gadget's bounds.
263 makeproto ASM VOID SetGadgetBounds(REG(a0) Object *obj, REG(a1) struct IBox *bounds)
265 DoSetMethodNG(obj, GA_Left, bounds->Left, GA_Top, bounds->Top,
266 GA_Width, bounds->Width, GA_Height, bounds->Height, TAG_DONE);
270 * Set an image's bounds.
272 makeproto ASM VOID SetImageBounds(REG(a0) Object *obj, REG(a1) struct IBox *bounds)
274 DoSetMethodNG(obj, IA_Left, bounds->Left, IA_Top, bounds->Top,
275 IA_Width, bounds->Width, IA_Height, bounds->Height, TAG_DONE);
280 * Un-map a mapped tag-list.
282 makeproto ASM VOID UnmapTags(REG(a0) struct TagItem *tags, REG(a1) struct TagItem *map)
284 struct TagItem *tag, *tag1;
285 struct TagItem *at = map;
288 * Go through the mapped tag-list.
290 while ((tag = NextTagItem(&at)))
293 * Is this tag in the unmapped list?
295 if ((tag1 = FindTagItem(tag->ti_Data, tags)))
297 * Yes. Unmap this tag.
299 tag1->ti_Tag = tag->ti_Tag;
304 * Create a vector image.
306 makeproto ASM Object *CreateVector(REG(a0) struct TagItem *attr)
308 struct TagItem *tag;
309 struct TagItem *tstate = attr;
311 while ((tag = NextTagItem(&tstate)))
313 if (VIT_TAG(tag->ti_Tag))
314 return BGUI_NewObjectA(BGUI_VECTOR_IMAGE, tag);
316 return NULL;
320 * Fix the tag pointer.
322 makeproto ASM struct TagItem *BGUI_NextTagItem(REG(a0) struct TagItem **t)
324 struct TagItem *rt, *tag, *tag2;
325 struct TagItem *tstate;
327 rt = NextTagItem(t);
329 if (rt)
331 switch (rt->ti_Tag)
333 case GROUP_Member:
334 tag2 = rt;
335 tstate = rt + 1;
336 while ((tag = NextTagItem(&tstate)))
337 tag2 = tag;
338 *t = tag2 + 2;
339 break;
342 return rt;