📄 draw.c
字号:
/*
* Win32 5.1 Theme drawing
*
* Copyright (C) 2003 Kevin Koltzau
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdlib.h>
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "wingdi.h"
#include "vfwmsgs.h"
#include "uxtheme.h"
#include "tmschema.h"
#include "msstyles.h"
#include "uxthemedll.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
/***********************************************************************
* Defines and global variables
*/
extern ATOM atDialogThemeEnabled;
/***********************************************************************/
/***********************************************************************
* EnableThemeDialogTexture (UXTHEME.@)
*/
HRESULT WINAPI EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags)
{
static const WCHAR szTab[] = { 'T','a','b',0 };
HRESULT hr;
TRACE("(%p,0x%08x\n", hwnd, dwFlags);
hr = SetPropW (hwnd, (LPCWSTR)MAKEINTATOM(atDialogThemeEnabled),
(HANDLE)(dwFlags|0x80000000));
/* 0x80000000 serves as a "flags set" flag */
if (FAILED(hr))
return hr;
if (dwFlags & ETDT_USETABTEXTURE)
return SetWindowTheme (hwnd, NULL, szTab);
else
return SetWindowTheme (hwnd, NULL, NULL);
return S_OK;
}
/***********************************************************************
* IsThemeDialogTextureEnabled (UXTHEME.@)
*/
BOOL WINAPI IsThemeDialogTextureEnabled(HWND hwnd)
{
DWORD dwDialogTextureFlags;
TRACE("(%p)\n", hwnd);
dwDialogTextureFlags = (DWORD)GetPropW (hwnd,
(LPCWSTR)MAKEINTATOM(atDialogThemeEnabled));
if (dwDialogTextureFlags == 0)
/* Means EnableThemeDialogTexture wasn't called for this dialog */
return TRUE;
return (dwDialogTextureFlags & ETDT_ENABLE) && !(dwDialogTextureFlags & ETDT_DISABLE);
}
/***********************************************************************
* DrawThemeParentBackground (UXTHEME.@)
*/
HRESULT WINAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT *prc)
{
RECT rt;
POINT org;
HWND hParent;
HRGN clip = NULL;
int hasClip = -1;
TRACE("(%p,%p,%p)\n", hwnd, hdc, prc);
hParent = GetParent(hwnd);
if(!hParent)
hParent = hwnd;
if(prc) {
CopyRect(&rt, prc);
MapWindowPoints(hwnd, NULL, (LPPOINT)&rt, 2);
clip = CreateRectRgn(0,0,1,1);
hasClip = GetClipRgn(hdc, clip);
if(hasClip == -1)
TRACE("Failed to get original clipping region\n");
else
IntersectClipRect(hdc, prc->left, prc->top, prc->right, prc->bottom);
}
else {
GetClientRect(hParent, &rt);
MapWindowPoints(hParent, NULL, (LPPOINT)&rt, 2);
}
OffsetViewportOrgEx(hdc, -rt.left, -rt.top, &org);
SendMessageW(hParent, WM_ERASEBKGND, (WPARAM)hdc, 0);
SendMessageW(hParent, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
SetViewportOrgEx(hdc, org.x, org.y, NULL);
if(prc) {
if(hasClip == 0)
SelectClipRgn(hdc, NULL);
else if(hasClip == 1)
SelectClipRgn(hdc, clip);
DeleteObject(clip);
}
return S_OK;
}
/***********************************************************************
* DrawThemeBackground (UXTHEME.@)
*/
HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
int iStateId, const RECT *pRect,
const RECT *pClipRect)
{
DTBGOPTS opts;
opts.dwSize = sizeof(DTBGOPTS);
opts.dwFlags = 0;
if(pClipRect) {
opts.dwFlags |= DTBG_CLIPRECT;
CopyRect(&opts.rcClip, pClipRect);
}
return DrawThemeBackgroundEx(hTheme, hdc, iPartId, iStateId, pRect, &opts);
}
/***********************************************************************
* UXTHEME_SelectImage
*
* Select the image to use
*/
static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph)
{
PTHEME_PROPERTY tp;
int imageselecttype = IST_NONE;
int i;
int image;
if(glyph)
image = TMT_GLYPHIMAGEFILE;
else
image = TMT_IMAGEFILE;
if((tp=MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, image)))
return tp;
GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGESELECTTYPE, &imageselecttype);
if(imageselecttype == IST_DPI) {
int reqdpi = 0;
int screendpi = GetDeviceCaps(hdc, LOGPIXELSX);
for(i=4; i>=0; i--) {
reqdpi = 0;
if(SUCCEEDED(GetThemeInt(hTheme, iPartId, iStateId, i + TMT_MINDPI1, &reqdpi))) {
if(reqdpi != 0 && screendpi >= reqdpi) {
TRACE("Using %d DPI, image %d\n", reqdpi, i + TMT_IMAGEFILE1);
return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, i + TMT_IMAGEFILE1);
}
}
}
/* If an image couldn't be selected, choose the first one */
return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, TMT_IMAGEFILE1);
}
else if(imageselecttype == IST_SIZE) {
POINT size = {pRect->right-pRect->left, pRect->bottom-pRect->top};
POINT reqsize;
for(i=4; i>=0; i--) {
PTHEME_PROPERTY fileProp =
MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, i + TMT_IMAGEFILE1);
if (!fileProp) continue;
if(FAILED(GetThemePosition(hTheme, iPartId, iStateId, i + TMT_MINSIZE1, &reqsize))) {
/* fall back to size of Nth image */
WCHAR szPath[MAX_PATH];
int imagelayout = IL_HORIZONTAL;
int imagecount = 1;
int imagenum;
BITMAP bmp;
HBITMAP hBmp;
BOOL hasAlpha;
lstrcpynW(szPath, fileProp->lpValue,
min(fileProp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, &hasAlpha);
if(!hBmp) continue;
GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGELAYOUT, &imagelayout);
GetThemeInt(hTheme, iPartId, iStateId, TMT_IMAGECOUNT, &imagecount);
imagenum = max (min (imagecount, iStateId), 1) - 1;
GetObjectW(hBmp, sizeof(bmp), &bmp);
if(imagelayout == IL_VERTICAL) {
reqsize.x = bmp.bmWidth;
reqsize.y = bmp.bmHeight/imagecount;
}
else {
reqsize.x = bmp.bmWidth/imagecount;
reqsize.y = bmp.bmHeight;
}
}
if(reqsize.x <= size.x && reqsize.y <= size.y) {
TRACE("Using image size %dx%d, image %d\n", reqsize.x, reqsize.y, i + TMT_IMAGEFILE1);
return fileProp;
}
}
/* If an image couldn't be selected, choose the smallest one */
return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, TMT_IMAGEFILE1);
}
return NULL;
}
/***********************************************************************
* UXTHEME_LoadImage
*
* Load image for part/state
*/
static HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph,
HBITMAP *hBmp, RECT *bmpRect, BOOL* hasImageAlpha)
{
int imagelayout = IL_HORIZONTAL;
int imagecount = 1;
int imagenum;
BITMAP bmp;
WCHAR szPath[MAX_PATH];
PTHEME_PROPERTY tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, pRect, glyph);
if(!tp) {
FIXME("Couldn't determine image for part/state %d/%d, invalid theme?\n", iPartId, iStateId);
return E_PROP_ID_UNSUPPORTED;
}
lstrcpynW(szPath, tp->lpValue, min(tp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
*hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, hasImageAlpha);
if(!*hBmp) {
TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));
return HRESULT_FROM_WIN32(GetLastError());
}
GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGELAYOUT, &imagelayout);
GetThemeInt(hTheme, iPartId, iStateId, TMT_IMAGECOUNT, &imagecount);
imagenum = max (min (imagecount, iStateId), 1) - 1;
GetObjectW(*hBmp, sizeof(bmp), &bmp);
if(imagelayout == IL_VERTICAL) {
int height = bmp.bmHeight/imagecount;
bmpRect->left = 0;
bmpRect->right = bmp.bmWidth;
bmpRect->top = imagenum * height;
bmpRect->bottom = bmpRect->top + height;
}
else {
int width = bmp.bmWidth/imagecount;
bmpRect->left = imagenum * width;
bmpRect->right = bmpRect->left + width;
bmpRect->top = 0;
bmpRect->bottom = bmp.bmHeight;
}
return S_OK;
}
/***********************************************************************
* UXTHEME_StretchBlt
*
* Pseudo TransparentBlt/StretchBlt
*/
static inline BOOL UXTHEME_StretchBlt(HDC hdcDst, int nXOriginDst, int nYOriginDst, int nWidthDst, int nHeightDst,
HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc,
INT transparent, COLORREF transcolor)
{
static const BLENDFUNCTION blendFunc =
{
AC_SRC_OVER, /* BlendOp */
0, /* BlendFlag */
255, /* SourceConstantAlpha */
AC_SRC_ALPHA /* AlphaFormat */
};
if (transparent == ALPHABLEND_BINARY) {
/* Ensure we don't pass any negative values to TransparentBlt */
return TransparentBlt(hdcDst, nXOriginDst, nYOriginDst, abs(nWidthDst), abs(nHeightDst),
hdcSrc, nXOriginSrc, nYOriginSrc, abs(nWidthSrc), abs(nHeightSrc),
transcolor);
}
if ((transparent == ALPHABLEND_NONE) ||
!AlphaBlend(hdcDst, nXOriginDst, nYOriginDst, nWidthDst, nHeightDst,
hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
blendFunc))
{
return StretchBlt(hdcDst, nXOriginDst, nYOriginDst, nWidthDst, nHeightDst,
hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
SRCCOPY);
}
return TRUE;
}
/***********************************************************************
* UXTHEME_Blt
*
* Simplify sending same width/height for both source and dest
*/
static inline BOOL UXTHEME_Blt(HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest,
HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
INT transparent, COLORREF transcolor)
{
return UXTHEME_StretchBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
hdcSrc, nXOriginSrc, nYOriginSrc, nWidthDest, nHeightDest,
transparent, transcolor);
}
/***********************************************************************
* UXTHEME_SizedBlt
*
* Stretches or tiles, depending on sizingtype.
*/
static inline BOOL UXTHEME_SizedBlt (HDC hdcDst, int nXOriginDst, int nYOriginDst,
int nWidthDst, int nHeightDst,
HDC hdcSrc, int nXOriginSrc, int nYOriginSrc,
int nWidthSrc, int nHeightSrc,
int sizingtype,
INT transparent, COLORREF transcolor)
{
if (sizingtype == ST_TILE)
{
int yOfs = nYOriginDst;
int yRemaining = nHeightDst;
while (yRemaining > 0)
{
int bltHeight = min (yRemaining, nHeightSrc);
int xOfs = nXOriginDst;
int xRemaining = nWidthDst;
while (xRemaining > 0)
{
int bltWidth = min (xRemaining, nWidthSrc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -