Skip to content

Commit

Permalink
Make toolbar dark mode support better for plugins
Browse files Browse the repository at this point in the history
Tweak dark mode custom draw for plugin:
- add plugin custom draw support for toolbar
- make code more consistent
- make plugin's authors custom draw implementation
to have higher priority than one from generic dark mode

ref #15078 (comment)

Close #15147
  • Loading branch information
ozone10 authored and donho committed May 17, 2024
1 parent e25e15b commit 5123016
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 41 deletions.
112 changes: 74 additions & 38 deletions PowerEditor/src/NppDarkMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2576,7 +2576,7 @@ namespace NppDarkMode
}
}

LRESULT darkToolBarNotifyCustomDraw(LPARAM lParam)
LRESULT darkToolBarNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin)
{
auto nmtbcd = reinterpret_cast<LPNMTBCUSTOMDRAW>(lParam);
static int roundCornerValue = 0;
Expand All @@ -2585,6 +2585,7 @@ namespace NppDarkMode
{
case CDDS_PREPAINT:
{
LRESULT lr = CDRF_DODEFAULT;
if (NppDarkMode::isEnabled())
{
if (NppDarkMode::isWindows11())
Expand All @@ -2595,9 +2596,15 @@ namespace NppDarkMode
}

::FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getDarkerBackgroundBrush());
return CDRF_NOTIFYITEMDRAW;
lr |= CDRF_NOTIFYITEMDRAW;
}
return CDRF_DODEFAULT;

if (isPlugin)
{
lr |= ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

return lr;
}

case CDDS_ITEMPREPAINT:
Expand All @@ -2622,7 +2629,13 @@ namespace NppDarkMode
nmtbcd->nmcd.uItemState &= ~CDIS_CHECKED;
}

return TBCDRF_HILITEHOTTRACK | TBCDRF_USECDCOLORS | CDRF_NOTIFYPOSTPAINT;
LRESULT lr = TBCDRF_HILITEHOTTRACK | TBCDRF_USECDCOLORS | CDRF_NOTIFYPOSTPAINT;
if (isPlugin)
{
lr |= ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

return lr;
}

case CDDS_ITEMPOSTPAINT:
Expand All @@ -2645,12 +2658,18 @@ namespace NppDarkMode
NppDarkMode::paintRoundFrameRect(nmtbcd->nmcd.hdc, nmtbcd->nmcd.rc, NppDarkMode::getHotEdgePen(), roundCornerValue, roundCornerValue);
}

if (isPlugin)
{
break;
}

return CDRF_DODEFAULT;
}

default:
return CDRF_DODEFAULT;
break;
}
return ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

