ReactOS  0.4.12-dev-57-g7050ac4
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 dwResultSize)
 
void NOTEPAD_LoadSettingsFromRegistry (void)
 
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 30 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry().

31 {
32  LONG lHeight;
33  HDC hDC;
34 
35  hDC = GetDC(NULL);
36  lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720);
37  ReleaseDC(NULL, hDC);
38 
39  return lHeight;
40 }
#define HDC
Definition: msvc.h:22
HDC WINAPI GetDC(_In_opt_ HWND)
long LONG
Definition: pedump.c:60
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
static HDC hDC
Definition: 3dtext.c:33
#define LOGPIXELSY
Definition: wingdi.h:717
#define MulDiv(x, y, z)
Definition: gdifloat.h:86

◆ NOTEPAD_LoadSettingsFromRegistry()

void NOTEPAD_LoadSettingsFromRegistry ( void  )

Definition at line 114 of file settings.c.

Referenced by _tWinMain().

115 {
116  HKEY hKey = NULL;
117  HFONT hFont;
118  DWORD dwPointSize = 0;
119  INT base_length, dx, dy;
120 
123 
124  dx = (INT)(base_length * .95);
125  dy = dx * 3 / 4;
126  SetRect(&Globals.main_rect, 0, 0, dx, dy);
127 
129  {
130  QueryByte(hKey, _T("lfCharSet"), &Globals.lfFont.lfCharSet);
131  QueryByte(hKey, _T("lfClipPrecision"), &Globals.lfFont.lfClipPrecision);
132  QueryDword(hKey, _T("lfEscapement"), (DWORD*)&Globals.lfFont.lfEscapement);
133  QueryString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName, ARRAY_SIZE(Globals.lfFont.lfFaceName));
134  QueryByte(hKey, _T("lfItalic"), &Globals.lfFont.lfItalic);
135  QueryDword(hKey, _T("lfOrientation"), (DWORD*)&Globals.lfFont.lfOrientation);
136  QueryByte(hKey, _T("lfOutPrecision"), &Globals.lfFont.lfOutPrecision);
137  QueryByte(hKey, _T("lfPitchAndFamily"), &Globals.lfFont.lfPitchAndFamily);
138  QueryByte(hKey, _T("lfQuality"), &Globals.lfFont.lfQuality);
139  QueryByte(hKey, _T("lfStrikeOut"), &Globals.lfFont.lfStrikeOut);
140  QueryByte(hKey, _T("lfUnderline"), &Globals.lfFont.lfUnderline);
141  QueryDword(hKey, _T("lfWeight"), (DWORD*)&Globals.lfFont.lfWeight);
142  QueryDword(hKey, _T("iPointSize"), &dwPointSize);
143  QueryBool(hKey, _T("fWrap"), &Globals.bWrapLongLines);
144  QueryBool(hKey, _T("fStatusBar"), &Globals.bShowStatusBar);
145  QueryString(hKey, _T("szHeader"), Globals.szHeader, ARRAY_SIZE(Globals.szHeader));
146  QueryString(hKey, _T("szTrailer"), Globals.szFooter, ARRAY_SIZE(Globals.szFooter));
147  QueryDword(hKey, _T("iMarginLeft"), (DWORD*)&Globals.lMargins.left);
148  QueryDword(hKey, _T("iMarginTop"), (DWORD*)&Globals.lMargins.top);
149  QueryDword(hKey, _T("iMarginRight"), (DWORD*)&Globals.lMargins.right);
150  QueryDword(hKey, _T("iMarginBottom"), (DWORD*)&Globals.lMargins.bottom);
151 
152  QueryDword(hKey, _T("iWindowPosX"), (DWORD*)&Globals.main_rect.left);
153  QueryDword(hKey, _T("iWindowPosY"), (DWORD*)&Globals.main_rect.top);
154  QueryDword(hKey, _T("iWindowPosDX"), (DWORD*)&dx);
155  QueryDword(hKey, _T("iWindowPosDY"), (DWORD*)&dy);
156 
157  Globals.main_rect.right = Globals.main_rect.left + dx;
158  Globals.main_rect.bottom = Globals.main_rect.top + dy;
159 
160  /* invert value because DIALOG_ViewStatusBar will be called to show it */
161  Globals.bShowStatusBar = !Globals.bShowStatusBar;
162 
163  if (dwPointSize != 0)
164  Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
165  else
166  Globals.lfFont.lfHeight = HeightFromPointSize(100);
167 
168  RegCloseKey(hKey);
169  }
170  else
171  {
172  /* If no settings are found in the registry, then use default values */
173  Globals.bShowStatusBar = FALSE;
174  Globals.bWrapLongLines = FALSE;
175  SetRect(&Globals.lMargins, 750, 1000, 750, 1000);
176 
177  /* FIXME: Globals.fSaveWindowPositions = FALSE; */
178  /* FIXME: Globals.fMLE_is_broken = FALSE; */
179 
181  ARRAY_SIZE(Globals.szHeader));
183  ARRAY_SIZE(Globals.szFooter));
184 
185  ZeroMemory(&Globals.lfFont, sizeof(Globals.lfFont));
186  Globals.lfFont.lfCharSet = ANSI_CHARSET;
187  Globals.lfFont.lfClipPrecision = CLIP_STROKE_PRECIS;
188  Globals.lfFont.lfEscapement = 0;
189  _tcscpy(Globals.lfFont.lfFaceName, _T("Lucida Console"));
190  Globals.lfFont.lfItalic = FALSE;
191  Globals.lfFont.lfOrientation = 0;
192  Globals.lfFont.lfOutPrecision = OUT_STRING_PRECIS;
193  Globals.lfFont.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
194  Globals.lfFont.lfQuality = PROOF_QUALITY;
195  Globals.lfFont.lfStrikeOut = FALSE;
196  Globals.lfFont.lfUnderline = FALSE;
197  Globals.lfFont.lfWeight = FW_NORMAL;
198  Globals.lfFont.lfHeight = HeightFromPointSize(100);
199  }
200 
201  hFont = CreateFontIndirect(&Globals.lfFont);
202  SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);
203  if (hFont)
204  {
205  if (Globals.hFont)
206  DeleteObject(Globals.hFont);
207  Globals.hFont = hFont;
208  }
209 }
static BOOL QueryByte(HKEY hKey, LPCTSTR pszValueName, BYTE *pbResult)
Definition: settings.c:83
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define PROOF_QUALITY
Definition: wingdi.h:436
int32_t INT
Definition: typedefs.h:56
HFONT hFont
Definition: main.c:53
#define STRING_PAGESETUP_HEADERVALUE
Definition: notepad_res.h:67
UINT_PTR WPARAM
Definition: windef.h:207
local int base_length[LENGTH_CODES]
Definition: trees.c:107
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define SM_CXSCREEN
Definition: winuser.h:949
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
LONG_PTR LPARAM
Definition: windef.h:208
#define FIXED_PITCH
Definition: wingdi.h:442
#define OUT_STRING_PRECIS
Definition: wingdi.h:414
#define INT(a)
Definition: assyntax.h:463
smooth NULL
Definition: ftsmooth.c:416
static BOOL QueryBool(HKEY hKey, LPCTSTR pszValueName, BOOL *pbResult)
Definition: settings.c:94
#define SM_CYSCREEN
Definition: winuser.h:950
#define _T(x)
Definition: vfdio.h:22
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
Definition: settings.c:78
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize)
Definition: settings.c:103
#define STRING_PAGESETUP_FOOTERVALUE
Definition: notepad_res.h:68
int WINAPI GetSystemMetrics(_In_ int)
unsigned long DWORD
Definition: ntddk_ex.h:95
static LPCTSTR s_szRegistryKey
Definition: settings.c:27
BOOL WINAPI SetRect(_Out_ LPRECT, _In_ int, _In_ int, _In_ int, _In_ int)
INT INT dy
Definition: msvc.h:65
#define ARRAY_SIZE(a)
Definition: main.h:24
#define FF_MODERN
Definition: wingdi.h:447
#define CreateFontIndirect
Definition: wingdi.h:4421
#define WM_SETFONT
Definition: winuser.h:1632
#define FW_NORMAL
Definition: wingdi.h:371
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define SendMessage
Definition: winuser.h:5709
static LONG HeightFromPointSize(DWORD dwPointSize)
Definition: settings.c:30
#define ANSI_CHARSET
Definition: wingdi.h:381
HINSTANCE hInstance
Definition: precomp.h:43
#define RegOpenKey
Definition: winreg.h:519
#define CLIP_STROKE_PRECIS
Definition: wingdi.h:426
#define LoadString
Definition: winuser.h:5685
INT dx
Definition: msvc.h:65

