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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define NO_SHLWAPI_REG
35 #include "uxthemedll.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
42 /***********************************************************************
43 * Defines and global variables
46 BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value);
47 BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize);
48 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf);
50 extern HINSTANCE hDllInst;
52 #define MSSTYLES_VERSION 0x0003
54 static const WCHAR szThemesIniResource[] = {
55 't','h','e','m','e','s','_','i','n','i','\0'
58 PTHEME_FILE tfActiveTheme = NULL;
60 /***********************************************************************/
62 /**********************************************************************
63 * MSSTYLES_OpenThemeFile
65 * Load and validate a theme
68 * lpThemeFile Path to theme file to load
69 * pszColorName Color name wanted, can be NULL
70 * pszSizeName Size name wanted, can be NULL
73 * If pszColorName or pszSizeName are NULL, the default color/size will be used.
74 * If one/both are provided, they are validated against valid color/sizes and if
75 * a match is not found, the function fails.
77 HRESULT MSSTYLES_OpenThemeFile(LPCWSTR lpThemeFile, LPCWSTR pszColorName, LPCWSTR pszSizeName, PTHEME_FILE *tf)
82 static const WCHAR szPackThemVersionResource[] = {
83 'P','A','C','K','T','H','E','M','_','V','E','R','S','I','O','N', '\0'
85 static const WCHAR szColorNamesResource[] = {
86 'C','O','L','O','R','N','A','M','E','S','\0'
88 static const WCHAR szSizeNamesResource[] = {
89 'S','I','Z','E','N','A','M','E','S','\0'
95 LPWSTR pszSelectedColor = NULL;
97 LPWSTR pszSelectedSize = NULL;
100 TRACE("Opening %s\n", debugstr_w(lpThemeFile));
102 hTheme = LoadLibraryExW(lpThemeFile, NULL, LOAD_LIBRARY_AS_DATAFILE);
104 /* Validate that this is really a theme */
106 hr = HRESULT_FROM_WIN32(GetLastError());
109 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szPackThemVersionResource))) {
110 TRACE("No version resource found\n");
111 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
114 if((versize = SizeofResource(hTheme, hrsc)) != 2)
116 TRACE("Version resource found, but wrong size: %ld\n", versize);
117 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
120 version = *(WORD*)LoadResource(hTheme, hrsc);
121 if(version != MSSTYLES_VERSION)
123 TRACE("Version of theme file is unsupported: 0x%04x\n", version);
124 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
128 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szColorNamesResource))) {
129 TRACE("Color names resource not found\n");
130 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
133 pszColors = (LPWSTR)LoadResource(hTheme, hrsc);
135 if(!(hrsc = FindResourceW(hTheme, MAKEINTRESOURCEW(1), szSizeNamesResource))) {
136 TRACE("Size names resource not found\n");
137 hr = HRESULT_FROM_WIN32(ERROR_BAD_FORMAT);
140 pszSizes = (LPWSTR)LoadResource(hTheme, hrsc);
142 /* Validate requested color against whats available from the theme */
146 if(!lstrcmpiW(pszColorName, tmp)) {
147 pszSelectedColor = tmp;
150 tmp += lstrlenW(tmp)+1;
154 pszSelectedColor = pszColors; /* Use the default color */
156 /* Validate requested size against whats available from the theme */
160 if(!lstrcmpiW(pszSizeName, tmp)) {
161 pszSelectedSize = tmp;
164 tmp += lstrlenW(tmp)+1;
168 pszSelectedSize = pszSizes; /* Use the default size */
170 if(!pszSelectedColor || !pszSelectedSize) {
171 TRACE("Requested color/size (%s/%s) not found in theme\n",
172 debugstr_w(pszColorName), debugstr_w(pszSizeName));
173 hr = E_PROP_ID_UNSUPPORTED;
177 *tf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(THEME_FILE));
178 (*tf)->hTheme = hTheme;
180 GetFullPathNameW(lpThemeFile, MAX_PATH, (*tf)->szThemeFile, NULL);
182 (*tf)->pszAvailColors = pszColors;
183 (*tf)->pszAvailSizes = pszSizes;
184 (*tf)->pszSelectedColor = pszSelectedColor;
185 (*tf)->pszSelectedSize = pszSelectedSize;
186 (*tf)->dwRefCount = 1;
190 if(hTheme) FreeLibrary(hTheme);
194 /***********************************************************************
195 * MSSTYLES_CloseThemeFile
197 * Close theme file and free resources
199 void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
203 if(!tf->dwRefCount) {
204 if(tf->hTheme) FreeLibrary(tf->hTheme);
207 PTHEME_CLASS pcls = tf->classes;
208 tf->classes = pcls->next;
209 while(pcls->partstate) {
210 PTHEME_PARTSTATE ps = pcls->partstate;
211 pcls->partstate = ps->next;
212 HeapFree(GetProcessHeap(), 0, ps);
214 HeapFree(GetProcessHeap(), 0, pcls);
217 HeapFree(GetProcessHeap(), 0, tf);
222 /***********************************************************************
223 * MSSTYLES_SetActiveTheme
225 * Set the current active theme
227 HRESULT MSSTYLES_SetActiveTheme(PTHEME_FILE tf)
230 MSSTYLES_CloseThemeFile(tfActiveTheme);
234 tfActiveTheme->dwRefCount++;
235 if(!tfActiveTheme->classes)
236 MSSTYLES_ParseThemeIni(tfActiveTheme);
241 /***********************************************************************
242 * MSSTYLES_GetThemeIni
244 * Retrieves themes.ini from a theme
246 PUXINI_FILE MSSTYLES_GetThemeIni(PTHEME_FILE tf)
248 return UXINI_LoadINI(tf->hTheme, szThemesIniResource);
251 /***********************************************************************
252 * MSSTYLES_GetActiveThemeIni
254 * Retrieve the ini file for the selected color/style
256 static PUXINI_FILE MSSTYLES_GetActiveThemeIni(PTHEME_FILE tf)
258 static const WCHAR szFileResNamesResource[] = {
259 'F','I','L','E','R','E','S','N','A','M','E','S','\0'
261 DWORD dwColorCount = 0;
262 DWORD dwSizeCount = 0;
263 DWORD dwColorNum = 0;
266 DWORD dwResourceIndex;
270 /* Count the number of available colors & styles, and determine the index number
271 of the color/style we are interested in
273 tmp = tf->pszAvailColors;
275 if(!lstrcmpiW(tf->pszSelectedColor, tmp))
276 dwColorNum = dwColorCount;
277 tmp += lstrlenW(tmp)+1;
280 tmp = tf->pszAvailSizes;
282 if(!lstrcmpiW(tf->pszSelectedSize, tmp))
283 dwSizeNum = dwSizeCount;
284 tmp += lstrlenW(tmp)+1;
288 if(!(hrsc = FindResourceW(tf->hTheme, MAKEINTRESOURCEW(1), szFileResNamesResource))) {
289 TRACE("FILERESNAMES map not found\n");
292 tmp = (LPWSTR)LoadResource(tf->hTheme, hrsc);
293 dwResourceIndex = (dwSizeCount * dwColorNum) + dwSizeNum;
294 for(i=0; i < dwResourceIndex; i++) {
295 tmp += lstrlenW(tmp)+1;
297 return UXINI_LoadINI(tf->hTheme, tmp);
301 /***********************************************************************
302 * MSSTYLES_ParseIniSectionName
304 * Parse an ini section name into its component parts
309 * [classname.part(state)]
310 * [application::classname]
311 * [application::classname(state)]
312 * [application::classname.part]
313 * [application::classname.part(state)]
316 * lpSection Section name
317 * dwLen Length of section name
318 * szAppName Location to store application name
319 * szClassName Location to store class name
320 * iPartId Location to store part id
321 * iStateId Location to store state id
323 static BOOL MSSTYLES_ParseIniSectionName(LPCWSTR lpSection, DWORD dwLen, LPWSTR szAppName, LPWSTR szClassName, int *iPartId, int *iStateId)
326 WCHAR part[60] = {'\0'};
327 WCHAR state[60] = {'\0'};
330 lstrcpynW(sec, lpSection, min(dwLen+1, sizeof(sec)/sizeof(sec[0])));
337 /* Get the application name */
338 tmp = StrChrW(comp, ':');
342 lstrcpynW(szAppName, comp, MAX_THEME_APP_NAME);
346 tmp = StrChrW(comp, '.');
349 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
351 /* now get the part & state */
352 tmp = StrChrW(comp, '(');
355 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
357 /* now get the state */
358 *StrChrW(comp, ')') = 0;
359 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
362 lstrcpynW(part, comp, sizeof(part)/sizeof(part[0]));
366 tmp = StrChrW(comp, '(');
369 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
371 /* now get the state */
372 *StrChrW(comp, ')') = 0;
373 lstrcpynW(state, comp, sizeof(state)/sizeof(state[0]));
376 lstrcpynW(szClassName, comp, MAX_THEME_CLASS_NAME);
379 if(!*szClassName) return FALSE;
380 return MSSTYLES_LookupPartState(szClassName, part[0]?part:NULL, state[0]?state:NULL, iPartId, iStateId);
383 /***********************************************************************
390 * pszAppName App name to find
391 * pszClassName Class name to find
394 * The class found, or NULL
396 PTHEME_CLASS MSSTYLES_FindClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
398 PTHEME_CLASS cur = tf->classes;
401 if(!*cur->szAppName && !lstrcmpiW(pszClassName, cur->szClassName))
405 if(!lstrcmpiW(pszAppName, cur->szAppName) && !lstrcmpiW(pszClassName, cur->szClassName))
413 /***********************************************************************
416 * Add a class to a theme file
420 * pszAppName App name to add
421 * pszClassName Class name to add
424 * The class added, or a class previously added with the same name
426 static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWSTR pszClassName)
428 PTHEME_CLASS cur = MSSTYLES_FindClass(tf, pszAppName, pszClassName);
431 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_CLASS));
432 cur->hTheme = tf->hTheme;
433 lstrcpyW(cur->szAppName, pszAppName);
434 lstrcpyW(cur->szClassName, pszClassName);
435 cur->next = tf->classes;
436 cur->partstate = NULL;
437 cur->overrides = NULL;
442 /***********************************************************************
443 * MSSTYLES_FindPartState
449 * iPartId Part ID to find
450 * iStateId State ID to find
451 * tcNext Receives the next class in the override chain
454 * The part/state found, or NULL
456 PTHEME_PARTSTATE MSSTYLES_FindPartState(PTHEME_CLASS tc, int iPartId, int iStateId, PTHEME_CLASS *tcNext)
458 PTHEME_PARTSTATE cur = tc->partstate;
460 if(cur->iPartId == iPartId && cur->iStateId == iStateId) {
461 if(tcNext) *tcNext = tc->overrides;
466 if(tc->overrides) return MSSTYLES_FindPartState(tc->overrides, iPartId, iStateId, tcNext);
470 /***********************************************************************
471 * MSSTYLES_AddPartState
473 * Add a part/state to a class
477 * iPartId Part ID to add
478 * iStateId State ID to add
481 * The part/state added, or a part/state previously added with the same IDs
483 static PTHEME_PARTSTATE MSSTYLES_AddPartState(PTHEME_CLASS tc, int iPartId, int iStateId)
485 PTHEME_PARTSTATE cur = MSSTYLES_FindPartState(tc, iPartId, iStateId, NULL);
488 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PARTSTATE));
489 cur->iPartId = iPartId;
490 cur->iStateId = iStateId;
491 cur->properties = NULL;
492 cur->next = tc->partstate;
497 /***********************************************************************
498 * MSSTYLES_LFindProperty
500 * Find a property within a property list
503 * tp property list to scan
504 * iPropertyPrimitive Type of value expected
505 * iPropertyId ID of the required value
508 * The property found, or NULL
510 static PTHEME_PROPERTY MSSTYLES_LFindProperty(PTHEME_PROPERTY tp, int iPropertyPrimitive, int iPropertyId)
512 PTHEME_PROPERTY cur = tp;
514 if(cur->iPropertyId == iPropertyId) {
515 if(cur->iPrimitiveType == iPropertyPrimitive) {
519 if(!iPropertyPrimitive)
529 /***********************************************************************
530 * MSSTYLES_PSFindProperty
532 * Find a value within a part/state
535 * ps Part/state to search
536 * iPropertyPrimitive Type of value expected
537 * iPropertyId ID of the required value
540 * The property found, or NULL
542 static inline PTHEME_PROPERTY MSSTYLES_PSFindProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId)
544 return MSSTYLES_LFindProperty(ps->properties, iPropertyPrimitive, iPropertyId);
547 /***********************************************************************
548 * MSSTYLES_FFindMetric
550 * Find a metric property for a theme file
554 * iPropertyPrimitive Type of value expected
555 * iPropertyId ID of the required value
558 * The property found, or NULL
560 static inline PTHEME_PROPERTY MSSTYLES_FFindMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId)
562 return MSSTYLES_LFindProperty(tf->metrics, iPropertyPrimitive, iPropertyId);
565 /***********************************************************************
566 * MSSTYLES_FindMetric
568 * Find a metric property for the current installed theme
572 * iPropertyPrimitive Type of value expected
573 * iPropertyId ID of the required value
576 * The property found, or NULL
578 PTHEME_PROPERTY MSSTYLES_FindMetric(int iPropertyPrimitive, int iPropertyId)
580 if(!tfActiveTheme) return NULL;
581 return MSSTYLES_FFindMetric(tfActiveTheme, iPropertyPrimitive, iPropertyId);
584 /***********************************************************************
585 * MSSTYLES_AddProperty
587 * Add a property to a part/state
591 * iPropertyPrimitive Primitive type of the property
592 * iPropertyId ID of the property
593 * lpValue Raw value (non-NULL terminated)
594 * dwValueLen Length of the value
597 * The property added, or a property previously added with the same IDs
599 static PTHEME_PROPERTY MSSTYLES_AddProperty(PTHEME_PARTSTATE ps, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen, BOOL isGlobal)
601 PTHEME_PROPERTY cur = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId);
602 /* Should duplicate properties overwrite the original, or be ignored? */
605 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
606 cur->iPrimitiveType = iPropertyPrimitive;
607 cur->iPropertyId = iPropertyId;
608 cur->lpValue = lpValue;
609 cur->dwValueLen = dwValueLen;
612 cur->origin = PO_STATE;
614 cur->origin = PO_PART;
616 cur->origin = PO_GLOBAL;
618 cur->origin = PO_CLASS;
620 cur->next = ps->properties;
621 ps->properties = cur;
625 /***********************************************************************
628 * Add a property to a part/state
632 * iPropertyPrimitive Primitive type of the property
633 * iPropertyId ID of the property
634 * lpValue Raw value (non-NULL terminated)
635 * dwValueLen Length of the value
638 * The property added, or a property previously added with the same IDs
640 static PTHEME_PROPERTY MSSTYLES_AddMetric(PTHEME_FILE tf, int iPropertyPrimitive, int iPropertyId, LPCWSTR lpValue, DWORD dwValueLen)
642 PTHEME_PROPERTY cur = MSSTYLES_FFindMetric(tf, iPropertyPrimitive, iPropertyId);
643 /* Should duplicate properties overwrite the original, or be ignored? */
646 cur = HeapAlloc(GetProcessHeap(), 0, sizeof(THEME_PROPERTY));
647 cur->iPrimitiveType = iPropertyPrimitive;
648 cur->iPropertyId = iPropertyId;
649 cur->lpValue = lpValue;
650 cur->dwValueLen = dwValueLen;
652 cur->origin = PO_GLOBAL;
654 cur->next = tf->metrics;
659 /***********************************************************************
660 * MSSTYLES_ParseThemeIni
662 * Parse the theme ini for the selected color/style
667 void MSSTYLES_ParseThemeIni(PTHEME_FILE tf)
669 static const WCHAR szSysMetrics[] = {'S','y','s','M','e','t','r','i','c','s','\0'};
670 static const WCHAR szGlobals[] = {'g','l','o','b','a','l','s','\0'};
672 PTHEME_CLASS globals;
675 WCHAR szAppName[MAX_THEME_APP_NAME];
676 WCHAR szClassName[MAX_THEME_CLASS_NAME];
677 WCHAR szPropertyName[MAX_THEME_VALUE_NAME];
680 int iPropertyPrimitive;
687 ini = MSSTYLES_GetActiveThemeIni(tf);
689 while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
690 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, szSysMetrics, -1) == CSTR_EQUAL) {
692 int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
693 COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
696 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
697 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
698 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
699 if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
701 lpValueEnd = lpValue + dwValueLen;
702 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r);
703 MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g);
704 if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
705 colorElements[colorCount] = iPropertyId - TMT_FIRSTCOLOR;
706 colorRgb[colorCount++] = RGB(r,g,b);
709 FIXME("Invalid color value for %s\n", debugstr_w(szPropertyName));
712 else if (iPropertyId == TMT_FLATMENUS) {
713 BOOL flatMenus = (*lpValue == 'T') || (*lpValue == 't');
714 SystemParametersInfoW (SPI_SETFLATMENU, 0, (PVOID)flatMenus, 0);
716 /* Catch all metrics, including colors */
717 MSSTYLES_AddMetric(tf, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen);
720 TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
724 SetSysColors(colorCount, colorElements, colorRgb);
727 if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {
728 BOOL isGlobal = FALSE;
729 if(!lstrcmpiW(szClassName, szGlobals)) {
732 cls = MSSTYLES_AddClass(tf, szAppName, szClassName);
733 ps = MSSTYLES_AddPartState(cls, iPartId, iStateId);
735 while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
736 lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
737 if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
738 MSSTYLES_AddProperty(ps, iPropertyPrimitive, iPropertyId, lpValue, dwValueLen, isGlobal);
741 TRACE("Unknown property %s\n", debugstr_w(szPropertyName));
747 /* App/Class combos override values defined by the base class, map these overrides */
748 globals = MSSTYLES_FindClass(tf, NULL, szGlobals);
751 if(*cls->szAppName) {
752 cls->overrides = MSSTYLES_FindClass(tf, NULL, cls->szClassName);
753 if(!cls->overrides) {
754 TRACE("No overrides found for app %s class %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName));
757 cls->overrides = globals;
761 /* Everything overrides globals..except globals */
762 if(cls != globals) cls->overrides = globals;
769 ERR("Failed to parse theme ini\n");
773 /***********************************************************************
774 * MSSTYLES_OpenThemeClass
776 * Open a theme class, uses the current active theme
779 * pszAppName Application name, for theme styles specific
780 * to a particular application
781 * pszClassList List of requested classes, semicolon delimited
783 PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList)
785 PTHEME_CLASS cls = NULL;
786 WCHAR szClassName[MAX_THEME_CLASS_NAME];
792 TRACE("there is no active theme\n");
795 if(!tfActiveTheme->classes) {
799 start = pszClassList;
800 while((end = StrChrW(start, ';'))) {
802 lstrcpynW(szClassName, start, min(len+1, sizeof(szClassName)/sizeof(szClassName[0])));
804 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
808 lstrcpynW(szClassName, start, sizeof(szClassName)/sizeof(szClassName[0]));
809 cls = MSSTYLES_FindClass(tfActiveTheme, pszAppName, szClassName);
812 TRACE("Opened app %s, class %s from list %s\n", debugstr_w(cls->szAppName), debugstr_w(cls->szClassName), debugstr_w(pszClassList));
813 cls->tf = tfActiveTheme;
814 cls->tf->dwRefCount++;
819 /***********************************************************************
820 * MSSTYLES_CloseThemeClass
822 * Close a theme class
825 * tc Theme class to close
828 * The MSSTYLES_CloseThemeFile decreases the refcount of the owning
829 * theme file and cleans it up, if needed.
831 HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc)
833 MSSTYLES_CloseThemeFile (tc->tf);
837 /***********************************************************************
838 * MSSTYLES_FindProperty
840 * Locate a property in a class. Part and state IDs will be used as a
841 * preference, but may be ignored in the attempt to locate the property.
842 * Will scan the entire chain of overrides for this class.
844 PTHEME_PROPERTY MSSTYLES_FindProperty(PTHEME_CLASS tc, int iPartId, int iStateId, int iPropertyPrimitive, int iPropertyId)
846 PTHEME_CLASS next = tc;
850 TRACE("(%p, %d, %d, %d)\n", tc, iPartId, iStateId, iPropertyId);
851 /* Try and find an exact match on part & state */
852 while(next && (ps = MSSTYLES_FindPartState(next, iPartId, iStateId, &next))) {
853 if((tp = MSSTYLES_PSFindProperty(ps, iPropertyPrimitive, iPropertyId))) {
857 /* If that fails, and we didn't already try it, search for just part */
860 /* As a last ditch attempt..go for just class */
861 else if(iPartId != 0)
866 if((tp = MSSTYLES_FindProperty(tc, iPartId, iStateId, iPropertyPrimitive, iPropertyId)))
871 HBITMAP MSSTYLES_LoadBitmap(HDC hdc, PTHEME_CLASS tc, LPCWSTR lpFilename)
873 WCHAR szFile[MAX_PATH];
875 lstrcpynW(szFile, lpFilename, sizeof(szFile)/sizeof(szFile[0]));
878 if(*tmp == '\\') *tmp = '_';
879 if(*tmp == '/') *tmp = '_';
880 if(*tmp == '.') *tmp = '_';
882 return LoadImageW(tc->hTheme, szFile, IMAGE_BITMAP, 0, 0, LR_SHARED|LR_CREATEDIBSECTION);
885 BOOL MSSTYLES_GetNextInteger(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, int *value)
887 LPCWSTR cur = lpStringStart;
891 while(cur < lpStringEnd && (*cur < '0' || *cur > '9' || *cur == '-')) cur++;
892 if(cur >= lpStringEnd) {
899 while(cur < lpStringEnd && (*cur >= '0' && *cur <= '9')) {
900 total = total * 10 + (*cur - '0');
903 if(gotNeg) total = -total;
905 if(lpValEnd) *lpValEnd = cur;
909 BOOL MSSTYLES_GetNextToken(LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPCWSTR *lpValEnd, LPWSTR lpBuff, DWORD buffSize) {
910 LPCWSTR cur = lpStringStart;
914 while(cur < lpStringEnd && (isspace(*cur) || *cur == ',')) cur++;
915 if(cur >= lpStringEnd) {
919 while(cur < lpStringEnd && *cur != ',') cur++;
921 while(isspace(*end)) end--;
923 lstrcpynW(lpBuff, start, min(buffSize, end-start+1));
925 if(lpValEnd) *lpValEnd = cur;
929 /***********************************************************************
930 * MSSTYLES_GetPropertyBool
932 * Retrieve a color value for a property
934 HRESULT MSSTYLES_GetPropertyBool(PTHEME_PROPERTY tp, BOOL *pfVal)
937 if(*tp->lpValue == 't' || *tp->lpValue == 'T')
942 /***********************************************************************
943 * MSSTYLES_GetPropertyColor
945 * Retrieve a color value for a property
947 HRESULT MSSTYLES_GetPropertyColor(PTHEME_PROPERTY tp, COLORREF *pColor)
951 int red, green, blue;
954 lpEnd = tp->lpValue + tp->dwValueLen;
956 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &red);
957 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &green);
958 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &blue)) {
959 TRACE("Could not parse color property\n");
960 return E_PROP_ID_UNSUPPORTED;
962 *pColor = RGB(red,green,blue);
966 /***********************************************************************
967 * MSSTYLES_GetPropertyColor
969 * Retrieve a color value for a property
971 HRESULT MSSTYLES_GetPropertyFont(PTHEME_PROPERTY tp, HDC hdc, LOGFONTW *pFont)
973 static const WCHAR szBold[] = {'b','o','l','d','\0'};
974 static const WCHAR szItalic[] = {'i','t','a','l','i','c','\0'};
975 static const WCHAR szUnderline[] = {'u','n','d','e','r','l','i','n','e','\0'};
976 static const WCHAR szStrikeOut[] = {'s','t','r','i','k','e','o','u','t','\0'};
979 LPCWSTR lpCur = tp->lpValue;
980 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
982 ZeroMemory(pFont, sizeof(LOGFONTW));
984 if(!MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, pFont->lfFaceName, LF_FACESIZE)) {
985 TRACE("Property is there, but failed to get face name\n");
986 return E_PROP_ID_UNSUPPORTED;
988 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pointSize)) {
989 TRACE("Property is there, but failed to get point size\n");
990 return E_PROP_ID_UNSUPPORTED;
992 pFont->lfHeight = -MulDiv(pointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
993 pFont->lfWeight = FW_REGULAR;
994 pFont->lfCharSet = DEFAULT_CHARSET;
995 while(MSSTYLES_GetNextToken(lpCur, lpEnd, &lpCur, attr, sizeof(attr)/sizeof(attr[0]))) {
996 if(!lstrcmpiW(szBold, attr)) pFont->lfWeight = FW_BOLD;
997 else if(!!lstrcmpiW(szItalic, attr)) pFont->lfItalic = TRUE;
998 else if(!!lstrcmpiW(szUnderline, attr)) pFont->lfUnderline = TRUE;
999 else if(!!lstrcmpiW(szStrikeOut, attr)) pFont->lfStrikeOut = TRUE;
1004 /***********************************************************************
1005 * MSSTYLES_GetPropertyInt
1007 * Retrieve an int value for a property
1009 HRESULT MSSTYLES_GetPropertyInt(PTHEME_PROPERTY tp, int *piVal)
1011 if(!MSSTYLES_GetNextInteger(tp->lpValue, (tp->lpValue + tp->dwValueLen), NULL, piVal)) {
1012 TRACE("Could not parse int property\n");
1013 return E_PROP_ID_UNSUPPORTED;
1018 /***********************************************************************
1019 * MSSTYLES_GetPropertyIntList
1021 * Retrieve an int list value for a property
1023 HRESULT MSSTYLES_GetPropertyIntList(PTHEME_PROPERTY tp, INTLIST *pIntList)
1026 LPCWSTR lpCur = tp->lpValue;
1027 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1029 for(i=0; i < MAX_INTLIST_COUNT; i++) {
1030 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pIntList->iValues[i]))
1033 pIntList->iValueCount = i;
1037 /***********************************************************************
1038 * MSSTYLES_GetPropertyPosition
1040 * Retrieve a position value for a property
1042 HRESULT MSSTYLES_GetPropertyPosition(PTHEME_PROPERTY tp, POINT *pPoint)
1045 LPCWSTR lpCur = tp->lpValue;
1046 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1048 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &x);
1049 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &y)) {
1050 TRACE("Could not parse position property\n");
1051 return E_PROP_ID_UNSUPPORTED;
1058 /***********************************************************************
1059 * MSSTYLES_GetPropertyString
1061 * Retrieve a string value for a property
1063 HRESULT MSSTYLES_GetPropertyString(PTHEME_PROPERTY tp, LPWSTR pszBuff, int cchMaxBuffChars)
1065 lstrcpynW(pszBuff, tp->lpValue, min(tp->dwValueLen+1, cchMaxBuffChars));
1069 /***********************************************************************
1070 * MSSTYLES_GetPropertyRect
1072 * Retrieve a rect value for a property
1074 HRESULT MSSTYLES_GetPropertyRect(PTHEME_PROPERTY tp, RECT *pRect)
1076 LPCWSTR lpCur = tp->lpValue;
1077 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1079 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->left);
1080 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->top);
1081 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->right);
1082 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, (int*)&pRect->bottom)) {
1083 TRACE("Could not parse rect property\n");
1084 return E_PROP_ID_UNSUPPORTED;
1089 /***********************************************************************
1090 * MSSTYLES_GetPropertyMargins
1092 * Retrieve a margins value for a property
1094 HRESULT MSSTYLES_GetPropertyMargins(PTHEME_PROPERTY tp, RECT *prc, MARGINS *pMargins)
1096 LPCWSTR lpCur = tp->lpValue;
1097 LPCWSTR lpEnd = tp->lpValue + tp->dwValueLen;
1099 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxLeftWidth);
1100 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cxRightWidth);
1101 MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyTopHeight);
1102 if(!MSSTYLES_GetNextInteger(lpCur, lpEnd, &lpCur, &pMargins->cyBottomHeight)) {
1103 TRACE("Could not parse margins property\n");
1104 return E_PROP_ID_UNSUPPORTED;