ReactOS 0.4.16-dev-257-g6aa11ac
settings.c File Reference
#include "notepad.h"
#include <winreg.h>
Include dependency graph for settings.c:

Go to the source code of this file.

Functions

static LONG HeightFromPointSize (DWORD dwPointSize)
 
static DWORD PointSizeFromHeight (LONG lHeight)
 
static BOOL QueryGeneric (HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, LPVOID pvResult, DWORD dwResultSize)
 
static BOOL QueryDword (HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
 
static BOOL QueryByte (HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult)
 
static BOOL QueryBool (HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
 
static BOOL QueryString (HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultLength)
 
void NOTEPAD_LoadSettingsFromRegistry (PWINDOWPLACEMENT pWP)
 
static BOOL SaveDword (HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
 
static BOOL SaveString (HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
 
void NOTEPAD_SaveSettingsToRegistry (void)
 

Variables

static LPCTSTR s_szRegistryKey = _T("Software\\Microsoft\\Notepad")
 

Function Documentation

◆ HeightFromPointSize()

static LONG HeightFromPointSize ( DWORD  dwPointSize)
static

Definition at line 17 of file settings.c.

18{
19 LONG lHeight;
20 HDC hDC;
21
22 hDC = GetDC(NULL);
23 lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720);
25
26 return lHeight;
27}
static HDC hDC
Definition: 3dtext.c:33
#define NULL
Definition: types.h:112
static HDC
Definition: imagelist.c:88
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
long LONG
Definition: pedump.c:60
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
#define LOGPIXELSY
Definition: wingdi.h:719
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)

Referenced by NOTEPAD_LoadSettingsFromRegistry().

◆ NOTEPAD_LoadSettingsFromRegistry()

void NOTEPAD_LoadSettingsFromRegistry ( PWINDOWPLACEMENT  pWP)

Definition at line 105 of file settings.c.

106{
107 HKEY hKey;
108 HFONT hFont;
109 DWORD dwPointSize;
110 DWORD x = CW_USEDEFAULT, y = CW_USEDEFAULT, cx = 0, cy = 0;
111
112 /* Set the default values */
113 Globals.bShowStatusBar = TRUE;
114 Globals.bWrapLongLines = FALSE;
115 SetRect(&Globals.lMargins, 750, 1000, 750, 1000);
116 ZeroMemory(&Globals.lfFont, sizeof(Globals.lfFont));
117 Globals.lfFont.lfCharSet = DEFAULT_CHARSET;
118 dwPointSize = 100;
119 Globals.lfFont.lfWeight = FW_NORMAL;
120 Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
121
122 /* FIXME: Globals.fSaveWindowPositions = FALSE; */
123 /* FIXME: Globals.fMLE_is_broken = FALSE; */
124
125 /* Open the target registry key */
127 hKey = NULL;
128
129 /* Load the values from registry */
130 if (hKey)
131 {
132 QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet);
133 QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision);
134 QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement);
135 QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic);
136 QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation);
137 QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision);
138 QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
139 QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality);
140 QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut);
141 QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline);
142 QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight);
143 QueryDword(hKey, _T("iPointSize"), &dwPointSize);
144
145 QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
146 QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
147
148 QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left);
149 QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top);
150 QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
151 QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
152
153 QueryDword(hKey, _T("iWindowPosX"), &x);
154 QueryDword(hKey, _T("iWindowPosY"), &y);
155 QueryDword(hKey, _T("iWindowPosDX"), &cx);
156 QueryDword(hKey, _T("iWindowPosDY"), &cy);
157
158 QueryString(hKey, _T("searchString"), Globals.szFindText, _countof(Globals.szFindText));
159 QueryString(hKey, _T("replaceString"), Globals.szReplaceText, _countof(Globals.szReplaceText));
160 }
161
162 pWP->length = sizeof(*pWP);
163 pWP->flags = 0;
164 pWP->showCmd = SW_SHOWDEFAULT;
165 if (cy & 0x80000000)
166 {
167 cy &= ~0x80000000;
170 }
171 pWP->rcNormalPosition.left = x;
172 pWP->rcNormalPosition.right = x + cx;
173 pWP->rcNormalPosition.top = y;
174 pWP->rcNormalPosition.bottom = y + cy;
175 pWP->ptMaxPosition.x = x;
176 pWP->ptMaxPosition.y = y;
177
178 Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
179 if (!hKey || !QueryString(hKey, _T("lfFaceName"),
180 Globals.lfFont.lfFaceName, _countof(Globals.lfFont.lfFaceName)))
181 {
183 _countof(Globals.lfFont.lfFaceName));
184 }
185
186 if (!hKey || !QueryString(hKey, _T("szHeader"), Globals.szHeader, _countof(Globals.szHeader)))
187 {
189 _countof(Globals.szHeader));
190 }
191
192 if (!hKey || !QueryString(hKey, _T("szTrailer"), Globals.szFooter, _countof(Globals.szFooter)))
193 {
195 _countof(Globals.szFooter));
196 }
197
198 if (hKey)
200
201 /* WORKAROUND: Far East Asian users may not have suitable fixed-pitch fonts. */
203 {
204 case LANG_CHINESE:
205 case LANG_JAPANESE:
206 case LANG_KOREAN:
207 Globals.lfFont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
208 break;
209 }
210
213 if (hFont)
214 {
215 if (Globals.hFont)
216 DeleteObject(Globals.hFont);
217 Globals.hFont = hFont;
218 }
219}
static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult)
Definition: settings.c:70
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
Definition: settings.c:81
static LPCTSTR s_szRegistryKey
Definition: settings.c:14
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultLength)
Definition: settings.c:90
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
Definition: settings.c:65
static LONG HeightFromPointSize(DWORD dwPointSize)
Definition: settings.c:17
HFONT hFont
Definition: main.c:53
#define RegCloseKey(hKey)
Definition: registry.h:49
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LANGID WINAPI GetUserDefaultLangID(void)
Definition: locale.c:1177
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define STRING_PAGESETUP_FOOTERVALUE
Definition: notepad_res.h:61
#define STRING_DEFAULTFONT
Definition: notepad_res.h:91
#define STRING_PAGESETUP_HEADERVALUE
Definition: notepad_res.h:60
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
_Out_opt_ int * cx
Definition: commctrl.h:585
#define LANG_CHINESE
Definition: nls.h:42
#define LANG_JAPANESE
Definition: nls.h:76
#define PRIMARYLANGID(l)
Definition: nls.h:16
#define LANG_KOREAN
Definition: nls.h:84
#define _countof(array)
Definition: sndvol32.h:70
HINSTANCE hInstance
Definition: precomp.h:43
POINT ptMaxPosition
Definition: winuser.h:3297
RECT rcNormalPosition
Definition: winuser.h:3298
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define _T(x)
Definition: vfdio.h:22
#define ZeroMemory
Definition: winbase.h:1737
UINT_PTR WPARAM
Definition: windef.h:207
#define FIXED_PITCH
Definition: wingdi.h:444
#define DEFAULT_PITCH
Definition: wingdi.h:443
#define FF_MODERN
Definition: wingdi.h:449
#define FF_DONTCARE
Definition: wingdi.h:448
#define DEFAULT_CHARSET
Definition: wingdi.h:384
#define FW_NORMAL
Definition: wingdi.h:373
#define CreateFontIndirect
Definition: wingdi.h:4444
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKey
Definition: winreg.h:519
#define SW_SHOWMAXIMIZED
Definition: winuser.h:776
#define SW_SHOWDEFAULT
Definition: winuser.h:783
#define WM_SETFONT
Definition: winuser.h:1653
#define SendMessage
Definition: winuser.h:5855
#define CW_USEDEFAULT
Definition: winuser.h:225
#define LoadString
Definition: winuser.h:5831
#define WPF_RESTORETOMAXIMIZED
Definition: winuser.h:2535
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)

