edit control: miscellaneous fixes

Lauri Tulmin lauri_ at ut.ee
Sat Sep 25 12:23:26 CDT 2004


changelog:
- when edit control is empty set text width = 0
- ES_CHARFROMPOS should return the position of closest char of point
- if window has border then leave 1px of empty space at each side
- don't allow \r, \n, \t if ES_NUMBER
- after font change scroll to current carret position
-------------- next part --------------
--- dlls/user/edit.c	2004-09-25 15:34:15.000000000 +0300
+++ dlls/user/edit.c	2004-09-25 19:23:06.827818688 +0300
@@ -1025,6 +1025,9 @@
 	if (istart == iend && delta == 0)
 		return;
 
+	if (strlenW(es->text) == 0)
+		es->text_width = 0;
+
 	dc = GetDC(es->hwndSelf);
 	if (es->font)
 		old_font = SelectObject(dc, es->font);
@@ -1223,7 +1226,7 @@
 			es->line_count--;
 		}
 	}
-	else
+	else if (delta != 0)
 	{
 		while (current_line)
 		{
@@ -1382,6 +1385,7 @@
 	HFONT old_font = 0;
 	INT line_width;
 	INT fw = es->format_rect.right - es->format_rect.left;
+	INT x_high = 0, x_low = 0;
 
 	if (es->style & ES_MULTILINE) {
 		INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
@@ -1418,10 +1422,19 @@
                     while (low < high - 1)
                     {
                         INT mid = (low + high) / 2;
-			if (LOWORD(GetTabbedTextExtentW(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
-                        else low = mid;
+			INT x_now = LOWORD(GetTabbedTextExtentW(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs));
+			if (x_now > x) {
+				high = mid;
+				x_high = x_now;
+                        } else {
+				low = mid;
+				x_low = x_now;
+			}
                     }
-                    index = low;
+		    if (abs(x_high - x) < abs(x_low - x))
+		    	index = high;
+		    else
+                    	index = low;
 
 		if (after_wrap)
 			*after_wrap = ((index == line_index + line_def->net_length) &&
@@ -1455,10 +1468,18 @@
                         INT mid = (low + high) / 2;
                         GetTextExtentPoint32W( dc, text + mid,
                                                es->x_offset - mid, &size );
-                        if (size.cx > -x) low = mid;
-                        else high = mid;
+                        if (size.cx > -x) {
+				low = mid;
+				x_low = size.cx;
+                        } else {
+				high = mid;
+				x_high = size.cx;
+			}
                     }
-                    index = low;
+		    if (abs(x_high + x) < abs(x_low + x))
+		    	index = high;
+		    else
+                    	index = low;
 		}
                 else
                 {
@@ -1469,10 +1490,18 @@
                         INT mid = (low + high) / 2;
                         GetTextExtentPoint32W( dc, text + es->x_offset,
                                                mid - es->x_offset, &size );
-                        if (size.cx > x) high = mid;
-                        else low = mid;
+                        if (size.cx > x) {
+				high = mid;
+				x_high = size.cx;
+                        } else {
+				low = mid;
+				x_low = size.cx;
+			}
                     }
-                    index = low;
+		    if (abs(x_high - x) < abs(x_low - x))
+		    	index = high;
+		    else
+                    	index = low;
 		}
 		if (es->style & ES_PASSWORD)
 			HeapFree(GetProcessHeap(), 0, text);
@@ -2184,6 +2213,16 @@
 		es->format_rect.right -= bw;
 		es->format_rect.bottom -= bw;
 	}
+
+	if ((GetWindowLongA(es->hwndSelf, GWL_EXSTYLE) & WS_EX_WINDOWEDGE) || 
+		(GetWindowLongA(es->hwndSelf, GWL_EXSTYLE) & WS_EX_CLIENTEDGE) || 
+		(es->style & WS_BORDER)) {
+		es->format_rect.left += 1;
+		es->format_rect.top += 1;
+		es->format_rect.right -= 1;
+		es->format_rect.bottom -= 1;
+	}
+
 	es->format_rect.left += es->left_margin;
 	es->format_rect.right -= es->right_margin;
 	es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width);
@@ -2916,7 +2955,7 @@
  *
  *	EM_REPLACESEL
  *
- *	FIXME: handle ES_NUMBER and ES_OEMCONVERT here
+ *	FIXME: handle ES_OEMCONVERT here
  *
  */
 static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit)
@@ -3677,10 +3716,11 @@
 	switch (c) {
 	case '\r':
 	    /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
-	    if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
+	    if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN)
+			 && !(es->style & ES_NUMBER))
 		break;
 	case '\n':
-		if (es->style & ES_MULTILINE) {
+		if ((es->style & ES_MULTILINE) && !(es->style & ES_NUMBER)) {
 			if (es->style & ES_READONLY) {
 				EDIT_MoveHome(es, FALSE);
 				EDIT_MoveDown_ML(es, FALSE);
@@ -3691,7 +3731,8 @@
 		}
 		break;
 	case '\t':
-		if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
+		if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)
+			 && !(es->style & ES_NUMBER))
 		{
 			static const WCHAR tabW[] = {'\t',0};
 			EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE, TRUE);
@@ -4657,11 +4698,15 @@
 	GetClientRect(es->hwndSelf, &r);
 	EDIT_SetRectNP(es, &r);
 
-	if (es->style & ES_MULTILINE)
+	if (es->style & ES_MULTILINE) {
+		es->text_width = 0;
 		EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
-	else
+	} else
 	    EDIT_CalcLineWidth_SL(es);
 
+	EDIT_EM_ScrollCaret(es);
+	EDIT_UpdateScrollInfo(es);
+
 	if (redraw)
 		EDIT_UpdateText(es, NULL, TRUE);
 	if (es->flags & EF_FOCUSED) {


More information about the wine-patches mailing list