|
| 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 | +} |
0 commit comments