DrawText upgrade - step 2

Medland, Bill Bill.Medland at accpac.com
Wed Jan 16 10:22:45 CST 2002


-------------- next part --------------
Bill Medland (medbi01 at accpac.com)
DrawText upgrade
1. Don't string copy from uninitialised stack memory.  In fact don't
   modify the input string if it didn't change.
2. Correct array size.
3. Logically separate the centring from the ellipsification.
4. Comment on prefix error.
Don't bother reformatting the ellipsification code; I'm going to move it
and change it in a couple of days.

Index: wine/dlls/user/text.c
===================================================================
RCS file: /home/wine/wine/dlls/user/text.c,v
retrieving revision 1.18
diff -u -r1.18 text.c
--- wine/dlls/user/text.c	2002/01/15 20:29:35	1.18
+++ wine/dlls/user/text.c	2002/01/16 14:28:04
@@ -23,6 +23,8 @@
 
 DEFAULT_DEBUG_CHANNEL(text);
 
+#define countof(a) (sizeof(a)/sizeof(a[0]))
+
 /*********************************************************************
  *
  *            DrawText functions
@@ -291,19 +293,18 @@
 	    if (flags & DT_VCENTER) y = rect->top +
 	    	(rect->bottom - rect->top) / 2 - size.cy / 2;
 	    else if (flags & DT_BOTTOM) y = rect->bottom - size.cy;
+        }
 
-	    if (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS))
-	    {
-	        WCHAR swapStr[sizeof(line)];
+        if ((flags & DT_SINGLELINE) && size.cx > width &&
+	    (flags & (DT_PATH_ELLIPSIS | DT_END_ELLIPSIS | DT_WORD_ELLIPSIS)))
+	{
+	        WCHAR swapStr[countof(line)];
 	        WCHAR* fnameDelim = NULL;
 	        int totalLen = i_count >= 0 ? i_count : strlenW(str);
-
-		if (size.cx > width)
-	        {
 	            int fnameLen = totalLen;
 
 	            /* allow room for '...' */
-	            count = min(totalLen+3, sizeof(line)-3);
+	            count = min(totalLen+3, countof(line)-3);
 
                     if (flags & DT_WORD_ELLIPSIS)
 	                flags |= DT_WORDBREAK;
@@ -374,10 +375,14 @@
 	            strncpyW(line, swapStr, len);
 	            line[len] = '\0';
 	            strPtr = NULL;
-	        }
+
                if (flags & DT_MODIFYSTRING)
                     strcpyW(str, swapStr);
-	    }
+
+               /* Note that really we ought to refigure the location of
+                * the underline for the prefix; it might be currently set for
+                * something we have just ellipsified out.
+                */
 	}
 	if (!(flags & DT_CALCRECT))
 	{


More information about the wine-patches mailing list