2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
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>
18 #include <aros/debug.h>
21 #include "sereditor.h"
24 /*** String Data ************************************************************/
26 CONST_STRPTR BaudrateLabels
[] =
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",
47 CONST_STRPTR StopBitsLabels
[] =
55 CONST_STRPTR DataBitsLabels
[] =
64 CONST_STRPTR BufferSizeLabels
[] =
67 (CONST_STRPTR
) "1024",
68 (CONST_STRPTR
) "2048",
69 (CONST_STRPTR
) "4096",
73 /*** Instance Data **********************************************************/
79 CONST_STRPTR ParityLabels
[6];
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
)
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
112 MUIA_PrefsEditor_Name
, _(MSG_WINTITLE
),
113 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/serial.prefs",
114 MUIA_PrefsEditor_IconTool
, (IPTR
) "SYS:Prefs/Serial",
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
;
131 icon
= DtpicObject
, MUIA_Dtpic_Name
, "PROGDIR:Serial.info", End
;
133 if (!icon
) icon
= HVSpace
;
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
,
149 Child
, (IPTR
)Label1(_(MSG_GAD_DATABITS
)),
150 Child
, (IPTR
)(data
->databits
= (Object
*)CycleObject
,
151 MUIA_Cycle_Entries
, (IPTR
)DataBitsLabels
,
153 Child
, (IPTR
)Label1(_(MSG_GAD_PARITY
)),
154 Child
, (IPTR
)(data
->parity
= (Object
*)CycleObject
,
155 MUIA_Cycle_Entries
, (IPTR
)data
->ParityLabels
,
157 Child
, (IPTR
)Label1(_(MSG_GAD_STOPBITS
)),
158 Child
, (IPTR
)(data
->stopbits
= (Object
*)CycleObject
,
159 MUIA_Cycle_Entries
, (IPTR
)StopBitsLabels
,
161 Child
, (IPTR
)Label1(_(MSG_GAD_INPUTBUFFERSIZE
)),
162 Child
, (IPTR
)(data
->inputbuffersize
= (Object
*)CycleObject
,
163 MUIA_Cycle_Entries
, (IPTR
)BufferSizeLabels
,
165 Child
, (IPTR
)Label1(_(MSG_GAD_OUTPUTBUFFERSIZE
)),
166 Child
, (IPTR
)(data
->outputbuffersize
= (Object
*)CycleObject
,
167 MUIA_Cycle_Entries
, (IPTR
)BufferSizeLabels
,
175 DoMethod(self
, OM_ADDMEMBER
, (IPTR
) data
->child
);
179 data
->baudrate
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
180 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
184 data
->stopbits
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
185 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
189 data
->databits
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
190 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
193 (data
->parity
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
194 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
198 data
->inputbuffersize
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
199 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
203 data
->outputbuffersize
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
204 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
207 SerPrefs2Gadgets(data
);
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
)
248 while (NULL
!= labels
[i
])
250 if (atol((char *) labels
[i
]) == value
)
252 NNSET(obj
, MUIA_Cycle_Active
, 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
283 D(bug("[seredit class] SerEdit Class Import\n"));
285 success
= Prefs_ImportFH(message
->fh
);
286 if (success
) SerPrefs2Gadgets(data
);
291 IPTR SerEditor__MUIM_PrefsEditor_ExportFH
293 Class
*CLASS
, Object
*self
,
294 struct MUIP_PrefsEditor_ExportFH
*message
300 D(bug("[seredit class] SerEdit Class Export\n"));
302 Gadgets2SerPrefs(data
);
303 success
= Prefs_ExportFH(message
->fh
);
308 IPTR SerEditor__MUIM_PrefsEditor_SetDefaults
310 Class
*CLASS
, Object
*self
, Msg message
316 D(bug("[seredit class] SerEdit Class SetDefaults\n"));
318 success
= Prefs_Default();
319 if (success
) SerPrefs2Gadgets(data
);
324 /*** Setup ******************************************************************/
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