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
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
42 /***********************************************************************
43 * Defines and global variables
46 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
);
47 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
);
48 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
);
49 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LOGFONTW
* logfont
);
51 extern int alphaBlendMode
;
53 #define MSSTYLES_VERSION 0x0003
55 static const WCHAR szThemesIniResource
[] = {
56 't','h','e','m','e','s','_','i','n','i','\0'
59 static PTHEME_FILE tfActiveTheme
;
61 /***********************************************************************/
63 /**********************************************************************
64 * MSSTYLES_OpenThemeFile
66 * Load and validate a theme
69 * lpThemeFile Path to theme file to load
70 * pszColorName Color name wanted, can be NULL
71 * pszSizeName Size name wanted, can be NULL
74 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
75 * If one/both are provided, they are validated against valid color/sizes and if
76 * a match is not found, the function fails.
78 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
83 static const WCHAR szPackThemVersionResource
[] = {
84 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
86 static const WCHAR szColorNamesResource
[] = {
87 'C','O','L','O','R','N','A','M','E','S','\0'
89 static const WCHAR szSizeNamesResource
[] = {
90 'S','I','Z','E','N','A','M','E','S','\0'
96 LPWSTR pszSelectedColor
= NULL
;
98 LPWSTR pszSelectedSize
= NULL
;
101 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
103 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
105 /* Validate that this is really a theme */
107 hr
= HRESULT_FROM_WIN32(GetLastError());
110 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szPackThemVersionResource
))) {
111 TRACE("No version resource found\n");
112 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
115 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
117 TRACE("Version resource found, but wrong size: %d\n", versize
);
118 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
121 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
122 if(version
!= MSSTYLES_VERSION
)
124 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
125 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
129 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szColorNamesResource
))) {
130 TRACE("Color names resource not found\n");
131 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
134 pszColors
= LoadResource(hTheme
, hrsc
);
136 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szSizeNamesResource
))) {
137 TRACE("Size names resource not found\n");
138 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
141 pszSizes
= LoadResource(hTheme
, hrsc
);
143 /* Validate requested color against what's available from the theme */
147 if(!lstrcmpiW(pszColorName
, tmp
)) {
148 pszSelectedColor
= tmp
;
151 tmp
+= lstrlenW(tmp
)+1;
155 pszSelectedColor
= pszColors
; /* Use the default color */
157 /* Validate requested size against what's available from the theme */
161 if(!lstrcmpiW(pszSizeName
, tmp
)) {
162 pszSelectedSize
= tmp
;
165 tmp
+= lstrlenW(tmp
)+1;
169 pszSelectedSize
= pszSizes
; /* Use the default size */
171 if(!pszSelectedColor
|| !pszSelectedSize
) {
172 TRACE("Requested color/size (%s/%s) not found in theme\n",
173 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
174 hr
= E_PROP_ID_UNSUPPORTED
;
178 *tf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(THEME_FILE
));
179 (*tf
)->hTheme
= hTheme
;
181 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
183 (*tf
)->pszAvailColors
= pszColors
;
184 (*tf
)->pszAvailSizes
= pszSizes
;
185 (*tf
)->pszSelectedColor
= pszSelectedColor
;
186 (*tf
)->pszSelectedSize
= pszSelectedSize
;
187 (*tf
)->dwRefCount
= 1;
191 if(hTheme
) FreeLibrary(hTheme
);
195 /***********************************************************************
196 * MSSTYLES_CloseThemeFile
198 * Close theme file and free resources
200 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
204 if(!tf
->dwRefCount
) {
205 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
208 PTHEME_CLASS pcls
= tf
->classes
;
209 tf
->classes
= pcls
->next
;
210 while(pcls
->partstate
) {
211 PTHEME_PARTSTATE ps
= pcls
->partstate
;
213 while(ps
->properties
) {
214 PTHEME_PROPERTY prop
= ps
->properties
;
215 ps
->properties
= prop
->next
;
216 HeapFree(GetProcessHeap(), 0, prop
);
219 pcls
->partstate
= ps
->next
;
220 HeapFree(GetProcessHeap(), 0, ps
);
222 HeapFree(GetProcessHeap(), 0, pcls
);
227 PTHEME_IMAGE img
= tf
->images
;
228 tf
->images
= img
->next
;
229 DeleteObject (img
->image
);
230 HeapFree (GetProcessHeap(), 0, img
);
232 HeapFree(GetProcessHeap(), 0, tf
);
237 /***********************************************************************
238 * MSSTYLES_SetActiveTheme
240 * Set the current active theme
242 HRESULT
MSSTYLES_SetActiveTheme(PTHEME_FILE tf
, BOOL setMetrics
)
245 MSSTYLES_CloseThemeFile(tfActiveTheme
);
249 tfActiveTheme
->dwRefCount
++;
250 if(!tfActiveTheme
->classes
)
251 MSSTYLES_ParseThemeIni(tfActiveTheme
, setMetrics
);
256 /***********************************************************************
257 * MSSTYLES_GetThemeIni
259 * Retrieves themes.ini from a theme
261 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
263 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
266 /***********************************************************************
267 * MSSTYLES_GetActiveThemeIni
269 * Retrieve the ini file for the selected color/style
271 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
273 static const WCHAR szFileResNamesResource
[] = {
274 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
276 DWORD dwColorCount
= 0;
277 DWORD dwSizeCount
= 0;
278 DWORD dwColorNum
= 0;
281 DWORD dwResourceIndex
;
285 /* Count the number of available colors & styles, and determine the index number
286 of the color/style we are interested in
288 tmp
= tf
->pszAvailColors
;
290 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
291 dwColorNum
= dwColorCount
;
292 tmp
+= lstrlenW(tmp
)+1;
295 tmp
= tf
->pszAvailSizes
;
297 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
298 dwSizeNum
= dwSizeCount
;
299 tmp
+= lstrlenW(tmp
)+1;
303 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
304 TRACE("FILERESNAMES map not found\n");
307 tmp
= LoadResource(tf
->hTheme
, hrsc
);
308 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
309 for(i
=0; i
< dwResourceIndex
; i
++) {
310 tmp
+= lstrlenW(tmp
)+1;
312 return UXINI_LoadINI(tf
->hTheme
, tmp
);
316 /***********************************************************************
317 * MSSTYLES_ParseIniSectionName
319 * Parse an ini section name into its component parts
324 * [classname.part(state)]
325 * [application::classname]
326 * [application::classname(state)]
327 * [application::classname.part]
328 * [application::classname.part(state)]
331 * lpSection Section name
332 * dwLen Length of section name
333 * szAppName Location to store application name
334 * szClassName Location to store class name
335 * iPartId Location to store part id
336 * iStateId Location to store state id
338 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
341 WCHAR part
[60] = {'\0'};
342 WCHAR state
[60] = {'\0'};
345 lstrcpynW(sec
, lpSection
, min(dwLen
+1, sizeof(sec
)/sizeof(sec
[0])));
352 /* Get the application name */
353 tmp
= strchrW(comp
, ':');
357 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
361 tmp
= strchrW(comp
, '.');
364 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
366 /* now get the part & state */
367 tmp
= strchrW(comp
, '(');
370 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
372 /* now get the state */
373 tmp
= strchrW(comp
, ')');
377 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
380 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
384 tmp
= strchrW(comp
, '(');
387 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
389 /* now get the state */
390 tmp
= strchrW(comp
, ')');
394 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
397 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
400 if(!*szClassName
) return FALSE
;
401 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
404 /***********************************************************************
411 * pszAppName App name to find
412 * pszClassName Class name to find
415 * The class found, or NULL
417 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
419 PTHEME_CLASS cur
= tf
->classes
;
422 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
426 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
434 /***********************************************************************
437 * Add a class to a theme file
441 * pszAppName App name to add
442 * pszClassName Class name to add
445 * The class added, or a class previously added with the same name
447 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
449 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
452 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS
));
453 cur
->hTheme
= tf
->hTheme
;
454 lstrcpyW(cur
->szAppName
, pszAppName
);
455 lstrcpyW(cur
->szClassName
, pszClassName
);
456 cur
->next
= tf
->classes
;
457 cur
->partstate
= NULL
;
458 cur
->overrides
= NULL
;
463 /***********************************************************************
464 * MSSTYLES_FindPartState
470 * iPartId Part ID to find
471 * iStateId State ID to find
472 * tcNext Receives the next class in the override chain
475 * The part/state found, or NULL
477 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
479 PTHEME_PARTSTATE cur
= tc
->partstate
;
481 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
482 if(tcNext
) *tcNext
= tc
->overrides
;
487 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
491 /***********************************************************************
492 * MSSTYLES_AddPartState
494 * Add a part/state to a class
498 * iPartId Part ID to add
499 * iStateId State ID to add
502 * The part/state added, or a part/state previously added with the same IDs
504 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
506 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
509 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE
));
510 cur
->iPartId
= iPartId
;
511 cur
->iStateId
= iStateId
;
512 cur
->properties
= NULL
;
513 cur
->next
= tc
->partstate
;
518 /***********************************************************************
519 * MSSTYLES_LFindProperty
521 * Find a property within a property list
524 * tp property list to scan
525 * iPropertyPrimitive Type of value expected
526 * iPropertyId ID of the required value
529 * The property found, or NULL
531 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
533 PTHEME_PROPERTY cur
= tp
;
535 if(cur
->iPropertyId
== iPropertyId
) {
536 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
540 if(!iPropertyPrimitive
)
550 /***********************************************************************
551 * MSSTYLES_PSFindProperty
553 * Find a value within a part/state
556 * ps Part/state to search
557 * iPropertyPrimitive Type of value expected
558 * iPropertyId ID of the required value
561 * The property found, or NULL
563 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
565 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
568 /***********************************************************************
569 * MSSTYLES_FFindMetric
571 * Find a metric property for a theme file
575 * iPropertyPrimitive Type of value expected
576 * iPropertyId ID of the required value
579 * The property found, or NULL
581 static inline PTHEME_PROPERTY
MSSTYLES_FFindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
583 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
586 /***********************************************************************
587 * MSSTYLES_FindMetric
589 * Find a metric property for the current installed theme
593 * iPropertyPrimitive Type of value expected
594 * iPropertyId ID of the required value
597 * The property found, or NULL
599 PTHEME_PROPERTY
MSSTYLES_FindMetric(int iPropertyPrimitive
, int iPropertyId
)
601 if(!tfActiveTheme
) return NULL
;
602 return MSSTYLES_FFindMetric(tfActiveTheme
, iPropertyPrimitive
, iPropertyId
);
605 /***********************************************************************
606 * MSSTYLES_AddProperty
608 * Add a property to a part/state
612 * iPropertyPrimitive Primitive type of the property
613 * iPropertyId ID of the property
614 * lpValue Raw value (non-NULL terminated)
615 * dwValueLen Length of the value
618 * The property added, or a property previously added with the same IDs
620 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
622 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
623 /* Should duplicate properties overwrite the original, or be ignored? */
626 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
627 cur
->iPrimitiveType
= iPropertyPrimitive
;
628 cur
->iPropertyId
= iPropertyId
;
629 cur
->lpValue
= lpValue
;
630 cur
->dwValueLen
= dwValueLen
;
633 cur
->origin
= PO_STATE
;
635 cur
->origin
= PO_PART
;
637 cur
->origin
= PO_GLOBAL
;
639 cur
->origin
= PO_CLASS
;
641 cur
->next
= ps
->properties
;
642 ps
->properties
= cur
;
646 /***********************************************************************
649 * Add a property to a part/state
653 * iPropertyPrimitive Primitive type of the property
654 * iPropertyId ID of the property
655 * lpValue Raw value (non-NULL terminated)
656 * dwValueLen Length of the value
659 * The property added, or a property previously added with the same IDs
661 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
663 PTHEME_PROPERTY cur
= MSSTYLES_FFindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
664 /* Should duplicate properties overwrite the original, or be ignored? */
667 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
668 cur
->iPrimitiveType
= iPropertyPrimitive
;
669 cur
->iPropertyId
= iPropertyId
;
670 cur
->lpValue
= lpValue
;
671 cur
->dwValueLen
= dwValueLen
;
673 cur
->origin
= PO_GLOBAL
;
675 cur
->next
= tf
->metrics
;
680 /* Color-related state for theme ini parsing */
681 struct PARSECOLORSTATE
684 int colorElements
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
685 COLORREF colorRgb
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
689 static inline void parse_init_color (struct PARSECOLORSTATE
* state
)
691 memset (state
, 0, sizeof (*state
));
694 static BOOL
parse_handle_color_property (struct PARSECOLORSTATE
* state
,
695 int iPropertyId
, LPCWSTR lpValue
,
699 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
700 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &r
) &&
701 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &g
) &&
702 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &b
)) {
703 state
->colorElements
[state
->colorCount
] = iPropertyId
- TMT_FIRSTCOLOR
;
704 state
->colorRgb
[state
->colorCount
++] = RGB(r
,g
,b
);
707 case TMT_ACTIVECAPTION
:
708 state
->captionColors
|= 0x1;
710 case TMT_INACTIVECAPTION
:
711 state
->captionColors
|= 0x2;
713 case TMT_GRADIENTACTIVECAPTION
:
714 state
->captionColors
|= 0x4;
716 case TMT_GRADIENTINACTIVECAPTION
:
717 state
->captionColors
|= 0x8;
727 static void parse_apply_color (struct PARSECOLORSTATE
* state
)
729 if (state
->colorCount
> 0)
730 SetSysColors(state
->colorCount
, state
->colorElements
, state
->colorRgb
);
731 if (state
->captionColors
== 0xf)
732 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS
, 0, (PVOID
)TRUE
, 0);
735 /* Non-client-metrics-related state for theme ini parsing */
736 struct PARSENONCLIENTSTATE
738 NONCLIENTMETRICSW metrics
;
740 LOGFONTW iconTitleFont
;
743 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE
* state
)
745 memset (state
, 0, sizeof (*state
));
746 state
->metrics
.cbSize
= sizeof (NONCLIENTMETRICSW
);
747 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (NONCLIENTMETRICSW
),
749 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (LOGFONTW
),
750 &state
->iconTitleFont
, 0);
753 static BOOL
parse_handle_nonclient_font (struct PARSENONCLIENTSTATE
* state
,
754 int iPropertyId
, LPCWSTR lpValue
,
759 memset (&font
, 0, sizeof (font
));
760 if (SUCCEEDED (MSSTYLES_GetFont (lpValue
, lpValue
+ dwValueLen
, &lpValue
,
765 case TMT_CAPTIONFONT
:
766 state
->metrics
.lfCaptionFont
= font
;
767 state
->metricsDirty
= TRUE
;
769 case TMT_SMALLCAPTIONFONT
:
770 state
->metrics
.lfSmCaptionFont
= font
;
771 state
->metricsDirty
= TRUE
;
774 state
->metrics
.lfMenuFont
= font
;
775 state
->metricsDirty
= TRUE
;
778 state
->metrics
.lfStatusFont
= font
;
779 state
->metricsDirty
= TRUE
;
782 state
->metrics
.lfMessageFont
= font
;
783 state
->metricsDirty
= TRUE
;
785 case TMT_ICONTITLEFONT
:
786 state
->iconTitleFont
= font
;
787 state
->metricsDirty
= TRUE
;
796 static BOOL
parse_handle_nonclient_size (struct PARSENONCLIENTSTATE
* state
,
797 int iPropertyId
, LPCWSTR lpValue
,
801 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
802 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &size
)) {
805 case TMT_SIZINGBORDERWIDTH
:
806 state
->metrics
.iBorderWidth
= size
;
807 state
->metricsDirty
= TRUE
;
809 case TMT_SCROLLBARWIDTH
:
810 state
->metrics
.iScrollWidth
= size
;
811 state
->metricsDirty
= TRUE
;
813 case TMT_SCROLLBARHEIGHT
:
814 state
->metrics
.iScrollHeight
= size
;
815 state
->metricsDirty
= TRUE
;
817 case TMT_CAPTIONBARWIDTH
:
818 state
->metrics
.iCaptionWidth
= size
;
819 state
->metricsDirty
= TRUE
;
821 case TMT_CAPTIONBARHEIGHT
:
822 state
->metrics
.iCaptionHeight
= size
;
823 state
->metricsDirty
= TRUE
;
825 case TMT_SMCAPTIONBARWIDTH
:
826 state
->metrics
.iSmCaptionWidth
= size
;
827 state
->metricsDirty
= TRUE
;
829 case TMT_SMCAPTIONBARHEIGHT
:
830 state
->metrics
.iSmCaptionHeight
= size
;
831 state
->metricsDirty
= TRUE
;
833 case TMT_MENUBARWIDTH
:
834 state
->metrics
.iMenuWidth
= size
;
835 state
->metricsDirty
= TRUE
;
837 case TMT_MENUBARHEIGHT
:
838 state
->metrics
.iMenuHeight
= size
;
839 state
->metricsDirty
= TRUE
;
848 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE
* state
)
850 if (state
->metricsDirty
)
852 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (state
->metrics
),
854 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (state
->iconTitleFont
),
855 &state
->iconTitleFont
, 0);
859 /***********************************************************************
860 * MSSTYLES_ParseThemeIni
862 * Parse the theme ini for the selected color/style
867 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
)
869 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
870 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
872 PTHEME_CLASS globals
;
875 WCHAR szAppName
[MAX_THEME_APP_NAME
];
876 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
877 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
880 int iPropertyPrimitive
;
887 ini
= MSSTYLES_GetActiveThemeIni(tf
);
889 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
))) {
890 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
) {
891 struct PARSECOLORSTATE colorState
;
892 struct PARSENONCLIENTSTATE nonClientState
;
894 parse_init_color (&colorState
);
895 parse_init_nonclient (&nonClientState
);
897 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
898 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
899 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
900 if(iPropertyId
>= TMT_FIRSTCOLOR
&& iPropertyId
<= TMT_LASTCOLOR
) {
901 if (!parse_handle_color_property (&colorState
, iPropertyId
,
902 lpValue
, dwValueLen
))
903 FIXME("Invalid color value for %s\n",
904 debugstr_w(szPropertyName
));
906 else if (setMetrics
&& (iPropertyId
== TMT_FLATMENUS
)) {
907 BOOL flatMenus
= (*lpValue
== 'T') || (*lpValue
== 't');
908 SystemParametersInfoW (SPI_SETFLATMENU
, 0, (PVOID
)(INT_PTR
)flatMenus
, 0);
910 else if ((iPropertyId
>= TMT_FIRSTFONT
)
911 && (iPropertyId
<= TMT_LASTFONT
))
913 if (!parse_handle_nonclient_font (&nonClientState
,
914 iPropertyId
, lpValue
, dwValueLen
))
915 FIXME("Invalid font value for %s\n",
916 debugstr_w(szPropertyName
));
918 else if ((iPropertyId
>= TMT_FIRSTSIZE
)
919 && (iPropertyId
<= TMT_LASTSIZE
))
921 if (!parse_handle_nonclient_size (&nonClientState
,
922 iPropertyId
, lpValue
, dwValueLen
))
923 FIXME("Invalid size value for %s\n",
924 debugstr_w(szPropertyName
));
926 /* Catch all metrics, including colors */
927 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
930 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
935 parse_apply_color (&colorState
);
936 parse_apply_nonclient (&nonClientState
);
940 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
)) {
941 BOOL isGlobal
= FALSE
;
942 if(!lstrcmpiW(szClassName
, szGlobals
)) {
945 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
946 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
948 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
949 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
950 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
951 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
954 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
960 /* App/Class combos override values defined by the base class, map these overrides */
961 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
964 if(*cls
->szAppName
) {
965 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
966 if(!cls
->overrides
) {
967 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
970 cls
->overrides
= globals
;
974 /* Everything overrides globals..except globals */
975 if(cls
!= globals
) cls
->overrides
= globals
;
982 ERR("Failed to parse theme ini\n");
986 /***********************************************************************
987 * MSSTYLES_OpenThemeClass
989 * Open a theme class, uses the current active theme
992 * pszAppName Application name, for theme styles specific
993 * to a particular application
994 * pszClassList List of requested classes, semicolon delimited
996 PTHEME_CLASS
MSSTYLES_OpenThemeClass(LPCWSTR pszAppName
, LPCWSTR pszClassList
)
998 PTHEME_CLASS cls
= NULL
;
999 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
1004 if(!tfActiveTheme
) {
1005 TRACE("there is no active theme\n");
1008 if(!tfActiveTheme
->classes
) {
1012 start
= pszClassList
;
1013 while((end
= strchrW(start
, ';'))) {
1015 lstrcpynW(szClassName
, start
, min(len
+1, sizeof(szClassName
)/sizeof(szClassName
[0])));
1017 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1020 if(!cls
&& *start
) {
1021 lstrcpynW(szClassName
, start
, sizeof(szClassName
)/sizeof(szClassName
[0]));
1022 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1025 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
1026 cls
->tf
= tfActiveTheme
;
1027 cls
->tf
->dwRefCount
++;
1032 /***********************************************************************
1033 * MSSTYLES_CloseThemeClass
1035 * Close a theme class
1038 * tc Theme class to close
1041 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1042 * theme file and cleans it up, if needed.
1044 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
1046 MSSTYLES_CloseThemeFile (tc
->tf
);
1050 /***********************************************************************
1051 * MSSTYLES_FindProperty
1053 * Locate a property in a class. Part and state IDs will be used as a
1054 * preference, but may be ignored in the attempt to locate the property.
1055 * Will scan the entire chain of overrides for this class.
1057 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
1059 PTHEME_CLASS next
= tc
;
1060 PTHEME_PARTSTATE ps
;
1063 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
1064 /* Try and find an exact match on part & state */
1065 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
1066 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
1070 /* If that fails, and we didn't already try it, search for just part */
1073 /* As a last ditch attempt..go for just class */
1074 else if(iPartId
!= 0)
1079 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
1084 /* Prepare a bitmap to be used for alpha blending */
1085 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
1093 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
1096 if(dib
.dsBm
.bmBitsPixel
!= 32)
1101 p
= dib
.dsBm
.bmBits
;
1102 n
= dib
.dsBmih
.biHeight
* dib
.dsBmih
.biWidth
;
1103 /* AlphaBlend() wants premultiplied alpha, so do that now */
1107 p
[0] = (p
[0] * a
) >> 8;
1108 p
[1] = (p
[1] * a
) >> 8;
1109 p
[2] = (p
[2] * a
) >> 8;
1116 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
1118 WCHAR szFile
[MAX_PATH
];
1121 lstrcpynW(szFile
, lpFilename
, sizeof(szFile
)/sizeof(szFile
[0]));
1124 if(*tmp
== '\\') *tmp
= '_';
1125 if(*tmp
== '/') *tmp
= '_';
1126 if(*tmp
== '.') *tmp
= '_';
1129 /* Try to locate in list of loaded images */
1130 img
= tc
->tf
->images
;
1133 if (lstrcmpiW (szFile
, img
->name
) == 0)
1135 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1136 *hasAlpha
= img
->hasAlpha
;
1141 /* Not found? Load from resources */
1142 img
= HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE
));
1143 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
1144 prepare_alpha (img
->image
, hasAlpha
);
1145 img
->hasAlpha
= *hasAlpha
;
1146 /* ...and stow away for later reuse. */
1147 lstrcpyW (img
->name
, szFile
);
1148 img
->next
= tc
->tf
->images
;
1149 tc
->tf
->images
= img
;
1150 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1154 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
1156 LPCWSTR cur
= lpStringStart
;
1158 BOOL gotNeg
= FALSE
;
1160 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
1161 if(cur
>= lpStringEnd
) {
1168 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
1169 total
= total
* 10 + (*cur
- '0');
1172 if(gotNeg
) total
= -total
;
1174 if(lpValEnd
) *lpValEnd
= cur
;
1178 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
1179 LPCWSTR cur
= lpStringStart
;
1183 while(cur
< lpStringEnd
&& (isspace(*cur
) || *cur
== ',')) cur
++;
1184 if(cur
>= lpStringEnd
) {
1188 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
1190 while(isspace(*end
)) end
--;
1192 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
1194 if(lpValEnd
) *lpValEnd
= cur
;
1198 /***********************************************************************
1199 * MSSTYLES_GetPropertyBool
1201 * Retrieve a color value for a property
1203 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
1206 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
1211 /***********************************************************************
1212 * MSSTYLES_GetPropertyColor
1214 * Retrieve a color value for a property
1216 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
1220 int red
, green
, blue
;
1222 lpCur
= tp
->lpValue
;
1223 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1225 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
)) {
1226 TRACE("Could not parse color property\n");
1227 return E_PROP_ID_UNSUPPORTED
;
1229 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
)) {
1230 TRACE("Could not parse color property\n");
1231 return E_PROP_ID_UNSUPPORTED
;
1233 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
1234 TRACE("Could not parse color property\n");
1235 return E_PROP_ID_UNSUPPORTED
;
1237 *pColor
= RGB(red
,green
,blue
);
1241 /***********************************************************************
1242 * MSSTYLES_GetPropertyColor
1244 * Retrieve a color value for a property
1246 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1247 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1249 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
1250 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
1251 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
1252 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
1256 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1257 TRACE("Property is there, but failed to get face name\n");
1259 return E_PROP_ID_UNSUPPORTED
;
1261 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1262 TRACE("Property is there, but failed to get point size\n");
1264 return E_PROP_ID_UNSUPPORTED
;
1266 pFont
->lfHeight
= pointSize
;
1267 pFont
->lfWeight
= FW_REGULAR
;
1268 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1269 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, sizeof(attr
)/sizeof(attr
[0]))) {
1270 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
1271 else if(!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
1272 else if(!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
1273 else if(!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
1279 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1281 LPCWSTR lpCur
= tp
->lpValue
;
1282 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1285 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1286 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1288 pFont
->lfHeight
= -MulDiv(pFont
->lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1293 /***********************************************************************
1294 * MSSTYLES_GetPropertyInt
1296 * Retrieve an int value for a property
1298 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1300 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1301 TRACE("Could not parse int property\n");
1302 return E_PROP_ID_UNSUPPORTED
;
1307 /***********************************************************************
1308 * MSSTYLES_GetPropertyIntList
1310 * Retrieve an int list value for a property
1312 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1315 LPCWSTR lpCur
= tp
->lpValue
;
1316 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1318 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1319 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1322 pIntList
->iValueCount
= i
;
1326 /***********************************************************************
1327 * MSSTYLES_GetPropertyPosition
1329 * Retrieve a position value for a property
1331 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1334 LPCWSTR lpCur
= tp
->lpValue
;
1335 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1337 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
)) {
1338 TRACE("Could not parse position property\n");
1339 return E_PROP_ID_UNSUPPORTED
;
1341 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1342 TRACE("Could not parse position property\n");
1343 return E_PROP_ID_UNSUPPORTED
;
1350 /***********************************************************************
1351 * MSSTYLES_GetPropertyString
1353 * Retrieve a string value for a property
1355 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1357 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1361 /***********************************************************************
1362 * MSSTYLES_GetPropertyRect
1364 * Retrieve a rect value for a property
1366 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1368 LPCWSTR lpCur
= tp
->lpValue
;
1369 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1371 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->left
);
1372 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->top
);
1373 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->right
);
1374 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->bottom
)) {
1375 TRACE("Could not parse rect property\n");
1376 return E_PROP_ID_UNSUPPORTED
;
1381 /***********************************************************************
1382 * MSSTYLES_GetPropertyMargins
1384 * Retrieve a margins value for a property
1386 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1388 LPCWSTR lpCur
= tp
->lpValue
;
1389 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1391 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1392 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1393 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1394 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1395 TRACE("Could not parse margins property\n");
1396 return E_PROP_ID_UNSUPPORTED
;