disable float support on m68k to prevent unwanted symbols being used in rom code...
[AROS.git] / workbench / prefs / screenmode / smproperties.c
blobe5ae5b6dfdd72b280a56f5c48b11f031e1a7850f
1 /*
2 Copyright © 2003-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
7 #define DEBUG 0
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>
21 #include "locale.h"
23 #include "smproperties.h"
25 struct ScreenModeProperties_DATA
27 Object *depth, *def_width, *def_height;
29 Object *objWidth;
30 Object *objHeight;
31 Object *autoscroll;
33 ULONG DisplayID;
34 UWORD MinWidth, MinHeight;
35 UWORD MaxWidth, MaxHeight;
36 UWORD DefWidth, DefHeight;
37 UWORD DefDepth;
38 BOOL VariableDepth;
41 #define CheckMarkObject \
42 ImageObject, \
43 ImageButtonFrame, \
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)
53 #undef HCenter
54 #define HCenter(obj...) \
55 (HGroup, (IPTR)GroupSpacing(0), Child, (IPTR)HSpace(0), Child, (IPTR)(obj), Child, \
56 (IPTR)HSpace(0), End)
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;
64 Object *autoscroll;
66 ULONG id;
68 self = (Object *)DoSuperNewTags
70 CLASS, self, NULL,
71 MUIA_Group_Horiz, TRUE,
72 Child, (IPTR)ColGroup(4),
73 Child, (IPTR)Label1(__(MSG_WIDTH)),
74 Child, HLeft(objWidth = (Object *)StringObject,
75 StringFrame,
76 MUIA_String_Accept, (IPTR)"0123456789",
77 MUIA_String_MaxLen, 6,
78 MUIA_CycleChain, TRUE,
79 MUIA_FixWidthTxt, (IPTR)"00000",
80 End),
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,
86 StringFrame,
87 MUIA_String_Accept, (IPTR)"0123456789",
88 MUIA_String_MaxLen, 6,
89 MUIA_CycleChain, TRUE,
90 MUIA_FixWidthTxt, (IPTR)"00000",
91 End),
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,
105 End,
107 TAG_MORE, (IPTR)message->ops_AttrList
110 if (!self)
111 goto err;
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;
118 data->depth = depth;
119 data->def_width = def_width;
120 data->def_height = def_height;
121 data->autoscroll = autoscroll;
123 DoMethod
125 objWidth, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
126 (IPTR)self, 3,
127 MUIM_Set, MUIA_ScreenModeProperties_WidthString, MUIV_TriggerValue
130 DoMethod
132 objHeight, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
133 (IPTR)self, 3,
134 MUIM_Set, MUIA_ScreenModeProperties_HeightString, MUIV_TriggerValue
137 DoMethod
139 depth, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
140 (IPTR)self, 3,
141 MUIM_Set, MUIA_ScreenModeProperties_Depth, MUIV_TriggerValue
144 DoMethod
146 def_width, MUIM_Notify, MUIA_Selected, TRUE,
147 (IPTR)self, 3,
148 MUIM_Set, MUIA_ScreenModeProperties_Width, -1
151 DoMethod
153 def_width, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
154 (IPTR)objWidth, 3,
155 MUIM_Set, MUIA_Disabled, MUIV_TriggerValue
158 DoMethod
160 def_height, MUIM_Notify, MUIA_Selected, TRUE,
161 (IPTR)self, 3,
162 MUIM_Set, MUIA_ScreenModeProperties_Height, -1
165 DoMethod
167 def_height, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
168 (IPTR)objHeight, 3,
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);
176 return self;
178 err:
179 CoerceMethod(CLASS, self, OM_DISPOSE);
180 return NULL;
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));
190 return 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));
200 return 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;
207 struct TagItem *tag;
208 ULONG id = INVALID_ID;
209 IPTR no_notify = TAG_IGNORE;
210 IPTR ret;
211 WORD depth;
212 LONG width, height;
214 DB2(bug("[smproperties] OM_SET called\n"));
215 for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
217 switch (tag->ti_Tag)
219 case MUIA_NoNotify:
220 no_notify = MUIA_NoNotify;
221 break;
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},
232 { TAG_DONE, 0 }
235 struct DimensionInfo dim;
236 BOOL autoscroll;
237 ULONG tmpid;
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))
250 IPTR isdefault, val;
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;
256 id = tmpid;
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);
271 if (isdefault)
272 width = data->DefWidth;
273 else
275 GetAttr(MUIA_String_Integer, data->objWidth, &val);
276 width = AdjustWidth((LONG)val, data);
279 GetAttr(MUIA_Selected, data->def_height, &isdefault);
280 if (isdefault)
281 height = data->DefHeight;
282 else
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
305 the resolution. */
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;
319 else
321 IPTR isdefault;
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,
335 TAG_DONE);
337 break;
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);
344 break;
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;
352 else
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);
357 break;
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);
363 break;
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;
371 else
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);
376 break;
378 case MUIA_ScreenModeProperties_Depth:
379 if (data->VariableDepth)
381 depth = tag->ti_Data;
383 D(bug("[smproperties] Set Depth = %ld\n", depth));
384 if (depth == -1)
385 depth = data->DefDepth;
386 SetAttrs(data->depth, no_notify, TRUE, MUIA_Numeric_Value, depth, TAG_DONE);
388 break;
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);
395 break;
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));
402 return 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;
413 break;
415 case MUIA_ScreenModeProperties_Width:
416 *message->opg_Storage = XGET(data->objWidth, MUIA_String_Integer);
417 break;
419 case MUIA_ScreenModeProperties_Height:
420 *message->opg_Storage = XGET(data->objHeight, MUIA_String_Integer);
421 break;
423 case MUIA_ScreenModeProperties_Depth:
424 *message->opg_Storage = XGET(data->depth, MUIA_Numeric_Value);
425 break;
427 case MUIA_ScreenModeProperties_Autoscroll:
428 *message->opg_Storage = XGET(data->autoscroll, MUIA_Selected);
429 break;
431 case MUIA_ScreenModeProperties_DefWidth:
432 *message->opg_Storage = data->DefWidth;
433 break;
435 case MUIA_ScreenModeProperties_DefHeight:
436 *message->opg_Storage = data->DefHeight;
437 break;
439 default:
440 return DoSuperMethodA(CLASS, self, (Msg)message);
443 return TRUE;
446 ZUNE_CUSTOMCLASS_3
448 ScreenModeProperties, NULL, MUIC_Group, NULL,
449 OM_NEW, struct opSet *,
450 OM_GET, struct opGet *,
451 OM_SET, struct opSet *