From 34384e4482cc38574c0ff43842380d307d2ac8ce Mon Sep 17 00:00:00 2001 From: RaiKoHoff Date: Tue, 1 Sep 2020 17:54:55 +0200 Subject: [PATCH] + chg: get dark mode for Statusbar segments only --- src/DarkMode/DarkMode.cpp | 7 ++- src/Dialogs.c | 69 +++++++++++++++++------ src/Dialogs.h | 6 +- src/Notepad3.c | 112 ++++++++++++++++++++++++++++++++------ src/Notepad3.h | 1 + src/Print.cpp | 2 +- src/TypeDefs.h | 3 +- 7 files changed, 160 insertions(+), 40 deletions(-) diff --git a/src/DarkMode/DarkMode.cpp b/src/DarkMode/DarkMode.cpp index aa0098845..ea2e61f81 100644 --- a/src/DarkMode/DarkMode.cpp +++ b/src/DarkMode/DarkMode.cpp @@ -223,6 +223,7 @@ static void _FixDarkScrollBar() } // ============================================================================ + constexpr bool CheckBuildNumber(DWORD buildNumber) { return (buildNumber == 17763 || // 1809 buildNumber == 18362 || // 1903 @@ -240,7 +241,7 @@ extern "C" void InitDarkMode() RtlGetNtVersionNumbers(&major, &minor, &s_dwWindowsBuildNumber); s_dwWindowsBuildNumber &= ~0xF0000000; - // undocumented function adresses are only valid for this WinVer build numbers + // undocumented function addresses are only valid for this WinVer build numbers if (major == 10 && minor == 0 && CheckBuildNumber(s_dwWindowsBuildNumber)) { HMODULE const hUxtheme = LoadLibraryExW(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); @@ -258,7 +259,7 @@ extern "C" void InitDarkMode() else _SetPreferredAppMode = reinterpret_cast(ord135); - _FlushMenuThemes = reinterpret_cast(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(136))); + //_FlushMenuThemes = reinterpret_cast(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(136))); _IsDarkModeAllowedForWindow = reinterpret_cast(GetProcAddress(hUxtheme, MAKEINTRESOURCEA(137))); _SetWindowCompositionAttribute = reinterpret_cast(GetProcAddress(GetModuleHandleW(L"user32.dll"), "SetWindowCompositionAttribute")); @@ -268,7 +269,7 @@ extern "C" void InitDarkMode() _ShouldAppsUseDarkMode && _AllowDarkModeForWindow && (_AllowDarkModeForApp || _SetPreferredAppMode) && - _FlushMenuThemes && + //_FlushMenuThemes && _IsDarkModeAllowedForWindow) { s_bDarkModeSupported = true; diff --git a/src/Dialogs.c b/src/Dialogs.c index 2876dc08b..519115dc0 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -706,8 +706,8 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam } if (IsDarkModeSupported() && CheckDarkModeEnabled()) { - SetWindowTheme(GetDlgItem(hwnd, IDOK), L"Explorer", NULL); - SetWindowTheme(GetDlgItem(hwnd, IDC_COPYVERSTRG), L"Explorer", NULL); + SetExplorerTheme(GetDlgItem(hwnd, IDOK)); + SetExplorerTheme(GetDlgItem(hwnd, IDC_COPYVERSTRG)); PostMessage(hwnd, WM_THEMECHANGED, 0, 0); } @@ -4610,37 +4610,74 @@ void DeleteBitmapButton(HWND hwnd, int nCtrlId) //============================================================================= // -// StatusSetText() +// StatusOwnerDrawText() // -void StatusSetText(HWND hwnd, UINT nPart, LPCWSTR lpszText) +void StatusSetText(HWND hwnd, BYTE nPart, LPCWSTR lpszText) { if (lpszText) { - UINT const uFlags = ((nPart == (UINT)STATUS_HELP) ? nPart | SBT_NOBORDERS : nPart); - StatusSetSimple(hwnd, (nPart == (UINT)STATUS_HELP)); - SendMessage(hwnd, SB_SETTEXT, uFlags, (LPARAM)lpszText); + SendMessage(hwnd, SB_SETTEXT, (WPARAM)(SBT_OWNERDRAW | nPart), (LPARAM)lpszText); } } + //============================================================================= // // StatusSetTextID() // -bool StatusSetTextID(HWND hwnd, UINT nPart, UINT uID) +bool StatusSetTextID(HWND hwnd, BYTE nPart, UINT uID) { - WCHAR szText[256] = { L'\0' }; - UINT const uFlags = (nPart == STATUS_HELP) ? nPart | SBT_NOBORDERS : nPart; - StatusSetSimple(hwnd, (nPart == (UINT)STATUS_HELP)); - if (!uID) { - SendMessage(hwnd, SB_SETTEXT, uFlags, 0); + SendMessage(hwnd, SB_SETTEXT, (WPARAM)(SBT_OWNERDRAW | nPart), (LPARAM)L""); return true; } - if (!GetLngString(uID, szText, 256)) { return false; } - - return (bool)SendMessage(hwnd, SB_SETTEXT, uFlags, (LPARAM)szText); + WCHAR szText[256] = { L'\0' }; + if (!GetLngString(uID, szText, COUNTOF(szText))) { + return false; + } + return (bool)SendMessage(hwnd, SB_SETTEXT, (WPARAM)(SBT_OWNERDRAW | nPart), (LPARAM)szText); } +#if 0 +//============================================================================= +// +// StatusSetText() +// +void StatusPartSetText(HWND hwnd, BYTE nPart, LPCWSTR lpszText) +{ + if (lpszText) { + BOOL const bSimpleSB = (nPart == STATUS_HELP); + StatusSetSimple(hwnd, bSimpleSB); + DWORD const wparam = (bSimpleSB ? SBT_NOBORDERS : 0) | nPart; + SendMessage(hwnd, SB_SETTEXT, (WPARAM)wparam, (LPARAM)lpszText); + } +} + + +//============================================================================= +// +// StatusPartSetTextID() +// +bool StatusPartSetTextID(HWND hwnd, BYTE nPart, UINT uID) +{ + BOOL const bSimpleSB = (nPart == STATUS_HELP); + StatusSetSimple(hwnd, bSimpleSB); + + DWORD const wparam = (bSimpleSB ? SBT_NOBORDERS : 0) | nPart; + if (!uID) { + SendMessage(hwnd, SB_SETTEXT, (WPARAM)wparam, 0); + return true; + } + + WCHAR szText[256] = { L'\0' }; + if (!GetLngString(uID, szText, COUNTOF(szText))) { + return false; + } + return (bool)SendMessage(hwnd, SB_SETTEXT, (WPARAM)wparam, (LPARAM)szText); +} +#endif + + //============================================================================= // // Toolbar_Get/SetButtons() diff --git a/src/Dialogs.h b/src/Dialogs.h index 87038678e..c45b34923 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -128,8 +128,10 @@ void DeleteBitmapButton(HWND hwnd, int nCtrlId); #define StatusSetSimple(hwnd,b) SendMessage(hwnd,SB_SIMPLE,(WPARAM)b,0) -void StatusSetText(HWND hwnd, UINT nPart, LPCWSTR lpszText); -bool StatusSetTextID(HWND hwnd, UINT nPart, UINT uID); +void StatusSetText(HWND hwnd, BYTE nPart, LPCWSTR lpszText); +bool StatusSetTextID(HWND hwnd, BYTE nPart, UINT uID); +//void StatusPartSetText(HWND hwnd, BYTE nPart, LPCWSTR lpszText); +//bool StatusPartSetTextID(HWND hwnd, BYTE nPart, UINT uID); int Toolbar_GetButtons(HANDLE hwnd, int cmdBase, LPWSTR lpszButtons, int cchButtons); int Toolbar_SetButtons(HANDLE, int, LPCWSTR, void*, int); diff --git a/src/Notepad3.c b/src/Notepad3.c index f77f67340..da6d98f8c 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1660,6 +1660,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) } break; + case WM_DRAWITEM: + return MsgDrawItem(hwnd, wParam, lParam); + case WM_DROPFILES: // see SCN_URIDROPP return MsgDropFiles(hwnd, wParam, lParam); @@ -2067,7 +2070,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam,LPARAM lParam) } if (IsDarkModeSupported()) { - AllowDarkModeForWindow(hwnd, true); + AllowDarkModeForWindow(hwnd, CheckDarkModeEnabled()); RefreshTitleBarThemeColor(hwnd); } @@ -2369,7 +2372,18 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) Globals.hwndToolbar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,dwToolbarStyle, 0,0,0,0,hwnd,(HMENU)IDC_TOOLBAR,hInstance,NULL); - //SetWindowLayoutRTL(Globals.hwndToolbar, Settings.DialogsLayoutRTL); ~ no correct behavior + //~InitWindowCommon(Globals.hwndToolbar, true); ~ SetWindowLayoutRTL() no correct behavior + SetExplorerTheme(Globals.hwndToolbar); + + // @@@ §§§ + if (IsDarkModeSupported()) { + AllowDarkModeForWindow(Globals.hwndToolbar, CheckDarkModeEnabled()); + } + + // @@@ §§§ no effect: + //HDC const hdcTB = GetWindowDC(Globals.hwndToolbar); + //SetBkColor(hdcTB, Globals.rgbDarkBkgColor); + //ReleaseDC(Globals.hwndToolbar, hdcTB); SendMessage(Globals.hwndToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0); @@ -2518,15 +2532,6 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) SendMessage(Globals.hwndToolbar, TB_ADDBUTTONS, COUNTOF(s_tbbMainWnd), (LPARAM)s_tbbMainWnd); } - // @@@ §§§ - if (IsDarkModeSupported()) { - SetWindowTheme(Globals.hwndToolbar, L"Explorer", NULL); - //SetWindowTheme(Globals.hwndToolbar, L"DarkMode_Explorer", NULL); - AllowDarkModeForWindow(Globals.hwndToolbar, CheckDarkModeEnabled()); - RefreshTitleBarThemeColor(Globals.hwndToolbar); - SendMessageW(Globals.hwndToolbar, WM_THEMECHANGED, 0, 0); - } - CloseSettingsFile(bDirtyFlag, bOpendByMe); // ------------------------------ @@ -2539,6 +2544,8 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) s_hwndReBar = CreateWindowEx(WS_EX_TOOLWINDOW,REBARCLASSNAME,NULL,dwReBarStyle, 0,0,0,0,hwnd,(HMENU)IDC_REBAR,hInstance,NULL); + SetExplorerTheme(s_hwndReBar); + REBARINFO rbi; rbi.cbSize = sizeof(REBARINFO); rbi.fMask = 0; @@ -2579,17 +2586,36 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) if (Globals.hwndStatus) { DestroyWindow(Globals.hwndStatus); } Globals.hwndStatus = CreateStatusWindow(dwStatusbarStyle, NULL, hwnd, IDC_STATUSBAR); + //Globals.hwndStatus = CreateWindowEx( + // 0, // no extended styles + // STATUSCLASSNAME, // name of status bar class + // (PCTSTR)NULL, // no text when first created + // dwStatusbarStyle, // creates a visible child window + // 0, 0, 0, 0, // ignores size and position + // hwnd, // handle to parent window + // (HMENU)IDC_STATUSBAR, // child window identifier + // hInstance, // handle to application instance + // NULL); // no window creation data - SetWindowLayoutRTL(Globals.hwndStatus, Settings.DialogsLayoutRTL); + InitWindowCommon(Globals.hwndStatus, true); // @@@ §§§ if (IsDarkModeSupported()) { - SetWindowTheme(Globals.hwndStatus, L"Explorer", NULL); - //SetWindowTheme(Globals.hwndToolbar, L"DarkMode_Explorer", NULL); AllowDarkModeForWindow(Globals.hwndStatus, CheckDarkModeEnabled()); - RefreshTitleBarThemeColor(Globals.hwndStatus); - SendMessageW(Globals.hwndStatus, WM_THEMECHANGED, 0, 0); } + + // @@@ §§§ + //if (IsDarkModeSupported() && CheckDarkModeEnabled()) + //{ + // RECT rcSB; + // HDC const hdc = GetWindowDC(Globals.hwndStatus); + // GetWindowRect(Globals.hwndStatus, &rcSB); + // SetMapMode(hdc, MM_ANISOTROPIC); + // SetWindowExtEx(hdc, 100, 100, NULL); + // SetViewportExtEx(hdc, rcSB.right, rcSB.bottom, NULL); + // FillRect(hdc, &rcSB, s_hbrBkgnd); + // ReleaseDC(Globals.hwndStatus, hdc); + //} } @@ -2812,6 +2838,58 @@ LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam) } +//============================================================================= +// +// MsgDrawItem() - Handles WM_DRAWITEM +// +// +LRESULT MsgDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + UNUSED(hwnd); + + if (LOWORD(wParam) == IDC_STATUSBAR) // Statusbar SB_SETTEXT caused parent's WM_DRAWITEM message + { + // https://docs.microsoft.com/en-us/windows/win32/controls/status-bars#owner-drawn-status-bars + + const DRAWITEMSTRUCT* const pDrawItem = (const DRAWITEMSTRUCT* const)lParam; + + HDC const hdc = pDrawItem->hDC; + HWND const hWndSB = pDrawItem->hwndItem; + //int const partId = (int)pDrawItem->itemID; + //int const stateId = (int)pDrawItem->itemState; + LPCWSTR const text = (LPCWSTR)(pDrawItem->itemData); + RECT rc = pDrawItem->rcItem; + + PAINTSTRUCT ps; + BeginPaint(hWndSB, &ps); + + //HTHEME const hTheme = OpenThemeData(hWndSB, L"Button"); + //if (hTheme) { + + if (CheckDarkModeEnabled()) { + SetBkColor(hdc, Globals.rgbDarkBkgColor); + DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT); + //DrawThemeEdge(hTheme, hdc, partId, stateId, &rc, EDGE_RAISED, BF_RECT, NULL); + SetTextColor(hdc, Globals.rgbDarkTextColor); + } else { + SetBkColor(hdc, GetSysColor(COLOR_BTNFACE)); + DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT); + //DrawThemeEdge(hTheme, hdc, partId, stateId, &rc, EDGE_RAISED, BF_RECT, NULL); + SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT)); + } + ExtTextOut(hdc, rc.left + 2, rc.top + 2, ETO_OPAQUE | ETO_NUMERICSLOCAL, + &rc, text, lstrlen(text), NULL); + + // CloseThemeData(hTheme); + //} + + EndPaint(hWndSB, &ps); + return TRUE; + } + return FALSE; +} + + //============================================================================= // // MsgDropFiles() - Handles WM_DROPFILES @@ -9145,7 +9223,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) if (bIsUpdateNeeded) { int aStatusbarSections[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; - int cnt = 0; + BYTE cnt = 0; int totalWidth = 0; for (int i = 0; i < STATUS_SECTOR_COUNT; ++i) { int const id = s_vSBSOrder[i]; diff --git a/src/Notepad3.h b/src/Notepad3.h index 9688a69e8..973a0ff51 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -187,6 +187,7 @@ LRESULT MsgEndSession(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam); LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam, LPARAM lParam); LRESULT MsgDPIChanged(HWND hwnd, WPARAM wParam, LPARAM lParam); LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam); +LRESULT MsgDrawItem(HWND hwnd, WPARAM wParam, LPARAM lParam); LRESULT MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam); LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam); LRESULT MsgContextMenu(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam); diff --git a/src/Print.cpp b/src/Print.cpp index 68a1df4cf..3db164118 100644 --- a/src/Print.cpp +++ b/src/Print.cpp @@ -60,7 +60,7 @@ void StatusUpdatePrintPage(int iPageNum) { WCHAR tch[80] = { L'\0' }; FormatLngStringW(tch,COUNTOF(tch),IDS_MUI_PRINTFILE,iPageNum); - StatusSetText(Globals.hwndStatus,255,tch); + StatusSetText(Globals.hwndStatus, STATUS_HELP, tch); //RedrawWindow(Globals.hwndStatus, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); InvalidateRect(Globals.hwndStatus,NULL,TRUE); //UpdateWindow(Globals.hwndStatus); diff --git a/src/TypeDefs.h b/src/TypeDefs.h index fd32637a6..d33ec6313 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -34,6 +34,7 @@ #define WIN32_LEAN_AND_MEAN 1 #endif #include +#include #define STRSAFE_NO_CB_FUNCTIONS #define STRSAFE_NO_DEPRECATE // don't allow deprecated functions @@ -144,7 +145,7 @@ typedef enum { STATUS_OCCURRENCE, STATUS_DOCSIZE, STATUS_CODEPAGE, STATUS_EOLMODE, STATUS_OVRMODE, STATUS_2ND_DEF, STATUS_LEXER, STATUS_DOCCHAR, STATUS_OCCREPLACE, STATUS_TINYEXPR, STATUS_SECTOR_COUNT, - STATUS_HELP = 255 + STATUS_HELP = SB_SIMPLEID // (!) } STATUS_SECTOR_T; #define SBS_INIT_ZERO { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }