Skip to content

Commit d2b1349

Browse files
committed
fix #24 , #27
- reverted change from #17 and partly from #19 as N++ in the meantime changed behavior for gui controls and therefore list control is working again as before - updated some files from N++
1 parent 351c0b9 commit d2b1349

6 files changed

+273
-10
lines changed

NppTaskList.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
<ClInclude Include="include\dockingResource.h" />
254254
<ClInclude Include="include\menuCmdID.h" />
255255
<ClInclude Include="include\Notepad_plus_msgs.h" />
256+
<ClInclude Include="include\NppDarkMode.h" />
256257
<ClInclude Include="include\PluginDefinition.h" />
257258
<ClInclude Include="include\PluginInterface.h" />
258259
<ClInclude Include="include\Scintilla.h" />
@@ -269,6 +270,7 @@
269270
<ClCompile Include="src\AboutDialog\AboutDlg.cpp" />
270271
<ClCompile Include="src\Common.cpp" />
271272
<ClCompile Include="src\config.cpp" />
273+
<ClCompile Include="src\NppDarkModeDummy.cpp" />
272274
<ClCompile Include="src\NppTaskListPlugin.cpp" />
273275
<ClCompile Include="src\PluginDefinition.cpp" />
274276
<ClCompile Include="src\StaticDialog.cpp" />

include/DockingDlgInterface.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <shlwapi.h>
2525
#include "Common.h"
2626
#include "StaticDialog.h"
27+
#include "NppDarkMode.h"
2728

2829

2930

@@ -93,9 +94,21 @@ protected :
9394
generic_string _pluginName;
9495
bool _isClosed = false;
9596

96-
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM , LPARAM lParam) {
97+
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
9798
switch (message)
9899
{
100+
case WM_ERASEBKGND:
101+
{
102+
if (!NppDarkMode::isEnabled())
103+
{
104+
break;
105+
}
106+
107+
RECT rc = {};
108+
getClientRect(rc);
109+
::FillRect(reinterpret_cast<HDC>(wParam), &rc, NppDarkMode::getDarkerBackgroundBrush());
110+
return TRUE;
111+
}
99112
case WM_NOTIFY:
100113
{
101114
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(lParam);

include/NppDarkMode.h

+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
// This file is part of Notepad++ project
2+
// Copyright (c) 2021 adzm / Adam D. Walling
3+
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// at your option any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
#pragma once
18+
19+
#include <windows.h>
20+
21+
constexpr COLORREF HEXRGB(DWORD rrggbb) {
22+
// from 0xRRGGBB like natural #RRGGBB
23+
// to the little-endian 0xBBGGRR
24+
return
25+
((rrggbb & 0xFF0000) >> 16) |
26+
((rrggbb & 0x00FF00) ) |
27+
((rrggbb & 0x0000FF) << 16);
28+
}
29+
30+
namespace NppDarkMode
31+
{
32+
struct Colors
33+
{
34+
COLORREF background = 0;
35+
COLORREF softerBackground = 0;
36+
COLORREF hotBackground = 0;
37+
COLORREF pureBackground = 0;
38+
COLORREF errorBackground = 0;
39+
COLORREF text = 0;
40+
COLORREF darkerText = 0;
41+
COLORREF disabledText = 0;
42+
COLORREF linkText = 0;
43+
COLORREF edge = 0;
44+
COLORREF hotEdge = 0;
45+
COLORREF disabledEdge = 0;
46+
};
47+
48+
struct Options
49+
{
50+
bool enable = false;
51+
bool enableMenubar = false;
52+
bool enablePlugin = false;
53+
};
54+
55+
struct NppDarkModeParams
56+
{
57+
const wchar_t* _themeClassName = nullptr;
58+
bool _subclass = false;
59+
bool _theme = false;
60+
};
61+
62+
enum class ToolTipsType
63+
{
64+
tooltip,
65+
toolbar,
66+
listview,
67+
treeview,
68+
tabbar
69+
};
70+
71+
enum ColorTone {
72+
blackTone = 0,
73+
redTone = 1,
74+
greenTone = 2,
75+
blueTone = 3,
76+
purpleTone = 4,
77+
cyanTone = 5,
78+
oliveTone = 6,
79+
customizedTone = 32
80+
};
81+
82+
enum class TreeViewStyle
83+
{
84+
classic = 0,
85+
light = 1,
86+
dark = 2
87+
};
88+
89+
void initDarkMode(); // pulls options from NppParameters
90+
void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent
91+
92+
bool isEnabled();
93+
bool isDarkMenuEnabled();
94+
bool isEnabledForPlugins();
95+
bool isExperimentalSupported();
96+
97+
bool isWindows10();
98+
bool isWindows11();
99+
100+
COLORREF invertLightness(COLORREF c);
101+
COLORREF invertLightnessSofter(COLORREF c);
102+
double calculatePerceivedLighness(COLORREF c);
103+
104+
void setDarkTone(ColorTone colorToneChoice);
105+
106+
COLORREF getBackgroundColor();
107+
COLORREF getSofterBackgroundColor();
108+
COLORREF getHotBackgroundColor();
109+
COLORREF getDarkerBackgroundColor();
110+
COLORREF getErrorBackgroundColor();
111+
112+
COLORREF getTextColor();
113+
COLORREF getDarkerTextColor();
114+
COLORREF getDisabledTextColor();
115+
COLORREF getLinkTextColor();
116+
117+
COLORREF getEdgeColor();
118+
COLORREF getHotEdgeColor();
119+
COLORREF getDisabledEdgeColor();
120+
121+
HBRUSH getBackgroundBrush();
122+
HBRUSH getDarkerBackgroundBrush();
123+
HBRUSH getSofterBackgroundBrush();
124+
HBRUSH getHotBackgroundBrush();
125+
HBRUSH getErrorBackgroundBrush();
126+
127+
HBRUSH getEdgeBrush();
128+
HBRUSH getHotEdgeBrush();
129+
HBRUSH getDisabledEdgeBrush();
130+
131+
HPEN getDarkerTextPen();
132+
HPEN getEdgePen();
133+
HPEN getHotEdgePen();
134+
HPEN getDisabledEdgePen();
135+
136+
COLORREF getIndividualTabColour(int colourIndex, bool themeDependant, bool saturated);
137+
138+
void setBackgroundColor(COLORREF c);
139+
void setSofterBackgroundColor(COLORREF c);
140+
void setHotBackgroundColor(COLORREF c);
141+
void setDarkerBackgroundColor(COLORREF c);
142+
void setErrorBackgroundColor(COLORREF c);
143+
void setTextColor(COLORREF c);
144+
void setDarkerTextColor(COLORREF c);
145+
void setDisabledTextColor(COLORREF c);
146+
void setLinkTextColor(COLORREF c);
147+
void setEdgeColor(COLORREF c);
148+
void setHotEdgeColor(COLORREF c);
149+
void setDisabledEdgeColor(COLORREF c);
150+
151+
Colors getDarkModeDefaultColors();
152+
void changeCustomTheme(const Colors& colors);
153+
154+
// handle events
155+
void handleSettingChange(HWND hwnd, LPARAM lParam);
156+
157+
// processes messages related to UAH / custom menubar drawing.
158+
// return true if handled, false to continue with normal processing in your wndproc
159+
bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr);
160+
void drawUAHMenuNCBottomLine(HWND hWnd);
161+
162+
// from DarkMode.h
163+
void initExperimentalDarkMode();
164+
void setDarkMode(bool useDark, bool fixDarkScrollbar);
165+
void allowDarkModeForApp(bool allow);
166+
bool allowDarkModeForWindow(HWND hWnd, bool allow);
167+
void setTitleBarThemeColor(HWND hWnd);
168+
169+
// enhancements to DarkMode.h
170+
void enableDarkScrollBarForWindowAndChildren(HWND hwnd);
171+
172+
inline void paintRoundFrameRect(HDC hdc, const RECT rect, const HPEN hpen, int width = 0, int height = 0);
173+
174+
void subclassButtonControl(HWND hwnd);
175+
void subclassGroupboxControl(HWND hwnd);
176+
void subclassTabControl(HWND hwnd);
177+
void subclassComboBoxControl(HWND hwnd);
178+
179+
void subclassAndThemeButton(HWND hwnd, NppDarkModeParams p);
180+
void subclassAndThemeComboBox(HWND hwnd, NppDarkModeParams p);
181+
void subclassAndThemeListBoxOrEditControl(HWND hwnd, NppDarkModeParams p, bool isListBox);
182+
void subclassAndThemeListView(HWND hwnd, NppDarkModeParams p);
183+
void themeTreeView(HWND hwnd, NppDarkModeParams p);
184+
void themeToolbar(HWND hwnd, NppDarkModeParams p);
185+
void themeRichEdit(HWND hwnd, NppDarkModeParams p);
186+
187+
void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass = true, bool theme = true);
188+
void autoThemeChildControls(HWND hwndParent);
189+
190+
LRESULT darkToolBarNotifyCustomDraw(LPARAM lParam);
191+
LRESULT darkListViewNotifyCustomDraw(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool isPlugin);
192+
LRESULT darkTreeViewNotifyCustomDraw(LPARAM lParam);
193+
194+
void autoSubclassAndThemePluginDockWindow(HWND hwnd);
195+
void autoSubclassAndThemeWindowNotify(HWND hwnd);
196+
197+
bool subclassTabUpDownControl(HWND hwnd);
198+
199+
void setDarkTitleBar(HWND hwnd);
200+
void setDarkExplorerTheme(HWND hwnd);
201+
void setDarkScrollBar(HWND hwnd);
202+
void setDarkTooltips(HWND hwnd, ToolTipsType type);
203+
void setDarkLineAbovePanelToolbar(HWND hwnd);
204+
void setDarkListView(HWND hwnd);
205+
206+
void disableVisualStyle(HWND hwnd, bool doDisable);
207+
void calculateTreeViewStyle();
208+
void setTreeViewStyle(HWND hwnd);
209+
void setBorder(HWND hwnd, bool border = true);
210+
211+
BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM lParam);
212+
void setDarkAutoCompletion();
213+
214+
LRESULT onCtlColor(HDC hdc);
215+
LRESULT onCtlColorSofter(HDC hdc);
216+
LRESULT onCtlColorDarker(HDC hdc);
217+
LRESULT onCtlColorError(HDC hdc);
218+
LRESULT onCtlColorDarkerBGStaticText(HDC hdc, bool isTextEnabled);
219+
INT_PTR onCtlColorListbox(WPARAM wParam, LPARAM lParam);
220+
}

