widl: Add support for protected attribute.
[wine.git] / dlls / uxtheme / msstyles.c
blobcfd21a48989ff1a146d1503045df7ba6c187ac51
1 /*
2 * Win32 5.1 msstyles theme format
4 * Copyright (C) 2003 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "vfwmsgs.h"
30 #include "uxtheme.h"
31 #include "vssym32.h"
33 #include "msstyles.h"
35 #include "wine/exception.h"
36 #include "wine/debug.h"
37 #include "wine/heap.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
41 /***********************************************************************
42 * Defines and global variables
45 static BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value);
46 static BOOL MSSTYLES_GetNextLong(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LONG *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 #define MSSTYLES_VERSION 0x0003
53 #define THEME_CLASS_SIGNATURE 0x12bc6d83
55 static PTHEME_FILE tfActiveTheme;
57 /***********************************************************************/
59 /**********************************************************************
60 * MSSTYLES_OpenThemeFile
62 * Load and validate a theme
64 * PARAMS
65 * lpThemeFile Path to theme file to load
66 * pszColorName Color name wanted, can be NULL
67 * pszSizeName Size name wanted, can be NULL
69 * NOTES
70 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
71 * If one/both are provided, they are validated against valid color/sizes and if
72 * a match is not found, the function fails.
74 HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWSTR pszSizeName, PTHEME_FILE *tf)
76 HMODULE hTheme;
77 HRSRC hrsc;
78 HRESULT hr = S_OK;
80 WORD version;
81 DWORD versize;
82 LPWSTR pszColors;
83 LPWSTR pszSelectedColor = NULL;
84 LPWSTR pszSizes;
85 LPWSTR pszSelectedSize = NULL;
86 LPWSTR tmp;
88 TRACE("Opening %s\n", debugstr_w(lpThemeFile));
90 hTheme = LoadLibraryExW(lpThemeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);
92 /* Validate that this is really a theme */
93 if(!hTheme) {
94 hr = HRESULT_FROM_WIN32(GetLastError());
95 goto invalid_theme;
97 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), L"PACKTHEM_VERSION"))) {
98 TRACE("No version resource found\n");
99 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
100 goto invalid_theme;
102 if((versize = SizeofResource(hTheme, hrsc)) != 2)
104 TRACE("Version resource found, but wrong size: %ld\n", versize);
105 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
106 goto invalid_theme;
108 version = *(WORD*)LoadResource(hTheme, hrsc);
109 if(version != MSSTYLES_VERSION)
111 TRACE("Version of theme file is unsupported: 0x%04x\n", version);
112 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
113 goto invalid_theme;
116 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), L"COLORNAMES"))) {
117 TRACE("Color names resource not found\n");
118 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
119 goto invalid_theme;
121 pszColors = LoadResource(hTheme, hrsc);
123 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), L"SIZENAMES"))) {
124 TRACE("Size names resource not found\n");
125 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
126 goto invalid_theme;
128 pszSizes = LoadResource(hTheme, hrsc);
130 /* Validate requested color against what's available from the theme */
131 if(pszColorName) {
132 tmp = pszColors;
133 while(*tmp) {
134 if(!lstrcmpiW(pszColorName, tmp)) {
135 pszSelectedColor = tmp;
136 break;
138 tmp += lstrlenW(tmp)+1;
141 else
142 pszSelectedColor = pszColors; /* Use the default color */
144 /* Validate requested size against what's available from the theme */
145 if(pszSizeName) {
146 tmp = pszSizes;
147 while(*tmp) {
148 if(!lstrcmpiW(pszSizeName, tmp)) {
149 pszSelectedSize = tmp;
150 break;
152 tmp += lstrlenW(tmp)+1;
155 else
156 pszSelectedSize = pszSizes; /* Use the default size */
158 if(!pszSelectedColor || !pszSelectedSize) {
159 TRACE("Requested color/size (%s/%s) not found in theme\n",
160 debugstr_w(pszColorName), debugstr_w(pszSizeName));
161 hr = E_PROP_ID_UNSUPPORTED;
162 goto invalid_theme;
165 *tf = heap_alloc_zero(sizeof(THEME_FILE));
166 (*tf)->hTheme = hTheme;
168 GetFullPathNameW(lpThemeFile, MAX_PATH, (*tf)->szThemeFile, NULL);
170 (*tf)->pszAvailColors = pszColors;
171 (*tf)->pszAvailSizes = pszSizes;
172 (*tf)->pszSelectedColor = pszSelectedColor;
173 (*tf)->pszSelectedSize = pszSelectedSize;
174 (*tf)->refcount = 1;
175 return S_OK;
177 invalid_theme:
178 *tf = NULL;
179 if(hTheme) FreeLibrary(hTheme);
180 return hr;
183 /***********************************************************************
184 * MSSTYLES_CloseThemeFile
186 * Close theme file and free resources
188 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
190 LONG refcount;
192 if(tf) {
193 refcount = InterlockedDecrement(&tf->refcount);
194 if (!refcount)
196 if(tf->hTheme) FreeLibrary(tf->hTheme);
197 if(tf->classes) {
198 while(tf->classes) {
199 PTHEME_CLASS pcls = tf->classes;
200 tf->classes = pcls->next;
201 while(pcls->partstate) {
202 PTHEME_PARTSTATE ps = pcls->partstate;
204 while(ps->properties) {
205 PTHEME_PROPERTY prop = ps->properties;
206 ps->properties = prop->next;
207 heap_free(prop);
210 pcls->partstate = ps->next;
211 heap_free(ps);
213 pcls->signature = 0;
214 heap_free(pcls);
217 while (tf->images)
219 PTHEME_IMAGE img = tf->images;
220 tf->images = img->next;
221 DeleteObject (img->image);
222 heap_free(img);
224 heap_free(tf);
229 /***********************************************************************
230 * MSSTYLES_SetActiveTheme
232 * Set the current active theme
234 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf, BOOL setMetrics)
236 if(tfActiveTheme)
237 MSSTYLES_CloseThemeFile(tfActiveTheme);
238 tfActiveTheme = tf;
239 if (tfActiveTheme)
241 InterlockedIncrement(&tfActiveTheme->refcount);
242 if(!tfActiveTheme->classes)
243 MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics);
245 return S_OK;
248 /***********************************************************************
249 * MSSTYLES_GetThemeIni
251 * Retrieves themes.ini from a theme
253 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf)
255 return UXINI_LoadINI(tf->hTheme, L"themes_ini");
258 /***********************************************************************
259 * MSSTYLES_GetThemeDPI
261 * Retrieves the DPI from a theme handle when it was opened
263 UINT MSSTYLES_GetThemeDPI(PTHEME_CLASS tc)
265 return tc->dpi;
268 /***********************************************************************
269 * MSSTYLES_GetActiveThemeIni
271 * Retrieve the ini file for the selected color/style
273 static PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf)
275 DWORD dwColorCount = 0;
276 DWORD dwSizeCount = 0;
277 DWORD dwColorNum = 0;
278 DWORD dwSizeNum = 0;
279 DWORD i;
280 DWORD dwResourceIndex;
281 LPWSTR tmp;
282 HRSRC hrsc;
284 /* Count the number of available colors & styles, and determine the index number
285 of the color/style we are interested in
287 tmp = tf->pszAvailColors;
288 while(*tmp) {
289 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
290 dwColorNum = dwColorCount;
291 tmp += lstrlenW(tmp)+1;
292 dwColorCount++;
294 tmp = tf->pszAvailSizes;
295 while(*tmp) {
296 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
297 dwSizeNum = dwSizeCount;
298 tmp += lstrlenW(tmp)+1;
299 dwSizeCount++;
302 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), L"FILERESNAMES"))) {
303 TRACE("FILERESNAMES map not found\n");
304 return NULL;
306 tmp = LoadResource(tf->hTheme, hrsc);
307 dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum;
308 for(i=0; i < dwResourceIndex; i++) {
309 tmp += lstrlenW(tmp)+1;
311 return UXINI_LoadINI(tf->hTheme, tmp);
315 /***********************************************************************
316 * MSSTYLES_ParseIniSectionName
318 * Parse an ini section name into its component parts
319 * Valid formats are:
320 * [classname]
321 * [classname(state)]
322 * [classname.part]
323 * [classname.part(state)]
324 * [application::classname]
325 * [application::classname(state)]
326 * [application::classname.part]
327 * [application::classname.part(state)]
329 * PARAMS
330 * lpSection Section name
331 * dwLen Length of section name
332 * szAppName Location to store application name
333 * szClassName Location to store class name
334 * iPartId Location to store part id
335 * iStateId Location to store state id
337 static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR szAppName, LPWSTR szClassName, int *iPartId, int *iStateId)
339 WCHAR sec[255];
340 WCHAR part[60] = {'\0'};
341 WCHAR state[60] = {'\0'};
342 LPWSTR tmp;
343 LPWSTR comp;
344 lstrcpynW(sec, lpSection, min(dwLen+1, ARRAY_SIZE(sec)));
346 *szAppName = 0;
347 *szClassName = 0;
348 *iPartId = 0;
349 *iStateId = 0;
350 comp = sec;
351 /* Get the application name */
352 tmp = wcschr(comp, ':');
353 if(tmp) {
354 *tmp++ = 0;
355 tmp++;
356 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
357 comp = tmp;
360 tmp = wcschr(comp, '.');
361 if(tmp) {
362 *tmp++ = 0;
363 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
364 comp = tmp;
365 /* now get the part & state */
366 tmp = wcschr(comp, '(');
367 if(tmp) {
368 *tmp++ = 0;
369 lstrcpynW(part, comp, ARRAY_SIZE(part));
370 comp = tmp;
371 /* now get the state */
372 tmp = wcschr(comp, ')');
373 if (!tmp)
374 return FALSE;
375 *tmp = 0;
376 lstrcpynW(state, comp, ARRAY_SIZE(state));
378 else {
379 lstrcpynW(part, comp, ARRAY_SIZE(part));
382 else {
383 tmp = wcschr(comp, '(');
384 if(tmp) {
385 *tmp++ = 0;
386 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
387 comp = tmp;
388 /* now get the state */
389 tmp = wcschr(comp, ')');
390 if (!tmp)
391 return FALSE;
392 *tmp = 0;
393 lstrcpynW(state, comp, ARRAY_SIZE(state));
395 else {
396 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
399 if(!*szClassName) return FALSE;
400 return MSSTYLES_LookupPartState(szClassName, part[0]?part:NULL, state[0]?state:NULL, iPartId, iStateId);
403 /***********************************************************************
404 * MSSTYLES_FindClass
406 * Find a class
408 * PARAMS
409 * tf Theme file
410 * pszAppName App name to find
411 * pszClassName Class name to find
413 * RETURNS
414 * The class found, or NULL
416 static PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
418 PTHEME_CLASS cur = tf->classes;
419 while(cur) {
420 if(!pszAppName) {
421 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
422 return cur;
424 else {
425 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
426 return cur;
428 cur = cur->next;
430 return NULL;
433 /***********************************************************************
434 * MSSTYLES_AddClass
436 * Add a class to a theme file
438 * PARAMS
439 * tf Theme file
440 * pszAppName App name to add
441 * pszClassName Class name to add
443 * RETURNS
444 * The class added, or a class previously added with the same name
446 static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
448 PTHEME_CLASS cur = MSSTYLES_FindClass(tf, pszAppName, pszClassName);
449 if(cur) return cur;
451 cur = heap_alloc(sizeof(*cur));
452 cur->signature = THEME_CLASS_SIGNATURE;
453 cur->refcount = 0;
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_FindPart
467 * Find a part
469 * PARAMS
470 * tc Class to search
471 * iPartId Part ID to find
473 * RETURNS
474 * The part found, or NULL
476 PTHEME_PARTSTATE MSSTYLES_FindPart(PTHEME_CLASS tc, int iPartId)
478 PTHEME_PARTSTATE cur = tc->partstate;
480 while (cur)
482 if (cur->iPartId == iPartId)
483 return cur;
485 cur = cur->next;
488 if (tc->overrides)
489 return MSSTYLES_FindPart(tc->overrides, iPartId);
491 return NULL;
494 /***********************************************************************
495 * MSSTYLES_FindPartState
497 * Find a part/state
499 * PARAMS
500 * tc Class to search
501 * iPartId Part ID to find
502 * iStateId State ID to find
503 * tcNext Receives the next class in the override chain
505 * RETURNS
506 * The part/state found, or NULL
508 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext)
510 PTHEME_PARTSTATE cur = tc->partstate;
511 while(cur) {
512 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
513 if(tcNext) *tcNext = tc->overrides;
514 return cur;
516 cur = cur->next;
518 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
519 return NULL;
522 /***********************************************************************
523 * MSSTYLES_AddPartState
525 * Add a part/state to a class
527 * PARAMS
528 * tc Theme class
529 * iPartId Part ID to add
530 * iStateId State ID to add
532 * RETURNS
533 * The part/state added, or a part/state previously added with the same IDs
535 static PTHEME_PARTSTATE MSSTYLES_AddPartState(PTHEME_CLASS tc, int iPartId, int iStateId)
537 PTHEME_PARTSTATE cur = MSSTYLES_FindPartState(tc, iPartId, iStateId, NULL);
538 if(cur) return cur;
540 cur = heap_alloc(sizeof(*cur));
541 cur->iPartId = iPartId;
542 cur->iStateId = iStateId;
543 cur->properties = NULL;
544 cur->next = tc->partstate;
545 tc->partstate = cur;
546 return cur;
549 /***********************************************************************
550 * MSSTYLES_LFindProperty
552 * Find a property within a property list
554 * PARAMS
555 * tp property list to scan
556 * iPropertyPrimitive Type of value expected
557 * iPropertyId ID of the required value
559 * RETURNS
560 * The property found, or NULL
562 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
564 PTHEME_PROPERTY cur = tp;
565 while(cur) {
566 if(cur->iPropertyId == iPropertyId) {
567 if(cur->iPrimitiveType == iPropertyPrimitive) {
568 return cur;
570 else {
571 if(!iPropertyPrimitive)
572 return cur;
573 return NULL;
576 cur = cur->next;
578 return NULL;
581 /***********************************************************************
582 * MSSTYLES_PSFindProperty
584 * Find a value within a part/state
586 * PARAMS
587 * ps Part/state to search
588 * iPropertyPrimitive Type of value expected
589 * iPropertyId ID of the required value
591 * RETURNS
592 * The property found, or NULL
594 static inline PTHEME_PROPERTY MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId)
596 return MSSTYLES_LFindProperty(ps->properties, iPropertyPrimitive, iPropertyId);
599 /***********************************************************************
600 * MSSTYLES_FFindMetric
602 * Find a metric property for a theme file
604 * PARAMS
605 * tf Theme file
606 * iPropertyPrimitive Type of value expected
607 * iPropertyId ID of the required value
609 * RETURNS
610 * The property found, or NULL
612 static inline PTHEME_PROPERTY MSSTYLES_FFindMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId)
614 return MSSTYLES_LFindProperty(tf->metrics, iPropertyPrimitive, iPropertyId);
617 /***********************************************************************
618 * MSSTYLES_FindMetric
620 * Find a metric property for the current installed theme
622 * PARAMS
623 * tf Theme file
624 * iPropertyPrimitive Type of value expected
625 * iPropertyId ID of the required value
627 * RETURNS
628 * The property found, or NULL
630 PTHEME_PROPERTY MSSTYLES_FindMetric(int iPropertyPrimitive, int iPropertyId)
632 if(!tfActiveTheme) return NULL;
633 return MSSTYLES_FFindMetric(tfActiveTheme, iPropertyPrimitive, iPropertyId);
636 /***********************************************************************
637 * MSSTYLES_AddProperty
639 * Add a property to a part/state
641 * PARAMS
642 * ps Part/state
643 * iPropertyPrimitive Primitive type of the property
644 * iPropertyId ID of the property
645 * lpValue Raw value (non-NULL terminated)
646 * dwValueLen Length of the value
648 * RETURNS
649 * The property added, or a property previously added with the same IDs
651 static PTHEME_PROPERTY MSSTYLES_AddProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen, BOOL isGlobal)
653 PTHEME_PROPERTY cur = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId);
654 /* Should duplicate properties overwrite the original, or be ignored? */
655 if(cur) return cur;
657 cur = heap_alloc(sizeof(*cur));
658 cur->iPrimitiveType = iPropertyPrimitive;
659 cur->iPropertyId = iPropertyId;
660 cur->lpValue = lpValue;
661 cur->dwValueLen = dwValueLen;
663 if(ps->iStateId)
664 cur->origin = PO_STATE;
665 else if(ps->iPartId)
666 cur->origin = PO_PART;
667 else if(isGlobal)
668 cur->origin = PO_GLOBAL;
669 else
670 cur->origin = PO_CLASS;
672 cur->next = ps->properties;
673 ps->properties = cur;
674 return cur;
677 /***********************************************************************
678 * MSSTYLES_AddMetric
680 * Add a property to a part/state
682 * PARAMS
683 * tf Theme file
684 * iPropertyPrimitive Primitive type of the property
685 * iPropertyId ID of the property
686 * lpValue Raw value (non-NULL terminated)
687 * dwValueLen Length of the value
689 * RETURNS
690 * The property added, or a property previously added with the same IDs
692 static PTHEME_PROPERTY MSSTYLES_AddMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen)
694 PTHEME_PROPERTY cur = MSSTYLES_FFindMetric(tf, iPropertyPrimitive, iPropertyId);
695 /* Should duplicate properties overwrite the original, or be ignored? */
696 if(cur) return cur;
698 cur = heap_alloc(sizeof(*cur));
699 cur->iPrimitiveType = iPropertyPrimitive;
700 cur->iPropertyId = iPropertyId;
701 cur->lpValue = lpValue;
702 cur->dwValueLen = dwValueLen;
704 cur->origin = PO_GLOBAL;
706 cur->next = tf->metrics;
707 tf->metrics = cur;
708 return cur;
711 /* Color-related state for theme ini parsing */
712 struct PARSECOLORSTATE
714 int colorCount;
715 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
716 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR+1];
717 int captionColors;
720 static inline void parse_init_color (struct PARSECOLORSTATE* state)
722 memset (state, 0, sizeof (*state));
725 static BOOL parse_handle_color_property (struct PARSECOLORSTATE* state,
726 int iPropertyId, LPCWSTR lpValue,
727 DWORD dwValueLen)
729 int r,g,b;
730 LPCWSTR lpValueEnd = lpValue + dwValueLen;
731 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r) &&
732 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g) &&
733 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
734 state->colorElements[state->colorCount] = iPropertyId - TMT_FIRSTCOLOR;
735 state->colorRgb[state->colorCount++] = RGB(r,g,b);
736 switch (iPropertyId)
738 case TMT_ACTIVECAPTION:
739 state->captionColors |= 0x1;
740 break;
741 case TMT_INACTIVECAPTION:
742 state->captionColors |= 0x2;
743 break;
744 case TMT_GRADIENTACTIVECAPTION:
745 state->captionColors |= 0x4;
746 break;
747 case TMT_GRADIENTINACTIVECAPTION:
748 state->captionColors |= 0x8;
749 break;
751 return TRUE;
753 else {
754 return FALSE;
758 static void parse_apply_color (struct PARSECOLORSTATE* state)
760 if (state->colorCount > 0)
761 SetSysColors(state->colorCount, state->colorElements, state->colorRgb);
762 if (state->captionColors == 0xf)
763 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
766 /* Non-client-metrics-related state for theme ini parsing */
767 struct PARSENONCLIENTSTATE
769 NONCLIENTMETRICSW metrics;
770 BOOL metricsDirty;
771 LOGFONTW iconTitleFont;
774 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE* state)
776 DPI_AWARENESS_CONTEXT old_context;
778 old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
780 memset (state, 0, sizeof (*state));
781 state->metrics.cbSize = sizeof (NONCLIENTMETRICSW);
782 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW),
783 &state->metrics, 0);
784 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (LOGFONTW),
785 &state->iconTitleFont, 0);
787 SetThreadDpiAwarenessContext(old_context);
790 static BOOL parse_handle_nonclient_font (struct PARSENONCLIENTSTATE* state,
791 int iPropertyId, LPCWSTR lpValue,
792 DWORD dwValueLen)
794 LOGFONTW font;
796 memset (&font, 0, sizeof (font));
797 if (SUCCEEDED (MSSTYLES_GetFont (lpValue, lpValue + dwValueLen, &lpValue,
798 &font)))
800 switch (iPropertyId)
802 case TMT_CAPTIONFONT:
803 state->metrics.lfCaptionFont = font;
804 state->metricsDirty = TRUE;
805 break;
806 case TMT_SMALLCAPTIONFONT:
807 state->metrics.lfSmCaptionFont = font;
808 state->metricsDirty = TRUE;
809 break;
810 case TMT_MENUFONT:
811 state->metrics.lfMenuFont = font;
812 state->metricsDirty = TRUE;
813 break;
814 case TMT_STATUSFONT:
815 state->metrics.lfStatusFont = font;
816 state->metricsDirty = TRUE;
817 break;
818 case TMT_MSGBOXFONT:
819 state->metrics.lfMessageFont = font;
820 state->metricsDirty = TRUE;
821 break;
822 case TMT_ICONTITLEFONT:
823 state->iconTitleFont = font;
824 state->metricsDirty = TRUE;
825 break;
827 return TRUE;
829 else
830 return FALSE;
833 static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
834 int iPropertyId, LPCWSTR lpValue,
835 DWORD dwValueLen)
837 int size;
838 LPCWSTR lpValueEnd = lpValue + dwValueLen;
839 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &size)) {
840 switch (iPropertyId)
842 case TMT_SIZINGBORDERWIDTH:
843 state->metrics.iBorderWidth = size;
844 state->metricsDirty = TRUE;
845 break;
846 case TMT_SCROLLBARWIDTH:
847 state->metrics.iScrollWidth = size;
848 state->metricsDirty = TRUE;
849 break;
850 case TMT_SCROLLBARHEIGHT:
851 state->metrics.iScrollHeight = size;
852 state->metricsDirty = TRUE;
853 break;
854 case TMT_CAPTIONBARWIDTH:
855 state->metrics.iCaptionWidth = size;
856 state->metricsDirty = TRUE;
857 break;
858 case TMT_CAPTIONBARHEIGHT:
859 state->metrics.iCaptionHeight = size;
860 state->metricsDirty = TRUE;
861 break;
862 case TMT_SMCAPTIONBARWIDTH:
863 state->metrics.iSmCaptionWidth = size;
864 state->metricsDirty = TRUE;
865 break;
866 case TMT_SMCAPTIONBARHEIGHT:
867 state->metrics.iSmCaptionHeight = size;
868 state->metricsDirty = TRUE;
869 break;
870 case TMT_MENUBARWIDTH:
871 state->metrics.iMenuWidth = size;
872 state->metricsDirty = TRUE;
873 break;
874 case TMT_MENUBARHEIGHT:
875 state->metrics.iMenuHeight = size;
876 state->metricsDirty = TRUE;
877 break;
879 return TRUE;
881 else
882 return FALSE;
885 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state)
887 DPI_AWARENESS_CONTEXT old_context;
889 if (state->metricsDirty)
891 old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
892 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics),
893 &state->metrics, 0);
894 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (state->iconTitleFont),
895 &state->iconTitleFont, 0);
896 SetThreadDpiAwarenessContext(old_context);
900 /***********************************************************************
901 * MSSTYLES_ParseThemeIni
903 * Parse the theme ini for the selected color/style
905 * PARAMS
906 * tf Theme to parse
908 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
910 PTHEME_CLASS cls;
911 PTHEME_CLASS globals;
912 PTHEME_PARTSTATE ps;
913 PUXINI_FILE ini;
914 WCHAR szAppName[MAX_THEME_APP_NAME];
915 WCHAR szClassName[MAX_THEME_CLASS_NAME];
916 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
917 int iPartId;
918 int iStateId;
919 int iPropertyPrimitive;
920 int iPropertyId;
921 DWORD dwLen;
922 LPCWSTR lpName;
923 DWORD dwValueLen;
924 LPCWSTR lpValue;
926 ini = MSSTYLES_GetActiveThemeIni(tf);
928 while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
929 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, L"SysMetrics", -1) == CSTR_EQUAL) {
930 struct PARSECOLORSTATE colorState;
931 struct PARSENONCLIENTSTATE nonClientState;
933 parse_init_color (&colorState);
934 parse_init_nonclient (&nonClientState);
936 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
937 lstrcpynW(szPropertyName, lpName, min(dwLen+1, ARRAY_SIZE(szPropertyName)));
938 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
939 if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
940 if (!parse_handle_color_property (&colorState, iPropertyId,
941 lpValue, dwValueLen))
942 FIXME("Invalid color value for %s\n",
943 debugstr_w(szPropertyName));
945 else if (setMetrics && (iPropertyId == TMT_FLATMENUS)) {
946 BOOL flatMenus = (*lpValue == 'T') || (*lpValue == 't');
947 SystemParametersInfoW (SPI_SETFLATMENU, 0, (PVOID)(INT_PTR)flatMenus, 0);
949 else if ((iPropertyId >= TMT_FIRSTFONT)
950 && (iPropertyId <= TMT_LASTFONT))
952 if (!parse_handle_nonclient_font (&nonClientState,
953 iPropertyId, lpValue, dwValueLen))
954 FIXME("Invalid font value for %s\n",
955 debugstr_w(szPropertyName));
957 else if ((iPropertyId >= TMT_FIRSTSIZE)
958 && (iPropertyId <= TMT_LASTSIZE))
960 if (!parse_handle_nonclient_size (&nonClientState,
961 iPropertyId, lpValue, dwValueLen))
962 FIXME("Invalid size value for %s\n",
963 debugstr_w(szPropertyName));
965 /* Catch all metrics, including colors */
966 MSSTYLES_AddMetric(tf, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen);
968 else {
969 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
972 if (setMetrics)
974 parse_apply_color (&colorState);
975 parse_apply_nonclient (&nonClientState);
977 continue;
979 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
980 BOOL isGlobal = FALSE;
981 if(!lstrcmpiW(szClassName, L"globals")) {
982 isGlobal = TRUE;
984 cls = MSSTYLES_AddClass(tf, szAppName, szClassName);
985 ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
987 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
988 lstrcpynW(szPropertyName, lpName, min(dwLen+1, ARRAY_SIZE(szPropertyName)));
989 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
990 MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
992 else {
993 TRACE("Unknown property %s\n", debugstr_w(szPropertyName));
999 /* App/Class combos override values defined by the base class, map these overrides */
1000 globals = MSSTYLES_FindClass(tf, NULL, L"globals");
1001 cls = tf->classes;
1002 while(cls) {
1003 if(*cls->szAppName) {
1004 cls->overrides = MSSTYLES_FindClass(tf, NULL, cls->szClassName);
1005 if(!cls->overrides) {
1006 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName));
1008 else {
1009 cls->overrides = globals;
1012 else {
1013 /* Everything overrides globals..except globals */
1014 if(cls != globals) cls->overrides = globals;
1016 cls = cls->next;
1018 UXINI_CloseINI(ini);
1020 if(!tf->classes) {
1021 ERR("Failed to parse theme ini\n");
1025 /***********************************************************************
1026 * MSSTYLES_OpenThemeClass
1028 * Open a theme class, uses the current active theme
1030 * PARAMS
1031 * pszAppName Application name, for theme styles specific
1032 * to a particular application
1033 * pszClassList List of requested classes, semicolon delimited
1034 * dpi DPI for theme parts
1036 PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList, UINT dpi)
1038 PTHEME_CLASS cls = NULL;
1039 WCHAR szClassName[MAX_THEME_CLASS_NAME];
1040 LPCWSTR start;
1041 LPCWSTR end;
1042 DWORD len;
1044 if(!tfActiveTheme) {
1045 TRACE("there is no active theme\n");
1046 return NULL;
1048 if(!tfActiveTheme->classes) {
1049 return NULL;
1052 start = pszClassList;
1053 while((end = wcschr(start, ';'))) {
1054 len = end-start;
1055 lstrcpynW(szClassName, start, min(len+1, ARRAY_SIZE(szClassName)));
1056 start = end+1;
1057 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1058 if(cls) break;
1060 if(!cls && *start) {
1061 lstrcpynW(szClassName, start, ARRAY_SIZE(szClassName));
1062 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1064 if(cls) {
1065 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList));
1066 cls->tf = tfActiveTheme;
1067 InterlockedIncrement(&cls->tf->refcount);
1068 InterlockedIncrement(&cls->refcount);
1069 cls->dpi = dpi;
1071 return cls;
1074 /***********************************************************************
1075 * MSSTYLES_CloseThemeClass
1077 * Close a theme class
1079 * PARAMS
1080 * tc Theme class to close
1082 * NOTES
1083 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1084 * theme file and cleans it up, if needed.
1086 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc)
1088 LONG refcount;
1090 __TRY
1092 if (tc->signature != THEME_CLASS_SIGNATURE)
1093 tc = NULL;
1095 __EXCEPT_PAGE_FAULT
1097 tc = NULL;
1099 __ENDTRY
1101 if (!tc)
1103 WARN("Invalid theme class handle\n");
1104 return E_HANDLE;
1107 refcount = InterlockedDecrement(&tc->refcount);
1108 /* Some buggy apps may double free HTHEME handles */
1109 if (refcount >= 0)
1110 MSSTYLES_CloseThemeFile(tc->tf);
1111 return S_OK;
1114 /***********************************************************************
1115 * MSSTYLES_FindProperty
1117 * Locate a property in a class. Part and state IDs will be used as a
1118 * preference, but may be ignored in the attempt to locate the property.
1119 * Will scan the entire chain of overrides for this class.
1121 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId)
1123 PTHEME_CLASS next = tc;
1124 PTHEME_PARTSTATE ps;
1125 PTHEME_PROPERTY tp;
1127 TRACE("(%p, %d, %d, %d)\n", tc, iPartId, iStateId, iPropertyId);
1128 /* Try and find an exact match on part & state */
1129 while(next && (ps = MSSTYLES_FindPartState(next, iPartId, iStateId, &next))) {
1130 if((tp = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId))) {
1131 return tp;
1134 /* If that fails, and we didn't already try it, search for just part */
1135 if(iStateId != 0)
1136 iStateId = 0;
1137 /* As a last ditch attempt..go for just class */
1138 else if(iPartId != 0)
1139 iPartId = 0;
1140 else
1141 return NULL;
1143 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
1144 return tp;
1145 return NULL;
1148 /* Prepare a bitmap to be used for alpha blending */
1149 static BOOL prepare_alpha (HBITMAP bmp, BOOL* hasAlpha)
1151 DIBSECTION dib;
1152 int n;
1153 BYTE* p;
1155 *hasAlpha = FALSE;
1157 if (!bmp || GetObjectW( bmp, sizeof(dib), &dib ) != sizeof(dib))
1158 return FALSE;
1160 if (dib.dsBm.bmBitsPixel != 32 || dib.dsBmih.biCompression != BI_RGB)
1161 /* nothing to do */
1162 return TRUE;
1164 /* If all alpha values are 0xff, don't use alpha blending */
1165 for (n = 0, p = dib.dsBm.bmBits; n < dib.dsBmih.biWidth * dib.dsBmih.biHeight; n++, p += 4)
1166 if ((*hasAlpha = (p[3] != 0xff)))
1167 break;
1169 if (!*hasAlpha)
1170 return TRUE;
1172 p = dib.dsBm.bmBits;
1173 n = dib.dsBmih.biHeight * dib.dsBmih.biWidth;
1174 /* AlphaBlend() wants premultiplied alpha, so do that now */
1175 while (n-- > 0)
1177 int a = p[3]+1;
1178 p[0] = (p[0] * a) >> 8;
1179 p[1] = (p[1] * a) >> 8;
1180 p[2] = (p[2] * a) >> 8;
1181 p += 4;
1184 return TRUE;
1187 HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
1189 WCHAR szFile[MAX_PATH];
1190 LPWSTR tmp;
1191 PTHEME_IMAGE img;
1192 lstrcpynW(szFile, lpFilename, ARRAY_SIZE(szFile));
1193 tmp = szFile;
1194 do {
1195 if(*tmp == '\\') *tmp = '_';
1196 if(*tmp == '/') *tmp = '_';
1197 if(*tmp == '.') *tmp = '_';
1198 } while(*tmp++);
1200 /* Try to locate in list of loaded images */
1201 img = tc->tf->images;
1202 while (img)
1204 if (lstrcmpiW (szFile, img->name) == 0)
1206 TRACE ("found %p %s: %p\n", img, debugstr_w (img->name), img->image);
1207 *hasAlpha = img->hasAlpha;
1208 return img->image;
1210 img = img->next;
1212 /* Not found? Load from resources */
1213 img = heap_alloc(sizeof(*img));
1214 img->image = LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
1215 prepare_alpha (img->image, hasAlpha);
1216 img->hasAlpha = *hasAlpha;
1217 /* ...and stow away for later reuse. */
1218 lstrcpyW (img->name, szFile);
1219 img->next = tc->tf->images;
1220 tc->tf->images = img;
1221 TRACE ("new %p %s: %p\n", img, debugstr_w (img->name), img->image);
1222 return img->image;
1225 static BOOL MSSTYLES_GetNextLong(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LONG *value)
1227 LPCWSTR cur = lpStringStart;
1228 LONG total = 0;
1229 BOOL gotNeg = FALSE;
1231 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
1232 if(cur >= lpStringEnd) {
1233 return FALSE;
1235 if(*cur == '-') {
1236 cur++;
1237 gotNeg = TRUE;
1239 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
1240 total = total * 10 + (*cur - '0');
1241 cur++;
1243 if(gotNeg) total = -total;
1244 *value = total;
1245 if(lpValEnd) *lpValEnd = cur;
1246 return TRUE;
1249 static BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
1251 return MSSTYLES_GetNextLong(lpStringStart, lpStringEnd, lpValEnd, (LONG *)value);
1254 static inline BOOL isSpace(WCHAR c)
1256 return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v';
1259 static BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize) {
1260 LPCWSTR cur = lpStringStart;
1261 LPCWSTR start;
1262 LPCWSTR end;
1264 while(cur < lpStringEnd && (isSpace(*cur) || *cur == ',')) cur++;
1265 if(cur >= lpStringEnd) {
1266 return FALSE;
1268 start = cur;
1269 while(cur < lpStringEnd && *cur != ',') cur++;
1270 end = cur;
1271 while(isSpace(*end)) end--;
1273 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
1275 if(lpValEnd) *lpValEnd = cur;
1276 return TRUE;
1279 /***********************************************************************
1280 * MSSTYLES_GetPropertyBool
1282 * Retrieve a color value for a property
1284 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
1286 *pfVal = FALSE;
1287 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
1288 *pfVal = TRUE;
1289 return S_OK;
1292 /***********************************************************************
1293 * MSSTYLES_GetPropertyColor
1295 * Retrieve a color value for a property
1297 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
1299 LPCWSTR lpEnd;
1300 LPCWSTR lpCur;
1301 int red, green, blue;
1303 lpCur = tp->lpValue;
1304 lpEnd = tp->lpValue + tp->dwValueLen;
1306 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &red)) {
1307 TRACE("Could not parse color property\n");
1308 return E_PROP_ID_UNSUPPORTED;
1310 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &green)) {
1311 TRACE("Could not parse color property\n");
1312 return E_PROP_ID_UNSUPPORTED;
1314 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &blue)) {
1315 TRACE("Could not parse color property\n");
1316 return E_PROP_ID_UNSUPPORTED;
1318 *pColor = RGB(red,green,blue);
1319 return S_OK;
1322 /***********************************************************************
1323 * MSSTYLES_GetPropertyColor
1325 * Retrieve a color value for a property
1327 static HRESULT MSSTYLES_GetFont (LPCWSTR lpCur, LPCWSTR lpEnd,
1328 LPCWSTR *lpValEnd, LOGFONTW* pFont)
1330 int pointSize;
1331 WCHAR attr[32];
1333 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
1334 TRACE("Property is there, but failed to get face name\n");
1335 *lpValEnd = lpCur;
1336 return E_PROP_ID_UNSUPPORTED;
1338 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pointSize)) {
1339 TRACE("Property is there, but failed to get point size\n");
1340 *lpValEnd = lpCur;
1341 return E_PROP_ID_UNSUPPORTED;
1343 pFont->lfHeight = pointSize;
1344 pFont->lfWeight = FW_REGULAR;
1345 pFont->lfCharSet = DEFAULT_CHARSET;
1346 while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, ARRAY_SIZE(attr))) {
1347 if(!lstrcmpiW(L"bold", attr)) pFont->lfWeight = FW_BOLD;
1348 else if(!lstrcmpiW(L"italic", attr)) pFont->lfItalic = TRUE;
1349 else if(!lstrcmpiW(L"underline", attr)) pFont->lfUnderline = TRUE;
1350 else if(!lstrcmpiW(L"strikeout", attr)) pFont->lfStrikeOut = TRUE;
1352 *lpValEnd = lpCur;
1353 return S_OK;
1356 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
1358 LPCWSTR lpCur = tp->lpValue;
1359 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1360 HRESULT hr;
1362 ZeroMemory(pFont, sizeof(LOGFONTW));
1363 hr = MSSTYLES_GetFont (lpCur, lpEnd, &lpCur, pFont);
1364 if (SUCCEEDED (hr))
1365 pFont->lfHeight = -MulDiv(pFont->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1367 return hr;
1370 /***********************************************************************
1371 * MSSTYLES_GetPropertyInt
1373 * Retrieve an int value for a property
1375 HRESULT MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp, int *piVal)
1377 if(!MSSTYLES_GetNextInteger(tp->lpValue, (tp->lpValue + tp->dwValueLen), NULL, piVal)) {
1378 TRACE("Could not parse int property\n");
1379 return E_PROP_ID_UNSUPPORTED;
1381 return S_OK;
1384 /***********************************************************************
1385 * MSSTYLES_GetPropertyIntList
1387 * Retrieve an int list value for a property
1389 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1391 int i;
1392 LPCWSTR lpCur = tp->lpValue;
1393 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1395 for(i=0; i < MAX_INTLIST_COUNT; i++) {
1396 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pIntList->iValues[i]))
1397 break;
1399 pIntList->iValueCount = i;
1400 return S_OK;
1403 /***********************************************************************
1404 * MSSTYLES_GetPropertyPosition
1406 * Retrieve a position value for a property
1408 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1410 int x,y;
1411 LPCWSTR lpCur = tp->lpValue;
1412 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1414 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &x)) {
1415 TRACE("Could not parse position property\n");
1416 return E_PROP_ID_UNSUPPORTED;
1418 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &y)) {
1419 TRACE("Could not parse position property\n");
1420 return E_PROP_ID_UNSUPPORTED;
1422 pPoint->x = x;
1423 pPoint->y = y;
1424 return S_OK;
1427 /***********************************************************************
1428 * MSSTYLES_GetPropertyString
1430 * Retrieve a string value for a property
1432 HRESULT MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp, LPWSTR pszBuff, int cchMaxBuffChars)
1434 lstrcpynW(pszBuff, tp->lpValue, min(tp->dwValueLen+1, cchMaxBuffChars));
1435 return S_OK;
1438 /***********************************************************************
1439 * MSSTYLES_GetPropertyRect
1441 * Retrieve a rect value for a property
1443 HRESULT MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp, RECT *pRect)
1445 LPCWSTR lpCur = tp->lpValue;
1446 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1448 MSSTYLES_GetNextLong(lpCur, lpEnd, &lpCur, &pRect->left);
1449 MSSTYLES_GetNextLong(lpCur, lpEnd, &lpCur, &pRect->top);
1450 MSSTYLES_GetNextLong(lpCur, lpEnd, &lpCur, &pRect->right);
1451 if(!MSSTYLES_GetNextLong(lpCur, lpEnd, &lpCur, &pRect->bottom)) {
1452 TRACE("Could not parse rect property\n");
1453 return E_PROP_ID_UNSUPPORTED;
1455 return S_OK;
1458 /***********************************************************************
1459 * MSSTYLES_GetPropertyMargins
1461 * Retrieve a margins value for a property
1463 HRESULT MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp, RECT *prc, MARGINS *pMargins)
1465 LPCWSTR lpCur = tp->lpValue;
1466 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1468 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxLeftWidth);
1469 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxRightWidth);
1470 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyTopHeight);
1471 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyBottomHeight)) {
1472 TRACE("Could not parse margins property\n");
1473 return E_PROP_ID_UNSUPPORTED;
1475 return S_OK;