2 * Win32 5.1 msstyles theme format
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
28 #define NO_SHLWAPI_REG
35 #include "uxthemedll.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
42 /***********************************************************************
43 * Defines and global variables
46 BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
);
47 BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
);
49 extern HINSTANCE hDllInst
;
51 #define MSSTYLES_VERSION 0x0003
53 static const WCHAR szThemesIniResource
[] = {
54 't','h','e','m','e','s','_','i','n','i','\0'
57 PTHEME_FILE tfActiveTheme
= NULL
;
59 /***********************************************************************/
61 /**********************************************************************
62 * MSSTYLES_OpenThemeFile
64 * Load and validate a theme
67 * lpThemeFile Path to theme file to load
68 * pszColorName Color name wanted, can be NULL
69 * pszSizeName Size name wanted, can be NULL
72 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
73 * If one/both are provided, they are validated against valid color/sizes and if
74 * a match is not found, the function fails.
76 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
81 static const WCHAR szPackThemVersionResource
[] = {
82 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
84 static const WCHAR szColorNamesResource
[] = {
85 'C','O','L','O','R','N','A','M','E','S','\0'
87 static const WCHAR szSizeNamesResource
[] = {
88 'S','I','Z','E','N','A','M','E','S','\0'
94 LPWSTR pszSelectedColor
= NULL
;
96 LPWSTR pszSelectedSize
= NULL
;
99 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
101 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
103 /* Validate that this is really a theme */
105 hr
= HRESULT_FROM_WIN32(GetLastError());
108 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szPackThemVersionResource
))) {
109 TRACE("No version resource found\n");
110 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
113 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
115 TRACE("Version resource found, but wrong size: %ld\n", versize
);
116 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
119 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
120 if(version
!= MSSTYLES_VERSION
)
122 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
123 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
127 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szColorNamesResource
))) {
128 TRACE("Color names resource not found\n");
129 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
132 pszColors
= (LPWSTR
)LoadResource(hTheme
, hrsc
);
134 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szSizeNamesResource
))) {
135 TRACE("Size names resource not found\n");
136 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
139 pszSizes
= (LPWSTR
)LoadResource(hTheme
, hrsc
);
141 /* Validate requested color against whats available from the theme */
145 if(!lstrcmpiW(pszColorName
, tmp
)) {
146 pszSelectedColor
= tmp
;
149 tmp
+= lstrlenW(tmp
)+1;
153 pszSelectedColor
= pszColors
; /* Use the default color */
155 /* Validate requested size against whats available from the theme */
159 if(!lstrcmpiW(pszSizeName
, tmp
)) {
160 pszSelectedSize
= tmp
;
163 tmp
+= lstrlenW(tmp
)+1;
167 pszSelectedSize
= pszSizes
; /* Use the default size */
169 if(!pszSelectedColor
|| !pszSelectedSize
) {
170 TRACE("Requested color/size (%s/%s) not found in theme\n",
171 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
172 hr
= E_PROP_ID_UNSUPPORTED
;
176 *tf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(THEME_FILE
));
177 (*tf
)->hTheme
= hTheme
;
179 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
181 (*tf
)->pszAvailColors
= pszColors
;
182 (*tf
)->pszAvailSizes
= pszSizes
;
183 (*tf
)->pszSelectedColor
= pszSelectedColor
;
184 (*tf
)->pszSelectedSize
= pszSelectedSize
;
185 (*tf
)->dwRefCount
= 1;
189 if(hTheme
) FreeLibrary(hTheme
);
193 /***********************************************************************
194 * MSSTYLES_CloseThemeFile
196 * Close theme file and free resources
198 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
202 if(!tf
->dwRefCount
) {
203 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
206 PTHEME_CLASS pcls
= tf
->classes
;
207 tf
->classes
= pcls
->next
;
208 while(pcls
->partstate
) {
209 PTHEME_PARTSTATE ps
= pcls
->partstate
;
210 pcls
->partstate
= ps
->next
;
211 HeapFree(GetProcessHeap(), 0, ps
);
213 HeapFree(GetProcessHeap(), 0, pcls
);
216 HeapFree(GetProcessHeap(), 0, tf
);
221 /***********************************************************************
222 * MSSTYLES_SetActiveTheme
224 * Set the current active theme
226 HRESULT
MSSTYLES_SetActiveTheme(PTHEME_FILE tf
)
229 MSSTYLES_CloseThemeFile(tfActiveTheme
);
232 tfActiveTheme
->dwRefCount
++;
236 /***********************************************************************
237 * MSSTYLES_GetThemeIni
239 * Retrieves themes.ini from a theme
241 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
243 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
246 /***********************************************************************
247 * MSSTYLES_GetActiveThemeIni
249 * Retrieve the ini file for the selected color/style
251 PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
253 static const WCHAR szFileResNamesResource
[] = {
254 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
256 DWORD dwColorCount
= 0;
257 DWORD dwSizeCount
= 0;
258 DWORD dwColorNum
= 0;
261 DWORD dwResourceIndex
;
265 /* Count the number of available colors & styles, and determine the index number
266 of the color/style we are interested in
268 tmp
= tf
->pszAvailColors
;
270 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
271 dwColorNum
= dwColorCount
;
272 tmp
+= lstrlenW(tmp
)+1;
275 tmp
= tf
->pszAvailSizes
;
277 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
278 dwSizeNum
= dwSizeCount
;
279 tmp
+= lstrlenW(tmp
)+1;
283 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
284 TRACE("FILERESNAMES map not found\n");
287 tmp
= (LPWSTR
)LoadResource(tf
->hTheme
, hrsc
);
288 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
289 for(i
=0; i
< dwResourceIndex
; i
++) {
290 tmp
+= lstrlenW(tmp
)+1;
292 return UXINI_LoadINI(tf
->hTheme
, tmp
);
296 /***********************************************************************
297 * MSSTYLES_ParseIniSectionName
299 * Parse an ini section name into its component parts
304 * [classname.part(state)]
305 * [application::classname]
306 * [application::classname(state)]
307 * [application::classname.part]
308 * [application::classname.part(state)]
311 * lpSection Section name
312 * dwLen Length of section name
313 * szAppName Location to store application name
314 * szClassName Location to store class name
315 * iPartId Location to store part id
316 * iStateId Location to store state id
318 BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
321 WCHAR part
[60] = {'\0'};
322 WCHAR state
[60] = {'\0'};
325 lstrcpynW(sec
, lpSection
, min(dwLen
+1, sizeof(sec
)/sizeof(sec
[0])));
332 /* Get the application name */
333 tmp
= StrChrW(comp
, ':');
337 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
341 tmp
= StrChrW(comp
, '.');
344 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
346 /* now get the part & state */
347 tmp
= StrChrW(comp
, '(');
350 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
352 /* now get the state */
353 *StrChrW(comp
, ')') = 0;
354 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
357 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
361 tmp
= StrChrW(comp
, '(');
364 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
366 /* now get the state */
367 *StrChrW(comp
, ')') = 0;
368 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
371 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
374 if(!*szClassName
) return FALSE
;
375 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
378 /***********************************************************************
385 * pszAppName App name to find
386 * pszClassName Class name to find
389 * The class found, or NULL
391 PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
393 PTHEME_CLASS cur
= tf
->classes
;
396 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
400 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
408 /***********************************************************************
411 * Add a class to a theme file
415 * pszAppName App name to add
416 * pszClassName Class name to add
419 * The class added, or a class previously added with the same name
421 PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
423 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
426 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS
));
427 cur
->hTheme
= tf
->hTheme
;
428 lstrcpyW(cur
->szAppName
, pszAppName
);
429 lstrcpyW(cur
->szClassName
, pszClassName
);
430 cur
->next
= tf
->classes
;
431 cur
->partstate
= NULL
;
432 cur
->overrides
= NULL
;
437 /***********************************************************************
438 * MSSTYLES_FindPartState
444 * iPartId Part ID to find
445 * iStateId State ID to find
446 * tcNext Receives the next class in the override chain
449 * The part/state found, or NULL
451 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
453 PTHEME_PARTSTATE cur
= tc
->partstate
;
455 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
456 if(tcNext
) *tcNext
= tc
->overrides
;
461 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
465 /***********************************************************************
466 * MSSTYLES_AddPartState
468 * Add a part/state to a class
472 * iPartId Part ID to add
473 * iStateId State ID to add
476 * The part/state added, or a part/state previously added with the same IDs
478 PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
480 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
483 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE
));
484 cur
->iPartId
= iPartId
;
485 cur
->iStateId
= iStateId
;
486 cur
->properties
= NULL
;
487 cur
->next
= tc
->partstate
;
492 /***********************************************************************
493 * MSSTYLES_LFindProperty
495 * Find a property within a property list
498 * tp property list to scan
499 * iPropertyPrimitive Type of value expected
500 * iPropertyId ID of the required value
503 * The property found, or NULL
505 PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
507 PTHEME_PROPERTY cur
= tp
;
509 if(cur
->iPropertyId
== iPropertyId
) {
510 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
514 if(!iPropertyPrimitive
)
524 /***********************************************************************
525 * MSSTYLES_PSFindProperty
527 * Find a value within a part/state
530 * ps Part/state to search
531 * iPropertyPrimitive Type of value expected
532 * iPropertyId ID of the required value
535 * The property found, or NULL
537 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
539 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
542 /***********************************************************************
543 * MSSTYLES_FFindMetric
545 * Find a metric property for a theme file
549 * iPropertyPrimitive Type of value expected
550 * iPropertyId ID of the required value
553 * The property found, or NULL
555 static inline PTHEME_PROPERTY
MSSTYLES_FFindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
557 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
560 /***********************************************************************
561 * MSSTYLES_FindMetric
563 * Find a metric property for the current installed theme
567 * iPropertyPrimitive Type of value expected
568 * iPropertyId ID of the required value
571 * The property found, or NULL
573 PTHEME_PROPERTY
MSSTYLES_FindMetric(int iPropertyPrimitive
, int iPropertyId
)
575 if(!tfActiveTheme
) return NULL
;
576 return MSSTYLES_FFindMetric(tfActiveTheme
, iPropertyPrimitive
, iPropertyId
);
579 /***********************************************************************
580 * MSSTYLES_AddProperty
582 * Add a property to a part/state
586 * iPropertyPrimitive Primitive type of the property
587 * iPropertyId ID of the property
588 * lpValue Raw value (non-NULL terminated)
589 * dwValueLen Length of the value
592 * The property added, or a property previously added with the same IDs
594 PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
596 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
597 /* Should duplicate properties overwrite the original, or be ignored? */
600 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
601 cur
->iPrimitiveType
= iPropertyPrimitive
;
602 cur
->iPropertyId
= iPropertyId
;
603 cur
->lpValue
= lpValue
;
604 cur
->dwValueLen
= dwValueLen
;
607 cur
->origin
= PO_STATE
;
609 cur
->origin
= PO_PART
;
611 cur
->origin
= PO_GLOBAL
;
613 cur
->origin
= PO_CLASS
;
615 cur
->next
= ps
->properties
;
616 ps
->properties
= cur
;
620 /***********************************************************************
623 * Add a property to a part/state
627 * iPropertyPrimitive Primitive type of the property
628 * iPropertyId ID of the property
629 * lpValue Raw value (non-NULL terminated)
630 * dwValueLen Length of the value
633 * The property added, or a property previously added with the same IDs
635 PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
637 PTHEME_PROPERTY cur
= MSSTYLES_FFindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
638 /* Should duplicate properties overwrite the original, or be ignored? */
641 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
642 cur
->iPrimitiveType
= iPropertyPrimitive
;
643 cur
->iPropertyId
= iPropertyId
;
644 cur
->lpValue
= lpValue
;
645 cur
->dwValueLen
= dwValueLen
;
647 cur
->origin
= PO_GLOBAL
;
649 cur
->next
= tf
->metrics
;
654 /***********************************************************************
655 * MSSTYLES_ParseThemeIni
657 * Parse the theme ini for the selected color/style
662 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
)
664 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
665 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
667 PTHEME_CLASS globals
;
670 WCHAR szAppName
[MAX_THEME_APP_NAME
];
671 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
672 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
675 int iPropertyPrimitive
;
682 ini
= MSSTYLES_GetActiveThemeIni(tf
);
684 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
))) {
685 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
) {
687 int colorElements
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
];
688 COLORREF colorRgb
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
];
691 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
692 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
693 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
694 if(iPropertyId
>= TMT_FIRSTCOLOR
&& iPropertyId
<= TMT_LASTCOLOR
) {
696 lpValueEnd
= lpValue
+ dwValueLen
;
697 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &r
);
698 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &g
);
699 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &b
)) {
700 colorElements
[colorCount
] = iPropertyId
- TMT_FIRSTCOLOR
;
701 colorRgb
[colorCount
++] = RGB(r
,g
,b
);
704 FIXME("Invalid color value for %s\n", debugstr_w(szPropertyName
));
707 /* Catch all metrics, including colors */
708 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
711 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
715 SetSysColors(colorCount
, colorElements
, colorRgb
);
718 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
)) {
719 BOOL isGlobal
= FALSE
;
720 if(!lstrcmpiW(szClassName
, szGlobals
)) {
723 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
724 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
726 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
727 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
728 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
729 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
732 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
738 /* App/Class combos override values defined by the base class, map these overrides */
739 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
742 if(*cls
->szAppName
) {
743 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
744 if(!cls
->overrides
) {
745 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
748 cls
->overrides
= globals
;
752 /* Everything overrides globals..except globals */
753 if(cls
!= globals
) cls
->overrides
= globals
;
760 ERR("Failed to parse theme ini\n");
764 /***********************************************************************
765 * MSSTYLES_OpenThemeClass
767 * Open a theme class, uses the current active theme
770 * pszAppName Application name, for theme styles specific
771 * to a particular application
772 * pszClassList List of requested classes, semicolon delimited
774 PTHEME_CLASS
MSSTYLES_OpenThemeClass(LPCWSTR pszAppName
, LPCWSTR pszClassList
)
776 PTHEME_CLASS cls
= NULL
;
777 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
783 TRACE("there is no active theme\n");
786 if(!tfActiveTheme
->classes
) {
787 MSSTYLES_ParseThemeIni(tfActiveTheme
);
788 if(!tfActiveTheme
->classes
)
792 start
= pszClassList
;
793 while((end
= StrChrW(start
, ';'))) {
795 lstrcpynW(szClassName
, start
, min(len
+1, sizeof(szClassName
)/sizeof(szClassName
[0])));
797 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
801 lstrcpynW(szClassName
, start
, sizeof(szClassName
)/sizeof(szClassName
[0]));
802 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
805 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
810 /***********************************************************************
811 * MSSTYLES_CloseThemeClass
813 * Close a theme class
816 * tc Theme class to close
819 * There is currently no need clean anything up for theme classes,
820 * so do nothing for now
822 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
827 /***********************************************************************
828 * MSSTYLES_FindProperty
830 * Locate a property in a class. Part and state IDs will be used as a
831 * preference, but may be ignored in the attempt to locate the property.
832 * Will scan the entire chain of overrides for this class.
834 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
836 PTHEME_CLASS next
= tc
;
840 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
841 /* Try and find an exact match on part & state */
842 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
843 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
847 /* If that fails, and we didn't already try it, search for just part */
850 /* As a last ditch attempt..go for just class */
851 else if(iPartId
!= 0)
856 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
861 HBITMAP
MSSTYLES_LoadBitmap(HDC hdc
, PTHEME_CLASS tc
, LPCWSTR lpFilename
)
863 WCHAR szFile
[MAX_PATH
];
865 lstrcpynW(szFile
, lpFilename
, sizeof(szFile
)/sizeof(szFile
[0]));
868 if(*tmp
== '\\') *tmp
= '_';
869 if(*tmp
== '/') *tmp
= '_';
870 if(*tmp
== '.') *tmp
= '_';
872 return LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_SHARED
|LR_CREATEDIBSECTION
);
875 BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
877 LPCWSTR cur
= lpStringStart
;
881 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
882 if(cur
>= lpStringEnd
) {
889 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
890 total
= total
* 10 + (*cur
- '0');
893 if(gotNeg
) total
= -total
;
895 if(lpValEnd
) *lpValEnd
= cur
;
899 BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
900 LPCWSTR cur
= lpStringStart
;
904 while(cur
< lpStringEnd
&& (isspace(*cur
) || *cur
== ',')) cur
++;
905 if(cur
>= lpStringEnd
) {
909 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
911 while(isspace(*end
)) end
--;
913 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
915 if(lpValEnd
) *lpValEnd
= cur
;
919 /***********************************************************************
920 * MSSTYLES_GetPropertyBool
922 * Retrieve a color value for a property
924 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
927 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
932 /***********************************************************************
933 * MSSTYLES_GetPropertyColor
935 * Retrieve a color value for a property
937 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
941 int red
, green
, blue
;
944 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
946 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
);
947 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
);
948 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
949 TRACE("Could not parse color property\n");
950 return E_PROP_ID_UNSUPPORTED
;
952 *pColor
= RGB(red
,green
,blue
);
956 /***********************************************************************
957 * MSSTYLES_GetPropertyColor
959 * Retrieve a color value for a property
961 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
963 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
964 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
965 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
966 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
969 LPCWSTR lpCur
= tp
->lpValue
;
970 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
972 ZeroMemory(pFont
, sizeof(LOGFONTW
));
974 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
975 TRACE("Property is there, but failed to get face name\n");
976 return E_PROP_ID_UNSUPPORTED
;
978 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
979 TRACE("Property is there, but failed to get point size\n");
980 return E_PROP_ID_UNSUPPORTED
;
982 pFont
->lfHeight
= -MulDiv(pointSize
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
983 pFont
->lfWeight
= FW_REGULAR
;
984 pFont
->lfCharSet
= DEFAULT_CHARSET
;
985 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, sizeof(attr
)/sizeof(attr
[0]))) {
986 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
987 else if(!!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
988 else if(!!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
989 else if(!!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
994 /***********************************************************************
995 * MSSTYLES_GetPropertyInt
997 * Retrieve an int value for a property
999 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1001 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1002 TRACE("Could not parse int property\n");
1003 return E_PROP_ID_UNSUPPORTED
;
1008 /***********************************************************************
1009 * MSSTYLES_GetPropertyIntList
1011 * Retrieve an int list value for a property
1013 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1016 LPCWSTR lpCur
= tp
->lpValue
;
1017 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1019 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1020 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1023 pIntList
->iValueCount
= i
;
1027 /***********************************************************************
1028 * MSSTYLES_GetPropertyPosition
1030 * Retrieve a position value for a property
1032 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1035 LPCWSTR lpCur
= tp
->lpValue
;
1036 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1038 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
);
1039 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1040 TRACE("Could not parse position property\n");
1041 return E_PROP_ID_UNSUPPORTED
;
1048 /***********************************************************************
1049 * MSSTYLES_GetPropertyString
1051 * Retrieve a string value for a property
1053 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1055 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1059 /***********************************************************************
1060 * MSSTYLES_GetPropertyRect
1062 * Retrieve a rect value for a property
1064 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1066 LPCWSTR lpCur
= tp
->lpValue
;
1067 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1069 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&pRect
->left
);
1070 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&pRect
->top
);
1071 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&pRect
->right
);
1072 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&pRect
->bottom
)) {
1073 TRACE("Could not parse rect property\n");
1074 return E_PROP_ID_UNSUPPORTED
;
1079 /***********************************************************************
1080 * MSSTYLES_GetPropertyMargins
1082 * Retrieve a margins value for a property
1084 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1086 LPCWSTR lpCur
= tp
->lpValue
;
1087 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1089 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1090 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1091 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1092 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1093 TRACE("Could not parse margins property\n");
1094 return E_PROP_ID_UNSUPPORTED
;