edit control: miscellaneous fixes take 2

Lauri Tulmin lauri_ at ut.ee
Sun Sep 26 12:47:55 CDT 2004


this time with patch

there were some bugs in previous patch

 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
 - after font change update scrollbar info

-------------- next part --------------
--- dlls/user/edit.c	2004-09-25 15:34:15.000000000 +0300
+++ dlls/user/edit.c	2004-09-26 19:39:42.929125808 +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)
 		{
@@ -1267,6 +1270,7 @@
 			rc.bottom = line_count * es->line_height;
 		else
 			rc.bottom = line_index * es->line_height;
+		rc.bottom += es->format_rect.top;
 		rc.bottom -= (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
 		tmphrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
 		CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR);
@@ -1382,6 +1386,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 +1423,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 +1469,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 +1491,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 +2214,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);
@@ -2216,6 +2256,8 @@
 
 	if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
 		EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
+	
+	EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
 }
 
 
@@ -2916,7 +2958,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)
@@ -4657,11 +4699,14 @@
 	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_UpdateScrollInfo(es);
+
 	if (redraw)
 		EDIT_UpdateText(es, NULL, TRUE);
 	if (es->flags & EF_FOCUSED) {


More information about the wine-patches mailing list