diff --git a/language/common_res.h b/language/common_res.h index 9bf21ce1e..7628fa0f4 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -312,7 +312,7 @@ #define CMD_JUMP2SELEND 20036 #define CMD_COPYPATHNAME 20037 #define CMD_COPYWINPOS 20038 -#define CMD_DEFAULTWINPOS 20039 +#define CMD_INITIALWINPOS 20039 #define CMD_OPENINIFILE 20040 #define CMD_CTRLENTER 20041 #define CMD_OPEN_HYPERLINK 20042 @@ -323,6 +323,8 @@ #define CMD_TAB 20047 #define CMD_BACKTAB 20048 #define CMD_VK_INSERT 20049 +#define CMD_FULLSCRWINPOS 20050 +#define CMD_DEFAULTWINPOS 20051 #define IDM_FILE_NEW 40000 #define IDM_FILE_OPEN 40001 diff --git a/language/np3_af_za/menu_af_za.rc b/language/np3_af_za/menu_af_za.rc index 2930eb51f..8b37b4a46 100644 Binary files a/language/np3_af_za/menu_af_za.rc and b/language/np3_af_za/menu_af_za.rc differ diff --git a/language/np3_de_de/menu_de_de.rc b/language/np3_de_de/menu_de_de.rc index 4f57f1b88..8941cf2f8 100644 Binary files a/language/np3_de_de/menu_de_de.rc and b/language/np3_de_de/menu_de_de.rc differ diff --git a/language/np3_en_gb/menu_en_gb.rc b/language/np3_en_gb/menu_en_gb.rc index 19f07f88a..acc2a3822 100644 Binary files a/language/np3_en_gb/menu_en_gb.rc and b/language/np3_en_gb/menu_en_gb.rc differ diff --git a/language/np3_en_us/menu_en_us.rc b/language/np3_en_us/menu_en_us.rc index 09cdf5137..fe76a5d17 100644 Binary files a/language/np3_en_us/menu_en_us.rc and b/language/np3_en_us/menu_en_us.rc differ diff --git a/language/np3_es_es/menu_es_es.rc b/language/np3_es_es/menu_es_es.rc index 369dd7651..e2adfbda3 100644 Binary files a/language/np3_es_es/menu_es_es.rc and b/language/np3_es_es/menu_es_es.rc differ diff --git a/language/np3_fr_fr/menu_fr_fr.rc b/language/np3_fr_fr/menu_fr_fr.rc index 23e6b9777..fa84df95a 100644 Binary files a/language/np3_fr_fr/menu_fr_fr.rc and b/language/np3_fr_fr/menu_fr_fr.rc differ diff --git a/language/np3_ja_jp/menu_ja_jp.rc b/language/np3_ja_jp/menu_ja_jp.rc index 27de59cff..04841a1e3 100644 Binary files a/language/np3_ja_jp/menu_ja_jp.rc and b/language/np3_ja_jp/menu_ja_jp.rc differ diff --git a/language/np3_nl_nl/menu_nl_nl.rc b/language/np3_nl_nl/menu_nl_nl.rc index 13ea8b9bd..7dd0477c2 100644 Binary files a/language/np3_nl_nl/menu_nl_nl.rc and b/language/np3_nl_nl/menu_nl_nl.rc differ diff --git a/language/np3_zh_cn/menu_zh_cn.rc b/language/np3_zh_cn/menu_zh_cn.rc index 28179e986..fcce19b11 100644 Binary files a/language/np3_zh_cn/menu_zh_cn.rc and b/language/np3_zh_cn/menu_zh_cn.rc differ diff --git a/src/Dialogs.c b/src/Dialogs.c index 886817f9c..587b9e41b 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2647,8 +2647,77 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) } return wi; } +// ---------------------------------------------------------------------------- +//============================================================================= +// +// FitIntoMonitorWorkArea() +// +// +RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo) +{ + MONITORINFO mi; + ZeroMemory(&mi, sizeof(MONITORINFO)); + mi.cbSize = sizeof(MONITORINFO); + HMONITOR const hMonitor = MonitorFromRect(pRect, MONITOR_DEFAULTTONEAREST); + GetMonitorInfo(hMonitor, &mi); + + if (pWinInfo) { + pWinInfo->x += (mi.rcWork.left - mi.rcMonitor.left); + pWinInfo->y += (mi.rcWork.top - mi.rcMonitor.top); + + if (pWinInfo->x < mi.rcWork.left) { pWinInfo->x = mi.rcWork.left; } + if (pWinInfo->y < mi.rcWork.top) { pWinInfo->y = mi.rcWork.top; } + if ((pWinInfo->x + pWinInfo->cx) > mi.rcWork.right) { + pWinInfo->x -= (pWinInfo->x + pWinInfo->cx - mi.rcWork.right); + if (pWinInfo->x < mi.rcWork.left) { pWinInfo->x = mi.rcWork.left; } + if ((pWinInfo->x + pWinInfo->cx) > mi.rcWork.right) { pWinInfo->cx = mi.rcWork.right - pWinInfo->x; } + } + if ((pWinInfo->y + pWinInfo->cy) > mi.rcWork.bottom) { + pWinInfo->y -= (pWinInfo->y + pWinInfo->cy - mi.rcWork.bottom); + if (pWinInfo->y < mi.rcWork.top) { pWinInfo->y = mi.rcWork.top; } + if ((pWinInfo->y + pWinInfo->cy) > mi.rcWork.bottom) { pWinInfo->cy = mi.rcWork.bottom - pWinInfo->y; } + } + SetRect(pRect, pWinInfo->x, pWinInfo->y, pWinInfo->x + pWinInfo->cx, pWinInfo->y + pWinInfo->cy); + } + + RECT rcPlacement; + rcPlacement.left = mi.rcMonitor.left; + rcPlacement.right = (mi.rcMonitor.left + (mi.rcWork.right - mi.rcWork.left)); + rcPlacement.top = mi.rcMonitor.top; + rcPlacement.bottom = (mi.rcMonitor.top + (mi.rcWork.bottom - mi.rcWork.top)); + return rcPlacement; +} +// ---------------------------------------------------------------------------- + + +//============================================================================= +// +// WindowPlacementFromInfo() +// +// +WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* const pWinInfo) +{ + WINDOWPLACEMENT wndpl; + ZeroMemory(&wndpl, sizeof(WINDOWPLACEMENT)); + wndpl.length = sizeof(WINDOWPLACEMENT); + wndpl.flags = WPF_ASYNCWINDOWPLACEMENT; + wndpl.showCmd = SW_RESTORE; + if (pWinInfo) { + wndpl.rcNormalPosition.left = pWinInfo->x; + wndpl.rcNormalPosition.top = pWinInfo->y; + wndpl.rcNormalPosition.right = pWinInfo->x + pWinInfo->cx; + wndpl.rcNormalPosition.bottom = pWinInfo->y + pWinInfo->cy; + if (pWinInfo->max) { wndpl.flags &= WPF_RESTORETOMAXIMIZED; } + } + else { + RECT rc; GetWindowRect(hwnd, &rc); + wndpl.rcNormalPosition = FitIntoMonitorWorkArea(&rc, NULL); + } + return wndpl; +} + //============================================================================= // @@ -3051,41 +3120,6 @@ void SetDlgPos(HWND hDlg, int xDlg, int yDlg) SetWindowPos(hDlg, NULL, max(xMin, min(xMax, x)), max(yMin, min(yMax, y)), 0, 0, SWP_NOZORDER | SWP_NOSIZE); } -/* - -... only if we are working with nonstandard dialog boxes ... - -//============================================================================= -// -// SnapToDefaultButton() -// -// Why doesn't the "Automatically move pointer to the default button in a dialog box" -// work for nonstandard dialog boxes, and how do I add it to my own nonstandard dialog boxes? -// https://blogs.msdn.microsoft.com/oldnewthing/20130826-00/?p=3413/ -// -void SnapToDefaultButton(HWND hwndBox) -{ -bool bSnapToDefButton = false; -if (SystemParametersInfo(SPI_GETSNAPTODEFBUTTON, 0, &bSnapToDefButton, 0) && bSnapToDefButton) { -// get child window at the top of the Z order. -// for all our MessageBoxs it's the OK or YES button or NULL. -HWND btn = GetWindow(hwndBox, GW_CHILD); -if (btn != NULL) { -WCHAR className[32] = L""; -GetClassName(btn, className, COUNTOF(className)); -if (lstrcmpi(className, L"Button") == 0) { -RECT rect; -int x, y; -GetWindowRect(btn, &rect); -x = rect.left + (rect.right - rect.left) / 2; -y = rect.top + (rect.bottom - rect.top) / 2; -SetCursorPos(x, y); -} -} -} -} -*/ - //============================================================================= // diff --git a/src/Dialogs.h b/src/Dialogs.h index b7dbf1e50..24ee4f1fa 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -38,6 +38,8 @@ bool RecodeDlg(HWND,int *); bool SelectDefLineEndingDlg(HWND,int *); WININFO GetMyWindowPlacement(HWND,MONITORINFO *); +RECT FitIntoMonitorWorkArea(RECT*, WININFO*); +WINDOWPLACEMENT WindowPlacementFromInfo(HWND, const WININFO* const); void DialogNewWindow(HWND,bool,bool); void DialogFileBrowse(HWND); diff --git a/src/Helpers.c b/src/Helpers.c index b42078374..72e28dcb5 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -2156,8 +2156,7 @@ static VOID GetTrayWndRect(LPRECT lpTrayRect) return; } - // OK. Haven't found a thing. Provide a default rect based on the current work - // area + // OK. Haven't found a thing. Provide a default rect based on the current work area SystemParametersInfo(SPI_GETWORKAREA,0,lpTrayRect,0); lpTrayRect->left=lpTrayRect->right-DEFAULT_RECT_WIDTH; lpTrayRect->top=lpTrayRect->bottom-DEFAULT_RECT_HEIGHT; diff --git a/src/Helpers.h b/src/Helpers.h index 4098b8e31..c394b2660 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -97,7 +97,6 @@ inline int float2int(float f) { return (int)lroundf(f); } inline float Round10th(float f) { return (float)float2int(f * 10.0f) / 10; } inline bool HasNonZeroFraction(float f) { return ((float2int(f * 10.0f) % 10) != 0); } - // direct heap allocation inline LPVOID AllocMem(size_t numBytes, DWORD dwFlags) { return HeapAlloc(GetProcessHeap(), (dwFlags | HEAP_GENERATE_EXCEPTIONS), numBytes); diff --git a/src/Notepad3.c b/src/Notepad3.c index a43a62ee6..4a39e9c4b 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -274,7 +274,6 @@ const int FontQuality[4] = { }; - static WININFO g_WinInfo = INIT_WININFO; static int g_WinCurrentWidth = 0; @@ -989,18 +988,25 @@ void EndWaitCursor() // _InitWindowPosition() // // -static void __fastcall _InitWindowPosition(HWND hwnd) +static RECT __fastcall _InitDefaultWndPos() +{ + RECT rc = { CW_USEDEFAULT, CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT }; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + rc = FitIntoMonitorWorkArea(&rc, NULL); + g_WinInfo.y = rc.top + 16; + g_WinInfo.cy = rc.bottom - rc.top - 32; + g_WinInfo.cx = (rc.right - rc.left) / 2; //min(rc.right - rc.left - 32, g_WinInfo.cy); + g_WinInfo.x = rc.right - g_WinInfo.cx - 16; + return rc; +} + +static void __fastcall _InitWindowPosition() { RECT rc; - if (hwnd) { - GetWindowRect(hwnd, &rc); - } - else { - rc.left = g_WinInfo.x; - rc.top = g_WinInfo.y; - rc.right = g_WinInfo.x + g_WinInfo.cx; - rc.bottom = g_WinInfo.y + g_WinInfo.cy; - } + rc.left = g_WinInfo.x; + rc.top = g_WinInfo.y; + rc.right = g_WinInfo.x + g_WinInfo.cx; + rc.bottom = g_WinInfo.y + g_WinInfo.cy; if (g_flagDefaultPos == 1) { @@ -1011,6 +1017,7 @@ static void __fastcall _InitWindowPosition(HWND hwnd) else if (g_flagDefaultPos >= 4) { SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + rc = FitIntoMonitorWorkArea(&rc, NULL); if (g_flagDefaultPos & 8) g_WinInfo.x = (rc.right - rc.left) / 2; else @@ -1038,55 +1045,29 @@ static void __fastcall _InitWindowPosition(HWND hwnd) g_WinInfo.cy -= (g_flagDefaultPos & (16 | 32)) ? 12 : 16; g_WinInfo.max = 1; g_WinInfo.zoom = 0; - } } else if (g_flagDefaultPos == 2 || g_flagDefaultPos == 3) // NP3 default window position { - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - g_WinInfo.y = rc.top + 16; - g_WinInfo.cy = rc.bottom - rc.top - 32; - g_WinInfo.cx = (rc.right - rc.left)/2; //min(rc.right - rc.left - 32, g_WinInfo.cy); - g_WinInfo.x = (g_flagDefaultPos == 3) ? rc.left + 16 : rc.right - g_WinInfo.cx - 16; + //SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + //rc = FitIntoMonitorWorkArea(&rc, NULL); + //g_WinInfo.y = rc.top + 16; + //g_WinInfo.cy = rc.bottom - rc.top - 32; + //g_WinInfo.cx = (rc.right - rc.left)/2; //min(rc.right - rc.left - 32, g_WinInfo.cy); + //g_WinInfo.x = (g_flagDefaultPos == 3) ? rc.left + 16 : rc.right - g_WinInfo.cx - 16; + rc = _InitDefaultWndPos(); + if (g_flagDefaultPos == 3) { g_WinInfo.x = rc.left + 16; } } else { // fit window into working area of current monitor - - MONITORINFO mi; - mi.cbSize = sizeof(mi); - HMONITOR hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); - GetMonitorInfo(hMonitor, &mi); - - g_WinInfo.x += (mi.rcWork.left - mi.rcMonitor.left); - g_WinInfo.y += (mi.rcWork.top - mi.rcMonitor.top); - if (g_WinInfo.x < mi.rcWork.left) - g_WinInfo.x = mi.rcWork.left; - if (g_WinInfo.y < mi.rcWork.top) - g_WinInfo.y = mi.rcWork.top; - if (g_WinInfo.x + g_WinInfo.cx > mi.rcWork.right) { - g_WinInfo.x -= (g_WinInfo.x + g_WinInfo.cx - mi.rcWork.right); - if (g_WinInfo.x < mi.rcWork.left) - g_WinInfo.x = mi.rcWork.left; - if (g_WinInfo.x + g_WinInfo.cx > mi.rcWork.right) - g_WinInfo.cx = mi.rcWork.right - g_WinInfo.x; - } - if (g_WinInfo.y + g_WinInfo.cy > mi.rcWork.bottom) { - g_WinInfo.y -= (g_WinInfo.y + g_WinInfo.cy - mi.rcWork.bottom); - if (g_WinInfo.y < mi.rcWork.top) - g_WinInfo.y = mi.rcWork.top; - if (g_WinInfo.y + g_WinInfo.cy > mi.rcWork.bottom) - g_WinInfo.cy = mi.rcWork.bottom - g_WinInfo.y; - } - SetRect(&rc, g_WinInfo.x, g_WinInfo.y, g_WinInfo.x + g_WinInfo.cx, g_WinInfo.y + g_WinInfo.cy); - + RECT rcWork = FitIntoMonitorWorkArea(&rc, &g_WinInfo); RECT rc2; - if (!IntersectRect(&rc2, &rc, &mi.rcWork)) { - g_WinInfo.y = mi.rcWork.top + 16; - g_WinInfo.cy = mi.rcWork.bottom - mi.rcWork.top - 32; - g_WinInfo.cx = min(mi.rcWork.right - mi.rcWork.left - 32, g_WinInfo.cy); - g_WinInfo.x = mi.rcWork.right - g_WinInfo.cx - 16; + if (!IntersectRect(&rc2, &rc, &rcWork)) { + g_WinInfo.y = rcWork.top + 16; + g_WinInfo.cy = rcWork.bottom - rcWork.top - 32; + g_WinInfo.cx = min(rcWork.right - rcWork.left - 32, g_WinInfo.cy); + g_WinInfo.x = rcWork.right - g_WinInfo.cx - 16; } } - g_WinCurrentWidth = g_WinInfo.cx; } @@ -1099,10 +1080,7 @@ static void __fastcall _InitWindowPosition(HWND hwnd) HWND InitInstance(HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow) { UNUSED(pszCmdLine); - - g_hwndMain = NULL; - - _InitWindowPosition(g_hwndMain); + _InitWindowPosition(); g_hwndMain = CreateWindowEx( 0, @@ -1124,6 +1102,7 @@ HWND InitInstance(HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow) if ((bAlwaysOnTop || g_flagAlwaysOnTop == 2) && g_flagAlwaysOnTop != 1) { SetWindowPos(g_hwndMain, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } + if (bTransparentMode) { SetWindowTransparentMode(g_hwndMain, true); } @@ -1143,6 +1122,8 @@ HWND InitInstance(HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow) ShowNotifyIcon(g_hwndMain,true); } + //SnapToWinInfoPos(g_hwndMain, false); + // Source Encoding if (lpEncodingArg) Encoding_SrcCmdLn(Encoding_MatchW(lpEncodingArg)); @@ -4913,15 +4894,9 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; case IDM_VIEW_TOOLBAR: - if (bShowToolbar) { - bShowToolbar = 0; - ShowWindow(g_hwndReBar,SW_HIDE); - } - else { - bShowToolbar = 1; - UpdateToolbar(); - ShowWindow(g_hwndReBar,SW_SHOW); - } + bShowToolbar = !bShowToolbar; + ShowWindow(g_hwndReBar, (bShowToolbar ? SW_SHOW : SW_HIDE)); + UpdateToolbar(); SendWMSize(hwnd, NULL); break; @@ -4934,17 +4909,10 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) SendMessage(g_hwndToolbar,TB_CUSTOMIZE,0,0); break; - case IDM_VIEW_STATUSBAR: - if (bShowStatusbar) { - bShowStatusbar = 0; - ShowWindow(g_hwndStatus,SW_HIDE); - } - else { - bShowStatusbar = 1; - UpdateStatusbar(false); - ShowWindow(g_hwndStatus,SW_SHOW); - } + bShowStatusbar = !bShowStatusbar; + ShowWindow(g_hwndStatus, (bShowStatusbar ? SW_SHOW : SW_HIDE)); + UpdateStatusbar(bShowStatusbar); SendWMSize(hwnd, NULL); break; @@ -5353,20 +5321,20 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; - case CMD_LEXHTML: - Style_SetHTMLLexer(g_hwndEdit); - UpdateToolbar(); - UpdateStatusbar(false); - UpdateLineNumberWidth(); - break; + //case CMD_LEXHTML: + // Style_SetHTMLLexer(g_hwndEdit); + // UpdateToolbar(); + // UpdateStatusbar(false); + // UpdateLineNumberWidth(); + // break; - case CMD_LEXXML: - Style_SetXMLLexer(g_hwndEdit); - UpdateToolbar(); - UpdateStatusbar(false); - UpdateLineNumberWidth(); - break; + //case CMD_LEXXML: + // Style_SetXMLLexer(g_hwndEdit); + // UpdateToolbar(); + // UpdateStatusbar(false); + // UpdateLineNumberWidth(); + // break; case CMD_TIMESTAMPS: @@ -5612,8 +5580,17 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; + case CMD_INITIALWINPOS: + SnapToWinInfoPos(hwnd,false); + break; + + case CMD_FULLSCRWINPOS: + SnapToWinInfoPos(hwnd, true); + break; + case CMD_DEFAULTWINPOS: - SnapToDefaultPos(hwnd); + _InitDefaultWndPos(); + SnapToWinInfoPos(hwnd, false); break; @@ -6986,20 +6963,20 @@ void LoadSettings() StringCchPrintf(tchMaximized, COUNTOF(tchMaximized), L"%ix%i Maximized", ResX, ResY); StringCchPrintf(tchZoom, COUNTOF(tchZoom), L"%ix%i Zoom", ResX, ResY); - g_WinInfo.x = IniSectionGetInt(pIniSection, tchPosX, INT_MAX - 1); - g_WinInfo.y = IniSectionGetInt(pIniSection, tchPosY, INT_MAX - 1); - g_WinInfo.cx = IniSectionGetInt(pIniSection, tchSizeX, INT_MAX - 1); - g_WinInfo.cy = IniSectionGetInt(pIniSection, tchSizeY, INT_MAX - 1); + g_WinInfo.x = IniSectionGetInt(pIniSection, tchPosX, (INT_MAX >> 1)); + g_WinInfo.y = IniSectionGetInt(pIniSection, tchPosY, (INT_MAX >> 1)); + g_WinInfo.cx = IniSectionGetInt(pIniSection, tchSizeX, (INT_MAX >> 1)); + g_WinInfo.cy = IniSectionGetInt(pIniSection, tchSizeY, (INT_MAX >> 1)); g_WinInfo.max = IniSectionGetInt(pIniSection, tchMaximized, 0); - if (g_WinInfo.max) g_WinInfo.max = 1; + g_WinInfo.max = clampi(g_WinInfo.max, 0, 1); g_WinInfo.zoom = IniSectionGetInt(pIniSection, tchZoom, 0); + g_WinInfo.zoom = clampi(g_WinInfo.zoom, -10, 20); - - if (((g_WinInfo.x & ~CW_USEDEFAULT) == (INT_MAX - 1)) || - ((g_WinInfo.y & ~CW_USEDEFAULT) == (INT_MAX - 1)) || - ((g_WinInfo.cx & ~CW_USEDEFAULT) == (INT_MAX - 1)) || - ((g_WinInfo.cy & ~CW_USEDEFAULT) == (INT_MAX - 1))) { - g_flagDefaultPos = 2; + if (((g_WinInfo.x & ~CW_USEDEFAULT) == (INT_MAX >> 1)) || + ((g_WinInfo.y & ~CW_USEDEFAULT) == (INT_MAX >> 1)) || + ((g_WinInfo.cx & ~CW_USEDEFAULT) == (INT_MAX >> 1)) || + ((g_WinInfo.cy & ~CW_USEDEFAULT) == (INT_MAX >> 1))) { + g_flagDefaultPos = 2; // std. default position (CmdLn: /pd) } } @@ -7419,7 +7396,6 @@ void ParseCommandLine() if (itok == 4 || itok == 5) { // scan successful g_flagPosParam = 1; g_flagDefaultPos = 0; - if (g_WinInfo.cx < 1) g_WinInfo.cx = CW_USEDEFAULT; if (g_WinInfo.cy < 1) g_WinInfo.cy = CW_USEDEFAULT; if (g_WinInfo.max) g_WinInfo.max = 1; @@ -10077,37 +10053,50 @@ bool RelaunchElevated(LPWSTR lpArgs) { //============================================================================= // -// SnapToDefaultPos() -// +// SnapToWinInfoPos() // Aligns Notepad3 to the default window position on the current screen // -// -void SnapToDefaultPos(HWND hwnd) -{ - RECT rcOld; GetWindowRect(hwnd, &rcOld); - - RECT rc; SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - - g_flagDefaultPos = 2; - _InitWindowPosition(hwnd); +void SnapToWinInfoPos(HWND hwnd, bool bFullWorkArea) +{ + static WINDOWPLACEMENT s_wndplPrev; + static bool s_bPrevFullWAFlag = false; + static bool s_bPrevShowToolbar = true; + static bool s_bPrevShowStatusbar = true; WINDOWPLACEMENT wndpl; - ZeroMemory(&wndpl, sizeof(WINDOWPLACEMENT)); - wndpl.length = sizeof(WINDOWPLACEMENT); - wndpl.flags = WPF_ASYNCWINDOWPLACEMENT; - wndpl.showCmd = SW_RESTORE; + RECT rcCurrent; GetWindowRect(hwnd, &rcCurrent); - wndpl.rcNormalPosition.left = g_WinInfo.x - rc.left; - wndpl.rcNormalPosition.top = g_WinInfo.y - rc.top; - wndpl.rcNormalPosition.right = g_WinInfo.x - rc.left + g_WinInfo.cx; - wndpl.rcNormalPosition.bottom = g_WinInfo.y - rc.top + g_WinInfo.cy; + if (bFullWorkArea) { + if (s_bPrevFullWAFlag) { // snap to previous rect + bShowToolbar = s_bPrevShowToolbar; + bShowStatusbar = s_bPrevShowStatusbar; + wndpl = s_wndplPrev; + } + else { + GetWindowPlacement(hwnd, &s_wndplPrev); + s_bPrevShowToolbar = bShowToolbar; + s_bPrevShowStatusbar = bShowStatusbar; + bShowToolbar = bShowStatusbar = false; + wndpl = WindowPlacementFromInfo(hwnd, NULL); + } + s_bPrevFullWAFlag = !s_bPrevFullWAFlag; + } + else { + wndpl = WindowPlacementFromInfo(hwnd, &g_WinInfo); + s_bPrevFullWAFlag = false; + } if (GetDoAnimateMinimize()) { - DrawAnimatedRects(hwnd,IDANI_CAPTION,&rcOld,&wndpl.rcNormalPosition); + DrawAnimatedRects(hwnd, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition); //OffsetRect(&wndpl.rcNormalPosition,mi.rcMonitor.left - mi.rcWork.left,mi.rcMonitor.top - mi.rcWork.top); } - SetWindowPlacement(hwnd,&wndpl); + + SetWindowPlacement(hwnd, &wndpl); SciCall_SetZoom(g_WinInfo.zoom); + + UpdateToolbar(); + UpdateStatusbar(true); + UpdateLineNumberWidth(); } diff --git a/src/Notepad3.h b/src/Notepad3.h index c72d78b66..3252c46f9 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -116,7 +116,7 @@ void EndWaitCursor(); bool ActivatePrevInst(); bool RelaunchMultiInst(); bool RelaunchElevated(LPWSTR); -void SnapToDefaultPos(HWND); +void SnapToWinInfoPos(HWND,bool); void ShowNotifyIcon(HWND,bool); void SetNotifyIconTitle(HWND); void InstallFileWatching(LPCWSTR); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 0dcfed460..58dc3ccc3 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -212,9 +212,10 @@ BEGIN VK_ESCAPE, CMD_SHIFTESC, VIRTKEY, SHIFT, NOINVERT VK_F1, IDM_HELP_ONLINEDOCUMENTATION, VIRTKEY, NOINVERT VK_F1, IDM_HELP_ABOUT, VIRTKEY, SHIFT, NOINVERT - VK_F11, CMD_LEXDEFAULT, VIRTKEY, NOINVERT - VK_F11, CMD_LEXHTML, VIRTKEY, CONTROL, NOINVERT - VK_F11, CMD_LEXXML, VIRTKEY, SHIFT, NOINVERT + VK_F11, CMD_FULLSCRWINPOS, VIRTKEY, NOINVERT + VK_F11, CMD_INITIALWINPOS, VIRTKEY, CONTROL, NOINVERT + //VK_F11, CMD_LEXHTML, VIRTKEY, CONTROL, NOINVERT + VK_F11, CMD_LEXDEFAULT, VIRTKEY, SHIFT, NOINVERT VK_F12, IDM_VIEW_SCHEME, VIRTKEY, NOINVERT VK_F12, IDM_VIEW_SCHEMECONFIG, VIRTKEY, CONTROL, NOINVERT VK_F12, IDM_VIEW_FONT, VIRTKEY, ALT, NOINVERT diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 2054a6356..578f1304b 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -63,6 +63,22 @@ typedef struct _wi #define INIT_WININFO { CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0 } +inline WININFO _GetWinInfo(HWND hwnd, int max, int zoom) +{ + WININFO winfo = INIT_WININFO; + RECT rc; GetWindowRect(hwnd, &rc); + winfo.x = rc.left; + winfo.y = rc.top; + winfo.cx = rc.right - rc.left; + winfo.cy = rc.bottom - rc.top; + winfo.max = max; + winfo.zoom = zoom; + return winfo; +} +// ---------------------------------------------------------------------------- + + + // -------------------------------------------------------------------------- typedef enum BufferSizes