2 Copyright 2003-2004, The AROS Development Team. All rights reserved.
3 $Id: ipeditor.c 21816 2007-09-25 12:35:29Z chodorowski, dariusb $
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>
28 #include <aros/debug.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 **********************************************************/
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
)
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
102 MUIA_PrefsEditor_Name
, __(MSG_NAME
),
103 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/Input.prefs",
105 Child
, (IPTR
) RegisterGroup(InputTabs
),
109 GroupFrameT(__(MSG_GAD_KEY_TYPE
)),
111 Child
, ListviewObject
,
112 MUIA_Listview_Input
, FALSE
,
113 MUIA_Listview_List
, keyTypes
= ListObject
,
115 MUIA_List_DisplayHook
, &display_hook
,
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,
127 MUIA_Numeric_Max
, 12,
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,
136 MUIA_Numeric_Max
, 74,
140 GroupFrameT(__(MSG_GAD_KEY_TEST
)),
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
),
166 GroupFrameT(__(MSG_GAD_MOUSE_SPEED
)),
167 Child
, GadMouseSpeed
= MUI_MakeObject(MUIO_Cycle
, NULL
, MouseSpeed
),
169 Child
, Label1(__(MSG_GAD_MOUSE_ACCELERATED
)),
170 Child
, Accelerated
= MUI_MakeObject(MUIO_Checkmark
, NULL
),
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,
178 MUIA_Numeric_Max
, 199,
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
;
202 ForeachNode(&keymap_list
, entry
)
204 root
= DoMethod(keyTypes
,
205 MUIM_List_InsertSingle
,
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
);
229 BOOL Gadgets2InputPrefs
231 struct IPEditor_DATA
*data
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
,
274 MUIV_List_GetEntry_Active
,
279 D(bug("IPrefs: selected %s\n", entry
->realname
));
280 strncpy(inputprefs
.ip_Keymap
, entry
->realname
, sizeof(inputprefs
.ip_Keymap
));
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
;
303 ForeachNode(&keymap_list
, entry
)
305 if (!stricmp(inputprefs
.ip_Keymap
, entry
->realname
))
307 NNSET(data
->iped_KeyTypes
, MUIA_List_Active
, pos
);
316 switch(inputprefs
.ip_PointerTicks
)
333 NNSET(data
->iped_MouseSpeed
, MUIA_Cycle_Active
, active
);
338 IPTR IPEditor__MUIM_PrefsEditor_ImportFH
340 Class
*CLASS
, Object
*self
,
341 struct MUIP_PrefsEditor_ImportFH
*message
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
);
357 IPTR IPEditor__MUIM_PrefsEditor_ExportFH
359 Class
*CLASS
, Object
*self
,
360 struct MUIP_PrefsEditor_ExportFH
*message
364 struct PrefHeader header
;
365 struct IFFHandle
*handle
;
369 if (Gadgets2InputPrefs(data
))
371 return SavePrefs(message
->fh
);
376 IPTR IPEditor__MUIM_PrefsEditor_Test
378 Class
*CLASS
, Object
*self
, Msg message
384 Gadgets2InputPrefs(data
);
387 try_setting_mousespeed();
388 try_setting_test_keymap();
389 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
390 SET(self
, MUIA_PrefsEditor_Testing
, TRUE
);
395 IPTR IPEditor__MUIM_PrefsEditor_Revert
397 Class
*CLASS
, Object
*self
, Msg message
403 CopyPrefs(&restore_prefs
, &inputprefs
);
405 InputPrefs2Gadgets(data
);
408 try_setting_mousespeed();
409 try_setting_test_keymap();
410 SET(self
, MUIA_PrefsEditor_Changed
, FALSE
);
411 SET(self
, MUIA_PrefsEditor_Testing
, FALSE
);
416 /*** Setup ******************************************************************/
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