2 Copyright © 2003-2013, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
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>
28 #include "smselector.h"
30 struct ScreenModeSelector_DATA
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
))
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
)]);
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
))
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
;
78 array
[0] = _(MSG_MODE_ID
);
79 array
[1] = _(MSG_DESCRIPTION
);
86 static struct Hook DisplayHook
= { .h_Entry
= DisplayFunc
};
88 Object
*ScreenModeSelector__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
92 ULONG id
, num_modes
, cur_mode
;
95 struct DisplayInfo DisplayInfo
;
96 struct DimensionInfo DimensionInfo
;
97 struct NameInfo NameInfo
;
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
);
109 ids_array
= AllocVec(sizeof(ULONG
) * (num_modes
+ 1), MEMF_ANY
);
113 ids_array
[num_modes
] = INVALID_ID
;
116 while ((id
= NextDisplayInfo(id
)) != INVALID_ID
)
118 if ((id
& MONITOR_ID_MASK
) == DEFAULT_MONITOR_ID
)
121 if (!(handle
= FindDisplayInfo(id
)))
124 if (!GetDisplayInfoData(handle
, (UBYTE
*)&NameInfo
, sizeof(struct NameInfo
), DTAG_NAME
, 0))
127 if (!GetDisplayInfoData(handle
, (UBYTE
*)&DisplayInfo
, sizeof(struct DisplayInfo
), DTAG_DISP
, 0))
130 if (!(DisplayInfo
.PropertyFlags
& DIPF_IS_WB
) || DisplayInfo
.NotAvailable
)
133 if (!GetDisplayInfoData(handle
, (UBYTE
*)&DimensionInfo
, sizeof(struct DimensionInfo
), DTAG_DIMS
, 0))
136 modes_array
[cur_mode
] = AllocVec(sizeof(NameInfo
.Name
), MEMF_ANY
);
137 if (!modes_array
[cur_mode
])
140 CopyMem(NameInfo
.Name
, modes_array
[cur_mode
], sizeof(NameInfo
.Name
));
141 ids_array
[cur_mode
] = id
;
146 DisplayHook
.h_Data
= ids_array
;
148 list
= (Object
*)ListObject
,
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
,
157 self
= (Object
*)DoSuperNewTags
160 MUIA_Listview_List
, (IPTR
)list
,
161 TAG_MORE
, (IPTR
)message
->ops_AttrList
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
;
177 CoerceMethod(CLASS
, self
, OM_DISPOSE
);
181 IPTR
ScreenModeSelector__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
183 struct ScreenModeSelector_DATA
*data
;
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
;
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
)); )
219 case MUIA_ScreenModeSelector_Active
:
223 D(bug("[smselector] Set Active ID 0x%08lX\n", tag
->ti_Data
));
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
;
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
);
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
)];
260 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
269 ScreenModeSelector
, NULL
, MUIC_Listview
, NULL
,
270 OM_NEW
, struct opSet
*,
272 OM_GET
, struct opGet
*,
273 OM_SET
, struct opSet
*