Skip to content

Commit

Permalink
Improve Styler Configurator performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ozone10 authored and donho committed Aug 23, 2024
1 parent ad79718 commit 86adb21
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 43 deletions.
2 changes: 2 additions & 0 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
93 changes: 55 additions & 38 deletions PowerEditor/src/NppDarkMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DWORD>(SendMessage(hwnd, BM_GETSTATE, 0, 0));
DWORD uiState = static_cast<DWORD>(SendMessage(hwnd, WM_QUERYUISTATE, 0, 0));
auto nStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE);
Expand Down Expand Up @@ -1414,7 +1415,7 @@ namespace NppDarkMode

hOldFont = static_cast<HFONT>(::SelectObject(hdc, hFont));

WCHAR szText[256] = { '\0' };
wchar_t szText[256] = { '\0' };
GetWindowText(hwnd, szText, _countof(szText));

auto style = static_cast<long>(::GetWindowLongPtr(hwnd, GWL_STYLE));
Expand Down Expand Up @@ -1486,14 +1487,12 @@ namespace NppDarkMode
DWORD_PTR dwRefData
)
{
UNREFERENCED_PARAMETER(uIdSubclass);

auto pButtonData = reinterpret_cast<ButtonData*>(dwRefData);

switch (uMsg)
{
case WM_NCDESTROY:
RemoveWindowSubclass(hWnd, GroupboxSubclass, g_groupboxSubclassID);
RemoveWindowSubclass(hWnd, GroupboxSubclass, uIdSubclass);
delete pButtonData;
break;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<long>(::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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/NppDarkMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LPARAM>(_iconListVector.at(NppDarkMode::isEnabled() ? 1 : 0)));
}
NppDarkMode::setTreeViewStyle(_treeView.getHSelf());
else
{
NppDarkMode::setTreeViewStyle(_treeView.getHSelf());
}

std::vector<int> imgIds = _treeView.getImageIds(
{ IDI_FB_ROOTOPEN, IDI_FB_ROOTCLOSE, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<LPARAM>(_iconListVector.at(NppDarkMode::isEnabled() ? 1 : 0)));
}
NppDarkMode::setTreeViewStyle(_treeView.getHSelf());
else
{
NppDarkMode::setTreeViewStyle(_treeView.getHSelf());
}

std::vector<int> imgIds = _treeView.getImageIds(
{ IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF }
Expand Down
5 changes: 4 additions & 1 deletion PowerEditor/src/WinControls/ProjectPanel/ProjectPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> imgIds = _treeView.getImageIds(
{ IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID }
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/WinControls/TreeView/TreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 86adb21

Please sign in to comment.