msvcrt: Don't include MSVC 7.0+ exception functions in SOs for older DLLs.
[wine.git] / dlls / uxtheme / msstyles.c
blobe471c3cc0c03c2d387ffff171b08fcef9db70754
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 "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "vfwmsgs.h"
32 #include "uxtheme.h"
33 #include "tmschema.h"
35 #include "msstyles.h"
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
68 * PARAMS
69 * lpThemeFile Path to theme file to load
70 * pszColorName Color name wanted, can be NULL
71 * pszSizeName Size name wanted, can be NULL
73 * NOTES
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)
80 HMODULE hTheme;
81 HRSRC hrsc;
82 HRESULT hr = S_OK;
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'
93 WORD version;
94 DWORD versize;
95 LPWSTR pszColors;
96 LPWSTR pszSelectedColor = NULL;
97 LPWSTR pszSizes;
98 LPWSTR pszSelectedSize = NULL;
99 LPWSTR tmp;
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 */
106 if(!hTheme) {
107 hr = HRESULT_FROM_WIN32(GetLastError());
108 goto invalid_theme;
110 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szPackThemVersionResource))) {
111 TRACE("No version resource found\n");
112 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
113 goto invalid_theme;
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);
119 goto invalid_theme;
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);
126 goto invalid_theme;
129 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szColorNamesResource))) {
130 TRACE("Color names resource not found\n");
131 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
132 goto invalid_theme;
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);
139 goto invalid_theme;
141 pszSizes = LoadResource(hTheme, hrsc);
143 /* Validate requested color against what's available from the theme */
144 if(pszColorName) {
145 tmp = pszColors;
146 while(*tmp) {
147 if(!lstrcmpiW(pszColorName, tmp)) {
148 pszSelectedColor = tmp;
149 break;
151 tmp += lstrlenW(tmp)+1;
154 else
155 pszSelectedColor = pszColors; /* Use the default color */
157 /* Validate requested size against what's available from the theme */
158 if(pszSizeName) {
159 tmp = pszSizes;
160 while(*tmp) {
161 if(!lstrcmpiW(pszSizeName, tmp)) {
162 pszSelectedSize = tmp;
163 break;
165 tmp += lstrlenW(tmp)+1;
168 else
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;
175 goto invalid_theme;
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;
188 return S_OK;
190 invalid_theme:
191 *tf = NULL;
192 if(hTheme) FreeLibrary(hTheme);
193 return hr;
196 /***********************************************************************
197 * MSSTYLES_CloseThemeFile
199 * Close theme file and free resources
201 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
203 if(tf) {
204 tf->dwRefCount--;
205 if(!tf->dwRefCount) {
206 if(tf->hTheme) FreeLibrary(tf->hTheme);
207 if(tf->classes) {
208 while(tf->classes) {
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);
226 while (tf->images)
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)
245 if(tfActiveTheme)
246 MSSTYLES_CloseThemeFile(tfActiveTheme);
247 tfActiveTheme = tf;
248 if (tfActiveTheme)
250 tfActiveTheme->dwRefCount++;
251 if(!tfActiveTheme->classes)
252 MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics);
254 return S_OK;
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;
280 DWORD dwSizeNum = 0;
281 DWORD i;
282 DWORD dwResourceIndex;
283 LPWSTR tmp;
284 HRSRC hrsc;
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;
290 while(*tmp) {
291 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
292 dwColorNum = dwColorCount;
293 tmp += lstrlenW(tmp)+1;
294 dwColorCount++;
296 tmp = tf->pszAvailSizes;
297 while(*tmp) {
298 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
299 dwSizeNum = dwSizeCount;
300 tmp += lstrlenW(tmp)+1;
301 dwSizeCount++;
304 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
305 TRACE("FILERESNAMES map not found\n");
306 return NULL;
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
321 * Valid formats are:
322 * [classname]
323 * [classname(state)]
324 * [classname.part]
325 * [classname.part(state)]
326 * [application::classname]
327 * [application::classname(state)]
328 * [application::classname.part]
329 * [application::classname.part(state)]
331 * PARAMS
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)
341 WCHAR sec[255];
342 WCHAR part[60] = {'\0'};
343 WCHAR state[60] = {'\0'};
344 LPWSTR tmp;
345 LPWSTR comp;
346 lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
348 *szAppName = 0;
349 *szClassName = 0;
350 *iPartId = 0;
351 *iStateId = 0;
352 comp = sec;
353 /* Get the application name */
354 tmp = strchrW(comp, ':');
355 if(tmp) {
356 *tmp++ = 0;
357 tmp++;
358 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
359 comp = tmp;
362 tmp = strchrW(comp, '.');
363 if(tmp) {
364 *tmp++ = 0;
365 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
366 comp = tmp;
367 /* now get the part & state */
368 tmp = strchrW(comp, '(');
369 if(tmp) {
370 *tmp++ = 0;
371 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
372 comp = tmp;
373 /* now get the state */
374 tmp = strchrW(comp, ')');
375 if (!tmp)
376 return FALSE;
377 *tmp = 0;
378 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
380 else {
381 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
384 else {
385 tmp = strchrW(comp, '(');
386 if(tmp) {
387 *tmp++ = 0;
388 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
389 comp = tmp;
390 /* now get the state */
391 tmp = strchrW(comp, ')');
392 if (!tmp)
393 return FALSE;
394 *tmp = 0;
395 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
397 else {
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 /***********************************************************************
406 * MSSTYLES_FindClass
408 * Find a class
410 * PARAMS
411 * tf Theme file
412 * pszAppName App name to find
413 * pszClassName Class name to find
415 * RETURNS
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;
421 while(cur) {
422 if(!pszAppName) {
423 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
424 return cur;
426 else {
427 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
428 return cur;
430 cur = cur->next;
432 return NULL;
435 /***********************************************************************
436 * MSSTYLES_AddClass
438 * Add a class to a theme file
440 * PARAMS
441 * tf Theme file
442 * pszAppName App name to add
443 * pszClassName Class name to add
445 * RETURNS
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);
451 if(cur) return cur;
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;
460 tf->classes = cur;
461 return cur;
464 /***********************************************************************
465 * MSSTYLES_FindPartState
467 * Find a part/state
469 * PARAMS
470 * tc Class to search
471 * iPartId Part ID to find
472 * iStateId State ID to find
473 * tcNext Receives the next class in the override chain
475 * RETURNS
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;
481 while(cur) {
482 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
483 if(tcNext) *tcNext = tc->overrides;
484 return cur;
486 cur = cur->next;
488 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
489 return NULL;
492 /***********************************************************************
493 * MSSTYLES_AddPartState
495 * Add a part/state to a class
497 * PARAMS
498 * tc Theme class
499 * iPartId Part ID to add
500 * iStateId State ID to add
502 * RETURNS
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);
508 if(cur) return cur;
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;
515 tc->partstate = cur;
516 return cur;
519 /***********************************************************************
520 * MSSTYLES_LFindProperty
522 * Find a property within a property list
524 * PARAMS
525 * tp property list to scan
526 * iPropertyPrimitive Type of value expected
527 * iPropertyId ID of the required value
529 * RETURNS
530 * The property found, or NULL
532 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
534 PTHEME_PROPERTY cur = tp;
535 while(cur) {
536 if(cur->iPropertyId == iPropertyId) {
537 if(cur->iPrimitiveType == iPropertyPrimitive) {
538 return cur;
540 else {
541 if(!iPropertyPrimitive)
542 return cur;
543 return NULL;
546 cur = cur->next;
548 return NULL;
551 /***********************************************************************
552 * MSSTYLES_PSFindProperty
554 * Find a value within a part/state
556 * PARAMS
557 * ps Part/state to search
558 * iPropertyPrimitive Type of value expected
559 * iPropertyId ID of the required value
561 * RETURNS
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
574 * PARAMS
575 * tf Theme file
576 * iPropertyPrimitive Type of value expected
577 * iPropertyId ID of the required value
579 * RETURNS
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
592 * PARAMS
593 * tf Theme file
594 * iPropertyPrimitive Type of value expected
595 * iPropertyId ID of the required value
597 * RETURNS
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
611 * PARAMS
612 * ps 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
618 * RETURNS
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? */
625 if(cur) return cur;
627 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
628 cur->iPrimitiveType = iPropertyPrimitive;
629 cur->iPropertyId = iPropertyId;
630 cur->lpValue = lpValue;
631 cur->dwValueLen = dwValueLen;
633 if(ps->iStateId)
634 cur->origin = PO_STATE;
635 else if(ps->iPartId)
636 cur->origin = PO_PART;
637 else if(isGlobal)
638 cur->origin = PO_GLOBAL;
639 else
640 cur->origin = PO_CLASS;
642 cur->next = ps->properties;
643 ps->properties = cur;
644 return cur;
647 /***********************************************************************
648 * MSSTYLES_AddMetric
650 * Add a property to a part/state
652 * PARAMS
653 * tf Theme file
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
659 * RETURNS
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? */
666 if(cur) return cur;
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;
677 tf->metrics = cur;
678 return cur;
681 /* Color-related state for theme ini parsing */
682 struct PARSECOLORSTATE
684 int colorCount;
685 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
686 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
687 int captionColors;
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,
697 DWORD dwValueLen)
699 int r,g,b;
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);
706 switch (iPropertyId)
708 case TMT_ACTIVECAPTION:
709 state->captionColors |= 0x1;
710 break;
711 case TMT_INACTIVECAPTION:
712 state->captionColors |= 0x2;
713 break;
714 case TMT_GRADIENTACTIVECAPTION:
715 state->captionColors |= 0x4;
716 break;
717 case TMT_GRADIENTINACTIVECAPTION:
718 state->captionColors |= 0x8;
719 break;
721 return TRUE;
723 else {
724 return FALSE;
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;
740 BOOL metricsDirty;
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),
749 &state->metrics, 0);
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,
756 DWORD dwValueLen)
758 LOGFONTW font;
760 memset (&font, 0, sizeof (font));
761 if (SUCCEEDED (MSSTYLES_GetFont (lpValue, lpValue + dwValueLen, &lpValue,
762 &font)))
764 switch (iPropertyId)
766 case TMT_CAPTIONFONT:
767 state->metrics.lfCaptionFont = font;
768 state->metricsDirty = TRUE;
769 break;
770 case TMT_SMALLCAPTIONFONT:
771 state->metrics.lfSmCaptionFont = font;
772 state->metricsDirty = TRUE;
773 break;
774 case TMT_MENUFONT:
775 state->metrics.lfMenuFont = font;
776 state->metricsDirty = TRUE;
777 break;
778 case TMT_STATUSFONT:
779 state->metrics.lfStatusFont = font;
780 state->metricsDirty = TRUE;
781 break;
782 case TMT_MSGBOXFONT:
783 state->metrics.lfMessageFont = font;
784 state->metricsDirty = TRUE;
785 break;
786 case TMT_ICONTITLEFONT:
787 state->iconTitleFont = font;
788 state->metricsDirty = TRUE;
789 break;
791 return TRUE;
793 else
794 return FALSE;
797 static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
798 int iPropertyId, LPCWSTR lpValue,
799 DWORD dwValueLen)
801 int size;
802 LPCWSTR lpValueEnd = lpValue + dwValueLen;
803 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &size)) {
804 switch (iPropertyId)
806 case TMT_SIZINGBORDERWIDTH:
807 state->metrics.iBorderWidth = size;
808 state->metricsDirty = TRUE;
809 break;
810 case TMT_SCROLLBARWIDTH:
811 state->metrics.iScrollWidth = size;
812 state->metricsDirty = TRUE;
813 break;
814 case TMT_SCROLLBARHEIGHT:
815 state->metrics.iScrollHeight = size;
816 state->metricsDirty = TRUE;
817 break;
818 case TMT_CAPTIONBARWIDTH:
819 state->metrics.iCaptionWidth = size;
820 state->metricsDirty = TRUE;
821 break;
822 case TMT_CAPTIONBARHEIGHT:
823 state->metrics.iCaptionHeight = size;
824 state->metricsDirty = TRUE;
825 break;
826 case TMT_SMCAPTIONBARWIDTH:
827 state->metrics.iSmCaptionWidth = size;
828 state->metricsDirty = TRUE;
829 break;
830 case TMT_SMCAPTIONBARHEIGHT:
831 state->metrics.iSmCaptionHeight = size;
832 state->metricsDirty = TRUE;
833 break;
834 case TMT_MENUBARWIDTH:
835 state->metrics.iMenuWidth = size;
836 state->metricsDirty = TRUE;
837 break;
838 case TMT_MENUBARHEIGHT:
839 state->metrics.iMenuHeight = size;
840 state->metricsDirty = TRUE;
841 break;
843 return TRUE;
845 else
846 return FALSE;
849 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state)
851 if (state->metricsDirty)
853 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics),
854 &state->metrics, 0);
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
865 * PARAMS
866 * tf Theme to parse
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'};
872 PTHEME_CLASS cls;
873 PTHEME_CLASS globals;
874 PTHEME_PARTSTATE ps;
875 PUXINI_FILE ini;
876 WCHAR szAppName[MAX_THEME_APP_NAME];
877 WCHAR szClassName[MAX_THEME_CLASS_NAME];
878 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
879 int iPartId;
880 int iStateId;
881 int iPropertyPrimitive;
882 int iPropertyId;
883 DWORD dwLen;
884 LPCWSTR lpName;
885 DWORD dwValueLen;
886 LPCWSTR lpValue;
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);
930 else {
931 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
934 if (setMetrics)
936 parse_apply_color (&colorState);
937 parse_apply_nonclient (&nonClientState);
939 continue;
941 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
942 BOOL isGlobal = FALSE;
943 if(!lstrcmpiW(szClassName, szGlobals)) {
944 isGlobal = TRUE;
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);
954 else {
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);
963 cls = tf->classes;
964 while(cls) {
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));
970 else {
971 cls->overrides = globals;
974 else {
975 /* Everything overrides globals..except globals */
976 if(cls != globals) cls->overrides = globals;
978 cls = cls->next;
980 UXINI_CloseINI(ini);
982 if(!tf->classes) {
983 ERR("Failed to parse theme ini\n");
987 /***********************************************************************
988 * MSSTYLES_OpenThemeClass
990 * Open a theme class, uses the current active theme
992 * PARAMS
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];
1001 LPCWSTR start;
1002 LPCWSTR end;
1003 DWORD len;
1005 if(!tfActiveTheme) {
1006 TRACE("there is no active theme\n");
1007 return NULL;
1009 if(!tfActiveTheme->classes) {
1010 return NULL;
1013 start = pszClassList;
1014 while((end = strchrW(start, ';'))) {
1015 len = end-start;
1016 lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
1017 start = end+1;
1018 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1019 if(cls) break;
1021 if(!cls && *start) {
1022 lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
1023 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1025 if(cls) {
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++;
1030 return cls;
1033 /***********************************************************************
1034 * MSSTYLES_CloseThemeClass
1036 * Close a theme class
1038 * PARAMS
1039 * tc Theme class to close
1041 * NOTES
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);
1048 return S_OK;
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;
1062 PTHEME_PROPERTY tp;
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))) {
1068 return tp;
1071 /* If that fails, and we didn't already try it, search for just part */
1072 if(iStateId != 0)
1073 iStateId = 0;
1074 /* As a last ditch attempt..go for just class */
1075 else if(iPartId != 0)
1076 iPartId = 0;
1077 else
1078 return NULL;
1080 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
1081 return tp;
1082 return NULL;
1085 /* Prepare a bitmap to be used for alpha blending */
1086 static BOOL prepare_alpha (HBITMAP bmp, BOOL* hasAlpha)
1088 DIBSECTION dib;
1089 int n;
1090 BYTE* p;
1092 *hasAlpha = FALSE;
1094 if (!bmp || GetObjectW( bmp, sizeof(dib), &dib ) != sizeof(dib))
1095 return FALSE;
1097 if(dib.dsBm.bmBitsPixel != 32)
1098 /* nothing to do */
1099 return TRUE;
1101 *hasAlpha = TRUE;
1102 p = dib.dsBm.bmBits;
1103 n = dib.dsBmih.biHeight * dib.dsBmih.biWidth;
1104 /* AlphaBlend() wants premultiplied alpha, so do that now */
1105 while (n-- > 0)
1107 int a = p[3]+1;
1108 p[0] = (p[0] * a) >> 8;
1109 p[1] = (p[1] * a) >> 8;
1110 p[2] = (p[2] * a) >> 8;
1111 p += 4;
1114 return TRUE;
1117 HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
1119 WCHAR szFile[MAX_PATH];
1120 LPWSTR tmp;
1121 PTHEME_IMAGE img;
1122 lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
1123 tmp = szFile;
1124 do {
1125 if(*tmp == '\\') *tmp = '_';
1126 if(*tmp == '/') *tmp = '_';
1127 if(*tmp == '.') *tmp = '_';
1128 } while(*tmp++);
1130 /* Try to locate in list of loaded images */
1131 img = tc->tf->images;
1132 while (img)
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;
1138 return img->image;
1140 img = img->next;
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);
1152 return img->image;
1155 static BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
1157 LPCWSTR cur = lpStringStart;
1158 int total = 0;
1159 BOOL gotNeg = FALSE;
1161 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
1162 if(cur >= lpStringEnd) {
1163 return FALSE;
1165 if(*cur == '-') {
1166 cur++;
1167 gotNeg = TRUE;
1169 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
1170 total = total * 10 + (*cur - '0');
1171 cur++;
1173 if(gotNeg) total = -total;
1174 *value = total;
1175 if(lpValEnd) *lpValEnd = cur;
1176 return TRUE;
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;
1186 LPCWSTR start;
1187 LPCWSTR end;
1189 while(cur < lpStringEnd && (isSpace(*cur) || *cur == ',')) cur++;
1190 if(cur >= lpStringEnd) {
1191 return FALSE;
1193 start = cur;
1194 while(cur < lpStringEnd && *cur != ',') cur++;
1195 end = cur;
1196 while(isSpace(*end)) end--;
1198 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
1200 if(lpValEnd) *lpValEnd = cur;
1201 return TRUE;
1204 /***********************************************************************
1205 * MSSTYLES_GetPropertyBool
1207 * Retrieve a color value for a property
1209 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
1211 *pfVal = FALSE;
1212 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
1213 *pfVal = TRUE;
1214 return S_OK;
1217 /***********************************************************************
1218 * MSSTYLES_GetPropertyColor
1220 * Retrieve a color value for a property
1222 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
1224 LPCWSTR lpEnd;
1225 LPCWSTR lpCur;
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);
1244 return S_OK;
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'};
1259 int pointSize;
1260 WCHAR attr[32];
1262 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
1263 TRACE("Property is there, but failed to get face name\n");
1264 *lpValEnd = lpCur;
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");
1269 *lpValEnd = lpCur;
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;
1281 *lpValEnd = lpCur;
1282 return S_OK;
1285 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
1287 LPCWSTR lpCur = tp->lpValue;
1288 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1289 HRESULT hr;
1291 ZeroMemory(pFont, sizeof(LOGFONTW));
1292 hr = MSSTYLES_GetFont (lpCur, lpEnd, &lpCur, pFont);
1293 if (SUCCEEDED (hr))
1294 pFont->lfHeight = -MulDiv(pFont->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1296 return hr;
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;
1310 return S_OK;
1313 /***********************************************************************
1314 * MSSTYLES_GetPropertyIntList
1316 * Retrieve an int list value for a property
1318 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1320 int i;
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]))
1326 break;
1328 pIntList->iValueCount = i;
1329 return S_OK;
1332 /***********************************************************************
1333 * MSSTYLES_GetPropertyPosition
1335 * Retrieve a position value for a property
1337 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1339 int x,y;
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;
1351 pPoint->x = x;
1352 pPoint->y = y;
1353 return S_OK;
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));
1364 return S_OK;
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;
1384 return S_OK;
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;
1404 return S_OK;