// This file is part of Notepad++ project // Copyright (c) 2021 adzm / Adam D. Walling // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // at your option any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . #pragma once #include #include "Common.h" // for generic_string //这段代码定义了一个名为NppDarkMode的命名空间,其中包含了一些结构体和函数。 namespace NppDarkMode { struct Colors { // 定义颜色结构体Colors,包括背景颜色、柔和背景颜色、热点背景颜色、纯背景颜色、错误背景颜色、文本颜色、深色文本颜色、禁用文本颜色、链接文本颜色、边缘颜色、热点边缘颜色、禁用边缘颜色 COLORREF background = 0; COLORREF softerBackground = 0; COLORREF hotBackground = 0; COLORREF pureBackground = 0; COLORREF errorBackground = 0; COLORREF text = 0; COLORREF darkerText = 0; COLORREF disabledText = 0; COLORREF linkText = 0; COLORREF edge = 0; COLORREF hotEdge = 0; COLORREF disabledEdge = 0; }; struct Options { // 定义Options结构体,用于存储暗黑模式的选项 bool enable = false; bool enableMenubar = false; bool enablePlugin = false; }; struct NppDarkModeParams { // 定义NppDarkModeParams结构体,用于存储暗黑模式的参数 const wchar_t* _themeClassName = nullptr; bool _subclass = false; bool _theme = false; }; enum class ToolTipsType { // 定义ToolTipsType枚举,用于标识不同类型的工具提示 tooltip, toolbar, listview, treeview, tabbar }; enum ColorTone { // 定义ColorTone枚举,用于标识不同的颜色调 blackTone = 0, redTone = 1, greenTone = 2, blueTone = 3, purpleTone = 4, cyanTone = 5, oliveTone = 6, customizedTone = 32 }; enum class TreeViewStyle { // 定义TreeViewStyle枚举,用于标识不同的树形视图样式 classic = 0, light = 1, dark = 2 }; struct AdvOptDefaults { // 定义AdvOptDefaults结构体,用于存储高级选项的默认值 generic_string _xmlFileName; int _toolBarIconSet = -1; int _tabIconSet = -1; bool _tabUseTheme = false; }; struct AdvancedOptions { // 定义AdvancedOptions结构体,用于存储高级选项 bool _enableWindowsMode = false; NppDarkMode::AdvOptDefaults _darkDefaults{ L"DarkModeDefault.xml", 0, 2, false }; NppDarkMode::AdvOptDefaults _lightDefaults{ L"", 4, 0, true }; }; void initDarkMode(); // 初始化暗黑模式,从NppParameters中获取选项 void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // 尝试应用新的选项,发送NPPM_INTERNAL_REFRESHDARKMODE消息到hwnd的顶级父窗口 void initAdvancedOptions(); // 初始化高级选项 bool isEnabled(); // 获取暗黑模式是否启用的状态 bool isDarkMenuEnabled(); // 获取菜单栏是否使用暗黑模式的状态 bool isEnabledForPlugins(); // 获取插件是否使用暗黑模式的状态 bool isExperimentalActive(); // 获取实验性暗黑模式是否启用的状态 bool isExperimentalSupported(); // 获取实验性暗黑模式是否受支持的状态 bool isWindowsModeEnabled(); // 获取Windows模式是否启用的状态 void setWindowsMode(bool enable); // 设置Windows模式是否启用 generic_string getThemeName(); // 获取主题名称 void setThemeName(const generic_string& newThemeName); // 设置主题名称 int getToolBarIconSet(bool useDark); // 获取工具栏图标集 void setToolBarIconSet(int state2Set, bool useDark); // 设置工具栏图标集 int getTabIconSet(bool useDark); // 获取选项卡图标集 void setTabIconSet(bool useAltIcons, bool useDark); // 设置选项卡图标集 bool useTabTheme(); // 获取选项卡主题是否启用 void setAdvancedOptions(); // 设置高级选项 bool isWindows10(); // 获取Windows是否为10版本 bool isWindows11(); // 获取Windows是否为11版本 DWORD getWindowsBuildNumber(); // 获取Windows的构建版本号 COLORREF invertLightness(COLORREF c); // 反转颜色的亮度 COLORREF invertLightnessSofter(COLORREF c); // 反转柔和颜色的亮度 double calculatePerceivedLighness(COLORREF c); // 计算颜色的亮度 void setDarkTone(ColorTone colorToneChoice); // 设置暗黑模式的颜色调 COLORREF getBackgroundColor(); // 获取背景颜色 COLORREF getSofterBackgroundColor(); // 获取柔和背景颜色 COLORREF getHotBackgroundColor(); // 获取热点背景颜色 COLORREF getDarkerBackgroundColor(); // 获取深色背景颜色 COLORREF getErrorBackgroundColor(); // 获取错误背景颜色 COLORREF getTextColor(); // 获取文本颜色 COLORREF getDarkerTextColor(); // 获取深色文本颜色 COLORREF getDisabledTextColor(); // 获取禁用文本颜色 COLORREF getLinkTextColor(); // 获取链接文本颜色 COLORREF getEdgeColor(); // 获取边缘颜色 COLORREF getHotEdgeColor(); // 获取热点边缘颜色 COLORREF getDisabledEdgeColor(); // 获取禁用边缘颜色 HBRUSH getBackgroundBrush(); // 获取背景画刷 HBRUSH getDarkerBackgroundBrush(); // 获取深色背景画刷 HBRUSH getSofterBackgroundBrush(); // 获取柔和背景画刷 HBRUSH getHotBackgroundBrush(); // 获取热点背景画刷 HBRUSH getErrorBackgroundBrush(); // 获取错误背景画刷 HBRUSH getEdgeBrush(); // 获取边缘画刷 HBRUSH getHotEdgeBrush(); // 获取热点边缘画刷 HBRUSH getDisabledEdgeBrush(); // 获取禁用边缘画刷 COLORREF getIndividualTabColour(int colourIndex, bool themeDependant, bool saturated); void setBackgroundColor(COLORREF c); void setSofterBackgroundColor(COLORREF c); void setHotBackgroundColor(COLORREF c); void setDarkerBackgroundColor(COLORREF c); void setErrorBackgroundColor(COLORREF c); void setTextColor(COLORREF c); void setDarkerTextColor(COLORREF c); void setDisabledTextColor(COLORREF c); void setLinkTextColor(COLORREF c); void setEdgeColor(COLORREF c); void setHotEdgeColor(COLORREF c); void setDisabledEdgeColor(COLORREF c); Colors getDarkModeDefaultColors(); void changeCustomTheme(const Colors& colors); // handle events void handleSettingChange(HWND hwnd, LPARAM lParam, bool isFromBtn = false); bool isDarkModeReg(); // processes messages related to UAH / custom menubar drawing. // return true if handled, false to continue with normal processing in your wndproc bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr); void drawUAHMenuNCBottomLine(HWND hWnd); // from DarkMode.h void initExperimentalDarkMode(); void setDarkMode(bool useDark, bool fixDarkScrollbar); void allowDarkModeForApp(bool allow); bool allowDarkModeForWindow(HWND hWnd, bool allow); void setTitleBarThemeColor(HWND hWnd); // enhancements to DarkMode.h void enableDarkScrollBarForWindowAndChildren(HWND hwnd); inline void paintRoundFrameRect(HDC hdc, const RECT rect, const HPEN hpen, int width = 0, int height = 0); void subclassButtonControl(HWND hwnd); void subclassGroupboxControl(HWND hwnd); void subclassTabControl(HWND hwnd); void subclassComboBoxControl(HWND hwnd); bool subclassTabUpDownControl(HWND hwnd); void subclassAndThemeButton(HWND hwnd, NppDarkModeParams p); void subclassAndThemeComboBox(HWND hwnd, NppDarkModeParams p); void subclassAndThemeListBoxOrEditControl(HWND hwnd, NppDarkModeParams p, bool isListBox); void subclassAndThemeListView(HWND hwnd, NppDarkModeParams p); void themeTreeView(HWND hwnd, NppDarkModeParams p); void themeToolbar(HWND hwnd, NppDarkModeParams p); void themeRichEdit(HWND hwnd, NppDarkModeParams p); 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); void autoSubclassAndThemePluginDockWindow(HWND hwnd); ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags); void autoSubclassAndThemeWindowNotify(HWND hwnd); void setDarkTitleBar(HWND hwnd); void setDarkExplorerTheme(HWND hwnd); void setDarkScrollBar(HWND hwnd); void setDarkTooltips(HWND hwnd, ToolTipsType type); void setDarkLineAbovePanelToolbar(HWND hwnd); void setDarkListView(HWND hwnd); void disableVisualStyle(HWND hwnd, bool doDisable); void calculateTreeViewStyle(); void setTreeViewStyle(HWND hwnd); bool isThemeDark(); void setBorder(HWND hwnd, bool border = true); BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM lParam); void setDarkAutoCompletion(); LRESULT onCtlColor(HDC hdc); LRESULT onCtlColorSofter(HDC hdc); LRESULT onCtlColorDarker(HDC hdc); LRESULT onCtlColorError(HDC hdc); LRESULT onCtlColorDarkerBGStaticText(HDC hdc, bool isTextEnabled); INT_PTR onCtlColorListbox(WPARAM wParam, LPARAM lParam); } //这些函数主要用于初始化和管理Notepad++的暗黑模式,包括颜色设置、主题样式、窗口控件的主题化等功能。