OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
NppDarkMode Namespace Reference

Classes

struct  ButtonData

Functions

bool IsEnabled ()
bool IsSupported ()
bool IsSystemMenuEnabled ()
COLORREF InvertLightness (COLORREF c)
COLORREF InvertLightnessSofter (COLORREF c)
COLORREF GetBackgroundColor ()
COLORREF GetSofterBackgroundColor ()
COLORREF GetTextColor ()
COLORREF GetHotTextColor ()
COLORREF GetSofterTextColor ()
COLORREF GetDarkerTextColor ()
COLORREF GetEdgeColor ()
HBRUSH GetBackgroundBrush ()
HPEN GetDarkerTextPen ()
HPEN GetEdgePen ()
HBRUSH GetSofterBackgroundBrush ()
bool OnSettingChange (HWND hwnd, LPARAM lParam)
bool UAHWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *lr)
void DrawUAHMenuNCBottomLine (HWND hWnd)
void InitDarkMode (bool set_dark_mode, bool set_sys_menu)
void SetDarkMode (bool dark_mode)
void SetSystemMenuForApp (bool set_sys_menu)
void AllowDarkModeForApp (bool allow)
bool AllowDarkModeForWindow (HWND hWnd, bool allow)
void RefreshTitleBarThemeColor (HWND hWnd)
void EnableDarkScrollBarForWindowAndChildren (HWND hwnd)
void SetDarkTitleBar (HWND hwnd)
void SetDarkExplorerTheme (HWND hwnd)
void SetDarkListView (HWND hwnd)
void SetDarkListViewHeader (HWND hHeader)
int scaled (HWND hwnd, int val)
void renderButton (HWND hwnd, HDC hdc, HTHEME hTheme, int iPartID, int iStateID)
void paintButton (HWND hwnd, HDC hdc, ButtonData &buttonData)
LRESULT CALLBACK ButtonSubclass (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
void subclassButtonControl (HWND hwnd)
void AutoSubclassAndThemeChildControls (HWND hwndParent, bool subclass, bool theme)

Variables

constexpr UINT_PTR g_buttonSubclassID = 42

Function Documentation

◆ AllowDarkModeForApp()

void NppDarkMode::AllowDarkModeForApp ( bool allow)
333 {
334 if (IsSupported())
336 }
bool IsSupported()
Definition dark_mode.cpp:37
void AllowDarkModeForApp(bool allow)
Definition dark_mode.cpp:332

References AllowDarkModeForApp(), and IsSupported().

Referenced by AllowDarkModeForApp(), and SetDarkMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllowDarkModeForWindow()

bool NppDarkMode::AllowDarkModeForWindow ( HWND hWnd,
bool allow )
339 {
340 if (IsSupported())
341 return ::AllowDarkModeForWindow(hWnd, allow);
342 return false;
343 }

References IsSupported().

Referenced by SetDarkTitleBar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ AutoSubclassAndThemeChildControls()

void NppDarkMode::AutoSubclassAndThemeChildControls ( HWND hwndParent,
bool subclass,
bool theme )
786 {
787 if (!IsSupported())
788 return;
789
790 struct Params
791 {
792 const wchar_t* themeClassName = nullptr;
793 bool subclass = false;
794 bool theme = false;
795 };
796
797 Params p{
798 IsEnabled() ? L"DarkMode_Explorer" : nullptr
799 , subclass
800 , theme
801 };
802
803 EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) WINAPI_LAMBDA{
804 auto & p = *reinterpret_cast<Params*>(lParam);
805 const size_t classNameLen = 16;
806 TCHAR className[classNameLen] = { 0 };
807 GetClassName(hwnd, className, classNameLen);
808
809 if (wcscmp(className, UPDOWN_CLASS) == 0)
810 {
811 auto nButtonStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE) & 0xF;
812 if (nButtonStyle == BS_AUTO3STATE && p.subclass)
813 {
815 }
816
817 return TRUE;
818 }
819 return TRUE;
820 }, reinterpret_cast<LPARAM>(&p));
821 }
#define L(s)
Definition ExtrusionEntity.cpp:25
#define WINAPI_LAMBDA
Definition dark_mode.cpp:23
bool IsEnabled()
Definition dark_mode.cpp:32
void subclassButtonControl(HWND hwnd)
Definition dark_mode.cpp:779

References IsEnabled(), IsSupported(), L, subclassButtonControl(), and WINAPI_LAMBDA.

Here is the call graph for this function:

◆ ButtonSubclass()

