Author: gadamopoulos
Date: Fri May 19 11:02:44 2017
New Revision: 74593
URL:
http://svn.reactos.org/svn/reactos?rev=74593&view=rev
Log:
[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.
Modified:
trunk/reactos/dll/win32/uxtheme/draw.c
trunk/reactos/dll/win32/uxtheme/metric.c
trunk/reactos/dll/win32/uxtheme/msstyles.c
trunk/reactos/dll/win32/uxtheme/property.c
trunk/reactos/dll/win32/uxtheme/system.c
trunk/reactos/dll/win32/uxtheme/uxthemep.h
Modified: trunk/reactos/dll/win32/uxtheme/draw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/draw.c?r…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/draw.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/draw.c [iso-8859-1] Fri May 19 11:02:44 2017
@@ -146,16 +146,19 @@
*/
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 @@
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 @@
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 @@
}
}
/* 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 @@
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());
Modified: trunk/reactos/dll/win32/uxtheme/metric.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/metric.c…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/metric.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/metric.c [iso-8859-1] Fri May 19 11:02:44 2017
@@ -28,12 +28,11 @@
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 @@
{
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 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 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 @@
SM_CXMENUSIZE, TMT_MENUBARWIDTH,
SM_CYMENUSIZE, TMT_MENUBARHEIGHT
};
-
- if(hTheme) {
- PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
-
+ PTHEME_CLASS ptc = ValidateHandle(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 @@
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);
Modified: trunk/reactos/dll/win32/uxtheme/msstyles.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/msstyles…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/msstyles.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/msstyles.c [iso-8859-1] Fri May 19 11:02:44 2017
@@ -77,9 +77,6 @@
LPWSTR pszSizes;
LPWSTR pszSelectedSize = NULL;
LPWSTR tmp;
-
- if (!gbThemeHooksActive)
- return E_FAIL;
TRACE("Opening %s\n", debugstr_w(lpThemeFile));
Modified: trunk/reactos/dll/win32/uxtheme/property.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/property…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/property.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/property.c [iso-8859-1] Fri May 19 11:02:44 2017
@@ -27,12 +27,14 @@
int iPropId, BOOL *pfVal)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_BOOL, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+
+ if(!pClass)
+ return E_HANDLE;
+
+ if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_BOOL, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyBool(tp, pfVal);
}
@@ -44,12 +46,13 @@
int iPropId, COLORREF *pColor)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_COLOR, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 hr;
WCHAR val[60];
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_ENUM, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 @@
int cchMaxBuffChars)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 @@
int iStateId, int iPropId, LOGFONTW *pFont)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FONT, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 @@
int iPropId, int *piVal)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_INT, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_INT, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyInt(tp, piVal);
}
@@ -138,12 +145,13 @@
int iPropId, INTLIST *pIntList)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_INTLIST, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_INTLIST, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyIntList(tp, pIntList);
}
@@ -155,12 +163,13 @@
int iPropId, POINT *pPoint)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_POSITION, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_POSITION, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyPosition(tp, pPoint);
}
@@ -172,12 +181,13 @@
int iPropId, RECT *pRect)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_RECT, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, TMT_RECT, iPropId)))
return E_PROP_ID_UNSUPPORTED;
return MSSTYLES_GetPropertyRect(tp, pRect);
}
@@ -189,12 +199,13 @@
int iPropId, LPWSTR pszBuff, int cchMaxBuffChars)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_STRING, iPropId)))
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 @@
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)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_MARGINS, iPropId)))
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 @@
PTHEME_PROPERTY tp;
WCHAR val[60];
HRESULT hr;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 0, iPropId)))
- return E_PROP_ID_UNSUPPORTED;
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ 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 @@
int iPropId, PROPERTYORIGIN *pOrigin)
{
PTHEME_PROPERTY tp;
-
- TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
- if(!hTheme)
- return E_HANDLE;
-
- if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 0, iPropId))) {
+ PTHEME_CLASS pClass = ValidateHandle(hTheme);
+
+ TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
+ if(!pClass)
+ return E_HANDLE;
+
+ if(!(tp = MSSTYLES_FindProperty(pClass, iPartId, iStateId, 0, iPropId))) {
*pOrigin = PO_NOTFOUND;
return S_OK;
}
Modified: trunk/reactos/dll/win32/uxtheme/system.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/system.c…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/system.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/system.c [iso-8859-1] Fri May 19 11:02:44 2017
@@ -53,6 +53,9 @@
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 @@
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 @@
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 @@
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 @@
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 @@
*/
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 @@
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 @@
*/
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 @@
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 @@
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);
}
@@ -1112,6 +1177,9 @@
TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
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 @@
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 @@
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 @@
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;
Modified: trunk/reactos/dll/win32/uxtheme/uxthemep.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/uxthemep…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/uxthemep.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/uxthemep.h [iso-8859-1] Fri May 19 11:02:44 2017
@@ -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);
@@ -85,6 +89,14 @@
} THEME_FILE, *PTHEME_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);