From 0ce3ad8d80f537a3eb592f4c819c50d65bd0aaa0 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 29 Aug 2018 08:56:59 +0200 Subject: [PATCH 1/7] + add: increased build env version + refactoring: C++ code cleanup for MiniPath DropSource --- minipath/minipath.vcxproj | 4 +- minipath/minipath.vcxproj.filters | 12 ++-- .../src/{Dropsource.cpp => DropSource.cpp} | 63 +++++++----------- minipath/src/{Dropsource.h => DropSource.h} | 28 ++++---- src/Version.h | Bin 12854 -> 12854 bytes 5 files changed, 47 insertions(+), 60 deletions(-) rename minipath/src/{Dropsource.cpp => DropSource.cpp} (74%) rename minipath/src/{Dropsource.h => DropSource.h} (64%) diff --git a/minipath/minipath.vcxproj b/minipath/minipath.vcxproj index e625fee38..0f2c18e5a 100644 --- a/minipath/minipath.vcxproj +++ b/minipath/minipath.vcxproj @@ -265,7 +265,7 @@ - + @@ -273,7 +273,7 @@ - + diff --git a/minipath/minipath.vcxproj.filters b/minipath/minipath.vcxproj.filters index 0ef64d0a7..b7d5236ca 100644 --- a/minipath/minipath.vcxproj.filters +++ b/minipath/minipath.vcxproj.filters @@ -25,15 +25,15 @@ C/C++ Source Files - - C/C++ Source Files - C/C++ Source Files C/C++ Source Files + + C/C++ Source Files + @@ -42,9 +42,6 @@ H Source Files - - H Source Files - H Source Files @@ -60,6 +57,9 @@ H Source Files + + H Source Files + diff --git a/minipath/src/Dropsource.cpp b/minipath/src/DropSource.cpp similarity index 74% rename from minipath/src/Dropsource.cpp rename to minipath/src/DropSource.cpp index ffcc44ad5..b4661a347 100644 --- a/minipath/src/Dropsource.cpp +++ b/minipath/src/DropSource.cpp @@ -6,6 +6,7 @@ * Dropsource.cpp * * OLE drop source functionality * * Based on code from metapath, (c) Florian Balmer 1996-2011 * +* and ZuFu Liu * * * * (c) Rizonesoft 2008-2016 * * https://rizonesoft.com * @@ -15,88 +16,70 @@ #define _WIN32_WINNT 0x601 #include //#include -#include "helpers.h" -#include "dropsource.h" - +#include "DropSource.h" /****************************************************************************** * * IUnknown Implementation * ******************************************************************************/ -STDMETHODIMP CDropSource::QueryInterface(REFIID iid, void FAR* FAR* ppv) -{ - if (iid == IID_IUnknown || iid == IID_IDropSource) - { +STDMETHODIMP CDropSource::QueryInterface(REFIID iid, PVOID *ppv) noexcept { + if (iid == IID_IUnknown || iid == IID_IDropSource) { *ppv = this; - ++m_refs; + AddRef(); return NOERROR; } - *ppv = NULL; + *ppv = nullptr; return E_NOINTERFACE; } - -STDMETHODIMP_(ULONG) CDropSource::AddRef() -{ +STDMETHODIMP_(ULONG) CDropSource::AddRef() noexcept { return ++m_refs; } - -STDMETHODIMP_(ULONG) CDropSource::Release() -{ - if(--m_refs == 0) - { +STDMETHODIMP_(ULONG) CDropSource::Release() noexcept { + const ULONG refs = --m_refs; + if (refs == 0) { delete this; - return 0; } - return m_refs; + return refs; } - /****************************************************************************** * * CDropSource Constructor * ******************************************************************************/ -CDropSource::CDropSource() -{ +CDropSource::CDropSource() noexcept { m_refs = 1; } - /****************************************************************************** * * IDropSource Implementation * ******************************************************************************/ -STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEscapePressed, - DWORD grfKeyState) -{ - if (fEscapePressed) +STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState) noexcept { + if (fEscapePressed) { return DRAGDROP_S_CANCEL; - - else if (!(grfKeyState & MK_LBUTTON) && !(grfKeyState & MK_RBUTTON)) + } + if (!(grfKeyState & MK_LBUTTON) && !(grfKeyState & MK_RBUTTON)) { return DRAGDROP_S_DROP; - - else - return NOERROR; + } + return NOERROR; } - -STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect) -{ +STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect) noexcept { UNUSED(dwEffect); return DRAGDROP_S_USEDEFAULTCURSORS; } - extern "C" { -LPDROPSOURCE CreateDropSource() -{ + +LPDROPSOURCE CreateDropSource(void) { return ((LPDROPSOURCE) new CDropSource); } + } - -// End of Dropsource.cpp +// End of DropSource.cpp diff --git a/minipath/src/Dropsource.h b/minipath/src/DropSource.h similarity index 64% rename from minipath/src/Dropsource.h rename to minipath/src/DropSource.h index cfdc6e226..e6f237e7d 100644 --- a/minipath/src/Dropsource.h +++ b/minipath/src/DropSource.h @@ -6,6 +6,7 @@ * Dropsource.h * * OLE drop source functionality * * Based on code from metapath, (c) Florian Balmer 1996-2011 * +* and ZuFu Liu * * * * (c) Rizonesoft 2008-2016 * * https://rizonesoft.com * @@ -13,25 +14,28 @@ * * *******************************************************************************/ -class FAR CDropSource : public IDropSource -{ +#ifndef METAPATH_DROPSOURCE_H_ +#define METAPATH_DROPSOURCE_H_ +class CDropSource : public IDropSource { public: - CDropSource(); + CDropSource() noexcept; + virtual ~CDropSource() = default; - /* IUnknown methods */ - STDMETHOD(QueryInterface)(REFIID riid,void FAR* FAR* ppvObj); - STDMETHOD_(ULONG,AddRef)(); - STDMETHOD_(ULONG,Release)(); + /* IUnknown methods */ + STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppv) noexcept override; + STDMETHODIMP_(ULONG)AddRef() noexcept override; + STDMETHODIMP_(ULONG)Release() noexcept override; - /* IDropSource methods */ - STDMETHOD(QueryContinueDrag)(BOOL fEscapePressed,DWORD grfKeyState); - STDMETHOD(GiveFeedback)(DWORD dwEffect); + /* IDropSource methods */ + STDMETHODIMP QueryContinueDrag(BOOL fEsc, DWORD grfKeyState) noexcept override; + STDMETHODIMP GiveFeedback(DWORD) noexcept override; private: - ULONG m_refs; - + ULONG m_refs; }; +#endif // METAPATH_DROPSOURCE_H_ + // End of Dropsource.h diff --git a/src/Version.h b/src/Version.h index fea965114a920fe7888d9b23694e15e3f8eba89c..d6aeff01237ba70b2637c93f9203fafab636f9ff 100644 GIT binary patch delta 16 Xcmdm%vMpsph2-Q8#hA@kB$FfnLna3( delta 16 Ycmdm%vMpsph2-RCvN4;lNG3@D07d!-f&c&j From e8f1d59599722735b2a2a2633972ca983f7fead2 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 29 Aug 2018 17:03:41 +0200 Subject: [PATCH 2/7] + fix: consider zoom level for margins --- language/common_res.h | 7 +++++-- minipath/language/common_res.h | 9 +++++++++ minipath/src/DropSource.cpp | 3 +-- minipath/src/DropSource.h | 1 - scintilla/win32/PlatWin.cxx | 2 +- src/Helpers.h | 2 ++ src/Notepad3.c | 18 +++++++++++++++++- src/Styles.c | 11 +++++++---- 8 files changed, 42 insertions(+), 11 deletions(-) diff --git a/language/common_res.h b/language/common_res.h index ecb015a05..9bf21ce1e 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -346,6 +346,7 @@ #define IDM_FILE_MANAGEFAV 40019 #define IDM_FILE_RECENT 40020 #define IDM_FILE_EXIT 40021 + #define IDM_ENCODING_ANSI 40100 #define IDM_ENCODING_UNICODE 40101 #define IDM_ENCODING_UNICODEREV 40102 @@ -366,6 +367,7 @@ #define BME_EDIT_BOOKMARKNEXT 40255 #define BME_EDIT_BOOKMARKCLEAR 40256 #define BME_EDIT_BOOKMARKPREV 40257 + #define IDM_EDIT_UNDO 40300 #define IDM_EDIT_REDO 40301 #define IDM_EDIT_CUT 40302 @@ -444,6 +446,7 @@ #define IDM_EDIT_REMOVEDUPLICATELINES 40375 #define IDM_EDIT_REMOVEEMPTYLINES 40376 #define IDM_EDIT_MERGEEMPTYLINES 40377 + #define IDM_VIEW_SCHEME 40400 #define IDM_VIEW_USE2NDDEFAULT 40401 #define IDM_VIEW_SCHEMECONFIG 40402 @@ -513,9 +516,11 @@ #define IDM_SET_BIDIRECTIONAL_NONE 40466 #define IDM_SET_BIDIRECTIONAL_L2R 40467 #define IDM_SET_BIDIRECTIONAL_R2L 40468 + #define IDM_HELP_ABOUT 40500 #define IDM_HELP_CMD 40501 #define IDM_HELP_ONLINEDOCUMENTATION 40502 + #define IDM_TRAY_RESTORE 40600 #define IDM_TRAY_EXIT 40601 #define IDM_SETPASS 40602 @@ -524,8 +529,6 @@ #define IDM_EDIT_INSERT_GUID 40605 - - #define IDS_ENC_ANSI 61000 #define IDS_ENC_OEM 61001 #define IDS_ENC_UTF16LEBOM 61002 diff --git a/minipath/language/common_res.h b/minipath/language/common_res.h index 4abd6dfe9..94b2b127a 100644 --- a/minipath/language/common_res.h +++ b/minipath/language/common_res.h @@ -105,11 +105,13 @@ #define IDC_TRANSL_AUTH 114 #define IDR_MAINWND48 200 + #define IDS_APPTITLE 10000 #define IDS_NUMFILES 10001 #define IDS_NUMFILES2 10002 #define IDS_SAVEFILE 10003 #define IDS_OPEN_FILE_WITH 10004 + #define IDS_SEARCHEXE 11000 #define IDS_GETQUICKVIEWER 11001 #define IDS_GETTARGET 11002 @@ -122,6 +124,7 @@ #define IDS_COPYMOVE 11009 #define IDS_CREATELINK 11010 #define IDS_SAVESETTINGS 11011 + #define IDM_FILE_OPEN 40001 #define IDM_FILE_OPENNEW 40002 #define IDM_FILE_RUN 40003 @@ -141,6 +144,7 @@ #define IDM_FILE_CHANGEDIR 40017 #define IDM_FILE_PROPERTIES 40018 #define IDM_FILE_DRIVEPROP 40019 + #define IDM_VIEW_NEWWINDOW 40201 #define IDM_VIEW_FOLDERS 40202 #define IDM_VIEW_FILES 40203 @@ -157,14 +161,17 @@ #define IDM_VIEW_SAVESETTINGS 40214 #define IDM_VIEW_FINDTARGET 40215 #define IDM_VIEW_OPTIONS 40216 + #define IDM_SORT_NAME 40301 #define IDM_SORT_SIZE 40302 #define IDM_SORT_TYPE 40303 #define IDM_SORT_DATE 40304 #define IDM_SORT_REVERSE 40305 + #define IDM_POP_COPYNAME 40501 #define IDM_TRAY_RESTORE 40601 #define IDM_TRAY_EXIT 40602 + #define ACC_ESCAPE 41001 #define ACC_NEXTCTL 41002 #define ACC_PREVCTL 41003 @@ -176,6 +183,7 @@ #define ACC_SNAPTOTARGET 41009 #define ACC_DEFAULTWINPOS 41010 #define ACC_SELECTINIFILE 41011 + #define IDT_HISTORY_BACK 42001 #define IDT_HISTORY_FORWARD 42002 #define IDT_UPDIR 42003 @@ -190,6 +198,7 @@ #define IDT_FILE_DELETE 42012 #define IDT_FILE_DELETE2 42013 #define IDT_VIEW_FILTER 42014 + #define IDS_ERR_CD 50000 #define IDS_ERR_FILE 50001 #define IDS_ERR_NEW 50002 diff --git a/minipath/src/DropSource.cpp b/minipath/src/DropSource.cpp index b4661a347..f95af10b0 100644 --- a/minipath/src/DropSource.cpp +++ b/minipath/src/DropSource.cpp @@ -6,7 +6,6 @@ * Dropsource.cpp * * OLE drop source functionality * * Based on code from metapath, (c) Florian Balmer 1996-2011 * -* and ZuFu Liu * * * * (c) Rizonesoft 2008-2016 * * https://rizonesoft.com * @@ -70,7 +69,7 @@ STDMETHODIMP CDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeySta } STDMETHODIMP CDropSource::GiveFeedback(DWORD dwEffect) noexcept { - UNUSED(dwEffect); + (void)(dwEffect); return DRAGDROP_S_USEDEFAULTCURSORS; } diff --git a/minipath/src/DropSource.h b/minipath/src/DropSource.h index e6f237e7d..f1c03fbdf 100644 --- a/minipath/src/DropSource.h +++ b/minipath/src/DropSource.h @@ -6,7 +6,6 @@ * Dropsource.h * * OLE drop source functionality * * Based on code from metapath, (c) Florian Balmer 1996-2011 * -* and ZuFu Liu * * * * (c) Rizonesoft 2008-2016 * * https://rizonesoft.com * diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index d9a02e327..0c28dc30f 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -2274,7 +2274,7 @@ static RECT RectFromMonitor(HMONITOR hMonitor) { return mi.rcWork; } RECT rc = {0, 0, 0, 0}; - if (::SystemParametersInfoA(SPI_GETWORKAREA, 0, &rc, 0) == 0) { + if (::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0) == 0) { rc.left = 0; rc.top = 0; rc.right = 0; diff --git a/src/Helpers.h b/src/Helpers.h index cd84cb429..4098b8e31 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -186,6 +186,8 @@ bool SetClipboardTextW(HWND, LPCWSTR); UINT GetCurrentDPI(HWND hwnd); UINT GetCurrentPPI(HWND hwnd); HBITMAP ResizeImageForCurrentDPI(HBITMAP hbmp); +#define ScaleIntToCurrentDPI(val) MulDiv((val), g_uCurrentDPI, USER_DEFAULT_SCREEN_DPI) +inline int ScaleToCurrentDPI(float fVal) { return float2int((fVal * g_uCurrentDPI) / (float)USER_DEFAULT_SCREEN_DPI); } #define ScaleIntFontSize(val) MulDiv((val), g_uCurrentDPI, g_uCurrentPPI) inline int ScaleFontSize(float fSize) { return float2int((fSize * g_uCurrentDPI) / (float)g_uCurrentPPI); } inline int ScaleFractionalFontSize(float fSize) { return float2int((fSize * 10.0f * g_uCurrentDPI) / (float)g_uCurrentPPI) * 10; } diff --git a/src/Notepad3.c b/src/Notepad3.c index 1fb4769f1..394083093 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2711,6 +2711,22 @@ LRESULT MsgTrayMessage(HWND hwnd, WPARAM wParam, LPARAM lParam) } +static bool __fastcall _IsInlineIMEActive() +{ + bool result = false; + if (g_IMEInteraction) { + HIMC himc = ImmGetContext(g_hwndEdit); + if (himc) { + DWORD dwConversion = IME_CMODE_ALPHANUMERIC, dwSentence = 0; + if (ImmGetConversionStatus(himc, &dwConversion, &dwSentence)) { + result = !(dwConversion == IME_CMODE_ALPHANUMERIC); + } + ImmReleaseContext(g_hwndEdit, himc); + } + } + return result; +} + //============================================================================= // @@ -5973,7 +5989,7 @@ void OpenHotSpotURL(DocPos position, bool bForceBrowser) //============================================================================= // -// _HandleAutoCloseTags() +// _HandleAutoIndent() // static void __fastcall _HandleAutoIndent(int const charAdded) { // in CRLF mode handle LF only... diff --git a/src/Styles.c b/src/Styles.c index 70105840d..f1bc3924a 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -93,7 +93,7 @@ EDITLEXER lexStandard = { SCLEX_NULL, IDS_LEX_DEF_TXT, L"Default Text", L"txt; t /* 9 */ { SCI_SETCARETFORE+SCI_SETCARETWIDTH, IDS_LEX_STD_CARET, L"Caret (Color, Size 1-3)", L"", L"" }, /* 10 */ { SCI_SETEDGECOLOUR, IDS_LEX_STD_LONG_LN, L"Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { SCI_SETEXTRAASCENT+SCI_SETEXTRADESCENT, IDS_LEX_STD_X_SPC, L"Extra Line Spacing (Size)", L"size:2", L"" }, - /* 12 */ { SCI_FOLDALL+SCI_MARKERSETALPHA, IDS_LEX_STD_BKMRK, L"Bookmarks and Folding (Colors, Size)", L"size:+0; fore:#000000; back:#808080; alpha:80", L"" }, + /* 12 */ { SCI_FOLDALL+SCI_MARKERSETALPHA, IDS_LEX_STD_BKMRK, L"Bookmarks and Folding (Colors, Size)", L"size:+2; fore:#000000; back:#808080; alpha:80", L"" }, /* 13 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, IDS_LEX_STR_63262, L"Mark Occurrences (Indicator)", L"alpha:100; alpha2:100; indic_roundbox", L"" }, /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, IDS_LEX_STR_63264, L"Hyperlink Hotspots", L"italic; fore:#0000FF", L"" }, { -1, 00000, L"", L"", L"" } } }; @@ -112,7 +112,7 @@ EDITLEXER lexStandard2nd = { SCLEX_NULL, IDS_LEX_STR_63266, L"2nd Default Text", /* 9 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, IDS_LEX_2ND_CARET, L"2nd Caret (Color, Size 1-3)", L"", L"" }, /* 10 */ { SCI_SETEDGECOLOUR, IDS_LEX_2ND_LONG_LN, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, /* 11 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, IDS_LEX_2ND_X_SPC, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, IDS_LEX_2ND_BKMRK, L"2nd Bookmarks and Folding (Colors, Size)", L"size:+0; fore:#000000; back:#808080; alpha:80; charset:2; case:U", L"" }, + /* 12 */ { SCI_FOLDALL + SCI_MARKERSETALPHA, IDS_LEX_2ND_BKMRK, L"2nd Bookmarks and Folding (Colors, Size)", L"size:+2; fore:#000000; back:#808080; alpha:80; charset:2; case:U", L"" }, /* 13 */ { SCI_MARKERSETBACK + SCI_MARKERSETALPHA, IDS_LEX_STR_63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0x000000; alpha:100; alpha2:220; indic_box", L"" }, /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, IDS_LEX_STR_63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, { -1, 00000, L"", L"", L"" } } }; @@ -4122,8 +4122,9 @@ void Style_SetFolding(HWND hwnd, bool bShowCodeFolding) float fSize = _GetBaseFontSize(); Style_StrGetSize(GetCurrentStdLexer()->Styles[STY_MARGIN].szValue, &fSize); // relative to LineNumber Style_StrGetSize(GetCurrentStdLexer()->Styles[STY_BOOK_MARK].szValue, &fSize); + float const zoomPoints = (float)SciCall_GetZoom(); - int const iSizeDPI = ScaleFontSize(fSize + 3.0f); + int const iSizeDPI = ScaleToCurrentDPI(fSize + zoomPoints); SciCall_SetMarginWidthN(MARGIN_SCI_FOLDING, (bShowCodeFolding) ? iSizeDPI : 0); } @@ -4138,13 +4139,15 @@ void Style_SetBookmark(HWND hwnd, bool bShowSelMargin) float fSize = _GetBaseFontSize(); Style_StrGetSize(GetCurrentStdLexer()->Styles[STY_MARGIN].szValue, &fSize); // relative to LineNumber Style_StrGetSize(GetCurrentStdLexer()->Styles[STY_BOOK_MARK].szValue, &fSize); + float const zoomPoints = (float)SciCall_GetZoom(); - int const iSizeDPI = ScaleFontSize(fSize + 6.0f); + int const iSizeDPI = ScaleToCurrentDPI(fSize + zoomPoints); SciCall_SetMarginWidthN(MARGIN_SCI_BOOKMRK, (bShowSelMargin) ? iSizeDPI : 0); // Depending on if the margin is visible or not, choose different bookmark indication if (bShowSelMargin) { SciCall_MarkerDefine(MARKER_NP3_BOOKMARK, SC_MARK_BOOKMARK); + //SciCall_MarkerDefine(MARKER_NP3_BOOKMARK, SC_MARK_SHORTARROW); } else { SciCall_MarkerDefine(MARKER_NP3_BOOKMARK, SC_MARK_BACKGROUND); From 33faa03a8dda5f6d95c4e36b6cf654c0db283c55 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 30 Aug 2018 15:55:54 +0200 Subject: [PATCH 3/7] + fix: minor bug fixes and IME changes --- minipath/src/minipath.c | 4 ++-- scintilla/win32/ScintillaWin.cxx | 6 +++--- src/Edit.c | 11 ++++++----- src/Notepad3.c | 31 +++++++++++++++++-------------- src/SciCall.h | 10 ++++++++++ 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/minipath/src/minipath.c b/minipath/src/minipath.c index d9dcc76d1..0ec2d15b6 100644 --- a/minipath/src/minipath.c +++ b/minipath/src/minipath.c @@ -881,7 +881,7 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) else if (iCmd == IDM_TRAY_EXIT) { ShowNotifyIcon(hwnd,FALSE); - SendMessage(hwnd,WM_CLOSE,0,0); + PostMessage(hwnd,WM_CLOSE,0,0); } } return TRUE; @@ -2194,7 +2194,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) else if (iEscFunction == 1) SendMessage(hwnd,WM_SYSCOMMAND,SC_MINIMIZE,0); else if (iEscFunction == 2) - SendMessage(hwnd,WM_CLOSE,0,0); + PostMessage(hwnd,WM_CLOSE,0,0); break; diff --git a/scintilla/win32/ScintillaWin.cxx b/scintilla/win32/ScintillaWin.cxx index b22c823f4..51ca1248a 100644 --- a/scintilla/win32/ScintillaWin.cxx +++ b/scintilla/win32/ScintillaWin.cxx @@ -1679,7 +1679,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam break; case WM_IME_STARTCOMPOSITION: // dbcs - if (KoreanIME() || imeInteraction == imeInline) { + if (imeInteraction == imeInline) { return 0; } else { ImeStartComposition(); @@ -1691,7 +1691,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam); case WM_IME_COMPOSITION: - if (KoreanIME() || imeInteraction == imeInline) { + if (imeInteraction == imeInline) { return HandleCompositionInline(wParam, lParam); } else { return HandleCompositionWindowed(wParam, lParam); @@ -1730,7 +1730,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam return 0; case WM_IME_SETCONTEXT: - if (KoreanIME() || imeInteraction == imeInline) { + if (imeInteraction == imeInline) { if (wParam) { LPARAM NoImeWin = lParam; NoImeWin = NoImeWin & (~ISC_SHOWUICOMPOSITIONWINDOW); diff --git a/src/Edit.c b/src/Edit.c index 924e3b72d..d8b134871 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6682,11 +6682,12 @@ void EditCompleteWord(HWND hwnd, bool autoInsert) LocalFree(t); } SendMessage(hwnd, SCI_AUTOCSETIGNORECASE, 1, 0); - //SendMessage(hwnd, SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE, 1, 0); - SendMessage(hwnd, SCI_AUTOCSETSEPARATOR, ' ', 0); - SendMessage(hwnd, SCI_AUTOCSETFILLUPS, 0, (LPARAM)"\t\n\r"); - SendMessage(hwnd, SCI_AUTOCSETCHOOSESINGLE, autoInsert, 0); - SendMessage(hwnd, SCI_AUTOCSHOW, iRootLen, (LPARAM)(pList + 1)); + SciCall_AutoCSetIgnoreCase(true); + //SendMessage(hwnd, SCI_AUTOCSETCASEINSENSITIVEBEHAVIOUR, (WPARAM)SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE, 0); + SciCall_AutoCSetSeperator(' '); + SciCall_AutoCSetFillups("\t\n\r"); + SciCall_AutoCSetChooseSingle(autoInsert); + SciCall_AutoCShow(iRootLen, (pList + 1)); LocalFree(pList); } } diff --git a/src/Notepad3.c b/src/Notepad3.c index 394083093..a43a62ee6 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2689,10 +2689,9 @@ LRESULT MsgTrayMessage(HWND hwnd, WPARAM wParam, LPARAM lParam) RestoreWndFromTray(hwnd); ShowOwnedPopups(hwnd, true); } - else if (iCmd == IDM_TRAY_EXIT) { //ShowNotifyIcon(hwnd,false); - SendMessage(hwnd, WM_CLOSE, 0, 0); + PostMessage(hwnd, WM_CLOSE, 0, 0); } } break; @@ -3336,7 +3335,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_EXIT: - SendMessage(hwnd,WM_CLOSE,0,0); + PostMessage(hwnd,WM_CLOSE,0,0); break; @@ -4749,8 +4748,9 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_AUTOCOMPLETEWORDS: g_bAutoCompleteWords = (g_bAutoCompleteWords) ? false : true; // toggle - if (!g_bAutoCompleteWords) - SendMessage(g_hwndEdit, SCI_AUTOCCANCEL, 0, 0); // close the auto completion list + if (!g_bAutoCompleteWords) { + SciCall_AutoCCancel(); // close the auto completion list + } break; case IDM_VIEW_ACCELWORDNAV: @@ -5159,18 +5159,21 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case CMD_ESCAPE: //close the autocomplete box - SendMessage(g_hwndEdit,SCI_AUTOCCANCEL,0, 0); + SciCall_AutoCCancel(); - if (iEscFunction == 1) - SendMessage(hwnd,WM_SYSCOMMAND,SC_MINIMIZE,0); - else if (iEscFunction == 2) - SendMessage(hwnd,WM_CLOSE,0,0); + if (iEscFunction == 1) { + SendMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); + } + else if (iEscFunction == 2) { + PostMessage(hwnd, WM_CLOSE, 0, 0); + } break; case CMD_SHIFTESC: - if (FileSave(true,false,false,false)) - SendMessage(hwnd,WM_CLOSE,0,0); + if (FileSave(true, false, false, false)) { + PostMessage(hwnd, WM_CLOSE, 0, 0); + } break; @@ -5782,7 +5785,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDT_FILE_EXIT: - SendMessage(hwnd,WM_CLOSE,0,0); + PostMessage(hwnd,WM_CLOSE,0,0); break; @@ -6321,7 +6324,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) else if (scn->ch == '?') { _HandleTinyExpr(); } - else if (g_bAutoCompleteWords && !SendMessage(g_hwndEdit, SCI_AUTOCACTIVE, 0, 0)) { + else if (g_bAutoCompleteWords && !SciCall_AutoCActive() && !_IsInlineIMEActive()) { EditCompleteWord(g_hwndEdit, false); } } diff --git a/src/SciCall.h b/src/SciCall.h index 05298b8db..6b4c4589f 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -246,6 +246,16 @@ DeclareSciCallR2(GetCurLine, GETCURLINE, DocPos, unsigned int, length, const cha DeclareSciCallV1(SetVirtualSpaceOptions, SETVIRTUALSPACEOPTIONS, int, options) +DeclareSciCallR0(AutoCActive, AUTOCACTIVE, bool) +DeclareSciCallV0(AutoCComplete, AUTOCCOMPLETE) +DeclareSciCallV0(AutoCCancel, AUTOCCANCEL) +DeclareSciCallV1(AutoCSetIgnoreCase, AUTOCSETIGNORECASE, bool, flag) +DeclareSciCallV1(AutoCSetSeperator, AUTOCSETSEPARATOR, char, seperator) +DeclareSciCallV01(AutoCSetFillups, AUTOCSETFILLUPS, const char*, text) +DeclareSciCallV1(AutoCSetChooseSingle, AUTOCSETCHOOSESINGLE, bool, flag) +DeclareSciCallV2(AutoCShow, AUTOCSHOW, int, len, const char*, list) + + //============================================================================= // // Commands From ca413dbcbdb8c1d6254161e25df0711cabcc683d Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 31 Aug 2018 18:10:37 +0200 Subject: [PATCH 4/7] + fix: windows positioning (1st part) --- language/common_res.h | 4 +- language/np3_af_za/menu_af_za.rc | Bin 42942 -> 43234 bytes language/np3_de_de/menu_de_de.rc | Bin 44650 -> 44952 bytes language/np3_en_gb/menu_en_gb.rc | Bin 43064 -> 43356 bytes language/np3_en_us/menu_en_us.rc | Bin 43038 -> 43330 bytes language/np3_es_es/menu_es_es.rc | Bin 43014 -> 43306 bytes language/np3_fr_fr/menu_fr_fr.rc | Bin 45508 -> 45802 bytes language/np3_ja_jp/menu_ja_jp.rc | Bin 41688 -> 41980 bytes language/np3_nl_nl/menu_nl_nl.rc | Bin 44562 -> 44854 bytes language/np3_zh_cn/menu_zh_cn.rc | Bin 41078 -> 41370 bytes src/Dialogs.c | 104 +++++++++----- src/Dialogs.h | 2 + src/Helpers.c | 3 +- src/Helpers.h | 1 - src/Notepad3.c | 229 +++++++++++++++---------------- src/Notepad3.h | 2 +- src/Notepad3.rc | 7 +- src/TypeDefs.h | 16 +++ 18 files changed, 205 insertions(+), 163 deletions(-) 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 2930eb51f029dbc843740ef413b234f7c67e0c21..8b37b4a4689b3a04f936b57dd239a361073e7f62 100644 GIT binary patch delta 170 zcmdmYp6Ss=rVTm`lPA>k@p>}kF=R570C6Hi&g9kgii&OwhCryqpu?cR;LPC5;KC5k z;K|?z#34ZJ$lxr-^KrT{7y_XZgU;kYXJMckKL$^R5FmDB@R|I+#dNZQJX>rI(4ZuS zRE8oT&IB7>%%BTYkq5L0!Y^S^K(`pEHjg0&Xdlc51qNpZUj`S3c%VoqgAWh}14V*B Lwrt+ixlh9%c0U(oMei@VSeHyc@ehvq-;D)#;NrMpa diff --git a/language/np3_en_gb/menu_en_gb.rc b/language/np3_en_gb/menu_en_gb.rc index 19f07f88a3f5ee27949ca441d68c6b087386d99a..acc2a3822956c4263230301ea07bda20df020065 100644 GIT binary patch delta 166 zcmdmSf$7dArVSPiljqd)@p>}kF=R570C6Hi&gAX&ii&OwhCryqpu?cR;LPC5;KC5k z;K|?z#34ZJ$lx=XvB5Mtgdv|H9SCz6Qi1B+7)pVx93ab)p$I6F2xJ8SRTM+b&Ij5O f1GEKZwgONd1Yzd8F@!Ss0AVmtBxo~ZgSiF(Yw;mg delta 13 Ucmca}iD}0LrVSPii(?u!05Ks3O8@`> diff --git a/language/np3_en_us/menu_en_us.rc b/language/np3_en_us/menu_en_us.rc index 09cdf513778a15bb0ea3ddc1c9c1e52bfc6ea18b..fe76a5d17187156f51b12be1d333946d2719dd83 100644 GIT binary patch delta 162 zcmbPtf$7jCrVR=W(s>Mt3&)QG;KC3OROJW6AwcZN;4|5`-c&vWs5>19a~M*A>f9Jgfvg-L%aNf7D3S;?NnF*9 h!4L?QfT9oxGtG@5l)(oGgMsD;0ZlXCtkCdJ9RQu(BE0|r delta 14 WcmX?fiD}*irVR=Wn_U|JsRIBt{RZ>^ diff --git a/language/np3_es_es/menu_es_es.rc b/language/np3_es_es/menu_es_es.rc index 369dd7651e9fe47e23e42c7707cd3de9a4ae9ebc..e2adfbda3b7fd0fec07404947dacde9e4719d402 100644 GIT binary patch delta 166 zcmZp>z_jWT(}swK$$RSgcs&{N7%~}3fH;vMXY%!WMMXCTLm*UQ&|y$uaAxpjaAAmN z@MQ1<;t(KqWbm1+*kBqR!jR994um-jsX%pZ45dI;4v^)@Py`f71hN8vDvF_I=L2nt f0onpHTLCB!f-v*l7(y9*fG`*+60}*d;i)QVseDFw1}fGkIbBA`ej nkQIPray~;IirET4c@Tt|@5T@cbc+u|Fi<22Wd7y@EkT+9D|IJy delta 14 WcmdmXk7?2!rVR&LHa}?%(gXlIlLwLj diff --git a/language/np3_zh_cn/menu_zh_cn.rc b/language/np3_zh_cn/menu_zh_cn.rc index 28179e986086e0b401779ce415d6f4e118e870c6..fcce19b116c1690d5723e7da3fe06f11e4699add 100644 GIT binary patch delta 210 zcmex%fN9oYrVUZm@xcsv42cW{32fo57925D1kRbbuhMZVaVB q7RYQzped<9d$8LAGg|>D4}viB-55d{e1I?*C=vuRe{)o|j4A-wIw-aP delta 14 VcmbPrnCaUArVUZmo9k+1Q~@@<28#dy 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 From 6df6e74bbc37998b7d4a6f96edce749fd518e3e1 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sat, 1 Sep 2018 03:20:27 +0200 Subject: [PATCH 5/7] + fix: refactoring bugs --- scintilla/win32/PlatWin.cxx | 2 +- src/Dialogs.c | 73 +++++++++++++++++++++---------------- src/Dialogs.h | 2 +- src/Notepad3.c | 72 +++++++++++++++--------------------- src/TypeDefs.h | 15 ++------ 5 files changed, 78 insertions(+), 86 deletions(-) diff --git a/scintilla/win32/PlatWin.cxx b/scintilla/win32/PlatWin.cxx index 0c28dc30f..6850a59d1 100644 --- a/scintilla/win32/PlatWin.cxx +++ b/scintilla/win32/PlatWin.cxx @@ -780,7 +780,7 @@ void SurfaceGDI::RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesir namespace { // Plot a point into a DWORD buffer symmetrically to all 4 quadrants -void AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD val) { +void __forceinline AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD val) { pixels[y*width+x] = val; pixels[y*width+width-1-x] = val; pixels[(height-1-y)*width+x] = val; diff --git a/src/Dialogs.c b/src/Dialogs.c index 587b9e41b..d07a76eb8 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2641,7 +2641,7 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) if (hMonitorInfo) { - HMONITOR hMonitor = MonitorFromRect(&wndpl.rcNormalPosition, MONITOR_DEFAULTTONEAREST); + HMONITOR hMonitor = MonitorFromRect(&(wndpl.rcNormalPosition), MONITOR_DEFAULTTONEAREST); hMonitorInfo->cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMonitor, hMonitorInfo); } @@ -2655,7 +2655,7 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) // FitIntoMonitorWorkArea() // // -RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo) +RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea) { MONITORINFO mi; ZeroMemory(&mi, sizeof(MONITORINFO)); @@ -2663,31 +2663,41 @@ RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo) 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); + if (bFullWorkArea) { + SetRect(pRect, mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom); + // monitor coord -> work area coord + pWinInfo->x = mi.rcWork.left - (mi.rcWork.left - mi.rcMonitor.left); + pWinInfo->y = mi.rcWork.top - (mi.rcWork.top - mi.rcMonitor.top); + pWinInfo->cx = (mi.rcWork.right - mi.rcWork.left); + pWinInfo->cy = (mi.rcWork.bottom - mi.rcWork.top); } - - 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; + else { + WININFO wi = *pWinInfo; + // work area coord -> monitor coord + wi.x += (mi.rcWork.left - mi.rcMonitor.left); + wi.y += (mi.rcWork.top - mi.rcMonitor.top); + // fit into area + if (wi.x < mi.rcWork.left) { wi.x = mi.rcWork.left; } + if (wi.y < mi.rcWork.top) { wi.y = mi.rcWork.top; } + if ((wi.x + wi.cx) > mi.rcWork.right) { + wi.x -= (wi.x + wi.cx - mi.rcWork.right); + if (wi.x < mi.rcWork.left) { wi.x = mi.rcWork.left; } + if ((wi.x + wi.cx) > mi.rcWork.right) { wi.cx = mi.rcWork.right - wi.x; } + } + if ((wi.y + wi.cy) > mi.rcWork.bottom) { + wi.y -= (wi.y + wi.cy - mi.rcWork.bottom); + if (wi.y < mi.rcWork.top) { wi.y = mi.rcWork.top; } + if ((wi.y + wi.cy) > mi.rcWork.bottom) { wi.cy = mi.rcWork.bottom - wi.y; } + } + SetRect(pRect, wi.x, wi.y, wi.x + wi.cx, wi.y + wi.cy); + // monitor coord -> work area coord + pWinInfo->x = wi.x - (mi.rcWork.left - mi.rcMonitor.left); + pWinInfo->y = wi.y - (mi.rcWork.top - mi.rcMonitor.top); + pWinInfo->cx = wi.cx; + pWinInfo->cy = wi.cy; + } + + return mi.rcWork; } // ---------------------------------------------------------------------------- @@ -2704,17 +2714,18 @@ WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* const pWinInfo wndpl.length = sizeof(WINDOWPLACEMENT); wndpl.flags = WPF_ASYNCWINDOWPLACEMENT; wndpl.showCmd = SW_RESTORE; + WININFO winfo = INIT_WININFO; 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; + RECT rc = RectFromWinInfo(pWinInfo); + winfo = *pWinInfo; + FitIntoMonitorWorkArea(&rc, &winfo, false); if (pWinInfo->max) { wndpl.flags &= WPF_RESTORETOMAXIMIZED; } } else { RECT rc; GetWindowRect(hwnd, &rc); - wndpl.rcNormalPosition = FitIntoMonitorWorkArea(&rc, NULL); + FitIntoMonitorWorkArea(&rc, &winfo, true); } + wndpl.rcNormalPosition = RectFromWinInfo(&winfo); return wndpl; } diff --git a/src/Dialogs.h b/src/Dialogs.h index 24ee4f1fa..77f338a5b 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -38,7 +38,7 @@ bool RecodeDlg(HWND,int *); bool SelectDefLineEndingDlg(HWND,int *); WININFO GetMyWindowPlacement(HWND,MONITORINFO *); -RECT FitIntoMonitorWorkArea(RECT*, WININFO*); +RECT FitIntoMonitorWorkArea(RECT*, WININFO*, bool); WINDOWPLACEMENT WindowPlacementFromInfo(HWND, const WININFO* const); void DialogNewWindow(HWND,bool,bool); diff --git a/src/Notepad3.c b/src/Notepad3.c index 4a39e9c4b..d66816b5c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -988,25 +988,14 @@ void EndWaitCursor() // _InitWindowPosition() // // -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; - 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; + RECT rc = RectFromWinInfo(&g_WinInfo); + + SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + WININFO winfo = INIT_WININFO; + FitIntoMonitorWorkArea(&rc, &winfo, true); // get work area + rc = RectFromWinInfo(&winfo); if (g_flagDefaultPos == 1) { @@ -1016,8 +1005,6 @@ static void __fastcall _InitWindowPosition() } 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 @@ -1049,24 +1036,22 @@ static void __fastcall _InitWindowPosition() } else if (g_flagDefaultPos == 2 || g_flagDefaultPos == 3) // NP3 default window position { - //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; } + 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; } else { // fit window into working area of current monitor - RECT rcWork = FitIntoMonitorWorkArea(&rc, &g_WinInfo); - RECT rc2; - 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; - } + + FitIntoMonitorWorkArea(&rc, &g_WinInfo, false); + //rc = RectFromWinInfo(&g_WinInfo); + //RECT rc2; + //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; } @@ -1082,15 +1067,19 @@ HWND InitInstance(HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow) UNUSED(pszCmdLine); _InitWindowPosition(); + // get monitor coordinates from g_WinInfo + RECT rc = RectFromWinInfo(&g_WinInfo); + FitIntoMonitorWorkArea(&rc, &g_WinInfo, false); + g_hwndMain = CreateWindowEx( 0, wchWndClass, L"" APPNAME, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, - g_WinInfo.x, - g_WinInfo.y, - g_WinInfo.cx, - g_WinInfo.cy, + rc.left, + rc.top, + rc.right - rc.left, + rc.bottom - rc.top, NULL, NULL, hInstance, @@ -1122,8 +1111,6 @@ 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)); @@ -5589,7 +5576,8 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) break; case CMD_DEFAULTWINPOS: - _InitDefaultWndPos(); + g_flagDefaultPos = 2; + _InitWindowPosition(); SnapToWinInfoPos(hwnd, false); break; diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 578f1304b..078f9e5f0 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -63,18 +63,11 @@ 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; + +inline RECT RectFromWinInfo(const WININFO* const pWinInfo) { + RECT rc; SetRect(&rc, pWinInfo->x, pWinInfo->y, pWinInfo->x + pWinInfo->cx, pWinInfo->y + pWinInfo->cy); return rc; } + // ---------------------------------------------------------------------------- From eb156b6570fb042df487d781d15ea007ea468bb2 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sat, 1 Sep 2018 10:59:22 +0200 Subject: [PATCH 6/7] + fix: Win Positions: Monitor/Sreen vs. Work Area placements --- src/Dialogs.c | 58 +++++++++++++++++++++++++++++++++++--------------- src/Dialogs.h | 3 ++- src/Edit.c | 1 - src/Notepad3.c | 52 ++++++++++++++++++++++---------------------- 4 files changed, 69 insertions(+), 45 deletions(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index d07a76eb8..b6620e118 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2619,12 +2619,47 @@ bool SelectDefLineEndingDlg(HWND hwnd,int *iOption) } +//============================================================================= +// +// GetMonitorInfoFromRect() +// +static void __fastcall GetMonitorInfoFromRect(const RECT* const rc, MONITORINFO* hMonitorInfo) +{ + if (hMonitorInfo) { + HMONITOR const hMonitor = MonitorFromRect(rc, MONITOR_DEFAULTTONEAREST); + ZeroMemory(hMonitorInfo, sizeof(MONITORINFO)); + hMonitorInfo->cbSize = sizeof(MONITORINFO); + GetMonitorInfo(hMonitor, hMonitorInfo); + } +} +// ---------------------------------------------------------------------------- + + + +//============================================================================= +// +// WinInfoToScreen() +// +void WinInfoToScreen(WININFO* pWinInfo) +{ + if (pWinInfo) { + MONITORINFO mi; + RECT rc = RectFromWinInfo(pWinInfo); + GetMonitorInfoFromRect(&rc, &mi); + + WININFO winfo = *pWinInfo; + winfo.x += (mi.rcWork.left - mi.rcMonitor.left); + winfo.y += (mi.rcWork.top - mi.rcMonitor.top); + + *pWinInfo = winfo; + } +} + //============================================================================= // // GetMyWindowPlacement() // -// WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) { WINDOWPLACEMENT wndpl; @@ -2639,12 +2674,8 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED); wi.zoom = SciCall_GetZoom(); - if (hMonitorInfo) - { - HMONITOR hMonitor = MonitorFromRect(&(wndpl.rcNormalPosition), MONITOR_DEFAULTTONEAREST); - hMonitorInfo->cbSize = sizeof(MONITORINFO); - GetMonitorInfo(hMonitor, hMonitorInfo); - } + GetMonitorInfoFromRect(&(wndpl.rcNormalPosition), hMonitorInfo); + return wi; } // ---------------------------------------------------------------------------- @@ -2655,13 +2686,10 @@ WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo) // FitIntoMonitorWorkArea() // // -RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea) +void FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea) { MONITORINFO mi; - ZeroMemory(&mi, sizeof(MONITORINFO)); - mi.cbSize = sizeof(MONITORINFO); - HMONITOR const hMonitor = MonitorFromRect(pRect, MONITOR_DEFAULTTONEAREST); - GetMonitorInfo(hMonitor, &mi); + GetMonitorInfoFromRect(pRect, &mi); if (bFullWorkArea) { SetRect(pRect, mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom); @@ -2673,9 +2701,7 @@ RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea) } else { WININFO wi = *pWinInfo; - // work area coord -> monitor coord - wi.x += (mi.rcWork.left - mi.rcMonitor.left); - wi.y += (mi.rcWork.top - mi.rcMonitor.top); + WinInfoToScreen(&wi); // fit into area if (wi.x < mi.rcWork.left) { wi.x = mi.rcWork.left; } if (wi.y < mi.rcWork.top) { wi.y = mi.rcWork.top; } @@ -2696,8 +2722,6 @@ RECT FitIntoMonitorWorkArea(RECT* pRect, WININFO* pWinInfo, bool bFullWorkArea) pWinInfo->cx = wi.cx; pWinInfo->cy = wi.cy; } - - return mi.rcWork; } // ---------------------------------------------------------------------------- diff --git a/src/Dialogs.h b/src/Dialogs.h index 77f338a5b..643c848b4 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -37,8 +37,9 @@ bool SelectEncodingDlg(HWND,int *); bool RecodeDlg(HWND,int *); bool SelectDefLineEndingDlg(HWND,int *); +void WinInfoToScreen(WININFO*); WININFO GetMyWindowPlacement(HWND,MONITORINFO *); -RECT FitIntoMonitorWorkArea(RECT*, WININFO*, bool); +void FitIntoMonitorWorkArea(RECT*, WININFO*, bool); WINDOWPLACEMENT WindowPlacementFromInfo(HWND, const WININFO* const); void DialogNewWindow(HWND,bool,bool); diff --git a/src/Edit.c b/src/Edit.c index d8b134871..41857e2f6 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -65,7 +65,6 @@ extern HMODULE g_hLngResContainer; extern HWND g_hwndMain; extern HWND g_hwndStatus; extern HWND g_hwndDlgFindReplace; -extern WININFO g_WinInfo; extern HICON g_hDlgIcon; //extern LPMALLOC g_lpMalloc; diff --git a/src/Notepad3.c b/src/Notepad3.c index d66816b5c..d2975f749 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -990,12 +990,14 @@ void EndWaitCursor() // static void __fastcall _InitWindowPosition() { - RECT rc = RectFromWinInfo(&g_WinInfo); + int const iBdrOff = IsWin10() ? 8 : 16; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - WININFO winfo = INIT_WININFO; - FitIntoMonitorWorkArea(&rc, &winfo, true); // get work area - rc = RectFromWinInfo(&winfo); + RECT rcMon = RectFromWinInfo(&g_WinInfo); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMon, 0); + + WININFO wiWorkArea = INIT_WININFO; + FitIntoMonitorWorkArea(&rcMon, &wiWorkArea, true); // get Monitor and Work Area + RECT const rc = RectFromWinInfo(&wiWorkArea); // use Work Area as RECT if (g_flagDefaultPos == 1) { @@ -1036,23 +1038,20 @@ static void __fastcall _InitWindowPosition() } else if (g_flagDefaultPos == 2 || g_flagDefaultPos == 3) // NP3 default window position { - 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.y = rc.top + iBdrOff; + g_WinInfo.cy = rc.bottom - rc.top - (iBdrOff * 2); + 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; } - else { // fit window into working area of current monitor + else { // restore window, move upper left corner to Work Area - FitIntoMonitorWorkArea(&rc, &g_WinInfo, false); - //rc = RectFromWinInfo(&g_WinInfo); - //RECT rc2; - //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; - //} + WININFO wiWin = g_WinInfo; wiWin.cx = wiWin.cy = iBdrOff * 2; // really small + FitIntoMonitorWorkArea(&rcMon, &wiWin, false); + g_WinInfo.x = wiWin.x; + g_WinInfo.y = wiWin.y; + } + g_WinCurrentWidth = g_WinInfo.cx; } @@ -1065,21 +1064,22 @@ static void __fastcall _InitWindowPosition() HWND InitInstance(HINSTANCE hInstance,LPWSTR pszCmdLine,int nCmdShow) { UNUSED(pszCmdLine); + _InitWindowPosition(); - + // get monitor coordinates from g_WinInfo - RECT rc = RectFromWinInfo(&g_WinInfo); - FitIntoMonitorWorkArea(&rc, &g_WinInfo, false); + WININFO srcninfo = g_WinInfo; + WinInfoToScreen(&srcninfo); g_hwndMain = CreateWindowEx( 0, wchWndClass, - L"" APPNAME, + TEXT(APPNAME), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, - rc.left, - rc.top, - rc.right - rc.left, - rc.bottom - rc.top, + srcninfo.x, + srcninfo.y, + srcninfo.cx, + srcninfo.cy, NULL, NULL, hInstance, From 6dccd0ddec01f0ad59c156e083206b790e347ee1 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Sat, 1 Sep 2018 11:35:28 +0200 Subject: [PATCH 7/7] + fix: default win pos handling --- src/Dialogs.c | 1 + src/Notepad3.c | 60 ++++++++++++++++++++++++++++++++++++-------------- src/Notepad3.h | 2 +- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/Dialogs.c b/src/Dialogs.c index b6620e118..7b5a73538 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -2748,6 +2748,7 @@ WINDOWPLACEMENT WindowPlacementFromInfo(HWND hwnd, const WININFO* const pWinInfo else { RECT rc; GetWindowRect(hwnd, &rc); FitIntoMonitorWorkArea(&rc, &winfo, true); + // TODO: maximize ? } wndpl.rcNormalPosition = RectFromWinInfo(&winfo); return wndpl; diff --git a/src/Notepad3.c b/src/Notepad3.c index d2975f749..f645adb26 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -988,17 +988,29 @@ void EndWaitCursor() // _InitWindowPosition() // // -static void __fastcall _InitWindowPosition() -{ - int const iBdrOff = IsWin10() ? 8 : 16; +#define _BORDEROFFSET (IsWin10() ? 8 : 16) - RECT rcMon = RectFromWinInfo(&g_WinInfo); + +static void __fastcall _InitDefaultWndPos(WININFO* pWinInfo) +{ + RECT rcMon = RectFromWinInfo(pWinInfo); SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMon, 0); WININFO wiWorkArea = INIT_WININFO; FitIntoMonitorWorkArea(&rcMon, &wiWorkArea, true); // get Monitor and Work Area RECT const rc = RectFromWinInfo(&wiWorkArea); // use Work Area as RECT + pWinInfo->y = rc.top + _BORDEROFFSET; + pWinInfo->cy = rc.bottom - rc.top - (_BORDEROFFSET * 2); + pWinInfo->cx = (rc.right - rc.left) / 2; //min(rc.right - rc.left - 32, g_WinInfo.cy); + pWinInfo->x = (g_flagDefaultPos == 3) ? rc.left + _BORDEROFFSET : rc.right - g_WinInfo.cx - _BORDEROFFSET; +} +// ---------------------------------------------------------------------------- + + +static void __fastcall _InitWindowPosition() +{ + if (g_flagDefaultPos == 1) { g_WinInfo.x = g_WinInfo.y = g_WinInfo.cx = g_WinInfo.cy = CW_USEDEFAULT; @@ -1007,6 +1019,13 @@ static void __fastcall _InitWindowPosition() } else if (g_flagDefaultPos >= 4) { + RECT rcMon = RectFromWinInfo(&g_WinInfo); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMon, 0); + + WININFO wiWorkArea = INIT_WININFO; + FitIntoMonitorWorkArea(&rcMon, &wiWorkArea, true); // get Monitor and Work Area + RECT const rc = RectFromWinInfo(&wiWorkArea); // use Work Area as RECT + if (g_flagDefaultPos & 8) g_WinInfo.x = (rc.right - rc.left) / 2; else @@ -1038,15 +1057,16 @@ static void __fastcall _InitWindowPosition() } else if (g_flagDefaultPos == 2 || g_flagDefaultPos == 3) // NP3 default window position { - g_WinInfo.y = rc.top + iBdrOff; - g_WinInfo.cy = rc.bottom - rc.top - (iBdrOff * 2); - 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; + _InitDefaultWndPos(&g_WinInfo); } else { // restore window, move upper left corner to Work Area - WININFO wiWin = g_WinInfo; wiWin.cx = wiWin.cy = iBdrOff * 2; // really small + RECT rcMon = RectFromWinInfo(&g_WinInfo); + SystemParametersInfo(SPI_GETWORKAREA, 0, &rcMon, 0); + + WININFO wiWin = g_WinInfo; wiWin.cx = wiWin.cy = _BORDEROFFSET * 2; // really small FitIntoMonitorWorkArea(&rcMon, &wiWin, false); + g_WinInfo.x = wiWin.x; g_WinInfo.y = wiWin.y; @@ -5568,17 +5588,19 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case CMD_INITIALWINPOS: - SnapToWinInfoPos(hwnd,false); + SnapToWinInfoPos(hwnd, &g_WinInfo, false); break; case CMD_FULLSCRWINPOS: - SnapToWinInfoPos(hwnd, true); + SnapToWinInfoPos(hwnd, &g_WinInfo, true); break; case CMD_DEFAULTWINPOS: - g_flagDefaultPos = 2; - _InitWindowPosition(); - SnapToWinInfoPos(hwnd, false); + { + WININFO winfo = g_WinInfo; + _InitDefaultWndPos(&winfo); + SnapToWinInfoPos(hwnd, &winfo, false); + } break; @@ -10044,7 +10066,7 @@ bool RelaunchElevated(LPWSTR lpArgs) { // SnapToWinInfoPos() // Aligns Notepad3 to the default window position on the current screen // -void SnapToWinInfoPos(HWND hwnd, bool bFullWorkArea) +void SnapToWinInfoPos(HWND hwnd, const WININFO* const pWinInfo, bool bFullWorkArea) { static WINDOWPLACEMENT s_wndplPrev; static bool s_bPrevFullWAFlag = false; @@ -10070,7 +10092,11 @@ void SnapToWinInfoPos(HWND hwnd, bool bFullWorkArea) s_bPrevFullWAFlag = !s_bPrevFullWAFlag; } else { - wndpl = WindowPlacementFromInfo(hwnd, &g_WinInfo); + wndpl = WindowPlacementFromInfo(hwnd, pWinInfo); + if (s_bPrevFullWAFlag) { + bShowToolbar = s_bPrevShowToolbar; + bShowStatusbar = s_bPrevShowStatusbar; + } s_bPrevFullWAFlag = false; } @@ -10080,7 +10106,7 @@ void SnapToWinInfoPos(HWND hwnd, bool bFullWorkArea) } SetWindowPlacement(hwnd, &wndpl); - SciCall_SetZoom(g_WinInfo.zoom); + SciCall_SetZoom(pWinInfo->zoom); UpdateToolbar(); UpdateStatusbar(true); diff --git a/src/Notepad3.h b/src/Notepad3.h index 3252c46f9..9c0a43aad 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -116,7 +116,7 @@ void EndWaitCursor(); bool ActivatePrevInst(); bool RelaunchMultiInst(); bool RelaunchElevated(LPWSTR); -void SnapToWinInfoPos(HWND,bool); +void SnapToWinInfoPos(HWND, const WININFO* const, bool); void ShowNotifyIcon(HWND,bool); void SetNotifyIconTitle(HWND); void InstallFileWatching(LPCWSTR);