2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
6 #include <clib/alib_protos.h>
7 #include <proto/exec.h>
8 #include <proto/utility.h>
9 #include <proto/intuition.h>
10 #include <proto/muimaster.h>
14 /* #define MYDEBUG 1 */
18 #include "muimaster_intern.h"
21 #include "support_classes.h"
22 #include "radio_private.h"
24 extern struct Library
*MUIMasterBase
;
26 IPTR
Radio__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
28 struct Radio_DATA
*data
;
29 const struct TagItem
*tags
;
32 const char **entries
= NULL
;
33 int entries_active
= 0;
35 struct TagItem
*grouptags
;
39 /* parse initial taglist */
41 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
45 case MUIA_Radio_Entries
:
46 entries
= (const char**)tag
->ti_Data
;
48 case MUIA_Radio_Active
:
49 entries_active
= tag
->ti_Data
;
56 D(bug("Radio_New: No Entries specified!\n"));
57 CoerceMethod(cl
,obj
,OM_DISPOSE
);
61 /* Count the number of entries */
62 for (i
=0;entries
[i
];i
++);
66 if ((entries_active
< 0) || (entries_active
> entries_num
- 1))
69 grouptags
= AllocateTagItems(entries_num
+ 1);
72 buttons
= AllocVec(i
* sizeof(Object
*), MEMF_PUBLIC
);
78 for (i
= 0; i
< entries_num
; i
++)
80 state
= (entries_active
== i
) ? TRUE
: FALSE
;
83 Child
, (IPTR
)ImageObject
,
84 MUIA_Image_FontMatch
, TRUE
,
85 MUIA_InputMode
, MUIV_InputMode_Immediate
,
87 MUIA_ShowSelState
, FALSE
,
88 MUIA_Image_Spec
, MUII_RadioButton
,
89 MUIA_Frame
, MUIV_Frame_None
,
91 Child
, (IPTR
)TextObject
,
92 MUIA_InputMode
, MUIV_InputMode_Immediate
,
93 MUIA_ShowSelState
, FALSE
,
95 MUIA_Text_Contents
, entries
[i
],
96 MUIA_Frame
, MUIV_Frame_None
,
97 MUIA_Text_PreParse
, (IPTR
)"\33l",
101 grouptags
[i
].ti_Tag
= MUIA_Group_Child
;
102 grouptags
[i
].ti_Data
= (IPTR
)buttons
[i
];
105 grouptags
[i
].ti_Tag
= TAG_MORE
;
106 grouptags
[i
].ti_Data
= (IPTR
)msg
->ops_AttrList
;
108 obj
= (Object
*)DoSuperNewTags(cl
, obj
, NULL
,
109 TAG_MORE
, (IPTR
)grouptags
);
110 FreeTagItems(grouptags
);
116 data
= INST_DATA(cl
, obj
);
117 data
->entries_active
= entries_active
;
118 data
->entries_num
= entries_num
;
119 data
->buttons
= buttons
;
121 for (i
= 0; i
< entries_num
; i
++)
123 DoMethod(buttons
[i
], MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
124 (IPTR
)obj
, 3, MUIM_Set
, MUIA_Radio_Active
, i
);
130 IPTR
Radio__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
132 struct Radio_DATA
*data
= INST_DATA(cl
,obj
);
133 if (data
->buttons
) FreeVec(data
->buttons
);
134 return DoSuperMethodA(cl
,obj
,msg
);
137 IPTR
Radio__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
139 struct Radio_DATA
*data
;
140 const struct TagItem
*tags
;
143 data
= INST_DATA(cl
, obj
);
145 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
149 case MUIA_Radio_Active
:
150 D(bug("Radio_Set(%p) MUIA_Radio_Active %ld\n",
152 if (tag
->ti_Data
>= 0 && tag
->ti_Data
< data
->entries_num
&&
153 tag
->ti_Data
!= data
->entries_active
)
155 DoMethod(data
->buttons
[data
->entries_active
],
156 MUIM_NoNotifySet
, MUIA_Selected
, FALSE
);
157 DoMethod(data
->buttons
[tag
->ti_Data
],
158 MUIM_NoNotifySet
, MUIA_Selected
, TRUE
);
159 data
->entries_active
= tag
->ti_Data
;
164 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
167 IPTR
Radio__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
169 struct Radio_DATA
*data
= INST_DATA(cl
, obj
);
170 #define STORE *(msg->opg_Storage)
172 switch(msg
->opg_AttrID
)
174 case MUIA_Radio_Active
:
175 STORE
= data
->entries_active
;
179 return DoSuperMethodA(cl
,obj
,(Msg
)msg
);
182 IPTR
Radio__MUIM_Setup(struct IClass
*cl
, Object
*obj
, Msg msg
)
184 if (!DoSuperMethodA(cl
, obj
, msg
))
187 set(obj
, MUIA_Group_HorizSpacing
, muiGlobalInfo(obj
)->mgi_Prefs
->radiobutton_hspacing
);
188 set(obj
, MUIA_Group_VertSpacing
, muiGlobalInfo(obj
)->mgi_Prefs
->radiobutton_vspacing
);
193 /**************************************************************************
194 MUIM_Export - to export an objects "contents" to a dataspace object.
195 **************************************************************************/
196 IPTR
Radio__MUIM_Export(struct IClass
*cl
, Object
*obj
, struct MUIP_Export
*msg
)
198 struct Radio_DATA
*data
= INST_DATA(cl
, obj
);
201 if ((id
= muiNotifyData(obj
)->mnd_ObjectID
))
203 LONG value
= data
->entries_active
;
204 DoMethod(msg
->dataspace
, MUIM_Dataspace_Add
,
212 /**************************************************************************
213 MUIM_Import - to import an objects "contents" from a dataspace object.
214 **************************************************************************/
215 IPTR
Radio__MUIM_Import(struct IClass
*cl
, Object
*obj
, struct MUIP_Import
*msg
)
220 if ((id
= muiNotifyData(obj
)->mnd_ObjectID
))
222 if ((s
= (LONG
*) DoMethod(msg
->dataspace
, MUIM_Dataspace_Find
, (IPTR
) id
)))
224 set(obj
, MUIA_Radio_Active
, *s
);
230 #if ZUNE_BUILTIN_RADIO
231 BOOPSI_DISPATCHER(IPTR
, Radio_Dispatcher
, cl
, obj
, msg
)
233 switch (msg
->MethodID
)
235 case OM_NEW
: return Radio__OM_NEW(cl
, obj
, (struct opSet
*) msg
);
236 case OM_DISPOSE
: return Radio__OM_DISPOSE(cl
, obj
, (Msg
) msg
);
237 case OM_SET
: return Radio__OM_SET(cl
, obj
, (struct opSet
*) msg
);
238 case OM_GET
: return Radio__OM_GET(cl
, obj
, (struct opGet
*) msg
);
239 case MUIM_Setup
: return Radio__MUIM_Setup(cl
, obj
, msg
);
240 case MUIM_Export
: return Radio__MUIM_Export(cl
, obj
, (Msg
) msg
);
241 case MUIM_Import
: return Radio__MUIM_Import(cl
, obj
, (Msg
) msg
);
242 default: return DoSuperMethodA(cl
, obj
, msg
);
245 BOOPSI_DISPATCHER_END
247 const struct __MUIBuiltinClass _MUI_Radio_desc
= {
250 sizeof(struct Radio_DATA
),
251 (void*)Radio_Dispatcher
253 #endif /* ZUNE_BUILTIN_RADIO */