2 Copyright © 2003-2006, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
9 #include <libraries/mui.h>
11 #include <proto/exec.h>
12 #include <proto/muimaster.h>
13 #include <proto/intuition.h>
14 #include <proto/graphics.h>
15 #include <proto/utility.h>
16 #include <proto/iffparse.h>
18 #include <zune/customclasses.h>
19 #include <zune/prefseditor.h>
20 #include <zune/systemprefswindow.h>
22 #include <prefs/screenmode.h>
23 #include <prefs/prefhdr.h>
30 #include "smselector.h"
31 #include "smproperties.h"
36 Object
*selector
, *properties
;
39 #define SMEditorObject BOOPSIOBJMACRO_START(SMEditor_CLASS->mcc_Class)
40 #define SETUP_INST_DATA struct SMEditor_DATA *data = INST_DATA(CLASS, self)
42 Object
*SMEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
44 Object
*selector
, *properties
;
45 self
= (Object
*) DoSuperNewTags
49 MUIA_PrefsEditor_Name
, (IPTR
) __(MSG_NAME
),
50 MUIA_PrefsEditor_Path
, (IPTR
)"SYS/screenmode.prefs",
53 Child
, (IPTR
)(selector
= ScreenModeSelectorObject
, End
),
54 Child
, (IPTR
)(properties
= ScreenModePropertiesObject
, GroupFrame
, End
),
64 data
->selector
= selector
;
65 data
->properties
= properties
;
67 /*-- Setup notifications -------------------------------------------*/
70 selector
, MUIM_Notify
, MUIA_ScreenModeSelector_Active
, MUIV_EveryTime
,
72 MUIM_Set
, MUIA_ScreenModeProperties_DisplayID
, MUIV_TriggerValue
77 properties
, MUIM_Notify
, MUIA_ScreenModeProperties_DisplayID
, MUIV_EveryTime
,
79 MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
84 properties
, MUIM_Notify
, MUIA_ScreenModeProperties_Width
, MUIV_EveryTime
,
86 MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
91 properties
, MUIM_Notify
, MUIA_ScreenModeProperties_Height
, MUIV_EveryTime
,
93 MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
98 properties
, MUIM_Notify
, MUIA_ScreenModeProperties_Depth
, MUIV_EveryTime
,
100 MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
105 properties
, MUIM_Notify
, MUIA_ScreenModeProperties_Autoscroll
, MUIV_EveryTime
,
107 MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
114 void SMPByteSwap(struct ScreenModePrefs
*smp
)
118 #define SWAP(type, field) smp->smp_ ## field = AROS_BE2 ## type(smp->smp_ ## field)
121 for (i
= 0; i
< sizeof(smp
->smp_Reserved
)/sizeof(ULONG
); i
++)
122 SWAP(LONG
, Reserved
[i
]);
124 SWAP(LONG
, DisplayID
);
132 IPTR SMEditor__MUIM_PrefsEditor_ImportFH
134 Class
*CLASS
, Object
*self
,
135 struct MUIP_PrefsEditor_ImportFH
*message
139 struct ContextNode
*context
;
140 struct IFFHandle
*handle
;
141 struct ScreenModePrefs smp
;
145 if (!(handle
= AllocIFF()))
148 handle
->iff_Stream
= (IPTR
) message
->fh
;
149 InitIFFasDOS(handle
);
151 if ((error
= OpenIFF(handle
, IFFF_READ
)) == 0)
156 // FIXME: We want some sanity checking here!
157 for (i
= 0; i
< 1; i
++)
159 if ((error
= StopChunk(handle
, ID_PREF
, ID_SCRM
)) == 0)
161 if ((error
= ParseIFF(handle
, IFFPARSE_SCAN
)) == 0)
163 context
= CurrentChunk(handle
);
165 error
= ReadChunkBytes
167 handle
, &smp
, sizeof(struct ScreenModePrefs
)
172 printf("Error: ReadChunkBytes() returned %ld!\n", error
);
177 printf("ParseIFF() failed, returncode %ld!\n", error
);
184 printf("StopChunk() failed, returncode %ld!\n", error
);
193 //ShowError(_(MSG_CANT_OPEN_STREAM));
203 nnset(data
->selector
, MUIA_ScreenModeSelector_Active
, smp
.smp_DisplayID
);
208 MUIA_ScreenModeProperties_DisplayID
, smp
.smp_DisplayID
,
209 MUIA_ScreenModeProperties_Width
, smp
.smp_Width
,
210 MUIA_ScreenModeProperties_Height
, smp
.smp_Height
,
211 MUIA_ScreenModeProperties_Depth
, smp
.smp_Depth
,
212 MUIA_ScreenModeProperties_Autoscroll
, smp
.smp_Control
& AUTOSCROLL
,
220 IPTR SMEditor__MUIM_PrefsEditor_ExportFH
222 Class
*CLASS
, Object
*self
,
223 struct MUIP_PrefsEditor_ExportFH
*message
228 struct PrefHeader header
= { 0 };
229 struct IFFHandle
*handle
;
233 if ((handle
= AllocIFF()))
235 handle
->iff_Stream
= (IPTR
) message
->fh
;
237 InitIFFasDOS(handle
);
239 if (!(error
= OpenIFF(handle
, IFFF_WRITE
))) /* NULL = successful! */
241 struct ScreenModePrefs smp
;
243 memset(&smp
, 0, sizeof(smp
));
247 PushChunk(handle
, ID_PREF
, ID_FORM
, IFFSIZE_UNKNOWN
); /* FIXME: IFFSIZE_UNKNOWN? */
249 header
.ph_Version
= PHV_CURRENT
;
252 PushChunk(handle
, ID_PREF
, ID_PRHD
, IFFSIZE_UNKNOWN
); /* FIXME: IFFSIZE_UNKNOWN? */
254 WriteChunkBytes(handle
, &header
, sizeof(struct PrefHeader
));
258 for (i
= 0; i
< 1; i
++)
260 error
= PushChunk(handle
, ID_PREF
, ID_SCRM
, sizeof(struct ScreenModePrefs
));
262 if (error
!= 0) // TODO: We need some error checking here!
264 printf("error: PushChunk() = %ld ", error
);
267 smp
.smp_DisplayID
= XGET(data
->properties
, MUIA_ScreenModeProperties_DisplayID
);
268 smp
.smp_Width
= XGET(data
->properties
, MUIA_ScreenModeProperties_Width
);
269 smp
.smp_Height
= XGET(data
->properties
, MUIA_ScreenModeProperties_Height
);
270 smp
.smp_Depth
= XGET(data
->properties
, MUIA_ScreenModeProperties_Depth
);
272 if (XGET(data
->properties
, MUIA_ScreenModeProperties_Autoscroll
))
273 smp
.smp_Control
= AUTOSCROLL
;
279 error
= WriteChunkBytes(handle
, &smp
, sizeof(struct ScreenModePrefs
));
280 error
= PopChunk(handle
);
282 if (error
!= 0) // TODO: We need some error checking here!
284 printf("error: PopChunk() = %ld ", error
);
288 // Terminate the FORM
293 //ShowError(_(MSG_CANT_OPEN_STREAM));
302 // Do something more here - if IFF allocation has failed, something isn't right
303 //ShowError(_(MSG_CANT_ALLOCATE_IFFPTR));
310 IPTR SMEditor__MUIM_PrefsEditor_Test
312 Class
*CLASS
, Object
*self
, Msg message
318 IPTR SMEditor__MUIM_PrefsEditor_Use
320 Class
*CLASS
, Object
*self
, Msg message
323 #warning "FIXME: Closing the window here only works because we're lucky "
324 #warning " and nothing needs to access anything that is put in the "
325 #warning " RenderInfo structure, which gets deallocated when closing"
326 #warning " the window. This needs to be fixed directly in the "
327 #warning " PrefsEditor class. "
328 if (muiRenderInfo(self
) && _win(self
))
329 set(_win(self
), MUIA_Window_Open
, FALSE
);
331 return DoSuperMethodA(CLASS
, self
, message
);
335 #define ALIAS(old, new) \
336 AROS_MAKE_ALIAS(SMEditor__MUIM_PrefsEditor_ ## old, SMEditor__MUIM_PrefsEditor_ ## new)
344 SMEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
345 OM_NEW
, struct opSet
*,
346 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
347 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*,
348 MUIM_PrefsEditor_Test
, Msg
,
349 MUIM_PrefsEditor_Revert
, Msg
,
350 MUIM_PrefsEditor_Use
, Msg
,
351 MUIM_PrefsEditor_Save
, Msg
,
352 MUIM_PrefsEditor_Cancel
, Msg