include/muimaster/macros.h: get() compiler delint
[AROS.git] / workbench / libs / muimaster / mui_makeobject.c
blob02a187dcc21d96575cb314bc32f85030c5150945
1 /*
2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <proto/alib.h>
9 #include <proto/intuition.h>
10 #include <intuition/classusr.h>
11 #include <libraries/gadtools.h>
12 #include <proto/dos.h>
13 #include <proto/utility.h>
14 #include <proto/muimaster.h>
15 #include <string.h>
17 #ifdef HAVE_COOLIMAGES
18 #include <libraries/coolimages.h>
19 #include <proto/coolimages.h>
20 #endif
22 #include "muimaster_intern.h"
23 #include "mui.h"
25 /* #define MYDEBUG 1 */
26 #include "debug.h"
28 extern struct Library *MUIMasterBase;
30 STATIC int get_control_char(const char *label)
32 /* find the control char */
33 int control_char = 0;
35 if (label)
37 const unsigned char *p = (const unsigned char *)label;
38 unsigned char c;
40 while ((c = *p++))
42 if (c == '_')
44 control_char = ToLower(*p);
45 break;
50 return control_char;
53 STATIC Object *CreateMenuString(struct NewMenu * newmenu, ULONG flags,
54 struct Library * MUIMasterBase)
56 int i = 0;
57 UWORD nmflags;
59 Object *menustrip = (Object *) MenustripObject, End;
60 Object *menu = NULL;
61 Object *menuitem = NULL;
63 if (!menustrip)
64 return NULL;
66 for (; newmenu[i].nm_Type != NM_END; i++)
68 nmflags = newmenu[i].nm_Flags;
70 if (newmenu[i].nm_Type == NM_TITLE)
72 menu = (Object *)MenuObject,
73 MUIA_Menu_Title, (IPTR)newmenu[i].nm_Label,
74 MUIA_UserData, (IPTR)newmenu[i].nm_UserData,
75 MUIA_Menu_Enabled, (nmflags & NM_MENUDISABLED) == 0,
76 End;
77 if (menu)
78 DoMethod(menustrip, MUIM_Family_AddTail, (IPTR) menu);
79 menuitem = NULL;
81 else
83 char *label = (char *)newmenu[i].nm_Label;
84 char *commkey;
86 if ((flags & MUIO_MenustripNM_CommandKeyCheck)
87 && label != (char *)NM_BARLABEL && label[1] == '\0')
89 label += 2;
90 commkey = label;
92 else
93 commkey = (char *)newmenu[i].nm_CommKey;
95 if (newmenu[i].nm_Type == NM_ITEM || (menuitem != NULL
96 && newmenu[i].nm_Type == NM_SUB))
98 Object *item = (Object *)(MenuitemObject,
99 MUIA_Menuitem_Title, (IPTR)label,
100 MUIA_Menuitem_Shortcut, (IPTR)commkey,
101 MUIA_UserData, (IPTR)newmenu[i].nm_UserData,
102 MUIA_Menuitem_Exclude, (IPTR)newmenu[i].nm_MutualExclude,
103 MUIA_Menuitem_Checkit, (nmflags & CHECKIT) != 0,
104 MUIA_Menuitem_Checked, (nmflags & CHECKED) != 0,
105 MUIA_Menuitem_Toggle, (nmflags & MENUTOGGLE) != 0,
106 MUIA_Menuitem_CommandString,
107 (nmflags & NM_COMMANDSTRING) != 0,
108 MUIA_Menuitem_Enabled, (nmflags & NM_ITEMDISABLED) == 0,
109 End);
111 if (item != NULL)
113 if (newmenu[i].nm_Type == NM_ITEM)
115 DoMethod(menu, MUIM_Family_AddTail, (IPTR) item);
116 menuitem = item;
118 else
119 DoMethod(menuitem, MUIM_Family_AddTail,
120 (IPTR) item);
125 return menustrip;
129 Object *INTERNAL_ImageButton(CONST_STRPTR label, CONST_STRPTR imagePath,
130 struct TextFont * textFont)
132 # define BUFFERSIZE 512
134 BPTR lock = Lock(imagePath, ACCESS_READ);
136 D(bug("[ImageButton] Font 0x%p\n", textFont));
137 if (lock != BNULL)
140 TEXT imageSpec[BUFFERSIZE];
141 TEXT controlChar = get_control_char(label);
143 imageSpec[0] = '\0';
144 strlcat(imageSpec, "3:", BUFFERSIZE);
145 strlcat(imageSpec, imagePath, BUFFERSIZE);
147 UnLock(lock);
149 return (Object *) HGroup,
150 ButtonFrame,
151 MUIA_Background, MUII_ButtonBack,
152 MUIA_CycleChain, 1,
153 MUIA_InputMode, MUIV_InputMode_RelVerify,
154 MUIA_Group_Spacing, 0,
155 //MUIA_Group_SameHeight, TRUE,
156 controlChar ? MUIA_ControlChar : TAG_IGNORE, (IPTR) controlChar,
158 Child, (IPTR)HVSpace,
159 Child, (IPTR)ImageObject,
160 MUIA_Image_Spec, (IPTR) imageSpec,
161 MUIA_Image_FreeVert, FALSE,
162 MUIA_Image_FreeHoriz, FALSE,
163 MUIA_Image_FontMatch, TRUE,
164 MUIA_Font, (IPTR) textFont,
165 MUIA_Weight, 0,
166 End,
167 Child, (IPTR)HSpace(4),
168 Child, (IPTR)TextObject,
169 MUIA_Font, (IPTR) MUIV_Font_Button,
170 MUIA_Text_HiCharIdx, (IPTR) '_',
171 MUIA_Text_Contents, (IPTR) label,
172 MUIA_Text_PreParse, (IPTR) "\33c",
173 MUIA_Weight, 0,
174 End,
175 Child, (IPTR)HVSpace,
176 End;
179 else
181 return SimpleButton(label);
184 # undef BUFFERSIZE
187 /*****************************************************************************
189 NAME */
190 AROS_LH2(Object *, MUI_MakeObjectA,
192 /* SYNOPSIS */
193 AROS_LHA(LONG, type, D0),
194 AROS_LHA(IPTR *, params, A0),
196 /* LOCATION */
197 struct Library *, MUIMasterBase, 20, MUIMaster)
199 /* FUNCTION
200 Create an object from the builtin object collection.
201 See file libraries/mui.h for a list of available objects
202 and their parameters. Note that this is not a taglist.
204 INPUTS
205 type - kind of builtin object
206 params - additional parameters for object
208 RESULT
209 Pointer to object
211 NOTES
213 EXAMPLE
215 BUGS
217 SEE ALSO
218 MUI_CreateCustomClass(), MUI_DeleteCustomClass()
220 INTERNALS
222 *****************************************************************************/
224 AROS_LIBFUNC_INIT
226 switch (type)
228 case MUIO_Label: /* STRPTR label, ULONG flags */
230 struct TagItem tags[5];
231 int ntags = 0;
233 if (params[1] & MUIO_Label_SingleFrame)
235 tags[ntags].ti_Tag = MUIA_Frame;
236 tags[ntags].ti_Data = (IPTR) MUIV_Frame_ImageButton;
237 ntags++;
239 else if (params[1] & MUIO_Label_DoubleFrame)
241 tags[ntags].ti_Tag = MUIA_Frame;
242 tags[ntags].ti_Data = (IPTR) MUIV_Frame_String;
243 ntags++;
246 if (params[1] & MUIO_Label_LeftAligned)
248 tags[ntags].ti_Tag = MUIA_Text_PreParse;
249 tags[ntags].ti_Data = (IPTR) "\33l";
250 ntags++;
252 else if (params[1] & MUIO_Label_Centered)
254 tags[ntags].ti_Tag = MUIA_Text_PreParse;
255 tags[ntags].ti_Data = (IPTR) "\33c";
256 ntags++;
258 else
260 tags[ntags].ti_Tag = MUIA_Text_PreParse;
261 tags[ntags].ti_Data = (IPTR) "\33r";
262 ntags++;
265 if (params[1] & MUIO_Label_FreeVert)
267 tags[ntags].ti_Tag = MUIA_Text_SetVMax;
268 tags[ntags].ti_Data = (IPTR) FALSE;
269 ntags++;
272 tags[ntags].ti_Tag = TAG_DONE;
273 tags[ntags].ti_Data = 0;
275 return MUI_NewObject(MUIC_Text,
276 MUIA_FramePhantomHoriz, TRUE,
277 MUIA_Weight, 0,
278 //MUIA_Text_SetMax, TRUE,
279 (params[1] & 0xff) ? MUIA_Text_HiChar : TAG_IGNORE,
280 params[1] & 0xff,
281 (params[1] & 0xff) ? TAG_IGNORE : MUIA_Text_HiCharIdx, '_',
282 MUIA_Text_Contents, params[0],
283 TAG_MORE, tags,
284 TAG_DONE);
285 break;
288 case MUIO_CoolButton: /* STRPTR label, APTR CoolImage, ULONG flags */
289 #ifdef HAVE_COOLIMAGES
290 if (CoolImagesBase)
292 struct CoolImage *img;
293 char *label = (char*)params[0];
294 int control_char = 0;
295 ULONG flags = params[2];
297 if (flags & MUIO_CoolButton_CoolImageID)
299 img = (struct CoolImage *)COOL_ObtainImageA(params[1], NULL);
301 else
303 img = (struct CoolImage *)params[1];
306 if (img)
308 control_char = get_control_char(label);
310 return (Object *)HGroup,
311 MUIA_VertWeight, 0,
312 ButtonFrame,
313 MUIA_Background, MUII_ButtonBack,
314 MUIA_InputMode, MUIV_InputMode_RelVerify,
315 MUIA_CycleChain, 1,
316 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
317 MUIA_Group_HorizSpacing, 0,
318 MUIA_Group_SameHeight, TRUE,
319 Child, (IPTR)HSpace(2),
320 Child, (IPTR)VGroup,
321 MUIA_Group_VertSpacing, 0,
322 Child, (IPTR)RectangleObject, End,
323 Child, (IPTR)ChunkyImageObject,
324 MUIA_FixWidth, img->width,
325 MUIA_FixHeight, img->height,
326 MUIA_ChunkyImage_Pixels, (IPTR)img->data,
327 MUIA_ChunkyImage_NumColors, img->numcolors,
328 MUIA_ChunkyImage_Palette, (IPTR)img->pal,
329 MUIA_Bitmap_Width, img->width,
330 MUIA_Bitmap_Height, img->height,
331 MUIA_Bitmap_UseFriend, TRUE,
332 MUIA_Bitmap_Transparent, 0,
333 End,
334 Child, (IPTR)RectangleObject, End,
335 End,
336 Child, (IPTR)HSpace(2),
337 Child, (IPTR)RectangleObject, End,
338 Child, (IPTR)VGroup,
339 MUIA_Group_VertSpacing, 0,
340 Child, (IPTR)RectangleObject, End,
341 Child, (IPTR)TextObject,
342 MUIA_Font, (IPTR)MUIV_Font_Button,
343 MUIA_Text_HiCharIdx, '_',
344 MUIA_Text_Contents, (IPTR)label,
345 MUIA_Text_SetMax, TRUE,
346 End,
347 Child, (IPTR)RectangleObject, End,
348 End,
349 Child, (IPTR)RectangleObject, End,
350 Child, (IPTR)HSpace(2),
351 End;
353 } /* if (img) */
355 } /* if (CoolImagesBase) */
356 #endif
357 /* fall through */
359 case MUIO_Button: /* STRPTR label */
361 int control_char = get_control_char((const char *)params[0]);
363 return MUI_NewObject(MUIC_Text,
364 ButtonFrame,
365 MUIA_Font, MUIV_Font_Button,
366 MUIA_Text_HiCharIdx, '_',
367 MUIA_Text_Contents, params[0],
368 MUIA_Text_PreParse, "\33c",
369 MUIA_InputMode , MUIV_InputMode_RelVerify,
370 MUIA_Background , MUII_ButtonBack,
371 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
372 MUIA_CycleChain, 1,
373 TAG_DONE);
375 case MUIO_ImageButton:
376 return INTERNAL_ImageButton
378 (CONST_STRPTR) params[0],
379 (CONST_STRPTR) params[1],
380 ((struct MUIMasterBase_intern *)MUIMasterBase)->topaz8font
383 case MUIO_Checkmark: /* STRPTR label */
385 int control_char = get_control_char((const char *)params[0]);
387 return MUI_NewObject(MUIC_Image,
388 ImageButtonFrame,
389 MUIA_Background, MUII_ButtonBack,
390 MUIA_Weight,0,
391 MUIA_Image_Spec, MUII_CheckMark,
392 MUIA_InputMode, MUIV_InputMode_Toggle,
393 MUIA_Image_FreeVert, TRUE,
394 MUIA_ShowSelState, FALSE,
395 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
396 TAG_DONE);
397 break;
400 case MUIO_Cycle: /* STRPTR label, STRPTR *entries */
402 int control_char = get_control_char((const char *)params[0]);
404 return MUI_NewObject(MUIC_Cycle,
405 ButtonFrame,
406 MUIA_Font, MUIV_Font_Button,
407 MUIA_Cycle_Entries, params[1],
408 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
409 MUIA_CycleChain, 1,
410 TAG_DONE);
411 break;
413 case MUIO_Radio: /* STRPTR label, STRPTR *entries */
415 int control_char = get_control_char((const char *)params[0]);
417 return MUI_NewObject(MUIC_Radio,
418 MUIA_Radio_Entries, params[1],
419 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
420 TAG_DONE);
421 break;
425 case MUIO_Slider: /* STRPTR label, LONG min, LONG max */
427 int control_char = get_control_char((const char *)params[0]);
429 return (Object *)SliderObject,
430 MUIA_Numeric_Min, params[1],
431 MUIA_Numeric_Max, params[2],
432 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
433 End;
434 break;
436 case MUIO_String: /* STRPTR label, LONG maxlen */
438 int control_char = get_control_char((const char *)params[0]);
440 return MUI_NewObject(MUIC_String,
441 StringFrame,
442 MUIA_String_MaxLen,params[1],
443 control_char ? MUIA_ControlChar : TAG_IGNORE, control_char,
444 TAG_DONE);
445 break;
447 case MUIO_PopButton: /* STRPTR imagespec */
448 return MUI_NewObject(MUIC_Image,
449 ImageButtonFrame,
450 MUIA_Background, MUII_ButtonBack,
451 MUIA_Image_Spec, params[0],
452 MUIA_InputMode, MUIV_InputMode_RelVerify,
453 MUIA_Image_FreeVert, TRUE,
454 MUIA_Image_FreeHoriz, FALSE,
455 TAG_DONE);
456 break;
458 case MUIO_HSpace: /* LONG space */
459 return MUI_NewObject(MUIC_Rectangle,
460 MUIA_VertWeight, 0,
461 MUIA_FixWidth, params[0],
462 TAG_DONE);
463 break;
465 case MUIO_VSpace: /* LONG space */
466 return MUI_NewObject(MUIC_Rectangle,
467 MUIA_HorizWeight, 0,
468 MUIA_FixHeight, params[0],
469 TAG_DONE);
470 break;
472 case MUIO_HBar: /* LONG space */
473 return MUI_NewObject(MUIC_Rectangle,
474 MUIA_Rectangle_HBar, TRUE,
475 MUIA_FixHeight, params[0],
476 TAG_DONE);
477 break;
479 case MUIO_VBar: /* LONG space */
480 return MUI_NewObject(MUIC_Rectangle,
481 MUIA_Rectangle_VBar, TRUE,
482 MUIA_FixWidth, params[0],
483 TAG_DONE);
484 break;
486 case MUIO_MenustripNM: /* struct NewMenu *nm, ULONG flags */
487 return CreateMenuString((struct NewMenu *)params[0], params[1],
488 MUIMasterBase);
490 case MUIO_Menuitem: /* STRPTR label, STRPTR shortcut, ULONG flags, ULONG data */
491 return MUI_NewObject( MUIC_Menuitem,
492 MUIA_Menuitem_Title, params[0],
493 MUIA_Menuitem_Shortcut, params[1],
494 MUIA_Menuitem_Checkit, !!(params[2] & CHECKIT),
495 MUIA_Menuitem_Checked, !!(params[2] & CHECKED),
496 MUIA_Menuitem_Toggle, !!(params[2] & MENUTOGGLE),
497 MUIA_Menuitem_Enabled, !(params[2] & NM_ITEMDISABLED),
498 /* flags NYI */
499 MUIA_UserData, params[3],
500 TAG_DONE);
502 case MUIO_BarTitle: /* STRPTR label */
503 return MUI_NewObject(MUIC_Rectangle,
504 MUIA_Rectangle_HBar, TRUE,
505 MUIA_Rectangle_BarTitle, params[0],
506 MUIA_FixHeight, 1,
507 TAG_DONE);
508 break;
510 case MUIO_NumericButton: /* STRPTR label, LONG min, LONG max, STRPTR format */
512 int control_char = get_control_char((const char *)params[0]);
514 return MUI_NewObject(MUIC_Numericbutton,
515 MUIA_Numeric_Min, params[1],
516 MUIA_Numeric_Max, params[2],
517 (params[3] ? MUIA_Numeric_Format : TAG_IGNORE), params[3],
518 (control_char ? MUIA_ControlChar: TAG_IGNORE), control_char,
519 TAG_DONE);
521 break;
524 return NULL;
526 AROS_LIBFUNC_EXIT
527 } /* MUIA_MakeObjectA */