2 Copyright © 2003-2017, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
9 #include <libraries/mui.h>
11 #include <proto/alib.h>
12 #include <proto/dos.h>
13 #include <proto/exec.h>
14 #include <proto/muimaster.h>
15 #include <proto/intuition.h>
16 #include <proto/graphics.h>
17 #include <proto/utility.h>
19 #include <zune/customclasses.h>
23 #include "smproperties.h"
25 struct ScreenModeProperties_DATA
27 Object
*depth
, *def_width
, *def_height
;
34 UWORD MinWidth
, MinHeight
;
35 UWORD MaxWidth
, MaxHeight
;
36 UWORD DefWidth
, DefHeight
;
41 #define CheckMarkObject \
44 MUIA_InputMode , MUIV_InputMode_Toggle, \
45 MUIA_Image_Spec , MUII_CheckMark, \
46 MUIA_Image_FreeVert , TRUE, \
47 MUIA_Background , MUII_ButtonBack, \
48 MUIA_ShowSelState , FALSE
50 #define HLeft(obj...) \
51 (IPTR)(HGroup, (IPTR)GroupSpacing(0), Child, (IPTR)(obj), Child, (IPTR)HSpace(0), End)
54 #define HCenter(obj...) \
55 (HGroup, (IPTR)GroupSpacing(0), Child, (IPTR)HSpace(0), Child, (IPTR)(obj), Child, \
58 Object
*ScreenModeProperties__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
60 struct ScreenModeProperties_DATA
*data
;
61 Object
*objWidth
, *objHeight
, *depth
,
62 *def_width
, *def_height
;
68 self
= (Object
*)DoSuperNewTags
71 MUIA_Group_Horiz
, TRUE
,
72 Child
, (IPTR
)ColGroup(4),
73 Child
, (IPTR
)Label1(__(MSG_WIDTH
)),
74 Child
, HLeft(objWidth
= (Object
*)StringObject
,
76 MUIA_String_Accept
, (IPTR
)"0123456789",
77 MUIA_String_MaxLen
, 6,
78 MUIA_CycleChain
, TRUE
,
79 MUIA_FixWidthTxt
, (IPTR
)"00000",
81 Child
, (IPTR
)(def_width
= (Object
*)CheckMarkObject
, MUIA_CycleChain
, TRUE
, End
),
82 Child
, (IPTR
)Label1(__(MSG_DEFAULT
)),
84 Child
, (IPTR
)Label1(__(MSG_HEIGHT
)),
85 Child
, HLeft(objHeight
= (Object
*)StringObject
,
87 MUIA_String_Accept
, (IPTR
)"0123456789",
88 MUIA_String_MaxLen
, 6,
89 MUIA_CycleChain
, TRUE
,
90 MUIA_FixWidthTxt
, (IPTR
)"00000",
92 Child
, HLeft(def_height
= (Object
*)CheckMarkObject
, MUIA_CycleChain
, TRUE
, End
),
93 Child
, (IPTR
)Label1(__(MSG_DEFAULT
)),
95 Child
, (IPTR
)Label1(__(MSG_DEPTH
)),
96 Child
, HLeft(depth
= (Object
*)SliderObject
, MUIA_CycleChain
, TRUE
, End
),
97 Child
, (IPTR
)RectangleObject
, End
,
98 Child
, (IPTR
)RectangleObject
, End
,
100 Child
, (IPTR
)Label1(__(MSG_AUTOSCROLL
)),
101 Child
, HLeft(autoscroll
= (Object
*)CheckMarkObject
, MUIA_CycleChain
, TRUE
, End
),
102 Child
, (IPTR
)RectangleObject
, End
,
103 Child
, (IPTR
)RectangleObject
, End
,
107 TAG_MORE
, (IPTR
)message
->ops_AttrList
113 D(bug("[smproperties] Created ScreenModeProperties object 0x%p\n", self
));
114 data
= INST_DATA(CLASS
, self
);
116 data
->objWidth
= objWidth
;
117 data
->objHeight
= objHeight
;
119 data
->def_width
= def_width
;
120 data
->def_height
= def_height
;
121 data
->autoscroll
= autoscroll
;
125 objWidth
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
127 MUIM_Set
, MUIA_ScreenModeProperties_WidthString
, MUIV_TriggerValue
132 objHeight
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
134 MUIM_Set
, MUIA_ScreenModeProperties_HeightString
, MUIV_TriggerValue
139 depth
, MUIM_Notify
, MUIA_Numeric_Value
, MUIV_EveryTime
,
141 MUIM_Set
, MUIA_ScreenModeProperties_Depth
, MUIV_TriggerValue
146 def_width
, MUIM_Notify
, MUIA_Selected
, TRUE
,
148 MUIM_Set
, MUIA_ScreenModeProperties_Width
, -1
153 def_width
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
155 MUIM_Set
, MUIA_Disabled
, MUIV_TriggerValue
160 def_height
, MUIM_Notify
, MUIA_Selected
, TRUE
,
162 MUIM_Set
, MUIA_ScreenModeProperties_Height
, -1
167 def_height
, MUIM_Notify
, MUIA_Selected
, MUIV_EveryTime
,
169 MUIM_Set
, MUIA_Disabled
, MUIV_TriggerValue
172 id
= GetTagData(MUIA_ScreenModeProperties_DisplayID
, INVALID_ID
, message
->ops_AttrList
);
173 D(bug("[smproperties] Setting initial ModeID 0x%08lX\n", id
));
174 set(self
, MUIA_ScreenModeProperties_DisplayID
, id
);
179 CoerceMethod(CLASS
, self
, OM_DISPOSE
);
183 static inline UWORD
AdjustWidth(UWORD width
, struct ScreenModeProperties_DATA
*data
)
185 if (width
< data
->MinWidth
)
186 width
= data
->MinWidth
;
187 if (width
> data
->MaxWidth
)
188 width
= data
->MaxWidth
;
189 D(bug("[smproperties] Adjusted width = %lu\n", width
));
193 static inline UWORD
AdjustHeight(UWORD height
, struct ScreenModeProperties_DATA
*data
)
195 if (height
< data
->MinHeight
)
196 height
= data
->MinHeight
;
197 if (height
> data
->MaxHeight
)
198 height
= data
->MaxHeight
;
199 D(bug("[smproperties] Adjusted height = %lu\n", height
));
203 IPTR
ScreenModeProperties__OM_SET(Class
*CLASS
, Object
*self
, struct opSet
*message
)
205 struct ScreenModeProperties_DATA
*data
= INST_DATA(CLASS
, self
);
206 struct TagItem
*tags
;
208 ULONG id
= INVALID_ID
;
209 IPTR no_notify
= TAG_IGNORE
;
214 DB2(bug("[smproperties] OM_SET called\n"));
215 for (tags
= message
->ops_AttrList
; (tag
= NextTagItem(&tags
)); )
220 no_notify
= MUIA_NoNotify
;
223 case MUIA_ScreenModeProperties_DisplayID
:
225 struct TagItem depth_tags
[] =
227 { MUIA_NoNotify
, TRUE
},
228 { MUIA_Numeric_Min
, 0 },
229 { MUIA_Numeric_Max
, 0 },
230 { MUIA_Numeric_Default
, 0 },
231 { MUIA_Disabled
, FALSE
},
235 struct DimensionInfo dim
;
239 tmpid
= tag
->ti_Data
;
240 D(bug("[smproperties] Set DisplayID = 0x%08lx\n", tmpid
));
242 if (!GetDisplayInfoData(NULL
, (UBYTE
*)&dim
, sizeof(dim
), DTAG_DIMS
, tmpid
))
244 tmpid
= BestModeID(TAG_DONE
);
245 nnset(data
->def_width
, MUIA_Selected
, TRUE
);
246 nnset(data
->def_height
, MUIA_Selected
, TRUE
);
248 if (GetDisplayInfoData(NULL
, (UBYTE
*)&dim
, sizeof(dim
), DTAG_DIMS
, tmpid
))
252 depth_tags
[1].ti_Data
= dim
.MaxDepth
> 8 ? dim
.MaxDepth
: 1;
253 depth_tags
[2].ti_Data
= dim
.MaxDepth
;
254 depth_tags
[3].ti_Data
= dim
.MaxDepth
;
257 data
->DefWidth
= dim
.Nominal
.MaxX
- dim
.Nominal
.MinX
+ 1;
258 data
->DefHeight
= dim
.Nominal
.MaxY
- dim
.Nominal
.MinY
+ 1;
259 data
->DefDepth
= depth_tags
[3].ti_Data
;
260 data
->MinWidth
= dim
.MinRasterWidth
;
261 data
->MinHeight
= dim
.MinRasterHeight
;
262 data
->MaxWidth
= dim
.MaxRasterWidth
;
263 data
->MaxHeight
= dim
.MaxRasterHeight
;
265 D(bug("[smproperties] Obtained DimensionsInfo:\n"));
266 D(bug("[smproperties] Minimum raster: %lux%lux1\n", dim
.MinRasterWidth
, dim
.MinRasterHeight
));
267 D(bug("[smproperties] Maximum raster: %lux%lux%lu\n", dim
.MaxRasterWidth
, dim
.MaxRasterHeight
, dim
.MaxDepth
));
268 D(bug("[smproperties] Display size: %lux%lu\n", data
->DefWidth
, data
->DefHeight
));
270 GetAttr(MUIA_Selected
, data
->def_width
, &isdefault
);
272 width
= data
->DefWidth
;
275 GetAttr(MUIA_String_Integer
, data
->objWidth
, &val
);
276 width
= AdjustWidth((LONG
)val
, data
);
279 GetAttr(MUIA_Selected
, data
->def_height
, &isdefault
);
281 height
= data
->DefHeight
;
284 GetAttr(MUIA_String_Integer
, data
->objHeight
, &val
);
285 height
= AdjustHeight((LONG
)val
, data
);
288 data
->VariableDepth
= TRUE
;
289 GetAttr(MUIA_Numeric_Value
, data
->depth
, &val
);
290 /* Original AmigaOS screenmode prefs do not allow to change depth for CyberGFX
291 * screenmodes if it is high or true color screenmode */
292 if (dim
.MaxDepth
> 8)
294 data
->VariableDepth
= FALSE
;
295 depth_tags
[3].ti_Tag
= MUIA_Numeric_Value
;
296 depth_tags
[4].ti_Data
= TRUE
;
297 } else if (val
> dim
.MaxDepth
) {
298 /* Make sure depth is always <= dim.MaxDepth */
299 depth_tags
[3].ti_Tag
= MUIA_Numeric_Value
;
300 depth_tags
[3].ti_Data
= dim
.MaxDepth
;
304 /* Enable autoscroll if one of the maximum sizes is bigger than
307 autoscroll
= data
->MaxWidth
> data
->DefWidth
||
308 data
->MaxHeight
> data
->DefHeight
;
310 data
->DisplayID
= id
;
312 SetAttrs(self
, MUIA_Disabled
, id
== INVALID_ID
, TAG_DONE
);
313 if (id
== INVALID_ID
)
315 nnset(data
->def_width
, MUIA_Selected
, TRUE
);
316 nnset(data
->def_height
, MUIA_Selected
, TRUE
);
317 depth_tags
[4].ti_Tag
= TAG_DONE
;
322 GetAttr(MUIA_Selected
, data
->def_height
, &isdefault
);
323 SetAttrs(data
->objHeight
, MUIA_Disabled
, isdefault
, TAG_DONE
);
324 GetAttr(MUIA_Selected
, data
->def_width
, &isdefault
);
325 SetAttrs(data
->objWidth
, MUIA_Disabled
, isdefault
, TAG_DONE
);
328 SetAttrs(data
->objWidth
, MUIA_String_Integer
, width
, TAG_DONE
);
329 SetAttrs(data
->objHeight
, MUIA_String_Integer
, height
, TAG_DONE
);
330 SetAttrsA(data
->depth
, depth_tags
);
332 SetAttrs(data
->autoscroll
, no_notify
, TRUE
,
333 MUIA_Disabled
, !autoscroll
,
334 MUIA_Selected
, autoscroll
,
340 case MUIA_ScreenModeProperties_WidthString
:
341 D(bug("[smproperties] Set WidthString = %s\n", (CONST_STRPTR
)tag
->ti_Data
));
342 StrToLong((CONST_STRPTR
)tag
->ti_Data
, &width
);
343 SetAttrs(self
, MUIA_ScreenModeProperties_Width
, width
, TAG_DONE
);
346 case MUIA_ScreenModeProperties_Width
:
347 width
= tag
->ti_Data
;
349 D(bug("[smproperties] Set Width = %ld\n", width
));
350 if ((WORD
)width
== STDSCREENWIDTH
)
351 width
= data
->DefWidth
;
353 width
= AdjustWidth(width
, data
);
354 SetAttrs(data
->objWidth
, MUIA_NoNotify
, TRUE
, MUIA_String_Integer
, width
, TAG_DONE
);
355 SetAttrs(data
->def_width
, MUIA_NoNotify
, TRUE
, MUIA_Selected
, width
== data
->DefWidth
, TAG_DONE
);
356 SetAttrs(data
->objWidth
, MUIA_NoNotify
, TRUE
, MUIA_Disabled
, width
== data
->DefWidth
, TAG_DONE
);
359 case MUIA_ScreenModeProperties_HeightString
:
360 D(bug("[smproperties] Set HeightString = %s\n", (CONST_STRPTR
)tag
->ti_Data
));
361 StrToLong((CONST_STRPTR
)tag
->ti_Data
, &height
);
362 SetAttrs(self
, MUIA_ScreenModeProperties_Height
, height
, TAG_DONE
);
365 case MUIA_ScreenModeProperties_Height
:
366 height
= tag
->ti_Data
;
368 D(bug("[smproperties] Set Height = %ld\n", height
));
369 if ((WORD
)height
== STDSCREENHEIGHT
)
370 height
= data
->DefHeight
;
372 height
= AdjustHeight(height
, data
);
373 SetAttrs(data
->objHeight
, MUIA_NoNotify
, TRUE
, MUIA_String_Integer
, height
, TAG_DONE
);
374 SetAttrs(data
->def_height
, MUIA_NoNotify
, TRUE
, MUIA_Selected
, height
== data
->DefHeight
, TAG_DONE
);
375 SetAttrs(data
->objHeight
, MUIA_NoNotify
, TRUE
, MUIA_Disabled
, height
== data
->DefHeight
, TAG_DONE
);
378 case MUIA_ScreenModeProperties_Depth
:
379 if (data
->VariableDepth
)
381 depth
= tag
->ti_Data
;
383 D(bug("[smproperties] Set Depth = %ld\n", depth
));
385 depth
= data
->DefDepth
;
386 SetAttrs(data
->depth
, no_notify
, TRUE
, MUIA_Numeric_Value
, depth
, TAG_DONE
);
390 case MUIA_ScreenModeProperties_Autoscroll
:
392 D(bug("[smproperties] Set Autoscroll = %lu\n", tag
->ti_Data
));
393 if (id
!= INVALID_ID
&& !XGET(data
->autoscroll
, MUIA_Disabled
))
394 SetAttrs(data
->autoscroll
, no_notify
, TRUE
, MUIA_Selected
, tag
->ti_Data
!= 0);
399 DB2(bug("[smproperties] Calling OM_SET() on superclass\n"));
400 ret
= DoSuperMethodA(CLASS
, self
, (Msg
)message
);
401 DB2(bug("[smproperties] OM_SET() on superclass returned %ld\n", ret
));
405 IPTR
ScreenModeProperties__OM_GET(Class
*CLASS
, Object
*self
, struct opGet
*message
)
407 struct ScreenModeProperties_DATA
*data
= INST_DATA(CLASS
, self
);
409 switch (message
->opg_AttrID
)
411 case MUIA_ScreenModeProperties_DisplayID
:
412 *message
->opg_Storage
= data
->DisplayID
;
415 case MUIA_ScreenModeProperties_Width
:
416 *message
->opg_Storage
= XGET(data
->objWidth
, MUIA_String_Integer
);
419 case MUIA_ScreenModeProperties_Height
:
420 *message
->opg_Storage
= XGET(data
->objHeight
, MUIA_String_Integer
);
423 case MUIA_ScreenModeProperties_Depth
:
424 *message
->opg_Storage
= XGET(data
->depth
, MUIA_Numeric_Value
);
427 case MUIA_ScreenModeProperties_Autoscroll
:
428 *message
->opg_Storage
= XGET(data
->autoscroll
, MUIA_Selected
);
431 case MUIA_ScreenModeProperties_DefWidth
:
432 *message
->opg_Storage
= data
->DefWidth
;
435 case MUIA_ScreenModeProperties_DefHeight
:
436 *message
->opg_Storage
= data
->DefHeight
;
440 return DoSuperMethodA(CLASS
, self
, (Msg
)message
);
448 ScreenModeProperties
, NULL
, MUIC_Group
, NULL
,
449 OM_NEW
, struct opSet
*,
450 OM_GET
, struct opGet
*,
451 OM_SET
, struct opSet
*