LRESULT darkListViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin)
Expand All @@ -2661,7 +2680,13 @@ namespace NppDarkMode
{
case CDDS_PREPAINT:
{
return CDRF_NOTIFYITEMDRAW;
LRESULT lr = CDRF_NOTIFYITEMDRAW;
if (isPlugin)
{
lr |= ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

return lr;
}

case CDDS_ITEMPREPAINT:
Expand Down Expand Up @@ -2691,14 +2716,14 @@ namespace NppDarkMode
::DrawFocusRect(lplvcd->nmcd.hdc, &lplvcd->nmcd.rc);
}

LRESULT lr = CDRF_DODEFAULT;
LRESULT lr = CDRF_NEWFONT;

if (isPlugin)
{
lr = ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
lr |= ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

return lr | CDRF_NEWFONT;
return lr;
}

default:
Expand All @@ -2715,48 +2740,54 @@ namespace NppDarkMode
{
case CDDS_PREPAINT:
{
LRESULT defaultValue = isPlugin ? DefSubclassProc(hWnd, uMsg, wParam, lParam) : CDRF_DODEFAULT;
if (NppDarkMode::isEnabled())
LRESULT lr = NppDarkMode::isEnabled() ? CDRF_NOTIFYITEMDRAW : CDRF_DODEFAULT;

if (isPlugin)
{
return defaultValue | CDRF_NOTIFYITEMDRAW;
lr |= ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
return defaultValue;

return lr;
}

case CDDS_ITEMPREPAINT:
{
LRESULT defaultValue = isPlugin ? DefSubclassProc(hWnd, uMsg, wParam, lParam) : CDRF_DODEFAULT;
if (NppDarkMode::isEnabled() && (lptvcd->nmcd.uItemState & CDIS_SELECTED) == CDIS_SELECTED)
{
lptvcd->clrText = NppDarkMode::getTextColor();
lptvcd->clrTextBk = NppDarkMode::getSofterBackgroundColor();
::FillRect(lptvcd->nmcd.hdc, &lptvcd->nmcd.rc, NppDarkMode::getSofterBackgroundBrush());

return defaultValue | CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT;
}
LRESULT lr = CDRF_DODEFAULT;

if (NppDarkMode::isEnabled() && (lptvcd->nmcd.uItemState & CDIS_HOT) == CDIS_HOT)
if (NppDarkMode::isEnabled())
{
lptvcd->clrText = NppDarkMode::getTextColor();
lptvcd->clrTextBk = NppDarkMode::getHotBackgroundColor();
if ((lptvcd->nmcd.uItemState & CDIS_SELECTED) == CDIS_SELECTED)
{
lptvcd->clrText = NppDarkMode::getTextColor();
lptvcd->clrTextBk = NppDarkMode::getSofterBackgroundColor();
::FillRect(lptvcd->nmcd.hdc, &lptvcd->nmcd.rc, NppDarkMode::getSofterBackgroundBrush());

auto notifyResult = defaultValue;
if (g_isAtLeastWindows10 || g_treeViewStyle == TreeViewStyle::light)
lr |= CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT;
}
else if ((lptvcd->nmcd.uItemState & CDIS_HOT) == CDIS_HOT)
{
::FillRect(lptvcd->nmcd.hdc, &lptvcd->nmcd.rc, NppDarkMode::getHotBackgroundBrush());
notifyResult |= CDRF_NOTIFYPOSTPAINT;
lptvcd->clrText = NppDarkMode::getTextColor();
lptvcd->clrTextBk = NppDarkMode::getHotBackgroundColor();

if (g_isAtLeastWindows10 || g_treeViewStyle == TreeViewStyle::light)
{
::FillRect(lptvcd->nmcd.hdc, &lptvcd->nmcd.rc, NppDarkMode::getHotBackgroundBrush());
lr |= CDRF_NOTIFYPOSTPAINT;
}
lr |= CDRF_NEWFONT;
}
}

return CDRF_NEWFONT | notifyResult;
if (isPlugin)
{
lr |= ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

return defaultValue;
return lr;
}

case CDDS_ITEMPOSTPAINT:
{
LRESULT defaultValue = isPlugin ? DefSubclassProc(hWnd, uMsg, wParam, lParam) : CDRF_DODEFAULT;

if (NppDarkMode::isEnabled())
{
RECT rcFrame = lptvcd->nmcd.rc;
Expand All @@ -2773,13 +2804,18 @@ namespace NppDarkMode
}
}

return defaultValue;

if (isPlugin)
{
break;
}

return CDRF_DODEFAULT;
}

default:
return isPlugin ? DefSubclassProc(hWnd, uMsg, wParam, lParam) : CDRF_DODEFAULT;
break;
}
return ::DefSubclassProc(hWnd, uMsg, wParam, lParam);
}

constexpr UINT_PTR g_pluginDockWindowSubclassID = 42;
Expand Down Expand Up @@ -2888,7 +2924,7 @@ namespace NppDarkMode

if (wcscmp(className, TOOLBARCLASSNAME) == 0)
{
return NppDarkMode::darkToolBarNotifyCustomDraw(lParam);
return NppDarkMode::darkToolBarNotifyCustomDraw(hWnd, uMsg, wParam, lParam, true);
}

if (wcscmp(className, WC_LISTVIEW) == 0)
Expand Down Expand Up @@ -3041,7 +3077,7 @@ namespace NppDarkMode
{
if (wcscmp(className, TOOLBARCLASSNAME) == 0)
{
return NppDarkMode::darkToolBarNotifyCustomDraw(lParam);
return NppDarkMode::darkToolBarNotifyCustomDraw(hWnd, uMsg, wParam, lParam, false);
}

if (wcscmp(className, WC_LISTVIEW) == 0)
Expand Down
6 changes: 3 additions & 3 deletions PowerEditor/src/NppDarkMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ namespace NppDarkMode
void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass = true, bool theme = true);
void autoThemeChildControls(HWND hwndParent);

LRESULT darkToolBarNotifyCustomDraw(LPARAM lParam);
LRESULT darkListViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);
LRESULT darkTreeViewNotifyCustomDraw(LPARAM lParam);
static LRESULT darkToolBarNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);

This comment has been minimized.

Copy link
@chcg

chcg May 21, 2024

Contributor

@ozone10
What is the idea behind static in the header file (https://stackoverflow.com/questions/780730/c-c-static-function-in-header-file-what-does-it-mean) ?

For my linux gcc 13 build (, see https://github.com/chcg/notepad-plus-plus/actions/runs/9157602518/job/25174304256) is causes:

compiling ../src/MISC/RegExt/regExtDlg.cpp
In file included from ../src/./dpiManagerV2.h:19,
                 from ../src/WinControls/StaticDialog/StaticDialog.h:18,
                 from ../src/MISC/RegExt/regExtDlg.h:21,
                 from ../src/MISC/RegExt/regExtDlg.cpp:17:
../src/./NppDarkMode.h:218:24: warning: ‘LRESULT NppDarkMode::darkToolBarNotifyCustomDraw(HWND, UINT, WPARAM, LPARAM, bool)’ declared ‘static’ but never defined [-Wunused-function]
  218 |         static LRESULT darkToolBarNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/./NppDarkMode.h:219:24: warning: ‘LRESULT NppDarkMode::darkListViewNotifyCustomDraw(HWND, UINT, WPARAM, LPARAM, bool)’ declared ‘static’ but never defined [-Wunused-function]
  219 |         static LRESULT darkListViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/./NppDarkMode.h:220:24: warning: ‘LRESULT NppDarkMode::darkTreeViewNotifyCustomDraw(HWND, UINT, WPARAM, LPARAM, bool)’ declared ‘static’ but never defined [-Wunused-function]
  220 |         static LRESULT darkTreeViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

for each cpp file including NppDarkMode.h

This comment has been minimized.

Copy link
@ozone10

ozone10 May 21, 2024

Author Contributor

@chcg
my mistake, I forgot to remove them (they are not used elsewhere, only in NppDarkMode.cpp).
Check PR #15171, it should fix it.

This comment has been minimized.

Copy link
@chcg

chcg May 22, 2024

Contributor

Yes the PR fixed it. Thanks for the fast reaction.

static LRESULT darkListViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);
static LRESULT darkTreeViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);

void autoSubclassAndThemePluginDockWindow(HWND hwnd);
ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags);
Expand Down

0 comments on commit 5123016

Please sign in to comment.