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
35 #include "uxthemedll.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
42 /***********************************************************************
43 * Defines and global variables
46 static const WCHAR szThemeManager[] = {
47 'S','o','f','t','w','a','r','e','\\',
48 'M','i','c','r','o','s','o','f','t','\\',
49 'W','i','n','d','o','w','s','\\',
50 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
51 'T','h','e','m','e','M','a','n','a','g','e','r','\0'
53 static const WCHAR szThemeActive[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
54 static const WCHAR szSizeName[] = {'S','i','z','e','N','a','m','e','\0'};
55 static const WCHAR szColorName[] = {'C','o','l','o','r','N','a','m','e','\0'};
56 static const WCHAR szDllName[] = {'D','l','l','N','a','m','e','\0'};
58 static const WCHAR szIniDocumentation[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
62 DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
66 ATOM atDialogThemeEnabled;
68 BOOL bThemeActive = FALSE;
69 WCHAR szCurrentTheme[MAX_PATH];
70 WCHAR szCurrentColor[64];
71 WCHAR szCurrentSize[64];
73 /***********************************************************************/
75 static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
77 PostMessageW(hWnd, msg, 0, 0);
81 /* Broadcast a message to *all* windows, including children */
82 static BOOL CALLBACK UXTHEME_broadcast_msg (HWND hWnd, LPARAM msg)
86 EnumWindows (UXTHEME_broadcast_msg, msg);
90 PostMessageW(hWnd, msg, 0, 0);
91 EnumChildWindows (hWnd, UXTHEME_broadcast_msg_enumchild, msg);
96 /***********************************************************************
99 * Set the current active theme from the registry
101 static void UXTHEME_LoadTheme(void)
109 /* Get current theme configuration */
110 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
111 TRACE("Loading theme config\n");
112 buffsize = sizeof(tmp)/sizeof(tmp[0]);
113 if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
114 bThemeActive = (tmp[0] != '0');
117 bThemeActive = FALSE;
118 TRACE("Failed to get ThemeActive: %ld\n", GetLastError());
120 buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]);
121 if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
122 szCurrentColor[0] = '\0';
123 buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]);
124 if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
125 szCurrentSize[0] = '\0';
126 if(SHRegGetPathW(hKey, NULL, szDllName, szCurrentTheme, 0))
127 szCurrentTheme[0] = '\0';
131 TRACE("Failed to open theme registry key\n");
134 /* Make sure the theme requested is actually valid */
135 hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
136 szCurrentColor[0]?szCurrentColor:NULL,
137 szCurrentSize[0]?szCurrentSize:NULL,
140 bThemeActive = FALSE;
141 szCurrentTheme[0] = '\0';
142 szCurrentColor[0] = '\0';
143 szCurrentSize[0] = '\0';
146 /* Make sure the global color & size match the theme */
147 lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
148 lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
150 MSSTYLES_SetActiveTheme(pt, FALSE);
151 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
152 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
153 MSSTYLES_CloseThemeFile(pt);
157 MSSTYLES_SetActiveTheme(NULL, FALSE);
158 TRACE("Themeing not active\n");
162 /***********************************************************************/
164 static const char * const SysColorsNames[] =
166 "Scrollbar", /* COLOR_SCROLLBAR */
167 "Background", /* COLOR_BACKGROUND */
168 "ActiveTitle", /* COLOR_ACTIVECAPTION */
169 "InactiveTitle", /* COLOR_INACTIVECAPTION */
170 "Menu", /* COLOR_MENU */
171 "Window", /* COLOR_WINDOW */
172 "WindowFrame", /* COLOR_WINDOWFRAME */
173 "MenuText", /* COLOR_MENUTEXT */
174 "WindowText", /* COLOR_WINDOWTEXT */
175 "TitleText", /* COLOR_CAPTIONTEXT */
176 "ActiveBorder", /* COLOR_ACTIVEBORDER */
177 "InactiveBorder", /* COLOR_INACTIVEBORDER */
178 "AppWorkSpace", /* COLOR_APPWORKSPACE */
179 "Hilight", /* COLOR_HIGHLIGHT */
180 "HilightText", /* COLOR_HIGHLIGHTTEXT */
181 "ButtonFace", /* COLOR_BTNFACE */
182 "ButtonShadow", /* COLOR_BTNSHADOW */
183 "GrayText", /* COLOR_GRAYTEXT */
184 "ButtonText", /* COLOR_BTNTEXT */
185 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
186 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
187 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
188 "ButtonLight", /* COLOR_3DLIGHT */
189 "InfoText", /* COLOR_INFOTEXT */
190 "InfoWindow", /* COLOR_INFOBK */
191 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
192 "HotTrackingColor", /* COLOR_HOTLIGHT */
193 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
194 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
195 "MenuHilight", /* COLOR_MENUHILIGHT */
196 "MenuBar", /* COLOR_MENUBAR */
198 static const WCHAR strColorKey[] =
199 { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
200 'C','o','l','o','r','s',0 };
201 static const WCHAR keyFlatMenus[] = { 'F','l','a','t','M','e','n','u', 0};
203 static const struct BackupSysParam
206 const WCHAR* keyName;
207 } backupSysParams[] =
209 {SPI_GETFLATMENU, SPI_SETFLATMENU, keyFlatMenus},
213 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
215 static void save_sys_colors (HKEY baseKey)
221 if (RegCreateKeyExW( baseKey, strColorKey,
222 0, 0, 0, KEY_ALL_ACCESS,
223 0, &hKey, 0 ) == ERROR_SUCCESS)
225 for (i = 0; i < NUM_SYS_COLORS; i++)
227 COLORREF col = GetSysColor (i);
229 sprintf (colorStr, "%d %d %d",
230 GetRValue (col), GetGValue (col), GetBValue (col));
232 RegSetValueExA (hKey, SysColorsNames[i], 0, REG_SZ,
233 (BYTE*)colorStr, strlen (colorStr)+1);
239 /* Before activating a theme, query current system colors, certain settings
240 * and backup them in the registry, so they can be restored when the theme
242 static void UXTHEME_BackupSystemMetrics(void)
245 const struct BackupSysParam* bsp = backupSysParams;
247 if (RegCreateKeyExW( HKEY_CURRENT_USER, szThemeManager,
248 0, 0, 0, KEY_ALL_ACCESS,
249 0, &hKey, 0) == ERROR_SUCCESS)
251 save_sys_colors (hKey);
253 while (bsp->spiGet >= 0)
257 SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
258 RegSetValueExW (hKey, bsp->keyName, 0, REG_DWORD,
259 (LPBYTE)&value, sizeof (value));
268 /* Read back old settings after a theme was deactivated */
269 static void UXTHEME_RestoreSystemMetrics(void)
272 const struct BackupSysParam* bsp = backupSysParams;
274 if (RegOpenKeyExW (HKEY_CURRENT_USER, szThemeManager,
275 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
279 /* read backed-up colors */
280 if (RegOpenKeyExW (hKey, strColorKey,
281 0, KEY_QUERY_VALUE, &colorKey) == ERROR_SUCCESS)
284 COLORREF sysCols[NUM_SYS_COLORS];
285 int sysColsIndices[NUM_SYS_COLORS];
288 for (i = 0; i < NUM_SYS_COLORS; i++)
292 DWORD count = sizeof(colorStr);
294 if (RegQueryValueExA (colorKey, SysColorsNames[i], 0,
295 &type, colorStr, &count) == ERROR_SUCCESS)
298 if (sscanf (colorStr, "%d %d %d", &r, &g, &b) == 3)
300 sysColsIndices[sysColCount] = i;
301 sysCols[sysColCount] = RGB(r, g, b);
306 RegCloseKey (colorKey);
308 SetSysColors (sysColCount, sysColsIndices, sysCols);
311 /* read backed-up other settings */
312 while (bsp->spiGet >= 0)
315 DWORD count = sizeof(value);
318 if (RegQueryValueExW (hKey, bsp->keyName, 0,
319 &type, (LPBYTE)&value, &count) == ERROR_SUCCESS)
321 SystemParametersInfoW (bsp->spiSet, 0, (LPVOID)value,
333 /* Make system settings persistent, so they're in effect even w/o uxtheme
335 static void UXTHEME_SaveSystemMetrics(void)
337 const struct BackupSysParam* bsp = backupSysParams;
339 save_sys_colors (HKEY_CURRENT_USER);
341 while (bsp->spiGet >= 0)
345 SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
346 SystemParametersInfoW (bsp->spiSet, 0, (LPVOID)value,
354 /***********************************************************************
355 * UXTHEME_SetActiveTheme
357 * Change the current active theme
359 HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
365 if(tf) UXTHEME_BackupSystemMetrics();
366 hr = MSSTYLES_SetActiveTheme(tf, TRUE);
371 lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
372 lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
373 lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
376 UXTHEME_RestoreSystemMetrics();
377 bThemeActive = FALSE;
378 szCurrentTheme[0] = '\0';
379 szCurrentColor[0] = '\0';
380 szCurrentSize[0] = '\0';
383 TRACE("Writing theme config to registry\n");
384 if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
385 tmp[0] = bThemeActive?'1':'0';
387 RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
389 RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor,
390 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
391 RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize,
392 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
393 RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme,
394 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
397 RegDeleteValueW(hKey, szColorName);
398 RegDeleteValueW(hKey, szSizeName);
399 RegDeleteValueW(hKey, szDllName);
405 TRACE("Failed to open theme registry key\n");
407 UXTHEME_SaveSystemMetrics ();
412 /***********************************************************************
415 void UXTHEME_InitSystem(HINSTANCE hInst)
417 static const WCHAR szWindowTheme[] = {
418 'u','x','_','t','h','e','m','e','\0'
420 static const WCHAR szSubAppName[] = {
421 'u','x','_','s','u','b','a','p','p','\0'
423 static const WCHAR szSubIdList[] = {
424 'u','x','_','s','u','b','i','d','l','s','t','\0'
426 static const WCHAR szDialogThemeEnabled[] = {
427 'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
432 atWindowTheme = GlobalAddAtomW(szWindowTheme);
433 atSubAppName = GlobalAddAtomW(szSubAppName);
434 atSubIdList = GlobalAddAtomW(szSubIdList);
435 atDialogThemeEnabled = GlobalAddAtomW(szDialogThemeEnabled);
440 /***********************************************************************
441 * IsAppThemed (UXTHEME.@)
443 BOOL WINAPI IsAppThemed(void)
445 return IsThemeActive();
448 /***********************************************************************
449 * IsThemeActive (UXTHEME.@)
451 BOOL WINAPI IsThemeActive(void)
457 /***********************************************************************
458 * EnableTheming (UXTHEME.@)
461 * This is a global and persistent change
463 HRESULT WINAPI EnableTheming(BOOL fEnable)
466 WCHAR szEnabled[] = {'0','\0'};
468 TRACE("(%d)\n", fEnable);
470 if(fEnable != bThemeActive) {
472 UXTHEME_BackupSystemMetrics();
474 UXTHEME_RestoreSystemMetrics();
475 UXTHEME_SaveSystemMetrics ();
476 bThemeActive = fEnable;
477 if(bThemeActive) szEnabled[0] = '1';
478 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
479 RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (LPBYTE)szEnabled, sizeof(WCHAR));
482 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
487 /***********************************************************************
488 * UXTHEME_SetWindowProperty
490 * I'm using atoms as there may be large numbers of duplicated strings
491 * and they do the work of keeping memory down as a cause of that quite nicely
493 HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
495 ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, MAKEINTATOMW(aProp));
497 DeleteAtom(oldValue);
499 ATOM atValue = AddAtomW(pszValue);
501 || !SetPropW(hwnd, MAKEINTATOMW(aProp), (LPWSTR)MAKEINTATOMW(atValue))) {
502 HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
503 if(atValue) DeleteAtom(atValue);
510 LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
512 ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, MAKEINTATOMW(aProp));
514 if(GetAtomNameW(atValue, pszBuffer, dwLen))
516 TRACE("property defined, but unable to get value\n");
521 /***********************************************************************
522 * OpenThemeData (UXTHEME.@)
524 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
526 WCHAR szAppBuff[256];
527 WCHAR szClassBuff[256];
529 LPCWSTR pszUseClassList;
530 HTHEME hTheme = NULL;
531 TRACE("(%p,%s)", hwnd, debugstr_w(pszClassList));
535 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
536 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
537 pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
539 pszUseClassList = pszClassList;
542 hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
545 SetPropW(hwnd, MAKEINTATOMW(atWindowTheme), hTheme);
546 TRACE(" = %p\n", hTheme);
550 /***********************************************************************
551 * GetWindowTheme (UXTHEME.@)
553 * Retrieve the last theme opened for a window
555 HTHEME WINAPI GetWindowTheme(HWND hwnd)
557 TRACE("(%p)\n", hwnd);
558 return GetPropW(hwnd, MAKEINTATOMW(atWindowTheme));
561 /***********************************************************************
562 * SetWindowTheme (UXTHEME.@)
564 * Persistent through the life of the window, even after themes change
566 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
567 LPCWSTR pszSubIdList)
570 TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
571 debugstr_w(pszSubIdList));
572 hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
574 hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
576 UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
580 /***********************************************************************
581 * GetCurrentThemeName (UXTHEME.@)
583 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
584 LPWSTR pszColorBuff, int cchMaxColorChars,
585 LPWSTR pszSizeBuff, int cchMaxSizeChars)
588 return E_PROP_ID_UNSUPPORTED;
589 if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
590 if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
591 if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
595 /***********************************************************************
596 * GetThemeAppProperties (UXTHEME.@)
598 DWORD WINAPI GetThemeAppProperties(void)
600 return dwThemeAppProperties;
603 /***********************************************************************
604 * SetThemeAppProperties (UXTHEME.@)
606 void WINAPI SetThemeAppProperties(DWORD dwFlags)
608 TRACE("(0x%08lx)\n", dwFlags);
609 dwThemeAppProperties = dwFlags;
612 /***********************************************************************
613 * CloseThemeData (UXTHEME.@)
615 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
617 TRACE("(%p)\n", hTheme);
620 return MSSTYLES_CloseThemeClass(hTheme);
623 /***********************************************************************
624 * HitTestThemeBackground (UXTHEME.@)
626 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
627 int iStateId, DWORD dwOptions,
628 const RECT *pRect, HRGN hrgn,
629 POINT ptTest, WORD *pwHitTestCode)
631 FIXME("%d %d 0x%08lx: stub\n", iPartId, iStateId, dwOptions);
634 return ERROR_CALL_NOT_IMPLEMENTED;
637 /***********************************************************************
638 * IsThemePartDefined (UXTHEME.@)
640 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
642 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
644 SetLastError(E_HANDLE);
647 if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
652 /***********************************************************************
653 * GetThemeDocumentationProperty (UXTHEME.@)
655 * Try and retrieve the documentation property from string resources
656 * if that fails, get it from the [documentation] section of themes.ini
658 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
659 LPCWSTR pszPropertyName,
663 const WORD wDocToRes[] = {
664 TMT_DISPLAYNAME,5000,
678 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
679 pszValueBuff, cchMaxValChars);
681 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
682 if(FAILED(hr)) return hr;
684 /* Try to load from string resources */
685 hr = E_PROP_ID_UNSUPPORTED;
686 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
687 for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
688 if(wDocToRes[i] == iDocId) {
689 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
696 /* If loading from string resource failed, try getting it from the theme.ini */
698 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
699 if(UXINI_FindSection(uf, szIniDocumentation)) {
702 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
703 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
710 MSSTYLES_CloseThemeFile(pt);
714 /**********************************************************************
715 * Undocumented functions
718 /**********************************************************************
719 * QueryThemeServices (UXTHEME.1)
722 * some kind of status flag
724 DWORD WINAPI QueryThemeServices()
727 return 3; /* This is what is returned under XP in most cases */
731 /**********************************************************************
732 * OpenThemeFile (UXTHEME.2)
734 * Opens a theme file, which can be used to change the current theme, etc
737 * pszThemeFileName Path to a msstyles theme file
738 * pszColorName Color defined in the theme, eg. NormalColor
739 * pszSizeName Size defined in the theme, eg. NormalSize
740 * hThemeFile Handle to theme file
742 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
743 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
746 TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName),
747 debugstr_w(pszColorName), debugstr_w(pszSizeName),
748 hThemeFile, unknown);
749 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
752 /**********************************************************************
753 * CloseThemeFile (UXTHEME.3)
755 * Releases theme file handle returned by OpenThemeFile
758 * hThemeFile Handle to theme file
760 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
762 TRACE("(%p)\n", hThemeFile);
763 MSSTYLES_CloseThemeFile(hThemeFile);
767 /**********************************************************************
768 * ApplyTheme (UXTHEME.4)
770 * Set a theme file to be the currently active theme
773 * hThemeFile Handle to theme file
775 * hWnd Window requesting the theme change
778 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
781 * the theme is applied with the screen redrawing really badly (flickers)
782 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
783 * the theme is applied smoothly (screen does not flicker)
784 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
785 * the function fails returning invalid parameter...very strange
787 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
790 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
791 hr = UXTHEME_SetActiveTheme(hThemeFile);
792 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
796 /**********************************************************************
797 * GetThemeDefaults (UXTHEME.7)
799 * Get the default color & size for a theme
802 * pszThemeFileName Path to a msstyles theme file
803 * pszColorName Buffer to receive the default color name
804 * dwColorNameLen Length, in characters, of color name buffer
805 * pszSizeName Buffer to receive the default size name
806 * dwSizeNameLen Length, in characters, of size name buffer
808 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
809 DWORD dwColorNameLen, LPWSTR pszSizeName,
814 TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName),
815 pszColorName, dwColorNameLen,
816 pszSizeName, dwSizeNameLen);
818 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
819 if(FAILED(hr)) return hr;
821 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
822 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
824 MSSTYLES_CloseThemeFile(pt);
828 /**********************************************************************
829 * EnumThemes (UXTHEME.8)
831 * Enumerate available themes, calls specified EnumThemeProc for each
832 * theme found. Passes lpData through to callback function.
835 * pszThemePath Path containing themes
836 * callback Called for each theme found in path
837 * lpData Passed through to callback
839 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
842 WCHAR szDir[MAX_PATH];
843 WCHAR szPath[MAX_PATH];
844 static const WCHAR szStar[] = {'*','.','*','\0'};
845 static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
846 static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
847 static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
851 WIN32_FIND_DATAW wfd;
854 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
856 if(!pszThemePath || !callback)
859 lstrcpyW(szDir, pszThemePath);
860 PathAddBackslashW(szDir);
862 lstrcpyW(szPath, szDir);
863 lstrcatW(szPath, szStar);
864 TRACE("searching %s\n", debugstr_w(szPath));
866 hFind = FindFirstFileW(szPath, &wfd);
867 if(hFind != INVALID_HANDLE_VALUE) {
869 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
870 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
871 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
873 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
875 hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
877 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
878 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
879 TRACE("callback ended enum\n");
884 } while(FindNextFileW(hFind, &wfd));
891 /**********************************************************************
892 * EnumThemeColors (UXTHEME.9)
894 * Enumerate theme colors available with a particular size
897 * pszThemeFileName Path to a msstyles theme file
898 * pszSizeName Theme size to enumerate available colors
899 * If NULL the default theme size is used
900 * dwColorNum Color index to retrieve, increment from 0
901 * pszColorNames Output color names
905 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
906 * or when pszSizeName does not refer to a valid size
909 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
910 * sizeof(THEMENAMES).
912 * Not very efficient that I'm opening & validating the theme every call, but
913 * this is undocumented and almost never called..
914 * (and this is how windows works too)
916 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
917 DWORD dwColorNum, PTHEMENAMES pszColorNames)
922 UINT resourceId = dwColorNum + 1000;
923 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
924 debugstr_w(pszSizeName), dwColorNum);
926 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
927 if(FAILED(hr)) return hr;
929 tmp = pt->pszAvailColors;
930 while(dwColorNum && *tmp) {
932 tmp += lstrlenW(tmp)+1;
934 if(!dwColorNum && *tmp) {
935 TRACE("%s\n", debugstr_w(tmp));
936 lstrcpyW(pszColorNames->szName, tmp);
937 LoadStringW (pt->hTheme, resourceId,
938 pszColorNames->szDisplayName,
939 sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
940 LoadStringW (pt->hTheme, resourceId+1000,
941 pszColorNames->szTooltip,
942 sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
945 hr = E_PROP_ID_UNSUPPORTED;
947 MSSTYLES_CloseThemeFile(pt);
951 /**********************************************************************
952 * EnumThemeSizes (UXTHEME.10)
954 * Enumerate theme colors available with a particular size
957 * pszThemeFileName Path to a msstyles theme file
958 * pszColorName Theme color to enumerate available sizes
959 * If NULL the default theme color is used
960 * dwSizeNum Size index to retrieve, increment from 0
961 * pszSizeNames Output size names
965 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
966 * or when pszColorName does not refer to a valid color
969 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
970 * sizeof(THEMENAMES).
972 * Not very efficient that I'm opening & validating the theme every call, but
973 * this is undocumented and almost never called..
974 * (and this is how windows works too)
976 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
977 DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
982 UINT resourceId = dwSizeNum + 3000;
983 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
984 debugstr_w(pszColorName), dwSizeNum);
986 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
987 if(FAILED(hr)) return hr;
989 tmp = pt->pszAvailSizes;
990 while(dwSizeNum && *tmp) {
992 tmp += lstrlenW(tmp)+1;
994 if(!dwSizeNum && *tmp) {
995 TRACE("%s\n", debugstr_w(tmp));
996 lstrcpyW(pszSizeNames->szName, tmp);
997 LoadStringW (pt->hTheme, resourceId,
998 pszSizeNames->szDisplayName,
999 sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
1000 LoadStringW (pt->hTheme, resourceId+1000,
1001 pszSizeNames->szTooltip,
1002 sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
1005 hr = E_PROP_ID_UNSUPPORTED;
1007 MSSTYLES_CloseThemeFile(pt);
1011 /**********************************************************************
1012 * ParseThemeIniFile (UXTHEME.11)
1014 * Enumerate data in a theme INI file.
1017 * pszIniFileName Path to a theme ini file
1018 * pszUnknown Cannot be NULL, L"" is valid
1019 * callback Called for each found entry
1020 * lpData Passed through to callback
1024 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1027 * When pszUnknown is NULL the callback is never called, the value does not seem to surve
1030 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1031 ParseThemeIniFileProc callback, LPVOID lpData)
1033 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1034 return ERROR_CALL_NOT_IMPLEMENTED;
1037 /**********************************************************************
1038 * CheckThemeSignature (UXTHEME.29)
1040 * Validates the signature of a theme file
1043 * pszIniFileName Path to a theme file
1045 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1049 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1050 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1053 MSSTYLES_CloseThemeFile(pt);