Fixed compatibility of output.
[AROS.git] / workbench / prefs / screenmode / smselector.c
blob14fbfe0d0f1eb2af8b96d9b197ce4729a84f15d4
1 /*
2 Copyright © 2003-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
7 #define DEBUG 0
9 #include <exec/rawfmt.h>
10 #include <libraries/mui.h>
11 #include <utility/hooks.h>
13 #include <proto/alib.h>
14 #include <proto/dos.h>
15 #include <proto/exec.h>
16 #include <proto/muimaster.h>
17 #include <proto/intuition.h>
18 #include <proto/graphics.h>
19 #include <proto/dos.h>
20 #include <proto/utility.h>
22 #include <zune/customclasses.h>
24 #include <string.h>
26 #include "locale.h"
28 #include "smselector.h"
30 struct ScreenModeSelector_DATA
32 STRPTR *modes_array;
33 ULONG *ids_array;
36 #define HOOK(name) \
37 struct Hook
39 #define HOOKFUNC(name) IPTR name ## Func(struct Hook *hook, APTR obj, APTR msg)
41 AROS_UFH3(IPTR, SelectFunc,
42 AROS_UFHA(struct Hook *, hook, A0),
43 AROS_UFHA(APTR , obj , A2),
44 AROS_UFHA(APTR , msg , A1))
46 AROS_USERFUNC_INIT
48 struct ScreenModeSelector_DATA *data = INST_DATA(OCLASS(obj), obj);
50 /* Note: the value used to set MUIA_List_Active may not be an index */
51 return set(obj, MUIA_ScreenModeSelector_Active,
52 data->ids_array[XGET(obj, MUIA_List_Active)]);
54 AROS_USERFUNC_EXIT;
56 static struct Hook SelectHook = { .h_Entry = SelectFunc };
58 AROS_UFH3(IPTR, DisplayFunc,
59 AROS_UFHA(struct Hook *, hook, A0),
60 AROS_UFHA(CONST_STRPTR *, array, A2),
61 AROS_UFHA(STRPTR, entry, A1))
63 AROS_USERFUNC_INIT
65 if (entry)
67 ULONG *ids_array = hook->h_Data;
68 ULONG num = (ULONG)(IPTR)array[-1];
69 ULONG modeid = ids_array[num];
70 static char modeid_str[9];
72 RawDoFmt("%08lx", (RAWARG)&modeid, RAWFMTFUNC_STRING, modeid_str);
73 array[0] = modeid_str;
74 array[1] = entry;
76 else
78 array[0] = _(MSG_MODE_ID);
79 array[1] = _(MSG_DESCRIPTION);
81 return 0;
83 AROS_USERFUNC_EXIT
86 static struct Hook DisplayHook = { .h_Entry = DisplayFunc };
88 Object *ScreenModeSelector__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
90 STRPTR *modes_array;
91 ULONG *ids_array;
92 ULONG id, num_modes, cur_mode;
93 Object *list;
95 struct DisplayInfo DisplayInfo;
96 struct DimensionInfo DimensionInfo;
97 struct NameInfo NameInfo;
98 APTR handle;
100 struct ScreenModeSelector_DATA *data;
102 num_modes = 0; id = INVALID_ID;
103 while ((id = NextDisplayInfo(id)) != INVALID_ID) num_modes++;
105 modes_array = AllocVec(sizeof(STRPTR) * (num_modes + 1), MEMF_CLEAR);
106 if (!modes_array)
107 goto err;
109 ids_array = AllocVec(sizeof(ULONG) * (num_modes + 1), MEMF_ANY);
110 if (!ids_array)
111 goto err;
113 ids_array[num_modes] = INVALID_ID;
115 cur_mode = 0;
116 while ((id = NextDisplayInfo(id)) != INVALID_ID)
118 if ((id & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID)
119 continue;
121 if (!(handle = FindDisplayInfo(id)))
122 continue;
124 if (!GetDisplayInfoData(handle, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, 0))
125 continue;
127 if (!GetDisplayInfoData(handle, (UBYTE *)&DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, 0))
128 continue;
130 if (!(DisplayInfo.PropertyFlags & DIPF_IS_WB) || DisplayInfo.NotAvailable)
131 continue;
133 if (!GetDisplayInfoData(handle, (UBYTE *)&DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, 0))
134 continue;
136 modes_array[cur_mode] = AllocVec(sizeof(NameInfo.Name), MEMF_ANY);
137 if (!modes_array[cur_mode])
138 continue;
140 CopyMem(NameInfo.Name, modes_array[cur_mode], sizeof(NameInfo.Name));
141 ids_array[cur_mode] = id;
143 cur_mode++;
146 DisplayHook.h_Data = ids_array;
148 list = (Object *)ListObject,
149 InputListFrame,
150 MUIA_List_DisplayHook, (IPTR)&DisplayHook,
151 MUIA_List_Format, (IPTR)"BAR,",
152 MUIA_List_SourceArray, (IPTR)modes_array,
153 MUIA_List_Title, TRUE,
154 MUIA_CycleChain, TRUE,
155 End;
157 self = (Object *)DoSuperNewTags
159 CLASS, self, NULL,
160 MUIA_Listview_List, (IPTR)list,
161 TAG_MORE, (IPTR)message->ops_AttrList
164 if (!self)
165 goto err;
167 DoMethod(self, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
168 (IPTR)self, 3, MUIM_CallHook, (IPTR)&SelectHook, MUIV_TriggerValue);
170 data = INST_DATA(CLASS, self);
171 data->modes_array = modes_array;
172 data->ids_array = ids_array;
174 return self;
176 err:
177 CoerceMethod(CLASS, self, OM_DISPOSE);
178 return NULL;
181 IPTR ScreenModeSelector__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
183 struct ScreenModeSelector_DATA *data;
184 ULONG cur_mode;
186 data = INST_DATA(CLASS, self);
188 if (data->modes_array)
190 for (cur_mode = 0; data->modes_array[cur_mode]; cur_mode++)
191 FreeVec(data->modes_array[cur_mode]);
193 FreeVec(data->modes_array);
196 FreeVec(data->ids_array);
198 return DoSuperMethodA(CLASS, self, message);
202 IPTR ScreenModeSelector__OM_SET(Class *CLASS, Object *self, struct opSet *message)
204 struct ScreenModeSelector_DATA *data = INST_DATA(CLASS, self);
205 struct TagItem *tags;
206 struct TagItem *tag;
207 struct TagItem noforward_tags[] =
209 {MUIA_Group_Forward , FALSE },
210 {TAG_MORE , (IPTR)message->ops_AttrList }
212 struct opSet noforward_message = *message;
213 noforward_message.ops_AttrList = noforward_tags;
215 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
217 switch (tag->ti_Tag)
219 case MUIA_ScreenModeSelector_Active:
221 int i;
223 D(bug("[smselector] Set Active ID 0x%08lX\n", tag->ti_Data));
226 i = 0;
227 data->ids_array[i] != tag->ti_Data && data->ids_array[i] != INVALID_ID;
231 if (data->ids_array[i] == INVALID_ID)
232 tag->ti_Data = INVALID_ID;
233 else
235 if (XGET(self, MUIA_List_Active) != i)
237 D(bug("[smselector] Set active item %lu\n", i));
238 NNFSET(self, MUIA_List_Active, i);
241 break;
246 return DoSuperMethodA(CLASS, self, (Msg)&noforward_message);
249 IPTR ScreenModeSelector__OM_GET(Class *CLASS, Object *self, struct opGet *message)
251 struct ScreenModeSelector_DATA *data = INST_DATA(CLASS, self);
253 switch (message->opg_AttrID)
255 case MUIA_ScreenModeSelector_Active:
256 *message->opg_Storage =
257 data->ids_array[XGET(self, MUIA_List_Active)];
258 break;
259 default:
260 return DoSuperMethodA(CLASS, self, (Msg)message);
263 return TRUE;
267 ZUNE_CUSTOMCLASS_4
269 ScreenModeSelector, NULL, MUIC_Listview, NULL,
270 OM_NEW, struct opSet *,
271 OM_DISPOSE, Msg,
272 OM_GET, struct opGet *,
273 OM_SET, struct opSet *