[MAGNIFY] Minor whitespace / formatting fixes; use the new file headers + some code...
[reactos.git] / base / applications / magnify / settings.c
1 /*
2 * PROJECT: ReactOS Magnify
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Magnification of parts of the screen.
5 * COPYRIGHT: Copyright 2007-2019 Marc Piulachs <marc.piulachs@codexchange.net>
6 * Copyright 2015-2019 David Quintana <gigaherz@gmail.com>
7 */
8
9 #include "magnifier.h"
10
11 #include <tchar.h>
12 #include <winreg.h>
13
14 UINT uiZoom = 3;
15
16 BOOL bShowWarning = TRUE;
17
18 BOOL bFollowMouse = TRUE;
19 BOOL bFollowFocus = TRUE;
20 BOOL bFollowCaret = TRUE;
21
22 BOOL bInvertColors = FALSE;
23 BOOL bStartMinimized = FALSE;
24 BOOL bShowMagnifier = TRUE;
25
26 struct _AppBarConfig_t AppBarConfig =
27 {
28 sizeof(struct _AppBarConfig_t),
29 -2 /* ABE_TOP */,
30 0, 1, /* unknown */
31 { 101,101,101,101 }, /* edge sizes */
32 { 20, 20, 600, 200 }, /* floating window rect */
33 };
34
35 void LoadSettings(void)
36 {
37 HKEY hkey;
38 LONG value;
39 ULONG len;
40 struct _AppBarConfig_t config_temp;
41
42 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Magnify"), 0, KEY_READ, &hkey) != ERROR_SUCCESS)
43 return;
44
45 len = sizeof(AppBarConfig);
46 if (RegQueryValueEx(hkey, _T("AppBar"), 0, 0, (BYTE *)&config_temp, &len) == ERROR_SUCCESS)
47 {
48 if(config_temp.cbSize == sizeof(AppBarConfig))
49 {
50 AppBarConfig = config_temp;
51 }
52 }
53
54 len = sizeof(value);
55 if (RegQueryValueEx(hkey, _T("StationaryMagLevel"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
56 {
57 if (value >= 0 && value <= 9)
58 uiZoom = value;
59 }
60
61 len = sizeof(value);
62 if (RegQueryValueEx(hkey, _T("ShowWarning"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
63 bShowWarning = !!value;
64
65 len = sizeof(value);
66 if (RegQueryValueEx(hkey, _T("StationaryInvertColors"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
67 bInvertColors = !!value;
68
69 len = sizeof(value);
70 if (RegQueryValueEx(hkey, _T("StationaryStartMinimized"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
71 bStartMinimized = !!value;
72
73 len = sizeof(value);
74 if (RegQueryValueEx(hkey, _T("StationaryTrackCursor"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
75 bFollowMouse = !!value;
76
77 len = sizeof(value);
78 if (RegQueryValueEx(hkey, _T("StationaryTrackFocus"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
79 bFollowFocus = !!value;
80
81 len = sizeof(value);
82 if (RegQueryValueEx(hkey, _T("StationaryTrackSecondaryFocus"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
83 bFollowFocus = !!value;
84
85 len = sizeof(value);
86 if (RegQueryValueEx(hkey, _T("StationaryTrackText"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
87 bFollowCaret = !!value;
88
89 RegCloseKey(hkey);
90 }
91
92 void SaveSettings(void)
93 {
94 HKEY hkey;
95 LONG value;
96
97 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Magnify"), 0, _T(""), 0, KEY_WRITE, NULL, &hkey, NULL) != ERROR_SUCCESS)
98 return;
99
100 RegSetValueEx(hkey, _T("AppBar"), 0, REG_BINARY, (BYTE *)&AppBarConfig, sizeof(AppBarConfig));
101
102 value = uiZoom;
103 RegSetValueEx(hkey, _T("StationaryMagLevel"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
104
105 value = bShowWarning;
106 RegSetValueEx(hkey, _T("ShowWarning"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
107
108 value = bInvertColors;
109 RegSetValueEx(hkey, _T("StationaryInvertColors"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
110
111 value = bStartMinimized;
112 RegSetValueEx(hkey, _T("StationaryStartMinimized"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
113
114 value = bFollowMouse;
115 RegSetValueEx(hkey, _T("StationaryTrackCursor"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
116
117 value = bFollowFocus;
118 RegSetValueEx(hkey, _T("StationaryTrackFocus"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
119
120 value = bFollowFocus;
121 RegSetValueEx(hkey, _T("StationaryTrackSecondaryFocus"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
122
123 value = bFollowCaret;
124 RegSetValueEx(hkey, _T("StationaryTrackText"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
125
126 RegCloseKey(hkey);
127 }