Sweden-Number/dlls/uxtheme/metric.c

260 lines
8.2 KiB
C
Raw Normal View History

2003-12-04 21:55:30 +01:00
/*
* Win32 5.1 Theme metrics
*
* 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
2003-12-04 21:55:30 +01:00
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
2004-02-20 06:12:21 +01:00
#include "winuser.h"
#include "vfwmsgs.h"
2003-12-04 21:55:30 +01:00
#include "uxtheme.h"
#include "vssym32.h"
2003-12-04 21:55:30 +01:00
#include "msstyles.h"
2003-12-04 21:55:30 +01:00
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
/***********************************************************************
* GetThemeSysBool (UXTHEME.@)
*/
BOOL WINAPI GetThemeSysBool(HTHEME hTheme, int iBoolID)
{
2004-02-20 06:12:21 +01:00
HRESULT hr;
PTHEME_PROPERTY tp;
BOOL ret;
TRACE("(%p, %d)\n", hTheme, iBoolID);
SetLastError(0);
if(hTheme) {
if((tp = MSSTYLES_FindMetric(TMT_BOOL, iBoolID))) {
hr = MSSTYLES_GetPropertyBool(tp, &ret);
if(SUCCEEDED(hr))
return ret;
else
SetLastError(hr);
}
}
if(iBoolID == TMT_FLATMENUS) {
if(SystemParametersInfoW(SPI_GETFLATMENU, 0, &ret, 0))
return ret;
}
else {
FIXME("Unknown bool id: %d\n", iBoolID);
SetLastError(STG_E_INVALIDPARAMETER);
}
2003-12-04 21:55:30 +01:00
return FALSE;
}
/***********************************************************************
* GetThemeSysColor (UXTHEME.@)
*/
COLORREF WINAPI GetThemeSysColor(HTHEME hTheme, int iColorID)
{
2004-02-20 06:12:21 +01:00
HRESULT hr;
PTHEME_PROPERTY tp;
TRACE("(%p, %d)\n", hTheme, iColorID);
SetLastError(0);
if(hTheme) {
if((tp = MSSTYLES_FindMetric(TMT_COLOR, iColorID))) {
COLORREF color;
hr = MSSTYLES_GetPropertyColor(tp, &color);
if(SUCCEEDED(hr))
return color;
else
SetLastError(hr);
}
}
return GetSysColor(iColorID);
2003-12-04 21:55:30 +01:00
}
/***********************************************************************
* GetThemeSysColorBrush (UXTHEME.@)
*/
HBRUSH WINAPI GetThemeSysColorBrush(HTHEME hTheme, int iColorID)
{
2004-02-20 06:12:21 +01:00
TRACE("(%p, %d)\n", hTheme, iColorID);
return CreateSolidBrush(GetThemeSysColor(hTheme, iColorID));
2003-12-04 21:55:30 +01:00
}
/***********************************************************************
* GetThemeSysFont (UXTHEME.@)
*/
HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf)
{
2004-02-20 06:12:21 +01:00
HRESULT hr = S_OK;
PTHEME_PROPERTY tp;
TRACE("(%p, %d)\n", hTheme, iFontID);
if(hTheme) {
if((tp = MSSTYLES_FindMetric(TMT_FONT, iFontID))) {
HDC hdc = GetDC(NULL);
hr = MSSTYLES_GetPropertyFont(tp, hdc, plf);
ReleaseDC(NULL, hdc);
if(SUCCEEDED(hr))
return S_OK;
}
}
if(iFontID == TMT_ICONTITLEFONT) {
2012-05-22 01:52:40 +02:00
if(!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(LOGFONTW), plf, 0))
2004-02-20 06:12:21 +01:00
return HRESULT_FROM_WIN32(GetLastError());
}
else {
NONCLIENTMETRICSW ncm;
LOGFONTW *font = NULL;
ncm.cbSize = sizeof(NONCLIENTMETRICSW);
if(!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0))
return HRESULT_FROM_WIN32(GetLastError());
switch(iFontID) {
case TMT_CAPTIONFONT: font = &ncm.lfCaptionFont; break;
case TMT_SMALLCAPTIONFONT: font = &ncm.lfSmCaptionFont; break;
case TMT_MENUFONT: font = &ncm.lfMenuFont; break;
case TMT_STATUSFONT: font = &ncm.lfStatusFont; break;
case TMT_MSGBOXFONT: font = &ncm.lfMessageFont; break;
default: FIXME("Unknown FontID: %d\n", iFontID); break;
}
if(font) *plf = *font;
2004-02-20 06:12:21 +01:00
else hr = STG_E_INVALIDPARAMETER;
}
return hr;
2003-12-04 21:55:30 +01:00
}
/***********************************************************************
* GetThemeSysInt (UXTHEME.@)
*/
HRESULT WINAPI GetThemeSysInt(HTHEME hTheme, int iIntID, int *piValue)
{
2004-02-20 06:12:21 +01:00
PTHEME_PROPERTY tp;
TRACE("(%p, %d)\n", hTheme, iIntID);
2003-12-04 21:55:30 +01:00
if(!hTheme)
return E_HANDLE;
if(iIntID < TMT_FIRSTINT || iIntID > TMT_LASTINT) {
WARN("Unknown IntID: %d\n", iIntID);
2004-02-20 06:12:21 +01:00
return STG_E_INVALIDPARAMETER;
}
if((tp = MSSTYLES_FindMetric(TMT_INT, iIntID)))
return MSSTYLES_GetPropertyInt(tp, piValue);
return E_PROP_ID_UNSUPPORTED;
2003-12-04 21:55:30 +01:00
}
/***********************************************************************
* GetThemeSysSize (UXTHEME.@)
*/
int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
{
static const int metricMap[] = {
2004-02-20 06:12:21 +01:00
SM_CXVSCROLL, TMT_SCROLLBARWIDTH,
SM_CYHSCROLL, TMT_SCROLLBARHEIGHT,
SM_CXSIZE, TMT_CAPTIONBARWIDTH,
SM_CYSIZE, TMT_CAPTIONBARHEIGHT,
SM_CXFRAME, TMT_SIZINGBORDERWIDTH,
SM_CYFRAME, TMT_SIZINGBORDERWIDTH, /* There is no TMT_SIZINGBORDERHEIGHT, but this works in windows.. */
SM_CXSMSIZE, TMT_SMCAPTIONBARWIDTH,
SM_CYSMSIZE, TMT_SMCAPTIONBARHEIGHT,
SM_CXMENUSIZE, TMT_MENUBARWIDTH,
SM_CYMENUSIZE, TMT_MENUBARHEIGHT
};
PTHEME_PROPERTY tp;
int i, id = -1;
2004-02-20 06:12:21 +01:00
if(hTheme) {
for(i=0; i<ARRAY_SIZE(metricMap); i+=2) {
2004-02-20 06:12:21 +01:00
if(metricMap[i] == iSizeID) {
id = metricMap[i+1];
break;
}
}
SetLastError(0);
if(id != -1) {
if((tp = MSSTYLES_FindMetric(TMT_SIZE, id))) {
if(SUCCEEDED(MSSTYLES_GetPropertyInt(tp, &i))) {
return i;
}
}
TRACE("Size %d not found in theme, using system metric\n", iSizeID);
}
else {
SetLastError(STG_E_INVALIDPARAMETER);
return 0;
}
}
return GetSystemMetrics(iSizeID);
2003-12-04 21:55:30 +01:00
}
/***********************************************************************
* GetThemeSysString (UXTHEME.@)
*/
HRESULT WINAPI GetThemeSysString(HTHEME hTheme, int iStringID,
LPWSTR pszStringBuff, int cchMaxStringChars)
{
2004-02-20 06:12:21 +01:00
PTHEME_PROPERTY tp;
TRACE("(%p, %d)\n", hTheme, iStringID);
2003-12-04 21:55:30 +01:00
if(!hTheme)
return E_HANDLE;
if(iStringID < TMT_FIRSTSTRING || iStringID > TMT_LASTSTRING) {
WARN("Unknown StringID: %d\n", iStringID);
2004-02-20 06:12:21 +01:00
return STG_E_INVALIDPARAMETER;
}
if((tp = MSSTYLES_FindMetric(TMT_STRING, iStringID)))
return MSSTYLES_GetPropertyString(tp, pszStringBuff, cchMaxStringChars);
return E_PROP_ID_UNSUPPORTED;
2003-12-04 21:55:30 +01:00
}
/***********************************************************************
* GetThemeTransitionDuration (UXTHEME.@)
*/
HRESULT WINAPI GetThemeTransitionDuration(HTHEME hTheme, int iPartId, int iStateIdFrom,
int iStateIdTo, int iPropId, DWORD *pdwDuration)
{
INTLIST intlist;
HRESULT hr;
TRACE("(%p, %d, %d, %d, %d, %p)\n", hTheme, iPartId, iStateIdFrom, iStateIdTo, iPropId,
pdwDuration);
if (!pdwDuration || iStateIdFrom < 1 || iStateIdTo < 1)
return E_INVALIDARG;
hr = GetThemeIntList(hTheme, iPartId, 0, iPropId, &intlist);
if (FAILED(hr))
{
if (hr == E_PROP_ID_UNSUPPORTED)
*pdwDuration = 0;
return hr;
}
if (intlist.iValueCount < 1 || iStateIdFrom > intlist.iValues[0]
|| iStateIdTo > intlist.iValues[0]
|| intlist.iValueCount != 1 + intlist.iValues[0] * intlist.iValues[0])
{
*pdwDuration = 0;
return E_INVALIDARG;
}
*pdwDuration = intlist.iValues[1 + intlist.iValues[0] * (iStateIdFrom - 1) + (iStateIdTo - 1)];
return S_OK;
}