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 "uxthemedll.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
43 /***********************************************************************
44 * Defines and global variables
47 BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
);
48 BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
);
49 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
);
50 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LOGFONTW
* logfont
);
52 extern HINSTANCE hDllInst
;
53 extern int alphaBlendMode
;
55 #define MSSTYLES_VERSION 0x0003
57 static const WCHAR szThemesIniResource
[] = {
58 't','h','e','m','e','s','_','i','n','i','\0'
61 static PTHEME_FILE tfActiveTheme
;
63 /***********************************************************************/
65 /**********************************************************************
66 * MSSTYLES_OpenThemeFile
68 * Load and validate a theme
71 * lpThemeFile Path to theme file to load
72 * pszColorName Color name wanted, can be NULL
73 * pszSizeName Size name wanted, can be NULL
76 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
77 * If one/both are provided, they are validated against valid color/sizes and if
78 * a match is not found, the function fails.
80 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
85 static const WCHAR szPackThemVersionResource
[] = {
86 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
88 static const WCHAR szColorNamesResource
[] = {
89 'C','O','L','O','R','N','A','M','E','S','\0'
91 static const WCHAR szSizeNamesResource
[] = {
92 'S','I','Z','E','N','A','M','E','S','\0'
98 LPWSTR pszSelectedColor
= NULL
;
100 LPWSTR pszSelectedSize
= NULL
;
103 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
105 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
107 /* Validate that this is really a theme */
109 hr
= HRESULT_FROM_WIN32(GetLastError());
112 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szPackThemVersionResource
))) {
113 TRACE("No version resource found\n");
114 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
117 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
119 TRACE("Version resource found, but wrong size: %d\n", versize
);
120 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
123 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
124 if(version
!= MSSTYLES_VERSION
)
126 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
127 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
131 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szColorNamesResource
))) {
132 TRACE("Color names resource not found\n");
133 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
136 pszColors
= (LPWSTR
)LoadResource(hTheme
, hrsc
);
138 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szSizeNamesResource
))) {
139 TRACE("Size names resource not found\n");
140 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
143 pszSizes
= (LPWSTR
)LoadResource(hTheme
, hrsc
);
145 /* Validate requested color against whats available from the theme */
149 if(!lstrcmpiW(pszColorName
, tmp
)) {
150 pszSelectedColor
= tmp
;
153 tmp
+= lstrlenW(tmp
)+1;
157 pszSelectedColor
= pszColors
; /* Use the default color */
159 /* Validate requested size against whats available from the theme */
163 if(!lstrcmpiW(pszSizeName
, tmp
)) {
164 pszSelectedSize
= tmp
;
167 tmp
+= lstrlenW(tmp
)+1;
171 pszSelectedSize
= pszSizes
; /* Use the default size */
173 if(!pszSelectedColor
|| !pszSelectedSize
) {
174 TRACE("Requested color/size (%s/%s) not found in theme\n",
175 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
176 hr
= E_PROP_ID_UNSUPPORTED
;
180 *tf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(THEME_FILE
));
181 (*tf
)->hTheme
= hTheme
;
183 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
185 (*tf
)->pszAvailColors
= pszColors
;
186 (*tf
)->pszAvailSizes
= pszSizes
;
187 (*tf
)->pszSelectedColor
= pszSelectedColor
;
188 (*tf
)->pszSelectedSize
= pszSelectedSize
;
189 (*tf
)->dwRefCount
= 1;
193 if(hTheme
) FreeLibrary(hTheme
);
197 /***********************************************************************
198 * MSSTYLES_CloseThemeFile
200 * Close theme file and free resources
202 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
206 if(!tf
->dwRefCount
) {
207 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
210 PTHEME_CLASS pcls
= tf
->classes
;
211 tf
->classes
= pcls
->next
;
212 while(pcls
->partstate
) {
213 PTHEME_PARTSTATE ps
= pcls
->partstate
;
214 pcls
->partstate
= ps
->next
;
215 HeapFree(GetProcessHeap(), 0, ps
);
217 HeapFree(GetProcessHeap(), 0, pcls
);
222 PTHEME_IMAGE img
= tf
->images
;
223 tf
->images
= img
->next
;
224 DeleteObject (img
->image
);
225 HeapFree (GetProcessHeap(), 0, img
);
227 HeapFree(GetProcessHeap(), 0, tf
);
232 /***********************************************************************
233 * MSSTYLES_SetActiveTheme
235 * Set the current active theme
237 HRESULT
MSSTYLES_SetActiveTheme(PTHEME_FILE tf
, BOOL setMetrics
)
240 MSSTYLES_CloseThemeFile(tfActiveTheme
);
244 tfActiveTheme
->dwRefCount
++;
245 if(!tfActiveTheme
->classes
)
246 MSSTYLES_ParseThemeIni(tfActiveTheme
, setMetrics
);
251 /***********************************************************************
252 * MSSTYLES_GetThemeIni
254 * Retrieves themes.ini from a theme
256 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
258 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
261 /***********************************************************************
262 * MSSTYLES_GetActiveThemeIni
264 * Retrieve the ini file for the selected color/style
266 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
268 static const WCHAR szFileResNamesResource
[] = {
269 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
271 DWORD dwColorCount
= 0;
272 DWORD dwSizeCount
= 0;
273 DWORD dwColorNum
= 0;
276 DWORD dwResourceIndex
;
280 /* Count the number of available colors & styles, and determine the index number
281 of the color/style we are interested in
283 tmp
= tf
->pszAvailColors
;
285 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
286 dwColorNum
= dwColorCount
;
287 tmp
+= lstrlenW(tmp
)+1;
290 tmp
= tf
->pszAvailSizes
;
292 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
293 dwSizeNum
= dwSizeCount
;
294 tmp
+= lstrlenW(tmp
)+1;
298 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
299 TRACE("FILERESNAMES map not found\n");
302 tmp
= (LPWSTR
)LoadResource(tf
->hTheme
, hrsc
);
303 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
304 for(i
=0; i
< dwResourceIndex
; i
++) {
305 tmp
+= lstrlenW(tmp
)+1;
307 return UXINI_LoadINI(tf
->hTheme
, tmp
);
311 /***********************************************************************
312 * MSSTYLES_ParseIniSectionName
314 * Parse an ini section name into its component parts
319 * [classname.part(state)]
320 * [application::classname]
321 * [application::classname(state)]
322 * [application::classname.part]
323 * [application::classname.part(state)]
326 * lpSection Section name
327 * dwLen Length of section name
328 * szAppName Location to store application name
329 * szClassName Location to store class name
330 * iPartId Location to store part id
331 * iStateId Location to store state id
333 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
336 WCHAR part
[60] = {'\0'};
337 WCHAR state
[60] = {'\0'};
340 lstrcpynW(sec
, lpSection
, min(dwLen
+1, sizeof(sec
)/sizeof(sec
[0])));
347 /* Get the application name */
348 tmp
= strchrW(comp
, ':');
352 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
356 tmp
= strchrW(comp
, '.');
359 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
361 /* now get the part & state */
362 tmp
= strchrW(comp
, '(');
365 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
367 /* now get the state */
368 *strchrW(comp
, ')') = 0;
369 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
372 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
376 tmp
= strchrW(comp
, '(');
379 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
381 /* now get the state */
382 *strchrW(comp
, ')') = 0;
383 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
386 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
389 if(!*szClassName
) return FALSE
;
390 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
393 /***********************************************************************
400 * pszAppName App name to find
401 * pszClassName Class name to find
404 * The class found, or NULL
406 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
408 PTHEME_CLASS cur
= tf
->classes
;
411 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
415 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
423 /***********************************************************************
426 * Add a class to a theme file
430 * pszAppName App name to add
431 * pszClassName Class name to add
434 * The class added, or a class previously added with the same name
436 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
438 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
441 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS
));
442 cur
->hTheme
= tf
->hTheme
;
443 lstrcpyW(cur
->szAppName
, pszAppName
);
444 lstrcpyW(cur
->szClassName
, pszClassName
);
445 cur
->next
= tf
->classes
;
446 cur
->partstate
= NULL
;
447 cur
->overrides
= NULL
;
452 /***********************************************************************
453 * MSSTYLES_FindPartState
459 * iPartId Part ID to find
460 * iStateId State ID to find
461 * tcNext Receives the next class in the override chain
464 * The part/state found, or NULL
466 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
468 PTHEME_PARTSTATE cur
= tc
->partstate
;
470 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
471 if(tcNext
) *tcNext
= tc
->overrides
;
476 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
480 /***********************************************************************
481 * MSSTYLES_AddPartState
483 * Add a part/state to a class
487 * iPartId Part ID to add
488 * iStateId State ID to add
491 * The part/state added, or a part/state previously added with the same IDs
493 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
495 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
498 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE
));
499 cur
->iPartId
= iPartId
;
500 cur
->iStateId
= iStateId
;
501 cur
->properties
= NULL
;
502 cur
->next
= tc
->partstate
;
507 /***********************************************************************
508 * MSSTYLES_LFindProperty
510 * Find a property within a property list
513 * tp property list to scan
514 * iPropertyPrimitive Type of value expected
515 * iPropertyId ID of the required value
518 * The property found, or NULL
520 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
522 PTHEME_PROPERTY cur
= tp
;
524 if(cur
->iPropertyId
== iPropertyId
) {
525 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
529 if(!iPropertyPrimitive
)
539 /***********************************************************************
540 * MSSTYLES_PSFindProperty
542 * Find a value within a part/state
545 * ps Part/state to search
546 * iPropertyPrimitive Type of value expected
547 * iPropertyId ID of the required value
550 * The property found, or NULL
552 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
554 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
557 /***********************************************************************
558 * MSSTYLES_FFindMetric
560 * Find a metric property for a theme file
564 * iPropertyPrimitive Type of value expected
565 * iPropertyId ID of the required value
568 * The property found, or NULL
570 static inline PTHEME_PROPERTY
MSSTYLES_FFindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
572 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
575 /***********************************************************************
576 * MSSTYLES_FindMetric
578 * Find a metric property for the current installed theme
582 * iPropertyPrimitive Type of value expected
583 * iPropertyId ID of the required value
586 * The property found, or NULL
588 PTHEME_PROPERTY
MSSTYLES_FindMetric(int iPropertyPrimitive
, int iPropertyId
)
590 if(!tfActiveTheme
) return NULL
;
591 return MSSTYLES_FFindMetric(tfActiveTheme
, iPropertyPrimitive
, iPropertyId
);
594 /***********************************************************************
595 * MSSTYLES_AddProperty
597 * Add a property to a part/state
601 * iPropertyPrimitive Primitive type of the property
602 * iPropertyId ID of the property
603 * lpValue Raw value (non-NULL terminated)
604 * dwValueLen Length of the value
607 * The property added, or a property previously added with the same IDs
609 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
611 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
612 /* Should duplicate properties overwrite the original, or be ignored? */
615 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
616 cur
->iPrimitiveType
= iPropertyPrimitive
;
617 cur
->iPropertyId
= iPropertyId
;
618 cur
->lpValue
= lpValue
;
619 cur
->dwValueLen
= dwValueLen
;
622 cur
->origin
= PO_STATE
;
624 cur
->origin
= PO_PART
;
626 cur
->origin
= PO_GLOBAL
;
628 cur
->origin
= PO_CLASS
;
630 cur
->next
= ps
->properties
;
631 ps
->properties
= cur
;
635 /***********************************************************************
638 * Add a property to a part/state
642 * iPropertyPrimitive Primitive type of the property
643 * iPropertyId ID of the property
644 * lpValue Raw value (non-NULL terminated)
645 * dwValueLen Length of the value
648 * The property added, or a property previously added with the same IDs
650 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
652 PTHEME_PROPERTY cur
= MSSTYLES_FFindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
653 /* Should duplicate properties overwrite the original, or be ignored? */
656 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
657 cur
->iPrimitiveType
= iPropertyPrimitive
;
658 cur
->iPropertyId
= iPropertyId
;
659 cur
->lpValue
= lpValue
;
660 cur
->dwValueLen
= dwValueLen
;
662 cur
->origin
= PO_GLOBAL
;
664 cur
->next
= tf
->metrics
;
669 /* Color-related state for theme ini parsing */
670 struct PARSECOLORSTATE
673 int colorElements
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
];
674 COLORREF colorRgb
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
];
678 static inline void parse_init_color (struct PARSECOLORSTATE
* state
)
680 memset (state
, 0, sizeof (*state
));
683 static BOOL
parse_handle_color_property (struct PARSECOLORSTATE
* state
,
684 int iPropertyId
, LPCWSTR lpValue
,
688 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
689 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &r
);
690 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &g
);
691 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &b
)) {
692 state
->colorElements
[state
->colorCount
] = iPropertyId
- TMT_FIRSTCOLOR
;
693 state
->colorRgb
[state
->colorCount
++] = RGB(r
,g
,b
);
696 case TMT_ACTIVECAPTION
:
697 state
->captionColors
|= 0x1;
699 case TMT_INACTIVECAPTION
:
700 state
->captionColors
|= 0x2;
702 case TMT_GRADIENTACTIVECAPTION
:
703 state
->captionColors
|= 0x4;
705 case TMT_GRADIENTINACTIVECAPTION
:
706 state
->captionColors
|= 0x8;
716 static void parse_apply_color (struct PARSECOLORSTATE
* state
)
718 if (state
->colorCount
> 0)
719 SetSysColors(state
->colorCount
, state
->colorElements
, state
->colorRgb
);
720 if (state
->captionColors
== 0xf)
721 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS
, 0, (PVOID
)TRUE
, 0);
724 /* Non-client-metrics-related state for theme ini parsing */
725 struct PARSENONCLIENTSTATE
727 NONCLIENTMETRICSW metrics
;
729 LOGFONTW iconTitleFont
;
732 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE
* state
)
734 memset (state
, 0, sizeof (*state
));
735 state
->metrics
.cbSize
= sizeof (NONCLIENTMETRICSW
);
736 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (NONCLIENTMETRICSW
),
737 (PVOID
)&state
->metrics
, 0);
738 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (LOGFONTW
),
739 (PVOID
)&state
->iconTitleFont
, 0);
742 static BOOL
parse_handle_nonclient_font (struct PARSENONCLIENTSTATE
* state
,
743 int iPropertyId
, LPCWSTR lpValue
,
748 memset (&font
, 0, sizeof (font
));
749 if (SUCCEEDED (MSSTYLES_GetFont (lpValue
, lpValue
+ dwValueLen
, &lpValue
,
754 case TMT_CAPTIONFONT
:
755 memcpy (&state
->metrics
.lfCaptionFont
, &font
, sizeof (LOGFONTW
));
756 state
->metricsDirty
= TRUE
;
758 case TMT_SMALLCAPTIONFONT
:
759 memcpy (&state
->metrics
.lfSmCaptionFont
, &font
, sizeof (LOGFONTW
));
760 state
->metricsDirty
= TRUE
;
763 memcpy (&state
->metrics
.lfMenuFont
, &font
, sizeof (LOGFONTW
));
764 state
->metricsDirty
= TRUE
;
767 memcpy (&state
->metrics
.lfStatusFont
, &font
, sizeof (LOGFONTW
));
768 state
->metricsDirty
= TRUE
;
771 memcpy (&state
->metrics
.lfMessageFont
, &font
, sizeof (LOGFONTW
));
772 state
->metricsDirty
= TRUE
;
774 case TMT_ICONTITLEFONT
:
775 memcpy (&state
->iconTitleFont
, &font
, sizeof (LOGFONTW
));
776 state
->metricsDirty
= TRUE
;
785 static BOOL
parse_handle_nonclient_size (struct PARSENONCLIENTSTATE
* state
,
786 int iPropertyId
, LPCWSTR lpValue
,
790 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
791 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &size
)) {
794 case TMT_SIZINGBORDERWIDTH
:
795 state
->metrics
.iBorderWidth
= size
;
796 state
->metricsDirty
= TRUE
;
798 case TMT_SCROLLBARWIDTH
:
799 state
->metrics
.iScrollWidth
= size
;
800 state
->metricsDirty
= TRUE
;
802 case TMT_SCROLLBARHEIGHT
:
803 state
->metrics
.iScrollHeight
= size
;
804 state
->metricsDirty
= TRUE
;
806 case TMT_CAPTIONBARWIDTH
:
807 state
->metrics
.iCaptionWidth
= size
;
808 state
->metricsDirty
= TRUE
;
810 case TMT_CAPTIONBARHEIGHT
:
811 state
->metrics
.iCaptionHeight
= size
;
812 state
->metricsDirty
= TRUE
;
814 case TMT_SMCAPTIONBARWIDTH
:
815 state
->metrics
.iSmCaptionWidth
= size
;
816 state
->metricsDirty
= TRUE
;
818 case TMT_SMCAPTIONBARHEIGHT
:
819 state
->metrics
.iSmCaptionHeight
= size
;
820 state
->metricsDirty
= TRUE
;
822 case TMT_MENUBARWIDTH
:
823 state
->metrics
.iMenuWidth
= size
;
824 state
->metricsDirty
= TRUE
;
826 case TMT_MENUBARHEIGHT
:
827 state
->metrics
.iMenuHeight
= size
;
828 state
->metricsDirty
= TRUE
;
837 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE
* state
)
839 if (state
->metricsDirty
)
841 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (state
->metrics
),
842 (PVOID
)&state
->metrics
, 0);
843 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (state
->iconTitleFont
),
844 (PVOID
)&state
->iconTitleFont
, 0);
848 /***********************************************************************
849 * MSSTYLES_ParseThemeIni
851 * Parse the theme ini for the selected color/style
856 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
)
858 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
859 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
861 PTHEME_CLASS globals
;
864 WCHAR szAppName
[MAX_THEME_APP_NAME
];
865 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
866 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
869 int iPropertyPrimitive
;
876 ini
= MSSTYLES_GetActiveThemeIni(tf
);
878 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
))) {
879 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
) {
880 struct PARSECOLORSTATE colorState
;
881 struct PARSENONCLIENTSTATE nonClientState
;
883 parse_init_color (&colorState
);
884 parse_init_nonclient (&nonClientState
);
886 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
887 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
888 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
889 if(iPropertyId
>= TMT_FIRSTCOLOR
&& iPropertyId
<= TMT_LASTCOLOR
) {
890 if (!parse_handle_color_property (&colorState
, iPropertyId
,
891 lpValue
, dwValueLen
))
892 FIXME("Invalid color value for %s\n",
893 debugstr_w(szPropertyName
));
895 else if (setMetrics
&& (iPropertyId
== TMT_FLATMENUS
)) {
896 BOOL flatMenus
= (*lpValue
== 'T') || (*lpValue
== 't');
897 SystemParametersInfoW (SPI_SETFLATMENU
, 0, (PVOID
)(INT_PTR
)flatMenus
, 0);
899 else if ((iPropertyId
>= TMT_FIRSTFONT
)
900 && (iPropertyId
<= TMT_LASTFONT
))
902 if (!parse_handle_nonclient_font (&nonClientState
,
903 iPropertyId
, lpValue
, dwValueLen
))
904 FIXME("Invalid font value for %s\n",
905 debugstr_w(szPropertyName
));
907 else if ((iPropertyId
>= TMT_FIRSTSIZE
)
908 && (iPropertyId
<= TMT_LASTSIZE
))
910 if (!parse_handle_nonclient_size (&nonClientState
,
911 iPropertyId
, lpValue
, dwValueLen
))
912 FIXME("Invalid size value for %s\n",
913 debugstr_w(szPropertyName
));
915 /* Catch all metrics, including colors */
916 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
919 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
924 parse_apply_color (&colorState
);
925 parse_apply_nonclient (&nonClientState
);
929 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
)) {
930 BOOL isGlobal
= FALSE
;
931 if(!lstrcmpiW(szClassName
, szGlobals
)) {
934 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
935 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
937 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
938 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
939 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
940 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
943 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
949 /* App/Class combos override values defined by the base class, map these overrides */
950 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
953 if(*cls
->szAppName
) {
954 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
955 if(!cls
->overrides
) {
956 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
959 cls
->overrides
= globals
;
963 /* Everything overrides globals..except globals */
964 if(cls
!= globals
) cls
->overrides
= globals
;
971 ERR("Failed to parse theme ini\n");
975 /***********************************************************************
976 * MSSTYLES_OpenThemeClass
978 * Open a theme class, uses the current active theme
981 * pszAppName Application name, for theme styles specific
982 * to a particular application
983 * pszClassList List of requested classes, semicolon delimited
985 PTHEME_CLASS
MSSTYLES_OpenThemeClass(LPCWSTR pszAppName
, LPCWSTR pszClassList
)
987 PTHEME_CLASS cls
= NULL
;
988 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
994 TRACE("there is no active theme\n");
997 if(!tfActiveTheme
->classes
) {
1001 start
= pszClassList
;
1002 while((end
= strchrW(start
, ';'))) {
1004 lstrcpynW(szClassName
, start
, min(len
+1, sizeof(szClassName
)/sizeof(szClassName
[0])));
1006 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1009 if(!cls
&& *start
) {
1010 lstrcpynW(szClassName
, start
, sizeof(szClassName
)/sizeof(szClassName
[0]));
1011 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1014 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
1015 cls
->tf
= tfActiveTheme
;
1016 cls
->tf
->dwRefCount
++;
1021 /***********************************************************************
1022 * MSSTYLES_CloseThemeClass
1024 * Close a theme class
1027 * tc Theme class to close
1030 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1031 * theme file and cleans it up, if needed.
1033 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
1035 MSSTYLES_CloseThemeFile (tc
->tf
);
1039 /***********************************************************************
1040 * MSSTYLES_FindProperty
1042 * Locate a property in a class. Part and state IDs will be used as a
1043 * preference, but may be ignored in the attempt to locate the property.
1044 * Will scan the entire chain of overrides for this class.
1046 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
1048 PTHEME_CLASS next
= tc
;
1049 PTHEME_PARTSTATE ps
;
1052 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
1053 /* Try and find an exact match on part & state */
1054 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
1055 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
1059 /* If that fails, and we didn't already try it, search for just part */
1062 /* As a last ditch attempt..go for just class */
1063 else if(iPartId
!= 0)
1068 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
1073 /* Prepare a bitmap to be used for alpha blending */
1074 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
1082 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
1085 if(dib
.dsBm
.bmBitsPixel
!= 32)
1090 p
= (BYTE
*)dib
.dsBm
.bmBits
;
1091 n
= abs(dib
.dsBmih
.biHeight
) * dib
.dsBmih
.biWidth
;
1092 /* AlphaBlend() wants premultiplied alpha, so do that now */
1096 p
[0] = (p
[0] * a
) >> 8;
1097 p
[1] = (p
[1] * a
) >> 8;
1098 p
[2] = (p
[2] * a
) >> 8;
1105 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
1107 WCHAR szFile
[MAX_PATH
];
1110 lstrcpynW(szFile
, lpFilename
, sizeof(szFile
)/sizeof(szFile
[0]));
1113 if(*tmp
== '\\') *tmp
= '_';
1114 if(*tmp
== '/') *tmp
= '_';
1115 if(*tmp
== '.') *tmp
= '_';
1118 /* Try to locate in list of loaded images */
1119 img
= tc
->tf
->images
;
1122 if (lstrcmpiW (szFile
, img
->name
) == 0)
1124 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1125 *hasAlpha
= img
->hasAlpha
;
1130 /* Not found? Load from resources */
1131 img
= HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE
));
1132 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
1133 prepare_alpha (img
->image
, hasAlpha
);
1134 img
->hasAlpha
= *hasAlpha
;
1135 /* ...and stow away for later reuse. */
1136 lstrcpyW (img
->name
, szFile
);
1137 img
->next
= tc
->tf
->images
;
1138 tc
->tf
->images
= img
;
1139 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1143 BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
1145 LPCWSTR cur
= lpStringStart
;
1147 BOOL gotNeg
= FALSE
;
1149 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
1150 if(cur
>= lpStringEnd
) {
1157 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
1158 total
= total
* 10 + (*cur
- '0');
1161 if(gotNeg
) total
= -total
;
1163 if(lpValEnd
) *lpValEnd
= cur
;
1167 BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
1168 LPCWSTR cur
= lpStringStart
;
1172 while(cur
< lpStringEnd
&& (isspace(*cur
) || *cur
== ',')) cur
++;
1173 if(cur
>= lpStringEnd
) {
1177 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
1179 while(isspace(*end
)) end
--;
1181 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
1183 if(lpValEnd
) *lpValEnd
= cur
;
1187 /***********************************************************************
1188 * MSSTYLES_GetPropertyBool
1190 * Retrieve a color value for a property
1192 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
1195 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
1200 /***********************************************************************
1201 * MSSTYLES_GetPropertyColor
1203 * Retrieve a color value for a property
1205 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
1209 int red
, green
, blue
;
1211 lpCur
= tp
->lpValue
;
1212 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1214 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
);
1215 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
);
1216 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
1217 TRACE("Could not parse color property\n");
1218 return E_PROP_ID_UNSUPPORTED
;
1220 *pColor
= RGB(red
,green
,blue
);
1224 /***********************************************************************
1225 * MSSTYLES_GetPropertyColor
1227 * Retrieve a color value for a property
1229 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1230 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1232 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
1233 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
1234 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
1235 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
1239 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1240 TRACE("Property is there, but failed to get face name\n");
1242 return E_PROP_ID_UNSUPPORTED
;
1244 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1245 TRACE("Property is there, but failed to get point size\n");
1247 return E_PROP_ID_UNSUPPORTED
;
1249 pFont
->lfHeight
= pointSize
;
1250 pFont
->lfWeight
= FW_REGULAR
;
1251 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1252 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, sizeof(attr
)/sizeof(attr
[0]))) {
1253 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
1254 else if(!!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
1255 else if(!!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
1256 else if(!!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
1262 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1264 LPCWSTR lpCur
= tp
->lpValue
;
1265 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1268 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1269 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1271 pFont
->lfHeight
= -MulDiv(pFont
->lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1276 /***********************************************************************
1277 * MSSTYLES_GetPropertyInt
1279 * Retrieve an int value for a property
1281 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1283 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1284 TRACE("Could not parse int property\n");
1285 return E_PROP_ID_UNSUPPORTED
;
1290 /***********************************************************************
1291 * MSSTYLES_GetPropertyIntList
1293 * Retrieve an int list value for a property
1295 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1298 LPCWSTR lpCur
= tp
->lpValue
;
1299 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1301 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1302 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1305 pIntList
->iValueCount
= i
;
1309 /***********************************************************************
1310 * MSSTYLES_GetPropertyPosition
1312 * Retrieve a position value for a property
1314 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1317 LPCWSTR lpCur
= tp
->lpValue
;
1318 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1320 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
);
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
, (int*)&pRect
->left
);
1352 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&pRect
->top
);
1353 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&pRect
->right
);
1354 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, (int*)&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
;