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

Alexandre Julliard julliard at wine.codeweavers.com
Mon Aug 14 14:10:20 CDT 2006


Module: wine
Branch: master
Commit: 3e4bdad4a3bf0f20b3308d545a96606d35750655
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=3e4bdad4a3bf0f20b3308d545a96606d35750655

Author: Frank Richter <frank.richter at gmail.com>
Date:   Mon Aug 14 17:35:13 2006 +0200

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)) {




More information about the wine-cvs mailing list