[UXTHEME] -Use and RTL handle table for HTHEME handles. In this way we can ensure that a value we take is valid even if it is non NULL. We can also detect leaks.

svn path=/trunk/; revision=74593
This commit is contained in:
Giannis Adamopoulos 2017-05-19 11:02:44 +00:00
parent 94f9c1a7c1
commit 5f36105c74
6 changed files with 174 additions and 64 deletions

View file

@ -146,16 +146,19 @@ HRESULT WINAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
*/
static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph)
{
PTHEME_CLASS pClass;
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)))
pClass = ValidateHandle(hTheme);
if((tp=MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, image)))
return tp;
GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGESELECTTYPE, &imageselecttype);
@ -167,19 +170,19 @@ static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId,
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);
return MSSTYLES_FindProperty(pClass, 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);
return MSSTYLES_FindProperty(pClass, 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);
MSSTYLES_FindProperty(pClass, 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 */
@ -192,7 +195,7 @@ static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId,
lstrcpynW(szPath, fileProp->lpValue,
min(fileProp->dwValueLen+1, sizeof(szPath)/sizeof(szPath[0])));
hBmp = MSSTYLES_LoadBitmap(hTheme, szPath, &hasAlpha);
hBmp = MSSTYLES_LoadBitmap(pClass, szPath, &hasAlpha);
if(!hBmp) continue;
GetThemeEnumValue(hTheme, iPartId, iStateId, TMT_IMAGELAYOUT, &imagelayout);
@ -214,7 +217,7 @@ static PTHEME_PROPERTY UXTHEME_SelectImage(HTHEME hTheme, HDC hdc, int iPartId,
}
}
/* If an image couldn't be selected, choose the smallest one */
return MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, TMT_IMAGEFILE1);
return MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, TMT_IMAGEFILE1);
}
return NULL;
}
@ -232,13 +235,20 @@ HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, con
int imagenum;
BITMAP bmp;
WCHAR szPath[MAX_PATH];
PTHEME_PROPERTY tp = UXTHEME_SelectImage(hTheme, hdc, iPartId, iStateId, pRect, glyph);
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass;
pClass = ValidateHandle(hTheme);
if (!pClass)
return E_HANDLE;
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);
*hBmp = MSSTYLES_LoadBitmap(pClass, szPath, hasImageAlpha);
if(!*hBmp) {
TRACE("Failed to load bitmap %s\n", debugstr_w(szPath));
return HRESULT_FROM_WIN32(GetLastError());

View file

@ -28,12 +28,11 @@ BOOL WINAPI GetThemeSysBool(HTHEME hTheme, int iBoolID)
HRESULT hr;
PTHEME_PROPERTY tp;
BOOL ret;
PTHEME_CLASS ptc = ValidateHandle(hTheme);
TRACE("(%p, %d)\n", hTheme, iBoolID);
SetLastError(0);
if(hTheme) {
PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
if(ptc) {
if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_BOOL, iBoolID))) {
hr = MSSTYLES_GetPropertyBool(tp, &ret);
if(SUCCEEDED(hr))
@ -60,11 +59,11 @@ COLORREF WINAPI GetThemeSysColor(HTHEME hTheme, int iColorID)
{
HRESULT hr;
PTHEME_PROPERTY tp;
PTHEME_CLASS ptc = ValidateHandle(hTheme);
TRACE("(%p, %d)\n", hTheme, iColorID);
SetLastError(0);
if(hTheme) {
PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
if(ptc) {
if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_COLOR, iColorID + TMT_FIRSTCOLOR))) {
COLORREF color;
hr = MSSTYLES_GetPropertyColor(tp, &color);
@ -93,10 +92,10 @@ HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf)
{
HRESULT hr = S_OK;
PTHEME_PROPERTY tp;
PTHEME_CLASS ptc = ValidateHandle(hTheme);
TRACE("(%p, %d)\n", hTheme, iFontID);
if(hTheme) {
PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
if(ptc) {
if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_FONT, iFontID))) {
HDC hdc = GetDC(NULL);
hr = MSSTYLES_GetPropertyFont(tp, hdc, plf);
@ -135,10 +134,10 @@ HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf)
HRESULT WINAPI GetThemeSysInt(HTHEME hTheme, int iIntID, int *piValue)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
PTHEME_CLASS ptc = ValidateHandle(hTheme);
TRACE("(%p, %d)\n", hTheme, iIntID);
if(!hTheme)
if(!ptc)
return E_HANDLE;
if(iIntID < TMT_FIRSTINT || iIntID > TMT_LASTINT) {
WARN("Unknown IntID: %d\n", iIntID);
@ -168,10 +167,9 @@ int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
SM_CXMENUSIZE, TMT_MENUBARWIDTH,
SM_CYMENUSIZE, TMT_MENUBARHEIGHT
};
PTHEME_CLASS ptc = ValidateHandle(hTheme);
if(hTheme) {
PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
if(ptc) {
for(i=0; i<sizeof(metricMap)/sizeof(metricMap[0]); i+=2) {
if(metricMap[i] == iSizeID) {
id = metricMap[i+1];
@ -208,10 +206,10 @@ HRESULT WINAPI GetThemeSysString(HTHEME hTheme, int iStringID,
LPWSTR pszStringBuff, int cchMaxStringChars)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
PTHEME_CLASS ptc = ValidateHandle(hTheme);
TRACE("(%p, %d)\n", hTheme, iStringID);
if(!hTheme)
if(!ptc)
return E_HANDLE;
if(iStringID < TMT_FIRSTSTRING || iStringID > TMT_LASTSTRING) {
WARN("Unknown StringID: %d\n", iStringID);

View file

@ -78,9 +78,6 @@ HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWST
LPWSTR pszSelectedSize = NULL;
LPWSTR tmp;
if (!gbThemeHooksActive)
return E_FAIL;
TRACE("Opening %s\n", debugstr_w(lpThemeFile));
hTheme = LoadLibraryExW(lpThemeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);

View file

@ -27,12 +27,14 @@ HRESULT WINAPI GetThemeBool(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, BOOL *pfVal)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_BOOL, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_BOOL, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyBool(tp, pfVal);
}
@ -44,12 +46,13 @@ HRESULT WINAPI GetThemeColor(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, COLORREF *pColor)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_COLOR, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_COLOR, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyColor(tp, pColor);
}
@ -63,12 +66,13 @@ HRESULT WINAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, int iStateId,
HRESULT hr;
WCHAR val[60];
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_ENUM, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_ENUM, iPropId)))
return E_PROP_ID_UNSUPPORTED;
hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0]));
@ -87,12 +91,13 @@ HRESULT WINAPI GetThemeFilename(HTHEME hTheme, int iPartId, int iStateId,
int cchMaxBuffChars)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FILENAME, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyString(tp, pszThemeFilename, cchMaxBuffChars);
}
@ -104,12 +109,13 @@ HRESULT WINAPI GetThemeFont(HTHEME hTheme, HDC hdc, int iPartId,
int iStateId, int iPropId, LOGFONTW *pFont)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FONT, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_FONT, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyFont(tp, hdc, pFont);
}
@ -121,12 +127,13 @@ HRESULT WINAPI GetThemeInt(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, int *piVal)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_INT, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_INT, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyInt(tp, piVal);
}
@ -138,12 +145,13 @@ HRESULT WINAPI GetThemeIntList(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, INTLIST *pIntList)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_INTLIST, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_INTLIST, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyIntList(tp, pIntList);
}
@ -155,12 +163,13 @@ HRESULT WINAPI GetThemePosition(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, POINT *pPoint)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_POSITION, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_POSITION, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyPosition(tp, pPoint);
}
@ -172,12 +181,13 @@ HRESULT WINAPI GetThemeRect(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, RECT *pRect)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_RECT, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_RECT, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyRect(tp, pRect);
}
@ -189,12 +199,13 @@ HRESULT WINAPI GetThemeString(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, LPWSTR pszBuff, int cchMaxBuffChars)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_STRING, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_STRING, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyString(tp, pszBuff, cchMaxBuffChars);
}
@ -207,13 +218,14 @@ HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId,
MARGINS *pMargins)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
memset (pMargins, 0, sizeof (MARGINS));
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_MARGINS, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_MARGINS, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyMargins(tp, prc, pMargins);
}
@ -227,13 +239,15 @@ HRESULT WINAPI GetThemeMetric(HTHEME hTheme, HDC hdc, int iPartId,
PTHEME_PROPERTY tp;
WCHAR val[60];
HRESULT hr;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 0, iPropId)))
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, 0, iPropId)))
return E_PROP_ID_UNSUPPORTED;
switch(tp->iPrimitiveType) {
case TMT_POSITION: /* Only the X coord is retrieved */
case TMT_MARGINS: /* Only the cxLeftWidth member is retrieved */
@ -267,12 +281,13 @@ HRESULT WINAPI GetThemePropertyOrigin(HTHEME hTheme, int iPartId, int iStateId,
int iPropId, PROPERTYORIGIN *pOrigin)
{
PTHEME_PROPERTY tp;
PTHEME_CLASS pClass = ValidateHandle(hTheme);
TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
if(!hTheme)
if(!pClass)
return E_HANDLE;
if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 0, iPropId))) {
if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, 0, iPropId))) {
*pOrigin = PO_NOTFOUND;
return S_OK;
}

