From f82802d3d632acf2aa3bea2ef992873ccb399ba6 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Sat, 25 Apr 2015 12:08:20 +0000 Subject: [PATCH] [UXTHEME] Apply Wine commit 2b650fa by Mark Harmstone: Resize source image if destination smaller than margins. svn path=/trunk/; revision=67407 --- reactos/dll/win32/uxtheme/draw.c | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/reactos/dll/win32/uxtheme/draw.c b/reactos/dll/win32/uxtheme/draw.c index d7081cc759e..f8c4950de6a 100644 --- a/reactos/dll/win32/uxtheme/draw.c +++ b/reactos/dll/win32/uxtheme/draw.c @@ -647,9 +647,9 @@ static HRESULT UXTHEME_DrawImageBackground(HTHEME hTheme, HDC hdc, int iPartId, const DTBGOPTS *pOptions) { HRESULT hr = S_OK; - HBITMAP bmpSrc; + HBITMAP bmpSrc, bmpSrcResized = NULL; HGDIOBJ oldSrc; - HDC hdcSrc; + HDC hdcSrc, hdcOrigSrc = NULL; RECT rcSrc; RECT rcDst; POINT dstSize; @@ -713,6 +713,34 @@ static HRESULT UXTHEME_DrawImageBackground(HTHEME hTheme, HDC hdc, int iPartId, GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_SIZINGMARGINS, NULL, &sm); + /* Resize source image if destination smaller than margins */ + if (sm.cyTopHeight + sm.cyBottomHeight > dstSize.y || sm.cxLeftWidth + sm.cxRightWidth > dstSize.x) { + if (sm.cyTopHeight + sm.cyBottomHeight > dstSize.y) { + sm.cyTopHeight = MulDiv(sm.cyTopHeight, dstSize.y, srcSize.y); + sm.cyBottomHeight = dstSize.y - sm.cyTopHeight; + srcSize.y = dstSize.y; + } + + if (sm.cxLeftWidth + sm.cxRightWidth > dstSize.x) { + sm.cxLeftWidth = MulDiv(sm.cxLeftWidth, dstSize.x, srcSize.x); + sm.cxRightWidth = dstSize.x - sm.cxLeftWidth; + srcSize.x = dstSize.x; + } + + hdcOrigSrc = hdcSrc; + hdcSrc = CreateCompatibleDC(NULL); + bmpSrcResized = CreateBitmap(srcSize.x, srcSize.y, 1, 32, NULL); + SelectObject(hdcSrc, bmpSrcResized); + + UXTHEME_StretchBlt(hdcSrc, 0, 0, srcSize.x, srcSize.y, hdcOrigSrc, rcSrc.left, rcSrc.top, + rcSrc.right - rcSrc.left, rcSrc.bottom - rcSrc.top, transparent, transparentcolor); + + rcSrc.left = 0; + rcSrc.top = 0; + rcSrc.right = srcSize.x; + rcSrc.bottom = srcSize.y; + } + hdcDst = hdc; OffsetViewportOrgEx(hdcDst, rcDst.left, rcDst.top, &org); @@ -817,6 +845,8 @@ draw_error: } SelectObject(hdcSrc, oldSrc); DeleteDC(hdcSrc); + if (bmpSrcResized) DeleteObject(bmpSrcResized); + if (hdcOrigSrc) DeleteDC(hdcOrigSrc); CopyRect(pRect, &rcDst); return hr; } -- 2.17.1