RICHEDIT: repaint optimization and cleanup + a few extra fixes

Krzysztof Foltman kfoltman at portal.onet.pl
Wed Mar 9 10:36:19 CST 2005


ChangeLog:
  * Optimized repaint of the area below the text
  * ME_JoinRuns didn't mark the paragraph for rewrapping, fixed
  * Removed PostQuitMessage(0) from WM_DESTROY handler (duh!)
  * use of EM_GETOLEINTERFACE is reported with FIXME instead of TRACE 
(any app using this message is likely to encounter major problems)

Krzysztof
-------------- next part --------------
Index: caret.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/caret.c,v
retrieving revision 1.3
diff -u -r1.3 caret.c
--- caret.c	9 Mar 2005 11:48:59 -0000	1.3
+++ caret.c	9 Mar 2005 16:07:03 -0000
@@ -380,6 +380,7 @@
     if (pRun->type == diRun) {
       p->pRun = pRun;
       assert(p->pRun->type == diRun);
+      assert(pRun->member.run.strText->nLen);
       p->nOffset = pRun->member.run.strText->nLen;
       if (p->nOffset) {
         p->nOffset = ME_StrRelPos2(pRun->member.run.strText, p->nOffset, -1);
@@ -974,3 +975,4 @@
   }
   return FALSE;
 }
+
Index: editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.c,v
retrieving revision 1.8
diff -u -r1.8 editor.c
--- editor.c	9 Mar 2005 12:40:01 -0000	1.8
+++ editor.c	9 Mar 2005 16:07:04 -0000
@@ -279,7 +279,6 @@
   RTF_Info parser;
   ME_Style *style;
 
-  FIXME("%08lx %p\n", format, stream);
   TRACE("%p %p\n", stream, editor->hWnd);
   
   if (format & SFF_SELECTION) {
@@ -340,7 +339,7 @@
   ed->pCursors[0].nOffset = 0;
   ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
   ed->pCursors[1].nOffset = 0;
-  ed->nTotalLength = 0;
+  ed->nLastTotalLength = ed->nTotalLength = 0;
   ed->nScrollPos = 0;
   ed->nUDArrowX = -1;
   ed->nSequence = 0;
@@ -398,6 +397,7 @@
   PAINTSTRUCT ps;
   SCROLLINFO si;
   ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
+  TRACE("msg %d %08lx %08lx\n", msg, wParam, lParam);
   switch(msg) {
   
   UNSUPPORTED_MSG(EM_AUTOURLDETECT)
@@ -703,15 +703,13 @@
   }
   case WM_CREATE:
     ME_CommitUndo(editor);
-/*    ME_InsertTextFromCursor(editor, 0, (WCHAR *)L"x", 1, editor->pBuffer->pDefaultStyle); */
     ME_WrapMarkedParagraphs(editor);
     ME_MoveCaret(editor);
     return 0;
   case WM_DESTROY:
     ME_DestroyEditor(editor);
     SetWindowLongW(hWnd, 0, 0);
-    PostQuitMessage(0);
-    break;
+    return 0;
   case WM_LBUTTONDOWN:
     SetFocus(hWnd);
     ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
@@ -727,7 +725,7 @@
     break;
   case WM_PAINT:
     hDC = BeginPaint(hWnd, &ps);
-    ME_PaintContent(editor, hDC, FALSE);
+    ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
     EndPaint(hWnd, &ps);
     break;
   case WM_SETFOCUS:
@@ -822,7 +820,7 @@
   case EM_GETOLEINTERFACE:
   {
     LPVOID *ppvObj = (LPVOID*) lParam;
-    TRACE("EM_GETOLEINTERFACE %p\n", ppvObj);
+    FIXME("EM_GETOLEINTERFACE %p: stub\n", ppvObj);
     return CreateIRichEditOle(ppvObj);
   }
   default:
Index: editor.h
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editor.h,v
retrieving revision 1.5
diff -u -r1.5 editor.h
--- editor.h	9 Mar 2005 11:48:59 -0000	1.5
+++ editor.h	9 Mar 2005 16:07:04 -0000
@@ -181,7 +181,7 @@
 void ME_MarkAllForWrapping(ME_TextEditor *editor);
 
 /* paint.c */
-void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew);
+void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpdate);
 void ME_Repaint(ME_TextEditor *editor);
 void ME_UpdateRepaint(ME_TextEditor *editor);
 void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph);
Index: editstr.h
===================================================================
RCS file: /home/wine/wine/dlls/riched20/editstr.h,v
retrieving revision 1.3
diff -u -r1.3 editstr.h
--- editstr.h	9 Mar 2005 11:48:59 -0000	1.3
+++ editstr.h	9 Mar 2005 16:07:04 -0000
@@ -211,7 +211,7 @@
   int nCursors;
   SIZE sizeWindow;
   int nScrollPos;
-  int nTotalLength;
+  int nTotalLength, nLastTotalLength;
   int nUDArrowX;
   int nSequence;
   int nOldSelFrom, nOldSelTo;
