mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 11:53:21 +00:00
set eol-style to native
svn path=/trunk/; revision=18166
This commit is contained in:
parent
60261f9699
commit
ec05f0f08f
1 changed files with 217 additions and 217 deletions
|
@ -1,217 +1,217 @@
|
||||||
/*
|
/*
|
||||||
* Notepad (settings.c)
|
* Notepad (settings.c)
|
||||||
*
|
*
|
||||||
* Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
|
* Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
|
||||||
* Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
|
* Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
|
||||||
* Copyright 2002 Andriy Palamarchuk
|
* Copyright 2002 Andriy Palamarchuk
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define UNICODE
|
#define UNICODE
|
||||||
#define _UNICODE
|
#define _UNICODE
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <commdlg.h>
|
#include <commdlg.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
static const TCHAR s_szRegistryKey[] = { 'S','o','f','t','w','a','r','e',
|
static const TCHAR s_szRegistryKey[] = { 'S','o','f','t','w','a','r','e',
|
||||||
'\\','M','i','c','r','o','s','o','f','t',
|
'\\','M','i','c','r','o','s','o','f','t',
|
||||||
'\\','N','o','t','e','p','a','d',0 };
|
'\\','N','o','t','e','p','a','d',0 };
|
||||||
|
|
||||||
|
|
||||||
static LONG HeightFromPointSize(DWORD dwPointSize)
|
static LONG HeightFromPointSize(DWORD dwPointSize)
|
||||||
{
|
{
|
||||||
LONG lHeight;
|
LONG lHeight;
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
|
|
||||||
hDC = GetDC(NULL);
|
hDC = GetDC(NULL);
|
||||||
lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720);
|
lHeight = -MulDiv(dwPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 720);
|
||||||
ReleaseDC(NULL, hDC);
|
ReleaseDC(NULL, hDC);
|
||||||
|
|
||||||
return lHeight;
|
return lHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DWORD PointSizeFromHeight(LONG lHeight)
|
static DWORD PointSizeFromHeight(LONG lHeight)
|
||||||
{
|
{
|
||||||
DWORD dwPointSize;
|
DWORD dwPointSize;
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
|
|
||||||
hDC = GetDC(NULL);
|
hDC = GetDC(NULL);
|
||||||
dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY));
|
dwPointSize = -MulDiv(lHeight, 720, GetDeviceCaps(hDC, LOGPIXELSY));
|
||||||
ReleaseDC(NULL, hDC);
|
ReleaseDC(NULL, hDC);
|
||||||
|
|
||||||
/* round to nearest multiple of 10 */
|
/* round to nearest multiple of 10 */
|
||||||
dwPointSize += 5;
|
dwPointSize += 5;
|
||||||
dwPointSize -= dwPointSize % 10;
|
dwPointSize -= dwPointSize % 10;
|
||||||
|
|
||||||
return dwPointSize;
|
return dwPointSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL QueryGeneric(HKEY hKey, LPCSTR pszValueName, DWORD dwExpectedType,
|
static BOOL QueryGeneric(HKEY hKey, LPCSTR pszValueName, DWORD dwExpectedType,
|
||||||
LPVOID pvResult, DWORD dwResultSize)
|
LPVOID pvResult, DWORD dwResultSize)
|
||||||
{
|
{
|
||||||
WCHAR szValueW[32];
|
WCHAR szValueW[32];
|
||||||
LPCTSTR pszValueNameT;
|
LPCTSTR pszValueNameT;
|
||||||
DWORD dwType, cbData;
|
DWORD dwType, cbData;
|
||||||
LPVOID *pTemp;
|
LPVOID *pTemp;
|
||||||
BOOL bSuccess = FALSE;
|
BOOL bSuccess = FALSE;
|
||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0]));
|
MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0]));
|
||||||
pszValueNameT = szValueW;
|
pszValueNameT = szValueW;
|
||||||
#else
|
#else
|
||||||
pszValueNameT = pszValueName;
|
pszValueNameT = pszValueName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pTemp = HeapAlloc(GetProcessHeap(), 0, dwResultSize);
|
pTemp = HeapAlloc(GetProcessHeap(), 0, dwResultSize);
|
||||||
if (!pTemp)
|
if (!pTemp)
|
||||||
goto done;
|
goto done;
|
||||||
memset(pTemp, 0, dwResultSize);
|
memset(pTemp, 0, dwResultSize);
|
||||||
|
|
||||||
cbData = dwResultSize;
|
cbData = dwResultSize;
|
||||||
if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS)
|
if (RegQueryValueEx(hKey, pszValueNameT, NULL, &dwType, (LPBYTE) pTemp, &cbData) != ERROR_SUCCESS)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (dwType != dwExpectedType)
|
if (dwType != dwExpectedType)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
memcpy(pvResult, pTemp, cbData);
|
memcpy(pvResult, pTemp, cbData);
|
||||||
bSuccess = TRUE;
|
bSuccess = TRUE;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (pTemp)
|
if (pTemp)
|
||||||
HeapFree(GetProcessHeap(), 0, pTemp);
|
HeapFree(GetProcessHeap(), 0, pTemp);
|
||||||
return bSuccess;
|
return bSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL QueryDword(HKEY hKey, LPCSTR pszValueName, DWORD *pdwResult)
|
static BOOL QueryDword(HKEY hKey, LPCSTR pszValueName, DWORD *pdwResult)
|
||||||
{
|
{
|
||||||
return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult));
|
return QueryGeneric(hKey, pszValueName, REG_DWORD, pdwResult, sizeof(*pdwResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL QueryByte(HKEY hKey, LPCSTR pszValueName, BYTE *pbResult)
|
static BOOL QueryByte(HKEY hKey, LPCSTR pszValueName, BYTE *pbResult)
|
||||||
{
|
{
|
||||||
DWORD dwResult;
|
DWORD dwResult;
|
||||||
if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult)))
|
if (!QueryGeneric(hKey, pszValueName, REG_DWORD, &dwResult, sizeof(dwResult)))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (dwResult >= 0x100)
|
if (dwResult >= 0x100)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
*pbResult = (BYTE) dwResult;
|
*pbResult = (BYTE) dwResult;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL QueryString(HKEY hKey, LPCSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize)
|
static BOOL QueryString(HKEY hKey, LPCSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize)
|
||||||
{
|
{
|
||||||
return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(*pszResult));
|
return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(*pszResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadSettings(void)
|
void LoadSettings(void)
|
||||||
{
|
{
|
||||||
HKEY hKey = NULL;
|
HKEY hKey = NULL;
|
||||||
HFONT hFont;
|
HFONT hFont;
|
||||||
DWORD dwPointSize = 0;
|
DWORD dwPointSize = 0;
|
||||||
|
|
||||||
if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS)
|
if (RegOpenKey(HKEY_CURRENT_USER, s_szRegistryKey, &hKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
QueryByte(hKey, "lfCharSet", &Globals.lfFont.lfCharSet);
|
QueryByte(hKey, "lfCharSet", &Globals.lfFont.lfCharSet);
|
||||||
QueryByte(hKey, "lfClipPrecision", &Globals.lfFont.lfClipPrecision);
|
QueryByte(hKey, "lfClipPrecision", &Globals.lfFont.lfClipPrecision);
|
||||||
QueryDword(hKey, "lfEscapement", &Globals.lfFont.lfEscapement);
|
QueryDword(hKey, "lfEscapement", &Globals.lfFont.lfEscapement);
|
||||||
QueryString(hKey, "lfFaceName", Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0]));
|
QueryString(hKey, "lfFaceName", Globals.lfFont.lfFaceName, sizeof(Globals.lfFont.lfFaceName) / sizeof(Globals.lfFont.lfFaceName[0]));
|
||||||
QueryByte(hKey, "lfItalic", &Globals.lfFont.lfItalic);
|
QueryByte(hKey, "lfItalic", &Globals.lfFont.lfItalic);
|
||||||
QueryDword(hKey, "lfOrientation", &Globals.lfFont.lfOrientation);
|
QueryDword(hKey, "lfOrientation", &Globals.lfFont.lfOrientation);
|
||||||
QueryByte(hKey, "lfOutPrecision", &Globals.lfFont.lfOutPrecision);
|
QueryByte(hKey, "lfOutPrecision", &Globals.lfFont.lfOutPrecision);
|
||||||
QueryByte(hKey, "lfPitchAndFamily", &Globals.lfFont.lfPitchAndFamily);
|
QueryByte(hKey, "lfPitchAndFamily", &Globals.lfFont.lfPitchAndFamily);
|
||||||
QueryByte(hKey, "lfQuality", &Globals.lfFont.lfQuality);
|
QueryByte(hKey, "lfQuality", &Globals.lfFont.lfQuality);
|
||||||
QueryByte(hKey, "lfStrikeOut", &Globals.lfFont.lfStrikeOut);
|
QueryByte(hKey, "lfStrikeOut", &Globals.lfFont.lfStrikeOut);
|
||||||
QueryByte(hKey, "lfUnderline", &Globals.lfFont.lfUnderline);
|
QueryByte(hKey, "lfUnderline", &Globals.lfFont.lfUnderline);
|
||||||
QueryDword(hKey, "lfWeight", &Globals.lfFont.lfWeight);
|
QueryDword(hKey, "lfWeight", &Globals.lfFont.lfWeight);
|
||||||
QueryDword(hKey, "iPointSize", &dwPointSize);
|
QueryDword(hKey, "iPointSize", &dwPointSize);
|
||||||
|
|
||||||
if (dwPointSize != 0)
|
if (dwPointSize != 0)
|
||||||
Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
|
Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize);
|
||||||
|
|
||||||
hFont = CreateFontIndirect(&Globals.lfFont);
|
hFont = CreateFontIndirect(&Globals.lfFont);
|
||||||
if (hFont)
|
if (hFont)
|
||||||
{
|
{
|
||||||
if (Globals.hFont)
|
if (Globals.hFont)
|
||||||
DeleteObject(Globals.hFont);
|
DeleteObject(Globals.hFont);
|
||||||
Globals.hFont = hFont;
|
Globals.hFont = hFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL SaveDword(HKEY hKey, LPCSTR pszValueName, DWORD dwValue)
|
static BOOL SaveDword(HKEY hKey, LPCSTR pszValueName, DWORD dwValue)
|
||||||
{
|
{
|
||||||
WCHAR szValueW[32];
|
WCHAR szValueW[32];
|
||||||
LPCTSTR pszValueNameT;
|
LPCTSTR pszValueNameT;
|
||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0]));
|
MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0]));
|
||||||
pszValueNameT = szValueW;
|
pszValueNameT = szValueW;
|
||||||
#else
|
#else
|
||||||
pszValueNameT = pszValueName;
|
pszValueNameT = pszValueName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS;
|
return RegSetValueEx(hKey, pszValueNameT, 0, REG_DWORD, (LPBYTE) &dwValue, sizeof(dwValue)) == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL SaveString(HKEY hKey, LPCSTR pszValueName, LPCTSTR pszValue)
|
static BOOL SaveString(HKEY hKey, LPCSTR pszValueName, LPCTSTR pszValue)
|
||||||
{
|
{
|
||||||
WCHAR szValueW[32];
|
WCHAR szValueW[32];
|
||||||
LPCTSTR pszValueNameT;
|
LPCTSTR pszValueNameT;
|
||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0]));
|
MultiByteToWideChar(CP_ACP, 0, pszValueName, -1, szValueW, sizeof(szValueW) / sizeof(szValueW[0]));
|
||||||
pszValueNameT = szValueW;
|
pszValueNameT = szValueW;
|
||||||
#else
|
#else
|
||||||
pszValueNameT = pszValueName;
|
pszValueNameT = pszValueName;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS;
|
return RegSetValueEx(hKey, pszValueNameT, 0, REG_SZ, (LPBYTE) pszValue, _tcslen(pszValue) * sizeof(*pszValue)) == ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveSettings(void)
|
void SaveSettings(void)
|
||||||
{
|
{
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
DWORD dwDisposition;
|
DWORD dwDisposition;
|
||||||
|
|
||||||
if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition)
|
if (RegCreateKeyEx(HKEY_CURRENT_USER, s_szRegistryKey, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition)
|
||||||
== ERROR_SUCCESS)
|
== ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
SaveDword(hKey, "lfCharSet", Globals.lfFont.lfCharSet);
|
SaveDword(hKey, "lfCharSet", Globals.lfFont.lfCharSet);
|
||||||
SaveDword(hKey, "lfClipPrecision", Globals.lfFont.lfClipPrecision);
|
SaveDword(hKey, "lfClipPrecision", Globals.lfFont.lfClipPrecision);
|
||||||
SaveDword(hKey, "lfEscapement", Globals.lfFont.lfEscapement);
|
SaveDword(hKey, "lfEscapement", Globals.lfFont.lfEscapement);
|
||||||
SaveString(hKey, "lfFaceName", Globals.lfFont.lfFaceName);
|
SaveString(hKey, "lfFaceName", Globals.lfFont.lfFaceName);
|
||||||
SaveDword(hKey, "lfItalic", Globals.lfFont.lfItalic);
|
SaveDword(hKey, "lfItalic", Globals.lfFont.lfItalic);
|
||||||
SaveDword(hKey, "lfOrientation", Globals.lfFont.lfOrientation);
|
SaveDword(hKey, "lfOrientation", Globals.lfFont.lfOrientation);
|
||||||
SaveDword(hKey, "lfOutPrecision", Globals.lfFont.lfOutPrecision);
|
SaveDword(hKey, "lfOutPrecision", Globals.lfFont.lfOutPrecision);
|
||||||
SaveDword(hKey, "lfPitchAndFamily", Globals.lfFont.lfPitchAndFamily);
|
SaveDword(hKey, "lfPitchAndFamily", Globals.lfFont.lfPitchAndFamily);
|
||||||
SaveDword(hKey, "lfQuality", Globals.lfFont.lfQuality);
|
SaveDword(hKey, "lfQuality", Globals.lfFont.lfQuality);
|
||||||
SaveDword(hKey, "lfStrikeOut", Globals.lfFont.lfStrikeOut);
|
SaveDword(hKey, "lfStrikeOut", Globals.lfFont.lfStrikeOut);
|
||||||
SaveDword(hKey, "lfUnderline", Globals.lfFont.lfUnderline);
|
SaveDword(hKey, "lfUnderline", Globals.lfFont.lfUnderline);
|
||||||
SaveDword(hKey, "lfWeight", Globals.lfFont.lfWeight);
|
SaveDword(hKey, "lfWeight", Globals.lfFont.lfWeight);
|
||||||
SaveDword(hKey, "iPointSize", PointSizeFromHeight(Globals.lfFont.lfHeight));
|
SaveDword(hKey, "iPointSize", PointSizeFromHeight(Globals.lfFont.lfHeight));
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue