[RICHED20]
authorAmine Khaldi <amine.khaldi@reactos.org>
Thu, 13 Dec 2012 13:10:17 +0000 (13:10 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Thu, 13 Dec 2012 13:10:17 +0000 (13:10 +0000)
* Sync with Wine 1.5.19.

svn path=/trunk/; revision=57901

13 files changed:
reactos/dll/win32/riched20/context.c
reactos/dll/win32/riched20/editor.c
reactos/dll/win32/riched20/editor.h
reactos/dll/win32/riched20/editstr.h
reactos/dll/win32/riched20/paint.c
reactos/dll/win32/riched20/para.c
reactos/dll/win32/riched20/reader.c
reactos/dll/win32/riched20/style.c
reactos/dll/win32/riched20/table.c
reactos/dll/win32/riched20/txthost.c
reactos/dll/win32/riched20/wrap.c
reactos/dll/win32/riched20/writer.c
reactos/media/doc/README.WINE

index 93d5caa..2cdaeff 100644 (file)
 
 void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
 {
-  c->nSequence = editor->nSequence++;
   c->hDC = hDC;
   c->editor = editor;
   c->pt.x = 0;
   c->pt.y = 0;
-  c->hbrMargin = CreateSolidBrush(RGB(224,224,224));
   c->rcView = editor->rcFormat;
   if (hDC) {
       c->dpi.cx = GetDeviceCaps(hDC, LOGPIXELSX);
@@ -44,5 +42,4 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
 void ME_DestroyContext(ME_Context *c)
 {
   if (c->hDC) ITextHost_TxReleaseDC(c->editor->texthost, c->hDC);
-  DeleteObject(c->hbrMargin);
 }
index e61aac4..6221f4b 100644 (file)
@@ -283,14 +283,16 @@ static ME_TextBuffer *ME_MakeText(void) {
 
 static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
 {
-  WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
   WCHAR *pText;
   LRESULT total_bytes_read = 0;
+  BOOL is_read = FALSE;
+  static const char bom_utf8[] = {0xEF, 0xBB, 0xBF};
 
   TRACE("%08x %p\n", dwFormat, stream);
 
   do {
     LONG nWideChars = 0;
+    WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
 
     if (!stream->dwSize)
     {
@@ -304,8 +306,22 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
 
     if (!(dwFormat & SF_UNICODE))
     {
-      /* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
-      nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE);
+      char * buf = stream->buffer;
+      DWORD size = stream->dwSize;
+      DWORD cp = CP_ACP;
+
+      if (!is_read)
+      {
+        is_read = TRUE;
+        if (stream->dwSize >= 3 && !memcmp(stream->buffer, bom_utf8, 3))
+        {
+          cp = CP_UTF8;
+          buf += 3;
+          size -= 3;
+        }
+      }
+
+      nWideChars = MultiByteToWideChar(cp, 0, buf, size, wszText, STREAMIN_BUFFER_SIZE);
       pText = wszText;
     }
     else
@@ -2687,7 +2703,6 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
   ed->nLastTotalLength = ed->nTotalLength = 0;
   ed->nLastTotalWidth = ed->nTotalWidth = 0;
   ed->nUDArrowX = -1;
-  ed->nSequence = 0;
   ed->rgbBackColor = -1;
   ed->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
   ed->bCaretAtEnd = FALSE;
@@ -2794,8 +2809,8 @@ static void ME_DestroyEditor(ME_TextEditor *editor)
   if (editor->rgbBackColor != -1)
     DeleteObject(editor->hbrBackground);
   if(editor->lpOleCallback)
-    IUnknown_Release(editor->lpOleCallback);
-  IUnknown_Release(editor->texthost);
+    IRichEditOleCallback_Release(editor->lpOleCallback);
+  ITextHost_Release(editor->texthost);
   OleUninitialize();
 
   FREE_OBJ(editor->pBuffer);
@@ -3592,6 +3607,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
     return FALSE;
   }
   case WM_PASTE:
+  case WM_MBUTTONDOWN:
     ME_Paste(editor);
     return 0;
   case WM_CUT:
@@ -4311,10 +4327,10 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
   }
   case EM_SETOLECALLBACK:
     if(editor->lpOleCallback)
-      IUnknown_Release(editor->lpOleCallback);
-    editor->lpOleCallback = (LPRICHEDITOLECALLBACK)lParam;
+      IRichEditOleCallback_Release(editor->lpOleCallback);
+    editor->lpOleCallback = (IRichEditOleCallback*)lParam;
     if(editor->lpOleCallback)
-      IUnknown_AddRef(editor->lpOleCallback);
+      IRichEditOleCallback_AddRef(editor->lpOleCallback);
     return TRUE;
   case EM_GETWORDBREAKPROC:
     return (LRESULT)editor->pfnWordBreak;
index 82d86a2..b9c055f 100644 (file)
@@ -187,7 +187,7 @@ void ME_DestroyContext(ME_Context *c) DECLSPEC_HIDDEN;
 
 /* wrap.c */
 BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) DECLSPEC_HIDDEN;
-void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor, ME_DisplayItem *start_para, ME_DisplayItem *end_para) DECLSPEC_HIDDEN;
+void ME_InvalidateParagraphRange(ME_TextEditor *editor, ME_DisplayItem *start_para, ME_DisplayItem *last_para) DECLSPEC_HIDDEN;
 void ME_SendRequestResize(ME_TextEditor *editor, BOOL force) DECLSPEC_HIDDEN;
 
 /* para.c */
@@ -201,8 +201,6 @@ void ME_DumpParaStyle(ME_Paragraph *s) DECLSPEC_HIDDEN;
 void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]) DECLSPEC_HIDDEN;
 BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
 void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
-/* marks from first up to (but not including) last */
-void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last) DECLSPEC_HIDDEN;
 void ME_MarkAllForWrapping(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 void ME_SetDefaultParaFormat(PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
 
@@ -261,6 +259,7 @@ ME_DisplayItem *ME_InsertTableCellFromCursor(ME_TextEditor *editor) DECLSPEC_HID
 ME_DisplayItem *ME_InsertTableRowEndFromCursor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 ME_DisplayItem *ME_GetTableRowEnd(ME_DisplayItem *para) DECLSPEC_HIDDEN;
 ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para) DECLSPEC_HIDDEN;
+ME_DisplayItem *ME_GetOuterParagraph(ME_DisplayItem *para) DECLSPEC_HIDDEN;
 void ME_CheckTablesForCorruption(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nChars) DECLSPEC_HIDDEN;
 ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row) DECLSPEC_HIDDEN;
index 5b5afae..8f136cb 100644 (file)
@@ -67,7 +67,6 @@ typedef struct tagME_Style
   HFONT hFont; /* cached font for the style */
   TEXTMETRICW tm; /* cached font metrics for the style */
   int nRefs; /* reference count */
-  int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
 } ME_Style;
 
 typedef enum {
@@ -139,7 +138,6 @@ typedef enum {
 
 /* this paragraph was already wrapped and hasn't changed, every change resets that flag */
 #define MEPF_REWRAP   0x01
-#define MEPF_REPAINT  0x02
 /* v4.1 */
 #define MEPF_CELL     0x04 /* The paragraph is nested in a cell */
 #define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
@@ -186,7 +184,6 @@ typedef struct tagME_Paragraph
   int nFlags;
   POINT pt;
   int nHeight, nWidth;
-  int nLastPaintYPos, nLastPaintHeight;
   int nRows;
   struct tagME_DisplayItem *prev_para, *next_para;
 } ME_Paragraph;
@@ -335,7 +332,6 @@ typedef struct tagME_TextEditor
   int nTotalWidth, nLastTotalWidth;
   int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
   int nUDArrowX;
-  int nSequence;
   COLORREF rgbBackColor;
   HBRUSH hbrBackground;
   BOOL bCaretAtEnd;
@@ -385,16 +381,12 @@ typedef struct tagME_Context
 {
   HDC hDC;
   POINT pt;
-  POINT ptRowOffset;
   RECT rcView;
-  HBRUSH hbrMargin;
   SIZE dpi;
   int nAvailWidth;
 
   /* those are valid inside ME_WrapTextParagraph and related */
-  POINT ptFirstRun;
   ME_TextEditor *editor;
-  int nSequence;
 } ME_Context;
 
 typedef struct tagME_WrapContext
index 0a2e1a9..f82802a 100644 (file)
@@ -41,7 +41,6 @@ void ME_PaintContent(ME_TextEditor *editor, HDC hDC, const RECT *rcUpdate)
   IntersectClipRect(hDC, rcUpdate->left, rcUpdate->top,
                      rcUpdate->right, rcUpdate->bottom);
 
-  editor->nSequence++;
   ME_InitContext(&c, editor, hDC);
   SetBkMode(hDC, TRANSPARENT);
   ME_MoveCaret(editor);
@@ -1275,32 +1274,29 @@ ME_InvalidateSelection(ME_TextEditor *editor)
    * they can point past the end of the document */
   if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
     repaint_start = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
-    repaint_end = editor->pBuffer->pLast;
-    ME_MarkForPainting(editor, repaint_start, repaint_end);
+    repaint_end = editor->pBuffer->pLast->member.para.prev_para;
   } else {
     /* if the start part of selection is being expanded or contracted... */
     if (nStart < editor->nLastSelStart) {
       repaint_start = sel_start;
-      repaint_end = editor->pLastSelStartPara->member.para.next_para;
+      repaint_end = editor->pLastSelStartPara;
     } else if (nStart > editor->nLastSelStart) {
       repaint_start = editor->pLastSelStartPara;
-      repaint_end = sel_start->member.para.next_para;
+      repaint_end = sel_start;
     }
-    ME_MarkForPainting(editor, repaint_start, repaint_end);
 
     /* if the end part of selection is being contracted or expanded... */
     if (nEnd < editor->nLastSelEnd) {
       if (!repaint_start) repaint_start = sel_end;
-      repaint_end = editor->pLastSelEndPara->member.para.next_para;
-      ME_MarkForPainting(editor, sel_end, repaint_end);
+      repaint_end = editor->pLastSelEndPara;
     } else if (nEnd > editor->nLastSelEnd) {
       if (!repaint_start) repaint_start = editor->pLastSelEndPara;
-      repaint_end = sel_end->member.para.next_para;
-      ME_MarkForPainting(editor, editor->pLastSelEndPara, repaint_end);
+      repaint_end = sel_end;
     }
   }
 
-  ME_InvalidateMarkedParagraphs(editor, repaint_start, repaint_end);
+  if (repaint_start)
+    ME_InvalidateParagraphRange(editor, repaint_start, repaint_end);
   /* remember the last invalidated position */
   ME_GetSelectionOfs(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
   ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
index efd3d04..ffa816d 100644 (file)
@@ -94,15 +94,6 @@ void ME_MarkAllForWrapping(ME_TextEditor *editor)
   ME_MarkForWrapping(editor, editor->pBuffer->pFirst->member.para.next_para, editor->pBuffer->pLast);
 }
 
-void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_DisplayItem *last)
-{
-  while(first != last && first)
-  {
-    first->member.para.nFlags |= MEPF_REPAINT;
-    first = first->member.para.next_para;
-  }
-}
-
 static void ME_UpdateTableFlags(ME_DisplayItem *para)
 {
   para->member.para.pFmt->dwMask |= PFM_TABLE|PFM_TABLEROWDELIMITER;
index 9f88cf7..02d4636 100644 (file)
@@ -2397,8 +2397,11 @@ CharAttr(RTF_Info *info)
                 font = RTFGetFont(info, info->rtfParam);
                 if (font)
                 {
-                        if (info->ansiCodePage != CP_UTF8)
+                        if (info->ansiCodePage != CP_UTF8 && info->codePage != font->rtfFCodePage)
+                        {
+                                RTFFlushOutputBuffer(info);
                                 info->codePage = font->rtfFCodePage;
+                        }
                         TRACE("font %d codepage %d\n", info->rtfParam, info->codePage);
                 }
                 else
index 605faeb..6292714 100644 (file)
@@ -41,7 +41,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
     CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
     to->cbSize = sizeof(CHARFORMAT2W);
     if (f->dwMask & CFM_FACE) {
-      MultiByteToWideChar(0, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
+      MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
     }
     return to;
   }
@@ -61,7 +61,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
     CopyMemory(to, f, FIELD_OFFSET(CHARFORMATA, szFaceName));
     /* convert face name */
     if (f->dwMask & CFM_FACE)
-      MultiByteToWideChar(0, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
+      MultiByteToWideChar(CP_ACP, 0, f->szFaceName, -1, to->szFaceName, sizeof(to->szFaceName)/sizeof(WCHAR));
     /* copy the rest of the 2A structure to 2W */
     CopyMemory(&to->wWeight, &f->wWeight, sizeof(CHARFORMAT2A)-FIELD_OFFSET(CHARFORMAT2A, wWeight));
     to->cbSize = sizeof(CHARFORMAT2W);
@@ -78,7 +78,7 @@ static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
   {
     CHARFORMATA *t = (CHARFORMATA *)to;
     CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
-    WideCharToMultiByte(0, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), 0, 0);
+    WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
     if (from->dwMask & CFM_UNDERLINETYPE)
     {
         switch (from->bUnderlineType)
@@ -123,7 +123,7 @@ static CHARFORMAT2W *ME_ToCFAny(CHARFORMAT2W *to, CHARFORMAT2W *from)
     /* copy the A structure without face name */
     CopyMemory(t, from, FIELD_OFFSET(CHARFORMATA, szFaceName));
     /* convert face name */
-    WideCharToMultiByte(0, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), 0, 0);
+    WideCharToMultiByte(CP_ACP, 0, from->szFaceName, -1, t->szFaceName, sizeof(t->szFaceName), NULL, NULL);
     /* copy the rest of the 2A structure to 2W */
     CopyMemory(&t->wWeight, &from->wWeight, sizeof(CHARFORMAT2W)-FIELD_OFFSET(CHARFORMAT2W,wWeight));
     t->cbSize = sizeof(*t); /* it was overwritten by CopyMemory */
@@ -145,7 +145,6 @@ ME_Style *ME_MakeStyle(CHARFORMAT2W *style)
 
   assert(style->cbSize == sizeof(CHARFORMAT2W));
   s->fmt = *style;
-  s->nSequence = -2;
   s->nRefs = 1;
   s->hFont = NULL;
   memset(&s->tm, 0, sizeof(s->tm));
index 053bedf..1182550 100644 (file)
@@ -172,6 +172,20 @@ ME_DisplayItem* ME_GetTableRowStart(ME_DisplayItem *para)
   return para;
 }
 
+ME_DisplayItem* ME_GetOuterParagraph(ME_DisplayItem *para)
+{
+  if (para->member.para.nFlags & MEPF_ROWEND)
+    para = para->member.para.prev_para;
+  while (para->member.para.pCell)
+  {
+    para = ME_GetTableRowStart(para);
+    if (!para->member.para.pCell)
+      break;
+    para = ME_FindItemBack(para->member.para.pCell, diParagraph);
+  }
+  return para;
+}
+
 /* Make a bunch of assertions to make sure tables haven't been corrupted.
  *
  * These invariants may not hold true in the middle of streaming in rich text
index bc96588..4b72d8b 100644 (file)
@@ -141,8 +141,7 @@ DECLSPEC_HIDDEN BOOL WINAPI ITextHostImpl_TxSetScrollRange(ITextHost *iface, INT
 DECLSPEC_HIDDEN BOOL WINAPI ITextHostImpl_TxSetScrollPos(ITextHost *iface, INT fnBar, INT nPos, BOOL fRedraw)
 {
     ITextHostImpl *This = impl_from_ITextHost(iface);
-    int pos = SetScrollPos(This->hWnd, fnBar, nPos, fRedraw);
-    return (pos ? TRUE : FALSE);
+    return SetScrollPos(This->hWnd, fnBar, nPos, fRedraw) != 0;
 }
 
 DECLSPEC_HIDDEN void WINAPI ITextHostImpl_TxInvalidateRect(ITextHost *iface, LPCRECT prc, BOOL fMode)
index ceb87ad..8ac14f9 100644 (file)
@@ -589,8 +589,7 @@ static void ME_MarkRepaintEnd(ME_DisplayItem *para,
 {
     if (!*repaint_start)
       *repaint_start = para;
-    *repaint_end = para->member.para.next_para;
-    para->member.para.nFlags |= MEPF_REPAINT;
+    *repaint_end = para;
 }
 
 BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
@@ -738,42 +737,35 @@ BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor)
   ME_DestroyContext(&c);
 
   if (repaint_start || editor->nTotalLength < editor->nLastTotalLength)
-  {
-    if (!repaint_start) repaint_start = editor->pBuffer->pFirst;
-    ME_InvalidateMarkedParagraphs(editor, repaint_start, repaint_end);
-  }
+    ME_InvalidateParagraphRange(editor, repaint_start, repaint_end);
   return !!repaint_start;
 }
 
-void ME_InvalidateMarkedParagraphs(ME_TextEditor *editor,
-                                   ME_DisplayItem *start_para,
-                                   ME_DisplayItem *end_para)
+void ME_InvalidateParagraphRange(ME_TextEditor *editor,
+                                 ME_DisplayItem *start_para,
+                                 ME_DisplayItem *last_para)
 {
   ME_Context c;
   RECT rc;
   int ofs;
-  ME_DisplayItem *item;
 
   ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
   rc = c.rcView;
   ofs = editor->vert_si.nPos;
 
-  item = start_para;
-  while(item && item != end_para) {
-    if (item->member.para.nFlags & MEPF_REPAINT) {
-      rc.top = c.rcView.top + item->member.para.pt.y - ofs;
-      rc.bottom = max(rc.top + item->member.para.nHeight, c.rcView.bottom);
-      ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
-      item->member.para.nFlags &= ~MEPF_REPAINT;
-    }
-    item = item->member.para.next_para;
+  if (start_para) {
+    start_para = ME_GetOuterParagraph(start_para);
+    last_para = ME_GetOuterParagraph(last_para);
+    rc.top = c.rcView.top + start_para->member.para.pt.y - ofs;
+  } else {
+    rc.top = c.rcView.top + editor->nTotalLength - ofs;
   }
   if (editor->nTotalLength < editor->nLastTotalLength)
-  {
-    rc.top = c.rcView.top + editor->nTotalLength - ofs;
     rc.bottom = c.rcView.top + editor->nLastTotalLength - ofs;
-    ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
-  }
+  else
+    rc.bottom = c.rcView.top + last_para->member.para.pt.y + last_para->member.para.nHeight - ofs;
+  ITextHost_TxInvalidateRect(editor->texthost, &rc, TRUE);
+
   ME_DestroyContext(&c);
 }
 
index a5e5d50..653eab6 100644 (file)
@@ -251,11 +251,8 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
   } while (item);
   item = ME_GetParagraph(pFirstRun);
   do {
-    if (item->member.para.pCell && item->member.para.pCell)
+    if ((pCell = item->member.para.pCell))
     {
-      pCell = item->member.para.pCell;
-      if (pCell)
-      {
         ME_Border* borders[4] = { &pCell->member.cell.border.top,
                                   &pCell->member.cell.border.left,
                                   &pCell->member.cell.border.bottom,
@@ -275,7 +272,6 @@ ME_StreamOutRTFFontAndColorTbl(ME_OutStream *pStream, ME_DisplayItem *pFirstRun,
             }
           }
         }
-      }
     }
     if (item == pLastPara)
       break;
index 4328a04..f8cdd48 100644 (file)
@@ -148,7 +148,7 @@ reactos/dll/win32/qmgrprxy        # Synced to Wine-1.14?
 reactos/dll/win32/query           # Synced to Wine-1.5.19
 reactos/dll/win32/rasapi32        # Synced to Wine-1.5.4
 reactos/dll/win32/resutils        # Synced to Wine-1.5.19
-reactos/dll/win32/riched20        # Synced to Wine-1.5.4
+reactos/dll/win32/riched20        # Synced to Wine-1.5.19
 reactos/dll/win32/riched32        # Synced to Wine-1.5.19
 reactos/dll/win32/rpcrt4          # Synced to Wine-1.3.26
 reactos/dll/win32/rsabase         # Autosync