Fix toolbar icon color picker's incoherent behaviour

Fix https://github.com/notepad-plus-plus/notepad-plus-plus/pull/16370#issuecomment-2810227200
This commit is contained in:
Don Ho 2025-04-17 12:29:05 +02:00
parent d5b5e5e107
commit b68f25f3d6
4 changed files with 62 additions and 46 deletions

View File

@ -116,8 +116,6 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
p.y = rc.top + rc.bottom; p.y = rc.top + rc.bottom;
::ClientToScreen(_hSelf, &p); ::ClientToScreen(_hSelf, &p);
::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURCLICKED), reinterpret_cast<LPARAM>(_hSelf));
if (!_pColourPopup) if (!_pColourPopup)
{ {
_pColourPopup = new ColourPopup(_currentColour); _pColourPopup = new ColourPopup(_currentColour);
@ -135,6 +133,9 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
{ {
if (_disableRightClick)
return FALSE;
_isEnabled = !_isEnabled; _isEnabled = !_isEnabled;
redraw(); redraw();
::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), reinterpret_cast<LPARAM>(_hSelf)); ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), reinterpret_cast<LPARAM>(_hSelf));

View File

@ -22,7 +22,6 @@
class ColourPopup; class ColourPopup;
#define CPN_COLOURPICKED (BN_CLICKED) #define CPN_COLOURPICKED (BN_CLICKED)
#define CPN_COLOURCLICKED (BN_SETFOCUS)
class ColourPicker : public Window class ColourPicker : public Window
{ {
@ -38,12 +37,14 @@ public :
COLORREF getColour() const {return _currentColour;}; COLORREF getColour() const {return _currentColour;};
bool isEnabled() {return _isEnabled;}; bool isEnabled() {return _isEnabled;};
void setEnabled(bool enabled) {_isEnabled = enabled;}; void setEnabled(bool enabled) {_isEnabled = enabled;};
void disableRightClick() {_disableRightClick = true;};
private : private :
COLORREF _currentColour = RGB(0xFF, 0x00, 0x00); COLORREF _currentColour = RGB(0xFF, 0x00, 0x00);
WNDPROC _buttonDefaultProc = nullptr; WNDPROC _buttonDefaultProc = nullptr;
ColourPopup *_pColourPopup = nullptr; ColourPopup *_pColourPopup = nullptr;
bool _isEnabled = true; bool _isEnabled = true;
bool _disableRightClick = false;
static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((ColourPicker *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(Message, wParam, lParam)); return (((ColourPicker *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(Message, wParam, lParam));

View File

@ -597,6 +597,24 @@ void ToolbarSubDlg::move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveW
::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE); ::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*/) intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM /*lParam*/)
{ {
NppParameters& nppParam = NppParameters::getInstance(); NppParameters& nppParam = NppParameters::getInstance();
@ -824,6 +842,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
_pIconColorPicker = new ColourPicker; _pIconColorPicker = new ColourPicker;
_pIconColorPicker->init(_hInst, _hSelf); _pIconColorPicker->init(_hInst, _hSelf);
_pIconColorPicker->disableRightClick();
move2CtrlLeft(IDC_STATIC, _pIconColorPicker->getHSelf(), cpDynamicalSize, cpDynamicalSize); move2CtrlLeft(IDC_STATIC, _pIconColorPicker->getHSelf(), cpDynamicalSize, cpDynamicalSize);
_pIconColorPicker->display(); _pIconColorPicker->display();
_pIconColorPicker->setColour(nppGUI._tbIconInfo._tbCustomColor); _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); ::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; return TRUE;
} }
@ -839,6 +865,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case NPPM_INTERNAL_CHANGETOOLBARCOLORABLESTATE: case NPPM_INTERNAL_CHANGETOOLBARCOLORABLESTATE:
{ {
bool enableColor = !isCheckedOrNot(IDC_RADIO_STANDARD); bool enableColor = !isCheckedOrNot(IDC_RADIO_STANDARD);
bool enableCustom = isCheckedOrNot(IDC_RADIO_CUSTOMCOLOR);
::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_COMPLETE), enableColor); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_COMPLETE), enableColor);
::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_PARTIAL), 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_ACCENTCOLOR), enableColor);
::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_CUSTOMCOLOR), enableColor); ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_CUSTOMCOLOR), enableColor);
::EnableWindow(_pIconColorPicker->getHSelf(), enableColor); enableIconColorPicker(enableColor && enableCustom);
const bool usePrevDarkMode = static_cast<bool>(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()) if (NppDarkMode::isEnabled())
{ {
@ -959,6 +972,8 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
return TRUE; return TRUE;
} }
case IDC_RADIO_CUSTOMCOLOR: case IDC_RADIO_CUSTOMCOLOR:
{ {
FluentColor c = FluentColor::custom; FluentColor c = FluentColor::custom;
@ -966,6 +981,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(true);
return TRUE; return TRUE;
} }
@ -976,6 +992,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -986,6 +1003,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -996,6 +1014,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -1006,6 +1025,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -1016,6 +1036,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -1026,6 +1047,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -1036,6 +1058,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -1046,6 +1069,7 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
@ -1056,12 +1080,12 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
nppGUI._tbIconInfo._tbColor = c; nppGUI._tbIconInfo._tbColor = c;
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
enableIconColorPicker(false);
return TRUE; return TRUE;
} }
case IDC_RADIO_COMPLETE: case IDC_RADIO_COMPLETE:
{ {
NppDarkMode::setToolbarFluentMonochrome(true); NppDarkMode::setToolbarFluentMonochrome(true);
@ -1085,44 +1109,20 @@ intptr_t CALLBACK ToolbarSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
default: default:
{ {
switch (HIWORD(wParam)) 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: case CPN_COLOURPICKED:
{ {
if (reinterpret_cast<HWND>(lParam) == _pIconColorPicker->getHSelf()) if (reinterpret_cast<HWND>(lParam) == _pIconColorPicker->getHSelf())
{ {
FluentColor colorType = FluentColor::custom;
NppDarkMode::setToolbarFluentColor(colorType);
nppGUI._tbIconInfo._tbColor = colorType;
COLORREF c = _pIconColorPicker->getColour(); COLORREF c = _pIconColorPicker->getColour();
nppGUI._tbIconInfo._tbCustomColor = c; nppGUI._tbIconInfo._tbCustomColor = c;
NppDarkMode::setToolbarFluentCustomColor(c); NppDarkMode::setToolbarFluentCustomColor(c);
UINT msg = getToolbarIconSetMsg(nullptr); UINT msg = getToolbarIconSetMsg(nullptr);
::SendMessage(::GetParent(_hParent), msg, TRUE, 0); ::SendMessage(::GetParent(_hParent), msg, TRUE, 0);
return TRUE; return TRUE;
} }
break; break;
@ -2136,7 +2136,6 @@ intptr_t CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
_pCtrlBackgroundColorPicker->init(_hInst, _hSelf); _pCtrlBackgroundColorPicker->init(_hInst, _hSelf);
_pHotBackgroundColorPicker->init(_hInst, _hSelf); _pHotBackgroundColorPicker->init(_hInst, _hSelf);
_pDlgBackgroundColorPicker->init(_hInst, _hSelf); _pDlgBackgroundColorPicker->init(_hInst, _hSelf);
_pErrorBackgroundColorPicker->init(_hInst, _hSelf); _pErrorBackgroundColorPicker->init(_hInst, _hSelf);
_pTextColorPicker->init(_hInst, _hSelf); _pTextColorPicker->init(_hInst, _hSelf);
_pDarkerTextColorPicker->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); _pHotEdgeColorPicker->init(_hInst, _hSelf);
_pDisabledEdgeColorPicker->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); _dpiManager.setDpi(_hSelf);
const int cpDynamicalSize = _dpiManager.scale(25); const int cpDynamicalSize = _dpiManager.scale(25);

View File

@ -59,7 +59,9 @@ private:
intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
UINT getToolbarIconSetMsg(int* idxIconSet); UINT getToolbarIconSetMsg(int* idxIconSet);
void move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight); void move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight);
void enableIconColorPicker(bool enable);
ColourPicker* _pIconColorPicker = nullptr; ColourPicker* _pIconColorPicker = nullptr;
}; };
class TabbarSubDlg : public StaticDialog class TabbarSubDlg : public StaticDialog