From 4d107e269106dcf136b635d6ff3ab42d3b0a8fce Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 11 Feb 2023 18:53:58 +0100 Subject: [PATCH] Close doc in document list on middle mouse button up In 94b83158dcd00d7e705d87aa95f16f8773cc70c0, closing doc in document list was on middle mouse button down. This commit make it on middle mouse button up (for aligning with closing tab behaviour in Notepad++, also with OS middle mouse button click behaviour). --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 2 +- .../VerticalFileSwitcher.cpp | 26 ++++++++++++++++++- .../VerticalFileSwitcher.h | 11 +++++++- PowerEditor/src/resource.h | 2 +- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index c53760243..fb0c2b5b4 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -542,7 +542,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; // allocate commandLineStr buffer with the return value + 1, then call it again to get the current command line string. #define NPPM_CREATELEXER (NPPMSG + 110) - // void* NPPN_CREATELEXER(0, const TCHAR *lexer_name) + // void* NPPM_CREATELEXER(0, const TCHAR *lexer_name) // Returns the ILexer pointer created by Lexilla #define NPPM_GETBOOKMARKID (NPPMSG + 111) diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 166c4ebba..2375879d4 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -45,6 +45,24 @@ int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSo return (0 - result); } +LRESULT run_listViewProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + + case WM_MBUTTONUP: + { + // Redirect the message to parent + ::SendMessage(::GetParent(hwnd), WM_PARENTNOTIFY, WM_MBUTTONUP, lParam); + return TRUE; + } + + default: + break; + } + return ::CallWindowProc(oldEditProc, hwnd, message, wParam, lParam); +} + void VerticalFileSwitcher::startColumnSort() { // reset sorting if exts column was just disabled @@ -77,6 +95,9 @@ intptr_t CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, _fileListView.initList(); _fileListView.display(); + ::SetWindowLongPtr(_fileListView.getHSelf(), GWLP_USERDATA, reinterpret_cast(this)); + _defaultListViewProc = reinterpret_cast(::SetWindowLongPtr(_fileListView.getHSelf(), GWLP_WNDPROC, reinterpret_cast(listViewStaticProc))); + NppDarkMode::autoSubclassAndThemeChildControls(_hSelf); NppDarkMode::autoSubclassAndThemeWindowNotify(_hSelf); @@ -89,11 +110,13 @@ intptr_t CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, return TRUE; } + // Different from WM_MBUTTONDOWN, WM_MBUTTONUP message is not sent to parent hwnd by WIN32 API + // So we subclass listview to redirect WM_MBUTTONUP via WM_PARENTNOTIFY (as WM_MBUTTONDOWN) case WM_PARENTNOTIFY: { switch ( wParam ) { - case WM_MBUTTONDOWN: + case WM_MBUTTONUP: { // Get item ID under cursor LVHITTESTINFO hitInfo{}; @@ -124,6 +147,7 @@ intptr_t CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, break; } + case WM_NOTIFY: { switch (reinterpret_cast(lParam)->code) diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h index ce898bace..6a9d83a74 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.h @@ -29,6 +29,8 @@ struct sortCompareData { int sortDirection = 0; }; +LRESULT run_listViewProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + class VerticalFileSwitcher : public DockingDlgInterface { public: VerticalFileSwitcher(): DockingDlgInterface(IDD_DOCLIST) {}; @@ -102,14 +104,21 @@ public: }; protected: HMENU _hGlobalMenu = NULL; - virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); void initPopupMenus(); void popupMenuCmd(int cmdID); + + + + static LRESULT CALLBACK listViewStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + const auto dlg = (VerticalFileSwitcher*)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)); + return (run_listViewProc(dlg->_defaultListViewProc, hwnd, message, wParam, lParam)); + }; private: bool colHeaderRClick = false; int _lastSortingColumn = 0; int _lastSortingDirection = SORT_DIRECTION_NONE; VerticalFileSwitcherListView _fileListView; HIMAGELIST _hImaLst = nullptr; + WNDPROC _defaultListViewProc = nullptr; }; diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index b04fd9489..7b1592d5a 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -622,7 +622,7 @@ #define NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 46) #define NPPM_INTERNAL_PRNTANDQUIT (NOTEPADPLUS_USER_INTERNAL + 47) #define NPPM_INTERNAL_SAVEBACKUP (NOTEPADPLUS_USER_INTERNAL + 48) - #define NPPM_INTERNAL_STOPMONITORING (NOTEPADPLUS_USER_INTERNAL + 49) // Used by Monitoring feature + #define NPPM_INTERNAL_STOPMONITORING (NOTEPADPLUS_USER_INTERNAL + 49) // Used by Monitoring feature #define NPPM_INTERNAL_EDGEBACKGROUND (NOTEPADPLUS_USER_INTERNAL + 50) #define NPPM_INTERNAL_EDGEMULTISETSIZE (NOTEPADPLUS_USER_INTERNAL + 51) #define NPPM_INTERNAL_UPDATECLICKABLELINKS (NOTEPADPLUS_USER_INTERNAL + 52)