From b68f25f3d65fb0d65c0aee8f13e6b58d7c91d3be Mon Sep 17 00:00:00 2001 From: Don Ho Date: Thu, 17 Apr 2025 12:29:05 +0200 Subject: [PATCH] Fix toolbar icon color picker's incoherent behaviour Fix https://github.com/notepad-plus-plus/notepad-plus-plus/pull/16370#issuecomment-2810227200 --- .../WinControls/ColourPicker/ColourPicker.cpp | 5 +- .../WinControls/ColourPicker/ColourPicker.h | 3 +- .../WinControls/Preference/preferenceDlg.cpp | 98 +++++++++++-------- .../WinControls/Preference/preferenceDlg.h | 2 + 4 files changed, 62 insertions(+), 46 deletions(-) diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp index cb58f3e38..caa6d39f2 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp @@ -116,8 +116,6 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) p.y = rc.top + rc.bottom; ::ClientToScreen(_hSelf, &p); - ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURCLICKED), reinterpret_cast(_hSelf)); - if (!_pColourPopup) { _pColourPopup = new ColourPopup(_currentColour); @@ -135,6 +133,9 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) case WM_RBUTTONDOWN: { + if (_disableRightClick) + return FALSE; + _isEnabled = !_isEnabled; redraw(); ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), reinterpret_cast(_hSelf)); diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h index c8a522659..dcabacbd0 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h @@ -22,7 +22,6 @@ class ColourPopup; #define CPN_COLOURPICKED (BN_CLICKED) -#define CPN_COLOURCLICKED (BN_SETFOCUS) class ColourPicker : public Window { @@ -38,12 +37,14 @@ public : COLORREF getColour() const {return _currentColour;}; bool isEnabled() {return _isEnabled;}; void setEnabled(bool enabled) {_isEnabled = enabled;}; + void disableRightClick() {_disableRightClick = true;}; private : COLORREF _currentColour = RGB(0xFF, 0x00, 0x00); WNDPROC _buttonDefaultProc = nullptr; ColourPopup *_pColourPopup = nullptr; bool _isEnabled = true; + bool _disableRightClick = false; static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { return (((ColourPicker *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(Message, wParam, lParam)); diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index 7f0aafbbd..71489ce1d 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -597,6 +597,24 @@ void ToolbarSubDlg::move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveW ::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE); } +void ToolbarSubDlg::enableIconColorPicker(bool enable) +{ + ::EnableWindow(_pIconColorPicker->getHSelf(), enable); + + if (enable) + { + const auto& tbIconInfo = NppDarkMode::getToolbarIconInfo(NppDarkMode::isEnabled()); + _pIconColorPicker->setColour(tbIconInfo._tbCustomColor); + } + else + { + COLORREF disabledColor = NppDarkMode::isEnabled() ? NppDarkMode::getDlgBackgroundColor() : ::GetSysColor(COLOR_3DFACE); + _pIconColorPicker->setColour(disabledColor); + } + + _pIconColorPicker->redraw(); +} + intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/) { NppParameters& nppParam = NppParameters::getInstance(); @@ -824,6 +842,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _pIconColorPicker = new ColourPicker; _pIconColorPicker->init(_hInst, _hSelf); + _pIconColorPicker->disableRightClick(); move2CtrlLeft(IDC_STATIC, _pIconColorPicker->getHSelf(), cpDynamicalSize, cpDynamicalSize); _pIconColorPicker->display(); _pIconColorPicker->setColour(nppGUI._tbIconInfo._tbCustomColor); @@ -832,6 +851,13 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM { ::SendMessage(_hSelf, NPPM_INTERNAL_CHANGETOOLBARCOLORABLESTATE, 0, 0); } + else // Eventually color picker needs to be disabled, if it's not custom choice. + { + if (ID2Check != IDC_RADIO_CUSTOMCOLOR) + { + enableIconColorPicker(false); + } + } return TRUE; } @@ -839,6 +865,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM case NPPM_INTERNAL_CHANGETOOLBARCOLORABLESTATE: { bool enableColor = !isCheckedOrNot(IDC_RADIO_STANDARD); + bool enableCustom = isCheckedOrNot(IDC_RADIO_CUSTOMCOLOR); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_COMPLETE), enableColor); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_PARTIAL), enableColor); @@ -854,22 +881,8 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_ACCENTCOLOR), enableColor); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_CUSTOMCOLOR), enableColor); - ::EnableWindow(_pIconColorPicker->getHSelf(), enableColor); + enableIconColorPicker(enableColor && enableCustom); - const bool usePrevDarkMode = static_cast(wParam) ? !NppDarkMode::isEnabled() : NppDarkMode::isEnabled(); - - if (enableColor) - { - const auto& tbIconInfo = NppDarkMode::getToolbarIconInfo(usePrevDarkMode); - _pIconColorPicker->setColour(tbIconInfo._tbCustomColor); - } - else - { - COLORREF disabledColor = usePrevDarkMode ? NppDarkMode::getDlgBackgroundColor() : ::GetSysColor(COLOR_3DFACE); - _pIconColorPicker->setColour(disabledColor); - } - - _pIconColorPicker->redraw(); if (NppDarkMode::isEnabled()) { @@ -959,6 +972,8 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM return TRUE; } + + case IDC_RADIO_CUSTOMCOLOR: { FluentColor c = FluentColor::custom; @@ -966,6 +981,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(true); return TRUE; } @@ -976,6 +992,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -986,6 +1003,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -996,6 +1014,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -1006,6 +1025,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -1016,6 +1036,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -1026,6 +1047,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -1036,6 +1058,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -1046,6 +1069,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } @@ -1056,12 +1080,12 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppGUI._tbIconInfo._tbColor = c; UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + enableIconColorPicker(false); return TRUE; } - case IDC_RADIO_COMPLETE: { NppDarkMode::setToolbarFluentMonochrome(true); @@ -1085,44 +1109,20 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM default: { + switch (HIWORD(wParam)) { - case CPN_COLOURCLICKED: - { - setChecked(IDC_RADIO_CUSTOMCOLOR, true); - setChecked(IDC_RADIO_RED, false); - setChecked(IDC_RADIO_GREEN, false); - setChecked(IDC_RADIO_BLUE, false); - setChecked(IDC_RADIO_PURPLE, false); - setChecked(IDC_RADIO_CYAN, false); - setChecked(IDC_RADIO_OLIVE, false); - setChecked(IDC_RADIO_YELLOW, false); - setChecked(IDC_RADIO_ACCENTCOLOR, false); - setChecked(IDC_RADIO_DEFAULTCOLOR, false); - - FluentColor colorType = FluentColor::custom; - NppDarkMode::setToolbarFluentColor(colorType); - nppGUI._tbIconInfo._tbColor = colorType; - UINT msg = getToolbarIconSetMsg(nullptr); - ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); - - return TRUE; - } - case CPN_COLOURPICKED: { if (reinterpret_cast(lParam) == _pIconColorPicker->getHSelf()) { - FluentColor colorType = FluentColor::custom; - NppDarkMode::setToolbarFluentColor(colorType); - nppGUI._tbIconInfo._tbColor = colorType; - COLORREF c = _pIconColorPicker->getColour(); nppGUI._tbIconInfo._tbCustomColor = c; NppDarkMode::setToolbarFluentCustomColor(c); UINT msg = getToolbarIconSetMsg(nullptr); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0); + return TRUE; } break; @@ -2136,7 +2136,6 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA _pCtrlBackgroundColorPicker->init(_hInst, _hSelf); _pHotBackgroundColorPicker->init(_hInst, _hSelf); _pDlgBackgroundColorPicker->init(_hInst, _hSelf); - _pErrorBackgroundColorPicker->init(_hInst, _hSelf); _pTextColorPicker->init(_hInst, _hSelf); _pDarkerTextColorPicker->init(_hInst, _hSelf); @@ -2146,6 +2145,19 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA _pHotEdgeColorPicker->init(_hInst, _hSelf); _pDisabledEdgeColorPicker->init(_hInst, _hSelf); + _pBackgroundColorPicker->disableRightClick(); + _pCtrlBackgroundColorPicker->disableRightClick(); + _pHotBackgroundColorPicker->disableRightClick(); + _pDlgBackgroundColorPicker->disableRightClick(); + _pErrorBackgroundColorPicker->disableRightClick(); + _pTextColorPicker->disableRightClick(); + _pDarkerTextColorPicker->disableRightClick(); + _pDisabledTextColorPicker->disableRightClick(); + _pEdgeColorPicker->disableRightClick(); + _pLinkColorPicker->disableRightClick(); + _pHotEdgeColorPicker->disableRightClick(); + _pDisabledEdgeColorPicker->disableRightClick(); + _dpiManager.setDpi(_hSelf); const int cpDynamicalSize = _dpiManager.scale(25); diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.h b/PowerEditor/src/WinControls/Preference/preferenceDlg.h index 1552bb31a..ba2962184 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.h +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.h @@ -59,7 +59,9 @@ private: intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; UINT getToolbarIconSetMsg(int* idxIconSet); void move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight); + void enableIconColorPicker(bool enable); ColourPicker* _pIconColorPicker = nullptr; + }; class TabbarSubDlg : public StaticDialog