◆ NOTEPAD_SaveSettingsToRegistry()

void NOTEPAD_SaveSettingsToRegistry ( void  )

Definition at line 227 of file settings.c.

Referenced by NOTEPAD_WndProc().

228 {
229  HKEY hKey;
230  DWORD dwDisposition;
231 
232  GetWindowRect(Globals.hMainWnd, &Globals.main_rect);
233 
235  0, NULL, 0, KEY_SET_VALUE, NULL,
236  &hKey, &dwDisposition) == ERROR_SUCCESS)
237  {
238  SaveDword(hKey, _T("lfCharSet"), Globals.lfFont.lfCharSet);
239  SaveDword(hKey, _T("lfClipPrecision"), Globals.lfFont.lfClipPrecision);
240  SaveDword(hKey, _T("lfEscapement"), Globals.lfFont.lfEscapement);
241  SaveString(hKey, _T("lfFaceName"), Globals.lfFont.lfFaceName);
242  SaveDword(hKey, _T("lfItalic"), Globals.lfFont.lfItalic);
243  SaveDword(hKey, _T("lfOrientation"), Globals.lfFont.lfOrientation);
244  SaveDword(hKey, _T("lfOutPrecision"), Globals.lfFont.lfOutPrecision);
245  SaveDword(hKey, _T("lfPitchAndFamily"), Globals.lfFont.lfPitchAndFamily);
246  SaveDword(hKey, _T("lfQuality"), Globals.lfFont.lfQuality);
247  SaveDword(hKey, _T("lfStrikeOut"), Globals.lfFont.lfStrikeOut);
248  SaveDword(hKey, _T("lfUnderline"), Globals.lfFont.lfUnderline);
249  SaveDword(hKey, _T("lfWeight"), Globals.lfFont.lfWeight);
250  SaveDword(hKey, _T("iPointSize"), PointSizeFromHeight(Globals.lfFont.lfHeight));
251  SaveDword(hKey, _T("fWrap"), Globals.bWrapLongLines ? 1 : 0);
252  SaveDword(hKey, _T("fStatusBar"), Globals.bShowStatusBar ? 1 : 0);
253  SaveString(hKey, _T("szHeader"), Globals.szHeader);
254  SaveString(hKey, _T("szTrailer"), Globals.szFooter);
255  SaveDword(hKey, _T("iMarginLeft"), Globals.lMargins.left);
256  SaveDword(hKey, _T("iMarginTop"), Globals.lMargins.top);
257  SaveDword(hKey, _T("iMarginRight"), Globals.lMargins.right);
258  SaveDword(hKey, _T("iMarginBottom"), Globals.lMargins.bottom);
259  SaveDword(hKey, _T("iWindowPosX"), Globals.main_rect.left);
260  SaveDword(hKey, _T("iWindowPosY"), Globals.main_rect.top);
261  SaveDword(hKey, _T("iWindowPosDX"), Globals.main_rect.right - Globals.main_rect.left);
262  SaveDword(hKey, _T("iWindowPosDY"), Globals.main_rect.bottom - Globals.main_rect.top);
263 
264  RegCloseKey(hKey);
265  }
266 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define HKEY_CURRENT_USER
Definition: winreg.h:11
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
static BOOL SaveDword(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwValue)
Definition: settings.c:211
static LPCTSTR s_szRegistryKey
Definition: settings.c:27
static DWORD PointSizeFromHeight(LONG lHeight)
Definition: settings.c:42
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
static BOOL SaveString(HKEY hKey, LPCTSTR pszValueNameT, LPCTSTR pszValue)
Definition: settings.c:216
#define RegCreateKeyEx
Definition: winreg.h:501