LRESULT CALLBACK NppDarkMode::ButtonSubclass ( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam,
UINT_PTR uIdSubclass,
DWORD_PTR dwRefData )
662 {
663 UNREFERENCED_PARAMETER(uIdSubclass);
664
665 auto pButtonData = reinterpret_cast<ButtonData*>(dwRefData);
666
667 auto paint = [pButtonData](HWND hWnd, WPARAM wParam)
668 {
669 PAINTSTRUCT ps = { 0 };
670 HDC hdc = reinterpret_cast<HDC>(wParam);
671 if (!hdc)
672 {
673 hdc = BeginPaint(hWnd, &ps);
674 }
675
676 paintButton(hWnd, hdc, *pButtonData);
677
678 if (ps.hdc)
679 {
680 EndPaint(hWnd, &ps);
681 }
682 };
683
684 switch (uMsg)
685 {
686 case WM_UPDATEUISTATE:
687 if (HIWORD(wParam) & (UISF_HIDEACCEL | UISF_HIDEFOCUS))
688 {
689 InvalidateRect(hWnd, nullptr, FALSE);
690 }
691 break;
692 case WM_NCDESTROY:
693 RemoveWindowSubclass(hWnd, ButtonSubclass, g_buttonSubclassID);
694 delete pButtonData;
695 break;
696 case WM_ERASEBKGND:
697 if (IsEnabled() && pButtonData->ensureTheme(hWnd))
698 {
699 return TRUE;
700 }
701 else
702 {
703 break;
704 }
705 case WM_THEMECHANGED:
706 pButtonData->closeTheme();
707 break;
708 case WM_PRINTCLIENT:
709 case WM_PAINT:
710 if (pButtonData->ensureTheme(hWnd))
711 {
712 paint(hWnd, wParam);
713 return 0;
714 }
715 break;
716 case WM_MOUSEMOVE:
717 {
718 DWORD nStyle = GetWindowLong(hWnd, GWL_STYLE);
719 DWORD nButtonStyle = nStyle & 0xF;
720 if (nButtonStyle == BS_AUTO3STATE)
721 {
722 int xPos = GET_X_LPARAM(lParam);
723 int yPos = GET_Y_LPARAM(lParam);
724
725 RECT rcClient = { 0 };
726 GetClientRect(hWnd, &rcClient);
727
728 int iStateID = 0;
729 if (xPos <= rcClient.top || xPos >= rcClient.bottom ||
730 yPos <= rcClient.left || yPos >= rcClient.right)
731 iStateID = ARROWBTNSTATES::ABS_UPNORMAL;
732 else
733 iStateID = yPos > 0.5 * rcClient.bottom ? ARROWBTNSTATES::ABS_DOWNHOT : ARROWBTNSTATES::ABS_UPHOT;
734
735 if (pButtonData->iStateID != iStateID)
736 {
737 pButtonData->iStateID = iStateID;
738 paint(hWnd, wParam);
739 }
740
741 return 0;
742 }
743 break;
744 }
745 case WM_KEYUP:
746 case WM_CHAR:
747 case WM_KEYDOWN:
748 case WM_VSCROLL:
749 {
750 DWORD nState = GET_KEYSTATE_WPARAM(wParam);
751 if (nState == VK_UP || nState == VK_DOWN) {
752 int iStateID = nState == VK_DOWN ? ARROWBTNSTATES::ABS_DOWNHOT : ARROWBTNSTATES::ABS_UPHOT;
753 if (pButtonData->iStateID != iStateID)
754 {
755 pButtonData->iStateID = iStateID;
756 paint(hWnd, wParam);
757 }
758 return 0;
759 }
760 break;
761 }
762 case WM_SIZE:
763 case WM_DESTROY:
764 BufferedPaintStopAllAnimations(hWnd);
765 break;
766 case WM_ENABLE:
767 if (IsEnabled())
768 {
769 // skip the button's normal wndproc so it won't redraw out of wm_paint
770 LRESULT lr = DefWindowProc(hWnd, uMsg, wParam, lParam);
771 InvalidateRect(hWnd, nullptr, FALSE);
772 return lr;
773 }
774 break;
775 }
776 return DefSubclassProc(hWnd, uMsg, wParam, lParam);
777 }
constexpr UINT_PTR g_buttonSubclassID
Definition dark_mode.cpp:652
void paintButton(HWND hwnd, HDC hdc, ButtonData &buttonData)
Definition dark_mode.cpp:576
LRESULT CALLBACK ButtonSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
Definition dark_mode.cpp:654
Definition dark_mode.cpp:408

References ButtonSubclass(), g_buttonSubclassID, IsEnabled(), and paintButton().

Referenced by ButtonSubclass(), and subclassButtonControl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DrawUAHMenuNCBottomLine()

void NppDarkMode::DrawUAHMenuNCBottomLine ( HWND hWnd)
278 {
279 MENUBARINFO mbi = { sizeof(mbi) };
280 if (!GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi))
281 {
282 return;
283 }
284
285 RECT rcClient = { 0 };
286 GetClientRect(hWnd, &rcClient);
287 MapWindowPoints(hWnd, nullptr, (POINT*)&rcClient, 2);
288
289 RECT rcWindow = { 0 };
290 GetWindowRect(hWnd, &rcWindow);
291
292 OffsetRect(&rcClient, -rcWindow.left, -rcWindow.top);
293
294 // the rcBar is offset by the window rect
295 RECT rcAnnoyingLine = rcClient;
296 rcAnnoyingLine.bottom = rcAnnoyingLine.top;
297 rcAnnoyingLine.top--;
298
299 HDC hdc = GetWindowDC(hWnd);
300 FillRect(hdc, &rcAnnoyingLine, GetBackgroundBrush());
301 ReleaseDC(hWnd, hdc);
302 }
HBRUSH GetBackgroundBrush()
Definition dark_mode.cpp:110

