From 171b886bc5652da63b5ed549c755aa3fa3337eab Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Mon, 6 Jul 2020 19:43:10 +1000 Subject: Split up ThemeDefWindowProc so that the right message handling code is shared with PanelWndProc. --- src/dutil/thmutil.cpp | 235 ++++++++++++++++++++++++++++---------------------- 1 file changed, 132 insertions(+), 103 deletions(-) (limited to 'src') diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp index 75b0e4a0..6025749e 100644 --- a/src/dutil/thmutil.cpp +++ b/src/dutil/thmutil.cpp @@ -334,6 +334,13 @@ static void GetControlDimensions( static HRESULT SizeListViewColumns( __inout THEME_CONTROL* pControl ); +static LRESULT CALLBACK ControlGroupDefWindowProc( + __in_opt THEME* pTheme, + __in HWND hWnd, + __in UINT uMsg, + __in WPARAM wParam, + __in LPARAM lParam + ); static LRESULT CALLBACK PanelWndProc( __in HWND hWnd, __in UINT uMsg, @@ -860,7 +867,14 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc( switch (uMsg) { case WM_NCCREATE: - OnNcCreate(pTheme, hWnd, lParam); + if (pTheme->hwndParent) + { + AssertSz(FALSE, "WM_NCCREATE called multiple times"); + } + else + { + OnNcCreate(pTheme, hWnd, lParam); + } break; case WM_NCHITTEST: @@ -877,41 +891,6 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc( } break; - case WM_DRAWITEM: - ThemeDrawControl(pTheme, reinterpret_cast(lParam)); - return TRUE; - - case WM_CTLCOLORBTN: __fallthrough; - case WM_CTLCOLORSTATIC: - { - HBRUSH hBrush = NULL; - if (ThemeSetControlColor(pTheme, reinterpret_cast(wParam), reinterpret_cast(lParam), &hBrush)) - { - return reinterpret_cast(hBrush); - } - } - break; - - case WM_SETCURSOR: - if (ThemeHoverControl(pTheme, hWnd, reinterpret_cast(wParam))) - { - return TRUE; - } - break; - - case WM_PAINT: - if (::GetUpdateRect(hWnd, NULL, FALSE)) - { - PAINTSTRUCT ps; - ::BeginPaint(hWnd, &ps); - if (hWnd == pTheme->hwndParent) - { - ThemeDrawBackground(pTheme, &ps); - } - ::EndPaint(hWnd, &ps); - } - return 0; - case WM_SIZING: if (pTheme->fAutoResize) { @@ -952,70 +931,10 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc( return 0; } break; - - case WM_TIMER: - OnBillboardTimer(pTheme, hWnd, wParam); - break; - - case WM_NOTIFY: - if (lParam) - { - LPNMHDR pnmhdr = reinterpret_cast(lParam); - switch (pnmhdr->code) - { - // Tab/Shift+Tab support for rich-edit control. - case EN_MSGFILTER: - { - MSGFILTER* msgFilter = reinterpret_cast(lParam); - if (WM_KEYDOWN == msgFilter->msg && VK_TAB == msgFilter->wParam) - { - BOOL fShift = 0x8000 & ::GetKeyState(VK_SHIFT); - HWND hwndFocus = ::GetNextDlgTabItem(hWnd, msgFilter->nmhdr.hwndFrom, fShift); - ::SetFocus(hwndFocus); - return 1; - } - break; - } - - // Hyperlink clicks from rich-edit control. - case EN_LINK: - return SUCCEEDED(OnRichEditEnLink(lParam, pnmhdr->hwndFrom, hWnd)); - - // Clicks on a hypertext/syslink control. - case NM_CLICK: __fallthrough; - case NM_RETURN: - if (ControlIsType(pTheme, static_cast(pnmhdr->idFrom), THEME_CONTROL_TYPE_HYPERTEXT)) - { - PNMLINK pnmlink = reinterpret_cast(lParam); - LITEM litem = pnmlink->item; - ShelExec(litem.szUrl, NULL, L"open", NULL, SW_SHOWDEFAULT, hWnd, NULL); - return 1; - } - - return 0; - } - } - break; - - case WM_COMMAND: - switch (HIWORD(wParam)) - { - case BN_CLICKED: - if (lParam) - { - const THEME_CONTROL* pControl = FindControlFromHWnd(pTheme, (HWND)lParam); - if (pControl && OnButtonClicked(pTheme, hWnd, pControl)) - { - return 0; - } - } - break; - } - break; } } - return ::DefWindowProcW(hWnd, uMsg, wParam, lParam); + return ControlGroupDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam); } @@ -4846,6 +4765,119 @@ LExit: } +static LRESULT CALLBACK ControlGroupDefWindowProc( + __in_opt THEME* pTheme, + __in HWND hWnd, + __in UINT uMsg, + __in WPARAM wParam, + __in LPARAM lParam + ) +{ + if (pTheme) + { + switch (uMsg) + { + case WM_DRAWITEM: + ThemeDrawControl(pTheme, reinterpret_cast(lParam)); + return TRUE; + + case WM_CTLCOLORBTN: __fallthrough; + case WM_CTLCOLORSTATIC: + { + HBRUSH hBrush = NULL; + if (ThemeSetControlColor(pTheme, reinterpret_cast(wParam), reinterpret_cast(lParam), &hBrush)) + { + return reinterpret_cast(hBrush); + } + } + break; + + case WM_SETCURSOR: + if (ThemeHoverControl(pTheme, hWnd, reinterpret_cast(wParam))) + { + return TRUE; + } + break; + + case WM_PAINT: + if (::GetUpdateRect(hWnd, NULL, FALSE)) + { + PAINTSTRUCT ps; + ::BeginPaint(hWnd, &ps); + if (hWnd == pTheme->hwndParent) + { + ThemeDrawBackground(pTheme, &ps); + } + ::EndPaint(hWnd, &ps); + } + return 0; + + case WM_TIMER: + OnBillboardTimer(pTheme, hWnd, wParam); + break; + + case WM_NOTIFY: + if (lParam) + { + LPNMHDR pnmhdr = reinterpret_cast(lParam); + switch (pnmhdr->code) + { + // Tab/Shift+Tab support for rich-edit control. + case EN_MSGFILTER: + { + MSGFILTER* msgFilter = reinterpret_cast(lParam); + if (WM_KEYDOWN == msgFilter->msg && VK_TAB == msgFilter->wParam) + { + BOOL fShift = 0x8000 & ::GetKeyState(VK_SHIFT); + HWND hwndFocus = ::GetNextDlgTabItem(hWnd, msgFilter->nmhdr.hwndFrom, fShift); + ::SetFocus(hwndFocus); + return 1; + } + break; + } + + // Hyperlink clicks from rich-edit control. + case EN_LINK: + return SUCCEEDED(OnRichEditEnLink(lParam, pnmhdr->hwndFrom, hWnd)); + + // Clicks on a hypertext/syslink control. + case NM_CLICK: __fallthrough; + case NM_RETURN: + if (ControlIsType(pTheme, static_cast(pnmhdr->idFrom), THEME_CONTROL_TYPE_HYPERTEXT)) + { + PNMLINK pnmlink = reinterpret_cast(lParam); + LITEM litem = pnmlink->item; + ShelExec(litem.szUrl, NULL, L"open", NULL, SW_SHOWDEFAULT, hWnd, NULL); + return 1; + } + + return 0; + } + } + break; + + case WM_COMMAND: + switch (HIWORD(wParam)) + { + case BN_CLICKED: + if (lParam) + { + const THEME_CONTROL* pControl = FindControlFromHWnd(pTheme, (HWND)lParam); + if (pControl && OnButtonClicked(pTheme, hWnd, pControl)) + { + return 0; + } + } + break; + } + break; + } + } + + return ::DefWindowProcW(hWnd, uMsg, wParam, lParam); +} + + static LRESULT CALLBACK PanelWndProc( __in HWND hWnd, __in UINT uMsg, @@ -4861,7 +4893,8 @@ static LRESULT CALLBACK PanelWndProc( case WM_NCCREATE: { LPCREATESTRUCTW lpcs = reinterpret_cast(lParam); - ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast(lpcs->lpCreateParams)); + pTheme = reinterpret_cast(lpcs->lpCreateParams); + ::SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast(pTheme)); } break; @@ -4873,13 +4906,9 @@ static LRESULT CALLBACK PanelWndProc( case WM_NCHITTEST: return HTCLIENT; break; - - case WM_DRAWITEM: - ThemeDrawControl(pTheme, reinterpret_cast(lParam)); - return TRUE; } - return ThemeDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam); + return ControlGroupDefWindowProc(pTheme, hWnd, uMsg, wParam, lParam); } -- cgit v1.2.3-55-g6feb