Don't keep asking for S2EVENT_CONNECT reports if driver doen't
[AROS.git] / workbench / prefs / screenmode / smselector.c
blob8da892ee6d83a8f9c8e479f1169606296d061ed6
1 /*
2 Copyright © 2003-2011, 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 return set(obj, MUIA_ScreenModeSelector_Active, data->ids_array[*(IPTR *)msg]);
52 AROS_USERFUNC_EXIT;
54 static struct Hook SelectHook = { .h_Entry = SelectFunc };
56 AROS_UFH3(IPTR, DisplayFunc,
57 AROS_UFHA(struct Hook *, hook, A0),
58 AROS_UFHA(CONST_STRPTR *, array, A2),
59 AROS_UFHA(STRPTR, entry, A1))
61 AROS_USERFUNC_INIT
63 if (entry)
65 ULONG *ids_array = hook->h_Data;
66 ULONG num = (ULONG)(IPTR)array[-1];
67 IPTR modeid = ids_array[num];
68 static char modeid_str[9];
70 RawDoFmt("%08lx", &modeid, RAWFMTFUNC_STRING, modeid_str);
71 array[0] = modeid_str;
72 array[1] = entry;
74 else
76 array[0] = _(MSG_MODE_ID);
77 array[1] = _(MSG_DESCRIPTION);
79 return 0;
81 AROS_USERFUNC_EXIT
84 static struct Hook DisplayHook = { .h_Entry = DisplayFunc };
86 Object *ScreenModeSelector__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
88 STRPTR *modes_array;
89 ULONG *ids_array;
90 ULONG id, num_modes, cur_mode;
91 Object *list;
93 struct DisplayInfo DisplayInfo;
94 struct DimensionInfo DimensionInfo;
95 struct NameInfo NameInfo;
96 APTR handle;
98 struct ScreenModeSelector_DATA *data;
100 num_modes = 0; id = INVALID_ID;
101 while ((id = NextDisplayInfo(id)) != INVALID_ID) num_modes++;
103 modes_array = AllocVec(sizeof(STRPTR) * (num_modes + 1), MEMF_CLEAR);
104 if (!modes_array)
105 goto err;
107 ids_array = AllocVec(sizeof(ULONG) * (num_modes + 1), MEMF_ANY);
108 if (!ids_array)
109 goto err;
111 ids_array[num_modes] = INVALID_ID;
113 cur_mode = 0;
114 while ((id = NextDisplayInfo(id)) != INVALID_ID)
116 if ((id & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID)
117 continue;
119 if (!(handle = FindDisplayInfo(id)))
120 continue;
122 if (!GetDisplayInfoData(handle, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, 0))
123 continue;
125 if (!GetDisplayInfoData(handle, (UBYTE *)&DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, 0))
126 continue;
128 if (!(DisplayInfo.PropertyFlags & DIPF_IS_WB) || DisplayInfo.NotAvailable)
129 continue;
131 if (!GetDisplayInfoData(handle, (UBYTE *)&DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, 0))
132 continue;
134 modes_array[cur_mode] = AllocVec(sizeof(NameInfo.Name), MEMF_ANY);
135 if (!modes_array[cur_mode])
136 continue;
138 CopyMem(NameInfo.Name, modes_array[cur_mode], sizeof(NameInfo.Name));
139 ids_array[cur_mode] = id;
141 cur_mode++;
144 DisplayHook.h_Data = ids_array;
146 list = (Object *)ListObject,
147 InputListFrame,
148 MUIA_List_DisplayHook, (IPTR)&DisplayHook,
149 MUIA_List_Format, (IPTR)"BAR,",
150 MUIA_List_SourceArray, (IPTR)modes_array,
151 MUIA_List_Title, TRUE,
152 MUIA_CycleChain, TRUE, /* CHECKME: Keyboard input in the list doesn't work, why? */
153 End;
155 self = (Object *)DoSuperNewTags
157 CLASS, self, NULL,
158 MUIA_Listview_List, (IPTR)list,
159 TAG_MORE, (IPTR)message->ops_AttrList
162 if (!self)
163 goto err;
165 DoMethod(self, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
166 (IPTR)self, 3, MUIM_CallHook, (IPTR)&SelectHook, MUIV_TriggerValue);
168 data = INST_DATA(CLASS, self);
169 data->modes_array = modes_array;
170 data->ids_array = ids_array;
172 return self;
174 err:
175 CoerceMethod(CLASS, self, OM_DISPOSE);
176 return NULL;
179 IPTR ScreenModeSelector__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
181 struct ScreenModeSelector_DATA *data;
182 ULONG cur_mode;
184 data = INST_DATA(CLASS, self);
186 if (data->modes_array)
188 for (cur_mode = 0; data->modes_array[cur_mode]; cur_mode++)
189 FreeVec(data->modes_array[cur_mode]);
191 FreeVec(data->modes_array);
194 FreeVec(data->ids_array);
196 return DoSuperMethodA(CLASS, self, message);
200 IPTR ScreenModeSelector__OM_SET(Class *CLASS, Object *self, struct opSet *message)
202 struct ScreenModeSelector_DATA *data = INST_DATA(CLASS, self);
203 struct TagItem *tags;
204 struct TagItem *tag;
205 struct TagItem noforward_tags[] =
207 {MUIA_Group_Forward , FALSE },
208 {TAG_MORE , (IPTR)message->ops_AttrList }
210 struct opSet noforward_message = *message;
211 noforward_message.ops_AttrList = noforward_tags;
213 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
215 switch (tag->ti_Tag)
217 case MUIA_ScreenModeSelector_Active:
219 int i;
221 D(bug("[smselector] Set Active ID 0x%08lX\n", tag->ti_Data));
224 i = 0;
225 data->ids_array[i] != tag->ti_Data && data->ids_array[i] != INVALID_ID;
229 if (data->ids_array[i] == INVALID_ID)
230 tag->ti_Data = INVALID_ID;
231 else
233 if (XGET(self, MUIA_List_Active) != i)
235 D(bug("[smselector] Set active item %lu\n", i));
236 NNFSET(self, MUIA_List_Active, i);
239 break;
244 return DoSuperMethodA(CLASS, self, (Msg)&noforward_message);
247 IPTR ScreenModeSelector__OM_GET(Class *CLASS, Object *self, struct opGet *message)
249 struct ScreenModeSelector_DATA *data = INST_DATA(CLASS, self);
251 switch (message->opg_AttrID)
253 case MUIA_ScreenModeSelector_Active:
254 *message->opg_Storage = data->ids_array[XGET(self, MUIA_Cycle_Active)];
255 break;
256 default:
257 return DoSuperMethodA(CLASS, self, (Msg)message);
260 return TRUE;
264 ZUNE_CUSTOMCLASS_4
266 ScreenModeSelector, NULL, MUIC_Listview, NULL,
267 OM_NEW, struct opSet *,
268 OM_DISPOSE, Msg,
269 OM_GET, struct opGet *,
270 OM_SET, struct opSet *