References GetBackgroundBrush().

Here is the call graph for this function:

◆ EnableDarkScrollBarForWindowAndChildren()

void NppDarkMode::EnableDarkScrollBarForWindowAndChildren ( HWND hwnd)
352 {
353 if (IsSupported())
355 }
void EnableDarkScrollBarForWindowAndChildren(HWND hwnd)
Definition dark_mode.cpp:351

References EnableDarkScrollBarForWindowAndChildren(), and IsSupported().

Referenced by EnableDarkScrollBarForWindowAndChildren().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBackgroundBrush()

HBRUSH NppDarkMode::GetBackgroundBrush ( )
111 {
112 static HBRUSH g_hbrBackground = ::CreateSolidBrush(GetBackgroundColor());
113 return g_hbrBackground;
114 }
COLORREF GetBackgroundColor()
Definition dark_mode.cpp:75

References GetBackgroundColor().

Referenced by DrawUAHMenuNCBottomLine(), and UAHWndProc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBackgroundColor()

COLORREF NppDarkMode::GetBackgroundColor ( )
76 {
77 return IsEnabled() ? RGB(0x2B, 0x2B, 0x2B) : wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR).GetRGB();
78 }

References IsEnabled().

Referenced by GetBackgroundBrush().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDarkerTextColor()

COLORREF NppDarkMode::GetDarkerTextColor ( )
101 {
102 return RGB(0xC0, 0xC0, 0xC0);
103 }

Referenced by GetDarkerTextPen().

Here is the caller graph for this function:

◆ GetDarkerTextPen()

HPEN NppDarkMode::GetDarkerTextPen ( )
117 {
118 static HPEN g_hpDarkerText = ::CreatePen(PS_SOLID, 1, GetDarkerTextColor());
119 return g_hpDarkerText;
120 }
COLORREF GetDarkerTextColor()
Definition dark_mode.cpp:100

References GetDarkerTextColor().

Here is the call graph for this function:

◆ GetEdgeColor()

COLORREF NppDarkMode::GetEdgeColor ( )
106 {
107 return RGB(0x80, 0x80, 0x80);
108 }

Referenced by GetEdgePen().

Here is the caller graph for this function:

◆ GetEdgePen()

HPEN NppDarkMode::GetEdgePen ( )
123 {
124 static HPEN g_hpEdgePen = ::CreatePen(PS_SOLID, 1, GetEdgeColor());
125 return g_hpEdgePen;
126 }
COLORREF GetEdgeColor()
Definition dark_mode.cpp:105

References GetEdgeColor().

Here is the call graph for this function:

◆ GetHotTextColor()

COLORREF NppDarkMode::GetHotTextColor ( )
91 {
92 return IsEnabled() ? RGB(0xFF, 0xFF, 0xFF) : wxSystemSettings::GetColour(wxSYS_COLOUR_ACTIVEBORDER).GetRGB();
93 }

References IsEnabled().

Here is the call graph for this function:

◆ GetSofterBackgroundBrush()

HBRUSH NppDarkMode::GetSofterBackgroundBrush ( )
129 {
130 static HBRUSH g_hbrSofterBackground = ::CreateSolidBrush(GetSofterBackgroundColor());
131 return g_hbrSofterBackground;
132 }
COLORREF GetSofterBackgroundColor()
Definition dark_mode.cpp:80

References GetSofterBackgroundColor().

Referenced by UAHWndProc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSofterBackgroundColor()

COLORREF NppDarkMode::GetSofterBackgroundColor ( )
81 {
82 return IsEnabled() ? RGB(0x40, 0x40, 0x40) : RGB(0xD9, 0xD9, 0xD9); //RGB(0x78, 0x78, 0x78);
83 }

References IsEnabled().

Referenced by GetSofterBackgroundBrush(), and renderButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSofterTextColor()

COLORREF NppDarkMode::GetSofterTextColor ( )
96 {
97 return IsEnabled() ? RGB(0xF0, 0xF0, 0xF0) : RGB(0x64, 0x64, 0x64);
98 }

References IsEnabled().

Referenced by renderButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTextColor()

COLORREF NppDarkMode::GetTextColor ( )
86 {
87 return IsEnabled() ? RGB(0xF0, 0xF0, 0xF0) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT).GetRGB();
88 }

References IsEnabled().

Referenced by UAHWndProc(), and Slic3r::GUI::GUI_App::UpdateDVCDarkUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitDarkMode()

void NppDarkMode::InitDarkMode ( bool set_dark_mode,
bool set_sys_menu )
307 {
309 g_SystemMenuEnabled = set_sys_menu;
310 SetDarkMode(set_dark_mode);
311 }
bool g_SystemMenuEnabled
Definition dark_mode.hpp:103
void InitDarkMode()
Definition dark_mode.hpp:230
void SetDarkMode(bool dark_mode)
Definition dark_mode.cpp:313

References g_SystemMenuEnabled, InitDarkMode(), and SetDarkMode().

Referenced by Slic3r::GUI::GUI_App::on_init_inner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InvertLightness()

