2 * Win32 5.1 Theme drawing
4 * Copyright (C) 2003 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "uxthemedll.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
40 /***********************************************************************
41 * Defines and global variables
44 DWORD dwDialogTextureFlags
;
46 /***********************************************************************/
48 /***********************************************************************
49 * EnableThemeDialogTexture (UXTHEME.@)
51 HRESULT WINAPI
EnableThemeDialogTexture(HWND hwnd
, DWORD dwFlags
)
53 TRACE("(%p,0x%08lx\n", hwnd
, dwFlags
);
54 dwDialogTextureFlags
= dwFlags
;
58 /***********************************************************************
59 * IsThemeDialogTextureEnabled (UXTHEME.@)
61 BOOL WINAPI
IsThemeDialogTextureEnabled(void)
64 return (dwDialogTextureFlags
& ETDT_ENABLE
) && !(dwDialogTextureFlags
& ETDT_DISABLE
);
67 /***********************************************************************
68 * DrawThemeParentBackground (UXTHEME.@)
70 HRESULT WINAPI
DrawThemeParentBackground(HWND hwnd
, HDC hdc
, RECT
*prc
)
75 TRACE("(%p,%p,%p)\n", hwnd
, hdc
, prc
);
76 hParent
= GetParent(hwnd
);
81 MapWindowPoints(hwnd
, NULL
, (LPPOINT
)&rt
, 2);
84 GetClientRect(hParent
, &rt
);
85 MapWindowPoints(hParent
, NULL
, (LPPOINT
)&rt
, 2);
88 SetViewportOrgEx(hdc
, rt
.left
, rt
.top
, &org
);
90 SendMessageW(hParent
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
91 SendMessageW(hParent
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
93 SetViewportOrgEx(hdc
, org
.x
, org
.y
, NULL
);
98 /***********************************************************************
99 * DrawThemeBackground (UXTHEME.@)
101 HRESULT WINAPI
DrawThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
102 int iStateId
, const RECT
*pRect
,
103 const RECT
*pClipRect
)
106 opts
.dwSize
= sizeof(DTBGOPTS
);
109 opts
.dwFlags
|= DTBG_CLIPRECT
;
110 CopyRect(&opts
.rcClip
, pClipRect
);
112 return DrawThemeBackgroundEx(hTheme
, hdc
, iPartId
, iStateId
, pRect
, &opts
);
115 /***********************************************************************
116 * UXTHEME_SelectImage
118 * Select the image to use
120 PTHEME_PROPERTY
UXTHEME_SelectImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
)
123 int imageselecttype
= IST_NONE
;
127 image
= TMT_GLYPHIMAGEFILE
;
129 image
= TMT_IMAGEFILE
;
131 if((tp
=MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, image
)))
133 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_IMAGESELECTTYPE
, &imageselecttype
);
135 if(imageselecttype
== IST_DPI
) {
137 int screendpi
= GetDeviceCaps(hdc
, LOGPIXELSX
);
138 for(i
=4; i
>=0; i
--) {
140 if(SUCCEEDED(GetThemeInt(hTheme
, iPartId
, iStateId
, i
+ TMT_MINDPI1
, &reqdpi
))) {
141 if(reqdpi
!= 0 && screendpi
>= reqdpi
) {
142 TRACE("Using %d DPI, image %d\n", reqdpi
, i
+ TMT_IMAGEFILE1
);
143 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
147 /* If an image couldnt be selected, choose the first one */
148 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
150 else if(imageselecttype
== IST_SIZE
) {
151 POINT size
= {pRect
->right
-pRect
->left
, pRect
->bottom
-pRect
->top
};
153 for(i
=4; i
>=0; i
--) {
154 if(SUCCEEDED(GetThemePosition(hTheme
, iPartId
, iStateId
, i
+ TMT_MINSIZE1
, &reqsize
))) {
155 if(reqsize
.x
>= size
.x
&& reqsize
.y
>= size
.y
) {
156 TRACE("Using image size %ldx%ld, image %d\n", reqsize
.x
, reqsize
.y
, i
+ TMT_IMAGEFILE1
);
157 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, i
+ TMT_IMAGEFILE1
);
161 /* If an image couldnt be selected, choose the smallest one */
162 return MSSTYLES_FindProperty(hTheme
, iPartId
, iStateId
, TMT_FILENAME
, TMT_IMAGEFILE1
);
167 /***********************************************************************
170 * Load image for part/state
172 HRESULT
UXTHEME_LoadImage(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
, const RECT
*pRect
, BOOL glyph
,
173 HBITMAP
*hBmp
, RECT
*bmpRect
)
175 int imagelayout
= IL_VERTICAL
;
178 WCHAR szPath
[MAX_PATH
];
179 PTHEME_PROPERTY tp
= UXTHEME_SelectImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, glyph
);
181 FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId
, iStateId
);
182 return E_PROP_ID_UNSUPPORTED
;
184 lstrcpynW(szPath
, tp
->lpValue
, min(tp
->dwValueLen
+1, sizeof(szPath
)/sizeof(szPath
[0])));
185 *hBmp
= MSSTYLES_LoadBitmap(hdc
, hTheme
, szPath
);
187 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath
));
188 return HRESULT_FROM_WIN32(GetLastError());
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 int height
= bmp
.bmHeight
/imagecount
;
198 bmpRect
->right
= bmp
.bmWidth
;
199 bmpRect
->top
= (min(imagecount
, iStateId
)-1) * height
;
200 bmpRect
->bottom
= bmpRect
->top
+ height
;
203 int width
= bmp
.bmWidth
/imagecount
;
204 bmpRect
->left
= (min(imagecount
, iStateId
)-1) * width
;
205 bmpRect
->right
= bmpRect
->left
+ width
;
207 bmpRect
->bottom
= bmp
.bmHeight
;
212 /***********************************************************************
215 * Psudo TransparentBlt/StretchBlt
217 static inline BOOL
UXTHEME_StretchBlt(HDC hdcDst
, int nXOriginDst
, int nYOriginDst
, int nWidthDst
, int nHeightDst
,
218 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
, int nWidthSrc
, int nHeightSrc
,
219 BOOL transparent
, COLORREF transcolor
)
222 /* Ensure we dont pass any negative values to TransparentBlt */
223 return TransparentBlt(hdcDst
, nXOriginDst
, nYOriginDst
, abs(nWidthDst
), abs(nHeightDst
),
224 hdcSrc
, nXOriginSrc
, nYOriginSrc
, abs(nWidthSrc
), abs(nHeightSrc
),
227 /* This should be using AlphaBlend */
228 return StretchBlt(hdcDst
, nXOriginDst
, nYOriginDst
, nWidthDst
, nHeightDst
,
229 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthSrc
, nHeightSrc
,
233 /***********************************************************************
236 * Simplify sending same width/height for both source and dest
238 static inline BOOL
UXTHEME_Blt(HDC hdcDest
, int nXOriginDest
, int nYOriginDest
, int nWidthDest
, int nHeightDest
,
239 HDC hdcSrc
, int nXOriginSrc
, int nYOriginSrc
,
240 BOOL transparent
, COLORREF transcolor
)
242 return UXTHEME_StretchBlt(hdcDest
, nXOriginDest
, nYOriginDest
, nWidthDest
, nHeightDest
,
243 hdcSrc
, nXOriginSrc
, nYOriginSrc
, nWidthDest
, nHeightDest
,
244 transparent
, transcolor
);
248 /***********************************************************************
249 * UXTHEME_DrawImageGlyph
251 * Draw an imagefile glyph
253 HRESULT
UXTHEME_DrawImageGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
254 int iStateId
, RECT
*pRect
,
255 const DTBGOPTS
*pOptions
)
258 HBITMAP bmpSrc
= NULL
;
260 HGDIOBJ oldSrc
= NULL
;
262 BOOL transparent
= FALSE
;
263 COLORREF transparentcolor
= 0;
264 int valign
= VA_CENTER
;
265 int halign
= HA_CENTER
;
270 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, TRUE
, &bmpSrc
, &rcSrc
);
271 if(FAILED(hr
)) return hr
;
272 hdcSrc
= CreateCompatibleDC(hdc
);
274 hr
= HRESULT_FROM_WIN32(GetLastError());
275 DeleteObject(bmpSrc
);
278 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
280 dstSize
.x
= pRect
->right
-pRect
->left
;
281 dstSize
.y
= pRect
->bottom
-pRect
->top
;
282 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
283 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
285 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_GLYPHTRANSPARENT
, &transparent
);
287 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GLYPHTRANSPARENTCOLOR
, &transparentcolor
))) {
288 /* If image is transparent, but no color was specified, get the color of the upper left corner */
289 transparentcolor
= GetPixel(hdcSrc
, 0, 0);
292 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_VALIGN
, &valign
);
293 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_HALIGN
, &halign
);
295 topleft
.x
= pRect
->left
;
296 topleft
.y
= pRect
->top
;
297 if(halign
== HA_CENTER
) topleft
.x
+= (dstSize
.x
/2)-(srcSize
.x
/2);
298 else if(halign
== HA_RIGHT
) topleft
.x
+= dstSize
.x
-srcSize
.x
;
299 if(valign
== VA_CENTER
) topleft
.y
+= (dstSize
.y
/2)-(srcSize
.y
/2);
300 else if(valign
== VA_BOTTOM
) topleft
.y
+= dstSize
.y
-srcSize
.y
;
302 if(!UXTHEME_Blt(hdc
, topleft
.x
, topleft
.y
, srcSize
.x
, srcSize
.y
,
303 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
304 transparent
, transparentcolor
)) {
305 hr
= HRESULT_FROM_WIN32(GetLastError());
308 SelectObject(hdcSrc
, oldSrc
);
310 DeleteObject(bmpSrc
);
314 /***********************************************************************
315 * UXTHEME_DrawImageGlyph
317 * Draw glyph on top of background, if appropriate
319 HRESULT
UXTHEME_DrawGlyph(HTHEME hTheme
, HDC hdc
, int iPartId
,
320 int iStateId
, RECT
*pRect
,
321 const DTBGOPTS
*pOptions
)
323 int glyphtype
= GT_NONE
;
325 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_GLYPHTYPE
, &glyphtype
);
327 if(glyphtype
== GT_IMAGEGLYPH
) {
328 return UXTHEME_DrawImageGlyph(hTheme
, hdc
, iPartId
, iStateId
, pRect
, pOptions
);
330 else if(glyphtype
== GT_FONTGLYPH
) {
331 /* I don't know what a font glyph is, I've never seen it used in any themes */
332 FIXME("Font glyph\n");
337 /***********************************************************************
338 * UXTHEME_DrawImageBackground
340 * Draw an imagefile background
342 HRESULT
UXTHEME_DrawImageBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
343 int iStateId
, RECT
*pRect
,
344 const DTBGOPTS
*pOptions
)
354 int sizingtype
= ST_TRUESIZE
;
355 BOOL uniformsizing
= FALSE
;
356 BOOL transparent
= FALSE
;
357 COLORREF transparentcolor
= 0;
359 hr
= UXTHEME_LoadImage(hTheme
, hdc
, iPartId
, iStateId
, pRect
, FALSE
, &bmpSrc
, &rcSrc
);
360 if(FAILED(hr
)) return hr
;
361 hdcSrc
= CreateCompatibleDC(hdc
);
363 hr
= HRESULT_FROM_WIN32(GetLastError());
364 DeleteObject(bmpSrc
);
367 oldSrc
= SelectObject(hdcSrc
, bmpSrc
);
369 CopyRect(&rcDst
, pRect
);
371 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_TRANSPARENT
, &transparent
);
373 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TRANSPARENTCOLOR
, &transparentcolor
))) {
374 /* If image is transparent, but no color was specified, get the color of the upper left corner */
375 transparentcolor
= GetPixel(hdcSrc
, 0, 0);
379 dstSize
.x
= rcDst
.right
-rcDst
.left
;
380 dstSize
.y
= rcDst
.bottom
-rcDst
.top
;
381 srcSize
.x
= rcSrc
.right
-rcSrc
.left
;
382 srcSize
.y
= rcSrc
.bottom
-rcSrc
.top
;
385 /* Scale height and width equally */
386 int widthDiff
= abs(srcSize
.x
-dstSize
.x
);
387 int heightDiff
= abs(srcSize
.y
-dstSize
.x
);
388 if(widthDiff
> heightDiff
) {
389 dstSize
.y
-= widthDiff
-heightDiff
;
390 rcDst
.bottom
= rcDst
.top
+ dstSize
.y
;
392 else if(heightDiff
> widthDiff
) {
393 dstSize
.x
-= heightDiff
-widthDiff
;
394 rcDst
.right
= rcDst
.left
+ dstSize
.x
;
398 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_SIZINGTYPE
, &sizingtype
);
399 if(sizingtype
== ST_TRUESIZE
) {
400 int truesizestretchmark
= 0;
402 if(dstSize
.x
< 0 || dstSize
.y
< 0) {
403 BOOL mirrorimage
= TRUE
;
404 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_MIRRORIMAGE
, &mirrorimage
);
407 rcDst
.left
+= dstSize
.x
;
408 rcDst
.right
+= dstSize
.x
;
411 rcDst
.top
+= dstSize
.y
;
412 rcDst
.bottom
+= dstSize
.y
;
416 /* Only stretch when target exceeds source by truesizestretchmark percent */
417 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_TRUESIZESTRETCHMARK
, &truesizestretchmark
);
418 if(dstSize
.x
< 0 || dstSize
.y
< 0 ||
419 MulDiv(srcSize
.x
, 100, dstSize
.x
) > truesizestretchmark
||
420 MulDiv(srcSize
.y
, 100, dstSize
.y
) > truesizestretchmark
) {
421 if(!UXTHEME_StretchBlt(hdc
, rcDst
.left
, rcDst
.top
, dstSize
.x
, dstSize
.y
,
422 hdcSrc
, rcSrc
.left
, rcSrc
.top
, srcSize
.x
, srcSize
.y
,
423 transparent
, transparentcolor
))
424 hr
= HRESULT_FROM_WIN32(GetLastError());
427 rcDst
.left
+= (dstSize
.x
/2)-(srcSize
.x
/2);
428 rcDst
.top
+= (dstSize
.y
/2)-(srcSize
.y
/2);
429 rcDst
.right
= rcDst
.left
+ srcSize
.x
;
430 rcDst
.bottom
= rcDst
.top
+ srcSize
.y
;
431 if(!UXTHEME_Blt(hdc
, rcDst
.left
, rcDst
.top
, srcSize
.x
, srcSize
.y
,
432 hdcSrc
, rcSrc
.left
, rcSrc
.top
,
433 transparent
, transparentcolor
))
434 hr
= HRESULT_FROM_WIN32(GetLastError());
439 HBITMAP bmpDst
= NULL
;
440 HGDIOBJ oldDst
= NULL
;
443 dstSize
.x
= abs(dstSize
.x
);
444 dstSize
.y
= abs(dstSize
.y
);
446 GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_SIZINGMARGINS
, NULL
, &sm
);
448 hdcDst
= CreateCompatibleDC(hdc
);
450 hr
= HRESULT_FROM_WIN32(GetLastError());
453 bmpDst
= CreateCompatibleBitmap(hdc
, dstSize
.x
, dstSize
.y
);
455 hr
= HRESULT_FROM_WIN32(GetLastError());
458 oldDst
= SelectObject(hdcDst
, bmpDst
);
460 /* Upper left corner */
461 if(!BitBlt(hdcDst
, 0, 0, sm
.cxLeftWidth
, sm
.cyTopHeight
,
462 hdcSrc
, rcSrc
.left
, rcSrc
.top
, SRCCOPY
)) {
463 hr
= HRESULT_FROM_WIN32(GetLastError());
466 /* Upper right corner */
467 if(!BitBlt(hdcDst
, dstSize
.x
-sm
.cxRightWidth
, 0, sm
.cxRightWidth
, sm
.cyTopHeight
,
468 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
, SRCCOPY
)) {
469 hr
= HRESULT_FROM_WIN32(GetLastError());
472 /* Lower left corner */
473 if(!BitBlt(hdcDst
, 0, dstSize
.y
-sm
.cyBottomHeight
, sm
.cxLeftWidth
, sm
.cyBottomHeight
,
474 hdcSrc
, rcSrc
.left
, rcSrc
.bottom
-sm
.cyBottomHeight
, SRCCOPY
)) {
475 hr
= HRESULT_FROM_WIN32(GetLastError());
478 /* Lower right corner */
479 if(!BitBlt(hdcDst
, dstSize
.x
-sm
.cxRightWidth
, dstSize
.y
-sm
.cyBottomHeight
, sm
.cxRightWidth
, sm
.cyBottomHeight
,
480 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
, SRCCOPY
)) {
481 hr
= HRESULT_FROM_WIN32(GetLastError());
485 if(sizingtype
== ST_TILE
) {
487 sizingtype
= ST_STRETCH
; /* Just use stretch for now */
489 if(sizingtype
== ST_STRETCH
) {
490 int destCenterWidth
= dstSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
491 int srcCenterWidth
= srcSize
.x
- (sm
.cxLeftWidth
+ sm
.cxRightWidth
);
492 int destCenterHeight
= dstSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
493 int srcCenterHeight
= srcSize
.y
- (sm
.cyTopHeight
+ sm
.cyBottomHeight
);
495 if(destCenterWidth
> 0) {
497 if(!StretchBlt(hdcDst
, sm
.cxLeftWidth
, 0, destCenterWidth
, sm
.cyTopHeight
,
498 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
, srcCenterWidth
, sm
.cyTopHeight
, SRCCOPY
)) {
499 hr
= HRESULT_FROM_WIN32(GetLastError());
503 if(!StretchBlt(hdcDst
, sm
.cxLeftWidth
, dstSize
.y
-sm
.cyBottomHeight
, destCenterWidth
, sm
.cyBottomHeight
,
504 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.bottom
-sm
.cyBottomHeight
, srcCenterWidth
, sm
.cyTopHeight
, SRCCOPY
)) {
505 hr
= HRESULT_FROM_WIN32(GetLastError());
509 if(destCenterHeight
> 0) {
511 if(!StretchBlt(hdcDst
, 0, sm
.cyTopHeight
, sm
.cxLeftWidth
, destCenterHeight
,
512 hdcSrc
, rcSrc
.left
, rcSrc
.top
+sm
.cyTopHeight
, sm
.cxLeftWidth
, srcCenterHeight
, SRCCOPY
)) {
513 hr
= HRESULT_FROM_WIN32(GetLastError());
517 if(!StretchBlt(hdcDst
, dstSize
.x
-sm
.cxRightWidth
, sm
.cyTopHeight
, sm
.cxRightWidth
, destCenterHeight
,
518 hdcSrc
, rcSrc
.right
-sm
.cxRightWidth
, rcSrc
.top
+sm
.cyTopHeight
, sm
.cxRightWidth
, srcCenterHeight
, SRCCOPY
)) {
519 hr
= HRESULT_FROM_WIN32(GetLastError());
523 if(destCenterHeight
> 0 && destCenterWidth
> 0) {
524 BOOL borderonly
= FALSE
;
525 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_BORDERONLY
, &borderonly
);
528 if(!StretchBlt(hdcDst
, sm
.cxLeftWidth
, sm
.cyTopHeight
, destCenterWidth
, destCenterHeight
,
529 hdcSrc
, rcSrc
.left
+sm
.cxLeftWidth
, rcSrc
.top
+sm
.cyTopHeight
, srcCenterWidth
, srcCenterHeight
, SRCCOPY
)) {
530 hr
= HRESULT_FROM_WIN32(GetLastError());
537 if(!UXTHEME_Blt(hdc
, rcDst
.left
, rcDst
.top
, dstSize
.x
, dstSize
.y
,
539 transparent
, transparentcolor
))
540 hr
= HRESULT_FROM_WIN32(GetLastError());
544 SelectObject(hdcDst
, oldDst
);
547 if(bmpDst
) DeleteObject(bmpDst
);
549 SelectObject(hdcSrc
, oldSrc
);
550 DeleteObject(bmpSrc
);
552 CopyRect(pRect
, &rcDst
);
556 /***********************************************************************
557 * UXTHEME_DrawBorderRectangle
559 * Draw the bounding rectangle for a borderfill background
561 HRESULT
UXTHEME_DrawBorderRectangle(HTHEME hTheme
, HDC hdc
, int iPartId
,
562 int iStateId
, RECT
*pRect
,
563 const DTBGOPTS
*pOptions
)
568 COLORREF bordercolor
= RGB(0,0,0);
571 GetThemeInt(hTheme
, iPartId
, iStateId
, TMT_BORDERSIZE
, &bordersize
);
574 ptCorners
[0].x
= pRect
->left
;
575 ptCorners
[0].y
= pRect
->top
;
576 ptCorners
[1].x
= pRect
->right
;
577 ptCorners
[1].y
= pRect
->top
;
578 ptCorners
[2].x
= pRect
->right
;
579 ptCorners
[2].y
= pRect
->bottom
;
580 ptCorners
[3].x
= pRect
->left
;
581 ptCorners
[3].y
= pRect
->bottom
;
583 InflateRect(pRect
, -bordersize
, -bordersize
);
584 if(pOptions
->dwFlags
& DTBG_OMITBORDER
)
586 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_BORDERCOLOR
, &bordercolor
);
587 hPen
= CreatePen(PS_SOLID
, bordersize
, bordercolor
);
589 return HRESULT_FROM_WIN32(GetLastError());
590 oldPen
= SelectObject(hdc
, hPen
);
592 if(!Polyline(hdc
, ptCorners
, 4))
593 hr
= HRESULT_FROM_WIN32(GetLastError());
595 SelectObject(hdc
, oldPen
);
601 /***********************************************************************
602 * UXTHEME_DrawBorderRectangle
604 * Fill a borderfill background rectangle
606 HRESULT
UXTHEME_DrawBackgroundFill(HTHEME hTheme
, HDC hdc
, int iPartId
,
607 int iStateId
, RECT
*pRect
,
608 const DTBGOPTS
*pOptions
)
611 int filltype
= FT_SOLID
;
613 TRACE("(%d,%d,%ld)\n", iPartId
, iStateId
, pOptions
->dwFlags
);
615 if(pOptions
->dwFlags
& DTBG_OMITCONTENT
)
618 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_FILLTYPE
, &filltype
);
620 if(filltype
== FT_SOLID
) {
622 COLORREF fillcolor
= RGB(255,255,255);
625 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_FILLCOLOR
, &fillcolor
);
626 hBrush
= CreateSolidBrush(fillcolor
);
627 if(!FillRect(hdc
, pRect
, hBrush
))
628 hr
= HRESULT_FROM_WIN32(GetLastError());
629 DeleteObject(hBrush
);
631 else if(filltype
== FT_VERTGRADIENT
|| filltype
== FT_HORZGRADIENT
) {
632 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
633 the gradient ratios (no idea how those work)
634 Few themes use this, and the ones I've seen only use 2 colors with
635 a gradient ratio of 0 and 255 respectivly
638 COLORREF gradient1
= RGB(0,0,0);
639 COLORREF gradient2
= RGB(255,255,255);
645 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR1
, &gradient1
);
646 GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_GRADIENTCOLOR2
, &gradient2
);
648 vert
[0].x
= pRect
->left
;
649 vert
[0].y
= pRect
->top
;
650 vert
[0].Red
= GetRValue(gradient1
) << 8;
651 vert
[0].Green
= GetGValue(gradient1
) << 8;
652 vert
[0].Blue
= GetBValue(gradient1
) << 8;
653 vert
[0].Alpha
= 0x0000;
655 vert
[1].x
= pRect
->right
;
656 vert
[1].y
= pRect
->bottom
;
657 vert
[1].Red
= GetRValue(gradient2
) << 8;
658 vert
[1].Green
= GetGValue(gradient2
) << 8;
659 vert
[1].Blue
= GetBValue(gradient2
) << 8;
660 vert
[1].Alpha
= 0x0000;
663 gRect
.LowerRight
= 1;
664 GradientFill(hdc
,vert
,2,&gRect
,1,filltype
==FT_HORZGRADIENT
?GRADIENT_FILL_RECT_H
:GRADIENT_FILL_RECT_V
);
666 else if(filltype
== FT_RADIALGRADIENT
) {
667 /* I've never seen this used in a theme */
668 FIXME("Radial gradient\n");
670 else if(filltype
== FT_TILEIMAGE
) {
671 /* I've never seen this used in a theme */
672 FIXME("Tile image\n");
677 /***********************************************************************
678 * UXTHEME_DrawImageBackground
680 * Draw an imagefile background
682 HRESULT
UXTHEME_DrawBorderBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
683 int iStateId
, const RECT
*pRect
,
684 const DTBGOPTS
*pOptions
)
689 CopyRect(&rt
, pRect
);
691 hr
= UXTHEME_DrawBorderRectangle(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
694 return UXTHEME_DrawBackgroundFill(hTheme
, hdc
, iPartId
, iStateId
, &rt
, pOptions
);
697 /***********************************************************************
698 * DrawThemeBackgroundEx (UXTHEME.@)
700 HRESULT WINAPI
DrawThemeBackgroundEx(HTHEME hTheme
, HDC hdc
, int iPartId
,
701 int iStateId
, const RECT
*pRect
,
702 const DTBGOPTS
*pOptions
)
705 const DTBGOPTS defaultOpts
= {sizeof(DTBGOPTS
), 0, {0,0,0,0}};
706 const DTBGOPTS
*opts
;
709 int bgtype
= BT_BORDERFILL
;
712 TRACE("(%p,%p,%d,%d,%ld,%ld)\n", hTheme
, hdc
, iPartId
, iStateId
,pRect
->left
,pRect
->top
);
716 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
718 if(!opts
) opts
= &defaultOpts
;
720 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
721 clip
= CreateRectRgn(0,0,1,1);
722 hasClip
= GetClipRgn(hdc
, clip
);
724 TRACE("Failed to get original clipping region\n");
726 IntersectClipRect(hdc
, opts
->rcClip
.left
, opts
->rcClip
.top
, opts
->rcClip
.right
, opts
->rcClip
.bottom
);
728 CopyRect(&rt
, pRect
);
730 GetThemeEnumValue(hTheme
, iPartId
, iStateId
, TMT_BGTYPE
, &bgtype
);
731 if(bgtype
== BT_IMAGEFILE
)
732 hr
= UXTHEME_DrawImageBackground(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
733 else if(bgtype
== BT_BORDERFILL
)
734 hr
= UXTHEME_DrawBorderBackground(hTheme
, hdc
, iPartId
, iStateId
, pRect
, opts
);
736 FIXME("Unknown background type\n");
737 /* This should never happen, and hence I don't know what to return */
741 hr
= UXTHEME_DrawGlyph(hTheme
, hdc
, iPartId
, iStateId
, &rt
, opts
);
742 if(opts
->dwFlags
& DTBG_CLIPRECT
) {
744 SelectClipRgn(hdc
, NULL
);
745 else if(hasClip
== 1)
746 SelectClipRgn(hdc
, clip
);
752 /***********************************************************************
753 * DrawThemeEdge (UXTHEME.@)
755 HRESULT WINAPI
DrawThemeEdge(HTHEME hTheme
, HDC hdc
, int iPartId
,
756 int iStateId
, const RECT
*pDestRect
, UINT uEdge
,
757 UINT uFlags
, RECT
*pContentRect
)
759 FIXME("%d %d 0x%08x 0x%08x: stub\n", iPartId
, iStateId
, uEdge
, uFlags
);
762 return ERROR_CALL_NOT_IMPLEMENTED
;
765 /***********************************************************************
766 * DrawThemeIcon (UXTHEME.@)
768 HRESULT WINAPI
DrawThemeIcon(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
769 const RECT
*pRect
, HIMAGELIST himl
, int iImageIndex
)
771 FIXME("%d %d: stub\n", iPartId
, iStateId
);
774 return ERROR_CALL_NOT_IMPLEMENTED
;
777 /***********************************************************************
778 * DrawThemeText (UXTHEME.@)
780 HRESULT WINAPI
DrawThemeText(HTHEME hTheme
, HDC hdc
, int iPartId
, int iStateId
,
781 LPCWSTR pszText
, int iCharCount
, DWORD dwTextFlags
,
782 DWORD dwTextFlags2
, const RECT
*pRect
)
786 HGDIOBJ oldFont
= NULL
;
789 COLORREF oldTextColor
;
793 TRACE("%d %d: stub\n", iPartId
, iStateId
);
797 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
799 hFont
= CreateFontIndirectW(&logfont
);
801 TRACE("Failed to create font\n");
803 CopyRect(&rt
, pRect
);
805 oldFont
= SelectObject(hdc
, hFont
);
807 if(dwTextFlags2
& DTT_GRAYED
)
808 textColor
= GetSysColor(COLOR_GRAYTEXT
);
810 if(FAILED(GetThemeColor(hTheme
, iPartId
, iStateId
, TMT_TEXTCOLOR
, &textColor
)))
811 textColor
= GetTextColor(hdc
);
813 oldTextColor
= SetTextColor(hdc
, textColor
);
814 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
815 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
);
816 SetBkMode(hdc
, oldBkMode
);
817 SetTextColor(hdc
, oldTextColor
);
820 SelectObject(hdc
, oldFont
);
826 /***********************************************************************
827 * GetThemeBackgroundContentRect (UXTHEME.@)
829 HRESULT WINAPI
GetThemeBackgroundContentRect(HTHEME hTheme
, HDC hdc
, int iPartId
,
831 const RECT
*pBoundingRect
,
837 TRACE("(%d,%d)\n", iPartId
, iStateId
);
841 hr
= GetThemeMargins(hTheme
, hdc
, iPartId
, iStateId
, TMT_CONTENTMARGINS
, NULL
, &margin
);
843 TRACE("Margins not found\n");
846 pContentRect
->left
= pBoundingRect
->left
+ margin
.cxLeftWidth
;
847 pContentRect
->top
= pBoundingRect
->top
+ margin
.cyTopHeight
;
848 pContentRect
->right
= pBoundingRect
->right
- margin
.cxRightWidth
;
849 pContentRect
->bottom
= pBoundingRect
->bottom
- margin
.cyBottomHeight
;
851 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pContentRect
->left
, pContentRect
->top
, pContentRect
->right
, pContentRect
->bottom
);
856 /***********************************************************************
857 * GetThemeBackgroundExtent (UXTHEME.@)
859 HRESULT WINAPI
GetThemeBackgroundExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
860 int iStateId
, const RECT
*pContentRect
,
863 FIXME("%d %d: stub\n", iPartId
, iStateId
);
866 return ERROR_CALL_NOT_IMPLEMENTED
;
869 /***********************************************************************
870 * GetThemeBackgroundRegion (UXTHEME.@)
872 HRESULT WINAPI
GetThemeBackgroundRegion(HTHEME hTheme
, HDC hdc
, int iPartId
,
873 int iStateId
, const RECT
*pRect
,
876 FIXME("%d %d: stub\n", iPartId
, iStateId
);
879 return ERROR_CALL_NOT_IMPLEMENTED
;
882 /***********************************************************************
883 * GetThemePartSize (UXTHEME.@)
885 HRESULT WINAPI
GetThemePartSize(HTHEME hTheme
, HDC hdc
, int iPartId
,
886 int iStateId
, RECT
*prc
, THEMESIZE eSize
,
889 FIXME("%d %d %d: stub\n", iPartId
, iStateId
, eSize
);
892 return ERROR_CALL_NOT_IMPLEMENTED
;
896 /***********************************************************************
897 * GetThemeTextExtent (UXTHEME.@)
899 HRESULT WINAPI
GetThemeTextExtent(HTHEME hTheme
, HDC hdc
, int iPartId
,
900 int iStateId
, LPCWSTR pszText
, int iCharCount
,
901 DWORD dwTextFlags
, const RECT
*pBoundingRect
,
906 HGDIOBJ oldFont
= NULL
;
908 RECT rt
= {0,0,0xFFFF,0xFFFF};
910 TRACE("%d %d: stub\n", iPartId
, iStateId
);
915 CopyRect(&rt
, pBoundingRect
);
917 hr
= GetThemeFont(hTheme
, hdc
, iPartId
, iStateId
, TMT_FONT
, &logfont
);
919 hFont
= CreateFontIndirectW(&logfont
);
921 TRACE("Failed to create font\n");
924 oldFont
= SelectObject(hdc
, hFont
);
926 DrawTextW(hdc
, pszText
, iCharCount
, &rt
, dwTextFlags
|DT_CALCRECT
);
927 CopyRect(pExtentRect
, &rt
);
930 SelectObject(hdc
, oldFont
);
936 FIXME("%d %d: stub\n", iPartId
, iStateId
);
939 return ERROR_CALL_NOT_IMPLEMENTED
;
942 /***********************************************************************
943 * GetThemeTextMetrics (UXTHEME.@)
945 HRESULT WINAPI
GetThemeTextMetrics(HTHEME hTheme
, HDC hdc
, int iPartId
,
946 int iStateId
, TEXTMETRICW
*ptm
)
948 FIXME("%d %d: stub\n", iPartId
, iStateId
);
951 return ERROR_CALL_NOT_IMPLEMENTED
;
954 /***********************************************************************
955 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
957 BOOL WINAPI
IsThemeBackgroundPartiallyTransparent(HTHEME hTheme
, int iPartId
,
960 BOOL transparent
= FALSE
;
961 TRACE("(%d,%d)\n", iPartId
, iStateId
);
962 GetThemeBool(hTheme
, iPartId
, iStateId
, TMT_TRANSPARENT
, &transparent
);