Every window needs to receive WM_THEMECHANGED (esp. controls), so also
[wine/gsoc_dplay.git] / dlls / uxtheme / system.c
blobaae1721aaa889e8746f225cafd852998c13bc9a7
1 /*
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
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "uxtheme.h"
32 #include "tmschema.h"
34 #include "uxthemedll.h"
35 #include "msstyles.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'};
59 HINSTANCE hDllInst;
61 DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
62 ATOM atWindowTheme;
63 ATOM atSubAppName;
64 ATOM atSubIdList;
66 BOOL bThemeActive = FALSE;
67 WCHAR szCurrentTheme[MAX_PATH];
68 WCHAR szCurrentColor[64];
69 WCHAR szCurrentSize[64];
71 /***********************************************************************/
73 static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
75 PostMessageW(hWnd, msg, 0, 0);
76 return TRUE;
79 /* Broadcast a message to *all* windows, including children */
80 static BOOL CALLBACK UXTHEME_broadcast_msg (HWND hWnd, LPARAM msg)
82 if (hWnd == NULL)
84 EnumWindows (UXTHEME_broadcast_msg, msg);
86 else
88 PostMessageW(hWnd, msg, 0, 0);
89 EnumChildWindows (hWnd, UXTHEME_broadcast_msg_enumchild, msg);
91 return TRUE;
94 /***********************************************************************
95 * UXTHEME_LoadTheme
97 * Set the current active theme from the registry
99 static void UXTHEME_LoadTheme(void)
101 HKEY hKey;
102 LONG buffsize;
103 HRESULT hr;
104 WCHAR tmp[10];
105 PTHEME_FILE pt;
107 /* Get current theme configuration */
108 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
109 TRACE("Loading theme config\n");
110 buffsize = sizeof(tmp)/sizeof(tmp[0]);
111 if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
112 bThemeActive = (tmp[0] != '0');
114 else {
115 bThemeActive = FALSE;
116 TRACE("Failed to get ThemeActive: %ld\n", GetLastError());
118 buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]);
119 if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
120 szCurrentColor[0] = '\0';
121 buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]);
122 if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
123 szCurrentSize[0] = '\0';
124 if(SHRegGetPathW(hKey, NULL, szDllName, szCurrentTheme, 0))
125 szCurrentTheme[0] = '\0';
126 RegCloseKey(hKey);
128 else
129 TRACE("Failed to open theme registry key\n");
131 if(bThemeActive) {
132 /* Make sure the theme requested is actually valid */
133 hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
134 szCurrentColor[0]?szCurrentColor:NULL,
135 szCurrentSize[0]?szCurrentSize:NULL,
136 &pt);
137 if(FAILED(hr)) {
138 bThemeActive = FALSE;
139 szCurrentTheme[0] = '\0';
140 szCurrentColor[0] = '\0';
141 szCurrentSize[0] = '\0';
143 else {
144 /* Make sure the global color & size match the theme */
145 lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
146 lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
148 MSSTYLES_SetActiveTheme(pt);
149 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
150 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
151 MSSTYLES_CloseThemeFile(pt);
154 if(!bThemeActive) {
155 MSSTYLES_SetActiveTheme(NULL);
156 TRACE("Themeing not active\n");
160 /***********************************************************************
161 * UXTHEME_SetActiveTheme
163 * Change the current active theme
165 HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
167 HKEY hKey;
168 WCHAR tmp[2];
169 HRESULT hr;
171 hr = MSSTYLES_SetActiveTheme(tf);
172 if(FAILED(hr))
173 return hr;
174 if(tf) {
175 bThemeActive = TRUE;
176 lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
177 lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
178 lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
180 else {
181 bThemeActive = FALSE;
182 szCurrentTheme[0] = '\0';
183 szCurrentColor[0] = '\0';
184 szCurrentSize[0] = '\0';
187 TRACE("Writing theme config to registry\n");
188 if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
189 tmp[0] = bThemeActive?'1':'0';
190 tmp[1] = '\0';
191 RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
192 if(bThemeActive) {
193 RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor,
194 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
195 RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize,
196 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
197 RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme,
198 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
200 else {
201 RegDeleteValueW(hKey, szColorName);
202 RegDeleteValueW(hKey, szSizeName);
203 RegDeleteValueW(hKey, szDllName);
206 RegCloseKey(hKey);
208 else
209 TRACE("Failed to open theme registry key\n");
210 return hr;
213 /***********************************************************************
214 * UXTHEME_InitSystem
216 void UXTHEME_InitSystem(HINSTANCE hInst)
218 static const WCHAR szWindowTheme[] = {
219 'u','x','_','t','h','e','m','e','\0'
221 static const WCHAR szSubAppName[] = {
222 'u','x','_','s','u','b','a','p','p','\0'
224 static const WCHAR szSubIdList[] = {
225 'u','x','_','s','u','b','i','d','l','s','t','\0'
228 hDllInst = hInst;
230 atWindowTheme = GlobalAddAtomW(szWindowTheme);
231 atSubAppName = GlobalAddAtomW(szSubAppName);
232 atSubIdList = GlobalAddAtomW(szSubIdList);
234 UXTHEME_LoadTheme();
237 /***********************************************************************
238 * IsAppThemed (UXTHEME.@)
240 BOOL WINAPI IsAppThemed(void)
242 return IsThemeActive();
245 /***********************************************************************
246 * IsThemeActive (UXTHEME.@)
248 BOOL WINAPI IsThemeActive(void)
250 TRACE("\n");
251 return bThemeActive;
254 /***********************************************************************
255 * EnableTheming (UXTHEME.@)
257 * NOTES
258 * This is a global and persistent change
260 HRESULT WINAPI EnableTheming(BOOL fEnable)
262 HKEY hKey;
263 WCHAR szEnabled[] = {'0','\0'};
265 TRACE("(%d)\n", fEnable);
267 if(fEnable != bThemeActive) {
268 bThemeActive = fEnable;
269 if(bThemeActive) szEnabled[0] = '1';
270 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
271 RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (LPBYTE)szEnabled, sizeof(WCHAR));
272 RegCloseKey(hKey);
274 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
276 return S_OK;
279 /***********************************************************************
280 * UXTHEME_SetWindowProperty
282 * I'm using atoms as there may be large numbers of duplicated strings
283 * and they do the work of keeping memory down as a cause of that quite nicely
285 HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
287 ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, MAKEINTATOMW(aProp));
288 if(oldValue)
289 DeleteAtom(oldValue);
290 if(pszValue) {
291 ATOM atValue = AddAtomW(pszValue);
292 if(!atValue
293 || !SetPropW(hwnd, MAKEINTATOMW(aProp), (LPWSTR)MAKEINTATOMW(atValue))) {
294 HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
295 if(atValue) DeleteAtom(atValue);
296 return hr;
299 return S_OK;
302 LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
304 ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, MAKEINTATOMW(aProp));
305 if(atValue) {
306 if(GetAtomNameW(atValue, pszBuffer, dwLen))
307 return pszBuffer;
308 TRACE("property defined, but unable to get value\n");
310 return NULL;
313 /***********************************************************************
314 * OpenThemeData (UXTHEME.@)
316 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
318 WCHAR szAppBuff[256];
319 WCHAR szClassBuff[256];
320 LPCWSTR pszAppName;
321 LPCWSTR pszUseClassList;
322 HTHEME hTheme;
323 TRACE("(%p,%s)\n", hwnd, debugstr_w(pszClassList));
324 if(!bThemeActive)
325 return NULL;
327 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
328 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
329 pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
330 if(!pszUseClassList)
331 pszUseClassList = pszClassList;
333 hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
334 if(IsWindow(hwnd))
335 SetPropW(hwnd, MAKEINTATOMW(atWindowTheme), hTheme);
336 return hTheme;
339 /***********************************************************************
340 * GetWindowTheme (UXTHEME.@)
342 * Retrieve the last theme opened for a window
344 HTHEME WINAPI GetWindowTheme(HWND hwnd)
346 TRACE("(%p)\n", hwnd);
347 return GetPropW(hwnd, MAKEINTATOMW(atWindowTheme));
350 /***********************************************************************
351 * SetWindowTheme (UXTHEME.@)
353 * Persistent through the life of the window, even after themes change
355 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
356 LPCWSTR pszSubIdList)
358 HRESULT hr;
359 TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
360 debugstr_w(pszSubIdList));
361 hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
362 if(SUCCEEDED(hr))
363 hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
364 if(SUCCEEDED(hr))
365 UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
366 return hr;
369 /***********************************************************************
370 * GetCurrentThemeName (UXTHEME.@)
372 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
373 LPWSTR pszColorBuff, int cchMaxColorChars,
374 LPWSTR pszSizeBuff, int cchMaxSizeChars)
376 if(!bThemeActive)
377 return E_PROP_ID_UNSUPPORTED;
378 if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
379 if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
380 if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
381 return S_OK;
384 /***********************************************************************
385 * GetThemeAppProperties (UXTHEME.@)
387 DWORD WINAPI GetThemeAppProperties(void)
389 return dwThemeAppProperties;
392 /***********************************************************************
393 * SetThemeAppProperties (UXTHEME.@)
395 void WINAPI SetThemeAppProperties(DWORD dwFlags)
397 TRACE("(0x%08lx)\n", dwFlags);
398 dwThemeAppProperties = dwFlags;
401 /***********************************************************************
402 * CloseThemeData (UXTHEME.@)
404 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
406 TRACE("(%p)\n", hTheme);
407 if(!hTheme)
408 return E_HANDLE;
409 return MSSTYLES_CloseThemeClass(hTheme);
412 /***********************************************************************
413 * HitTestThemeBackground (UXTHEME.@)
415 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
416 int iStateId, DWORD dwOptions,
417 const RECT *pRect, HRGN hrgn,
418 POINT ptTest, WORD *pwHitTestCode)
420 FIXME("%d %d 0x%08lx: stub\n", iPartId, iStateId, dwOptions);
421 if(!hTheme)
422 return E_HANDLE;
423 return ERROR_CALL_NOT_IMPLEMENTED;
426 /***********************************************************************
427 * IsThemePartDefined (UXTHEME.@)
429 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
431 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
432 if(!hTheme) {
433 SetLastError(E_HANDLE);
434 return FALSE;
436 if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
437 return TRUE;
438 return FALSE;
441 /***********************************************************************
442 * GetThemeDocumentationProperty (UXTHEME.@)
444 * Try and retrieve the documentation property from string resources
445 * if that fails, get it from the [documentation] section of themes.ini
447 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
448 LPCWSTR pszPropertyName,
449 LPWSTR pszValueBuff,
450 int cchMaxValChars)
452 const WORD wDocToRes[] = {
453 TMT_DISPLAYNAME,5000,
454 TMT_TOOLTIP,5001,
455 TMT_COMPANY,5002,
456 TMT_AUTHOR,5003,
457 TMT_COPYRIGHT,5004,
458 TMT_URL,5005,
459 TMT_VERSION,5006,
460 TMT_DESCRIPTION,5007
463 PTHEME_FILE pt;
464 HRESULT hr;
465 unsigned int i;
466 int iDocId;
467 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
468 pszValueBuff, cchMaxValChars);
470 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
471 if(FAILED(hr)) return hr;
473 /* Try to load from string resources */
474 hr = E_PROP_ID_UNSUPPORTED;
475 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
476 for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
477 if(wDocToRes[i] == iDocId) {
478 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
479 hr = S_OK;
480 break;
485 /* If loading from string resource failed, try getting it from the theme.ini */
486 if(FAILED(hr)) {
487 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
488 if(UXINI_FindSection(uf, szIniDocumentation)) {
489 LPCWSTR lpValue;
490 DWORD dwLen;
491 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
492 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
493 hr = S_OK;
496 UXINI_CloseINI(uf);
499 MSSTYLES_CloseThemeFile(pt);
500 return hr;
503 /**********************************************************************
504 * Undocumented functions
507 /**********************************************************************
508 * QueryThemeServices (UXTHEME.1)
510 * RETURNS
511 * some kind of status flag
513 DWORD WINAPI QueryThemeServices()
515 FIXME("stub\n");
516 return 3; /* This is what is returned under XP in most cases */
520 /**********************************************************************
521 * OpenThemeFile (UXTHEME.2)
523 * Opens a theme file, which can be used to change the current theme, etc
525 * PARAMS
526 * pszThemeFileName Path to a msstyles theme file
527 * pszColorName Color defined in the theme, eg. NormalColor
528 * pszSizeName Size defined in the theme, eg. NormalSize
529 * hThemeFile Handle to theme file
531 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
532 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
533 DWORD unknown)
535 TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName),
536 debugstr_w(pszColorName), debugstr_w(pszSizeName),
537 hThemeFile, unknown);
538 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
541 /**********************************************************************
542 * CloseThemeFile (UXTHEME.3)
544 * Releases theme file handle returned by OpenThemeFile
546 * PARAMS
547 * hThemeFile Handle to theme file
549 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
551 TRACE("(%p)\n", hThemeFile);
552 MSSTYLES_CloseThemeFile(hThemeFile);
553 return S_OK;
556 /**********************************************************************
557 * ApplyTheme (UXTHEME.4)
559 * Set a theme file to be the currently active theme
561 * PARAMS
562 * hThemeFile Handle to theme file
563 * unknown See notes
564 * hWnd Window requesting the theme change
566 * NOTES
567 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
568 * Under XP if I pass
569 * char b[] = "";
570 * the theme is applied with the screen redrawing really badly (flickers)
571 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
572 * the theme is applied smoothly (screen does not flicker)
573 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
574 * the function fails returning invalid parameter...very strange
576 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
578 HRESULT hr;
579 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
580 hr = UXTHEME_SetActiveTheme(hThemeFile);
581 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
582 return hr;
585 /**********************************************************************
586 * GetThemeDefaults (UXTHEME.7)
588 * Get the default color & size for a theme
590 * PARAMS
591 * pszThemeFileName Path to a msstyles theme file
592 * pszColorName Buffer to receive the default color name
593 * dwColorNameLen Length, in characters, of color name buffer
594 * pszSizeName Buffer to receive the default size name
595 * dwSizeNameLen Length, in characters, of size name buffer
597 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
598 DWORD dwColorNameLen, LPWSTR pszSizeName,
599 DWORD dwSizeNameLen)
601 PTHEME_FILE pt;
602 HRESULT hr;
603 TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName),
604 pszColorName, dwColorNameLen,
605 pszSizeName, dwSizeNameLen);
607 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
608 if(FAILED(hr)) return hr;
610 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
611 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
613 MSSTYLES_CloseThemeFile(pt);
614 return S_OK;
617 /**********************************************************************
618 * EnumThemes (UXTHEME.8)
620 * Enumerate available themes, calls specified EnumThemeProc for each
621 * theme found. Passes lpData through to callback function.
623 * PARAMS
624 * pszThemePath Path containing themes
625 * callback Called for each theme found in path
626 * lpData Passed through to callback
628 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
629 LPVOID lpData)
631 WCHAR szDir[MAX_PATH];
632 WCHAR szPath[MAX_PATH];
633 static const WCHAR szStar[] = {'*','.','*','\0'};
634 static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
635 static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
636 static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
637 WCHAR szName[60];
638 WCHAR szTip[60];
639 HANDLE hFind;
640 WIN32_FIND_DATAW wfd;
641 HRESULT hr;
643 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
645 if(!pszThemePath || !callback)
646 return E_POINTER;
648 lstrcpyW(szDir, pszThemePath);
649 PathAddBackslashW(szDir);
651 lstrcpyW(szPath, szDir);
652 lstrcatW(szPath, szStar);
653 TRACE("searching %s\n", debugstr_w(szPath));
655 hFind = FindFirstFileW(szPath, &wfd);
656 if(hFind != INVALID_HANDLE_VALUE) {
657 do {
658 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
659 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
660 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
662 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
663 if(SUCCEEDED(hr))
664 hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
665 if(SUCCEEDED(hr)) {
666 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
667 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
668 TRACE("callback ended enum\n");
669 break;
673 } while(FindNextFileW(hFind, &wfd));
674 FindClose(hFind);
676 return S_OK;
680 /**********************************************************************
681 * EnumThemeColors (UXTHEME.9)
683 * Enumerate theme colors available with a particular size
685 * PARAMS
686 * pszThemeFileName Path to a msstyles theme file
687 * pszSizeName Theme size to enumerate available colors
688 * If NULL the default theme size is used
689 * dwColorNum Color index to retrieve, increment from 0
690 * pszColorName Output color name
692 * RETURNS
693 * S_OK on success
694 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
695 * or when pszSizeName does not refer to a valid size
697 * NOTES
698 * XP fails with E_POINTER when pszColorName points to a buffer smaller then 605
699 * characters
701 * Not very efficient that I'm opening & validating the theme every call, but
702 * this is undocumented and almost never called..
703 * (and this is how windows works too)
705 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
706 DWORD dwColorNum, LPWSTR pszColorName)
708 PTHEME_FILE pt;
709 HRESULT hr;
710 LPWSTR tmp;
711 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
712 debugstr_w(pszSizeName), dwColorNum);
714 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
715 if(FAILED(hr)) return hr;
717 tmp = pt->pszAvailColors;
718 while(dwColorNum && *tmp) {
719 dwColorNum--;
720 tmp += lstrlenW(tmp)+1;
722 if(!dwColorNum && *tmp) {
723 TRACE("%s\n", debugstr_w(tmp));
724 lstrcpyW(pszColorName, tmp);
726 else
727 hr = E_PROP_ID_UNSUPPORTED;
729 MSSTYLES_CloseThemeFile(pt);
730 return hr;
733 /**********************************************************************
734 * EnumThemeSizes (UXTHEME.10)
736 * Enumerate theme colors available with a particular size
738 * PARAMS
739 * pszThemeFileName Path to a msstyles theme file
740 * pszColorName Theme color to enumerate available sizes
741 * If NULL the default theme color is used
742 * dwSizeNum Size index to retrieve, increment from 0
743 * pszSizeName Output size name
745 * RETURNS
746 * S_OK on success
747 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
748 * or when pszColorName does not refer to a valid color
750 * NOTES
751 * XP fails with E_POINTER when pszSizeName points to a buffer smaller then 605
752 * characters
754 * Not very efficient that I'm opening & validating the theme every call, but
755 * this is undocumented and almost never called..
756 * (and this is how windows works too)
758 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
759 DWORD dwSizeNum, LPWSTR pszSizeName)
761 PTHEME_FILE pt;
762 HRESULT hr;
763 LPWSTR tmp;
764 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
765 debugstr_w(pszColorName), dwSizeNum);
767 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
768 if(FAILED(hr)) return hr;
770 tmp = pt->pszAvailSizes;
771 while(dwSizeNum && *tmp) {
772 dwSizeNum--;
773 tmp += lstrlenW(tmp)+1;
775 if(!dwSizeNum && *tmp) {
776 TRACE("%s\n", debugstr_w(tmp));
777 lstrcpyW(pszSizeName, tmp);
779 else
780 hr = E_PROP_ID_UNSUPPORTED;
782 MSSTYLES_CloseThemeFile(pt);
783 return hr;
786 /**********************************************************************
787 * ParseThemeIniFile (UXTHEME.11)
789 * Enumerate data in a theme INI file.
791 * PARAMS
792 * pszIniFileName Path to a theme ini file
793 * pszUnknown Cannot be NULL, L"" is valid
794 * callback Called for each found entry
795 * lpData Passed through to callback
797 * RETURNS
798 * S_OK on success
799 * 0x800706488 (Unknown property) when enumeration is canceled from callback
801 * NOTES
802 * When pszUnknown is NULL the callback is never called, the value does not seem to surve
803 * any other purpose
805 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
806 ParseThemeIniFileProc callback, LPVOID lpData)
808 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
809 return ERROR_CALL_NOT_IMPLEMENTED;
812 /**********************************************************************
813 * CheckThemeSignature (UXTHEME.29)
815 * Validates the signature of a theme file
817 * PARAMS
818 * pszIniFileName Path to a theme file
820 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
822 PTHEME_FILE pt;
823 HRESULT hr;
824 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
825 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
826 if(FAILED(hr))
827 return hr;
828 MSSTYLES_CloseThemeFile(pt);
829 return S_OK;