Index: paint.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/paint.c,v
retrieving revision 1.4
diff -u -r1.4 paint.c
--- paint.c	9 Mar 2005 11:48:59 -0000	1.4
+++ paint.c	9 Mar 2005 16:07:05 -0000
@@ -22,41 +22,76 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
 
-void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew) {
+void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, RECT *rcUpdate) {
   ME_DisplayItem *item;
   ME_Context c;
+  int yoffset;
 
   editor->nSequence++;
+  yoffset = GetScrollPos(editor->hWnd, SB_VERT);
   ME_InitContext(&c, editor, hDC);
   SetBkMode(hDC, TRANSPARENT);
   ME_MoveCaret(editor);
   item = editor->pBuffer->pFirst->next;
-  c.pt.y=-GetScrollPos(editor->hWnd, SB_VERT);
+  c.pt.y -= yoffset;
   while(item != editor->pBuffer->pLast) {
     assert(item->type == diParagraph);
     if (!bOnlyNew || (item->member.para.nFlags & MEPF_REPAINT))
     {
-      ME_DrawParagraph(&c, item);
-      item->member.para.nFlags &= ~MEPF_REPAINT;
+      BOOL bPaint = (rcUpdate == NULL);
+      if (rcUpdate)
+        bPaint = c.pt.y<rcUpdate->bottom && 
+          c.pt.y+item->member.para.nHeight>rcUpdate->top;
+      if (bPaint)
+      {
+        ME_DrawParagraph(&c, item);
+        item->member.para.nFlags &= ~MEPF_REPAINT;
+      }
     }
     c.pt.y += item->member.para.nHeight;
     item = item->member.para.next_para;
   }
-  /* FIXME this code just sucks, it should try to redraw incrementally */
   if (c.pt.y<c.rcView.bottom) {
     RECT rc;
-    rc.left = c.rcView.left;
+    int xs = c.rcView.left, xe = c.rcView.right;
+    int ys = c.pt.y, ye = c.rcView.bottom;
+    
+    if (bOnlyNew)
+    {
+      int y1 = editor->nTotalLength-yoffset, y2 = editor->nLastTotalLength-yoffset;
+      if (y1<y2)
+        ys = y1, ye = y2+1;
+      else
+        ys = ye;
+    }
+    
+    if (rcUpdate && ys!=ye)
+    {
+      xs = rcUpdate->left, xe = rcUpdate->right;
+      if (rcUpdate->top > ys)
+        ys = rcUpdate->top;
+      if (rcUpdate->bottom < ye)
+        ye = rcUpdate->bottom;
+    }
+    
+    rc.left = xs; /* FIXME remove if it's not necessary anymore */
     rc.top = c.pt.y;
-    rc.right = c.rcView.right;
+    rc.right = xe;
     rc.bottom = c.pt.y+1;
     FillRect(hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
 
-    rc.left = c.rcView.left;
-    rc.top = c.pt.y+1;
-    rc.right = c.rcView.right;
-    rc.bottom = c.rcView.bottom;
-    FillRect(hDC, &rc, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
+    if (ys == c.pt.y) /* don't overwrite the top bar */
+      ys++;
+    if (ye>ys) {
+      rc.left = xs;
+      rc.top = ys;
+      rc.right = xe;
+      rc.bottom = ye;
+      /* this is not supposed to be gray, I know, but lets keep it gray for now for debugging purposes */
+      FillRect(hDC, &rc, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
+    }
   }
+  editor->nLastTotalLength = editor->nTotalLength;
   ME_DestroyContext(&c);
 }
 
@@ -120,7 +155,7 @@
   ME_WrapMarkedParagraphs(editor);
   hDC = GetDC(editor->hWnd);
   ME_HideCaret(editor);
-  ME_PaintContent(editor, hDC, TRUE);
+  ME_PaintContent(editor, hDC, TRUE, NULL);
   ReleaseDC(editor->hWnd, hDC);
   ME_ShowCaret(editor);
 }
Index: run.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/run.c,v
retrieving revision 1.3
diff -u -r1.3 run.c
--- run.c	9 Mar 2005 11:48:59 -0000	1.3
+++ run.c	9 Mar 2005 16:07:05 -0000
@@ -172,6 +172,7 @@
   int i;
   assert(p->type == diRun && pNext->type == diRun);
   assert(p->member.run.nCharOfs != -1);
+  ME_GetParagraph(p)->member.para.nFlags |= MEPF_REWRAP;
 
   for (i=0; i<editor->nCursors; i++) {
     if (editor->pCursors[i].pRun == pNext) {
Index: wrap.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/wrap.c,v
retrieving revision 1.3
diff -u -r1.3 wrap.c
--- wrap.c	9 Mar 2005 11:48:59 -0000	1.3
+++ wrap.c	9 Mar 2005 16:07:05 -0000
@@ -442,7 +442,7 @@
   }
   editor->sizeWindow.cx = c.rcView.right-c.rcView.left;
   editor->sizeWindow.cy = c.rcView.bottom-c.rcView.top;
-  editor->nTotalLength = c.pt.y-c.rcView.top;
+  editor->nTotalLength = c.pt.y;
   
   ME_DestroyContext(&c);
   ReleaseDC(hWnd, hDC);


More information about the wine-patches mailing list