From: Zhiyi Zhang <zzhang(a)codeweavers.com> --- dlls/comctl32/comctl32.h | 1 + dlls/comctl32/commctrl.c | 49 ++++++++++++++++++++++++++++++++++++++ dlls/comctl32_v6/listbox.c | 39 +----------------------------- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/dlls/comctl32/comctl32.h b/dlls/comctl32/comctl32.h index adf3de64738..de4b2dac956 100644 --- a/dlls/comctl32/comctl32.h +++ b/dlls/comctl32/comctl32.h @@ -196,6 +196,7 @@ void COMCTL32_DrawInsertMark(HDC hDC, const RECT *lpRect, COLORREF clrInsertMark void COMCTL32_EnsureBitmapSize(HBITMAP *pBitmap, int cxMinWidth, int cyMinHeight, COLORREF crBackground); void COMCTL32_GetFontMetrics(HFONT hFont, TEXTMETRICW *ptm); BOOL COMCTL32_IsReflectedMessage(UINT uMsg); +LRESULT COMCTL32_NCPaint(HWND hwnd, WPARAM wp, LPARAM lp, const WCHAR *theme_class); LRESULT COMCTL32_SetVersion(INT *current_version, INT new_version); LRESULT COMCTL32_ThemeChanged(HWND hwnd, const WCHAR *theme_class, BOOL invalidate, BOOL erase); INT Str_GetPtrWtoA(LPCWSTR lpSrc, LPSTR lpDest, INT nMaxLen); diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c index 3cc0d79c248..c7541a91668 100644 --- a/dlls/comctl32/commctrl.c +++ b/dlls/comctl32/commctrl.c @@ -3145,3 +3145,52 @@ LRESULT COMCTL32_ThemeChanged(HWND hwnd, const WCHAR *theme_class, BOOL invalida InvalidateRect(hwnd, NULL, erase); return 0; } + +/* A helper to handle WM_NCPAINT messages + * + * If theme_class is specified, open the specified theme class. Otherwise, get the theme class from + * the window. + */ +LRESULT COMCTL32_NCPaint(HWND hwnd, WPARAM wp, LPARAM lp, const WCHAR *theme_class) +{ + HRGN region = (HRGN)wp, clipRgn; + INT cxEdge, cyEdge; + HTHEME theme; + LONG exStyle; + HDC dc; + RECT r; + + exStyle = GetWindowLongW(hwnd, GWL_EXSTYLE); + if (!(exStyle & WS_EX_CLIENTEDGE)) + return DefWindowProcW(hwnd, WM_NCPAINT, wp, lp); + + if (theme_class) + theme = OpenThemeDataForDpi(NULL, theme_class, GetDpiForWindow(hwnd)); + else + theme = GetWindowTheme(hwnd); + if (!theme) + return DefWindowProcW(hwnd, WM_NCPAINT, wp, lp); + + cxEdge = GetSystemMetrics(SM_CXEDGE); + cyEdge = GetSystemMetrics(SM_CYEDGE); + GetWindowRect(hwnd, &r); + + /* New clipping region passed to default proc to exclude border */ + clipRgn = CreateRectRgn(r.left + cxEdge, r.top + cyEdge, r.right - cxEdge, r.bottom - cyEdge); + if (region != (HRGN)1) + CombineRgn(clipRgn, clipRgn, region, RGN_AND); + OffsetRect(&r, -r.left, -r.top); + + dc = GetDCEx(hwnd, region, DCX_WINDOW | DCX_INTERSECTRGN); + if (IsThemeBackgroundPartiallyTransparent(theme, 0, 0)) + DrawThemeParentBackground(hwnd, dc, &r); + DrawThemeBackground(theme, dc, 0, 0, &r, 0); + ReleaseDC(hwnd, dc); + if (theme_class) + CloseThemeData(theme); + + /* Call default proc to get the scrollbars etc. also painted */ + DefWindowProcW(hwnd, WM_NCPAINT, (WPARAM)clipRgn, 0); + DeleteObject(clipRgn); + return 0; +} diff --git a/dlls/comctl32_v6/listbox.c b/dlls/comctl32_v6/listbox.c index 9caa30239a9..7dec0e2d999 100644 --- a/dlls/comctl32_v6/listbox.c +++ b/dlls/comctl32_v6/listbox.c @@ -1196,43 +1196,6 @@ static LRESULT LISTBOX_Paint( LB_DESCR *descr, HDC hdc ) return 0; } -static LRESULT LISTBOX_NCPaint( LB_DESCR *descr, HRGN region ) -{ - DWORD exstyle = GetWindowLongW( descr->self, GWL_EXSTYLE); - HTHEME theme = GetWindowTheme( descr->self ); - HRGN cliprgn = region; - int cxEdge, cyEdge; - HDC hdc; - RECT r; - - if (!theme || !(exstyle & WS_EX_CLIENTEDGE)) - return DefWindowProcW(descr->self, WM_NCPAINT, (WPARAM)region, 0); - - cxEdge = GetSystemMetrics(SM_CXEDGE); - cyEdge = GetSystemMetrics(SM_CYEDGE); - - GetWindowRect(descr->self, &r); - - /* New clipping region passed to default proc to exclude border */ - cliprgn = CreateRectRgn(r.left + cxEdge, r.top + cyEdge, - r.right - cxEdge, r.bottom - cyEdge); - if (region != (HRGN)1) - CombineRgn(cliprgn, cliprgn, region, RGN_AND); - OffsetRect(&r, -r.left, -r.top); - - hdc = GetDCEx(descr->self, region, DCX_WINDOW|DCX_INTERSECTRGN); - - if (IsThemeBackgroundPartiallyTransparent (theme, 0, 0)) - DrawThemeParentBackground(descr->self, hdc, &r); - DrawThemeBackground (theme, hdc, 0, 0, &r, 0); - ReleaseDC(descr->self, hdc); - - /* Call default proc to get the scrollbars etc. also painted */ - DefWindowProcW(descr->self, WM_NCPAINT, (WPARAM)cliprgn, 0); - DeleteObject(cliprgn); - return 0; -} - /*********************************************************************** * LISTBOX_InvalidateItems * @@ -2998,7 +2961,7 @@ static LRESULT CALLBACK LISTBOX_WindowProc( HWND hwnd, UINT msg, WPARAM wParam, return ret; case WM_NCPAINT: - return LISTBOX_NCPaint( descr, (HRGN)wParam ); + return COMCTL32_NCPaint( descr->self, wParam, lParam, NULL ); case WM_GETOBJECT: if ((LONG)lParam == OBJID_QUERYCLASSNAMEIDX) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9221