2 Copyright © 1995-1997 Stefan Stuntz.
3 Copyright © 2009-2010, The AROS Development Team.
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>
21 #include "displayidlist_class.h"
23 /****************************************************************************************/
25 struct DispIDlist_Data
28 struct Hook ConstructHook
;
29 struct Hook DisplayHook
;
32 /****************************************************************************************/
34 IPTR
DispIDlist_DisplayFunc(struct Hook
*hook
, char **array
, struct NameInfo
*ni
)
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
)
54 /****************************************************************************************/
56 IPTR
DispIDlist_ConstructFunc(struct Hook
*hook
, APTR pool
, ULONG modeid
)
59 struct NameInfo NameInfo
;
60 struct DisplayInfo DisplayInfo
;
61 struct DimensionInfo DimensionInfo
;
64 if ((modeid
& MONITOR_ID_MASK
) == DEFAULT_MONITOR_ID
)
67 if (!(handle
= FindDisplayInfo(modeid
)))
70 if (!GetDisplayInfoData(handle
, (char *)&NameInfo
, sizeof(struct NameInfo
), DTAG_NAME
, 0))
73 if (!GetDisplayInfoData(handle
, (char *)&DisplayInfo
, sizeof(struct DisplayInfo
), DTAG_DISP
, 0))
76 if (!GetDisplayInfoData(handle
, (char *)&DimensionInfo
, sizeof(struct DimensionInfo
), DTAG_DIMS
, 0))
79 if (!(DisplayInfo
.PropertyFlags
& DIPF_IS_WB
))
82 if (DisplayInfo
.NotAvailable
)
85 if (!(ni
= AllocVec(sizeof(struct NameInfo
), MEMF_ANY
)))
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
)))
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
,
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
);
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
;
154 DoMethod(obj
, MUIM_List_GetEntry
, i
, &ni
);
157 if ((ni
->Header
.DisplayID
& ~mask
) == (data
->CurrentID
& ~mask
))
159 mask
= MONITOR_ID_MASK
;
165 if (mask
== MONITOR_ID_MASK
)
167 mask
= MONITOR_ID_MASK
;
171 set(obj
, MUIA_List_Active
, i
);
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
;
192 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
195 /****************************************************************************************/
197 IPTR
DispIDlist_Change(struct IClass
*cl
, Object
*obj
, Msg msg
)
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
));
203 MUIA_DispIDlist_Quiet
, TRUE
,
204 MUIA_DispIDlist_CurrentID
, ni
? ni
->Header
.DisplayID
: INVALID_ID
,
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
);