2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
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>
17 #ifdef HAVE_COOLIMAGES
18 #include <libraries/coolimages.h>
19 #include <proto/coolimages.h>
22 #include "muimaster_intern.h"
25 /* #define MYDEBUG 1 */
28 extern struct Library
*MUIMasterBase
;
30 STATIC
int get_control_char(const char *label
)
32 /* find the control char */
37 const unsigned char *p
= (const unsigned char *)label
;
44 control_char
= ToLower(*p
);
53 STATIC Object
*CreateMenuString(struct NewMenu
* newmenu
, ULONG flags
,
54 struct Library
* MUIMasterBase
)
59 Object
*menustrip
= (Object
*) MenustripObject
, End
;
61 Object
*menuitem
= 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,
78 DoMethod(menustrip
, MUIM_Family_AddTail
, (IPTR
) menu
);
83 char *label
= (char *)newmenu
[i
].nm_Label
;
86 if ((flags
& MUIO_MenustripNM_CommandKeyCheck
)
87 && label
!= (char *)NM_BARLABEL
&& label
[1] == '\0')
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,
113 if (newmenu
[i
].nm_Type
== NM_ITEM
)
115 DoMethod(menu
, MUIM_Family_AddTail
, (IPTR
) item
);
119 DoMethod(menuitem
, MUIM_Family_AddTail
,
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
));
140 TEXT imageSpec
[BUFFERSIZE
];
141 TEXT controlChar
= get_control_char(label
);
144 strlcat(imageSpec
, "3:", BUFFERSIZE
);
145 strlcat(imageSpec
, imagePath
, BUFFERSIZE
);
149 return (Object
*) HGroup
,
151 MUIA_Background
, MUII_ButtonBack
,
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
,
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",
175 Child
, (IPTR
)HVSpace
,
181 return SimpleButton(label
);
187 /*****************************************************************************
190 AROS_LH2(Object
*, MUI_MakeObjectA
,
193 AROS_LHA(LONG
, type
, D0
),
194 AROS_LHA(IPTR
*, params
, A0
),
197 struct Library
*, MUIMasterBase
, 20, MUIMaster
)
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.
205 type - kind of builtin object
206 params - additional parameters for object
218 MUI_CreateCustomClass(), MUI_DeleteCustomClass()
222 *****************************************************************************/
228 case MUIO_Label
: /* STRPTR label, ULONG flags */
230 struct TagItem tags
[5];
233 if (params
[1] & MUIO_Label_SingleFrame
)
235 tags
[ntags
].ti_Tag
= MUIA_Frame
;
236 tags
[ntags
].ti_Data
= (IPTR
) MUIV_Frame_ImageButton
;
239 else if (params
[1] & MUIO_Label_DoubleFrame
)
241 tags
[ntags
].ti_Tag
= MUIA_Frame
;
242 tags
[ntags
].ti_Data
= (IPTR
) MUIV_Frame_String
;
246 if (params
[1] & MUIO_Label_LeftAligned
)
248 tags
[ntags
].ti_Tag
= MUIA_Text_PreParse
;
249 tags
[ntags
].ti_Data
= (IPTR
) "\33l";
252 else if (params
[1] & MUIO_Label_Centered
)
254 tags
[ntags
].ti_Tag
= MUIA_Text_PreParse
;
255 tags
[ntags
].ti_Data
= (IPTR
) "\33c";
260 tags
[ntags
].ti_Tag
= MUIA_Text_PreParse
;
261 tags
[ntags
].ti_Data
= (IPTR
) "\33r";
265 if (params
[1] & MUIO_Label_FreeVert
)
267 tags
[ntags
].ti_Tag
= MUIA_Text_SetVMax
;
268 tags
[ntags
].ti_Data
= (IPTR
) FALSE
;
272 tags
[ntags
].ti_Tag
= TAG_DONE
;
273 tags
[ntags
].ti_Data
= 0;
275 return MUI_NewObject(MUIC_Text
,
276 MUIA_FramePhantomHoriz
, TRUE
,
278 //MUIA_Text_SetMax, TRUE,
279 (params
[1] & 0xff) ? MUIA_Text_HiChar
: TAG_IGNORE
,
281 (params
[1] & 0xff) ? TAG_IGNORE
: MUIA_Text_HiCharIdx
, '_',
282 MUIA_Text_Contents
, params
[0],
288 case MUIO_CoolButton
: /* STRPTR label, APTR CoolImage, ULONG flags */
289 #ifdef HAVE_COOLIMAGES
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
);
303 img
= (struct CoolImage
*)params
[1];
308 control_char
= get_control_char(label
);
310 return (Object
*)HGroup
,
313 MUIA_Background
, MUII_ButtonBack
,
314 MUIA_InputMode
, MUIV_InputMode_RelVerify
,
316 control_char
? MUIA_ControlChar
: TAG_IGNORE
, control_char
,
317 MUIA_Group_HorizSpacing
, 0,
318 MUIA_Group_SameHeight
, TRUE
,
319 Child
, (IPTR
)HSpace(2),
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,
334 Child
, (IPTR
)RectangleObject
, End
,
336 Child
, (IPTR
)HSpace(2),
337 Child
, (IPTR
)RectangleObject
, End
,
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
,
347 Child
, (IPTR
)RectangleObject
, End
,
349 Child
, (IPTR
)RectangleObject
, End
,
350 Child
, (IPTR
)HSpace(2),
355 } /* if (CoolImagesBase) */
359 case MUIO_Button
: /* STRPTR label */
361 int control_char
= get_control_char((const char *)params
[0]);
363 return MUI_NewObject(MUIC_Text
,
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
,
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
,
389 MUIA_Background
, MUII_ButtonBack
,
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
,
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
,
406 MUIA_Font
, MUIV_Font_Button
,
407 MUIA_Cycle_Entries
, params
[1],
408 control_char
? MUIA_ControlChar
: TAG_IGNORE
, control_char
,
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
,
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
,
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
,
442 MUIA_String_MaxLen
,params
[1],
443 control_char
? MUIA_ControlChar
: TAG_IGNORE
, control_char
,
447 case MUIO_PopButton
: /* STRPTR imagespec */
448 return MUI_NewObject(MUIC_Image
,
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
,
458 case MUIO_HSpace
: /* LONG space */
459 return MUI_NewObject(MUIC_Rectangle
,
461 MUIA_FixWidth
, params
[0],
465 case MUIO_VSpace
: /* LONG space */
466 return MUI_NewObject(MUIC_Rectangle
,
468 MUIA_FixHeight
, params
[0],
472 case MUIO_HBar
: /* LONG space */
473 return MUI_NewObject(MUIC_Rectangle
,
474 MUIA_Rectangle_HBar
, TRUE
,
475 MUIA_FixHeight
, params
[0],
479 case MUIO_VBar
: /* LONG space */
480 return MUI_NewObject(MUIC_Rectangle
,
481 MUIA_Rectangle_VBar
, TRUE
,
482 MUIA_FixWidth
, params
[0],
486 case MUIO_MenustripNM
: /* struct NewMenu *nm, ULONG flags */
487 return CreateMenuString((struct NewMenu
*)params
[0], params
[1],
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
),
499 MUIA_UserData
, params
[3],
502 case MUIO_BarTitle
: /* STRPTR label */
503 return MUI_NewObject(MUIC_Rectangle
,
504 MUIA_Rectangle_HBar
, TRUE
,
505 MUIA_Rectangle_BarTitle
, params
[0],
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
,
527 } /* MUIA_MakeObjectA */