4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * Copyright 2002 Andriy Palamarchuk
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 static const TCHAR s_szRegistryKey
[] = { 'S','o','f','t','w','a','r','e',
35 '\\','M','i','c','r','o','s','o','f','t',
36 '\\','N','o','t','e','p','a','d',0 };
39 static LONG
HeightFromPointSize(DWORD dwPointSize
)
45 lHeight
= -MulDiv(dwPointSize
, GetDeviceCaps(hDC
, LOGPIXELSY
), 720);
51 static DWORD
PointSizeFromHeight(LONG lHeight
)
57 dwPointSize
= -MulDiv(lHeight
, 720, GetDeviceCaps(hDC
, LOGPIXELSY
));
60 /* round to nearest multiple of 10 */
62 dwPointSize
-= dwPointSize
% 10;
67 static BOOL
QueryGeneric(HKEY hKey
, LPCSTR pszValueName
, DWORD dwExpectedType
,
68 LPVOID pvResult
, DWORD dwResultSize
)
71 LPCTSTR pszValueNameT
;
74 BOOL bSuccess
= FALSE
;
77 MultiByteToWideChar(CP_ACP
, 0, pszValueName
, -1, szValueW
, sizeof(szValueW
) / sizeof(szValueW
[0]));
78 pszValueNameT
= szValueW
;
80 pszValueNameT
= pszValueName
;
83 pTemp
= HeapAlloc(GetProcessHeap(), 0, dwResultSize
);
86 memset(pTemp
, 0, dwResultSize
);
88 cbData
= dwResultSize
;
89 if (RegQueryValueEx(hKey
, pszValueNameT
, NULL
, &dwType
, (LPBYTE
) pTemp
, &cbData
) != ERROR_SUCCESS
)
92 if (dwType
!= dwExpectedType
)
95 memcpy(pvResult
, pTemp
, cbData
);
100 HeapFree(GetProcessHeap(), 0, pTemp
);
104 static BOOL
QueryDword(HKEY hKey
, LPCSTR pszValueName
, DWORD
*pdwResult
)
106 return QueryGeneric(hKey
, pszValueName
, REG_DWORD
, pdwResult
, sizeof(*pdwResult
));
109 static BOOL
QueryByte(HKEY hKey
, LPCSTR pszValueName
, BYTE
*pbResult
)
112 if (!QueryGeneric(hKey
, pszValueName
, REG_DWORD
, &dwResult
, sizeof(dwResult
)))
114 if (dwResult
>= 0x100)
116 *pbResult
= (BYTE
) dwResult
;
120 static BOOL
QueryString(HKEY hKey
, LPCSTR pszValueName
, LPTSTR pszResult
, DWORD dwResultSize
)
122 return QueryGeneric(hKey
, pszValueName
, REG_SZ
, pszResult
, dwResultSize
* sizeof(*pszResult
));
125 void LoadSettings(void)
129 DWORD dwPointSize
= 0;
131 if (RegOpenKey(HKEY_CURRENT_USER
, s_szRegistryKey
, &hKey
) == ERROR_SUCCESS
)
133 QueryByte(hKey
, "lfCharSet", &Globals
.lfFont
.lfCharSet
);
134 QueryByte(hKey
, "lfClipPrecision", &Globals
.lfFont
.lfClipPrecision
);
135 QueryDword(hKey
, "lfEscapement", &Globals
.lfFont
.lfEscapement
);
136 QueryString(hKey
, "lfFaceName", Globals
.lfFont
.lfFaceName
, sizeof(Globals
.lfFont
.lfFaceName
) / sizeof(Globals
.lfFont
.lfFaceName
[0]));
137 QueryByte(hKey
, "lfItalic", &Globals
.lfFont
.lfItalic
);
138 QueryDword(hKey
, "lfOrientation", &Globals
.lfFont
.lfOrientation
);
139 QueryByte(hKey
, "lfOutPrecision", &Globals
.lfFont
.lfOutPrecision
);
140 QueryByte(hKey
, "lfPitchAndFamily", &Globals
.lfFont
.lfPitchAndFamily
);
141 QueryByte(hKey
, "lfQuality", &Globals
.lfFont
.lfQuality
);
142 QueryByte(hKey
, "lfStrikeOut", &Globals
.lfFont
.lfStrikeOut
);
143 QueryByte(hKey
, "lfUnderline", &Globals
.lfFont
.lfUnderline
);
144 QueryDword(hKey
, "lfWeight", &Globals
.lfFont
.lfWeight
);
145 QueryDword(hKey
, "iPointSize", &dwPointSize
);
147 if (dwPointSize
!= 0)
148 Globals
.lfFont
.lfHeight
= HeightFromPointSize(dwPointSize
);
150 hFont
= CreateFontIndirect(&Globals
.lfFont
);
154 DeleteObject(Globals
.hFont
);
155 Globals
.hFont
= hFont
;
162 static BOOL
SaveDword(HKEY hKey
, LPCSTR pszValueName
, DWORD dwValue
)
165 LPCTSTR pszValueNameT
;
168 MultiByteToWideChar(CP_ACP
, 0, pszValueName
, -1, szValueW
, sizeof(szValueW
) / sizeof(szValueW
[0]));
169 pszValueNameT
= szValueW
;
171 pszValueNameT
= pszValueName
;
174 return RegSetValueEx(hKey
, pszValueNameT
, 0, REG_DWORD
, (LPBYTE
) &dwValue
, sizeof(dwValue
)) == ERROR_SUCCESS
;
177 static BOOL
SaveString(HKEY hKey
, LPCSTR pszValueName
, LPCTSTR pszValue
)
180 LPCTSTR pszValueNameT
;
183 MultiByteToWideChar(CP_ACP
, 0, pszValueName
, -1, szValueW
, sizeof(szValueW
) / sizeof(szValueW
[0]));
184 pszValueNameT
= szValueW
;
186 pszValueNameT
= pszValueName
;
189 return RegSetValueEx(hKey
, pszValueNameT
, 0, REG_SZ
, (LPBYTE
) pszValue
, _tcslen(pszValue
) * sizeof(*pszValue
)) == ERROR_SUCCESS
;
192 void SaveSettings(void)
197 if (RegCreateKeyEx(HKEY_CURRENT_USER
, s_szRegistryKey
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisposition
)
200 SaveDword(hKey
, "lfCharSet", Globals
.lfFont
.lfCharSet
);
201 SaveDword(hKey
, "lfClipPrecision", Globals
.lfFont
.lfClipPrecision
);
202 SaveDword(hKey
, "lfEscapement", Globals
.lfFont
.lfEscapement
);
203 SaveString(hKey
, "lfFaceName", Globals
.lfFont
.lfFaceName
);
204 SaveDword(hKey
, "lfItalic", Globals
.lfFont
.lfItalic
);
205 SaveDword(hKey
, "lfOrientation", Globals
.lfFont
.lfOrientation
);
206 SaveDword(hKey
, "lfOutPrecision", Globals
.lfFont
.lfOutPrecision
);
207 SaveDword(hKey
, "lfPitchAndFamily", Globals
.lfFont
.lfPitchAndFamily
);
208 SaveDword(hKey
, "lfQuality", Globals
.lfFont
.lfQuality
);
209 SaveDword(hKey
, "lfStrikeOut", Globals
.lfFont
.lfStrikeOut
);
210 SaveDword(hKey
, "lfUnderline", Globals
.lfFont
.lfUnderline
);
211 SaveDword(hKey
, "lfWeight", Globals
.lfFont
.lfWeight
);
212 SaveDword(hKey
, "iPointSize", PointSizeFromHeight(Globals
.lfFont
.lfHeight
));