dsound/tests: Allow more time for an event to be signalled.
[wine.git] / dlls / uxtheme / msstyles.c
blobcee5aaf054ec5c78d90fae2ae7e8c43d2c6269b2
1 /*
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
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "vfwmsgs.h"
30 #include "uxtheme.h"
31 #include "tmschema.h"
33 #include "msstyles.h"
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
66 * PARAMS
67 * lpThemeFile Path to theme file to load
68 * pszColorName Color name wanted, can be NULL
69 * pszSizeName Size name wanted, can be NULL
71 * NOTES
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)
78 HMODULE hTheme;
79 HRSRC hrsc;
80 HRESULT hr = S_OK;
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'
91 WORD version;
92 DWORD versize;
93 LPWSTR pszColors;
94 LPWSTR pszSelectedColor = NULL;
95 LPWSTR pszSizes;
96 LPWSTR pszSelectedSize = NULL;
97 LPWSTR tmp;
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 */
104 if(!hTheme) {
105 hr = HRESULT_FROM_WIN32(GetLastError());
106 goto invalid_theme;
108 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szPackThemVersionResource))) {
109 TRACE("No version resource found\n");
110 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
111 goto invalid_theme;
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);
117 goto invalid_theme;
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);
124 goto invalid_theme;
127 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szColorNamesResource))) {
128 TRACE("Color names resource not found\n");
129 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
130 goto invalid_theme;
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);
137 goto invalid_theme;
139 pszSizes = LoadResource(hTheme, hrsc);
141 /* Validate requested color against what's available from the theme */
142 if(pszColorName) {
143 tmp = pszColors;
144 while(*tmp) {
145 if(!lstrcmpiW(pszColorName, tmp)) {
146 pszSelectedColor = tmp;
147 break;
149 tmp += lstrlenW(tmp)+1;
152 else
153 pszSelectedColor = pszColors; /* Use the default color */
155 /* Validate requested size against what's available from the theme */
156 if(pszSizeName) {
157 tmp = pszSizes;
158 while(*tmp) {
159 if(!lstrcmpiW(pszSizeName, tmp)) {
160 pszSelectedSize = tmp;
161 break;
163 tmp += lstrlenW(tmp)+1;
166 else
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;
173 goto invalid_theme;
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;
186 return S_OK;
188 invalid_theme:
189 *tf = NULL;
190 if(hTheme) FreeLibrary(hTheme);
191 return hr;
194 /***********************************************************************
195 * MSSTYLES_CloseThemeFile
197 * Close theme file and free resources
199 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
201 if(tf) {
202 tf->dwRefCount--;
203 if(!tf->dwRefCount) {
204 if(tf->hTheme) FreeLibrary(tf->hTheme);
205 if(tf->classes) {
206 while(tf->classes) {
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;
215 heap_free(prop);
218 pcls->partstate = ps->next;
219 heap_free(ps);
221 heap_free(pcls);
224 while (tf->images)
226 PTHEME_IMAGE img = tf->images;
227 tf->images = img->next;
228 DeleteObject (img->image);
229 heap_free(img);
231 heap_free(tf);
236 /***********************************************************************
237 * MSSTYLES_SetActiveTheme
239 * Set the current active theme
241 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf, BOOL setMetrics)
243 if(tfActiveTheme)
244 MSSTYLES_CloseThemeFile(tfActiveTheme);
245 tfActiveTheme = tf;
246 if (tfActiveTheme)
248 tfActiveTheme->dwRefCount++;
249 if(!tfActiveTheme->classes)
250 MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics);
252 return S_OK;
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;
278 DWORD dwSizeNum = 0;
279 DWORD i;
280 DWORD dwResourceIndex;
281 LPWSTR tmp;
282 HRSRC hrsc;
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;
288 while(*tmp) {
289 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
290 dwColorNum = dwColorCount;
291 tmp += lstrlenW(tmp)+1;
292 dwColorCount++;
294 tmp = tf->pszAvailSizes;
295 while(*tmp) {
296 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
297 dwSizeNum = dwSizeCount;
298 tmp += lstrlenW(tmp)+1;
299 dwSizeCount++;
302 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
303 TRACE("FILERESNAMES map not found\n");
304 return NULL;
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
319 * Valid formats are:
320 * [classname]
321 * [classname(state)]
322 * [classname.part]
323 * [classname.part(state)]
324 * [application::classname]
325 * [application::classname(state)]
326 * [application::classname.part]
327 * [application::classname.part(state)]
329 * PARAMS
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)
339 WCHAR sec[255];
340 WCHAR part[60] = {'\0'};
341 WCHAR state[60] = {'\0'};
342 LPWSTR tmp;
343 LPWSTR comp;
344 lstrcpynW(sec, lpSection, min(dwLen+1, ARRAY_SIZE(sec)));
346 *szAppName = 0;
347 *szClassName = 0;
348 *iPartId = 0;
349 *iStateId = 0;
350 comp = sec;
351 /* Get the application name */
352 tmp = wcschr(comp, ':');
353 if(tmp) {
354 *tmp++ = 0;
355 tmp++;
356 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
357 comp = tmp;
360 tmp = wcschr(comp, '.');
361 if(tmp) {
362 *tmp++ = 0;
363 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
364 comp = tmp;
365 /* now get the part & state */
366 tmp = wcschr(comp, '(');
367 if(tmp) {
368 *tmp++ = 0;
369 lstrcpynW(part, comp, ARRAY_SIZE(part));
370 comp = tmp;
371 /* now get the state */
372 tmp = wcschr(comp, ')');
373 if (!tmp)
374 return FALSE;
375 *tmp = 0;
376 lstrcpynW(state, comp, ARRAY_SIZE(state));
378 else {
379 lstrcpynW(part, comp, ARRAY_SIZE(part));
382 else {
383 tmp = wcschr(comp, '(');
384 if(tmp) {
385 *tmp++ = 0;
386 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
387 comp = tmp;
388 /* now get the state */
389 tmp = wcschr(comp, ')');
390 if (!tmp)
391 return FALSE;
392 *tmp = 0;
393 lstrcpynW(state, comp, ARRAY_SIZE(state));
395 else {
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 /***********************************************************************
404 * MSSTYLES_FindClass
406 * Find a class
408 * PARAMS
409 * tf Theme file
410 * pszAppName App name to find
411 * pszClassName Class name to find
413 * RETURNS
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;
419 while(cur) {
420 if(!pszAppName) {
421 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
422 return cur;
424 else {
425 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
426 return cur;
428 cur = cur->next;
430 return NULL;
433 /***********************************************************************
434 * MSSTYLES_AddClass
436 * Add a class to a theme file
438 * PARAMS
439 * tf Theme file
440 * pszAppName App name to add
441 * pszClassName Class name to add
443 * RETURNS
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);
449 if(cur) return cur;
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;
458 tf->classes = cur;
459 return cur;
462 /***********************************************************************
463 * MSSTYLES_FindPartState
465 * Find a part/state
467 * PARAMS
468 * tc Class to search
469 * iPartId Part ID to find
470 * iStateId State ID to find
471 * tcNext Receives the next class in the override chain
473 * RETURNS
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;
479 while(cur) {
480 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
481 if(tcNext) *tcNext = tc->overrides;
482 return cur;
484 cur = cur->next;
486 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
487 return NULL;
490 /***********************************************************************
491 * MSSTYLES_AddPartState
493 * Add a part/state to a class
495 * PARAMS
496 * tc Theme class
497 * iPartId Part ID to add
498 * iStateId State ID to add
500 * RETURNS
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);
506 if(cur) return cur;
508 cur = heap_alloc(sizeof(*cur));
509 cur->iPartId = iPartId;
510 cur->iStateId = iStateId;
511 cur->properties = NULL;
512 cur->next = tc->partstate;
513 tc->partstate = cur;
514 return cur;
517 /***********************************************************************
518 * MSSTYLES_LFindProperty
520 * Find a property within a property list
522 * PARAMS
523 * tp property list to scan
524 * iPropertyPrimitive Type of value expected
525 * iPropertyId ID of the required value
527 * RETURNS
528 * The property found, or NULL
530 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
532 PTHEME_PROPERTY cur = tp;
533 while(cur) {
534 if(cur->iPropertyId == iPropertyId) {
535 if(cur->iPrimitiveType == iPropertyPrimitive) {
536 return cur;
538 else {
539 if(!iPropertyPrimitive)
540 return cur;
541 return NULL;
544 cur = cur->next;
546 return NULL;
549 /***********************************************************************
550 * MSSTYLES_PSFindProperty
552 * Find a value within a part/state
554 * PARAMS
555 * ps Part/state to search
556 * iPropertyPrimitive Type of value expected
557 * iPropertyId ID of the required value
559 * RETURNS
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
572 * PARAMS
573 * tf Theme file
574 * iPropertyPrimitive Type of value expected
575 * iPropertyId ID of the required value
577 * RETURNS
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
590 * PARAMS
591 * tf Theme file
592 * iPropertyPrimitive Type of value expected
593 * iPropertyId ID of the required value
595 * RETURNS
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
609 * PARAMS
610 * ps 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
616 * RETURNS
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? */
623 if(cur) return cur;
625 cur = heap_alloc(sizeof(*cur));
626 cur->iPrimitiveType = iPropertyPrimitive;
627 cur->iPropertyId = iPropertyId;
628 cur->lpValue = lpValue;
629 cur->dwValueLen = dwValueLen;
631 if(ps->iStateId)
632 cur->origin = PO_STATE;
633 else if(ps->iPartId)
634 cur->origin = PO_PART;
635 else if(isGlobal)
636 cur->origin = PO_GLOBAL;
637 else
638 cur->origin = PO_CLASS;
640 cur->next = ps->properties;
641 ps->properties = cur;
642 return cur;
645 /***********************************************************************
646 * MSSTYLES_AddMetric
648 * Add a property to a part/state
650 * PARAMS
651 * tf Theme file
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
657 * RETURNS
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? */
664 if(cur) return cur;
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;
675 tf->metrics = cur;
676 return cur;
679 /* Color-related state for theme ini parsing */
680 struct PARSECOLORSTATE
682 int colorCount;
683 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
684 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
685 int captionColors;
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,
695 DWORD dwValueLen)
697 int r,g,b;
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);
704 switch (iPropertyId)
706 case TMT_ACTIVECAPTION:
707 state->captionColors |= 0x1;
708 break;
709 case TMT_INACTIVECAPTION:
710 state->captionColors |= 0x2;
711 break;
712 case TMT_GRADIENTACTIVECAPTION:
713 state->captionColors |= 0x4;
714 break;
715 case TMT_GRADIENTINACTIVECAPTION:
716 state->captionColors |= 0x8;
717 break;
719 return TRUE;
721 else {
722 return FALSE;
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;
738 BOOL metricsDirty;
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),
747 &state->metrics, 0);
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,
754 DWORD dwValueLen)
756 LOGFONTW font;
758 memset (&font, 0, sizeof (font));
759 if (SUCCEEDED (MSSTYLES_GetFont (lpValue, lpValue + dwValueLen, &lpValue,
760 &font)))
762 switch (iPropertyId)
764 case TMT_CAPTIONFONT:
765 state->metrics.lfCaptionFont = font;
766 state->metricsDirty = TRUE;
767 break;
768 case TMT_SMALLCAPTIONFONT:
769 state->metrics.lfSmCaptionFont = font;
770 state->metricsDirty = TRUE;
771 break;
772 case TMT_MENUFONT:
773 state->metrics.lfMenuFont = font;
774 state->metricsDirty = TRUE;
775 break;
776 case TMT_STATUSFONT:
777 state->metrics.lfStatusFont = font;
778 state->metricsDirty = TRUE;
779 break;
780 case TMT_MSGBOXFONT:
781 state->metrics.lfMessageFont = font;
782 state->metricsDirty = TRUE;
783 break;
784 case TMT_ICONTITLEFONT:
785 state->iconTitleFont = font;
786 state->metricsDirty = TRUE;
787 break;
789 return TRUE;
791 else
792 return FALSE;
795 static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
796 int iPropertyId, LPCWSTR lpValue,
797 DWORD dwValueLen)
799 int size;
800 LPCWSTR lpValueEnd = lpValue + dwValueLen;
801 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &size)) {
802 switch (iPropertyId)
804 case TMT_SIZINGBORDERWIDTH:
805 state->metrics.iBorderWidth = size;
806 state->metricsDirty = TRUE;
807 break;
808 case TMT_SCROLLBARWIDTH:
809 state->metrics.iScrollWidth = size;
810 state->metricsDirty = TRUE;
811 break;
812 case TMT_SCROLLBARHEIGHT:
813 state->metrics.iScrollHeight = size;
814 state->metricsDirty = TRUE;
815 break;
816 case TMT_CAPTIONBARWIDTH:
817 state->metrics.iCaptionWidth = size;
818 state->metricsDirty = TRUE;
819 break;
820 case TMT_CAPTIONBARHEIGHT:
821 state->metrics.iCaptionHeight = size;
822 state->metricsDirty = TRUE;
823 break;
824 case TMT_SMCAPTIONBARWIDTH:
825 state->metrics.iSmCaptionWidth = size;
826 state->metricsDirty = TRUE;
827 break;
828 case TMT_SMCAPTIONBARHEIGHT:
829 state->metrics.iSmCaptionHeight = size;
830 state->metricsDirty = TRUE;
831 break;
832 case TMT_MENUBARWIDTH:
833 state->metrics.iMenuWidth = size;
834 state->metricsDirty = TRUE;
835 break;
836 case TMT_MENUBARHEIGHT:
837 state->metrics.iMenuHeight = size;
838 state->metricsDirty = TRUE;
839 break;
841 return TRUE;
843 else
844 return FALSE;
847 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state)
849 if (state->metricsDirty)
851 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics),
852 &state->metrics, 0);
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
863 * PARAMS
864 * tf Theme to parse
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'};
870 PTHEME_CLASS cls;
871 PTHEME_CLASS globals;
872 PTHEME_PARTSTATE ps;
873 PUXINI_FILE ini;
874 WCHAR szAppName[MAX_THEME_APP_NAME];
875 WCHAR szClassName[MAX_THEME_CLASS_NAME];
876 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
877 int iPartId;
878 int iStateId;
879 int iPropertyPrimitive;
880 int iPropertyId;
881 DWORD dwLen;
882 LPCWSTR lpName;
883 DWORD dwValueLen;
884 LPCWSTR lpValue;
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);
928 else {
929 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
932 if (setMetrics)
934 parse_apply_color (&colorState);
935 parse_apply_nonclient (&nonClientState);
937 continue;
939 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
940 BOOL isGlobal = FALSE;
941 if(!lstrcmpiW(szClassName, szGlobals)) {
942 isGlobal = TRUE;
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);
952 else {
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);
961 cls = tf->classes;
962 while(cls) {
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));
968 else {
969 cls->overrides = globals;
972 else {
973 /* Everything overrides globals..except globals */
974 if(cls != globals) cls->overrides = globals;
976 cls = cls->next;
978 UXINI_CloseINI(ini);
980 if(!tf->classes) {
981 ERR("Failed to parse theme ini\n");
985 /***********************************************************************
986 * MSSTYLES_OpenThemeClass
988 * Open a theme class, uses the current active theme
990 * PARAMS
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];
999 LPCWSTR start;
1000 LPCWSTR end;
1001 DWORD len;
1003 if(!tfActiveTheme) {
1004 TRACE("there is no active theme\n");
1005 return NULL;
1007 if(!tfActiveTheme->classes) {
1008 return NULL;
1011 start = pszClassList;
1012 while((end = wcschr(start, ';'))) {
1013 len = end-start;
1014 lstrcpynW(szClassName, start, min(len+1, ARRAY_SIZE(szClassName)));
1015 start = end+1;
1016 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1017 if(cls) break;
1019 if(!cls && *start) {
1020 lstrcpynW(szClassName, start, ARRAY_SIZE(szClassName));
1021 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1023 if(cls) {
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++;
1028 return cls;
1031 /***********************************************************************
1032 * MSSTYLES_CloseThemeClass
1034 * Close a theme class
1036 * PARAMS
1037 * tc Theme class to close
1039 * NOTES
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);
1046 return S_OK;
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;
1060 PTHEME_PROPERTY tp;
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))) {
1066 return tp;
1069 /* If that fails, and we didn't already try it, search for just part */
1070 if(iStateId != 0)
1071 iStateId = 0;
1072 /* As a last ditch attempt..go for just class */
1073 else if(iPartId != 0)
1074 iPartId = 0;
1075 else
1076 return NULL;
1078 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
1079 return tp;
1080 return NULL;
1083 /* Prepare a bitmap to be used for alpha blending */
1084 static BOOL prepare_alpha (HBITMAP bmp, BOOL* hasAlpha)
1086 DIBSECTION dib;
1087 int n;
1088 BYTE* p;
1090 *hasAlpha = FALSE;
1092 if (!bmp || GetObjectW( bmp, sizeof(dib), &dib ) != sizeof(dib))
1093 return FALSE;
1095 if(dib.dsBm.bmBitsPixel != 32)
1096 /* nothing to do */
1097 return TRUE;
1099 *hasAlpha = TRUE;
1100 p = dib.dsBm.bmBits;
1101 n = dib.dsBmih.biHeight * dib.dsBmih.biWidth;
1102 /* AlphaBlend() wants premultiplied alpha, so do that now */
1103 while (n-- > 0)
1105 int a = p[3]+1;
1106 p[0] = (p[0] * a) >> 8;
1107 p[1] = (p[1] * a) >> 8;
1108 p[2] = (p[2] * a) >> 8;
1109 p += 4;
1112 return TRUE;
1115 HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
1117 WCHAR szFile[MAX_PATH];
1118 LPWSTR tmp;
1119 PTHEME_IMAGE img;
1120 lstrcpynW(szFile, lpFilename, ARRAY_SIZE(szFile));
1121 tmp = szFile;
1122 do {
1123 if(*tmp == '\\') *tmp = '_';
1124 if(*tmp == '/') *tmp = '_';
1125 if(*tmp == '.') *tmp = '_';
1126 } while(*tmp++);
1128 /* Try to locate in list of loaded images */
1129 img = tc->tf->images;
1130 while (img)
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;
1136 return img->image;
1138 img = img->next;
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);
1150 return img->image;
1153 static BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
1155 LPCWSTR cur = lpStringStart;
1156 int total = 0;
1157 BOOL gotNeg = FALSE;
1159 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
1160 if(cur >= lpStringEnd) {
1161 return FALSE;
1163 if(*cur == '-') {
1164 cur++;
1165 gotNeg = TRUE;
1167 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
1168 total = total * 10 + (*cur - '0');
1169 cur++;
1171 if(gotNeg) total = -total;
1172 *value = total;
1173 if(lpValEnd) *lpValEnd = cur;
1174 return TRUE;
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;
1184 LPCWSTR start;
1185 LPCWSTR end;
1187 while(cur < lpStringEnd && (isSpace(*cur) || *cur == ',')) cur++;
1188 if(cur >= lpStringEnd) {
1189 return FALSE;
1191 start = cur;
1192 while(cur < lpStringEnd && *cur != ',') cur++;
1193 end = cur;
1194 while(isSpace(*end)) end--;
1196 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
1198 if(lpValEnd) *lpValEnd = cur;
1199 return TRUE;
1202 /***********************************************************************
1203 * MSSTYLES_GetPropertyBool
1205 * Retrieve a color value for a property
1207 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
1209 *pfVal = FALSE;
1210 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
1211 *pfVal = TRUE;
1212 return S_OK;
1215 /***********************************************************************
1216 * MSSTYLES_GetPropertyColor
1218 * Retrieve a color value for a property
1220 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
1222 LPCWSTR lpEnd;
1223 LPCWSTR lpCur;
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);
1242 return S_OK;
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'};
1257 int pointSize;
1258 WCHAR attr[32];
1260 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
1261 TRACE("Property is there, but failed to get face name\n");
1262 *lpValEnd = lpCur;
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");
1267 *lpValEnd = lpCur;
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;
1279 *lpValEnd = lpCur;
1280 return S_OK;
1283 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
1285 LPCWSTR lpCur = tp->lpValue;
1286 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1287 HRESULT hr;
1289 ZeroMemory(pFont, sizeof(LOGFONTW));
1290 hr = MSSTYLES_GetFont (lpCur, lpEnd, &lpCur, pFont);
1291 if (SUCCEEDED (hr))
1292 pFont->lfHeight = -MulDiv(pFont->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1294 return hr;
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;
1308 return S_OK;
1311 /***********************************************************************
1312 * MSSTYLES_GetPropertyIntList
1314 * Retrieve an int list value for a property
1316 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1318 int i;
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]))
1324 break;
1326 pIntList->iValueCount = i;
1327 return S_OK;
1330 /***********************************************************************
1331 * MSSTYLES_GetPropertyPosition
1333 * Retrieve a position value for a property
1335 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1337 int x,y;
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;
1349 pPoint->x = x;
1350 pPoint->y = y;
1351 return S_OK;
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));
1362 return S_OK;
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;
1382 return S_OK;
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;
1402 return S_OK;