2 * Win32 5.1 Theme drawing
4 * Copyright (C) 2003 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "uxthemedll.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
40 /***********************************************************************
41 * Defines and global variables
44 extern ATOM atDialogThemeEnabled
;
46 /***********************************************************************/
48 /***********************************************************************
49 * EnableThemeDialogTexture (UXTHEME.@)
51 HRESULT WINAPI
EnableThemeDialogTexture(HWND hwnd
, DWORD dwFlags
)
53 static const WCHAR szTab
[] = { 'T','a','b',0 };
56 TRACE("(%p,0x%08lx\n", hwnd
, dwFlags
);
57 hr
= SetPropW (hwnd
, MAKEINTATOMW (atDialogThemeEnabled
),
58 (HANDLE
)(dwFlags
|0x80000000));
59 /* 0x80000000 serves as a "flags set" flag */
62 if (dwFlags
& ETDT_USETABTEXTURE
)
63 return SetWindowTheme (hwnd
, NULL
, szTab
);
65 return SetWindowTheme (hwnd
, NULL
, NULL
);
69 /***********************************************************************
70 * IsThemeDialogTextureEnabled (UXTHEME.@)
72 BOOL WINAPI
IsThemeDialogTextureEnabled(HWND hwnd
)
74 DWORD dwDialogTextureFlags
;
75 TRACE("(%p)\n", hwnd
);
77 dwDialogTextureFlags
= (DWORD
)GetPropW (hwnd
,
78 MAKEINTATOMW (atDialogThemeEnabled
));
79 if (dwDialogTextureFlags
== 0)
80 /* Means EnableThemeDialogTexture wasn't called for this dialog */
83 return (dwDialogTextureFlags
& ETDT_ENABLE
) && !(dwDialogTextureFlags
& ETDT_DISABLE
);
86 /***********************************************************************
87 * DrawThemeParentBackground (UXTHEME.@)
89 HRESULT WINAPI
DrawThemeParentBackground(HWND hwnd
, HDC hdc
, RECT
*prc
)
97 TRACE("(%p,%p,%p)\n", hwnd
, hdc
, prc
);
98 hParent
= GetParent(hwnd
);
103 MapWindowPoints(hwnd
, NULL
, (LPPOINT
)&rt
, 2);
105 clip
= CreateRectRgn(0,0,1,1);
106 hasClip
= GetClipRgn(hdc
, clip
);
108 TRACE("Failed to get original clipping region\n");
110 IntersectClipRect(hdc
, prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
113 GetClientRect(hParent
, &rt
);
114 MapWindowPoints(hParent
, NULL
, (LPPOINT
)&rt
, 2);
117 OffsetViewportOrgEx(hdc
, -rt
.left
, -rt
.top
, &org
);
119 SendMessageW(hParent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
120 SendMessageW(hParent
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
122 SetViewportOrgEx(hdc
, org
.x
, org
.y
, NULL
);
125 SelectClipRgn(hdc
, NULL
);
126 else if(hasClip
== 1)
127 SelectClipRgn(hdc
, clip
);
134 /***********************************************************************
135 * DrawThemeBackground (UXTHEME.@)
137 HRESULT WINAPI
DrawThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
138 int iStateId
, const RECT
*pRect
,
139 const RECT
*pClipRect
)
142 opts
.dwSize
= sizeof(DTBGOPTS
);
145 opts
.dwFlags
|= DTBG_CLIPRECT
;
146 CopyRect(&opts
.rcClip
, pClipRect
);
148 return DrawThemeBackgroundEx(hTheme
, hdc
, iPartId
, iStateId
, pRect
, &opts
);
151 /***********************************************************************
152 * UXTHEME_SelectImage
154 * Select the image to use
156 static PTHEME_PROPERTY
UXTHEME_SelectImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
)
159 int imageselecttype
= IST_NONE
;
163 image
= TMT_GLYPHIMAGEFILE
;
165 image
= TMT_IMAGEFILE
;
167 if((tp
=MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, image
)))
169 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGESELECTTYPE
, &imageselecttype
);
171 if(imageselecttype
== IST_DPI
) {
173 int screendpi
= GetDeviceCaps(hdc
, LOGPIXELSX
);
174 for(i
=4; i
>=0; i
--) {
176 if(SUCCEEDED(GetThemeInt(hTheme
, iPartId
, iStateId
, i
+ TMT_MINDPI1
, &reqdpi
))) {
177 if(reqdpi
!= 0 && screendpi
>= reqdpi
) {
178 TRACE("Using %d DPI, image %d\n", reqdpi
, i
+ TMT_IMAGEFILE1
);
179 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
183 /* If an image couldnt be selected, choose the first one */
184 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
186 else if(imageselecttype
== IST_SIZE
) {
187 POINT size
= {pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
};
189 for(i
=4; i
>=0; i
--) {
190 if(SUCCEEDED(GetThemePosition(hTheme
, iPartId
, iStateId
, i
+ TMT_MINSIZE1
, &reqsize
))) {
191 if(reqsize
.x
>= size
.x
&& reqsize
.y
>= size
.y
) {
192 TRACE("Using image size %ldx%ld, image %d\n", reqsize
.x
, reqsize
.y
, i
+ TMT_IMAGEFILE1
);
193 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
197 /* If an image couldnt be selected, choose the smallest one */
198 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
203 /***********************************************************************
206 * Load image for part/state
208 static HRESULT
UXTHEME_LoadImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
,
209 HBITMAP
*hBmp
, RECT
*bmpRect
)
211 int imagelayout
= IL_VERTICAL
;
214 WCHAR szPath
[MAX_PATH
];
215 PTHEME_PROPERTY tp
= UXTHEME_SelectImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, glyph
);
217 FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId
, iStateId
);
218 return E_PROP_ID_UNSUPPORTED
;
220 lstrcpynW(szPath
, tp
->lpValue
, min(tp
->dwValueLen
+1, sizeof(szPath
)/sizeof(szPath
[0])));
221 *hBmp
= MSSTYLES_LoadBitmap(hdc
, hTheme
, szPath
);
223 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath
));
224 return HRESULT_FROM_WIN32(GetLastError());
227 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
228 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
230 GetObjectW(*hBmp
, sizeof(bmp
), &bmp
);
231 if(imagelayout
== IL_VERTICAL
) {
232 int height
= bmp
.bmHeight
/imagecount
;
234 bmpRect
->right
= bmp
.bmWidth
;
235 bmpRect
->top
= (max(min(imagecount
, iStateId
), 1)-1) * height
;
236 bmpRect
->bottom
= bmpRect
->top
+ height
;
239 int width
= bmp
.bmWidth
/imagecount
;
240 bmpRect
->left
= (max(min(imagecount
, iStateId
), 1)-1) * width
;
241 bmpRect
->right
= bmpRect
->left
+ width
;
243 bmpRect
->bottom
= bmp
.bmHeight
;
248 /***********************************************************************
251 * Pseudo TransparentBlt/StretchBlt
253 static inline BOOL
UXTHEME_StretchBlt(HDC hdcDst
, int nXOriginDst
, int nYOriginDst
, int nWidthDst
, int nHeightDst
,
254 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
255 BOOL transparent
, COLORREF transcolor
)
258 /* Ensure we don't pass any negative values to TransparentBlt */
259 return TransparentBlt(hdcDst
, nXOriginDst
, nYOriginDst
, abs(nWidthDst
), abs(nHeightDst
),
260 hdcSrc
, nXOriginSrc
, nYOriginSrc
, abs(nWidthSrc
), abs(nHeightSrc
),
263 /* This should be using AlphaBlend */
264 return StretchBlt(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
265 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
269 /***********************************************************************
272 * Simplify sending same width/height for both source and dest
274 static inline BOOL
UXTHEME_Blt(HDC hdcDest
, int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
275 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
276 BOOL transparent
, COLORREF transcolor
)
278 return UXTHEME_StretchBlt(hdcDest
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
279 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthDest
, nHeightDest
,
280 transparent
, transcolor
);
283 /***********************************************************************
286 * Stretches or tiles, depending on sizingtype.
288 static inline BOOL
UXTHEME_SizedBlt (HDC hdcDst
, int nXOriginDst
, int nYOriginDst
,
289 int nWidthDst
, int nHeightDst
,
290 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
291 int nWidthSrc
, int nHeightSrc
,
294 if (sizingtype
== ST_TILE
)
296 int yOfs
= nYOriginDst
;
297 int yRemaining
= nHeightDst
;
298 while (yRemaining
> 0)
300 int bltHeight
= min (yRemaining
, nHeightSrc
);
301 int xOfs
= nXOriginDst
;
302 int xRemaining
= nWidthDst
;
303 while (xRemaining
> 0)
305 int bltWidth
= min (xRemaining
, nWidthSrc
);
306 if (!BitBlt (hdcDst
, xOfs
, yOfs
, bltWidth
, bltHeight
,
307 hdcSrc
, nXOriginSrc
, nYOriginSrc
, SRCCOPY
))
310 xRemaining
-= nWidthSrc
;
313 yRemaining
-= nHeightSrc
;
319 return StretchBlt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
320 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
325 /***********************************************************************
326 * UXTHEME_DrawImageGlyph
328 * Draw an imagefile glyph
330 static HRESULT
UXTHEME_DrawImageGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
331 int iStateId
, RECT
*pRect
,
332 const DTBGOPTS
*pOptions
)
335 HBITMAP bmpSrc
= NULL
;
337 HGDIOBJ oldSrc
= NULL
;
339 BOOL transparent
= FALSE
;
340 COLORREF transparentcolor
= 0;
341 int valign
= VA_CENTER
;
342 int halign
= HA_CENTER
;
347 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, TRUE
, &bmpSrc
, &rcSrc
);
348 if(FAILED(hr
)) return hr
;
349 hdcSrc
= CreateCompatibleDC(hdc
);
351 hr
= HRESULT_FROM_WIN32(GetLastError());
352 DeleteObject(bmpSrc
);
355 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
357 dstSize
.x
= pRect
->right
-pRect
->left
;
358 dstSize
.y
= pRect
->bottom
-pRect
->top
;
359 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
360 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
362 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_GLYPHTRANSPARENT
, &transparent
);
364 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GLYPHTRANSPARENTCOLOR
, &transparentcolor
))) {
365 /* If image is transparent, but no color was specified, use magenta */
366 transparentcolor
= RGB(255, 0, 255);
369 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
370 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
372 topleft
.x
= pRect
->left
;
373 topleft
.y
= pRect
->top
;
374 if(halign
== HA_CENTER
) topleft
.x
+= (dstSize
.x
/2)-(srcSize
.x
/2);
375 else if(halign
== HA_RIGHT
) topleft
.x
+= dstSize
.x
-srcSize
.x
;
376 if(valign
== VA_CENTER
) topleft
.y
+= (dstSize
.y
/2)-(srcSize
.y
/2);
377 else if(valign
== VA_BOTTOM
) topleft
.y
+= dstSize
.y
-srcSize
.y
;
379 if(!UXTHEME_Blt(hdc
, topleft
.x
, topleft
.y
, srcSize
.x
, srcSize
.y
,
380 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
381 transparent
, transparentcolor
)) {
382 hr
= HRESULT_FROM_WIN32(GetLastError());
385 SelectObject(hdcSrc
, oldSrc
);
387 DeleteObject(bmpSrc
);
391 /***********************************************************************
392 * UXTHEME_DrawImageGlyph
394 * Draw glyph on top of background, if appropriate
396 static HRESULT
UXTHEME_DrawGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
397 int iStateId
, RECT
*pRect
,
398 const DTBGOPTS
*pOptions
)
400 int glyphtype
= GT_NONE
;
402 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_GLYPHTYPE
, &glyphtype
);
404 if(glyphtype
== GT_IMAGEGLYPH
) {
405 return UXTHEME_DrawImageGlyph(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pOptions
);
407 else if(glyphtype
== GT_FONTGLYPH
) {
408 /* I don't know what a font glyph is, I've never seen it used in any themes */
409 FIXME("Font glyph\n");
414 /***********************************************************************
415 * get_image_part_size
417 * Used by GetThemePartSize and UXTHEME_DrawImageBackground
419 static HRESULT
get_image_part_size (HTHEME hTheme
, HDC hdc
, int iPartId
,
420 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
427 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, prc
, FALSE
, &bmpSrc
, &rcSrc
);
428 if (FAILED(hr
)) return hr
;
438 int sizingtype
= ST_STRETCH
;
439 BOOL uniformsizing
= FALSE
;
441 CopyRect(&rcDst
, prc
);
443 dstSize
.x
= rcDst
.right
-rcDst
.left
;
444 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
445 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
446 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
448 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_UNIFORMSIZING
, &uniformsizing
);
450 /* Scale height and width equally */
451 int widthDiff
= abs(srcSize
.x
-dstSize
.x
);
452 int heightDiff
= abs(srcSize
.y
-dstSize
.x
);
453 if(widthDiff
> heightDiff
) {
454 dstSize
.y
-= widthDiff
-heightDiff
;
455 rcDst
.bottom
= rcDst
.top
+ dstSize
.y
;
457 else if(heightDiff
> widthDiff
) {
458 dstSize
.x
-= heightDiff
-widthDiff
;
459 rcDst
.right
= rcDst
.left
+ dstSize
.x
;
463 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
464 if(sizingtype
== ST_TRUESIZE
) {
465 int truesizestretchmark
= 0;
467 if(dstSize
.x
< 0 || dstSize
.y
< 0) {
468 BOOL mirrorimage
= TRUE
;
469 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_MIRRORIMAGE
, &mirrorimage
);
472 rcDst
.left
+= dstSize
.x
;
473 rcDst
.right
+= dstSize
.x
;
476 rcDst
.top
+= dstSize
.y
;
477 rcDst
.bottom
+= dstSize
.y
;
481 /* Only stretch when target exceeds source by truesizestretchmark percent */
482 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_TRUESIZESTRETCHMARK
, &truesizestretchmark
);
483 if(dstSize
.x
< 0 || dstSize
.y
< 0 ||
484 MulDiv(srcSize
.x
, 100, dstSize
.x
) > truesizestretchmark
||
485 MulDiv(srcSize
.y
, 100, dstSize
.y
) > truesizestretchmark
) {
486 memcpy (psz
, &dstSize
, sizeof (SIZE
));
489 memcpy (psz
, &srcSize
, sizeof (SIZE
));
494 psz
->x
= abs(dstSize
.x
);
495 psz
->y
= abs(dstSize
.y
);
499 /* else fall through */
501 /* FIXME: couldn't figure how native uxtheme computes min size */
503 psz
->x
= rcSrc
.right
- rcSrc
.left
;
504 psz
->y
= rcSrc
.bottom
- rcSrc
.top
;
510 /***********************************************************************
511 * UXTHEME_DrawImageBackground
513 * Draw an imagefile background
515 static HRESULT
UXTHEME_DrawImageBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
516 int iStateId
, RECT
*pRect
,
517 const DTBGOPTS
*pOptions
)
528 int sizingtype
= ST_STRETCH
;
529 BOOL transparent
= FALSE
;
530 COLORREF transparentcolor
= 0;
532 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, FALSE
, &bmpSrc
, &rcSrc
);
533 if(FAILED(hr
)) return hr
;
534 hdcSrc
= CreateCompatibleDC(hdc
);
536 hr
= HRESULT_FROM_WIN32(GetLastError());
537 DeleteObject(bmpSrc
);
540 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
542 CopyRect(&rcDst
, pRect
);
544 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_TRANSPARENT
, &transparent
);
546 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TRANSPARENTCOLOR
, &transparentcolor
))) {
547 /* If image is transparent, but no color was specified, get the color of the upper left corner */
548 transparentcolor
= GetPixel(hdcSrc
, 0, 0);
552 dstSize
.x
= rcDst
.right
-rcDst
.left
;
553 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
554 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
555 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
557 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
558 if(sizingtype
== ST_TRUESIZE
) {
559 get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, pRect
, TS_DRAW
, &drawSize
);
560 rcDst
.left
+= (dstSize
.x
/2)-(drawSize
.x
/2);
561 rcDst
.top
+= (dstSize
.y
/2)-(drawSize
.y
/2);
562 rcDst
.right
= rcDst
.left
+ drawSize
.x
;
563 rcDst
.bottom
= rcDst
.top
+ drawSize
.y
;
564 if(!UXTHEME_StretchBlt(hdc
, rcDst
.left
, rcDst
.top
, drawSize
.x
, drawSize
.y
,
565 hdcSrc
, rcSrc
.left
, rcSrc
.top
, srcSize
.x
, srcSize
.y
,
566 transparent
, transparentcolor
))
567 hr
= HRESULT_FROM_WIN32(GetLastError());
571 HBITMAP bmpDst
= NULL
;
572 HGDIOBJ oldDst
= NULL
;
575 dstSize
.x
= abs(dstSize
.x
);
576 dstSize
.y
= abs(dstSize
.y
);
578 GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_SIZINGMARGINS
, NULL
, &sm
);
580 hdcDst
= CreateCompatibleDC(hdc
);
582 hr
= HRESULT_FROM_WIN32(GetLastError());
585 bmpDst
= CreateCompatibleBitmap(hdc
, dstSize
.x
, dstSize
.y
);
587 hr
= HRESULT_FROM_WIN32(GetLastError());
590 oldDst
= SelectObject(hdcDst
, bmpDst
);
592 /* Upper left corner */
593 if(!BitBlt(hdcDst
, 0, 0, sm
.cxLeftWidth
, sm
.cyTopHeight
,
594 hdcSrc
, rcSrc
.left
, rcSrc
.top
, SRCCOPY
)) {
595 hr
= HRESULT_FROM_WIN32(GetLastError());
598 /* Upper right corner */
599 if(!BitBlt(hdcDst
, dstSize
.x
-sm
.cxRightWidth
, 0, sm
.cxRightWidth
, sm
.cyTopHeight
,
600 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
, SRCCOPY
)) {
601 hr
= HRESULT_FROM_WIN32(GetLastError());
604 /* Lower left corner */
605 if(!BitBlt(hdcDst
, 0, dstSize
.y
-sm
.cyBottomHeight
, sm
.cxLeftWidth
, sm
.cyBottomHeight
,
606 hdcSrc
, rcSrc
.left
, rcSrc
.bottom
-sm
.cyBottomHeight
, SRCCOPY
)) {
607 hr
= HRESULT_FROM_WIN32(GetLastError());
610 /* Lower right corner */
611 if(!BitBlt(hdcDst
, dstSize
.x
-sm
.cxRightWidth
, dstSize
.y
-sm
.cyBottomHeight
, sm
.cxRightWidth
, sm
.cyBottomHeight
,
612 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
, SRCCOPY
)) {
613 hr
= HRESULT_FROM_WIN32(GetLastError());
617 if ((sizingtype
== ST_STRETCH
) || (sizingtype
== ST_TILE
)) {
618 int destCenterWidth
= dstSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
619 int srcCenterWidth
= srcSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
620 int destCenterHeight
= dstSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
621 int srcCenterHeight
= srcSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
623 if(destCenterWidth
> 0) {
625 if(!UXTHEME_SizedBlt(hdcDst
, sm
.cxLeftWidth
, 0, destCenterWidth
, sm
.cyTopHeight
,
626 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
, srcCenterWidth
, sm
.cyTopHeight
, sizingtype
)) {
627 hr
= HRESULT_FROM_WIN32(GetLastError());
631 if(!UXTHEME_SizedBlt(hdcDst
, sm
.cxLeftWidth
, dstSize
.y
-sm
.cyBottomHeight
, destCenterWidth
, sm
.cyBottomHeight
,
632 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
, srcCenterWidth
, sm
.cyTopHeight
, sizingtype
)) {
633 hr
= HRESULT_FROM_WIN32(GetLastError());
637 if(destCenterHeight
> 0) {
639 if(!UXTHEME_SizedBlt(hdcDst
, 0, sm
.cyTopHeight
, sm
.cxLeftWidth
, destCenterHeight
,
640 hdcSrc
, rcSrc
.left
, rcSrc
.top
+sm
.cyTopHeight
, sm
.cxLeftWidth
, srcCenterHeight
, sizingtype
)) {
641 hr
= HRESULT_FROM_WIN32(GetLastError());
645 if(!UXTHEME_SizedBlt(hdcDst
, dstSize
.x
-sm
.cxRightWidth
, sm
.cyTopHeight
, sm
.cxRightWidth
, destCenterHeight
,
646 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
+sm
.cyTopHeight
, sm
.cxRightWidth
, srcCenterHeight
, sizingtype
)) {
647 hr
= HRESULT_FROM_WIN32(GetLastError());
651 if(destCenterHeight
> 0 && destCenterWidth
> 0) {
652 BOOL borderonly
= FALSE
;
653 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_BORDERONLY
, &borderonly
);
656 if(!UXTHEME_SizedBlt(hdcDst
, sm
.cxLeftWidth
, sm
.cyTopHeight
, destCenterWidth
, destCenterHeight
,
657 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
+sm
.cyTopHeight
, srcCenterWidth
, srcCenterHeight
, sizingtype
)) {
658 hr
= HRESULT_FROM_WIN32(GetLastError());
665 if(!UXTHEME_Blt(hdc
, rcDst
.left
, rcDst
.top
, dstSize
.x
, dstSize
.y
,
667 transparent
, transparentcolor
))
668 hr
= HRESULT_FROM_WIN32(GetLastError());
672 SelectObject(hdcDst
, oldDst
);
675 if(bmpDst
) DeleteObject(bmpDst
);
677 SelectObject(hdcSrc
, oldSrc
);
678 DeleteObject(bmpSrc
);
680 CopyRect(pRect
, &rcDst
);
684 /***********************************************************************
685 * UXTHEME_DrawBorderRectangle
687 * Draw the bounding rectangle for a borderfill background
689 static HRESULT
UXTHEME_DrawBorderRectangle(HTHEME hTheme
, HDC hdc
, int iPartId
,
690 int iStateId
, RECT
*pRect
,
691 const DTBGOPTS
*pOptions
)
696 COLORREF bordercolor
= RGB(0,0,0);
699 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
702 ptCorners
[0].x
= pRect
->left
;
703 ptCorners
[0].y
= pRect
->top
;
704 ptCorners
[1].x
= pRect
->right
-1;
705 ptCorners
[1].y
= pRect
->top
;
706 ptCorners
[2].x
= pRect
->right
-1;
707 ptCorners
[2].y
= pRect
->bottom
-1;
708 ptCorners
[3].x
= pRect
->left
;
709 ptCorners
[3].y
= pRect
->bottom
-1;
710 ptCorners
[4].x
= pRect
->left
;
711 ptCorners
[4].y
= pRect
->top
;
713 InflateRect(pRect
, -bordersize
, -bordersize
);
714 if(pOptions
->dwFlags
& DTBG_OMITBORDER
)
716 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_BORDERCOLOR
, &bordercolor
);
717 hPen
= CreatePen(PS_SOLID
, bordersize
, bordercolor
);
719 return HRESULT_FROM_WIN32(GetLastError());
720 oldPen
= SelectObject(hdc
, hPen
);
722 if(!Polyline(hdc
, ptCorners
, 5))
723 hr
= HRESULT_FROM_WIN32(GetLastError());
725 SelectObject(hdc
, oldPen
);
731 /***********************************************************************
732 * UXTHEME_DrawBackgroundFill
734 * Fill a borderfill background rectangle
736 static HRESULT
UXTHEME_DrawBackgroundFill(HTHEME hTheme
, HDC hdc
, int iPartId
,
737 int iStateId
, RECT
*pRect
,
738 const DTBGOPTS
*pOptions
)
741 int filltype
= FT_SOLID
;
743 TRACE("(%d,%d,%ld)\n", iPartId
, iStateId
, pOptions
->dwFlags
);
745 if(pOptions
->dwFlags
& DTBG_OMITCONTENT
)
748 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_FILLTYPE
, &filltype
);
750 if(filltype
== FT_SOLID
) {
752 COLORREF fillcolor
= RGB(255,255,255);
754 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_FILLCOLOR
, &fillcolor
);
755 hBrush
= CreateSolidBrush(fillcolor
);
756 if(!FillRect(hdc
, pRect
, hBrush
))
757 hr
= HRESULT_FROM_WIN32(GetLastError());
758 DeleteObject(hBrush
);
760 else if(filltype
== FT_VERTGRADIENT
|| filltype
== FT_HORZGRADIENT
) {
761 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
762 the gradient ratios (no idea how those work)
763 Few themes use this, and the ones I've seen only use 2 colors with
764 a gradient ratio of 0 and 255 respectivly
767 COLORREF gradient1
= RGB(0,0,0);
768 COLORREF gradient2
= RGB(255,255,255);
772 FIXME("Gradient implementation not complete\n");
774 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR1
, &gradient1
);
775 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR2
, &gradient2
);
777 vert
[0].x
= pRect
->left
;
778 vert
[0].y
= pRect
->top
;
779 vert
[0].Red
= GetRValue(gradient1
) << 8;
780 vert
[0].Green
= GetGValue(gradient1
) << 8;
781 vert
[0].Blue
= GetBValue(gradient1
) << 8;
782 vert
[0].Alpha
= 0x0000;
784 vert
[1].x
= pRect
->right
;
785 vert
[1].y
= pRect
->bottom
;
786 vert
[1].Red
= GetRValue(gradient2
) << 8;
787 vert
[1].Green
= GetGValue(gradient2
) << 8;
788 vert
[1].Blue
= GetBValue(gradient2
) << 8;
789 vert
[1].Alpha
= 0x0000;
792 gRect
.LowerRight
= 1;
793 GradientFill(hdc
,vert
,2,&gRect
,1,filltype
==FT_HORZGRADIENT
?GRADIENT_FILL_RECT_H
:GRADIENT_FILL_RECT_V
);
795 else if(filltype
== FT_RADIALGRADIENT
) {
796 /* I've never seen this used in a theme */
797 FIXME("Radial gradient\n");
799 else if(filltype
== FT_TILEIMAGE
) {
800 /* I've never seen this used in a theme */
801 FIXME("Tile image\n");
806 /***********************************************************************
807 * UXTHEME_DrawBorderBackground
809 * Draw an imagefile background
811 static HRESULT
UXTHEME_DrawBorderBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
812 int iStateId
, const RECT
*pRect
,
813 const DTBGOPTS
*pOptions
)
818 CopyRect(&rt
, pRect
);
820 hr
= UXTHEME_DrawBorderRectangle(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
823 return UXTHEME_DrawBackgroundFill(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
826 /***********************************************************************
827 * DrawThemeBackgroundEx (UXTHEME.@)
829 HRESULT WINAPI
DrawThemeBackgroundEx(HTHEME hTheme
, HDC hdc
, int iPartId
,
830 int iStateId
, const RECT
*pRect
,
831 const DTBGOPTS
*pOptions
)
834 const DTBGOPTS defaultOpts
= {sizeof(DTBGOPTS
), 0, {0,0,0,0}};
835 const DTBGOPTS
*opts
;
838 int bgtype
= BT_BORDERFILL
;
841 TRACE("(%p,%p,%d,%d,%ld,%ld)\n", hTheme
, hdc
, iPartId
, iStateId
,pRect
->left
,pRect
->top
);
845 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
846 if (bgtype
== BT_NONE
) return S_OK
;
848 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
850 if(!opts
) opts
= &defaultOpts
;
852 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
853 clip
= CreateRectRgn(0,0,1,1);
854 hasClip
= GetClipRgn(hdc
, clip
);
856 TRACE("Failed to get original clipping region\n");
858 IntersectClipRect(hdc
, opts
->rcClip
.left
, opts
->rcClip
.top
, opts
->rcClip
.right
, opts
->rcClip
.bottom
);
860 CopyRect(&rt
, pRect
);
862 if(bgtype
== BT_IMAGEFILE
)
863 hr
= UXTHEME_DrawImageBackground(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
864 else if(bgtype
== BT_BORDERFILL
)
865 hr
= UXTHEME_DrawBorderBackground(hTheme
, hdc
, iPartId
, iStateId
, pRect
, opts
);
867 FIXME("Unknown background type\n");
868 /* This should never happen, and hence I don't know what to return */
872 hr
= UXTHEME_DrawGlyph(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
873 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
875 SelectClipRgn(hdc
, NULL
);
876 else if(hasClip
== 1)
877 SelectClipRgn(hdc
, clip
);
883 /***********************************************************************
884 * DrawThemeEdge (UXTHEME.@)
886 HRESULT WINAPI
DrawThemeEdge(HTHEME hTheme
, HDC hdc
, int iPartId
,
887 int iStateId
, const RECT
*pDestRect
, UINT uEdge
,
888 UINT uFlags
, RECT
*pContentRect
)
890 FIXME("%d %d 0x%08x 0x%08x: stub\n", iPartId
, iStateId
, uEdge
, uFlags
);
893 return ERROR_CALL_NOT_IMPLEMENTED
;
896 /***********************************************************************
897 * DrawThemeIcon (UXTHEME.@)
899 HRESULT WINAPI
DrawThemeIcon(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
900 const RECT
*pRect
, HIMAGELIST himl
, int iImageIndex
)
902 FIXME("%d %d: stub\n", iPartId
, iStateId
);
905 return ERROR_CALL_NOT_IMPLEMENTED
;
908 /***********************************************************************
909 * DrawThemeText (UXTHEME.@)
911 HRESULT WINAPI
DrawThemeText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
912 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
913 DWORD dwTextFlags2
, const RECT
*pRect
)
917 HGDIOBJ oldFont
= NULL
;
920 COLORREF oldTextColor
;
924 TRACE("%d %d: stub\n", iPartId
, iStateId
);
928 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
930 hFont
= CreateFontIndirectW(&logfont
);
932 TRACE("Failed to create font\n");
934 CopyRect(&rt
, pRect
);
936 oldFont
= SelectObject(hdc
, hFont
);
938 if(dwTextFlags2
& DTT_GRAYED
)
939 textColor
= GetSysColor(COLOR_GRAYTEXT
);
941 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TEXTCOLOR
, &textColor
)))
942 textColor
= GetTextColor(hdc
);
944 oldTextColor
= SetTextColor(hdc
, textColor
);
945 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
946 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
947 SetBkMode(hdc
, oldBkMode
);
948 SetTextColor(hdc
, oldTextColor
);
951 SelectObject(hdc
, oldFont
);
957 /***********************************************************************
958 * GetThemeBackgroundContentRect (UXTHEME.@)
960 HRESULT WINAPI
GetThemeBackgroundContentRect(HTHEME hTheme
, HDC hdc
, int iPartId
,
962 const RECT
*pBoundingRect
,
968 TRACE("(%d,%d)\n", iPartId
, iStateId
);
972 /* try content margins property... */
973 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
975 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
976 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
977 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
978 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
980 /* otherwise, try to determine content rect from the background type and props */
981 int bgtype
= BT_BORDERFILL
;
982 memcpy(pContentRect
, pBoundingRect
, sizeof(RECT
));
984 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
985 if(bgtype
== BT_BORDERFILL
) {
988 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
989 InflateRect(pContentRect
, -bordersize
, -bordersize
);
990 } else if ((bgtype
== BT_IMAGEFILE
)
991 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
992 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
993 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
994 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
995 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
996 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
998 /* If nothing was found, leave unchanged */
1001 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pContentRect
->left
, pContentRect
->top
, pContentRect
->right
, pContentRect
->bottom
);
1006 /***********************************************************************
1007 * GetThemeBackgroundExtent (UXTHEME.@)
1009 HRESULT WINAPI
GetThemeBackgroundExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1010 int iStateId
, const RECT
*pContentRect
,
1016 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1020 /* try content margins property... */
1021 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1023 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1024 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1025 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1026 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1028 /* otherwise, try to determine content rect from the background type and props */
1029 int bgtype
= BT_BORDERFILL
;
1030 memcpy(pExtentRect
, pContentRect
, sizeof(RECT
));
1032 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1033 if(bgtype
== BT_BORDERFILL
) {
1036 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1037 InflateRect(pExtentRect
, bordersize
, bordersize
);
1038 } else if ((bgtype
== BT_IMAGEFILE
)
1039 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1040 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1041 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1042 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1043 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1044 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1046 /* If nothing was found, leave unchanged */
1049 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pExtentRect
->left
, pExtentRect
->top
, pExtentRect
->right
, pExtentRect
->bottom
);
1054 /***********************************************************************
1055 * GetThemeBackgroundRegion (UXTHEME.@)
1057 * Calculate the background region, taking into consideration transparent areas
1058 * of the background image.
1060 HRESULT WINAPI
GetThemeBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
,
1061 int iStateId
, const RECT
*pRect
,
1065 int bgtype
= BT_BORDERFILL
;
1067 TRACE("(%p,%p,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
);
1070 if(!pRect
|| !pRegion
)
1073 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1074 if(bgtype
== BT_IMAGEFILE
) {
1075 FIXME("Images not handled yet\n");
1076 hr
= ERROR_CALL_NOT_IMPLEMENTED
;
1078 else if(bgtype
== BT_BORDERFILL
) {
1079 *pRegion
= CreateRectRgn(pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
1081 hr
= HRESULT_FROM_WIN32(GetLastError());
1084 FIXME("Unknown background type\n");
1085 /* This should never happen, and hence I don't know what to return */
1091 /* compute part size for "borderfill" backgrounds */
1092 HRESULT
get_border_background_size (HTHEME hTheme
, int iPartId
,
1093 int iStateId
, THEMESIZE eSize
, POINT
* psz
)
1098 if (SUCCEEDED (hr
= GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
,
1101 psz
->x
= psz
->y
= 2*bordersize
;
1102 if (eSize
!= TS_MIN
)
1111 /***********************************************************************
1112 * GetThemePartSize (UXTHEME.@)
1114 HRESULT WINAPI
GetThemePartSize(HTHEME hTheme
, HDC hdc
, int iPartId
,
1115 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
1118 int bgtype
= BT_BORDERFILL
;
1120 POINT size
= {1, 1};
1125 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1126 if (bgtype
== BT_NONE
)
1128 else if(bgtype
== BT_IMAGEFILE
)
1129 hr
= get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, prc
, eSize
, &size
);
1130 else if(bgtype
== BT_BORDERFILL
)
1131 hr
= get_border_background_size (hTheme
, iPartId
, iStateId
, eSize
, &size
);
1133 FIXME("Unknown background type\n");
1134 /* This should never happen, and hence I don't know what to return */
1143 /***********************************************************************
1144 * GetThemeTextExtent (UXTHEME.@)
1146 HRESULT WINAPI
GetThemeTextExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1147 int iStateId
, LPCWSTR pszText
, int iCharCount
,
1148 DWORD dwTextFlags
, const RECT
*pBoundingRect
,
1153 HGDIOBJ oldFont
= NULL
;
1155 RECT rt
= {0,0,0xFFFF,0xFFFF};
1157 TRACE("%d %d: stub\n", iPartId
, iStateId
);
1162 CopyRect(&rt
, pBoundingRect
);
1164 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
1166 hFont
= CreateFontIndirectW(&logfont
);
1168 TRACE("Failed to create font\n");
1171 oldFont
= SelectObject(hdc
, hFont
);
1173 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
|DT_CALCRECT
);
1174 CopyRect(pExtentRect
, &rt
);
1177 SelectObject(hdc
, oldFont
);
1178 DeleteObject(hFont
);
1183 /***********************************************************************
1184 * GetThemeTextMetrics (UXTHEME.@)
1186 HRESULT WINAPI
GetThemeTextMetrics(HTHEME hTheme
, HDC hdc
, int iPartId
,
1187 int iStateId
, TEXTMETRICW
*ptm
)
1191 HGDIOBJ oldFont
= NULL
;
1194 TRACE("(%p, %p, %d, %d)\n", hTheme
, hdc
, iPartId
, iStateId
);
1198 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
1200 hFont
= CreateFontIndirectW(&logfont
);
1202 TRACE("Failed to create font\n");
1205 oldFont
= SelectObject(hdc
, hFont
);
1207 if(!GetTextMetricsW(hdc
, ptm
))
1208 hr
= HRESULT_FROM_WIN32(GetLastError());
1211 SelectObject(hdc
, oldFont
);
1212 DeleteObject(hFont
);
1217 /***********************************************************************
1218 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
1220 BOOL WINAPI
IsThemeBackgroundPartiallyTransparent(HTHEME hTheme
, int iPartId
,
1223 BOOL transparent
= FALSE
;
1224 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1225 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_TRANSPARENT
, &transparent
);