diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 37ad044798f9..12e2b38ad1be 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2286,6 +2286,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case WM_UPDATESCINTILLAS: { + bool isThemeChanged = (wParam == TRUE); + //reset styler for change in Stylers.xml _mainEditView.defineDocType(_mainEditView.getCurrentBuffer()->getLangType()); _mainEditView.performGlobalStyles(); @@ -2313,62 +2315,65 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa AutoCompletion::drawAutocomplete(_pEditView); AutoCompletion::drawAutocomplete(_pNonEditView); - NppDarkMode::calculateTreeViewStyle(); - auto refreshOnlyTreeView = static_cast(TRUE); - - // Set default fg/bg colors on internal docking dialog - if (pStyle && _pFuncList) + if (isThemeChanged) // Theme change { - _pFuncList->setBackgroundColor(pStyle->_bgColor); - _pFuncList->setForegroundColor(pStyle->_fgColor); - ::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); - } + NppDarkMode::calculateTreeViewStyle(); + auto refreshOnlyTreeView = static_cast(TRUE); - if (pStyle && _pAnsiCharPanel) - { - _pAnsiCharPanel->setBackgroundColor(pStyle->_bgColor); - _pAnsiCharPanel->setForegroundColor(pStyle->_fgColor); - } + // Set default fg/bg colors on internal docking dialog + if (pStyle && _pFuncList) + { + _pFuncList->setBackgroundColor(pStyle->_bgColor); + _pFuncList->setForegroundColor(pStyle->_fgColor); + ::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); + } - if (pStyle && _pDocumentListPanel) - { - _pDocumentListPanel->setBackgroundColor(pStyle->_bgColor); - _pDocumentListPanel->setForegroundColor(pStyle->_fgColor); - } + if (pStyle && _pAnsiCharPanel) + { + _pAnsiCharPanel->setBackgroundColor(pStyle->_bgColor); + _pAnsiCharPanel->setForegroundColor(pStyle->_fgColor); + } - if (pStyle && _pClipboardHistoryPanel) - { - _pClipboardHistoryPanel->setBackgroundColor(pStyle->_bgColor); - _pClipboardHistoryPanel->setForegroundColor(pStyle->_fgColor); - _pClipboardHistoryPanel->redraw(true); - } + if (pStyle && _pDocumentListPanel) + { + _pDocumentListPanel->setBackgroundColor(pStyle->_bgColor); + _pDocumentListPanel->setForegroundColor(pStyle->_fgColor); + } - if (pStyle && _pProjectPanel_1) - { - _pProjectPanel_1->setBackgroundColor(pStyle->_bgColor); - _pProjectPanel_1->setForegroundColor(pStyle->_fgColor); - ::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); - } + if (pStyle && _pClipboardHistoryPanel) + { + _pClipboardHistoryPanel->setBackgroundColor(pStyle->_bgColor); + _pClipboardHistoryPanel->setForegroundColor(pStyle->_fgColor); + _pClipboardHistoryPanel->redraw(true); + } - if (pStyle && _pProjectPanel_2) - { - _pProjectPanel_2->setBackgroundColor(pStyle->_bgColor); - _pProjectPanel_2->setForegroundColor(pStyle->_fgColor); - ::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); - } + if (pStyle && _pProjectPanel_1) + { + _pProjectPanel_1->setBackgroundColor(pStyle->_bgColor); + _pProjectPanel_1->setForegroundColor(pStyle->_fgColor); + ::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); + } - if (pStyle && _pProjectPanel_3) - { - _pProjectPanel_3->setBackgroundColor(pStyle->_bgColor); - _pProjectPanel_3->setForegroundColor(pStyle->_fgColor); - ::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); - } + if (pStyle && _pProjectPanel_2) + { + _pProjectPanel_2->setBackgroundColor(pStyle->_bgColor); + _pProjectPanel_2->setForegroundColor(pStyle->_fgColor); + ::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); + } - if (pStyle && _pFileBrowser) - { - _pFileBrowser->setBackgroundColor(pStyle->_bgColor); - _pFileBrowser->setForegroundColor(pStyle->_fgColor); - ::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); + if (pStyle && _pProjectPanel_3) + { + _pProjectPanel_3->setBackgroundColor(pStyle->_bgColor); + _pProjectPanel_3->setForegroundColor(pStyle->_fgColor); + ::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); + } + + if (pStyle && _pFileBrowser) + { + _pFileBrowser->setBackgroundColor(pStyle->_bgColor); + _pFileBrowser->setForegroundColor(pStyle->_fgColor); + ::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); + } } if (_pDocMap) diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index be29a5bda517..870999f12dd0 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -290,14 +290,14 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM { updateUserKeywords(); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } else if (editID == IDC_USER_EXT_EDIT) { updateExtension(); notifyDataModified(); - apply(false); + apply(NO_VISUAL_CHANGE); return TRUE; } return FALSE; @@ -309,19 +309,19 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM case IDC_BOLD_CHECK : updateFontStyleStatus(BOLD_STATUS); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; case IDC_ITALIC_CHECK : updateFontStyleStatus(ITALIC_STATUS); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; case IDC_UNDERLINE_CHECK : updateFontStyleStatus(UNDERLINE_STATUS); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; case IDC_GLOBAL_GOTOSETTINGS_LINK : @@ -429,7 +429,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableFg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } @@ -438,7 +438,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableBg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } @@ -447,7 +447,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableFont = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } case IDC_GLOBAL_FONTSIZE_CHECK : @@ -455,7 +455,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableFontSize = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } case IDC_GLOBAL_BOLD_CHECK : @@ -463,7 +463,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableBold = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } @@ -472,7 +472,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableItalic = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } case IDC_GLOBAL_UNDERLINE_CHECK : @@ -480,7 +480,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM GlobalOverride & glo = (NppParameters::getInstance()).getGlobalOverrideStyle(); glo.enableUnderLine = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0)); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); return TRUE; } @@ -494,12 +494,12 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM case IDC_FONT_COMBO : updateFontName(); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); break; case IDC_FONTSIZE_COMBO : updateFontSize(); notifyDataModified(); - apply(); + apply(GENERAL_CHANGE); break; case IDC_LANGUAGES_LIST : { @@ -525,12 +525,15 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM case CPN_COLOURPICKED: { + int applicationInfo = getApplicationInfo(); + int tabColourIndex = whichTabColourIndex(); + if (reinterpret_cast(lParam) == _pFgColour->getHSelf()) { updateColour(C_FOREGROUND); notifyDataModified(); - int tabColourIndex; - if ((tabColourIndex = whichTabColourIndex()) != -1) + + if (tabColourIndex != -1) { TabBarPlus::setColour(_pFgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex, nullptr); } @@ -538,15 +541,16 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM { ViewZoneDlg::setColour(_pFgColour->getColour(), ViewZoneDlg::ViewZoneColorIndex::focus); } - apply(); + apply(applicationInfo); return TRUE; } else if (reinterpret_cast(lParam) == _pBgColour->getHSelf()) { updateColour(C_BACKGROUND); notifyDataModified(); - int tabColourIndex; - if ((tabColourIndex = whichTabColourIndex()) != -1) + + + if (tabColourIndex != -1) { tabColourIndex = (tabColourIndex == TabBarPlus::inactiveText ? TabBarPlus::inactiveBg : tabColourIndex); TabBarPlus::setColour(_pBgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex, nullptr); @@ -569,7 +573,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM } } - apply(); + apply(applicationInfo); return TRUE; } else @@ -633,7 +637,7 @@ void WordStyleDlg::updateThemeName(const wstring& themeName) nppGUI._themeName.assign( themeName ); } -bool WordStyleDlg::getStyleName(wchar_t *styleName, const size_t styleNameLen) +bool WordStyleDlg::getStyleName(wchar_t *styleName, const size_t styleNameLen) const { auto i = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETCURSEL, 0, 0); if (i == LB_ERR) @@ -648,7 +652,40 @@ bool WordStyleDlg::getStyleName(wchar_t *styleName, const size_t styleNameLen) return true; } -int WordStyleDlg::whichTabColourIndex() +int WordStyleDlg::getApplicationInfo() const +{ + constexpr size_t styleNameLen = 128; + wchar_t styleName[styleNameLen + 1] = { '\0' }; + + if (!WordStyleDlg::getStyleName(styleName, styleNameLen)) + { + return NO_VISUAL_CHANGE; + } + + if (lstrcmp(styleName, L"Default Style") == 0) + return (GENERAL_CHANGE | THEME_CHANGE); + + if ((lstrcmp(styleName, L"Mark Style 1") == 0) || + (lstrcmp(styleName, L"Mark Style 2") == 0) || + (lstrcmp(styleName, L"Mark Style 3") == 0) || + (lstrcmp(styleName, L"Mark Style 4") == 0) || + (lstrcmp(styleName, L"Mark Style 5") == 0) || + (lstrcmp(styleName, L"Tab color 1") == 0) || + (lstrcmp(styleName, L"Tab color 2") == 0) || + (lstrcmp(styleName, L"Tab color 3") == 0) || + (lstrcmp(styleName, L"Tab color 4") == 0) || + (lstrcmp(styleName, L"Tab color 5") == 0) || + (lstrcmp(styleName, L"Tab color dark mode 1") == 0) || + (lstrcmp(styleName, L"Tab color dark mode 2") == 0) || + (lstrcmp(styleName, L"Tab color dark mode 3") == 0) || + (lstrcmp(styleName, L"Tab color dark mode 4") == 0) || + (lstrcmp(styleName, L"Tab color dark mode 5") == 0)) + return (GENERAL_CHANGE | COLOR_CHANGE_4_MENU); + + return GENERAL_CHANGE; +} + +int WordStyleDlg::whichTabColourIndex() const { constexpr size_t styleNameLen = 128; wchar_t styleName[styleNameLen + 1] = { '\0' }; @@ -880,7 +917,7 @@ void WordStyleDlg::applyCurrentSelectedThemeAndUpdateUI() setVisualFromStyleList(); notifyDataModified(); _isThemeDirty = false; - apply(); + apply(GENERAL_CHANGE | THEME_CHANGE); } bool WordStyleDlg::selectThemeByName(const wchar_t* themeName) @@ -1319,8 +1356,7 @@ void WordStyleDlg::restoreGlobalOverrideValues() gOverride = _gOverride2restored; } - -void WordStyleDlg::apply(bool needVisualApply) +void WordStyleDlg::apply(int applicationInfo) { LexerStylerArray & lsa = (NppParameters::getInstance()).getLStylerArray(); lsa = _lsArray; @@ -1328,11 +1364,10 @@ void WordStyleDlg::apply(bool needVisualApply) StyleArray & globalStyles = (NppParameters::getInstance()).getGlobalStylers(); globalStyles = _globalStyles; - if (needVisualApply) - { - ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); + if (applicationInfo & GENERAL_CHANGE || applicationInfo & THEME_CHANGE) + ::SendMessage(_hParent, WM_UPDATESCINTILLAS, (applicationInfo & THEME_CHANGE) != 0, 0); + if (applicationInfo & COLOR_CHANGE_4_MENU) ::SendMessage(_hParent, WM_UPDATEMAINMENUBITMAPS, 0, 0); - } ::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE); } diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h index b8fce2900a82..d6c4341604df 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h @@ -26,6 +26,11 @@ #define WM_UPDATESCINTILLAS (WORDSTYLE_USER + 1) //GlobalStyleDlg's msg 2 send 2 its parent #define WM_UPDATEMAINMENUBITMAPS (WORDSTYLE_USER + 2) +#define NO_VISUAL_CHANGE 0x00 +#define GENERAL_CHANGE 0x01 +#define THEME_CHANGE 0x02 +#define COLOR_CHANGE_4_MENU 0x04 + enum fontStyleType {BOLD_STATUS, ITALIC_STATUS, UNDERLINE_STATUS}; const bool C_FOREGROUND = false; @@ -67,7 +72,6 @@ public : void prepare2Cancel(); void redraw(bool forceUpdate = false) const override; void restoreGlobalOverrideValues(); - void apply(bool needVisualApply = true); void addLastThemeEntry(); bool selectThemeByName(const wchar_t* themeName); bool goToSection(const wchar_t* sectionNames); // sectionNames is formed as following: "Language name:Style name" @@ -116,10 +120,12 @@ private : Style& getCurrentStyler(); - bool getStyleName(wchar_t *styleName, const size_t styleNameLen); + bool getStyleName(wchar_t *styleName, const size_t styleNameLen) const; - int whichTabColourIndex(); + int whichTabColourIndex() const; int whichIndividualTabColourId(); + void apply(int applicationInfo); + int getApplicationInfo() const; bool isDocumentMapStyle(); void move2CtrlRight(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight); void updateColour(bool which);