Dylan Smith : richedit: Prevent typing text at end of table row.

Alexandre Julliard julliard at winehq.org
Fri Aug 29 07:30:49 CDT 2008


Module: wine
Branch: master
Commit: f11fe1c7a98b76eec509269cc8defafa5772e0b1
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f11fe1c7a98b76eec509269cc8defafa5772e0b1

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Thu Aug 28 16:52:00 2008 -0400

richedit: Prevent typing text at end of table row.

---

 dlls/riched20/editor.c |   71 +++++++++++++++++++++++++++++++++++++++++++++++-
 dlls/riched20/editor.h |    1 +
 dlls/riched20/table.c  |   10 +++++--
 3 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 3e6c79b..adc9362 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -3685,6 +3685,8 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
     if (((unsigned)wstr)>=' '
         || (wstr=='\r' && (GetWindowLongW(hWnd, GWL_STYLE) & ES_MULTILINE))
         || wstr=='\t') {
+      ME_Cursor cursor = editor->pCursors[0];
+      ME_DisplayItem *para = ME_GetParagraph(cursor.pRun);
       int from, to;
       BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
       ME_GetSelection(editor, &from, &to);
@@ -3693,7 +3695,6 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
           && !(ctrl_is_down && !editor->bEmulateVersion10)
           )
       {
-        ME_Cursor cursor = editor->pCursors[0];
         ME_DisplayItem *para;
         BOOL bSelectedRow = FALSE;
 
@@ -3712,6 +3713,74 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
           ME_CommitUndo(editor);
           return 0;
         }
+      } else if (!editor->bEmulateVersion10) { /* v4.1 */
+        if (para->member.para.nFlags & MEPF_ROWEND) {
+          if (wstr=='\r') {
+            /* FIXME: Add a new table row after this row. */
+            return 0;
+          } else if (from == to) {
+            para = para->member.para.next_para;
+            if (para->member.para.nFlags & MEPF_ROWSTART)
+              para = para->member.para.next_para;
+            editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
+            editor->pCursors[0].nOffset = 0;
+            editor->pCursors[1] = editor->pCursors[0];
+          }
+        }
+        else if (para == ME_GetParagraph(editor->pCursors[1].pRun) &&
+                 cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 &&
+                 para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART &&
+                 !para->member.para.prev_para->member.para.nCharOfs)
+        {
+          /* FIXME: Insert a newline before the table. */
+        }
+      } else { /* v1.0 - 3.0 */
+        ME_DisplayItem *para = ME_GetParagraph(cursor.pRun);
+        if (ME_IsInTable(cursor.pRun))
+        {
+          if (cursor.pRun->member.run.nFlags & MERF_ENDPARA)
+          {
+            if (from == to) {
+              if (wstr=='\r') {
+                ME_ContinueCoalescingTransaction(editor);
+                para = ME_AppendTableRow(editor, para);
+                editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
+                editor->pCursors[0].nOffset = 0;
+                editor->pCursors[1] = editor->pCursors[0];
+                ME_CommitCoalescingUndo(editor);
+                ME_UpdateRepaint(editor);
+              } else {
+                /* Text should not be inserted at the end of the table. */
+                MessageBeep(-1);
+              }
+              return 0;
+            }
+          } else if (wstr == '\r') {
+            ME_ContinueCoalescingTransaction(editor);
+            if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
+                !ME_IsInTable(para->member.para.prev_para))
+            {
+              /* Insert newline before table */
+              WCHAR endl = '\r';
+              cursor.pRun = ME_FindItemBack(para, diRun);
+              if (cursor.pRun)
+                editor->pCursors[0].pRun = cursor.pRun;
+              editor->pCursors[0].nOffset = 0;
+              editor->pCursors[1] = editor->pCursors[0];
+              ME_InsertTextFromCursor(editor, 0, &endl, 1,
+                                      editor->pCursors[0].pRun->member.run.style);
+            } else {
+              editor->pCursors[1] = editor->pCursors[0];
+              para = ME_AppendTableRow(editor, para);
+              editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
+              editor->pCursors[0].nOffset = 0;
+              editor->pCursors[1] = editor->pCursors[0];
+            }
+            ME_CommitCoalescingUndo(editor);
+            ME_UpdateRepaint(editor);
+            return 0;
+          }
+        }
       }
       /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
       /* WM_CHAR is restricted to nTextLimit */
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 5e6f4cb..5e73c97 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -296,6 +296,7 @@ ME_DisplayItem *ME_GetTableRowEnd(ME_DisplayItem *para);
 ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para);
 void ME_CheckTablesForCorruption(ME_TextEditor *editor);
 void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars);
+ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row);
 void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow);
 struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor);
 void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef);
diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c
index 1e2f5fa..6289e34 100644
--- a/dlls/riched20/table.c
+++ b/dlls/riched20/table.c
@@ -381,8 +381,8 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars)
   }
 }
 
-static ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
-                                         ME_DisplayItem *table_row)
+ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
+                                  ME_DisplayItem *table_row)
 {
   WCHAR endl = '\r', tab = '\t';
   ME_DisplayItem *run;
@@ -390,9 +390,13 @@ static ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
   int i;
 
   assert(table_row);
+  assert(table_row->type == diParagraph);
   if (!editor->bEmulateVersion10) { /* v4.1 */
     ME_DisplayItem *insertedCell, *para, *cell;
-    cell = ME_FindItemFwd(table_row, diCell);
+    if (table_row->member.para.nFlags & MEPF_ROWEND)
+      cell = ME_FindItemBack(table_row, diCell);
+    else
+      cell = ME_FindItemFwd(table_row, diCell);
     run = ME_GetTableRowEnd(table_row)->member.para.next_para;
     run = ME_FindItemFwd(run, diRun);
     editor->pCursors[0].pRun = run;




More information about the wine-cvs mailing list