Browse Source

Make toolbar dark mode support better for plugins

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
pull/15154/head
ozone10 6 months ago committed by Don Ho
parent
commit
5123016baa
  1. 112
      PowerEditor/src/NppDarkMode.cpp
  2. 6
      PowerEditor/src/NppDarkMode.h

112
PowerEditor/src/NppDarkMode.cpp

@ -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;
@ -2585,6 +2585,7 @@ namespace NppDarkMode
{
case CDDS_PREPAINT:
{
LRESULT lr = CDRF_DODEFAULT;
if (NppDarkMode::isEnabled())
{
if (NppDarkMode::isWindows11())
@ -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:
@ -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:
@ -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)
@ -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:
@ -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:
@ -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;
@ -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;
@ -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)
@ -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)

6
PowerEditor/src/NppDarkMode.h

@ -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);
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);

Loading…
Cancel
Save