Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / mui_makeobject.c
blob9b409dba00c5c31a433413cc5d791114b000c527
1 /*
2 Copyright 2002-2009, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <proto/intuition.h>
9 #include <intuition/classusr.h>
10 #include <libraries/gadtools.h>
11 #include <proto/dos.h>
12 #include <proto/utility.h>
13 #include <proto/muimaster.h>
14 #include <string.h>
16 #ifdef HAVE_COOLIMAGES
17 #include <libraries/coolimages.h>
18 #include <proto/coolimages.h>
19 #endif
21 #include "muimaster_intern.h"
22 #include "mui.h"
24 /* #define MYDEBUG 1 */
25 #include "debug.h"
27 extern struct Library *MUIMasterBase;
29 STATIC int get_control_char(const char *label)
31 /* find the control char */
32 int control_char = 0;
34 if (label)
36 const unsigned char *p = (const unsigned char *)label;
37 unsigned char c;
39 while ((c = *p++))
41 if (c == '_')
43 control_char = ToLower(*p);
44 break;
49 return control_char;
52 STATIC Object *CreateMenuString( struct NewMenu *newmenu, ULONG flags, struct Library *MUIMasterBase)
54 int i = 0;
56 Object *menustrip = (Object *)MenuitemObject,End;
57 Object *menu = NULL;
58 Object *menuitem = NULL;
60 if (!menustrip) return NULL;
62 for (; newmenu[i].nm_Type != NM_END; i++)
64 if (newmenu[i].nm_Type == NM_TITLE)
66 menu = (Object *)MenuitemObject,
67 MUIA_Menuitem_Title, (IPTR)newmenu[i].nm_Label,
68 MUIA_UserData, (IPTR)newmenu[i].nm_UserData,
69 MUIA_Menuitem_Enabled, (newmenu[i].nm_Flags & NM_MENUDISABLED) == 0,
70 End;
71 if (menu)
72 DoMethod(menustrip, MUIM_Family_AddTail, (IPTR)menu);
73 menuitem = NULL;
75 else
77 char *label = (char *)newmenu[i].nm_Label;
78 char *commkey;
82 (flags & MUIO_MenustripNM_CommandKeyCheck)
83 && label != (char*)NM_BARLABEL
84 && label[1] == '\0'
87 label += 2;
88 commkey = label;
90 else
91 commkey = (char *)newmenu[i].nm_CommKey;
93 if (newmenu[i].nm_Type == NM_ITEM || (menuitem != NULL && newmenu[i].nm_Type == NM_SUB))
95 Object *item = (Object *)(MenuitemObject,
96 MUIA_Menuitem_Title, (IPTR)label,
97 MUIA_Menuitem_Shortcut, (IPTR)commkey,
98 MUIA_UserData, (IPTR)newmenu[i].nm_UserData,
99 MUIA_Menuitem_Exclude, (IPTR)newmenu[i].nm_MutualExclude,
100 MUIA_Menuitem_Checkit, (newmenu[i].nm_Flags & CHECKIT) != 0,
101 MUIA_Menuitem_Checked, (newmenu[i].nm_Flags & CHECKED) != 0,
102 MUIA_Menuitem_Toggle, (newmenu[i].nm_Flags & MENUTOGGLE) != 0,
103 MUIA_Menuitem_CommandString, (newmenu[i].nm_Flags & NM_COMMANDSTRING) != 0,
104 MUIA_Menuitem_Enabled, (newmenu[i].nm_Flags & NM_ITEMDISABLED) == 0,
105 End);
107 if (item != NULL)
109 if (newmenu[i].nm_Type == NM_ITEM )
111 DoMethod(menu, MUIM_Family_AddTail, (IPTR)item);
112 menuitem = item;
114 else
115 DoMethod(menuitem, MUIM_Family_AddTail, (IPTR)item);
120 return menustrip;
124 Object *INTERNAL_ImageButton(CONST_STRPTR label, CONST_STRPTR imagePath, struct TextFont *textFont)
126 # define BUFFERSIZE 512
128 BPTR lock = Lock(imagePath, ACCESS_READ);
129 if (lock != NULL)
132 TEXT imageSpec[BUFFERSIZE];
133 TEXT controlChar = get_control_char(label);
135 imageSpec[0] = '\0';
136 strlcat(imageSpec, "3:", BUFFERSIZE);
137 strlcat(imageSpec, imagePath, BUFFERSIZE);
139 UnLock(lock);
141 return (Object *)HGroup,
142 ButtonFrame,
143 MUIA_Background, MUII_ButtonBack,
144 MUIA_CycleChain, 1,
145 MUIA_InputMode, MUIV_InputMode_RelVerify,
146 MUIA_Group_Spacing, 0,
147 //MUIA_Group_SameHeight, TRUE,
148 controlChar ?
149 MUIA_ControlChar :
150 TAG_IGNORE, (IPTR) controlChar,
152 Child, (IPTR)HVSpace,
153 Child, (IPTR)ImageObject,
154 MUIA_Image_Spec, (IPTR) imageSpec,
155 MUIA_Image_FreeVert, FALSE,
156 MUIA_Image_FreeHoriz, FALSE,
157 MUIA_Image_FontMatch, TRUE,
158 MUIA_Font, (IPTR) textFont,
159 MUIA_Weight, 0,
160 End,
161 Child, (IPTR)HSpace(4),
162 Child, (IPTR)TextObject,
163 MUIA_Font, MUIV_Font_Button,
164 MUIA_Text_HiCharIdx, (IPTR) '_',
165 MUIA_Text_Contents, (IPTR) label,
166 MUIA_Text_PreParse, (IPTR) "\33c",
167 MUIA_Weight, 0,
168 End,
169 Child, (IPTR)HVSpace,
170 End;
173 else
175 return SimpleButton(label);
178 # undef BUFFERSIZE
181 /*****************************************************************************
183 NAME */
184 AROS_LH2(Object *, MUI_MakeObjectA,
186 /* SYNOPSIS */
187 AROS_LHA(LONG, type, D0),
188 AROS_LHA(IPTR *, params, A0),
190 /* LOCATION */
191 struct Library *, MUIMasterBase, 20, MUIMaster)
193 /* FUNCTION
194 Create an object from the builtin object collection.
195 See file libraries/mui.h for a list of available objects
196 and their parameters. Note that this is not a taglist.
198 INPUTS
199 type - kind of builtin object
200 params - additional parameters for object
202 RESULT
203 Pointer to object
205 NOTES
207 EXAMPLE
209 BUGS
211 SEE ALSO
212 MUI_CreateCustomClass(), MUI_DeleteCustomClass()
214 INTERNALS
216 HISTORY
218 *****************************************************************************/
220 AROS_LIBFUNC_INIT
222 switch (type)
224 case MUIO_Label: /* STRPTR label, ULONG flags */
226 struct TagItem tags[5];
227 int ntags = 0;
229 if (params[1] & MUIO_Label_SingleFrame)
231 tags[ntags].ti_Tag = MUIA_Frame;
232 tags[ntags].ti_Data = (IPTR)MUIV_Frame_ImageButton;
233 ntags++;
235 else if (params[1] & MUIO_Label_DoubleFrame)
237 tags[ntags].ti_Tag = MUIA_Frame;
238 tags[ntags].ti_Data = (IPTR)MUIV_Frame_String;
239 ntags++;
242 if (params[1] & MUIO_Label_LeftAligned)
244 tags[ntags].ti_Tag = MUIA_Text_PreParse;
245 tags[ntags].ti_Data = (IPTR)"\33l";
246 ntags++;
248 else if (params[1] & MUIO_Label_Centered)
250 tags[ntags].ti_Tag = MUIA_Text_PreParse;
251 tags[ntags].ti_Data = (IPTR)"\33c";
252 ntags++;
254 else
256 tags[ntags].ti_Tag = MUIA_Text_PreParse;
257 tags[ntags].ti_Data = (IPTR)"\33r";
258 ntags++;
261 if (params[1] & MUIO_Label_FreeVert)
263 tags[ntags].ti_Tag = MUIA_Text_SetVMax;
264 tags[ntags].ti_Data = (IPTR)FALSE;
265 ntags++;
268 tags[ntags].ti_Tag = TAG_DONE;
269 tags[ntags].ti_Data = 0;
271 return MUI_NewObject(MUIC_Text,
272 MUIA_FramePhantomHoriz, TRUE,
273 MUIA_Weight, 0,
274 //MUIA_Text_SetMax, TRUE,
275 (params[1] & 0xff)?MUIA_Text_HiChar:TAG_IGNORE, params[1] & 0xff,
276 (params[1] & 0xff)?TAG_IGNORE:MUIA_Text_HiCharIdx, '_',
277 MUIA_Text_Contents, params[0],
278 TAG_MORE, tags,
279 TAG_DONE);
280 break;
283 case MUIO_CoolButton: /* STRPTR label, APTR CoolImage, ULONG flags */
284 #ifdef HAVE_COOLIMAGES
285 if (CoolImagesBase)
287 struct CoolImage *img;
288 char *label = (char*)params[0];
289 int control_char = 0;
290 ULONG flags = params[2];
292 if (flags & MUIO_CoolButton_CoolImageID)
294 img = (struct CoolImage *)COOL_ObtainImageA(params[1], NULL);
296 else
298 img = (struct CoolImage *)params[1];
301 if (img)
303 control_char = get_control_char(label);
305 return (Object *)HGroup,
306 MUIA_VertWeight, 0,
307 ButtonFrame,
308 MUIA_Background, MUII_ButtonBack,
309 MUIA_InputMode, MUIV_InputMode_RelVerify,
310 MUIA_CycleChain, 1,
311 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
312 MUIA_Group_HorizSpacing, 0,
313 MUIA_Group_SameHeight, TRUE,
314 Child, (IPTR)HSpace(2),
315 Child, (IPTR)VGroup,
316 MUIA_Group_VertSpacing, 0,
317 Child, (IPTR)RectangleObject, End,
318 Child, (IPTR)ChunkyImageObject,
319 MUIA_FixWidth, img->width,
320 MUIA_FixHeight, img->height,
321 MUIA_ChunkyImage_Pixels, (IPTR)img->data,
322 MUIA_ChunkyImage_NumColors, img->numcolors,
323 MUIA_ChunkyImage_Palette, (IPTR)img->pal,
324 MUIA_Bitmap_Width, img->width,
325 MUIA_Bitmap_Height, img->height,
326 MUIA_Bitmap_UseFriend, TRUE,
327 MUIA_Bitmap_Transparent, 0,
328 End,
329 Child, (IPTR)RectangleObject, End,
330 End,
331 Child, (IPTR)HSpace(2),
332 Child, (IPTR)RectangleObject, End,
333 Child, (IPTR)VGroup,
334 MUIA_Group_VertSpacing, 0,
335 Child, (IPTR)RectangleObject, End,
336 Child, (IPTR)TextObject,
337 MUIA_Font, MUIV_Font_Button,
338 MUIA_Text_HiCharIdx, '_',
339 MUIA_Text_Contents, (IPTR)label,
340 MUIA_Text_SetMax, TRUE,
341 End,
342 Child, (IPTR)RectangleObject, End,
343 End,
344 Child, (IPTR)RectangleObject, End,
345 Child, (IPTR)HSpace(2),
346 End;
348 } /* if (img) */
350 } /* if (CoolImagesBase) */
351 #endif
352 /* fall through */
354 case MUIO_Button: /* STRPTR label */
356 int control_char = get_control_char((const char *)params[0]);
358 return MUI_NewObject(MUIC_Text,
359 ButtonFrame,
360 MUIA_Font, MUIV_Font_Button,
361 MUIA_Text_HiCharIdx, '_',
362 MUIA_Text_Contents, params[0],
363 MUIA_Text_PreParse, "\33c",
364 MUIA_InputMode , MUIV_InputMode_RelVerify,
365 MUIA_Background , MUII_ButtonBack,
366 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
367 MUIA_CycleChain, 1,
368 TAG_DONE);
371 case MUIO_ImageButton:
372 return INTERNAL_ImageButton
374 (CONST_STRPTR) params[0],
375 (CONST_STRPTR) params[1],
376 ((struct MUIMasterBase_intern *)MUIMasterBase)->topaz8font
379 case MUIO_Checkmark: /* STRPTR label */
381 int control_char = get_control_char((const char *)params[0]);
383 return MUI_NewObject(MUIC_Image,
384 ImageButtonFrame,
385 MUIA_Background, MUII_ButtonBack,
386 MUIA_Weight,0,
387 MUIA_Image_Spec, MUII_CheckMark,
388 MUIA_InputMode, MUIV_InputMode_Toggle,
389 MUIA_Image_FreeVert, TRUE,
390 MUIA_ShowSelState, FALSE,
391 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
392 TAG_DONE);
393 break;
396 case MUIO_Cycle: /* STRPTR label, STRPTR *entries */
398 int control_char = get_control_char((const char *)params[0]);
400 return MUI_NewObject(MUIC_Cycle,
401 ButtonFrame,
402 MUIA_Font, MUIV_Font_Button,
403 MUIA_Cycle_Entries, params[1],
404 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
405 MUIA_CycleChain, 1,
406 TAG_DONE);
407 break;
409 case MUIO_Radio: /* STRPTR label, STRPTR *entries */
411 int control_char = get_control_char((const char *)params[0]);
413 return MUI_NewObject(MUIC_Radio,
414 MUIA_Radio_Entries, params[1],
415 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
416 TAG_DONE);
417 break;
421 case MUIO_Slider: /* STRPTR label, LONG min, LONG max */
423 int control_char = get_control_char((const char *)params[0]);
425 return (Object *)SliderObject,
426 MUIA_Numeric_Min, params[1],
427 MUIA_Numeric_Max, params[2],
428 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
429 End;
430 break;
432 case MUIO_String: /* STRPTR label, LONG maxlen */
434 int control_char = get_control_char((const char *)params[0]);
436 return MUI_NewObject(MUIC_String,
437 StringFrame,
438 MUIA_String_MaxLen,params[1],
439 control_char?MUIA_ControlChar:TAG_IGNORE, control_char,
440 TAG_DONE);
441 break;
443 case MUIO_PopButton: /* STRPTR imagespec */
444 return MUI_NewObject(MUIC_Image,
445 ImageButtonFrame,
446 MUIA_Background, MUII_ButtonBack,
447 MUIA_Image_Spec, params[0],
448 MUIA_InputMode, MUIV_InputMode_RelVerify,
449 MUIA_Image_FreeVert, TRUE,
450 MUIA_Image_FreeHoriz, FALSE,
451 TAG_DONE);
452 break;
454 case MUIO_HSpace: /* LONG space */
455 return MUI_NewObject(MUIC_Rectangle,
456 MUIA_VertWeight, 0,
457 MUIA_FixWidth, params[0],
458 TAG_DONE);
459 break;
461 case MUIO_VSpace: /* LONG space */
462 return MUI_NewObject(MUIC_Rectangle,
463 MUIA_HorizWeight, 0,
464 MUIA_FixHeight, params[0],
465 TAG_DONE);
466 break;
468 case MUIO_HBar: /* LONG space */
469 return MUI_NewObject(MUIC_Rectangle,
470 MUIA_Rectangle_HBar, TRUE,
471 MUIA_FixHeight, params[0],
472 TAG_DONE);
473 break;
475 case MUIO_VBar: /* LONG space */
476 return MUI_NewObject(MUIC_Rectangle,
477 MUIA_Rectangle_VBar, TRUE,
478 MUIA_FixWidth, params[0],
479 TAG_DONE);
480 break;
482 case MUIO_MenustripNM: /* struct NewMenu *nm, ULONG flags */
483 return CreateMenuString((struct NewMenu *)params[0],params[1],MUIMasterBase);
485 case MUIO_Menuitem: /* STRPTR label, STRPTR shortcut, ULONG flags, ULONG data */
486 return MUI_NewObject( MUIC_Menuitem,
487 MUIA_Menuitem_Title, params[0],
488 MUIA_Menuitem_Shortcut, params[1],
489 MUIA_Menuitem_Checkit, !!(params[2]&CHECKIT),
490 MUIA_Menuitem_Checked, !!(params[2]&CHECKED),
491 MUIA_Menuitem_Toggle, !!(params[2]&MENUTOGGLE),
492 MUIA_Menuitem_Enabled, !(params[2]&NM_ITEMDISABLED),
493 /* flags NYI */
494 MUIA_UserData, params[3],
495 TAG_DONE);
497 case MUIO_BarTitle: /* STRPTR label */
498 return MUI_NewObject(MUIC_Rectangle,
499 MUIA_Rectangle_HBar, TRUE,
500 MUIA_Rectangle_BarTitle, params[0],
501 MUIA_FixHeight, 1,
502 TAG_DONE);
503 break;
505 case MUIO_NumericButton: /* STRPTR label, LONG min, LONG max, STRPTR format */
507 int control_char = get_control_char((const char *)params[0]);
509 return MUI_NewObject(MUIC_Numericbutton,
510 MUIA_Numeric_Min, params[1],
511 MUIA_Numeric_Max, params[2],
512 (params[3] ? MUIA_Numeric_Format : TAG_IGNORE), params[3],
513 (control_char ? MUIA_ControlChar: TAG_IGNORE), control_char,
514 TAG_DONE);
516 break;
520 return NULL;
522 AROS_LIBFUNC_EXIT
524 } /* MUIA_MakeObjectA */