added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / prefs / input / ipeditor.c
blobc88d1096c42edaa1a8c1ea73a7ca4bc8aef7785d
1 /*
2 Copyright 2003-2004, The AROS Development Team. All rights reserved.
3 $Id: ipeditor.c 21816 2007-09-25 12:35:29Z chodorowski, dariusb $
4 */
6 // #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/asl.h>
11 #include <libraries/mui.h>
12 #include <prefs/prefhdr.h>
13 #include <prefs/input.h>
14 #include <zune/customclasses.h>
15 #include <zune/prefseditor.h>
17 #include <proto/exec.h>
18 #include <proto/intuition.h>
19 #include <proto/utility.h>
20 #include <proto/muimaster.h>
21 #include <proto/dos.h>
22 #include <proto/iffparse.h>
24 #include <string.h>
25 #include <stdio.h>
27 #define DEBUG 0
28 #include <aros/debug.h>
30 #include "misc.h"
31 #include "locale.h"
32 #include "ipeditor.h"
33 #include "prefs.h"
35 extern struct List keymap_list;
36 extern struct InputPrefs inputprefs;
37 extern struct InputPrefs restore_prefs;
39 extern struct MUI_CustomClass *StringifyClass;
41 static STRPTR InputTabs[] = {NULL, NULL, NULL, };
42 static STRPTR ButtonMappings[] = {NULL, NULL, NULL, NULL, };
43 static STRPTR MouseSpeed[] = {NULL, NULL, NULL, NULL, };
45 /*** Instance Data **********************************************************/
47 struct IPEditor_DATA
49 struct InputPrefs iped_InputPrefs;
50 Object *iped_KeyTypes;
51 Object *iped_RepeatRate;
52 Object *iped_RepeatDelay;
53 Object *iped_Accelerated;
54 Object *iped_MouseSpeed;
55 Object *iped_DoubleClickDelay;
58 BOOL InputPrefs2Gadgets(struct IPEditor_DATA *data);
60 /*** Macros *****************************************************************/
61 #define SETUP_INST_DATA struct IPEditor_DATA *data = INST_DATA(CLASS, self)
63 /****************************************************************
64 The display function for the KeyTypes listview
65 *****************************************************************/
66 static void keytypes_display_func(struct Hook *h, char **array, struct ListviewEntry * entry)
68 *array++ = entry->displayname;
71 /*** Methods ****************************************************************/
72 Object *IPEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
74 Object *keyTypes;
75 Object *RepeatRate;
76 Object *RepeatDelay;
77 Object *Accelerated;
78 Object *GadMouseSpeed;
79 Object *DoubleClickDelay;
81 struct ListviewEntry *entry;
82 static struct Hook display_hook;
84 display_hook.h_Entry = HookEntry;
85 display_hook.h_SubEntry = (HOOKFUNC)keytypes_display_func;
87 InputTabs[0] = __(MSG_GAD_TAB_KEYBOARD);
88 InputTabs[1] = __(MSG_GAD_TAB_MOUSE);
90 ButtonMappings[0] = __(MSG_GAD_MOUSE_MAPPING_SELECT);
91 ButtonMappings[1] = __(MSG_GAD_MOUSE_MAPPING_MENU);
92 ButtonMappings[2] = __(MSG_GAD_MOUSE_MAPPING_THIRD);
94 MouseSpeed[0] = __(MSG_GAD_MOUSE_SPEED_SLOW);
95 MouseSpeed[1] = __(MSG_GAD_MOUSE_SPEED_NORMAL);
96 MouseSpeed[2] = __(MSG_GAD_MOUSE_SPEED_FAST);
98 self = (Object *) DoSuperNewTags
100 CLASS, self, NULL,
102 MUIA_PrefsEditor_Name, __(MSG_NAME),
103 MUIA_PrefsEditor_Path, (IPTR) "SYS/Input.prefs",
105 Child, (IPTR) RegisterGroup(InputTabs),
106 Child, VGroup,
107 Child, HGroup,
108 Child, VGroup,
109 GroupFrameT(__(MSG_GAD_KEY_TYPE)),
110 MUIA_Weight, 45,
111 Child, ListviewObject,
112 MUIA_Listview_Input, FALSE,
113 MUIA_Listview_List, keyTypes = ListObject,
114 InputListFrame,
115 MUIA_List_DisplayHook, &display_hook,
116 End,
117 End,
118 End,
119 Child, VGroup,
120 MUIA_Weight, 55,
121 Child, HGroup,
122 GroupFrameT(__(MSG_GAD_KEY_REPEAT_RATE)),
123 Child, RepeatRate = NewObject(StringifyClass->mcc_Class,0,
124 MUIA_MyStringifyType, STRINGIFY_RepeatRate,
125 MUIA_Numeric_Value, 0,
126 MUIA_Numeric_Min, 0,
127 MUIA_Numeric_Max, 12,
128 TAG_DONE),
129 End,
130 Child, HGroup,
131 GroupFrameT(__(MSG_GAD_KEY_REPEAT_DELAY)),
132 Child, RepeatDelay = NewObject(StringifyClass->mcc_Class,0,
133 MUIA_MyStringifyType, STRINGIFY_RepeatDelay,
134 MUIA_Numeric_Value, 0,
135 MUIA_Numeric_Min, 0,
136 MUIA_Numeric_Max, 74,
137 TAG_DONE),
138 End,
139 Child, VGroup,
140 GroupFrameT(__(MSG_GAD_KEY_TEST)),
141 Child, HVSpace,
142 Child, StringObject,
143 StringFrame,
144 End,
145 Child, HVSpace,
146 End,
147 End,
148 End,
149 End,
150 Child, VGroup,
151 Child, HGroup,
152 Child, VGroup,
153 Child, ColGroup(2),
154 GroupFrameT(__(MSG_GAD_MOUSE_BUTTON_MAPPING)),
155 Child, Label1(__(MSG_GAD_MOUSE_LEFT)),
156 Child, MUI_MakeObject(MUIO_Cycle, NULL, ButtonMappings),
157 Child, Label1(__(MSG_GAD_MOUSE_MIDDLE)),
158 Child, MUI_MakeObject(MUIO_Cycle, NULL, ButtonMappings),
159 Child, Label1(__(MSG_GAD_MOUSE_RIGHT)),
160 Child, MUI_MakeObject(MUIO_Cycle, NULL, ButtonMappings),
161 End,
162 Child, HVSpace,
163 End,
164 Child, VGroup,
165 Child, ColGroup(2),
166 GroupFrameT(__(MSG_GAD_MOUSE_SPEED)),
167 Child, GadMouseSpeed = MUI_MakeObject(MUIO_Cycle, NULL, MouseSpeed),
168 Child, HVSpace,
169 Child, Label1(__(MSG_GAD_MOUSE_ACCELERATED)),
170 Child, Accelerated = MUI_MakeObject(MUIO_Checkmark, NULL),
171 End,
172 Child, HGroup,
173 GroupFrameT(__(MSG_GAD_MOUSE_DOUBLE_CLICK_DELAY)),
174 Child, DoubleClickDelay = NewObject(StringifyClass->mcc_Class,0,
175 MUIA_MyStringifyType, STRINGIFY_DoubleClickDelay,
176 MUIA_Numeric_Value, 0,
177 MUIA_Numeric_Min, 0,
178 MUIA_Numeric_Max, 199,
179 TAG_DONE),
180 End,
181 End,
182 End,
183 End,
184 End,
186 TAG_DONE
189 if (self != NULL)
191 SETUP_INST_DATA;
193 data->iped_RepeatRate = RepeatRate;
194 data->iped_RepeatDelay = RepeatDelay;
195 data->iped_KeyTypes = keyTypes;
196 data->iped_Accelerated = Accelerated;
197 data->iped_MouseSpeed = GadMouseSpeed;
198 data->iped_DoubleClickDelay = DoubleClickDelay;
200 IPTR root;
202 ForeachNode(&keymap_list, entry)
204 root = DoMethod(keyTypes,
205 MUIM_List_InsertSingle,
206 (IPTR)entry,
207 MUIV_List_Insert_Bottom);
210 /* Set default Values */
212 InputPrefs2Gadgets(data);
214 DoMethod(RepeatRate, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
215 DoMethod(RepeatDelay, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
216 DoMethod(DoubleClickDelay, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
218 DoMethod(GadMouseSpeed, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
220 DoMethod(keyTypes, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
222 DoMethod(Accelerated, MUIM_Notify, MUIA_Selected, MUIV_EveryTime, (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE);
226 return self;
229 BOOL Gadgets2InputPrefs
231 struct IPEditor_DATA *data
234 IPTR val;
235 ULONG micros, secs;
237 GET(data->iped_RepeatRate, MUIA_Numeric_Value, &val);
239 micros = (12 - val) * 20000;
241 inputprefs.ip_KeyRptSpeed.tv_micro = micros;
242 inputprefs.ip_KeyRptSpeed.tv_secs = 0;
244 GET(data->iped_RepeatDelay, MUIA_Numeric_Value, &val);
246 micros = 20000 + val * 20000;
247 secs = (int) (micros / 1000000);
248 micros = micros % 1000000;
250 inputprefs.ip_KeyRptDelay.tv_micro = micros;
251 inputprefs.ip_KeyRptDelay.tv_secs = secs;
253 GET(data->iped_DoubleClickDelay, MUIA_Numeric_Value, &val);
255 micros = 20000 + val * 20000;
256 secs = (int) (micros / 1000000);
257 micros = micros % 1000000;
259 inputprefs.ip_DoubleClick.tv_micro = micros;
260 inputprefs.ip_DoubleClick.tv_secs = secs;
262 GET(data->iped_Accelerated, MUIA_Selected, &val);
264 if (val != 0) inputprefs.ip_MouseAccel = ~0; else inputprefs.ip_MouseAccel = 0;
266 GET(data->iped_MouseSpeed, MUIA_Cycle_Active, &val);
268 inputprefs.ip_PointerTicks = 1 << (2 - val);
270 struct ListviewEntry *entry;
272 DoMethod(data->iped_KeyTypes,
273 MUIM_List_GetEntry,
274 MUIV_List_GetEntry_Active,
275 &entry);
277 if (entry != NULL)
279 D(bug("IPrefs: selected %s\n", entry->realname));
280 strncpy(inputprefs.ip_Keymap, entry->realname, sizeof(inputprefs.ip_Keymap));
283 return TRUE;
286 BOOL InputPrefs2Gadgets
288 struct IPEditor_DATA *data
291 ULONG rrate = 12 -(inputprefs.ip_KeyRptSpeed.tv_micro / 20000);
292 ULONG rdelay = ((inputprefs.ip_KeyRptDelay.tv_micro + (inputprefs.ip_KeyRptDelay.tv_secs * 1000000)) / 20000) - 1;
293 ULONG dcdelay = ((inputprefs.ip_DoubleClick.tv_micro + (inputprefs.ip_DoubleClick.tv_secs * 1000000)) / 20000) - 1;
295 NNSET(data->iped_RepeatRate, MUIA_Numeric_Value, (IPTR) rrate);
296 NNSET(data->iped_RepeatDelay, MUIA_Numeric_Value, (IPTR) rdelay);
297 NNSET(data->iped_DoubleClickDelay, MUIA_Numeric_Value, (IPTR) dcdelay);
298 NNSET(data->iped_Accelerated, MUIA_Selected, (IPTR) (inputprefs.ip_MouseAccel != 0) ? TRUE : FALSE);
300 struct ListviewEntry *entry;
301 LONG pos = 0;
303 ForeachNode(&keymap_list, entry)
305 if (!stricmp(inputprefs.ip_Keymap, entry->realname))
307 NNSET(data->iped_KeyTypes, MUIA_List_Active, pos);
308 break;
311 ++pos;
314 IPTR active = 0;
316 switch(inputprefs.ip_PointerTicks)
318 case 3:
319 case 4:
320 active = 0;
321 break;
323 case 2:
324 active = 1;
325 break;
327 case 1:
328 default:
329 active = 2;
330 break;
333 NNSET(data->iped_MouseSpeed, MUIA_Cycle_Active, active);
335 return TRUE;
338 IPTR IPEditor__MUIM_PrefsEditor_ImportFH
340 Class *CLASS, Object *self,
341 struct MUIP_PrefsEditor_ImportFH *message
344 SETUP_INST_DATA;
346 if (LoadPrefs(message->fh))
348 CopyPrefs(&inputprefs, &restore_prefs);
349 IPTR back = InputPrefs2Gadgets(data);
350 SET(self, MUIA_PrefsEditor_Changed, FALSE);
351 SET(self, MUIA_PrefsEditor_Testing, FALSE);
352 return back;
354 return FALSE;
357 IPTR IPEditor__MUIM_PrefsEditor_ExportFH
359 Class *CLASS, Object *self,
360 struct MUIP_PrefsEditor_ExportFH *message
363 SETUP_INST_DATA;
364 struct PrefHeader header;
365 struct IFFHandle *handle;
366 BOOL success = TRUE;
367 LONG error = 0;
369 if (Gadgets2InputPrefs(data))
371 return SavePrefs(message->fh);
373 return FALSE;
376 IPTR IPEditor__MUIM_PrefsEditor_Test
378 Class *CLASS, Object *self, Msg message
382 SETUP_INST_DATA;
384 Gadgets2InputPrefs(data);
386 update_inputdev();
387 try_setting_mousespeed();
388 try_setting_test_keymap();
389 SET(self, MUIA_PrefsEditor_Changed, FALSE);
390 SET(self, MUIA_PrefsEditor_Testing, TRUE);
392 return TRUE;
395 IPTR IPEditor__MUIM_PrefsEditor_Revert
397 Class *CLASS, Object *self, Msg message
401 SETUP_INST_DATA;
403 CopyPrefs(&restore_prefs, &inputprefs);
405 InputPrefs2Gadgets(data);
407 update_inputdev();
408 try_setting_mousespeed();
409 try_setting_test_keymap();
410 SET(self, MUIA_PrefsEditor_Changed, FALSE);
411 SET(self, MUIA_PrefsEditor_Testing, FALSE);
413 return TRUE;
416 /*** Setup ******************************************************************/
417 ZUNE_CUSTOMCLASS_5
419 IPEditor, NULL, MUIC_PrefsEditor, NULL,
420 OM_NEW, struct opSet *,
421 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
422 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
423 MUIM_PrefsEditor_Test, Msg,
424 MUIM_PrefsEditor_Revert, Msg