diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index b7f259e6b..47ad855a4 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1622,7 +1622,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa { if (NppDarkMode::isEnabled()) { - FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getPureBackgroundBrush()); + FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getDarkerBackgroundBrush()); nmtbcd->clrText = NppDarkMode::getTextColor(); SetTextColor(nmtbcd->nmcd.hdc, NppDarkMode::getTextColor()); return CDRF_SKIPDEFAULT; diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 871b6f9c5..9e6fb737a 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -15,6 +15,73 @@ 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 edge = 0; + }; + + struct Brushes + { + HBRUSH background = nullptr; + HBRUSH softerBackground = nullptr; + HBRUSH hotBackground = nullptr; + HBRUSH pureBackground = nullptr; + HBRUSH errorBackground = nullptr; + + Brushes(const Colors& colors) + : background(::CreateSolidBrush(colors.background)) + , softerBackground(::CreateSolidBrush(colors.softerBackground)) + , hotBackground(::CreateSolidBrush(colors.hotBackground)) + , pureBackground(::CreateSolidBrush(colors.pureBackground)) + , errorBackground(::CreateSolidBrush(colors.errorBackground)) + {} + + ~Brushes() + { + ::DeleteObject(background); background = nullptr; + ::DeleteObject(softerBackground); softerBackground = nullptr; + ::DeleteObject(hotBackground); hotBackground = nullptr; + ::DeleteObject(pureBackground); pureBackground = nullptr; + ::DeleteObject(errorBackground); errorBackground = nullptr; + } + }; + + static const Colors darkColors{ + HEXRGB(0x202020), // background + HEXRGB(0x282828), // softerBackground + HEXRGB(0x404040), // hotBackground + HEXRGB(0x000000), // pureBackground + HEXRGB(0xB00000), // errorBackground + HEXRGB(0xE0E0E0), // textColor + HEXRGB(0xC0C0C0), // darkerTextColor + HEXRGB(0x808080), // edgeColor + }; + + struct Theme + { + Colors colors; + Brushes brushes; + + Theme(const Colors& colors) + : colors(colors) + , brushes(colors) + {} + }; + + Theme& getTheme() + { + static Theme g_theme(darkColors); + return g_theme; + } + static Options _options; // actual runtime options const Options& configuredOptions() @@ -121,75 +188,20 @@ namespace NppDarkMode return invert_c; } - COLORREF getBackgroundColor() - { - return RGB(0x20, 0x20, 0x20); - } + COLORREF getBackgroundColor() { return getTheme().colors.background; } + COLORREF getSofterBackgroundColor() { return getTheme().colors.softerBackground; } + COLORREF getHotBackgroundColor() { return getTheme().colors.hotBackground; } + COLORREF getDarkerBackgroundColor() { return getTheme().colors.pureBackground; } + COLORREF getErrorBackgroundColor() { return getTheme().colors.errorBackground; } + COLORREF getTextColor() { return getTheme().colors.text; } + COLORREF getDarkerTextColor() { return getTheme().colors.darkerText; } + COLORREF getEdgeColor() { return getTheme().colors.edge; } - COLORREF getSofterBackgroundColor() - { - return RGB(0x2B, 0x2B, 0x2B); - } - - COLORREF getHotBackgroundColor() - { - return RGB(0x4D, 0x4D, 0x4D); - } - - COLORREF getPureBackgroundColor() - { - return RGB(0, 0, 0); - } - - COLORREF getTextColor() - { - return RGB(0xE0, 0xE0, 0xE0); - } - - COLORREF getDarkerTextColor() - { - return RGB(0xC0, 0xC0, 0xC0); - } - - COLORREF getEdgeColor() - { - return RGB(0x80, 0x80, 0x80); - } - - COLORREF getErrorBackgroundColor() - { - return RGB(0xB0, 0x00, 0x00); - } - - HBRUSH getBackgroundBrush() - { - static HBRUSH g_hbrBackground = ::CreateSolidBrush(getBackgroundColor()); - return g_hbrBackground; - } - - HBRUSH getSofterBackgroundBrush() - { - static HBRUSH g_hbrSofterBackground = ::CreateSolidBrush(getSofterBackgroundColor()); - return g_hbrSofterBackground; - } - - HBRUSH getHotBackgroundBrush() - { - static HBRUSH g_hbrHotBackground = ::CreateSolidBrush(getHotBackgroundColor()); - return g_hbrHotBackground; - } - - HBRUSH getPureBackgroundBrush() - { - static HBRUSH g_hbrPureBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH); - return g_hbrPureBackground; - } - - HBRUSH getErrorBackgroundBrush() - { - static HBRUSH g_hbrErrorBackground = ::CreateSolidBrush(getErrorBackgroundColor()); - return g_hbrErrorBackground; - } + HBRUSH getBackgroundBrush() { return getTheme().brushes.background; } + HBRUSH getSofterBackgroundBrush() { return getTheme().brushes.softerBackground; } + HBRUSH getHotBackgroundBrush() { return getTheme().brushes.hotBackground; } + HBRUSH getDarkerBackgroundBrush() { return getTheme().brushes.pureBackground; } + HBRUSH getErrorBackgroundBrush() { return getTheme().brushes.errorBackground; } // handle events @@ -237,7 +249,7 @@ namespace NppDarkMode rc.top -= 1; } - FillRect(pUDM->hdc, &rc, NppDarkMode::getPureBackgroundBrush()); + FillRect(pUDM->hdc, &rc, NppDarkMode::getDarkerBackgroundBrush()); *lr = 0; @@ -301,7 +313,7 @@ namespace NppDarkMode if (iBackgroundStateID == MPI_NORMAL || iBackgroundStateID == MPI_DISABLED) { - FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getPureBackgroundBrush()); + FillRect(pUDMI->um.hdc, &pUDMI->dis.rcItem, NppDarkMode::getDarkerBackgroundBrush()); } else if (iBackgroundStateID == MPI_HOT || iBackgroundStateID == MPI_DISABLEDHOT) { @@ -824,7 +836,7 @@ namespace NppDarkMode PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); - FillRect(hdc, &ps.rcPaint, NppDarkMode::getPureBackgroundBrush()); + FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush()); static HPEN g_hpen = CreatePen(PS_SOLID, 1, NppDarkMode::getEdgeColor()); @@ -870,7 +882,7 @@ namespace NppDarkMode SetTextColor(hdc, (bHot || (i == nSelTab) ) ? NppDarkMode::getTextColor() : NppDarkMode::getDarkerTextColor()); - FillRect(hdc, &rcItem, (i == nSelTab) ? NppDarkMode::getPureBackgroundBrush() : NppDarkMode::getBackgroundBrush()); + FillRect(hdc, &rcItem, (i == nSelTab) ? NppDarkMode::getBackgroundBrush() : NppDarkMode::getSofterBackgroundBrush()); SetBkMode(hdc, TRANSPARENT); diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index 5df3c28c5..71f9a2b24 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -2,6 +2,15 @@ #include +constexpr COLORREF HEXRGB(DWORD rrggbb) { + // from 0xRRGGBB like natural #RRGGBB + // to the little-endian 0xBBGGRR + return + ((rrggbb & 0xFF0000) >> 16) | + ((rrggbb & 0x00FF00) ) | + ((rrggbb & 0x0000FF) << 16); +} + namespace NppDarkMode { struct Options @@ -26,14 +35,15 @@ namespace NppDarkMode COLORREF getBackgroundColor(); COLORREF getSofterBackgroundColor(); COLORREF getHotBackgroundColor(); - COLORREF getPureBackgroundColor(); + COLORREF getDarkerBackgroundColor(); + COLORREF getErrorBackgroundColor(); + COLORREF getTextColor(); COLORREF getDarkerTextColor(); COLORREF getEdgeColor(); - COLORREF getErrorBackgroundColor(); HBRUSH getBackgroundBrush(); - HBRUSH getPureBackgroundBrush(); + HBRUSH getDarkerBackgroundBrush(); HBRUSH getSofterBackgroundBrush(); HBRUSH getHotBackgroundBrush(); HBRUSH getErrorBackgroundBrush(); diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index bdbc1c137..8caec932b 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -859,8 +859,8 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM } SetTextColor((HDC)wParam, NppDarkMode::getTextColor()); - SetBkColor((HDC)wParam, NppDarkMode::getPureBackgroundColor()); - return (LRESULT)GetStockObject(BLACK_BRUSH); + SetBkColor((HDC)wParam, NppDarkMode::getBackgroundColor()); + return (LRESULT)NppDarkMode::getBackgroundBrush(); } case WM_PRINTCLIENT: case WM_ERASEBKGND: @@ -871,7 +871,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM } RECT rc = { 0 }; getClientRect(rc); - FillRect((HDC)wParam, &rc, NppDarkMode::getPureBackgroundBrush()); + FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush()); SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, TRUE); return TRUE; } @@ -3683,7 +3683,7 @@ void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) } else if (_statusbarFindStatus == FSMessage) { - fgColor = RGB(0x50, 0x50, 0xFF); // blue + fgColor = RGB(0x70, 0x70, 0xFF); // blue } else if (_statusbarFindStatus == FSTopReached || _statusbarFindStatus == FSEndReached) { @@ -4430,8 +4430,8 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR if (FSNotFound != getFindStatus()) { SetTextColor((HDC)wParam, NppDarkMode::getTextColor()); - SetBkColor((HDC)wParam, NppDarkMode::getPureBackgroundColor()); - return (LRESULT)NppDarkMode::getPureBackgroundBrush(); + SetBkColor((HDC)wParam, NppDarkMode::getBackgroundColor()); + return (LRESULT)NppDarkMode::getBackgroundBrush(); } else // text not found { @@ -4462,8 +4462,8 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR } SetTextColor((HDC)wParam, NppDarkMode::getTextColor()); - SetBkColor((HDC)wParam, NppDarkMode::getPureBackgroundColor()); - return (LRESULT)GetStockObject(BLACK_BRUSH); + SetBkColor((HDC)wParam, NppDarkMode::getBackgroundColor()); + return (LRESULT)NppDarkMode::getBackgroundBrush(); } case NPPM_INTERNAL_REFRESHDARKMODE: @@ -4577,15 +4577,25 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR case WM_ERASEBKGND: { - HWND hParent = ::GetParent(_hSelf); - HDC winDC = (HDC)wParam; - //RTL handling - POINT pt = {0, 0}, ptOrig = {0, 0}; - ::MapWindowPoints(_hSelf, hParent, &pt, 1); - ::OffsetWindowOrgEx((HDC)wParam, pt.x, pt.y, &ptOrig); - LRESULT lResult = SendMessage(hParent, WM_ERASEBKGND, reinterpret_cast(winDC), 0); - ::SetWindowOrgEx(winDC, ptOrig.x, ptOrig.y, NULL); - return (BOOL)lResult; + if (NppDarkMode::isEnabled()) + { + RECT rcClient = { 0 }; + GetClientRect(_hSelf, &rcClient); + FillRect((HDC)wParam, &rcClient, NppDarkMode::getBackgroundBrush()); + return TRUE; + } + else + { + HWND hParent = ::GetParent(_hSelf); + HDC winDC = (HDC)wParam; + //RTL handling + POINT pt = { 0, 0 }, ptOrig = { 0, 0 }; + ::MapWindowPoints(_hSelf, hParent, &pt, 1); + ::OffsetWindowOrgEx((HDC)wParam, pt.x, pt.y, &ptOrig); + LRESULT lResult = SendMessage(hParent, WM_ERASEBKGND, reinterpret_cast(winDC), 0); + ::SetWindowOrgEx(winDC, ptOrig.x, ptOrig.y, NULL); + return (BOOL)lResult; + } } } return DefWindowProc(getHSelf(), message, wParam, lParam); diff --git a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp index da053fb92..7516f86d7 100644 --- a/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp +++ b/PowerEditor/src/WinControls/FileBrowser/fileBrowser.cpp @@ -710,7 +710,7 @@ void FileBrowser::notified(LPNMHDR notification) { if (NppDarkMode::isEnabled()) { - FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getPureBackgroundBrush()); + FillRect(nmtbcd->nmcd.hdc, &nmtbcd->nmcd.rc, NppDarkMode::getBackgroundBrush()); nmtbcd->clrText = NppDarkMode::getTextColor(); SetTextColor(nmtbcd->nmcd.hdc, NppDarkMode::getTextColor()); SetWindowLongPtr(_hSelf, DWLP_MSGRESULT, CDRF_SKIPDEFAULT); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 999b16424..6d5a6f131 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -866,7 +866,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara RECT rc = { 0 }; GetClientRect(hwnd, &rc); - FillRect((HDC)wParam, &rc, NppDarkMode::getPureBackgroundBrush()); + FillRect((HDC)wParam, &rc, NppDarkMode::getDarkerBackgroundBrush()); return 1; } @@ -886,7 +886,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); - FillRect(hdc, &ps.rcPaint, NppDarkMode::getPureBackgroundBrush()); + FillRect(hdc, &ps.rcPaint, NppDarkMode::getDarkerBackgroundBrush()); UINT id = ::GetDlgCtrlID(hwnd);