Add DarkMode usage detection support for plugins
Add APIs: 2 new messages NPPM_ISDARKMODEENABLED & NPPM_GETDARKMODECOLORS, and 1 new notification NPPN_DARKMODECHANGED. Fixed also a bug in dark mode for PushLike CheckBoxes. Fix #11546, close #11547pull/11591/head
parent
1dffb05e0a
commit
1eb5b10e41
|
@ -480,6 +480,36 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
|
|||
// MacroStatus NPPM_GETCURRENTMACROSTATUS(0, 0)
|
||||
// Gets current enum class MacroStatus { Idle - means macro is not in use and it's empty, RecordInProgress, RecordingStopped, PlayingBack }
|
||||
|
||||
#define NPPM_ISDARKMODEENABLED (NPPMSG + 107)
|
||||
// bool NPPM_ISDARKMODEENABLED(0, 0)
|
||||
// Returns true when Notepad++ Dark Mode is enable, false when it is not.
|
||||
|
||||
#define NPPM_GETDARKMODECOLORS (NPPMSG + 108)
|
||||
// bool NPPM_GETDARKMODECOLORS (size_t cbSize, NppDarkMode::Colors* returnColors)
|
||||
// - cbSize must be filled with sizeof(NppDarkMode::Colors).
|
||||
// - returnColors must be a pre-allocated NppDarkMode::Colors struct.
|
||||
// Returns true when successful, false otherwise.
|
||||
// You need to uncomment the following code to use NppDarkMode::Colors structure:
|
||||
//
|
||||
// namespace NppDarkMode
|
||||
// {
|
||||
// struct 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;
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// Note: in the case of calling failure ("false" is returned), you may need to change NppDarkMode::Colors structure to:
|
||||
// https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/PowerEditor/src/NppDarkMode.h#L32
|
||||
|
||||
|
||||
#define VAR_NOT_RECOGNIZED 0
|
||||
|
@ -666,3 +696,9 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
|
|||
//scnNotification->nmhdr.code = NPPN_FILEDELETED;
|
||||
//scnNotification->nmhdr.hwndFrom = hwndNpp;
|
||||
//scnNotification->nmhdr.idFrom = BufferID;
|
||||
|
||||
#define NPPN_DARKMODECHANGED (NPPN_FIRST + 27) // To notify plugins that Dark Mode was enabled/disabled
|
||||
//scnNotification->nmhdr.code = NPPN_DARKMODECHANGED;
|
||||
//scnNotification->nmhdr.hwndFrom = hwndNpp;
|
||||
//scnNotification->nmhdr.idFrom = 0;
|
||||
|
||||
|
|
|
@ -202,6 +202,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
case NPPM_INTERNAL_REFRESHDARKMODE:
|
||||
{
|
||||
refreshDarkMode(static_cast<bool>(wParam));
|
||||
// Notify plugins that Dark Mode changed
|
||||
SCNotification scnN;
|
||||
scnN.nmhdr.code = NPPN_DARKMODECHANGED;
|
||||
scnN.nmhdr.hwndFrom = reinterpret_cast<void*>(lParam);
|
||||
scnN.nmhdr.idFrom = 0;
|
||||
_pluginsManager.notify(&scnN);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -2605,6 +2611,37 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
|
|||
return nppParam.getNppGUI()._maitainIndent;
|
||||
}
|
||||
|
||||
case NPPM_ISDARKMODEENABLED:
|
||||
{
|
||||
return NppDarkMode::isEnabled();
|
||||
}
|
||||
|
||||
case NPPM_GETDARKMODECOLORS:
|
||||
{
|
||||
if (static_cast<size_t>(wParam) != sizeof(NppDarkMode::Colors))
|
||||
return static_cast<LRESULT>(false);
|
||||
|
||||
NppDarkMode::Colors* currentColors = reinterpret_cast<NppDarkMode::Colors*>(lParam);
|
||||
|
||||
if (currentColors != NULL)
|
||||
{
|
||||
currentColors->background = NppDarkMode::getBackgroundColor();
|
||||
currentColors->softerBackground = NppDarkMode::getSofterBackgroundColor();
|
||||
currentColors->hotBackground = NppDarkMode::getHotBackgroundColor();
|
||||
currentColors->pureBackground = NppDarkMode::getDarkerBackgroundColor();
|
||||
currentColors->errorBackground = NppDarkMode::getErrorBackgroundColor();
|
||||
currentColors->text = NppDarkMode::getTextColor();
|
||||
currentColors->darkerText = NppDarkMode::getDarkerTextColor();
|
||||
currentColors->disabledText = NppDarkMode::getDisabledTextColor();
|
||||
currentColors->linkText = NppDarkMode::getLinkTextColor();
|
||||
currentColors->edge = NppDarkMode::getEdgeColor();
|
||||
|
||||
return static_cast<LRESULT>(true);
|
||||
}
|
||||
|
||||
return static_cast<LRESULT>(false);
|
||||
}
|
||||
|
||||
case NPPM_DOCLISTDISABLEPATHCOLUMN:
|
||||
case NPPM_DOCLISTDISABLEEXTCOLUMN:
|
||||
{
|
||||
|
|
|
@ -1175,7 +1175,7 @@ namespace NppDarkMode
|
|||
}
|
||||
|
||||
LONG_PTR dwStyle = GetWindowLongPtr(hWnd, GWL_STYLE);
|
||||
if ((dwStyle & TCS_BOTTOM) || (dwStyle & TCS_BUTTONS) || (dwStyle & TCS_VERTICAL))
|
||||
if ((dwStyle & TCS_BUTTONS) || (dwStyle & TCS_VERTICAL))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1477,24 +1477,39 @@ namespace NppDarkMode
|
|||
case BS_AUTOCHECKBOX:
|
||||
case BS_RADIOBUTTON:
|
||||
case BS_AUTORADIOBUTTON:
|
||||
{
|
||||
auto nButtonAllStyles = ::GetWindowLongPtr(hwnd, GWL_STYLE);
|
||||
if (nButtonAllStyles & BS_PUSHLIKE)
|
||||
{
|
||||
if (p.theme)
|
||||
{
|
||||
SetWindowTheme(hwnd, p.themeClassName, nullptr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (p.subclass)
|
||||
{
|
||||
NppDarkMode::subclassButtonControl(hwnd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BS_GROUPBOX:
|
||||
{
|
||||
if (p.subclass)
|
||||
{
|
||||
NppDarkMode::subclassGroupboxControl(hwnd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BS_DEFPUSHBUTTON:
|
||||
case BS_PUSHBUTTON:
|
||||
{
|
||||
if (p.theme)
|
||||
{
|
||||
SetWindowTheme(hwnd, p.themeClassName, nullptr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue