[PATCH] UXTHEME: Split color handling out of MSSTYLES_ParseThemeIni into smaller helper functions

Frank Richter frank.richter at gmail.com
Mon Aug 14 10:35:13 CDT 2006


Applies on top of "Enable gradient captions ...".

-------------- next part --------------
>From 06ee50913e8c6994a6900678d00a14b438321fc5 Mon Sep 17 00:00:00 2001
From: Frank Richter frank.richter at gmail.com <frank.richter at gmail.com>
Date: Mon, 14 Aug 2006 17:33:44 +0200
Subject: [PATCH] UXTHEME: Split color handling out of MSSTYLES_ParseThemeIni into smaller helper functions
---
 dlls/uxtheme/msstyles.c |   98 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 63 insertions(+), 35 deletions(-)

diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c
index 827bdf6..4649a36 100644
--- a/dlls/uxtheme/msstyles.c
+++ b/dlls/uxtheme/msstyles.c
@@ -664,6 +664,61 @@ static PTHEME_PROPERTY MSSTYLES_AddMetri
     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 
 
     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 
                     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)) {
-- 
1.4.1.1



More information about the wine-patches mailing list