riched20: Use cell ptrs in the rtf parsing code.

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-22 12:46:48 +01:00 committed by Alexandre Julliard
parent 670dadf719
commit 431ee50875
4 changed files with 55 additions and 19 deletions

View File

@ -987,8 +987,9 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
/* else fall through since v4.1 treats rtfNestRow and rtfRow the same */ /* else fall through since v4.1 treats rtfNestRow and rtfRow the same */
case rtfRow: case rtfRow:
{ {
ME_DisplayItem *cell, *run; ME_DisplayItem *run;
ME_Paragraph *para; ME_Paragraph *para;
ME_Cell *cell;
int i; int i;
if (!tableDef) if (!tableDef)
@ -1004,44 +1005,44 @@ void ME_RTFSpecialCharHook(RTF_Info *info)
info->nestingLevel++; info->nestingLevel++;
} }
para = tableDef->row_start; para = tableDef->row_start;
cell = ME_FindItemFwd( para_get_di( para ), diCell ); cell = table_row_first_cell( para );
assert(cell && !cell->member.cell.prev_cell); assert( cell && !cell_prev( cell ) );
if (tableDef->numCellsDefined < 1) if (tableDef->numCellsDefined < 1)
{ {
/* 2000 twips appears to be the cell size that native richedit uses /* 2000 twips appears to be the cell size that native richedit uses
* when no cell sizes are specified. */ * when no cell sizes are specified. */
const int defaultCellSize = 2000; const int default_size = 2000;
int nRightBoundary = defaultCellSize; int right_boundary = default_size;
cell->member.cell.nRightBoundary = nRightBoundary; cell->nRightBoundary = right_boundary;
while (cell->member.cell.next_cell) { while (cell_next( cell ))
cell = cell->member.cell.next_cell; {
nRightBoundary += defaultCellSize; cell = cell_next( cell );
cell->member.cell.nRightBoundary = nRightBoundary; right_boundary += default_size;
cell->nRightBoundary = right_boundary;
} }
para = table_insert_cell( info->editor, info->editor->pCursors ); para = table_insert_cell( info->editor, info->editor->pCursors );
cell = para->pCell; cell = para_cell( para );
cell->member.cell.nRightBoundary = nRightBoundary; cell->nRightBoundary = right_boundary;
} }
else else
{ {
for (i = 0; i < tableDef->numCellsDefined; i++) for (i = 0; i < tableDef->numCellsDefined; i++)
{ {
RTFCell *cellDef = &tableDef->cells[i]; RTFCell *cellDef = &tableDef->cells[i];
cell->member.cell.nRightBoundary = cellDef->rightBoundary; cell->nRightBoundary = cellDef->rightBoundary;
ME_ApplyBorderProperties(info, &cell->member.cell.border, ME_ApplyBorderProperties( info, &cell->border, cellDef->border );
cellDef->border); cell = cell_next( cell );
cell = cell->member.cell.next_cell;
if (!cell) if (!cell)
{ {
para = table_insert_cell( info->editor, info->editor->pCursors ); para = table_insert_cell( info->editor, info->editor->pCursors );
cell = para->pCell; cell = para_cell( para );
} }
} }
/* Cell for table row delimiter is empty */ /* Cell for table row delimiter is empty */
cell->member.cell.nRightBoundary = tableDef->cells[i-1].rightBoundary; cell->nRightBoundary = tableDef->cells[i - 1].rightBoundary;
} }
run = ME_FindItemFwd(cell, diRun); run = ME_FindItemFwd( cell_get_di( cell) , diRun );
if (info->editor->pCursors[0].pRun != run || if (info->editor->pCursors[0].pRun != run ||
info->editor->pCursors[0].nOffset) info->editor->pCursors[0].nOffset)
{ {

View File

@ -204,6 +204,7 @@ void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPE
void ME_MarkAllForWrapping(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_MarkAllForWrapping(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN; void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN;
int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN; int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN;
ME_Cell *para_cell( ME_Paragraph *para ) DECLSPEC_HIDDEN;
void para_destroy( ME_TextEditor *editor, ME_Paragraph *item ) DECLSPEC_HIDDEN; void para_destroy( ME_TextEditor *editor, ME_Paragraph *item ) DECLSPEC_HIDDEN;
ME_Run *para_end_run( ME_Paragraph *para ) DECLSPEC_HIDDEN; ME_Run *para_end_run( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Run *para_first_run( ME_Paragraph *para ) DECLSPEC_HIDDEN; ME_Run *para_first_run( ME_Paragraph *para ) DECLSPEC_HIDDEN;
@ -279,6 +280,8 @@ ME_Paragraph *editor_first_para( ME_TextEditor *editor ) DECLSPEC_HIDDEN;
/* table.c */ /* table.c */
BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN; BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN;
ME_Cell *cell_next( ME_Cell *cell ) DECLSPEC_HIDDEN;
ME_Cell *cell_prev( ME_Cell *cell ) DECLSPEC_HIDDEN;
ME_Paragraph *table_append_row( ME_TextEditor *editor, ME_Paragraph *table_row ) DECLSPEC_HIDDEN; ME_Paragraph *table_append_row( ME_TextEditor *editor, ME_Paragraph *table_row ) DECLSPEC_HIDDEN;
ME_Paragraph *table_insert_cell( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN; ME_Paragraph *table_insert_cell( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
ME_Paragraph *table_insert_row_end( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN; ME_Paragraph *table_insert_row_end( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
@ -286,6 +289,7 @@ ME_Paragraph *table_insert_row_start( ME_TextEditor *editor, ME_Cursor *cursor )
ME_Paragraph *table_insert_row_start_at_para( ME_TextEditor *editor, ME_Paragraph *para ) 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_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_Cell *table_row_first_cell( 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;
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;
@ -293,6 +297,11 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) DECLSPEC_HID
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;
void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef) DECLSPEC_HIDDEN; void ME_InitTableDef(ME_TextEditor *editor, struct RTFTable *tableDef) DECLSPEC_HIDDEN;
static inline ME_DisplayItem *cell_get_di(ME_Cell *cell)
{
return (ME_DisplayItem *)((ptrdiff_t)cell - offsetof(ME_DisplayItem, member));
}
/* txthost.c */ /* txthost.c */
ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion10) DECLSPEC_HIDDEN; ITextHost *ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion10) DECLSPEC_HIDDEN;

View File

@ -124,6 +124,12 @@ BOOL para_in_table( ME_Paragraph *para )
return para->fmt.wEffects & PFE_TABLE; return para->fmt.wEffects & PFE_TABLE;
} }
ME_Cell *para_cell( ME_Paragraph *para )
{
if (!para->pCell) return NULL;
return &para->pCell->member.cell;
}
void ME_MakeFirstParagraph(ME_TextEditor *editor) void ME_MakeFirstParagraph(ME_TextEditor *editor)
{ {
static const WCHAR cr_lf[] = {'\r','\n',0}; static const WCHAR cr_lf[] = {'\r','\n',0};

View File

@ -172,6 +172,26 @@ ME_Paragraph* table_outer_para( ME_Paragraph *para )
return para; return para;
} }
ME_Cell *table_row_first_cell( ME_Paragraph *para )
{
if (!para_in_table( para )) return NULL;
para = para_next( table_row_start( para ) );
return para_cell( para );
}
ME_Cell *cell_next( ME_Cell *cell )
{
if (!cell->next_cell) return NULL;
return &cell->next_cell->member.cell;
}
ME_Cell *cell_prev( ME_Cell *cell )
{
if (!cell->prev_cell) return NULL;
return &cell->prev_cell->member.cell;
}
/* Make a bunch of assertions to make sure tables haven't been corrupted. /* 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 * These invariants may not hold true in the middle of streaming in rich text