Skip to content

Commit ec4a874

Browse files
committed
add darkmode support for dialogs derived from StaticDialog
1 parent 2e6a5d4 commit ec4a874

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

NppPlugin/src/NppDarkModeDummy.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1-
#include "stdafx.h" //ADDED BY PYTHONSCRIPT
21
#include "NppDarkMode.h"
2+
#include "PluginInterface.h"
3+
4+
extern NppData nppData;
5+
6+
static constexpr COLORREF HEXRGB(DWORD rrggbb) {
7+
// from 0xRRGGBB like natural #RRGGBB
8+
// to the little-endian 0xBBGGRR
9+
return
10+
((rrggbb & 0xFF0000) >> 16) |
11+
((rrggbb & 0x00FF00)) |
12+
((rrggbb & 0x0000FF) << 16);
13+
}
14+
315

416
namespace NppDarkMode
517
{
618
bool isEnabled()
719
{
8-
return false;
20+
return ::SendMessage(nppData._nppHandle, NPPM_ISDARKMODEENABLED, 0, 0);
21+
}
22+
23+
HBRUSH getDarkerBackgroundBrush()
24+
{
25+
return ::CreateSolidBrush(HEXRGB(0x202020));
26+
}
27+
28+
COLORREF getTextColor()
29+
{
30+
return HEXRGB(0xE0E0E0);
931
}
1032

11-
HBRUSH getDlgBackgroundBrush()
33+
COLORREF getDarkerTextColor()
1234
{
13-
return 0;
35+
return HEXRGB(0xC0C0C0);
36+
}
37+
38+
COLORREF getLinkTextColor()
39+
{
40+
return HEXRGB(0xFFFF00);
41+
}
42+
43+
COLORREF getDarkerBackgroundColor()
44+
{
45+
return HEXRGB(0x202020);
1446
}
1547

1648
void setDarkTitleBar(HWND /*hwnd*/)
@@ -19,6 +51,19 @@ namespace NppDarkMode
1951

2052
bool isWindows10()
2153
{
22-
return true;
54+
return false;
2355
}
56+
57+
LRESULT onCtlColorDarker(HDC hdc)
58+
{
59+
if (!NppDarkMode::isEnabled())
60+
{
61+
return FALSE;
62+
}
63+
64+
::SetTextColor(hdc, NppDarkMode::getTextColor());
65+
::SetBkColor(hdc, NppDarkMode::getDarkerBackgroundColor());
66+
return reinterpret_cast<LRESULT>(NppDarkMode::getDarkerBackgroundBrush());
67+
}
68+
2469
}

NppPlugin/src/StaticDialog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
274274

275275
// if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent
276276
::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf));
277+
//Modified for darkmode support
278+
::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_DARKMODESUBCLASSANDTHEME, static_cast<WPARAM>(NppDarkMode::dmfInit), reinterpret_cast<LPARAM>(_hSelf));
277279
}
278280

279281
intptr_t CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

0 commit comments

Comments
 (0)