Add support for the BT_NONE background type.
[wine/multimedia.git] / dlls / uxtheme / draw.c
blobd938cd995adfc05687c6f41b5d801bf67ea9b3d8
1 /*
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "wingdi.h"
30 #include "uxtheme.h"
31 #include "tmschema.h"
33 #include "msstyles.h"
34 #include "uxthemedll.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
40 /***********************************************************************
41 * Defines and global variables
44 extern ATOM atDialogThemeEnabled;
46 /***********************************************************************/
48 /***********************************************************************
49 * EnableThemeDialogTexture (UXTHEME.@)
51 HRESULT WINAPI EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags)
53 static const WCHAR szTab[] = { 'T','a','b',0 };
54 HRESULT hr;
56 TRACE("(%p,0x%08lx\n", hwnd, dwFlags);
57 hr = SetPropW (hwnd, MAKEINTATOMW (atDialogThemeEnabled),
58 (HANDLE)(dwFlags|0x80000000));
59 /* 0x80000000 serves as a "flags set" flag */
60 if (FAILED(hr))
61 return hr;
62 if (dwFlags & ETDT_USETABTEXTURE)
63 return SetWindowTheme (hwnd, NULL, szTab);
64 else
65 return SetWindowTheme (hwnd, NULL, NULL);
66 return S_OK;
69 /***********************************************************************
70 * IsThemeDialogTextureEnabled (UXTHEME.@)
72 BOOL WINAPI IsThemeDialogTextureEnabled(HWND hwnd)
74 DWORD dwDialogTextureFlags;
75 TRACE("(%p)\n", hwnd);
77 dwDialogTextureFlags = (DWORD)GetPropW (hwnd,
78 MAKEINTATOMW (atDialogThemeEnabled));
79 if (dwDialogTextureFlags == 0)
80 /* Means EnableThemeDialogTexture wasn't called for this dialog */
81 return TRUE;
83 return (dwDialogTextureFlags & ETDT_ENABLE) && !(dwDialogTextureFlags & ETDT_DISABLE);
86 /***********************************************************************
87 * DrawThemeParentBackground (UXTHEME.@)
89 HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
91 RECT rt;
92 POINT org;
93 HWND hParent;
94 HRGN clip = NULL;
95 int hasClip = -1;
97 TRACE("(%p,%p,%p)\n", hwnd, hdc, prc);
98 hParent = GetParent(hwnd);
99 if(!hParent)
100 hParent = hwnd;
101 if(prc) {
102 CopyRect(&rt, prc);
103 MapWindowPoints(hwnd, NULL, (LPPOINT)&rt, 2);
105 clip = CreateRectRgn(0,0,1,1);
106 hasClip = GetClipRgn(hdc, clip);
107 if(hasClip == -1)
108 TRACE("Failed to get original clipping region\n");
109 else
110 IntersectClipRect(hdc, prc->left, prc->top, prc->right, prc->bottom);
112 else {
113 GetClientRect(hParent, &rt);
114 MapWindowPoints(hParent, NULL, (LPPOINT)&rt, 2);
117 OffsetViewportOrgEx(hdc, -rt.left, -rt.top, &org);
119 SendMessageW(hParent, WM_ERASEBKGND, (WPARAM)hdc, 0);
120 SendMessageW(hParent, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
122 SetViewportOrgEx(hdc, org.x, org.y, NULL);
123 if(prc) {
124 if(hasClip == 0)
125 SelectClipRgn(hdc, NULL);
126 else if(hasClip == 1)
127 SelectClipRgn(hdc, clip);
128 DeleteObject(clip);
130 return S_OK;
134 /***********************************************************************
135 * DrawThemeBackground (UXTHEME.@)
137 HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
138 int iStateId, const RECT *pRect,
139 const RECT *pClipRect)
141 DTBGOPTS opts;
142 opts.dwSize = sizeof(DTBGOPTS);
143 opts.dwFlags = 0;
144 if(pClipRect) {
145 opts.dwFlags |= DTBG_CLIPRECT;
146 CopyRect(&opts.rcClip, pClipRect);
148 return DrawThemeBackgroundEx(hTheme, hdc, iPartId, iStateId, pRect, &opts);
151 /***********************************************************************
152 * UXTHEME_SelectImage
154 * Select the image to use
156 static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph)
158 PTHEME_PROPERTY tp;
159 int imageselecttype = IST_NONE;
160 int i;
161 int image;
162 if(glyph)
163 image = TMT_GLYPHIMAGEFILE;
164 else
165 image = TMT_IMAGEFILE;
167 if((tp=MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, image)))
168 return tp;
169 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGESELECTTYPE, &imageselecttype);
171 if(imageselecttype == IST_DPI) {
172 int reqdpi = 0;
173 int screendpi = GetDeviceCaps(hdc, LOGPIXELSX);
174 for(i=4; i>=0; i--) {
175 reqdpi = 0;
176 if(SUCCEEDED(GetThemeInt(hTheme, iPartId, iStateId, i + TMT_MINDPI1, &reqdpi))) {
177 if(reqdpi != 0 && screendpi >= reqdpi) {
178 TRACE("Using %d DPI, image %d\n", reqdpi, i + TMT_IMAGEFILE1);
179 return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, i + TMT_IMAGEFILE1);
183 /* If an image couldnt be selected, choose the first one */
184 return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, TMT_IMAGEFILE1);
186 else if(imageselecttype == IST_SIZE) {
187 POINT size = {pRect->right-pRect->left, pRect->bottom-pRect->top};
188 POINT reqsize;
189 for(i=4; i>=0; i--) {
190 if(SUCCEEDED(GetThemePosition(hTheme, iPartId, iStateId, i + TMT_MINSIZE1, &reqsize))) {
191 if(reqsize.x >= size.x && reqsize.y >= size.y) {
192 TRACE("Using image size %ldx%ld, image %d\n", reqsize.x, reqsize.y, i + TMT_IMAGEFILE1);
193 return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, i + TMT_IMAGEFILE1);
197 /* If an image couldnt be selected, choose the smallest one */
198 return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, TMT_IMAGEFILE1);
200 return NULL;
203 /***********************************************************************
204 * UXTHEME_LoadImage
206 * Load image for part/state
208 static HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph,
209 HBITMAP *hBmp, RECT *bmpRect)
211 int imagelayout = IL_VERTICAL;
212 int imagecount = 1;
213 BITMAP bmp;
214 WCHAR szPath[MAX_PATH];
215 PTHEME_PROPERTY tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, pRect, glyph);
216 if(!tp) {
217 FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId, iStateId);
218 return E_PROP_ID_UNSUPPORTED;
220 lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
221 *hBmp = MSSTYLES_LoadBitmap(hdc, hTheme, szPath);
222 if(!*hBmp) {
223 TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));
224 return HRESULT_FROM_WIN32(GetLastError());
227 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGELAYOUT, &imagelayout);
228 GetThemeInt(hTheme, iPartId, iStateId, TMT_IMAGECOUNT, &imagecount);
230 GetObjectW(*hBmp, sizeof(bmp), &bmp);
231 if(imagelayout == IL_VERTICAL) {
232 int height = bmp.bmHeight/imagecount;
233 bmpRect->left = 0;
234 bmpRect->right = bmp.bmWidth;
235 bmpRect->top = (max(min(imagecount, iStateId), 1)-1) * height;
236 bmpRect->bottom = bmpRect->top + height;
238 else {
239 int width = bmp.bmWidth/imagecount;
240 bmpRect->left = (max(min(imagecount, iStateId), 1)-1) * width;
241 bmpRect->right = bmpRect->left + width;
242 bmpRect->top = 0;
243 bmpRect->bottom = bmp.bmHeight;
245 return S_OK;
248 /***********************************************************************
249 * UXTHEME_StretchBlt
251 * Pseudo TransparentBlt/StretchBlt
253 static inline BOOL UXTHEME_StretchBlt(HDC hdcDst, int nXOriginDst, int nYOriginDst, int nWidthDst, int nHeightDst,
254 HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
255 BOOL transparent, COLORREF transcolor)
257 if(transparent) {
258 /* Ensure we don't pass any negative values to TransparentBlt */
259 return TransparentBlt(hdcDst, nXOriginDst, nYOriginDst, abs(nWidthDst), abs(nHeightDst),
260 hdcSrc, nXOriginSrc, nYOriginSrc, abs(nWidthSrc), abs(nHeightSrc),
261 transcolor);
263 /* This should be using AlphaBlend */
264 return StretchBlt(hdcDst, nXOriginDst, nYOriginDst, nWidthDst, nHeightDst,
265 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
266 SRCCOPY);
269 /***********************************************************************
270 * UXTHEME_Blt
272 * Simplify sending same width/height for both source and dest
274 static inline BOOL UXTHEME_Blt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
275 HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
276 BOOL transparent, COLORREF transcolor)
278 return UXTHEME_StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
279 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthDest, nHeightDest,
280 transparent, transcolor);
283 /***********************************************************************
284 * UXTHEME_SizedBlt
286 * Stretches or tiles, depending on sizingtype.
288 static inline BOOL UXTHEME_SizedBlt (HDC hdcDst, int nXOriginDst, int nYOriginDst,
289 int nWidthDst, int nHeightDst,
290 HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
291 int nWidthSrc, int nHeightSrc,
292 int sizingtype)
294 if (sizingtype == ST_TILE)
296 int yOfs = nYOriginDst;
297 int yRemaining = nHeightDst;
298 while (yRemaining > 0)
300 int bltHeight = min (yRemaining, nHeightSrc);
301 int xOfs = nXOriginDst;
302 int xRemaining = nWidthDst;
303 while (xRemaining > 0)
305 int bltWidth = min (xRemaining, nWidthSrc);
306 if (!BitBlt (hdcDst, xOfs, yOfs, bltWidth, bltHeight,
307 hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY))
308 return FALSE;
309 xOfs += nWidthSrc;
310 xRemaining -= nWidthSrc;
312 yOfs += nHeightSrc;
313 yRemaining -= nHeightSrc;
315 return TRUE;
317 else
319 return StretchBlt (hdcDst, nXOriginDst, nYOriginDst, nWidthDst, nHeightDst,
320 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
321 SRCCOPY);
325 /***********************************************************************
326 * UXTHEME_DrawImageGlyph
328 * Draw an imagefile glyph
330 static HRESULT UXTHEME_DrawImageGlyph(HTHEME hTheme, HDC hdc, int iPartId,
331 int iStateId, RECT *pRect,
332 const DTBGOPTS *pOptions)
334 HRESULT hr;
335 HBITMAP bmpSrc = NULL;
336 HDC hdcSrc = NULL;
337 HGDIOBJ oldSrc = NULL;
338 RECT rcSrc;
339 BOOL transparent = FALSE;
340 COLORREF transparentcolor = 0;
341 int valign = VA_CENTER;
342 int halign = HA_CENTER;
343 POINT dstSize;
344 POINT srcSize;
345 POINT topleft;
347 hr = UXTHEME_LoadImage(hTheme, hdc, iPartId, iStateId, pRect, TRUE, &bmpSrc, &rcSrc);
348 if(FAILED(hr)) return hr;
349 hdcSrc = CreateCompatibleDC(hdc);
350 if(!hdcSrc) {
351 hr = HRESULT_FROM_WIN32(GetLastError());
352 DeleteObject(bmpSrc);
353 return hr;
355 oldSrc = SelectObject(hdcSrc, bmpSrc);
357 dstSize.x = pRect->right-pRect->left;
358 dstSize.y = pRect->bottom-pRect->top;
359 srcSize.x = rcSrc.right-rcSrc.left;
360 srcSize.y = rcSrc.bottom-rcSrc.top;
362 GetThemeBool(hTheme, iPartId, iStateId, TMT_GLYPHTRANSPARENT, &transparent);
363 if(transparent) {
364 if(FAILED(GetThemeColor(hTheme, iPartId, iStateId, TMT_GLYPHTRANSPARENTCOLOR, &transparentcolor))) {
365 /* If image is transparent, but no color was specified, use magenta */
366 transparentcolor = RGB(255, 0, 255);
369 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_VALIGN, &valign);
370 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_HALIGN, &halign);
372 topleft.x = pRect->left;
373 topleft.y = pRect->top;
374 if(halign == HA_CENTER) topleft.x += (dstSize.x/2)-(srcSize.x/2);
375 else if(halign == HA_RIGHT) topleft.x += dstSize.x-srcSize.x;
376 if(valign == VA_CENTER) topleft.y += (dstSize.y/2)-(srcSize.y/2);
377 else if(valign == VA_BOTTOM) topleft.y += dstSize.y-srcSize.y;
379 if(!UXTHEME_Blt(hdc, topleft.x, topleft.y, srcSize.x, srcSize.y,
380 hdcSrc, rcSrc.left, rcSrc.top,
381 transparent, transparentcolor)) {
382 hr = HRESULT_FROM_WIN32(GetLastError());
385 SelectObject(hdcSrc, oldSrc);
386 DeleteDC(hdcSrc);
387 DeleteObject(bmpSrc);
388 return hr;
391 /***********************************************************************
392 * UXTHEME_DrawImageGlyph
394 * Draw glyph on top of background, if appropriate
396 static HRESULT UXTHEME_DrawGlyph(HTHEME hTheme, HDC hdc, int iPartId,
397 int iStateId, RECT *pRect,
398 const DTBGOPTS *pOptions)
400 int glyphtype = GT_NONE;
402 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_GLYPHTYPE, &glyphtype);
404 if(glyphtype == GT_IMAGEGLYPH) {
405 return UXTHEME_DrawImageGlyph(hTheme, hdc, iPartId, iStateId, pRect, pOptions);
407 else if(glyphtype == GT_FONTGLYPH) {
408 /* I don't know what a font glyph is, I've never seen it used in any themes */
409 FIXME("Font glyph\n");
411 return S_OK;
414 /***********************************************************************
415 * get_image_part_size
417 * Used by GetThemePartSize and UXTHEME_DrawImageBackground
419 static HRESULT get_image_part_size (HTHEME hTheme, HDC hdc, int iPartId,
420 int iStateId, RECT *prc, THEMESIZE eSize,
421 POINT *psz)
423 HRESULT hr = S_OK;
424 HBITMAP bmpSrc;
425 RECT rcSrc;
427 hr = UXTHEME_LoadImage(hTheme, hdc, iPartId, iStateId, prc, FALSE, &bmpSrc, &rcSrc);
428 if (FAILED(hr)) return hr;
430 switch (eSize)
432 case TS_DRAW:
433 if (prc != NULL)
435 RECT rcDst;
436 POINT dstSize;
437 POINT srcSize;
438 int sizingtype = ST_STRETCH;
439 BOOL uniformsizing = FALSE;
441 CopyRect(&rcDst, prc);
443 dstSize.x = rcDst.right-rcDst.left;
444 dstSize.y = rcDst.bottom-rcDst.top;
445 srcSize.x = rcSrc.right-rcSrc.left;
446 srcSize.y = rcSrc.bottom-rcSrc.top;
448 GetThemeBool(hTheme, iPartId, iStateId, TMT_UNIFORMSIZING, &uniformsizing);
449 if(uniformsizing) {
450 /* Scale height and width equally */
451 int widthDiff = abs(srcSize.x-dstSize.x);
452 int heightDiff = abs(srcSize.y-dstSize.x);
453 if(widthDiff > heightDiff) {
454 dstSize.y -= widthDiff-heightDiff;
455 rcDst.bottom = rcDst.top + dstSize.y;
457 else if(heightDiff > widthDiff) {
458 dstSize.x -= heightDiff-widthDiff;
459 rcDst.right = rcDst.left + dstSize.x;
463 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_SIZINGTYPE, &sizingtype);
464 if(sizingtype == ST_TRUESIZE) {
465 int truesizestretchmark = 0;
467 if(dstSize.x < 0 || dstSize.y < 0) {
468 BOOL mirrorimage = TRUE;
469 GetThemeBool(hTheme, iPartId, iStateId, TMT_MIRRORIMAGE, &mirrorimage);
470 if(mirrorimage) {
471 if(dstSize.x < 0) {
472 rcDst.left += dstSize.x;
473 rcDst.right += dstSize.x;
475 if(dstSize.y < 0) {
476 rcDst.top += dstSize.y;
477 rcDst.bottom += dstSize.y;
481 /* Only stretch when target exceeds source by truesizestretchmark percent */
482 GetThemeInt(hTheme, iPartId, iStateId, TMT_TRUESIZESTRETCHMARK, &truesizestretchmark);
483 if(dstSize.x < 0 || dstSize.y < 0 ||
484 MulDiv(srcSize.x, 100, dstSize.x) > truesizestretchmark ||
485 MulDiv(srcSize.y, 100, dstSize.y) > truesizestretchmark) {
486 memcpy (psz, &dstSize, sizeof (SIZE));
488 else {
489 memcpy (psz, &srcSize, sizeof (SIZE));
492 else
494 psz->x = abs(dstSize.x);
495 psz->y = abs(dstSize.y);
497 break;
499 /* else fall through */
500 case TS_MIN:
501 /* FIXME: couldn't figure how native uxtheme computes min size */
502 case TS_TRUE:
503 psz->x = rcSrc.right - rcSrc.left;
504 psz->y = rcSrc.bottom - rcSrc.top;
505 break;
507 return hr;
510 /***********************************************************************
511 * UXTHEME_DrawImageBackground
513 * Draw an imagefile background
515 static HRESULT UXTHEME_DrawImageBackground(HTHEME hTheme, HDC hdc, int iPartId,
516 int iStateId, RECT *pRect,
517 const DTBGOPTS *pOptions)
519 HRESULT hr = S_OK;
520 HBITMAP bmpSrc;
521 HGDIOBJ oldSrc;
522 HDC hdcSrc;
523 RECT rcSrc;
524 RECT rcDst;
525 POINT dstSize;
526 POINT srcSize;
527 POINT drawSize;
528 int sizingtype = ST_STRETCH;
529 BOOL transparent = FALSE;
530 COLORREF transparentcolor = 0;
532 hr = UXTHEME_LoadImage(hTheme, hdc, iPartId, iStateId, pRect, FALSE, &bmpSrc, &rcSrc);
533 if(FAILED(hr)) return hr;
534 hdcSrc = CreateCompatibleDC(hdc);
535 if(!hdcSrc) {
536 hr = HRESULT_FROM_WIN32(GetLastError());
537 DeleteObject(bmpSrc);
538 return hr;
540 oldSrc = SelectObject(hdcSrc, bmpSrc);
542 CopyRect(&rcDst, pRect);
544 GetThemeBool(hTheme, iPartId, iStateId, TMT_TRANSPARENT, &transparent);
545 if(transparent) {
546 if(FAILED(GetThemeColor(hTheme, iPartId, iStateId, TMT_TRANSPARENTCOLOR, &transparentcolor))) {
547 /* If image is transparent, but no color was specified, get the color of the upper left corner */
548 transparentcolor = GetPixel(hdcSrc, 0, 0);
552 dstSize.x = rcDst.right-rcDst.left;
553 dstSize.y = rcDst.bottom-rcDst.top;
554 srcSize.x = rcSrc.right-rcSrc.left;
555 srcSize.y = rcSrc.bottom-rcSrc.top;
557 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_SIZINGTYPE, &sizingtype);
558 if(sizingtype == ST_TRUESIZE) {
559 get_image_part_size (hTheme, hdc, iPartId, iStateId, pRect, TS_DRAW, &drawSize);
560 rcDst.left += (dstSize.x/2)-(drawSize.x/2);
561 rcDst.top += (dstSize.y/2)-(drawSize.y/2);
562 rcDst.right = rcDst.left + drawSize.x;
563 rcDst.bottom = rcDst.top + drawSize.y;
564 if(!UXTHEME_StretchBlt(hdc, rcDst.left, rcDst.top, drawSize.x, drawSize.y,
565 hdcSrc, rcSrc.left, rcSrc.top, srcSize.x, srcSize.y,
566 transparent, transparentcolor))
567 hr = HRESULT_FROM_WIN32(GetLastError());
569 else {
570 HDC hdcDst = NULL;
571 HBITMAP bmpDst = NULL;
572 HGDIOBJ oldDst = NULL;
573 MARGINS sm;
575 dstSize.x = abs(dstSize.x);
576 dstSize.y = abs(dstSize.y);
578 GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_SIZINGMARGINS, NULL, &sm);
580 hdcDst = CreateCompatibleDC(hdc);
581 if(!hdcDst) {
582 hr = HRESULT_FROM_WIN32(GetLastError());
583 goto draw_error;
585 bmpDst = CreateCompatibleBitmap(hdc, dstSize.x, dstSize.y);
586 if(!bmpDst) {
587 hr = HRESULT_FROM_WIN32(GetLastError());
588 goto draw_error;
590 oldDst = SelectObject(hdcDst, bmpDst);
592 /* Upper left corner */
593 if(!BitBlt(hdcDst, 0, 0, sm.cxLeftWidth, sm.cyTopHeight,
594 hdcSrc, rcSrc.left, rcSrc.top, SRCCOPY)) {
595 hr = HRESULT_FROM_WIN32(GetLastError());
596 goto draw_error;
598 /* Upper right corner */
599 if(!BitBlt(hdcDst, dstSize.x-sm.cxRightWidth, 0, sm.cxRightWidth, sm.cyTopHeight,
600 hdcSrc, rcSrc.right-sm.cxRightWidth, rcSrc.top, SRCCOPY)) {
601 hr = HRESULT_FROM_WIN32(GetLastError());
602 goto draw_error;
604 /* Lower left corner */
605 if(!BitBlt(hdcDst, 0, dstSize.y-sm.cyBottomHeight, sm.cxLeftWidth, sm.cyBottomHeight,
606 hdcSrc, rcSrc.left, rcSrc.bottom-sm.cyBottomHeight, SRCCOPY)) {
607 hr = HRESULT_FROM_WIN32(GetLastError());
608 goto draw_error;
610 /* Lower right corner */
611 if(!BitBlt(hdcDst, dstSize.x-sm.cxRightWidth, dstSize.y-sm.cyBottomHeight, sm.cxRightWidth, sm.cyBottomHeight,
612 hdcSrc, rcSrc.right-sm.cxRightWidth, rcSrc.bottom-sm.cyBottomHeight, SRCCOPY)) {
613 hr = HRESULT_FROM_WIN32(GetLastError());
614 goto draw_error;
617 if ((sizingtype == ST_STRETCH) || (sizingtype == ST_TILE)) {
618 int destCenterWidth = dstSize.x - (sm.cxLeftWidth + sm.cxRightWidth);
619 int srcCenterWidth = srcSize.x - (sm.cxLeftWidth + sm.cxRightWidth);
620 int destCenterHeight = dstSize.y - (sm.cyTopHeight + sm.cyBottomHeight);
621 int srcCenterHeight = srcSize.y - (sm.cyTopHeight + sm.cyBottomHeight);
623 if(destCenterWidth > 0) {
624 /* Center top */
625 if(!UXTHEME_SizedBlt(hdcDst, sm.cxLeftWidth, 0, destCenterWidth, sm.cyTopHeight,
626 hdcSrc, rcSrc.left+sm.cxLeftWidth, rcSrc.top, srcCenterWidth, sm.cyTopHeight, sizingtype)) {
627 hr = HRESULT_FROM_WIN32(GetLastError());
628 goto draw_error;
630 /* Center bottom */
631 if(!UXTHEME_SizedBlt(hdcDst, sm.cxLeftWidth, dstSize.y-sm.cyBottomHeight, destCenterWidth, sm.cyBottomHeight,
632 hdcSrc, rcSrc.left+sm.cxLeftWidth, rcSrc.bottom-sm.cyBottomHeight, srcCenterWidth, sm.cyTopHeight, sizingtype)) {
633 hr = HRESULT_FROM_WIN32(GetLastError());
634 goto draw_error;
637 if(destCenterHeight > 0) {
638 /* Left center */
639 if(!UXTHEME_SizedBlt(hdcDst, 0, sm.cyTopHeight, sm.cxLeftWidth, destCenterHeight,
640 hdcSrc, rcSrc.left, rcSrc.top+sm.cyTopHeight, sm.cxLeftWidth, srcCenterHeight, sizingtype)) {
641 hr = HRESULT_FROM_WIN32(GetLastError());
642 goto draw_error;
644 /* Right center */
645 if(!UXTHEME_SizedBlt(hdcDst, dstSize.x-sm.cxRightWidth, sm.cyTopHeight, sm.cxRightWidth, destCenterHeight,
646 hdcSrc, rcSrc.right-sm.cxRightWidth, rcSrc.top+sm.cyTopHeight, sm.cxRightWidth, srcCenterHeight, sizingtype)) {
647 hr = HRESULT_FROM_WIN32(GetLastError());
648 goto draw_error;
651 if(destCenterHeight > 0 && destCenterWidth > 0) {
652 BOOL borderonly = FALSE;
653 GetThemeBool(hTheme, iPartId, iStateId, TMT_BORDERONLY, &borderonly);
654 if(!borderonly) {
655 /* Center */
656 if(!UXTHEME_SizedBlt(hdcDst, sm.cxLeftWidth, sm.cyTopHeight, destCenterWidth, destCenterHeight,
657 hdcSrc, rcSrc.left+sm.cxLeftWidth, rcSrc.top+sm.cyTopHeight, srcCenterWidth, srcCenterHeight, sizingtype)) {
658 hr = HRESULT_FROM_WIN32(GetLastError());
659 goto draw_error;
665 if(!UXTHEME_Blt(hdc, rcDst.left, rcDst.top, dstSize.x, dstSize.y,
666 hdcDst, 0, 0,
667 transparent, transparentcolor))
668 hr = HRESULT_FROM_WIN32(GetLastError());
670 draw_error:
671 if(hdcDst) {
672 SelectObject(hdcDst, oldDst);
673 DeleteDC(hdcDst);
675 if(bmpDst) DeleteObject(bmpDst);
677 SelectObject(hdcSrc, oldSrc);
678 DeleteObject(bmpSrc);
679 DeleteDC(hdcSrc);
680 CopyRect(pRect, &rcDst);
681 return hr;
684 /***********************************************************************
685 * UXTHEME_DrawBorderRectangle
687 * Draw the bounding rectangle for a borderfill background
689 static HRESULT UXTHEME_DrawBorderRectangle(HTHEME hTheme, HDC hdc, int iPartId,
690 int iStateId, RECT *pRect,
691 const DTBGOPTS *pOptions)
693 HRESULT hr = S_OK;
694 HPEN hPen;
695 HGDIOBJ oldPen;
696 COLORREF bordercolor = RGB(0,0,0);
697 int bordersize = 1;
699 GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE, &bordersize);
700 if(bordersize > 0) {
701 POINT ptCorners[5];
702 ptCorners[0].x = pRect->left;
703 ptCorners[0].y = pRect->top;
704 ptCorners[1].x = pRect->right-1;
705 ptCorners[1].y = pRect->top;
706 ptCorners[2].x = pRect->right-1;
707 ptCorners[2].y = pRect->bottom-1;
708 ptCorners[3].x = pRect->left;
709 ptCorners[3].y = pRect->bottom-1;
710 ptCorners[4].x = pRect->left;
711 ptCorners[4].y = pRect->top;
713 InflateRect(pRect, -bordersize, -bordersize);
714 if(pOptions->dwFlags & DTBG_OMITBORDER)
715 return S_OK;
716 GetThemeColor(hTheme, iPartId, iStateId, TMT_BORDERCOLOR, &bordercolor);
717 hPen = CreatePen(PS_SOLID, bordersize, bordercolor);
718 if(!hPen)
719 return HRESULT_FROM_WIN32(GetLastError());
720 oldPen = SelectObject(hdc, hPen);
722 if(!Polyline(hdc, ptCorners, 5))
723 hr = HRESULT_FROM_WIN32(GetLastError());
725 SelectObject(hdc, oldPen);
726 DeleteObject(hPen);
728 return hr;
731 /***********************************************************************
732 * UXTHEME_DrawBackgroundFill
734 * Fill a borderfill background rectangle
736 static HRESULT UXTHEME_DrawBackgroundFill(HTHEME hTheme, HDC hdc, int iPartId,
737 int iStateId, RECT *pRect,
738 const DTBGOPTS *pOptions)
740 HRESULT hr = S_OK;
741 int filltype = FT_SOLID;
743 TRACE("(%d,%d,%ld)\n", iPartId, iStateId, pOptions->dwFlags);
745 if(pOptions->dwFlags & DTBG_OMITCONTENT)
746 return S_OK;
748 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_FILLTYPE, &filltype);
750 if(filltype == FT_SOLID) {
751 HBRUSH hBrush;
752 COLORREF fillcolor = RGB(255,255,255);
754 GetThemeColor(hTheme, iPartId, iStateId, TMT_FILLCOLOR, &fillcolor);
755 hBrush = CreateSolidBrush(fillcolor);
756 if(!FillRect(hdc, pRect, hBrush))
757 hr = HRESULT_FROM_WIN32(GetLastError());
758 DeleteObject(hBrush);
760 else if(filltype == FT_VERTGRADIENT || filltype == FT_HORZGRADIENT) {
761 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
762 the gradient ratios (no idea how those work)
763 Few themes use this, and the ones I've seen only use 2 colors with
764 a gradient ratio of 0 and 255 respectivly
767 COLORREF gradient1 = RGB(0,0,0);
768 COLORREF gradient2 = RGB(255,255,255);
769 TRIVERTEX vert[2];
770 GRADIENT_RECT gRect;
772 FIXME("Gradient implementation not complete\n");
774 GetThemeColor(hTheme, iPartId, iStateId, TMT_GRADIENTCOLOR1, &gradient1);
775 GetThemeColor(hTheme, iPartId, iStateId, TMT_GRADIENTCOLOR2, &gradient2);
777 vert[0].x = pRect->left;
778 vert[0].y = pRect->top;
779 vert[0].Red = GetRValue(gradient1) << 8;
780 vert[0].Green = GetGValue(gradient1) << 8;
781 vert[0].Blue = GetBValue(gradient1) << 8;
782 vert[0].Alpha = 0x0000;
784 vert[1].x = pRect->right;
785 vert[1].y = pRect->bottom;
786 vert[1].Red = GetRValue(gradient2) << 8;
787 vert[1].Green = GetGValue(gradient2) << 8;
788 vert[1].Blue = GetBValue(gradient2) << 8;
789 vert[1].Alpha = 0x0000;
791 gRect.UpperLeft = 0;
792 gRect.LowerRight = 1;
793 GradientFill(hdc,vert,2,&gRect,1,filltype==FT_HORZGRADIENT?GRADIENT_FILL_RECT_H:GRADIENT_FILL_RECT_V);
795 else if(filltype == FT_RADIALGRADIENT) {
796 /* I've never seen this used in a theme */
797 FIXME("Radial gradient\n");
799 else if(filltype == FT_TILEIMAGE) {
800 /* I've never seen this used in a theme */
801 FIXME("Tile image\n");
803 return hr;
806 /***********************************************************************
807 * UXTHEME_DrawBorderBackground
809 * Draw an imagefile background
811 static HRESULT UXTHEME_DrawBorderBackground(HTHEME hTheme, HDC hdc, int iPartId,
812 int iStateId, const RECT *pRect,
813 const DTBGOPTS *pOptions)
815 HRESULT hr;
816 RECT rt;
818 CopyRect(&rt, pRect);
820 hr = UXTHEME_DrawBorderRectangle(hTheme, hdc, iPartId, iStateId, &rt, pOptions);
821 if(FAILED(hr))
822 return hr;
823 return UXTHEME_DrawBackgroundFill(hTheme, hdc, iPartId, iStateId, &rt, pOptions);
826 /***********************************************************************
827 * DrawThemeBackgroundEx (UXTHEME.@)
829 HRESULT WINAPI DrawThemeBackgroundEx(HTHEME hTheme, HDC hdc, int iPartId,
830 int iStateId, const RECT *pRect,
831 const DTBGOPTS *pOptions)
833 HRESULT hr;
834 const DTBGOPTS defaultOpts = {sizeof(DTBGOPTS), 0, {0,0,0,0}};
835 const DTBGOPTS *opts;
836 HRGN clip = NULL;
837 int hasClip = -1;
838 int bgtype = BT_BORDERFILL;
839 RECT rt;
841 TRACE("(%p,%p,%d,%d,%ld,%ld)\n", hTheme, hdc, iPartId, iStateId,pRect->left,pRect->top);
842 if(!hTheme)
843 return E_HANDLE;
845 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
846 if (bgtype == BT_NONE) return S_OK;
848 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
849 opts = pOptions;
850 if(!opts) opts = &defaultOpts;
852 if(opts->dwFlags & DTBG_CLIPRECT) {
853 clip = CreateRectRgn(0,0,1,1);
854 hasClip = GetClipRgn(hdc, clip);
855 if(hasClip == -1)
856 TRACE("Failed to get original clipping region\n");
857 else
858 IntersectClipRect(hdc, opts->rcClip.left, opts->rcClip.top, opts->rcClip.right, opts->rcClip.bottom);
860 CopyRect(&rt, pRect);
862 if(bgtype == BT_IMAGEFILE)
863 hr = UXTHEME_DrawImageBackground(hTheme, hdc, iPartId, iStateId, &rt, opts);
864 else if(bgtype == BT_BORDERFILL)
865 hr = UXTHEME_DrawBorderBackground(hTheme, hdc, iPartId, iStateId, pRect, opts);
866 else {
867 FIXME("Unknown background type\n");
868 /* This should never happen, and hence I don't know what to return */
869 hr = E_FAIL;
871 if(SUCCEEDED(hr))
872 hr = UXTHEME_DrawGlyph(hTheme, hdc, iPartId, iStateId, &rt, opts);
873 if(opts->dwFlags & DTBG_CLIPRECT) {
874 if(hasClip == 0)
875 SelectClipRgn(hdc, NULL);
876 else if(hasClip == 1)
877 SelectClipRgn(hdc, clip);
878 DeleteObject(clip);
880 return hr;
883 /***********************************************************************
884 * DrawThemeEdge (UXTHEME.@)
886 HRESULT WINAPI DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId,
887 int iStateId, const RECT *pDestRect, UINT uEdge,
888 UINT uFlags, RECT *pContentRect)
890 FIXME("%d %d 0x%08x 0x%08x: stub\n", iPartId, iStateId, uEdge, uFlags);
891 if(!hTheme)
892 return E_HANDLE;
893 return ERROR_CALL_NOT_IMPLEMENTED;
896 /***********************************************************************
897 * DrawThemeIcon (UXTHEME.@)
899 HRESULT WINAPI DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
900 const RECT *pRect, HIMAGELIST himl, int iImageIndex)
902 FIXME("%d %d: stub\n", iPartId, iStateId);
903 if(!hTheme)
904 return E_HANDLE;
905 return ERROR_CALL_NOT_IMPLEMENTED;
908 /***********************************************************************
909 * DrawThemeText (UXTHEME.@)
911 HRESULT WINAPI DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
912 LPCWSTR pszText, int iCharCount, DWORD dwTextFlags,
913 DWORD dwTextFlags2, const RECT *pRect)
915 HRESULT hr;
916 HFONT hFont = NULL;
917 HGDIOBJ oldFont = NULL;
918 LOGFONTW logfont;
919 COLORREF textColor;
920 COLORREF oldTextColor;
921 int oldBkMode;
922 RECT rt;
924 TRACE("%d %d: stub\n", iPartId, iStateId);
925 if(!hTheme)
926 return E_HANDLE;
928 hr = GetThemeFont(hTheme, hdc, iPartId, iStateId, TMT_FONT, &logfont);
929 if(SUCCEEDED(hr)) {
930 hFont = CreateFontIndirectW(&logfont);
931 if(!hFont)
932 TRACE("Failed to create font\n");
934 CopyRect(&rt, pRect);
935 if(hFont)
936 oldFont = SelectObject(hdc, hFont);
938 if(dwTextFlags2 & DTT_GRAYED)
939 textColor = GetSysColor(COLOR_GRAYTEXT);
940 else {
941 if(FAILED(GetThemeColor(hTheme, iPartId, iStateId, TMT_TEXTCOLOR, &textColor)))
942 textColor = GetTextColor(hdc);
944 oldTextColor = SetTextColor(hdc, textColor);
945 oldBkMode = SetBkMode(hdc, TRANSPARENT);
946 DrawTextW(hdc, pszText, iCharCount, &rt, dwTextFlags);
947 SetBkMode(hdc, oldBkMode);
948 SetTextColor(hdc, oldTextColor);
950 if(hFont) {
951 SelectObject(hdc, oldFont);
952 DeleteObject(hFont);
954 return S_OK;
957 /***********************************************************************
958 * GetThemeBackgroundContentRect (UXTHEME.@)
960 HRESULT WINAPI GetThemeBackgroundContentRect(HTHEME hTheme, HDC hdc, int iPartId,
961 int iStateId,
962 const RECT *pBoundingRect,
963 RECT *pContentRect)
965 MARGINS margin;
966 HRESULT hr;
968 TRACE("(%d,%d)\n", iPartId, iStateId);
969 if(!hTheme)
970 return E_HANDLE;
972 /* try content margins property... */
973 hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_CONTENTMARGINS, NULL, &margin);
974 if(SUCCEEDED(hr)) {
975 pContentRect->left = pBoundingRect->left + margin.cxLeftWidth;
976 pContentRect->top = pBoundingRect->top + margin.cyTopHeight;
977 pContentRect->right = pBoundingRect->right - margin.cxRightWidth;
978 pContentRect->bottom = pBoundingRect->bottom - margin.cyBottomHeight;
979 } else {
980 /* otherwise, try to determine content rect from the background type and props */
981 int bgtype = BT_BORDERFILL;
982 memcpy(pContentRect, pBoundingRect, sizeof(RECT));
984 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
985 if(bgtype == BT_BORDERFILL) {
986 int bordersize = 1;
988 GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE, &bordersize);
989 InflateRect(pContentRect, -bordersize, -bordersize);
990 } else if ((bgtype == BT_IMAGEFILE)
991 && (SUCCEEDED(hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId,
992 TMT_SIZINGMARGINS, NULL, &margin)))) {
993 pContentRect->left = pBoundingRect->left + margin.cxLeftWidth;
994 pContentRect->top = pBoundingRect->top + margin.cyTopHeight;
995 pContentRect->right = pBoundingRect->right - margin.cxRightWidth;
996 pContentRect->bottom = pBoundingRect->bottom - margin.cyBottomHeight;
998 /* If nothing was found, leave unchanged */
1001 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pContentRect->left, pContentRect->top, pContentRect->right, pContentRect->bottom);
1003 return S_OK;
1006 /***********************************************************************
1007 * GetThemeBackgroundExtent (UXTHEME.@)
1009 HRESULT WINAPI GetThemeBackgroundExtent(HTHEME hTheme, HDC hdc, int iPartId,
1010 int iStateId, const RECT *pContentRect,
1011 RECT *pExtentRect)
1013 MARGINS margin;
1014 HRESULT hr;
1016 TRACE("(%d,%d)\n", iPartId, iStateId);
1017 if(!hTheme)
1018 return E_HANDLE;
1020 /* try content margins property... */
1021 hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_CONTENTMARGINS, NULL, &margin);
1022 if(SUCCEEDED(hr)) {
1023 pExtentRect->left = pContentRect->left - margin.cxLeftWidth;
1024 pExtentRect->top = pContentRect->top - margin.cyTopHeight;
1025 pExtentRect->right = pContentRect->right + margin.cxRightWidth;
1026 pExtentRect->bottom = pContentRect->bottom + margin.cyBottomHeight;
1027 } else {
1028 /* otherwise, try to determine content rect from the background type and props */
1029 int bgtype = BT_BORDERFILL;
1030 memcpy(pExtentRect, pContentRect, sizeof(RECT));
1032 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1033 if(bgtype == BT_BORDERFILL) {
1034 int bordersize = 1;
1036 GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE, &bordersize);
1037 InflateRect(pExtentRect, bordersize, bordersize);
1038 } else if ((bgtype == BT_IMAGEFILE)
1039 && (SUCCEEDED(hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId,
1040 TMT_SIZINGMARGINS, NULL, &margin)))) {
1041 pExtentRect->left = pContentRect->left - margin.cxLeftWidth;
1042 pExtentRect->top = pContentRect->top - margin.cyTopHeight;
1043 pExtentRect->right = pContentRect->right + margin.cxRightWidth;
1044 pExtentRect->bottom = pContentRect->bottom + margin.cyBottomHeight;
1046 /* If nothing was found, leave unchanged */
1049 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pExtentRect->left, pExtentRect->top, pExtentRect->right, pExtentRect->bottom);
1051 return S_OK;
1054 /***********************************************************************
1055 * GetThemeBackgroundRegion (UXTHEME.@)
1057 * Calculate the background region, taking into consideration transparent areas
1058 * of the background image.
1060 HRESULT WINAPI GetThemeBackgroundRegion(HTHEME hTheme, HDC hdc, int iPartId,
1061 int iStateId, const RECT *pRect,
1062 HRGN *pRegion)
1064 HRESULT hr = S_OK;
1065 int bgtype = BT_BORDERFILL;
1067 TRACE("(%p,%p,%d,%d)\n", hTheme, hdc, iPartId, iStateId);
1068 if(!hTheme)
1069 return E_HANDLE;
1070 if(!pRect || !pRegion)
1071 return E_POINTER;
1073 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1074 if(bgtype == BT_IMAGEFILE) {
1075 FIXME("Images not handled yet\n");
1076 hr = ERROR_CALL_NOT_IMPLEMENTED;
1078 else if(bgtype == BT_BORDERFILL) {
1079 *pRegion = CreateRectRgn(pRect->left, pRect->top, pRect->right, pRect->bottom);
1080 if(!*pRegion)
1081 hr = HRESULT_FROM_WIN32(GetLastError());
1083 else {
1084 FIXME("Unknown background type\n");
1085 /* This should never happen, and hence I don't know what to return */
1086 hr = E_FAIL;
1088 return hr;
1091 /* compute part size for "borderfill" backgrounds */
1092 HRESULT get_border_background_size (HTHEME hTheme, int iPartId,
1093 int iStateId, THEMESIZE eSize, POINT* psz)
1095 HRESULT hr = S_OK;
1096 int bordersize = 1;
1098 if (SUCCEEDED (hr = GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE,
1099 &bordersize)))
1101 psz->x = psz->y = 2*bordersize;
1102 if (eSize != TS_MIN)
1104 psz->x++;
1105 psz->y++;
1108 return hr;
1111 /***********************************************************************
1112 * GetThemePartSize (UXTHEME.@)
1114 HRESULT WINAPI GetThemePartSize(HTHEME hTheme, HDC hdc, int iPartId,
1115 int iStateId, RECT *prc, THEMESIZE eSize,
1116 SIZE *psz)
1118 int bgtype = BT_BORDERFILL;
1119 HRESULT hr = S_OK;
1120 POINT size = {1, 1};
1122 if(!hTheme)
1123 return E_HANDLE;
1125 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1126 if (bgtype == BT_NONE)
1127 /* do nothing */;
1128 else if(bgtype == BT_IMAGEFILE)
1129 hr = get_image_part_size (hTheme, hdc, iPartId, iStateId, prc, eSize, &size);
1130 else if(bgtype == BT_BORDERFILL)
1131 hr = get_border_background_size (hTheme, iPartId, iStateId, eSize, &size);
1132 else {
1133 FIXME("Unknown background type\n");
1134 /* This should never happen, and hence I don't know what to return */
1135 hr = E_FAIL;
1137 psz->cx = size.x;
1138 psz->cy = size.y;
1139 return hr;
1143 /***********************************************************************
1144 * GetThemeTextExtent (UXTHEME.@)
1146 HRESULT WINAPI GetThemeTextExtent(HTHEME hTheme, HDC hdc, int iPartId,
1147 int iStateId, LPCWSTR pszText, int iCharCount,
1148 DWORD dwTextFlags, const RECT *pBoundingRect,
1149 RECT *pExtentRect)
1151 HRESULT hr;
1152 HFONT hFont = NULL;
1153 HGDIOBJ oldFont = NULL;
1154 LOGFONTW logfont;
1155 RECT rt = {0,0,0xFFFF,0xFFFF};
1157 TRACE("%d %d: stub\n", iPartId, iStateId);
1158 if(!hTheme)
1159 return E_HANDLE;
1161 if(pBoundingRect)
1162 CopyRect(&rt, pBoundingRect);
1164 hr = GetThemeFont(hTheme, hdc, iPartId, iStateId, TMT_FONT, &logfont);
1165 if(SUCCEEDED(hr)) {
1166 hFont = CreateFontIndirectW(&logfont);
1167 if(!hFont)
1168 TRACE("Failed to create font\n");
1170 if(hFont)
1171 oldFont = SelectObject(hdc, hFont);
1173 DrawTextW(hdc, pszText, iCharCount, &rt, dwTextFlags|DT_CALCRECT);
1174 CopyRect(pExtentRect, &rt);
1176 if(hFont) {
1177 SelectObject(hdc, oldFont);
1178 DeleteObject(hFont);
1180 return S_OK;
1183 /***********************************************************************
1184 * GetThemeTextMetrics (UXTHEME.@)
1186 HRESULT WINAPI GetThemeTextMetrics(HTHEME hTheme, HDC hdc, int iPartId,
1187 int iStateId, TEXTMETRICW *ptm)
1189 HRESULT hr;
1190 HFONT hFont = NULL;
1191 HGDIOBJ oldFont = NULL;
1192 LOGFONTW logfont;
1194 TRACE("(%p, %p, %d, %d)\n", hTheme, hdc, iPartId, iStateId);
1195 if(!hTheme)
1196 return E_HANDLE;
1198 hr = GetThemeFont(hTheme, hdc, iPartId, iStateId, TMT_FONT, &logfont);
1199 if(SUCCEEDED(hr)) {
1200 hFont = CreateFontIndirectW(&logfont);
1201 if(!hFont)
1202 TRACE("Failed to create font\n");
1204 if(hFont)
1205 oldFont = SelectObject(hdc, hFont);
1207 if(!GetTextMetricsW(hdc, ptm))
1208 hr = HRESULT_FROM_WIN32(GetLastError());
1210 if(hFont) {
1211 SelectObject(hdc, oldFont);
1212 DeleteObject(hFont);
1214 return hr;
1217 /***********************************************************************
1218 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
1220 BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId,
1221 int iStateId)
1223 BOOL transparent = FALSE;
1224 TRACE("(%d,%d)\n", iPartId, iStateId);
1225 GetThemeBool(hTheme, iPartId, iStateId, TMT_TRANSPARENT, &transparent);
1226 return transparent;