Referenced by _tWinMain().

◆ NOTEPAD_SaveSettingsToRegistry()

void NOTEPAD_SaveSettingsToRegistry ( void  )

Definition at line 236 of file settings.c.

237{
238 HKEY hKey;
239 DWORD dwDisposition;
241 UINT x, y, cx, cy;
242
243 wp.length = sizeof(wp);
247 cx = wp.rcNormalPosition.right - x;
250 cy |= 0x80000000;
251
252
254 0, NULL, 0, KEY_SET_VALUE, NULL,
255 &hKey, &dwDisposition) == ERROR_SUCCESS)
256 {
257 SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet);
258 SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision);
259 SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement);
260 SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName);
261 SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic);
262 SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation);
263 SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision);
264 SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily);
265 SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality);
266 SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut);
267 SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline);
268 SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight);
269 SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight));
270 SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
271 SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0);
272 SaveString(hKey, _T("szHeader"), Globals.szHeader);
273 SaveString(hKey, _T("szTrailer"), Globals.szFooter);
274 SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left);
275 SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
276 SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
277 SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
278 SaveDword(hKey, _T("iWindowPosX"), x);
279 SaveDword(hKey, _T("iWindowPosY"), y);
280 SaveDword(hKey, _T("iWindowPosDX"), cx);
281 SaveDword(hKey, _T("iWindowPosDY"), cy);
282 SaveString(hKey, _T("searchString"), Globals.szFindText);
283 SaveString(hKey, _T("replaceString"), Globals.szReplaceText);
284
286 }
287}
static DWORD PointSizeFromHeight(LONG lHeight)
Definition: settings.c:29
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
Definition: settings.c:226
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
Definition: settings.c:221
unsigned int UINT
Definition: ndis.h:50
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define RegCreateKeyEx
Definition: winreg.h:501
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)