COLORREF NppDarkMode::InvertLightness ( COLORREF c)
48 {
49 WORD h = 0;
50 WORD s = 0;
51 WORD l = 0;
52 ColorRGBToHLS(c, &h, &l, &s);
53
54 l = 240 - l;
55
56 COLORREF invert_c = ColorHLSToRGB(h, l, s);
57
58 return invert_c;
59 }

◆ InvertLightnessSofter()

COLORREF NppDarkMode::InvertLightnessSofter ( COLORREF c)
62 {
63 WORD h = 0;
64 WORD s = 0;
65 WORD l = 0;
66 ColorRGBToHLS(c, &h, &l, &s);
67
68 l = std::min(240 - l, 211);
69
70 COLORREF invert_c = ColorHLSToRGB(h, l, s);
71
72 return invert_c;
73 }

◆ IsEnabled()

bool NppDarkMode::IsEnabled ( )
33 {
34 return g_darkModeEnabled;
35 }
bool g_darkModeEnabled
Definition dark_mode.hpp:102

References g_darkModeEnabled.

Referenced by AutoSubclassAndThemeChildControls(), ButtonSubclass(), GetBackgroundColor(), GetHotTextColor(), GetSofterBackgroundColor(), GetSofterTextColor(), GetTextColor(), SetDarkExplorerTheme(), SetDarkListView(), SetDarkListViewHeader(), SetDarkTitleBar(), and UAHWndProc().

Here is the caller graph for this function:

◆ IsSupported()

bool NppDarkMode::IsSupported ( )
38 {
40 }
bool g_darkModeSupported
Definition dark_mode.hpp:101

References g_darkModeSupported.

Referenced by AllowDarkModeForApp(), AllowDarkModeForWindow(), AutoSubclassAndThemeChildControls(), EnableDarkScrollBarForWindowAndChildren(), RefreshTitleBarThemeColor(), SetDarkExplorerTheme(), SetDarkListView(), SetDarkListViewHeader(), SetDarkMode(), SetDarkTitleBar(), and SetSystemMenuForApp().

Here is the caller graph for this function:

◆ IsSystemMenuEnabled()

bool NppDarkMode::IsSystemMenuEnabled ( )
43 {
45 }

References g_SystemMenuEnabled.

◆ OnSettingChange()

bool NppDarkMode::OnSettingChange ( HWND hwnd,
LPARAM lParam )
137 {
138 bool toggled = false;
139 if (IsColorSchemeChangeMessage(lParam))
140 {
141 bool darkModeWasEnabled = g_darkModeEnabled;
143
145
146 if (!!darkModeWasEnabled != !!g_darkModeEnabled) {
147 toggled = true;
148 RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN);
149 }
150 }
151
152 return toggled;
153 }
bool IsColorSchemeChangeMessage(LPARAM lParam)
Definition dark_mode.hpp:139
bool IsHighContrast()
Definition dark_mode.hpp:113
fnShouldAppsUseDarkMode _ShouldAppsUseDarkMode
Definition dark_mode.hpp:89
void RefreshTitleBarThemeColor(HWND hWnd)
Definition dark_mode.cpp:345

References _ShouldAppsUseDarkMode, g_darkModeEnabled, IsColorSchemeChangeMessage(), IsHighContrast(), and RefreshTitleBarThemeColor().

Here is the call graph for this function:

◆ paintButton()

void NppDarkMode::paintButton ( HWND hwnd,
HDC hdc,
ButtonData & buttonData )
577 {
578 DWORD nState = static_cast<DWORD>(SendMessage(hwnd, BM_GETSTATE, 0, 0));
579 DWORD nStyle = GetWindowLong(hwnd, GWL_STYLE);
580 DWORD nButtonStyle = nStyle & 0xF;
581
582 int iPartID = BP_CHECKBOX;
583 if (nButtonStyle == BS_CHECKBOX || nButtonStyle == BS_AUTOCHECKBOX)
584 {
585 iPartID = BP_CHECKBOX;
586 }
587 else if (nButtonStyle == BS_RADIOBUTTON || nButtonStyle == BS_AUTORADIOBUTTON)
588 {
589 iPartID = BP_RADIOBUTTON;
590 }
591 else if (nButtonStyle == BS_AUTO3STATE)
592 {
593 iPartID = SBP_ARROWBTN;
594 }
595 else
596 {
597 assert(false);
598 }
599
600 // states of BP_CHECKBOX and BP_RADIOBUTTON are the same
601 int iStateID = RBS_UNCHECKEDNORMAL;
602
603 if (nStyle & WS_DISABLED) iStateID = RBS_UNCHECKEDDISABLED;
604 else if (nState & BST_PUSHED) iStateID = RBS_UNCHECKEDPRESSED;
605 else if (nState & BST_HOT) iStateID = RBS_UNCHECKEDHOT;
606
607 if (nState & BST_CHECKED) iStateID += 4;
608
609 if (BufferedPaintRenderAnimation(hwnd, hdc))
610 {
611 return;
612 }
613
614 BP_ANIMATIONPARAMS animParams = { sizeof(animParams) };
615 animParams.style = BPAS_LINEAR;
616 if (iStateID != buttonData.iStateID)
617 {
618 GetThemeTransitionDuration(buttonData.hTheme, iPartID, buttonData.iStateID, iStateID, TMT_TRANSITIONDURATIONS, &animParams.dwDuration);
619 }
620
621 RECT rcClient = { 0 };
622 GetClientRect(hwnd, &rcClient);
623
624 HDC hdcFrom = nullptr;
625 HDC hdcTo = nullptr;
626 HANIMATIONBUFFER hbpAnimation = BeginBufferedAnimation(hwnd, hdc, &rcClient, BPBF_COMPATIBLEBITMAP, nullptr, &animParams, &hdcFrom, &hdcTo);
627 if (hbpAnimation)
628 {
629 if (hdcFrom)
630 {
631 renderButton(hwnd, hdcFrom, buttonData.hTheme, iPartID, buttonData.iStateID);
632 }
633 if (hdcTo)
634 {
635 if (iPartID == SBP_ARROWBTN && (buttonData.iStateID == ARROWBTNSTATES::ABS_DOWNHOT || buttonData.iStateID == ARROWBTNSTATES::ABS_UPHOT) )
636 iStateID = buttonData.iStateID;
637 renderButton(hwnd, hdcTo, buttonData.hTheme, iPartID, iStateID);
638 }
639
640 buttonData.iStateID = iStateID;
641
642 EndBufferedAnimation(hbpAnimation, TRUE);
643 }
644 else
645 {
646 renderButton(hwnd, hdc, buttonData.hTheme, iPartID, iStateID);
647
648 buttonData.iStateID = iStateID;
649 }
650 }
void renderButton(HWND hwnd, HDC hdc, HTHEME hTheme, int iPartID, int iStateID)
Definition dark_mode.cpp:437
HTHEME hTheme
Definition dark_mode.cpp:409
int iStateID
Definition dark_mode.cpp:410

