riched20: Pass and return paragraph ptrs in the table append row function.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-10-21 10:05:55 +01:00 committed by Alexandre Julliard
parent 75433bc39b
commit f0783863f9
3 changed files with 70 additions and 66 deletions

View File

@ -2504,7 +2504,7 @@ static BOOL handle_enter(ME_TextEditor *editor)
if (para->member.para.nFlags & MEPF_ROWEND) if (para->member.para.nFlags & MEPF_ROWEND)
{ {
/* Add a new table row after this row. */ /* Add a new table row after this row. */
para = ME_AppendTableRow(editor, para); para = para_get_di( table_append_row( editor, &para->member.para ) );
para = para->member.para.next_para; para = para->member.para.next_para;
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
@ -2552,7 +2552,7 @@ static BOOL handle_enter(ME_TextEditor *editor)
if (from == to) if (from == to)
{ {
ME_ContinueCoalescingTransaction(editor); ME_ContinueCoalescingTransaction(editor);
para = ME_AppendTableRow(editor, para); para = para_get_di( table_append_row( editor, &para->member.para ) );
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
@ -2583,7 +2583,7 @@ static BOOL handle_enter(ME_TextEditor *editor)
else else
{ {
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
para = ME_AppendTableRow(editor, para); para = para_get_di( table_append_row( editor, &para->member.para ) );
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;

View File

@ -284,12 +284,12 @@ ME_DisplayItem *ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
ME_DisplayItem *para) DECLSPEC_HIDDEN; ME_DisplayItem *para) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_InsertTableCellFromCursor(ME_TextEditor *editor) DECLSPEC_HIDDEN; ME_DisplayItem *ME_InsertTableCellFromCursor(ME_TextEditor *editor) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_InsertTableRowEndFromCursor(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_outer_para( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Paragraph *table_row_end( 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; ME_Paragraph *table_row_start( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Paragraph *table_outer_para( ME_Paragraph *para ) DECLSPEC_HIDDEN;
void ME_CheckTablesForCorruption(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_CheckTablesForCorruption(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nChars) 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;
void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) DECLSPEC_HIDDEN; void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) DECLSPEC_HIDDEN;
void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor) DECLSPEC_HIDDEN;
struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor) DECLSPEC_HIDDEN; struct RTFTable *ME_MakeTableDef(ME_TextEditor *editor) DECLSPEC_HIDDEN;

View File

@ -398,98 +398,98 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nC
} }
} }
ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_Paragraph* table_append_row( ME_TextEditor *editor, ME_Paragraph *table_row )
ME_DisplayItem *table_row)
{ {
WCHAR endl = '\r', tab = '\t'; WCHAR endl = '\r', tab = '\t';
ME_DisplayItem *run; ME_Run *run;
PARAFORMAT2 *pFmt; PARAFORMAT2 *pFmt;
int i; int i;
assert(table_row); assert(table_row);
assert(table_row->type == diParagraph); if (!editor->bEmulateVersion10) /* v4.1 */
if (!editor->bEmulateVersion10) { /* v4.1 */ {
ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd; ME_DisplayItem *insertedCell, *cell;
cell = ME_FindItemFwd( para_get_di( table_row_start( &table_row->member.para ) ), diCell ); ME_Paragraph *para, *prev_table_end;
prevTableEnd = para_get_di( table_row_end( &table_row->member.para ) );
para = prevTableEnd->member.para.next_para; cell = ME_FindItemFwd( para_get_di( table_row_start( table_row ) ), diCell );
run = ME_FindItemFwd(para, diRun); prev_table_end = table_row_end( table_row );
editor->pCursors[0].pPara = para; para = para_next( prev_table_end );
editor->pCursors[0].pRun = run; run = para_first_run( para );
editor->pCursors[0].pPara = para_get_di( para );
editor->pCursors[0].pRun = run_get_di( run );
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
para = ME_InsertTableRowStartFromCursor(editor); para = &ME_InsertTableRowStartFromCursor(editor)->member.para;
insertedCell = ME_FindItemFwd(para, diCell); insertedCell = ME_FindItemFwd( para_get_di( para ), diCell );
/* Copy cell properties */ /* Copy cell properties */
insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary; insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
insertedCell->member.cell.border = cell->member.cell.border; insertedCell->member.cell.border = cell->member.cell.border;
while (cell->member.cell.next_cell) { while (cell->member.cell.next_cell)
{
cell = cell->member.cell.next_cell; cell = cell->member.cell.next_cell;
para = ME_InsertTableCellFromCursor(editor); para = &ME_InsertTableCellFromCursor( editor )->member.para;
insertedCell = ME_FindItemBack(para, diCell); insertedCell = ME_FindItemBack( para_get_di( para ), diCell );
/* Copy cell properties */ /* Copy cell properties */
insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary; insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
insertedCell->member.cell.border = cell->member.cell.border; insertedCell->member.cell.border = cell->member.cell.border;
}; };
para = ME_InsertTableRowEndFromCursor(editor); para = &ME_InsertTableRowEndFromCursor(editor)->member.para;
para->member.para.fmt = prevTableEnd->member.para.fmt; para->fmt = prev_table_end->fmt;
/* return the table row start for the inserted paragraph */ /* return the table row start for the inserted paragraph */
return ME_FindItemFwd(cell, diParagraph)->member.para.next_para; return para_next( &ME_FindItemFwd( cell, diParagraph )->member.para );
} else { /* v1.0 - 3.0 */ }
run = ME_FindItemBack(table_row->member.para.next_para, diRun); else /* v1.0 - 3.0 */
pFmt = &table_row->member.para.fmt; {
run = para_end_run( table_row );
pFmt = &table_row->fmt;
assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE); assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE);
editor->pCursors[0].pPara = table_row; editor->pCursors[0].pPara = para_get_di( table_row );
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run_get_di( run );
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
ME_InsertTextFromCursor(editor, 0, &endl, 1, run->member.run.style); ME_InsertTextFromCursor( editor, 0, &endl, 1, run->style );
run = editor->pCursors[0].pRun; run = &editor->pCursors[0].pRun->member.run;
for (i = 0; i < pFmt->cTabCount; i++) { for (i = 0; i < pFmt->cTabCount; i++)
ME_InsertTextFromCursor(editor, 0, &tab, 1, run->member.run.style); ME_InsertTextFromCursor(editor, 0, &tab, 1, run->style);
}
return table_row->member.para.next_para; return para_next( table_row );
} }
} }
/* Selects the next table cell or appends a new table row if at end of table */ /* Selects the next table cell or appends a new table row if at end of table */
static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, static void ME_SelectOrInsertNextCell( ME_TextEditor *editor, ME_DisplayItem *run )
ME_DisplayItem *run)
{ {
ME_DisplayItem *para = ME_GetParagraph(run); ME_Paragraph *para = run->member.run.para;
int i; int i;
assert(run && run->type == diRun); assert(run && run->type == diRun);
assert(ME_IsInTable(run)); assert(ME_IsInTable(run));
if (!editor->bEmulateVersion10) { /* v4.1 */ if (!editor->bEmulateVersion10) /* v4.1 */
{
ME_DisplayItem *cell; ME_DisplayItem *cell;
/* Get the initial cell */ /* Get the initial cell */
if (para->member.para.nFlags & MEPF_ROWSTART) { if (para->nFlags & MEPF_ROWSTART) cell = para_next( para )->pCell;
cell = para->member.para.next_para->member.para.pCell; else if (para->nFlags & MEPF_ROWEND) cell = para_prev( para )->pCell;
} else if (para->member.para.nFlags & MEPF_ROWEND) { else cell = para->pCell;
cell = para->member.para.prev_para->member.para.pCell;
} else {
cell = para->member.para.pCell;
}
assert(cell); assert(cell);
/* Get the next cell. */ /* Get the next cell. */
if (cell->member.cell.next_cell && if (cell->member.cell.next_cell &&
cell->member.cell.next_cell->member.cell.next_cell) cell->member.cell.next_cell->member.cell.next_cell)
{ {
cell = cell->member.cell.next_cell; cell = cell->member.cell.next_cell;
} else { } else {
para = table_row_end( &ME_FindItemFwd( cell, diParagraph )->member.para )->next_para; para = para_next( table_row_end( &ME_FindItemFwd( cell, diParagraph )->member.para ) );
assert(para); if (para->nFlags & MEPF_ROWSTART) cell = para_next( para )->pCell;
if (para->member.para.nFlags & MEPF_ROWSTART) { else
cell = para->member.para.next_para->member.para.pCell; {
} else {
/* Insert row */ /* Insert row */
para = para->member.para.prev_para; para = para_prev( para );
para = ME_AppendTableRow( editor, para_get_di( table_row_start( &para->member.para ) ) ); para = table_append_row( editor, table_row_start( para ) );
/* Put cursor at the start of the new table row */ /* Put cursor at the start of the new table row */
para = para->member.para.next_para; para = para_next( para );
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para_get_di( para );
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = run_get_di( para_first_run( para ) );
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
ME_WrapMarkedParagraphs(editor); ME_WrapMarkedParagraphs(editor);
@ -506,7 +506,9 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
editor->pCursors[0].pPara = ME_GetParagraph(editor->pCursors[0].pRun); editor->pCursors[0].pPara = ME_GetParagraph(editor->pCursors[0].pRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
assert(editor->pCursors[1].pRun); assert(editor->pCursors[1].pRun);
} else { /* v1.0 - 3.0 */ }
else /* v1.0 - 3.0 */
{
if (run->member.run.nFlags & MERF_ENDPARA && if (run->member.run.nFlags & MERF_ENDPARA &&
ME_IsInTable(ME_FindItemFwd(run, diParagraphOrEnd))) ME_IsInTable(ME_FindItemFwd(run, diParagraphOrEnd)))
{ {
@ -520,21 +522,23 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
run = ME_FindItemFwd(run, diRunOrParagraphOrEnd); run = ME_FindItemFwd(run, diRunOrParagraphOrEnd);
if (run->type != diRun) if (run->type != diRun)
{ {
para = run; para = &run->member.para;
if (ME_IsInTable(para)) if (para_in_table( para ))
{ {
run = ME_FindItemFwd(para, diRun); run = run_get_di( para_first_run( para ) );
assert(run); assert(run);
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para_get_di( para );
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
i = 1; i = 1;
} else { }
else
{
/* Insert table row */ /* Insert table row */
para = ME_AppendTableRow(editor, para->member.para.prev_para); para = table_append_row( editor, para_prev( para ) );
/* Put cursor at the start of the new table row */ /* Put cursor at the start of the new table row */
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para_get_di( para );
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = run_get_di( para_first_run( para ) );
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
ME_WrapMarkedParagraphs(editor); ME_WrapMarkedParagraphs(editor);