Referenced by NOTEPAD_WndProc().

◆ PointSizeFromHeight()

static DWORD PointSizeFromHeight ( LONG  lHeight)
static

Definition at line 29 of file settings.c.

30{
31 DWORD dwPointSize;
32 HDC hDC;
33
34 hDC = GetDC(NULL);
35 dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY));
37
38 /* round to nearest multiple of 10 */
39 dwPointSize += 5;
40 dwPointSize -= dwPointSize % 10;
41
42 return dwPointSize;
43}

Referenced by NOTEPAD_SaveSettingsToRegistry().

◆ QueryBool()

static BOOL QueryBool ( HKEY  hKey,
LPCTSTR  pszValueName,
BOOL pbResult 
)
static

Definition at line 81 of file settings.c.

82{
83 DWORD dwResult;
84 if (!QueryDword(hKey, pszValueName, &dwResult))
85 return FALSE;
86 *pbResult = dwResult ? TRUE : FALSE;
87 return TRUE;
88}

Referenced by NOTEPAD_LoadSettingsFromRegistry().

◆ QueryByte()

static BOOL QueryByte ( HKEY  hKey,
LPCTSTR  pszValueName,
BYTE pbResult 
)
static

Definition at line 70 of file settings.c.

71{
72 DWORD dwResult;
73 if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult)))
74 return FALSE;
75 if (dwResult >= 0x100)
76 return FALSE;
77 *pbResult = (BYTE) dwResult;
78 return TRUE;
79}
static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, LPVOID pvResult, DWORD dwResultSize)
Definition: settings.c:46
#define REG_DWORD
Definition: sdbapi.c:596
unsigned char BYTE
Definition: xxhash.c:193

Referenced by NOTEPAD_LoadSettingsFromRegistry().

◆ QueryDword()

static BOOL QueryDword ( HKEY  hKey,
LPCTSTR  pszValueName,
DWORD pdwResult 
)
static

Definition at line 65 of file settings.c.

66{
67 return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult));
68}
_In_ UINT _In_ DWORD _Out_ DWORD * pdwResult
Definition: ntgdi.h:250

Referenced by NOTEPAD_LoadSettingsFromRegistry(), and QueryBool().

◆ QueryGeneric()

static BOOL QueryGeneric ( HKEY  hKey,
LPCTSTR  pszValueNameT,
DWORD  dwExpectedType,
LPVOID  pvResult,
DWORD  dwResultSize 
)
static

Definition at line 46 of file settings.c.

48{
49 DWORD dwType, cbData;
50 LPVOID *pTemp = _alloca(dwResultSize);
51
52 ZeroMemory(pTemp, dwResultSize);
53
54 cbData = dwResultSize;
55 if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS)
56 return FALSE;
57
58 if (dwType != dwExpectedType)
59 return FALSE;
60
61 memcpy(pvResult, pTemp, cbData);
62 return TRUE;
63}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned char * LPBYTE
Definition: typedefs.h:53
#define RegQueryValueEx
Definition: winreg.h:524

Referenced by QueryByte(), QueryDword(), and QueryString().

◆ QueryString()

static BOOL QueryString ( HKEY  hKey,
LPCTSTR  pszValueName,
LPTSTR  pszResult,
DWORD  dwResultLength 
)
static

Definition at line 90 of file settings.c.

91{
92 if (dwResultLength == 0)
93 return FALSE;
94 if (!QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultLength * sizeof(TCHAR)))
95 return FALSE;
96 pszResult[dwResultLength - 1] = 0; /* Avoid buffer overrun */
97 return TRUE;
98}
#define REG_SZ
Definition: layer.c:22
char TCHAR
Definition: xmlstorage.h:189

Referenced by NOTEPAD_LoadSettingsFromRegistry().

◆ SaveDword()

static BOOL SaveDword ( HKEY  hKey,
LPCTSTR  pszValueNameT,
DWORD  dwValue 
)
static

Definition at line 221 of file settings.c.

222{
223 return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS;
224}
#define RegSetValueEx
Definition: winreg.h:533

Referenced by NOTEPAD_SaveSettingsToRegistry().

◆ SaveString()

static BOOL SaveString ( HKEY  hKey,
LPCTSTR  pszValueNameT,
LPCTSTR  pszValue 
)
static

Definition at line 226 of file settings.c.

227{
228 return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, (DWORD) _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS;
229}
#define _tcslen
Definition: xmlstorage.h:198

Referenced by NOTEPAD_SaveSettingsToRegistry().

Variable Documentation

◆ s_szRegistryKey

LPCTSTR s_szRegistryKey = _T("Software\\Microsoft\\Notepad")
static

Definition at line 14 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry(), and NOTEPAD_SaveSettingsToRegistry().