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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "uxthemedll.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
41 /***********************************************************************
42 * Defines and global variables
45 static const WCHAR szThemeManager
[] = {
46 'S','o','f','t','w','a','r','e','\\',
47 'M','i','c','r','o','s','o','f','t','\\',
48 'W','i','n','d','o','w','s','\\',
49 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
50 'T','h','e','m','e','M','a','n','a','g','e','r','\0'
52 static const WCHAR szThemeActive
[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
53 static const WCHAR szSizeName
[] = {'S','i','z','e','N','a','m','e','\0'};
54 static const WCHAR szColorName
[] = {'C','o','l','o','r','N','a','m','e','\0'};
55 static const WCHAR szDllName
[] = {'D','l','l','N','a','m','e','\0'};
57 static const WCHAR szIniDocumentation
[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
61 DWORD dwThemeAppProperties
= STAP_ALLOW_NONCLIENT
| STAP_ALLOW_CONTROLS
;
65 ATOM atDialogThemeEnabled
;
67 BOOL bThemeActive
= FALSE
;
68 WCHAR szCurrentTheme
[MAX_PATH
];
69 WCHAR szCurrentColor
[64];
70 WCHAR szCurrentSize
[64];
72 /***********************************************************************/
74 static BOOL CALLBACK
UXTHEME_broadcast_msg_enumchild (HWND hWnd
, LPARAM msg
)
76 PostMessageW(hWnd
, msg
, 0, 0);
80 /* Broadcast a message to *all* windows, including children */
81 static BOOL CALLBACK
UXTHEME_broadcast_msg (HWND hWnd
, LPARAM msg
)
85 EnumWindows (UXTHEME_broadcast_msg
, msg
);
89 PostMessageW(hWnd
, msg
, 0, 0);
90 EnumChildWindows (hWnd
, UXTHEME_broadcast_msg_enumchild
, msg
);
95 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
96 * here to avoid linking against shlwapi. */
97 static DWORD
query_reg_path (HKEY hKey
, LPCWSTR lpszValue
,
100 DWORD dwRet
, dwType
, dwUnExpDataLen
= MAX_PATH
, dwExpDataLen
;
102 TRACE("(hkey=%p,%s,%p)\n", hKey
, debugstr_w(lpszValue
),
105 dwRet
= RegQueryValueExW(hKey
, lpszValue
, 0, &dwType
, pvData
, &dwUnExpDataLen
);
106 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
109 if (dwType
== REG_EXPAND_SZ
)
113 /* Expand type REG_EXPAND_SZ into REG_SZ */
116 /* If the caller didn't supply a buffer or the buffer is too small we have
117 * to allocate our own
119 if (dwRet
== ERROR_MORE_DATA
)
122 nBytesToAlloc
= dwUnExpDataLen
;
124 szData
= (LPWSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
125 RegQueryValueExW (hKey
, lpszValue
, 0, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
126 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, &cNull
, 1);
127 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
128 LocalFree((HLOCAL
) szData
);
132 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
133 szData
= (LPWSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
134 lstrcpyW(szData
, pvData
);
135 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, MAX_PATH
);
136 if (dwExpDataLen
> MAX_PATH
) dwRet
= ERROR_MORE_DATA
;
137 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
138 LocalFree((HLOCAL
) szData
);
146 /***********************************************************************
149 * Set the current active theme from the registry
151 static void UXTHEME_LoadTheme(void)
159 /* Get current theme configuration */
160 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
161 TRACE("Loading theme config\n");
162 buffsize
= sizeof(tmp
)/sizeof(tmp
[0]);
163 if(!RegQueryValueExW(hKey
, szThemeActive
, NULL
, NULL
, (LPBYTE
)tmp
, &buffsize
)) {
164 bThemeActive
= (tmp
[0] != '0');
167 bThemeActive
= FALSE
;
168 TRACE("Failed to get ThemeActive: %ld\n", GetLastError());
170 buffsize
= sizeof(szCurrentColor
)/sizeof(szCurrentColor
[0]);
171 if(RegQueryValueExW(hKey
, szColorName
, NULL
, NULL
, (LPBYTE
)szCurrentColor
, &buffsize
))
172 szCurrentColor
[0] = '\0';
173 buffsize
= sizeof(szCurrentSize
)/sizeof(szCurrentSize
[0]);
174 if(RegQueryValueExW(hKey
, szSizeName
, NULL
, NULL
, (LPBYTE
)szCurrentSize
, &buffsize
))
175 szCurrentSize
[0] = '\0';
176 if (query_reg_path (hKey
, szDllName
, szCurrentTheme
))
177 szCurrentTheme
[0] = '\0';
181 TRACE("Failed to open theme registry key\n");
184 /* Make sure the theme requested is actually valid */
185 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
186 szCurrentColor
[0]?szCurrentColor
:NULL
,
187 szCurrentSize
[0]?szCurrentSize
:NULL
,
190 bThemeActive
= FALSE
;
191 szCurrentTheme
[0] = '\0';
192 szCurrentColor
[0] = '\0';
193 szCurrentSize
[0] = '\0';
196 /* Make sure the global color & size match the theme */
197 lstrcpynW(szCurrentColor
, pt
->pszSelectedColor
, sizeof(szCurrentColor
)/sizeof(szCurrentColor
[0]));
198 lstrcpynW(szCurrentSize
, pt
->pszSelectedSize
, sizeof(szCurrentSize
)/sizeof(szCurrentSize
[0]));
200 MSSTYLES_SetActiveTheme(pt
, FALSE
);
201 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme
),
202 debugstr_w(szCurrentColor
), debugstr_w(szCurrentSize
));
203 MSSTYLES_CloseThemeFile(pt
);
207 MSSTYLES_SetActiveTheme(NULL
, FALSE
);
208 TRACE("Themeing not active\n");
212 /***********************************************************************/
214 static const char * const SysColorsNames
[] =
216 "Scrollbar", /* COLOR_SCROLLBAR */
217 "Background", /* COLOR_BACKGROUND */
218 "ActiveTitle", /* COLOR_ACTIVECAPTION */
219 "InactiveTitle", /* COLOR_INACTIVECAPTION */
220 "Menu", /* COLOR_MENU */
221 "Window", /* COLOR_WINDOW */
222 "WindowFrame", /* COLOR_WINDOWFRAME */
223 "MenuText", /* COLOR_MENUTEXT */
224 "WindowText", /* COLOR_WINDOWTEXT */
225 "TitleText", /* COLOR_CAPTIONTEXT */
226 "ActiveBorder", /* COLOR_ACTIVEBORDER */
227 "InactiveBorder", /* COLOR_INACTIVEBORDER */
228 "AppWorkSpace", /* COLOR_APPWORKSPACE */
229 "Hilight", /* COLOR_HIGHLIGHT */
230 "HilightText", /* COLOR_HIGHLIGHTTEXT */
231 "ButtonFace", /* COLOR_BTNFACE */
232 "ButtonShadow", /* COLOR_BTNSHADOW */
233 "GrayText", /* COLOR_GRAYTEXT */
234 "ButtonText", /* COLOR_BTNTEXT */
235 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
236 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
237 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
238 "ButtonLight", /* COLOR_3DLIGHT */
239 "InfoText", /* COLOR_INFOTEXT */
240 "InfoWindow", /* COLOR_INFOBK */
241 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
242 "HotTrackingColor", /* COLOR_HOTLIGHT */
243 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
244 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
245 "MenuHilight", /* COLOR_MENUHILIGHT */
246 "MenuBar", /* COLOR_MENUBAR */
248 static const WCHAR strColorKey
[] =
249 { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
250 'C','o','l','o','r','s',0 };
251 static const WCHAR keyFlatMenus
[] = { 'F','l','a','t','M','e','n','u', 0};
253 static const struct BackupSysParam
256 const WCHAR
* keyName
;
257 } backupSysParams
[] =
259 {SPI_GETFLATMENU
, SPI_SETFLATMENU
, keyFlatMenus
},
263 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
265 static void save_sys_colors (HKEY baseKey
)
271 if (RegCreateKeyExW( baseKey
, strColorKey
,
272 0, 0, 0, KEY_ALL_ACCESS
,
273 0, &hKey
, 0 ) == ERROR_SUCCESS
)
275 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
277 COLORREF col
= GetSysColor (i
);
279 sprintf (colorStr
, "%d %d %d",
280 GetRValue (col
), GetGValue (col
), GetBValue (col
));
282 RegSetValueExA (hKey
, SysColorsNames
[i
], 0, REG_SZ
,
283 (BYTE
*)colorStr
, strlen (colorStr
)+1);
289 /* Before activating a theme, query current system colors, certain settings
290 * and backup them in the registry, so they can be restored when the theme
292 static void UXTHEME_BackupSystemMetrics(void)
295 const struct BackupSysParam
* bsp
= backupSysParams
;
297 if (RegCreateKeyExW( HKEY_CURRENT_USER
, szThemeManager
,
298 0, 0, 0, KEY_ALL_ACCESS
,
299 0, &hKey
, 0) == ERROR_SUCCESS
)
301 save_sys_colors (hKey
);
303 while (bsp
->spiGet
>= 0)
307 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
308 RegSetValueExW (hKey
, bsp
->keyName
, 0, REG_DWORD
,
309 (LPBYTE
)&value
, sizeof (value
));
318 /* Read back old settings after a theme was deactivated */
319 static void UXTHEME_RestoreSystemMetrics(void)
322 const struct BackupSysParam
* bsp
= backupSysParams
;
324 if (RegOpenKeyExW (HKEY_CURRENT_USER
, szThemeManager
,
325 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
329 /* read backed-up colors */
330 if (RegOpenKeyExW (hKey
, strColorKey
,
331 0, KEY_QUERY_VALUE
, &colorKey
) == ERROR_SUCCESS
)
334 COLORREF sysCols
[NUM_SYS_COLORS
];
335 int sysColsIndices
[NUM_SYS_COLORS
];
338 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
342 DWORD count
= sizeof(colorStr
);
344 if (RegQueryValueExA (colorKey
, SysColorsNames
[i
], 0,
345 &type
, (LPBYTE
) colorStr
, &count
) == ERROR_SUCCESS
)
348 if (sscanf (colorStr
, "%d %d %d", &r
, &g
, &b
) == 3)
350 sysColsIndices
[sysColCount
] = i
;
351 sysCols
[sysColCount
] = RGB(r
, g
, b
);
356 RegCloseKey (colorKey
);
358 SetSysColors (sysColCount
, sysColsIndices
, sysCols
);
361 /* read backed-up other settings */
362 while (bsp
->spiGet
>= 0)
365 DWORD count
= sizeof(value
);
368 if (RegQueryValueExW (hKey
, bsp
->keyName
, 0,
369 &type
, (LPBYTE
)&value
, &count
) == ERROR_SUCCESS
)
371 SystemParametersInfoW (bsp
->spiSet
, 0, (LPVOID
)value
,
383 /* Make system settings persistent, so they're in effect even w/o uxtheme
385 static void UXTHEME_SaveSystemMetrics(void)
387 const struct BackupSysParam
* bsp
= backupSysParams
;
389 save_sys_colors (HKEY_CURRENT_USER
);
391 while (bsp
->spiGet
>= 0)
395 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
396 SystemParametersInfoW (bsp
->spiSet
, 0, (LPVOID
)value
,
404 /***********************************************************************
405 * UXTHEME_SetActiveTheme
407 * Change the current active theme
409 HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
415 if(tf
) UXTHEME_BackupSystemMetrics();
416 hr
= MSSTYLES_SetActiveTheme(tf
, TRUE
);
421 lstrcpynW(szCurrentTheme
, tf
->szThemeFile
, sizeof(szCurrentTheme
)/sizeof(szCurrentTheme
[0]));
422 lstrcpynW(szCurrentColor
, tf
->pszSelectedColor
, sizeof(szCurrentColor
)/sizeof(szCurrentColor
[0]));
423 lstrcpynW(szCurrentSize
, tf
->pszSelectedSize
, sizeof(szCurrentSize
)/sizeof(szCurrentSize
[0]));
426 UXTHEME_RestoreSystemMetrics();
427 bThemeActive
= FALSE
;
428 szCurrentTheme
[0] = '\0';
429 szCurrentColor
[0] = '\0';
430 szCurrentSize
[0] = '\0';
433 TRACE("Writing theme config to registry\n");
434 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
435 tmp
[0] = bThemeActive
?'1':'0';
437 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
439 RegSetValueExW(hKey
, szColorName
, 0, REG_SZ
, (const BYTE
*)szCurrentColor
,
440 (lstrlenW(szCurrentColor
)+1)*sizeof(WCHAR
));
441 RegSetValueExW(hKey
, szSizeName
, 0, REG_SZ
, (const BYTE
*)szCurrentSize
,
442 (lstrlenW(szCurrentSize
)+1)*sizeof(WCHAR
));
443 RegSetValueExW(hKey
, szDllName
, 0, REG_SZ
, (const BYTE
*)szCurrentTheme
,
444 (lstrlenW(szCurrentTheme
)+1)*sizeof(WCHAR
));
447 RegDeleteValueW(hKey
, szColorName
);
448 RegDeleteValueW(hKey
, szSizeName
);
449 RegDeleteValueW(hKey
, szDllName
);
455 TRACE("Failed to open theme registry key\n");
457 UXTHEME_SaveSystemMetrics ();
462 /***********************************************************************
465 void UXTHEME_InitSystem(HINSTANCE hInst
)
467 static const WCHAR szWindowTheme
[] = {
468 'u','x','_','t','h','e','m','e','\0'
470 static const WCHAR szSubAppName
[] = {
471 'u','x','_','s','u','b','a','p','p','\0'
473 static const WCHAR szSubIdList
[] = {
474 'u','x','_','s','u','b','i','d','l','s','t','\0'
476 static const WCHAR szDialogThemeEnabled
[] = {
477 'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
482 atWindowTheme
= GlobalAddAtomW(szWindowTheme
);
483 atSubAppName
= GlobalAddAtomW(szSubAppName
);
484 atSubIdList
= GlobalAddAtomW(szSubIdList
);
485 atDialogThemeEnabled
= GlobalAddAtomW(szDialogThemeEnabled
);
490 /***********************************************************************
491 * IsAppThemed (UXTHEME.@)
493 BOOL WINAPI
IsAppThemed(void)
495 return IsThemeActive();
498 /***********************************************************************
499 * IsThemeActive (UXTHEME.@)
501 BOOL WINAPI
IsThemeActive(void)
507 /***********************************************************************
508 * EnableTheming (UXTHEME.@)
511 * This is a global and persistent change
513 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
516 WCHAR szEnabled
[] = {'0','\0'};
518 TRACE("(%d)\n", fEnable
);
520 if(fEnable
!= bThemeActive
) {
522 UXTHEME_BackupSystemMetrics();
524 UXTHEME_RestoreSystemMetrics();
525 UXTHEME_SaveSystemMetrics ();
526 bThemeActive
= fEnable
;
527 if(bThemeActive
) szEnabled
[0] = '1';
528 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
529 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (LPBYTE
)szEnabled
, sizeof(WCHAR
));
532 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
537 /***********************************************************************
538 * UXTHEME_SetWindowProperty
540 * I'm using atoms as there may be large numbers of duplicated strings
541 * and they do the work of keeping memory down as a cause of that quite nicely
543 HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
545 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, MAKEINTATOMW(aProp
));
547 DeleteAtom(oldValue
);
549 ATOM atValue
= AddAtomW(pszValue
);
551 || !SetPropW(hwnd
, MAKEINTATOMW(aProp
), (LPWSTR
)MAKEINTATOMW(atValue
))) {
552 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
553 if(atValue
) DeleteAtom(atValue
);
560 LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
562 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, MAKEINTATOMW(aProp
));
564 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
566 TRACE("property defined, but unable to get value\n");
571 /***********************************************************************
572 * OpenThemeData (UXTHEME.@)
574 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR pszClassList
)
576 WCHAR szAppBuff
[256];
577 WCHAR szClassBuff
[256];
579 LPCWSTR pszUseClassList
;
580 HTHEME hTheme
= NULL
;
581 TRACE("(%p,%s)", hwnd
, debugstr_w(pszClassList
));
585 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, sizeof(szAppBuff
)/sizeof(szAppBuff
[0]));
586 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
587 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, sizeof(szClassBuff
)/sizeof(szClassBuff
[0]));
589 pszUseClassList
= pszClassList
;
592 hTheme
= MSSTYLES_OpenThemeClass(pszAppName
, pszUseClassList
);
595 SetPropW(hwnd
, MAKEINTATOMW(atWindowTheme
), hTheme
);
596 TRACE(" = %p\n", hTheme
);
600 /***********************************************************************
601 * GetWindowTheme (UXTHEME.@)
603 * Retrieve the last theme opened for a window
605 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
607 TRACE("(%p)\n", hwnd
);
608 return GetPropW(hwnd
, MAKEINTATOMW(atWindowTheme
));
611 /***********************************************************************
612 * SetWindowTheme (UXTHEME.@)
614 * Persistent through the life of the window, even after themes change
616 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
617 LPCWSTR pszSubIdList
)
620 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
621 debugstr_w(pszSubIdList
));
622 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
624 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
626 UXTHEME_broadcast_msg (hwnd
, WM_THEMECHANGED
);
630 /***********************************************************************
631 * GetCurrentThemeName (UXTHEME.@)
633 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
634 LPWSTR pszColorBuff
, int cchMaxColorChars
,
635 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
638 return E_PROP_ID_UNSUPPORTED
;
639 if(pszThemeFileName
) lstrcpynW(pszThemeFileName
, szCurrentTheme
, dwMaxNameChars
);
640 if(pszColorBuff
) lstrcpynW(pszColorBuff
, szCurrentColor
, cchMaxColorChars
);
641 if(pszSizeBuff
) lstrcpynW(pszSizeBuff
, szCurrentSize
, cchMaxSizeChars
);
645 /***********************************************************************
646 * GetThemeAppProperties (UXTHEME.@)
648 DWORD WINAPI
GetThemeAppProperties(void)
650 return dwThemeAppProperties
;
653 /***********************************************************************
654 * SetThemeAppProperties (UXTHEME.@)
656 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
658 TRACE("(0x%08lx)\n", dwFlags
);
659 dwThemeAppProperties
= dwFlags
;
662 /***********************************************************************
663 * CloseThemeData (UXTHEME.@)
665 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
667 TRACE("(%p)\n", hTheme
);
670 return MSSTYLES_CloseThemeClass(hTheme
);
673 /***********************************************************************
674 * HitTestThemeBackground (UXTHEME.@)
676 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
677 int iStateId
, DWORD dwOptions
,
678 const RECT
*pRect
, HRGN hrgn
,
679 POINT ptTest
, WORD
*pwHitTestCode
)
681 FIXME("%d %d 0x%08lx: stub\n", iPartId
, iStateId
, dwOptions
);
684 return ERROR_CALL_NOT_IMPLEMENTED
;
687 /***********************************************************************
688 * IsThemePartDefined (UXTHEME.@)
690 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
692 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
694 SetLastError(E_HANDLE
);
697 if(MSSTYLES_FindPartState(hTheme
, iPartId
, iStateId
, NULL
))
702 /***********************************************************************
703 * GetThemeDocumentationProperty (UXTHEME.@)
705 * Try and retrieve the documentation property from string resources
706 * if that fails, get it from the [documentation] section of themes.ini
708 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
709 LPCWSTR pszPropertyName
,
713 const WORD wDocToRes
[] = {
714 TMT_DISPLAYNAME
,5000,
728 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
729 pszValueBuff
, cchMaxValChars
);
731 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
732 if(FAILED(hr
)) return hr
;
734 /* Try to load from string resources */
735 hr
= E_PROP_ID_UNSUPPORTED
;
736 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
737 for(i
=0; i
<sizeof(wDocToRes
)/sizeof(wDocToRes
[0]); i
+=2) {
738 if(wDocToRes
[i
] == iDocId
) {
739 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
746 /* If loading from string resource failed, try getting it from the theme.ini */
748 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
749 if(UXINI_FindSection(uf
, szIniDocumentation
)) {
752 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
753 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
760 MSSTYLES_CloseThemeFile(pt
);
764 /**********************************************************************
765 * Undocumented functions
768 /**********************************************************************
769 * QueryThemeServices (UXTHEME.1)
772 * some kind of status flag
774 DWORD WINAPI
QueryThemeServices()
777 return 3; /* This is what is returned under XP in most cases */
781 /**********************************************************************
782 * OpenThemeFile (UXTHEME.2)
784 * Opens a theme file, which can be used to change the current theme, etc
787 * pszThemeFileName Path to a msstyles theme file
788 * pszColorName Color defined in the theme, eg. NormalColor
789 * pszSizeName Size defined in the theme, eg. NormalSize
790 * hThemeFile Handle to theme file
792 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
793 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
796 TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName
),
797 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
798 hThemeFile
, unknown
);
799 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
802 /**********************************************************************
803 * CloseThemeFile (UXTHEME.3)
805 * Releases theme file handle returned by OpenThemeFile
808 * hThemeFile Handle to theme file
810 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
812 TRACE("(%p)\n", hThemeFile
);
813 MSSTYLES_CloseThemeFile(hThemeFile
);
817 /**********************************************************************
818 * ApplyTheme (UXTHEME.4)
820 * Set a theme file to be the currently active theme
823 * hThemeFile Handle to theme file
825 * hWnd Window requesting the theme change
828 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
831 * the theme is applied with the screen redrawing really badly (flickers)
832 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
833 * the theme is applied smoothly (screen does not flicker)
834 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
835 * the function fails returning invalid parameter...very strange
837 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
840 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
841 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
842 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
846 /**********************************************************************
847 * GetThemeDefaults (UXTHEME.7)
849 * Get the default color & size for a theme
852 * pszThemeFileName Path to a msstyles theme file
853 * pszColorName Buffer to receive the default color name
854 * dwColorNameLen Length, in characters, of color name buffer
855 * pszSizeName Buffer to receive the default size name
856 * dwSizeNameLen Length, in characters, of size name buffer
858 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
859 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
864 TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName
),
865 pszColorName
, dwColorNameLen
,
866 pszSizeName
, dwSizeNameLen
);
868 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
869 if(FAILED(hr
)) return hr
;
871 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
872 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
874 MSSTYLES_CloseThemeFile(pt
);
878 /**********************************************************************
879 * EnumThemes (UXTHEME.8)
881 * Enumerate available themes, calls specified EnumThemeProc for each
882 * theme found. Passes lpData through to callback function.
885 * pszThemePath Path containing themes
886 * callback Called for each theme found in path
887 * lpData Passed through to callback
889 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
892 WCHAR szDir
[MAX_PATH
];
893 WCHAR szPath
[MAX_PATH
];
894 static const WCHAR szStar
[] = {'*','.','*','\0'};
895 static const WCHAR szFormat
[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
896 static const WCHAR szDisplayName
[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
897 static const WCHAR szTooltip
[] = {'t','o','o','l','t','i','p','\0'};
901 WIN32_FIND_DATAW wfd
;
905 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
907 if(!pszThemePath
|| !callback
)
910 lstrcpyW(szDir
, pszThemePath
);
911 pathLen
= lstrlenW (szDir
);
912 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
914 szDir
[pathLen
] = '\\';
915 szDir
[pathLen
+1] = 0;
918 lstrcpyW(szPath
, szDir
);
919 lstrcatW(szPath
, szStar
);
920 TRACE("searching %s\n", debugstr_w(szPath
));
922 hFind
= FindFirstFileW(szPath
, &wfd
);
923 if(hFind
!= INVALID_HANDLE_VALUE
) {
925 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
926 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
927 wsprintfW(szPath
, szFormat
, szDir
, wfd
.cFileName
, wfd
.cFileName
);
929 hr
= GetThemeDocumentationProperty(szPath
, szDisplayName
, szName
, sizeof(szName
)/sizeof(szName
[0]));
931 hr
= GetThemeDocumentationProperty(szPath
, szTooltip
, szTip
, sizeof(szTip
)/sizeof(szTip
[0]));
933 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
934 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
935 TRACE("callback ended enum\n");
940 } while(FindNextFileW(hFind
, &wfd
));
947 /**********************************************************************
948 * EnumThemeColors (UXTHEME.9)
950 * Enumerate theme colors available with a particular size
953 * pszThemeFileName Path to a msstyles theme file
954 * pszSizeName Theme size to enumerate available colors
955 * If NULL the default theme size is used
956 * dwColorNum Color index to retrieve, increment from 0
957 * pszColorNames Output color names
961 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
962 * or when pszSizeName does not refer to a valid size
965 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
966 * sizeof(THEMENAMES).
968 * Not very efficient that I'm opening & validating the theme every call, but
969 * this is undocumented and almost never called..
970 * (and this is how windows works too)
972 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
973 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
978 UINT resourceId
= dwColorNum
+ 1000;
979 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName
),
980 debugstr_w(pszSizeName
), dwColorNum
);
982 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
983 if(FAILED(hr
)) return hr
;
985 tmp
= pt
->pszAvailColors
;
986 while(dwColorNum
&& *tmp
) {
988 tmp
+= lstrlenW(tmp
)+1;
990 if(!dwColorNum
&& *tmp
) {
991 TRACE("%s\n", debugstr_w(tmp
));
992 lstrcpyW(pszColorNames
->szName
, tmp
);
993 LoadStringW (pt
->hTheme
, resourceId
,
994 pszColorNames
->szDisplayName
,
995 sizeof (pszColorNames
->szDisplayName
) / sizeof (WCHAR
));
996 LoadStringW (pt
->hTheme
, resourceId
+1000,
997 pszColorNames
->szTooltip
,
998 sizeof (pszColorNames
->szTooltip
) / sizeof (WCHAR
));
1001 hr
= E_PROP_ID_UNSUPPORTED
;
1003 MSSTYLES_CloseThemeFile(pt
);
1007 /**********************************************************************
1008 * EnumThemeSizes (UXTHEME.10)
1010 * Enumerate theme colors available with a particular size
1013 * pszThemeFileName Path to a msstyles theme file
1014 * pszColorName Theme color to enumerate available sizes
1015 * If NULL the default theme color is used
1016 * dwSizeNum Size index to retrieve, increment from 0
1017 * pszSizeNames Output size names
1021 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1022 * or when pszColorName does not refer to a valid color
1025 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1026 * sizeof(THEMENAMES).
1028 * Not very efficient that I'm opening & validating the theme every call, but
1029 * this is undocumented and almost never called..
1030 * (and this is how windows works too)
1032 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1033 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1038 UINT resourceId
= dwSizeNum
+ 3000;
1039 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName
),
1040 debugstr_w(pszColorName
), dwSizeNum
);
1042 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1043 if(FAILED(hr
)) return hr
;
1045 tmp
= pt
->pszAvailSizes
;
1046 while(dwSizeNum
&& *tmp
) {
1048 tmp
+= lstrlenW(tmp
)+1;
1050 if(!dwSizeNum
&& *tmp
) {
1051 TRACE("%s\n", debugstr_w(tmp
));
1052 lstrcpyW(pszSizeNames
->szName
, tmp
);
1053 LoadStringW (pt
->hTheme
, resourceId
,
1054 pszSizeNames
->szDisplayName
,
1055 sizeof (pszSizeNames
->szDisplayName
) / sizeof (WCHAR
));
1056 LoadStringW (pt
->hTheme
, resourceId
+1000,
1057 pszSizeNames
->szTooltip
,
1058 sizeof (pszSizeNames
->szTooltip
) / sizeof (WCHAR
));
1061 hr
= E_PROP_ID_UNSUPPORTED
;
1063 MSSTYLES_CloseThemeFile(pt
);
1067 /**********************************************************************
1068 * ParseThemeIniFile (UXTHEME.11)
1070 * Enumerate data in a theme INI file.
1073 * pszIniFileName Path to a theme ini file
1074 * pszUnknown Cannot be NULL, L"" is valid
1075 * callback Called for each found entry
1076 * lpData Passed through to callback
1080 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1083 * When pszUnknown is NULL the callback is never called, the value does not seem to surve
1086 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1087 ParseThemeIniFileProc callback
, LPVOID lpData
)
1089 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1090 return ERROR_CALL_NOT_IMPLEMENTED
;
1093 /**********************************************************************
1094 * CheckThemeSignature (UXTHEME.29)
1096 * Validates the signature of a theme file
1099 * pszIniFileName Path to a theme file
1101 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1105 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1106 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1109 MSSTYLES_CloseThemeFile(pt
);