2 Copyright 2002-2009, The AROS Development Team. All rights reserved.
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>
16 #ifdef HAVE_COOLIMAGES
17 #include <libraries/coolimages.h>
18 #include <proto/coolimages.h>
21 #include "muimaster_intern.h"
24 /* #define MYDEBUG 1 */
27 extern struct Library
*MUIMasterBase
;
29 STATIC
int get_control_char(const char *label
)
31 /* find the control char */
36 const unsigned char *p
= (const unsigned char *)label
;
43 control_char
= ToLower(*p
);
52 STATIC Object
*CreateMenuString( struct NewMenu
*newmenu
, ULONG flags
, struct Library
*MUIMasterBase
)
56 Object
*menustrip
= (Object
*)MenuitemObject
,End
;
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,
72 DoMethod(menustrip
, MUIM_Family_AddTail
, (IPTR
)menu
);
77 char *label
= (char *)newmenu
[i
].nm_Label
;
82 (flags
& MUIO_MenustripNM_CommandKeyCheck
)
83 && label
!= (char*)NM_BARLABEL
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,
109 if (newmenu
[i
].nm_Type
== NM_ITEM
)
111 DoMethod(menu
, MUIM_Family_AddTail
, (IPTR
)item
);
115 DoMethod(menuitem
, MUIM_Family_AddTail
, (IPTR
)item
);
124 Object
*INTERNAL_ImageButton(CONST_STRPTR label
, CONST_STRPTR imagePath
, struct TextFont
*textFont
)
126 # define BUFFERSIZE 512
128 BPTR lock
= Lock(imagePath
, ACCESS_READ
);
132 TEXT imageSpec
[BUFFERSIZE
];
133 TEXT controlChar
= get_control_char(label
);
136 strlcat(imageSpec
, "3:", BUFFERSIZE
);
137 strlcat(imageSpec
, imagePath
, BUFFERSIZE
);
141 return (Object
*)HGroup
,
143 MUIA_Background
, MUII_ButtonBack
,
145 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
146 MUIA_Group_Spacing
, 0,
147 //MUIA_Group_SameHeight, TRUE,
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
,
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",
169 Child
, (IPTR
)HVSpace
,
175 return SimpleButton(label
);
181 /*****************************************************************************
184 AROS_LH2(Object
*, MUI_MakeObjectA
,
187 AROS_LHA(LONG
, type
, D0
),
188 AROS_LHA(IPTR
*, params
, A0
),
191 struct Library
*, MUIMasterBase
, 20, MUIMaster
)
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.
199 type - kind of builtin object
200 params - additional parameters for object
212 MUI_CreateCustomClass(), MUI_DeleteCustomClass()
218 *****************************************************************************/
224 case MUIO_Label
: /* STRPTR label, ULONG flags */
226 struct TagItem tags
[5];
229 if (params
[1] & MUIO_Label_SingleFrame
)
231 tags
[ntags
].ti_Tag
= MUIA_Frame
;
232 tags
[ntags
].ti_Data
= (IPTR
)MUIV_Frame_ImageButton
;
235 else if (params
[1] & MUIO_Label_DoubleFrame
)
237 tags
[ntags
].ti_Tag
= MUIA_Frame
;
238 tags
[ntags
].ti_Data
= (IPTR
)MUIV_Frame_String
;
242 if (params
[1] & MUIO_Label_LeftAligned
)
244 tags
[ntags
].ti_Tag
= MUIA_Text_PreParse
;
245 tags
[ntags
].ti_Data
= (IPTR
)"\33l";
248 else if (params
[1] & MUIO_Label_Centered
)
250 tags
[ntags
].ti_Tag
= MUIA_Text_PreParse
;
251 tags
[ntags
].ti_Data
= (IPTR
)"\33c";
256 tags
[ntags
].ti_Tag
= MUIA_Text_PreParse
;
257 tags
[ntags
].ti_Data
= (IPTR
)"\33r";
261 if (params
[1] & MUIO_Label_FreeVert
)
263 tags
[ntags
].ti_Tag
= MUIA_Text_SetVMax
;
264 tags
[ntags
].ti_Data
= (IPTR
)FALSE
;
268 tags
[ntags
].ti_Tag
= TAG_DONE
;
269 tags
[ntags
].ti_Data
= 0;
271 return MUI_NewObject(MUIC_Text
,
272 MUIA_FramePhantomHoriz
, TRUE
,
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],
283 case MUIO_CoolButton
: /* STRPTR label, APTR CoolImage, ULONG flags */
284 #ifdef HAVE_COOLIMAGES
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
);
298 img
= (struct CoolImage
*)params
[1];
303 control_char
= get_control_char(label
);
305 return (Object
*)HGroup
,
308 MUIA_Background
, MUII_ButtonBack
,
309 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
311 control_char
?MUIA_ControlChar
:TAG_IGNORE
, control_char
,
312 MUIA_Group_HorizSpacing
, 0,
313 MUIA_Group_SameHeight
, TRUE
,
314 Child
, (IPTR
)HSpace(2),
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,
329 Child
, (IPTR
)RectangleObject
, End
,
331 Child
, (IPTR
)HSpace(2),
332 Child
, (IPTR
)RectangleObject
, End
,
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
,
342 Child
, (IPTR
)RectangleObject
, End
,
344 Child
, (IPTR
)RectangleObject
, End
,
345 Child
, (IPTR
)HSpace(2),
350 } /* if (CoolImagesBase) */
354 case MUIO_Button
: /* STRPTR label */
356 int control_char
= get_control_char((const char *)params
[0]);
358 return MUI_NewObject(MUIC_Text
,
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
,
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
,
385 MUIA_Background
, MUII_ButtonBack
,
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
,
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
,
402 MUIA_Font
, MUIV_Font_Button
,
403 MUIA_Cycle_Entries
, params
[1],
404 control_char
?MUIA_ControlChar
:TAG_IGNORE
, control_char
,
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
,
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
,
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
,
438 MUIA_String_MaxLen
,params
[1],
439 control_char
?MUIA_ControlChar
:TAG_IGNORE
, control_char
,
443 case MUIO_PopButton
: /* STRPTR imagespec */
444 return MUI_NewObject(MUIC_Image
,
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
,
454 case MUIO_HSpace
: /* LONG space */
455 return MUI_NewObject(MUIC_Rectangle
,
457 MUIA_FixWidth
, params
[0],
461 case MUIO_VSpace
: /* LONG space */
462 return MUI_NewObject(MUIC_Rectangle
,
464 MUIA_FixHeight
, params
[0],
468 case MUIO_HBar
: /* LONG space */
469 return MUI_NewObject(MUIC_Rectangle
,
470 MUIA_Rectangle_HBar
, TRUE
,
471 MUIA_FixHeight
, params
[0],
475 case MUIO_VBar
: /* LONG space */
476 return MUI_NewObject(MUIC_Rectangle
,
477 MUIA_Rectangle_VBar
, TRUE
,
478 MUIA_FixWidth
, params
[0],
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
),
494 MUIA_UserData
, params
[3],
497 case MUIO_BarTitle
: /* STRPTR label */
498 return MUI_NewObject(MUIC_Rectangle
,
499 MUIA_Rectangle_HBar
, TRUE
,
500 MUIA_Rectangle_BarTitle
, params
[0],
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
,
524 } /* MUIA_MakeObjectA */