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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "uxthemedll.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
39 /***********************************************************************
40 * Defines and global variables
43 extern ATOM atDialogThemeEnabled
;
45 /***********************************************************************/
47 /***********************************************************************
48 * EnableThemeDialogTexture (UXTHEME.@)
50 HRESULT WINAPI
EnableThemeDialogTexture(HWND hwnd
, DWORD dwFlags
)
54 TRACE("(%p,0x%08x\n", hwnd
, dwFlags
);
55 res
= SetPropW (hwnd
, (LPCWSTR
)MAKEINTATOM(atDialogThemeEnabled
),
56 UlongToHandle(dwFlags
|0x80000000));
57 /* 0x80000000 serves as a "flags set" flag */
59 return HRESULT_FROM_WIN32(GetLastError());
60 if (dwFlags
& ETDT_USETABTEXTURE
)
61 return SetWindowTheme (hwnd
, NULL
, L
"Tab");
63 return SetWindowTheme (hwnd
, NULL
, NULL
);
66 /***********************************************************************
67 * IsThemeDialogTextureEnabled (UXTHEME.@)
69 BOOL WINAPI
IsThemeDialogTextureEnabled(HWND hwnd
)
71 DWORD dwDialogTextureFlags
;
72 TRACE("(%p)\n", hwnd
);
74 dwDialogTextureFlags
= HandleToUlong( GetPropW( hwnd
, (LPCWSTR
)MAKEINTATOM(atDialogThemeEnabled
) ));
75 if (dwDialogTextureFlags
== 0)
76 /* Means EnableThemeDialogTexture wasn't called for this dialog */
79 return (dwDialogTextureFlags
& ETDT_ENABLE
) && !(dwDialogTextureFlags
& ETDT_DISABLE
);
82 /***********************************************************************
83 * DrawThemeParentBackground (UXTHEME.@)
85 HRESULT WINAPI
DrawThemeParentBackground(HWND hwnd
, HDC hdc
, RECT
*prc
)
93 TRACE("(%p,%p,%p)\n", hwnd
, hdc
, prc
);
94 hParent
= GetParent(hwnd
);
99 MapWindowPoints(hwnd
, hParent
, (LPPOINT
)&rt
, 2);
101 clip
= CreateRectRgn(0,0,1,1);
102 hasClip
= GetClipRgn(hdc
, clip
);
104 TRACE("Failed to get original clipping region\n");
106 IntersectClipRect(hdc
, prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
109 GetClientRect(hwnd
, &rt
);
110 MapWindowPoints(hwnd
, hParent
, (LPPOINT
)&rt
, 2);
113 OffsetViewportOrgEx(hdc
, -rt
.left
, -rt
.top
, &org
);
115 SendMessageW(hParent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
116 SendMessageW(hParent
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
118 SetViewportOrgEx(hdc
, org
.x
, org
.y
, NULL
);
121 SelectClipRgn(hdc
, NULL
);
122 else if(hasClip
== 1)
123 SelectClipRgn(hdc
, clip
);
130 /***********************************************************************
131 * DrawThemeBackground (UXTHEME.@)
133 HRESULT WINAPI
DrawThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
134 int iStateId
, const RECT
*pRect
,
135 const RECT
*pClipRect
)
138 opts
.dwSize
= sizeof(DTBGOPTS
);
141 opts
.dwFlags
|= DTBG_CLIPRECT
;
142 opts
.rcClip
= *pClipRect
;
144 return DrawThemeBackgroundEx(hTheme
, hdc
, iPartId
, iStateId
, pRect
, &opts
);
147 /***********************************************************************
148 * UXTHEME_SelectImage
150 * Select the image to use
152 static PTHEME_PROPERTY
UXTHEME_SelectImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
)
155 int imageselecttype
= IST_NONE
;
159 image
= TMT_GLYPHIMAGEFILE
;
161 image
= TMT_IMAGEFILE
;
163 if((tp
=MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, image
)))
165 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGESELECTTYPE
, &imageselecttype
);
167 if(imageselecttype
== IST_DPI
) {
169 int screendpi
= GetDeviceCaps(hdc
, LOGPIXELSX
);
170 for(i
=4; i
>=0; i
--) {
172 if(SUCCEEDED(GetThemeInt(hTheme
, iPartId
, iStateId
, i
+ TMT_MINDPI1
, &reqdpi
))) {
173 if(reqdpi
!= 0 && screendpi
>= reqdpi
) {
174 TRACE("Using %d DPI, image %d\n", reqdpi
, i
+ TMT_IMAGEFILE1
);
175 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
179 /* If an image couldn't be selected, choose the first one */
180 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
182 else if(imageselecttype
== IST_SIZE
) {
183 POINT size
= {pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
};
185 for(i
=4; i
>=0; i
--) {
186 PTHEME_PROPERTY fileProp
=
187 MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
188 if (!fileProp
) continue;
189 if(FAILED(GetThemePosition(hTheme
, iPartId
, iStateId
, i
+ TMT_MINSIZE1
, &reqsize
))) {
190 /* fall back to size of Nth image */
191 WCHAR szPath
[MAX_PATH
];
192 int imagelayout
= IL_HORIZONTAL
;
198 lstrcpynW(szPath
, fileProp
->lpValue
, min(fileProp
->dwValueLen
+1, ARRAY_SIZE(szPath
)));
199 hBmp
= MSSTYLES_LoadBitmap(hTheme
, szPath
, &hasAlpha
);
202 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
203 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
205 GetObjectW(hBmp
, sizeof(bmp
), &bmp
);
206 if(imagelayout
== IL_VERTICAL
) {
207 reqsize
.x
= bmp
.bmWidth
;
208 reqsize
.y
= bmp
.bmHeight
/imagecount
;
211 reqsize
.x
= bmp
.bmWidth
/imagecount
;
212 reqsize
.y
= bmp
.bmHeight
;
215 if(reqsize
.x
<= size
.x
&& reqsize
.y
<= size
.y
) {
216 TRACE("Using image size %dx%d, image %d\n", reqsize
.x
, reqsize
.y
, i
+ TMT_IMAGEFILE1
);
220 /* If an image couldn't be selected, choose the smallest one */
221 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
226 /***********************************************************************
229 * Load image for part/state
231 static HRESULT
UXTHEME_LoadImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
,
232 HBITMAP
*hBmp
, RECT
*bmpRect
, BOOL
* hasImageAlpha
)
234 int imagelayout
= IL_HORIZONTAL
;
238 WCHAR szPath
[MAX_PATH
];
239 PTHEME_PROPERTY tp
= UXTHEME_SelectImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, glyph
);
241 FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId
, iStateId
);
242 return E_PROP_ID_UNSUPPORTED
;
244 lstrcpynW(szPath
, tp
->lpValue
, min(tp
->dwValueLen
+1, ARRAY_SIZE(szPath
)));
245 *hBmp
= MSSTYLES_LoadBitmap(hTheme
, szPath
, hasImageAlpha
);
247 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath
));
248 return HRESULT_FROM_WIN32(GetLastError());
251 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
252 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
254 imagenum
= max (min (imagecount
, iStateId
), 1) - 1;
255 GetObjectW(*hBmp
, sizeof(bmp
), &bmp
);
257 if(imagecount
< 1) imagecount
= 1;
259 if(imagelayout
== IL_VERTICAL
) {
260 int height
= bmp
.bmHeight
/imagecount
;
262 bmpRect
->right
= bmp
.bmWidth
;
263 bmpRect
->top
= imagenum
* height
;
264 bmpRect
->bottom
= bmpRect
->top
+ height
;
267 int width
= bmp
.bmWidth
/imagecount
;
268 bmpRect
->left
= imagenum
* width
;
269 bmpRect
->right
= bmpRect
->left
+ width
;
271 bmpRect
->bottom
= bmp
.bmHeight
;
276 /***********************************************************************
279 * Pseudo TransparentBlt/StretchBlt
281 static inline BOOL
UXTHEME_StretchBlt(HDC hdcDst
, int nXOriginDst
, int nYOriginDst
, int nWidthDst
, int nHeightDst
,
282 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
283 INT transparent
, COLORREF transcolor
)
285 static const BLENDFUNCTION blendFunc
=
287 AC_SRC_OVER
, /* BlendOp */
289 255, /* SourceConstantAlpha */
290 AC_SRC_ALPHA
/* AlphaFormat */
294 int old_stretch_mode
;
297 old_stretch_mode
= SetStretchBltMode(hdcDst
, HALFTONE
);
298 SetBrushOrgEx(hdcDst
, nXOriginDst
, nYOriginDst
, &old_brush_org
);
300 if (transparent
== ALPHABLEND_BINARY
) {
301 /* Ensure we don't pass any negative values to TransparentBlt */
302 ret
= TransparentBlt(hdcDst
, nXOriginDst
, nYOriginDst
, abs(nWidthDst
), abs(nHeightDst
),
303 hdcSrc
, nXOriginSrc
, nYOriginSrc
, abs(nWidthSrc
), abs(nHeightSrc
),
305 } else if ((transparent
== ALPHABLEND_NONE
) ||
306 !AlphaBlend(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
307 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
310 ret
= StretchBlt(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
311 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
315 SetBrushOrgEx(hdcDst
, old_brush_org
.x
, old_brush_org
.y
, NULL
);
316 SetStretchBltMode(hdcDst
, old_stretch_mode
);
321 /***********************************************************************
324 * Simplify sending same width/height for both source and dest
326 static inline BOOL
UXTHEME_Blt(HDC hdcDest
, int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
327 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
328 INT transparent
, COLORREF transcolor
)
330 return UXTHEME_StretchBlt(hdcDest
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
331 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthDest
, nHeightDest
,
332 transparent
, transcolor
);
335 /***********************************************************************
338 * Stretches or tiles, depending on sizingtype.
340 static inline BOOL
UXTHEME_SizedBlt (HDC hdcDst
, int nXOriginDst
, int nYOriginDst
,
341 int nWidthDst
, int nHeightDst
,
342 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
343 int nWidthSrc
, int nHeightSrc
,
345 INT transparent
, COLORREF transcolor
)
347 if (sizingtype
== ST_TILE
)
352 if (!nWidthSrc
|| !nHeightSrc
) return TRUE
;
354 /* For destination width/height less than or equal to source
355 width/height, do not bother with memory bitmap optimization */
356 if (nWidthSrc
>= nWidthDst
&& nHeightSrc
>= nHeightDst
)
358 int bltWidth
= min (nWidthDst
, nWidthSrc
);
359 int bltHeight
= min (nHeightDst
, nHeightSrc
);
361 return UXTHEME_Blt (hdcDst
, nXOriginDst
, nYOriginDst
, bltWidth
, bltHeight
,
362 hdcSrc
, nXOriginSrc
, nYOriginSrc
,
363 transparent
, transcolor
);
366 /* Create a DC with a bitmap consisting of a tiling of the source
367 bitmap, with standard GDI functions. This is faster than an
368 iteration with UXTHEME_Blt(). */
369 hdcTemp
= CreateCompatibleDC(hdcSrc
);
374 int nWidthTemp
, nHeightTemp
;
375 int xOfs
, xRemaining
;
376 int yOfs
, yRemaining
;
379 /* Calculate temp dimensions of integer multiples of source dimensions */
380 nWidthTemp
= ((nWidthDst
+ nWidthSrc
- 1) / nWidthSrc
) * nWidthSrc
;
381 nHeightTemp
= ((nHeightDst
+ nHeightSrc
- 1) / nHeightSrc
) * nHeightSrc
;
382 bitmapTemp
= CreateCompatibleBitmap(hdcSrc
, nWidthTemp
, nHeightTemp
);
383 bitmapOrig
= SelectObject(hdcTemp
, bitmapTemp
);
385 /* Initial copy of bitmap */
386 BitBlt(hdcTemp
, 0, 0, nWidthSrc
, nHeightSrc
, hdcSrc
, nXOriginSrc
, nYOriginSrc
, SRCCOPY
);
388 /* Extend bitmap in the X direction. Growth of width is exponential */
390 xRemaining
= nWidthTemp
- nWidthSrc
;
391 growSize
= nWidthSrc
;
392 while (xRemaining
> 0)
394 growSize
= min(growSize
, xRemaining
);
395 BitBlt(hdcTemp
, xOfs
, 0, growSize
, nHeightSrc
, hdcTemp
, 0, 0, SRCCOPY
);
397 xRemaining
-= growSize
;
401 /* Extend bitmap in the Y direction. Growth of height is exponential */
403 yRemaining
= nHeightTemp
- nHeightSrc
;
404 growSize
= nHeightSrc
;
405 while (yRemaining
> 0)
407 growSize
= min(growSize
, yRemaining
);
408 BitBlt(hdcTemp
, 0, yOfs
, nWidthTemp
, growSize
, hdcTemp
, 0, 0, SRCCOPY
);
410 yRemaining
-= growSize
;
414 /* Use temporary hdc for source */
415 result
= UXTHEME_Blt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
417 transparent
, transcolor
);
419 SelectObject(hdcTemp
, bitmapOrig
);
420 DeleteObject(bitmapTemp
);
427 return UXTHEME_StretchBlt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
428 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
429 transparent
, transcolor
);
433 /* Get transparency parameters passed to UXTHEME_StretchBlt() - the parameters
434 * depend on whether the image has full alpha or whether it is
435 * color-transparent or just opaque. */
436 static inline void get_transparency (HTHEME hTheme
, int iPartId
, int iStateId
,
437 BOOL hasImageAlpha
, INT
* transparent
,
438 COLORREF
* transparentcolor
, BOOL glyph
)
442 *transparent
= ALPHABLEND_FULL
;
443 *transparentcolor
= RGB (255, 0, 255);
448 GetThemeBool(hTheme
, iPartId
, iStateId
,
449 glyph
? TMT_GLYPHTRANSPARENT
: TMT_TRANSPARENT
, &trans
);
451 *transparent
= ALPHABLEND_BINARY
;
452 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
,
453 glyph
? TMT_GLYPHTRANSPARENTCOLOR
: TMT_TRANSPARENTCOLOR
,
454 transparentcolor
))) {
455 /* If image is transparent, but no color was specified, use magenta */
456 *transparentcolor
= RGB(255, 0, 255);
460 *transparent
= ALPHABLEND_NONE
;
464 /***********************************************************************
465 * UXTHEME_DrawImageGlyph
467 * Draw an imagefile glyph
469 static HRESULT
UXTHEME_DrawImageGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
470 int iStateId
, RECT
*pRect
,
471 const DTBGOPTS
*pOptions
)
474 HBITMAP bmpSrc
= NULL
;
476 HGDIOBJ oldSrc
= NULL
;
479 COLORREF transparentcolor
;
480 int valign
= VA_CENTER
;
481 int halign
= HA_CENTER
;
487 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, TRUE
,
488 &bmpSrc
, &rcSrc
, &hasAlpha
);
489 if(FAILED(hr
)) return hr
;
490 hdcSrc
= CreateCompatibleDC(hdc
);
492 hr
= HRESULT_FROM_WIN32(GetLastError());
495 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
497 dstSize
.x
= pRect
->right
-pRect
->left
;
498 dstSize
.y
= pRect
->bottom
-pRect
->top
;
499 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
500 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
502 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
503 &transparentcolor
, TRUE
);
504 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
505 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
507 topleft
.x
= pRect
->left
;
508 topleft
.y
= pRect
->top
;
509 if(halign
== HA_CENTER
) topleft
.x
+= (dstSize
.x
/2)-(srcSize
.x
/2);
510 else if(halign
== HA_RIGHT
) topleft
.x
+= dstSize
.x
-srcSize
.x
;
511 if(valign
== VA_CENTER
) topleft
.y
+= (dstSize
.y
/2)-(srcSize
.y
/2);
512 else if(valign
== VA_BOTTOM
) topleft
.y
+= dstSize
.y
-srcSize
.y
;
514 if(!UXTHEME_Blt(hdc
, topleft
.x
, topleft
.y
, srcSize
.x
, srcSize
.y
,
515 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
516 transparent
, transparentcolor
)) {
517 hr
= HRESULT_FROM_WIN32(GetLastError());
520 SelectObject(hdcSrc
, oldSrc
);
525 /***********************************************************************
526 * UXTHEME_DrawImageGlyph
528 * Draw glyph on top of background, if appropriate
530 static HRESULT
UXTHEME_DrawGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
531 int iStateId
, RECT
*pRect
,
532 const DTBGOPTS
*pOptions
)
534 int glyphtype
= GT_NONE
;
536 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_GLYPHTYPE
, &glyphtype
);
538 if(glyphtype
== GT_IMAGEGLYPH
) {
539 return UXTHEME_DrawImageGlyph(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pOptions
);
541 else if(glyphtype
== GT_FONTGLYPH
) {
542 /* I don't know what a font glyph is, I've never seen it used in any themes */
543 FIXME("Font glyph\n");
548 /***********************************************************************
549 * get_image_part_size
551 * Used by GetThemePartSize and UXTHEME_DrawImageBackground
553 static HRESULT
get_image_part_size (HTHEME hTheme
, HDC hdc
, int iPartId
,
554 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
562 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, prc
, FALSE
,
563 &bmpSrc
, &rcSrc
, &hasAlpha
);
564 if (FAILED(hr
)) return hr
;
574 int sizingtype
= ST_STRETCH
;
575 BOOL uniformsizing
= FALSE
;
579 dstSize
.x
= rcDst
.right
-rcDst
.left
;
580 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
581 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
582 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
584 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_UNIFORMSIZING
, &uniformsizing
);
586 /* Scale height and width equally */
587 if (dstSize
.x
*srcSize
.y
< dstSize
.y
*srcSize
.x
)
589 dstSize
.y
= MulDiv (srcSize
.y
, dstSize
.x
, srcSize
.x
);
590 rcDst
.bottom
= rcDst
.top
+ dstSize
.y
;
594 dstSize
.x
= MulDiv (srcSize
.x
, dstSize
.y
, srcSize
.y
);
595 rcDst
.right
= rcDst
.left
+ dstSize
.x
;
599 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
600 if(sizingtype
== ST_TRUESIZE
) {
601 int truesizestretchmark
= 100;
603 if(dstSize
.x
< 0 || dstSize
.y
< 0) {
604 BOOL mirrorimage
= TRUE
;
605 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_MIRRORIMAGE
, &mirrorimage
);
608 rcDst
.left
+= dstSize
.x
;
609 rcDst
.right
+= dstSize
.x
;
612 rcDst
.top
+= dstSize
.y
;
613 rcDst
.bottom
+= dstSize
.y
;
617 /* Whatever TrueSizeStretchMark does - it does not seem to
618 * be what's outlined below. It appears as if native
619 * uxtheme always stretches if dest is smaller than source
620 * (ie as if TrueSizeStretchMark==100 with the code below) */
622 /* Only stretch when target exceeds source by truesizestretchmark percent */
623 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_TRUESIZESTRETCHMARK
, &truesizestretchmark
);
625 if(dstSize
.x
< 0 || dstSize
.y
< 0 ||
626 (MulDiv(srcSize
.x
, 100, dstSize
.x
) > truesizestretchmark
&&
627 MulDiv(srcSize
.y
, 100, dstSize
.y
) > truesizestretchmark
)) {
628 memcpy (psz
, &dstSize
, sizeof (SIZE
));
631 memcpy (psz
, &srcSize
, sizeof (SIZE
));
636 psz
->x
= abs(dstSize
.x
);
637 psz
->y
= abs(dstSize
.y
);
641 /* else fall through */
643 /* FIXME: couldn't figure how native uxtheme computes min size */
645 psz
->x
= rcSrc
.right
- rcSrc
.left
;
646 psz
->y
= rcSrc
.bottom
- rcSrc
.top
;
652 /***********************************************************************
653 * UXTHEME_DrawImageBackground
655 * Draw an imagefile background
657 static HRESULT
UXTHEME_DrawImageBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
658 int iStateId
, RECT
*pRect
,
659 const DTBGOPTS
*pOptions
)
662 HBITMAP bmpSrc
, bmpSrcResized
= NULL
;
664 HDC hdcSrc
, hdcOrigSrc
= NULL
;
670 int sizingtype
= ST_STRETCH
;
672 COLORREF transparentcolor
= 0;
675 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, FALSE
,
676 &bmpSrc
, &rcSrc
, &hasAlpha
);
677 if(FAILED(hr
)) return hr
;
678 hdcSrc
= CreateCompatibleDC(hdc
);
680 hr
= HRESULT_FROM_WIN32(GetLastError());
683 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
687 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
688 &transparentcolor
, FALSE
);
690 dstSize
.x
= rcDst
.right
-rcDst
.left
;
691 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
692 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
693 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
695 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
696 if(sizingtype
== ST_TRUESIZE
) {
697 int valign
= VA_CENTER
, halign
= HA_CENTER
;
699 get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, pRect
, TS_DRAW
, &drawSize
);
700 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
701 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
703 if (halign
== HA_CENTER
)
704 rcDst
.left
+= (dstSize
.x
/2)-(drawSize
.x
/2);
705 else if (halign
== HA_RIGHT
)
706 rcDst
.left
= rcDst
.right
- drawSize
.x
;
707 if (valign
== VA_CENTER
)
708 rcDst
.top
+= (dstSize
.y
/2)-(drawSize
.y
/2);
709 else if (valign
== VA_BOTTOM
)
710 rcDst
.top
= rcDst
.bottom
- drawSize
.y
;
711 rcDst
.right
= rcDst
.left
+ drawSize
.x
;
712 rcDst
.bottom
= rcDst
.top
+ drawSize
.y
;
713 if(!UXTHEME_StretchBlt(hdc
, rcDst
.left
, rcDst
.top
, drawSize
.x
, drawSize
.y
,
714 hdcSrc
, rcSrc
.left
, rcSrc
.top
, srcSize
.x
, srcSize
.y
,
715 transparent
, transparentcolor
))
716 hr
= HRESULT_FROM_WIN32(GetLastError());
723 dstSize
.x
= abs(dstSize
.x
);
724 dstSize
.y
= abs(dstSize
.y
);
726 GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_SIZINGMARGINS
, NULL
, &sm
);
728 /* Resize source image if destination smaller than margins */
729 if (sm
.cyTopHeight
+ sm
.cyBottomHeight
> dstSize
.y
|| sm
.cxLeftWidth
+ sm
.cxRightWidth
> dstSize
.x
) {
730 if (sm
.cyTopHeight
+ sm
.cyBottomHeight
> dstSize
.y
) {
731 sm
.cyTopHeight
= MulDiv(sm
.cyTopHeight
, dstSize
.y
, srcSize
.y
);
732 sm
.cyBottomHeight
= dstSize
.y
- sm
.cyTopHeight
;
733 srcSize
.y
= dstSize
.y
;
736 if (sm
.cxLeftWidth
+ sm
.cxRightWidth
> dstSize
.x
) {
737 sm
.cxLeftWidth
= MulDiv(sm
.cxLeftWidth
, dstSize
.x
, srcSize
.x
);
738 sm
.cxRightWidth
= dstSize
.x
- sm
.cxLeftWidth
;
739 srcSize
.x
= dstSize
.x
;
743 hdcSrc
= CreateCompatibleDC(NULL
);
744 bmpSrcResized
= CreateBitmap(srcSize
.x
, srcSize
.y
, 1, 32, NULL
);
745 SelectObject(hdcSrc
, bmpSrcResized
);
747 UXTHEME_StretchBlt(hdcSrc
, 0, 0, srcSize
.x
, srcSize
.y
, hdcOrigSrc
, rcSrc
.left
, rcSrc
.top
,
748 rcSrc
.right
- rcSrc
.left
, rcSrc
.bottom
- rcSrc
.top
, transparent
, transparentcolor
);
752 rcSrc
.right
= srcSize
.x
;
753 rcSrc
.bottom
= srcSize
.y
;
757 OffsetViewportOrgEx(hdcDst
, rcDst
.left
, rcDst
.top
, &org
);
759 /* Upper left corner */
760 if(!UXTHEME_Blt(hdcDst
, 0, 0, sm
.cxLeftWidth
, sm
.cyTopHeight
,
761 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
762 transparent
, transparentcolor
)) {
763 hr
= HRESULT_FROM_WIN32(GetLastError());
766 /* Upper right corner */
767 if(!UXTHEME_Blt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, 0,
768 sm
.cxRightWidth
, sm
.cyTopHeight
,
769 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
,
770 transparent
, transparentcolor
)) {
771 hr
= HRESULT_FROM_WIN32(GetLastError());
774 /* Lower left corner */
775 if(!UXTHEME_Blt (hdcDst
, 0, dstSize
.y
-sm
.cyBottomHeight
,
776 sm
.cxLeftWidth
, sm
.cyBottomHeight
,
777 hdcSrc
, rcSrc
.left
, rcSrc
.bottom
-sm
.cyBottomHeight
,
778 transparent
, transparentcolor
)) {
779 hr
= HRESULT_FROM_WIN32(GetLastError());
782 /* Lower right corner */
783 if(!UXTHEME_Blt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, dstSize
.y
-sm
.cyBottomHeight
,
784 sm
.cxRightWidth
, sm
.cyBottomHeight
,
785 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
,
786 transparent
, transparentcolor
)) {
787 hr
= HRESULT_FROM_WIN32(GetLastError());
791 if ((sizingtype
== ST_STRETCH
) || (sizingtype
== ST_TILE
)) {
792 int destCenterWidth
= dstSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
793 int srcCenterWidth
= srcSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
794 int destCenterHeight
= dstSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
795 int srcCenterHeight
= srcSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
797 if(destCenterWidth
> 0) {
799 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, 0,
800 destCenterWidth
, sm
.cyTopHeight
,
801 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
,
802 srcCenterWidth
, sm
.cyTopHeight
,
803 sizingtype
, transparent
, transparentcolor
)) {
804 hr
= HRESULT_FROM_WIN32(GetLastError());
808 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, dstSize
.y
-sm
.cyBottomHeight
,
809 destCenterWidth
, sm
.cyBottomHeight
,
810 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
,
811 srcCenterWidth
, sm
.cyBottomHeight
,
812 sizingtype
, transparent
, transparentcolor
)) {
813 hr
= HRESULT_FROM_WIN32(GetLastError());
817 if(destCenterHeight
> 0) {
819 if(!UXTHEME_SizedBlt (hdcDst
, 0, sm
.cyTopHeight
,
820 sm
.cxLeftWidth
, destCenterHeight
,
821 hdcSrc
, rcSrc
.left
, rcSrc
.top
+sm
.cyTopHeight
,
822 sm
.cxLeftWidth
, srcCenterHeight
,
824 transparent
, transparentcolor
)) {
825 hr
= HRESULT_FROM_WIN32(GetLastError());
829 if(!UXTHEME_SizedBlt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, sm
.cyTopHeight
,
830 sm
.cxRightWidth
, destCenterHeight
,
831 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
+sm
.cyTopHeight
,
832 sm
.cxRightWidth
, srcCenterHeight
,
833 sizingtype
, transparent
, transparentcolor
)) {
834 hr
= HRESULT_FROM_WIN32(GetLastError());
838 if(destCenterHeight
> 0 && destCenterWidth
> 0) {
839 BOOL borderonly
= FALSE
;
840 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_BORDERONLY
, &borderonly
);
843 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, sm
.cyTopHeight
,
844 destCenterWidth
, destCenterHeight
,
845 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
+sm
.cyTopHeight
,
846 srcCenterWidth
, srcCenterHeight
,
847 sizingtype
, transparent
, transparentcolor
)) {
848 hr
= HRESULT_FROM_WIN32(GetLastError());
856 SetViewportOrgEx (hdcDst
, org
.x
, org
.y
, NULL
);
858 SelectObject(hdcSrc
, oldSrc
);
860 if (bmpSrcResized
) DeleteObject(bmpSrcResized
);
861 if (hdcOrigSrc
) DeleteDC(hdcOrigSrc
);
866 /***********************************************************************
867 * UXTHEME_DrawBorderRectangle
869 * Draw the bounding rectangle for a borderfill background
871 static HRESULT
UXTHEME_DrawBorderRectangle(HTHEME hTheme
, HDC hdc
, int iPartId
,
872 int iStateId
, RECT
*pRect
,
873 const DTBGOPTS
*pOptions
)
878 COLORREF bordercolor
= RGB(0,0,0);
881 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
884 ptCorners
[0].x
= pRect
->left
;
885 ptCorners
[0].y
= pRect
->top
;
886 ptCorners
[1].x
= pRect
->right
-1;
887 ptCorners
[1].y
= pRect
->top
;
888 ptCorners
[2].x
= pRect
->right
-1;
889 ptCorners
[2].y
= pRect
->bottom
-1;
890 ptCorners
[3].x
= pRect
->left
;
891 ptCorners
[3].y
= pRect
->bottom
-1;
892 ptCorners
[4].x
= pRect
->left
;
893 ptCorners
[4].y
= pRect
->top
;
895 InflateRect(pRect
, -bordersize
, -bordersize
);
896 if(pOptions
->dwFlags
& DTBG_OMITBORDER
)
898 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_BORDERCOLOR
, &bordercolor
);
899 hPen
= CreatePen(PS_SOLID
, bordersize
, bordercolor
);
901 return HRESULT_FROM_WIN32(GetLastError());
902 oldPen
= SelectObject(hdc
, hPen
);
904 if(!Polyline(hdc
, ptCorners
, 5))
905 hr
= HRESULT_FROM_WIN32(GetLastError());
907 SelectObject(hdc
, oldPen
);
913 /***********************************************************************
914 * UXTHEME_DrawBackgroundFill
916 * Fill a borderfill background rectangle
918 static HRESULT
UXTHEME_DrawBackgroundFill(HTHEME hTheme
, HDC hdc
, int iPartId
,
919 int iStateId
, RECT
*pRect
,
920 const DTBGOPTS
*pOptions
)
923 int filltype
= FT_SOLID
;
925 TRACE("(%d,%d,%d)\n", iPartId
, iStateId
, pOptions
->dwFlags
);
927 if(pOptions
->dwFlags
& DTBG_OMITCONTENT
)
930 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_FILLTYPE
, &filltype
);
932 if(filltype
== FT_SOLID
) {
934 COLORREF fillcolor
= RGB(255,255,255);
936 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_FILLCOLOR
, &fillcolor
);
937 hBrush
= CreateSolidBrush(fillcolor
);
938 if(!FillRect(hdc
, pRect
, hBrush
))
939 hr
= HRESULT_FROM_WIN32(GetLastError());
940 DeleteObject(hBrush
);
942 else if(filltype
== FT_VERTGRADIENT
|| filltype
== FT_HORZGRADIENT
) {
943 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
944 the gradient ratios (no idea how those work)
945 Few themes use this, and the ones I've seen only use 2 colors with
946 a gradient ratio of 0 and 255 respectively
949 COLORREF gradient1
= RGB(0,0,0);
950 COLORREF gradient2
= RGB(255,255,255);
954 FIXME("Gradient implementation not complete\n");
956 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR1
, &gradient1
);
957 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR2
, &gradient2
);
959 vert
[0].x
= pRect
->left
;
960 vert
[0].y
= pRect
->top
;
961 vert
[0].Red
= GetRValue(gradient1
) << 8;
962 vert
[0].Green
= GetGValue(gradient1
) << 8;
963 vert
[0].Blue
= GetBValue(gradient1
) << 8;
964 vert
[0].Alpha
= 0xff00;
966 vert
[1].x
= pRect
->right
;
967 vert
[1].y
= pRect
->bottom
;
968 vert
[1].Red
= GetRValue(gradient2
) << 8;
969 vert
[1].Green
= GetGValue(gradient2
) << 8;
970 vert
[1].Blue
= GetBValue(gradient2
) << 8;
971 vert
[1].Alpha
= 0xff00;
974 gRect
.LowerRight
= 1;
975 GradientFill(hdc
,vert
,2,&gRect
,1,filltype
==FT_HORZGRADIENT
?GRADIENT_FILL_RECT_H
:GRADIENT_FILL_RECT_V
);
977 else if(filltype
== FT_RADIALGRADIENT
) {
978 /* I've never seen this used in a theme */
979 FIXME("Radial gradient\n");
981 else if(filltype
== FT_TILEIMAGE
) {
982 /* I've never seen this used in a theme */
983 FIXME("Tile image\n");
988 /***********************************************************************
989 * UXTHEME_DrawBorderBackground
991 * Draw an imagefile background
993 static HRESULT
UXTHEME_DrawBorderBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
994 int iStateId
, const RECT
*pRect
,
995 const DTBGOPTS
*pOptions
)
1002 hr
= UXTHEME_DrawBorderRectangle(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
1005 return UXTHEME_DrawBackgroundFill(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
1008 /***********************************************************************
1009 * DrawThemeBackgroundEx (UXTHEME.@)
1011 HRESULT WINAPI
DrawThemeBackgroundEx(HTHEME hTheme
, HDC hdc
, int iPartId
,
1012 int iStateId
, const RECT
*pRect
,
1013 const DTBGOPTS
*pOptions
)
1016 const DTBGOPTS defaultOpts
= {sizeof(DTBGOPTS
), 0, {0,0,0,0}};
1017 const DTBGOPTS
*opts
;
1020 int bgtype
= BT_BORDERFILL
;
1023 TRACE("(%p,%p,%d,%d,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
,pRect
->left
,pRect
->top
);
1027 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1028 if (bgtype
== BT_NONE
) return S_OK
;
1030 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
1032 if(!opts
) opts
= &defaultOpts
;
1034 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
1035 clip
= CreateRectRgn(0,0,1,1);
1036 hasClip
= GetClipRgn(hdc
, clip
);
1038 TRACE("Failed to get original clipping region\n");
1040 IntersectClipRect(hdc
, opts
->rcClip
.left
, opts
->rcClip
.top
, opts
->rcClip
.right
, opts
->rcClip
.bottom
);
1044 if(bgtype
== BT_IMAGEFILE
)
1045 hr
= UXTHEME_DrawImageBackground(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
1046 else if(bgtype
== BT_BORDERFILL
)
1047 hr
= UXTHEME_DrawBorderBackground(hTheme
, hdc
, iPartId
, iStateId
, pRect
, opts
);
1049 FIXME("Unknown background type\n");
1050 /* This should never happen, and hence I don't know what to return */
1054 hr
= UXTHEME_DrawGlyph(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
1055 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
1057 SelectClipRgn(hdc
, NULL
);
1058 else if(hasClip
== 1)
1059 SelectClipRgn(hdc
, clip
);
1066 * DrawThemeEdge() implementation
1068 * Since it basically is DrawEdge() with different colors, I copied its code
1069 * from user32's uitools.c.
1090 } EdgeColorMap
[EDGE_NUMCOLORS
] = {
1091 {TMT_EDGELIGHTCOLOR
, COLOR_3DLIGHT
},
1092 {TMT_EDGEHIGHLIGHTCOLOR
, COLOR_BTNHIGHLIGHT
},
1093 {TMT_EDGESHADOWCOLOR
, COLOR_BTNSHADOW
},
1094 {TMT_EDGEDKSHADOWCOLOR
, COLOR_3DDKSHADOW
},
1095 {TMT_EDGEFILLCOLOR
, COLOR_BTNFACE
},
1097 {-1, COLOR_WINDOWFRAME
}
1100 static const signed char LTInnerNormal
[] = {
1102 -1, EDGE_HIGHLIGHT
, EDGE_HIGHLIGHT
, -1,
1103 -1, EDGE_DARKSHADOW
, EDGE_DARKSHADOW
, -1,
1107 static const signed char LTOuterNormal
[] = {
1108 -1, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1109 EDGE_HIGHLIGHT
, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1110 EDGE_DARKSHADOW
, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1111 -1, EDGE_LIGHT
, EDGE_SHADOW
, -1
1114 static const signed char RBInnerNormal
[] = {
1116 -1, EDGE_SHADOW
, EDGE_SHADOW
, -1,
1117 -1, EDGE_LIGHT
, EDGE_LIGHT
, -1,
1121 static const signed char RBOuterNormal
[] = {
1122 -1, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1123 EDGE_SHADOW
, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1124 EDGE_LIGHT
, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1125 -1, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1
1128 static const signed char LTInnerSoft
[] = {
1130 -1, EDGE_LIGHT
, EDGE_LIGHT
, -1,
1131 -1, EDGE_SHADOW
, EDGE_SHADOW
, -1,
1135 static const signed char LTOuterSoft
[] = {
1136 -1, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1137 EDGE_LIGHT
, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1138 EDGE_SHADOW
, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1139 -1, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1
1142 #define RBInnerSoft RBInnerNormal /* These are the same */
1143 #define RBOuterSoft RBOuterNormal
1145 static const signed char LTRBOuterMono
[] = {
1146 -1, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1147 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1148 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1149 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1152 static const signed char LTRBInnerMono
[] = {
1154 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1155 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1156 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1159 static const signed char LTRBOuterFlat
[] = {
1160 -1, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1161 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1162 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1163 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1166 static const signed char LTRBInnerFlat
[] = {
1168 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1169 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1170 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1173 static COLORREF
get_edge_color (int edgeType
, HTHEME theme
, int part
, int state
)
1176 if ((EdgeColorMap
[edgeType
].themeProp
== -1)
1177 || FAILED (GetThemeColor (theme
, part
, state
,
1178 EdgeColorMap
[edgeType
].themeProp
, &col
)))
1179 col
= GetSysColor (EdgeColorMap
[edgeType
].sysColor
);
1183 static inline HPEN
get_edge_pen (int edgeType
, HTHEME theme
, int part
, int state
)
1185 return CreatePen (PS_SOLID
, 1, get_edge_color (edgeType
, theme
, part
, state
));
1188 static inline HBRUSH
get_edge_brush (int edgeType
, HTHEME theme
, int part
, int state
)
1190 return CreateSolidBrush (get_edge_color (edgeType
, theme
, part
, state
));
1193 /***********************************************************************
1196 * Same as DrawEdge invoked with BF_DIAGONAL
1198 static HRESULT
draw_diag_edge (HDC hdc
, HTHEME theme
, int part
, int state
,
1199 const RECT
* rc
, UINT uType
,
1200 UINT uFlags
, LPRECT contentsRect
)
1203 signed char InnerI
, OuterI
;
1204 HPEN InnerPen
, OuterPen
;
1209 int Width
= rc
->right
- rc
->left
;
1210 int Height
= rc
->bottom
- rc
->top
;
1211 int SmallDiam
= Width
> Height
? Height
: Width
;
1212 HRESULT retval
= (((uType
& BDR_INNER
) == BDR_INNER
1213 || (uType
& BDR_OUTER
) == BDR_OUTER
)
1214 && !(uFlags
& (BF_FLAT
|BF_MONO
)) ) ? E_FAIL
: S_OK
;
1215 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
1216 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
1218 /* Init some vars */
1219 OuterPen
= InnerPen
= GetStockObject(NULL_PEN
);
1220 SavePen
= SelectObject(hdc
, InnerPen
);
1221 spx
= spy
= epx
= epy
= 0; /* Satisfy the compiler... */
1223 /* Determine the colors of the edges */
1224 if(uFlags
& BF_MONO
)
1226 InnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1227 OuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1229 else if(uFlags
& BF_FLAT
)
1231 InnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1232 OuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1234 else if(uFlags
& BF_SOFT
)
1236 if(uFlags
& BF_BOTTOM
)
1238 InnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1239 OuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1243 InnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1244 OuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1249 if(uFlags
& BF_BOTTOM
)
1251 InnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1252 OuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1256 InnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1257 OuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1261 if(InnerI
!= -1) InnerPen
= get_edge_pen (InnerI
, theme
, part
, state
);
1262 if(OuterI
!= -1) OuterPen
= get_edge_pen (OuterI
, theme
, part
, state
);
1264 MoveToEx(hdc
, 0, 0, &SavePoint
);
1266 /* Don't ask me why, but this is what is visible... */
1267 /* This must be possible to do much simpler, but I fail to */
1268 /* see the logic in the MS implementation (sigh...). */
1269 /* So, this might look a bit brute force here (and it is), but */
1270 /* it gets the job done;) */
1272 switch(uFlags
& BF_RECT
)
1278 /* Left bottom endpoint */
1280 spx
= epx
+ SmallDiam
;
1282 spy
= epy
- SmallDiam
;
1286 case BF_BOTTOMRIGHT
:
1287 /* Left top endpoint */
1289 spx
= epx
+ SmallDiam
;
1291 spy
= epy
+ SmallDiam
;
1297 case BF_RIGHT
|BF_LEFT
:
1298 case BF_RIGHT
|BF_LEFT
|BF_TOP
:
1299 case BF_BOTTOM
|BF_TOP
:
1300 case BF_BOTTOM
|BF_TOP
|BF_LEFT
:
1301 case BF_BOTTOMRIGHT
|BF_LEFT
:
1302 case BF_BOTTOMRIGHT
|BF_TOP
:
1304 /* Right top endpoint */
1306 epx
= spx
+ SmallDiam
;
1308 epy
= spy
- SmallDiam
;
1312 MoveToEx(hdc
, spx
, spy
, NULL
);
1313 SelectObject(hdc
, OuterPen
);
1314 LineTo(hdc
, epx
, epy
);
1316 SelectObject(hdc
, InnerPen
);
1318 switch(uFlags
& (BF_RECT
|BF_DIAGONAL
))
1320 case BF_DIAGONAL_ENDBOTTOMLEFT
:
1321 case (BF_DIAGONAL
|BF_BOTTOM
):
1323 case (BF_DIAGONAL
|BF_LEFT
):
1324 MoveToEx(hdc
, spx
-1, spy
, NULL
);
1325 LineTo(hdc
, epx
, epy
-1);
1326 Points
[0].x
= spx
-add
;
1328 Points
[1].x
= rc
->left
;
1329 Points
[1].y
= rc
->top
;
1330 Points
[2].x
= epx
+1;
1331 Points
[2].y
= epy
-1-add
;
1332 Points
[3] = Points
[2];
1335 case BF_DIAGONAL_ENDBOTTOMRIGHT
:
1336 MoveToEx(hdc
, spx
-1, spy
, NULL
);
1337 LineTo(hdc
, epx
, epy
+1);
1338 Points
[0].x
= spx
-add
;
1340 Points
[1].x
= rc
->left
;
1341 Points
[1].y
= rc
->bottom
-1;
1342 Points
[2].x
= epx
+1;
1343 Points
[2].y
= epy
+1+add
;
1344 Points
[3] = Points
[2];
1347 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
):
1348 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
1349 case BF_DIAGONAL_ENDTOPRIGHT
:
1350 case (BF_DIAGONAL
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
1351 MoveToEx(hdc
, spx
+1, spy
, NULL
);
1352 LineTo(hdc
, epx
, epy
+1);
1353 Points
[0].x
= epx
-1;
1354 Points
[0].y
= epy
+1+add
;
1355 Points
[1].x
= rc
->right
-1;
1356 Points
[1].y
= rc
->top
+add
;
1357 Points
[2].x
= rc
->right
-1;
1358 Points
[2].y
= rc
->bottom
-1;
1359 Points
[3].x
= spx
+add
;
1363 case BF_DIAGONAL_ENDTOPLEFT
:
1364 MoveToEx(hdc
, spx
, spy
-1, NULL
);
1365 LineTo(hdc
, epx
+1, epy
);
1366 Points
[0].x
= epx
+1+add
;
1367 Points
[0].y
= epy
+1;
1368 Points
[1].x
= rc
->right
-1;
1369 Points
[1].y
= rc
->top
;
1370 Points
[2].x
= rc
->right
-1;
1371 Points
[2].y
= rc
->bottom
-1-add
;
1373 Points
[3].y
= spy
-add
;
1376 case (BF_DIAGONAL
|BF_TOP
):
1377 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
):
1378 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
|BF_LEFT
):
1379 MoveToEx(hdc
, spx
+1, spy
-1, NULL
);
1380 LineTo(hdc
, epx
, epy
);
1381 Points
[0].x
= epx
-1;
1382 Points
[0].y
= epy
+1;
1383 Points
[1].x
= rc
->right
-1;
1384 Points
[1].y
= rc
->top
;
1385 Points
[2].x
= rc
->right
-1;
1386 Points
[2].y
= rc
->bottom
-1-add
;
1387 Points
[3].x
= spx
+add
;
1388 Points
[3].y
= spy
-add
;
1391 case (BF_DIAGONAL
|BF_RIGHT
):
1392 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
):
1393 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
|BF_BOTTOM
):
1394 MoveToEx(hdc
, spx
, spy
, NULL
);
1395 LineTo(hdc
, epx
-1, epy
+1);
1398 Points
[1].x
= rc
->left
;
1399 Points
[1].y
= rc
->top
+add
;
1400 Points
[2].x
= epx
-1-add
;
1401 Points
[2].y
= epy
+1+add
;
1402 Points
[3] = Points
[2];
1406 /* Fill the interior if asked */
1407 if((uFlags
& BF_MIDDLE
) && retval
)
1410 HBRUSH hb
= get_edge_brush ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1411 theme
, part
, state
);
1413 HPEN hp
= get_edge_pen ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1414 theme
, part
, state
);
1415 hbsave
= SelectObject(hdc
, hb
);
1416 hpsave
= SelectObject(hdc
, hp
);
1417 Polygon(hdc
, Points
, 4);
1418 SelectObject(hdc
, hbsave
);
1419 SelectObject(hdc
, hpsave
);
1424 /* Adjust rectangle if asked */
1425 if(uFlags
& BF_ADJUST
)
1427 *contentsRect
= *rc
;
1428 if(uFlags
& BF_LEFT
) contentsRect
->left
+= add
;
1429 if(uFlags
& BF_RIGHT
) contentsRect
->right
-= add
;
1430 if(uFlags
& BF_TOP
) contentsRect
->top
+= add
;
1431 if(uFlags
& BF_BOTTOM
) contentsRect
->bottom
-= add
;
1435 SelectObject(hdc
, SavePen
);
1436 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
1437 if(InnerI
!= -1) DeleteObject (InnerPen
);
1438 if(OuterI
!= -1) DeleteObject (OuterPen
);
1443 /***********************************************************************
1446 * Same as DrawEdge invoked without BF_DIAGONAL
1448 static HRESULT
draw_rect_edge (HDC hdc
, HTHEME theme
, int part
, int state
,
1449 const RECT
* rc
, UINT uType
,
1450 UINT uFlags
, LPRECT contentsRect
)
1452 signed char LTInnerI
, LTOuterI
;
1453 signed char RBInnerI
, RBOuterI
;
1454 HPEN LTInnerPen
, LTOuterPen
;
1455 HPEN RBInnerPen
, RBOuterPen
;
1456 RECT InnerRect
= *rc
;
1463 HRESULT retval
= (((uType
& BDR_INNER
) == BDR_INNER
1464 || (uType
& BDR_OUTER
) == BDR_OUTER
)
1465 && !(uFlags
& (BF_FLAT
|BF_MONO
)) ) ? E_FAIL
: S_OK
;
1467 /* Init some vars */
1468 LTInnerPen
= LTOuterPen
= RBInnerPen
= RBOuterPen
= GetStockObject(NULL_PEN
);
1469 SavePen
= SelectObject(hdc
, LTInnerPen
);
1471 /* Determine the colors of the edges */
1472 if(uFlags
& BF_MONO
)
1474 LTInnerI
= RBInnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1475 LTOuterI
= RBOuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1477 else if(uFlags
& BF_FLAT
)
1479 LTInnerI
= RBInnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1480 LTOuterI
= RBOuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1482 if( LTInnerI
!= -1 ) LTInnerI
= RBInnerI
= EDGE_FILL
;
1484 else if(uFlags
& BF_SOFT
)
1486 LTInnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1487 LTOuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1488 RBInnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1489 RBOuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1493 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1494 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1495 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1496 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1499 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
) LBpenplus
= 1;
1500 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
) RTpenplus
= 1;
1501 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
) RBpenplus
= 1;
1502 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
) LTpenplus
= 1;
1504 if(LTInnerI
!= -1) LTInnerPen
= get_edge_pen (LTInnerI
, theme
, part
, state
);
1505 if(LTOuterI
!= -1) LTOuterPen
= get_edge_pen (LTOuterI
, theme
, part
, state
);
1506 if(RBInnerI
!= -1) RBInnerPen
= get_edge_pen (RBInnerI
, theme
, part
, state
);
1507 if(RBOuterI
!= -1) RBOuterPen
= get_edge_pen (RBOuterI
, theme
, part
, state
);
1509 MoveToEx(hdc
, 0, 0, &SavePoint
);
1511 /* Draw the outer edge */
1512 SelectObject(hdc
, LTOuterPen
);
1515 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
1516 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
1518 if(uFlags
& BF_LEFT
)
1520 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
1521 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
1523 SelectObject(hdc
, RBOuterPen
);
1524 if(uFlags
& BF_BOTTOM
)
1526 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.bottom
-1, NULL
);
1527 LineTo(hdc
, InnerRect
.left
-1, InnerRect
.bottom
-1);
1529 if(uFlags
& BF_RIGHT
)
1531 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.bottom
-1, NULL
);
1532 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.top
-1);
1535 /* Draw the inner edge */
1536 SelectObject(hdc
, LTInnerPen
);
1539 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
1540 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
1542 if(uFlags
& BF_LEFT
)
1544 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
1545 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
1547 SelectObject(hdc
, RBInnerPen
);
1548 if(uFlags
& BF_BOTTOM
)
1550 MoveToEx(hdc
, InnerRect
.right
-1-RBpenplus
, InnerRect
.bottom
-2, NULL
);
1551 LineTo(hdc
, InnerRect
.left
-1+LBpenplus
, InnerRect
.bottom
-2);
1553 if(uFlags
& BF_RIGHT
)
1555 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-1-RBpenplus
, NULL
);
1556 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.top
-1+RTpenplus
);
1559 if( ((uFlags
& BF_MIDDLE
) && retval
) || (uFlags
& BF_ADJUST
) )
1561 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
1562 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
1564 if(uFlags
& BF_LEFT
) InnerRect
.left
+= add
;
1565 if(uFlags
& BF_RIGHT
) InnerRect
.right
-= add
;
1566 if(uFlags
& BF_TOP
) InnerRect
.top
+= add
;
1567 if(uFlags
& BF_BOTTOM
) InnerRect
.bottom
-= add
;
1569 if((uFlags
& BF_MIDDLE
) && retval
)
1571 HBRUSH br
= get_edge_brush ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1572 theme
, part
, state
);
1573 FillRect(hdc
, &InnerRect
, br
);
1577 if(uFlags
& BF_ADJUST
)
1578 *contentsRect
= InnerRect
;
1582 SelectObject(hdc
, SavePen
);
1583 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
1584 if(LTInnerI
!= -1) DeleteObject (LTInnerPen
);
1585 if(LTOuterI
!= -1) DeleteObject (LTOuterPen
);
1586 if(RBInnerI
!= -1) DeleteObject (RBInnerPen
);
1587 if(RBOuterI
!= -1) DeleteObject (RBOuterPen
);
1592 /***********************************************************************
1593 * DrawThemeEdge (UXTHEME.@)
1595 * DrawThemeEdge() is pretty similar to the vanilla DrawEdge() - the
1596 * difference is that it does not rely on the system colors alone, but
1597 * also allows color specification in the theme.
1599 HRESULT WINAPI
DrawThemeEdge(HTHEME hTheme
, HDC hdc
, int iPartId
,
1600 int iStateId
, const RECT
*pDestRect
, UINT uEdge
,
1601 UINT uFlags
, RECT
*pContentRect
)
1603 TRACE("%d %d 0x%08x 0x%08x\n", iPartId
, iStateId
, uEdge
, uFlags
);
1607 if(uFlags
& BF_DIAGONAL
)
1608 return draw_diag_edge (hdc
, hTheme
, iPartId
, iStateId
, pDestRect
,
1609 uEdge
, uFlags
, pContentRect
);
1611 return draw_rect_edge (hdc
, hTheme
, iPartId
, iStateId
, pDestRect
,
1612 uEdge
, uFlags
, pContentRect
);
1616 /***********************************************************************
1617 * DrawThemeIcon (UXTHEME.@)
1619 HRESULT WINAPI
DrawThemeIcon(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1620 const RECT
*pRect
, HIMAGELIST himl
, int iImageIndex
)
1622 FIXME("%d %d: stub\n", iPartId
, iStateId
);
1628 /***********************************************************************
1629 * DrawThemeText (UXTHEME.@)
1631 HRESULT WINAPI
DrawThemeText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1632 LPCWSTR pszText
, int iCharCount
, DWORD flags
,
1633 DWORD flags2
, const RECT
*pRect
)
1635 DTTOPTS opts
= { 0 };
1638 TRACE("%d %d\n", iPartId
, iStateId
);
1642 opts
.dwSize
= sizeof(opts
);
1643 if (flags2
& DTT_GRAYED
) {
1644 opts
.dwFlags
= DTT_TEXTCOLOR
;
1645 opts
.crText
= GetSysColor(COLOR_GRAYTEXT
);
1647 return DrawThemeTextEx(hTheme
, hdc
, iPartId
, iStateId
, pszText
, iCharCount
, flags
, &rt
, &opts
);
1650 /***********************************************************************
1651 * DrawThemeTextEx (UXTHEME.@)
1653 HRESULT WINAPI
DrawThemeTextEx(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1654 LPCWSTR pszText
, int iCharCount
, DWORD flags
, RECT
*rect
, const DTTOPTS
*options
)
1658 HGDIOBJ oldFont
= NULL
;
1661 COLORREF oldTextColor
;
1665 TRACE("%p %p %d %d %s:%d 0x%08x %p %p\n", hTheme
, hdc
, iPartId
, iStateId
,
1666 debugstr_wn(pszText
, iCharCount
), iCharCount
, flags
, rect
, options
);
1671 if (options
->dwFlags
& ~(DTT_TEXTCOLOR
| DTT_FONTPROP
))
1672 FIXME("unsupported flags 0x%08x\n", options
->dwFlags
);
1674 if (options
->dwFlags
& DTT_FONTPROP
)
1675 fontProp
= options
->iFontPropId
;
1677 fontProp
= TMT_FONT
;
1679 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, fontProp
, &logfont
);
1681 hFont
= CreateFontIndirectW(&logfont
);
1683 TRACE("Failed to create font\n");
1687 oldFont
= SelectObject(hdc
, hFont
);
1689 if (options
->dwFlags
& DTT_TEXTCOLOR
)
1690 textColor
= options
->crText
;
1692 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TEXTCOLOR
, &textColor
)))
1693 textColor
= GetTextColor(hdc
);
1695 oldTextColor
= SetTextColor(hdc
, textColor
);
1696 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1697 DrawTextW(hdc
, pszText
, iCharCount
, rect
, flags
);
1698 SetBkMode(hdc
, oldBkMode
);
1699 SetTextColor(hdc
, oldTextColor
);
1702 SelectObject(hdc
, oldFont
);
1703 DeleteObject(hFont
);
1708 /***********************************************************************
1709 * GetThemeBackgroundContentRect (UXTHEME.@)
1711 HRESULT WINAPI
GetThemeBackgroundContentRect(HTHEME hTheme
, HDC hdc
, int iPartId
,
1713 const RECT
*pBoundingRect
,
1719 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1723 /* try content margins property... */
1724 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1726 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
1727 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
1728 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
1729 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
1731 /* otherwise, try to determine content rect from the background type and props */
1732 int bgtype
= BT_BORDERFILL
;
1733 *pContentRect
= *pBoundingRect
;
1735 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1736 if(bgtype
== BT_BORDERFILL
) {
1739 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1740 InflateRect(pContentRect
, -bordersize
, -bordersize
);
1741 } else if ((bgtype
== BT_IMAGEFILE
)
1742 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1743 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1744 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
1745 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
1746 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
1747 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
1749 /* If nothing was found, leave unchanged */
1752 TRACE("%s\n", wine_dbgstr_rect(pContentRect
));
1757 /***********************************************************************
1758 * GetThemeBackgroundExtent (UXTHEME.@)
1760 HRESULT WINAPI
GetThemeBackgroundExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1761 int iStateId
, const RECT
*pContentRect
,
1767 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1771 /* try content margins property... */
1772 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1774 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1775 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1776 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1777 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1779 /* otherwise, try to determine content rect from the background type and props */
1780 int bgtype
= BT_BORDERFILL
;
1781 *pExtentRect
= *pContentRect
;
1783 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1784 if(bgtype
== BT_BORDERFILL
) {
1787 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1788 InflateRect(pExtentRect
, bordersize
, bordersize
);
1789 } else if ((bgtype
== BT_IMAGEFILE
)
1790 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1791 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1792 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1793 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1794 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1795 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1797 /* If nothing was found, leave unchanged */
1800 TRACE("%s\n", wine_dbgstr_rect(pExtentRect
));
1805 static inline void flush_rgn_data( HRGN rgn
, RGNDATA
*data
)
1807 HRGN tmp
= ExtCreateRegion( NULL
, data
->rdh
.dwSize
+ data
->rdh
.nRgnSize
, data
);
1809 CombineRgn( rgn
, rgn
, tmp
, RGN_OR
);
1810 DeleteObject( tmp
);
1811 data
->rdh
.nCount
= 0;
1814 static inline void add_row( HRGN rgn
, RGNDATA
*data
, int x
, int y
, int len
)
1816 RECT
*rect
= (RECT
*)data
->Buffer
+ data
->rdh
.nCount
;
1818 if (len
<= 0) return;
1821 rect
->right
= x
+ len
;
1822 rect
->bottom
= y
+ 1;
1824 if (data
->rdh
.nCount
* sizeof(RECT
) > data
->rdh
.nRgnSize
- sizeof(RECT
))
1825 flush_rgn_data( rgn
, data
);
1828 static HRESULT
create_image_bg_region(HTHEME theme
, int part
, int state
, const RECT
*rect
, HRGN
*rgn
)
1835 COLORREF transcolour
;
1837 unsigned int x
, y
, start
;
1838 BITMAPINFO bitmapinfo
;
1841 RGNDATA
*data
= (RGNDATA
*)buffer
;
1843 if (FAILED(GetThemeBool(theme
, part
, state
, TMT_TRANSPARENT
, &istrans
)) || !istrans
) {
1844 *rgn
= CreateRectRgn(rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
1849 OffsetRect(&r
, -r
.left
, -r
.top
);
1851 if (FAILED(GetThemeColor(theme
, part
, state
, TMT_TRANSPARENTCOLOR
, &transcolour
)))
1852 transcolour
= RGB(255, 0, 255); /* defaults to magenta */
1854 dc
= CreateCompatibleDC(NULL
);
1856 WARN("CreateCompatibleDC failed\n");
1860 bitmapinfo
.bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1861 bitmapinfo
.bmiHeader
.biWidth
= rect
->right
- rect
->left
;
1862 bitmapinfo
.bmiHeader
.biHeight
= -(rect
->bottom
- rect
->top
);
1863 bitmapinfo
.bmiHeader
.biPlanes
= 1;
1864 bitmapinfo
.bmiHeader
.biBitCount
= 32;
1865 bitmapinfo
.bmiHeader
.biCompression
= BI_RGB
;
1866 bitmapinfo
.bmiHeader
.biSizeImage
= bitmapinfo
.bmiHeader
.biWidth
* bitmapinfo
.bmiHeader
.biHeight
* 4;
1867 bitmapinfo
.bmiHeader
.biXPelsPerMeter
= 0;
1868 bitmapinfo
.bmiHeader
.biYPelsPerMeter
= 0;
1869 bitmapinfo
.bmiHeader
.biClrUsed
= 0;
1870 bitmapinfo
.bmiHeader
.biClrImportant
= 0;
1872 bmp
= CreateDIBSection(dc
, &bitmapinfo
, DIB_RGB_COLORS
, (void**)&bits
, NULL
, 0);
1874 WARN("CreateDIBSection failed\n");
1879 SelectObject(dc
, bmp
);
1881 transbrush
= CreateSolidBrush(transcolour
);
1882 FillRect(dc
, &r
, transbrush
);
1883 DeleteObject(transbrush
);
1885 if (FAILED(DrawThemeBackground(theme
, dc
, part
, state
, &r
, NULL
))) {
1886 WARN("DrawThemeBackground failed\n");
1892 data
->rdh
.dwSize
= sizeof(data
->rdh
);
1893 data
->rdh
.iType
= RDH_RECTANGLES
;
1894 data
->rdh
.nCount
= 0;
1895 data
->rdh
.nRgnSize
= sizeof(buffer
) - sizeof(data
->rdh
);
1897 hrgn
= CreateRectRgn(0, 0, 0, 0);
1899 for (y
= 0; y
< r
.bottom
; y
++, bits
+= r
.right
) {
1901 while (x
< r
.right
) {
1902 while (x
< r
.right
&& (bits
[x
] & 0xffffff) == transcolour
) x
++;
1904 while (x
< r
.right
&& !((bits
[x
] & 0xffffff) == transcolour
)) x
++;
1905 add_row( hrgn
, data
, rect
->left
+ start
, rect
->top
+ y
, x
- start
);
1909 if (data
->rdh
.nCount
> 0) flush_rgn_data(hrgn
, data
);
1919 /***********************************************************************
1920 * GetThemeBackgroundRegion (UXTHEME.@)
1922 * Calculate the background region, taking into consideration transparent areas
1923 * of the background image.
1925 HRESULT WINAPI
GetThemeBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
,
1926 int iStateId
, const RECT
*pRect
,
1930 int bgtype
= BT_BORDERFILL
;
1932 TRACE("(%p,%p,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
);
1935 if(!pRect
|| !pRegion
)
1938 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1939 if(bgtype
== BT_IMAGEFILE
) {
1940 hr
= create_image_bg_region(hTheme
, iPartId
, iStateId
, pRect
, pRegion
);
1942 else if(bgtype
== BT_BORDERFILL
) {
1943 *pRegion
= CreateRectRgn(pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
1945 hr
= HRESULT_FROM_WIN32(GetLastError());
1948 FIXME("Unknown background type\n");
1949 /* This should never happen, and hence I don't know what to return */
1955 /* compute part size for "borderfill" backgrounds */
1956 static HRESULT
get_border_background_size (HTHEME hTheme
, int iPartId
,
1957 int iStateId
, THEMESIZE eSize
, POINT
* psz
)
1962 if (SUCCEEDED (hr
= GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
,
1965 psz
->x
= psz
->y
= 2*bordersize
;
1966 if (eSize
!= TS_MIN
)
1975 /***********************************************************************
1976 * GetThemePartSize (UXTHEME.@)
1978 HRESULT WINAPI
GetThemePartSize(HTHEME hTheme
, HDC hdc
, int iPartId
,
1979 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
1982 int bgtype
= BT_BORDERFILL
;
1984 POINT size
= {1, 1};
1989 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1990 if (bgtype
== BT_NONE
)
1992 else if(bgtype
== BT_IMAGEFILE
)
1993 hr
= get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, prc
, eSize
, &size
);
1994 else if(bgtype
== BT_BORDERFILL
)
1995 hr
= get_border_background_size (hTheme
, iPartId
, iStateId
, eSize
, &size
);
1997 FIXME("Unknown background type\n");
1998 /* This should never happen, and hence I don't know what to return */
2007 /***********************************************************************
2008 * GetThemeTextExtent (UXTHEME.@)
2010 HRESULT WINAPI
GetThemeTextExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
2011 int iStateId
, LPCWSTR pszText
, int iCharCount
,
2012 DWORD dwTextFlags
, const RECT
*pBoundingRect
,
2017 HGDIOBJ oldFont
= NULL
;
2019 RECT rt
= {0,0,0xFFFF,0xFFFF};
2021 TRACE("%d %d\n", iPartId
, iStateId
);
2026 rt
= *pBoundingRect
;
2028 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
2030 hFont
= CreateFontIndirectW(&logfont
);
2032 TRACE("Failed to create font\n");
2035 oldFont
= SelectObject(hdc
, hFont
);
2037 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
|DT_CALCRECT
);
2041 SelectObject(hdc
, oldFont
);
2042 DeleteObject(hFont
);
2047 /***********************************************************************
2048 * GetThemeTextMetrics (UXTHEME.@)
2050 HRESULT WINAPI
GetThemeTextMetrics(HTHEME hTheme
, HDC hdc
, int iPartId
,
2051 int iStateId
, TEXTMETRICW
*ptm
)
2055 HGDIOBJ oldFont
= NULL
;
2058 TRACE("(%p, %p, %d, %d)\n", hTheme
, hdc
, iPartId
, iStateId
);
2062 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
2064 hFont
= CreateFontIndirectW(&logfont
);
2066 TRACE("Failed to create font\n");
2069 oldFont
= SelectObject(hdc
, hFont
);
2071 if(!GetTextMetricsW(hdc
, ptm
))
2072 hr
= HRESULT_FROM_WIN32(GetLastError());
2075 SelectObject(hdc
, oldFont
);
2076 DeleteObject(hFont
);
2081 /***********************************************************************
2082 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
2084 BOOL WINAPI
IsThemeBackgroundPartiallyTransparent(HTHEME hTheme
, int iPartId
,
2087 int bgtype
= BT_BORDERFILL
;
2088 RECT rect
= {0, 0, 0, 0};
2093 COLORREF transparentcolor
;
2095 TRACE("(%d,%d)\n", iPartId
, iStateId
);
2100 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
2102 if (bgtype
!= BT_IMAGEFILE
) return FALSE
;
2104 if(FAILED (UXTHEME_LoadImage (hTheme
, 0, iPartId
, iStateId
, &rect
, FALSE
,
2105 &bmpSrc
, &rcSrc
, &hasAlpha
)))
2108 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
2109 &transparentcolor
, FALSE
);
2110 return (transparent
!= ALPHABLEND_NONE
);