From 6d06000600e3e50aeb71edd60b851498b75e2e10 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sun, 25 Jul 2021 09:05:18 +0200 Subject: [PATCH] Apply dark mode on column editor Fix #10236, close #10237 --- PowerEditor/src/NppDarkMode.cpp | 20 +++++-- .../src/ScintillaComponent/columnEditor.cpp | 53 +++++++++++++++++-- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 23f687b24..1a01edbf9 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -984,22 +984,28 @@ namespace NppDarkMode hFont = hCreatedFont; } - if (!hFont) { + if (!hFont) + { hFont = reinterpret_cast(SendMessage(hwnd, WM_GETFONT, 0, 0)); } - SelectObject(hdc, hFont); - + hOldFont = static_cast(::SelectObject(hdc, hFont)); WCHAR szText[256] = { 0 }; GetWindowText(hwnd, szText, _countof(szText)); + auto style = static_cast(::GetWindowLongPtr(hwnd, GWL_STYLE)); + bool isCenter = (style & BS_CENTER) == BS_CENTER; + if (szText[0]) { SIZE textSize = { 0 }; GetTextExtentPoint32(hdc, szText, static_cast(wcslen(szText)), &textSize); + + int centerPosX = isCenter ? ((rcClient.right - rcClient.left - textSize.cx) / 2) : 7; + rcBackground.top += textSize.cy / 2; - rcText.left += 7; + rcText.left += centerPosX; rcText.bottom = rcText.top + textSize.cy; rcText.right = rcText.left + textSize.cx + 4; @@ -1029,7 +1035,9 @@ namespace NppDarkMode DTTOPTS dtto = { sizeof(DTTOPTS), DTT_TEXTCOLOR }; dtto.crText = NppDarkMode::getTextColor(); - DrawThemeTextEx(buttonData.hTheme, hdc, BP_GROUPBOX, iStateID, szText, -1, DT_LEFT | DT_SINGLELINE, &rcText, &dtto); + DWORD textFlags = isCenter ? DT_CENTER : DT_LEFT; + + DrawThemeTextEx(buttonData.hTheme, hdc, BP_GROUPBOX, iStateID, szText, -1, textFlags | DT_SINGLELINE, &rcText, &dtto); } if (hCreatedFont) DeleteObject(hCreatedFont); @@ -1394,6 +1402,8 @@ namespace NppDarkMode , theme }; + ::EnableThemeDialogTexture(hwndParent, theme ? ETDT_ENABLETAB : ETDT_DISABLE); + EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) { auto& p = *reinterpret_cast(lParam); const size_t classNameLen = 16; diff --git a/PowerEditor/src/ScintillaComponent/columnEditor.cpp b/PowerEditor/src/ScintillaComponent/columnEditor.cpp index 5ad3b5dae..e9e19bede 100644 --- a/PowerEditor/src/ScintillaComponent/columnEditor.cpp +++ b/PowerEditor/src/ScintillaComponent/columnEditor.cpp @@ -44,6 +44,8 @@ INT_PTR CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA { case WM_INITDIALOG : { + NppDarkMode::autoSubclassAndThemeChildControls(_hSelf); + switchTo(activeText); ::SendDlgItemMessage(_hSelf, IDC_COL_DEC_RADIO, BM_SETCHECK, TRUE, 0); goToCenter(); @@ -57,6 +59,53 @@ INT_PTR CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA } return TRUE; } + + case WM_CTLCOLOREDIT: + { + if (NppDarkMode::isEnabled()) + { + return NppDarkMode::onCtlColorSofter(reinterpret_cast(wParam)); + } + break; + } + + case WM_CTLCOLORDLG: + case WM_CTLCOLORSTATIC: + { + if (NppDarkMode::isEnabled()) + { + return NppDarkMode::onCtlColorDarker(reinterpret_cast(wParam)); + } + break; + } + + case WM_PRINTCLIENT: + { + if (NppDarkMode::isEnabled()) + { + return TRUE; + } + break; + } + + case WM_ERASEBKGND: + { + if (NppDarkMode::isEnabled()) + { + RECT rc = { 0 }; + getClientRect(rc); + ::FillRect(reinterpret_cast(wParam), &rc, NppDarkMode::getDarkerBackgroundBrush()); + return TRUE; + } + break; + } + + case NPPM_INTERNAL_REFRESHDARKMODE: + { + NppDarkMode::autoThemeChildControls(_hSelf); + return TRUE; + } + case WM_COMMAND : { switch (wParam) @@ -282,7 +331,7 @@ INT_PTR CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA default : return FALSE; } - //return FALSE; + return FALSE; } void ColumnEditorDlg::switchTo(bool toText) @@ -299,7 +348,6 @@ void ColumnEditorDlg::switchTo(bool toText) ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_INCREASENUM_EDIT), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_REPEATNUM_STATIC), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_REPEATNUM_EDIT), !toText); - ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_FORMAT_GRP_STATIC), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_DEC_RADIO), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_HEX_RADIO), !toText); ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_OCT_RADIO), !toText); @@ -321,4 +369,3 @@ UCHAR ColumnEditorDlg::getFormat() f = 3; return (f | (isLeadingZeros?MASK_ZERO_LEADING:0)); } -