2 * Win32 5.1 msstyles theme format
4 * Copyright (C) 2003 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme
);
42 /***********************************************************************
43 * Defines and global variables
46 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
);
47 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
);
48 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
);
49 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LOGFONTW
* logfont
);
51 extern int alphaBlendMode
;
53 #define MSSTYLES_VERSION 0x0003
55 static const WCHAR szThemesIniResource
[] = {
56 't','h','e','m','e','s','_','i','n','i','\0'
59 static PTHEME_FILE tfActiveTheme
;
61 /***********************************************************************/
63 /**********************************************************************
64 * MSSTYLES_OpenThemeFile
66 * Load and validate a theme
69 * lpThemeFile Path to theme file to load
70 * pszColorName Color name wanted, can be NULL
71 * pszSizeName Size name wanted, can be NULL
74 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
75 * If one/both are provided, they are validated against valid color/sizes and if
76 * a match is not found, the function fails.
78 HRESULT
MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile
, LPCWSTR pszColorName
, LPCWSTR pszSizeName
, PTHEME_FILE
*tf
)
83 static const WCHAR szPackThemVersionResource
[] = {
84 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
86 static const WCHAR szColorNamesResource
[] = {
87 'C','O','L','O','R','N','A','M','E','S','\0'
89 static const WCHAR szSizeNamesResource
[] = {
90 'S','I','Z','E','N','A','M','E','S','\0'
96 LPWSTR pszSelectedColor
= NULL
;
98 LPWSTR pszSelectedSize
= NULL
;
101 TRACE("Opening %s\n", debugstr_w(lpThemeFile
));
103 hTheme
= LoadLibraryExW(lpThemeFile
, NULL
, LOAD_LIBRARY_AS_DATAFILE
);
105 /* Validate that this is really a theme */
107 hr
= HRESULT_FROM_WIN32(GetLastError());
110 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szPackThemVersionResource
))) {
111 TRACE("No version resource found\n");
112 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
115 if((versize
= SizeofResource(hTheme
, hrsc
)) != 2)
117 TRACE("Version resource found, but wrong size: %d\n", versize
);
118 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
121 version
= *(WORD
*)LoadResource(hTheme
, hrsc
);
122 if(version
!= MSSTYLES_VERSION
)
124 TRACE("Version of theme file is unsupported: 0x%04x\n", version
);
125 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
129 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szColorNamesResource
))) {
130 TRACE("Color names resource not found\n");
131 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
134 pszColors
= LoadResource(hTheme
, hrsc
);
136 if(!(hrsc
= FindResourceW(hTheme
, MAKEINTRESOURCEW(1), szSizeNamesResource
))) {
137 TRACE("Size names resource not found\n");
138 hr
= HRESULT_FROM_WIN32(ERROR_BAD_FORMAT
);
141 pszSizes
= LoadResource(hTheme
, hrsc
);
143 /* Validate requested color against what's available from the theme */
147 if(!lstrcmpiW(pszColorName
, tmp
)) {
148 pszSelectedColor
= tmp
;
151 tmp
+= lstrlenW(tmp
)+1;
155 pszSelectedColor
= pszColors
; /* Use the default color */
157 /* Validate requested size against what's available from the theme */
161 if(!lstrcmpiW(pszSizeName
, tmp
)) {
162 pszSelectedSize
= tmp
;
165 tmp
+= lstrlenW(tmp
)+1;
169 pszSelectedSize
= pszSizes
; /* Use the default size */
171 if(!pszSelectedColor
|| !pszSelectedSize
) {
172 TRACE("Requested color/size (%s/%s) not found in theme\n",
173 debugstr_w(pszColorName
), debugstr_w(pszSizeName
));
174 hr
= E_PROP_ID_UNSUPPORTED
;
178 *tf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(THEME_FILE
));
179 (*tf
)->hTheme
= hTheme
;
181 GetFullPathNameW(lpThemeFile
, MAX_PATH
, (*tf
)->szThemeFile
, NULL
);
183 (*tf
)->pszAvailColors
= pszColors
;
184 (*tf
)->pszAvailSizes
= pszSizes
;
185 (*tf
)->pszSelectedColor
= pszSelectedColor
;
186 (*tf
)->pszSelectedSize
= pszSelectedSize
;
187 (*tf
)->dwRefCount
= 1;
192 if(hTheme
) FreeLibrary(hTheme
);
196 /***********************************************************************
197 * MSSTYLES_CloseThemeFile
199 * Close theme file and free resources
201 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf
)
205 if(!tf
->dwRefCount
) {
206 if(tf
->hTheme
) FreeLibrary(tf
->hTheme
);
209 PTHEME_CLASS pcls
= tf
->classes
;
210 tf
->classes
= pcls
->next
;
211 while(pcls
->partstate
) {
212 PTHEME_PARTSTATE ps
= pcls
->partstate
;
214 while(ps
->properties
) {
215 PTHEME_PROPERTY prop
= ps
->properties
;
216 ps
->properties
= prop
->next
;
217 HeapFree(GetProcessHeap(), 0, prop
);
220 pcls
->partstate
= ps
->next
;
221 HeapFree(GetProcessHeap(), 0, ps
);
223 HeapFree(GetProcessHeap(), 0, pcls
);
228 PTHEME_IMAGE img
= tf
->images
;
229 tf
->images
= img
->next
;
230 DeleteObject (img
->image
);
231 HeapFree (GetProcessHeap(), 0, img
);
233 HeapFree(GetProcessHeap(), 0, tf
);
238 /***********************************************************************
239 * MSSTYLES_SetActiveTheme
241 * Set the current active theme
243 HRESULT
MSSTYLES_SetActiveTheme(PTHEME_FILE tf
, BOOL setMetrics
)
246 MSSTYLES_CloseThemeFile(tfActiveTheme
);
250 tfActiveTheme
->dwRefCount
++;
251 if(!tfActiveTheme
->classes
)
252 MSSTYLES_ParseThemeIni(tfActiveTheme
, setMetrics
);
257 /***********************************************************************
258 * MSSTYLES_GetThemeIni
260 * Retrieves themes.ini from a theme
262 PUXINI_FILE
MSSTYLES_GetThemeIni(PTHEME_FILE tf
)
264 return UXINI_LoadINI(tf
->hTheme
, szThemesIniResource
);
267 /***********************************************************************
268 * MSSTYLES_GetActiveThemeIni
270 * Retrieve the ini file for the selected color/style
272 static PUXINI_FILE
MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf
)
274 static const WCHAR szFileResNamesResource
[] = {
275 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
277 DWORD dwColorCount
= 0;
278 DWORD dwSizeCount
= 0;
279 DWORD dwColorNum
= 0;
282 DWORD dwResourceIndex
;
286 /* Count the number of available colors & styles, and determine the index number
287 of the color/style we are interested in
289 tmp
= tf
->pszAvailColors
;
291 if(!lstrcmpiW(tf
->pszSelectedColor
, tmp
))
292 dwColorNum
= dwColorCount
;
293 tmp
+= lstrlenW(tmp
)+1;
296 tmp
= tf
->pszAvailSizes
;
298 if(!lstrcmpiW(tf
->pszSelectedSize
, tmp
))
299 dwSizeNum
= dwSizeCount
;
300 tmp
+= lstrlenW(tmp
)+1;
304 if(!(hrsc
= FindResourceW(tf
->hTheme
, MAKEINTRESOURCEW(1), szFileResNamesResource
))) {
305 TRACE("FILERESNAMES map not found\n");
308 tmp
= LoadResource(tf
->hTheme
, hrsc
);
309 dwResourceIndex
= (dwSizeCount
* dwColorNum
) + dwSizeNum
;
310 for(i
=0; i
< dwResourceIndex
; i
++) {
311 tmp
+= lstrlenW(tmp
)+1;
313 return UXINI_LoadINI(tf
->hTheme
, tmp
);
317 /***********************************************************************
318 * MSSTYLES_ParseIniSectionName
320 * Parse an ini section name into its component parts
325 * [classname.part(state)]
326 * [application::classname]
327 * [application::classname(state)]
328 * [application::classname.part]
329 * [application::classname.part(state)]
332 * lpSection Section name
333 * dwLen Length of section name
334 * szAppName Location to store application name
335 * szClassName Location to store class name
336 * iPartId Location to store part id
337 * iStateId Location to store state id
339 static BOOL
MSSTYLES_ParseIniSectionName(LPCWSTR lpSection
, DWORD dwLen
, LPWSTR szAppName
, LPWSTR szClassName
, int *iPartId
, int *iStateId
)
342 WCHAR part
[60] = {'\0'};
343 WCHAR state
[60] = {'\0'};
346 lstrcpynW(sec
, lpSection
, min(dwLen
+1, sizeof(sec
)/sizeof(sec
[0])));
353 /* Get the application name */
354 tmp
= strchrW(comp
, ':');
358 lstrcpynW(szAppName
, comp
, MAX_THEME_APP_NAME
);
362 tmp
= strchrW(comp
, '.');
365 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
367 /* now get the part & state */
368 tmp
= strchrW(comp
, '(');
371 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
373 /* now get the state */
374 tmp
= strchrW(comp
, ')');
378 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
381 lstrcpynW(part
, comp
, sizeof(part
)/sizeof(part
[0]));
385 tmp
= strchrW(comp
, '(');
388 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
390 /* now get the state */
391 tmp
= strchrW(comp
, ')');
395 lstrcpynW(state
, comp
, sizeof(state
)/sizeof(state
[0]));
398 lstrcpynW(szClassName
, comp
, MAX_THEME_CLASS_NAME
);
401 if(!*szClassName
) return FALSE
;
402 return MSSTYLES_LookupPartState(szClassName
, part
[0]?part
:NULL
, state
[0]?state
:NULL
, iPartId
, iStateId
);
405 /***********************************************************************
412 * pszAppName App name to find
413 * pszClassName Class name to find
416 * The class found, or NULL
418 static PTHEME_CLASS
MSSTYLES_FindClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
420 PTHEME_CLASS cur
= tf
->classes
;
423 if(!*cur
->szAppName
&& !lstrcmpiW(pszClassName
, cur
->szClassName
))
427 if(!lstrcmpiW(pszAppName
, cur
->szAppName
) && !lstrcmpiW(pszClassName
, cur
->szClassName
))
435 /***********************************************************************
438 * Add a class to a theme file
442 * pszAppName App name to add
443 * pszClassName Class name to add
446 * The class added, or a class previously added with the same name
448 static PTHEME_CLASS
MSSTYLES_AddClass(PTHEME_FILE tf
, LPCWSTR pszAppName
, LPCWSTR pszClassName
)
450 PTHEME_CLASS cur
= MSSTYLES_FindClass(tf
, pszAppName
, pszClassName
);
453 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS
));
454 cur
->hTheme
= tf
->hTheme
;
455 lstrcpyW(cur
->szAppName
, pszAppName
);
456 lstrcpyW(cur
->szClassName
, pszClassName
);
457 cur
->next
= tf
->classes
;
458 cur
->partstate
= NULL
;
459 cur
->overrides
= NULL
;
464 /***********************************************************************
465 * MSSTYLES_FindPartState
471 * iPartId Part ID to find
472 * iStateId State ID to find
473 * tcNext Receives the next class in the override chain
476 * The part/state found, or NULL
478 PTHEME_PARTSTATE
MSSTYLES_FindPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
, PTHEME_CLASS
*tcNext
)
480 PTHEME_PARTSTATE cur
= tc
->partstate
;
482 if(cur
->iPartId
== iPartId
&& cur
->iStateId
== iStateId
) {
483 if(tcNext
) *tcNext
= tc
->overrides
;
488 if(tc
->overrides
) return MSSTYLES_FindPartState(tc
->overrides
, iPartId
, iStateId
, tcNext
);
492 /***********************************************************************
493 * MSSTYLES_AddPartState
495 * Add a part/state to a class
499 * iPartId Part ID to add
500 * iStateId State ID to add
503 * The part/state added, or a part/state previously added with the same IDs
505 static PTHEME_PARTSTATE
MSSTYLES_AddPartState(PTHEME_CLASS tc
, int iPartId
, int iStateId
)
507 PTHEME_PARTSTATE cur
= MSSTYLES_FindPartState(tc
, iPartId
, iStateId
, NULL
);
510 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE
));
511 cur
->iPartId
= iPartId
;
512 cur
->iStateId
= iStateId
;
513 cur
->properties
= NULL
;
514 cur
->next
= tc
->partstate
;
519 /***********************************************************************
520 * MSSTYLES_LFindProperty
522 * Find a property within a property list
525 * tp property list to scan
526 * iPropertyPrimitive Type of value expected
527 * iPropertyId ID of the required value
530 * The property found, or NULL
532 static PTHEME_PROPERTY
MSSTYLES_LFindProperty(PTHEME_PROPERTY tp
, int iPropertyPrimitive
, int iPropertyId
)
534 PTHEME_PROPERTY cur
= tp
;
536 if(cur
->iPropertyId
== iPropertyId
) {
537 if(cur
->iPrimitiveType
== iPropertyPrimitive
) {
541 if(!iPropertyPrimitive
)
551 /***********************************************************************
552 * MSSTYLES_PSFindProperty
554 * Find a value within a part/state
557 * ps Part/state to search
558 * iPropertyPrimitive Type of value expected
559 * iPropertyId ID of the required value
562 * The property found, or NULL
564 static inline PTHEME_PROPERTY
MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
)
566 return MSSTYLES_LFindProperty(ps
->properties
, iPropertyPrimitive
, iPropertyId
);
569 /***********************************************************************
570 * MSSTYLES_FFindMetric
572 * Find a metric property for a theme file
576 * iPropertyPrimitive Type of value expected
577 * iPropertyId ID of the required value
580 * The property found, or NULL
582 static inline PTHEME_PROPERTY
MSSTYLES_FFindMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
)
584 return MSSTYLES_LFindProperty(tf
->metrics
, iPropertyPrimitive
, iPropertyId
);
587 /***********************************************************************
588 * MSSTYLES_FindMetric
590 * Find a metric property for the current installed theme
594 * iPropertyPrimitive Type of value expected
595 * iPropertyId ID of the required value
598 * The property found, or NULL
600 PTHEME_PROPERTY
MSSTYLES_FindMetric(int iPropertyPrimitive
, int iPropertyId
)
602 if(!tfActiveTheme
) return NULL
;
603 return MSSTYLES_FFindMetric(tfActiveTheme
, iPropertyPrimitive
, iPropertyId
);
606 /***********************************************************************
607 * MSSTYLES_AddProperty
609 * Add a property to a part/state
613 * iPropertyPrimitive Primitive type of the property
614 * iPropertyId ID of the property
615 * lpValue Raw value (non-NULL terminated)
616 * dwValueLen Length of the value
619 * The property added, or a property previously added with the same IDs
621 static PTHEME_PROPERTY
MSSTYLES_AddProperty(PTHEME_PARTSTATE ps
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
, BOOL isGlobal
)
623 PTHEME_PROPERTY cur
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
);
624 /* Should duplicate properties overwrite the original, or be ignored? */
627 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
628 cur
->iPrimitiveType
= iPropertyPrimitive
;
629 cur
->iPropertyId
= iPropertyId
;
630 cur
->lpValue
= lpValue
;
631 cur
->dwValueLen
= dwValueLen
;
634 cur
->origin
= PO_STATE
;
636 cur
->origin
= PO_PART
;
638 cur
->origin
= PO_GLOBAL
;
640 cur
->origin
= PO_CLASS
;
642 cur
->next
= ps
->properties
;
643 ps
->properties
= cur
;
647 /***********************************************************************
650 * Add a property to a part/state
654 * iPropertyPrimitive Primitive type of the property
655 * iPropertyId ID of the property
656 * lpValue Raw value (non-NULL terminated)
657 * dwValueLen Length of the value
660 * The property added, or a property previously added with the same IDs
662 static PTHEME_PROPERTY
MSSTYLES_AddMetric(PTHEME_FILE tf
, int iPropertyPrimitive
, int iPropertyId
, LPCWSTR lpValue
, DWORD dwValueLen
)
664 PTHEME_PROPERTY cur
= MSSTYLES_FFindMetric(tf
, iPropertyPrimitive
, iPropertyId
);
665 /* Should duplicate properties overwrite the original, or be ignored? */
668 cur
= HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY
));
669 cur
->iPrimitiveType
= iPropertyPrimitive
;
670 cur
->iPropertyId
= iPropertyId
;
671 cur
->lpValue
= lpValue
;
672 cur
->dwValueLen
= dwValueLen
;
674 cur
->origin
= PO_GLOBAL
;
676 cur
->next
= tf
->metrics
;
681 /* Color-related state for theme ini parsing */
682 struct PARSECOLORSTATE
685 int colorElements
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
686 COLORREF colorRgb
[TMT_LASTCOLOR
-TMT_FIRSTCOLOR
+1];
690 static inline void parse_init_color (struct PARSECOLORSTATE
* state
)
692 memset (state
, 0, sizeof (*state
));
695 static BOOL
parse_handle_color_property (struct PARSECOLORSTATE
* state
,
696 int iPropertyId
, LPCWSTR lpValue
,
700 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
701 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &r
) &&
702 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &g
) &&
703 MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &b
)) {
704 state
->colorElements
[state
->colorCount
] = iPropertyId
- TMT_FIRSTCOLOR
;
705 state
->colorRgb
[state
->colorCount
++] = RGB(r
,g
,b
);
708 case TMT_ACTIVECAPTION
:
709 state
->captionColors
|= 0x1;
711 case TMT_INACTIVECAPTION
:
712 state
->captionColors
|= 0x2;
714 case TMT_GRADIENTACTIVECAPTION
:
715 state
->captionColors
|= 0x4;
717 case TMT_GRADIENTINACTIVECAPTION
:
718 state
->captionColors
|= 0x8;
728 static void parse_apply_color (struct PARSECOLORSTATE
* state
)
730 if (state
->colorCount
> 0)
731 SetSysColors(state
->colorCount
, state
->colorElements
, state
->colorRgb
);
732 if (state
->captionColors
== 0xf)
733 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS
, 0, (PVOID
)TRUE
, 0);
736 /* Non-client-metrics-related state for theme ini parsing */
737 struct PARSENONCLIENTSTATE
739 NONCLIENTMETRICSW metrics
;
741 LOGFONTW iconTitleFont
;
744 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE
* state
)
746 memset (state
, 0, sizeof (*state
));
747 state
->metrics
.cbSize
= sizeof (NONCLIENTMETRICSW
);
748 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (NONCLIENTMETRICSW
),
750 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (LOGFONTW
),
751 &state
->iconTitleFont
, 0);
754 static BOOL
parse_handle_nonclient_font (struct PARSENONCLIENTSTATE
* state
,
755 int iPropertyId
, LPCWSTR lpValue
,
760 memset (&font
, 0, sizeof (font
));
761 if (SUCCEEDED (MSSTYLES_GetFont (lpValue
, lpValue
+ dwValueLen
, &lpValue
,
766 case TMT_CAPTIONFONT
:
767 state
->metrics
.lfCaptionFont
= font
;
768 state
->metricsDirty
= TRUE
;
770 case TMT_SMALLCAPTIONFONT
:
771 state
->metrics
.lfSmCaptionFont
= font
;
772 state
->metricsDirty
= TRUE
;
775 state
->metrics
.lfMenuFont
= font
;
776 state
->metricsDirty
= TRUE
;
779 state
->metrics
.lfStatusFont
= font
;
780 state
->metricsDirty
= TRUE
;
783 state
->metrics
.lfMessageFont
= font
;
784 state
->metricsDirty
= TRUE
;
786 case TMT_ICONTITLEFONT
:
787 state
->iconTitleFont
= font
;
788 state
->metricsDirty
= TRUE
;
797 static BOOL
parse_handle_nonclient_size (struct PARSENONCLIENTSTATE
* state
,
798 int iPropertyId
, LPCWSTR lpValue
,
802 LPCWSTR lpValueEnd
= lpValue
+ dwValueLen
;
803 if(MSSTYLES_GetNextInteger(lpValue
, lpValueEnd
, &lpValue
, &size
)) {
806 case TMT_SIZINGBORDERWIDTH
:
807 state
->metrics
.iBorderWidth
= size
;
808 state
->metricsDirty
= TRUE
;
810 case TMT_SCROLLBARWIDTH
:
811 state
->metrics
.iScrollWidth
= size
;
812 state
->metricsDirty
= TRUE
;
814 case TMT_SCROLLBARHEIGHT
:
815 state
->metrics
.iScrollHeight
= size
;
816 state
->metricsDirty
= TRUE
;
818 case TMT_CAPTIONBARWIDTH
:
819 state
->metrics
.iCaptionWidth
= size
;
820 state
->metricsDirty
= TRUE
;
822 case TMT_CAPTIONBARHEIGHT
:
823 state
->metrics
.iCaptionHeight
= size
;
824 state
->metricsDirty
= TRUE
;
826 case TMT_SMCAPTIONBARWIDTH
:
827 state
->metrics
.iSmCaptionWidth
= size
;
828 state
->metricsDirty
= TRUE
;
830 case TMT_SMCAPTIONBARHEIGHT
:
831 state
->metrics
.iSmCaptionHeight
= size
;
832 state
->metricsDirty
= TRUE
;
834 case TMT_MENUBARWIDTH
:
835 state
->metrics
.iMenuWidth
= size
;
836 state
->metricsDirty
= TRUE
;
838 case TMT_MENUBARHEIGHT
:
839 state
->metrics
.iMenuHeight
= size
;
840 state
->metricsDirty
= TRUE
;
849 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE
* state
)
851 if (state
->metricsDirty
)
853 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (state
->metrics
),
855 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (state
->iconTitleFont
),
856 &state
->iconTitleFont
, 0);
860 /***********************************************************************
861 * MSSTYLES_ParseThemeIni
863 * Parse the theme ini for the selected color/style
868 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf
, BOOL setMetrics
)
870 static const WCHAR szSysMetrics
[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
871 static const WCHAR szGlobals
[] = {'g','l','o','b','a','l','s','\0'};
873 PTHEME_CLASS globals
;
876 WCHAR szAppName
[MAX_THEME_APP_NAME
];
877 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
878 WCHAR szPropertyName
[MAX_THEME_VALUE_NAME
];
881 int iPropertyPrimitive
;
888 ini
= MSSTYLES_GetActiveThemeIni(tf
);
890 while((lpName
=UXINI_GetNextSection(ini
, &dwLen
))) {
891 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, lpName
, dwLen
, szSysMetrics
, -1) == CSTR_EQUAL
) {
892 struct PARSECOLORSTATE colorState
;
893 struct PARSENONCLIENTSTATE nonClientState
;
895 parse_init_color (&colorState
);
896 parse_init_nonclient (&nonClientState
);
898 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
899 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
900 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
901 if(iPropertyId
>= TMT_FIRSTCOLOR
&& iPropertyId
<= TMT_LASTCOLOR
) {
902 if (!parse_handle_color_property (&colorState
, iPropertyId
,
903 lpValue
, dwValueLen
))
904 FIXME("Invalid color value for %s\n",
905 debugstr_w(szPropertyName
));
907 else if (setMetrics
&& (iPropertyId
== TMT_FLATMENUS
)) {
908 BOOL flatMenus
= (*lpValue
== 'T') || (*lpValue
== 't');
909 SystemParametersInfoW (SPI_SETFLATMENU
, 0, (PVOID
)(INT_PTR
)flatMenus
, 0);
911 else if ((iPropertyId
>= TMT_FIRSTFONT
)
912 && (iPropertyId
<= TMT_LASTFONT
))
914 if (!parse_handle_nonclient_font (&nonClientState
,
915 iPropertyId
, lpValue
, dwValueLen
))
916 FIXME("Invalid font value for %s\n",
917 debugstr_w(szPropertyName
));
919 else if ((iPropertyId
>= TMT_FIRSTSIZE
)
920 && (iPropertyId
<= TMT_LASTSIZE
))
922 if (!parse_handle_nonclient_size (&nonClientState
,
923 iPropertyId
, lpValue
, dwValueLen
))
924 FIXME("Invalid size value for %s\n",
925 debugstr_w(szPropertyName
));
927 /* Catch all metrics, including colors */
928 MSSTYLES_AddMetric(tf
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
);
931 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName
));
936 parse_apply_color (&colorState
);
937 parse_apply_nonclient (&nonClientState
);
941 if(MSSTYLES_ParseIniSectionName(lpName
, dwLen
, szAppName
, szClassName
, &iPartId
, &iStateId
)) {
942 BOOL isGlobal
= FALSE
;
943 if(!lstrcmpiW(szClassName
, szGlobals
)) {
946 cls
= MSSTYLES_AddClass(tf
, szAppName
, szClassName
);
947 ps
= MSSTYLES_AddPartState(cls
, iPartId
, iStateId
);
949 while((lpName
=UXINI_GetNextValue(ini
, &dwLen
, &lpValue
, &dwValueLen
))) {
950 lstrcpynW(szPropertyName
, lpName
, min(dwLen
+1, sizeof(szPropertyName
)/sizeof(szPropertyName
[0])));
951 if(MSSTYLES_LookupProperty(szPropertyName
, &iPropertyPrimitive
, &iPropertyId
)) {
952 MSSTYLES_AddProperty(ps
, iPropertyPrimitive
, iPropertyId
, lpValue
, dwValueLen
, isGlobal
);
955 TRACE("Unknown property %s\n", debugstr_w(szPropertyName
));
961 /* App/Class combos override values defined by the base class, map these overrides */
962 globals
= MSSTYLES_FindClass(tf
, NULL
, szGlobals
);
965 if(*cls
->szAppName
) {
966 cls
->overrides
= MSSTYLES_FindClass(tf
, NULL
, cls
->szClassName
);
967 if(!cls
->overrides
) {
968 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
));
971 cls
->overrides
= globals
;
975 /* Everything overrides globals..except globals */
976 if(cls
!= globals
) cls
->overrides
= globals
;
983 ERR("Failed to parse theme ini\n");
987 /***********************************************************************
988 * MSSTYLES_OpenThemeClass
990 * Open a theme class, uses the current active theme
993 * pszAppName Application name, for theme styles specific
994 * to a particular application
995 * pszClassList List of requested classes, semicolon delimited
997 PTHEME_CLASS
MSSTYLES_OpenThemeClass(LPCWSTR pszAppName
, LPCWSTR pszClassList
)
999 PTHEME_CLASS cls
= NULL
;
1000 WCHAR szClassName
[MAX_THEME_CLASS_NAME
];
1005 if(!tfActiveTheme
) {
1006 TRACE("there is no active theme\n");
1009 if(!tfActiveTheme
->classes
) {
1013 start
= pszClassList
;
1014 while((end
= strchrW(start
, ';'))) {
1016 lstrcpynW(szClassName
, start
, min(len
+1, sizeof(szClassName
)/sizeof(szClassName
[0])));
1018 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1021 if(!cls
&& *start
) {
1022 lstrcpynW(szClassName
, start
, sizeof(szClassName
)/sizeof(szClassName
[0]));
1023 cls
= MSSTYLES_FindClass(tfActiveTheme
, pszAppName
, szClassName
);
1026 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls
->szAppName
), debugstr_w(cls
->szClassName
), debugstr_w(pszClassList
));
1027 cls
->tf
= tfActiveTheme
;
1028 cls
->tf
->dwRefCount
++;
1033 /***********************************************************************
1034 * MSSTYLES_CloseThemeClass
1036 * Close a theme class
1039 * tc Theme class to close
1042 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1043 * theme file and cleans it up, if needed.
1045 HRESULT
MSSTYLES_CloseThemeClass(PTHEME_CLASS tc
)
1047 MSSTYLES_CloseThemeFile (tc
->tf
);
1051 /***********************************************************************
1052 * MSSTYLES_FindProperty
1054 * Locate a property in a class. Part and state IDs will be used as a
1055 * preference, but may be ignored in the attempt to locate the property.
1056 * Will scan the entire chain of overrides for this class.
1058 PTHEME_PROPERTY
MSSTYLES_FindProperty(PTHEME_CLASS tc
, int iPartId
, int iStateId
, int iPropertyPrimitive
, int iPropertyId
)
1060 PTHEME_CLASS next
= tc
;
1061 PTHEME_PARTSTATE ps
;
1064 TRACE("(%p, %d, %d, %d)\n", tc
, iPartId
, iStateId
, iPropertyId
);
1065 /* Try and find an exact match on part & state */
1066 while(next
&& (ps
= MSSTYLES_FindPartState(next
, iPartId
, iStateId
, &next
))) {
1067 if((tp
= MSSTYLES_PSFindProperty(ps
, iPropertyPrimitive
, iPropertyId
))) {
1071 /* If that fails, and we didn't already try it, search for just part */
1074 /* As a last ditch attempt..go for just class */
1075 else if(iPartId
!= 0)
1080 if((tp
= MSSTYLES_FindProperty(tc
, iPartId
, iStateId
, iPropertyPrimitive
, iPropertyId
)))
1085 /* Prepare a bitmap to be used for alpha blending */
1086 static BOOL
prepare_alpha (HBITMAP bmp
, BOOL
* hasAlpha
)
1094 if (!bmp
|| GetObjectW( bmp
, sizeof(dib
), &dib
) != sizeof(dib
))
1097 if(dib
.dsBm
.bmBitsPixel
!= 32)
1102 p
= dib
.dsBm
.bmBits
;
1103 n
= dib
.dsBmih
.biHeight
* dib
.dsBmih
.biWidth
;
1104 /* AlphaBlend() wants premultiplied alpha, so do that now */
1108 p
[0] = (p
[0] * a
) >> 8;
1109 p
[1] = (p
[1] * a
) >> 8;
1110 p
[2] = (p
[2] * a
) >> 8;
1117 HBITMAP
MSSTYLES_LoadBitmap (PTHEME_CLASS tc
, LPCWSTR lpFilename
, BOOL
* hasAlpha
)
1119 WCHAR szFile
[MAX_PATH
];
1122 lstrcpynW(szFile
, lpFilename
, sizeof(szFile
)/sizeof(szFile
[0]));
1125 if(*tmp
== '\\') *tmp
= '_';
1126 if(*tmp
== '/') *tmp
= '_';
1127 if(*tmp
== '.') *tmp
= '_';
1130 /* Try to locate in list of loaded images */
1131 img
= tc
->tf
->images
;
1134 if (lstrcmpiW (szFile
, img
->name
) == 0)
1136 TRACE ("found %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1137 *hasAlpha
= img
->hasAlpha
;
1142 /* Not found? Load from resources */
1143 img
= HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE
));
1144 img
->image
= LoadImageW(tc
->hTheme
, szFile
, IMAGE_BITMAP
, 0, 0, LR_CREATEDIBSECTION
);
1145 prepare_alpha (img
->image
, hasAlpha
);
1146 img
->hasAlpha
= *hasAlpha
;
1147 /* ...and stow away for later reuse. */
1148 lstrcpyW (img
->name
, szFile
);
1149 img
->next
= tc
->tf
->images
;
1150 tc
->tf
->images
= img
;
1151 TRACE ("new %p %s: %p\n", img
, debugstr_w (img
->name
), img
->image
);
1155 static BOOL
MSSTYLES_GetNextInteger(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, int *value
)
1157 LPCWSTR cur
= lpStringStart
;
1159 BOOL gotNeg
= FALSE
;
1161 while(cur
< lpStringEnd
&& (*cur
< '0' || *cur
> '9' || *cur
== '-')) cur
++;
1162 if(cur
>= lpStringEnd
) {
1169 while(cur
< lpStringEnd
&& (*cur
>= '0' && *cur
<= '9')) {
1170 total
= total
* 10 + (*cur
- '0');
1173 if(gotNeg
) total
= -total
;
1175 if(lpValEnd
) *lpValEnd
= cur
;
1179 static inline BOOL
isSpace(WCHAR c
)
1181 return c
== ' ' || c
== '\f' || c
== '\n' || c
== '\r' || c
== '\t' || c
== '\v';
1184 static BOOL
MSSTYLES_GetNextToken(LPCWSTR lpStringStart
, LPCWSTR lpStringEnd
, LPCWSTR
*lpValEnd
, LPWSTR lpBuff
, DWORD buffSize
) {
1185 LPCWSTR cur
= lpStringStart
;
1189 while(cur
< lpStringEnd
&& (isSpace(*cur
) || *cur
== ',')) cur
++;
1190 if(cur
>= lpStringEnd
) {
1194 while(cur
< lpStringEnd
&& *cur
!= ',') cur
++;
1196 while(isSpace(*end
)) end
--;
1198 lstrcpynW(lpBuff
, start
, min(buffSize
, end
-start
+1));
1200 if(lpValEnd
) *lpValEnd
= cur
;
1204 /***********************************************************************
1205 * MSSTYLES_GetPropertyBool
1207 * Retrieve a color value for a property
1209 HRESULT
MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp
, BOOL
*pfVal
)
1212 if(*tp
->lpValue
== 't' || *tp
->lpValue
== 'T')
1217 /***********************************************************************
1218 * MSSTYLES_GetPropertyColor
1220 * Retrieve a color value for a property
1222 HRESULT
MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp
, COLORREF
*pColor
)
1226 int red
, green
, blue
;
1228 lpCur
= tp
->lpValue
;
1229 lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1231 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &red
)) {
1232 TRACE("Could not parse color property\n");
1233 return E_PROP_ID_UNSUPPORTED
;
1235 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &green
)) {
1236 TRACE("Could not parse color property\n");
1237 return E_PROP_ID_UNSUPPORTED
;
1239 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &blue
)) {
1240 TRACE("Could not parse color property\n");
1241 return E_PROP_ID_UNSUPPORTED
;
1243 *pColor
= RGB(red
,green
,blue
);
1247 /***********************************************************************
1248 * MSSTYLES_GetPropertyColor
1250 * Retrieve a color value for a property
1252 static HRESULT
MSSTYLES_GetFont (LPCWSTR lpCur
, LPCWSTR lpEnd
,
1253 LPCWSTR
*lpValEnd
, LOGFONTW
* pFont
)
1255 static const WCHAR szBold
[] = {'b','o','l','d','\0'};
1256 static const WCHAR szItalic
[] = {'i','t','a','l','i','c','\0'};
1257 static const WCHAR szUnderline
[] = {'u','n','d','e','r','l','i','n','e','\0'};
1258 static const WCHAR szStrikeOut
[] = {'s','t','r','i','k','e','o','u','t','\0'};
1262 if(!MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, pFont
->lfFaceName
, LF_FACESIZE
)) {
1263 TRACE("Property is there, but failed to get face name\n");
1265 return E_PROP_ID_UNSUPPORTED
;
1267 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pointSize
)) {
1268 TRACE("Property is there, but failed to get point size\n");
1270 return E_PROP_ID_UNSUPPORTED
;
1272 pFont
->lfHeight
= pointSize
;
1273 pFont
->lfWeight
= FW_REGULAR
;
1274 pFont
->lfCharSet
= DEFAULT_CHARSET
;
1275 while(MSSTYLES_GetNextToken(lpCur
, lpEnd
, &lpCur
, attr
, sizeof(attr
)/sizeof(attr
[0]))) {
1276 if(!lstrcmpiW(szBold
, attr
)) pFont
->lfWeight
= FW_BOLD
;
1277 else if(!lstrcmpiW(szItalic
, attr
)) pFont
->lfItalic
= TRUE
;
1278 else if(!lstrcmpiW(szUnderline
, attr
)) pFont
->lfUnderline
= TRUE
;
1279 else if(!lstrcmpiW(szStrikeOut
, attr
)) pFont
->lfStrikeOut
= TRUE
;
1285 HRESULT
MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp
, HDC hdc
, LOGFONTW
*pFont
)
1287 LPCWSTR lpCur
= tp
->lpValue
;
1288 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1291 ZeroMemory(pFont
, sizeof(LOGFONTW
));
1292 hr
= MSSTYLES_GetFont (lpCur
, lpEnd
, &lpCur
, pFont
);
1294 pFont
->lfHeight
= -MulDiv(pFont
->lfHeight
, GetDeviceCaps(hdc
, LOGPIXELSY
), 72);
1299 /***********************************************************************
1300 * MSSTYLES_GetPropertyInt
1302 * Retrieve an int value for a property
1304 HRESULT
MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp
, int *piVal
)
1306 if(!MSSTYLES_GetNextInteger(tp
->lpValue
, (tp
->lpValue
+ tp
->dwValueLen
), NULL
, piVal
)) {
1307 TRACE("Could not parse int property\n");
1308 return E_PROP_ID_UNSUPPORTED
;
1313 /***********************************************************************
1314 * MSSTYLES_GetPropertyIntList
1316 * Retrieve an int list value for a property
1318 HRESULT
MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp
, INTLIST
*pIntList
)
1321 LPCWSTR lpCur
= tp
->lpValue
;
1322 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1324 for(i
=0; i
< MAX_INTLIST_COUNT
; i
++) {
1325 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pIntList
->iValues
[i
]))
1328 pIntList
->iValueCount
= i
;
1332 /***********************************************************************
1333 * MSSTYLES_GetPropertyPosition
1335 * Retrieve a position value for a property
1337 HRESULT
MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp
, POINT
*pPoint
)
1340 LPCWSTR lpCur
= tp
->lpValue
;
1341 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1343 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &x
)) {
1344 TRACE("Could not parse position property\n");
1345 return E_PROP_ID_UNSUPPORTED
;
1347 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &y
)) {
1348 TRACE("Could not parse position property\n");
1349 return E_PROP_ID_UNSUPPORTED
;
1356 /***********************************************************************
1357 * MSSTYLES_GetPropertyString
1359 * Retrieve a string value for a property
1361 HRESULT
MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp
, LPWSTR pszBuff
, int cchMaxBuffChars
)
1363 lstrcpynW(pszBuff
, tp
->lpValue
, min(tp
->dwValueLen
+1, cchMaxBuffChars
));
1367 /***********************************************************************
1368 * MSSTYLES_GetPropertyRect
1370 * Retrieve a rect value for a property
1372 HRESULT
MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp
, RECT
*pRect
)
1374 LPCWSTR lpCur
= tp
->lpValue
;
1375 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1377 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->left
);
1378 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->top
);
1379 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->right
);
1380 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pRect
->bottom
)) {
1381 TRACE("Could not parse rect property\n");
1382 return E_PROP_ID_UNSUPPORTED
;
1387 /***********************************************************************
1388 * MSSTYLES_GetPropertyMargins
1390 * Retrieve a margins value for a property
1392 HRESULT
MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp
, RECT
*prc
, MARGINS
*pMargins
)
1394 LPCWSTR lpCur
= tp
->lpValue
;
1395 LPCWSTR lpEnd
= tp
->lpValue
+ tp
->dwValueLen
;
1397 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxLeftWidth
);
1398 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cxRightWidth
);
1399 MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyTopHeight
);
1400 if(!MSSTYLES_GetNextInteger(lpCur
, lpEnd
, &lpCur
, &pMargins
->cyBottomHeight
)) {
1401 TRACE("Could not parse margins property\n");
1402 return E_PROP_ID_UNSUPPORTED
;