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
35 #include "wine/debug.h"
36 #include "wine/heap.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
40 /***********************************************************************
41 * Defines and global variables
44 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
);
45 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
);
46 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
);
47 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LOGFONTW
* logfont
);
49 #define MSSTYLES_VERSION 0x0003
51 static PTHEME_FILE tfActiveTheme
;
53 /***********************************************************************/
55 /**********************************************************************
56 * MSSTYLES_OpenThemeFile
58 * Load and validate a theme
61 * lpThemeFile Path to theme file to load
62 * pszColorName Color name wanted, can be NULL
63 * pszSizeName Size name wanted, can be NULL
66 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
67 * If one/both are provided, they are validated against valid color/sizes and if
68 * a match is not found, the function fails.
70 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
79 LPWSTR pszSelectedColor
= NULL
;
81 LPWSTR pszSelectedSize
= NULL
;
84 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
86 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
88 /* Validate that this is really a theme */
90 hr
= HRESULT_FROM_WIN32(GetLastError());
93 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), L
"PACKTHEM_VERSION"))) {
94 TRACE("No version resource found\n");
95 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
98 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
100 TRACE("Version resource found, but wrong size: %d\n", versize
);
101 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
104 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
105 if(version
!= MSSTYLES_VERSION
)
107 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
108 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
112 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), L
"COLORNAMES"))) {
113 TRACE("Color names resource not found\n");
114 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
117 pszColors
= LoadResource(hTheme
, hrsc
);
119 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), L
"SIZENAMES"))) {
120 TRACE("Size names resource not found\n");
121 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
124 pszSizes
= LoadResource(hTheme
, hrsc
);
126 /* Validate requested color against what's available from the theme */
130 if(!lstrcmpiW(pszColorName
, tmp
)) {
131 pszSelectedColor
= tmp
;
134 tmp
+= lstrlenW(tmp
)+1;
138 pszSelectedColor
= pszColors
; /* Use the default color */
140 /* Validate requested size against what's available from the theme */
144 if(!lstrcmpiW(pszSizeName
, tmp
)) {
145 pszSelectedSize
= tmp
;
148 tmp
+= lstrlenW(tmp
)+1;
152 pszSelectedSize
= pszSizes
; /* Use the default size */
154 if(!pszSelectedColor
|| !pszSelectedSize
) {
155 TRACE("Requested color/size (%s/%s) not found in theme\n",
156 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
157 hr
= E_PROP_ID_UNSUPPORTED
;
161 *tf
= heap_alloc_zero(sizeof(THEME_FILE
));
162 (*tf
)->hTheme
= hTheme
;
164 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
166 (*tf
)->pszAvailColors
= pszColors
;
167 (*tf
)->pszAvailSizes
= pszSizes
;
168 (*tf
)->pszSelectedColor
= pszSelectedColor
;
169 (*tf
)->pszSelectedSize
= pszSelectedSize
;
170 (*tf
)->dwRefCount
= 1;
175 if(hTheme
) FreeLibrary(hTheme
);
179 /***********************************************************************
180 * MSSTYLES_CloseThemeFile
182 * Close theme file and free resources
184 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
188 if(!tf
->dwRefCount
) {
189 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
192 PTHEME_CLASS pcls
= tf
->classes
;
193 tf
->classes
= pcls
->next
;
194 while(pcls
->partstate
) {
195 PTHEME_PARTSTATE ps
= pcls
->partstate
;
197 while(ps
->properties
) {
198 PTHEME_PROPERTY prop
= ps
->properties
;
199 ps
->properties
= prop
->next
;
203 pcls
->partstate
= ps
->next
;
211 PTHEME_IMAGE img
= tf
->images
;
212 tf
->images
= img
->next
;
213 DeleteObject (img
->image
);
221 /***********************************************************************
222 * MSSTYLES_SetActiveTheme
224 * Set the current active theme
226 HRESULT
MSSTYLES_SetActiveTheme(PTHEME_FILE tf
, BOOL setMetrics
)
229 MSSTYLES_CloseThemeFile(tfActiveTheme
);
233 tfActiveTheme
->dwRefCount
++;
234 if(!tfActiveTheme
->classes
)
235 MSSTYLES_ParseThemeIni(tfActiveTheme
, setMetrics
);
240 /***********************************************************************
241 * MSSTYLES_GetThemeIni
243 * Retrieves themes.ini from a theme
245 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
247 return UXINI_LoadINI(tf
->hTheme
, L
"themes_ini");
250 /***********************************************************************
251 * MSSTYLES_GetActiveThemeIni
253 * Retrieve the ini file for the selected color/style
255 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
257 DWORD dwColorCount
= 0;
258 DWORD dwSizeCount
= 0;
259 DWORD dwColorNum
= 0;
262 DWORD dwResourceIndex
;
266 /* Count the number of available colors & styles, and determine the index number
267 of the color/style we are interested in
269 tmp
= tf
->pszAvailColors
;
271 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
272 dwColorNum
= dwColorCount
;
273 tmp
+= lstrlenW(tmp
)+1;
276 tmp
= tf
->pszAvailSizes
;
278 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
279 dwSizeNum
= dwSizeCount
;
280 tmp
+= lstrlenW(tmp
)+1;
284 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), L
"FILERESNAMES"))) {
285 TRACE("FILERESNAMES map not found\n");
288 tmp
= LoadResource(tf
->hTheme
, hrsc
);
289 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
290 for(i
=0; i
< dwResourceIndex
; i
++) {
291 tmp
+= lstrlenW(tmp
)+1;
293 return UXINI_LoadINI(tf
->hTheme
, tmp
);
297 /***********************************************************************
298 * MSSTYLES_ParseIniSectionName
300 * Parse an ini section name into its component parts
305 * [classname.part(state)]
306 * [application::classname]
307 * [application::classname(state)]
308 * [application::classname.part]
309 * [application::classname.part(state)]
312 * lpSection Section name
313 * dwLen Length of section name
314 * szAppName Location to store application name
315 * szClassName Location to store class name
316 * iPartId Location to store part id
317 * iStateId Location to store state id
319 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
322 WCHAR part
[60] = {'\0'};
323 WCHAR state
[60] = {'\0'};
326 lstrcpynW(sec
, lpSection
, min(dwLen
+1, ARRAY_SIZE(sec
)));
333 /* Get the application name */
334 tmp
= wcschr(comp
, ':');
338 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
342 tmp
= wcschr(comp
, '.');
345 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
347 /* now get the part & state */
348 tmp
= wcschr(comp
, '(');
351 lstrcpynW(part
, comp
, ARRAY_SIZE(part
));
353 /* now get the state */
354 tmp
= wcschr(comp
, ')');
358 lstrcpynW(state
, comp
, ARRAY_SIZE(state
));
361 lstrcpynW(part
, comp
, ARRAY_SIZE(part
));
365 tmp
= wcschr(comp
, '(');
368 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
370 /* now get the state */
371 tmp
= wcschr(comp
, ')');
375 lstrcpynW(state
, comp
, ARRAY_SIZE(state
));
378 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
381 if(!*szClassName
) return FALSE
;
382 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
385 /***********************************************************************
392 * pszAppName App name to find
393 * pszClassName Class name to find
396 * The class found, or NULL
398 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
400 PTHEME_CLASS cur
= tf
->classes
;
403 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
407 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
415 /***********************************************************************
418 * Add a class to a theme file
422 * pszAppName App name to add
423 * pszClassName Class name to add
426 * The class added, or a class previously added with the same name
428 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
430 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
433 cur
= heap_alloc(sizeof(*cur
));
434 cur
->hTheme
= tf
->hTheme
;
435 lstrcpyW(cur
->szAppName
, pszAppName
);
436 lstrcpyW(cur
->szClassName
, pszClassName
);
437 cur
->next
= tf
->classes
;
438 cur
->partstate
= NULL
;
439 cur
->overrides
= NULL
;
444 /***********************************************************************
445 * MSSTYLES_FindPartState
451 * iPartId Part ID to find
452 * iStateId State ID to find
453 * tcNext Receives the next class in the override chain
456 * The part/state found, or NULL
458 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
460 PTHEME_PARTSTATE cur
= tc
->partstate
;
462 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
463 if(tcNext
) *tcNext
= tc
->overrides
;
468 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
472 /***********************************************************************
473 * MSSTYLES_AddPartState
475 * Add a part/state to a class
479 * iPartId Part ID to add
480 * iStateId State ID to add
483 * The part/state added, or a part/state previously added with the same IDs
485 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
487 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
490 cur
= heap_alloc(sizeof(*cur
));
491 cur
->iPartId
= iPartId
;
492 cur
->iStateId
= iStateId
;
493 cur
->properties
= NULL
;
494 cur
->next
= tc
->partstate
;
499 /***********************************************************************
500 * MSSTYLES_LFindProperty
502 * Find a property within a property list
505 * tp property list to scan
506 * iPropertyPrimitive Type of value expected
507 * iPropertyId ID of the required value
510 * The property found, or NULL
512 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
514 PTHEME_PROPERTY cur
= tp
;
516 if(cur
->iPropertyId
== iPropertyId
) {
517 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
521 if(!iPropertyPrimitive
)
531 /***********************************************************************
532 * MSSTYLES_PSFindProperty
534 * Find a value within a part/state
537 * ps Part/state to search
538 * iPropertyPrimitive Type of value expected
539 * iPropertyId ID of the required value
542 * The property found, or NULL
544 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
546 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
549 /***********************************************************************
550 * MSSTYLES_FFindMetric
552 * Find a metric property for a theme file
556 * iPropertyPrimitive Type of value expected
557 * iPropertyId ID of the required value
560 * The property found, or NULL
562 static inline PTHEME_PROPERTY
MSSTYLES_FFindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
564 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
567 /***********************************************************************
568 * MSSTYLES_FindMetric
570 * Find a metric property for the current installed theme
574 * iPropertyPrimitive Type of value expected
575 * iPropertyId ID of the required value
578 * The property found, or NULL
580 PTHEME_PROPERTY
MSSTYLES_FindMetric(int iPropertyPrimitive
, int iPropertyId
)
582 if(!tfActiveTheme
) return NULL
;
583 return MSSTYLES_FFindMetric(tfActiveTheme
, iPropertyPrimitive
, iPropertyId
);
586 /***********************************************************************
587 * MSSTYLES_AddProperty
589 * Add a property to a part/state
593 * iPropertyPrimitive Primitive type of the property
594 * iPropertyId ID of the property
595 * lpValue Raw value (non-NULL terminated)
596 * dwValueLen Length of the value
599 * The property added, or a property previously added with the same IDs
601 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
603 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
604 /* Should duplicate properties overwrite the original, or be ignored? */
607 cur
= heap_alloc(sizeof(*cur
));
608 cur
->iPrimitiveType
= iPropertyPrimitive
;
609 cur
->iPropertyId
= iPropertyId
;
610 cur
->lpValue
= lpValue
;
611 cur
->dwValueLen
= dwValueLen
;
614 cur
->origin
= PO_STATE
;
616 cur
->origin
= PO_PART
;
618 cur
->origin
= PO_GLOBAL
;
620 cur
->origin
= PO_CLASS
;
622 cur
->next
= ps
->properties
;
623 ps
->properties
= cur
;
627 /***********************************************************************
630 * Add a property to a part/state
634 * iPropertyPrimitive Primitive type of the property
635 * iPropertyId ID of the property
636 * lpValue Raw value (non-NULL terminated)
637 * dwValueLen Length of the value
640 * The property added, or a property previously added with the same IDs
642 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
644 PTHEME_PROPERTY cur
= MSSTYLES_FFindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
645 /* Should duplicate properties overwrite the original, or be ignored? */
648 cur
= heap_alloc(sizeof(*cur
));
649 cur
->iPrimitiveType
= iPropertyPrimitive
;
650 cur
->iPropertyId
= iPropertyId
;
651 cur
->lpValue
= lpValue
;
652 cur
->dwValueLen
= dwValueLen
;
654 cur
->origin
= PO_GLOBAL
;
656 cur
->next
= tf
->metrics
;
661 /* Color-related state for theme ini parsing */
662 struct PARSECOLORSTATE
665 int colorElements
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
666 COLORREF colorRgb
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
670 static inline void parse_init_color (struct PARSECOLORSTATE
* state
)
672 memset (state
, 0, sizeof (*state
));
675 static BOOL
parse_handle_color_property (struct PARSECOLORSTATE
* state
,
676 int iPropertyId
, LPCWSTR lpValue
,
680 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
681 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &r
) &&
682 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &g
) &&
683 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &b
)) {
684 state
->colorElements
[state
->colorCount
] = iPropertyId
- TMT_FIRSTCOLOR
;
685 state
->colorRgb
[state
->colorCount
++] = RGB(r
,g
,b
);
688 case TMT_ACTIVECAPTION
:
689 state
->captionColors
|= 0x1;
691 case TMT_INACTIVECAPTION
:
692 state
->captionColors
|= 0x2;
694 case TMT_GRADIENTACTIVECAPTION
:
695 state
->captionColors
|= 0x4;
697 case TMT_GRADIENTINACTIVECAPTION
:
698 state
->captionColors
|= 0x8;
708 static void parse_apply_color (struct PARSECOLORSTATE
* state
)
710 if (state
->colorCount
> 0)
711 SetSysColors(state
->colorCount
, state
->colorElements
, state
->colorRgb
);
712 if (state
->captionColors
== 0xf)
713 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS
, 0, (PVOID
)TRUE
, 0);
716 /* Non-client-metrics-related state for theme ini parsing */
717 struct PARSENONCLIENTSTATE
719 NONCLIENTMETRICSW metrics
;
721 LOGFONTW iconTitleFont
;
724 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE
* state
)
726 memset (state
, 0, sizeof (*state
));
727 state
->metrics
.cbSize
= sizeof (NONCLIENTMETRICSW
);
728 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (NONCLIENTMETRICSW
),
730 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (LOGFONTW
),
731 &state
->iconTitleFont
, 0);
734 static BOOL
parse_handle_nonclient_font (struct PARSENONCLIENTSTATE
* state
,
735 int iPropertyId
, LPCWSTR lpValue
,
740 memset (&font
, 0, sizeof (font
));
741 if (SUCCEEDED (MSSTYLES_GetFont (lpValue
, lpValue
+ dwValueLen
, &lpValue
,
746 case TMT_CAPTIONFONT
:
747 state
->metrics
.lfCaptionFont
= font
;
748 state
->metricsDirty
= TRUE
;
750 case TMT_SMALLCAPTIONFONT
:
751 state
->metrics
.lfSmCaptionFont
= font
;
752 state
->metricsDirty
= TRUE
;
755 state
->metrics
.lfMenuFont
= font
;
756 state
->metricsDirty
= TRUE
;
759 state
->metrics
.lfStatusFont
= font
;
760 state
->metricsDirty
= TRUE
;
763 state
->metrics
.lfMessageFont
= font
;
764 state
->metricsDirty
= TRUE
;
766 case TMT_ICONTITLEFONT
:
767 state
->iconTitleFont
= font
;
768 state
->metricsDirty
= TRUE
;
777 static BOOL
parse_handle_nonclient_size (struct PARSENONCLIENTSTATE
* state
,
778 int iPropertyId
, LPCWSTR lpValue
,
782 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
783 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &size
)) {
786 case TMT_SIZINGBORDERWIDTH
:
787 state
->metrics
.iBorderWidth
= size
;
788 state
->metricsDirty
= TRUE
;
790 case TMT_SCROLLBARWIDTH
:
791 state
->metrics
.iScrollWidth
= size
;
792 state
->metricsDirty
= TRUE
;
794 case TMT_SCROLLBARHEIGHT
:
795 state
->metrics
.iScrollHeight
= size
;
796 state
->metricsDirty
= TRUE
;
798 case TMT_CAPTIONBARWIDTH
:
799 state
->metrics
.iCaptionWidth
= size
;
800 state
->metricsDirty
= TRUE
;
802 case TMT_CAPTIONBARHEIGHT
:
803 state
->metrics
.iCaptionHeight
= size
;
804 state
->metricsDirty
= TRUE
;
806 case TMT_SMCAPTIONBARWIDTH
:
807 state
->metrics
.iSmCaptionWidth
= size
;
808 state
->metricsDirty
= TRUE
;
810 case TMT_SMCAPTIONBARHEIGHT
:
811 state
->metrics
.iSmCaptionHeight
= size
;
812 state
->metricsDirty
= TRUE
;
814 case TMT_MENUBARWIDTH
:
815 state
->metrics
.iMenuWidth
= size
;
816 state
->metricsDirty
= TRUE
;
818 case TMT_MENUBARHEIGHT
:
819 state
->metrics
.iMenuHeight
= size
;
820 state
->metricsDirty
= TRUE
;
829 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE
* state
)
831 if (state
->metricsDirty
)
833 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (state
->metrics
),
835 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (state
->iconTitleFont
),
836 &state
->iconTitleFont
, 0);
840 /***********************************************************************
841 * MSSTYLES_ParseThemeIni
843 * Parse the theme ini for the selected color/style
848 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
)
851 PTHEME_CLASS globals
;
854 WCHAR szAppName
[MAX_THEME_APP_NAME
];
855 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
856 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
859 int iPropertyPrimitive
;
866 ini
= MSSTYLES_GetActiveThemeIni(tf
);
868 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
))) {
869 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, L
"SysMetrics", -1) == CSTR_EQUAL
) {
870 struct PARSECOLORSTATE colorState
;
871 struct PARSENONCLIENTSTATE nonClientState
;
873 parse_init_color (&colorState
);
874 parse_init_nonclient (&nonClientState
);
876 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
877 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, ARRAY_SIZE(szPropertyName
)));
878 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
879 if(iPropertyId
>= TMT_FIRSTCOLOR
&& iPropertyId
<= TMT_LASTCOLOR
) {
880 if (!parse_handle_color_property (&colorState
, iPropertyId
,
881 lpValue
, dwValueLen
))
882 FIXME("Invalid color value for %s\n",
883 debugstr_w(szPropertyName
));
885 else if (setMetrics
&& (iPropertyId
== TMT_FLATMENUS
)) {
886 BOOL flatMenus
= (*lpValue
== 'T') || (*lpValue
== 't');
887 SystemParametersInfoW (SPI_SETFLATMENU
, 0, (PVOID
)(INT_PTR
)flatMenus
, 0);
889 else if ((iPropertyId
>= TMT_FIRSTFONT
)
890 && (iPropertyId
<= TMT_LASTFONT
))
892 if (!parse_handle_nonclient_font (&nonClientState
,
893 iPropertyId
, lpValue
, dwValueLen
))
894 FIXME("Invalid font value for %s\n",
895 debugstr_w(szPropertyName
));
897 else if ((iPropertyId
>= TMT_FIRSTSIZE
)
898 && (iPropertyId
<= TMT_LASTSIZE
))
900 if (!parse_handle_nonclient_size (&nonClientState
,
901 iPropertyId
, lpValue
, dwValueLen
))
902 FIXME("Invalid size value for %s\n",
903 debugstr_w(szPropertyName
));
905 /* Catch all metrics, including colors */
906 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
909 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
914 parse_apply_color (&colorState
);
915 parse_apply_nonclient (&nonClientState
);
919 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
)) {
920 BOOL isGlobal
= FALSE
;
921 if(!lstrcmpiW(szClassName
, L
"globals")) {
924 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
925 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
927 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
928 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, ARRAY_SIZE(szPropertyName
)));
929 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
930 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
933 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
939 /* App/Class combos override values defined by the base class, map these overrides */
940 globals
= MSSTYLES_FindClass(tf
, NULL
, L
"globals");
943 if(*cls
->szAppName
) {
944 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
945 if(!cls
->overrides
) {
946 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
949 cls
->overrides
= globals
;
953 /* Everything overrides globals..except globals */
954 if(cls
!= globals
) cls
->overrides
= globals
;
961 ERR("Failed to parse theme ini\n");
965 /***********************************************************************
966 * MSSTYLES_OpenThemeClass
968 * Open a theme class, uses the current active theme
971 * pszAppName Application name, for theme styles specific
972 * to a particular application
973 * pszClassList List of requested classes, semicolon delimited
975 PTHEME_CLASS
MSSTYLES_OpenThemeClass(LPCWSTR pszAppName
, LPCWSTR pszClassList
)
977 PTHEME_CLASS cls
= NULL
;
978 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
984 TRACE("there is no active theme\n");
987 if(!tfActiveTheme
->classes
) {
991 start
= pszClassList
;
992 while((end
= wcschr(start
, ';'))) {
994 lstrcpynW(szClassName
, start
, min(len
+1, ARRAY_SIZE(szClassName
)));
996 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1000 lstrcpynW(szClassName
, start
, ARRAY_SIZE(szClassName
));
1001 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1004 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
1005 cls
->tf
= tfActiveTheme
;
1006 cls
->tf
->dwRefCount
++;
1011 /***********************************************************************
1012 * MSSTYLES_CloseThemeClass
1014 * Close a theme class
1017 * tc Theme class to close
1020 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1021 * theme file and cleans it up, if needed.
1023 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
1025 MSSTYLES_CloseThemeFile (tc
->tf
);
1029 /***********************************************************************
1030 * MSSTYLES_FindProperty
1032 * Locate a property in a class. Part and state IDs will be used as a
1033 * preference, but may be ignored in the attempt to locate the property.
1034 * Will scan the entire chain of overrides for this class.
1036 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
1038 PTHEME_CLASS next
= tc
;
1039 PTHEME_PARTSTATE ps
;
1042 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
1043 /* Try and find an exact match on part & state */
1044 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
1045 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
1049 /* If that fails, and we didn't already try it, search for just part */
1052 /* As a last ditch attempt..go for just class */
1053 else if(iPartId
!= 0)
1058 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
1063 /* Prepare a bitmap to be used for alpha blending */
1064 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
1072 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
1075 if(dib
.dsBm
.bmBitsPixel
!= 32)
1080 p
= dib
.dsBm
.bmBits
;
1081 n
= dib
.dsBmih
.biHeight
* dib
.dsBmih
.biWidth
;
1082 /* AlphaBlend() wants premultiplied alpha, so do that now */
1086 p
[0] = (p
[0] * a
) >> 8;
1087 p
[1] = (p
[1] * a
) >> 8;
1088 p
[2] = (p
[2] * a
) >> 8;
1095 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
1097 WCHAR szFile
[MAX_PATH
];
1100 lstrcpynW(szFile
, lpFilename
, ARRAY_SIZE(szFile
));
1103 if(*tmp
== '\\') *tmp
= '_';
1104 if(*tmp
== '/') *tmp
= '_';
1105 if(*tmp
== '.') *tmp
= '_';
1108 /* Try to locate in list of loaded images */
1109 img
= tc
->tf
->images
;
1112 if (lstrcmpiW (szFile
, img
->name
) == 0)
1114 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1115 *hasAlpha
= img
->hasAlpha
;
1120 /* Not found? Load from resources */
1121 img
= heap_alloc(sizeof(*img
));
1122 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
1123 prepare_alpha (img
->image
, hasAlpha
);
1124 img
->hasAlpha
= *hasAlpha
;
1125 /* ...and stow away for later reuse. */
1126 lstrcpyW (img
->name
, szFile
);
1127 img
->next
= tc
->tf
->images
;
1128 tc
->tf
->images
= img
;
1129 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1133 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
1135 LPCWSTR cur
= lpStringStart
;
1137 BOOL gotNeg
= FALSE
;
1139 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
1140 if(cur
>= lpStringEnd
) {
1147 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
1148 total
= total
* 10 + (*cur
- '0');
1151 if(gotNeg
) total
= -total
;
1153 if(lpValEnd
) *lpValEnd
= cur
;
1157 static inline BOOL
isSpace(WCHAR c
)
1159 return c
== ' ' || c
== '\f' || c
== '\n' || c
== '\r' || c
== '\t' || c
== '\v';
1162 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
1163 LPCWSTR cur
= lpStringStart
;
1167 while(cur
< lpStringEnd
&& (isSpace(*cur
) || *cur
== ',')) cur
++;
1168 if(cur
>= lpStringEnd
) {
1172 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
1174 while(isSpace(*end
)) end
--;
1176 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
1178 if(lpValEnd
) *lpValEnd
= cur
;
1182 /***********************************************************************
1183 * MSSTYLES_GetPropertyBool
1185 * Retrieve a color value for a property
1187 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
1190 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
1195 /***********************************************************************
1196 * MSSTYLES_GetPropertyColor
1198 * Retrieve a color value for a property
1200 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
1204 int red
, green
, blue
;
1206 lpCur
= tp
->lpValue
;
1207 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1209 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
)) {
1210 TRACE("Could not parse color property\n");
1211 return E_PROP_ID_UNSUPPORTED
;
1213 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
)) {
1214 TRACE("Could not parse color property\n");
1215 return E_PROP_ID_UNSUPPORTED
;
1217 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
1218 TRACE("Could not parse color property\n");
1219 return E_PROP_ID_UNSUPPORTED
;
1221 *pColor
= RGB(red
,green
,blue
);
1225 /***********************************************************************
1226 * MSSTYLES_GetPropertyColor
1228 * Retrieve a color value for a property
1230 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1231 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1236 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1237 TRACE("Property is there, but failed to get face name\n");
1239 return E_PROP_ID_UNSUPPORTED
;
1241 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1242 TRACE("Property is there, but failed to get point size\n");
1244 return E_PROP_ID_UNSUPPORTED
;
1246 pFont
->lfHeight
= pointSize
;
1247 pFont
->lfWeight
= FW_REGULAR
;
1248 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1249 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, ARRAY_SIZE(attr
))) {
1250 if(!lstrcmpiW(L
"bold", attr
)) pFont
->lfWeight
= FW_BOLD
;
1251 else if(!lstrcmpiW(L
"italic", attr
)) pFont
->lfItalic
= TRUE
;
1252 else if(!lstrcmpiW(L
"underline", attr
)) pFont
->lfUnderline
= TRUE
;
1253 else if(!lstrcmpiW(L
"strikeout", attr
)) pFont
->lfStrikeOut
= TRUE
;
1259 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1261 LPCWSTR lpCur
= tp
->lpValue
;
1262 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1265 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1266 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1268 pFont
->lfHeight
= -MulDiv(pFont
->lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1273 /***********************************************************************
1274 * MSSTYLES_GetPropertyInt
1276 * Retrieve an int value for a property
1278 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1280 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1281 TRACE("Could not parse int property\n");
1282 return E_PROP_ID_UNSUPPORTED
;
1287 /***********************************************************************
1288 * MSSTYLES_GetPropertyIntList
1290 * Retrieve an int list value for a property
1292 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1295 LPCWSTR lpCur
= tp
->lpValue
;
1296 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1298 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1299 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1302 pIntList
->iValueCount
= i
;
1306 /***********************************************************************
1307 * MSSTYLES_GetPropertyPosition
1309 * Retrieve a position value for a property
1311 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1314 LPCWSTR lpCur
= tp
->lpValue
;
1315 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1317 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
)) {
1318 TRACE("Could not parse position property\n");
1319 return E_PROP_ID_UNSUPPORTED
;
1321 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1322 TRACE("Could not parse position property\n");
1323 return E_PROP_ID_UNSUPPORTED
;
1330 /***********************************************************************
1331 * MSSTYLES_GetPropertyString
1333 * Retrieve a string value for a property
1335 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1337 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1341 /***********************************************************************
1342 * MSSTYLES_GetPropertyRect
1344 * Retrieve a rect value for a property
1346 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1348 LPCWSTR lpCur
= tp
->lpValue
;
1349 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1351 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->left
);
1352 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->top
);
1353 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->right
);
1354 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->bottom
)) {
1355 TRACE("Could not parse rect property\n");
1356 return E_PROP_ID_UNSUPPORTED
;
1361 /***********************************************************************
1362 * MSSTYLES_GetPropertyMargins
1364 * Retrieve a margins value for a property
1366 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1368 LPCWSTR lpCur
= tp
->lpValue
;
1369 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1371 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1372 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1373 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1374 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1375 TRACE("Could not parse margins property\n");
1376 return E_PROP_ID_UNSUPPORTED
;