- define additional shell paths for CSIDL_... constants
[wine] / dlls / uxtheme / msstyles.c
1 /*
2  * Win32 5.1 msstyles theme format
3  *
4  * Copyright (C) 2003 Kevin Koltzau
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #define NO_SHLWAPI_REG
29 #include "shlwapi.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "uxtheme.h"
33 #include "tmschema.h"
34
35 #include "uxthemedll.h"
36 #include "msstyles.h"
37
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
41
42 /***********************************************************************
43  * Defines and global variables
44  */
45
46 extern HINSTANCE hDllInst;
47
48 #define MSSTYLES_VERSION 0x0003
49
50 static const WCHAR szThemesIniResource[] = {
51     't','h','e','m','e','s','_','i','n','i','\0'
52 };
53
54 PTHEME_FILE tfActiveTheme = NULL;
55
56 /***********************************************************************/
57
58 /**********************************************************************
59  *      MSSTYLES_OpenThemeFile
60  *
61  * Load and validate a theme
62  *
63  * PARAMS
64  *     lpThemeFile         Path to theme file to load
65  *     pszColorName        Color name wanted, can be NULL
66  *     pszSizeName         Size name wanted, can be NULL
67  *
68  * NOTES
69  * If pszColorName or pszSizeName are NULL, the default color/size will be used.
70  * If one/both are provided, they are validated against valid color/sizes and if
71  * a match is not found, the function fails.
72  */
73 HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWSTR pszSizeName, PTHEME_FILE *tf)
74 {
75     HMODULE hTheme;
76     HRSRC hrsc;
77     HRESULT hr = S_OK;
78     WCHAR szPackThemVersionResource[] = {
79         'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
80     };
81     WCHAR szColorNamesResource[] = {
82         'C','O','L','O','R','N','A','M','E','S','\0'
83     };
84     WCHAR szSizeNamesResource[] = {
85         'S','I','Z','E','N','A','M','E','S','\0'
86     };
87
88     WORD version;
89     DWORD versize;
90     LPWSTR pszColors;
91     LPWSTR pszSelectedColor = NULL;
92     LPWSTR pszSizes;
93     LPWSTR pszSelectedSize = NULL;
94     LPWSTR tmp;
95
96     TRACE("Opening %s\n", debugstr_w(lpThemeFile));
97
98     hTheme = LoadLibraryExW(lpThemeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);
99
100     /* Validate that this is really a theme */
101     if(!hTheme) goto invalid_theme;
102     if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szPackThemVersionResource))) {
103         TRACE("No version resource found\n");
104         goto invalid_theme;
105     }
106     if((versize = SizeofResource(hTheme, hrsc)) != 2)
107     {
108         TRACE("Version resource found, but wrong size: %ld\n", versize);
109         goto invalid_theme;
110     }
111     version = *(WORD*)LoadResource(hTheme, hrsc);
112     if(version != MSSTYLES_VERSION)
113     {
114         TRACE("Version of theme file is unsupported: 0x%04x\n", version);
115         goto invalid_theme;
116     }
117
118     if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szColorNamesResource))) {
119         TRACE("Color names resource not found\n");
120         goto invalid_theme;
121     }
122     pszColors = (LPWSTR)LoadResource(hTheme, hrsc);
123
124     if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szSizeNamesResource))) {
125         TRACE("Size names resource not found\n");
126         goto invalid_theme;
127     }
128     pszSizes = (LPWSTR)LoadResource(hTheme, hrsc);
129
130     /* Validate requested color against whats available from the theme */
131     if(pszColorName) {
132         tmp = pszColors;
133         while(*tmp) {
134             if(!lstrcmpiW(pszColorName, tmp)) {
135                 pszSelectedColor = tmp;
136                 break;
137             }
138             tmp += lstrlenW(tmp)+1;
139         }
140     }
141     else
142         pszSelectedColor = pszColors; /* Use the default color */
143
144     /* Validate requested size against whats available from the theme */
145     if(pszSizeName) {
146         tmp = pszSizes;
147         while(*tmp) {
148             if(!lstrcmpiW(pszSizeName, tmp)) {
149                 pszSelectedSize = tmp;
150                 break;
151             }
152             tmp += lstrlenW(tmp)+1;
153         }
154     }
155     else
156         pszSelectedSize = pszSizes; /* Use the default size */
157
158     if(!pszSelectedColor || !pszSelectedSize) {
159         TRACE("Requested color/size (%s/%s) not found in theme\n",
160               debugstr_w(pszColorName), debugstr_w(pszSizeName));
161         hr = E_PROP_ID_UNSUPPORTED;
162         goto invalid_theme;
163     }
164
165     *tf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(THEME_FILE));
166     (*tf)->hTheme = hTheme;
167     (*tf)->pszAvailColors = pszColors;
168     (*tf)->pszAvailSizes = pszSizes;
169     (*tf)->pszSelectedColor = pszSelectedColor;
170     (*tf)->pszSelectedSize = pszSelectedSize;
171     (*tf)->dwRefCount = 1;
172     return S_OK;
173
174 invalid_theme:
175     if(hTheme) FreeLibrary(hTheme);
176     if(!hr) hr = HRESULT_FROM_WIN32(GetLastError());
177     return hr;
178 }
179
180 /***********************************************************************
181  *      MSSTYLES_CloseThemeFile
182  *
183  * Close theme file and free resources
184  */
185 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
186 {
187     if(tf) {
188         tf->dwRefCount--;
189         if(!tf->dwRefCount) {
190             if(tf->hTheme) FreeLibrary(tf->hTheme);
191             if(tf->classes) {
192                 while(tf->classes) {
193                     PTHEME_CLASS pcls = tf->classes;
194                     tf->classes = pcls->next;
195                     while(pcls->partstate) {
196                         PTHEME_PARTSTATE ps = pcls->partstate;
197                         pcls->partstate = ps->next;
198                         HeapFree(GetProcessHeap(), 0, ps);
199                     }
200                     HeapFree(GetProcessHeap(), 0, pcls);
201                 }
202             }
203             HeapFree(GetProcessHeap(), 0, tf);
204         }
205     }
206 }
207
208 /***********************************************************************
209  *      MSSTYLES_SetActiveTheme
210  *
211  * Set the current active theme
212  */
213 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf)
214 {
215     if(tfActiveTheme)
216         MSSTYLES_CloseThemeFile(tfActiveTheme);
217     tfActiveTheme = tf;
218     tfActiveTheme->dwRefCount++;
219     return S_OK;
220 }
221
222 /***********************************************************************
223  *      MSSTYLES_GetThemeIni
224  *
225  * Retrieves themes.ini from a theme
226  */
227 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf)
228 {
229     return UXINI_LoadINI(tf->hTheme, szThemesIniResource);
230 }
231
232 /***********************************************************************
233  *      MSSTYLES_GetActiveThemeIni
234  *
235  * Retrieve the ini file for the selected color/style
236  */
237 PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf)
238 {
239     WCHAR szFileResNamesResource[] = {
240         'F','I','L','E','R','E','S','N','A','M','E','S','\0'
241     };
242     DWORD dwColorCount = 0;
243     DWORD dwSizeCount = 0;
244     DWORD dwColorNum = 0;
245     DWORD dwSizeNum = 0;
246     DWORD i;
247     DWORD dwResourceIndex;
248     LPWSTR tmp;
249     HRSRC hrsc;
250
251     /* Count the number of available colors & styles, and determine the index number
252        of the color/style we are interested in
253     */
254     tmp = tf->pszAvailColors;
255     while(*tmp) {
256         if(!lstrcmpiW(tf->pszSelectedColor, tmp))
257             dwColorNum = dwColorCount;
258         tmp += lstrlenW(tmp)+1;
259         dwColorCount++;
260     }
261     tmp = tf->pszAvailSizes;
262     while(*tmp) {
263         if(!lstrcmpiW(tf->pszSelectedSize, tmp))
264             dwSizeNum = dwSizeCount;
265         tmp += lstrlenW(tmp)+1;
266         dwSizeCount++;
267     }
268
269     if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
270         TRACE("FILERESNAMES map not found\n");
271         return NULL;
272     }
273     tmp = (LPWSTR)LoadResource(tf->hTheme, hrsc);
274     dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum;
275     for(i=0; i < dwResourceIndex; i++) {
276         tmp += lstrlenW(tmp)+1;
277     }
278     return UXINI_LoadINI(tf->hTheme, tmp);
279 }
280
281
282 /***********************************************************************
283  *      MSSTYLES_ParseIniSectionName
284  *
285  * Parse an ini section name into its component parts
286  * Valid formats are:
287  * [classname]
288  * [classname(state)]
289  * [classname.part]
290  * [classname.part(state)]
291  * [application::classname]
292  * [application::classname(state)]
293  * [application::classname.part]
294  * [application::classname.part(state)]
295  *
296  * PARAMS
297  *     lpSection           Section name
298  *     dwLen               Length of section name
299  *     szAppName           Location to store application name
300  *     szClassName         Location to store class name
301  *     iPartId             Location to store part id
302  *     iStateId            Location to store state id
303  */
304 BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR szAppName, LPWSTR szClassName, int *iPartId, int *iStateId)
305 {
306     WCHAR sec[255];
307     WCHAR part[60] = {'\0'};
308     WCHAR state[60] = {'\0'};
309     LPWSTR tmp;
310     LPWSTR comp;
311     lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
312
313     *szAppName = 0;
314     *szClassName = 0;
315     *iPartId = 0;
316     *iStateId = 0;
317     comp = sec;
318     /* Get the application name */
319     tmp = StrChrW(comp, ':');
320     if(tmp) {
321         *tmp++ = 0;
322         tmp++;
323         lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
324         comp = tmp;
325     }
326
327     tmp = StrChrW(comp, '.');
328     if(tmp) {
329         *tmp++ = 0;
330         lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
331         comp = tmp;
332         /* now get the part & state */
333         tmp = StrChrW(comp, '(');
334         if(tmp) {
335             *tmp++ = 0;
336             lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
337             comp = tmp;
338             /* now get the state */
339             *StrChrW(comp, ')') = 0;
340             lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
341         }
342         else {
343             lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
344         }
345     }
346     else {
347         tmp = StrChrW(comp, '(');
348         if(tmp) {
349             *tmp++ = 0;
350             lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
351             comp = tmp;
352             /* now get the state */
353             *StrChrW(comp, ')') = 0;
354             lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
355         }
356         else {
357             lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
358         }
359     }
360     if(!*szClassName) return FALSE;
361     return MSSTYLES_LookupPartState(szClassName, part[0]?part:NULL, state[0]?state:NULL, iPartId, iStateId);
362 }
363
364 /***********************************************************************
365  *      MSSTYLES_FindClass
366  *
367  * Find a class
368  *
369  * PARAMS
370  *     tf                  Theme file
371  *     pszAppName          App name to find
372  *     pszClassName        Class name to find
373  *
374  * RETURNS
375  *  The class found, or NULL
376  */
377 PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
378 {
379     PTHEME_CLASS cur = tf->classes;
380     while(cur) {
381         if(!pszAppName) {
382             if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
383                 return cur;
384         }
385         else {
386             if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
387                 return cur;
388         }
389         cur = cur->next;
390     }
391     return NULL;
392 }
393
394 /***********************************************************************
395  *      MSSTYLES_AddClass
396  *
397  * Add a class to a theme file
398  *
399  * PARAMS
400  *     tf                  Theme file
401  *     pszAppName          App name to add
402  *     pszClassName        Class name to add
403  *
404  * RETURNS
405  *  The class added, or a class previously added with the same name
406  */
407 PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
408 {
409     PTHEME_CLASS cur = MSSTYLES_FindClass(tf, pszAppName, pszClassName);
410     if(cur) return cur;
411
412     cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS));
413     cur->hTheme = tf->hTheme;
414     lstrcpyW(cur->szAppName, pszAppName);
415     lstrcpyW(cur->szClassName, pszClassName);
416     cur->next = tf->classes;
417     cur->partstate = NULL;
418     cur->overrides = NULL;
419     tf->classes = cur;
420     return cur;
421 }
422
423 /***********************************************************************
424  *      MSSTYLES_FindPartState
425  *
426  * Find a part/state
427  *
428  * PARAMS
429  *     tc                  Class to search
430  *     iPartId             Part ID to find
431  *     iStateId            State ID to find
432  *     tcNext              Receives the next class in the override chain
433  *
434  * RETURNS
435  *  The part/state found, or NULL
436  */
437 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext)
438 {
439     PTHEME_PARTSTATE cur = tc->partstate;
440     while(cur) {
441         if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
442             if(tcNext) *tcNext = tc->overrides;
443             return cur;
444         }
445         cur = cur->next;
446     }
447     if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
448     return NULL;
449 }
450
451 /***********************************************************************
452  *      MSSTYLES_AddPartState
453  *
454  * Add a part/state to a class
455  *
456  * PARAMS
457  *     tc                  Theme class
458  *     iPartId             Part ID to add
459  *     iStateId            State ID to add
460  *
461  * RETURNS
462  *  The part/state added, or a part/state previously added with the same IDs
463  */
464 PTHEME_PARTSTATE MSSTYLES_AddPartState(PTHEME_CLASS tc, int iPartId, int iStateId)
465 {
466     PTHEME_PARTSTATE cur = MSSTYLES_FindPartState(tc, iPartId, iStateId, NULL);
467     if(cur) return cur;
468
469     cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE));
470     cur->iPartId = iPartId;
471     cur->iStateId = iStateId;
472     cur->properties = NULL;
473     cur->next = tc->partstate;
474     tc->partstate = cur;
475     return cur;
476 }
477
478 /***********************************************************************
479  *      MSSTYLES_PSFindProperty
480  *
481  * Find a value within a part/state
482  *
483  * PARAMS
484  *     ps                  Part/state to search
485  *     iPropertyPrimitive  Type of value expected
486  *     iPropertyId         ID of the required value
487  *
488  * RETURNS
489  *  The property found, or NULL
490  */
491 PTHEME_PROPERTY MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId)
492 {
493     PTHEME_PROPERTY cur = ps->properties;
494     while(cur) {
495         if(cur->iPropertyId == iPropertyId) {
496             if(cur->iPrimitiveType == iPropertyPrimitive) {
497                 return cur;
498             }
499             else {
500                 if(!iPropertyPrimitive)
501                     return cur;
502                 return NULL;
503             }
504         }
505         cur = cur->next;
506     }
507     return NULL;
508 }
509
510 /***********************************************************************
511  *      MSSTYLES_AddProperty
512  *
513  * Add a property to a part/state
514  *
515  * PARAMS
516  *     ps                  Part/state
517  *     iPropertyPrimitive  Primitive type of the property
518  *     iPropertyId         ID of the property
519  *     lpValue             Raw value (non-NULL terminated)
520  *     dwValueLen          Length of the value
521  *
522  * RETURNS
523  *  The property added, or a property previously added with the same IDs
524  */
525 PTHEME_PROPERTY MSSTYLES_AddProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen, BOOL isGlobal)
526 {
527     PTHEME_PROPERTY cur = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId);
528     /* Should duplicate properties overwrite the original, or be ignored? */
529     if(cur) return cur;
530
531     cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
532     cur->iPrimitiveType = iPropertyPrimitive;
533     cur->iPropertyId = iPropertyId;
534     cur->lpValue = lpValue;
535     cur->dwValueLen = dwValueLen;
536
537     if(ps->iStateId)
538         cur->origin = PO_STATE;
539     else if(ps->iPartId)
540         cur->origin = PO_PART;
541     else if(isGlobal)
542         cur->origin = PO_GLOBAL;
543     else
544         cur->origin = PO_CLASS;
545
546     cur->next = ps->properties;
547     ps->properties = cur;
548     return cur;
549 }
550
551 /***********************************************************************
552  *      MSSTYLES_ParseThemeIni
553  *
554  * Parse the theme ini for the selected color/style
555  *
556  * PARAMS
557  *     tf                  Theme to parse
558  */
559 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf)
560 {
561     WCHAR szSysMetrics[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
562     WCHAR szGlobals[] = {'g','l','o','b','a','l','s','\0'};
563     PTHEME_CLASS cls;
564     PTHEME_CLASS globals;
565     PTHEME_PARTSTATE ps;
566     PUXINI_FILE ini;
567     WCHAR szAppName[MAX_THEME_APP_NAME];
568     WCHAR szClassName[MAX_THEME_CLASS_NAME];
569     WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
570     int iPartId;
571     int iStateId;
572     int iPropertyPrimitive;
573     int iPropertyId;
574     DWORD dwLen;
575     LPCWSTR lpName;
576     DWORD dwValueLen;
577     LPCWSTR lpValue;
578
579     ini = MSSTYLES_GetActiveThemeIni(tf);
580
581     while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
582         if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, szSysMetrics, -1) == CSTR_EQUAL) {
583             FIXME("Process system metrics\n");
584             continue;
585         }
586         if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
587             BOOL isGlobal = FALSE;
588             if(!lstrcmpiW(szClassName, szGlobals)) {
589                 isGlobal = TRUE;
590             }
591             cls = MSSTYLES_AddClass(tf, szAppName, szClassName);
592             ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
593
594             while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
595                 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
596                 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
597                     MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
598                 }
599                 else {
600                     TRACE("Unknown property %s\n", debugstr_w(szPropertyName));
601                 }
602             }
603         }
604     }
605
606     /* App/Class combos override values defined by the base class, map these overrides */
607     globals = MSSTYLES_FindClass(tf, NULL, szGlobals);
608     cls = tf->classes;
609     while(cls) {
610         if(*cls->szAppName) {
611             cls->overrides = MSSTYLES_FindClass(tf, NULL, cls->szClassName);
612             if(!cls->overrides) {
613                 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName));
614             }
615             else {
616                 cls->overrides = globals;
617             }
618         }
619         else {
620             /* Everything overrides globals..except globals */
621             if(cls != globals) cls->overrides = globals;
622         }
623         cls = cls->next;
624     }
625     UXINI_CloseINI(ini);
626
627     if(!tf->classes) {
628         ERR("Failed to parse theme ini\n");
629     }
630 }
631
632 /***********************************************************************
633  *      MSSTYLES_OpenThemeClass
634  *
635  * Open a theme class, uses the current active theme
636  *
637  * PARAMS
638  *     pszAppName          Application name, for theme styles specific
639  *                         to a particular application
640  *     pszClassList        List of requested classes, semicolon delimited
641  */
642 PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
643 {
644     PTHEME_CLASS cls = NULL;
645     WCHAR szClassName[MAX_THEME_CLASS_NAME];
646     LPCWSTR start;
647     LPCWSTR end;
648     DWORD len;
649
650     if(!tfActiveTheme) {
651         TRACE("there is no active theme\n");
652         return NULL;
653     }
654     if(!tfActiveTheme->classes) {
655         MSSTYLES_ParseThemeIni(tfActiveTheme);
656         if(!tfActiveTheme->classes)
657             return NULL;
658     }
659
660     start = pszClassList;
661     while((end = StrChrW(start, ';'))) {
662         len = end-start;
663         lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
664         start = end+1;
665         cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
666         if(cls) break;
667     }
668     if(!cls && *start) {
669         lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
670         cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
671     }
672     if(cls) {
673         TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList));
674     }
675     return cls;
676 }
677
678 /***********************************************************************
679  *      MSSTYLES_CloseThemeClass
680  *
681  * Close a theme class
682  *
683  * PARAMS
684  *     tc                  Theme class to close
685  *
686  * NOTES
687  *  There is currently no need clean anything up for theme classes,
688  *  so do nothing for now
689  */
690 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc)
691 {
692     return S_OK;
693 }
694
695 /***********************************************************************
696  *      MSSTYLES_FindProperty
697  *
698  * Locate a property in a class. Part and state IDs will be used as a
699  * preference, but may be ignored in the attempt to locate the property.
700  * Will scan the entire chain of overrides for this class.
701  */
702 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId)
703 {
704     PTHEME_CLASS next = tc;
705     PTHEME_PARTSTATE ps;
706     PTHEME_PROPERTY tp;
707
708     TRACE("(%p, %d, %d, %d)\n", tc, iPartId, iStateId, iPropertyId);
709      /* Try and find an exact match on part & state */
710     while(next && (ps = MSSTYLES_FindPartState(next, iPartId, iStateId, &next))) {
711         if((tp = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId))) {
712             return tp;
713         }
714     }
715     /* If that fails, and we didn't already try it, search for just part */
716     if(iStateId != 0)
717         iStateId = 0;
718     /* As a last ditch attempt..go for just class */
719     else if(iPartId != 0)
720         iPartId = 0;
721     else
722         return NULL;
723
724     if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
725         return tp;
726     return NULL;
727 }