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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <wine/unicode.h>
25 /***********************************************************************
26 * Defines and global variables
29 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
);
30 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
);
31 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LOGFONTW
* logfont
);
33 extern HINSTANCE hDllInst
;
34 extern int alphaBlendMode
;
36 #define MSSTYLES_VERSION 0x0003
38 static const WCHAR szThemesIniResource
[] = {
39 't','h','e','m','e','s','_','i','n','i','\0'
42 /***********************************************************************/
44 /**********************************************************************
45 * MSSTYLES_OpenThemeFile
47 * Load and validate a theme
50 * lpThemeFile Path to theme file to load
51 * pszColorName Color name wanted, can be NULL
52 * pszSizeName Size name wanted, can be NULL
55 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
56 * If one/both are provided, they are validated against valid color/sizes and if
57 * a match is not found, the function fails.
59 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
64 static const WCHAR szPackThemVersionResource
[] = {
65 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
67 static const WCHAR szColorNamesResource
[] = {
68 'C','O','L','O','R','N','A','M','E','S','\0'
70 static const WCHAR szSizeNamesResource
[] = {
71 'S','I','Z','E','N','A','M','E','S','\0'
77 LPWSTR pszSelectedColor
= NULL
;
79 LPWSTR pszSelectedSize
= NULL
;
82 if (!gbThemeHooksActive
)
85 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
87 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
89 /* Validate that this is really a theme */
91 hr
= HRESULT_FROM_WIN32(GetLastError());
94 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szPackThemVersionResource
))) {
95 TRACE("No version resource found\n");
96 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
99 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
101 TRACE("Version resource found, but wrong size: %d\n", versize
);
102 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
105 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
106 if(version
!= MSSTYLES_VERSION
)
108 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
109 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
113 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szColorNamesResource
))) {
114 TRACE("Color names resource not found\n");
115 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
118 pszColors
= LoadResource(hTheme
, hrsc
);
120 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szSizeNamesResource
))) {
121 TRACE("Size names resource not found\n");
122 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
125 pszSizes
= LoadResource(hTheme
, hrsc
);
127 /* Validate requested color against what's available from the theme */
131 if(!lstrcmpiW(pszColorName
, tmp
)) {
132 pszSelectedColor
= tmp
;
135 tmp
+= lstrlenW(tmp
)+1;
139 pszSelectedColor
= pszColors
; /* Use the default color */
141 /* Validate requested size against what's available from the theme */
145 if(!lstrcmpiW(pszSizeName
, tmp
)) {
146 pszSelectedSize
= tmp
;
149 tmp
+= lstrlenW(tmp
)+1;
153 pszSelectedSize
= pszSizes
; /* Use the default size */
155 if(!pszSelectedColor
|| !pszSelectedSize
) {
156 TRACE("Requested color/size (%s/%s) not found in theme\n",
157 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
158 hr
= E_PROP_ID_UNSUPPORTED
;
162 *tf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(THEME_FILE
));
163 (*tf
)->hTheme
= hTheme
;
165 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
167 (*tf
)->pszAvailColors
= pszColors
;
168 (*tf
)->pszAvailSizes
= pszSizes
;
169 (*tf
)->pszSelectedColor
= pszSelectedColor
;
170 (*tf
)->pszSelectedSize
= pszSelectedSize
;
171 (*tf
)->dwRefCount
= 1;
173 TRACE("Theme %p refcount: %d\n", *tf
, (*tf
)->dwRefCount
);
178 if(hTheme
) FreeLibrary(hTheme
);
182 /***********************************************************************
183 * MSSTYLES_CloseThemeFile
185 * Close theme file and free resources
187 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
192 TRACE("Theme %p refcount: %d\n", tf
, tf
->dwRefCount
);
194 if(!tf
->dwRefCount
) {
195 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
198 PTHEME_CLASS pcls
= tf
->classes
;
199 tf
->classes
= pcls
->next
;
200 while(pcls
->partstate
) {
201 PTHEME_PARTSTATE ps
= pcls
->partstate
;
202 pcls
->partstate
= ps
->next
;
203 HeapFree(GetProcessHeap(), 0, ps
);
205 HeapFree(GetProcessHeap(), 0, pcls
);
210 PTHEME_IMAGE img
= tf
->images
;
211 tf
->images
= img
->next
;
212 DeleteObject (img
->image
);
213 HeapFree (GetProcessHeap(), 0, img
);
215 HeapFree(GetProcessHeap(), 0, tf
);
220 /***********************************************************************
221 * MSSTYLES_ReferenceTheme
223 * Increase the reference count of the theme file
225 HRESULT
MSSTYLES_ReferenceTheme(PTHEME_FILE tf
)
228 TRACE("Theme %p refcount: %d\n", tf
, tf
->dwRefCount
);
232 /***********************************************************************
233 * MSSTYLES_GetThemeIni
235 * Retrieves themes.ini from a theme
237 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
239 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
242 /***********************************************************************
243 * MSSTYLES_GetActiveThemeIni
245 * Retrieve the ini file for the selected color/style
247 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
249 static const WCHAR szFileResNamesResource
[] = {
250 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
252 DWORD dwColorCount
= 0;
253 DWORD dwSizeCount
= 0;
254 DWORD dwColorNum
= 0;
257 DWORD dwResourceIndex
;
261 /* Count the number of available colors & styles, and determine the index number
262 of the color/style we are interested in
264 tmp
= tf
->pszAvailColors
;
266 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
267 dwColorNum
= dwColorCount
;
268 tmp
+= lstrlenW(tmp
)+1;
271 tmp
= tf
->pszAvailSizes
;
273 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
274 dwSizeNum
= dwSizeCount
;
275 tmp
+= lstrlenW(tmp
)+1;
279 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
280 TRACE("FILERESNAMES map not found\n");
283 tmp
= LoadResource(tf
->hTheme
, hrsc
);
284 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
285 for(i
=0; i
< dwResourceIndex
; i
++) {
286 tmp
+= lstrlenW(tmp
)+1;
288 return UXINI_LoadINI(tf
->hTheme
, tmp
);
292 /***********************************************************************
293 * MSSTYLES_ParseIniSectionName
295 * Parse an ini section name into its component parts
300 * [classname.part(state)]
301 * [application::classname]
302 * [application::classname(state)]
303 * [application::classname.part]
304 * [application::classname.part(state)]
307 * lpSection Section name
308 * dwLen Length of section name
309 * szAppName Location to store application name
310 * szClassName Location to store class name
311 * iPartId Location to store part id
312 * iStateId Location to store state id
314 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
317 WCHAR part
[60] = {'\0'};
318 WCHAR state
[60] = {'\0'};
321 lstrcpynW(sec
, lpSection
, min(dwLen
+1, sizeof(sec
)/sizeof(sec
[0])));
328 /* Get the application name */
329 tmp
= strchrW(comp
, ':');
333 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
337 tmp
= strchrW(comp
, '.');
340 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
342 /* now get the part & state */
343 tmp
= strchrW(comp
, '(');
346 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
348 /* now get the state */
349 tmp
= strchrW(comp
, ')');
353 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
356 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
360 tmp
= strchrW(comp
, '(');
363 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
365 /* now get the state */
366 tmp
= strchrW(comp
, ')');
370 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
373 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
376 if(!*szClassName
) return FALSE
;
377 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
380 /***********************************************************************
387 * pszAppName App name to find
388 * pszClassName Class name to find
391 * The class found, or NULL
393 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
395 PTHEME_CLASS cur
= tf
->classes
;
398 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
402 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
410 /***********************************************************************
413 * Add a class to a theme file
417 * pszAppName App name to add
418 * pszClassName Class name to add
421 * The class added, or a class previously added with the same name
423 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
425 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
428 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS
));
429 cur
->hTheme
= tf
->hTheme
;
430 lstrcpyW(cur
->szAppName
, pszAppName
);
431 lstrcpyW(cur
->szClassName
, pszClassName
);
432 cur
->next
= tf
->classes
;
433 cur
->partstate
= NULL
;
434 cur
->overrides
= NULL
;
439 /***********************************************************************
440 * MSSTYLES_FindPartState
446 * iPartId Part ID to find
447 * iStateId State ID to find
448 * tcNext Receives the next class in the override chain
451 * The part/state found, or NULL
453 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
455 PTHEME_PARTSTATE cur
= tc
->partstate
;
457 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
458 if(tcNext
) *tcNext
= tc
->overrides
;
463 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
467 /***********************************************************************
468 * MSSTYLES_AddPartState
470 * Add a part/state to a class
474 * iPartId Part ID to add
475 * iStateId State ID to add
478 * The part/state added, or a part/state previously added with the same IDs
480 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
482 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
485 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE
));
486 cur
->iPartId
= iPartId
;
487 cur
->iStateId
= iStateId
;
488 cur
->properties
= NULL
;
489 cur
->next
= tc
->partstate
;
494 /***********************************************************************
495 * MSSTYLES_LFindProperty
497 * Find a property within a property list
500 * tp property list to scan
501 * iPropertyPrimitive Type of value expected
502 * iPropertyId ID of the required value
505 * The property found, or NULL
507 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
509 PTHEME_PROPERTY cur
= tp
;
511 if(cur
->iPropertyId
== iPropertyId
) {
512 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
516 if(!iPropertyPrimitive
)
526 /***********************************************************************
527 * MSSTYLES_PSFindProperty
529 * Find a value within a part/state
532 * ps Part/state to search
533 * iPropertyPrimitive Type of value expected
534 * iPropertyId ID of the required value
537 * The property found, or NULL
539 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
541 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
544 /***********************************************************************
545 * MSSTYLES_FindMetric
547 * Find a metric property for a theme file
551 * iPropertyPrimitive Type of value expected
552 * iPropertyId ID of the required value
555 * The property found, or NULL
557 PTHEME_PROPERTY
MSSTYLES_FindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
559 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
562 /***********************************************************************
563 * MSSTYLES_AddProperty
565 * Add a property to a part/state
569 * iPropertyPrimitive Primitive type of the property
570 * iPropertyId ID of the property
571 * lpValue Raw value (non-NULL terminated)
572 * dwValueLen Length of the value
575 * The property added, or a property previously added with the same IDs
577 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
579 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
580 /* Should duplicate properties overwrite the original, or be ignored? */
583 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
584 cur
->iPrimitiveType
= iPropertyPrimitive
;
585 cur
->iPropertyId
= iPropertyId
;
586 cur
->lpValue
= lpValue
;
587 cur
->dwValueLen
= dwValueLen
;
590 cur
->origin
= PO_STATE
;
592 cur
->origin
= PO_PART
;
594 cur
->origin
= PO_GLOBAL
;
596 cur
->origin
= PO_CLASS
;
598 cur
->next
= ps
->properties
;
599 ps
->properties
= cur
;
603 /***********************************************************************
606 * Add a property to a part/state
610 * iPropertyPrimitive Primitive type of the property
611 * iPropertyId ID of the property
612 * lpValue Raw value (non-NULL terminated)
613 * dwValueLen Length of the value
616 * The property added, or a property previously added with the same IDs
618 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
620 PTHEME_PROPERTY cur
= MSSTYLES_FindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
621 /* Should duplicate properties overwrite the original, or be ignored? */
624 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
625 cur
->iPrimitiveType
= iPropertyPrimitive
;
626 cur
->iPropertyId
= iPropertyId
;
627 cur
->lpValue
= lpValue
;
628 cur
->dwValueLen
= dwValueLen
;
630 cur
->origin
= PO_GLOBAL
;
632 cur
->next
= tf
->metrics
;
637 /***********************************************************************
638 * MSSTYLES_ParseThemeIni
640 * Parse the theme ini for the selected color/style
645 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
)
647 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
648 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
650 PTHEME_CLASS globals
;
653 WCHAR szAppName
[MAX_THEME_APP_NAME
];
654 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
655 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
658 int iPropertyPrimitive
;
668 ini
= MSSTYLES_GetActiveThemeIni(tf
);
670 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
)))
672 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
)
674 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
)))
676 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
677 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
))
679 /* Catch all metrics, including colors */
680 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
684 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
690 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
))
692 BOOL isGlobal
= FALSE
;
693 if(!lstrcmpiW(szClassName
, szGlobals
))
697 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
698 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
700 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
)))
702 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
703 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
))
705 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
709 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
715 /* App/Class combos override values defined by the base class, map these overrides */
716 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
722 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
725 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
729 cls
->overrides
= globals
;
734 /* Everything overrides globals..except globals */
736 cls
->overrides
= globals
;
743 ERR("Failed to parse theme ini\n");
747 /***********************************************************************
748 * MSSTYLES_OpenThemeClass
750 * Open a theme class, uses the current active theme
753 * pszAppName Application name, for theme styles specific
754 * to a particular application
755 * pszClassList List of requested classes, semicolon delimited
757 PTHEME_CLASS
MSSTYLES_OpenThemeClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassList
)
759 PTHEME_CLASS cls
= NULL
;
760 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
769 start
= pszClassList
;
770 while((end
= strchrW(start
, ';'))) {
772 lstrcpynW(szClassName
, start
, min(len
+1, sizeof(szClassName
)/sizeof(szClassName
[0])));
774 cls
= MSSTYLES_FindClass(tf
, pszAppName
, szClassName
);
778 lstrcpynW(szClassName
, start
, sizeof(szClassName
)/sizeof(szClassName
[0]));
779 cls
= MSSTYLES_FindClass(tf
, pszAppName
, szClassName
);
782 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
784 cls
->tf
->dwRefCount
++;
785 TRACE("Theme %p refcount: %d\n", tf
, tf
->dwRefCount
);
790 /***********************************************************************
791 * MSSTYLES_CloseThemeClass
793 * Close a theme class
796 * tc Theme class to close
799 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
800 * theme file and cleans it up, if needed.
802 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
804 MSSTYLES_CloseThemeFile (tc
->tf
);
808 /***********************************************************************
809 * MSSTYLES_FindProperty
811 * Locate a property in a class. Part and state IDs will be used as a
812 * preference, but may be ignored in the attempt to locate the property.
813 * Will scan the entire chain of overrides for this class.
815 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
817 PTHEME_CLASS next
= tc
;
821 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
822 /* Try and find an exact match on part & state */
823 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
824 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
828 /* If that fails, and we didn't already try it, search for just part */
831 /* As a last ditch attempt..go for just class */
832 else if(iPartId
!= 0)
837 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
842 /* Prepare a bitmap to be used for alpha blending */
843 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
851 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
854 if(dib
.dsBm
.bmBitsPixel
!= 32)
860 n
= dib
.dsBmih
.biHeight
* dib
.dsBmih
.biWidth
;
861 /* AlphaBlend() wants premultiplied alpha, so do that now */
865 p
[0] = (p
[0] * a
) >> 8;
866 p
[1] = (p
[1] * a
) >> 8;
867 p
[2] = (p
[2] * a
) >> 8;
874 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
876 WCHAR szFile
[MAX_PATH
];
879 lstrcpynW(szFile
, lpFilename
, sizeof(szFile
)/sizeof(szFile
[0]));
882 if(*tmp
== '\\') *tmp
= '_';
883 if(*tmp
== '/') *tmp
= '_';
884 if(*tmp
== '.') *tmp
= '_';
887 /* Try to locate in list of loaded images */
888 img
= tc
->tf
->images
;
891 if (lstrcmpiW (szFile
, img
->name
) == 0)
893 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
894 *hasAlpha
= img
->hasAlpha
;
899 /* Not found? Load from resources */
900 img
= HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE
));
901 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
902 prepare_alpha (img
->image
, hasAlpha
);
903 img
->hasAlpha
= *hasAlpha
;
904 /* ...and stow away for later reuse. */
905 lstrcpyW (img
->name
, szFile
);
906 img
->next
= tc
->tf
->images
;
907 tc
->tf
->images
= img
;
908 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
912 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
914 LPCWSTR cur
= lpStringStart
;
918 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
919 if(cur
>= lpStringEnd
) {
926 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
927 total
= total
* 10 + (*cur
- '0');
930 if(gotNeg
) total
= -total
;
932 if(lpValEnd
) *lpValEnd
= cur
;
936 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
937 LPCWSTR cur
= lpStringStart
;
941 while(cur
< lpStringEnd
&& (isspace(*cur
) || *cur
== ',')) cur
++;
942 if(cur
>= lpStringEnd
) {
946 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
948 while(isspace(*end
)) end
--;
950 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
952 if(lpValEnd
) *lpValEnd
= cur
;
956 /***********************************************************************
957 * MSSTYLES_GetPropertyBool
959 * Retrieve a color value for a property
961 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
964 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
969 /***********************************************************************
970 * MSSTYLES_GetPropertyColor
972 * Retrieve a color value for a property
974 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
978 int red
, green
, blue
;
981 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
983 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
)) {
984 TRACE("Could not parse color property\n");
985 return E_PROP_ID_UNSUPPORTED
;
987 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
)) {
988 TRACE("Could not parse color property\n");
989 return E_PROP_ID_UNSUPPORTED
;
991 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
992 TRACE("Could not parse color property\n");
993 return E_PROP_ID_UNSUPPORTED
;
995 *pColor
= RGB(red
,green
,blue
);
999 /***********************************************************************
1000 * MSSTYLES_GetPropertyColor
1002 * Retrieve a color value for a property
1004 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1005 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1007 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
1008 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
1009 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
1010 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
1014 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1015 TRACE("Property is there, but failed to get face name\n");
1017 return E_PROP_ID_UNSUPPORTED
;
1019 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1020 TRACE("Property is there, but failed to get point size\n");
1022 return E_PROP_ID_UNSUPPORTED
;
1027 pointSize
= -MulDiv(pointSize
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1031 pFont
->lfHeight
= pointSize
;
1032 pFont
->lfWeight
= FW_REGULAR
;
1033 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1034 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, sizeof(attr
)/sizeof(attr
[0]))) {
1035 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
1036 else if(!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
1037 else if(!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
1038 else if(!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
1044 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1046 LPCWSTR lpCur
= tp
->lpValue
;
1047 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1050 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1051 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1056 /***********************************************************************
1057 * MSSTYLES_GetPropertyInt
1059 * Retrieve an int value for a property
1061 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1063 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1064 TRACE("Could not parse int property\n");
1065 return E_PROP_ID_UNSUPPORTED
;
1070 /***********************************************************************
1071 * MSSTYLES_GetPropertyIntList
1073 * Retrieve an int list value for a property
1075 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1078 LPCWSTR lpCur
= tp
->lpValue
;
1079 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1081 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1082 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1085 pIntList
->iValueCount
= i
;
1089 /***********************************************************************
1090 * MSSTYLES_GetPropertyPosition
1092 * Retrieve a position value for a property
1094 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1097 LPCWSTR lpCur
= tp
->lpValue
;
1098 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1100 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
)) {
1101 TRACE("Could not parse position property\n");
1102 return E_PROP_ID_UNSUPPORTED
;
1104 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1105 TRACE("Could not parse position property\n");
1106 return E_PROP_ID_UNSUPPORTED
;
1113 /***********************************************************************
1114 * MSSTYLES_GetPropertyString
1116 * Retrieve a string value for a property
1118 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1120 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1124 /***********************************************************************
1125 * MSSTYLES_GetPropertyRect
1127 * Retrieve a rect value for a property
1129 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1131 LPCWSTR lpCur
= tp
->lpValue
;
1132 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1134 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->left
);
1135 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->top
);
1136 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->right
);
1137 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->bottom
)) {
1138 TRACE("Could not parse rect property\n");
1139 return E_PROP_ID_UNSUPPORTED
;
1144 /***********************************************************************
1145 * MSSTYLES_GetPropertyMargins
1147 * Retrieve a margins value for a property
1149 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1151 LPCWSTR lpCur
= tp
->lpValue
;
1152 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1154 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1155 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1156 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1157 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1158 TRACE("Could not parse margins property\n");
1159 return E_PROP_ID_UNSUPPORTED
;