◆ PointSizeFromHeight()

static DWORD PointSizeFromHeight ( LONG  lHeight)
static

Definition at line 42 of file settings.c.

Referenced by NOTEPAD_SaveSettingsToRegistry().

43 {
44  DWORD dwPointSize;
45  HDC hDC;
46 
47  hDC = GetDC(NULL);
48  dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY));
49  ReleaseDC(NULL, hDC);
50 
51  /* round to nearest multiple of 10 */
52  dwPointSize += 5;
53  dwPointSize -= dwPointSize % 10;
54 
55  return dwPointSize;
56 }
#define HDC
Definition: msvc.h:22
HDC WINAPI GetDC(_In_opt_ HWND)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
static HDC hDC
Definition: 3dtext.c:33
#define LOGPIXELSY
Definition: wingdi.h:717
#define MulDiv(x, y, z)
Definition: gdifloat.h:86

◆ QueryBool()

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

Definition at line 94 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry().

95 {
96  DWORD dwResult;
97  if (!QueryDword(hKey, pszValueName, &dwResult))
98  return FALSE;
99  *pbResult = dwResult ? TRUE : FALSE;
100  return TRUE;
101 }
#define TRUE
Definition: types.h:120
static BOOL QueryDword(HKEY hKey, LPCTSTR pszValueName, DWORD *pdwResult)
Definition: settings.c:78
unsigned long DWORD
Definition: ntddk_ex.h:95

