Author: gadamopoulos
Date: Fri May 19 10:01:50 2017
New Revision: 74592
URL:
http://svn.reactos.org/svn/reactos?rev=74592&view=rev
Log:
[UXTHEME] Greatly reduce the number of times we open the theme data for the non client
area.
- Implement OTD_NONCLIENT for OpenThemeDataEx and OpenThemeDataFromFile.
- Open the WINDOW or the SCROLLBAR theme classes only when needed. Use OpenThemeDataEx
instead of the internal MSSTYLES_OpenThemeClass. Cache the open theme in the WND_DATA for
later use.
Modified:
trunk/reactos/dll/win32/uxtheme/nonclient.c
trunk/reactos/dll/win32/uxtheme/system.c
trunk/reactos/dll/win32/uxtheme/themehooks.c
trunk/reactos/dll/win32/uxtheme/uxthemep.h
Modified: trunk/reactos/dll/win32/uxtheme/nonclient.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/nonclien…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/nonclient.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/nonclient.c [iso-8859-1] Fri May 19 10:01:50 2017
@@ -173,8 +173,8 @@
GetWindowInfo(hWnd, &pcontext->wi);
pcontext->hWnd = hWnd;
pcontext->Active = IsWindowActive(hWnd, pcontext->wi.dwExStyle);
- pcontext->theme = MSSTYLES_OpenThemeClass(ActiveThemeFile, NULL,
L"WINDOW");
- pcontext->scrolltheme = MSSTYLES_OpenThemeClass(ActiveThemeFile, NULL,
L"SCROLLBAR");
+ pcontext->theme = GetNCCaptionTheme(hWnd, pcontext->wi.dwStyle);
+ pcontext->scrolltheme = GetNCScrollbarTheme(hWnd, pcontext->wi.dwStyle);
pcontext->CaptionHeight = pcontext->wi.cyWindowBorders;
pcontext->CaptionHeight += GetSystemMetrics(pcontext->wi.dwExStyle &
WS_EX_TOOLWINDOW ? SM_CYSMCAPTION : SM_CYCAPTION );
@@ -192,9 +192,6 @@
ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext)
{
ReleaseDC(pcontext->hWnd ,pcontext->hDC);
-
- CloseThemeData (pcontext->theme);
- CloseThemeData (pcontext->scrolltheme);
if(pcontext->hRgn != NULL)
{
@@ -1115,7 +1112,10 @@
/* Paint the window on the preview hDC */
rcCurrent = context.wi.rcWindow;
ThemePaintWindow(&context, &rcCurrent, FALSE);
+
context.hDC = NULL;
+ CloseThemeData (context.theme);
+ CloseThemeData (context.scrolltheme);
ThemeCleanupDrawContext(&context);
/* Cleanup */
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 10:01:50 2017
@@ -724,9 +724,6 @@
return NULL;
}
- if(flags)
- FIXME("unhandled flags: %x\n", flags);
-
if (ThemeFile)
{
pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff,
sizeof(szAppBuff)/sizeof(szAppBuff[0]));
@@ -745,7 +742,10 @@
if(IsWindow(hwnd))
{
- SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
+ if ((flags & OTD_NONCLIENT) == 0)
+ {
+ SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
+ }
}
else
{
Modified: trunk/reactos/dll/win32/uxtheme/themehooks.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/uxtheme/themehoo…
==============================================================================
--- trunk/reactos/dll/win32/uxtheme/themehooks.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/uxtheme/themehooks.c [iso-8859-1] Fri May 19 10:01:50 2017
@@ -63,18 +63,66 @@
CloseThemeData(GetWindowTheme(hWnd));
DeleteObject(pwndData->hTabBackgroundBrush);
- pwndData->hTabBackgroundBrush = NULL;
}
if (pwndData->hTabBackgroundBmp != NULL)
{
DeleteObject(pwndData->hTabBackgroundBmp);
- pwndData->hTabBackgroundBmp = NULL;
+ }
+
+ if (pwndData->hthemeWindow)
+ {
+ CloseThemeData(pwndData->hthemeWindow);
+ }
+
+ if (pwndData->hthemeScrollbar)
+ {
+ CloseThemeData(pwndData->hthemeScrollbar);
}
HeapFree(GetProcessHeap(), 0, pwndData);
SetPropW( hWnd, (LPCWSTR)MAKEINTATOM(atWndContext), NULL);
+}
+
+HTHEME GetNCCaptionTheme(HWND hWnd, DWORD style)
+{
+ PWND_DATA pwndData;
+
+ /* We only get the theme for the window class if the window has a caption */
+ if((style & WS_CAPTION) != WS_CAPTION)
+ return NULL;
+
+ /* Get theme data for this window */
+ pwndData = ThemeGetWndData(hWnd);
+ if (pwndData == NULL)
+ return NULL;
+
+ /* If the theme data was not cached, open it now */
+ if (!pwndData->hthemeWindow)
+ pwndData->hthemeWindow = OpenThemeDataEx(hWnd, L"WINDOW",
OTD_NONCLIENT);
+
+ return pwndData->hthemeWindow;
+}
+
+HTHEME GetNCScrollbarTheme(HWND hWnd, DWORD style)
+{
+ PWND_DATA pwndData;
+
+ /* We only get the theme for the scrollbar class if the window has a scrollbar */
+ if((style & (WS_HSCROLL|WS_VSCROLL)) == 0)
+ return NULL;
+
+ /* Get theme data for this window */
+ pwndData = ThemeGetWndData(hWnd);
+ if (pwndData == NULL)
+ return NULL;
+
+ /* If the theme data was not cached, open it now */
+ if (!pwndData->hthemeScrollbar)
+ pwndData->hthemeScrollbar = OpenThemeDataEx(hWnd, L"SCROLLBAR",
OTD_NONCLIENT);
+
+ return pwndData->hthemeScrollbar;
}
static BOOL CALLBACK ThemeCleanupChildWndContext (HWND hWnd, LPARAM msg)
@@ -130,9 +178,8 @@
rcWindow.top = 0;
rcWindow.left = 0;
- hTheme = MSSTYLES_OpenThemeClass(ActiveThemeFile, NULL, L"WINDOW");
+ hTheme = GetNCCaptionTheme(hWnd, wi.dwStyle);
GetThemeBackgroundRegion(hTheme, 0, iPart, FS_ACTIVE, &rcWindow, &hrgn);
- CloseThemeData(hTheme);
GetWindowRect(hWnd, &rcWindow);
rcWindow.right -= rcWindow.left;
@@ -259,6 +306,18 @@
{
DeleteObject(pwndData->hTabBackgroundBmp);
pwndData->hTabBackgroundBmp = NULL;
+ }
+
+ if (pwndData->hthemeWindow)
+ {
+ CloseThemeData(pwndData->hthemeWindow);
+ pwndData->hthemeWindow = NULL;
+ }
+
+ if (pwndData->hthemeScrollbar)
+ {
+ CloseThemeData(pwndData->hthemeScrollbar);
+ pwndData->hthemeScrollbar = NULL;
}
}
case WM_NCCREATE:
@@ -306,8 +365,12 @@
HBITMAP hbmp;
RECT dummy, bmpRect;
BOOL hasImageAlpha;
-
- UXTHEME_LoadImage(theme, 0, TABP_BODY, 0, &dummy, FALSE, &hbmp,
&bmpRect, &hasImageAlpha);
+ HRESULT hr;
+
+ hr = UXTHEME_LoadImage(theme, 0, TABP_BODY, 0, &dummy, FALSE, &hbmp,
&bmpRect, &hasImageAlpha);
+ if (FAILED(hr))
+ return hr;
+
if (changeOrigin)
{
/* Unfortunately SetBrushOrgEx doesn't work at all */
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 10:01:50 2017
@@ -136,6 +136,9 @@
/* The window context stores data for the window needed through the life of the window
*/
typedef struct _WND_DATA
{
+ HTHEME hthemeWindow;
+ HTHEME hthemeScrollbar;
+
UINT lastHitTest;
BOOL HasAppDefinedRgn;
BOOL HasThemeRgn;
@@ -229,6 +232,8 @@
void ThemeInitDrawContext(PDRAW_CONTEXT pcontext, HWND hWnd, HRGN hRgn);
void ThemeCleanupDrawContext(PDRAW_CONTEXT pcontext);
PWND_DATA ThemeGetWndData(HWND hWnd);
+HTHEME GetNCCaptionTheme(HWND hWnd, DWORD style);
+HTHEME GetNCScrollbarTheme(HWND hWnd, DWORD style);
extern HINSTANCE hDllInst;
extern ATOM atWindowTheme;