2 Copyright © 2003-2017, 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
40 #define HOOKFUNC(name) IPTR name ## Func(struct Hook *hook, APTR obj, APTR msg)
42 AROS_UFH3(IPTR
, SelectFunc
,
43 AROS_UFHA(struct Hook
*, hook
, A0
),
44 AROS_UFHA(APTR
, obj
, A2
),
45 AROS_UFHA(APTR
, msg
, A1
))
49 struct ScreenModeSelector_DATA
*data
= INST_DATA(OCLASS(obj
), obj
);
51 /* Note: the value used to set MUIA_List_Active may not be an index */
52 return set(obj
, MUIA_ScreenModeSelector_Active
,
53 data
->ids_array
[XGET(obj
, MUIA_List_Active
)]);
57 static struct Hook SelectHook
= { .h_Entry
= SelectFunc
};
59 AROS_UFH3(IPTR
, DisplayFunc
,
60 AROS_UFHA(struct Hook
*, hook
, A0
),
61 AROS_UFHA(CONST_STRPTR
*, array
, A2
),
62 AROS_UFHA(STRPTR
, entry
, A1
))
68 ULONG
*ids_array
= hook
->h_Data
;
69 ULONG num
= (ULONG
)(IPTR
)array
[-1];
70 ULONG modeid
= ids_array
[num
];
71 static char modeid_str
[9];
73 RawDoFmt("%08lx", (RAWARG
)&modeid
, RAWFMTFUNC_STRING
, modeid_str
);
74 array
[0] = modeid_str
;
79 array
[0] = _(MSG_MODE_ID
);
80 array
[1] = _(MSG_DESCRIPTION
);
87 static struct Hook DisplayHook
= { .h_Entry
= DisplayFunc
};
89 Object
*ScreenModeSelector__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
93 ULONG id
, num_modes
, cur_mode
;
96 struct DisplayInfo DisplayInfo
;
97 struct DimensionInfo DimensionInfo
;
98 struct NameInfo NameInfo
;
101 struct ScreenModeSelector_DATA
*data
;
103 num_modes
= 0; id
= INVALID_ID
;
104 while ((id
= NextDisplayInfo(id
)) != INVALID_ID
) num_modes
++;
106 modes_array
= AllocVec(sizeof(STRPTR
) * (num_modes
+ 1), MEMF_CLEAR
);
110 ids_array
= AllocVec(sizeof(ULONG
) * (num_modes
+ 1), MEMF_ANY
);
114 ids_array
[num_modes
] = INVALID_ID
;
117 while ((id
= NextDisplayInfo(id
)) != INVALID_ID
)
119 if ((id
& MONITOR_ID_MASK
) == DEFAULT_MONITOR_ID
)
122 if (!(handle
= FindDisplayInfo(id
)))
125 if (!GetDisplayInfoData(handle
, (UBYTE
*)&NameInfo
, sizeof(struct NameInfo
), DTAG_NAME
, 0))
128 if (!GetDisplayInfoData(handle
, (UBYTE
*)&DisplayInfo
, sizeof(struct DisplayInfo
), DTAG_DISP
, 0))
131 if (!(DisplayInfo
.PropertyFlags
& DIPF_IS_WB
) || DisplayInfo
.NotAvailable
)
134 if (!GetDisplayInfoData(handle
, (UBYTE
*)&DimensionInfo
, sizeof(struct DimensionInfo
), DTAG_DIMS
, 0))
137 modes_array
[cur_mode
] = AllocVec(sizeof(NameInfo
.Name
), MEMF_ANY
);
138 if (!modes_array
[cur_mode
])
141 CopyMem(NameInfo
.Name
, modes_array
[cur_mode
], sizeof(NameInfo
.Name
));
142 ids_array
[cur_mode
] = id
;
147 DisplayHook
.h_Data
= ids_array
;
149 list
= (Object
*)ListObject
,
151 MUIA_List_AutoVisible
, (IPTR
)TRUE
,
152 MUIA_List_DisplayHook
, (IPTR
)&DisplayHook
,
153 MUIA_List_Format
, (IPTR
)"BAR,",
154 MUIA_List_SourceArray
, (IPTR
)modes_array
,
155 MUIA_List_Title
, TRUE
,
156 MUIA_CycleChain
, TRUE
,
159 self
= (Object
*)DoSuperNewTags
162 MUIA_Listview_List
, (IPTR
)list
,
163 TAG_MORE
, (IPTR
)message
->ops_AttrList
169 DoMethod(self
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
170 (IPTR
)self
, 3, MUIM_CallHook
, (IPTR
)&SelectHook
, MUIV_TriggerValue
);
172 data
= INST_DATA(CLASS
, self
);
173 data
->mode_list
= list
;
174 data
->modes_array
= modes_array
;
175 data
->ids_array
= ids_array
;
180 CoerceMethod(CLASS
, self
, OM_DISPOSE
);
184 IPTR
ScreenModeSelector__OM_DISPOSE(Class
*CLASS
, Object
*self
, Msg message
)
186 struct ScreenModeSelector_DATA
*data
;
189 data
= INST_DATA(CLASS
, self
);
191 if (data
->modes_array
)
193 for (cur_mode
= 0; data
->modes_array
[cur_mode
]; cur_mode
++)
194 FreeVec(data
->modes_array
[cur_mode
]);
196 FreeVec(data
->modes_array
);
199 FreeVec(data
->ids_array
);
201 return DoSuperMethodA(CLASS
, self
, message
);
205 IPTR
ScreenModeSelector__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
207 struct ScreenModeSelector_DATA
*data
= INST_DATA(CLASS
, self
);
208 struct TagItem
*tags
;
210 struct TagItem noforward_tags
[] =
212 {MUIA_Group_Forward
, FALSE
},
213 {TAG_MORE
, (IPTR
)message
->ops_AttrList
}
215 struct opSet noforward_message
= *message
;
216 noforward_message
.ops_AttrList
= noforward_tags
;
218 for (tags
= message
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
222 case MUIA_ScreenModeSelector_Active
:
226 D(bug("[smselector] Set Active ID 0x%08lX\n", tag
->ti_Data
));
230 data
->ids_array
[i
] != tag
->ti_Data
&& data
->ids_array
[i
] != INVALID_ID
;
234 if (data
->ids_array
[i
] == INVALID_ID
)
235 tag
->ti_Data
= INVALID_ID
;
238 if (XGET(data
->mode_list
, MUIA_List_Active
) != i
)
240 D(bug("[smselector] Set active item %lu\n", i
));
241 NNFSET(data
->mode_list
, MUIA_List_Active
, i
);
249 return DoSuperMethodA(CLASS
, self
, (Msg
)&noforward_message
);
252 IPTR
ScreenModeSelector__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
254 struct ScreenModeSelector_DATA
*data
= INST_DATA(CLASS
, self
);
256 switch (message
->opg_AttrID
)
258 case MUIA_ScreenModeSelector_Active
:
259 *message
->opg_Storage
=
260 data
->ids_array
[XGET(data
->mode_list
, MUIA_List_Active
)];
263 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
272 ScreenModeSelector
, NULL
, MUIC_Listview
, NULL
,
273 OM_NEW
, struct opSet
*,
275 OM_GET
, struct opGet
*,
276 OM_SET
, struct opSet
*