◆ QueryByte()

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

Definition at line 83 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry().

84 {
85  DWORD dwResult;
86  if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult)))
87  return FALSE;
88  if (dwResult >= 0x100)
89  return FALSE;
90  *pbResult = (BYTE) dwResult;
91  return TRUE;
92 }
#define TRUE
Definition: types.h:120
static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, LPVOID pvResult, DWORD dwResultSize)
Definition: settings.c:59
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned char BYTE
Definition: ntddk_ex.h:96
#define REG_DWORD
Definition: sdbapi.c:539

◆ QueryDword()

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

Definition at line 78 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry(), and QueryBool().

79 {
80  return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult));
81 }
static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, LPVOID pvResult, DWORD dwResultSize)
Definition: settings.c:59
_In_ UINT _In_ DWORD _Out_ DWORD * pdwResult
Definition: ntgdi.h:248
#define REG_DWORD
Definition: sdbapi.c:539

◆ QueryGeneric()

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

Definition at line 59 of file settings.c.

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

61 {
62  DWORD dwType, cbData;
63  LPVOID *pTemp = _alloca(dwResultSize);
64 
65  ZeroMemory(pTemp, dwResultSize);
66 
67  cbData = dwResultSize;
68  if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS)
69  return FALSE;
70 
71  if (dwType != dwExpectedType)
72  return FALSE;
73 
74  memcpy(pvResult, pTemp, cbData);
75  return TRUE;
76 }
#define RegQueryValueEx
Definition: winreg.h:524
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ZeroMemory
Definition: winbase.h:1635
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ QueryString()

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

Definition at line 103 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry().

104 {
105  return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(TCHAR));
106 }
static BOOL QueryGeneric(HKEY hKey, LPCTSTR pszValueNameT, DWORD dwExpectedType, LPVOID pvResult, DWORD dwResultSize)
Definition: settings.c:59
char TCHAR
Definition: xmlstorage.h:189
#define REG_SZ
Definition: layer.c:22

◆ SaveDword()

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

Definition at line 211 of file settings.c.

Referenced by NOTEPAD_SaveSettingsToRegistry().

212 {
213  return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS;
214 }
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned char * LPBYTE
Definition: typedefs.h:52
#define REG_DWORD
Definition: sdbapi.c:539
#define RegSetValueEx
Definition: winreg.h:533

◆ SaveString()

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

Definition at line 216 of file settings.c.

Referenced by NOTEPAD_SaveSettingsToRegistry().

217 {
218  return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, (DWORD) _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS;
219 }
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned char * LPBYTE
Definition: typedefs.h:52
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
unsigned long DWORD
Definition: ntddk_ex.h:95
#define RegSetValueEx
Definition: winreg.h:533
#define REG_SZ
Definition: layer.c:22

Variable Documentation

◆ s_szRegistryKey

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

Definition at line 27 of file settings.c.

Referenced by NOTEPAD_LoadSettingsFromRegistry(), and NOTEPAD_SaveSettingsToRegistry().