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 extern int alphaBlendMode
;
51 #define MSSTYLES_VERSION 0x0003
53 static const WCHAR szThemesIniResource
[] = {
54 't','h','e','m','e','s','_','i','n','i','\0'
57 static PTHEME_FILE tfActiveTheme
;
59 /***********************************************************************/
61 /**********************************************************************
62 * MSSTYLES_OpenThemeFile
64 * Load and validate a theme
67 * lpThemeFile Path to theme file to load
68 * pszColorName Color name wanted, can be NULL
69 * pszSizeName Size name wanted, can be NULL
72 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
73 * If one/both are provided, they are validated against valid color/sizes and if
74 * a match is not found, the function fails.
76 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
81 static const WCHAR szPackThemVersionResource
[] = {
82 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
84 static const WCHAR szColorNamesResource
[] = {
85 'C','O','L','O','R','N','A','M','E','S','\0'
87 static const WCHAR szSizeNamesResource
[] = {
88 'S','I','Z','E','N','A','M','E','S','\0'
94 LPWSTR pszSelectedColor
= NULL
;
96 LPWSTR pszSelectedSize
= NULL
;
99 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
101 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
103 /* Validate that this is really a theme */
105 hr
= HRESULT_FROM_WIN32(GetLastError());
108 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szPackThemVersionResource
))) {
109 TRACE("No version resource found\n");
110 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
113 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
115 TRACE("Version resource found, but wrong size: %d\n", versize
);
116 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
119 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
120 if(version
!= MSSTYLES_VERSION
)
122 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
123 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
127 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szColorNamesResource
))) {
128 TRACE("Color names resource not found\n");
129 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
132 pszColors
= LoadResource(hTheme
, hrsc
);
134 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szSizeNamesResource
))) {
135 TRACE("Size names resource not found\n");
136 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
139 pszSizes
= LoadResource(hTheme
, hrsc
);
141 /* Validate requested color against what's available from the theme */
145 if(!lstrcmpiW(pszColorName
, tmp
)) {
146 pszSelectedColor
= tmp
;
149 tmp
+= lstrlenW(tmp
)+1;
153 pszSelectedColor
= pszColors
; /* Use the default color */
155 /* Validate requested size against what's available from the theme */
159 if(!lstrcmpiW(pszSizeName
, tmp
)) {
160 pszSelectedSize
= tmp
;
163 tmp
+= lstrlenW(tmp
)+1;
167 pszSelectedSize
= pszSizes
; /* Use the default size */
169 if(!pszSelectedColor
|| !pszSelectedSize
) {
170 TRACE("Requested color/size (%s/%s) not found in theme\n",
171 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
172 hr
= E_PROP_ID_UNSUPPORTED
;
176 *tf
= heap_alloc_zero(sizeof(THEME_FILE
));
177 (*tf
)->hTheme
= hTheme
;
179 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
181 (*tf
)->pszAvailColors
= pszColors
;
182 (*tf
)->pszAvailSizes
= pszSizes
;
183 (*tf
)->pszSelectedColor
= pszSelectedColor
;
184 (*tf
)->pszSelectedSize
= pszSelectedSize
;
185 (*tf
)->dwRefCount
= 1;
190 if(hTheme
) FreeLibrary(hTheme
);
194 /***********************************************************************
195 * MSSTYLES_CloseThemeFile
197 * Close theme file and free resources
199 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
203 if(!tf
->dwRefCount
) {
204 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
207 PTHEME_CLASS pcls
= tf
->classes
;
208 tf
->classes
= pcls
->next
;
209 while(pcls
->partstate
) {
210 PTHEME_PARTSTATE ps
= pcls
->partstate
;
212 while(ps
->properties
) {
213 PTHEME_PROPERTY prop
= ps
->properties
;
214 ps
->properties
= prop
->next
;
218 pcls
->partstate
= ps
->next
;
226 PTHEME_IMAGE img
= tf
->images
;
227 tf
->images
= img
->next
;
228 DeleteObject (img
->image
);
236 /***********************************************************************
237 * MSSTYLES_SetActiveTheme
239 * Set the current active theme
241 HRESULT
MSSTYLES_SetActiveTheme(PTHEME_FILE tf
, BOOL setMetrics
)
244 MSSTYLES_CloseThemeFile(tfActiveTheme
);
248 tfActiveTheme
->dwRefCount
++;
249 if(!tfActiveTheme
->classes
)
250 MSSTYLES_ParseThemeIni(tfActiveTheme
, setMetrics
);
255 /***********************************************************************
256 * MSSTYLES_GetThemeIni
258 * Retrieves themes.ini from a theme
260 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
262 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
265 /***********************************************************************
266 * MSSTYLES_GetActiveThemeIni
268 * Retrieve the ini file for the selected color/style
270 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
272 static const WCHAR szFileResNamesResource
[] = {
273 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
275 DWORD dwColorCount
= 0;
276 DWORD dwSizeCount
= 0;
277 DWORD dwColorNum
= 0;
280 DWORD dwResourceIndex
;
284 /* Count the number of available colors & styles, and determine the index number
285 of the color/style we are interested in
287 tmp
= tf
->pszAvailColors
;
289 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
290 dwColorNum
= dwColorCount
;
291 tmp
+= lstrlenW(tmp
)+1;
294 tmp
= tf
->pszAvailSizes
;
296 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
297 dwSizeNum
= dwSizeCount
;
298 tmp
+= lstrlenW(tmp
)+1;
302 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
303 TRACE("FILERESNAMES map not found\n");
306 tmp
= LoadResource(tf
->hTheme
, hrsc
);
307 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
308 for(i
=0; i
< dwResourceIndex
; i
++) {
309 tmp
+= lstrlenW(tmp
)+1;
311 return UXINI_LoadINI(tf
->hTheme
, tmp
);
315 /***********************************************************************
316 * MSSTYLES_ParseIniSectionName
318 * Parse an ini section name into its component parts
323 * [classname.part(state)]
324 * [application::classname]
325 * [application::classname(state)]
326 * [application::classname.part]
327 * [application::classname.part(state)]
330 * lpSection Section name
331 * dwLen Length of section name
332 * szAppName Location to store application name
333 * szClassName Location to store class name
334 * iPartId Location to store part id
335 * iStateId Location to store state id
337 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
340 WCHAR part
[60] = {'\0'};
341 WCHAR state
[60] = {'\0'};
344 lstrcpynW(sec
, lpSection
, min(dwLen
+1, ARRAY_SIZE(sec
)));
351 /* Get the application name */
352 tmp
= wcschr(comp
, ':');
356 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
360 tmp
= wcschr(comp
, '.');
363 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
365 /* now get the part & state */
366 tmp
= wcschr(comp
, '(');
369 lstrcpynW(part
, comp
, ARRAY_SIZE(part
));
371 /* now get the state */
372 tmp
= wcschr(comp
, ')');
376 lstrcpynW(state
, comp
, ARRAY_SIZE(state
));
379 lstrcpynW(part
, comp
, ARRAY_SIZE(part
));
383 tmp
= wcschr(comp
, '(');
386 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
388 /* now get the state */
389 tmp
= wcschr(comp
, ')');
393 lstrcpynW(state
, comp
, ARRAY_SIZE(state
));
396 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
399 if(!*szClassName
) return FALSE
;
400 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
403 /***********************************************************************
410 * pszAppName App name to find
411 * pszClassName Class name to find
414 * The class found, or NULL
416 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
418 PTHEME_CLASS cur
= tf
->classes
;
421 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
425 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
433 /***********************************************************************
436 * Add a class to a theme file
440 * pszAppName App name to add
441 * pszClassName Class name to add
444 * The class added, or a class previously added with the same name
446 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
448 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
451 cur
= heap_alloc(sizeof(*cur
));
452 cur
->hTheme
= tf
->hTheme
;
453 lstrcpyW(cur
->szAppName
, pszAppName
);
454 lstrcpyW(cur
->szClassName
, pszClassName
);
455 cur
->next
= tf
->classes
;
456 cur
->partstate
= NULL
;
457 cur
->overrides
= NULL
;
462 /***********************************************************************
463 * MSSTYLES_FindPartState
469 * iPartId Part ID to find
470 * iStateId State ID to find
471 * tcNext Receives the next class in the override chain
474 * The part/state found, or NULL
476 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
478 PTHEME_PARTSTATE cur
= tc
->partstate
;
480 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
481 if(tcNext
) *tcNext
= tc
->overrides
;
486 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
490 /***********************************************************************
491 * MSSTYLES_AddPartState
493 * Add a part/state to a class
497 * iPartId Part ID to add
498 * iStateId State ID to add
501 * The part/state added, or a part/state previously added with the same IDs
503 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
505 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
508 cur
= heap_alloc(sizeof(*cur
));
509 cur
->iPartId
= iPartId
;
510 cur
->iStateId
= iStateId
;
511 cur
->properties
= NULL
;
512 cur
->next
= tc
->partstate
;
517 /***********************************************************************
518 * MSSTYLES_LFindProperty
520 * Find a property within a property list
523 * tp property list to scan
524 * iPropertyPrimitive Type of value expected
525 * iPropertyId ID of the required value
528 * The property found, or NULL
530 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
532 PTHEME_PROPERTY cur
= tp
;
534 if(cur
->iPropertyId
== iPropertyId
) {
535 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
539 if(!iPropertyPrimitive
)
549 /***********************************************************************
550 * MSSTYLES_PSFindProperty
552 * Find a value within a part/state
555 * ps Part/state to search
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_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
564 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
567 /***********************************************************************
568 * MSSTYLES_FFindMetric
570 * Find a metric property for a theme file
574 * iPropertyPrimitive Type of value expected
575 * iPropertyId ID of the required value
578 * The property found, or NULL
580 static inline PTHEME_PROPERTY
MSSTYLES_FFindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
582 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
585 /***********************************************************************
586 * MSSTYLES_FindMetric
588 * Find a metric property for the current installed theme
592 * iPropertyPrimitive Type of value expected
593 * iPropertyId ID of the required value
596 * The property found, or NULL
598 PTHEME_PROPERTY
MSSTYLES_FindMetric(int iPropertyPrimitive
, int iPropertyId
)
600 if(!tfActiveTheme
) return NULL
;
601 return MSSTYLES_FFindMetric(tfActiveTheme
, iPropertyPrimitive
, iPropertyId
);
604 /***********************************************************************
605 * MSSTYLES_AddProperty
607 * Add a property to a part/state
611 * iPropertyPrimitive Primitive type of the property
612 * iPropertyId ID of the property
613 * lpValue Raw value (non-NULL terminated)
614 * dwValueLen Length of the value
617 * The property added, or a property previously added with the same IDs
619 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
621 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
622 /* Should duplicate properties overwrite the original, or be ignored? */
625 cur
= heap_alloc(sizeof(*cur
));
626 cur
->iPrimitiveType
= iPropertyPrimitive
;
627 cur
->iPropertyId
= iPropertyId
;
628 cur
->lpValue
= lpValue
;
629 cur
->dwValueLen
= dwValueLen
;
632 cur
->origin
= PO_STATE
;
634 cur
->origin
= PO_PART
;
636 cur
->origin
= PO_GLOBAL
;
638 cur
->origin
= PO_CLASS
;
640 cur
->next
= ps
->properties
;
641 ps
->properties
= cur
;
645 /***********************************************************************
648 * Add a property to a part/state
652 * iPropertyPrimitive Primitive type of the property
653 * iPropertyId ID of the property
654 * lpValue Raw value (non-NULL terminated)
655 * dwValueLen Length of the value
658 * The property added, or a property previously added with the same IDs
660 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
662 PTHEME_PROPERTY cur
= MSSTYLES_FFindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
663 /* Should duplicate properties overwrite the original, or be ignored? */
666 cur
= heap_alloc(sizeof(*cur
));
667 cur
->iPrimitiveType
= iPropertyPrimitive
;
668 cur
->iPropertyId
= iPropertyId
;
669 cur
->lpValue
= lpValue
;
670 cur
->dwValueLen
= dwValueLen
;
672 cur
->origin
= PO_GLOBAL
;
674 cur
->next
= tf
->metrics
;
679 /* Color-related state for theme ini parsing */
680 struct PARSECOLORSTATE
683 int colorElements
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
684 COLORREF colorRgb
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
688 static inline void parse_init_color (struct PARSECOLORSTATE
* state
)
690 memset (state
, 0, sizeof (*state
));
693 static BOOL
parse_handle_color_property (struct PARSECOLORSTATE
* state
,
694 int iPropertyId
, LPCWSTR lpValue
,
698 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
699 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &r
) &&
700 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &g
) &&
701 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &b
)) {
702 state
->colorElements
[state
->colorCount
] = iPropertyId
- TMT_FIRSTCOLOR
;
703 state
->colorRgb
[state
->colorCount
++] = RGB(r
,g
,b
);
706 case TMT_ACTIVECAPTION
:
707 state
->captionColors
|= 0x1;
709 case TMT_INACTIVECAPTION
:
710 state
->captionColors
|= 0x2;
712 case TMT_GRADIENTACTIVECAPTION
:
713 state
->captionColors
|= 0x4;
715 case TMT_GRADIENTINACTIVECAPTION
:
716 state
->captionColors
|= 0x8;
726 static void parse_apply_color (struct PARSECOLORSTATE
* state
)
728 if (state
->colorCount
> 0)
729 SetSysColors(state
->colorCount
, state
->colorElements
, state
->colorRgb
);
730 if (state
->captionColors
== 0xf)
731 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS
, 0, (PVOID
)TRUE
, 0);
734 /* Non-client-metrics-related state for theme ini parsing */
735 struct PARSENONCLIENTSTATE
737 NONCLIENTMETRICSW metrics
;
739 LOGFONTW iconTitleFont
;
742 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE
* state
)
744 memset (state
, 0, sizeof (*state
));
745 state
->metrics
.cbSize
= sizeof (NONCLIENTMETRICSW
);
746 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (NONCLIENTMETRICSW
),
748 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (LOGFONTW
),
749 &state
->iconTitleFont
, 0);
752 static BOOL
parse_handle_nonclient_font (struct PARSENONCLIENTSTATE
* state
,
753 int iPropertyId
, LPCWSTR lpValue
,
758 memset (&font
, 0, sizeof (font
));
759 if (SUCCEEDED (MSSTYLES_GetFont (lpValue
, lpValue
+ dwValueLen
, &lpValue
,
764 case TMT_CAPTIONFONT
:
765 state
->metrics
.lfCaptionFont
= font
;
766 state
->metricsDirty
= TRUE
;
768 case TMT_SMALLCAPTIONFONT
:
769 state
->metrics
.lfSmCaptionFont
= font
;
770 state
->metricsDirty
= TRUE
;
773 state
->metrics
.lfMenuFont
= font
;
774 state
->metricsDirty
= TRUE
;
777 state
->metrics
.lfStatusFont
= font
;
778 state
->metricsDirty
= TRUE
;
781 state
->metrics
.lfMessageFont
= font
;
782 state
->metricsDirty
= TRUE
;
784 case TMT_ICONTITLEFONT
:
785 state
->iconTitleFont
= font
;
786 state
->metricsDirty
= TRUE
;
795 static BOOL
parse_handle_nonclient_size (struct PARSENONCLIENTSTATE
* state
,
796 int iPropertyId
, LPCWSTR lpValue
,
800 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
801 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &size
)) {
804 case TMT_SIZINGBORDERWIDTH
:
805 state
->metrics
.iBorderWidth
= size
;
806 state
->metricsDirty
= TRUE
;
808 case TMT_SCROLLBARWIDTH
:
809 state
->metrics
.iScrollWidth
= size
;
810 state
->metricsDirty
= TRUE
;
812 case TMT_SCROLLBARHEIGHT
:
813 state
->metrics
.iScrollHeight
= size
;
814 state
->metricsDirty
= TRUE
;
816 case TMT_CAPTIONBARWIDTH
:
817 state
->metrics
.iCaptionWidth
= size
;
818 state
->metricsDirty
= TRUE
;
820 case TMT_CAPTIONBARHEIGHT
:
821 state
->metrics
.iCaptionHeight
= size
;
822 state
->metricsDirty
= TRUE
;
824 case TMT_SMCAPTIONBARWIDTH
:
825 state
->metrics
.iSmCaptionWidth
= size
;
826 state
->metricsDirty
= TRUE
;
828 case TMT_SMCAPTIONBARHEIGHT
:
829 state
->metrics
.iSmCaptionHeight
= size
;
830 state
->metricsDirty
= TRUE
;
832 case TMT_MENUBARWIDTH
:
833 state
->metrics
.iMenuWidth
= size
;
834 state
->metricsDirty
= TRUE
;
836 case TMT_MENUBARHEIGHT
:
837 state
->metrics
.iMenuHeight
= size
;
838 state
->metricsDirty
= TRUE
;
847 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE
* state
)
849 if (state
->metricsDirty
)
851 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (state
->metrics
),
853 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (state
->iconTitleFont
),
854 &state
->iconTitleFont
, 0);
858 /***********************************************************************
859 * MSSTYLES_ParseThemeIni
861 * Parse the theme ini for the selected color/style
866 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
)
868 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
869 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
871 PTHEME_CLASS globals
;
874 WCHAR szAppName
[MAX_THEME_APP_NAME
];
875 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
876 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
879 int iPropertyPrimitive
;
886 ini
= MSSTYLES_GetActiveThemeIni(tf
);
888 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
))) {
889 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
) {
890 struct PARSECOLORSTATE colorState
;
891 struct PARSENONCLIENTSTATE nonClientState
;
893 parse_init_color (&colorState
);
894 parse_init_nonclient (&nonClientState
);
896 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
897 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, ARRAY_SIZE(szPropertyName
)));
898 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
899 if(iPropertyId
>= TMT_FIRSTCOLOR
&& iPropertyId
<= TMT_LASTCOLOR
) {
900 if (!parse_handle_color_property (&colorState
, iPropertyId
,
901 lpValue
, dwValueLen
))
902 FIXME("Invalid color value for %s\n",
903 debugstr_w(szPropertyName
));
905 else if (setMetrics
&& (iPropertyId
== TMT_FLATMENUS
)) {
906 BOOL flatMenus
= (*lpValue
== 'T') || (*lpValue
== 't');
907 SystemParametersInfoW (SPI_SETFLATMENU
, 0, (PVOID
)(INT_PTR
)flatMenus
, 0);
909 else if ((iPropertyId
>= TMT_FIRSTFONT
)
910 && (iPropertyId
<= TMT_LASTFONT
))
912 if (!parse_handle_nonclient_font (&nonClientState
,
913 iPropertyId
, lpValue
, dwValueLen
))
914 FIXME("Invalid font value for %s\n",
915 debugstr_w(szPropertyName
));
917 else if ((iPropertyId
>= TMT_FIRSTSIZE
)
918 && (iPropertyId
<= TMT_LASTSIZE
))
920 if (!parse_handle_nonclient_size (&nonClientState
,
921 iPropertyId
, lpValue
, dwValueLen
))
922 FIXME("Invalid size value for %s\n",
923 debugstr_w(szPropertyName
));
925 /* Catch all metrics, including colors */
926 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
929 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
934 parse_apply_color (&colorState
);
935 parse_apply_nonclient (&nonClientState
);
939 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
)) {
940 BOOL isGlobal
= FALSE
;
941 if(!lstrcmpiW(szClassName
, szGlobals
)) {
944 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
945 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
947 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
948 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, ARRAY_SIZE(szPropertyName
)));
949 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
950 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
953 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
959 /* App/Class combos override values defined by the base class, map these overrides */
960 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
963 if(*cls
->szAppName
) {
964 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
965 if(!cls
->overrides
) {
966 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
969 cls
->overrides
= globals
;
973 /* Everything overrides globals..except globals */
974 if(cls
!= globals
) cls
->overrides
= globals
;
981 ERR("Failed to parse theme ini\n");
985 /***********************************************************************
986 * MSSTYLES_OpenThemeClass
988 * Open a theme class, uses the current active theme
991 * pszAppName Application name, for theme styles specific
992 * to a particular application
993 * pszClassList List of requested classes, semicolon delimited
995 PTHEME_CLASS
MSSTYLES_OpenThemeClass(LPCWSTR pszAppName
, LPCWSTR pszClassList
)
997 PTHEME_CLASS cls
= NULL
;
998 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
1003 if(!tfActiveTheme
) {
1004 TRACE("there is no active theme\n");
1007 if(!tfActiveTheme
->classes
) {
1011 start
= pszClassList
;
1012 while((end
= wcschr(start
, ';'))) {
1014 lstrcpynW(szClassName
, start
, min(len
+1, ARRAY_SIZE(szClassName
)));
1016 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1019 if(!cls
&& *start
) {
1020 lstrcpynW(szClassName
, start
, ARRAY_SIZE(szClassName
));
1021 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1024 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
1025 cls
->tf
= tfActiveTheme
;
1026 cls
->tf
->dwRefCount
++;
1031 /***********************************************************************
1032 * MSSTYLES_CloseThemeClass
1034 * Close a theme class
1037 * tc Theme class to close
1040 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1041 * theme file and cleans it up, if needed.
1043 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
1045 MSSTYLES_CloseThemeFile (tc
->tf
);
1049 /***********************************************************************
1050 * MSSTYLES_FindProperty
1052 * Locate a property in a class. Part and state IDs will be used as a
1053 * preference, but may be ignored in the attempt to locate the property.
1054 * Will scan the entire chain of overrides for this class.
1056 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
1058 PTHEME_CLASS next
= tc
;
1059 PTHEME_PARTSTATE ps
;
1062 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
1063 /* Try and find an exact match on part & state */
1064 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
1065 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
1069 /* If that fails, and we didn't already try it, search for just part */
1072 /* As a last ditch attempt..go for just class */
1073 else if(iPartId
!= 0)
1078 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
1083 /* Prepare a bitmap to be used for alpha blending */
1084 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
1092 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
1095 if(dib
.dsBm
.bmBitsPixel
!= 32)
1100 p
= dib
.dsBm
.bmBits
;
1101 n
= dib
.dsBmih
.biHeight
* dib
.dsBmih
.biWidth
;
1102 /* AlphaBlend() wants premultiplied alpha, so do that now */
1106 p
[0] = (p
[0] * a
) >> 8;
1107 p
[1] = (p
[1] * a
) >> 8;
1108 p
[2] = (p
[2] * a
) >> 8;
1115 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
1117 WCHAR szFile
[MAX_PATH
];
1120 lstrcpynW(szFile
, lpFilename
, ARRAY_SIZE(szFile
));
1123 if(*tmp
== '\\') *tmp
= '_';
1124 if(*tmp
== '/') *tmp
= '_';
1125 if(*tmp
== '.') *tmp
= '_';
1128 /* Try to locate in list of loaded images */
1129 img
= tc
->tf
->images
;
1132 if (lstrcmpiW (szFile
, img
->name
) == 0)
1134 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1135 *hasAlpha
= img
->hasAlpha
;
1140 /* Not found? Load from resources */
1141 img
= heap_alloc(sizeof(*img
));
1142 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
1143 prepare_alpha (img
->image
, hasAlpha
);
1144 img
->hasAlpha
= *hasAlpha
;
1145 /* ...and stow away for later reuse. */
1146 lstrcpyW (img
->name
, szFile
);
1147 img
->next
= tc
->tf
->images
;
1148 tc
->tf
->images
= img
;
1149 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1153 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
1155 LPCWSTR cur
= lpStringStart
;
1157 BOOL gotNeg
= FALSE
;
1159 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
1160 if(cur
>= lpStringEnd
) {
1167 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
1168 total
= total
* 10 + (*cur
- '0');
1171 if(gotNeg
) total
= -total
;
1173 if(lpValEnd
) *lpValEnd
= cur
;
1177 static inline BOOL
isSpace(WCHAR c
)
1179 return c
== ' ' || c
== '\f' || c
== '\n' || c
== '\r' || c
== '\t' || c
== '\v';
1182 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
1183 LPCWSTR cur
= lpStringStart
;
1187 while(cur
< lpStringEnd
&& (isSpace(*cur
) || *cur
== ',')) cur
++;
1188 if(cur
>= lpStringEnd
) {
1192 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
1194 while(isSpace(*end
)) end
--;
1196 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
1198 if(lpValEnd
) *lpValEnd
= cur
;
1202 /***********************************************************************
1203 * MSSTYLES_GetPropertyBool
1205 * Retrieve a color value for a property
1207 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
1210 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
1215 /***********************************************************************
1216 * MSSTYLES_GetPropertyColor
1218 * Retrieve a color value for a property
1220 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
1224 int red
, green
, blue
;
1226 lpCur
= tp
->lpValue
;
1227 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1229 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
)) {
1230 TRACE("Could not parse color property\n");
1231 return E_PROP_ID_UNSUPPORTED
;
1233 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
)) {
1234 TRACE("Could not parse color property\n");
1235 return E_PROP_ID_UNSUPPORTED
;
1237 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
1238 TRACE("Could not parse color property\n");
1239 return E_PROP_ID_UNSUPPORTED
;
1241 *pColor
= RGB(red
,green
,blue
);
1245 /***********************************************************************
1246 * MSSTYLES_GetPropertyColor
1248 * Retrieve a color value for a property
1250 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1251 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1253 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
1254 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
1255 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
1256 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
1260 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1261 TRACE("Property is there, but failed to get face name\n");
1263 return E_PROP_ID_UNSUPPORTED
;
1265 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1266 TRACE("Property is there, but failed to get point size\n");
1268 return E_PROP_ID_UNSUPPORTED
;
1270 pFont
->lfHeight
= pointSize
;
1271 pFont
->lfWeight
= FW_REGULAR
;
1272 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1273 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, ARRAY_SIZE(attr
))) {
1274 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
1275 else if(!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
1276 else if(!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
1277 else if(!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
1283 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1285 LPCWSTR lpCur
= tp
->lpValue
;
1286 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1289 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1290 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1292 pFont
->lfHeight
= -MulDiv(pFont
->lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1297 /***********************************************************************
1298 * MSSTYLES_GetPropertyInt
1300 * Retrieve an int value for a property
1302 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1304 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1305 TRACE("Could not parse int property\n");
1306 return E_PROP_ID_UNSUPPORTED
;
1311 /***********************************************************************
1312 * MSSTYLES_GetPropertyIntList
1314 * Retrieve an int list value for a property
1316 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1319 LPCWSTR lpCur
= tp
->lpValue
;
1320 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1322 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1323 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1326 pIntList
->iValueCount
= i
;
1330 /***********************************************************************
1331 * MSSTYLES_GetPropertyPosition
1333 * Retrieve a position value for a property
1335 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1338 LPCWSTR lpCur
= tp
->lpValue
;
1339 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1341 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
)) {
1342 TRACE("Could not parse position property\n");
1343 return E_PROP_ID_UNSUPPORTED
;
1345 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1346 TRACE("Could not parse position property\n");
1347 return E_PROP_ID_UNSUPPORTED
;
1354 /***********************************************************************
1355 * MSSTYLES_GetPropertyString
1357 * Retrieve a string value for a property
1359 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1361 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1365 /***********************************************************************
1366 * MSSTYLES_GetPropertyRect
1368 * Retrieve a rect value for a property
1370 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1372 LPCWSTR lpCur
= tp
->lpValue
;
1373 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1375 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->left
);
1376 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->top
);
1377 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->right
);
1378 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->bottom
)) {
1379 TRACE("Could not parse rect property\n");
1380 return E_PROP_ID_UNSUPPORTED
;
1385 /***********************************************************************
1386 * MSSTYLES_GetPropertyMargins
1388 * Retrieve a margins value for a property
1390 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1392 LPCWSTR lpCur
= tp
->lpValue
;
1393 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1395 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1396 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1397 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1398 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1399 TRACE("Could not parse margins property\n");
1400 return E_PROP_ID_UNSUPPORTED
;