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
25 /***********************************************************************
26 * Defines and global variables
29 extern ATOM atDialogThemeEnabled
;
31 /***********************************************************************/
33 /***********************************************************************
34 * EnableThemeDialogTexture (UXTHEME.@)
36 HRESULT WINAPI
EnableThemeDialogTexture(HWND hwnd
, DWORD dwFlags
)
38 static const WCHAR szTab
[] = { 'T','a','b',0 };
41 TRACE("(%p,0x%08x\n", hwnd
, dwFlags
);
42 res
= SetPropW (hwnd
, (LPCWSTR
)MAKEINTATOM(atDialogThemeEnabled
),
43 UlongToHandle(dwFlags
|0x80000000));
44 /* 0x80000000 serves as a "flags set" flag */
46 return HRESULT_FROM_WIN32(GetLastError());
47 if (dwFlags
& ETDT_USETABTEXTURE
)
48 return SetWindowTheme (hwnd
, NULL
, szTab
);
50 return SetWindowTheme (hwnd
, NULL
, NULL
);
53 /***********************************************************************
54 * IsThemeDialogTextureEnabled (UXTHEME.@)
56 BOOL WINAPI
IsThemeDialogTextureEnabled(HWND hwnd
)
58 DWORD dwDialogTextureFlags
;
59 TRACE("(%p)\n", hwnd
);
61 dwDialogTextureFlags
= HandleToUlong( GetPropW( hwnd
, (LPCWSTR
)MAKEINTATOM(atDialogThemeEnabled
) ));
62 if (dwDialogTextureFlags
== 0)
63 /* Means EnableThemeDialogTexture wasn't called for this dialog */
66 return (dwDialogTextureFlags
& ETDT_ENABLE
) && !(dwDialogTextureFlags
& ETDT_DISABLE
);
69 /***********************************************************************
70 * DrawThemeParentBackground (UXTHEME.@)
72 HRESULT WINAPI
DrawThemeParentBackground(HWND hwnd
, HDC hdc
, RECT
*prc
)
80 TRACE("(%p,%p,%p)\n", hwnd
, hdc
, prc
);
81 hParent
= GetParent(hwnd
);
86 MapWindowPoints(hwnd
, hParent
, (LPPOINT
)&rt
, 2);
88 clip
= CreateRectRgn(0,0,1,1);
89 hasClip
= GetClipRgn(hdc
, clip
);
91 TRACE("Failed to get original clipping region\n");
93 IntersectClipRect(hdc
, prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
96 GetClientRect(hwnd
, &rt
);
97 MapWindowPoints(hwnd
, hParent
, (LPPOINT
)&rt
, 2);
100 OffsetViewportOrgEx(hdc
, -rt
.left
, -rt
.top
, &org
);
102 SendMessageW(hParent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
103 SendMessageW(hParent
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
105 SetViewportOrgEx(hdc
, org
.x
, org
.y
, NULL
);
108 SelectClipRgn(hdc
, NULL
);
109 else if(hasClip
== 1)
110 SelectClipRgn(hdc
, clip
);
117 /***********************************************************************
118 * DrawThemeBackground (UXTHEME.@)
120 HRESULT WINAPI
DrawThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
121 int iStateId
, const RECT
*pRect
,
122 const RECT
*pClipRect
)
125 opts
.dwSize
= sizeof(DTBGOPTS
);
128 opts
.dwFlags
|= DTBG_CLIPRECT
;
129 CopyRect(&opts
.rcClip
, pClipRect
);
131 return DrawThemeBackgroundEx(hTheme
, hdc
, iPartId
, iStateId
, pRect
, &opts
);
134 /***********************************************************************
135 * UXTHEME_SelectImage
137 * Select the image to use
139 static PTHEME_PROPERTY
UXTHEME_SelectImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
)
142 int imageselecttype
= IST_NONE
;
146 image
= TMT_GLYPHIMAGEFILE
;
148 image
= TMT_IMAGEFILE
;
150 if((tp
=MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, image
)))
152 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGESELECTTYPE
, &imageselecttype
);
154 if(imageselecttype
== IST_DPI
) {
156 int screendpi
= GetDeviceCaps(hdc
, LOGPIXELSX
);
157 for(i
=4; i
>=0; i
--) {
159 if(SUCCEEDED(GetThemeInt(hTheme
, iPartId
, iStateId
, i
+ TMT_MINDPI1
, &reqdpi
))) {
160 if(reqdpi
!= 0 && screendpi
>= reqdpi
) {
161 TRACE("Using %d DPI, image %d\n", reqdpi
, i
+ TMT_IMAGEFILE1
);
162 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
166 /* If an image couldn't be selected, choose the first one */
167 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
169 else if(imageselecttype
== IST_SIZE
) {
170 POINT size
= {pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
};
172 for(i
=4; i
>=0; i
--) {
173 PTHEME_PROPERTY fileProp
=
174 MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
175 if (!fileProp
) continue;
176 if(FAILED(GetThemePosition(hTheme
, iPartId
, iStateId
, i
+ TMT_MINSIZE1
, &reqsize
))) {
177 /* fall back to size of Nth image */
178 WCHAR szPath
[MAX_PATH
];
179 int imagelayout
= IL_HORIZONTAL
;
185 lstrcpynW(szPath
, fileProp
->lpValue
,
186 min(fileProp
->dwValueLen
+1, sizeof(szPath
)/sizeof(szPath
[0])));
187 hBmp
= MSSTYLES_LoadBitmap(hTheme
, szPath
, &hasAlpha
);
190 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
191 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
193 GetObjectW(hBmp
, sizeof(bmp
), &bmp
);
194 if(imagelayout
== IL_VERTICAL
) {
195 reqsize
.x
= bmp
.bmWidth
;
196 reqsize
.y
= bmp
.bmHeight
/imagecount
;
199 reqsize
.x
= bmp
.bmWidth
/imagecount
;
200 reqsize
.y
= bmp
.bmHeight
;
203 if(reqsize
.x
<= size
.x
&& reqsize
.y
<= size
.y
) {
204 TRACE("Using image size %dx%d, image %d\n", reqsize
.x
, reqsize
.y
, i
+ TMT_IMAGEFILE1
);
208 /* If an image couldn't be selected, choose the smallest one */
209 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
214 /***********************************************************************
217 * Load image for part/state
219 static HRESULT
UXTHEME_LoadImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
,
220 HBITMAP
*hBmp
, RECT
*bmpRect
, BOOL
* hasImageAlpha
)
222 int imagelayout
= IL_HORIZONTAL
;
226 WCHAR szPath
[MAX_PATH
];
227 PTHEME_PROPERTY tp
= UXTHEME_SelectImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, glyph
);
229 FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId
, iStateId
);
230 return E_PROP_ID_UNSUPPORTED
;
232 lstrcpynW(szPath
, tp
->lpValue
, min(tp
->dwValueLen
+1, sizeof(szPath
)/sizeof(szPath
[0])));
233 *hBmp
= MSSTYLES_LoadBitmap(hTheme
, szPath
, hasImageAlpha
);
235 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath
));
236 return HRESULT_FROM_WIN32(GetLastError());
239 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGELAYOUT
, &imagelayout
);
240 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_IMAGECOUNT
, &imagecount
);
242 imagenum
= max (min (imagecount
, iStateId
), 1) - 1;
243 GetObjectW(*hBmp
, sizeof(bmp
), &bmp
);
244 if(imagelayout
== IL_VERTICAL
) {
245 int height
= bmp
.bmHeight
/imagecount
;
247 bmpRect
->right
= bmp
.bmWidth
;
248 bmpRect
->top
= imagenum
* height
;
249 bmpRect
->bottom
= bmpRect
->top
+ height
;
252 int width
= bmp
.bmWidth
/imagecount
;
253 bmpRect
->left
= imagenum
* width
;
254 bmpRect
->right
= bmpRect
->left
+ width
;
256 bmpRect
->bottom
= bmp
.bmHeight
;
261 /***********************************************************************
264 * Pseudo TransparentBlt/StretchBlt
266 static inline BOOL
UXTHEME_StretchBlt(HDC hdcDst
, int nXOriginDst
, int nYOriginDst
, int nWidthDst
, int nHeightDst
,
267 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
268 INT transparent
, COLORREF transcolor
)
270 static const BLENDFUNCTION blendFunc
=
272 AC_SRC_OVER
, /* BlendOp */
274 255, /* SourceConstantAlpha */
275 AC_SRC_ALPHA
/* AlphaFormat */
279 int old_stretch_mode
;
282 old_stretch_mode
= SetStretchBltMode(hdcDst
, HALFTONE
);
283 SetBrushOrgEx(hdcDst
, nXOriginDst
, nYOriginDst
, &old_brush_org
);
285 if (transparent
== ALPHABLEND_BINARY
) {
286 /* Ensure we don't pass any negative values to TransparentBlt */
287 ret
= TransparentBlt(hdcDst
, nXOriginDst
, nYOriginDst
, abs(nWidthDst
), abs(nHeightDst
),
288 hdcSrc
, nXOriginSrc
, nYOriginSrc
, abs(nWidthSrc
), abs(nHeightSrc
),
290 } else if ((transparent
== ALPHABLEND_NONE
) ||
291 !AlphaBlend(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
292 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
295 ret
= StretchBlt(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
296 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
300 SetBrushOrgEx(hdcDst
, old_brush_org
.x
, old_brush_org
.y
, NULL
);
301 SetStretchBltMode(hdcDst
, old_stretch_mode
);
306 /***********************************************************************
309 * Simplify sending same width/height for both source and dest
311 static inline BOOL
UXTHEME_Blt(HDC hdcDest
, int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
312 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
313 INT transparent
, COLORREF transcolor
)
315 return UXTHEME_StretchBlt(hdcDest
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
316 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthDest
, nHeightDest
,
317 transparent
, transcolor
);
320 /***********************************************************************
323 * Stretches or tiles, depending on sizingtype.
325 static inline BOOL
UXTHEME_SizedBlt (HDC hdcDst
, int nXOriginDst
, int nYOriginDst
,
326 int nWidthDst
, int nHeightDst
,
327 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
328 int nWidthSrc
, int nHeightSrc
,
330 INT transparent
, COLORREF transcolor
)
332 if (sizingtype
== ST_TILE
)
337 if (!nWidthSrc
|| !nHeightSrc
) return TRUE
;
339 /* For destination width/height less than or equal to source
340 width/height, do not bother with memory bitmap optimization */
341 if (nWidthSrc
>= nWidthDst
&& nHeightSrc
>= nHeightDst
)
343 int bltWidth
= min (nWidthDst
, nWidthSrc
);
344 int bltHeight
= min (nHeightDst
, nHeightSrc
);
346 return UXTHEME_Blt (hdcDst
, nXOriginDst
, nYOriginDst
, bltWidth
, bltHeight
,
347 hdcSrc
, nXOriginSrc
, nYOriginSrc
,
348 transparent
, transcolor
);
351 /* Create a DC with a bitmap consisting of a tiling of the source
352 bitmap, with standard GDI functions. This is faster than an
353 iteration with UXTHEME_Blt(). */
354 hdcTemp
= CreateCompatibleDC(hdcSrc
);
359 int nWidthTemp
, nHeightTemp
;
360 int xOfs
, xRemaining
;
361 int yOfs
, yRemaining
;
364 /* Calculate temp dimensions of integer multiples of source dimensions */
365 nWidthTemp
= ((nWidthDst
+ nWidthSrc
- 1) / nWidthSrc
) * nWidthSrc
;
366 nHeightTemp
= ((nHeightDst
+ nHeightSrc
- 1) / nHeightSrc
) * nHeightSrc
;
367 bitmapTemp
= CreateCompatibleBitmap(hdcSrc
, nWidthTemp
, nHeightTemp
);
368 bitmapOrig
= SelectObject(hdcTemp
, bitmapTemp
);
370 /* Initial copy of bitmap */
371 BitBlt(hdcTemp
, 0, 0, nWidthSrc
, nHeightSrc
, hdcSrc
, nXOriginSrc
, nYOriginSrc
, SRCCOPY
);
373 /* Extend bitmap in the X direction. Growth of width is exponential */
375 xRemaining
= nWidthTemp
- nWidthSrc
;
376 growSize
= nWidthSrc
;
377 while (xRemaining
> 0)
379 growSize
= min(growSize
, xRemaining
);
380 BitBlt(hdcTemp
, xOfs
, 0, growSize
, nHeightSrc
, hdcTemp
, 0, 0, SRCCOPY
);
382 xRemaining
-= growSize
;
386 /* Extend bitmap in the Y direction. Growth of height is exponential */
388 yRemaining
= nHeightTemp
- nHeightSrc
;
389 growSize
= nHeightSrc
;
390 while (yRemaining
> 0)
392 growSize
= min(growSize
, yRemaining
);
393 BitBlt(hdcTemp
, 0, yOfs
, nWidthTemp
, growSize
, hdcTemp
, 0, 0, SRCCOPY
);
395 yRemaining
-= growSize
;
399 /* Use temporary hdc for source */
400 result
= UXTHEME_Blt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
402 transparent
, transcolor
);
404 SelectObject(hdcTemp
, bitmapOrig
);
405 DeleteObject(bitmapTemp
);
412 return UXTHEME_StretchBlt (hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
413 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
414 transparent
, transcolor
);
418 /* Get transparency parameters passed to UXTHEME_StretchBlt() - the parameters
419 * depend on whether the image has full alpha or whether it is
420 * color-transparent or just opaque. */
421 static inline void get_transparency (HTHEME hTheme
, int iPartId
, int iStateId
,
422 BOOL hasImageAlpha
, INT
* transparent
,
423 COLORREF
* transparentcolor
, BOOL glyph
)
427 *transparent
= ALPHABLEND_FULL
;
428 *transparentcolor
= RGB (255, 0, 255);
433 GetThemeBool(hTheme
, iPartId
, iStateId
,
434 glyph
? TMT_GLYPHTRANSPARENT
: TMT_TRANSPARENT
, &trans
);
436 *transparent
= ALPHABLEND_BINARY
;
437 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
,
438 glyph
? TMT_GLYPHTRANSPARENTCOLOR
: TMT_TRANSPARENTCOLOR
,
439 transparentcolor
))) {
440 /* If image is transparent, but no color was specified, use magenta */
441 *transparentcolor
= RGB(255, 0, 255);
445 *transparent
= ALPHABLEND_NONE
;
449 /***********************************************************************
450 * UXTHEME_DrawImageGlyph
452 * Draw an imagefile glyph
454 static HRESULT
UXTHEME_DrawImageGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
455 int iStateId
, RECT
*pRect
,
456 const DTBGOPTS
*pOptions
)
459 HBITMAP bmpSrc
= NULL
;
461 HGDIOBJ oldSrc
= NULL
;
463 INT transparent
= FALSE
;
464 COLORREF transparentcolor
;
465 int valign
= VA_CENTER
;
466 int halign
= HA_CENTER
;
472 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, TRUE
,
473 &bmpSrc
, &rcSrc
, &hasAlpha
);
474 if(FAILED(hr
)) return hr
;
475 hdcSrc
= CreateCompatibleDC(hdc
);
477 hr
= HRESULT_FROM_WIN32(GetLastError());
480 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
482 dstSize
.x
= pRect
->right
-pRect
->left
;
483 dstSize
.y
= pRect
->bottom
-pRect
->top
;
484 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
485 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
487 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
488 &transparentcolor
, TRUE
);
489 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
490 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
492 topleft
.x
= pRect
->left
;
493 topleft
.y
= pRect
->top
;
494 if(halign
== HA_CENTER
) topleft
.x
+= (dstSize
.x
/2)-(srcSize
.x
/2);
495 else if(halign
== HA_RIGHT
) topleft
.x
+= dstSize
.x
-srcSize
.x
;
496 if(valign
== VA_CENTER
) topleft
.y
+= (dstSize
.y
/2)-(srcSize
.y
/2);
497 else if(valign
== VA_BOTTOM
) topleft
.y
+= dstSize
.y
-srcSize
.y
;
499 if(!UXTHEME_Blt(hdc
, topleft
.x
, topleft
.y
, srcSize
.x
, srcSize
.y
,
500 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
501 transparent
, transparentcolor
)) {
502 hr
= HRESULT_FROM_WIN32(GetLastError());
505 SelectObject(hdcSrc
, oldSrc
);
510 /***********************************************************************
511 * UXTHEME_DrawImageGlyph
513 * Draw glyph on top of background, if appropriate
515 static HRESULT
UXTHEME_DrawGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
516 int iStateId
, RECT
*pRect
,
517 const DTBGOPTS
*pOptions
)
519 int glyphtype
= GT_NONE
;
521 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_GLYPHTYPE
, &glyphtype
);
523 if(glyphtype
== GT_IMAGEGLYPH
) {
524 return UXTHEME_DrawImageGlyph(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pOptions
);
526 else if(glyphtype
== GT_FONTGLYPH
) {
527 /* I don't know what a font glyph is, I've never seen it used in any themes */
528 FIXME("Font glyph\n");
533 /***********************************************************************
534 * get_image_part_size
536 * Used by GetThemePartSize and UXTHEME_DrawImageBackground
538 static HRESULT
get_image_part_size (HTHEME hTheme
, HDC hdc
, int iPartId
,
539 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
547 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, prc
, FALSE
,
548 &bmpSrc
, &rcSrc
, &hasAlpha
);
549 if (FAILED(hr
)) return hr
;
559 int sizingtype
= ST_STRETCH
;
560 BOOL uniformsizing
= FALSE
;
562 CopyRect(&rcDst
, prc
);
564 dstSize
.x
= rcDst
.right
-rcDst
.left
;
565 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
566 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
567 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
569 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_UNIFORMSIZING
, &uniformsizing
);
571 /* Scale height and width equally */
572 if (dstSize
.x
*srcSize
.y
< dstSize
.y
*srcSize
.x
)
574 dstSize
.y
= MulDiv (srcSize
.y
, dstSize
.x
, srcSize
.x
);
575 rcDst
.bottom
= rcDst
.top
+ dstSize
.y
;
579 dstSize
.x
= MulDiv (srcSize
.x
, dstSize
.y
, srcSize
.y
);
580 rcDst
.right
= rcDst
.left
+ dstSize
.x
;
584 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
585 if(sizingtype
== ST_TRUESIZE
) {
586 int truesizestretchmark
= 100;
588 if(dstSize
.x
< 0 || dstSize
.y
< 0) {
589 BOOL mirrorimage
= TRUE
;
590 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_MIRRORIMAGE
, &mirrorimage
);
593 rcDst
.left
+= dstSize
.x
;
594 rcDst
.right
+= dstSize
.x
;
597 rcDst
.top
+= dstSize
.y
;
598 rcDst
.bottom
+= dstSize
.y
;
602 /* Whatever TrueSizeStretchMark does - it does not seem to
603 * be what's outlined below. It appears as if native
604 * uxtheme always stretches if dest is smaller than source
605 * (ie as if TrueSizeStretchMark==100 with the code below) */
607 /* Only stretch when target exceeds source by truesizestretchmark percent */
608 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_TRUESIZESTRETCHMARK
, &truesizestretchmark
);
610 if(dstSize
.x
< 0 || dstSize
.y
< 0 ||
611 (MulDiv(srcSize
.x
, 100, dstSize
.x
) > truesizestretchmark
&&
612 MulDiv(srcSize
.y
, 100, dstSize
.y
) > truesizestretchmark
)) {
613 memcpy (psz
, &dstSize
, sizeof (SIZE
));
616 memcpy (psz
, &srcSize
, sizeof (SIZE
));
621 psz
->x
= abs(dstSize
.x
);
622 psz
->y
= abs(dstSize
.y
);
626 /* else fall through */
628 /* FIXME: couldn't figure how native uxtheme computes min size */
630 psz
->x
= rcSrc
.right
- rcSrc
.left
;
631 psz
->y
= rcSrc
.bottom
- rcSrc
.top
;
637 /***********************************************************************
638 * UXTHEME_DrawImageBackground
640 * Draw an imagefile background
642 static HRESULT
UXTHEME_DrawImageBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
643 int iStateId
, RECT
*pRect
,
644 const DTBGOPTS
*pOptions
)
655 int sizingtype
= ST_STRETCH
;
657 COLORREF transparentcolor
= 0;
660 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, FALSE
,
661 &bmpSrc
, &rcSrc
, &hasAlpha
);
662 if(FAILED(hr
)) return hr
;
663 hdcSrc
= CreateCompatibleDC(hdc
);
665 hr
= HRESULT_FROM_WIN32(GetLastError());
668 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
670 CopyRect(&rcDst
, pRect
);
672 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
673 &transparentcolor
, FALSE
);
675 dstSize
.x
= rcDst
.right
-rcDst
.left
;
676 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
677 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
678 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
680 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
681 if(sizingtype
== ST_TRUESIZE
) {
682 int valign
= VA_CENTER
, halign
= HA_CENTER
;
684 get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, pRect
, TS_DRAW
, &drawSize
);
685 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
686 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
688 if (halign
== HA_CENTER
)
689 rcDst
.left
+= (dstSize
.x
/2)-(drawSize
.x
/2);
690 else if (halign
== HA_RIGHT
)
691 rcDst
.left
= rcDst
.right
- drawSize
.x
;
692 if (valign
== VA_CENTER
)
693 rcDst
.top
+= (dstSize
.y
/2)-(drawSize
.y
/2);
694 else if (valign
== VA_BOTTOM
)
695 rcDst
.top
= rcDst
.bottom
- drawSize
.y
;
696 rcDst
.right
= rcDst
.left
+ drawSize
.x
;
697 rcDst
.bottom
= rcDst
.top
+ drawSize
.y
;
698 if(!UXTHEME_StretchBlt(hdc
, rcDst
.left
, rcDst
.top
, drawSize
.x
, drawSize
.y
,
699 hdcSrc
, rcSrc
.left
, rcSrc
.top
, srcSize
.x
, srcSize
.y
,
700 transparent
, transparentcolor
))
701 hr
= HRESULT_FROM_WIN32(GetLastError());
708 dstSize
.x
= abs(dstSize
.x
);
709 dstSize
.y
= abs(dstSize
.y
);
711 GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_SIZINGMARGINS
, NULL
, &sm
);
714 OffsetViewportOrgEx(hdcDst
, rcDst
.left
, rcDst
.top
, &org
);
716 /* Upper left corner */
717 if(!UXTHEME_Blt(hdcDst
, 0, 0, sm
.cxLeftWidth
, sm
.cyTopHeight
,
718 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
719 transparent
, transparentcolor
)) {
720 hr
= HRESULT_FROM_WIN32(GetLastError());
723 /* Upper right corner */
724 if(!UXTHEME_Blt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, 0,
725 sm
.cxRightWidth
, sm
.cyTopHeight
,
726 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
,
727 transparent
, transparentcolor
)) {
728 hr
= HRESULT_FROM_WIN32(GetLastError());
731 /* Lower left corner */
732 if(!UXTHEME_Blt (hdcDst
, 0, dstSize
.y
-sm
.cyBottomHeight
,
733 sm
.cxLeftWidth
, sm
.cyBottomHeight
,
734 hdcSrc
, rcSrc
.left
, rcSrc
.bottom
-sm
.cyBottomHeight
,
735 transparent
, transparentcolor
)) {
736 hr
= HRESULT_FROM_WIN32(GetLastError());
739 /* Lower right corner */
740 if(!UXTHEME_Blt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, dstSize
.y
-sm
.cyBottomHeight
,
741 sm
.cxRightWidth
, sm
.cyBottomHeight
,
742 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
,
743 transparent
, transparentcolor
)) {
744 hr
= HRESULT_FROM_WIN32(GetLastError());
748 if ((sizingtype
== ST_STRETCH
) || (sizingtype
== ST_TILE
)) {
749 int destCenterWidth
= dstSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
750 int srcCenterWidth
= srcSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
751 int destCenterHeight
= dstSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
752 int srcCenterHeight
= srcSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
754 if(destCenterWidth
> 0) {
756 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, 0,
757 destCenterWidth
, sm
.cyTopHeight
,
758 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
,
759 srcCenterWidth
, sm
.cyTopHeight
,
760 sizingtype
, transparent
, transparentcolor
)) {
761 hr
= HRESULT_FROM_WIN32(GetLastError());
765 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, dstSize
.y
-sm
.cyBottomHeight
,
766 destCenterWidth
, sm
.cyBottomHeight
,
767 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
,
768 srcCenterWidth
, sm
.cyBottomHeight
,
769 sizingtype
, transparent
, transparentcolor
)) {
770 hr
= HRESULT_FROM_WIN32(GetLastError());
774 if(destCenterHeight
> 0) {
776 if(!UXTHEME_SizedBlt (hdcDst
, 0, sm
.cyTopHeight
,
777 sm
.cxLeftWidth
, destCenterHeight
,
778 hdcSrc
, rcSrc
.left
, rcSrc
.top
+sm
.cyTopHeight
,
779 sm
.cxLeftWidth
, srcCenterHeight
,
781 transparent
, transparentcolor
)) {
782 hr
= HRESULT_FROM_WIN32(GetLastError());
786 if(!UXTHEME_SizedBlt (hdcDst
, dstSize
.x
-sm
.cxRightWidth
, sm
.cyTopHeight
,
787 sm
.cxRightWidth
, destCenterHeight
,
788 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
+sm
.cyTopHeight
,
789 sm
.cxRightWidth
, srcCenterHeight
,
790 sizingtype
, transparent
, transparentcolor
)) {
791 hr
= HRESULT_FROM_WIN32(GetLastError());
795 if(destCenterHeight
> 0 && destCenterWidth
> 0) {
796 BOOL borderonly
= FALSE
;
797 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_BORDERONLY
, &borderonly
);
800 if(!UXTHEME_SizedBlt (hdcDst
, sm
.cxLeftWidth
, sm
.cyTopHeight
,
801 destCenterWidth
, destCenterHeight
,
802 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
+sm
.cyTopHeight
,
803 srcCenterWidth
, srcCenterHeight
,
804 sizingtype
, transparent
, transparentcolor
)) {
805 hr
= HRESULT_FROM_WIN32(GetLastError());
813 SetViewportOrgEx (hdcDst
, org
.x
, org
.y
, NULL
);
815 SelectObject(hdcSrc
, oldSrc
);
817 CopyRect(pRect
, &rcDst
);
821 /***********************************************************************
822 * UXTHEME_DrawBorderRectangle
824 * Draw the bounding rectangle for a borderfill background
826 static HRESULT
UXTHEME_DrawBorderRectangle(HTHEME hTheme
, HDC hdc
, int iPartId
,
827 int iStateId
, RECT
*pRect
,
828 const DTBGOPTS
*pOptions
)
833 COLORREF bordercolor
= RGB(0,0,0);
836 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
839 ptCorners
[0].x
= pRect
->left
;
840 ptCorners
[0].y
= pRect
->top
;
841 ptCorners
[1].x
= pRect
->right
-1;
842 ptCorners
[1].y
= pRect
->top
;
843 ptCorners
[2].x
= pRect
->right
-1;
844 ptCorners
[2].y
= pRect
->bottom
-1;
845 ptCorners
[3].x
= pRect
->left
;
846 ptCorners
[3].y
= pRect
->bottom
-1;
847 ptCorners
[4].x
= pRect
->left
;
848 ptCorners
[4].y
= pRect
->top
;
850 InflateRect(pRect
, -bordersize
, -bordersize
);
851 if(pOptions
->dwFlags
& DTBG_OMITBORDER
)
853 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_BORDERCOLOR
, &bordercolor
);
854 hPen
= CreatePen(PS_SOLID
, bordersize
, bordercolor
);
856 return HRESULT_FROM_WIN32(GetLastError());
857 oldPen
= SelectObject(hdc
, hPen
);
859 if(!Polyline(hdc
, ptCorners
, 5))
860 hr
= HRESULT_FROM_WIN32(GetLastError());
862 SelectObject(hdc
, oldPen
);
868 /***********************************************************************
869 * UXTHEME_DrawBackgroundFill
871 * Fill a borderfill background rectangle
873 static HRESULT
UXTHEME_DrawBackgroundFill(HTHEME hTheme
, HDC hdc
, int iPartId
,
874 int iStateId
, RECT
*pRect
,
875 const DTBGOPTS
*pOptions
)
878 int filltype
= FT_SOLID
;
880 TRACE("(%d,%d,%d)\n", iPartId
, iStateId
, pOptions
->dwFlags
);
882 if(pOptions
->dwFlags
& DTBG_OMITCONTENT
)
885 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_FILLTYPE
, &filltype
);
887 if(filltype
== FT_SOLID
) {
889 COLORREF fillcolor
= RGB(255,255,255);
891 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_FILLCOLOR
, &fillcolor
);
892 hBrush
= CreateSolidBrush(fillcolor
);
893 if(!FillRect(hdc
, pRect
, hBrush
))
894 hr
= HRESULT_FROM_WIN32(GetLastError());
895 DeleteObject(hBrush
);
897 else if(filltype
== FT_VERTGRADIENT
|| filltype
== FT_HORZGRADIENT
) {
898 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
899 the gradient ratios (no idea how those work)
900 Few themes use this, and the ones I've seen only use 2 colors with
901 a gradient ratio of 0 and 255 respectively
904 COLORREF gradient1
= RGB(0,0,0);
905 COLORREF gradient2
= RGB(255,255,255);
909 FIXME("Gradient implementation not complete\n");
911 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR1
, &gradient1
);
912 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR2
, &gradient2
);
914 vert
[0].x
= pRect
->left
;
915 vert
[0].y
= pRect
->top
;
916 vert
[0].Red
= GetRValue(gradient1
) << 8;
917 vert
[0].Green
= GetGValue(gradient1
) << 8;
918 vert
[0].Blue
= GetBValue(gradient1
) << 8;
919 vert
[0].Alpha
= 0xff00;
921 vert
[1].x
= pRect
->right
;
922 vert
[1].y
= pRect
->bottom
;
923 vert
[1].Red
= GetRValue(gradient2
) << 8;
924 vert
[1].Green
= GetGValue(gradient2
) << 8;
925 vert
[1].Blue
= GetBValue(gradient2
) << 8;
926 vert
[1].Alpha
= 0xff00;
929 gRect
.LowerRight
= 1;
930 GradientFill(hdc
,vert
,2,&gRect
,1,filltype
==FT_HORZGRADIENT
?GRADIENT_FILL_RECT_H
:GRADIENT_FILL_RECT_V
);
932 else if(filltype
== FT_RADIALGRADIENT
) {
933 /* I've never seen this used in a theme */
934 FIXME("Radial gradient\n");
936 else if(filltype
== FT_TILEIMAGE
) {
937 /* I've never seen this used in a theme */
938 FIXME("Tile image\n");
943 /***********************************************************************
944 * UXTHEME_DrawBorderBackground
946 * Draw an imagefile background
948 static HRESULT
UXTHEME_DrawBorderBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
949 int iStateId
, const RECT
*pRect
,
950 const DTBGOPTS
*pOptions
)
955 CopyRect(&rt
, pRect
);
957 hr
= UXTHEME_DrawBorderRectangle(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
960 return UXTHEME_DrawBackgroundFill(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
963 /***********************************************************************
964 * DrawThemeBackgroundEx (UXTHEME.@)
966 HRESULT WINAPI
DrawThemeBackgroundEx(HTHEME hTheme
, HDC hdc
, int iPartId
,
967 int iStateId
, const RECT
*pRect
,
968 const DTBGOPTS
*pOptions
)
971 const DTBGOPTS defaultOpts
= {sizeof(DTBGOPTS
), 0, {0,0,0,0}};
972 const DTBGOPTS
*opts
;
975 int bgtype
= BT_BORDERFILL
;
978 TRACE("(%p,%p,%d,%d,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
,pRect
->left
,pRect
->top
);
982 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
983 if (bgtype
== BT_NONE
) return S_OK
;
985 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
987 if(!opts
) opts
= &defaultOpts
;
989 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
990 clip
= CreateRectRgn(0,0,1,1);
991 hasClip
= GetClipRgn(hdc
, clip
);
993 TRACE("Failed to get original clipping region\n");
995 IntersectClipRect(hdc
, opts
->rcClip
.left
, opts
->rcClip
.top
, opts
->rcClip
.right
, opts
->rcClip
.bottom
);
997 CopyRect(&rt
, pRect
);
999 if(bgtype
== BT_IMAGEFILE
)
1000 hr
= UXTHEME_DrawImageBackground(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
1001 else if(bgtype
== BT_BORDERFILL
)
1002 hr
= UXTHEME_DrawBorderBackground(hTheme
, hdc
, iPartId
, iStateId
, pRect
, opts
);
1004 FIXME("Unknown background type\n");
1005 /* This should never happen, and hence I don't know what to return */
1009 hr
= UXTHEME_DrawGlyph(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
1010 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
1012 SelectClipRgn(hdc
, NULL
);
1013 else if(hasClip
== 1)
1014 SelectClipRgn(hdc
, clip
);
1021 * DrawThemeEdge() implementation
1023 * Since it basically is DrawEdge() with different colors, I copied its code
1024 * from user32's uitools.c.
1045 } EdgeColorMap
[EDGE_NUMCOLORS
] = {
1046 {TMT_EDGELIGHTCOLOR
, COLOR_3DLIGHT
},
1047 {TMT_EDGEHIGHLIGHTCOLOR
, COLOR_BTNHIGHLIGHT
},
1048 {TMT_EDGESHADOWCOLOR
, COLOR_BTNSHADOW
},
1049 {TMT_EDGEDKSHADOWCOLOR
, COLOR_3DDKSHADOW
},
1050 {TMT_EDGEFILLCOLOR
, COLOR_BTNFACE
},
1052 {-1, COLOR_WINDOWFRAME
}
1055 static const signed char LTInnerNormal
[] = {
1057 -1, EDGE_HIGHLIGHT
, EDGE_HIGHLIGHT
, -1,
1058 -1, EDGE_DARKSHADOW
, EDGE_DARKSHADOW
, -1,
1062 static const signed char LTOuterNormal
[] = {
1063 -1, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1064 EDGE_HIGHLIGHT
, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1065 EDGE_DARKSHADOW
, EDGE_LIGHT
, EDGE_SHADOW
, -1,
1066 -1, EDGE_LIGHT
, EDGE_SHADOW
, -1
1069 static const signed char RBInnerNormal
[] = {
1071 -1, EDGE_SHADOW
, EDGE_SHADOW
, -1,
1072 -1, EDGE_LIGHT
, EDGE_LIGHT
, -1,
1076 static const signed char RBOuterNormal
[] = {
1077 -1, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1078 EDGE_SHADOW
, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1079 EDGE_LIGHT
, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1,
1080 -1, EDGE_DARKSHADOW
, EDGE_HIGHLIGHT
, -1
1083 static const signed char LTInnerSoft
[] = {
1085 -1, EDGE_LIGHT
, EDGE_LIGHT
, -1,
1086 -1, EDGE_SHADOW
, EDGE_SHADOW
, -1,
1090 static const signed char LTOuterSoft
[] = {
1091 -1, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1092 EDGE_LIGHT
, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1093 EDGE_SHADOW
, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1,
1094 -1, EDGE_HIGHLIGHT
, EDGE_DARKSHADOW
, -1
1097 #define RBInnerSoft RBInnerNormal /* These are the same */
1098 #define RBOuterSoft RBOuterNormal
1100 static const signed char LTRBOuterMono
[] = {
1101 -1, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1102 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1103 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1104 EDGE_WINDOW
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
, EDGE_WINDOWFRAME
,
1107 static const signed char LTRBInnerMono
[] = {
1109 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1110 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1111 -1, EDGE_WINDOW
, EDGE_WINDOW
, EDGE_WINDOW
,
1114 static const signed char LTRBOuterFlat
[] = {
1115 -1, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1116 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1117 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1118 EDGE_FILL
, EDGE_SHADOW
, EDGE_SHADOW
, EDGE_SHADOW
,
1121 static const signed char LTRBInnerFlat
[] = {
1123 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1124 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1125 -1, EDGE_FILL
, EDGE_FILL
, EDGE_FILL
,
1128 static COLORREF
get_edge_color (int edgeType
, HTHEME theme
, int part
, int state
)
1131 if ((EdgeColorMap
[edgeType
].themeProp
== -1)
1132 || FAILED (GetThemeColor (theme
, part
, state
,
1133 EdgeColorMap
[edgeType
].themeProp
, &col
)))
1134 col
= GetSysColor (EdgeColorMap
[edgeType
].sysColor
);
1138 static inline HPEN
get_edge_pen (int edgeType
, HTHEME theme
, int part
, int state
)
1140 return CreatePen (PS_SOLID
, 1, get_edge_color (edgeType
, theme
, part
, state
));
1143 static inline HBRUSH
get_edge_brush (int edgeType
, HTHEME theme
, int part
, int state
)
1145 return CreateSolidBrush (get_edge_color (edgeType
, theme
, part
, state
));
1148 /***********************************************************************
1151 * Same as DrawEdge invoked with BF_DIAGONAL
1153 static HRESULT
draw_diag_edge (HDC hdc
, HTHEME theme
, int part
, int state
,
1154 const RECT
* rc
, UINT uType
,
1155 UINT uFlags
, LPRECT contentsRect
)
1158 signed char InnerI
, OuterI
;
1159 HPEN InnerPen
, OuterPen
;
1164 int Width
= rc
->right
- rc
->left
;
1165 int Height
= rc
->bottom
- rc
->top
;
1166 int SmallDiam
= Width
> Height
? Height
: Width
;
1167 HRESULT retval
= (((uType
& BDR_INNER
) == BDR_INNER
1168 || (uType
& BDR_OUTER
) == BDR_OUTER
)
1169 && !(uFlags
& (BF_FLAT
|BF_MONO
)) ) ? E_FAIL
: S_OK
;
1170 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
1171 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
1173 /* Init some vars */
1174 OuterPen
= InnerPen
= GetStockObject(NULL_PEN
);
1175 SavePen
= SelectObject(hdc
, InnerPen
);
1176 spx
= spy
= epx
= epy
= 0; /* Satisfy the compiler... */
1178 /* Determine the colors of the edges */
1179 if(uFlags
& BF_MONO
)
1181 InnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1182 OuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1184 else if(uFlags
& BF_FLAT
)
1186 InnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1187 OuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1189 else if(uFlags
& BF_SOFT
)
1191 if(uFlags
& BF_BOTTOM
)
1193 InnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1194 OuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1198 InnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1199 OuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1204 if(uFlags
& BF_BOTTOM
)
1206 InnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1207 OuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1211 InnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1212 OuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1216 if(InnerI
!= -1) InnerPen
= get_edge_pen (InnerI
, theme
, part
, state
);
1217 if(OuterI
!= -1) OuterPen
= get_edge_pen (OuterI
, theme
, part
, state
);
1219 MoveToEx(hdc
, 0, 0, &SavePoint
);
1221 /* Don't ask me why, but this is what is visible... */
1222 /* This must be possible to do much simpler, but I fail to */
1223 /* see the logic in the MS implementation (sigh...). */
1224 /* So, this might look a bit brute force here (and it is), but */
1225 /* it gets the job done;) */
1227 switch(uFlags
& BF_RECT
)
1233 /* Left bottom endpoint */
1235 spx
= epx
+ SmallDiam
;
1237 spy
= epy
- SmallDiam
;
1241 case BF_BOTTOMRIGHT
:
1242 /* Left top endpoint */
1244 spx
= epx
+ SmallDiam
;
1246 spy
= epy
+ SmallDiam
;
1252 case BF_RIGHT
|BF_LEFT
:
1253 case BF_RIGHT
|BF_LEFT
|BF_TOP
:
1254 case BF_BOTTOM
|BF_TOP
:
1255 case BF_BOTTOM
|BF_TOP
|BF_LEFT
:
1256 case BF_BOTTOMRIGHT
|BF_LEFT
:
1257 case BF_BOTTOMRIGHT
|BF_TOP
:
1259 /* Right top endpoint */
1261 epx
= spx
+ SmallDiam
;
1263 epy
= spy
- SmallDiam
;
1267 MoveToEx(hdc
, spx
, spy
, NULL
);
1268 SelectObject(hdc
, OuterPen
);
1269 LineTo(hdc
, epx
, epy
);
1271 SelectObject(hdc
, InnerPen
);
1273 switch(uFlags
& (BF_RECT
|BF_DIAGONAL
))
1275 case BF_DIAGONAL_ENDBOTTOMLEFT
:
1276 case (BF_DIAGONAL
|BF_BOTTOM
):
1278 case (BF_DIAGONAL
|BF_LEFT
):
1279 MoveToEx(hdc
, spx
-1, spy
, NULL
);
1280 LineTo(hdc
, epx
, epy
-1);
1281 Points
[0].x
= spx
-add
;
1283 Points
[1].x
= rc
->left
;
1284 Points
[1].y
= rc
->top
;
1285 Points
[2].x
= epx
+1;
1286 Points
[2].y
= epy
-1-add
;
1287 Points
[3] = Points
[2];
1290 case BF_DIAGONAL_ENDBOTTOMRIGHT
:
1291 MoveToEx(hdc
, spx
-1, spy
, NULL
);
1292 LineTo(hdc
, epx
, epy
+1);
1293 Points
[0].x
= spx
-add
;
1295 Points
[1].x
= rc
->left
;
1296 Points
[1].y
= rc
->bottom
-1;
1297 Points
[2].x
= epx
+1;
1298 Points
[2].y
= epy
+1+add
;
1299 Points
[3] = Points
[2];
1302 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
):
1303 case (BF_DIAGONAL
|BF_BOTTOM
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
1304 case BF_DIAGONAL_ENDTOPRIGHT
:
1305 case (BF_DIAGONAL
|BF_RIGHT
|BF_TOP
|BF_LEFT
):
1306 MoveToEx(hdc
, spx
+1, spy
, NULL
);
1307 LineTo(hdc
, epx
, epy
+1);
1308 Points
[0].x
= epx
-1;
1309 Points
[0].y
= epy
+1+add
;
1310 Points
[1].x
= rc
->right
-1;
1311 Points
[1].y
= rc
->top
+add
;
1312 Points
[2].x
= rc
->right
-1;
1313 Points
[2].y
= rc
->bottom
-1;
1314 Points
[3].x
= spx
+add
;
1318 case BF_DIAGONAL_ENDTOPLEFT
:
1319 MoveToEx(hdc
, spx
, spy
-1, NULL
);
1320 LineTo(hdc
, epx
+1, epy
);
1321 Points
[0].x
= epx
+1+add
;
1322 Points
[0].y
= epy
+1;
1323 Points
[1].x
= rc
->right
-1;
1324 Points
[1].y
= rc
->top
;
1325 Points
[2].x
= rc
->right
-1;
1326 Points
[2].y
= rc
->bottom
-1-add
;
1328 Points
[3].y
= spy
-add
;
1331 case (BF_DIAGONAL
|BF_TOP
):
1332 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
):
1333 case (BF_DIAGONAL
|BF_BOTTOM
|BF_TOP
|BF_LEFT
):
1334 MoveToEx(hdc
, spx
+1, spy
-1, NULL
);
1335 LineTo(hdc
, epx
, epy
);
1336 Points
[0].x
= epx
-1;
1337 Points
[0].y
= epy
+1;
1338 Points
[1].x
= rc
->right
-1;
1339 Points
[1].y
= rc
->top
;
1340 Points
[2].x
= rc
->right
-1;
1341 Points
[2].y
= rc
->bottom
-1-add
;
1342 Points
[3].x
= spx
+add
;
1343 Points
[3].y
= spy
-add
;
1346 case (BF_DIAGONAL
|BF_RIGHT
):
1347 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
):
1348 case (BF_DIAGONAL
|BF_RIGHT
|BF_LEFT
|BF_BOTTOM
):
1349 MoveToEx(hdc
, spx
, spy
, NULL
);
1350 LineTo(hdc
, epx
-1, epy
+1);
1353 Points
[1].x
= rc
->left
;
1354 Points
[1].y
= rc
->top
+add
;
1355 Points
[2].x
= epx
-1-add
;
1356 Points
[2].y
= epy
+1+add
;
1357 Points
[3] = Points
[2];
1361 /* Fill the interior if asked */
1362 if((uFlags
& BF_MIDDLE
) && retval
)
1365 HBRUSH hb
= get_edge_brush ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1366 theme
, part
, state
);
1368 HPEN hp
= get_edge_pen ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1369 theme
, part
, state
);
1370 hbsave
= SelectObject(hdc
, hb
);
1371 hpsave
= SelectObject(hdc
, hp
);
1372 Polygon(hdc
, Points
, 4);
1373 SelectObject(hdc
, hbsave
);
1374 SelectObject(hdc
, hpsave
);
1379 /* Adjust rectangle if asked */
1380 if(uFlags
& BF_ADJUST
)
1382 *contentsRect
= *rc
;
1383 if(uFlags
& BF_LEFT
) contentsRect
->left
+= add
;
1384 if(uFlags
& BF_RIGHT
) contentsRect
->right
-= add
;
1385 if(uFlags
& BF_TOP
) contentsRect
->top
+= add
;
1386 if(uFlags
& BF_BOTTOM
) contentsRect
->bottom
-= add
;
1390 SelectObject(hdc
, SavePen
);
1391 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
1392 if(InnerI
!= -1) DeleteObject (InnerPen
);
1393 if(OuterI
!= -1) DeleteObject (OuterPen
);
1398 /***********************************************************************
1401 * Same as DrawEdge invoked without BF_DIAGONAL
1403 static HRESULT
draw_rect_edge (HDC hdc
, HTHEME theme
, int part
, int state
,
1404 const RECT
* rc
, UINT uType
,
1405 UINT uFlags
, LPRECT contentsRect
)
1407 signed char LTInnerI
, LTOuterI
;
1408 signed char RBInnerI
, RBOuterI
;
1409 HPEN LTInnerPen
, LTOuterPen
;
1410 HPEN RBInnerPen
, RBOuterPen
;
1411 RECT InnerRect
= *rc
;
1418 HRESULT retval
= (((uType
& BDR_INNER
) == BDR_INNER
1419 || (uType
& BDR_OUTER
) == BDR_OUTER
)
1420 && !(uFlags
& (BF_FLAT
|BF_MONO
)) ) ? E_FAIL
: S_OK
;
1422 /* Init some vars */
1423 LTInnerPen
= LTOuterPen
= RBInnerPen
= RBOuterPen
= GetStockObject(NULL_PEN
);
1424 SavePen
= SelectObject(hdc
, LTInnerPen
);
1426 /* Determine the colors of the edges */
1427 if(uFlags
& BF_MONO
)
1429 LTInnerI
= RBInnerI
= LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1430 LTOuterI
= RBOuterI
= LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)];
1432 else if(uFlags
& BF_FLAT
)
1434 LTInnerI
= RBInnerI
= LTRBInnerFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1435 LTOuterI
= RBOuterI
= LTRBOuterFlat
[uType
& (BDR_INNER
|BDR_OUTER
)];
1437 if( LTInnerI
!= -1 ) LTInnerI
= RBInnerI
= EDGE_FILL
;
1439 else if(uFlags
& BF_SOFT
)
1441 LTInnerI
= LTInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1442 LTOuterI
= LTOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1443 RBInnerI
= RBInnerSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1444 RBOuterI
= RBOuterSoft
[uType
& (BDR_INNER
|BDR_OUTER
)];
1448 LTInnerI
= LTInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1449 LTOuterI
= LTOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1450 RBInnerI
= RBInnerNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1451 RBOuterI
= RBOuterNormal
[uType
& (BDR_INNER
|BDR_OUTER
)];
1454 if((uFlags
& BF_BOTTOMLEFT
) == BF_BOTTOMLEFT
) LBpenplus
= 1;
1455 if((uFlags
& BF_TOPRIGHT
) == BF_TOPRIGHT
) RTpenplus
= 1;
1456 if((uFlags
& BF_BOTTOMRIGHT
) == BF_BOTTOMRIGHT
) RBpenplus
= 1;
1457 if((uFlags
& BF_TOPLEFT
) == BF_TOPLEFT
) LTpenplus
= 1;
1459 if(LTInnerI
!= -1) LTInnerPen
= get_edge_pen (LTInnerI
, theme
, part
, state
);
1460 if(LTOuterI
!= -1) LTOuterPen
= get_edge_pen (LTOuterI
, theme
, part
, state
);
1461 if(RBInnerI
!= -1) RBInnerPen
= get_edge_pen (RBInnerI
, theme
, part
, state
);
1462 if(RBOuterI
!= -1) RBOuterPen
= get_edge_pen (RBOuterI
, theme
, part
, state
);
1464 MoveToEx(hdc
, 0, 0, &SavePoint
);
1466 /* Draw the outer edge */
1467 SelectObject(hdc
, LTOuterPen
);
1470 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
1471 LineTo(hdc
, InnerRect
.right
, InnerRect
.top
);
1473 if(uFlags
& BF_LEFT
)
1475 MoveToEx(hdc
, InnerRect
.left
, InnerRect
.top
, NULL
);
1476 LineTo(hdc
, InnerRect
.left
, InnerRect
.bottom
);
1478 SelectObject(hdc
, RBOuterPen
);
1479 if(uFlags
& BF_BOTTOM
)
1481 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.bottom
-1, NULL
);
1482 LineTo(hdc
, InnerRect
.left
-1, InnerRect
.bottom
-1);
1484 if(uFlags
& BF_RIGHT
)
1486 MoveToEx(hdc
, InnerRect
.right
-1, InnerRect
.bottom
-1, NULL
);
1487 LineTo(hdc
, InnerRect
.right
-1, InnerRect
.top
-1);
1490 /* Draw the inner edge */
1491 SelectObject(hdc
, LTInnerPen
);
1494 MoveToEx(hdc
, InnerRect
.left
+LTpenplus
, InnerRect
.top
+1, NULL
);
1495 LineTo(hdc
, InnerRect
.right
-RTpenplus
, InnerRect
.top
+1);
1497 if(uFlags
& BF_LEFT
)
1499 MoveToEx(hdc
, InnerRect
.left
+1, InnerRect
.top
+LTpenplus
, NULL
);
1500 LineTo(hdc
, InnerRect
.left
+1, InnerRect
.bottom
-LBpenplus
);
1502 SelectObject(hdc
, RBInnerPen
);
1503 if(uFlags
& BF_BOTTOM
)
1505 MoveToEx(hdc
, InnerRect
.right
-1-RBpenplus
, InnerRect
.bottom
-2, NULL
);
1506 LineTo(hdc
, InnerRect
.left
-1+LBpenplus
, InnerRect
.bottom
-2);
1508 if(uFlags
& BF_RIGHT
)
1510 MoveToEx(hdc
, InnerRect
.right
-2, InnerRect
.bottom
-1-RBpenplus
, NULL
);
1511 LineTo(hdc
, InnerRect
.right
-2, InnerRect
.top
-1+RTpenplus
);
1514 if( ((uFlags
& BF_MIDDLE
) && retval
) || (uFlags
& BF_ADJUST
) )
1516 int add
= (LTRBInnerMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0)
1517 + (LTRBOuterMono
[uType
& (BDR_INNER
|BDR_OUTER
)] != -1 ? 1 : 0);
1519 if(uFlags
& BF_LEFT
) InnerRect
.left
+= add
;
1520 if(uFlags
& BF_RIGHT
) InnerRect
.right
-= add
;
1521 if(uFlags
& BF_TOP
) InnerRect
.top
+= add
;
1522 if(uFlags
& BF_BOTTOM
) InnerRect
.bottom
-= add
;
1524 if((uFlags
& BF_MIDDLE
) && retval
)
1526 HBRUSH br
= get_edge_brush ((uFlags
& BF_MONO
) ? EDGE_WINDOW
: EDGE_FILL
,
1527 theme
, part
, state
);
1528 FillRect(hdc
, &InnerRect
, br
);
1532 if(uFlags
& BF_ADJUST
)
1533 *contentsRect
= InnerRect
;
1537 SelectObject(hdc
, SavePen
);
1538 MoveToEx(hdc
, SavePoint
.x
, SavePoint
.y
, NULL
);
1539 if(LTInnerI
!= -1) DeleteObject (LTInnerPen
);
1540 if(LTOuterI
!= -1) DeleteObject (LTOuterPen
);
1541 if(RBInnerI
!= -1) DeleteObject (RBInnerPen
);
1542 if(RBOuterI
!= -1) DeleteObject (RBOuterPen
);
1547 /***********************************************************************
1548 * DrawThemeEdge (UXTHEME.@)
1550 * DrawThemeEdge() is pretty similar to the vanilla DrawEdge() - the
1551 * difference is that it does not rely on the system colors alone, but
1552 * also allows color specification in the theme.
1554 HRESULT WINAPI
DrawThemeEdge(HTHEME hTheme
, HDC hdc
, int iPartId
,
1555 int iStateId
, const RECT
*pDestRect
, UINT uEdge
,
1556 UINT uFlags
, RECT
*pContentRect
)
1558 TRACE("%d %d 0x%08x 0x%08x\n", iPartId
, iStateId
, uEdge
, uFlags
);
1562 if(uFlags
& BF_DIAGONAL
)
1563 return draw_diag_edge (hdc
, hTheme
, iPartId
, iStateId
, pDestRect
,
1564 uEdge
, uFlags
, pContentRect
);
1566 return draw_rect_edge (hdc
, hTheme
, iPartId
, iStateId
, pDestRect
,
1567 uEdge
, uFlags
, pContentRect
);
1571 /***********************************************************************
1572 * DrawThemeIcon (UXTHEME.@)
1574 HRESULT WINAPI
DrawThemeIcon(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1575 const RECT
*pRect
, HIMAGELIST himl
, int iImageIndex
)
1577 FIXME("%d %d: stub\n", iPartId
, iStateId
);
1580 return ERROR_CALL_NOT_IMPLEMENTED
;
1583 /***********************************************************************
1584 * DrawThemeText (UXTHEME.@)
1586 HRESULT WINAPI
DrawThemeText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
1587 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
1588 DWORD dwTextFlags2
, const RECT
*pRect
)
1592 HGDIOBJ oldFont
= NULL
;
1595 COLORREF oldTextColor
;
1599 TRACE("%d %d: stub\n", iPartId
, iStateId
);
1603 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
1605 hFont
= CreateFontIndirectW(&logfont
);
1607 TRACE("Failed to create font\n");
1609 CopyRect(&rt
, pRect
);
1611 oldFont
= SelectObject(hdc
, hFont
);
1613 if(dwTextFlags2
& DTT_GRAYED
)
1614 textColor
= GetSysColor(COLOR_GRAYTEXT
);
1616 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TEXTCOLOR
, &textColor
)))
1617 textColor
= GetTextColor(hdc
);
1619 oldTextColor
= SetTextColor(hdc
, textColor
);
1620 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
1621 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
1622 SetBkMode(hdc
, oldBkMode
);
1623 SetTextColor(hdc
, oldTextColor
);
1626 SelectObject(hdc
, oldFont
);
1627 DeleteObject(hFont
);
1632 /***********************************************************************
1633 * GetThemeBackgroundContentRect (UXTHEME.@)
1635 HRESULT WINAPI
GetThemeBackgroundContentRect(HTHEME hTheme
, HDC hdc
, int iPartId
,
1637 const RECT
*pBoundingRect
,
1643 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1647 /* try content margins property... */
1648 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1650 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
1651 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
1652 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
1653 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
1655 /* otherwise, try to determine content rect from the background type and props */
1656 int bgtype
= BT_BORDERFILL
;
1657 *pContentRect
= *pBoundingRect
;
1659 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1660 if(bgtype
== BT_BORDERFILL
) {
1663 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1664 InflateRect(pContentRect
, -bordersize
, -bordersize
);
1665 } else if ((bgtype
== BT_IMAGEFILE
)
1666 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1667 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1668 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
1669 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
1670 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
1671 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
1673 /* If nothing was found, leave unchanged */
1676 TRACE("left:%d,top:%d,right:%d,bottom:%d\n", pContentRect
->left
, pContentRect
->top
, pContentRect
->right
, pContentRect
->bottom
);
1681 /***********************************************************************
1682 * GetThemeBackgroundExtent (UXTHEME.@)
1684 HRESULT WINAPI
GetThemeBackgroundExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1685 int iStateId
, const RECT
*pContentRect
,
1691 TRACE("(%d,%d)\n", iPartId
, iStateId
);
1695 /* try content margins property... */
1696 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
1698 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1699 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1700 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1701 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1703 /* otherwise, try to determine content rect from the background type and props */
1704 int bgtype
= BT_BORDERFILL
;
1705 *pExtentRect
= *pContentRect
;
1707 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1708 if(bgtype
== BT_BORDERFILL
) {
1711 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
1712 InflateRect(pExtentRect
, bordersize
, bordersize
);
1713 } else if ((bgtype
== BT_IMAGEFILE
)
1714 && (SUCCEEDED(hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
,
1715 TMT_SIZINGMARGINS
, NULL
, &margin
)))) {
1716 pExtentRect
->left
= pContentRect
->left
- margin
.cxLeftWidth
;
1717 pExtentRect
->top
= pContentRect
->top
- margin
.cyTopHeight
;
1718 pExtentRect
->right
= pContentRect
->right
+ margin
.cxRightWidth
;
1719 pExtentRect
->bottom
= pContentRect
->bottom
+ margin
.cyBottomHeight
;
1721 /* If nothing was found, leave unchanged */
1724 TRACE("left:%d,top:%d,right:%d,bottom:%d\n", pExtentRect
->left
, pExtentRect
->top
, pExtentRect
->right
, pExtentRect
->bottom
);
1730 static HBITMAP
UXTHEME_DrawThemePartToDib(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, LPCRECT pRect
)
1734 HBITMAP hbmp
, hbmpOld
;
1737 hdcMem
= CreateCompatibleDC(0);
1739 memset(&bmi
, 0, sizeof(bmi
));
1740 bmi
.bmiHeader
.biSize
= sizeof(bmi
.bmiHeader
);
1741 bmi
.bmiHeader
.biWidth
= pRect
->right
;
1742 bmi
.bmiHeader
.biHeight
= -pRect
->bottom
;
1743 bmi
.bmiHeader
.biPlanes
= 1;
1744 bmi
.bmiHeader
.biBitCount
= 32;
1745 hbmp
= CreateDIBSection(hdcMem
, &bmi
, DIB_RGB_COLORS
, NULL
, 0, 0);
1747 hbmpOld
= (HBITMAP
)SelectObject(hdcMem
, hbmp
);
1749 /* FIXME: use an internal function that doesn't do transparent blt */
1750 hbrBack
= CreateSolidBrush(RGB(255,0,255));
1752 FillRect(hdcMem
, pRect
, hbrBack
);
1754 DrawThemeBackground(hTheme
, hdcMem
, iPartId
, iStateId
, pRect
, NULL
);
1756 DeleteObject(hbrBack
);
1757 SelectObject(hdcMem
, hbmpOld
);
1758 DeleteObject(hdcMem
);
1763 #define PT_IN_RECT(lprc,x,y) ( x >= lprc->left && x < lprc->right && \
1764 y >= lprc->top && y < lprc->bottom)
1766 static HRGN
UXTHEME_RegionFromDibBits(RGBQUAD
* pBuffer
, RGBQUAD
* pclrTransparent
, LPCRECT pRect
)
1769 int cMaxRgnRects
, cRgnDataSize
, cRgnRects
;
1772 ULONG clrTransparent
, *pclrCurrent
;
1775 pclrCurrent
= (PULONG
)pBuffer
;
1776 clrTransparent
= *(PULONG
)pclrTransparent
;
1778 /* Create a region and pre-allocate memory enough for 3 spaces in one row*/
1780 cMaxRgnRects
= 4* (pRect
->bottom
-pRect
->top
);
1781 cRgnDataSize
= sizeof(RGNDATA
) + cMaxRgnRects
* sizeof(RECT
);
1783 /* Allocate the region data */
1784 prgnData
= (PRGNDATA
)HeapAlloc(GetProcessHeap(), 0, cRgnDataSize
);
1786 prcCurrent
= (PRECT
)prgnData
->Buffer
;
1788 /* Calculate the region rects */
1790 /* Scan each line of the bitmap */
1791 while(y
<pRect
->bottom
)
1794 /* Scan each pixel */
1795 while (x
<pRect
->right
)
1797 /* Check if the pixel is not transparent and it is in the requested rect */
1798 if(*pclrCurrent
!= clrTransparent
&& PT_IN_RECT(pRect
,x
,y
))
1801 /* Find the end of the opaque row of pixels */
1802 while (x
<pRect
->right
)
1804 if(*pclrCurrent
== clrTransparent
|| !PT_IN_RECT(pRect
,x
,y
))
1810 /* Add the scaned line to the region */
1811 SetRect(prcCurrent
, xstart
, y
,x
,y
+1);
1815 /* Increase the size of the buffer if it is full */
1816 if(cRgnRects
== cMaxRgnRects
)
1819 cRgnDataSize
= sizeof(RGNDATA
) + cMaxRgnRects
* sizeof(RECT
);
1820 prgnData
= (PRGNDATA
)HeapReAlloc(GetProcessHeap(),
1824 prcCurrent
= (RECT
*)prgnData
->Buffer
+ cRgnRects
;
1836 /* Fill the region data header */
1837 prgnData
->rdh
.dwSize
= sizeof(prgnData
->rdh
);
1838 prgnData
->rdh
.iType
= RDH_RECTANGLES
;
1839 prgnData
->rdh
.nCount
= cRgnRects
;
1840 prgnData
->rdh
.nRgnSize
= cRgnDataSize
;
1841 prgnData
->rdh
.rcBound
= *pRect
;
1843 /* Create the region*/
1844 hrgnRet
= ExtCreateRegion (NULL
, cRgnDataSize
, prgnData
);
1846 /* Free the region data*/
1847 HeapFree(GetProcessHeap(),0,prgnData
);
1849 /* return the region*/
1853 HRESULT
UXTHEME_GetImageBackBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, LPCRECT pRect
, HRGN
*pRegion
)
1857 RGBQUAD clrTransparent
= {0xFF,0x0, 0xFF,0x0};
1859 /* Draw the theme part to a dib */
1860 hbmp
= UXTHEME_DrawThemePartToDib(hTheme
, hdc
, iPartId
, iStateId
, pRect
);
1862 /* Retrieve the info of the dib section */
1863 GetObjectW(hbmp
, sizeof (DIBSECTION
), &dib
);
1865 /* Convert the bits of the dib section to a region */
1866 *pRegion
= UXTHEME_RegionFromDibBits((RGBQUAD
*)dib
.dsBm
.bmBits
, &clrTransparent
, pRect
);
1868 /* Free the temp bitmap */
1874 /***********************************************************************
1875 * GetThemeBackgroundRegion (UXTHEME.@)
1877 * Calculate the background region, taking into consideration transparent areas
1878 * of the background image.
1880 HRESULT WINAPI
GetThemeBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
,
1881 int iStateId
, const RECT
*pRect
,
1885 int bgtype
= BT_BORDERFILL
;
1887 TRACE("(%p,%p,%d,%d)\n", hTheme
, hdc
, iPartId
, iStateId
);
1890 if(!pRect
|| !pRegion
)
1893 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1894 if(bgtype
== BT_IMAGEFILE
) {
1895 hr
= UXTHEME_GetImageBackBackgroundRegion(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pRegion
);
1897 else if(bgtype
== BT_BORDERFILL
) {
1898 *pRegion
= CreateRectRgn(pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
1900 hr
= HRESULT_FROM_WIN32(GetLastError());
1903 FIXME("Unknown background type\n");
1904 /* This should never happen, and hence I don't know what to return */
1910 /* compute part size for "borderfill" backgrounds */
1911 static HRESULT
get_border_background_size (HTHEME hTheme
, int iPartId
,
1912 int iStateId
, THEMESIZE eSize
, POINT
* psz
)
1917 if (SUCCEEDED (hr
= GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
,
1920 psz
->x
= psz
->y
= 2*bordersize
;
1921 if (eSize
!= TS_MIN
)
1930 /***********************************************************************
1931 * GetThemePartSize (UXTHEME.@)
1933 HRESULT WINAPI
GetThemePartSize(HTHEME hTheme
, HDC hdc
, int iPartId
,
1934 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
1937 int bgtype
= BT_BORDERFILL
;
1939 POINT size
= {1, 1};
1944 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
1945 if (bgtype
== BT_NONE
)
1947 else if(bgtype
== BT_IMAGEFILE
)
1948 hr
= get_image_part_size (hTheme
, hdc
, iPartId
, iStateId
, prc
, eSize
, &size
);
1949 else if(bgtype
== BT_BORDERFILL
)
1950 hr
= get_border_background_size (hTheme
, iPartId
, iStateId
, eSize
, &size
);
1952 FIXME("Unknown background type\n");
1953 /* This should never happen, and hence I don't know what to return */
1962 /***********************************************************************
1963 * GetThemeTextExtent (UXTHEME.@)
1965 HRESULT WINAPI
GetThemeTextExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
1966 int iStateId
, LPCWSTR pszText
, int iCharCount
,
1967 DWORD dwTextFlags
, const RECT
*pBoundingRect
,
1972 HGDIOBJ oldFont
= NULL
;
1974 RECT rt
= {0,0,0xFFFF,0xFFFF};
1976 TRACE("%d %d: stub\n", iPartId
, iStateId
);
1981 CopyRect(&rt
, pBoundingRect
);
1983 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
1985 hFont
= CreateFontIndirectW(&logfont
);
1987 TRACE("Failed to create font\n");
1990 oldFont
= SelectObject(hdc
, hFont
);
1992 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
|DT_CALCRECT
);
1993 CopyRect(pExtentRect
, &rt
);
1996 SelectObject(hdc
, oldFont
);
1997 DeleteObject(hFont
);
2002 /***********************************************************************
2003 * GetThemeTextMetrics (UXTHEME.@)
2005 HRESULT WINAPI
GetThemeTextMetrics(HTHEME hTheme
, HDC hdc
, int iPartId
,
2006 int iStateId
, TEXTMETRICW
*ptm
)
2010 HGDIOBJ oldFont
= NULL
;
2013 TRACE("(%p, %p, %d, %d)\n", hTheme
, hdc
, iPartId
, iStateId
);
2017 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
2019 hFont
= CreateFontIndirectW(&logfont
);
2021 TRACE("Failed to create font\n");
2024 oldFont
= SelectObject(hdc
, hFont
);
2026 if(!GetTextMetricsW(hdc
, ptm
))
2027 hr
= HRESULT_FROM_WIN32(GetLastError());
2030 SelectObject(hdc
, oldFont
);
2031 DeleteObject(hFont
);
2036 /***********************************************************************
2037 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
2039 BOOL WINAPI
IsThemeBackgroundPartiallyTransparent(HTHEME hTheme
, int iPartId
,
2042 int bgtype
= BT_BORDERFILL
;
2043 RECT rect
= {0, 0, 0, 0};
2048 COLORREF transparentcolor
;
2050 TRACE("(%d,%d)\n", iPartId
, iStateId
);
2055 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
2057 if (bgtype
!= BT_IMAGEFILE
) return FALSE
;
2059 if(FAILED (UXTHEME_LoadImage (hTheme
, 0, iPartId
, iStateId
, &rect
, FALSE
,
2060 &bmpSrc
, &rcSrc
, &hasAlpha
)))
2063 get_transparency (hTheme
, iPartId
, iStateId
, hasAlpha
, &transparent
,
2064 &transparentcolor
, FALSE
);
2065 return (transparent
!= ALPHABLEND_NONE
);