View file

@ -53,6 +53,9 @@ ATOM atWndContext;
PTHEME_FILE ActiveThemeFile;
RTL_HANDLE_TABLE g_UxThemeHandleTable;
int g_cHandles;
/***********************************************************************/
static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
@ -189,7 +192,7 @@ void UXTHEME_LoadTheme(BOOL bLoad)
WCHAR szCurrentSize[64];
BOOL bThemeActive = FALSE;
if(bLoad == TRUE)
if(bLoad == TRUE && gbThemeHooksActive)
{
/* Get current theme configuration */
if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
@ -582,6 +585,9 @@ void UXTHEME_InitSystem(HINSTANCE hInst)
atSubIdList = GlobalAddAtomW(szSubIdList);
atDialogThemeEnabled = GlobalAddAtomW(szDialogThemeEnabled);
atWndContext = GlobalAddAtomW(L"ux_WndContext");
RtlInitializeHandleTable(0xFFF, sizeof(UXTHEME_HANDLE), &g_UxThemeHandleTable);
g_cHandles = 0;
}
/***********************************************************************
@ -708,6 +714,23 @@ static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer,
return NULL;
}
PTHEME_CLASS ValidateHandle(HTHEME hTheme)
{
PUXTHEME_HANDLE pHandle;
if (!gbThemeHooksActive || !hTheme || hTheme == INVALID_HANDLE_VALUE)
return NULL;
if (!RtlIsValidHandle(&g_UxThemeHandleTable, (PRTL_HANDLE_TABLE_ENTRY)hTheme))
{
ERR("Invalid handle 0x%x!\n", hTheme);
return NULL;
}
pHandle = hTheme;
return pHandle->pClass;
}
static HTHEME WINAPI
OpenThemeDataInternal(PTHEME_FILE ThemeFile, HWND hwnd, LPCWSTR pszClassList, DWORD flags)
{
@ -732,11 +755,31 @@ OpenThemeDataInternal(PTHEME_FILE ThemeFile, HWND hwnd, LPCWSTR pszClassList, DW
if(!pszUseClassList)
pszUseClassList = pszClassList;
if (pszUseClassList)
{
if (!ThemeFile->classes)
MSSTYLES_ParseThemeIni(ThemeFile);
hTheme = MSSTYLES_OpenThemeClass(ThemeFile, pszAppName, pszUseClassList);
if (pszUseClassList)
{
PTHEME_CLASS pClass;
PUXTHEME_HANDLE pHandle;
if (!ThemeFile->classes)
MSSTYLES_ParseThemeIni(ThemeFile);
pClass = MSSTYLES_OpenThemeClass(ThemeFile, pszAppName, pszUseClassList);
if (pClass)
{
pHandle = (PUXTHEME_HANDLE)RtlAllocateHandle(&g_UxThemeHandleTable, NULL);
if (pHandle)
{
g_cHandles++;
TRACE("Created handle 0x%x for class 0x%x, app %S, class %S. Count: %d\n", pHandle, pClass, pszAppName, pszUseClassList, g_cHandles);
pHandle->pClass = pClass;
pHandle->Handle.Flags = RTL_HANDLE_VALID;
hTheme = pHandle;
}
else
{
MSSTYLES_CloseThemeClass(pClass);
}
}
}
}
@ -894,12 +937,22 @@ void WINAPI SetThemeAppProperties(DWORD dwFlags)
*/
HRESULT WINAPI CloseThemeData(HTHEME hTheme)
{
PUXTHEME_HANDLE pHandle = hTheme;
HRESULT hr;
TRACE("(%p)\n", hTheme);
if(!hTheme || hTheme == INVALID_HANDLE_VALUE)
if (!RtlIsValidHandle(&g_UxThemeHandleTable, (PRTL_HANDLE_TABLE_ENTRY)hTheme))
return E_HANDLE;
if(IsBadReadPtr (hTheme, sizeof(THEME_CLASS))) /* This check is a hack! */
return E_HANDLE;
return MSSTYLES_CloseThemeClass(hTheme);
hr = MSSTYLES_CloseThemeClass(pHandle->pClass);
if (SUCCEEDED(hr))
{
RtlFreeHandle(&g_UxThemeHandleTable, (PRTL_HANDLE_TABLE_ENTRY)pHandle);
g_cHandles--;
TRACE("Destroying handle 0x%x for class 0x%x. Count: %d\n", pHandle, pHandle->pClass, g_cHandles);
}
return hr;
}
/***********************************************************************
@ -911,7 +964,7 @@ HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
POINT ptTest, WORD *pwHitTestCode)
{
FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
if(!hTheme)
if (!ValidateHandle(hTheme))
return E_HANDLE;
return E_NOTIMPL;
}
@ -921,12 +974,17 @@ HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
*/
BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
{
PTHEME_CLASS pClass;
TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
if(!hTheme) {
pClass = ValidateHandle(hTheme);
if (!pClass)
{
SetLastError(E_HANDLE);
return FALSE;
}
if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
if(MSSTYLES_FindPartState(pClass, iPartId, iStateId, NULL))
return TRUE;
return FALSE;
}
@ -960,6 +1018,9 @@ HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
pszValueBuff, cchMaxValChars);
if (!gbThemeHooksActive)
return E_FAIL;
hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
if(FAILED(hr)) return hr;
@ -1032,6 +1093,10 @@ HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
debugstr_w(pszColorName), debugstr_w(pszSizeName),
hThemeFile, unknown);
if (!gbThemeHooksActive)
return E_FAIL;
return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
}
@ -1113,6 +1178,9 @@ HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
pszColorName, dwColorNameLen,
pszSizeName, dwSizeNameLen);
if (!gbThemeHooksActive)
return E_FAIL;
hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
if(FAILED(hr)) return hr;
@ -1231,6 +1299,9 @@ HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
debugstr_w(pszSizeName), dwColorNum);
if (!gbThemeHooksActive)
return E_FAIL;
hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
if(FAILED(hr)) return hr;
@ -1291,6 +1362,9 @@ HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
debugstr_w(pszColorName), dwSizeNum);
if (!gbThemeHooksActive)
return E_FAIL;
hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
if(FAILED(hr)) return hr;
@ -1359,6 +1433,10 @@ HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
PTHEME_FILE pt;
HRESULT hr;
TRACE("(%s)\n", debugstr_w(pszThemeFileName));
if (!gbThemeHooksActive)
return E_FAIL;
hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
if(FAILED(hr))
return hr;

View file

@ -20,6 +20,10 @@
#include <vfwmsgs.h>
#include <tmschema.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>
#include <ndk/rtltypes.h>
#include <wine/debug.h>
WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
@ -86,6 +90,14 @@ typedef struct _THEME_FILE {
typedef struct _UXINI_FILE *PUXINI_FILE;
typedef struct _UXTHEME_HANDLE
{
RTL_HANDLE_TABLE_ENTRY Handle;
PTHEME_CLASS pClass;
} UXTHEME_HANDLE, *PUXTHEME_HANDLE;
PTHEME_CLASS ValidateHandle(HTHEME hTheme);
HRESULT UXTHEME_LoadImage(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, BOOL glyph,
HBITMAP *hBmp, RECT *bmpRect, BOOL* hasImageAlpha);