References NppDarkMode::ButtonData::hTheme, NppDarkMode::ButtonData::iStateID, and renderButton().

Referenced by ButtonSubclass().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RefreshTitleBarThemeColor()

void NppDarkMode::RefreshTitleBarThemeColor ( HWND hWnd)
346 {
347 if (IsSupported())
349 }

References IsSupported(), and RefreshTitleBarThemeColor().

Referenced by OnSettingChange(), RefreshTitleBarThemeColor(), and SetDarkTitleBar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ renderButton()

void NppDarkMode::renderButton ( HWND hwnd,
HDC hdc,
HTHEME hTheme,
int iPartID,
int iStateID )
438 {
439 RECT rcClient = { 0 };
440 DWORD nStyle = GetWindowLong(hwnd, GWL_STYLE);
441/* WCHAR szText[256] = { 0 };
442 DWORD nState = static_cast<DWORD>(SendMessage(hwnd, BM_GETSTATE, 0, 0));
443 DWORD uiState = static_cast<DWORD>(SendMessage(hwnd, WM_QUERYUISTATE, 0, 0));
444
445 HFONT hFont = nullptr;
446 HFONT hOldFont = nullptr;
447 HFONT hCreatedFont = nullptr;
448 LOGFONT lf = { 0 };
449 if (SUCCEEDED(GetThemeFont(hTheme, hdc, iPartID, iStateID, TMT_FONT, &lf)))
450 {
451 hCreatedFont = CreateFontIndirect(&lf);
452 hFont = hCreatedFont;
453 }
454
455 if (!hFont) {
456 hFont = reinterpret_cast<HFONT>(SendMessage(hwnd, WM_GETFONT, 0, 0));
457 }
458
459 hOldFont = static_cast<HFONT>(SelectObject(hdc, hFont));
460
461 DWORD dtFlags = DT_LEFT; // DT_LEFT is 0
462 dtFlags |= (nStyle & BS_MULTILINE) ? DT_WORDBREAK : DT_SINGLELINE;
463 dtFlags |= ((nStyle & BS_CENTER) == BS_CENTER) ? DT_CENTER : (nStyle & BS_RIGHT) ? DT_RIGHT : 0;
464 dtFlags |= ((nStyle & BS_VCENTER) == BS_VCENTER) ? DT_VCENTER : (nStyle & BS_BOTTOM) ? DT_BOTTOM : 0;
465 dtFlags |= (uiState & UISF_HIDEACCEL) ? DT_HIDEPREFIX : 0;
466
467 if (!(nStyle & BS_MULTILINE) && !(nStyle & BS_BOTTOM) && !(nStyle & BS_TOP))
468 {
469 dtFlags |= DT_VCENTER;
470 }
471
472 GetClientRect(hwnd, &rcClient);
473 GetWindowText(hwnd, szText, _countof(szText));
474
475 SIZE szBox = { 13, 13 };
476 GetThemePartSize(hTheme, hdc, iPartID, iStateID, NULL, TS_DRAW, &szBox);
477
478 RECT rcText = rcClient;
479 GetThemeBackgroundContentRect(hTheme, hdc, iPartID, iStateID, &rcClient, &rcText);
480
481 RECT rcBackground = rcClient;
482 if (dtFlags & DT_SINGLELINE)
483 {
484 rcBackground.top += (rcText.bottom - rcText.top - szBox.cy) / 2;
485 }
486 rcBackground.bottom = rcBackground.top + szBox.cy;
487 rcBackground.right = rcBackground.left + szBox.cx;
488 rcText.left = rcBackground.right + 3;
489
490 DrawThemeParentBackground(hwnd, hdc, &rcClient);
491 DrawThemeBackground(hTheme, hdc, iPartID, iStateID, &rcBackground, nullptr);
492
493 DTTOPTS dtto = { sizeof(DTTOPTS), DTT_TEXTCOLOR };
494 dtto.crText = iPartID == SBP_ARROWBTN ? GetSofterTextColor() : GetTextColor();
495
496 if (nStyle & WS_DISABLED)
497 {
498 dtto.crText = GetSofterBackgroundColor();
499 }
500*/
501 GetClientRect(hwnd, &rcClient);
502 DrawThemeParentBackground(hwnd, hdc, &rcClient);
503
504 if (iPartID == SBP_ARROWBTN)
505 {
506 {
507 HBRUSH hbrush = ::CreateSolidBrush(RGB(0x64, 0x64, 0x64));
508 ::FrameRect(hdc, &rcClient, hbrush);
509 ::DeleteObject(hbrush);
510 }
511
512 COLORREF color = nStyle & WS_DISABLED ? GetSofterBackgroundColor() : GetSofterTextColor();
513
514 HPEN hPen = CreatePen(PS_SOLID, 1, color);
515 HPEN hOldPen = SelectPen(hdc, hPen);
516
517 HBRUSH hBrush = CreateSolidBrush(color);
518 HBRUSH hOldBrush = SelectBrush(hdc, hBrush);
519
520 // Up arrow
521 RECT rcFocus = rcClient;
522 rcFocus.bottom *= 0.5;
523 rcFocus.left += 1;
524 InflateRect(&rcFocus, -1, -1);
525
526 int triangle_edge = int(0.25 * (rcClient.right - rcClient.left));
527
528 int left_pos = triangle_edge + 1;
529 int shift_from_center = 0.5 * triangle_edge;
530 int bottom_pos = rcFocus.bottom - shift_from_center;
531 rcFocus.bottom += 1;
532 POINT vertices_up[] = { {left_pos, bottom_pos }, {left_pos + triangle_edge, bottom_pos - triangle_edge}, {left_pos + 2*triangle_edge, bottom_pos} };
533 Polygon(hdc, vertices_up, 3);
534
535 if (iStateID == ARROWBTNSTATES::ABS_UPHOT)
536 DrawFocusRect(hdc, &rcFocus);
537
538 // Down arrow
539 rcFocus = rcClient;
540 rcFocus.top = 0.5 * rcFocus.bottom;
541 rcFocus.left += 1;
542 InflateRect(&rcFocus, -1, -1);
543
544 int top_pos = rcFocus.top + shift_from_center;
545 POINT vertices_down[] = { {left_pos, top_pos }, {left_pos + triangle_edge, top_pos + triangle_edge}, {left_pos + 2 * triangle_edge, top_pos} };
546 Polygon(hdc, vertices_down, 3);
547
548 if (iStateID == ARROWBTNSTATES::ABS_DOWNHOT)
549 DrawFocusRect(hdc, &rcFocus);
550
551 SelectBrush(hdc, hOldBrush);
552 DeleteObject(hBrush);
553
554 SelectPen(hdc, hOldPen);
555 DeleteObject(hPen);
556 }
557/* else
558 DrawThemeTextEx(hTheme, hdc, iPartID, iStateID, szText, -1, dtFlags, &rcText, &dtto);
559
560 if ((nState & BST_FOCUS) && !(uiState & UISF_HIDEFOCUS))
561 {
562 RECT rcTextOut = rcText;
563 dtto.dwFlags |= DTT_CALCRECT;
564 DrawThemeTextEx(hTheme, hdc, iPartID, iStateID, szText, -1, dtFlags | DT_CALCRECT, &rcTextOut, &dtto);
565 RECT rcFocus = rcTextOut;
566 rcFocus.bottom++;
567 rcFocus.left--;
568 rcFocus.right++;
569 DrawFocusRect(hdc, &rcFocus);
570 }
571
572 if (hCreatedFont) DeleteObject(hCreatedFont);
573 SelectObject(hdc, hOldFont);
574*/ }
COLORREF GetSofterTextColor()
Definition dark_mode.cpp:95
Slic3r::Polygon Polygon
Definition Emboss.cpp:101

References GetSofterBackgroundColor(), and GetSofterTextColor().

Referenced by paintButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scaled()

int NppDarkMode::scaled ( HWND hwnd,
int val )
399 {
400 float scale = 1.0;
401 // Both GetDpiForWindow and GetDpiForSystem shall be supported since Windows 10, version 1607
403 scale = float(_GetDpiForWindow(hwnd)) / _GetDpiForSystem();
404 return std::round(scale * val);
405 }
int scale(const int val)
Definition WipeTowerDialog.cpp:58
fnGetDpiForWindow _GetDpiForWindow
Definition dark_mode.hpp:87
fnGetDpiForSystem _GetDpiForSystem
Definition dark_mode.hpp:88

References _GetDpiForSystem, _GetDpiForWindow, and scale().

Here is the call graph for this function:

◆ SetDarkExplorerTheme()

void NppDarkMode::SetDarkExplorerTheme ( HWND hwnd)
368 {
369 if (IsSupported())
370 SetWindowTheme(hwnd, IsEnabled() ? L"DarkMode_Explorer" : nullptr, nullptr);
371 }

References IsEnabled(), IsSupported(), and L.

Referenced by Slic3r::GUI::GUI_App::force_colors_update(), Slic3r::GUI::PreferencesDialog::set_dark_mode(), SetDarkTitleBar(), Slic3r::GUI::GUI_App::UpdateDlgDarkUI(), and Slic3r::GUI::GUI_App::UpdateFrameDarkUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDarkListView()

