added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / screenmode / smeditor.c
blob114d58501806d1747be4c04fc6eec84bf53784c0
1 /*
2 Copyright © 2003-2006, 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/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>
25 #include <stdio.h>
27 #include "locale.h"
29 #include "smeditor.h"
30 #include "smselector.h"
31 #include "smproperties.h"
34 struct SMEditor_DATA
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
47 CLASS, self, NULL,
49 MUIA_PrefsEditor_Name, (IPTR) __(MSG_NAME),
50 MUIA_PrefsEditor_Path, (IPTR)"SYS/screenmode.prefs",
52 Child, (IPTR)VGroup,
53 Child, (IPTR)(selector = ScreenModeSelectorObject, End),
54 Child, (IPTR)(properties = ScreenModePropertiesObject, GroupFrame, End),
55 End,
57 TAG_DONE
60 if (self)
62 SETUP_INST_DATA;
64 data->selector = selector;
65 data->properties = properties;
67 /*-- Setup notifications -------------------------------------------*/
68 DoMethod
70 selector, MUIM_Notify, MUIA_ScreenModeSelector_Active, MUIV_EveryTime,
71 (IPTR)properties, 3,
72 MUIM_Set, MUIA_ScreenModeProperties_DisplayID, MUIV_TriggerValue
75 DoMethod
77 properties, MUIM_Notify, MUIA_ScreenModeProperties_DisplayID, MUIV_EveryTime,
78 (IPTR)self, 3,
79 MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
82 DoMethod
84 properties, MUIM_Notify, MUIA_ScreenModeProperties_Width, MUIV_EveryTime,
85 (IPTR)self, 3,
86 MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
89 DoMethod
91 properties, MUIM_Notify, MUIA_ScreenModeProperties_Height, MUIV_EveryTime,
92 (IPTR)self, 3,
93 MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
96 DoMethod
98 properties, MUIM_Notify, MUIA_ScreenModeProperties_Depth, MUIV_EveryTime,
99 (IPTR)self, 3,
100 MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
103 DoMethod
105 properties, MUIM_Notify, MUIA_ScreenModeProperties_Autoscroll, MUIV_EveryTime,
106 (IPTR)self, 3,
107 MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
111 return self;
114 void SMPByteSwap(struct ScreenModePrefs *smp)
116 #if 0
117 #undef SWAP
118 #define SWAP(type, field) smp->smp_ ## field = AROS_BE2 ## type(smp->smp_ ## field)
120 int i;
121 for (i = 0; i < sizeof(smp->smp_Reserved)/sizeof(ULONG); i++)
122 SWAP(LONG, Reserved[i]);
124 SWAP(LONG, DisplayID);
125 SWAP(WORD, Width);
126 SWAP(WORD, Height);
127 SWAP(WORD, Depth);
128 SWAP(WORD, Control);
129 #endif
132 IPTR SMEditor__MUIM_PrefsEditor_ImportFH
134 Class *CLASS, Object *self,
135 struct MUIP_PrefsEditor_ImportFH *message
138 SETUP_INST_DATA;
139 struct ContextNode *context;
140 struct IFFHandle *handle;
141 struct ScreenModePrefs smp;
142 BOOL success = TRUE;
143 LONG error;
145 if (!(handle = AllocIFF()))
146 return FALSE;
148 handle->iff_Stream = (IPTR) message->fh;
149 InitIFFasDOS(handle);
151 if ((error = OpenIFF(handle, IFFF_READ)) == 0)
154 BYTE i;
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)
170 if (error < 0)
172 printf("Error: ReadChunkBytes() returned %ld!\n", error);
175 else
177 printf("ParseIFF() failed, returncode %ld!\n", error);
178 success = FALSE;
179 break;
182 else
184 printf("StopChunk() failed, returncode %ld!\n", error);
185 success = FALSE;
189 CloseIFF(handle);
191 else
193 //ShowError(_(MSG_CANT_OPEN_STREAM));
196 FreeIFF(handle);
199 if (success)
201 SMPByteSwap(&smp);
203 nnset(data->selector, MUIA_ScreenModeSelector_Active, smp.smp_DisplayID);
204 SetAttrs
206 data->properties,
207 MUIA_NoNotify, TRUE,
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,
213 TAG_DONE
217 return success;
220 IPTR SMEditor__MUIM_PrefsEditor_ExportFH
222 Class *CLASS, Object *self,
223 struct MUIP_PrefsEditor_ExportFH *message
226 SETUP_INST_DATA;
228 struct PrefHeader header = { 0 };
229 struct IFFHandle *handle;
230 BOOL success = TRUE;
231 LONG error = 0;
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));
245 BYTE i;
247 PushChunk(handle, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
249 header.ph_Version = PHV_CURRENT;
250 header.ph_Type = 0;
252 PushChunk(handle, ID_PREF, ID_PRHD, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
254 WriteChunkBytes(handle, &header, sizeof(struct PrefHeader));
256 PopChunk(handle);
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;
274 else
275 smp.smp_Control = 0;
277 SMPByteSwap(&smp);
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
289 PopChunk(handle);
291 else
293 //ShowError(_(MSG_CANT_OPEN_STREAM));
294 success = FALSE;
297 CloseIFF(handle);
298 FreeIFF(handle);
300 else // AllocIFF()
302 // Do something more here - if IFF allocation has failed, something isn't right
303 //ShowError(_(MSG_CANT_ALLOCATE_IFFPTR));
304 success = FALSE;
307 return success;
310 IPTR SMEditor__MUIM_PrefsEditor_Test
312 Class *CLASS, Object *self, Msg message
315 return FALSE;
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);
334 #undef ALIAS
335 #define ALIAS(old, new) \
336 AROS_MAKE_ALIAS(SMEditor__MUIM_PrefsEditor_ ## old, SMEditor__MUIM_PrefsEditor_ ## new)
338 ALIAS(Test, Revert);
339 ALIAS(Use, Save);
340 ALIAS(Use, Cancel);
342 ZUNE_CUSTOMCLASS_8
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