grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / prefs / serial / sereditor.c
blob8a63ebb012cd8eafc6e8428523d0647045ce9d41
1 /*
2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 // #define DEBUG 1
9 #include <zune/customclasses.h>
10 #include <zune/prefseditor.h>
12 #include <proto/alib.h>
13 #include <proto/intuition.h>
14 #include <proto/muimaster.h>
16 #include <stdlib.h>
18 #include <aros/debug.h>
20 #include "locale.h"
21 #include "sereditor.h"
22 #include "prefs.h"
24 /*** String Data ************************************************************/
26 CONST_STRPTR BaudrateLabels[] =
28 (CONST_STRPTR) "50",
29 (CONST_STRPTR) "75",
30 (CONST_STRPTR) "110",
31 (CONST_STRPTR) "134",
32 (CONST_STRPTR) "150",
33 (CONST_STRPTR) "200",
34 (CONST_STRPTR) "300",
35 (CONST_STRPTR) "600",
36 (CONST_STRPTR) "1200",
37 (CONST_STRPTR) "2400",
38 (CONST_STRPTR) "4800",
39 (CONST_STRPTR) "9600",
40 (CONST_STRPTR) "19200",
41 (CONST_STRPTR) "38400",
42 (CONST_STRPTR) "57600",
43 (CONST_STRPTR)"115200",
44 (CONST_STRPTR) NULL
47 CONST_STRPTR StopBitsLabels[] =
49 (CONST_STRPTR) "1",
50 (CONST_STRPTR) "1.5",
51 (CONST_STRPTR) "2",
52 NULL
55 CONST_STRPTR DataBitsLabels[] =
57 (CONST_STRPTR) "8",
58 (CONST_STRPTR) "7",
59 (CONST_STRPTR) "6",
60 (CONST_STRPTR) "5",
61 NULL
64 CONST_STRPTR BufferSizeLabels[] =
66 (CONST_STRPTR) "512",
67 (CONST_STRPTR) "1024",
68 (CONST_STRPTR) "2048",
69 (CONST_STRPTR) "4096",
70 NULL
73 /*** Instance Data **********************************************************/
75 struct SerEditor_DATA
77 int i;
79 CONST_STRPTR ParityLabels[6];
80 Object *child;
81 Object *baudrate;
82 Object *stopbits;
83 Object *databits;
84 Object *parity;
85 Object *inputbuffersize;
86 Object *outputbuffersize;
89 STATIC VOID SerPrefs2Gadgets(struct SerEditor_DATA *data);
90 STATIC VOID Gadgets2SerPrefs(struct SerEditor_DATA *data);
92 /*** Macros *****************************************************************/
93 #define SETUP_INST_DATA struct SerEditor_DATA *data = INST_DATA(CLASS, self)
95 /*** Methods ****************************************************************/
96 Object *SerEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
98 #if SHOWICON
99 Object *icon;
100 #endif
102 D(bug("[seredit class] SerEdit Class New\n"));
105 * we create self first and then create the child,
106 * so we have self->data available already
109 self = (Object *) DoSuperNewTags
111 CLASS, self, NULL,
112 MUIA_PrefsEditor_Name, _(MSG_WINTITLE),
113 MUIA_PrefsEditor_Path, (IPTR) "SYS/serial.prefs",
114 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/Serial",
116 TAG_DONE
119 if (self)
121 SETUP_INST_DATA;
123 data->ParityLabels[0] = _(MSG_PARITY_NONE);
124 data->ParityLabels[1] = _(MSG_PARITY_EVEN);
125 data->ParityLabels[2] = _(MSG_PARITY_ODD);
126 data->ParityLabels[3] = _(MSG_PARITY_MARK);
127 data->ParityLabels[4] = _(MSG_PARITY_SPACE);
128 data->ParityLabels[5] = NULL;
130 #if SHOWPIC
131 icon = DtpicObject, MUIA_Dtpic_Name, "PROGDIR:Serial.info", End;
133 if (!icon) icon = HVSpace;
134 #endif
136 data->child =
137 #if SHOWPIC
138 HGroup,
139 Child, icon,
140 Child,
141 #endif
143 VGroup,
144 Child, (IPTR)ColGroup(2),
145 Child, (IPTR)Label1(_(MSG_GAD_BAUDRATE)),
146 Child, (IPTR)(data->baudrate = (Object *)CycleObject,
147 MUIA_Cycle_Entries, (IPTR)BaudrateLabels,
148 End),
149 Child, (IPTR)Label1(_(MSG_GAD_DATABITS)),
150 Child, (IPTR)(data->databits = (Object *)CycleObject,
151 MUIA_Cycle_Entries, (IPTR)DataBitsLabels,
152 End),
153 Child, (IPTR)Label1(_(MSG_GAD_PARITY)),
154 Child, (IPTR)(data->parity = (Object *)CycleObject,
155 MUIA_Cycle_Entries, (IPTR)data->ParityLabels,
156 End),
157 Child, (IPTR)Label1(_(MSG_GAD_STOPBITS)),
158 Child, (IPTR)(data->stopbits = (Object *)CycleObject,
159 MUIA_Cycle_Entries, (IPTR)StopBitsLabels,
160 End),
161 Child, (IPTR)Label1(_(MSG_GAD_INPUTBUFFERSIZE)),
162 Child, (IPTR)(data->inputbuffersize = (Object *)CycleObject,
163 MUIA_Cycle_Entries, (IPTR)BufferSizeLabels,
164 End),
165 Child, (IPTR)Label1(_(MSG_GAD_OUTPUTBUFFERSIZE)),
166 Child, (IPTR)(data->outputbuffersize = (Object *)CycleObject,
167 MUIA_Cycle_Entries, (IPTR)BufferSizeLabels,
168 End),
169 End, /* ColGroup */
170 #if SHOWPIC
171 End,
172 #endif
173 End;
175 DoMethod(self, OM_ADDMEMBER, (IPTR) data->child);
177 DoMethod
179 data->baudrate, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
180 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
182 DoMethod
184 data->stopbits, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
185 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
187 DoMethod
189 data->databits, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
190 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
192 DoMethod
193 (data->parity, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
194 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
196 DoMethod
198 data->inputbuffersize, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
199 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
201 DoMethod
203 data->outputbuffersize, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
204 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
207 SerPrefs2Gadgets(data);
210 return self;
214 * update struct serialprefs with actual data selected in gadgets
216 STATIC void Gadgets2SerPrefs (struct SerEditor_DATA *data)
218 D(bug("Gadgets2SerPrefs\n"));
220 serialprefs.sp_BaudRate = atol
222 (char *)BaudrateLabels[XGET(data->baudrate, MUIA_Cycle_Active)]
225 serialprefs.sp_BitsPerChar = XGET(data->databits, MUIA_Cycle_Active);
226 serialprefs.sp_Parity = XGET(data->parity,MUIA_Cycle_Active);
227 serialprefs.sp_StopBits = XGET(data->stopbits,MUIA_Cycle_Active);
229 serialprefs.sp_InputBuffer = atol
231 (char *)BufferSizeLabels[XGET(data->inputbuffersize, MUIA_Cycle_Active)]
233 serialprefs.sp_OutputBuffer = atol
235 (char *)BufferSizeLabels[XGET(data->outputbuffersize, MUIA_Cycle_Active)]
238 D(bug("Gadgets2SerPrefs left\n"));
242 * helper for SerPrefs2Gadgets
244 STATIC VOID RefreshGadget(Object *obj, ULONG value, CONST_STRPTR *labels)
246 ULONG i = 0;
248 while (NULL != labels[i])
250 if (atol((char *) labels[i]) == value)
252 NNSET(obj, MUIA_Cycle_Active, i);
253 return;
255 i++;
257 NNSET(obj, MUIA_Cycle_Active, 0);
261 * update gadgets with values of struct serialprefs
263 STATIC VOID SerPrefs2Gadgets(struct SerEditor_DATA *data)
265 RefreshGadget(data->baudrate, serialprefs.sp_BaudRate, BaudrateLabels);
267 NNSET(data->databits, MUIA_Cycle_Active, serialprefs.sp_BitsPerChar);
268 NNSET(data->parity, MUIA_Cycle_Active, serialprefs.sp_Parity);
269 NNSET(data->stopbits, MUIA_Cycle_Active, serialprefs.sp_StopBits);
271 RefreshGadget(data->inputbuffersize, serialprefs.sp_InputBuffer, BufferSizeLabels);
272 RefreshGadget(data->outputbuffersize, serialprefs.sp_OutputBuffer, BufferSizeLabels);
275 IPTR SerEditor__MUIM_PrefsEditor_ImportFH (
276 Class *CLASS, Object *self,
277 struct MUIP_PrefsEditor_ImportFH *message
280 SETUP_INST_DATA;
281 BOOL success = TRUE;
283 D(bug("[seredit class] SerEdit Class Import\n"));
285 success = Prefs_ImportFH(message->fh);
286 if (success) SerPrefs2Gadgets(data);
288 return success;
291 IPTR SerEditor__MUIM_PrefsEditor_ExportFH
293 Class *CLASS, Object *self,
294 struct MUIP_PrefsEditor_ExportFH *message
297 SETUP_INST_DATA;
298 BOOL success = TRUE;
300 D(bug("[seredit class] SerEdit Class Export\n"));
302 Gadgets2SerPrefs(data);
303 success = Prefs_ExportFH(message->fh);
305 return success;
308 IPTR SerEditor__MUIM_PrefsEditor_SetDefaults
310 Class *CLASS, Object *self, Msg message
313 SETUP_INST_DATA;
314 BOOL success = TRUE;
316 D(bug("[seredit class] SerEdit Class SetDefaults\n"));
318 success = Prefs_Default();
319 if (success) SerPrefs2Gadgets(data);
321 return success;
324 /*** Setup ******************************************************************/
325 ZUNE_CUSTOMCLASS_4
327 SerEditor, NULL, MUIC_PrefsEditor, NULL,
328 OM_NEW, struct opSet *,
329 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
330 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
331 MUIM_PrefsEditor_SetDefaults, Msg