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
;
203 while(ps
->properties
) {
204 PTHEME_PROPERTY prop
= ps
->properties
;
205 ps
->properties
= prop
->next
;
206 HeapFree(GetProcessHeap(), 0, prop
);
209 pcls
->partstate
= ps
->next
;
210 HeapFree(GetProcessHeap(), 0, ps
);
212 HeapFree(GetProcessHeap(), 0, pcls
);
217 PTHEME_IMAGE img
= tf
->images
;
218 tf
->images
= img
->next
;
219 DeleteObject (img
->image
);
220 HeapFree (GetProcessHeap(), 0, img
);
222 HeapFree(GetProcessHeap(), 0, tf
);
227 /***********************************************************************
228 * MSSTYLES_ReferenceTheme
230 * Increase the reference count of the theme file
232 HRESULT
MSSTYLES_ReferenceTheme(PTHEME_FILE tf
)
235 TRACE("Theme %p refcount: %d\n", tf
, tf
->dwRefCount
);
239 /***********************************************************************
240 * MSSTYLES_GetThemeIni
242 * Retrieves themes.ini from a theme
244 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
246 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
249 /***********************************************************************
250 * MSSTYLES_GetActiveThemeIni
252 * Retrieve the ini file for the selected color/style
254 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
256 static const WCHAR szFileResNamesResource
[] = {
257 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
259 DWORD dwColorCount
= 0;
260 DWORD dwSizeCount
= 0;
261 DWORD dwColorNum
= 0;
264 DWORD dwResourceIndex
;
268 /* Count the number of available colors & styles, and determine the index number
269 of the color/style we are interested in
271 tmp
= tf
->pszAvailColors
;
273 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
274 dwColorNum
= dwColorCount
;
275 tmp
+= lstrlenW(tmp
)+1;
278 tmp
= tf
->pszAvailSizes
;
280 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
281 dwSizeNum
= dwSizeCount
;
282 tmp
+= lstrlenW(tmp
)+1;
286 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
287 TRACE("FILERESNAMES map not found\n");
290 tmp
= LoadResource(tf
->hTheme
, hrsc
);
291 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
292 for(i
=0; i
< dwResourceIndex
; i
++) {
293 tmp
+= lstrlenW(tmp
)+1;
295 return UXINI_LoadINI(tf
->hTheme
, tmp
);
299 /***********************************************************************
300 * MSSTYLES_ParseIniSectionName
302 * Parse an ini section name into its component parts
307 * [classname.part(state)]
308 * [application::classname]
309 * [application::classname(state)]
310 * [application::classname.part]
311 * [application::classname.part(state)]
314 * lpSection Section name
315 * dwLen Length of section name
316 * szAppName Location to store application name
317 * szClassName Location to store class name
318 * iPartId Location to store part id
319 * iStateId Location to store state id
321 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
324 WCHAR part
[60] = {'\0'};
325 WCHAR state
[60] = {'\0'};
328 lstrcpynW(sec
, lpSection
, min(dwLen
+1, sizeof(sec
)/sizeof(sec
[0])));
335 /* Get the application name */
336 tmp
= strchrW(comp
, ':');
340 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
344 tmp
= strchrW(comp
, '.');
347 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
349 /* now get the part & state */
350 tmp
= strchrW(comp
, '(');
353 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
355 /* now get the state */
356 tmp
= strchrW(comp
, ')');
360 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
363 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
367 tmp
= strchrW(comp
, '(');
370 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
372 /* now get the state */
373 tmp
= strchrW(comp
, ')');
377 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
380 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
383 if(!*szClassName
) return FALSE
;
384 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
387 /***********************************************************************
394 * pszAppName App name to find
395 * pszClassName Class name to find
398 * The class found, or NULL
400 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
402 PTHEME_CLASS cur
= tf
->classes
;
405 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
409 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
417 /***********************************************************************
420 * Add a class to a theme file
424 * pszAppName App name to add
425 * pszClassName Class name to add
428 * The class added, or a class previously added with the same name
430 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
432 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
435 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS
));
436 cur
->hTheme
= tf
->hTheme
;
437 lstrcpyW(cur
->szAppName
, pszAppName
);
438 lstrcpyW(cur
->szClassName
, pszClassName
);
439 cur
->next
= tf
->classes
;
440 cur
->partstate
= NULL
;
441 cur
->overrides
= NULL
;
446 /***********************************************************************
447 * MSSTYLES_FindPartState
453 * iPartId Part ID to find
454 * iStateId State ID to find
455 * tcNext Receives the next class in the override chain
458 * The part/state found, or NULL
460 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
462 PTHEME_PARTSTATE cur
= tc
->partstate
;
464 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
465 if(tcNext
) *tcNext
= tc
->overrides
;
470 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
474 /***********************************************************************
475 * MSSTYLES_AddPartState
477 * Add a part/state to a class
481 * iPartId Part ID to add
482 * iStateId State ID to add
485 * The part/state added, or a part/state previously added with the same IDs
487 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
489 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
492 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE
));
493 cur
->iPartId
= iPartId
;
494 cur
->iStateId
= iStateId
;
495 cur
->properties
= NULL
;
496 cur
->next
= tc
->partstate
;
501 /***********************************************************************
502 * MSSTYLES_LFindProperty
504 * Find a property within a property list
507 * tp property list to scan
508 * iPropertyPrimitive Type of value expected
509 * iPropertyId ID of the required value
512 * The property found, or NULL
514 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
516 PTHEME_PROPERTY cur
= tp
;
518 if(cur
->iPropertyId
== iPropertyId
) {
519 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
523 if(!iPropertyPrimitive
)
533 /***********************************************************************
534 * MSSTYLES_PSFindProperty
536 * Find a value within a part/state
539 * ps Part/state to search
540 * iPropertyPrimitive Type of value expected
541 * iPropertyId ID of the required value
544 * The property found, or NULL
546 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
548 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
551 /***********************************************************************
552 * MSSTYLES_FindMetric
554 * Find a metric property for a theme file
558 * iPropertyPrimitive Type of value expected
559 * iPropertyId ID of the required value
562 * The property found, or NULL
564 PTHEME_PROPERTY
MSSTYLES_FindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
566 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
569 /***********************************************************************
570 * MSSTYLES_AddProperty
572 * Add a property to a part/state
576 * iPropertyPrimitive Primitive type of the property
577 * iPropertyId ID of the property
578 * lpValue Raw value (non-NULL terminated)
579 * dwValueLen Length of the value
582 * The property added, or a property previously added with the same IDs
584 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
586 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
587 /* Should duplicate properties overwrite the original, or be ignored? */
590 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
591 cur
->iPrimitiveType
= iPropertyPrimitive
;
592 cur
->iPropertyId
= iPropertyId
;
593 cur
->lpValue
= lpValue
;
594 cur
->dwValueLen
= dwValueLen
;
597 cur
->origin
= PO_STATE
;
599 cur
->origin
= PO_PART
;
601 cur
->origin
= PO_GLOBAL
;
603 cur
->origin
= PO_CLASS
;
605 cur
->next
= ps
->properties
;
606 ps
->properties
= cur
;
610 /***********************************************************************
613 * Add a property to a part/state
617 * iPropertyPrimitive Primitive type of the property
618 * iPropertyId ID of the property
619 * lpValue Raw value (non-NULL terminated)
620 * dwValueLen Length of the value
623 * The property added, or a property previously added with the same IDs
625 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
627 PTHEME_PROPERTY cur
= MSSTYLES_FindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
628 /* Should duplicate properties overwrite the original, or be ignored? */
631 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
632 cur
->iPrimitiveType
= iPropertyPrimitive
;
633 cur
->iPropertyId
= iPropertyId
;
634 cur
->lpValue
= lpValue
;
635 cur
->dwValueLen
= dwValueLen
;
637 cur
->origin
= PO_GLOBAL
;
639 cur
->next
= tf
->metrics
;
644 /***********************************************************************
645 * MSSTYLES_ParseThemeIni
647 * Parse the theme ini for the selected color/style
652 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
)
654 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
655 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
657 PTHEME_CLASS globals
;
660 WCHAR szAppName
[MAX_THEME_APP_NAME
];
661 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
662 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
665 int iPropertyPrimitive
;
675 ini
= MSSTYLES_GetActiveThemeIni(tf
);
677 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
)))
679 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
)
681 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
)))
683 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
684 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
))
686 /* Catch all metrics, including colors */
687 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
691 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
697 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
))
699 BOOL isGlobal
= FALSE
;
700 if(!lstrcmpiW(szClassName
, szGlobals
))
704 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
705 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
707 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
)))
709 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
710 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
))
712 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
716 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
722 /* App/Class combos override values defined by the base class, map these overrides */
723 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
729 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
732 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
736 cls
->overrides
= globals
;
741 /* Everything overrides globals..except globals */
743 cls
->overrides
= globals
;
750 ERR("Failed to parse theme ini\n");
754 /***********************************************************************
755 * MSSTYLES_OpenThemeClass
757 * Open a theme class, uses the current active theme
760 * pszAppName Application name, for theme styles specific
761 * to a particular application
762 * pszClassList List of requested classes, semicolon delimited
764 PTHEME_CLASS
MSSTYLES_OpenThemeClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassList
)
766 PTHEME_CLASS cls
= NULL
;
767 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
776 start
= pszClassList
;
777 while((end
= strchrW(start
, ';'))) {
779 lstrcpynW(szClassName
, start
, min(len
+1, sizeof(szClassName
)/sizeof(szClassName
[0])));
781 cls
= MSSTYLES_FindClass(tf
, pszAppName
, szClassName
);
785 lstrcpynW(szClassName
, start
, sizeof(szClassName
)/sizeof(szClassName
[0]));
786 cls
= MSSTYLES_FindClass(tf
, pszAppName
, szClassName
);
789 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
791 cls
->tf
->dwRefCount
++;
792 TRACE("Theme %p refcount: %d\n", tf
, tf
->dwRefCount
);
797 /***********************************************************************
798 * MSSTYLES_CloseThemeClass
800 * Close a theme class
803 * tc Theme class to close
806 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
807 * theme file and cleans it up, if needed.
809 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
811 MSSTYLES_CloseThemeFile (tc
->tf
);
815 /***********************************************************************
816 * MSSTYLES_FindProperty
818 * Locate a property in a class. Part and state IDs will be used as a
819 * preference, but may be ignored in the attempt to locate the property.
820 * Will scan the entire chain of overrides for this class.
822 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
824 PTHEME_CLASS next
= tc
;
828 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
829 /* Try and find an exact match on part & state */
830 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
831 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
835 /* If that fails, and we didn't already try it, search for just part */
838 /* As a last ditch attempt..go for just class */
839 else if(iPartId
!= 0)
844 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
849 /* Prepare a bitmap to be used for alpha blending */
850 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
858 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
861 if(dib
.dsBm
.bmBitsPixel
!= 32)
867 n
= dib
.dsBmih
.biHeight
* dib
.dsBmih
.biWidth
;
868 /* AlphaBlend() wants premultiplied alpha, so do that now */
872 p
[0] = (p
[0] * a
) >> 8;
873 p
[1] = (p
[1] * a
) >> 8;
874 p
[2] = (p
[2] * a
) >> 8;
881 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
883 WCHAR szFile
[MAX_PATH
];
886 lstrcpynW(szFile
, lpFilename
, sizeof(szFile
)/sizeof(szFile
[0]));
889 if(*tmp
== '\\') *tmp
= '_';
890 if(*tmp
== '/') *tmp
= '_';
891 if(*tmp
== '.') *tmp
= '_';
894 /* Try to locate in list of loaded images */
895 img
= tc
->tf
->images
;
898 if (lstrcmpiW (szFile
, img
->name
) == 0)
900 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
901 *hasAlpha
= img
->hasAlpha
;
906 /* Not found? Load from resources */
907 img
= HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE
));
908 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
909 prepare_alpha (img
->image
, hasAlpha
);
910 img
->hasAlpha
= *hasAlpha
;
911 /* ...and stow away for later reuse. */
912 lstrcpyW (img
->name
, szFile
);
913 img
->next
= tc
->tf
->images
;
914 tc
->tf
->images
= img
;
915 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
919 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
921 LPCWSTR cur
= lpStringStart
;
925 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
926 if(cur
>= lpStringEnd
) {
933 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
934 total
= total
* 10 + (*cur
- '0');
937 if(gotNeg
) total
= -total
;
939 if(lpValEnd
) *lpValEnd
= cur
;
943 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
944 LPCWSTR cur
= lpStringStart
;
948 while(cur
< lpStringEnd
&& (isspace(*cur
) || *cur
== ',')) cur
++;
949 if(cur
>= lpStringEnd
) {
953 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
955 while(isspace(*end
)) end
--;
957 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
959 if(lpValEnd
) *lpValEnd
= cur
;
963 /***********************************************************************
964 * MSSTYLES_GetPropertyBool
966 * Retrieve a color value for a property
968 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
971 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
976 /***********************************************************************
977 * MSSTYLES_GetPropertyColor
979 * Retrieve a color value for a property
981 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
985 int red
, green
, blue
;
988 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
990 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
)) {
991 TRACE("Could not parse color property\n");
992 return E_PROP_ID_UNSUPPORTED
;
994 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
)) {
995 TRACE("Could not parse color property\n");
996 return E_PROP_ID_UNSUPPORTED
;
998 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
999 TRACE("Could not parse color property\n");
1000 return E_PROP_ID_UNSUPPORTED
;
1002 *pColor
= RGB(red
,green
,blue
);
1006 /***********************************************************************
1007 * MSSTYLES_GetPropertyColor
1009 * Retrieve a color value for a property
1011 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1012 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1014 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
1015 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
1016 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
1017 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
1021 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1022 TRACE("Property is there, but failed to get face name\n");
1024 return E_PROP_ID_UNSUPPORTED
;
1026 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1027 TRACE("Property is there, but failed to get point size\n");
1029 return E_PROP_ID_UNSUPPORTED
;
1034 pointSize
= -MulDiv(pointSize
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1038 pFont
->lfHeight
= pointSize
;
1039 pFont
->lfWeight
= FW_REGULAR
;
1040 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1041 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, sizeof(attr
)/sizeof(attr
[0]))) {
1042 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
1043 else if(!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
1044 else if(!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
1045 else if(!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
1051 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1053 LPCWSTR lpCur
= tp
->lpValue
;
1054 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1057 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1058 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1063 /***********************************************************************
1064 * MSSTYLES_GetPropertyInt
1066 * Retrieve an int value for a property
1068 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1070 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1071 TRACE("Could not parse int property\n");
1072 return E_PROP_ID_UNSUPPORTED
;
1077 /***********************************************************************
1078 * MSSTYLES_GetPropertyIntList
1080 * Retrieve an int list value for a property
1082 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1085 LPCWSTR lpCur
= tp
->lpValue
;
1086 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1088 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1089 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1092 pIntList
->iValueCount
= i
;
1096 /***********************************************************************
1097 * MSSTYLES_GetPropertyPosition
1099 * Retrieve a position value for a property
1101 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1104 LPCWSTR lpCur
= tp
->lpValue
;
1105 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1107 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
)) {
1108 TRACE("Could not parse position property\n");
1109 return E_PROP_ID_UNSUPPORTED
;
1111 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1112 TRACE("Could not parse position property\n");
1113 return E_PROP_ID_UNSUPPORTED
;
1120 /***********************************************************************
1121 * MSSTYLES_GetPropertyString
1123 * Retrieve a string value for a property
1125 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1127 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1131 /***********************************************************************
1132 * MSSTYLES_GetPropertyRect
1134 * Retrieve a rect value for a property
1136 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1138 LPCWSTR lpCur
= tp
->lpValue
;
1139 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1141 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->left
);
1142 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->top
);
1143 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->right
);
1144 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->bottom
)) {
1145 TRACE("Could not parse rect property\n");
1146 return E_PROP_ID_UNSUPPORTED
;
1151 /***********************************************************************
1152 * MSSTYLES_GetPropertyMargins
1154 * Retrieve a margins value for a property
1156 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1158 LPCWSTR lpCur
= tp
->lpValue
;
1159 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1161 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1162 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1163 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1164 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1165 TRACE("Could not parse margins property\n");
1166 return E_PROP_ID_UNSUPPORTED
;