2 * Win32 5.1 Theme system
4 * Copyright (C) 2003 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 /***********************************************************************
28 * Defines and global variables
31 static const WCHAR szThemeManager
[] = {
32 'S','o','f','t','w','a','r','e','\\',
33 'M','i','c','r','o','s','o','f','t','\\',
34 'W','i','n','d','o','w','s','\\',
35 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
36 'T','h','e','m','e','M','a','n','a','g','e','r','\0'
38 static const WCHAR szThemeActive
[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
39 static const WCHAR szSizeName
[] = {'S','i','z','e','N','a','m','e','\0'};
40 static const WCHAR szColorName
[] = {'C','o','l','o','r','N','a','m','e','\0'};
41 static const WCHAR szDllName
[] = {'D','l','l','N','a','m','e','\0'};
43 static const WCHAR szIniDocumentation
[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
46 ATOM atDialogThemeEnabled
;
48 static DWORD dwThemeAppProperties
= STAP_ALLOW_NONCLIENT
| STAP_ALLOW_CONTROLS
;
50 static ATOM atSubAppName
;
51 static ATOM atSubIdList
;
54 PTHEME_FILE ActiveThemeFile
;
56 /***********************************************************************/
58 static BOOL CALLBACK
UXTHEME_broadcast_msg_enumchild (HWND hWnd
, LPARAM msg
)
60 SendMessageW(hWnd
, msg
, 0, 0);
64 /* Broadcast a message to *all* windows, including children */
65 BOOL CALLBACK
UXTHEME_broadcast_msg (HWND hWnd
, LPARAM msg
)
69 EnumWindows (UXTHEME_broadcast_msg
, msg
);
73 SendMessageW(hWnd
, msg
, 0, 0);
74 EnumChildWindows (hWnd
, UXTHEME_broadcast_msg_enumchild
, msg
);
79 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
80 * here to avoid linking against shlwapi. */
81 static DWORD
query_reg_path (HKEY hKey
, LPCWSTR lpszValue
,
84 DWORD dwRet
, dwType
, dwUnExpDataLen
= MAX_PATH
* sizeof(WCHAR
), dwExpDataLen
;
86 TRACE("(hkey=%p,%s,%p)\n", hKey
, debugstr_w(lpszValue
),
89 dwRet
= RegQueryValueExW(hKey
, lpszValue
, 0, &dwType
, pvData
, &dwUnExpDataLen
);
90 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
93 if (dwType
== REG_EXPAND_SZ
)
97 /* Expand type REG_EXPAND_SZ into REG_SZ */
100 /* If the caller didn't supply a buffer or the buffer is too small we have
101 * to allocate our own
103 if (dwRet
== ERROR_MORE_DATA
)
106 nBytesToAlloc
= dwUnExpDataLen
;
108 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
109 RegQueryValueExW (hKey
, lpszValue
, 0, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
110 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, &cNull
, 1);
111 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
116 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
117 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
118 lstrcpyW(szData
, pvData
);
119 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, MAX_PATH
);
120 if (dwExpDataLen
> MAX_PATH
) dwRet
= ERROR_MORE_DATA
;
121 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
129 static HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
132 MSSTYLES_CloseThemeFile(ActiveThemeFile
);
133 ActiveThemeFile
= tf
;
136 MSSTYLES_ReferenceTheme(ActiveThemeFile
);
137 MSSTYLES_ParseThemeIni(ActiveThemeFile
);
142 static BOOL
bIsThemeActive(LPCWSTR pszTheme
, LPCWSTR pszColor
, LPCWSTR pszSize
)
144 if (ActiveThemeFile
== NULL
)
147 if (wcscmp(pszTheme
, ActiveThemeFile
->szThemeFile
) != 0)
152 if (ActiveThemeFile
->pszAvailColors
!= ActiveThemeFile
->pszSelectedColor
)
157 if (wcscmp(pszColor
, ActiveThemeFile
->pszSelectedColor
) != 0)
163 if (ActiveThemeFile
->pszAvailSizes
!= ActiveThemeFile
->pszSelectedSize
)
168 if (wcscmp(pszSize
, ActiveThemeFile
->pszSelectedSize
) != 0)
175 /***********************************************************************
178 * Set the current active theme from the registry
180 void UXTHEME_LoadTheme(BOOL bLoad
)
187 WCHAR szCurrentTheme
[MAX_PATH
];
188 WCHAR szCurrentColor
[64];
189 WCHAR szCurrentSize
[64];
190 BOOL bThemeActive
= FALSE
;
194 /* Get current theme configuration */
195 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
196 TRACE("Loading theme config\n");
197 buffsize
= sizeof(tmp
);
198 if(!RegQueryValueExW(hKey
, szThemeActive
, NULL
, NULL
, (LPBYTE
)tmp
, &buffsize
)) {
199 bThemeActive
= (tmp
[0] != '0');
202 bThemeActive
= FALSE
;
203 TRACE("Failed to get ThemeActive: %d\n", GetLastError());
205 buffsize
= sizeof(szCurrentColor
);
206 if(RegQueryValueExW(hKey
, szColorName
, NULL
, NULL
, (LPBYTE
)szCurrentColor
, &buffsize
))
207 szCurrentColor
[0] = '\0';
208 buffsize
= sizeof(szCurrentSize
);
209 if(RegQueryValueExW(hKey
, szSizeName
, NULL
, NULL
, (LPBYTE
)szCurrentSize
, &buffsize
))
210 szCurrentSize
[0] = '\0';
211 if (query_reg_path (hKey
, szDllName
, szCurrentTheme
))
212 szCurrentTheme
[0] = '\0';
216 TRACE("Failed to open theme registry key\n");
220 bThemeActive
= FALSE
;
225 if( bIsThemeActive(szCurrentTheme
, szCurrentColor
, szCurrentSize
) )
227 TRACE("Tried to load active theme again\n");
231 /* Make sure the theme requested is actually valid */
232 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
233 szCurrentColor
[0]?szCurrentColor
:NULL
,
234 szCurrentSize
[0]?szCurrentSize
:NULL
,
237 bThemeActive
= FALSE
;
240 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme
),
241 debugstr_w(szCurrentColor
), debugstr_w(szCurrentSize
));
243 UXTHEME_SetActiveTheme(pt
);
244 MSSTYLES_CloseThemeFile(pt
);
248 UXTHEME_SetActiveTheme(NULL
);
249 TRACE("Theming not active\n");
253 /***********************************************************************/
255 static const char * const SysColorsNames
[] =
257 "Scrollbar", /* COLOR_SCROLLBAR */
258 "Background", /* COLOR_BACKGROUND */
259 "ActiveTitle", /* COLOR_ACTIVECAPTION */
260 "InactiveTitle", /* COLOR_INACTIVECAPTION */
261 "Menu", /* COLOR_MENU */
262 "Window", /* COLOR_WINDOW */
263 "WindowFrame", /* COLOR_WINDOWFRAME */
264 "MenuText", /* COLOR_MENUTEXT */
265 "WindowText", /* COLOR_WINDOWTEXT */
266 "TitleText", /* COLOR_CAPTIONTEXT */
267 "ActiveBorder", /* COLOR_ACTIVEBORDER */
268 "InactiveBorder", /* COLOR_INACTIVEBORDER */
269 "AppWorkSpace", /* COLOR_APPWORKSPACE */
270 "Hilight", /* COLOR_HIGHLIGHT */
271 "HilightText", /* COLOR_HIGHLIGHTTEXT */
272 "ButtonFace", /* COLOR_BTNFACE */
273 "ButtonShadow", /* COLOR_BTNSHADOW */
274 "GrayText", /* COLOR_GRAYTEXT */
275 "ButtonText", /* COLOR_BTNTEXT */
276 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
277 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
278 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
279 "ButtonLight", /* COLOR_3DLIGHT */
280 "InfoText", /* COLOR_INFOTEXT */
281 "InfoWindow", /* COLOR_INFOBK */
282 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
283 "HotTrackingColor", /* COLOR_HOTLIGHT */
284 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
285 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
286 "MenuHilight", /* COLOR_MENUHILIGHT */
287 "MenuBar", /* COLOR_MENUBAR */
289 static const WCHAR strColorKey
[] =
290 { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
291 'C','o','l','o','r','s',0 };
292 static const WCHAR keyFlatMenus
[] = { 'F','l','a','t','M','e','n','u', 0};
293 static const WCHAR keyGradientCaption
[] = { 'G','r','a','d','i','e','n','t',
294 'C','a','p','t','i','o','n', 0 };
295 static const WCHAR keyNonClientMetrics
[] = { 'N','o','n','C','l','i','e','n','t',
296 'M','e','t','r','i','c','s',0 };
297 static const WCHAR keyIconTitleFont
[] = { 'I','c','o','n','T','i','t','l','e',
300 static const struct BackupSysParam
303 const WCHAR
* keyName
;
304 } backupSysParams
[] =
306 {SPI_GETFLATMENU
, SPI_SETFLATMENU
, keyFlatMenus
},
307 {SPI_GETGRADIENTCAPTIONS
, SPI_SETGRADIENTCAPTIONS
, keyGradientCaption
},
311 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
313 static void save_sys_colors (HKEY baseKey
)
319 if (RegCreateKeyExW( baseKey
, strColorKey
,
320 0, 0, 0, KEY_ALL_ACCESS
,
321 0, &hKey
, 0 ) == ERROR_SUCCESS
)
323 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
325 COLORREF col
= GetSysColor (i
);
327 sprintf (colorStr
, "%d %d %d",
328 GetRValue (col
), GetGValue (col
), GetBValue (col
));
330 RegSetValueExA (hKey
, SysColorsNames
[i
], 0, REG_SZ
,
331 (BYTE
*)colorStr
, strlen (colorStr
)+1);
337 /* Before activating a theme, query current system colors, certain settings
338 * and backup them in the registry, so they can be restored when the theme
340 static void UXTHEME_BackupSystemMetrics(void)
343 const struct BackupSysParam
* bsp
= backupSysParams
;
345 if (RegCreateKeyExW( HKEY_CURRENT_USER
, szThemeManager
,
346 0, 0, 0, KEY_ALL_ACCESS
,
347 0, &hKey
, 0) == ERROR_SUCCESS
)
349 NONCLIENTMETRICSW ncm
;
350 LOGFONTW iconTitleFont
;
353 save_sys_colors (hKey
);
355 /* back up "other" settings */
356 while (bsp
->spiGet
>= 0)
360 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
361 RegSetValueExW (hKey
, bsp
->keyName
, 0, REG_DWORD
,
362 (LPBYTE
)&value
, sizeof (value
));
367 /* back up non-client metrics */
368 memset (&ncm
, 0, sizeof (ncm
));
369 ncm
.cbSize
= sizeof (ncm
);
370 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
371 RegSetValueExW (hKey
, keyNonClientMetrics
, 0, REG_BINARY
, (LPBYTE
)&ncm
,
373 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
374 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
376 RegSetValueExW (hKey
, keyIconTitleFont
, 0, REG_BINARY
,
377 (LPBYTE
)&iconTitleFont
, sizeof (iconTitleFont
));
383 /* Read back old settings after a theme was deactivated */
384 static void UXTHEME_RestoreSystemMetrics(void)
387 const struct BackupSysParam
* bsp
= backupSysParams
;
389 if (RegOpenKeyExW (HKEY_CURRENT_USER
, szThemeManager
,
390 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
394 /* read backed-up colors */
395 if (RegOpenKeyExW (hKey
, strColorKey
,
396 0, KEY_QUERY_VALUE
, &colorKey
) == ERROR_SUCCESS
)
399 COLORREF sysCols
[NUM_SYS_COLORS
];
400 int sysColsIndices
[NUM_SYS_COLORS
];
403 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
407 DWORD count
= sizeof(colorStr
);
409 if (RegQueryValueExA (colorKey
, SysColorsNames
[i
], 0,
410 &type
, (LPBYTE
) colorStr
, &count
) == ERROR_SUCCESS
)
413 if (sscanf (colorStr
, "%d %d %d", &r
, &g
, &b
) == 3)
415 sysColsIndices
[sysColCount
] = i
;
416 sysCols
[sysColCount
] = RGB(r
, g
, b
);
421 RegCloseKey (colorKey
);
423 SetSysColors (sysColCount
, sysColsIndices
, sysCols
);
426 /* read backed-up other settings */
427 while (bsp
->spiGet
>= 0)
430 DWORD count
= sizeof(value
);
433 if (RegQueryValueExW (hKey
, bsp
->keyName
, 0,
434 &type
, (LPBYTE
)&value
, &count
) == ERROR_SUCCESS
)
436 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
442 /* read backed-up non-client metrics */
444 NONCLIENTMETRICSW ncm
;
445 LOGFONTW iconTitleFont
;
446 DWORD count
= sizeof(ncm
);
449 if (RegQueryValueExW (hKey
, keyNonClientMetrics
, 0,
450 &type
, (LPBYTE
)&ncm
, &count
) == ERROR_SUCCESS
)
452 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
,
453 count
, &ncm
, SPIF_UPDATEINIFILE
);
456 count
= sizeof(iconTitleFont
);
458 if (RegQueryValueExW (hKey
, keyIconTitleFont
, 0,
459 &type
, (LPBYTE
)&iconTitleFont
, &count
) == ERROR_SUCCESS
)
461 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
,
462 count
, &iconTitleFont
, SPIF_UPDATEINIFILE
);
470 /* Make system settings persistent, so they're in effect even w/o uxtheme
472 * For efficiency reasons, only the last SystemParametersInfoW sets
473 * SPIF_SENDWININICHANGE */
474 static void UXTHEME_SaveSystemMetrics(void)
476 const struct BackupSysParam
* bsp
= backupSysParams
;
477 NONCLIENTMETRICSW ncm
;
478 LOGFONTW iconTitleFont
;
480 save_sys_colors (HKEY_CURRENT_USER
);
482 while (bsp
->spiGet
>= 0)
486 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
487 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
491 memset (&ncm
, 0, sizeof (ncm
));
492 ncm
.cbSize
= sizeof (ncm
);
493 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
494 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
,
497 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
498 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
500 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (iconTitleFont
),
501 &iconTitleFont
, SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
504 /***********************************************************************
507 * Change the current active theme
509 static HRESULT
UXTHEME_ApplyTheme(PTHEME_FILE tf
)
515 TRACE("UXTHEME_ApplyTheme\n");
517 if (tf
&& !ActiveThemeFile
)
519 UXTHEME_BackupSystemMetrics();
522 hr
= UXTHEME_SetActiveTheme(tf
);
528 UXTHEME_RestoreSystemMetrics();
531 TRACE("Writing theme config to registry\n");
532 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
533 tmp
[0] = ActiveThemeFile
?'1':'0';
535 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
536 if (ActiveThemeFile
) {
537 RegSetValueExW(hKey
, szColorName
, 0, REG_SZ
, (const BYTE
*)tf
->pszSelectedColor
,
538 (lstrlenW(tf
->pszSelectedColor
)+1)*sizeof(WCHAR
));
539 RegSetValueExW(hKey
, szSizeName
, 0, REG_SZ
, (const BYTE
*)tf
->pszSelectedSize
,
540 (lstrlenW(tf
->pszSelectedSize
)+1)*sizeof(WCHAR
));
541 RegSetValueExW(hKey
, szDllName
, 0, REG_SZ
, (const BYTE
*)tf
->szThemeFile
,
542 (lstrlenW(tf
->szThemeFile
)+1)*sizeof(WCHAR
));
545 RegDeleteValueW(hKey
, szColorName
);
546 RegDeleteValueW(hKey
, szSizeName
);
547 RegDeleteValueW(hKey
, szDllName
);
553 TRACE("Failed to open theme registry key\n");
555 UXTHEME_SaveSystemMetrics ();
560 /***********************************************************************
563 void UXTHEME_InitSystem(HINSTANCE hInst
)
565 static const WCHAR szWindowTheme
[] = {
566 'u','x','_','t','h','e','m','e','\0'
568 static const WCHAR szSubAppName
[] = {
569 'u','x','_','s','u','b','a','p','p','\0'
571 static const WCHAR szSubIdList
[] = {
572 'u','x','_','s','u','b','i','d','l','s','t','\0'
574 static const WCHAR szDialogThemeEnabled
[] = {
575 'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
580 atWindowTheme
= GlobalAddAtomW(szWindowTheme
);
581 atSubAppName
= GlobalAddAtomW(szSubAppName
);
582 atSubIdList
= GlobalAddAtomW(szSubIdList
);
583 atDialogThemeEnabled
= GlobalAddAtomW(szDialogThemeEnabled
);
584 atWndContext
= GlobalAddAtomW(L
"ux_WndContext");
587 /***********************************************************************
588 * IsAppThemed (UXTHEME.@)
590 BOOL WINAPI
IsAppThemed(void)
593 SetLastError(ERROR_SUCCESS
);
594 return (ActiveThemeFile
!= NULL
);
597 /***********************************************************************
598 * IsThemeActive (UXTHEME.@)
600 BOOL WINAPI
IsThemeActive(void)
608 TRACE("IsThemeActive\n");
609 SetLastError(ERROR_SUCCESS
);
614 if (gbThemeHooksActive
)
618 Result
= RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
);
619 if (Result
== ERROR_SUCCESS
)
621 buffsize
= sizeof(tmp
);
622 if (!RegQueryValueExW(hKey
, szThemeActive
, NULL
, NULL
, (LPBYTE
)tmp
, &buffsize
))
623 bActive
= (tmp
[0] != '0');
630 /***********************************************************************
631 * EnableTheming (UXTHEME.@)
634 * This is a global and persistent change
636 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
639 WCHAR szEnabled
[] = {'0','\0'};
641 TRACE("(%d)\n", fEnable
);
643 if (fEnable
!= (ActiveThemeFile
!= NULL
)) {
645 UXTHEME_BackupSystemMetrics();
647 UXTHEME_RestoreSystemMetrics();
648 UXTHEME_SaveSystemMetrics ();
650 if (fEnable
) szEnabled
[0] = '1';
651 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
652 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (LPBYTE
)szEnabled
, sizeof(WCHAR
));
655 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
660 /***********************************************************************
661 * UXTHEME_SetWindowProperty
663 * I'm using atoms as there may be large numbers of duplicated strings
664 * and they do the work of keeping memory down as a cause of that quite nicely
666 static HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
668 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
671 DeleteAtom(oldValue
);
678 /* A string with zero lenght is not acceptatble in AddAtomW but we want to support
679 users passing an empty string meaning they want no theme for the specified window */
683 atValue
= AddAtomW(pszValue
);
686 ERR("AddAtomW for %S failed with last error %d!\n", pszValue
, GetLastError());
687 return HRESULT_FROM_WIN32(GetLastError());
690 if (!SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
)))
692 ERR("SetPropW for atom %d failed with last error %d\n", aProp
, GetLastError());
693 if(atValue
) DeleteAtom(atValue
);
694 return HRESULT_FROM_WIN32(GetLastError());
700 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
702 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
704 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
706 TRACE("property defined, but unable to get value\n");
712 OpenThemeDataInternal(PTHEME_FILE ThemeFile
, HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
714 WCHAR szAppBuff
[256];
715 WCHAR szClassBuff
[256];
717 LPCWSTR pszUseClassList
;
718 HTHEME hTheme
= NULL
;
719 TRACE("(%p,%s, %x)\n", hwnd
, debugstr_w(pszClassList
), flags
);
723 SetLastError(E_POINTER
);
728 FIXME("unhandled flags: %x\n", flags
);
732 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, sizeof(szAppBuff
)/sizeof(szAppBuff
[0]));
733 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
734 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, sizeof(szClassBuff
)/sizeof(szClassBuff
[0]));
736 pszUseClassList
= pszClassList
;
740 if (!ThemeFile
->classes
)
741 MSSTYLES_ParseThemeIni(ThemeFile
);
742 hTheme
= MSSTYLES_OpenThemeClass(ThemeFile
, pszAppName
, pszUseClassList
);
748 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
752 SetLastError(E_PROP_ID_UNSUPPORTED
);
755 SetLastError(hTheme
? ERROR_SUCCESS
: E_PROP_ID_UNSUPPORTED
);
757 TRACE(" = %p\n", hTheme
);
761 /***********************************************************************
762 * OpenThemeDataEx (UXTHEME.61)
764 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
766 return OpenThemeDataInternal(ActiveThemeFile
, hwnd
, pszClassList
, flags
);
769 /***********************************************************************
770 * OpenThemeDataFromFile (UXTHEME.16)
772 HTHEME WINAPI
OpenThemeDataFromFile(HTHEMEFILE hThemeFile
, HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
774 return OpenThemeDataInternal((PTHEME_FILE
)hThemeFile
, hwnd
, pszClassList
, flags
);
777 /***********************************************************************
778 * OpenThemeData (UXTHEME.@)
780 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR classlist
)
782 return OpenThemeDataInternal(ActiveThemeFile
, hwnd
, classlist
, 0);
785 /***********************************************************************
786 * GetWindowTheme (UXTHEME.@)
788 * Retrieve the last theme opened for a window.
791 * hwnd [I] window to retrieve the theme for
794 * The most recent theme.
796 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
798 TRACE("(%p)\n", hwnd
);
802 SetLastError(E_HANDLE
);
806 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
809 /***********************************************************************
810 * SetWindowTheme (UXTHEME.@)
812 * Persistent through the life of the window, even after themes change
814 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
815 LPCWSTR pszSubIdList
)
818 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
819 debugstr_w(pszSubIdList
));
824 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
828 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
832 UXTHEME_broadcast_msg (hwnd
, WM_THEMECHANGED
);
836 /***********************************************************************
837 * GetCurrentThemeName (UXTHEME.@)
839 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
840 LPWSTR pszColorBuff
, int cchMaxColorChars
,
841 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
845 if(ActiveThemeFile
== NULL
)
846 return E_PROP_ID_UNSUPPORTED
;
848 if (pszThemeFileName
&& dwMaxNameChars
)
850 cchar
= lstrlenW(ActiveThemeFile
->szThemeFile
) + 1;
851 if(cchar
> dwMaxNameChars
)
852 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
853 lstrcpynW(pszThemeFileName
, ActiveThemeFile
->szThemeFile
, cchar
);
856 if (pszColorBuff
&& cchMaxColorChars
)
858 cchar
= lstrlenW(ActiveThemeFile
->pszSelectedColor
) + 1;
859 if(cchar
> cchMaxColorChars
)
860 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
861 lstrcpynW(pszColorBuff
, ActiveThemeFile
->pszSelectedColor
, cchar
);
864 if (pszSizeBuff
&& cchMaxSizeChars
)
866 cchar
= lstrlenW(ActiveThemeFile
->pszSelectedSize
) + 1;
867 if(cchar
> cchMaxSizeChars
)
868 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
869 lstrcpynW(pszSizeBuff
, ActiveThemeFile
->pszSelectedSize
, cchar
);
875 /***********************************************************************
876 * GetThemeAppProperties (UXTHEME.@)
878 DWORD WINAPI
GetThemeAppProperties(void)
880 return dwThemeAppProperties
;
883 /***********************************************************************
884 * SetThemeAppProperties (UXTHEME.@)
886 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
888 TRACE("(0x%08x)\n", dwFlags
);
889 dwThemeAppProperties
= dwFlags
;
892 /***********************************************************************
893 * CloseThemeData (UXTHEME.@)
895 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
897 TRACE("(%p)\n", hTheme
);
898 if(!hTheme
|| hTheme
== INVALID_HANDLE_VALUE
)
900 if(IsBadReadPtr (hTheme
, sizeof(THEME_CLASS
))) /* This check is a hack! */
902 return MSSTYLES_CloseThemeClass(hTheme
);
905 /***********************************************************************
906 * HitTestThemeBackground (UXTHEME.@)
908 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
909 int iStateId
, DWORD dwOptions
,
910 const RECT
*pRect
, HRGN hrgn
,
911 POINT ptTest
, WORD
*pwHitTestCode
)
913 FIXME("%d %d 0x%08x: stub\n", iPartId
, iStateId
, dwOptions
);
919 /***********************************************************************
920 * IsThemePartDefined (UXTHEME.@)
922 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
924 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
926 SetLastError(E_HANDLE
);
929 if(MSSTYLES_FindPartState(hTheme
, iPartId
, iStateId
, NULL
))
934 /***********************************************************************
935 * GetThemeDocumentationProperty (UXTHEME.@)
937 * Try and retrieve the documentation property from string resources
938 * if that fails, get it from the [documentation] section of themes.ini
940 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
941 LPCWSTR pszPropertyName
,
945 const WORD wDocToRes
[] = {
946 TMT_DISPLAYNAME
,5000,
960 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
961 pszValueBuff
, cchMaxValChars
);
963 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
964 if(FAILED(hr
)) return hr
;
966 /* Try to load from string resources */
967 hr
= E_PROP_ID_UNSUPPORTED
;
968 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
969 for(i
=0; i
<sizeof(wDocToRes
)/sizeof(wDocToRes
[0]); i
+=2) {
970 if(wDocToRes
[i
] == iDocId
) {
971 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
978 /* If loading from string resource failed, try getting it from the theme.ini */
980 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
981 if(UXINI_FindSection(uf
, szIniDocumentation
)) {
984 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
985 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
992 MSSTYLES_CloseThemeFile(pt
);
996 /**********************************************************************
997 * Undocumented functions
1000 /**********************************************************************
1001 * QueryThemeServices (UXTHEME.1)
1004 * some kind of status flag
1006 DWORD WINAPI
QueryThemeServices(void)
1009 return 3; /* This is what is returned under XP in most cases */
1013 /**********************************************************************
1014 * OpenThemeFile (UXTHEME.2)
1016 * Opens a theme file, which can be used to change the current theme, etc
1019 * pszThemeFileName Path to a msstyles theme file
1020 * pszColorName Color defined in the theme, eg. NormalColor
1021 * pszSizeName Size defined in the theme, eg. NormalSize
1022 * hThemeFile Handle to theme file
1026 * Failure: HRESULT error-code
1028 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
1029 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
1032 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName
),
1033 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
1034 hThemeFile
, unknown
);
1035 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
1038 /**********************************************************************
1039 * CloseThemeFile (UXTHEME.3)
1041 * Releases theme file handle returned by OpenThemeFile
1044 * hThemeFile Handle to theme file
1048 * Failure: HRESULT error-code
1050 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
1052 TRACE("(%p)\n", hThemeFile
);
1053 MSSTYLES_CloseThemeFile(hThemeFile
);
1057 /**********************************************************************
1058 * ApplyTheme (UXTHEME.4)
1060 * Set a theme file to be the currently active theme
1063 * hThemeFile Handle to theme file
1065 * hWnd Window requesting the theme change
1069 * Failure: HRESULT error-code
1072 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
1073 * Under XP if I pass
1075 * the theme is applied with the screen redrawing really badly (flickers)
1076 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
1077 * the theme is applied smoothly (screen does not flicker)
1078 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
1079 * the function fails returning invalid parameter... very strange
1081 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
1084 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
1085 hr
= UXTHEME_ApplyTheme(hThemeFile
);
1086 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
1090 /**********************************************************************
1091 * GetThemeDefaults (UXTHEME.7)
1093 * Get the default color & size for a theme
1096 * pszThemeFileName Path to a msstyles theme file
1097 * pszColorName Buffer to receive the default color name
1098 * dwColorNameLen Length, in characters, of color name buffer
1099 * pszSizeName Buffer to receive the default size name
1100 * dwSizeNameLen Length, in characters, of size name buffer
1104 * Failure: HRESULT error-code
1106 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
1107 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
1108 DWORD dwSizeNameLen
)
1112 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName
),
1113 pszColorName
, dwColorNameLen
,
1114 pszSizeName
, dwSizeNameLen
);
1116 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1117 if(FAILED(hr
)) return hr
;
1119 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
1120 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
1122 MSSTYLES_CloseThemeFile(pt
);
1126 /**********************************************************************
1127 * EnumThemes (UXTHEME.8)
1129 * Enumerate available themes, calls specified EnumThemeProc for each
1130 * theme found. Passes lpData through to callback function.
1133 * pszThemePath Path containing themes
1134 * callback Called for each theme found in path
1135 * lpData Passed through to callback
1139 * Failure: HRESULT error-code
1141 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, ENUMTHEMEPROC callback
,
1144 WCHAR szDir
[MAX_PATH
];
1145 WCHAR szPath
[MAX_PATH
];
1146 static const WCHAR szStar
[] = {'*','.','*','\0'};
1147 static const WCHAR szFormat
[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
1148 static const WCHAR szDisplayName
[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
1149 static const WCHAR szTooltip
[] = {'t','o','o','l','t','i','p','\0'};
1153 WIN32_FIND_DATAW wfd
;
1157 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
1159 if(!pszThemePath
|| !callback
)
1162 lstrcpyW(szDir
, pszThemePath
);
1163 pathLen
= lstrlenW (szDir
);
1164 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
1166 szDir
[pathLen
] = '\\';
1167 szDir
[pathLen
+1] = 0;
1170 lstrcpyW(szPath
, szDir
);
1171 lstrcatW(szPath
, szStar
);
1172 TRACE("searching %s\n", debugstr_w(szPath
));
1174 hFind
= FindFirstFileW(szPath
, &wfd
);
1175 if(hFind
!= INVALID_HANDLE_VALUE
) {
1177 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1178 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1179 wsprintfW(szPath
, szFormat
, szDir
, wfd
.cFileName
, wfd
.cFileName
);
1181 hr
= GetThemeDocumentationProperty(szPath
, szDisplayName
, szName
, sizeof(szName
)/sizeof(szName
[0]));
1183 hr
= GetThemeDocumentationProperty(szPath
, szTooltip
, szTip
, sizeof(szTip
)/sizeof(szTip
[0]));
1185 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1186 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1187 TRACE("callback ended enum\n");
1192 } while(FindNextFileW(hFind
, &wfd
));
1199 /**********************************************************************
1200 * EnumThemeColors (UXTHEME.9)
1202 * Enumerate theme colors available with a particular size
1205 * pszThemeFileName Path to a msstyles theme file
1206 * pszSizeName Theme size to enumerate available colors
1207 * If NULL the default theme size is used
1208 * dwColorNum Color index to retrieve, increment from 0
1209 * pszColorNames Output color names
1213 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1214 * or when pszSizeName does not refer to a valid size
1217 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1218 * sizeof(THEMENAMES).
1220 * Not very efficient that I'm opening & validating the theme every call, but
1221 * this is undocumented and almost never called..
1222 * (and this is how windows works too)
1224 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1225 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1230 UINT resourceId
= dwColorNum
+ 1000;
1231 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1232 debugstr_w(pszSizeName
), dwColorNum
);
1234 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1235 if(FAILED(hr
)) return hr
;
1237 tmp
= pt
->pszAvailColors
;
1238 while(dwColorNum
&& *tmp
) {
1240 tmp
+= lstrlenW(tmp
)+1;
1242 if(!dwColorNum
&& *tmp
) {
1243 TRACE("%s\n", debugstr_w(tmp
));
1244 lstrcpyW(pszColorNames
->szName
, tmp
);
1245 LoadStringW (pt
->hTheme
, resourceId
,
1246 pszColorNames
->szDisplayName
,
1247 sizeof (pszColorNames
->szDisplayName
) / sizeof (WCHAR
));
1248 LoadStringW (pt
->hTheme
, resourceId
+1000,
1249 pszColorNames
->szTooltip
,
1250 sizeof (pszColorNames
->szTooltip
) / sizeof (WCHAR
));
1253 hr
= E_PROP_ID_UNSUPPORTED
;
1255 MSSTYLES_CloseThemeFile(pt
);
1259 /**********************************************************************
1260 * EnumThemeSizes (UXTHEME.10)
1262 * Enumerate theme colors available with a particular size
1265 * pszThemeFileName Path to a msstyles theme file
1266 * pszColorName Theme color to enumerate available sizes
1267 * If NULL the default theme color is used
1268 * dwSizeNum Size index to retrieve, increment from 0
1269 * pszSizeNames Output size names
1273 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1274 * or when pszColorName does not refer to a valid color
1277 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1278 * sizeof(THEMENAMES).
1280 * Not very efficient that I'm opening & validating the theme every call, but
1281 * this is undocumented and almost never called..
1282 * (and this is how windows works too)
1284 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1285 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1290 UINT resourceId
= dwSizeNum
+ 3000;
1291 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1292 debugstr_w(pszColorName
), dwSizeNum
);
1294 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1295 if(FAILED(hr
)) return hr
;
1297 tmp
= pt
->pszAvailSizes
;
1298 while(dwSizeNum
&& *tmp
) {
1300 tmp
+= lstrlenW(tmp
)+1;
1302 if(!dwSizeNum
&& *tmp
) {
1303 TRACE("%s\n", debugstr_w(tmp
));
1304 lstrcpyW(pszSizeNames
->szName
, tmp
);
1305 LoadStringW (pt
->hTheme
, resourceId
,
1306 pszSizeNames
->szDisplayName
,
1307 sizeof (pszSizeNames
->szDisplayName
) / sizeof (WCHAR
));
1308 LoadStringW (pt
->hTheme
, resourceId
+1000,
1309 pszSizeNames
->szTooltip
,
1310 sizeof (pszSizeNames
->szTooltip
) / sizeof (WCHAR
));
1313 hr
= E_PROP_ID_UNSUPPORTED
;
1315 MSSTYLES_CloseThemeFile(pt
);
1319 /**********************************************************************
1320 * ParseThemeIniFile (UXTHEME.11)
1322 * Enumerate data in a theme INI file.
1325 * pszIniFileName Path to a theme ini file
1326 * pszUnknown Cannot be NULL, L"" is valid
1327 * callback Called for each found entry
1328 * lpData Passed through to callback
1332 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1335 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1338 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1339 PARSETHEMEINIFILEPROC callback
, LPVOID lpData
)
1341 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1345 /**********************************************************************
1346 * CheckThemeSignature (UXTHEME.29)
1348 * Validates the signature of a theme file
1351 * pszIniFileName Path to a theme file
1355 * Failure: HRESULT error-code
1357 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1361 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1362 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1365 MSSTYLES_CloseThemeFile(pt
);