2 Copyright © 2003-2011, 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 return set(obj
, MUIA_ScreenModeSelector_Active
, data
->ids_array
[*(IPTR
*)msg
]);
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
))
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
;
76 array
[0] = _(MSG_MODE_ID
);
77 array
[1] = _(MSG_DESCRIPTION
);
84 static struct Hook DisplayHook
= { .h_Entry
= DisplayFunc
};
86 Object
*ScreenModeSelector__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
90 ULONG id
, num_modes
, cur_mode
;
93 struct DisplayInfo DisplayInfo
;
94 struct DimensionInfo DimensionInfo
;
95 struct NameInfo NameInfo
;
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
);
107 ids_array
= AllocVec(sizeof(ULONG
) * (num_modes
+ 1), MEMF_ANY
);
111 ids_array
[num_modes
] = INVALID_ID
;
114 while ((id
= NextDisplayInfo(id
)) != INVALID_ID
)
116 if ((id
& MONITOR_ID_MASK
) == DEFAULT_MONITOR_ID
)
119 if (!(handle
= FindDisplayInfo(id
)))
122 if (!GetDisplayInfoData(handle
, (UBYTE
*)&NameInfo
, sizeof(struct NameInfo
), DTAG_NAME
, 0))
125 if (!GetDisplayInfoData(handle
, (UBYTE
*)&DisplayInfo
, sizeof(struct DisplayInfo
), DTAG_DISP
, 0))
128 if (!(DisplayInfo
.PropertyFlags
& DIPF_IS_WB
) || DisplayInfo
.NotAvailable
)
131 if (!GetDisplayInfoData(handle
, (UBYTE
*)&DimensionInfo
, sizeof(struct DimensionInfo
), DTAG_DIMS
, 0))
134 modes_array
[cur_mode
] = AllocVec(sizeof(NameInfo
.Name
), MEMF_ANY
);
135 if (!modes_array
[cur_mode
])
138 CopyMem(NameInfo
.Name
, modes_array
[cur_mode
], sizeof(NameInfo
.Name
));
139 ids_array
[cur_mode
] = id
;
144 DisplayHook
.h_Data
= ids_array
;
146 list
= (Object
*)ListObject
,
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? */
155 self
= (Object
*)DoSuperNewTags
158 MUIA_Listview_List
, (IPTR
)list
,
159 TAG_MORE
, (IPTR
)message
->ops_AttrList
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
;
175 CoerceMethod(CLASS
, self
, OM_DISPOSE
);
179 IPTR
ScreenModeSelector__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
181 struct ScreenModeSelector_DATA
*data
;
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
;
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
)); )
217 case MUIA_ScreenModeSelector_Active
:
221 D(bug("[smselector] Set Active ID 0x%08lX\n", tag
->ti_Data
));
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
;
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
);
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
)];
257 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
266 ScreenModeSelector
, NULL
, MUIC_Listview
, NULL
,
267 OM_NEW
, struct opSet
*,
269 OM_GET
, struct opGet
*,
270 OM_SET
, struct opSet
*