added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / screenmode / smselector.c
blob454b8c49b117d99c492824fff5e0bff45fca4b93
1 /*
2 Copyright © 2003-2006, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
7 #define DEBUG 0
9 #include <libraries/mui.h>
10 #include <utility/hooks.h>
12 #include <proto/exec.h>
13 #include <proto/muimaster.h>
14 #include <proto/intuition.h>
15 #include <proto/graphics.h>
16 #include <proto/dos.h>
17 #include <proto/utility.h>
19 #include <zune/customclasses.h>
21 #include <string.h>
23 #include "locale.h"
25 #include "smselector.h"
27 struct ScreenModeSelector_DATA
29 STRPTR *modes_array;
30 ULONG *ids_array;
33 #define HOOK(name) \
34 struct Hook
36 #define HOOKFUNC(name) IPTR name ## Func(struct Hook *hook, APTR obj, APTR msg)
38 AROS_UFH3(IPTR, SelectFunc,
39 AROS_UFHA(struct Hook *, hook, A0),
40 AROS_UFHA(APTR , obj , A2),
41 AROS_UFHA(APTR , msg , A1))
43 AROS_USERFUNC_INIT
45 struct ScreenModeSelector_DATA *data = INST_DATA(OCLASS(obj), obj);
47 return set(obj, MUIA_ScreenModeSelector_Active, data->ids_array[*(IPTR *)msg]);
49 AROS_USERFUNC_EXIT;
51 static struct Hook SelectHook = { .h_Entry = SelectFunc };
53 Object *ScreenModeSelector__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
55 STRPTR *modes_array;
56 ULONG *ids_array;
57 ULONG id, num_modes, cur_mode;
59 struct DisplayInfo DisplayInfo;
60 struct DimensionInfo DimensionInfo;
61 struct NameInfo NameInfo;
62 APTR handle;
64 struct ScreenModeSelector_DATA *data;
66 num_modes = 0; id = INVALID_ID;
67 while ((id = NextDisplayInfo(id)) != INVALID_ID) num_modes++;
69 modes_array = AllocVec(sizeof(STRPTR) * (1 + num_modes + 1), MEMF_CLEAR);
70 if (!modes_array)
71 goto err;
73 ids_array = AllocVec(sizeof(ULONG) * (1 + num_modes + 1), MEMF_ANY);
74 if (!ids_array)
75 goto err;
77 modes_array[0] = __(MSG_SELECT);
78 ids_array[0] = INVALID_ID;
79 ids_array[num_modes + 1] = INVALID_ID;
81 cur_mode = 1;
82 while ((id = NextDisplayInfo(id)) != INVALID_ID)
84 if ((id & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID)
85 continue;
87 if (!(handle = FindDisplayInfo(id)))
88 continue;
90 if (!GetDisplayInfoData(handle, (UBYTE *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, 0))
91 continue;
93 if (!GetDisplayInfoData(handle, (UBYTE *)&DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, 0))
94 continue;
96 if (!(DisplayInfo.PropertyFlags & DIPF_IS_WB) || DisplayInfo.NotAvailable)
97 continue;
99 if (!GetDisplayInfoData(handle, (UBYTE *)&DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, 0))
100 continue;
102 modes_array[cur_mode] = AllocVec(sizeof(NameInfo.Name), MEMF_ANY);
103 if (!modes_array[cur_mode])
104 continue;
106 CopyMem(NameInfo.Name, modes_array[cur_mode], sizeof(NameInfo.Name));
107 ids_array[cur_mode] = id;
109 cur_mode++;
112 self = (Object *)DoSuperNewTags
114 CLASS, self, NULL,
115 MUIA_Cycle_Entries, (IPTR)modes_array,
116 TAG_MORE, (IPTR)message->ops_AttrList
119 if (!self)
120 goto err;
122 DoMethod(self, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
123 (IPTR)self, 3, MUIM_CallHook, (IPTR)&SelectHook, MUIV_TriggerValue);
125 data = INST_DATA(CLASS, self);
126 data->modes_array = modes_array;
127 data->ids_array = ids_array;
129 return self;
131 err:
132 CoerceMethod(CLASS, self, OM_DISPOSE);
133 return NULL;
136 IPTR ScreenModeSelector__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
138 struct ScreenModeSelector_DATA *data;
139 ULONG cur_mode;
141 data = INST_DATA(CLASS, self);
143 if (data->modes_array)
145 for (cur_mode = 1; data->modes_array[cur_mode]; cur_mode++)
146 FreeVec(data->modes_array[cur_mode]);
148 FreeVec(data->modes_array);
151 FreeVec(data->ids_array);
153 return DoSuperMethodA(CLASS, self, message);
157 IPTR ScreenModeSelector__OM_SET(Class *CLASS, Object *self, struct opSet *message)
159 struct ScreenModeSelector_DATA *data = INST_DATA(CLASS, self);
160 const struct TagItem *tags;
161 struct TagItem *tag;
162 struct TagItem noforward_tags[] =
164 {MUIA_Group_Forward , FALSE },
165 {TAG_MORE , (IPTR)message->ops_AttrList }
167 struct opSet noforward_message = *message;
168 noforward_message.ops_AttrList = noforward_tags;
170 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
172 switch (tag->ti_Tag)
174 case MUIA_ScreenModeSelector_Active:
176 int i;
180 i = 1;
181 data->ids_array[i] != tag->ti_Data && data->ids_array[i] != INVALID_ID;
185 if (data->ids_array[i] == INVALID_ID)
186 tag->ti_Data = INVALID_ID;
187 else
188 if (XGET(self, MUIA_Cycle_Active) != i)
189 NFSET(self, MUIA_Cycle_Active, i);
191 break;
196 return DoSuperMethodA(CLASS, self, (Msg)&noforward_message);
199 IPTR ScreenModeSelector__OM_GET(Class *CLASS, Object *self, struct opGet *message)
201 struct ScreenModeSelector_DATA *data = INST_DATA(CLASS, self);
203 switch (message->opg_AttrID)
205 case MUIA_ScreenModeSelector_Active:
206 *message->opg_Storage = data->ids_array[XGET(self, MUIA_Cycle_Active)];
207 break;
208 default:
209 return DoSuperMethodA(CLASS, self, (Msg)message);
212 return TRUE;
216 ZUNE_CUSTOMCLASS_4
218 ScreenModeSelector, NULL, MUIC_Cycle, NULL,
219 OM_NEW, struct opSet *,
220 OM_DISPOSE, Msg,
221 OM_GET, struct opGet *,
222 OM_SET, struct opSet *