Some fix for scrolling with lasso.
[tangerine.git] / workbench / libs / muimaster / classes / radio.c
blob1e1b7de35c52f92816d1d37b5b630e3db6d7321e
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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>
12 #include <string.h>
14 /* #define MYDEBUG 1 */
15 #include "debug.h"
17 #include "mui.h"
18 #include "muimaster_intern.h"
19 #include "prefs.h"
20 #include "support.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 struct TagItem *tag, *tags;
30 int i;
31 const char **entries = NULL;
32 int entries_active = 0;
33 int entries_num;
34 struct TagItem *grouptags;
35 Object **buttons;
36 int state;
38 /* parse initial taglist */
40 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
42 switch (tag->ti_Tag)
44 case MUIA_Radio_Entries:
45 entries = (const char**)tag->ti_Data;
46 break;
47 case MUIA_Radio_Active:
48 entries_active = tag->ti_Data;
49 break;
53 if (!entries)
55 D(bug("Radio_New: No Entries specified!\n"));
56 CoerceMethod(cl,obj,OM_DISPOSE);
57 return NULL;
60 /* Count the number of entries */
61 for (i=0;entries[i];i++);
63 entries_num = i;
65 if ((entries_active < 0) || (entries_active > entries_num - 1))
66 entries_active = 0;
68 grouptags = AllocateTagItems(entries_num + 1);
69 if (!grouptags)
70 return FALSE;
71 buttons = AllocVec(i * sizeof(Object *), MEMF_PUBLIC);
72 if (!buttons)
74 FreeVec(grouptags);
75 return FALSE;
77 for (i = 0; i < entries_num; i++)
79 state = (entries_active == i) ? TRUE : FALSE;
81 buttons[i] = HGroup,
82 Child, (IPTR)ImageObject,
83 MUIA_Image_FontMatch, TRUE,
84 MUIA_InputMode, MUIV_InputMode_Immediate,
85 MUIA_Selected, state,
86 MUIA_ShowSelState, FALSE,
87 MUIA_Image_Spec, MUII_RadioButton,
88 MUIA_Frame, MUIV_Frame_None,
89 End,
90 Child, (IPTR)TextObject,
91 MUIA_InputMode, MUIV_InputMode_Immediate,
92 MUIA_ShowSelState, FALSE,
93 MUIA_Selected, state,
94 MUIA_Text_Contents, entries[i],
95 MUIA_Frame, MUIV_Frame_None,
96 MUIA_Text_PreParse, (IPTR)"\33l",
97 End,
98 End;
100 grouptags[i].ti_Tag = MUIA_Group_Child;
101 grouptags[i].ti_Data = (IPTR)buttons[i];
104 grouptags[i].ti_Tag = TAG_MORE;
105 grouptags[i].ti_Data = (IPTR)msg->ops_AttrList;
107 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
108 TAG_MORE, (IPTR)grouptags);
109 FreeTagItems(grouptags);
110 if (!obj)
112 FreeVec(buttons);
113 return FALSE;
115 data = INST_DATA(cl, obj);
116 data->entries_active = entries_active;
117 data->entries_num = entries_num;
118 data->buttons = buttons;
120 for (i = 0; i < entries_num; i++)
122 DoMethod(buttons[i], MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
123 (IPTR)obj, 3, MUIM_Set, MUIA_Radio_Active, i);
126 return (IPTR)obj;
129 IPTR Radio__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
131 struct Radio_DATA *data = INST_DATA(cl,obj);
132 if (data->buttons) FreeVec(data->buttons);
133 return DoSuperMethodA(cl,obj,msg);
136 IPTR Radio__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
138 struct Radio_DATA *data;
139 struct TagItem *tag, *tags;
141 data = INST_DATA(cl, obj);
143 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
145 switch (tag->ti_Tag)
147 case MUIA_Radio_Active:
148 D(bug("Radio_Set(%p) MUIA_Radio_Active %ld\n",
149 obj, tag->ti_Data));
150 if (tag->ti_Data >= 0 && tag->ti_Data < data->entries_num &&
151 tag->ti_Data != data->entries_active)
153 DoMethod(data->buttons[data->entries_active],
154 MUIM_NoNotifySet, MUIA_Selected, FALSE);
155 DoMethod(data->buttons[tag->ti_Data],
156 MUIM_NoNotifySet, MUIA_Selected, TRUE);
157 data->entries_active = tag->ti_Data;
159 break;
162 return DoSuperMethodA(cl,obj,(Msg)msg);
165 IPTR Radio__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
167 struct Radio_DATA *data = INST_DATA(cl, obj);
168 #define STORE *(msg->opg_Storage)
170 switch(msg->opg_AttrID)
172 case MUIA_Radio_Active:
173 STORE = data->entries_active;
174 return 1;
177 return DoSuperMethodA(cl,obj,(Msg)msg);
180 IPTR Radio__MUIM_Setup(struct IClass *cl, Object *obj, Msg msg)
182 if (!DoSuperMethodA(cl, obj, msg))
183 return FALSE;
185 set(obj, MUIA_Group_HorizSpacing, muiGlobalInfo(obj)->mgi_Prefs->radiobutton_hspacing);
186 set(obj, MUIA_Group_VertSpacing, muiGlobalInfo(obj)->mgi_Prefs->radiobutton_vspacing);
188 return TRUE;
191 #if ZUNE_BUILTIN_RADIO
192 BOOPSI_DISPATCHER(IPTR, Radio_Dispatcher, cl, obj, msg)
194 switch (msg->MethodID)
196 case OM_NEW: return Radio__OM_NEW(cl, obj, (struct opSet *) msg);
197 case OM_DISPOSE: return Radio__OM_DISPOSE(cl, obj, (Msg) msg);
198 case OM_SET: return Radio__OM_SET(cl, obj, (struct opSet *) msg);
199 case OM_GET: return Radio__OM_GET(cl, obj, (struct opGet *) msg);
200 case MUIM_Setup: return Radio__MUIM_Setup(cl, obj, msg);
201 default: return DoSuperMethodA(cl, obj, msg);
204 BOOPSI_DISPATCHER_END
206 const struct __MUIBuiltinClass _MUI_Radio_desc = {
207 MUIC_Radio,
208 MUIC_Group,
209 sizeof(struct Radio_DATA),
210 (void*)Radio_Dispatcher
212 #endif /* ZUNE_BUILTIN_RADIO */