2 Copyright © 2002-2014, 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
;
32 const char **entries
= NULL
;
33 int entries_active
= 0;
35 struct TagItem
*grouptags
;
36 Object
**buttons
, **imgobjs
, **textobjs
;
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
*) * 3, MEMF_PUBLIC
);
78 imgobjs
= buttons
+ i
;
79 textobjs
= imgobjs
+ i
;
81 for (i
= 0; i
< entries_num
; i
++)
83 state
= (entries_active
== i
) ? TRUE
: FALSE
;
86 Child
, (IPTR
)(imgobjs
[i
] = ImageObject
,
87 MUIA_Image_FontMatch
, TRUE
,
88 MUIA_InputMode
, MUIV_InputMode_Immediate
,
90 MUIA_ShowSelState
, FALSE
,
91 MUIA_Image_Spec
, MUII_RadioButton
,
92 MUIA_Frame
, MUIV_Frame_None
,
94 Child
, (IPTR
)(textobjs
[i
] = TextObject
,
95 MUIA_InputMode
, MUIV_InputMode_Immediate
,
96 MUIA_ShowSelState
, FALSE
,
98 MUIA_Text_Contents
, entries
[i
],
99 MUIA_Frame
, MUIV_Frame_None
,
100 MUIA_Text_PreParse
, (IPTR
)"\33l",
104 grouptags
[i
].ti_Tag
= MUIA_Group_Child
;
105 grouptags
[i
].ti_Data
= (IPTR
) buttons
[i
];
108 grouptags
[i
].ti_Tag
= TAG_MORE
;
109 grouptags
[i
].ti_Data
= (IPTR
) msg
->ops_AttrList
;
111 obj
= (Object
*) DoSuperNewTags(cl
, obj
, NULL
,
112 TAG_MORE
, (IPTR
) grouptags
);
113 FreeTagItems(grouptags
);
119 data
= INST_DATA(cl
, obj
);
120 data
->entries_active
= entries_active
;
121 data
->entries_num
= entries_num
;
122 data
->buttons
= buttons
;
124 for (i
= 0; i
< entries_num
; i
++)
126 DoMethod(imgobjs
[i
], MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
127 (IPTR
) obj
, 3, MUIM_Set
, MUIA_Radio_Active
, i
);
128 DoMethod(textobjs
[i
], MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
129 (IPTR
) obj
, 3, MUIM_Set
, MUIA_Radio_Active
, i
);
135 IPTR
Radio__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
137 struct Radio_DATA
*data
= INST_DATA(cl
, obj
);
139 FreeVec(data
->buttons
);
140 return DoSuperMethodA(cl
, obj
, msg
);
143 IPTR
Radio__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
145 struct Radio_DATA
*data
;
146 struct TagItem
*tags
;
149 data
= INST_DATA(cl
, obj
);
151 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
155 case MUIA_Radio_Active
:
156 D(bug("Radio_Set(%p) MUIA_Radio_Active %ld\n",
158 if (tag
->ti_Data
>= 0 && tag
->ti_Data
< data
->entries_num
&&
159 tag
->ti_Data
!= data
->entries_active
)
161 DoMethod(data
->buttons
[data
->entries_active
],
162 MUIM_NoNotifySet
, MUIA_Selected
, FALSE
);
163 DoMethod(data
->buttons
[tag
->ti_Data
],
164 MUIM_NoNotifySet
, MUIA_Selected
, TRUE
);
165 data
->entries_active
= tag
->ti_Data
;
170 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
173 IPTR
Radio__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
175 struct Radio_DATA
*data
= INST_DATA(cl
, obj
);
176 #define STORE *(msg->opg_Storage)
178 switch (msg
->opg_AttrID
)
180 case MUIA_Radio_Active
:
181 STORE
= data
->entries_active
;
185 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
188 IPTR
Radio__MUIM_Setup(struct IClass
*cl
, Object
*obj
, Msg msg
)
190 if (!DoSuperMethodA(cl
, obj
, msg
))
193 set(obj
, MUIA_Group_HorizSpacing
,
194 muiGlobalInfo(obj
)->mgi_Prefs
->radiobutton_hspacing
);
195 set(obj
, MUIA_Group_VertSpacing
,
196 muiGlobalInfo(obj
)->mgi_Prefs
->radiobutton_vspacing
);
201 /**************************************************************************
202 MUIM_Export - to export an object's "contents" to a dataspace object.
203 **************************************************************************/
204 IPTR
Radio__MUIM_Export(struct IClass
*cl
, Object
*obj
,
205 struct MUIP_Export
*msg
)
207 struct Radio_DATA
*data
= INST_DATA(cl
, obj
);
210 if ((id
= muiNotifyData(obj
)->mnd_ObjectID
))
212 LONG value
= data
->entries_active
;
213 DoMethod(msg
->dataspace
, MUIM_Dataspace_Add
,
214 (IPTR
) & value
, sizeof(value
), (IPTR
) id
);
219 /**************************************************************************
220 MUIM_Import - to import an object's "contents" from a dataspace object.
221 **************************************************************************/
222 IPTR
Radio__MUIM_Import(struct IClass
*cl
, Object
*obj
,
223 struct MUIP_Import
*msg
)
228 if ((id
= muiNotifyData(obj
)->mnd_ObjectID
))
230 if ((s
= (LONG
*) DoMethod(msg
->dataspace
, MUIM_Dataspace_Find
,
233 set(obj
, MUIA_Radio_Active
, *s
);
239 #if ZUNE_BUILTIN_RADIO
240 BOOPSI_DISPATCHER(IPTR
, Radio_Dispatcher
, cl
, obj
, msg
)
242 switch (msg
->MethodID
)
245 return Radio__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
247 return Radio__OM_DISPOSE(cl
, obj
, (Msg
) msg
);
249 return Radio__OM_SET(cl
, obj
, (struct opSet
*)msg
);
251 return Radio__OM_GET(cl
, obj
, (struct opGet
*)msg
);
253 return Radio__MUIM_Setup(cl
, obj
, msg
);
255 return Radio__MUIM_Export(cl
, obj
, (struct MUIP_Export
*) msg
);
257 return Radio__MUIM_Import(cl
, obj
, (struct MUIP_Import
*) msg
);
259 return DoSuperMethodA(cl
, obj
, msg
);
262 BOOPSI_DISPATCHER_END
264 const struct __MUIBuiltinClass _MUI_Radio_desc
=
268 sizeof(struct Radio_DATA
),
269 (void *) Radio_Dispatcher
271 #endif /* ZUNE_BUILTIN_RADIO */