include/TaskListDlg.h

+1-9
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,7 @@ public :
7474
return;
7575
//clear list LB_RESETCONTENT
7676
::SendMessage( _hList, LB_RESETCONTENT, NULL, NULL );
77-
if ( !todoItems.empty() )
78-
{
79-
// "if" branch replaces previous todoItems.clear(); to address the following issue:
80-
// https://community.notepad-plus-plus.org/topic/23236/npp-task-list-plugin-window-overwrites/5
81-
todoItems.clear();
82-
todoItemsFingerprint = "";
83-
findTasks();
84-
return;
85-
}
77+
todoItems.clear();
8678

8779

8880
//add list items LB_ADDSTRING

src/NppDarkModeDummy.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "NppDarkMode.h"
2+
#include "PluginInterface.h"
3+
4+
extern NppData nppData;
5+
6+
namespace NppDarkMode
7+
{
8+
bool isEnabled()
9+
{
10+
return ::SendMessage(nppData._nppHandle, NPPM_ISDARKMODEENABLED, 0, 0);
11+
}
12+
13+
HBRUSH getDarkerBackgroundBrush()
14+
{
15+
return ::CreateSolidBrush(HEXRGB(0x202020));
16+
}
17+
18+
COLORREF getDarkerTextColor()
19+
{
20+
return HEXRGB(0xC0C0C0);
21+
}
22+
23+
COLORREF getLinkTextColor()
24+
{
25+
return HEXRGB(0xFFFF00);
26+
}
27+
28+
void setDarkTitleBar(HWND /*hwnd*/)
29+
{
30+
}
31+
}

src/StaticDialog.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <windows.h>
1919
#include "StaticDialog.h"
2020
#include "Common.h"
21+
#include "NppDarkMode.h"
2122

2223
StaticDialog::~StaticDialog()
2324
{
@@ -227,6 +228,8 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
227228
return;
228229
}
229230

231+
NppDarkMode::setDarkTitleBar(_hSelf);
232+
230233
// if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent
231234
::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf));
232235
}
@@ -237,6 +240,8 @@ intptr_t CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam,
237240
{
238241
case WM_INITDIALOG:
239242
{
243+
NppDarkMode::setDarkTitleBar(hwnd);
244+
240245
StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(lParam);
241246
pStaticDlg->_hSelf = hwnd;
242247
::SetWindowLongPtr(hwnd, GWLP_USERDATA, static_cast<LONG_PTR>(lParam));

0 commit comments

Comments
 (0)