Commit cd5a04fd authored by Alexandre Julliard's avatar Alexandre Julliard

notepad: Fallback to default position if saved position if off-screen.

parent 1dc38cf2
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
NOTEPAD_GLOBALS Globals; NOTEPAD_GLOBALS Globals;
static ATOM aFINDMSGSTRING; static ATOM aFINDMSGSTRING;
static RECT main_rect;
static const WCHAR notepad_reg_key[] = {'S','o','f','t','w','a','r','e','\\', static const WCHAR notepad_reg_key[] = {'S','o','f','t','w','a','r','e','\\',
'M','i','c','r','o','s','o','f','t','\\','N','o','t','e','p','a','d','\0'}; 'M','i','c','r','o','s','o','f','t','\\','N','o','t','e','p','a','d','\0'};
...@@ -111,20 +112,15 @@ static VOID NOTEPAD_SaveSettingToRegistry(void) ...@@ -111,20 +112,15 @@ static VOID NOTEPAD_SaveSettingToRegistry(void)
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disp) == ERROR_SUCCESS) REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &disp) == ERROR_SUCCESS)
{ {
DWORD data; DWORD data;
RECT rect;
GetWindowRect(Globals.hMainWnd, &rect); GetWindowRect(Globals.hMainWnd, &main_rect);
Globals.iWindowPosX = rect.left;
Globals.iWindowPosY = rect.top;
Globals.iWindowPosDX = rect.right - rect.left;
Globals.iWindowPosDY = rect.bottom - rect.top;
#define SET_NOTEPAD_REG(hkey, value_name, value_data) do { DWORD data = (DWORD)value_data; RegSetValueEx(hkey, value_name, 0, REG_DWORD, (LPBYTE)&data, sizeof(DWORD)); }while(0) #define SET_NOTEPAD_REG(hkey, value_name, value_data) do { DWORD data = (DWORD)(value_data); RegSetValueEx(hkey, value_name, 0, REG_DWORD, (LPBYTE)&data, sizeof(DWORD)); }while(0)
SET_NOTEPAD_REG(hkey, value_fWrap, Globals.bWrapLongLines); SET_NOTEPAD_REG(hkey, value_fWrap, Globals.bWrapLongLines);
SET_NOTEPAD_REG(hkey, value_iWindowPosX, Globals.iWindowPosX); SET_NOTEPAD_REG(hkey, value_iWindowPosX, main_rect.left);
SET_NOTEPAD_REG(hkey, value_iWindowPosY, Globals.iWindowPosY); SET_NOTEPAD_REG(hkey, value_iWindowPosY, main_rect.top);
SET_NOTEPAD_REG(hkey, value_iWindowPosDX, Globals.iWindowPosDX); SET_NOTEPAD_REG(hkey, value_iWindowPosDX, main_rect.right - main_rect.left);
SET_NOTEPAD_REG(hkey, value_iWindowPosDY, Globals.iWindowPosDY); SET_NOTEPAD_REG(hkey, value_iWindowPosDY, main_rect.bottom - main_rect.top);
SET_NOTEPAD_REG(hkey, value_lfCharSet, Globals.lfFont.lfCharSet); SET_NOTEPAD_REG(hkey, value_lfCharSet, Globals.lfFont.lfCharSet);
SET_NOTEPAD_REG(hkey, value_lfClipPrecision, Globals.lfFont.lfClipPrecision); SET_NOTEPAD_REG(hkey, value_lfClipPrecision, Globals.lfFont.lfClipPrecision);
SET_NOTEPAD_REG(hkey, value_lfEscapement, Globals.lfFont.lfEscapement); SET_NOTEPAD_REG(hkey, value_lfEscapement, Globals.lfFont.lfEscapement);
...@@ -158,15 +154,14 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void) ...@@ -158,15 +154,14 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void)
{ {
static const WCHAR systemW[] = { 'S','y','s','t','e','m','\0' }; static const WCHAR systemW[] = { 'S','y','s','t','e','m','\0' };
HKEY hkey; HKEY hkey;
INT base_length; INT base_length, dx, dy;
base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))? base_length = (GetSystemMetrics(SM_CXSCREEN) > GetSystemMetrics(SM_CYSCREEN))?
GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN); GetSystemMetrics(SM_CYSCREEN) : GetSystemMetrics(SM_CXSCREEN);
Globals.iWindowPosX = 0; dx = base_length * .95;
Globals.iWindowPosY = 0; dy = dx * 3 / 4;
Globals.iWindowPosDX = base_length * .95; SetRect( &main_rect, 0, 0, dx, dy );
Globals.iWindowPosDY = Globals.iWindowPosDX * 3 / 4;
Globals.bWrapLongLines = TRUE; Globals.bWrapLongLines = TRUE;
...@@ -192,10 +187,10 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void) ...@@ -192,10 +187,10 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void)
#define QUERY_NOTEPAD_REG(hkey, value_name, ret) do { DWORD type, data; DWORD size = sizeof(DWORD); if(RegQueryValueEx(hkey, value_name, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS) if(type == REG_DWORD) ret = (typeof(ret))data; } while(0) #define QUERY_NOTEPAD_REG(hkey, value_name, ret) do { DWORD type, data; DWORD size = sizeof(DWORD); if(RegQueryValueEx(hkey, value_name, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS) if(type == REG_DWORD) ret = (typeof(ret))data; } while(0)
QUERY_NOTEPAD_REG(hkey, value_fWrap, Globals.bWrapLongLines); QUERY_NOTEPAD_REG(hkey, value_fWrap, Globals.bWrapLongLines);
QUERY_NOTEPAD_REG(hkey, value_iWindowPosX, Globals.iWindowPosX); QUERY_NOTEPAD_REG(hkey, value_iWindowPosX, main_rect.left);
QUERY_NOTEPAD_REG(hkey, value_iWindowPosY, Globals.iWindowPosY); QUERY_NOTEPAD_REG(hkey, value_iWindowPosY, main_rect.top);
QUERY_NOTEPAD_REG(hkey, value_iWindowPosDX, Globals.iWindowPosDX); QUERY_NOTEPAD_REG(hkey, value_iWindowPosDX, dx);
QUERY_NOTEPAD_REG(hkey, value_iWindowPosDY, Globals.iWindowPosDY); QUERY_NOTEPAD_REG(hkey, value_iWindowPosDY, dy);
QUERY_NOTEPAD_REG(hkey, value_lfCharSet, Globals.lfFont.lfCharSet); QUERY_NOTEPAD_REG(hkey, value_lfCharSet, Globals.lfFont.lfCharSet);
QUERY_NOTEPAD_REG(hkey, value_lfClipPrecision, Globals.lfFont.lfClipPrecision); QUERY_NOTEPAD_REG(hkey, value_lfClipPrecision, Globals.lfFont.lfClipPrecision);
QUERY_NOTEPAD_REG(hkey, value_lfEscapement, Globals.lfFont.lfEscapement); QUERY_NOTEPAD_REG(hkey, value_lfEscapement, Globals.lfFont.lfEscapement);
...@@ -209,6 +204,9 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void) ...@@ -209,6 +204,9 @@ static VOID NOTEPAD_LoadSettingFromRegistry(void)
QUERY_NOTEPAD_REG(hkey, value_lfWeight, Globals.lfFont.lfWeight); QUERY_NOTEPAD_REG(hkey, value_lfWeight, Globals.lfFont.lfWeight);
#undef QUERY_NOTEPAD_REG #undef QUERY_NOTEPAD_REG
main_rect.right = main_rect.left + dx;
main_rect.bottom = main_rect.top + dy;
size = sizeof(DWORD); size = sizeof(DWORD);
if(RegQueryValueEx(hkey, value_iPointSize, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS) if(RegQueryValueEx(hkey, value_iPointSize, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS)
if(type == REG_DWORD) if(type == REG_DWORD)
...@@ -593,6 +591,9 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show) ...@@ -593,6 +591,9 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
MSG msg; MSG msg;
HACCEL hAccel; HACCEL hAccel;
WNDCLASSEX class; WNDCLASSEX class;
HMONITOR monitor;
MONITORINFO info;
INT x, y;
static const WCHAR className[] = {'N','o','t','e','p','a','d',0}; static const WCHAR className[] = {'N','o','t','e','p','a','d',0};
static const WCHAR winName[] = {'N','o','t','e','p','a','d',0}; static const WCHAR winName[] = {'N','o','t','e','p','a','d',0};
...@@ -616,10 +617,21 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show) ...@@ -616,10 +617,21 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
/* Setup windows */ /* Setup windows */
monitor = MonitorFromRect( &main_rect, MONITOR_DEFAULTTOPRIMARY );
info.cbSize = sizeof(info);
GetMonitorInfoW( monitor, &info );
x = main_rect.left;
y = main_rect.top;
if (main_rect.left >= info.rcWork.right ||
main_rect.top >= info.rcWork.bottom ||
main_rect.right < info.rcWork.left ||
main_rect.bottom < info.rcWork.top)
x = y = CW_USEDEFAULT;
Globals.hMainWnd = Globals.hMainWnd =
CreateWindow(className, winName, WS_OVERLAPPEDWINDOW, CreateWindow(className, winName, WS_OVERLAPPEDWINDOW, x, y,
Globals.iWindowPosX, Globals.iWindowPosY, main_rect.right - main_rect.left, main_rect.bottom - main_rect.top,
Globals.iWindowPosDX, Globals.iWindowPosDY,
NULL, NULL, Globals.hInstance, NULL); NULL, NULL, Globals.hInstance, NULL);
if (!Globals.hMainWnd) if (!Globals.hMainWnd)
{ {
......
...@@ -45,11 +45,6 @@ typedef struct ...@@ -45,11 +45,6 @@ typedef struct
WCHAR szHeader[MAX_PATH]; WCHAR szHeader[MAX_PATH];
WCHAR szFooter[MAX_PATH]; WCHAR szFooter[MAX_PATH];
INT iWindowPosX;
INT iWindowPosY;
INT iWindowPosDX;
INT iWindowPosDY;
FINDREPLACE find; FINDREPLACE find;
FINDREPLACE lastFind; FINDREPLACE lastFind;
HGLOBAL hDevMode; /* printer mode */ HGLOBAL hDevMode; /* printer mode */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment