diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 5e74c74d5964..dacecd368de5 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2374,6 +2374,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa _pFileBrowser->setForegroundColor(pStyle->_fgColor); ::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); } + + NppDarkMode::updateTreeViewStylePrev(); } if (_pDocMap) diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 075effd5d0ef..63eb0a18cd2d 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -591,6 +591,7 @@ namespace NppDarkMode return invert_c; } + static TreeViewStyle g_treeViewStylePrev = TreeViewStyle::classic; static TreeViewStyle g_treeViewStyle = TreeViewStyle::classic; static COLORREF g_treeViewBg = NppParameters::getInstance().getCurrentDefaultBgColor(); static double g_lightnessTreeView = 50.0; @@ -1094,7 +1095,7 @@ namespace NppDarkMode static void renderButton(HWND hwnd, HDC hdc, HTHEME hTheme, int iPartID, int iStateID) { RECT rcClient{}; - WCHAR szText[256] = { '\0' }; + wchar_t szText[256] = { '\0' }; DWORD nState = static_cast(SendMessage(hwnd, BM_GETSTATE, 0, 0)); DWORD uiState = static_cast(SendMessage(hwnd, WM_QUERYUISTATE, 0, 0)); auto nStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE); @@ -1414,7 +1415,7 @@ namespace NppDarkMode hOldFont = static_cast(::SelectObject(hdc, hFont)); - WCHAR szText[256] = { '\0' }; + wchar_t szText[256] = { '\0' }; GetWindowText(hwnd, szText, _countof(szText)); auto style = static_cast(::GetWindowLongPtr(hwnd, GWL_STYLE)); @@ -1486,14 +1487,12 @@ namespace NppDarkMode DWORD_PTR dwRefData ) { - UNREFERENCED_PARAMETER(uIdSubclass); - auto pButtonData = reinterpret_cast(dwRefData); switch (uMsg) { case WM_NCDESTROY: - RemoveWindowSubclass(hWnd, GroupboxSubclass, g_groupboxSubclassID); + RemoveWindowSubclass(hWnd, GroupboxSubclass, uIdSubclass); delete pButtonData; break; @@ -2577,8 +2576,8 @@ namespace NppDarkMode TreeView_SetTextColor(hwnd, NppParameters::getInstance().getCurrentDefaultFgColor()); TreeView_SetBkColor(hwnd, NppParameters::getInstance().getCurrentDefaultBgColor()); - NppDarkMode::calculateTreeViewStyle(); - NppDarkMode::setTreeViewStyle(hwnd); + //NppDarkMode::calculateTreeViewStyle(); + NppDarkMode::setTreeViewStyle(hwnd, p._theme); if (p._theme) { @@ -3253,54 +3252,72 @@ namespace NppDarkMode } } + void updateTreeViewStylePrev() + { + g_treeViewStylePrev = g_treeViewStyle; + } + TreeViewStyle getTreeViewStyle() { const auto style = g_treeViewStyle; return style; } - void setTreeViewStyle(HWND hwnd) + void setTreeViewStyle(HWND hWnd, bool force) { - auto style = static_cast(::GetWindowLongPtr(hwnd, GWL_STYLE)); - bool hasHotStyle = (style & TVS_TRACKSELECT) == TVS_TRACKSELECT; - bool change = false; - switch (g_treeViewStyle) + if (force || g_treeViewStylePrev != g_treeViewStyle) { - case TreeViewStyle::light: + auto style = ::GetWindowLongPtr(hWnd, GWL_STYLE); + const bool hasHotStyle = (style & TVS_TRACKSELECT) == TVS_TRACKSELECT; + bool change = false; + std::wstring strSubAppName; + + switch (g_treeViewStyle) { - if (!hasHotStyle) + case TreeViewStyle::light: { - style |= TVS_TRACKSELECT; - change = true; + if (!hasHotStyle) + { + style |= TVS_TRACKSELECT; + change = true; + } + strSubAppName = L"Explorer"; + break; } - SetWindowTheme(hwnd, L"Explorer", nullptr); - break; - } - case TreeViewStyle::dark: - { - if (!hasHotStyle) + + case TreeViewStyle::dark: + { + if (NppDarkMode::isExperimentalSupported()) + { + if (!hasHotStyle) + { + style |= TVS_TRACKSELECT; + change = true; + } + strSubAppName = L"DarkMode_Explorer"; + break; + } + [[fallthrough]]; + } + + case TreeViewStyle::classic: { - style |= TVS_TRACKSELECT; - change = true; + if (hasHotStyle) + { + style &= ~TVS_TRACKSELECT; + change = true; + } + strSubAppName = L""; + break; } - SetWindowTheme(hwnd, g_isAtLeastWindows10 ? L"DarkMode_Explorer" : nullptr, nullptr); - break; } - case TreeViewStyle::classic: + + if (change) { - if (hasHotStyle) - { - style &= ~TVS_TRACKSELECT; - change = true; - } - SetWindowTheme(hwnd, nullptr, nullptr); - break; + ::SetWindowLongPtr(hWnd, GWL_STYLE, style); } - } - if (change) - { - ::SetWindowLongPtr(hwnd, GWL_STYLE, style); + ::SetWindowTheme(hWnd, strSubAppName.empty() ? nullptr : strSubAppName.c_str(), nullptr); } } diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index fe8163925395..497a95e36eb9 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -226,8 +226,9 @@ namespace NppDarkMode void disableVisualStyle(HWND hwnd, bool doDisable); void calculateTreeViewStyle(); + void updateTreeViewStylePrev(); TreeViewStyle getTreeViewStyle(); - void setTreeViewStyle(HWND hwnd); + void setTreeViewStyle(HWND hWnd, bool force = false); bool isThemeDark(); void setBorder(HWND hwnd, bool border = true); diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index 01e1f407f9d6..1a15ba8b9704 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -217,7 +217,10 @@ intptr_t CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM l NppDarkMode::autoThemeChildControls(_hSelf); ::SendMessage(_hToolbarMenu, TB_SETIMAGELIST, 0, reinterpret_cast(_iconListVector.at(NppDarkMode::isEnabled() ? 1 : 0))); } - NppDarkMode::setTreeViewStyle(_treeView.getHSelf()); + else + { + NppDarkMode::setTreeViewStyle(_treeView.getHSelf()); + } std::vector imgIds = _treeView.getImageIds( { IDI_FB_ROOTOPEN, IDI_FB_ROOTCLOSE, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE } diff --git a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp index e02bb721996c..fff2c104f184 100644 --- a/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp +++ b/PowerEditor/src/WinControls/FunctionList/functionListPanel.cpp @@ -971,7 +971,10 @@ intptr_t CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LP NppDarkMode::autoThemeChildControls(_hSelf); ::SendMessage(_hToolbarMenu, TB_SETIMAGELIST, 0, reinterpret_cast(_iconListVector.at(NppDarkMode::isEnabled() ? 1 : 0))); } - NppDarkMode::setTreeViewStyle(_treeView.getHSelf()); + else + { + NppDarkMode::setTreeViewStyle(_treeView.getHSelf()); + } std::vector imgIds = _treeView.getImageIds( { IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF } diff --git a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp index 918144c6871b..b0d98f23688e 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp @@ -110,7 +110,10 @@ intptr_t CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM { NppDarkMode::autoThemeChildControls(_hSelf); } - NppDarkMode::setTreeViewStyle(_treeView.getHSelf()); + else + { + NppDarkMode::setTreeViewStyle(_treeView.getHSelf()); + } std::vector imgIds = _treeView.getImageIds( { IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID } diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.cpp b/PowerEditor/src/WinControls/TreeView/TreeView.cpp index 2f45124644bf..52a8f2cb45b8 100644 --- a/PowerEditor/src/WinControls/TreeView/TreeView.cpp +++ b/PowerEditor/src/WinControls/TreeView/TreeView.cpp @@ -46,7 +46,7 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID) _hInst, nullptr); - NppDarkMode::setTreeViewStyle(_hSelf); + NppDarkMode::setTreeViewStyle(_hSelf, true); const int itemHeight = DPIManagerV2::scale(g_treeviewIcoSize + g_treeviewItemPadding * 2, _hParent); TreeView_SetItemHeight(_hSelf, itemHeight);