revert between 56095 -> 55830 in arch
[AROS.git] / workbench / prefs / PSI / displayidlist_class.c
blobaf0610a8f9d66fac2aa5d995ab26f2eff363315d
1 /*
2 Copyright © 1995-1997 Stefan Stuntz.
3 Copyright © 2009-2010, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 #define DEBUG 0
10 #include "aros/debug.h"
12 #include <proto/exec.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
15 #include <proto/alib.h>
16 #include <proto/utility.h>
17 #include <proto/muimaster.h>
19 #include <string.h>
21 #include "displayidlist_class.h"
23 /****************************************************************************************/
25 struct DispIDlist_Data
27 ULONG CurrentID;
28 struct Hook ConstructHook;
29 struct Hook DisplayHook;
32 /****************************************************************************************/
34 IPTR DispIDlist_DisplayFunc(struct Hook *hook, char **array, struct NameInfo *ni)
36 *array = ni->Name;
37 return 0;
40 /****************************************************************************************/
42 IPTR DispIDlist_CompareFunc(struct Hook *hook, struct NameInfo *n1, struct NameInfo *n2)
44 return stricmp(n1->Name, n2->Name);
47 /****************************************************************************************/
49 VOID DispIDlist_DestructFunc(struct Hook *hook, APTR pool, struct NameInfo *ni)
51 FreeVec(ni);
54 /****************************************************************************************/
56 IPTR DispIDlist_ConstructFunc(struct Hook *hook, APTR pool, ULONG modeid)
58 APTR handle;
59 struct NameInfo NameInfo;
60 struct DisplayInfo DisplayInfo;
61 struct DimensionInfo DimensionInfo;
62 struct NameInfo *ni;
64 if ((modeid & MONITOR_ID_MASK) == DEFAULT_MONITOR_ID)
65 return 0;
67 if (!(handle = FindDisplayInfo(modeid)))
68 return 0;
70 if (!GetDisplayInfoData(handle, (char *)&NameInfo, sizeof(struct NameInfo), DTAG_NAME, 0))
71 return 0;
73 if (!GetDisplayInfoData(handle, (char *)&DisplayInfo, sizeof(struct DisplayInfo), DTAG_DISP, 0))
74 return 0;
76 if (!GetDisplayInfoData(handle, (char *)&DimensionInfo, sizeof(struct DimensionInfo), DTAG_DIMS, 0))
77 return 0;
79 if (!(DisplayInfo.PropertyFlags & DIPF_IS_WB))
80 return 0;
82 if (DisplayInfo.NotAvailable)
83 return 0;
85 if (!(ni = AllocVec(sizeof(struct NameInfo), MEMF_ANY)))
86 return 0;
88 *ni = NameInfo;
89 return (IPTR)ni;
92 /****************************************************************************************/
94 IPTR DispIDlist_New(struct IClass *cl,Object *obj,Msg msg)
96 static struct Hook ConstructHook;
97 ConstructHook.h_Entry = HookEntry;
98 ConstructHook.h_SubEntry = DispIDlist_ConstructFunc;
99 static struct Hook DestructHook;
100 DestructHook.h_Entry = HookEntry;
101 DestructHook.h_SubEntry = (HOOKFUNC)DispIDlist_DestructFunc;
102 static struct Hook CompareHook;
103 CompareHook.h_Entry = HookEntry;
104 CompareHook.h_SubEntry = DispIDlist_CompareFunc;
105 static struct Hook DisplayHook;
106 DisplayHook.h_Entry = HookEntry;
107 DisplayHook.h_SubEntry = DispIDlist_DisplayFunc;
108 LONG id = INVALID_ID;
110 if (!(obj=(Object *)DoSuperMethodA(cl,obj,msg)))
111 return 0;
113 SetSuperAttrs(cl, obj,
114 MUIA_List_ConstructHook, &ConstructHook,
115 MUIA_List_DestructHook , &DestructHook,
116 MUIA_List_CompareHook , &CompareHook,
117 MUIA_List_DisplayHook , &DisplayHook,
118 MUIA_List_AutoVisible , TRUE,
119 TAG_DONE);
121 while ((id = NextDisplayInfo(id)) != INVALID_ID)
122 DoMethod(obj, MUIM_List_InsertSingle, id, MUIV_List_Insert_Bottom);
124 DoMethod(obj, MUIM_List_Sort);
126 DoMethod(obj, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime, obj, 1, MUIM_DispIDlist_Change);
128 return (IPTR)obj;
131 /****************************************************************************************/
133 IPTR DispIDlist_Set(struct IClass *cl, Object *obj, struct opSet *msg)
135 struct DispIDlist_Data *data = INST_DATA(cl, obj);
136 struct TagItem *tag,*quiet;
138 quiet = FindTagItem(MUIA_DispIDlist_Quiet, msg->ops_AttrList);
140 if ((tag = FindTagItem(MUIA_DispIDlist_CurrentID, msg->ops_AttrList)))
142 data->CurrentID = tag->ti_Data;
144 if (!quiet)
146 int i;
147 struct NameInfo *ni;
148 ULONG mask = 0;
150 for (;;)
152 for (i = 0; ; i++)
154 DoMethod(obj, MUIM_List_GetEntry, i, &ni);
155 if (!ni)
156 break;
157 if ((ni->Header.DisplayID & ~mask) == (data->CurrentID & ~mask))
159 mask = MONITOR_ID_MASK;
160 break;
163 if (!ni)
164 break;
165 if (mask == MONITOR_ID_MASK)
166 break;
167 mask = MONITOR_ID_MASK;
170 if (ni)
171 set(obj, MUIA_List_Active, i);
172 else
173 set(obj, MUIA_List_Active, MUIV_List_Active_Off);
176 return DoSuperMethodA(cl, obj, (Msg)msg);
179 /****************************************************************************************/
181 IPTR DispIDlist_Get(struct IClass *cl, Object *obj, struct opGet *msg)
183 struct DispIDlist_Data *data = INST_DATA(cl, obj);
185 switch (msg->opg_AttrID)
187 case MUIA_DispIDlist_CurrentID:
188 *(msg->opg_Storage) = data->CurrentID;
189 return TRUE;
192 return DoSuperMethodA(cl, obj, (Msg)msg);
195 /****************************************************************************************/
197 IPTR DispIDlist_Change(struct IClass *cl, Object *obj, Msg msg)
199 struct NameInfo *ni;
200 DoMethod(obj, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &ni);
201 D(bug("[PSI/DispIDlist_Change] ni %p id %d\n", ni, ni ? ni->Header.DisplayID : INVALID_ID));
202 SetAttrs(obj,
203 MUIA_DispIDlist_Quiet, TRUE,
204 MUIA_DispIDlist_CurrentID, ni ? ni->Header.DisplayID : INVALID_ID,
205 TAG_DONE);
207 return 0;
210 /****************************************************************************************/
212 BOOPSI_DISPATCHER(IPTR, DispIDlist_Dispatcher, cl, obj, msg)
214 switch (msg->MethodID)
216 case OM_NEW: return DispIDlist_New(cl, obj, (APTR)msg);
217 case OM_SET: return DispIDlist_Set(cl, obj, (APTR)msg);
218 case OM_GET: return DispIDlist_Get(cl, obj, (APTR)msg);
219 case MUIM_DispIDlist_Change: return DispIDlist_Change(cl, obj, (APTR)msg);
221 return DoSuperMethodA(cl, obj, msg);
223 BOOPSI_DISPATCHER_END
225 /****************************************************************************************/
227 VOID DispIDlist_Init(VOID)
229 CL_DispIDlist = MUI_CreateCustomClass
231 NULL, MUIC_List, NULL, sizeof(struct DispIDlist_Data), DispIDlist_Dispatcher
235 /****************************************************************************************/
237 VOID DispIDlist_Exit(VOID)
239 if (CL_DispIDlist) MUI_DeleteCustomClass(CL_DispIDlist);