[OSK] Implement standard/enhanced keyboard handler (#1338)
[reactos.git] / base / applications / osk / settings.c
1 /*
2 * PROJECT: ReactOS On-Screen Keyboard
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Settings file for warning dialog on startup
5 * COPYRIGHT: Copyright 2018 Bișoc George (fraizeraust99 at gmail dot com)
6 */
7
8 /* INCLUDES *******************************************************************/
9
10 #include "osk.h"
11 #include "settings.h"
12
13 /* FUNCTIONS *******************************************************************/
14
15 BOOL LoadDataFromRegistry()
16 {
17 HKEY hKey;
18 LONG lResult;
19 DWORD dwShowWarningData, dwLayout;
20 DWORD cbData = sizeof(DWORD);
21
22 /* Set the structure members to TRUE */
23 Globals.bShowWarning = TRUE;
24 Globals.bIsEnhancedKeyboard = TRUE;
25
26 /* Open the key, so that we can query it */
27 lResult = RegOpenKeyExW(HKEY_CURRENT_USER,
28 L"Software\\Microsoft\\osk",
29 0,
30 KEY_READ,
31 &hKey);
32
33 if (lResult != ERROR_SUCCESS)
34 {
35 /* Bail out and return FALSE if we fail */
36 return FALSE;
37 }
38
39 /* Query the key */
40 lResult = RegQueryValueExW(hKey,
41 L"ShowWarning",
42 0,
43 0,
44 (BYTE *)&dwShowWarningData,
45 &cbData);
46
47 if (lResult != ERROR_SUCCESS)
48 {
49 /* Bail out and return FALSE if we fail */
50 RegCloseKey(hKey);
51 return FALSE;
52 }
53
54 /* Load the data value (it can be either FALSE or TRUE depending on the data itself) */
55 Globals.bShowWarning = (dwShowWarningData != 0);
56
57 /* Query the key */
58 lResult = RegQueryValueExW(hKey,
59 L"IsEnhancedKeyboard",
60 0,
61 0,
62 (BYTE *)&dwLayout,
63 &cbData);
64
65 if (lResult != ERROR_SUCCESS)
66 {
67 /* Bail out and return FALSE if we fail */
68 RegCloseKey(hKey);
69 return FALSE;
70 }
71
72 /* Load the dialog layout value */
73 Globals.bIsEnhancedKeyboard = (dwLayout != 0);
74
75 /* If we're here then we succeed, close the key and return TRUE */
76 RegCloseKey(hKey);
77 return TRUE;
78 }
79
80 BOOL SaveDataToRegistry()
81 {
82 HKEY hKey;
83 LONG lResult;
84 DWORD dwShowWarningData, dwLayout;
85
86 /* If no key has been made, create one */
87 lResult = RegCreateKeyExW(HKEY_CURRENT_USER,
88 L"Software\\Microsoft\\osk",
89 0,
90 NULL,
91 0,
92 KEY_WRITE,
93 NULL,
94 &hKey,
95 NULL);
96
97 if (lResult != ERROR_SUCCESS)
98 {
99 /* Bail out and return FALSE if we fail */
100 return FALSE;
101 }
102
103 /* The data value of the subkey will be appended to the warning dialog switch */
104 dwShowWarningData = Globals.bShowWarning;
105
106 lResult = RegSetValueExW(hKey,
107 L"ShowWarning",
108 0,
109 REG_DWORD,
110 (BYTE *)&dwShowWarningData,
111 sizeof(dwShowWarningData));
112
113 if (lResult != ERROR_SUCCESS)
114 {
115 /* Bail out and return FALSE if we fail */
116 RegCloseKey(hKey);
117 return FALSE;
118 }
119
120 /* The value will be appended to the layout dialog */
121 dwLayout = Globals.bIsEnhancedKeyboard;
122
123 lResult = RegSetValueExW(hKey,
124 L"IsEnhancedKeyboard",
125 0,
126 REG_DWORD,
127 (BYTE *)&dwLayout,
128 sizeof(dwLayout));
129
130 if (lResult != ERROR_SUCCESS)
131 {
132 /* Bail out and return FALSE if we fail */
133 RegCloseKey(hKey);
134 return FALSE;
135 }
136
137 /* If we're here then we succeed, close the key and return TRUE */
138 RegCloseKey(hKey);
139 return TRUE;
140 }