riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / uxtheme / msstyles.c
blobe62b95d4f16ccb86ce212b6fa65bbf9e29152f4d
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 if(hTheme) FreeLibrary(hTheme);
192 return hr;
195 /***********************************************************************
196 * MSSTYLES_CloseThemeFile
198 * Close theme file and free resources
200 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
202 if(tf) {
203 tf->dwRefCount--;
204 if(!tf->dwRefCount) {
205 if(tf->hTheme) FreeLibrary(tf->hTheme);
206 if(tf->classes) {
207 while(tf->classes) {
208 PTHEME_CLASS pcls = tf->classes;
209 tf->classes = pcls->next;
210 while(pcls->partstate) {
211 PTHEME_PARTSTATE ps = pcls->partstate;
213 while(ps->properties) {
214 PTHEME_PROPERTY prop = ps->properties;
215 ps->properties = prop->next;
216 HeapFree(GetProcessHeap(), 0, prop);
219 pcls->partstate = ps->next;
220 HeapFree(GetProcessHeap(), 0, ps);
222 HeapFree(GetProcessHeap(), 0, pcls);
225 while (tf->images)
227 PTHEME_IMAGE img = tf->images;
228 tf->images = img->next;
229 DeleteObject (img->image);
230 HeapFree (GetProcessHeap(), 0, img);
232 HeapFree(GetProcessHeap(), 0, tf);
237 /***********************************************************************
238 * MSSTYLES_SetActiveTheme
240 * Set the current active theme
242 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf, BOOL setMetrics)
244 if(tfActiveTheme)
245 MSSTYLES_CloseThemeFile(tfActiveTheme);
246 tfActiveTheme = tf;
247 if (tfActiveTheme)
249 tfActiveTheme->dwRefCount++;
250 if(!tfActiveTheme->classes)
251 MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics);
253 return S_OK;
256 /***********************************************************************
257 * MSSTYLES_GetThemeIni
259 * Retrieves themes.ini from a theme
261 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf)
263 return UXINI_LoadINI(tf->hTheme, szThemesIniResource);
266 /***********************************************************************
267 * MSSTYLES_GetActiveThemeIni
269 * Retrieve the ini file for the selected color/style
271 static PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf)
273 static const WCHAR szFileResNamesResource[] = {
274 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
276 DWORD dwColorCount = 0;
277 DWORD dwSizeCount = 0;
278 DWORD dwColorNum = 0;
279 DWORD dwSizeNum = 0;
280 DWORD i;
281 DWORD dwResourceIndex;
282 LPWSTR tmp;
283 HRSRC hrsc;
285 /* Count the number of available colors & styles, and determine the index number
286 of the color/style we are interested in
288 tmp = tf->pszAvailColors;
289 while(*tmp) {
290 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
291 dwColorNum = dwColorCount;
292 tmp += lstrlenW(tmp)+1;
293 dwColorCount++;
295 tmp = tf->pszAvailSizes;
296 while(*tmp) {
297 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
298 dwSizeNum = dwSizeCount;
299 tmp += lstrlenW(tmp)+1;
300 dwSizeCount++;
303 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
304 TRACE("FILERESNAMES map not found\n");
305 return NULL;
307 tmp = LoadResource(tf->hTheme, hrsc);
308 dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum;
309 for(i=0; i < dwResourceIndex; i++) {
310 tmp += lstrlenW(tmp)+1;
312 return UXINI_LoadINI(tf->hTheme, tmp);
316 /***********************************************************************
317 * MSSTYLES_ParseIniSectionName
319 * Parse an ini section name into its component parts
320 * Valid formats are:
321 * [classname]
322 * [classname(state)]
323 * [classname.part]
324 * [classname.part(state)]
325 * [application::classname]
326 * [application::classname(state)]
327 * [application::classname.part]
328 * [application::classname.part(state)]
330 * PARAMS
331 * lpSection Section name
332 * dwLen Length of section name
333 * szAppName Location to store application name
334 * szClassName Location to store class name
335 * iPartId Location to store part id
336 * iStateId Location to store state id
338 static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR szAppName, LPWSTR szClassName, int *iPartId, int *iStateId)
340 WCHAR sec[255];
341 WCHAR part[60] = {'\0'};
342 WCHAR state[60] = {'\0'};
343 LPWSTR tmp;
344 LPWSTR comp;
345 lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
347 *szAppName = 0;
348 *szClassName = 0;
349 *iPartId = 0;
350 *iStateId = 0;
351 comp = sec;
352 /* Get the application name */
353 tmp = strchrW(comp, ':');
354 if(tmp) {
355 *tmp++ = 0;
356 tmp++;
357 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
358 comp = tmp;
361 tmp = strchrW(comp, '.');
362 if(tmp) {
363 *tmp++ = 0;
364 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
365 comp = tmp;
366 /* now get the part & state */
367 tmp = strchrW(comp, '(');
368 if(tmp) {
369 *tmp++ = 0;
370 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
371 comp = tmp;
372 /* now get the state */
373 tmp = strchrW(comp, ')');
374 if (!tmp)
375 return FALSE;
376 *tmp = 0;
377 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
379 else {
380 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
383 else {
384 tmp = strchrW(comp, '(');
385 if(tmp) {
386 *tmp++ = 0;
387 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
388 comp = tmp;
389 /* now get the state */
390 tmp = strchrW(comp, ')');
391 if (!tmp)
392 return FALSE;
393 *tmp = 0;
394 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
396 else {
397 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
400 if(!*szClassName) return FALSE;
401 return MSSTYLES_LookupPartState(szClassName, part[0]?part:NULL, state[0]?state:NULL, iPartId, iStateId);
404 /***********************************************************************
405 * MSSTYLES_FindClass
407 * Find a class
409 * PARAMS
410 * tf Theme file
411 * pszAppName App name to find
412 * pszClassName Class name to find
414 * RETURNS
415 * The class found, or NULL
417 static PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
419 PTHEME_CLASS cur = tf->classes;
420 while(cur) {
421 if(!pszAppName) {
422 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
423 return cur;
425 else {
426 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
427 return cur;
429 cur = cur->next;
431 return NULL;
434 /***********************************************************************
435 * MSSTYLES_AddClass
437 * Add a class to a theme file
439 * PARAMS
440 * tf Theme file
441 * pszAppName App name to add
442 * pszClassName Class name to add
444 * RETURNS
445 * The class added, or a class previously added with the same name
447 static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
449 PTHEME_CLASS cur = MSSTYLES_FindClass(tf, pszAppName, pszClassName);
450 if(cur) return cur;
452 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS));
453 cur->hTheme = tf->hTheme;
454 lstrcpyW(cur->szAppName, pszAppName);
455 lstrcpyW(cur->szClassName, pszClassName);
456 cur->next = tf->classes;
457 cur->partstate = NULL;
458 cur->overrides = NULL;
459 tf->classes = cur;
460 return cur;
463 /***********************************************************************
464 * MSSTYLES_FindPartState
466 * Find a part/state
468 * PARAMS
469 * tc Class to search
470 * iPartId Part ID to find
471 * iStateId State ID to find
472 * tcNext Receives the next class in the override chain
474 * RETURNS
475 * The part/state found, or NULL
477 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext)
479 PTHEME_PARTSTATE cur = tc->partstate;
480 while(cur) {
481 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
482 if(tcNext) *tcNext = tc->overrides;
483 return cur;
485 cur = cur->next;
487 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
488 return NULL;
491 /***********************************************************************
492 * MSSTYLES_AddPartState
494 * Add a part/state to a class
496 * PARAMS
497 * tc Theme class
498 * iPartId Part ID to add
499 * iStateId State ID to add
501 * RETURNS
502 * The part/state added, or a part/state previously added with the same IDs
504 static PTHEME_PARTSTATE MSSTYLES_AddPartState(PTHEME_CLASS tc, int iPartId, int iStateId)
506 PTHEME_PARTSTATE cur = MSSTYLES_FindPartState(tc, iPartId, iStateId, NULL);
507 if(cur) return cur;
509 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE));
510 cur->iPartId = iPartId;
511 cur->iStateId = iStateId;
512 cur->properties = NULL;
513 cur->next = tc->partstate;
514 tc->partstate = cur;
515 return cur;
518 /***********************************************************************
519 * MSSTYLES_LFindProperty
521 * Find a property within a property list
523 * PARAMS
524 * tp property list to scan
525 * iPropertyPrimitive Type of value expected
526 * iPropertyId ID of the required value
528 * RETURNS
529 * The property found, or NULL
531 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
533 PTHEME_PROPERTY cur = tp;
534 while(cur) {
535 if(cur->iPropertyId == iPropertyId) {
536 if(cur->iPrimitiveType == iPropertyPrimitive) {
537 return cur;
539 else {
540 if(!iPropertyPrimitive)
541 return cur;
542 return NULL;
545 cur = cur->next;
547 return NULL;
550 /***********************************************************************
551 * MSSTYLES_PSFindProperty
553 * Find a value within a part/state
555 * PARAMS
556 * ps Part/state to search
557 * iPropertyPrimitive Type of value expected
558 * iPropertyId ID of the required value
560 * RETURNS
561 * The property found, or NULL
563 static inline PTHEME_PROPERTY MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId)
565 return MSSTYLES_LFindProperty(ps->properties, iPropertyPrimitive, iPropertyId);
568 /***********************************************************************
569 * MSSTYLES_FFindMetric
571 * Find a metric property for a theme file
573 * PARAMS
574 * tf Theme file
575 * iPropertyPrimitive Type of value expected
576 * iPropertyId ID of the required value
578 * RETURNS
579 * The property found, or NULL
581 static inline PTHEME_PROPERTY MSSTYLES_FFindMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId)
583 return MSSTYLES_LFindProperty(tf->metrics, iPropertyPrimitive, iPropertyId);
586 /***********************************************************************
587 * MSSTYLES_FindMetric
589 * Find a metric property for the current installed theme
591 * PARAMS
592 * tf Theme file
593 * iPropertyPrimitive Type of value expected
594 * iPropertyId ID of the required value
596 * RETURNS
597 * The property found, or NULL
599 PTHEME_PROPERTY MSSTYLES_FindMetric(int iPropertyPrimitive, int iPropertyId)
601 if(!tfActiveTheme) return NULL;
602 return MSSTYLES_FFindMetric(tfActiveTheme, iPropertyPrimitive, iPropertyId);
605 /***********************************************************************
606 * MSSTYLES_AddProperty
608 * Add a property to a part/state
610 * PARAMS
611 * ps Part/state
612 * iPropertyPrimitive Primitive type of the property
613 * iPropertyId ID of the property
614 * lpValue Raw value (non-NULL terminated)
615 * dwValueLen Length of the value
617 * RETURNS
618 * The property added, or a property previously added with the same IDs
620 static PTHEME_PROPERTY MSSTYLES_AddProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen, BOOL isGlobal)
622 PTHEME_PROPERTY cur = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId);
623 /* Should duplicate properties overwrite the original, or be ignored? */
624 if(cur) return cur;
626 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
627 cur->iPrimitiveType = iPropertyPrimitive;
628 cur->iPropertyId = iPropertyId;
629 cur->lpValue = lpValue;
630 cur->dwValueLen = dwValueLen;
632 if(ps->iStateId)
633 cur->origin = PO_STATE;
634 else if(ps->iPartId)
635 cur->origin = PO_PART;
636 else if(isGlobal)
637 cur->origin = PO_GLOBAL;
638 else
639 cur->origin = PO_CLASS;
641 cur->next = ps->properties;
642 ps->properties = cur;
643 return cur;
646 /***********************************************************************
647 * MSSTYLES_AddMetric
649 * Add a property to a part/state
651 * PARAMS
652 * tf Theme file
653 * iPropertyPrimitive Primitive type of the property
654 * iPropertyId ID of the property
655 * lpValue Raw value (non-NULL terminated)
656 * dwValueLen Length of the value
658 * RETURNS
659 * The property added, or a property previously added with the same IDs
661 static PTHEME_PROPERTY MSSTYLES_AddMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen)
663 PTHEME_PROPERTY cur = MSSTYLES_FFindMetric(tf, iPropertyPrimitive, iPropertyId);
664 /* Should duplicate properties overwrite the original, or be ignored? */
665 if(cur) return cur;
667 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
668 cur->iPrimitiveType = iPropertyPrimitive;
669 cur->iPropertyId = iPropertyId;
670 cur->lpValue = lpValue;
671 cur->dwValueLen = dwValueLen;
673 cur->origin = PO_GLOBAL;
675 cur->next = tf->metrics;
676 tf->metrics = cur;
677 return cur;
680 /* Color-related state for theme ini parsing */
681 struct PARSECOLORSTATE
683 int colorCount;
684 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
685 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
686 int captionColors;
689 static inline void parse_init_color (struct PARSECOLORSTATE* state)
691 memset (state, 0, sizeof (*state));
694 static BOOL parse_handle_color_property (struct PARSECOLORSTATE* state,
695 int iPropertyId, LPCWSTR lpValue,
696 DWORD dwValueLen)
698 int r,g,b;
699 LPCWSTR lpValueEnd = lpValue + dwValueLen;
700 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r) &&
701 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g) &&
702 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
703 state->colorElements[state->colorCount] = iPropertyId - TMT_FIRSTCOLOR;
704 state->colorRgb[state->colorCount++] = RGB(r,g,b);
705 switch (iPropertyId)
707 case TMT_ACTIVECAPTION:
708 state->captionColors |= 0x1;
709 break;
710 case TMT_INACTIVECAPTION:
711 state->captionColors |= 0x2;
712 break;
713 case TMT_GRADIENTACTIVECAPTION:
714 state->captionColors |= 0x4;
715 break;
716 case TMT_GRADIENTINACTIVECAPTION:
717 state->captionColors |= 0x8;
718 break;
720 return TRUE;
722 else {
723 return FALSE;
727 static void parse_apply_color (struct PARSECOLORSTATE* state)
729 if (state->colorCount > 0)
730 SetSysColors(state->colorCount, state->colorElements, state->colorRgb);
731 if (state->captionColors == 0xf)
732 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
735 /* Non-client-metrics-related state for theme ini parsing */
736 struct PARSENONCLIENTSTATE
738 NONCLIENTMETRICSW metrics;
739 BOOL metricsDirty;
740 LOGFONTW iconTitleFont;
743 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE* state)
745 memset (state, 0, sizeof (*state));
746 state->metrics.cbSize = sizeof (NONCLIENTMETRICSW);
747 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW),
748 &state->metrics, 0);
749 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (LOGFONTW),
750 &state->iconTitleFont, 0);
753 static BOOL parse_handle_nonclient_font (struct PARSENONCLIENTSTATE* state,
754 int iPropertyId, LPCWSTR lpValue,
755 DWORD dwValueLen)
757 LOGFONTW font;
759 memset (&font, 0, sizeof (font));
760 if (SUCCEEDED (MSSTYLES_GetFont (lpValue, lpValue + dwValueLen, &lpValue,
761 &font)))
763 switch (iPropertyId)
765 case TMT_CAPTIONFONT:
766 state->metrics.lfCaptionFont = font;
767 state->metricsDirty = TRUE;
768 break;
769 case TMT_SMALLCAPTIONFONT:
770 state->metrics.lfSmCaptionFont = font;
771 state->metricsDirty = TRUE;
772 break;
773 case TMT_MENUFONT:
774 state->metrics.lfMenuFont = font;
775 state->metricsDirty = TRUE;
776 break;
777 case TMT_STATUSFONT:
778 state->metrics.lfStatusFont = font;
779 state->metricsDirty = TRUE;
780 break;
781 case TMT_MSGBOXFONT:
782 state->metrics.lfMessageFont = font;
783 state->metricsDirty = TRUE;
784 break;
785 case TMT_ICONTITLEFONT:
786 state->iconTitleFont = font;
787 state->metricsDirty = TRUE;
788 break;
790 return TRUE;
792 else
793 return FALSE;
796 static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
797 int iPropertyId, LPCWSTR lpValue,
798 DWORD dwValueLen)
800 int size;
801 LPCWSTR lpValueEnd = lpValue + dwValueLen;
802 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &size)) {
803 switch (iPropertyId)
805 case TMT_SIZINGBORDERWIDTH:
806 state->metrics.iBorderWidth = size;
807 state->metricsDirty = TRUE;
808 break;
809 case TMT_SCROLLBARWIDTH:
810 state->metrics.iScrollWidth = size;
811 state->metricsDirty = TRUE;
812 break;
813 case TMT_SCROLLBARHEIGHT:
814 state->metrics.iScrollHeight = size;
815 state->metricsDirty = TRUE;
816 break;
817 case TMT_CAPTIONBARWIDTH:
818 state->metrics.iCaptionWidth = size;
819 state->metricsDirty = TRUE;
820 break;
821 case TMT_CAPTIONBARHEIGHT:
822 state->metrics.iCaptionHeight = size;
823 state->metricsDirty = TRUE;
824 break;
825 case TMT_SMCAPTIONBARWIDTH:
826 state->metrics.iSmCaptionWidth = size;
827 state->metricsDirty = TRUE;
828 break;
829 case TMT_SMCAPTIONBARHEIGHT:
830 state->metrics.iSmCaptionHeight = size;
831 state->metricsDirty = TRUE;
832 break;
833 case TMT_MENUBARWIDTH:
834 state->metrics.iMenuWidth = size;
835 state->metricsDirty = TRUE;
836 break;
837 case TMT_MENUBARHEIGHT:
838 state->metrics.iMenuHeight = size;
839 state->metricsDirty = TRUE;
840 break;
842 return TRUE;
844 else
845 return FALSE;
848 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state)
850 if (state->metricsDirty)
852 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics),
853 &state->metrics, 0);
854 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (state->iconTitleFont),
855 &state->iconTitleFont, 0);
859 /***********************************************************************
860 * MSSTYLES_ParseThemeIni
862 * Parse the theme ini for the selected color/style
864 * PARAMS
865 * tf Theme to parse
867 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
869 static const WCHAR szSysMetrics[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
870 static const WCHAR szGlobals[] = {'g','l','o','b','a','l','s','\0'};
871 PTHEME_CLASS cls;
872 PTHEME_CLASS globals;
873 PTHEME_PARTSTATE ps;
874 PUXINI_FILE ini;
875 WCHAR szAppName[MAX_THEME_APP_NAME];
876 WCHAR szClassName[MAX_THEME_CLASS_NAME];
877 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
878 int iPartId;
879 int iStateId;
880 int iPropertyPrimitive;
881 int iPropertyId;
882 DWORD dwLen;
883 LPCWSTR lpName;
884 DWORD dwValueLen;
885 LPCWSTR lpValue;
887 ini = MSSTYLES_GetActiveThemeIni(tf);
889 while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
890 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, szSysMetrics, -1) == CSTR_EQUAL) {
891 struct PARSECOLORSTATE colorState;
892 struct PARSENONCLIENTSTATE nonClientState;
894 parse_init_color (&colorState);
895 parse_init_nonclient (&nonClientState);
897 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
898 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
899 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
900 if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
901 if (!parse_handle_color_property (&colorState, iPropertyId,
902 lpValue, dwValueLen))
903 FIXME("Invalid color value for %s\n",
904 debugstr_w(szPropertyName));
906 else if (setMetrics && (iPropertyId == TMT_FLATMENUS)) {
907 BOOL flatMenus = (*lpValue == 'T') || (*lpValue == 't');
908 SystemParametersInfoW (SPI_SETFLATMENU, 0, (PVOID)(INT_PTR)flatMenus, 0);
910 else if ((iPropertyId >= TMT_FIRSTFONT)
911 && (iPropertyId <= TMT_LASTFONT))
913 if (!parse_handle_nonclient_font (&nonClientState,
914 iPropertyId, lpValue, dwValueLen))
915 FIXME("Invalid font value for %s\n",
916 debugstr_w(szPropertyName));
918 else if ((iPropertyId >= TMT_FIRSTSIZE)
919 && (iPropertyId <= TMT_LASTSIZE))
921 if (!parse_handle_nonclient_size (&nonClientState,
922 iPropertyId, lpValue, dwValueLen))
923 FIXME("Invalid size value for %s\n",
924 debugstr_w(szPropertyName));
926 /* Catch all metrics, including colors */
927 MSSTYLES_AddMetric(tf, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen);
929 else {
930 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
933 if (setMetrics)
935 parse_apply_color (&colorState);
936 parse_apply_nonclient (&nonClientState);
938 continue;
940 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
941 BOOL isGlobal = FALSE;
942 if(!lstrcmpiW(szClassName, szGlobals)) {
943 isGlobal = TRUE;
945 cls = MSSTYLES_AddClass(tf, szAppName, szClassName);
946 ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
948 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
949 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
950 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
951 MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
953 else {
954 TRACE("Unknown property %s\n", debugstr_w(szPropertyName));
960 /* App/Class combos override values defined by the base class, map these overrides */
961 globals = MSSTYLES_FindClass(tf, NULL, szGlobals);
962 cls = tf->classes;
963 while(cls) {
964 if(*cls->szAppName) {
965 cls->overrides = MSSTYLES_FindClass(tf, NULL, cls->szClassName);
966 if(!cls->overrides) {
967 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName));
969 else {
970 cls->overrides = globals;
973 else {
974 /* Everything overrides globals..except globals */
975 if(cls != globals) cls->overrides = globals;
977 cls = cls->next;
979 UXINI_CloseINI(ini);
981 if(!tf->classes) {
982 ERR("Failed to parse theme ini\n");
986 /***********************************************************************
987 * MSSTYLES_OpenThemeClass
989 * Open a theme class, uses the current active theme
991 * PARAMS
992 * pszAppName Application name, for theme styles specific
993 * to a particular application
994 * pszClassList List of requested classes, semicolon delimited
996 PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
998 PTHEME_CLASS cls = NULL;
999 WCHAR szClassName[MAX_THEME_CLASS_NAME];
1000 LPCWSTR start;
1001 LPCWSTR end;
1002 DWORD len;
1004 if(!tfActiveTheme) {
1005 TRACE("there is no active theme\n");
1006 return NULL;
1008 if(!tfActiveTheme->classes) {
1009 return NULL;
1012 start = pszClassList;
1013 while((end = strchrW(start, ';'))) {
1014 len = end-start;
1015 lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
1016 start = end+1;
1017 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1018 if(cls) break;
1020 if(!cls && *start) {
1021 lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
1022 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1024 if(cls) {
1025 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList));
1026 cls->tf = tfActiveTheme;
1027 cls->tf->dwRefCount++;
1029 return cls;
1032 /***********************************************************************
1033 * MSSTYLES_CloseThemeClass
1035 * Close a theme class
1037 * PARAMS
1038 * tc Theme class to close
1040 * NOTES
1041 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1042 * theme file and cleans it up, if needed.
1044 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc)
1046 MSSTYLES_CloseThemeFile (tc->tf);
1047 return S_OK;
1050 /***********************************************************************
1051 * MSSTYLES_FindProperty
1053 * Locate a property in a class. Part and state IDs will be used as a
1054 * preference, but may be ignored in the attempt to locate the property.
1055 * Will scan the entire chain of overrides for this class.
1057 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId)
1059 PTHEME_CLASS next = tc;
1060 PTHEME_PARTSTATE ps;
1061 PTHEME_PROPERTY tp;
1063 TRACE("(%p, %d, %d, %d)\n", tc, iPartId, iStateId, iPropertyId);
1064 /* Try and find an exact match on part & state */
1065 while(next && (ps = MSSTYLES_FindPartState(next, iPartId, iStateId, &next))) {
1066 if((tp = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId))) {
1067 return tp;
1070 /* If that fails, and we didn't already try it, search for just part */
1071 if(iStateId != 0)
1072 iStateId = 0;
1073 /* As a last ditch attempt..go for just class */
1074 else if(iPartId != 0)
1075 iPartId = 0;
1076 else
1077 return NULL;
1079 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
1080 return tp;
1081 return NULL;
1084 /* Prepare a bitmap to be used for alpha blending */
1085 static BOOL prepare_alpha (HBITMAP bmp, BOOL* hasAlpha)
1087 DIBSECTION dib;
1088 int n;
1089 BYTE* p;
1091 *hasAlpha = FALSE;
1093 if (!bmp || GetObjectW( bmp, sizeof(dib), &dib ) != sizeof(dib))
1094 return FALSE;
1096 if(dib.dsBm.bmBitsPixel != 32)
1097 /* nothing to do */
1098 return TRUE;
1100 *hasAlpha = TRUE;
1101 p = dib.dsBm.bmBits;
1102 n = dib.dsBmih.biHeight * dib.dsBmih.biWidth;
1103 /* AlphaBlend() wants premultiplied alpha, so do that now */
1104 while (n-- > 0)
1106 int a = p[3]+1;
1107 p[0] = (p[0] * a) >> 8;
1108 p[1] = (p[1] * a) >> 8;
1109 p[2] = (p[2] * a) >> 8;
1110 p += 4;
1113 return TRUE;
1116 HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
1118 WCHAR szFile[MAX_PATH];
1119 LPWSTR tmp;
1120 PTHEME_IMAGE img;
1121 lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
1122 tmp = szFile;
1123 do {
1124 if(*tmp == '\\') *tmp = '_';
1125 if(*tmp == '/') *tmp = '_';
1126 if(*tmp == '.') *tmp = '_';
1127 } while(*tmp++);
1129 /* Try to locate in list of loaded images */
1130 img = tc->tf->images;
1131 while (img)
1133 if (lstrcmpiW (szFile, img->name) == 0)
1135 TRACE ("found %p %s: %p\n", img, debugstr_w (img->name), img->image);
1136 *hasAlpha = img->hasAlpha;
1137 return img->image;
1139 img = img->next;
1141 /* Not found? Load from resources */
1142 img = HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE));
1143 img->image = LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
1144 prepare_alpha (img->image, hasAlpha);
1145 img->hasAlpha = *hasAlpha;
1146 /* ...and stow away for later reuse. */
1147 lstrcpyW (img->name, szFile);
1148 img->next = tc->tf->images;
1149 tc->tf->images = img;
1150 TRACE ("new %p %s: %p\n", img, debugstr_w (img->name), img->image);
1151 return img->image;
1154 static BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
1156 LPCWSTR cur = lpStringStart;
1157 int total = 0;
1158 BOOL gotNeg = FALSE;
1160 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
1161 if(cur >= lpStringEnd) {
1162 return FALSE;
1164 if(*cur == '-') {
1165 cur++;
1166 gotNeg = TRUE;
1168 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
1169 total = total * 10 + (*cur - '0');
1170 cur++;
1172 if(gotNeg) total = -total;
1173 *value = total;
1174 if(lpValEnd) *lpValEnd = cur;
1175 return TRUE;
1178 static BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize) {
1179 LPCWSTR cur = lpStringStart;
1180 LPCWSTR start;
1181 LPCWSTR end;
1183 while(cur < lpStringEnd && (isspace(*cur) || *cur == ',')) cur++;
1184 if(cur >= lpStringEnd) {
1185 return FALSE;
1187 start = cur;
1188 while(cur < lpStringEnd && *cur != ',') cur++;
1189 end = cur;
1190 while(isspace(*end)) end--;
1192 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
1194 if(lpValEnd) *lpValEnd = cur;
1195 return TRUE;
1198 /***********************************************************************
1199 * MSSTYLES_GetPropertyBool
1201 * Retrieve a color value for a property
1203 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
1205 *pfVal = FALSE;
1206 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
1207 *pfVal = TRUE;
1208 return S_OK;
1211 /***********************************************************************
1212 * MSSTYLES_GetPropertyColor
1214 * Retrieve a color value for a property
1216 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
1218 LPCWSTR lpEnd;
1219 LPCWSTR lpCur;
1220 int red, green, blue;
1222 lpCur = tp->lpValue;
1223 lpEnd = tp->lpValue + tp->dwValueLen;
1225 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &red)) {
1226 TRACE("Could not parse color property\n");
1227 return E_PROP_ID_UNSUPPORTED;
1229 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &green)) {
1230 TRACE("Could not parse color property\n");
1231 return E_PROP_ID_UNSUPPORTED;
1233 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &blue)) {
1234 TRACE("Could not parse color property\n");
1235 return E_PROP_ID_UNSUPPORTED;
1237 *pColor = RGB(red,green,blue);
1238 return S_OK;
1241 /***********************************************************************
1242 * MSSTYLES_GetPropertyColor
1244 * Retrieve a color value for a property
1246 static HRESULT MSSTYLES_GetFont (LPCWSTR lpCur, LPCWSTR lpEnd,
1247 LPCWSTR *lpValEnd, LOGFONTW* pFont)
1249 static const WCHAR szBold[] = {'b','o','l','d','\0'};
1250 static const WCHAR szItalic[] = {'i','t','a','l','i','c','\0'};
1251 static const WCHAR szUnderline[] = {'u','n','d','e','r','l','i','n','e','\0'};
1252 static const WCHAR szStrikeOut[] = {'s','t','r','i','k','e','o','u','t','\0'};
1253 int pointSize;
1254 WCHAR attr[32];
1256 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
1257 TRACE("Property is there, but failed to get face name\n");
1258 *lpValEnd = lpCur;
1259 return E_PROP_ID_UNSUPPORTED;
1261 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pointSize)) {
1262 TRACE("Property is there, but failed to get point size\n");
1263 *lpValEnd = lpCur;
1264 return E_PROP_ID_UNSUPPORTED;
1266 pFont->lfHeight = pointSize;
1267 pFont->lfWeight = FW_REGULAR;
1268 pFont->lfCharSet = DEFAULT_CHARSET;
1269 while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, sizeof(attr)/sizeof(attr[0]))) {
1270 if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD;
1271 else if(!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE;
1272 else if(!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE;
1273 else if(!lstrcmpiW(szStrikeOut, attr)) pFont->lfStrikeOut = TRUE;
1275 *lpValEnd = lpCur;
1276 return S_OK;
1279 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
1281 LPCWSTR lpCur = tp->lpValue;
1282 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1283 HRESULT hr;
1285 ZeroMemory(pFont, sizeof(LOGFONTW));
1286 hr = MSSTYLES_GetFont (lpCur, lpEnd, &lpCur, pFont);
1287 if (SUCCEEDED (hr))
1288 pFont->lfHeight = -MulDiv(pFont->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1290 return hr;
1293 /***********************************************************************
1294 * MSSTYLES_GetPropertyInt
1296 * Retrieve an int value for a property
1298 HRESULT MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp, int *piVal)
1300 if(!MSSTYLES_GetNextInteger(tp->lpValue, (tp->lpValue + tp->dwValueLen), NULL, piVal)) {
1301 TRACE("Could not parse int property\n");
1302 return E_PROP_ID_UNSUPPORTED;
1304 return S_OK;
1307 /***********************************************************************
1308 * MSSTYLES_GetPropertyIntList
1310 * Retrieve an int list value for a property
1312 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1314 int i;
1315 LPCWSTR lpCur = tp->lpValue;
1316 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1318 for(i=0; i < MAX_INTLIST_COUNT; i++) {
1319 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pIntList->iValues[i]))
1320 break;
1322 pIntList->iValueCount = i;
1323 return S_OK;
1326 /***********************************************************************
1327 * MSSTYLES_GetPropertyPosition
1329 * Retrieve a position value for a property
1331 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1333 int x,y;
1334 LPCWSTR lpCur = tp->lpValue;
1335 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1337 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &x)) {
1338 TRACE("Could not parse position property\n");
1339 return E_PROP_ID_UNSUPPORTED;
1341 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &y)) {
1342 TRACE("Could not parse position property\n");
1343 return E_PROP_ID_UNSUPPORTED;
1345 pPoint->x = x;
1346 pPoint->y = y;
1347 return S_OK;
1350 /***********************************************************************
1351 * MSSTYLES_GetPropertyString
1353 * Retrieve a string value for a property
1355 HRESULT MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp, LPWSTR pszBuff, int cchMaxBuffChars)
1357 lstrcpynW(pszBuff, tp->lpValue, min(tp->dwValueLen+1, cchMaxBuffChars));
1358 return S_OK;
1361 /***********************************************************************
1362 * MSSTYLES_GetPropertyRect
1364 * Retrieve a rect value for a property
1366 HRESULT MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp, RECT *pRect)
1368 LPCWSTR lpCur = tp->lpValue;
1369 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1371 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->left);
1372 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->top);
1373 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->right);
1374 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->bottom)) {
1375 TRACE("Could not parse rect property\n");
1376 return E_PROP_ID_UNSUPPORTED;
1378 return S_OK;
1381 /***********************************************************************
1382 * MSSTYLES_GetPropertyMargins
1384 * Retrieve a margins value for a property
1386 HRESULT MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp, RECT *prc, MARGINS *pMargins)
1388 LPCWSTR lpCur = tp->lpValue;
1389 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1391 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxLeftWidth);
1392 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxRightWidth);
1393 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyTopHeight);
1394 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyBottomHeight)) {
1395 TRACE("Could not parse margins property\n");
1396 return E_PROP_ID_UNSUPPORTED;
1398 return S_OK;