void NppDarkMode::SetDarkListView ( HWND hwnd)
374 {
375 if (!IsSupported())
376 return;
377 bool useDark = IsEnabled();
378
379 if (HWND hHeader = ListView_GetHeader(hwnd)) {
380 _AllowDarkModeForWindow(hHeader, useDark);
381 SetWindowTheme(hHeader, useDark ? L"ItemsView" : nullptr, nullptr);
382 }
383
384 _AllowDarkModeForWindow(hwnd, useDark);
385 SetWindowTheme(hwnd, L"Explorer", nullptr);
386 }
fnAllowDarkModeForWindow _AllowDarkModeForWindow
Definition dark_mode.hpp:90

References _AllowDarkModeForWindow, IsEnabled(), IsSupported(), and L.

Here is the call graph for this function:

◆ SetDarkListViewHeader()

void NppDarkMode::SetDarkListViewHeader ( HWND hHeader)
389 {
390 if (!IsSupported())
391 return;
392 bool useDark = IsEnabled();
393
394 _AllowDarkModeForWindow(hHeader, useDark);
395 SetWindowTheme(hHeader, useDark ? L"ItemsView" : nullptr, nullptr);
396 }

References _AllowDarkModeForWindow, IsEnabled(), IsSupported(), and L.

Referenced by Slic3r::GUI::GUI_App::UpdateDVCDarkUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDarkMode()

void NppDarkMode::SetDarkMode ( bool dark_mode)
314 {
315 g_darkModeEnabled = dark_mode;
316
317 if (!IsSupported())
318 return;
319
320 AllowDarkModeForApp(dark_mode);
324 }
void FixDarkScrollBar()
Definition dark_mode.hpp:192
fnFlushMenuThemes _FlushMenuThemes
Definition dark_mode.hpp:92

References _FlushMenuThemes, AllowDarkModeForApp(), FixDarkScrollBar(), g_darkModeEnabled, g_SystemMenuEnabled, and IsSupported().

Referenced by Slic3r::GUI::GUI_App::force_colors_update(), InitDarkMode(), and Slic3r::GUI::GUI_App::on_init_inner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDarkTitleBar()

void NppDarkMode::SetDarkTitleBar ( HWND hwnd)
358 {
359 if (!IsSupported())
360 return;
361
365 }
bool AllowDarkModeForWindow(HWND hWnd, bool allow)
Definition dark_mode.cpp:338
void SetDarkExplorerTheme(HWND hwnd)
Definition dark_mode.cpp:367

References AllowDarkModeForWindow(), IsEnabled(), IsSupported(), RefreshTitleBarThemeColor(), and SetDarkExplorerTheme().

Referenced by Slic3r::GUI::GUI_App::force_colors_update(), Slic3r::GUI::PreferencesDialog::set_dark_mode(), Slic3r::GUI::GUI_App::UpdateDlgDarkUI(), and Slic3r::GUI::GUI_App::UpdateFrameDarkUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSystemMenuForApp()

void NppDarkMode::SetSystemMenuForApp ( bool set_sys_menu)
327 {
328 if (IsSupported())
329 g_SystemMenuEnabled = set_sys_menu;
330 }

References g_SystemMenuEnabled, and IsSupported().

Referenced by Slic3r::GUI::GUI_App::on_init_inner().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subclassButtonControl()

void NppDarkMode::subclassButtonControl ( HWND hwnd)
780 {
781 DWORD_PTR pButtonData = reinterpret_cast<DWORD_PTR>(new ButtonData());
782 SetWindowSubclass(hwnd, ButtonSubclass, g_buttonSubclassID, pButtonData);
783 }

References ButtonSubclass(), and g_buttonSubclassID.

Referenced by AutoSubclassAndThemeChildControls().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UAHWndProc()

