localspl: Add a comment, why we do not implement AddPort for XcvDataPort.
[wine/wine64.git] / dlls / uxtheme / msstyles.c
blobe555eb2c92a823be8f3c5337a09c41639aa668cf
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 "uxthemedll.h"
36 #include "msstyles.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
43 /***********************************************************************
44 * Defines and global variables
47 BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value);
48 BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize);
49 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics);
50 static HRESULT MSSTYLES_GetFont (LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LOGFONTW* logfont);
52 extern HINSTANCE hDllInst;
53 extern int alphaBlendMode;
55 #define MSSTYLES_VERSION 0x0003
57 static const WCHAR szThemesIniResource[] = {
58 't','h','e','m','e','s','_','i','n','i','\0'
61 static PTHEME_FILE tfActiveTheme;
63 /***********************************************************************/
65 /**********************************************************************
66 * MSSTYLES_OpenThemeFile
68 * Load and validate a theme
70 * PARAMS
71 * lpThemeFile Path to theme file to load
72 * pszColorName Color name wanted, can be NULL
73 * pszSizeName Size name wanted, can be NULL
75 * NOTES
76 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
77 * If one/both are provided, they are validated against valid color/sizes and if
78 * a match is not found, the function fails.
80 HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWSTR pszSizeName, PTHEME_FILE *tf)
82 HMODULE hTheme;
83 HRSRC hrsc;
84 HRESULT hr = S_OK;
85 static const WCHAR szPackThemVersionResource[] = {
86 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
88 static const WCHAR szColorNamesResource[] = {
89 'C','O','L','O','R','N','A','M','E','S','\0'
91 static const WCHAR szSizeNamesResource[] = {
92 'S','I','Z','E','N','A','M','E','S','\0'
95 WORD version;
96 DWORD versize;
97 LPWSTR pszColors;
98 LPWSTR pszSelectedColor = NULL;
99 LPWSTR pszSizes;
100 LPWSTR pszSelectedSize = NULL;
101 LPWSTR tmp;
103 TRACE("Opening %s\n", debugstr_w(lpThemeFile));
105 hTheme = LoadLibraryExW(lpThemeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);
107 /* Validate that this is really a theme */
108 if(!hTheme) {
109 hr = HRESULT_FROM_WIN32(GetLastError());
110 goto invalid_theme;
112 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szPackThemVersionResource))) {
113 TRACE("No version resource found\n");
114 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
115 goto invalid_theme;
117 if((versize = SizeofResource(hTheme, hrsc)) != 2)
119 TRACE("Version resource found, but wrong size: %d\n", versize);
120 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
121 goto invalid_theme;
123 version = *(WORD*)LoadResource(hTheme, hrsc);
124 if(version != MSSTYLES_VERSION)
126 TRACE("Version of theme file is unsupported: 0x%04x\n", version);
127 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
128 goto invalid_theme;
131 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szColorNamesResource))) {
132 TRACE("Color names resource not found\n");
133 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
134 goto invalid_theme;
136 pszColors = (LPWSTR)LoadResource(hTheme, hrsc);
138 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szSizeNamesResource))) {
139 TRACE("Size names resource not found\n");
140 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
141 goto invalid_theme;
143 pszSizes = (LPWSTR)LoadResource(hTheme, hrsc);
145 /* Validate requested color against whats available from the theme */
146 if(pszColorName) {
147 tmp = pszColors;
148 while(*tmp) {
149 if(!lstrcmpiW(pszColorName, tmp)) {
150 pszSelectedColor = tmp;
151 break;
153 tmp += lstrlenW(tmp)+1;
156 else
157 pszSelectedColor = pszColors; /* Use the default color */
159 /* Validate requested size against whats available from the theme */
160 if(pszSizeName) {
161 tmp = pszSizes;
162 while(*tmp) {
163 if(!lstrcmpiW(pszSizeName, tmp)) {
164 pszSelectedSize = tmp;
165 break;
167 tmp += lstrlenW(tmp)+1;
170 else
171 pszSelectedSize = pszSizes; /* Use the default size */
173 if(!pszSelectedColor || !pszSelectedSize) {
174 TRACE("Requested color/size (%s/%s) not found in theme\n",
175 debugstr_w(pszColorName), debugstr_w(pszSizeName));
176 hr = E_PROP_ID_UNSUPPORTED;
177 goto invalid_theme;
180 *tf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(THEME_FILE));
181 (*tf)->hTheme = hTheme;
183 GetFullPathNameW(lpThemeFile, MAX_PATH, (*tf)->szThemeFile, NULL);
185 (*tf)->pszAvailColors = pszColors;
186 (*tf)->pszAvailSizes = pszSizes;
187 (*tf)->pszSelectedColor = pszSelectedColor;
188 (*tf)->pszSelectedSize = pszSelectedSize;
189 (*tf)->dwRefCount = 1;
190 return S_OK;
192 invalid_theme:
193 if(hTheme) FreeLibrary(hTheme);
194 return hr;
197 /***********************************************************************
198 * MSSTYLES_CloseThemeFile
200 * Close theme file and free resources
202 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
204 if(tf) {
205 tf->dwRefCount--;
206 if(!tf->dwRefCount) {
207 if(tf->hTheme) FreeLibrary(tf->hTheme);
208 if(tf->classes) {
209 while(tf->classes) {
210 PTHEME_CLASS pcls = tf->classes;
211 tf->classes = pcls->next;
212 while(pcls->partstate) {
213 PTHEME_PARTSTATE ps = pcls->partstate;
214 pcls->partstate = ps->next;
215 HeapFree(GetProcessHeap(), 0, ps);
217 HeapFree(GetProcessHeap(), 0, pcls);
220 while (tf->images)
222 PTHEME_IMAGE img = tf->images;
223 tf->images = img->next;
224 DeleteObject (img->image);
225 HeapFree (GetProcessHeap(), 0, img);
227 HeapFree(GetProcessHeap(), 0, tf);
232 /***********************************************************************
233 * MSSTYLES_SetActiveTheme
235 * Set the current active theme
237 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf, BOOL setMetrics)
239 if(tfActiveTheme)
240 MSSTYLES_CloseThemeFile(tfActiveTheme);
241 tfActiveTheme = tf;
242 if (tfActiveTheme)
244 tfActiveTheme->dwRefCount++;
245 if(!tfActiveTheme->classes)
246 MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics);
248 return S_OK;
251 /***********************************************************************
252 * MSSTYLES_GetThemeIni
254 * Retrieves themes.ini from a theme
256 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf)
258 return UXINI_LoadINI(tf->hTheme, szThemesIniResource);
261 /***********************************************************************
262 * MSSTYLES_GetActiveThemeIni
264 * Retrieve the ini file for the selected color/style
266 static PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf)
268 static const WCHAR szFileResNamesResource[] = {
269 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
271 DWORD dwColorCount = 0;
272 DWORD dwSizeCount = 0;
273 DWORD dwColorNum = 0;
274 DWORD dwSizeNum = 0;
275 DWORD i;
276 DWORD dwResourceIndex;
277 LPWSTR tmp;
278 HRSRC hrsc;
280 /* Count the number of available colors & styles, and determine the index number
281 of the color/style we are interested in
283 tmp = tf->pszAvailColors;
284 while(*tmp) {
285 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
286 dwColorNum = dwColorCount;
287 tmp += lstrlenW(tmp)+1;
288 dwColorCount++;
290 tmp = tf->pszAvailSizes;
291 while(*tmp) {
292 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
293 dwSizeNum = dwSizeCount;
294 tmp += lstrlenW(tmp)+1;
295 dwSizeCount++;
298 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
299 TRACE("FILERESNAMES map not found\n");
300 return NULL;
302 tmp = (LPWSTR)LoadResource(tf->hTheme, hrsc);
303 dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum;
304 for(i=0; i < dwResourceIndex; i++) {
305 tmp += lstrlenW(tmp)+1;
307 return UXINI_LoadINI(tf->hTheme, tmp);
311 /***********************************************************************
312 * MSSTYLES_ParseIniSectionName
314 * Parse an ini section name into its component parts
315 * Valid formats are:
316 * [classname]
317 * [classname(state)]
318 * [classname.part]
319 * [classname.part(state)]
320 * [application::classname]
321 * [application::classname(state)]
322 * [application::classname.part]
323 * [application::classname.part(state)]
325 * PARAMS
326 * lpSection Section name
327 * dwLen Length of section name
328 * szAppName Location to store application name
329 * szClassName Location to store class name
330 * iPartId Location to store part id
331 * iStateId Location to store state id
333 static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR szAppName, LPWSTR szClassName, int *iPartId, int *iStateId)
335 WCHAR sec[255];
336 WCHAR part[60] = {'\0'};
337 WCHAR state[60] = {'\0'};
338 LPWSTR tmp;
339 LPWSTR comp;
340 lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
342 *szAppName = 0;
343 *szClassName = 0;
344 *iPartId = 0;
345 *iStateId = 0;
346 comp = sec;
347 /* Get the application name */
348 tmp = strchrW(comp, ':');
349 if(tmp) {
350 *tmp++ = 0;
351 tmp++;
352 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
353 comp = tmp;
356 tmp = strchrW(comp, '.');
357 if(tmp) {
358 *tmp++ = 0;
359 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
360 comp = tmp;
361 /* now get the part & state */
362 tmp = strchrW(comp, '(');
363 if(tmp) {
364 *tmp++ = 0;
365 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
366 comp = tmp;
367 /* now get the state */
368 *strchrW(comp, ')') = 0;
369 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
371 else {
372 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
375 else {
376 tmp = strchrW(comp, '(');
377 if(tmp) {
378 *tmp++ = 0;
379 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
380 comp = tmp;
381 /* now get the state */
382 *strchrW(comp, ')') = 0;
383 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
385 else {
386 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
389 if(!*szClassName) return FALSE;
390 return MSSTYLES_LookupPartState(szClassName, part[0]?part:NULL, state[0]?state:NULL, iPartId, iStateId);
393 /***********************************************************************
394 * MSSTYLES_FindClass
396 * Find a class
398 * PARAMS
399 * tf Theme file
400 * pszAppName App name to find
401 * pszClassName Class name to find
403 * RETURNS
404 * The class found, or NULL
406 static PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
408 PTHEME_CLASS cur = tf->classes;
409 while(cur) {
410 if(!pszAppName) {
411 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
412 return cur;
414 else {
415 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
416 return cur;
418 cur = cur->next;
420 return NULL;
423 /***********************************************************************
424 * MSSTYLES_AddClass
426 * Add a class to a theme file
428 * PARAMS
429 * tf Theme file
430 * pszAppName App name to add
431 * pszClassName Class name to add
433 * RETURNS
434 * The class added, or a class previously added with the same name
436 static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
438 PTHEME_CLASS cur = MSSTYLES_FindClass(tf, pszAppName, pszClassName);
439 if(cur) return cur;
441 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS));
442 cur->hTheme = tf->hTheme;
443 lstrcpyW(cur->szAppName, pszAppName);
444 lstrcpyW(cur->szClassName, pszClassName);
445 cur->next = tf->classes;
446 cur->partstate = NULL;
447 cur->overrides = NULL;
448 tf->classes = cur;
449 return cur;
452 /***********************************************************************
453 * MSSTYLES_FindPartState
455 * Find a part/state
457 * PARAMS
458 * tc Class to search
459 * iPartId Part ID to find
460 * iStateId State ID to find
461 * tcNext Receives the next class in the override chain
463 * RETURNS
464 * The part/state found, or NULL
466 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext)
468 PTHEME_PARTSTATE cur = tc->partstate;
469 while(cur) {
470 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
471 if(tcNext) *tcNext = tc->overrides;
472 return cur;
474 cur = cur->next;
476 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
477 return NULL;
480 /***********************************************************************
481 * MSSTYLES_AddPartState
483 * Add a part/state to a class
485 * PARAMS
486 * tc Theme class
487 * iPartId Part ID to add
488 * iStateId State ID to add
490 * RETURNS
491 * The part/state added, or a part/state previously added with the same IDs
493 static PTHEME_PARTSTATE MSSTYLES_AddPartState(PTHEME_CLASS tc, int iPartId, int iStateId)
495 PTHEME_PARTSTATE cur = MSSTYLES_FindPartState(tc, iPartId, iStateId, NULL);
496 if(cur) return cur;
498 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE));
499 cur->iPartId = iPartId;
500 cur->iStateId = iStateId;
501 cur->properties = NULL;
502 cur->next = tc->partstate;
503 tc->partstate = cur;
504 return cur;
507 /***********************************************************************
508 * MSSTYLES_LFindProperty
510 * Find a property within a property list
512 * PARAMS
513 * tp property list to scan
514 * iPropertyPrimitive Type of value expected
515 * iPropertyId ID of the required value
517 * RETURNS
518 * The property found, or NULL
520 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
522 PTHEME_PROPERTY cur = tp;
523 while(cur) {
524 if(cur->iPropertyId == iPropertyId) {
525 if(cur->iPrimitiveType == iPropertyPrimitive) {
526 return cur;
528 else {
529 if(!iPropertyPrimitive)
530 return cur;
531 return NULL;
534 cur = cur->next;
536 return NULL;
539 /***********************************************************************
540 * MSSTYLES_PSFindProperty
542 * Find a value within a part/state
544 * PARAMS
545 * ps Part/state to search
546 * iPropertyPrimitive Type of value expected
547 * iPropertyId ID of the required value
549 * RETURNS
550 * The property found, or NULL
552 static inline PTHEME_PROPERTY MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId)
554 return MSSTYLES_LFindProperty(ps->properties, iPropertyPrimitive, iPropertyId);
557 /***********************************************************************
558 * MSSTYLES_FFindMetric
560 * Find a metric property for a theme file
562 * PARAMS
563 * tf Theme file
564 * iPropertyPrimitive Type of value expected
565 * iPropertyId ID of the required value
567 * RETURNS
568 * The property found, or NULL
570 static inline PTHEME_PROPERTY MSSTYLES_FFindMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId)
572 return MSSTYLES_LFindProperty(tf->metrics, iPropertyPrimitive, iPropertyId);
575 /***********************************************************************
576 * MSSTYLES_FindMetric
578 * Find a metric property for the current installed theme
580 * PARAMS
581 * tf Theme file
582 * iPropertyPrimitive Type of value expected
583 * iPropertyId ID of the required value
585 * RETURNS
586 * The property found, or NULL
588 PTHEME_PROPERTY MSSTYLES_FindMetric(int iPropertyPrimitive, int iPropertyId)
590 if(!tfActiveTheme) return NULL;
591 return MSSTYLES_FFindMetric(tfActiveTheme, iPropertyPrimitive, iPropertyId);
594 /***********************************************************************
595 * MSSTYLES_AddProperty
597 * Add a property to a part/state
599 * PARAMS
600 * ps Part/state
601 * iPropertyPrimitive Primitive type of the property
602 * iPropertyId ID of the property
603 * lpValue Raw value (non-NULL terminated)
604 * dwValueLen Length of the value
606 * RETURNS
607 * The property added, or a property previously added with the same IDs
609 static PTHEME_PROPERTY MSSTYLES_AddProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen, BOOL isGlobal)
611 PTHEME_PROPERTY cur = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId);
612 /* Should duplicate properties overwrite the original, or be ignored? */
613 if(cur) return cur;
615 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
616 cur->iPrimitiveType = iPropertyPrimitive;
617 cur->iPropertyId = iPropertyId;
618 cur->lpValue = lpValue;
619 cur->dwValueLen = dwValueLen;
621 if(ps->iStateId)
622 cur->origin = PO_STATE;
623 else if(ps->iPartId)
624 cur->origin = PO_PART;
625 else if(isGlobal)
626 cur->origin = PO_GLOBAL;
627 else
628 cur->origin = PO_CLASS;
630 cur->next = ps->properties;
631 ps->properties = cur;
632 return cur;
635 /***********************************************************************
636 * MSSTYLES_AddMetric
638 * Add a property to a part/state
640 * PARAMS
641 * tf Theme file
642 * iPropertyPrimitive Primitive type of the property
643 * iPropertyId ID of the property
644 * lpValue Raw value (non-NULL terminated)
645 * dwValueLen Length of the value
647 * RETURNS
648 * The property added, or a property previously added with the same IDs
650 static PTHEME_PROPERTY MSSTYLES_AddMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen)
652 PTHEME_PROPERTY cur = MSSTYLES_FFindMetric(tf, iPropertyPrimitive, iPropertyId);
653 /* Should duplicate properties overwrite the original, or be ignored? */
654 if(cur) return cur;
656 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
657 cur->iPrimitiveType = iPropertyPrimitive;
658 cur->iPropertyId = iPropertyId;
659 cur->lpValue = lpValue;
660 cur->dwValueLen = dwValueLen;
662 cur->origin = PO_GLOBAL;
664 cur->next = tf->metrics;
665 tf->metrics = cur;
666 return cur;
669 /* Color-related state for theme ini parsing */
670 struct PARSECOLORSTATE
672 int colorCount;
673 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
674 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
675 int captionColors;
678 static inline void parse_init_color (struct PARSECOLORSTATE* state)
680 memset (state, 0, sizeof (*state));
683 static BOOL parse_handle_color_property (struct PARSECOLORSTATE* state,
684 int iPropertyId, LPCWSTR lpValue,
685 DWORD dwValueLen)
687 int r,g,b;
688 LPCWSTR lpValueEnd = lpValue + dwValueLen;
689 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r);
690 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g);
691 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
692 state->colorElements[state->colorCount] = iPropertyId - TMT_FIRSTCOLOR;
693 state->colorRgb[state->colorCount++] = RGB(r,g,b);
694 switch (iPropertyId)
696 case TMT_ACTIVECAPTION:
697 state->captionColors |= 0x1;
698 break;
699 case TMT_INACTIVECAPTION:
700 state->captionColors |= 0x2;
701 break;
702 case TMT_GRADIENTACTIVECAPTION:
703 state->captionColors |= 0x4;
704 break;
705 case TMT_GRADIENTINACTIVECAPTION:
706 state->captionColors |= 0x8;
707 break;
709 return TRUE;
711 else {
712 return FALSE;
716 static void parse_apply_color (struct PARSECOLORSTATE* state)
718 if (state->colorCount > 0)
719 SetSysColors(state->colorCount, state->colorElements, state->colorRgb);
720 if (state->captionColors == 0xf)
721 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
724 /* Non-client-metrics-related state for theme ini parsing */
725 struct PARSENONCLIENTSTATE
727 NONCLIENTMETRICSW metrics;
728 BOOL metricsDirty;
729 LOGFONTW iconTitleFont;
732 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE* state)
734 memset (state, 0, sizeof (*state));
735 state->metrics.cbSize = sizeof (NONCLIENTMETRICSW);
736 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW),
737 (PVOID)&state->metrics, 0);
738 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (LOGFONTW),
739 (PVOID)&state->iconTitleFont, 0);
742 static BOOL parse_handle_nonclient_font (struct PARSENONCLIENTSTATE* state,
743 int iPropertyId, LPCWSTR lpValue,
744 DWORD dwValueLen)
746 LOGFONTW font;
748 memset (&font, 0, sizeof (font));
749 if (SUCCEEDED (MSSTYLES_GetFont (lpValue, lpValue + dwValueLen, &lpValue,
750 &font)))
752 switch (iPropertyId)
754 case TMT_CAPTIONFONT:
755 memcpy (&state->metrics.lfCaptionFont, &font, sizeof (LOGFONTW));
756 state->metricsDirty = TRUE;
757 break;
758 case TMT_SMALLCAPTIONFONT:
759 memcpy (&state->metrics.lfSmCaptionFont, &font, sizeof (LOGFONTW));
760 state->metricsDirty = TRUE;
761 break;
762 case TMT_MENUFONT:
763 memcpy (&state->metrics.lfMenuFont, &font, sizeof (LOGFONTW));
764 state->metricsDirty = TRUE;
765 break;
766 case TMT_STATUSFONT:
767 memcpy (&state->metrics.lfStatusFont, &font, sizeof (LOGFONTW));
768 state->metricsDirty = TRUE;
769 break;
770 case TMT_MSGBOXFONT:
771 memcpy (&state->metrics.lfMessageFont, &font, sizeof (LOGFONTW));
772 state->metricsDirty = TRUE;
773 break;
774 case TMT_ICONTITLEFONT:
775 memcpy (&state->iconTitleFont, &font, sizeof (LOGFONTW));
776 state->metricsDirty = TRUE;
777 break;
779 return TRUE;
781 else
782 return FALSE;
785 static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
786 int iPropertyId, LPCWSTR lpValue,
787 DWORD dwValueLen)
789 int size;
790 LPCWSTR lpValueEnd = lpValue + dwValueLen;
791 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &size)) {
792 switch (iPropertyId)
794 case TMT_SIZINGBORDERWIDTH:
795 state->metrics.iBorderWidth = size;
796 state->metricsDirty = TRUE;
797 break;
798 case TMT_SCROLLBARWIDTH:
799 state->metrics.iScrollWidth = size;
800 state->metricsDirty = TRUE;
801 break;
802 case TMT_SCROLLBARHEIGHT:
803 state->metrics.iScrollHeight = size;
804 state->metricsDirty = TRUE;
805 break;
806 case TMT_CAPTIONBARWIDTH:
807 state->metrics.iCaptionWidth = size;
808 state->metricsDirty = TRUE;
809 break;
810 case TMT_CAPTIONBARHEIGHT:
811 state->metrics.iCaptionHeight = size;
812 state->metricsDirty = TRUE;
813 break;
814 case TMT_SMCAPTIONBARWIDTH:
815 state->metrics.iSmCaptionWidth = size;
816 state->metricsDirty = TRUE;
817 break;
818 case TMT_SMCAPTIONBARHEIGHT:
819 state->metrics.iSmCaptionHeight = size;
820 state->metricsDirty = TRUE;
821 break;
822 case TMT_MENUBARWIDTH:
823 state->metrics.iMenuWidth = size;
824 state->metricsDirty = TRUE;
825 break;
826 case TMT_MENUBARHEIGHT:
827 state->metrics.iMenuHeight = size;
828 state->metricsDirty = TRUE;
829 break;
831 return TRUE;
833 else
834 return FALSE;
837 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state)
839 if (state->metricsDirty)
841 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics),
842 (PVOID)&state->metrics, 0);
843 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (state->iconTitleFont),
844 (PVOID)&state->iconTitleFont, 0);
848 /***********************************************************************
849 * MSSTYLES_ParseThemeIni
851 * Parse the theme ini for the selected color/style
853 * PARAMS
854 * tf Theme to parse
856 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
858 static const WCHAR szSysMetrics[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
859 static const WCHAR szGlobals[] = {'g','l','o','b','a','l','s','\0'};
860 PTHEME_CLASS cls;
861 PTHEME_CLASS globals;
862 PTHEME_PARTSTATE ps;
863 PUXINI_FILE ini;
864 WCHAR szAppName[MAX_THEME_APP_NAME];
865 WCHAR szClassName[MAX_THEME_CLASS_NAME];
866 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
867 int iPartId;
868 int iStateId;
869 int iPropertyPrimitive;
870 int iPropertyId;
871 DWORD dwLen;
872 LPCWSTR lpName;
873 DWORD dwValueLen;
874 LPCWSTR lpValue;
876 ini = MSSTYLES_GetActiveThemeIni(tf);
878 while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
879 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, szSysMetrics, -1) == CSTR_EQUAL) {
880 struct PARSECOLORSTATE colorState;
881 struct PARSENONCLIENTSTATE nonClientState;
883 parse_init_color (&colorState);
884 parse_init_nonclient (&nonClientState);
886 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
887 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
888 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
889 if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
890 if (!parse_handle_color_property (&colorState, iPropertyId,
891 lpValue, dwValueLen))
892 FIXME("Invalid color value for %s\n",
893 debugstr_w(szPropertyName));
895 else if (setMetrics && (iPropertyId == TMT_FLATMENUS)) {
896 BOOL flatMenus = (*lpValue == 'T') || (*lpValue == 't');
897 SystemParametersInfoW (SPI_SETFLATMENU, 0, (PVOID)(INT_PTR)flatMenus, 0);
899 else if ((iPropertyId >= TMT_FIRSTFONT)
900 && (iPropertyId <= TMT_LASTFONT))
902 if (!parse_handle_nonclient_font (&nonClientState,
903 iPropertyId, lpValue, dwValueLen))
904 FIXME("Invalid font value for %s\n",
905 debugstr_w(szPropertyName));
907 else if ((iPropertyId >= TMT_FIRSTSIZE)
908 && (iPropertyId <= TMT_LASTSIZE))
910 if (!parse_handle_nonclient_size (&nonClientState,
911 iPropertyId, lpValue, dwValueLen))
912 FIXME("Invalid size value for %s\n",
913 debugstr_w(szPropertyName));
915 /* Catch all metrics, including colors */
916 MSSTYLES_AddMetric(tf, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen);
918 else {
919 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
922 if (setMetrics)
924 parse_apply_color (&colorState);
925 parse_apply_nonclient (&nonClientState);
927 continue;
929 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
930 BOOL isGlobal = FALSE;
931 if(!lstrcmpiW(szClassName, szGlobals)) {
932 isGlobal = TRUE;
934 cls = MSSTYLES_AddClass(tf, szAppName, szClassName);
935 ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
937 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
938 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
939 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
940 MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
942 else {
943 TRACE("Unknown property %s\n", debugstr_w(szPropertyName));
949 /* App/Class combos override values defined by the base class, map these overrides */
950 globals = MSSTYLES_FindClass(tf, NULL, szGlobals);
951 cls = tf->classes;
952 while(cls) {
953 if(*cls->szAppName) {
954 cls->overrides = MSSTYLES_FindClass(tf, NULL, cls->szClassName);
955 if(!cls->overrides) {
956 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName));
958 else {
959 cls->overrides = globals;
962 else {
963 /* Everything overrides globals..except globals */
964 if(cls != globals) cls->overrides = globals;
966 cls = cls->next;
968 UXINI_CloseINI(ini);
970 if(!tf->classes) {
971 ERR("Failed to parse theme ini\n");
975 /***********************************************************************
976 * MSSTYLES_OpenThemeClass
978 * Open a theme class, uses the current active theme
980 * PARAMS
981 * pszAppName Application name, for theme styles specific
982 * to a particular application
983 * pszClassList List of requested classes, semicolon delimited
985 PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
987 PTHEME_CLASS cls = NULL;
988 WCHAR szClassName[MAX_THEME_CLASS_NAME];
989 LPCWSTR start;
990 LPCWSTR end;
991 DWORD len;
993 if(!tfActiveTheme) {
994 TRACE("there is no active theme\n");
995 return NULL;
997 if(!tfActiveTheme->classes) {
998 return NULL;
1001 start = pszClassList;
1002 while((end = strchrW(start, ';'))) {
1003 len = end-start;
1004 lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
1005 start = end+1;
1006 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1007 if(cls) break;
1009 if(!cls && *start) {
1010 lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
1011 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1013 if(cls) {
1014 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList));
1015 cls->tf = tfActiveTheme;
1016 cls->tf->dwRefCount++;
1018 return cls;
1021 /***********************************************************************
1022 * MSSTYLES_CloseThemeClass
1024 * Close a theme class
1026 * PARAMS
1027 * tc Theme class to close
1029 * NOTES
1030 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1031 * theme file and cleans it up, if needed.
1033 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc)
1035 MSSTYLES_CloseThemeFile (tc->tf);
1036 return S_OK;
1039 /***********************************************************************
1040 * MSSTYLES_FindProperty
1042 * Locate a property in a class. Part and state IDs will be used as a
1043 * preference, but may be ignored in the attempt to locate the property.
1044 * Will scan the entire chain of overrides for this class.
1046 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId)
1048 PTHEME_CLASS next = tc;
1049 PTHEME_PARTSTATE ps;
1050 PTHEME_PROPERTY tp;
1052 TRACE("(%p, %d, %d, %d)\n", tc, iPartId, iStateId, iPropertyId);
1053 /* Try and find an exact match on part & state */
1054 while(next && (ps = MSSTYLES_FindPartState(next, iPartId, iStateId, &next))) {
1055 if((tp = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId))) {
1056 return tp;
1059 /* If that fails, and we didn't already try it, search for just part */
1060 if(iStateId != 0)
1061 iStateId = 0;
1062 /* As a last ditch attempt..go for just class */
1063 else if(iPartId != 0)
1064 iPartId = 0;
1065 else
1066 return NULL;
1068 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
1069 return tp;
1070 return NULL;
1073 /* Prepare a bitmap to be used for alpha blending */
1074 static BOOL prepare_alpha (HBITMAP bmp, BOOL* hasAlpha)
1076 DIBSECTION dib;
1077 int n;
1078 BYTE* p;
1080 *hasAlpha = FALSE;
1082 if (!bmp || GetObjectW( bmp, sizeof(dib), &dib ) != sizeof(dib))
1083 return FALSE;
1085 if(dib.dsBm.bmBitsPixel != 32)
1086 /* nothing to do */
1087 return TRUE;
1089 *hasAlpha = TRUE;
1090 p = (BYTE*)dib.dsBm.bmBits;
1091 n = abs(dib.dsBmih.biHeight) * dib.dsBmih.biWidth;
1092 /* AlphaBlend() wants premultiplied alpha, so do that now */
1093 while (n-- > 0)
1095 int a = p[3]+1;
1096 p[0] = (p[0] * a) >> 8;
1097 p[1] = (p[1] * a) >> 8;
1098 p[2] = (p[2] * a) >> 8;
1099 p += 4;
1102 return TRUE;
1105 HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
1107 WCHAR szFile[MAX_PATH];
1108 LPWSTR tmp;
1109 PTHEME_IMAGE img;
1110 lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
1111 tmp = szFile;
1112 do {
1113 if(*tmp == '\\') *tmp = '_';
1114 if(*tmp == '/') *tmp = '_';
1115 if(*tmp == '.') *tmp = '_';
1116 } while(*tmp++);
1118 /* Try to locate in list of loaded images */
1119 img = tc->tf->images;
1120 while (img)
1122 if (lstrcmpiW (szFile, img->name) == 0)
1124 TRACE ("found %p %s: %p\n", img, debugstr_w (img->name), img->image);
1125 *hasAlpha = img->hasAlpha;
1126 return img->image;
1128 img = img->next;
1130 /* Not found? Load from resources */
1131 img = HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE));
1132 img->image = LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
1133 prepare_alpha (img->image, hasAlpha);
1134 img->hasAlpha = *hasAlpha;
1135 /* ...and stow away for later reuse. */
1136 lstrcpyW (img->name, szFile);
1137 img->next = tc->tf->images;
1138 tc->tf->images = img;
1139 TRACE ("new %p %s: %p\n", img, debugstr_w (img->name), img->image);
1140 return img->image;
1143 BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
1145 LPCWSTR cur = lpStringStart;
1146 int total = 0;
1147 BOOL gotNeg = FALSE;
1149 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
1150 if(cur >= lpStringEnd) {
1151 return FALSE;
1153 if(*cur == '-') {
1154 cur++;
1155 gotNeg = TRUE;
1157 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
1158 total = total * 10 + (*cur - '0');
1159 cur++;
1161 if(gotNeg) total = -total;
1162 *value = total;
1163 if(lpValEnd) *lpValEnd = cur;
1164 return TRUE;
1167 BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize) {
1168 LPCWSTR cur = lpStringStart;
1169 LPCWSTR start;
1170 LPCWSTR end;
1172 while(cur < lpStringEnd && (isspace(*cur) || *cur == ',')) cur++;
1173 if(cur >= lpStringEnd) {
1174 return FALSE;
1176 start = cur;
1177 while(cur < lpStringEnd && *cur != ',') cur++;
1178 end = cur;
1179 while(isspace(*end)) end--;
1181 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
1183 if(lpValEnd) *lpValEnd = cur;
1184 return TRUE;
1187 /***********************************************************************
1188 * MSSTYLES_GetPropertyBool
1190 * Retrieve a color value for a property
1192 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
1194 *pfVal = FALSE;
1195 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
1196 *pfVal = TRUE;
1197 return S_OK;
1200 /***********************************************************************
1201 * MSSTYLES_GetPropertyColor
1203 * Retrieve a color value for a property
1205 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
1207 LPCWSTR lpEnd;
1208 LPCWSTR lpCur;
1209 int red, green, blue;
1211 lpCur = tp->lpValue;
1212 lpEnd = tp->lpValue + tp->dwValueLen;
1214 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &red);
1215 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &green);
1216 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &blue)) {
1217 TRACE("Could not parse color property\n");
1218 return E_PROP_ID_UNSUPPORTED;
1220 *pColor = RGB(red,green,blue);
1221 return S_OK;
1224 /***********************************************************************
1225 * MSSTYLES_GetPropertyColor
1227 * Retrieve a color value for a property
1229 static HRESULT MSSTYLES_GetFont (LPCWSTR lpCur, LPCWSTR lpEnd,
1230 LPCWSTR *lpValEnd, LOGFONTW* pFont)
1232 static const WCHAR szBold[] = {'b','o','l','d','\0'};
1233 static const WCHAR szItalic[] = {'i','t','a','l','i','c','\0'};
1234 static const WCHAR szUnderline[] = {'u','n','d','e','r','l','i','n','e','\0'};
1235 static const WCHAR szStrikeOut[] = {'s','t','r','i','k','e','o','u','t','\0'};
1236 int pointSize;
1237 WCHAR attr[32];
1239 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
1240 TRACE("Property is there, but failed to get face name\n");
1241 *lpValEnd = lpCur;
1242 return E_PROP_ID_UNSUPPORTED;
1244 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pointSize)) {
1245 TRACE("Property is there, but failed to get point size\n");
1246 *lpValEnd = lpCur;
1247 return E_PROP_ID_UNSUPPORTED;
1249 pFont->lfHeight = pointSize;
1250 pFont->lfWeight = FW_REGULAR;
1251 pFont->lfCharSet = DEFAULT_CHARSET;
1252 while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, sizeof(attr)/sizeof(attr[0]))) {
1253 if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD;
1254 else if(!!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE;
1255 else if(!!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE;
1256 else if(!!lstrcmpiW(szStrikeOut, attr)) pFont->lfStrikeOut = TRUE;
1258 *lpValEnd = lpCur;
1259 return S_OK;
1262 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
1264 LPCWSTR lpCur = tp->lpValue;
1265 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1266 HRESULT hr;
1268 ZeroMemory(pFont, sizeof(LOGFONTW));
1269 hr = MSSTYLES_GetFont (lpCur, lpEnd, &lpCur, pFont);
1270 if (SUCCEEDED (hr))
1271 pFont->lfHeight = -MulDiv(pFont->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1273 return hr;
1276 /***********************************************************************
1277 * MSSTYLES_GetPropertyInt
1279 * Retrieve an int value for a property
1281 HRESULT MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp, int *piVal)
1283 if(!MSSTYLES_GetNextInteger(tp->lpValue, (tp->lpValue + tp->dwValueLen), NULL, piVal)) {
1284 TRACE("Could not parse int property\n");
1285 return E_PROP_ID_UNSUPPORTED;
1287 return S_OK;
1290 /***********************************************************************
1291 * MSSTYLES_GetPropertyIntList
1293 * Retrieve an int list value for a property
1295 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1297 int i;
1298 LPCWSTR lpCur = tp->lpValue;
1299 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1301 for(i=0; i < MAX_INTLIST_COUNT; i++) {
1302 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pIntList->iValues[i]))
1303 break;
1305 pIntList->iValueCount = i;
1306 return S_OK;
1309 /***********************************************************************
1310 * MSSTYLES_GetPropertyPosition
1312 * Retrieve a position value for a property
1314 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1316 int x,y;
1317 LPCWSTR lpCur = tp->lpValue;
1318 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1320 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &x);
1321 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &y)) {
1322 TRACE("Could not parse position property\n");
1323 return E_PROP_ID_UNSUPPORTED;
1325 pPoint->x = x;
1326 pPoint->y = y;
1327 return S_OK;
1330 /***********************************************************************
1331 * MSSTYLES_GetPropertyString
1333 * Retrieve a string value for a property
1335 HRESULT MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp, LPWSTR pszBuff, int cchMaxBuffChars)
1337 lstrcpynW(pszBuff, tp->lpValue, min(tp->dwValueLen+1, cchMaxBuffChars));
1338 return S_OK;
1341 /***********************************************************************
1342 * MSSTYLES_GetPropertyRect
1344 * Retrieve a rect value for a property
1346 HRESULT MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp, RECT *pRect)
1348 LPCWSTR lpCur = tp->lpValue;
1349 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1351 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->left);
1352 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->top);
1353 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->right);
1354 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->bottom)) {
1355 TRACE("Could not parse rect property\n");
1356 return E_PROP_ID_UNSUPPORTED;
1358 return S_OK;
1361 /***********************************************************************
1362 * MSSTYLES_GetPropertyMargins
1364 * Retrieve a margins value for a property
1366 HRESULT MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp, RECT *prc, MARGINS *pMargins)
1368 LPCWSTR lpCur = tp->lpValue;
1369 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1371 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxLeftWidth);
1372 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxRightWidth);
1373 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyTopHeight);
1374 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyBottomHeight)) {
1375 TRACE("Could not parse margins property\n");
1376 return E_PROP_ID_UNSUPPORTED;
1378 return S_OK;