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 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 };
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 */
62 if (dwFlags & ETDT_USETABTEXTURE)
63 return SetWindowTheme (hwnd, NULL, szTab);
65 return SetWindowTheme (hwnd, NULL, NULL);
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 */
83 return (dwDialogTextureFlags & ETDT_ENABLE) && !(dwDialogTextureFlags & ETDT_DISABLE);
86 /***********************************************************************
87 * DrawThemeParentBackground (UXTHEME.@)
89 HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
97 TRACE("(%p,%p,%p)\n", hwnd, hdc, prc);
98 hParent = GetParent(hwnd);
103 MapWindowPoints(hwnd, NULL, (LPPOINT)&rt, 2);
105 clip = CreateRectRgn(0,0,1,1);
106 hasClip = GetClipRgn(hdc, clip);
108 TRACE("Failed to get original clipping region\n");
110 IntersectClipRect(hdc, prc->left, prc->top, prc->right, prc->bottom);
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);
125 SelectClipRgn(hdc, NULL);
126 else if(hasClip == 1)
127 SelectClipRgn(hdc, clip);
134 /***********************************************************************
135 * DrawThemeBackground (UXTHEME.@)
137 HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
138 int iStateId, const RECT *pRect,
139 const RECT *pClipRect)
142 opts.dwSize = sizeof(DTBGOPTS);
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)
159 int imageselecttype = IST_NONE;
163 image = TMT_GLYPHIMAGEFILE;
165 image = TMT_IMAGEFILE;
167 if((tp=MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, image)))
169 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGESELECTTYPE, &imageselecttype);
171 if(imageselecttype == IST_DPI) {
173 int screendpi = GetDeviceCaps(hdc, LOGPIXELSX);
174 for(i=4; i>=0; i--) {
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};
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);
203 /***********************************************************************
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_HORIZONTAL;
214 WCHAR szPath[MAX_PATH];
215 PTHEME_PROPERTY tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, pRect, glyph);
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);
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;
234 bmpRect->right = bmp.bmWidth;
235 bmpRect->top = (max(min(imagecount, iStateId), 1)-1) * height;
236 bmpRect->bottom = bmpRect->top + height;
239 int width = bmp.bmWidth/imagecount;
240 bmpRect->left = (max(min(imagecount, iStateId), 1)-1) * width;
241 bmpRect->right = bmpRect->left + width;
243 bmpRect->bottom = bmp.bmHeight;
248 /***********************************************************************
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)
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),
263 /* This should be using AlphaBlend */
264 return StretchBlt(hdcDst, nXOriginDst, nYOriginDst, nWidthDst, nHeightDst,
265 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
269 /***********************************************************************
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 /***********************************************************************
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,
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))
310 xRemaining -= nWidthSrc;
313 yRemaining -= nHeightSrc;
319 return StretchBlt (hdcDst, nXOriginDst, nYOriginDst, nWidthDst, nHeightDst,
320 hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
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)
335 HBITMAP bmpSrc = NULL;
337 HGDIOBJ oldSrc = NULL;
339 BOOL transparent = FALSE;
340 COLORREF transparentcolor = 0;
341 int valign = VA_CENTER;
342 int halign = HA_CENTER;
347 hr = UXTHEME_LoadImage(hTheme, hdc, iPartId, iStateId, pRect, TRUE, &bmpSrc, &rcSrc);
348 if(FAILED(hr)) return hr;
349 hdcSrc = CreateCompatibleDC(hdc);
351 hr = HRESULT_FROM_WIN32(GetLastError());
352 DeleteObject(bmpSrc);
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);
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);
387 DeleteObject(bmpSrc);
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");
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,
427 hr = UXTHEME_LoadImage(hTheme, hdc, iPartId, iStateId, prc, FALSE, &bmpSrc, &rcSrc);
428 if (FAILED(hr)) return hr;
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);
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 = 100;
467 if(dstSize.x < 0 || dstSize.y < 0) {
468 BOOL mirrorimage = TRUE;
469 GetThemeBool(hTheme, iPartId, iStateId, TMT_MIRRORIMAGE, &mirrorimage);
472 rcDst.left += dstSize.x;
473 rcDst.right += dstSize.x;
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));
489 memcpy (psz, &srcSize, sizeof (SIZE));
494 psz->x = abs(dstSize.x);
495 psz->y = abs(dstSize.y);
499 /* else fall through */
501 /* FIXME: couldn't figure how native uxtheme computes min size */
503 psz->x = rcSrc.right - rcSrc.left;
504 psz->y = rcSrc.bottom - rcSrc.top;
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)
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);
536 hr = HRESULT_FROM_WIN32(GetLastError());
537 DeleteObject(bmpSrc);
540 oldSrc = SelectObject(hdcSrc, bmpSrc);
542 CopyRect(&rcDst, pRect);
544 GetThemeBool(hTheme, iPartId, iStateId, TMT_TRANSPARENT, &transparent);
546 if(FAILED(GetThemeColor(hTheme, iPartId, iStateId, TMT_TRANSPARENTCOLOR, &transparentcolor))) {
547 /* If image is transparent, but no color was specified, use magenta */
548 transparentcolor = RGB(255, 0, 255);
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 int valign = VA_CENTER, halign = HA_CENTER;
561 get_image_part_size (hTheme, hdc, iPartId, iStateId, pRect, TS_DRAW, &drawSize);
562 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_VALIGN, &valign);
563 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_HALIGN, &halign);
565 if (halign == HA_CENTER)
566 rcDst.left += (dstSize.x/2)-(drawSize.x/2);
567 else if (halign == HA_RIGHT)
568 rcDst.left = rcDst.right - drawSize.x;
569 if (valign == VA_CENTER)
570 rcDst.top += (dstSize.y/2)-(drawSize.y/2);
571 else if (valign == VA_BOTTOM)
572 rcDst.top = rcDst.bottom - drawSize.y;
573 rcDst.right = rcDst.left + drawSize.x;
574 rcDst.bottom = rcDst.top + drawSize.y;
575 if(!UXTHEME_StretchBlt(hdc, rcDst.left, rcDst.top, drawSize.x, drawSize.y,
576 hdcSrc, rcSrc.left, rcSrc.top, srcSize.x, srcSize.y,
577 transparent, transparentcolor))
578 hr = HRESULT_FROM_WIN32(GetLastError());
582 HBITMAP bmpDst = NULL;
583 HGDIOBJ oldDst = NULL;
586 dstSize.x = abs(dstSize.x);
587 dstSize.y = abs(dstSize.y);
589 GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_SIZINGMARGINS, NULL, &sm);
591 hdcDst = CreateCompatibleDC(hdc);
593 hr = HRESULT_FROM_WIN32(GetLastError());
596 bmpDst = CreateCompatibleBitmap(hdc, dstSize.x, dstSize.y);
598 hr = HRESULT_FROM_WIN32(GetLastError());
601 oldDst = SelectObject(hdcDst, bmpDst);
603 /* Upper left corner */
604 if(!BitBlt(hdcDst, 0, 0, sm.cxLeftWidth, sm.cyTopHeight,
605 hdcSrc, rcSrc.left, rcSrc.top, SRCCOPY)) {
606 hr = HRESULT_FROM_WIN32(GetLastError());
609 /* Upper right corner */
610 if(!BitBlt(hdcDst, dstSize.x-sm.cxRightWidth, 0, sm.cxRightWidth, sm.cyTopHeight,
611 hdcSrc, rcSrc.right-sm.cxRightWidth, rcSrc.top, SRCCOPY)) {
612 hr = HRESULT_FROM_WIN32(GetLastError());
615 /* Lower left corner */
616 if(!BitBlt(hdcDst, 0, dstSize.y-sm.cyBottomHeight, sm.cxLeftWidth, sm.cyBottomHeight,
617 hdcSrc, rcSrc.left, rcSrc.bottom-sm.cyBottomHeight, SRCCOPY)) {
618 hr = HRESULT_FROM_WIN32(GetLastError());
621 /* Lower right corner */
622 if(!BitBlt(hdcDst, dstSize.x-sm.cxRightWidth, dstSize.y-sm.cyBottomHeight, sm.cxRightWidth, sm.cyBottomHeight,
623 hdcSrc, rcSrc.right-sm.cxRightWidth, rcSrc.bottom-sm.cyBottomHeight, SRCCOPY)) {
624 hr = HRESULT_FROM_WIN32(GetLastError());
628 if ((sizingtype == ST_STRETCH) || (sizingtype == ST_TILE)) {
629 int destCenterWidth = dstSize.x - (sm.cxLeftWidth + sm.cxRightWidth);
630 int srcCenterWidth = srcSize.x - (sm.cxLeftWidth + sm.cxRightWidth);
631 int destCenterHeight = dstSize.y - (sm.cyTopHeight + sm.cyBottomHeight);
632 int srcCenterHeight = srcSize.y - (sm.cyTopHeight + sm.cyBottomHeight);
634 if(destCenterWidth > 0) {
636 if(!UXTHEME_SizedBlt(hdcDst, sm.cxLeftWidth, 0, destCenterWidth, sm.cyTopHeight,
637 hdcSrc, rcSrc.left+sm.cxLeftWidth, rcSrc.top, srcCenterWidth, sm.cyTopHeight, sizingtype)) {
638 hr = HRESULT_FROM_WIN32(GetLastError());
642 if(!UXTHEME_SizedBlt(hdcDst, sm.cxLeftWidth, dstSize.y-sm.cyBottomHeight, destCenterWidth, sm.cyBottomHeight,
643 hdcSrc, rcSrc.left+sm.cxLeftWidth, rcSrc.bottom-sm.cyBottomHeight, srcCenterWidth, sm.cyTopHeight, sizingtype)) {
644 hr = HRESULT_FROM_WIN32(GetLastError());
648 if(destCenterHeight > 0) {
650 if(!UXTHEME_SizedBlt(hdcDst, 0, sm.cyTopHeight, sm.cxLeftWidth, destCenterHeight,
651 hdcSrc, rcSrc.left, rcSrc.top+sm.cyTopHeight, sm.cxLeftWidth, srcCenterHeight, sizingtype)) {
652 hr = HRESULT_FROM_WIN32(GetLastError());
656 if(!UXTHEME_SizedBlt(hdcDst, dstSize.x-sm.cxRightWidth, sm.cyTopHeight, sm.cxRightWidth, destCenterHeight,
657 hdcSrc, rcSrc.right-sm.cxRightWidth, rcSrc.top+sm.cyTopHeight, sm.cxRightWidth, srcCenterHeight, sizingtype)) {
658 hr = HRESULT_FROM_WIN32(GetLastError());
662 if(destCenterHeight > 0 && destCenterWidth > 0) {
663 BOOL borderonly = FALSE;
664 GetThemeBool(hTheme, iPartId, iStateId, TMT_BORDERONLY, &borderonly);
667 if(!UXTHEME_SizedBlt(hdcDst, sm.cxLeftWidth, sm.cyTopHeight, destCenterWidth, destCenterHeight,
668 hdcSrc, rcSrc.left+sm.cxLeftWidth, rcSrc.top+sm.cyTopHeight, srcCenterWidth, srcCenterHeight, sizingtype)) {
669 hr = HRESULT_FROM_WIN32(GetLastError());
676 if(!UXTHEME_Blt(hdc, rcDst.left, rcDst.top, dstSize.x, dstSize.y,
678 transparent, transparentcolor))
679 hr = HRESULT_FROM_WIN32(GetLastError());
683 SelectObject(hdcDst, oldDst);
686 if(bmpDst) DeleteObject(bmpDst);
688 SelectObject(hdcSrc, oldSrc);
689 DeleteObject(bmpSrc);
691 CopyRect(pRect, &rcDst);
695 /***********************************************************************
696 * UXTHEME_DrawBorderRectangle
698 * Draw the bounding rectangle for a borderfill background
700 static HRESULT UXTHEME_DrawBorderRectangle(HTHEME hTheme, HDC hdc, int iPartId,
701 int iStateId, RECT *pRect,
702 const DTBGOPTS *pOptions)
707 COLORREF bordercolor = RGB(0,0,0);
710 GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE, &bordersize);
713 ptCorners[0].x = pRect->left;
714 ptCorners[0].y = pRect->top;
715 ptCorners[1].x = pRect->right-1;
716 ptCorners[1].y = pRect->top;
717 ptCorners[2].x = pRect->right-1;
718 ptCorners[2].y = pRect->bottom-1;
719 ptCorners[3].x = pRect->left;
720 ptCorners[3].y = pRect->bottom-1;
721 ptCorners[4].x = pRect->left;
722 ptCorners[4].y = pRect->top;
724 InflateRect(pRect, -bordersize, -bordersize);
725 if(pOptions->dwFlags & DTBG_OMITBORDER)
727 GetThemeColor(hTheme, iPartId, iStateId, TMT_BORDERCOLOR, &bordercolor);
728 hPen = CreatePen(PS_SOLID, bordersize, bordercolor);
730 return HRESULT_FROM_WIN32(GetLastError());
731 oldPen = SelectObject(hdc, hPen);
733 if(!Polyline(hdc, ptCorners, 5))
734 hr = HRESULT_FROM_WIN32(GetLastError());
736 SelectObject(hdc, oldPen);
742 /***********************************************************************
743 * UXTHEME_DrawBackgroundFill
745 * Fill a borderfill background rectangle
747 static HRESULT UXTHEME_DrawBackgroundFill(HTHEME hTheme, HDC hdc, int iPartId,
748 int iStateId, RECT *pRect,
749 const DTBGOPTS *pOptions)
752 int filltype = FT_SOLID;
754 TRACE("(%d,%d,%ld)\n", iPartId, iStateId, pOptions->dwFlags);
756 if(pOptions->dwFlags & DTBG_OMITCONTENT)
759 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_FILLTYPE, &filltype);
761 if(filltype == FT_SOLID) {
763 COLORREF fillcolor = RGB(255,255,255);
765 GetThemeColor(hTheme, iPartId, iStateId, TMT_FILLCOLOR, &fillcolor);
766 hBrush = CreateSolidBrush(fillcolor);
767 if(!FillRect(hdc, pRect, hBrush))
768 hr = HRESULT_FROM_WIN32(GetLastError());
769 DeleteObject(hBrush);
771 else if(filltype == FT_VERTGRADIENT || filltype == FT_HORZGRADIENT) {
772 /* FIXME: This only accounts for 2 gradient colors (out of 5) and ignores
773 the gradient ratios (no idea how those work)
774 Few themes use this, and the ones I've seen only use 2 colors with
775 a gradient ratio of 0 and 255 respectivly
778 COLORREF gradient1 = RGB(0,0,0);
779 COLORREF gradient2 = RGB(255,255,255);
783 FIXME("Gradient implementation not complete\n");
785 GetThemeColor(hTheme, iPartId, iStateId, TMT_GRADIENTCOLOR1, &gradient1);
786 GetThemeColor(hTheme, iPartId, iStateId, TMT_GRADIENTCOLOR2, &gradient2);
788 vert[0].x = pRect->left;
789 vert[0].y = pRect->top;
790 vert[0].Red = GetRValue(gradient1) << 8;
791 vert[0].Green = GetGValue(gradient1) << 8;
792 vert[0].Blue = GetBValue(gradient1) << 8;
793 vert[0].Alpha = 0x0000;
795 vert[1].x = pRect->right;
796 vert[1].y = pRect->bottom;
797 vert[1].Red = GetRValue(gradient2) << 8;
798 vert[1].Green = GetGValue(gradient2) << 8;
799 vert[1].Blue = GetBValue(gradient2) << 8;
800 vert[1].Alpha = 0x0000;
803 gRect.LowerRight = 1;
804 GradientFill(hdc,vert,2,&gRect,1,filltype==FT_HORZGRADIENT?GRADIENT_FILL_RECT_H:GRADIENT_FILL_RECT_V);
806 else if(filltype == FT_RADIALGRADIENT) {
807 /* I've never seen this used in a theme */
808 FIXME("Radial gradient\n");
810 else if(filltype == FT_TILEIMAGE) {
811 /* I've never seen this used in a theme */
812 FIXME("Tile image\n");
817 /***********************************************************************
818 * UXTHEME_DrawBorderBackground
820 * Draw an imagefile background
822 static HRESULT UXTHEME_DrawBorderBackground(HTHEME hTheme, HDC hdc, int iPartId,
823 int iStateId, const RECT *pRect,
824 const DTBGOPTS *pOptions)
829 CopyRect(&rt, pRect);
831 hr = UXTHEME_DrawBorderRectangle(hTheme, hdc, iPartId, iStateId, &rt, pOptions);
834 return UXTHEME_DrawBackgroundFill(hTheme, hdc, iPartId, iStateId, &rt, pOptions);
837 /***********************************************************************
838 * DrawThemeBackgroundEx (UXTHEME.@)
840 HRESULT WINAPI DrawThemeBackgroundEx(HTHEME hTheme, HDC hdc, int iPartId,
841 int iStateId, const RECT *pRect,
842 const DTBGOPTS *pOptions)
845 const DTBGOPTS defaultOpts = {sizeof(DTBGOPTS), 0, {0,0,0,0}};
846 const DTBGOPTS *opts;
849 int bgtype = BT_BORDERFILL;
852 TRACE("(%p,%p,%d,%d,%ld,%ld)\n", hTheme, hdc, iPartId, iStateId,pRect->left,pRect->top);
856 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
857 if (bgtype == BT_NONE) return S_OK;
859 /* Ensure we have a DTBGOPTS structure available, simplifies some of the code */
861 if(!opts) opts = &defaultOpts;
863 if(opts->dwFlags & DTBG_CLIPRECT) {
864 clip = CreateRectRgn(0,0,1,1);
865 hasClip = GetClipRgn(hdc, clip);
867 TRACE("Failed to get original clipping region\n");
869 IntersectClipRect(hdc, opts->rcClip.left, opts->rcClip.top, opts->rcClip.right, opts->rcClip.bottom);
871 CopyRect(&rt, pRect);
873 if(bgtype == BT_IMAGEFILE)
874 hr = UXTHEME_DrawImageBackground(hTheme, hdc, iPartId, iStateId, &rt, opts);
875 else if(bgtype == BT_BORDERFILL)
876 hr = UXTHEME_DrawBorderBackground(hTheme, hdc, iPartId, iStateId, pRect, opts);
878 FIXME("Unknown background type\n");
879 /* This should never happen, and hence I don't know what to return */
883 hr = UXTHEME_DrawGlyph(hTheme, hdc, iPartId, iStateId, &rt, opts);
884 if(opts->dwFlags & DTBG_CLIPRECT) {
886 SelectClipRgn(hdc, NULL);
887 else if(hasClip == 1)
888 SelectClipRgn(hdc, clip);
895 * DrawThemeEdge() implementation
897 * Since it basically is DrawEdge() with different colors, I copied its code
898 * from user32's uitools.c.
919 } EdgeColorMap[EDGE_NUMCOLORS] = {
920 {TMT_EDGELIGHTCOLOR, COLOR_3DLIGHT},
921 {TMT_EDGEHIGHLIGHTCOLOR, COLOR_BTNHIGHLIGHT},
922 {TMT_EDGESHADOWCOLOR, COLOR_BTNSHADOW},
923 {TMT_EDGEDKSHADOWCOLOR, COLOR_3DDKSHADOW},
924 {TMT_EDGEFILLCOLOR, COLOR_BTNFACE},
926 {-1, COLOR_WINDOWFRAME}
929 static const signed char LTInnerNormal[] = {
931 -1, EDGE_HIGHLIGHT, EDGE_HIGHLIGHT, -1,
932 -1, EDGE_DARKSHADOW, EDGE_DARKSHADOW, -1,
936 static const signed char LTOuterNormal[] = {
937 -1, EDGE_LIGHT, EDGE_SHADOW, -1,
938 EDGE_HIGHLIGHT, EDGE_LIGHT, EDGE_SHADOW, -1,
939 EDGE_DARKSHADOW, EDGE_LIGHT, EDGE_SHADOW, -1,
940 -1, EDGE_LIGHT, EDGE_SHADOW, -1
943 static const signed char RBInnerNormal[] = {
945 -1, EDGE_SHADOW, EDGE_SHADOW, -1,
946 -1, EDGE_LIGHT, EDGE_LIGHT, -1,
950 static const signed char RBOuterNormal[] = {
951 -1, EDGE_DARKSHADOW, EDGE_HIGHLIGHT, -1,
952 EDGE_SHADOW, EDGE_DARKSHADOW, EDGE_HIGHLIGHT, -1,
953 EDGE_LIGHT, EDGE_DARKSHADOW, EDGE_HIGHLIGHT, -1,
954 -1, EDGE_DARKSHADOW, EDGE_HIGHLIGHT, -1
957 static const signed char LTInnerSoft[] = {
959 -1, EDGE_LIGHT, EDGE_LIGHT, -1,
960 -1, EDGE_SHADOW, EDGE_SHADOW, -1,
964 static const signed char LTOuterSoft[] = {
965 -1, EDGE_HIGHLIGHT, EDGE_DARKSHADOW, -1,
966 EDGE_LIGHT, EDGE_HIGHLIGHT, EDGE_DARKSHADOW, -1,
967 EDGE_SHADOW, EDGE_HIGHLIGHT, EDGE_DARKSHADOW, -1,
968 -1, EDGE_HIGHLIGHT, EDGE_DARKSHADOW, -1
971 #define RBInnerSoft RBInnerNormal /* These are the same */
972 #define RBOuterSoft RBOuterNormal
974 static const signed char LTRBOuterMono[] = {
975 -1, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME,
976 EDGE_WINDOW, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME,
977 EDGE_WINDOW, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME,
978 EDGE_WINDOW, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME, EDGE_WINDOWFRAME,
981 static const signed char LTRBInnerMono[] = {
983 -1, EDGE_WINDOW, EDGE_WINDOW, EDGE_WINDOW,
984 -1, EDGE_WINDOW, EDGE_WINDOW, EDGE_WINDOW,
985 -1, EDGE_WINDOW, EDGE_WINDOW, EDGE_WINDOW,
988 static const signed char LTRBOuterFlat[] = {
989 -1, EDGE_SHADOW, EDGE_SHADOW, EDGE_SHADOW,
990 EDGE_FILL, EDGE_SHADOW, EDGE_SHADOW, EDGE_SHADOW,
991 EDGE_FILL, EDGE_SHADOW, EDGE_SHADOW, EDGE_SHADOW,
992 EDGE_FILL, EDGE_SHADOW, EDGE_SHADOW, EDGE_SHADOW,
995 static const signed char LTRBInnerFlat[] = {
997 -1, EDGE_FILL, EDGE_FILL, EDGE_FILL,
998 -1, EDGE_FILL, EDGE_FILL, EDGE_FILL,
999 -1, EDGE_FILL, EDGE_FILL, EDGE_FILL,
1002 static COLORREF get_edge_color (int edgeType, HTHEME theme, int part, int state)
1005 if ((EdgeColorMap[edgeType].themeProp == -1)
1006 || FAILED (GetThemeColor (theme, part, state,
1007 EdgeColorMap[edgeType].themeProp, &col)))
1008 col = GetSysColor (EdgeColorMap[edgeType].sysColor);
1012 static inline HPEN get_edge_pen (int edgeType, HTHEME theme, int part, int state)
1014 return CreatePen (PS_SOLID, 1, get_edge_color (edgeType, theme, part, state));
1017 static inline HBRUSH get_edge_brush (int edgeType, HTHEME theme, int part, int state)
1019 return CreateSolidBrush (get_edge_color (edgeType, theme, part, state));
1022 /***********************************************************************
1025 * Same as DrawEdge invoked with BF_DIAGONAL
1027 static HRESULT draw_diag_edge (HDC hdc, HTHEME theme, int part, int state,
1028 const RECT* rc, UINT uType,
1029 UINT uFlags, LPRECT contentsRect)
1032 signed char InnerI, OuterI;
1033 HPEN InnerPen, OuterPen;
1038 int Width = rc->right - rc->left;
1039 int Height= rc->bottom - rc->top;
1040 int SmallDiam = Width > Height ? Height : Width;
1041 HRESULT retval = (((uType & BDR_INNER) == BDR_INNER
1042 || (uType & BDR_OUTER) == BDR_OUTER)
1043 && !(uFlags & (BF_FLAT|BF_MONO)) ) ? E_FAIL : S_OK;
1044 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
1045 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
1047 /* Init some vars */
1048 OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN);
1049 SavePen = (HPEN)SelectObject(hdc, InnerPen);
1050 spx = spy = epx = epy = 0; /* Satisfy the compiler... */
1052 /* Determine the colors of the edges */
1053 if(uFlags & BF_MONO)
1055 InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
1056 OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
1058 else if(uFlags & BF_FLAT)
1060 InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
1061 OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
1063 else if(uFlags & BF_SOFT)
1065 if(uFlags & BF_BOTTOM)
1067 InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
1068 OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
1072 InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
1073 OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
1078 if(uFlags & BF_BOTTOM)
1080 InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
1081 OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
1085 InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
1086 OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
1090 if(InnerI != -1) InnerPen = get_edge_pen (InnerI, theme, part, state);
1091 if(OuterI != -1) OuterPen = get_edge_pen (OuterI, theme, part, state);
1093 MoveToEx(hdc, 0, 0, &SavePoint);
1095 /* Don't ask me why, but this is what is visible... */
1096 /* This must be possible to do much simpler, but I fail to */
1097 /* see the logic in the MS implementation (sigh...). */
1098 /* So, this might look a bit brute force here (and it is), but */
1099 /* it gets the job done;) */
1101 switch(uFlags & BF_RECT)
1107 /* Left bottom endpoint */
1109 spx = epx + SmallDiam;
1111 spy = epy - SmallDiam;
1115 case BF_BOTTOMRIGHT:
1116 /* Left top endpoint */
1118 spx = epx + SmallDiam;
1120 spy = epy + SmallDiam;
1126 case BF_RIGHT|BF_LEFT:
1127 case BF_RIGHT|BF_LEFT|BF_TOP:
1128 case BF_BOTTOM|BF_TOP:
1129 case BF_BOTTOM|BF_TOP|BF_LEFT:
1130 case BF_BOTTOMRIGHT|BF_LEFT:
1131 case BF_BOTTOMRIGHT|BF_TOP:
1133 /* Right top endpoint */
1135 epx = spx + SmallDiam;
1137 epy = spy - SmallDiam;
1141 MoveToEx(hdc, spx, spy, NULL);
1142 SelectObject(hdc, OuterPen);
1143 LineTo(hdc, epx, epy);
1145 SelectObject(hdc, InnerPen);
1147 switch(uFlags & (BF_RECT|BF_DIAGONAL))
1149 case BF_DIAGONAL_ENDBOTTOMLEFT:
1150 case (BF_DIAGONAL|BF_BOTTOM):
1152 case (BF_DIAGONAL|BF_LEFT):
1153 MoveToEx(hdc, spx-1, spy, NULL);
1154 LineTo(hdc, epx, epy-1);
1155 Points[0].x = spx-add;
1157 Points[1].x = rc->left;
1158 Points[1].y = rc->top;
1159 Points[2].x = epx+1;
1160 Points[2].y = epy-1-add;
1161 Points[3] = Points[2];
1164 case BF_DIAGONAL_ENDBOTTOMRIGHT:
1165 MoveToEx(hdc, spx-1, spy, NULL);
1166 LineTo(hdc, epx, epy+1);
1167 Points[0].x = spx-add;
1169 Points[1].x = rc->left;
1170 Points[1].y = rc->bottom-1;
1171 Points[2].x = epx+1;
1172 Points[2].y = epy+1+add;
1173 Points[3] = Points[2];
1176 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP):
1177 case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT):
1178 case BF_DIAGONAL_ENDTOPRIGHT:
1179 case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT):
1180 MoveToEx(hdc, spx+1, spy, NULL);
1181 LineTo(hdc, epx, epy+1);
1182 Points[0].x = epx-1;
1183 Points[0].y = epy+1+add;
1184 Points[1].x = rc->right-1;
1185 Points[1].y = rc->top+add;
1186 Points[2].x = rc->right-1;
1187 Points[2].y = rc->bottom-1;
1188 Points[3].x = spx+add;
1192 case BF_DIAGONAL_ENDTOPLEFT:
1193 MoveToEx(hdc, spx, spy-1, NULL);
1194 LineTo(hdc, epx+1, epy);
1195 Points[0].x = epx+1+add;
1196 Points[0].y = epy+1;
1197 Points[1].x = rc->right-1;
1198 Points[1].y = rc->top;
1199 Points[2].x = rc->right-1;
1200 Points[2].y = rc->bottom-1-add;
1202 Points[3].y = spy-add;
1205 case (BF_DIAGONAL|BF_TOP):
1206 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP):
1207 case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT):
1208 MoveToEx(hdc, spx+1, spy-1, NULL);
1209 LineTo(hdc, epx, epy);
1210 Points[0].x = epx-1;
1211 Points[0].y = epy+1;
1212 Points[1].x = rc->right-1;
1213 Points[1].y = rc->top;
1214 Points[2].x = rc->right-1;
1215 Points[2].y = rc->bottom-1-add;
1216 Points[3].x = spx+add;
1217 Points[3].y = spy-add;
1220 case (BF_DIAGONAL|BF_RIGHT):
1221 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT):
1222 case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM):
1223 MoveToEx(hdc, spx, spy, NULL);
1224 LineTo(hdc, epx-1, epy+1);
1227 Points[1].x = rc->left;
1228 Points[1].y = rc->top+add;
1229 Points[2].x = epx-1-add;
1230 Points[2].y = epy+1+add;
1231 Points[3] = Points[2];
1235 /* Fill the interior if asked */
1236 if((uFlags & BF_MIDDLE) && retval)
1239 HBRUSH hb = get_edge_brush ((uFlags & BF_MONO) ? EDGE_WINDOW : EDGE_FILL,
1240 theme, part, state);
1242 HPEN hp = get_edge_pen ((uFlags & BF_MONO) ? EDGE_WINDOW : EDGE_FILL,
1243 theme, part, state);
1244 hbsave = (HBRUSH)SelectObject(hdc, hb);
1245 hpsave = (HPEN)SelectObject(hdc, hp);
1246 Polygon(hdc, Points, 4);
1247 SelectObject(hdc, hbsave);
1248 SelectObject(hdc, hpsave);
1253 /* Adjust rectangle if asked */
1254 if(uFlags & BF_ADJUST)
1256 *contentsRect = *rc;
1257 if(uFlags & BF_LEFT) contentsRect->left += add;
1258 if(uFlags & BF_RIGHT) contentsRect->right -= add;
1259 if(uFlags & BF_TOP) contentsRect->top += add;
1260 if(uFlags & BF_BOTTOM) contentsRect->bottom -= add;
1264 SelectObject(hdc, SavePen);
1265 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
1266 if(InnerI != -1) DeleteObject (InnerPen);
1267 if(OuterI != -1) DeleteObject (OuterPen);
1272 /***********************************************************************
1275 * Same as DrawEdge invoked without BF_DIAGONAL
1277 static HRESULT draw_rect_edge (HDC hdc, HTHEME theme, int part, int state,
1278 const RECT* rc, UINT uType,
1279 UINT uFlags, LPRECT contentsRect)
1281 signed char LTInnerI, LTOuterI;
1282 signed char RBInnerI, RBOuterI;
1283 HPEN LTInnerPen, LTOuterPen;
1284 HPEN RBInnerPen, RBOuterPen;
1285 RECT InnerRect = *rc;
1292 HRESULT retval = (((uType & BDR_INNER) == BDR_INNER
1293 || (uType & BDR_OUTER) == BDR_OUTER)
1294 && !(uFlags & (BF_FLAT|BF_MONO)) ) ? E_FAIL : S_OK;
1296 /* Init some vars */
1297 LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN);
1298 SavePen = (HPEN)SelectObject(hdc, LTInnerPen);
1300 /* Determine the colors of the edges */
1301 if(uFlags & BF_MONO)
1303 LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)];
1304 LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)];
1306 else if(uFlags & BF_FLAT)
1308 LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)];
1309 LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)];
1311 if( LTInnerI != -1 ) LTInnerI = RBInnerI = COLOR_BTNFACE;
1313 else if(uFlags & BF_SOFT)
1315 LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
1316 LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
1317 RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)];
1318 RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)];
1322 LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
1323 LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
1324 RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)];
1325 RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)];
1328 if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1;
1329 if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1;
1330 if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1;
1331 if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1;
1333 if(LTInnerI != -1) LTInnerPen = get_edge_pen (LTInnerI, theme, part, state);
1334 if(LTOuterI != -1) LTOuterPen = get_edge_pen (LTOuterI, theme, part, state);
1335 if(RBInnerI != -1) RBInnerPen = get_edge_pen (RBInnerI, theme, part, state);
1336 if(RBOuterI != -1) RBOuterPen = get_edge_pen (RBOuterI, theme, part, state);
1338 MoveToEx(hdc, 0, 0, &SavePoint);
1340 /* Draw the outer edge */
1341 SelectObject(hdc, LTOuterPen);
1344 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
1345 LineTo(hdc, InnerRect.right, InnerRect.top);
1347 if(uFlags & BF_LEFT)
1349 MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL);
1350 LineTo(hdc, InnerRect.left, InnerRect.bottom);
1352 SelectObject(hdc, RBOuterPen);
1353 if(uFlags & BF_BOTTOM)
1355 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
1356 LineTo(hdc, InnerRect.left-1, InnerRect.bottom-1);
1358 if(uFlags & BF_RIGHT)
1360 MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL);
1361 LineTo(hdc, InnerRect.right-1, InnerRect.top-1);
1364 /* Draw the inner edge */
1365 SelectObject(hdc, LTInnerPen);
1368 MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL);
1369 LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1);
1371 if(uFlags & BF_LEFT)
1373 MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL);
1374 LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus);
1376 SelectObject(hdc, RBInnerPen);
1377 if(uFlags & BF_BOTTOM)
1379 MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL);
1380 LineTo(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2);
1382 if(uFlags & BF_RIGHT)
1384 MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL);
1385 LineTo(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus);
1388 if( ((uFlags & BF_MIDDLE) && retval) || (uFlags & BF_ADJUST) )
1390 int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0)
1391 + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0);
1393 if(uFlags & BF_LEFT) InnerRect.left += add;
1394 if(uFlags & BF_RIGHT) InnerRect.right -= add;
1395 if(uFlags & BF_TOP) InnerRect.top += add;
1396 if(uFlags & BF_BOTTOM) InnerRect.bottom -= add;
1398 if((uFlags & BF_MIDDLE) && retval)
1400 HBRUSH br = get_edge_brush ((uFlags & BF_MONO) ? EDGE_WINDOW : EDGE_FILL,
1401 theme, part, state);
1402 FillRect(hdc, &InnerRect, br);
1406 if(uFlags & BF_ADJUST)
1407 *contentsRect = InnerRect;
1411 SelectObject(hdc, SavePen);
1412 MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL);
1413 if(LTInnerI != -1) DeleteObject (LTInnerPen);
1414 if(LTOuterI != -1) DeleteObject (LTOuterPen);
1415 if(RBInnerI != -1) DeleteObject (RBInnerPen);
1416 if(RBOuterI != -1) DeleteObject (RBOuterPen);
1421 /***********************************************************************
1422 * DrawThemeEdge (UXTHEME.@)
1424 * DrawThemeEdge() is pretty similar to the vanilla DrawEdge() - the
1425 * difference is that it does not rely on the system colors alone, but
1426 * also allows color specification in the theme.
1428 HRESULT WINAPI DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId,
1429 int iStateId, const RECT *pDestRect, UINT uEdge,
1430 UINT uFlags, RECT *pContentRect)
1432 TRACE("%d %d 0x%08x 0x%08x\n", iPartId, iStateId, uEdge, uFlags);
1436 if(uFlags & BF_DIAGONAL)
1437 return draw_diag_edge (hdc, hTheme, iPartId, iStateId, pDestRect,
1438 uEdge, uFlags, pContentRect);
1440 return draw_rect_edge (hdc, hTheme, iPartId, iStateId, pDestRect,
1441 uEdge, uFlags, pContentRect);
1445 /***********************************************************************
1446 * DrawThemeIcon (UXTHEME.@)
1448 HRESULT WINAPI DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
1449 const RECT *pRect, HIMAGELIST himl, int iImageIndex)
1451 FIXME("%d %d: stub\n", iPartId, iStateId);
1454 return ERROR_CALL_NOT_IMPLEMENTED;
1457 /***********************************************************************
1458 * DrawThemeText (UXTHEME.@)
1460 HRESULT WINAPI DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
1461 LPCWSTR pszText, int iCharCount, DWORD dwTextFlags,
1462 DWORD dwTextFlags2, const RECT *pRect)
1466 HGDIOBJ oldFont = NULL;
1469 COLORREF oldTextColor;
1473 TRACE("%d %d: stub\n", iPartId, iStateId);
1477 hr = GetThemeFont(hTheme, hdc, iPartId, iStateId, TMT_FONT, &logfont);
1479 hFont = CreateFontIndirectW(&logfont);
1481 TRACE("Failed to create font\n");
1483 CopyRect(&rt, pRect);
1485 oldFont = SelectObject(hdc, hFont);
1487 if(dwTextFlags2 & DTT_GRAYED)
1488 textColor = GetSysColor(COLOR_GRAYTEXT);
1490 if(FAILED(GetThemeColor(hTheme, iPartId, iStateId, TMT_TEXTCOLOR, &textColor)))
1491 textColor = GetTextColor(hdc);
1493 oldTextColor = SetTextColor(hdc, textColor);
1494 oldBkMode = SetBkMode(hdc, TRANSPARENT);
1495 DrawTextW(hdc, pszText, iCharCount, &rt, dwTextFlags);
1496 SetBkMode(hdc, oldBkMode);
1497 SetTextColor(hdc, oldTextColor);
1500 SelectObject(hdc, oldFont);
1501 DeleteObject(hFont);
1506 /***********************************************************************
1507 * GetThemeBackgroundContentRect (UXTHEME.@)
1509 HRESULT WINAPI GetThemeBackgroundContentRect(HTHEME hTheme, HDC hdc, int iPartId,
1511 const RECT *pBoundingRect,
1517 TRACE("(%d,%d)\n", iPartId, iStateId);
1521 /* try content margins property... */
1522 hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_CONTENTMARGINS, NULL, &margin);
1524 pContentRect->left = pBoundingRect->left + margin.cxLeftWidth;
1525 pContentRect->top = pBoundingRect->top + margin.cyTopHeight;
1526 pContentRect->right = pBoundingRect->right - margin.cxRightWidth;
1527 pContentRect->bottom = pBoundingRect->bottom - margin.cyBottomHeight;
1529 /* otherwise, try to determine content rect from the background type and props */
1530 int bgtype = BT_BORDERFILL;
1531 memcpy(pContentRect, pBoundingRect, sizeof(RECT));
1533 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1534 if(bgtype == BT_BORDERFILL) {
1537 GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE, &bordersize);
1538 InflateRect(pContentRect, -bordersize, -bordersize);
1539 } else if ((bgtype == BT_IMAGEFILE)
1540 && (SUCCEEDED(hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId,
1541 TMT_SIZINGMARGINS, NULL, &margin)))) {
1542 pContentRect->left = pBoundingRect->left + margin.cxLeftWidth;
1543 pContentRect->top = pBoundingRect->top + margin.cyTopHeight;
1544 pContentRect->right = pBoundingRect->right - margin.cxRightWidth;
1545 pContentRect->bottom = pBoundingRect->bottom - margin.cyBottomHeight;
1547 /* If nothing was found, leave unchanged */
1550 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pContentRect->left, pContentRect->top, pContentRect->right, pContentRect->bottom);
1555 /***********************************************************************
1556 * GetThemeBackgroundExtent (UXTHEME.@)
1558 HRESULT WINAPI GetThemeBackgroundExtent(HTHEME hTheme, HDC hdc, int iPartId,
1559 int iStateId, const RECT *pContentRect,
1565 TRACE("(%d,%d)\n", iPartId, iStateId);
1569 /* try content margins property... */
1570 hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId, TMT_CONTENTMARGINS, NULL, &margin);
1572 pExtentRect->left = pContentRect->left - margin.cxLeftWidth;
1573 pExtentRect->top = pContentRect->top - margin.cyTopHeight;
1574 pExtentRect->right = pContentRect->right + margin.cxRightWidth;
1575 pExtentRect->bottom = pContentRect->bottom + margin.cyBottomHeight;
1577 /* otherwise, try to determine content rect from the background type and props */
1578 int bgtype = BT_BORDERFILL;
1579 memcpy(pExtentRect, pContentRect, sizeof(RECT));
1581 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1582 if(bgtype == BT_BORDERFILL) {
1585 GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE, &bordersize);
1586 InflateRect(pExtentRect, bordersize, bordersize);
1587 } else if ((bgtype == BT_IMAGEFILE)
1588 && (SUCCEEDED(hr = GetThemeMargins(hTheme, hdc, iPartId, iStateId,
1589 TMT_SIZINGMARGINS, NULL, &margin)))) {
1590 pExtentRect->left = pContentRect->left - margin.cxLeftWidth;
1591 pExtentRect->top = pContentRect->top - margin.cyTopHeight;
1592 pExtentRect->right = pContentRect->right + margin.cxRightWidth;
1593 pExtentRect->bottom = pContentRect->bottom + margin.cyBottomHeight;
1595 /* If nothing was found, leave unchanged */
1598 TRACE("left:%ld,top:%ld,right:%ld,bottom:%ld\n", pExtentRect->left, pExtentRect->top, pExtentRect->right, pExtentRect->bottom);
1603 /***********************************************************************
1604 * GetThemeBackgroundRegion (UXTHEME.@)
1606 * Calculate the background region, taking into consideration transparent areas
1607 * of the background image.
1609 HRESULT WINAPI GetThemeBackgroundRegion(HTHEME hTheme, HDC hdc, int iPartId,
1610 int iStateId, const RECT *pRect,
1614 int bgtype = BT_BORDERFILL;
1616 TRACE("(%p,%p,%d,%d)\n", hTheme, hdc, iPartId, iStateId);
1619 if(!pRect || !pRegion)
1622 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1623 if(bgtype == BT_IMAGEFILE) {
1624 FIXME("Images not handled yet\n");
1625 hr = ERROR_CALL_NOT_IMPLEMENTED;
1627 else if(bgtype == BT_BORDERFILL) {
1628 *pRegion = CreateRectRgn(pRect->left, pRect->top, pRect->right, pRect->bottom);
1630 hr = HRESULT_FROM_WIN32(GetLastError());
1633 FIXME("Unknown background type\n");
1634 /* This should never happen, and hence I don't know what to return */
1640 /* compute part size for "borderfill" backgrounds */
1641 HRESULT get_border_background_size (HTHEME hTheme, int iPartId,
1642 int iStateId, THEMESIZE eSize, POINT* psz)
1647 if (SUCCEEDED (hr = GetThemeInt(hTheme, iPartId, iStateId, TMT_BORDERSIZE,
1650 psz->x = psz->y = 2*bordersize;
1651 if (eSize != TS_MIN)
1660 /***********************************************************************
1661 * GetThemePartSize (UXTHEME.@)
1663 HRESULT WINAPI GetThemePartSize(HTHEME hTheme, HDC hdc, int iPartId,
1664 int iStateId, RECT *prc, THEMESIZE eSize,
1667 int bgtype = BT_BORDERFILL;
1669 POINT size = {1, 1};
1674 GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_BGTYPE, &bgtype);
1675 if (bgtype == BT_NONE)
1677 else if(bgtype == BT_IMAGEFILE)
1678 hr = get_image_part_size (hTheme, hdc, iPartId, iStateId, prc, eSize, &size);
1679 else if(bgtype == BT_BORDERFILL)
1680 hr = get_border_background_size (hTheme, iPartId, iStateId, eSize, &size);
1682 FIXME("Unknown background type\n");
1683 /* This should never happen, and hence I don't know what to return */
1692 /***********************************************************************
1693 * GetThemeTextExtent (UXTHEME.@)
1695 HRESULT WINAPI GetThemeTextExtent(HTHEME hTheme, HDC hdc, int iPartId,
1696 int iStateId, LPCWSTR pszText, int iCharCount,
1697 DWORD dwTextFlags, const RECT *pBoundingRect,
1702 HGDIOBJ oldFont = NULL;
1704 RECT rt = {0,0,0xFFFF,0xFFFF};
1706 TRACE("%d %d: stub\n", iPartId, iStateId);
1711 CopyRect(&rt, pBoundingRect);
1713 hr = GetThemeFont(hTheme, hdc, iPartId, iStateId, TMT_FONT, &logfont);
1715 hFont = CreateFontIndirectW(&logfont);
1717 TRACE("Failed to create font\n");
1720 oldFont = SelectObject(hdc, hFont);
1722 DrawTextW(hdc, pszText, iCharCount, &rt, dwTextFlags|DT_CALCRECT);
1723 CopyRect(pExtentRect, &rt);
1726 SelectObject(hdc, oldFont);
1727 DeleteObject(hFont);
1732 /***********************************************************************
1733 * GetThemeTextMetrics (UXTHEME.@)
1735 HRESULT WINAPI GetThemeTextMetrics(HTHEME hTheme, HDC hdc, int iPartId,
1736 int iStateId, TEXTMETRICW *ptm)
1740 HGDIOBJ oldFont = NULL;
1743 TRACE("(%p, %p, %d, %d)\n", hTheme, hdc, iPartId, iStateId);
1747 hr = GetThemeFont(hTheme, hdc, iPartId, iStateId, TMT_FONT, &logfont);
1749 hFont = CreateFontIndirectW(&logfont);
1751 TRACE("Failed to create font\n");
1754 oldFont = SelectObject(hdc, hFont);
1756 if(!GetTextMetricsW(hdc, ptm))
1757 hr = HRESULT_FROM_WIN32(GetLastError());
1760 SelectObject(hdc, oldFont);
1761 DeleteObject(hFont);
1766 /***********************************************************************
1767 * IsThemeBackgroundPartiallyTransparent (UXTHEME.@)
1769 BOOL WINAPI IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId,
1772 BOOL transparent = FALSE;
1773 TRACE("(%d,%d)\n", iPartId, iStateId);
1774 GetThemeBool(hTheme, iPartId, iStateId, TMT_TRANSPARENT, &transparent);