[PATCH 1/5] riched20: Return a para ptr from the insert start table row functions.

Huw Davies huw at codeweavers.com
Thu Oct 22 06:46:46 CDT 2020


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/riched20/editor.c | 191 +++++++++++++++++++++--------------------
 dlls/riched20/editor.h |   5 +-
 dlls/riched20/rtf.h    |   4 +-
 dlls/riched20/table.c  |  63 +++++++-------
 4 files changed, 131 insertions(+), 132 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 5cf1ad35f59..36c2e108b2d 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -585,27 +585,29 @@ void ME_RTFParAttrHook(RTF_Info *info)
 
     if (!info->editor->bEmulateVersion10) /* v4.1 */
     {
-      if (info->tableDef && info->tableDef->tableRowStart &&
-          info->tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
+      if (info->tableDef && info->tableDef->row_start &&
+          info->tableDef->row_start->nFlags & MEPF_ROWEND)
       {
         ME_Cursor cursor;
-        ME_DisplayItem *para;
+        ME_Paragraph *para;
         /* We are just after a table row. */
         RTFFlushOutputBuffer(info);
         cursor = info->editor->pCursors[0];
-        para = cursor.pPara;
-        if (para  == info->tableDef->tableRowStart->member.para.next_para
+        para = &cursor.pPara->member.para;
+        if (para == para_next( info->tableDef->row_start )
             && !cursor.nOffset && !cursor.pRun->member.run.nCharOfs)
         {
           /* Since the table row end, no text has been inserted, and the \intbl
            * control word has not be used.  We can confirm that we are not in a
            * table anymore.
            */
-          info->tableDef->tableRowStart = NULL;
+          info->tableDef->row_start = NULL;
           info->canInheritInTbl = FALSE;
         }
       }
-    } else { /* v1.0 - v3.0 */
+    }
+    else /* v1.0 - v3.0 */
+    {
       info->fmt.dwMask |= PFM_TABLE;
       info->fmt.wEffects &= ~PFE_TABLE;
     }
@@ -613,26 +615,26 @@ void ME_RTFParAttrHook(RTF_Info *info)
   case rtfNestLevel:
     if (!info->editor->bEmulateVersion10) /* v4.1 */
     {
-      while (info->rtfParam > info->nestingLevel) {
+      while (info->rtfParam > info->nestingLevel)
+      {
         RTFTable *tableDef = heap_alloc_zero(sizeof(*tableDef));
         tableDef->parent = info->tableDef;
         info->tableDef = tableDef;
 
         RTFFlushOutputBuffer(info);
-        if (tableDef->tableRowStart &&
-            tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
+        if (tableDef->row_start && tableDef->row_start->nFlags & MEPF_ROWEND)
+        {
+          ME_Paragraph *para = para_next( tableDef->row_start );
+          tableDef->row_start = table_insert_row_start_at_para( info->editor, para );
+        }
+        else
         {
-          ME_DisplayItem *para = tableDef->tableRowStart;
-          para = para->member.para.next_para;
-          para = ME_InsertTableRowStartAtParagraph(info->editor, para);
-          tableDef->tableRowStart = para;
-        } else {
           ME_Cursor cursor;
           WCHAR endl = '\r';
           cursor = info->editor->pCursors[0];
           if (cursor.nOffset || cursor.pRun->member.run.nCharOfs)
             ME_InsertTextFromCursor(info->editor, 0, &endl, 1, info->style);
-          tableDef->tableRowStart = ME_InsertTableRowStartFromCursor(info->editor);
+          tableDef->row_start = table_insert_row_start( info->editor, info->editor->pCursors );
         }
 
         info->nestingLevel++;
@@ -647,21 +649,19 @@ void ME_RTFParAttrHook(RTF_Info *info)
       if (info->nestingLevel < 1)
       {
         RTFTable *tableDef;
+        ME_Paragraph *para;
+
         if (!info->tableDef)
             info->tableDef = heap_alloc_zero(sizeof(*info->tableDef));
         tableDef = info->tableDef;
         RTFFlushOutputBuffer(info);
-        if (tableDef->tableRowStart &&
-            tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
-        {
-          ME_DisplayItem *para = tableDef->tableRowStart;
-          para = para->member.para.next_para;
-          para = ME_InsertTableRowStartAtParagraph(info->editor, para);
-          tableDef->tableRowStart = para;
-        }
+        if (tableDef->row_start && tableDef->row_start->nFlags & MEPF_ROWEND)
+          para = para_next( tableDef->row_start );
         else
-          tableDef->tableRowStart = ME_InsertTableRowStartAtParagraph( info->editor,
-                                                                       info->editor->pCursors[0].pPara );
+          para = &info->editor->pCursors[0].pPara->member.para;
+
+        tableDef->row_start = table_insert_row_start_at_para( info->editor, para );
+
         info->nestingLevel = 1;
         info->canInheritInTbl = TRUE;
       }
@@ -956,25 +956,24 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
       if (!tableDef)
         break;
       RTFFlushOutputBuffer(info);
-      if (!info->editor->bEmulateVersion10) { /* v4.1 */
-        if (tableDef->tableRowStart)
+      if (!info->editor->bEmulateVersion10) /* v4.1 */
+      {
+        if (tableDef->row_start)
         {
-          if (!info->nestingLevel &&
-              tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
+          if (!info->nestingLevel && tableDef->row_start->nFlags & MEPF_ROWEND)
           {
-            ME_DisplayItem *para = tableDef->tableRowStart;
-            para = para->member.para.next_para;
-            para = ME_InsertTableRowStartAtParagraph(info->editor, para);
-            tableDef->tableRowStart = para;
+            ME_Paragraph *para = para_next( tableDef->row_start );
+            tableDef->row_start = table_insert_row_start_at_para( info->editor, para );
             info->nestingLevel = 1;
           }
           ME_InsertTableCellFromCursor(info->editor);
         }
-      } else { /* v1.0 - v3.0 */
-        ME_DisplayItem *para = info->editor->pCursors[0].pPara;
-        PARAFORMAT2 *pFmt = &para->member.para.fmt;
-        if (pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE &&
-            tableDef->numCellsInserted < tableDef->numCellsDefined)
+      }
+      else /* v1.0 - v3.0 */
+      {
+        ME_Paragraph *para = &info->editor->pCursors[0].pPara->member.para;
+
+        if (para_in_table( para ) && tableDef->numCellsInserted < tableDef->numCellsDefined)
         {
           WCHAR tab = '\t';
           ME_InsertTextFromCursor(info->editor, 0, &tab, 1, info->style);
@@ -988,26 +987,24 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
       /* else fall through since v4.1 treats rtfNestRow and rtfRow the same */
     case rtfRow:
     {
-      ME_DisplayItem *para, *cell, *run;
+      ME_DisplayItem *cell, *run;
+      ME_Paragraph *para;
       int i;
 
       if (!tableDef)
         break;
       RTFFlushOutputBuffer(info);
-      if (!info->editor->bEmulateVersion10) { /* v4.1 */
-        if (!tableDef->tableRowStart)
-          break;
-        if (!info->nestingLevel &&
-            tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
+      if (!info->editor->bEmulateVersion10) /* v4.1 */
+      {
+        if (!tableDef->row_start) break;
+        if (!info->nestingLevel && tableDef->row_start->nFlags & MEPF_ROWEND)
         {
-          para = tableDef->tableRowStart;
-          para = para->member.para.next_para;
-          para = ME_InsertTableRowStartAtParagraph(info->editor, para);
-          tableDef->tableRowStart = para;
+          para = para_next( tableDef->row_start );
+          tableDef->row_start = table_insert_row_start_at_para( info->editor, para );
           info->nestingLevel++;
         }
-        para = tableDef->tableRowStart;
-        cell = ME_FindItemFwd(para, diCell);
+        para = tableDef->row_start;
+        cell = ME_FindItemFwd( para_get_di( para ), diCell );
         assert(cell && !cell->member.cell.prev_cell);
         if (tableDef->numCellsDefined < 1)
         {
@@ -1021,10 +1018,12 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
             nRightBoundary += defaultCellSize;
             cell->member.cell.nRightBoundary = nRightBoundary;
           }
-          para = ME_InsertTableCellFromCursor(info->editor);
-          cell = para->member.para.pCell;
+          para = &ME_InsertTableCellFromCursor(info->editor)->member.para;
+          cell = para->pCell;
           cell->member.cell.nRightBoundary = nRightBoundary;
-        } else {
+        }
+        else
+        {
           for (i = 0; i < tableDef->numCellsDefined; i++)
           {
             RTFCell *cellDef = &tableDef->cells[i];
@@ -1034,8 +1033,8 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
             cell = cell->member.cell.next_cell;
             if (!cell)
             {
-              para = ME_InsertTableCellFromCursor(info->editor);
-              cell = para->member.para.pCell;
+              para = &ME_InsertTableCellFromCursor(info->editor)->member.para;
+              cell = para->pCell;
             }
           }
           /* Cell for table row delimiter is empty */
@@ -1057,45 +1056,47 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
                                 nChars, TRUE);
         }
 
-        para = ME_InsertTableRowEndFromCursor(info->editor);
-        para->member.para.fmt.dxOffset = abs(info->tableDef->gapH);
-        para->member.para.fmt.dxStartIndent = info->tableDef->leftEdge;
-        ME_ApplyBorderProperties(info, &para->member.para.border,
-                                 tableDef->border);
+        para = &ME_InsertTableRowEndFromCursor(info->editor)->member.para;
+        para->fmt.dxOffset = abs(info->tableDef->gapH);
+        para->fmt.dxStartIndent = info->tableDef->leftEdge;
+        ME_ApplyBorderProperties( info, &para->border, tableDef->border );
         info->nestingLevel--;
         if (!info->nestingLevel)
         {
-          if (info->canInheritInTbl) {
-            tableDef->tableRowStart = para;
-          } else {
-            while (info->tableDef) {
+          if (info->canInheritInTbl) tableDef->row_start = para;
+          else
+          {
+            while (info->tableDef)
+            {
               tableDef = info->tableDef;
               info->tableDef = tableDef->parent;
               heap_free(tableDef);
             }
           }
-        } else {
+        }
+        else
+        {
           info->tableDef = tableDef->parent;
           heap_free(tableDef);
         }
-      } else { /* v1.0 - v3.0 */
+      }
+      else /* v1.0 - v3.0 */
+      {
         WCHAR endl = '\r';
-        ME_DisplayItem *para = info->editor->pCursors[0].pPara;
-        PARAFORMAT2 *pFmt = &para->member.para.fmt;
-        pFmt->dxOffset = info->tableDef->gapH;
-        pFmt->dxStartIndent = info->tableDef->leftEdge;
 
-        ME_ApplyBorderProperties(info, &para->member.para.border,
-                                 tableDef->border);
+        para = &info->editor->pCursors[0].pPara->member.para;
+        para->fmt.dxOffset = info->tableDef->gapH;
+        para->fmt.dxStartIndent = info->tableDef->leftEdge;
+
+        ME_ApplyBorderProperties( info, &para->border, tableDef->border );
         while (tableDef->numCellsInserted < tableDef->numCellsDefined)
         {
           WCHAR tab = '\t';
           ME_InsertTextFromCursor(info->editor, 0, &tab, 1, info->style);
           tableDef->numCellsInserted++;
         }
-        pFmt->cTabCount = min(tableDef->numCellsDefined, MAX_TAB_STOPS);
-        if (!tableDef->numCellsDefined)
-          pFmt->wEffects &= ~PFE_TABLE;
+        para->fmt.cTabCount = min(tableDef->numCellsDefined, MAX_TAB_STOPS);
+        if (!tableDef->numCellsDefined) para->fmt.wEffects &= ~PFE_TABLE;
         ME_InsertTextFromCursor(info->editor, 0, &endl, 1, info->style);
         tableDef->numCellsInserted = 0;
       }
@@ -1103,13 +1104,13 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
     }
     case rtfTab:
     case rtfPar:
-      if (info->editor->bEmulateVersion10) { /* v1.0 - 3.0 */
-        ME_DisplayItem *para;
-        PARAFORMAT2 *pFmt;
+      if (info->editor->bEmulateVersion10) /* v1.0 - 3.0 */
+      {
+        ME_Paragraph *para;
+
         RTFFlushOutputBuffer(info);
-        para = info->editor->pCursors[0].pPara;
-        pFmt = &para->member.para.fmt;
-        if (pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
+        para = &info->editor->pCursors[0].pPara->member.para;
+        if (para_in_table( para ))
         {
           /* rtfPar is treated like a space within a table. */
           info->rtfClass = rtfText;
@@ -1695,13 +1696,14 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
       /* do the parsing */
       RTFRead(&parser);
       RTFFlushOutputBuffer(&parser);
-      if (!editor->bEmulateVersion10) { /* v4.1 */
-        if (parser.tableDef && parser.tableDef->tableRowStart &&
+      if (!editor->bEmulateVersion10) /* v4.1 */
+      {
+        if (parser.tableDef && parser.tableDef->row_start &&
             (parser.nestingLevel > 0 || parser.canInheritInTbl))
         {
           /* Delete any incomplete table row at the end of the rich text. */
           int nOfs, nChars;
-          ME_DisplayItem *para;
+          ME_Paragraph *para;
 
           parser.rtfMinor = rtfRow;
           /* Complete the table row before deleting it.
@@ -1712,23 +1714,24 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
           {
             while (parser.nestingLevel > 1)
               ME_RTFSpecialCharHook(&parser); /* Decrements nestingLevel */
-            para = parser.tableDef->tableRowStart;
+            para = parser.tableDef->row_start;
             ME_RTFSpecialCharHook(&parser);
-          } else {
-            para = parser.tableDef->tableRowStart;
+          }
+          else
+          {
+            para = parser.tableDef->row_start;
             ME_RTFSpecialCharHook(&parser);
-            assert(para->member.para.nFlags & MEPF_ROWEND);
-            para = para->member.para.next_para;
+            assert( para->nFlags & MEPF_ROWEND );
+            para = para_next( para );
           }
 
-          editor->pCursors[1].pPara = para;
-          editor->pCursors[1].pRun = ME_FindItemFwd(para, diRun);
+          editor->pCursors[1].pPara = para_get_di( para );
+          editor->pCursors[1].pRun = run_get_di( para_first_run( para ) );
           editor->pCursors[1].nOffset = 0;
           nOfs = ME_GetCursorOfs(&editor->pCursors[1]);
           nChars = ME_GetCursorOfs(&editor->pCursors[0]) - nOfs;
           ME_InternalDeleteText(editor, &editor->pCursors[1], nChars, TRUE);
-          if (parser.tableDef)
-            parser.tableDef->tableRowStart = NULL;
+          if (parser.tableDef) parser.tableDef->row_start = NULL;
         }
       }
       ME_CheckTablesForCorruption(editor);
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index b1cd75f2946..e9a7a77e234 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -279,12 +279,11 @@ ME_Paragraph *editor_first_para( ME_TextEditor *editor ) DECLSPEC_HIDDEN;
 
 /* table.c */
 BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN;
-ME_DisplayItem *ME_InsertTableRowStartFromCursor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
-ME_DisplayItem *ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
-                                                  ME_DisplayItem *para) DECLSPEC_HIDDEN;
 ME_DisplayItem *ME_InsertTableCellFromCursor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 ME_DisplayItem *ME_InsertTableRowEndFromCursor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
 ME_Paragraph *table_append_row( ME_TextEditor *editor, ME_Paragraph *table_row ) DECLSPEC_HIDDEN;
+ME_Paragraph *table_insert_row_start( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
+ME_Paragraph *table_insert_row_start_at_para( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN;
 ME_Paragraph *table_outer_para( ME_Paragraph *para ) DECLSPEC_HIDDEN;
 ME_Paragraph *table_row_end( ME_Paragraph *para ) DECLSPEC_HIDDEN;
 ME_Paragraph *table_row_start( ME_Paragraph *para ) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/rtf.h b/dlls/riched20/rtf.h
index 66d88b55da9..35a0ee878e9 100644
--- a/dlls/riched20/rtf.h
+++ b/dlls/riched20/rtf.h
@@ -1035,10 +1035,10 @@ struct RTFTable
 	int numCellsInserted;
 
 	/* v4.1 */
-	/* tableRowStart may be the start row paragraph of the table row,
+	/* row_start may be the start row paragraph of the table row,
 	 * or it may store the end of the previous row if it may still be
 	 * continued, otherwise NULL is stored. */
-	ME_DisplayItem *tableRowStart;
+	ME_Paragraph *row_start;
 
 	/* Table definitions are stored as a stack to support nested tables. */
 	RTFTable *parent;
diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c
index 14fdf6eb73a..1b735638606 100644
--- a/dlls/riched20/table.c
+++ b/dlls/riched20/table.c
@@ -73,44 +73,41 @@ static ME_Paragraph* table_insert_end_para( ME_TextEditor *editor, ME_Cursor *cu
     return para;
 }
 
-ME_DisplayItem* ME_InsertTableRowStartFromCursor(ME_TextEditor *editor)
+ME_Paragraph* table_insert_row_start( ME_TextEditor *editor, ME_Cursor *cursor )
 {
     ME_Paragraph *para;
 
-    para = table_insert_end_para( editor, editor->pCursors, cr_lf, 2, MEPF_ROWSTART );
-    return para_get_di( para_prev( para ) );
+    para = table_insert_end_para( editor, cursor, cr_lf, 2, MEPF_ROWSTART );
+    return para_prev( para );
 }
 
-ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
-                                                  ME_DisplayItem *para)
+ME_Paragraph* table_insert_row_start_at_para( ME_TextEditor *editor, ME_Paragraph *para )
 {
-  ME_DisplayItem *prev_para, *end_para;
-  ME_Cursor savedCursor = editor->pCursors[0];
-  ME_DisplayItem *startRowPara;
-  editor->pCursors[0].pPara = para;
-  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
-  editor->pCursors[0].nOffset = 0;
-  editor->pCursors[1] = editor->pCursors[0];
-  startRowPara = ME_InsertTableRowStartFromCursor(editor);
-  savedCursor.pPara = ME_GetParagraph(savedCursor.pRun);
-  editor->pCursors[0] = savedCursor;
-  editor->pCursors[1] = editor->pCursors[0];
-
-  end_para = editor->pCursors[0].pPara->member.para.next_para;
-  prev_para = startRowPara->member.para.next_para;
-  para = prev_para->member.para.next_para;
-  while (para != end_para)
-  {
-    para->member.para.pCell = prev_para->member.para.pCell;
-    para->member.para.nFlags |= MEPF_CELL;
-    para->member.para.nFlags &= ~(MEPF_ROWSTART|MEPF_ROWEND);
-    para->member.para.fmt.dwMask |= PFM_TABLE|PFM_TABLEROWDELIMITER;
-    para->member.para.fmt.wEffects |= PFE_TABLE;
-    para->member.para.fmt.wEffects &= ~PFE_TABLEROWDELIMITER;
-    prev_para = para;
-    para = para->member.para.next_para;
-  }
-  return startRowPara;
+    ME_Paragraph *prev_para, *end_para, *start_row;
+    ME_Cursor cursor;
+
+    cursor.pPara = para_get_di( para );
+    cursor.pRun = run_get_di( para_first_run( para ) );
+    cursor.nOffset = 0;
+
+    start_row = table_insert_row_start( editor, &cursor );
+
+    end_para = para_next( &editor->pCursors[0].pPara->member.para );
+    prev_para = para_next( start_row );
+    para = para_next( prev_para );
+
+    while (para != end_para)
+    {
+        para->pCell = prev_para->pCell;
+        para->nFlags |= MEPF_CELL;
+        para->nFlags &= ~(MEPF_ROWSTART | MEPF_ROWEND);
+        para->fmt.dwMask |= PFM_TABLE | PFM_TABLEROWDELIMITER;
+        para->fmt.wEffects |= PFE_TABLE;
+        para->fmt.wEffects &= ~PFE_TABLEROWDELIMITER;
+        prev_para = para;
+        para = para_next( para );
+    }
+    return start_row;
 }
 
 /* Inserts a diCell and starts a new paragraph for the next cell.
@@ -419,7 +416,7 @@ ME_Paragraph* table_append_row( ME_TextEditor *editor, ME_Paragraph *table_row )
     editor->pCursors[0].pRun = run_get_di( run );
     editor->pCursors[0].nOffset = 0;
     editor->pCursors[1] = editor->pCursors[0];
-    para = &ME_InsertTableRowStartFromCursor(editor)->member.para;
+    para = table_insert_row_start( editor, editor->pCursors );
     insertedCell = ME_FindItemFwd( para_get_di( para ), diCell );
     /* Copy cell properties */
     insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
-- 
2.23.0




More information about the wine-devel mailing list