825645d2f4b1720f8e08b63c8d0bf95bc9c8b7e7
[reactos.git] / reactos / dll / win32 / uxtheme / msstyles.c
1 /*
2 * Win32 5.1 msstyles theme format
3 *
4 * Copyright (C) 2003 Kevin Koltzau
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <stdlib.h>
25
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"
34
35 #include "msstyles.h"
36
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
41
42 /***********************************************************************
43 * Defines and global variables
44 */
45
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);
50
51 extern HINSTANCE hDllInst;
52 extern int alphaBlendMode;
53
54 #define MSSTYLES_VERSION 0x0003
55
56 static const WCHAR szThemesIniResource[] = {
57 't','h','e','m','e','s','_','i','n','i','\0'
58 };
59
60 static PTHEME_FILE tfActiveTheme;
61
62 /***********************************************************************/
63
64 /**********************************************************************
65 * MSSTYLES_OpenThemeFile
66 *
67 * Load and validate a theme
68 *
69 * PARAMS
70 * lpThemeFile Path to theme file to load
71 * pszColorName Color name wanted, can be NULL
72 * pszSizeName Size name wanted, can be NULL
73 *
74 * NOTES
75 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
76 * If one/both are provided, they are validated against valid color/sizes and if
77 * a match is not found, the function fails.
78 */
79 HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWSTR pszSizeName, PTHEME_FILE *tf)
80 {
81 HMODULE hTheme;
82 HRSRC hrsc;
83 HRESULT hr = S_OK;
84 static const WCHAR szPackThemVersionResource[] = {
85 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
86 };
87 static const WCHAR szColorNamesResource[] = {
88 'C','O','L','O','R','N','A','M','E','S','\0'
89 };
90 static const WCHAR szSizeNamesResource[] = {
91 'S','I','Z','E','N','A','M','E','S','\0'
92 };
93
94 WORD version;
95 DWORD versize;
96 LPWSTR pszColors;
97 LPWSTR pszSelectedColor = NULL;
98 LPWSTR pszSizes;
99 LPWSTR pszSelectedSize = NULL;
100 LPWSTR tmp;
101
102 TRACE("Opening %s\n", debugstr_w(lpThemeFile));
103
104 hTheme = LoadLibraryExW(lpThemeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);
105
106 /* Validate that this is really a theme */
107 if(!hTheme) {
108 hr = HRESULT_FROM_WIN32(GetLastError());
109 goto invalid_theme;
110 }
111 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szPackThemVersionResource))) {
112 TRACE("No version resource found\n");
113 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
114 goto invalid_theme;
115 }
116 if((versize = SizeofResource(hTheme, hrsc)) != 2)
117 {
118 TRACE("Version resource found, but wrong size: %d\n", versize);
119 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
120 goto invalid_theme;
121 }
122 version = *(WORD*)LoadResource(hTheme, hrsc);
123 if(version != MSSTYLES_VERSION)
124 {
125 TRACE("Version of theme file is unsupported: 0x%04x\n", version);
126 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
127 goto invalid_theme;
128 }
129
130 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szColorNamesResource))) {
131 TRACE("Color names resource not found\n");
132 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
133 goto invalid_theme;
134 }
135 pszColors = LoadResource(hTheme, hrsc);
136
137 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szSizeNamesResource))) {
138 TRACE("Size names resource not found\n");
139 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
140 goto invalid_theme;
141 }
142 pszSizes = LoadResource(hTheme, hrsc);
143
144 /* Validate requested color against what's available from the theme */
145 if(pszColorName) {
146 tmp = pszColors;
147 while(*tmp) {
148 if(!lstrcmpiW(pszColorName, tmp)) {
149 pszSelectedColor = tmp;
150 break;
151 }
152 tmp += lstrlenW(tmp)+1;
153 }
154 }
155 else
156 pszSelectedColor = pszColors; /* Use the default color */
157
158 /* Validate requested size against what's available from the theme */
159 if(pszSizeName) {
160 tmp = pszSizes;
161 while(*tmp) {
162 if(!lstrcmpiW(pszSizeName, tmp)) {
163 pszSelectedSize = tmp;
164 break;
165 }
166 tmp += lstrlenW(tmp)+1;
167 }
168 }
169 else
170 pszSelectedSize = pszSizes; /* Use the default size */
171
172 if(!pszSelectedColor || !pszSelectedSize) {
173 TRACE("Requested color/size (%s/%s) not found in theme\n",
174 debugstr_w(pszColorName), debugstr_w(pszSizeName));
175 hr = E_PROP_ID_UNSUPPORTED;
176 goto invalid_theme;
177 }
178
179 *tf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(THEME_FILE));
180 (*tf)->hTheme = hTheme;
181
182 GetFullPathNameW(lpThemeFile, MAX_PATH, (*tf)->szThemeFile, NULL);
183
184 (*tf)->pszAvailColors = pszColors;
185 (*tf)->pszAvailSizes = pszSizes;
186 (*tf)->pszSelectedColor = pszSelectedColor;
187 (*tf)->pszSelectedSize = pszSelectedSize;
188 (*tf)->dwRefCount = 1;
189 return S_OK;
190
191 invalid_theme:
192 if(hTheme) FreeLibrary(hTheme);
193 return hr;
194 }
195
196 /***********************************************************************
197 * MSSTYLES_CloseThemeFile
198 *
199 * Close theme file and free resources
200 */
201 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
202 {
203 if(tf) {
204 tf->dwRefCount--;
205 if(!tf->dwRefCount) {
206 if(tf->hTheme) FreeLibrary(tf->hTheme);
207 if(tf->classes) {
208 while(tf->classes) {
209 PTHEME_CLASS pcls = tf->classes;
210 tf->classes = pcls->next;
211 while(pcls->partstate) {
212 PTHEME_PARTSTATE ps = pcls->partstate;
213 pcls->partstate = ps->next;
214 HeapFree(GetProcessHeap(), 0, ps);
215 }
216 HeapFree(GetProcessHeap(), 0, pcls);
217 }
218 }
219 while (tf->images)
220 {
221 PTHEME_IMAGE img = tf->images;
222 tf->images = img->next;
223 DeleteObject (img->image);
224 HeapFree (GetProcessHeap(), 0, img);
225 }
226 HeapFree(GetProcessHeap(), 0, tf);
227 }
228 }
229 }
230
231 /***********************************************************************
232 * MSSTYLES_SetActiveTheme
233 *
234 * Set the current active theme
235 */
236 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf, BOOL setMetrics)
237 {
238 if(tfActiveTheme)
239 MSSTYLES_CloseThemeFile(tfActiveTheme);
240 tfActiveTheme = tf;
241 if (tfActiveTheme)
242 {
243 tfActiveTheme->dwRefCount++;
244 if(!tfActiveTheme->classes)
245 MSSTYLES_ParseThemeIni(tfActiveTheme, setMetrics);
246 }
247 return S_OK;
248 }
249
250 /***********************************************************************
251 * MSSTYLES_GetThemeIni
252 *
253 * Retrieves themes.ini from a theme
254 */
255 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf)
256 {
257 return UXINI_LoadINI(tf->hTheme, szThemesIniResource);
258 }
259
260 /***********************************************************************
261 * MSSTYLES_GetActiveThemeIni
262 *
263 * Retrieve the ini file for the selected color/style
264 */
265 static PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf)
266 {
267 static const WCHAR szFileResNamesResource[] = {
268 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
269 };
270 DWORD dwColorCount = 0;
271 DWORD dwSizeCount = 0;
272 DWORD dwColorNum = 0;
273 DWORD dwSizeNum = 0;
274 DWORD i;
275 DWORD dwResourceIndex;
276 LPWSTR tmp;
277 HRSRC hrsc;
278
279 /* Count the number of available colors & styles, and determine the index number
280 of the color/style we are interested in
281 */
282 tmp = tf->pszAvailColors;
283 while(*tmp) {
284 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
285 dwColorNum = dwColorCount;
286 tmp += lstrlenW(tmp)+1;
287 dwColorCount++;
288 }
289 tmp = tf->pszAvailSizes;
290 while(*tmp) {
291 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
292 dwSizeNum = dwSizeCount;
293 tmp += lstrlenW(tmp)+1;
294 dwSizeCount++;
295 }
296
297 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
298 TRACE("FILERESNAMES map not found\n");
299 return NULL;
300 }
301 tmp = LoadResource(tf->hTheme, hrsc);
302 dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum;
303 for(i=0; i < dwResourceIndex; i++) {
304 tmp += lstrlenW(tmp)+1;
305 }
306 return UXINI_LoadINI(tf->hTheme, tmp);
307 }
308
309
310 /***********************************************************************
311 * MSSTYLES_ParseIniSectionName
312 *
313 * Parse an ini section name into its component parts
314 * Valid formats are:
315 * [classname]
316 * [classname(state)]
317 * [classname.part]
318 * [classname.part(state)]
319 * [application::classname]
320 * [application::classname(state)]
321 * [application::classname.part]
322 * [application::classname.part(state)]
323 *
324 * PARAMS
325 * lpSection Section name
326 * dwLen Length of section name
327 * szAppName Location to store application name
328 * szClassName Location to store class name
329 * iPartId Location to store part id
330 * iStateId Location to store state id
331 */
332 static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR szAppName, LPWSTR szClassName, int *iPartId, int *iStateId)
333 {
334 WCHAR sec[255];
335 WCHAR part[60] = {'\0'};
336 WCHAR state[60] = {'\0'};
337 LPWSTR tmp;
338 LPWSTR comp;
339 lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
340
341 *szAppName = 0;
342 *szClassName = 0;
343 *iPartId = 0;
344 *iStateId = 0;
345 comp = sec;
346 /* Get the application name */
347 tmp = strchrW(comp, ':');
348 if(tmp) {
349 *tmp++ = 0;
350 tmp++;
351 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
352 comp = tmp;
353 }
354
355 tmp = strchrW(comp, '.');
356 if(tmp) {
357 *tmp++ = 0;
358 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
359 comp = tmp;
360 /* now get the part & state */
361 tmp = strchrW(comp, '(');
362 if(tmp) {
363 *tmp++ = 0;
364 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
365 comp = tmp;
366 /* now get the state */
367 *strchrW(comp, ')') = 0;
368 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
369 }
370 else {
371 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
372 }
373 }
374 else {
375 tmp = strchrW(comp, '(');
376 if(tmp) {
377 *tmp++ = 0;
378 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
379 comp = tmp;
380 /* now get the state */
381 *strchrW(comp, ')') = 0;
382 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
383 }
384 else {
385 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
386 }
387 }
388 if(!*szClassName) return FALSE;
389 return MSSTYLES_LookupPartState(szClassName, part[0]?part:NULL, state[0]?state:NULL, iPartId, iStateId);
390 }
391
392 /***********************************************************************
393 * MSSTYLES_FindClass
394 *
395 * Find a class
396 *
397 * PARAMS
398 * tf Theme file
399 * pszAppName App name to find
400 * pszClassName Class name to find
401 *
402 * RETURNS
403 * The class found, or NULL
404 */
405 static PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
406 {
407 PTHEME_CLASS cur = tf->classes;
408 while(cur) {
409 if(!pszAppName) {
410 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
411 return cur;
412 }
413 else {
414 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
415 return cur;
416 }
417 cur = cur->next;
418 }
419 return NULL;
420 }
421
422 /***********************************************************************
423 * MSSTYLES_AddClass
424 *
425 * Add a class to a theme file
426 *
427 * PARAMS
428 * tf Theme file
429 * pszAppName App name to add
430 * pszClassName Class name to add
431 *
432 * RETURNS
433 * The class added, or a class previously added with the same name
434 */
435 static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
436 {
437 PTHEME_CLASS cur = MSSTYLES_FindClass(tf, pszAppName, pszClassName);
438 if(cur) return cur;
439
440 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS));
441 cur->hTheme = tf->hTheme;
442 lstrcpyW(cur->szAppName, pszAppName);
443 lstrcpyW(cur->szClassName, pszClassName);
444 cur->next = tf->classes;
445 cur->partstate = NULL;
446 cur->overrides = NULL;
447 tf->classes = cur;
448 return cur;
449 }
450
451 /***********************************************************************
452 * MSSTYLES_FindPartState
453 *
454 * Find a part/state
455 *
456 * PARAMS
457 * tc Class to search
458 * iPartId Part ID to find
459 * iStateId State ID to find
460 * tcNext Receives the next class in the override chain
461 *
462 * RETURNS
463 * The part/state found, or NULL
464 */
465 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext)
466 {
467 PTHEME_PARTSTATE cur = tc->partstate;
468 while(cur) {
469 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
470 if(tcNext) *tcNext = tc->overrides;
471 return cur;
472 }
473 cur = cur->next;
474 }
475 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
476 return NULL;
477 }
478
479 /***********************************************************************
480 * MSSTYLES_AddPartState
481 *
482 * Add a part/state to a class
483 *
484 * PARAMS
485 * tc Theme class
486 * iPartId Part ID to add
487 * iStateId State ID to add
488 *
489 * RETURNS
490 * The part/state added, or a part/state previously added with the same IDs
491 */
492 static PTHEME_PARTSTATE MSSTYLES_AddPartState(PTHEME_CLASS tc, int iPartId, int iStateId)
493 {
494 PTHEME_PARTSTATE cur = MSSTYLES_FindPartState(tc, iPartId, iStateId, NULL);
495 if(cur) return cur;
496
497 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE));
498 cur->iPartId = iPartId;
499 cur->iStateId = iStateId;
500 cur->properties = NULL;
501 cur->next = tc->partstate;
502 tc->partstate = cur;
503 return cur;
504 }
505
506 /***********************************************************************
507 * MSSTYLES_LFindProperty
508 *
509 * Find a property within a property list
510 *
511 * PARAMS
512 * tp property list to scan
513 * iPropertyPrimitive Type of value expected
514 * iPropertyId ID of the required value
515 *
516 * RETURNS
517 * The property found, or NULL
518 */
519 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
520 {
521 PTHEME_PROPERTY cur = tp;
522 while(cur) {
523 if(cur->iPropertyId == iPropertyId) {
524 if(cur->iPrimitiveType == iPropertyPrimitive) {
525 return cur;
526 }
527 else {
528 if(!iPropertyPrimitive)
529 return cur;
530 return NULL;
531 }
532 }
533 cur = cur->next;
534 }
535 return NULL;
536 }
537
538 /***********************************************************************
539 * MSSTYLES_PSFindProperty
540 *
541 * Find a value within a part/state
542 *
543 * PARAMS
544 * ps Part/state to search
545 * iPropertyPrimitive Type of value expected
546 * iPropertyId ID of the required value
547 *
548 * RETURNS
549 * The property found, or NULL
550 */
551 static inline PTHEME_PROPERTY MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId)
552 {
553 return MSSTYLES_LFindProperty(ps->properties, iPropertyPrimitive, iPropertyId);
554 }
555
556 /***********************************************************************
557 * MSSTYLES_FFindMetric
558 *
559 * Find a metric property for a theme file
560 *
561 * PARAMS
562 * tf Theme file
563 * iPropertyPrimitive Type of value expected
564 * iPropertyId ID of the required value
565 *
566 * RETURNS
567 * The property found, or NULL
568 */
569 static inline PTHEME_PROPERTY MSSTYLES_FFindMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId)
570 {
571 return MSSTYLES_LFindProperty(tf->metrics, iPropertyPrimitive, iPropertyId);
572 }
573
574 /***********************************************************************
575 * MSSTYLES_FindMetric
576 *
577 * Find a metric property for the current installed theme
578 *
579 * PARAMS
580 * tf Theme file
581 * iPropertyPrimitive Type of value expected
582 * iPropertyId ID of the required value
583 *
584 * RETURNS
585 * The property found, or NULL
586 */
587 PTHEME_PROPERTY MSSTYLES_FindMetric(int iPropertyPrimitive, int iPropertyId)
588 {
589 if(!tfActiveTheme) return NULL;
590 return MSSTYLES_FFindMetric(tfActiveTheme, iPropertyPrimitive, iPropertyId);
591 }
592
593 /***********************************************************************
594 * MSSTYLES_AddProperty
595 *
596 * Add a property to a part/state
597 *
598 * PARAMS
599 * ps Part/state
600 * iPropertyPrimitive Primitive type of the property
601 * iPropertyId ID of the property
602 * lpValue Raw value (non-NULL terminated)
603 * dwValueLen Length of the value
604 *
605 * RETURNS
606 * The property added, or a property previously added with the same IDs
607 */
608 static PTHEME_PROPERTY MSSTYLES_AddProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen, BOOL isGlobal)
609 {
610 PTHEME_PROPERTY cur = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId);
611 /* Should duplicate properties overwrite the original, or be ignored? */
612 if(cur) return cur;
613
614 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
615 cur->iPrimitiveType = iPropertyPrimitive;
616 cur->iPropertyId = iPropertyId;
617 cur->lpValue = lpValue;
618 cur->dwValueLen = dwValueLen;
619
620 if(ps->iStateId)
621 cur->origin = PO_STATE;
622 else if(ps->iPartId)
623 cur->origin = PO_PART;
624 else if(isGlobal)
625 cur->origin = PO_GLOBAL;
626 else
627 cur->origin = PO_CLASS;
628
629 cur->next = ps->properties;
630 ps->properties = cur;
631 return cur;
632 }
633
634 /***********************************************************************
635 * MSSTYLES_AddMetric
636 *
637 * Add a property to a part/state
638 *
639 * PARAMS
640 * tf Theme file
641 * iPropertyPrimitive Primitive type of the property
642 * iPropertyId ID of the property
643 * lpValue Raw value (non-NULL terminated)
644 * dwValueLen Length of the value
645 *
646 * RETURNS
647 * The property added, or a property previously added with the same IDs
648 */
649 static PTHEME_PROPERTY MSSTYLES_AddMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen)
650 {
651 PTHEME_PROPERTY cur = MSSTYLES_FFindMetric(tf, iPropertyPrimitive, iPropertyId);
652 /* Should duplicate properties overwrite the original, or be ignored? */
653 if(cur) return cur;
654
655 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
656 cur->iPrimitiveType = iPropertyPrimitive;
657 cur->iPropertyId = iPropertyId;
658 cur->lpValue = lpValue;
659 cur->dwValueLen = dwValueLen;
660
661 cur->origin = PO_GLOBAL;
662
663 cur->next = tf->metrics;
664 tf->metrics = cur;
665 return cur;
666 }
667
668 /* Color-related state for theme ini parsing */
669 struct PARSECOLORSTATE
670 {
671 int colorCount;
672 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
673 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
674 int captionColors;
675 };
676
677 static inline void parse_init_color (struct PARSECOLORSTATE* state)
678 {
679 memset (state, 0, sizeof (*state));
680 }
681
682 static BOOL parse_handle_color_property (struct PARSECOLORSTATE* state,
683 int iPropertyId, LPCWSTR lpValue,
684 DWORD dwValueLen)
685 {
686 int r,g,b;
687 LPCWSTR lpValueEnd = lpValue + dwValueLen;
688 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r) &&
689 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g) &&
690 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
691 state->colorElements[state->colorCount] = iPropertyId - TMT_FIRSTCOLOR;
692 state->colorRgb[state->colorCount++] = RGB(r,g,b);
693 switch (iPropertyId)
694 {
695 case TMT_ACTIVECAPTION:
696 state->captionColors |= 0x1;
697 break;
698 case TMT_INACTIVECAPTION:
699 state->captionColors |= 0x2;
700 break;
701 case TMT_GRADIENTACTIVECAPTION:
702 state->captionColors |= 0x4;
703 break;
704 case TMT_GRADIENTINACTIVECAPTION:
705 state->captionColors |= 0x8;
706 break;
707 }
708 return TRUE;
709 }
710 else {
711 return FALSE;
712 }
713 }
714
715 static void parse_apply_color (struct PARSECOLORSTATE* state)
716 {
717 if (state->colorCount > 0)
718 SetSysColors(state->colorCount, state->colorElements, state->colorRgb);
719 if (state->captionColors == 0xf)
720 SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
721 }
722
723 /* Non-client-metrics-related state for theme ini parsing */
724 struct PARSENONCLIENTSTATE
725 {
726 NONCLIENTMETRICSW metrics;
727 BOOL metricsDirty;
728 LOGFONTW iconTitleFont;
729 };
730
731 static inline void parse_init_nonclient (struct PARSENONCLIENTSTATE* state)
732 {
733 memset (state, 0, sizeof (*state));
734 state->metrics.cbSize = sizeof (NONCLIENTMETRICSW);
735 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (NONCLIENTMETRICSW),
736 &state->metrics, 0);
737 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (LOGFONTW),
738 &state->iconTitleFont, 0);
739 }
740
741 static BOOL parse_handle_nonclient_font (struct PARSENONCLIENTSTATE* state,
742 int iPropertyId, LPCWSTR lpValue,
743 DWORD dwValueLen)
744 {
745 LOGFONTW font;
746
747 memset (&font, 0, sizeof (font));
748 if (SUCCEEDED (MSSTYLES_GetFont (lpValue, lpValue + dwValueLen, &lpValue,
749 &font)))
750 {
751 switch (iPropertyId)
752 {
753 case TMT_CAPTIONFONT:
754 state->metrics.lfCaptionFont = font;
755 state->metricsDirty = TRUE;
756 break;
757 case TMT_SMALLCAPTIONFONT:
758 state->metrics.lfSmCaptionFont = font;
759 state->metricsDirty = TRUE;
760 break;
761 case TMT_MENUFONT:
762 state->metrics.lfMenuFont = font;
763 state->metricsDirty = TRUE;
764 break;
765 case TMT_STATUSFONT:
766 state->metrics.lfStatusFont = font;
767 state->metricsDirty = TRUE;
768 break;
769 case TMT_MSGBOXFONT:
770 state->metrics.lfMessageFont = font;
771 state->metricsDirty = TRUE;
772 break;
773 case TMT_ICONTITLEFONT:
774 state->iconTitleFont = font;
775 state->metricsDirty = TRUE;
776 break;
777 }
778 return TRUE;
779 }
780 else
781 return FALSE;
782 }
783
784 static BOOL parse_handle_nonclient_size (struct PARSENONCLIENTSTATE* state,
785 int iPropertyId, LPCWSTR lpValue,
786 DWORD dwValueLen)
787 {
788 int size;
789 LPCWSTR lpValueEnd = lpValue + dwValueLen;
790 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &size)) {
791 switch (iPropertyId)
792 {
793 case TMT_SIZINGBORDERWIDTH:
794 state->metrics.iBorderWidth = size;
795 state->metricsDirty = TRUE;
796 break;
797 case TMT_SCROLLBARWIDTH:
798 state->metrics.iScrollWidth = size;
799 state->metricsDirty = TRUE;
800 break;
801 case TMT_SCROLLBARHEIGHT:
802 state->metrics.iScrollHeight = size;
803 state->metricsDirty = TRUE;
804 break;
805 case TMT_CAPTIONBARWIDTH:
806 state->metrics.iCaptionWidth = size;
807 state->metricsDirty = TRUE;
808 break;
809 case TMT_CAPTIONBARHEIGHT:
810 state->metrics.iCaptionHeight = size;
811 state->metricsDirty = TRUE;
812 break;
813 case TMT_SMCAPTIONBARWIDTH:
814 state->metrics.iSmCaptionWidth = size;
815 state->metricsDirty = TRUE;
816 break;
817 case TMT_SMCAPTIONBARHEIGHT:
818 state->metrics.iSmCaptionHeight = size;
819 state->metricsDirty = TRUE;
820 break;
821 case TMT_MENUBARWIDTH:
822 state->metrics.iMenuWidth = size;
823 state->metricsDirty = TRUE;
824 break;
825 case TMT_MENUBARHEIGHT:
826 state->metrics.iMenuHeight = size;
827 state->metricsDirty = TRUE;
828 break;
829 }
830 return TRUE;
831 }
832 else
833 return FALSE;
834 }
835
836 static void parse_apply_nonclient (struct PARSENONCLIENTSTATE* state)
837 {
838 if (state->metricsDirty)
839 {
840 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (state->metrics),
841 &state->metrics, 0);
842 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (state->iconTitleFont),
843 &state->iconTitleFont, 0);
844 }
845 }
846
847 /***********************************************************************
848 * MSSTYLES_ParseThemeIni
849 *
850 * Parse the theme ini for the selected color/style
851 *
852 * PARAMS
853 * tf Theme to parse
854 */
855 static void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
856 {
857 static const WCHAR szSysMetrics[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
858 static const WCHAR szGlobals[] = {'g','l','o','b','a','l','s','\0'};
859 PTHEME_CLASS cls;
860 PTHEME_CLASS globals;
861 PTHEME_PARTSTATE ps;
862 PUXINI_FILE ini;
863 WCHAR szAppName[MAX_THEME_APP_NAME];
864 WCHAR szClassName[MAX_THEME_CLASS_NAME];
865 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
866 int iPartId;
867 int iStateId;
868 int iPropertyPrimitive;
869 int iPropertyId;
870 DWORD dwLen;
871 LPCWSTR lpName;
872 DWORD dwValueLen;
873 LPCWSTR lpValue;
874
875 ini = MSSTYLES_GetActiveThemeIni(tf);
876
877 while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
878 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, szSysMetrics, -1) == CSTR_EQUAL) {
879 struct PARSECOLORSTATE colorState;
880 struct PARSENONCLIENTSTATE nonClientState;
881
882 parse_init_color (&colorState);
883 parse_init_nonclient (&nonClientState);
884
885 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
886 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
887 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
888 if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
889 if (!parse_handle_color_property (&colorState, iPropertyId,
890 lpValue, dwValueLen))
891 FIXME("Invalid color value for %s\n",
892 debugstr_w(szPropertyName));
893 }
894 else if (setMetrics && (iPropertyId == TMT_FLATMENUS)) {
895 BOOL flatMenus = (*lpValue == 'T') || (*lpValue == 't');
896 SystemParametersInfoW (SPI_SETFLATMENU, 0, (PVOID)(INT_PTR)flatMenus, 0);
897 }
898 else if ((iPropertyId >= TMT_FIRSTFONT)
899 && (iPropertyId <= TMT_LASTFONT))
900 {
901 if (!parse_handle_nonclient_font (&nonClientState,
902 iPropertyId, lpValue, dwValueLen))
903 FIXME("Invalid font value for %s\n",
904 debugstr_w(szPropertyName));
905 }
906 else if ((iPropertyId >= TMT_FIRSTSIZE)
907 && (iPropertyId <= TMT_LASTSIZE))
908 {
909 if (!parse_handle_nonclient_size (&nonClientState,
910 iPropertyId, lpValue, dwValueLen))
911 FIXME("Invalid size value for %s\n",
912 debugstr_w(szPropertyName));
913 }
914 /* Catch all metrics, including colors */
915 MSSTYLES_AddMetric(tf, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen);
916 }
917 else {
918 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
919 }
920 }
921 if (setMetrics)
922 {
923 parse_apply_color (&colorState);
924 parse_apply_nonclient (&nonClientState);
925 }
926 continue;
927 }
928 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
929 BOOL isGlobal = FALSE;
930 if(!lstrcmpiW(szClassName, szGlobals)) {
931 isGlobal = TRUE;
932 }
933 cls = MSSTYLES_AddClass(tf, szAppName, szClassName);
934 ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
935
936 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
937 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
938 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
939 MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
940 }
941 else {
942 TRACE("Unknown property %s\n", debugstr_w(szPropertyName));
943 }
944 }
945 }
946 }
947
948 /* App/Class combos override values defined by the base class, map these overrides */
949 globals = MSSTYLES_FindClass(tf, NULL, szGlobals);
950 cls = tf->classes;
951 while(cls) {
952 if(*cls->szAppName) {
953 cls->overrides = MSSTYLES_FindClass(tf, NULL, cls->szClassName);
954 if(!cls->overrides) {
955 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName));
956 }
957 else {
958 cls->overrides = globals;
959 }
960 }
961 else {
962 /* Everything overrides globals..except globals */
963 if(cls != globals) cls->overrides = globals;
964 }
965 cls = cls->next;
966 }
967 UXINI_CloseINI(ini);
968
969 if(!tf->classes) {
970 ERR("Failed to parse theme ini\n");
971 }
972 }
973
974 /***********************************************************************
975 * MSSTYLES_OpenThemeClass
976 *
977 * Open a theme class, uses the current active theme
978 *
979 * PARAMS
980 * pszAppName Application name, for theme styles specific
981 * to a particular application
982 * pszClassList List of requested classes, semicolon delimited
983 */
984 PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
985 {
986 PTHEME_CLASS cls = NULL;
987 WCHAR szClassName[MAX_THEME_CLASS_NAME];
988 LPCWSTR start;
989 LPCWSTR end;
990 DWORD len;
991
992 if(!tfActiveTheme) {
993 TRACE("there is no active theme\n");
994 return NULL;
995 }
996 if(!tfActiveTheme->classes) {
997 return NULL;
998 }
999
1000 start = pszClassList;
1001 while((end = strchrW(start, ';'))) {
1002 len = end-start;
1003 lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
1004 start = end+1;
1005 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1006 if(cls) break;
1007 }
1008 if(!cls && *start) {
1009 lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
1010 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
1011 }
1012 if(cls) {
1013 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList));
1014 cls->tf = tfActiveTheme;
1015 cls->tf->dwRefCount++;
1016 }
1017 return cls;
1018 }
1019
1020 /***********************************************************************
1021 * MSSTYLES_CloseThemeClass
1022 *
1023 * Close a theme class
1024 *
1025 * PARAMS
1026 * tc Theme class to close
1027 *
1028 * NOTES
1029 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
1030 * theme file and cleans it up, if needed.
1031 */
1032 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc)
1033 {
1034 MSSTYLES_CloseThemeFile (tc->tf);
1035 return S_OK;
1036 }
1037
1038 /***********************************************************************
1039 * MSSTYLES_FindProperty
1040 *
1041 * Locate a property in a class. Part and state IDs will be used as a
1042 * preference, but may be ignored in the attempt to locate the property.
1043 * Will scan the entire chain of overrides for this class.
1044 */
1045 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId)
1046 {
1047 PTHEME_CLASS next = tc;
1048 PTHEME_PARTSTATE ps;
1049 PTHEME_PROPERTY tp;
1050
1051 TRACE("(%p, %d, %d, %d)\n", tc, iPartId, iStateId, iPropertyId);
1052 /* Try and find an exact match on part & state */
1053 while(next && (ps = MSSTYLES_FindPartState(next, iPartId, iStateId, &next))) {
1054 if((tp = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId))) {
1055 return tp;
1056 }
1057 }
1058 /* If that fails, and we didn't already try it, search for just part */
1059 if(iStateId != 0)
1060 iStateId = 0;
1061 /* As a last ditch attempt..go for just class */
1062 else if(iPartId != 0)
1063 iPartId = 0;
1064 else
1065 return NULL;
1066
1067 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
1068 return tp;
1069 return NULL;
1070 }
1071
1072 /* Prepare a bitmap to be used for alpha blending */
1073 static BOOL prepare_alpha (HBITMAP bmp, BOOL* hasAlpha)
1074 {
1075 DIBSECTION dib;
1076 int n;
1077 BYTE* p;
1078
1079 *hasAlpha = FALSE;
1080
1081 if (!bmp || GetObjectW( bmp, sizeof(dib), &dib ) != sizeof(dib))
1082 return FALSE;
1083
1084 if(dib.dsBm.bmBitsPixel != 32)
1085 /* nothing to do */
1086 return TRUE;
1087
1088 *hasAlpha = TRUE;
1089 p = dib.dsBm.bmBits;
1090 n = abs(dib.dsBmih.biHeight) * dib.dsBmih.biWidth;
1091 /* AlphaBlend() wants premultiplied alpha, so do that now */
1092 while (n-- > 0)
1093 {
1094 int a = p[3]+1;
1095 p[0] = (p[0] * a) >> 8;
1096 p[1] = (p[1] * a) >> 8;
1097 p[2] = (p[2] * a) >> 8;
1098 p += 4;
1099 }
1100
1101 return TRUE;
1102 }
1103
1104 HBITMAP MSSTYLES_LoadBitmap (PTHEME_CLASS tc, LPCWSTR lpFilename, BOOL* hasAlpha)
1105 {
1106 WCHAR szFile[MAX_PATH];
1107 LPWSTR tmp;
1108 PTHEME_IMAGE img;
1109 lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
1110 tmp = szFile;
1111 do {
1112 if(*tmp == '\\') *tmp = '_';
1113 if(*tmp == '/') *tmp = '_';
1114 if(*tmp == '.') *tmp = '_';
1115 } while(*tmp++);
1116
1117 /* Try to locate in list of loaded images */
1118 img = tc->tf->images;
1119 while (img)
1120 {
1121 if (lstrcmpiW (szFile, img->name) == 0)
1122 {
1123 TRACE ("found %p %s: %p\n", img, debugstr_w (img->name), img->image);
1124 *hasAlpha = img->hasAlpha;
1125 return img->image;
1126 }
1127 img = img->next;
1128 }
1129 /* Not found? Load from resources */
1130 img = HeapAlloc (GetProcessHeap(), 0, sizeof (THEME_IMAGE));
1131 img->image = LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
1132 prepare_alpha (img->image, hasAlpha);
1133 img->hasAlpha = *hasAlpha;
1134 /* ...and stow away for later reuse. */
1135 lstrcpyW (img->name, szFile);
1136 img->next = tc->tf->images;
1137 tc->tf->images = img;
1138 TRACE ("new %p %s: %p\n", img, debugstr_w (img->name), img->image);
1139 return img->image;
1140 }
1141
1142 static BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
1143 {
1144 LPCWSTR cur = lpStringStart;
1145 int total = 0;
1146 BOOL gotNeg = FALSE;
1147
1148 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
1149 if(cur >= lpStringEnd) {
1150 return FALSE;
1151 }
1152 if(*cur == '-') {
1153 cur++;
1154 gotNeg = TRUE;
1155 }
1156 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
1157 total = total * 10 + (*cur - '0');
1158 cur++;
1159 }
1160 if(gotNeg) total = -total;
1161 *value = total;
1162 if(lpValEnd) *lpValEnd = cur;
1163 return TRUE;
1164 }
1165
1166 static BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize) {
1167 LPCWSTR cur = lpStringStart;
1168 LPCWSTR start;
1169 LPCWSTR end;
1170
1171 while(cur < lpStringEnd && (isspace(*cur) || *cur == ',')) cur++;
1172 if(cur >= lpStringEnd) {
1173 return FALSE;
1174 }
1175 start = cur;
1176 while(cur < lpStringEnd && *cur != ',') cur++;
1177 end = cur;
1178 while(isspace(*end)) end--;
1179
1180 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
1181
1182 if(lpValEnd) *lpValEnd = cur;
1183 return TRUE;
1184 }
1185
1186 /***********************************************************************
1187 * MSSTYLES_GetPropertyBool
1188 *
1189 * Retrieve a color value for a property
1190 */
1191 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
1192 {
1193 *pfVal = FALSE;
1194 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
1195 *pfVal = TRUE;
1196 return S_OK;
1197 }
1198
1199 /***********************************************************************
1200 * MSSTYLES_GetPropertyColor
1201 *
1202 * Retrieve a color value for a property
1203 */
1204 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
1205 {
1206 LPCWSTR lpEnd;
1207 LPCWSTR lpCur;
1208 int red, green, blue;
1209
1210 lpCur = tp->lpValue;
1211 lpEnd = tp->lpValue + tp->dwValueLen;
1212
1213 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &red)) {
1214 TRACE("Could not parse color property\n");
1215 return E_PROP_ID_UNSUPPORTED;
1216 }
1217 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &green)) {
1218 TRACE("Could not parse color property\n");
1219 return E_PROP_ID_UNSUPPORTED;
1220 }
1221 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &blue)) {
1222 TRACE("Could not parse color property\n");
1223 return E_PROP_ID_UNSUPPORTED;
1224 }
1225 *pColor = RGB(red,green,blue);
1226 return S_OK;
1227 }
1228
1229 /***********************************************************************
1230 * MSSTYLES_GetPropertyColor
1231 *
1232 * Retrieve a color value for a property
1233 */
1234 static HRESULT MSSTYLES_GetFont (LPCWSTR lpCur, LPCWSTR lpEnd,
1235 LPCWSTR *lpValEnd, LOGFONTW* pFont)
1236 {
1237 static const WCHAR szBold[] = {'b','o','l','d','\0'};
1238 static const WCHAR szItalic[] = {'i','t','a','l','i','c','\0'};
1239 static const WCHAR szUnderline[] = {'u','n','d','e','r','l','i','n','e','\0'};
1240 static const WCHAR szStrikeOut[] = {'s','t','r','i','k','e','o','u','t','\0'};
1241 int pointSize;
1242 WCHAR attr[32];
1243
1244 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
1245 TRACE("Property is there, but failed to get face name\n");
1246 *lpValEnd = lpCur;
1247 return E_PROP_ID_UNSUPPORTED;
1248 }
1249 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pointSize)) {
1250 TRACE("Property is there, but failed to get point size\n");
1251 *lpValEnd = lpCur;
1252 return E_PROP_ID_UNSUPPORTED;
1253 }
1254 pFont->lfHeight = pointSize;
1255 pFont->lfWeight = FW_REGULAR;
1256 pFont->lfCharSet = DEFAULT_CHARSET;
1257 while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, sizeof(attr)/sizeof(attr[0]))) {
1258 if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD;
1259 else if(!!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE;
1260 else if(!!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE;
1261 else if(!!lstrcmpiW(szStrikeOut, attr)) pFont->lfStrikeOut = TRUE;
1262 }
1263 *lpValEnd = lpCur;
1264 return S_OK;
1265 }
1266
1267 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
1268 {
1269 LPCWSTR lpCur = tp->lpValue;
1270 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1271 HRESULT hr;
1272
1273 ZeroMemory(pFont, sizeof(LOGFONTW));
1274 hr = MSSTYLES_GetFont (lpCur, lpEnd, &lpCur, pFont);
1275 if (SUCCEEDED (hr))
1276 pFont->lfHeight = -MulDiv(pFont->lfHeight, GetDeviceCaps(hdc, LOGPIXELSY), 72);
1277
1278 return hr;
1279 }
1280
1281 /***********************************************************************
1282 * MSSTYLES_GetPropertyInt
1283 *
1284 * Retrieve an int value for a property
1285 */
1286 HRESULT MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp, int *piVal)
1287 {
1288 if(!MSSTYLES_GetNextInteger(tp->lpValue, (tp->lpValue + tp->dwValueLen), NULL, piVal)) {
1289 TRACE("Could not parse int property\n");
1290 return E_PROP_ID_UNSUPPORTED;
1291 }
1292 return S_OK;
1293 }
1294
1295 /***********************************************************************
1296 * MSSTYLES_GetPropertyIntList
1297 *
1298 * Retrieve an int list value for a property
1299 */
1300 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1301 {
1302 int i;
1303 LPCWSTR lpCur = tp->lpValue;
1304 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1305
1306 for(i=0; i < MAX_INTLIST_COUNT; i++) {
1307 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pIntList->iValues[i]))
1308 break;
1309 }
1310 pIntList->iValueCount = i;
1311 return S_OK;
1312 }
1313
1314 /***********************************************************************
1315 * MSSTYLES_GetPropertyPosition
1316 *
1317 * Retrieve a position value for a property
1318 */
1319 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1320 {
1321 int x,y;
1322 LPCWSTR lpCur = tp->lpValue;
1323 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1324
1325 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &x)) {
1326 TRACE("Could not parse position property\n");
1327 return E_PROP_ID_UNSUPPORTED;
1328 }
1329 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &y)) {
1330 TRACE("Could not parse position property\n");
1331 return E_PROP_ID_UNSUPPORTED;
1332 }
1333 pPoint->x = x;
1334 pPoint->y = y;
1335 return S_OK;
1336 }
1337
1338 /***********************************************************************
1339 * MSSTYLES_GetPropertyString
1340 *
1341 * Retrieve a string value for a property
1342 */
1343 HRESULT MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp, LPWSTR pszBuff, int cchMaxBuffChars)
1344 {
1345 lstrcpynW(pszBuff, tp->lpValue, min(tp->dwValueLen+1, cchMaxBuffChars));
1346 return S_OK;
1347 }
1348
1349 /***********************************************************************
1350 * MSSTYLES_GetPropertyRect
1351 *
1352 * Retrieve a rect value for a property
1353 */
1354 HRESULT MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp, RECT *pRect)
1355 {
1356 LPCWSTR lpCur = tp->lpValue;
1357 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1358
1359 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->left);
1360 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->top);
1361 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->right);
1362 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pRect->bottom)) {
1363 TRACE("Could not parse rect property\n");
1364 return E_PROP_ID_UNSUPPORTED;
1365 }
1366 return S_OK;
1367 }
1368
1369 /***********************************************************************
1370 * MSSTYLES_GetPropertyMargins
1371 *
1372 * Retrieve a margins value for a property
1373 */
1374 HRESULT MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp, RECT *prc, MARGINS *pMargins)
1375 {
1376 LPCWSTR lpCur = tp->lpValue;
1377 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1378
1379 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxLeftWidth);
1380 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxRightWidth);
1381 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyTopHeight);
1382 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyBottomHeight)) {
1383 TRACE("Could not parse margins property\n");
1384 return E_PROP_ID_UNSUPPORTED;
1385 }
1386 return S_OK;
1387 }