uxtheme: Split color handling out of MSSTYLES_ParseThemeIni into smaller helper functions.

This commit is contained in:
Frank Richter 2006-08-14 17:35:13 +02:00 committed by Alexandre Julliard
parent f34412b957
commit 3e4bdad4a3
1 changed files with 63 additions and 35 deletions

View File

@ -664,6 +664,61 @@ static PTHEME_PROPERTY MSSTYLES_AddMetric(PTHEME_FILE tf, int iPropertyPrimitive
return cur;
}
/* Color-related state for theme ini parsing */
struct PARSECOLORSTATE
{
int colorCount;
int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
int captionColors;
};
inline void parse_init_color (struct PARSECOLORSTATE* state)
{
memset (state, 0, sizeof (*state));
}
static BOOL parse_handle_color_property (struct PARSECOLORSTATE* state,
int iPropertyId, LPCWSTR lpValue,
DWORD dwValueLen)
{
int r,g,b;
LPCWSTR lpValueEnd = lpValue + dwValueLen;
MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r);
MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g);
if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
state->colorElements[state->colorCount] = iPropertyId - TMT_FIRSTCOLOR;
state->colorRgb[state->colorCount++] = RGB(r,g,b);
switch (iPropertyId)
{
case TMT_ACTIVECAPTION:
state->captionColors |= 0x1;
break;
case TMT_INACTIVECAPTION:
state->captionColors |= 0x2;
break;
case TMT_GRADIENTACTIVECAPTION:
state->captionColors |= 0x4;
break;
case TMT_GRADIENTINACTIVECAPTION:
state->captionColors |= 0x8;
break;
}
return TRUE;
}
else {
return FALSE;
}
}
static void parse_apply_color (struct PARSECOLORSTATE* state)
{
if (state->colorCount > 0)
SetSysColors(state->colorCount, state->colorElements, state->colorRgb);
if (state->captionColors == 0xf)
SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
}
/***********************************************************************
* MSSTYLES_ParseThemeIni
*
@ -696,42 +751,18 @@ void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
while((lpName=UXINI_GetNextSection(ini, &dwLen))) {
if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, lpName, dwLen, szSysMetrics, -1) == CSTR_EQUAL) {
int colorCount = 0;
int colorElements[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
COLORREF colorRgb[TMT_LASTCOLOR-TMT_FIRSTCOLOR];
LPCWSTR lpValueEnd;
int captionColors = 0;
struct PARSECOLORSTATE colorState;
parse_init_color (&colorState);
while((lpName=UXINI_GetNextValue(ini, &dwLen, &lpValue, &dwValueLen))) {
lstrcpynW(szPropertyName, lpName, min(dwLen+1, sizeof(szPropertyName)/sizeof(szPropertyName[0])));
if(MSSTYLES_LookupProperty(szPropertyName, &iPropertyPrimitive, &iPropertyId)) {
if(iPropertyId >= TMT_FIRSTCOLOR && iPropertyId <= TMT_LASTCOLOR) {
int r,g,b;
lpValueEnd = lpValue + dwValueLen;
MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &r);
MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &g);
if(MSSTYLES_GetNextInteger(lpValue, lpValueEnd, &lpValue, &b)) {
colorElements[colorCount] = iPropertyId - TMT_FIRSTCOLOR;
colorRgb[colorCount++] = RGB(r,g,b);
switch (iPropertyId)
{
case TMT_ACTIVECAPTION:
captionColors |= 0x1;
break;
case TMT_INACTIVECAPTION:
captionColors |= 0x2;
break;
case TMT_GRADIENTACTIVECAPTION:
captionColors |= 0x4;
break;
case TMT_GRADIENTINACTIVECAPTION:
captionColors |= 0x8;
break;
}
}
else {
FIXME("Invalid color value for %s\n", debugstr_w(szPropertyName));
}
if (!parse_handle_color_property (&colorState, iPropertyId,
lpValue, dwValueLen))
FIXME("Invalid color value for %s\n",
debugstr_w(szPropertyName));
}
else if (setMetrics && (iPropertyId == TMT_FLATMENUS)) {
BOOL flatMenus = (*lpValue == 'T') || (*lpValue == 't');
@ -744,10 +775,7 @@ void MSSTYLES_ParseThemeIni(PTHEME_FILE tf, BOOL setMetrics)
TRACE("Unknown system metric %s\n", debugstr_w(szPropertyName));
}
}
if (setMetrics && (colorCount > 0))
SetSysColors(colorCount, colorElements, colorRgb);
if (setMetrics && (captionColors == 0xf))
SystemParametersInfoW (SPI_SETGRADIENTCAPTIONS, 0, (PVOID)TRUE, 0);
if (setMetrics) parse_apply_color (&colorState);
continue;
}
if(MSSTYLES_ParseIniSectionName(lpName, dwLen, szAppName, szClassName, &iPartId, &iStateId)) {