bool NppDarkMode::UAHWndProc ( HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam,
LRESULT * lr )
158 {
159 if (!IsEnabled())
160 return false;
161
162 static HTHEME g_menuTheme = nullptr;
163
164 UNREFERENCED_PARAMETER(wParam);
165 switch (message)
166 {
167 case WM_UAHDRAWMENU:
168 {
169 UAHMENU* pUDM = (UAHMENU*)lParam;
170 RECT rc = { 0 };
171
172 // get the menubar rect
173 {
174 MENUBARINFO mbi = { sizeof(mbi) };
175 GetMenuBarInfo(hWnd, OBJID_MENU, 0, &mbi);
176
177 RECT rcWindow;
178 GetWindowRect(hWnd, &rcWindow);
179
180 // the rcBar is offset by the window rect
181 rc = mbi.rcBar;
182 OffsetRect(&rc, -rcWindow.left, -rcWindow.top);
183
184 rc.top -= 1;
185 }
186
187 FillRect(pUDM->hdc, &rc, GetBackgroundBrush());
188
189 *lr = 0;
190
191 return true;
192 }
194 {
195 UAHDRAWMENUITEM* pUDMI = (UAHDRAWMENUITEM*)lParam;
196
197 // get the menu item string
198 wchar_t menuString[256] = { 0 };
199 MENUITEMINFO mii = { sizeof(mii), MIIM_STRING };
200 {
201 mii.dwTypeData = menuString;
202 mii.cch = (sizeof(menuString) / 2) - 1;
203
204 GetMenuItemInfo(pUDMI->um.hmenu, pUDMI->umi.iPosition, TRUE, &mii);
205 }
206
207 // get the item state for drawing
208
209 DWORD dwFlags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
210
211 int iTextStateID = MPI_NORMAL;
212 int iBackgroundStateID = MPI_NORMAL;
213 {
214 if ((pUDMI->dis.itemState & ODS_INACTIVE) | (pUDMI->dis.itemState & ODS_DEFAULT)) {
215 // normal display
216 iTextStateID = MPI_NORMAL;
217 iBackgroundStateID = MPI_NORMAL;
218 }
219 if (pUDMI->dis.itemState & ODS_HOTLIGHT) {
220 // hot tracking
221 iTextStateID = MPI_HOT;
222 iBackgroundStateID = MPI_HOT;
223 }
224 if (pUDMI->dis.itemState & ODS_SELECTED) {
225 // clicked -- MENU_POPUPITEM has no state for this, though MENU_BARITEM does
226 iTextStateID = MPI_HOT;
227 iBackgroundStateID = MPI_HOT;
228 }
229 if ((pUDMI->dis.itemState & ODS_GRAYED) || (pUDMI->dis.itemState & ODS_DISABLED)) {
230 // disabled / grey text
231 iTextStateID = MPI_DISABLED;
232 iBackgroundStateID = MPI_DISABLED;
233 }
234 if (pUDMI->dis.itemState & ODS_NOACCEL) {
235 dwFlags |= DT_HIDEPREFIX;
236 }
237 }
238
239 if (!g_menuTheme) {
240 g_menuTheme = OpenThemeData(hWnd, L"Menu");
241 }
242
243 if (iBackgroundStateID == MPI_NORMAL || iBackgroundStateID == MPI_DISABLED) {
244 FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::GetBackgroundBrush());
245 }
246 else if (iBackgroundStateID == MPI_HOT) {
247 FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::GetSofterBackgroundBrush());
248 }
249 else {
250 DrawThemeBackground(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iBackgroundStateID, &pUDMI->dis.rcItem, nullptr);
251 }
252 DTTOPTS dttopts = { sizeof(dttopts) };
253 if (iTextStateID == MPI_NORMAL || iTextStateID == MPI_HOT) {
254 dttopts.dwFlags |= DTT_TEXTCOLOR;
255 dttopts.crText = NppDarkMode::GetTextColor();
256 }
257 DrawThemeTextEx(g_menuTheme, pUDMI->um.hdc, MENU_POPUPITEM, iTextStateID, menuString, mii.cch, dwFlags, &pUDMI->dis.rcItem, &dttopts);
258
259 *lr = 0;
260
261 return true;
262 }
263 case WM_THEMECHANGED:
264 {
265 if (g_menuTheme) {
266 CloseThemeData(g_menuTheme);
267 g_menuTheme = nullptr;
268 }
269 // continue processing in main wndproc
270 return false;
271 }
272 default:
273 return false;
274 }
275 }
#define WM_UAHDRAWMENU
Definition UAHMenuBar.hpp:12
int iPosition
Definition UAHMenuBar.hpp:51
UAHMENUITEM umi
Definition UAHMenuBar.hpp:63
HMENU hmenu
Definition UAHMenuBar.hpp:43
DRAWITEMSTRUCT dis
Definition UAHMenuBar.hpp:61
struct UAHDRAWMENUITEM UAHDRAWMENUITEM
struct tagUAHMENU UAHMENU
#define WM_UAHDRAWMENUITEM
Definition UAHMenuBar.hpp:13
UAHMENU um
Definition UAHMenuBar.hpp:62
HDC hdc
Definition UAHMenuBar.hpp:44
COLORREF GetTextColor()
Definition dark_mode.cpp:85
HBRUSH GetSofterBackgroundBrush()
Definition dark_mode.cpp:128

References UAHDRAWMENUITEM::dis, GetBackgroundBrush(), GetSofterBackgroundBrush(), GetTextColor(), tagUAHMENU::hdc, tagUAHMENU::hmenu, tagUAHMENUITEM::iPosition, IsEnabled(), L, UAHDRAWMENUITEM::um, UAHDRAWMENUITEM::umi, WM_UAHDRAWMENU, and WM_UAHDRAWMENUITEM.

Here is the call graph for this function:

Variable Documentation

◆ g_buttonSubclassID

UINT_PTR NppDarkMode::g_buttonSubclassID = 42
constexpr