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
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
26 /***********************************************************************
27 * Defines and global variables
30 extern ATOM atDialogThemeEnabled
;
32 /***********************************************************************/
34 /***********************************************************************
35 * EnableThemeDialogTexture (UXTHEME.@)
37 HRESULT WINAPI
EnableThemeDialogTexture(HWND hwnd
, DWORD dwFlags
)
39 static const WCHAR szTab
[] = { 'T','a','b',0 };
42 TRACE("(%p,0x%08x\n", hwnd
, dwFlags
);
43 res
= SetPropW (hwnd
, (LPCWSTR
)MAKEINTATOM(atDialogThemeEnabled
),
44 UlongToHandle(dwFlags
|0x80000000));
45 /* 0x80000000 serves as a "flags set" flag */
47 return HRESULT_FROM_WIN32(GetLastError());
48 if (dwFlags
& ETDT_USETABTEXTURE
)
49 return SetWindowTheme (hwnd
, NULL
, szTab
);
51 return SetWindowTheme (hwnd
, NULL
, NULL
);
54 /***********************************************************************
55 * IsThemeDialogTextureEnabled (UXTHEME.@)
57 BOOL WINAPI
IsThemeDialogTextureEnabled(HWND hwnd
)
59 DWORD dwDialogTextureFlags
;
60 TRACE("(%p)\n", hwnd
);
62 dwDialogTextureFlags
= HandleToUlong( GetPropW( hwnd
, (LPCWSTR
)MAKEINTATOM(atDialogThemeEnabled
) ));
63 if (dwDialogTextureFlags
== 0)
64 /* Means EnableThemeDialogTexture wasn't called for this dialog */
67 return (dwDialogTextureFlags
& ETDT_ENABLE
) && !(dwDialogTextureFlags
& ETDT_DISABLE
);
70 /***********************************************************************
71 * DrawThemeParentBackground (UXTHEME.@)
73 HRESULT WINAPI
DrawThemeParentBackground(HWND hwnd
, HDC hdc
, RECT
*prc
)
81 TRACE("(%p,%p,%p)\n", hwnd
, hdc
, prc
);
82 hParent
= GetParent(hwnd
);
87 MapWindowPoints(hwnd
, hParent
, (LPPOINT
)&rt
, 2);
89 clip
= CreateRectRgn(0,0,1,1);
90 hasClip
= GetClipRgn(hdc
, clip
);
92 TRACE("Failed to get original clipping region\n");
94 IntersectClipRect(hdc
, prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
97 GetClientRect(hwnd
, &rt
);
98 MapWindowPoints(hwnd
, hParent
, (LPPOINT
)&rt
, 2);
101 OffsetViewportOrgEx(hdc
, -rt
.left
, -rt
.top
, &org
);
103 SendMessageW(hParent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
104 SendMessageW(hParent
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
106 SetViewportOrgEx(hdc
, org
.x
, org
.y
, NULL
);
109 SelectClipRgn(hdc
, NULL
);
110 else if(hasClip
== 1)
111 SelectClipRgn(hdc
, clip
);
118 /***********************************************************************
119 * DrawThemeBackground (UXTHEME.@)
121 HRESULT WINAPI
DrawThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
122 int iStateId
, const RECT
*pRect
,
123 const RECT
*pClipRect
)
126 opts
.dwSize
= sizeof(DTBGOPTS
);
129 opts
.dwFlags
|= DTBG_CLIPRECT
;
130 CopyRect(&opts
.rcClip
, pClipRect
);
132 return DrawThemeBackgroundEx(hTheme
, hdc
, iPartId
, iStateId
, pRect
, &opts
);
135 /***********************************************************************
136 * UXTHEME_SelectImage
138 * Select the image to use
140 static PTHEME_PROPERTY
UXTHEME_SelectImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
)
143 int imageselecttype
= IST_NONE
;
147 image
= TMT_GLYPHIMAGEFILE
;
149 image
= TMT_IMAGEFILE
;
151 if((tp
=MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, image
)))
153 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGESELECTTYPE
, &imageselecttype
);
155 if(imageselecttype
== IST_DPI
) {
157 int screendpi
= GetDeviceCaps(hdc
, LOGPIXELSX
);
158 for(i
=4; i
>=0; i
--) {
160 if(SUCCEEDED(GetThemeInt(hTheme
, iPartId
, iStateId
, i
+ TMT_MINDPI1
, &reqdpi
))) {
161 if(reqdpi
!= 0 && screendpi
>= reqdpi
) {
162 TRACE("Using %d DPI, image %d\n", reqdpi
, i
+ TMT_IMAGEFILE1
);
163 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
167 /* If an image couldn't be selected, choose the first one */
168 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
170 else if(imageselecttype
== IST_SIZE
) {
171 POINT size
= {pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
};
173 for(i
=4; i
>=0; i
--) {
174 PTHEME_PROPERTY fileProp
=
175 MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
176 if (!fileProp
) continue;
177 if(FAILED(GetThemePosition(hTheme
, iPartId
, iStateId
, i
+ TMT_MINSIZE1
, &reqsize
))) {
178 /* fall back to size of Nth image */
179 WCHAR szPath
[MAX_PATH
];
180 int imagelayout
= IL_HORIZONTAL
;
186 lstrcpynW(szPath
, fileProp
->lpValue
,
187 min(fileProp
->dwValueLen
+1, sizeof(szPath
)/sizeof(szPath
[0])));
188 hBmp
= MSSTYLES_LoadBitmap(hTheme
, szPath
, &hasAlpha
);
191 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
192 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
194 GetObjectW(hBmp
, sizeof(bmp
), &bmp
);
195 if(imagelayout
== IL_VERTICAL
) {
196 reqsize
.x
= bmp
.bmWidth
;
197 reqsize
.y
= bmp
.bmHeight
/imagecount
;
200 reqsize
.x
= bmp
.bmWidth
/imagecount
;
201 reqsize
.y
= bmp
.bmHeight
;
204 if(reqsize
.x
<= size
.x
&& reqsize
.y
<= size
.y
) {
205 TRACE("Using image size %dx%d, image %d\n", reqsize
.x
, reqsize
.y
, i
+ TMT_IMAGEFILE1
);
209 /* If an image couldn't be selected, choose the smallest one */
210 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
215 /***********************************************************************
218 * Load image for part/state
220 static HRESULT
UXTHEME_LoadImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
,
221 HBITMAP
*hBmp
, RECT
*bmpRect
, BOOL
* hasImageAlpha
)
223 int imagelayout
= IL_HORIZONTAL
;
227 WCHAR szPath
[MAX_PATH
];
228 PTHEME_PROPERTY tp
= UXTHEME_SelectImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, glyph
);
230 FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId
, iStateId
);
231 return E_PROP_ID_UNSUPPORTED
;
233 lstrcpynW(szPath
, tp
->lpValue
, min(tp
->dwValueLen
+1, sizeof(szPath
)/sizeof(szPath
[0])));
234 *hBmp
= MSSTYLES_LoadBitmap(hTheme
, szPath
, hasImageAlpha
);
236 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath
));
237 return HRESULT_FROM_WIN32(GetLastError());
240 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
241 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
243 imagenum
= max (min (imagecount
, iStateId
), 1) - 1;
244 GetObjectW(*hBmp
, sizeof(bmp
), &bmp
);
245 if(imagelayout
== IL_VERTICAL
) {
246 int height
= bmp
.bmHeight
/imagecount
;
248 bmpRect
->right
= bmp
.bmWidth
;
249 bmpRect
->top
= imagenum
* height
;
250 bmpRect
->bottom
= bmpRect
->top
+ height
;
253 int width
= bmp
.bmWidth
/imagecount
;
254 bmpRect
->left
= imagenum
* width
;
255 bmpRect
->right
= bmpRect
->left
+ width
;
257 bmpRect
->bottom
= bmp
.bmHeight
;
262 /***********************************************************************
265 * Pseudo TransparentBlt/StretchBlt
267 static inline BOOL
UXTHEME_StretchBlt(HDC hdcDst
, int nXOriginDst
, int nYOriginDst
, int nWidthDst
, int nHeightDst
,
268 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
269 INT transparent
, COLORREF transcolor
)
271 static const BLENDFUNCTION blendFunc
=
273 AC_SRC_OVER
, /* BlendOp */
275 255, /* SourceConstantAlpha */
276 AC_SRC_ALPHA
/* AlphaFormat */
278 if (transparent
== ALPHABLEND_BINARY
) {
279 /* Ensure we don't pass any negative values to TransparentBlt */
280 return TransparentBlt(hdcDst
, nXOriginDst
, nYOriginDst
, abs(nWidthDst
), abs(nHeightDst
),
281 hdcSrc
, nXOriginSrc
, nYOriginSrc
, abs(nWidthSrc
), abs(nHeightSrc
),
284 if ((transparent
== ALPHABLEND_NONE
) ||
285 !AlphaBlend(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
286 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
289 return StretchBlt(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
290 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
296 /***********************************************************************
299 * Simplify sending same width/height for both source and dest
301 static inline BOOL
UXTHEME_Blt(HDC hdcDest
, int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
302 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
303 INT transparent
, COLORREF transcolor
)
305 return UXTHEME_StretchBlt(hdcDest
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
306 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthDest
, nHeightDest
,
307 transparent
, transcolor
);
310 /***********************************************************************
313 * Stretches or tiles, depending on sizingtype.
315 static inline BOOL
UXTHEME_SizedBlt (HDC hdcDst
, int nXOriginDst
, int nYOriginDst
,
316 int nWidthDst
, int nHeightDst
,
317 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
318 int nWidthSrc
, int nHeightSrc
,
320 INT transparent
, COLORREF transcolor
)
322 if (sizingtype
== ST_TILE
)
327 if (!nWidthSrc
|| !nHeightSrc
) return TRUE
;
329 /* For destination width/height less than or equal to source
330 width/height, do not bother with memory bitmap optimization */
331 if (nWidthSrc
>= nWidthDst
&& nHeightSrc
>= nHeightDst
)
333 int bltWidth
= min (nWidthDst
, nWidthSrc
);
334 int bltHeight
= min (nHeightDst
, nHeightSrc
);
336 return UXTHEME_Blt (hdcDst
, nXOriginDst
, nYOriginDst
, bltWidth
, bltHeight
,
337 hdcSrc
, nXOriginSrc
, nYOriginSrc
,
338 transparent
, transcolor
);
341 /* Create a DC with a bitmap consisting of a tiling of the source
342 bitmap, with standard GDI functions. This is faster than an
343 iteration with UXTHEME_Blt(). */
344 hdcTemp
= CreateCompatibleDC(hdcSrc
);
349 int nWidthTemp
, nHeightTemp
;
350 int xOfs
, xRemaining
;
351 int yOfs
, yRemaining
;
354 /* Calculate temp dimensions of integer multiples of source dimensions */
355 nWidthTemp
= ((nWidthDst
+ nWidthSrc
- 1) / nWidthSrc
) * nWidthSrc
;
356 nHeightTemp
= ((nHeightDst
+ nHeightSrc
- 1) / nHeightSrc
) * nHeightSrc
;
357 bitmapTemp
= CreateCompatibleBitmap(hdcSrc
, nWidthTemp
, nHeightTemp
);
358 bitmapOrig
= SelectObject(hdcTemp
, bitmapTemp
);
360 /* Initial copy of bitmap */
361 BitBlt(hdcTemp
, 0, 0, nWidthSrc
, nHeightSrc
, hdcSrc
, nXOriginSrc
, nYOriginSrc
, SRCCOPY
);
363 /* Extend bitmap in the X direction. Growth of width is exponential */
365 xRemaining
= nWidthTemp
- nWidthSrc
;
366 growSize
= nWidthSrc
;
367 while (xRemaining
> 0)
369 growSize
= min(growSize
, xRemaining
);
370 BitBlt(hdcTemp
, xOfs
, 0, growSize
, nHeightSrc
, hdcTemp
, 0, 0, SRCCOPY
);
372 xRemaining
-= growSize
;
376 /* Extend bitmap in the Y direction. Growth of height is exponential */
378 yRemaining
= nHeightTemp
- nHeightSrc
;
379 growSize
= nHeightSrc
;
380 while (yRemaining
> 0)
382 growSize
= min(growSize
, yRemaining
);
383 BitBlt(hdcTemp
, 0, yOfs
, nWidthTemp
, growSize
, hdcTemp
, 0, 0, SRCCOPY
);
385 yRemaining
-= growSize
;
389 /* Use temporary hdc for source */
390 result
= UXTHEME_Blt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
392 transparent
, transcolor
);
394 SelectObject(hdcTemp
, bitmapOrig
);
395 DeleteObject(bitmapTemp
);
402 return UXTHEME_StretchBlt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
403 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
404 transparent
, transcolor
);
408 /* Get transparency parameters passed to UXTHEME_StretchBlt() - the parameters
409 * depend on whether the image has full alpha or whether it is
410 * color-transparent or just opaque. */
411 static inline void get_transparency (HTHEME hTheme
, int iPartId
, int iStateId
,
412 BOOL hasImageAlpha
, INT
* transparent
,
413 COLORREF
* transparentcolor
, BOOL glyph
)
417 *transparent
= ALPHABLEND_FULL
;
418 *transparentcolor
= RGB (255, 0, 255);
423 GetThemeBool(hTheme
, iPartId
, iStateId
,
424 glyph
? TMT_GLYPHTRANSPARENT
: TMT_TRANSPARENT
, &trans
);
426 *transparent
= ALPHABLEND_BINARY
;
427 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
,
428 glyph
? TMT_GLYPHTRANSPARENTCOLOR
: TMT_TRANSPARENTCOLOR
,
429 transparentcolor
))) {
430 /* If image is transparent, but no color was specified, use magenta */
431 *transparentcolor
= RGB(255, 0, 255);
435 *transparent
= ALPHABLEND_NONE
;
439 /***********************************************************************
440 * UXTHEME_DrawImageGlyph
442 * Draw an imagefile glyph
444 static HRESULT
UXTHEME_DrawImageGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
445 int iStateId
, RECT
*pRect
,
446 const DTBGOPTS
*pOptions
)
449 HBITMAP bmpSrc
= NULL
;
451 HGDIOBJ oldSrc
= NULL
;
453 INT transparent
= FALSE
;
454 COLORREF transparentcolor
;
455 int valign
= VA_CENTER
;
456 int halign
= HA_CENTER
;
462 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, TRUE
,
463 &bmpSrc
, &rcSrc
, &hasAlpha
);
464 if(FAILED(hr
)) return hr
;
465 hdcSrc
= CreateCompatibleDC(hdc
);
467 hr
= HRESULT_FROM_WIN32(GetLastError());
470 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
472 dstSize
.x
= pRect
->right
-pRect
->left
;
473 dstSize
.y
= pRect
->bottom
-pRect
->top
;
474 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
475 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
477 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
478 &transparentcolor
, TRUE
);
479 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
480 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
482 topleft
.x
= pRect
->left
;
483 topleft
.y
= pRect
->top
;
484 if(halign
== HA_CENTER
) topleft
.x
+= (dstSize
.x
/2)-(srcSize
.x
/2);
485 else if(halign
== HA_RIGHT
) topleft
.x
+= dstSize
.x
-srcSize
.x
;
486 if(valign
== VA_CENTER
) topleft
.y
+= (dstSize
.y
/2)-(srcSize
.y
/2);
487 else if(valign
== VA_BOTTOM
) topleft
.y
+= dstSize
.y
-srcSize
.y
;
489 if(!UXTHEME_Blt(hdc
, topleft
.x
, topleft
.y
, srcSize
.x
, srcSize
.y
,
490 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
491 transparent
, transparentcolor
)) {
492 hr
= HRESULT_FROM_WIN32(GetLastError());
495 SelectObject(hdcSrc
, oldSrc
);
500 /***********************************************************************
501 * UXTHEME_DrawImageGlyph
503 * Draw glyph on top of background, if appropriate
505 static HRESULT
UXTHEME_DrawGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
506 int iStateId
, RECT
*pRect
,
507 const DTBGOPTS
*pOptions
)
509 int glyphtype
= GT_NONE
;
511 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_GLYPHTYPE
, &glyphtype
);
513 if(glyphtype
== GT_IMAGEGLYPH
) {
514 return UXTHEME_DrawImageGlyph(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pOptions
);
516 else if(glyphtype
== GT_FONTGLYPH
) {
517 /* I don't know what a font glyph is, I've never seen it used in any themes */
518 FIXME("Font glyph\n");
523 /***********************************************************************
524 * get_image_part_size
526 * Used by GetThemePartSize and UXTHEME_DrawImageBackground
528 static HRESULT
get_image_part_size (HTHEME hTheme
, HDC hdc
, int iPartId
,
529 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
537 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, prc
, FALSE
,
538 &bmpSrc
, &rcSrc
, &hasAlpha
);
539 if (FAILED(hr
)) return hr
;
549 int sizingtype
= ST_STRETCH
;
550 BOOL uniformsizing
= FALSE
;
552 CopyRect(&rcDst
, prc
);
554 dstSize
.x
= rcDst
.right
-rcDst
.left
;
555 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
556 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
557 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
559 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_UNIFORMSIZING
, &uniformsizing
);
561 /* Scale height and width equally */
562 if (dstSize
.x
*srcSize
.y
< dstSize
.y
*srcSize
.x
)
564 dstSize
.y
= MulDiv (srcSize
.y
, dstSize
.x
, srcSize
.x
);
565 rcDst
.bottom
= rcDst
.top
+ dstSize
.y
;
569 dstSize
.x
= MulDiv (srcSize
.x
, dstSize
.y
, srcSize
.y
);
570 rcDst
.right
= rcDst
.left
+ dstSize
.x
;
574 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
575 if(sizingtype
== ST_TRUESIZE
) {
576 int truesizestretchmark
= 100;
578 if(dstSize
.x
< 0 || dstSize
.y
< 0) {
579 BOOL mirrorimage
= TRUE
;
580 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_MIRRORIMAGE
, &mirrorimage
);
583 rcDst
.left
+= dstSize
.x
;
584 rcDst
.right
+= dstSize
.x
;
587 rcDst
.top
+= dstSize
.y
;
588 rcDst
.bottom
+= dstSize
.y
;
592 /* Whatever TrueSizeStretchMark does - it does not seem to
593 * be what's outlined below. It appears as if native
594 * uxtheme always stretches if dest is smaller than source
595 * (ie as if TrueSizeStretchMark==100 with the code below) */
597 /* Only stretch when target exceeds source by truesizestretchmark percent */
598 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_TRUESIZESTRETCHMARK
, &truesizestretchmark
);
600 if(dstSize
.x
< 0 || dstSize
.y
< 0 ||
601 (MulDiv(srcSize
.x
, 100, dstSize
.x
) > truesizestretchmark
&&
602 MulDiv(srcSize
.y
, 100, dstSize
.y
) > truesizestretchmark
)) {
603 memcpy (psz
, &dstSize
, sizeof (SIZE
));
606 memcpy (psz
, &srcSize
, sizeof (SIZE
));
611 psz
->x
= abs(dstSize
.x
);
612 psz
->y
= abs(dstSize
.y
);
616 /* else fall through */
618 /* FIXME: couldn't figure how native uxtheme computes min size */
620 psz
->x
= rcSrc
.right
- rcSrc
.left
;
621 psz
->y
= rcSrc
.bottom
- rcSrc
.top
;
627 /***********************************************************************
628 * UXTHEME_DrawImageBackground
630 * Draw an imagefile background
632 static HRESULT
UXTHEME_DrawImageBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
633 int iStateId
, RECT
*pRect
,
634 const DTBGOPTS
*pOptions
)
645 int sizingtype
= ST_STRETCH
;
647 COLORREF transparentcolor
= 0;
650 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, FALSE
,
651 &bmpSrc
, &rcSrc
, &hasAlpha
);
652 if(FAILED(hr
)) return hr
;
653 hdcSrc
= CreateCompatibleDC(hdc
);
655 hr
= HRESULT_FROM_WIN32(GetLastError());
658 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
660 CopyRect(&rcDst
, pRect
);
662 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
663 &transparentcolor
, FALSE
);
665 dstSize
.x
= rcDst
.right
-rcDst
.left
;
666 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
667 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
668 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
670 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
671 if(sizingtype
== ST_TRUESIZE
) {
672 int valign
= VA_CENTER
, halign
= HA_CENTER
;
674 get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, pRect
, TS_DRAW
, &drawSize
);
675 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
676 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
678 if (halign
== HA_CENTER
)
679 rcDst
.left
+= (dstSize
.x
/2)-(drawSize
.x
/2);
680 else if (halign
== HA_RIGHT
)
681 rcDst
.left
= rcDst
.right
- drawSize
.x
;
682 if (valign
== VA_CENTER
)
683 rcDst
.top
+= (dstSize
.y
/2)-(drawSize
.y
/2);
684 else if (valign
== VA_BOTTOM
)
685 rcDst
.top
= rcDst
.bottom
- drawSize
.y
;
686 rcDst
.right
= rcDst
.left
+ drawSize
.x
;
687 rcDst
.bottom
= rcDst
.top
+ drawSize
.y
;
688 if(!UXTHEME_StretchBlt(hdc
, rcDst
.left
, rcDst
.top
, drawSize
.x
, drawSize
.y
,
689 hdcSrc
, rcSrc
.left
, rcSrc
.top
, srcSize
.x
, srcSize
.y
,
690 transparent
, transparentcolor
))
691 hr
= HRESULT_FROM_WIN32(GetLastError());
698 dstSize
.x
= abs(dstSize
.x
);
699 dstSize
.y
= abs(dstSize
.y
);
701 GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_SIZINGMARGINS
, NULL
, &sm
);
704 OffsetViewportOrgEx(hdcDst
, rcDst
.left
, rcDst
.top
, &org
);
706 /* Upper left corner */
707 if(!UXTHEME_Blt(hdcDst
, 0, 0, sm
.cxLeftWidth
, sm
.cyTopHeight
,
708 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
709 transparent
, transparentcolor
)) {
710 hr
= HRESULT_FROM_WIN32(GetLastError());
713 /* Upper right corner */
714 if(!UXTHEME_Blt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, 0,
715 sm
.cxRightWidth
, sm
.cyTopHeight
,
716 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
,
717 transparent
, transparentcolor
)) {
718 hr
= HRESULT_FROM_WIN32(GetLastError());
721 /* Lower left corner */
722 if(!UXTHEME_Blt (hdcDst
, 0, dstSize
.y
-sm
.cyBottomHeight
,
723 sm
.cxLeftWidth
, sm
.cyBottomHeight
,
724 hdcSrc
, rcSrc
.left
, rcSrc
.bottom
-sm
.cyBottomHeight
,
725 transparent
, transparentcolor
)) {
726 hr
= HRESULT_FROM_WIN32(GetLastError());
729 /* Lower right corner */
730 if(!UXTHEME_Blt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, dstSize
.y
-sm
.cyBottomHeight
,
731 sm
.cxRightWidth
, sm
.cyBottomHeight
,
732 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
,
733 transparent
, transparentcolor
)) {
734 hr
= HRESULT_FROM_WIN32(GetLastError());
738 if ((sizingtype
== ST_STRETCH
) || (sizingtype
== ST_TILE
)) {
739 int destCenterWidth
= dstSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
740 int srcCenterWidth
= srcSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
741 int destCenterHeight
= dstSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
742 int srcCenterHeight
= srcSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
744 if(destCenterWidth
> 0) {
746 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, 0,
747 destCenterWidth
, sm
.cyTopHeight
,
748 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
,
749 srcCenterWidth
, sm
.cyTopHeight
,
750 sizingtype
, transparent
, transparentcolor
)) {
751 hr
= HRESULT_FROM_WIN32(GetLastError());
755 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, dstSize
.y
-sm
.cyBottomHeight
,
756 destCenterWidth
, sm
.cyBottomHeight
,
757 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
,
758 srcCenterWidth
, sm
.cyBottomHeight
,
759 sizingtype
, transparent
, transparentcolor
)) {
760 hr
= HRESULT_FROM_WIN32(GetLastError());
764 if(destCenterHeight
> 0) {
766 if(!UXTHEME_SizedBlt (hdcDst
, 0, sm
.cyTopHeight
,
767 sm
.cxLeftWidth
, destCenterHeight
,
768 hdcSrc
, rcSrc
.left
, rcSrc
.top
+sm
.cyTopHeight
,
769 sm
.cxLeftWidth
, srcCenterHeight
,
771 transparent
, transparentcolor
)) {
772 hr
= HRESULT_FROM_WIN32(GetLastError());
776 if(!UXTHEME_SizedBlt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, sm
.cyTopHeight
,
777 sm
.cxRightWidth
, destCenterHeight
,
778 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
+sm
.cyTopHeight
,
779 sm
.cxRightWidth
, srcCenterHeight
,
780 sizingtype
, transparent
, transparentcolor
)) {
781 hr
= HRESULT_FROM_WIN32(GetLastError());
785 if(destCenterHeight
> 0 && destCenterWidth
> 0) {
786 BOOL borderonly
= FALSE
;
787 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_BORDERONLY
, &borderonly
);
790 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, sm
.cyTopHeight
,
791 destCenterWidth
, destCenterHeight
,
792 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
+sm
.cyTopHeight
,
793 srcCenterWidth
, srcCenterHeight
,
794 sizingtype
, transparent
, transparentcolor
)) {
795 hr
= HRESULT_FROM_WIN32(GetLastError());
803 SetViewportOrgEx (hdcDst
, org
.x
, org
.y
, NULL
);
805 SelectObject(hdcSrc
, oldSrc
);
807 CopyRect(pRect
, &rcDst
);
811 /***********************************************************************
812 * UXTHEME_DrawBorderRectangle
814 * Draw the bounding rectangle for a borderfill background
816 static HRESULT
UXTHEME_DrawBorderRectangle(HTHEME hTheme
, HDC hdc
, int iPartId
,
817 int iStateId
, RECT
*pRect
,
818 const DTBGOPTS
*pOptions
)
823 COLORREF bordercolor
= RGB(0,0,0);
826 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
829 ptCorners
[0].x
= pRect
->left
;
830 ptCorners
[0].y
= pRect
->top
;
831 ptCorners
[1].x
= pRect
->right
-1;
832 ptCorners
[1].y
= pRect
->top
;
833 ptCorners
[2].x
= pRect
->right
-1;
834 ptCorners
[2].y
= pRect
->bottom
-1;
835 ptCorners
[3].x
= pRect
->left
;
836 ptCorners
[3].y
= pRect
->bottom
-1;
837 ptCorners
[4].x
= pRect
->left
;
838 ptCorners
[4].y
= pRect
->top
;
840 InflateRect(pRect
, -bordersize
, -bordersize
);
841 if(pOptions
->dwFlags
& DTBG_OMITBORDER
)
843 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_BORDERCOLOR
, &bordercolor
);
844 hPen
= CreatePen(PS_SOLID
, bordersize
, bordercolor
);
846 return HRESULT_FROM_WIN32(GetLastError());
847 oldPen
= SelectObject(hdc
, hPen
);
849 if(!Polyline(hdc
, ptCorners
, 5))
850 hr
= HRESULT_FROM_WIN32(GetLastError());
852 SelectObject(hdc
, oldPen
);
858 /***********************************************************************
859 * UXTHEME_DrawBackgroundFill
861 * Fill a borderfill background rectangle
863 static HRESULT
UXTHEME_DrawBackgroundFill(HTHEME hTheme
, HDC hdc
, int iPartId
,
864 int iStateId
, RECT
*pRect
,
865 const DTBGOPTS
*pOptions
)
868 int filltype
= FT_SOLID
;
870 TRACE("(%d,%d,%d)\n", iPartId
, iStateId
, pOptions
->dwFlags
);
872 if(pOptions
->dwFlags
& DTBG_OMITCONTENT
)
875 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_FILLTYPE
, &filltype
);
877 if(filltype
== FT_SOLID
) {
879 COLORREF fillcolor
= RGB(255,255,255);
881 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_FILLCOLOR
, &fillcolor
);
882 hBrush
= CreateSolidBrush(fillcolor
);
883 if(!FillRect(hdc
, pRect
, hBrush
))
884 hr
= HRESULT_FROM_WIN32(GetLastError());
885 DeleteObject(hBrush
);
887 else if(filltype
== FT_VERTGRADIENT
|| filltype
== FT_HORZGRADIENT
) {
888 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
889 the gradient ratios (no idea how those work)
890 Few themes use this, and the ones I've seen only use 2 colors with
891 a gradient ratio of 0 and 255 respectively
894 COLORREF gradient1
= RGB(0,0,0);
895 COLORREF gradient2
= RGB(255,255,255);
899 FIXME("Gradient implementation not complete\n");
901 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR1
, &gradient1
);
902 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR2
, &gradient2
);
904 vert
[0].x
= pRect
->left
;
905 vert
[0].y
= pRect
->top
;
906 vert
[0].Red
= GetRValue(gradient1
) << 8;
907 vert
[0].Green
= GetGValue(gradient1
) << 8;
908 vert
[0].Blue
= GetBValue(gradient1
) << 8;
909 vert
[0].Alpha
= 0x0000;
911 vert
[1].x
= pRect
->right
;
912 vert
[1].y
= pRect
->bottom
;
913 vert
[1].Red
= GetRValue(gradient2
) << 8;
914 vert
[1].Green
= GetGValue(gradient2
) << 8;
915 vert
[1].Blue
= GetBValue(gradient2
) << 8;
916 vert
[1].Alpha
= 0x0000;
919 gRect
.LowerRight
= 1;
920 GradientFill(hdc
,vert
,2,&gRect
,1,filltype
==FT_HORZGRADIENT
?GRADIENT_FILL_RECT_H
:GRADIENT_FILL_RECT_V
);
922 else if(filltype
== FT_RADIALGRADIENT
) {
923 /* I've never seen this used in a theme */
924 FIXME("Radial gradient\n");
926 else if(filltype
== FT_TILEIMAGE
) {
927 /* I've never seen this used in a theme */
928 FIXME("Tile image\n");
933 /***********************************************************************
934 * UXTHEME_DrawBorderBackground
936 * Draw an imagefile background
938 static HRESULT
UXTHEME_DrawBorderBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
939 int iStateId
, const RECT
*pRect
,
940 const DTBGOPTS
*pOptions
)
945 CopyRect(&rt
, pRect
);
947 hr
= UXTHEME_DrawBorderRectangle(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
950 return UXTHEME_DrawBackgroundFill(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
953 /***********************************************************************
954 * DrawThemeBackgroundEx (UXTHEME.@)
956 HRESULT WINAPI
DrawThemeBackgroundEx(HTHEME hTheme
, HDC hdc
, int iPartId
,
957 int iStateId
, const RECT
*pRect
,
958 const DTBGOPTS
*pOptions
)
961 const DTBGOPTS defaultOpts
= {sizeof(DTBGOPTS
), 0, {0,0,0,0}};
962 const DTBGOPTS
*opts
;
965 int bgtype
= BT_BORDERFILL
;
968 TRACE("(%p,%p,%d,%d,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
,pRect
->left
,pRect
->top
);
972 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
973 if (bgtype
== BT_NONE
) return S_OK
;
975 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
977 if(!opts
) opts
= &defaultOpts
;
979 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
980 clip
= CreateRectRgn(0,0,1,1);
981 hasClip
= GetClipRgn(hdc
, clip
);
983 TRACE("Failed to get original clipping region\n");
985 IntersectClipRect(hdc
, opts
->rcClip
.left
, opts
->rcClip
.top
, opts
->rcClip
.right
, opts
->rcClip
.bottom
);
987 CopyRect(&rt
, pRect
);
989 if(bgtype
== BT_IMAGEFILE
)
990 hr
= UXTHEME_DrawImageBackground(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
991 else if(bgtype
== BT_BORDERFILL
)
992 hr
= UXTHEME_DrawBorderBackground(hTheme
, hdc
, iPartId
, iStateId
, pRect
, opts
);
994 FIXME("Unknown background type\n");
995 /* This should never happen, and hence I don't know what to return */
999 hr
= UXTHEME_DrawGlyph(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
1000 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
1002 SelectClipRgn(hdc
, NULL
);
1003 else if(hasClip
== 1)
1004 SelectClipRgn(hdc
, clip
);
1011 * DrawThemeEdge() implementation
1013 * Since it basically is DrawEdge() with different colors, I copied its code
1014 * from user32's uitools.c.
1035 } EdgeColorMap
[EDGE_NUMCOLORS
] = {
1036 {TMT_EDGELIGHTCOLOR
, COLOR_3DLIGHT
},
1037 {TMT_EDGEHIGHLIGHTCOLOR
, COLOR_BTNHIGHLIGHT
},
1038 {TMT_EDGESHADOWCOLOR
, COLOR_BTNSHADOW
},
1039 {TMT_EDGEDKSHADOWCOLOR
, COLOR_3DDKSHADOW
},
1040 {TMT_EDGEFILLCOLOR
, COLOR_BTNFACE
},
1042 {-1, COLOR_WINDOWFRAME
}
1045 static const signed char LTInnerNormal
[] = {
1047 -1, EDGE_HIGHLIGHT
, EDGE_HIGHLIGHT
, -1,
1048 -1, EDGE_DARKSHADOW
, EDGE_DARKSHADOW
, -1,
1052 static const signed char LTOuterNormal
[] = {
1053 -1, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1054 EDGE_HIGHLIGHT
, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1055 EDGE_DARKSHADOW
, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1056 -1, EDGE_LIGHT
, EDGE_SHADOW
, -1
1059 static const signed char RBInnerNormal
[] = {
1061 -1, EDGE_SHADOW
, EDGE_SHADOW
, -1,
1062 -1, EDGE_LIGHT
, EDGE_LIGHT
, -1,
1066 static const signed char RBOuterNormal
[] = {
1067 -1, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1068 EDGE_SHADOW
, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1069 EDGE_LIGHT
, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1070 -1, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1
1073 static const signed char LTInnerSoft
[] = {
1075 -1, EDGE_LIGHT
, EDGE_LIGHT
, -1,
1076 -1, EDGE_SHADOW
, EDGE_SHADOW
, -1,
1080 static const signed char LTOuterSoft
[] = {
1081 -1, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1082 EDGE_LIGHT
, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1083 EDGE_SHADOW
, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1084 -1, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1
1087 #define RBInnerSoft RBInnerNormal /* These are the same */
1088 #define RBOuterSoft RBOuterNormal
1090 static const signed char LTRBOuterMono
[] = {
1091 -1, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1092 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1093 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1094 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1097 static const signed char LTRBInnerMono
[] = {
1099 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1100 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1101 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1104 static const signed char LTRBOuterFlat
[] = {
1105 -1, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1106 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1107 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1108 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1111 static const signed char LTRBInnerFlat
[] = {
1113 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1114 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1115 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1118 static COLORREF
get_edge_color (int edgeType
, HTHEME theme
, int part
, int state
)
1121 if ((EdgeColorMap
[edgeType
].themeProp
== -1)
1122 || FAILED (GetThemeColor (theme
, part
, state
,
1123 EdgeColorMap
[edgeType
].themeProp
, &col
)))
1124 col
= GetSysColor (EdgeColorMap
[edgeType
].sysColor
);
1128 static inline HPEN
get_edge_pen (int edgeType
, HTHEME theme
, int part
, int state
)
1130 return CreatePen (PS_SOLID
, 1, get_edge_color (edgeType
, theme
, part
, state
));
1133 static inline HBRUSH
get_edge_brush (int edgeType
, HTHEME theme
, int part
, int state
)
1135 return CreateSolidBrush (get_edge_color (edgeType
, theme
, part
, state
));
1138 /***********************************************************************
1141 * Same as DrawEdge invoked with BF_DIAGONAL
1143 static HRESULT
draw_diag_edge (HDC hdc
, HTHEME theme
, int part
, int state
,
1144 const RECT
* rc
, UINT uType
,
1145 UINT uFlags
, LPRECT contentsRect
)
1148 signed char InnerI
, OuterI
;
1149 HPEN InnerPen
, OuterPen
;
1154 int Width
= rc
->right
- rc
->left
;
1155 int Height
= rc
->bottom
- rc
->top
;
1156 int SmallDiam
= Width
> Height
? Height
: Width
;
1157 HRESULT retval
= (((uType
& BDR_INNER
) == BDR_INNER
1158 || (uType
& BDR_OUTER
) == BDR_OUTER
)
1159 && !(uFlags
& (BF_FLAT
|BF_MONO
)) ) ? E_FAIL
: S_OK
;
1160 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
1161 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
1163 /* Init some vars */
1164 OuterPen
= InnerPen
= GetStockObject(NULL_PEN
);
1165 SavePen
= SelectObject(hdc
, InnerPen
);
1166 spx
= spy
= epx
= epy
= 0; /* Satisfy the compiler... */
1168 /* Determine the colors of the edges */
1169 if(uFlags
& BF_MONO
)
1171 InnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1172 OuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1174 else if(uFlags
& BF_FLAT
)
1176 InnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1177 OuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1179 else if(uFlags
& BF_SOFT
)
1181 if(uFlags
& BF_BOTTOM
)
1183 InnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1184 OuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1188 InnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1189 OuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1194 if(uFlags
& BF_BOTTOM
)
1196 InnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1197 OuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1201 InnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1202 OuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1206 if(InnerI
!= -1) InnerPen
= get_edge_pen (InnerI
, theme
, part
, state
);
1207 if(OuterI
!= -1) OuterPen
= get_edge_pen (OuterI
, theme
, part
, state
);
1209 MoveToEx(hdc
, 0, 0, &SavePoint
);
1211 /* Don't ask me why, but this is what is visible... */
1212 /* This must be possible to do much simpler, but I fail to */
1213 /* see the logic in the MS implementation (sigh...). */
1214 /* So, this might look a bit brute force here (and it is), but */
1215 /* it gets the job done;) */
1217 switch(uFlags
& BF_RECT
)
1223 /* Left bottom endpoint */
1225 spx
= epx
+ SmallDiam
;
1227 spy
= epy
- SmallDiam
;
1231 case BF_BOTTOMRIGHT
:
1232 /* Left top endpoint */
1234 spx
= epx
+ SmallDiam
;
1236 spy
= epy
+ SmallDiam
;
1242 case BF_RIGHT
|BF_LEFT
:
1243 case BF_RIGHT
|BF_LEFT
|BF_TOP
:
1244 case BF_BOTTOM
|BF_TOP
:
1245 case BF_BOTTOM
|BF_TOP
|BF_LEFT
:
1246 case BF_BOTTOMRIGHT
|BF_LEFT
:
1247 case BF_BOTTOMRIGHT
|BF_TOP
:
1249 /* Right top endpoint */
1251 epx
= spx
+ SmallDiam
;
1253 epy
= spy
- SmallDiam
;
1257 MoveToEx(hdc
, spx
, spy
, NULL
);
1258 SelectObject(hdc
, OuterPen
);
1259 LineTo(hdc
, epx
, epy
);
1261 SelectObject(hdc
, InnerPen
);
1263 switch(uFlags
& (BF_RECT
|BF_DIAGONAL
))
1265 case BF_DIAGONAL_ENDBOTTOMLEFT
:
1266 case (BF_DIAGONAL
|BF_BOTTOM
):
1268 case (BF_DIAGONAL
|BF_LEFT
):
1269 MoveToEx(hdc
, spx
-1, spy
, NULL
);
1270 LineTo(hdc
, epx
, epy
-1);
1271 Points
[0].x
= spx
-add
;
1273 Points
[1].x
= rc
->left
;
1274 Points
[1].y
= rc
->top
;
1275 Points
[2].x
= epx
+1;
1276 Points
[2].y
= epy
-1-add
;
1277 Points
[3] = Points
[2];
1280 case BF_DIAGONAL_ENDBOTTOMRIGHT
:
1281 MoveToEx(hdc
, spx
-1, spy
, NULL
);
1282 LineTo(hdc
, epx
, epy
+1);
1283 Points
[0].x
= spx
-add
;
1285 Points
[1].x
= rc
->left
;
1286 Points
[1].y
= rc
->bottom
-1;
1287 Points
[2].x
= epx
+1;
1288 Points
[2].y
= epy
+1+add
;
1289 Points
[3] = Points
[2];
1292 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
):
1293 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
1294 case BF_DIAGONAL_ENDTOPRIGHT
:
1295 case (BF_DIAGONAL
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
1296 MoveToEx(hdc
, spx
+1, spy
, NULL
);
1297 LineTo(hdc
, epx
, epy
+1);
1298 Points
[0].x
= epx
-1;
1299 Points
[0].y
= epy
+1+add
;
1300 Points
[1].x
= rc
->right
-1;
1301 Points
[1].y
= rc
->top
+add
;
1302 Points
[2].x
= rc
->right
-1;
1303 Points
[2].y
= rc
->bottom
-1;
1304 Points
[3].x
= spx
+add
;
1308 case BF_DIAGONAL_ENDTOPLEFT
:
1309 MoveToEx(hdc
, spx
, spy
-1, NULL
);
1310 LineTo(hdc
, epx
+1, epy
);
1311 Points
[0].x
= epx
+1+add
;
1312 Points
[0].y
= epy
+1;
1313 Points
[1].x
= rc
->right
-1;
1314 Points
[1].y
= rc
->top
;
1315 Points
[2].x
= rc
->right
-1;
1316 Points
[2].y
= rc
->bottom
-1-add
;
1318 Points
[3].y
= spy
-add
;
1321 case (BF_DIAGONAL
|BF_TOP
):
1322 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
):
1323 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
|BF_LEFT
):
1324 MoveToEx(hdc
, spx
+1, spy
-1, NULL
);
1325 LineTo(hdc
, epx
, epy
);
1326 Points
[0].x
= epx
-1;
1327 Points
[0].y
= epy
+1;
1328 Points
[1].x
= rc
->right
-1;
1329 Points
[1].y
= rc
->top
;
1330 Points
[2].x
= rc
->right
-1;
1331 Points
[2].y
= rc
->bottom
-1-add
;
1332 Points
[3].x
= spx
+add
;
1333 Points
[3].y
= spy
-add
;
1336 case (BF_DIAGONAL
|BF_RIGHT
):
1337 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
):
1338 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
|BF_BOTTOM
):
1339 MoveToEx(hdc
, spx
, spy
, NULL
);
1340 LineTo(hdc
, epx
-1, epy
+1);
1343 Points
[1].x
= rc
->left
;
1344 Points
[1].y
= rc
->top
+add
;
1345 Points
[2].x
= epx
-1-add
;
1346 Points
[2].y
= epy
+1+add
;
1347 Points
[3] = Points
[2];
1351 /* Fill the interior if asked */
1352 if((uFlags
& BF_MIDDLE
) && retval
)
1355 HBRUSH hb
= get_edge_brush ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1356 theme
, part
, state
);
1358 HPEN hp
= get_edge_pen ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1359 theme
, part
, state
);
1360 hbsave
= SelectObject(hdc
, hb
);
1361 hpsave
= SelectObject(hdc
, hp
);
1362 Polygon(hdc
, Points
, 4);
1363 SelectObject(hdc
, hbsave
);
1364 SelectObject(hdc
, hpsave
);
1369 /* Adjust rectangle if asked */
1370 if(uFlags
& BF_ADJUST
)
1372 *contentsRect
= *rc
;
1373 if(uFlags
& BF_LEFT
) contentsRect
->left
+= add
;
1374 if(uFlags
& BF_RIGHT
) contentsRect
->right
-= add
;
1375 if(uFlags
& BF_TOP
) contentsRect
->top
+= add
;
1376 if(uFlags
& BF_BOTTOM
) contentsRect
->bottom
-= add
;
1380 SelectObject(hdc
, SavePen
);
1381 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
1382 if(InnerI
!= -1) DeleteObject (InnerPen
);
1383 if(OuterI
!= -1) DeleteObject (OuterPen
);
1388 /***********************************************************************
1391 * Same as DrawEdge invoked without BF_DIAGONAL
1393 static HRESULT
draw_rect_edge (HDC hdc
, HTHEME theme
, int part
, int state
,
1394 const RECT
* rc
, UINT uType
,
1395 UINT uFlags
, LPRECT contentsRect
)
1397 signed char LTInnerI
, LTOuterI
;
1398 signed char RBInnerI
, RBOuterI
;
1399 HPEN LTInnerPen
, LTOuterPen
;
1400 HPEN RBInnerPen
, RBOuterPen
;
1401 RECT InnerRect
= *rc
;
1408 HRESULT retval
= (((uType
& BDR_INNER
) == BDR_INNER
1409 || (uType
& BDR_OUTER
) == BDR_OUTER
)
1410 && !(uFlags
& (BF_FLAT
|BF_MONO
)) ) ? E_FAIL
: S_OK
;
1412 /* Init some vars */
1413 LTInnerPen
= LTOuterPen
= RBInnerPen
= RBOuterPen
= GetStockObject(NULL_PEN
);
1414 SavePen
= SelectObject(hdc
, LTInnerPen
);
1416 /* Determine the colors of the edges */
1417 if(uFlags
& BF_MONO
)
1419 LTInnerI
= RBInnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1420 LTOuterI
= RBOuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1422 else if(uFlags
& BF_FLAT
)
1424 LTInnerI
= RBInnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1425 LTOuterI
= RBOuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1427 if( LTInnerI
!= -1 ) LTInnerI
= RBInnerI
= EDGE_FILL
;
1429 else if(uFlags
& BF_SOFT
)
1431 LTInnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1432 LTOuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1433 RBInnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1434 RBOuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1438 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1439 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1440 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1441 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1444 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
) LBpenplus
= 1;
1445 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
) RTpenplus
= 1;
1446 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
) RBpenplus
= 1;
1447 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
) LTpenplus
= 1;
1449 if(LTInnerI
!= -1) LTInnerPen
= get_edge_pen (LTInnerI
, theme
, part
, state
);
1450 if(LTOuterI
!= -1) LTOuterPen
= get_edge_pen (LTOuterI
, theme
, part
, state
);
1451 if(RBInnerI
!= -1) RBInnerPen
= get_edge_pen (RBInnerI
, theme
, part
, state
);
1452 if(RBOuterI
!= -1) RBOuterPen
= get_edge_pen (RBOuterI
, theme
, part
, state
);
1454 MoveToEx(hdc
, 0, 0, &SavePoint
);
1456 /* Draw the outer edge */
1457 SelectObject(hdc
, LTOuterPen
);
1460 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
1461 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
1463 if(uFlags
& BF_LEFT
)
1465 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
1466 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
1468 SelectObject(hdc
, RBOuterPen
);
1469 if(uFlags
& BF_BOTTOM
)
1471 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.bottom
-1, NULL
);
1472 LineTo(hdc
, InnerRect
.left
-1, InnerRect
.bottom
-1);
1474 if(uFlags
& BF_RIGHT
)
1476 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.bottom
-1, NULL
);
1477 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.top
-1);
1480 /* Draw the inner edge */
1481 SelectObject(hdc
, LTInnerPen
);
1484 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
1485 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
1487 if(uFlags
& BF_LEFT
)
1489 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
1490 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
1492 SelectObject(hdc
, RBInnerPen
);
1493 if(uFlags
& BF_BOTTOM
)
1495 MoveToEx(hdc
, InnerRect
.right
-1-RBpenplus
, InnerRect
.bottom
-2, NULL
);
1496 LineTo(hdc
, InnerRect
.left
-1+LBpenplus
, InnerRect
.bottom
-2);
1498 if(uFlags
& BF_RIGHT
)
1500 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-1-RBpenplus
, NULL
);
1501 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.top
-1+RTpenplus
);
1504 if( ((uFlags
& BF_MIDDLE
) && retval
) || (uFlags
& BF_ADJUST
) )
1506 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
1507 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
1509 if(uFlags
& BF_LEFT
) InnerRect
.left
+= add
;
1510 if(uFlags
& BF_RIGHT
) InnerRect
.right
-= add
;
1511 if(uFlags
& BF_TOP
) InnerRect
.top
+= add
;
1512 if(uFlags
& BF_BOTTOM
) InnerRect
.bottom
-= add
;
1514 if((uFlags
& BF_MIDDLE
) && retval
)
1516 HBRUSH br
= get_edge_brush ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1517 theme
, part
, state
);
1518 FillRect(hdc
, &InnerRect
, br
);
1522 if(uFlags
& BF_ADJUST
)
1523 *contentsRect
= InnerRect
;
1527 SelectObject(hdc
, SavePen
);
1528 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
1529 if(LTInnerI
!= -1) DeleteObject (LTInnerPen
);
1530 if(LTOuterI
!= -1) DeleteObject (LTOuterPen
);
1531 if(RBInnerI
!= -1) DeleteObject (RBInnerPen
);
1532 if(RBOuterI
!= -1) DeleteObject (RBOuterPen
);
1537 /***********************************************************************
1538 * DrawThemeEdge (UXTHEME.@)
1540 * DrawThemeEdge() is pretty similar to the vanilla DrawEdge() - the
1541 * difference is that it does not rely on the system colors alone, but
1542 * also allows color specification in the theme.
1544 HRESULT WINAPI
DrawThemeEdge(HTHEME hTheme
, HDC hdc
, int iPartId
,
1545 int iStateId
, const RECT
*pDestRect
, UINT uEdge
,
1546 UINT uFlags
, RECT
*pContentRect
)
1548 TRACE("%d %d 0x%08x 0x%08x\n", iPartId
, iStateId
, uEdge
, uFlags
);
1552 if(uFlags
& BF_DIAGONAL
)
1553 return draw_diag_edge (hdc
, hTheme
, iPartId
, iStateId
, pDestRect
,
1554 uEdge
, uFlags
, pContentRect
);
1556 return draw_rect_edge (hdc
, hTheme
, iPartId
, iStateId
, pDestRect
,
1557 uEdge
, uFlags
, pContentRect
);
1561 /***********************************************************************
1562 * DrawThemeIcon (UXTHEME.@)
1564 HRESULT WINAPI
DrawThemeIcon(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1565 const RECT
*pRect
, HIMAGELIST himl
, int iImageIndex
)
1567 FIXME("%d %d: stub\n", iPartId
, iStateId
);
1570 return ERROR_CALL_NOT_IMPLEMENTED
;
1573 /***********************************************************************
1574 * DrawThemeText (UXTHEME.@)
1576 HRESULT WINAPI
DrawThemeText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1577 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
1578 DWORD dwTextFlags2
, const RECT
*pRect
)
1582 HGDIOBJ oldFont
= NULL
;
1585 COLORREF oldTextColor
;
1589 TRACE("%d %d: stub\n", iPartId
, iStateId
);
1593 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
1595 hFont
= CreateFontIndirectW(&logfont
);
1597 TRACE("Failed to create font\n");
1599 CopyRect(&rt
, pRect
);
1601 oldFont
= SelectObject(hdc
, hFont
);
1603 if(dwTextFlags2
& DTT_GRAYED
)
1604 textColor
= GetSysColor(COLOR_GRAYTEXT
);
1606 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TEXTCOLOR
, &textColor
)))
1607 textColor
= GetTextColor(hdc
);
1609 oldTextColor
= SetTextColor(hdc
, textColor
);
1610 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1611 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
1612 SetBkMode(hdc
, oldBkMode
);
1613 SetTextColor(hdc
, oldTextColor
);
1616 SelectObject(hdc
, oldFont
);
1617 DeleteObject(hFont
);
1622 /***********************************************************************
1623 * GetThemeBackgroundContentRect (UXTHEME.@)
1625 HRESULT WINAPI
GetThemeBackgroundContentRect(HTHEME hTheme
, HDC hdc
, int iPartId
,
1627 const RECT
*pBoundingRect
,
1633 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1637 /* try content margins property... */
1638 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1640 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
1641 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
1642 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
1643 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
1645 /* otherwise, try to determine content rect from the background type and props */
1646 int bgtype
= BT_BORDERFILL
;
1647 *pContentRect
= *pBoundingRect
;
1649 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1650 if(bgtype
== BT_BORDERFILL
) {
1653 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1654 InflateRect(pContentRect
, -bordersize
, -bordersize
);
1655 } else if ((bgtype
== BT_IMAGEFILE
)
1656 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1657 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1658 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
1659 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
1660 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
1661 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
1663 /* If nothing was found, leave unchanged */
1666 TRACE("left:%d,top:%d,right:%d,bottom:%d\n", pContentRect
->left
, pContentRect
->top
, pContentRect
->right
, pContentRect
->bottom
);
1671 /***********************************************************************
1672 * GetThemeBackgroundExtent (UXTHEME.@)
1674 HRESULT WINAPI
GetThemeBackgroundExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1675 int iStateId
, const RECT
*pContentRect
,
1681 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1685 /* try content margins property... */
1686 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1688 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1689 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1690 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1691 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1693 /* otherwise, try to determine content rect from the background type and props */
1694 int bgtype
= BT_BORDERFILL
;
1695 *pExtentRect
= *pContentRect
;
1697 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1698 if(bgtype
== BT_BORDERFILL
) {
1701 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1702 InflateRect(pExtentRect
, bordersize
, bordersize
);
1703 } else if ((bgtype
== BT_IMAGEFILE
)
1704 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1705 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1706 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1707 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1708 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1709 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1711 /* If nothing was found, leave unchanged */
1714 TRACE("left:%d,top:%d,right:%d,bottom:%d\n", pExtentRect
->left
, pExtentRect
->top
, pExtentRect
->right
, pExtentRect
->bottom
);
1720 static HBITMAP
UXTHEME_DrawThemePartToDib(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, LPCRECT pRect
)
1724 HBITMAP hbmp
, hbmpOld
;
1727 hdcMem
= CreateCompatibleDC(0);
1729 memset(&bmi
, 0, sizeof(bmi
));
1730 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
1731 bmi
.bmiHeader
.biWidth
= pRect
->right
;
1732 bmi
.bmiHeader
.biHeight
= -pRect
->bottom
;
1733 bmi
.bmiHeader
.biPlanes
= 1;
1734 bmi
.bmiHeader
.biBitCount
= 32;
1735 hbmp
= CreateDIBSection(hdcMem
, &bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
1737 hbmpOld
= (HBITMAP
)SelectObject(hdcMem
, hbmp
);
1739 /* FIXME: use an internal function that doesn't do transparent blt */
1740 hbrBack
= CreateSolidBrush(RGB(255,0,255));
1742 FillRect(hdcMem
, pRect
, hbrBack
);
1744 DrawThemeBackground(hTheme
, hdcMem
, iPartId
, iStateId
, pRect
, NULL
);
1746 DeleteObject(hbrBack
);
1747 SelectObject(hdcMem
, hbmpOld
);
1748 DeleteObject(hdcMem
);
1753 #define PT_IN_RECT(lprc,x,y) ( x >= lprc->left && x < lprc->right && \
1754 y >= lprc->top && y < lprc->bottom)
1756 static HRGN
UXTHEME_RegionFromDibBits(RGBQUAD
* pBuffer
, RGBQUAD
* pclrTransparent
, LPCRECT pRect
)
1759 #ifdef EXTCREATEREGION_WORKS
1760 int cMaxRgnRects
, cRgnDataSize
, cRgnRects
;
1766 ULONG clrTransparent
, *pclrCurrent
;
1769 pclrCurrent
= (PULONG
)pBuffer
;
1770 clrTransparent
= *(PULONG
)pclrTransparent
;
1772 #ifdef EXTCREATEREGION_WORKS
1773 /* Create a region and pre-allocate memory enough for 3 spaces in one row*/
1775 cMaxRgnRects
= 4* (pRect
->bottom
-pRect
->top
);
1776 cRgnDataSize
= sizeof(RGNDATA
) + cMaxRgnRects
* sizeof(RECT
);
1778 /* Allocate the region data */
1779 prgnData
= (PRGNDATA
)HeapAlloc(GetProcessHeap(), 0, cRgnDataSize
);
1781 prcCurrent
= (PRECT
)prgnData
->Buffer
;
1783 hrgnRet
= CreateRectRgn(0,0,0,0);
1786 /* Calculate the region rects */
1788 /* Scan each line of the bitmap */
1789 while(y
<pRect
->bottom
)
1792 /* Scan each pixel */
1793 while (x
<pRect
->right
)
1795 /* Check if the pixel is not transparent and it is in the requested rect */
1796 if(*pclrCurrent
!= clrTransparent
&& PT_IN_RECT(pRect
,x
,y
))
1799 /* Find the end of the opaque row of pixels */
1800 while (x
<pRect
->right
)
1802 if(*pclrCurrent
== clrTransparent
|| !PT_IN_RECT(pRect
,x
,y
))
1808 #ifdef EXTCREATEREGION_WORKS
1809 /* Add the scaned line to the region */
1810 SetRect(prcCurrent
, xstart
, y
,x
,y
+1);
1814 /* Increase the size of the buffer if it is full */
1815 if(cRgnRects
== cMaxRgnRects
)
1818 cRgnDataSize
= sizeof(RGNDATA
) + cMaxRgnRects
* sizeof(RECT
);
1819 prgnData
= (PRGNDATA
)HeapReAlloc(GetProcessHeap(),
1823 prcCurrent
= (RECT
*)prgnData
->Buffer
+ cRgnRects
;
1826 hrgnTemp
= CreateRectRgn(xstart
, y
,x
,y
+1);
1827 CombineRgn(hrgnRet
, hrgnRet
, hrgnTemp
, RGN_OR
);
1828 DeleteObject(hrgnTemp
);
1840 #ifdef EXTCREATEREGION_WORKS
1841 /* Fill the region data header */
1842 prgnData
->rdh
.dwSize
= sizeof(prgnData
->rdh
);
1843 prgnData
->rdh
.iType
= RDH_RECTANGLES
;
1844 prgnData
->rdh
.nCount
= cRgnRects
;
1845 prgnData
->rdh
.nRgnSize
= cRgnDataSize
;
1846 prgnData
->rdh
.rcBound
= *pRect
;
1848 /* Create the region*/
1849 hrgnRet
= ExtCreateRegion (NULL
, cRgnDataSize
, prgnData
);
1851 /* Free the region data*/
1852 HeapFree(GetProcessHeap(),0,prgnData
);
1855 /* return the region*/
1859 HRESULT
UXTHEME_GetImageBackBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, LPCRECT pRect
, HRGN
*pRegion
)
1863 RGBQUAD clrTransparent
= {0xFF,0x0, 0xFF,0x0};
1865 /* Draw the theme part to a dib */
1866 hbmp
= UXTHEME_DrawThemePartToDib(hTheme
, hdc
, iPartId
, iStateId
, pRect
);
1868 /* Retrieve the info of the dib section */
1869 GetObjectW(hbmp
, sizeof (DIBSECTION
), &dib
);
1871 /* Convert the bits of the dib section to a region */
1872 *pRegion
= UXTHEME_RegionFromDibBits((RGBQUAD
*)dib
.dsBm
.bmBits
, &clrTransparent
, pRect
);
1874 /* Free the temp bitmap */
1880 /***********************************************************************
1881 * GetThemeBackgroundRegion (UXTHEME.@)
1883 * Calculate the background region, taking into consideration transparent areas
1884 * of the background image.
1886 HRESULT WINAPI
GetThemeBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
,
1887 int iStateId
, const RECT
*pRect
,
1891 int bgtype
= BT_BORDERFILL
;
1893 TRACE("(%p,%p,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
);
1896 if(!pRect
|| !pRegion
)
1899 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1900 if(bgtype
== BT_IMAGEFILE
) {
1901 hr
= UXTHEME_GetImageBackBackgroundRegion(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pRegion
);
1903 else if(bgtype
== BT_BORDERFILL
) {
1904 *pRegion
= CreateRectRgn(pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
1906 hr
= HRESULT_FROM_WIN32(GetLastError());
1909 FIXME("Unknown background type\n");
1910 /* This should never happen, and hence I don't know what to return */
1916 /* compute part size for "borderfill" backgrounds */
1917 static HRESULT
get_border_background_size (HTHEME hTheme
, int iPartId
,
1918 int iStateId
, THEMESIZE eSize
, POINT
* psz
)
1923 if (SUCCEEDED (hr
= GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
,
1926 psz
->x
= psz
->y
= 2*bordersize
;
1927 if (eSize
!= TS_MIN
)
1936 /***********************************************************************
1937 * GetThemePartSize (UXTHEME.@)
1939 HRESULT WINAPI
GetThemePartSize(HTHEME hTheme
, HDC hdc
, int iPartId
,
1940 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
1943 int bgtype
= BT_BORDERFILL
;
1945 POINT size
= {1, 1};
1950 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1951 if (bgtype
== BT_NONE
)
1953 else if(bgtype
== BT_IMAGEFILE
)
1954 hr
= get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, prc
, eSize
, &size
);
1955 else if(bgtype
== BT_BORDERFILL
)
1956 hr
= get_border_background_size (hTheme
, iPartId
, iStateId
, eSize
, &size
);
1958 FIXME("Unknown background type\n");
1959 /* This should never happen, and hence I don't know what to return */
1968 /***********************************************************************
1969 * GetThemeTextExtent (UXTHEME.@)
1971 HRESULT WINAPI
GetThemeTextExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1972 int iStateId
, LPCWSTR pszText
, int iCharCount
,
1973 DWORD dwTextFlags
, const RECT
*pBoundingRect
,
1978 HGDIOBJ oldFont
= NULL
;
1980 RECT rt
= {0,0,0xFFFF,0xFFFF};
1982 TRACE("%d %d: stub\n", iPartId
, iStateId
);
1987 CopyRect(&rt
, pBoundingRect
);
1989 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
1991 hFont
= CreateFontIndirectW(&logfont
);
1993 TRACE("Failed to create font\n");
1996 oldFont
= SelectObject(hdc
, hFont
);
1998 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
|DT_CALCRECT
);
1999 CopyRect(pExtentRect
, &rt
);
2002 SelectObject(hdc
, oldFont
);
2003 DeleteObject(hFont
);
2008 /***********************************************************************
2009 * GetThemeTextMetrics (UXTHEME.@)
2011 HRESULT WINAPI
GetThemeTextMetrics(HTHEME hTheme
, HDC hdc
, int iPartId
,
2012 int iStateId
, TEXTMETRICW
*ptm
)
2016 HGDIOBJ oldFont
= NULL
;
2019 TRACE("(%p, %p, %d, %d)\n", hTheme
, hdc
, iPartId
, iStateId
);
2023 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
2025 hFont
= CreateFontIndirectW(&logfont
);
2027 TRACE("Failed to create font\n");
2030 oldFont
= SelectObject(hdc
, hFont
);
2032 if(!GetTextMetricsW(hdc
, ptm
))
2033 hr
= HRESULT_FROM_WIN32(GetLastError());
2036 SelectObject(hdc
, oldFont
);
2037 DeleteObject(hFont
);
2042 /***********************************************************************
2043 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
2045 BOOL WINAPI
IsThemeBackgroundPartiallyTransparent(HTHEME hTheme
, int iPartId
,
2048 int bgtype
= BT_BORDERFILL
;
2049 RECT rect
= {0, 0, 0, 0};
2054 COLORREF transparentcolor
;
2056 TRACE("(%d,%d)\n", iPartId
, iStateId
);
2061 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
2063 if (bgtype
!= BT_IMAGEFILE
) return FALSE
;
2065 if(FAILED (UXTHEME_LoadImage (hTheme
, 0, iPartId
, iStateId
, &rect
, FALSE
,
2066 &bmpSrc
, &rcSrc
, &hasAlpha
)))
2069 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
2070 &transparentcolor
, FALSE
);
2071 return (transparent
!= ALPHABLEND_NONE
);