Commit 1bda5913 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Use ME_Paragraph ptrs in a few of the table functions.

parent c3e6cb5b
...@@ -1033,7 +1033,7 @@ static BOOL ME_FindPixelPos(ME_TextEditor *editor, int x, int y, ...@@ -1033,7 +1033,7 @@ static BOOL ME_FindPixelPos(ME_TextEditor *editor, int x, int y,
} }
else if (p->member.para.nFlags & MEPF_ROWSTART) else if (p->member.para.nFlags & MEPF_ROWSTART)
{ {
p = ME_GetTableRowEnd(p); p = para_get_di( table_row_end( &p->member.para ) );
} }
} }
/* find row */ /* find row */
...@@ -1304,7 +1304,7 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL ...@@ -1304,7 +1304,7 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL
pOldPara->member.para.pCell != pNewPara->member.para.pCell)) pOldPara->member.para.pCell != pNewPara->member.para.pCell))
{ {
/* Brought out of a cell */ /* Brought out of a cell */
pNewPara = ME_GetTableRowStart(pOldPara)->member.para.prev_para; pNewPara = table_row_start( &pOldPara->member.para )->prev_para;
if (pNewPara->type == diTextStart) if (pNewPara->type == diTextStart)
return; /* At the top, so don't go anywhere. */ return; /* At the top, so don't go anywhere. */
pItem = ME_FindItemFwd(pNewPara, diStartRow); pItem = ME_FindItemFwd(pNewPara, diStartRow);
...@@ -1335,7 +1335,7 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL ...@@ -1335,7 +1335,7 @@ ME_MoveCursorLines(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs, BOOL
pOldPara->member.para.pCell != pNewPara->member.para.pCell)) pOldPara->member.para.pCell != pNewPara->member.para.pCell))
{ {
/* Brought out of a cell */ /* Brought out of a cell */
pNewPara = ME_GetTableRowEnd(pOldPara)->member.para.next_para; pNewPara = table_row_end( &pOldPara->member.para )->next_para;
if (pNewPara->type == diTextEnd) if (pNewPara->type == diTextEnd)
return; /* At the bottom, so don't go anywhere. */ return; /* At the bottom, so don't go anywhere. */
pItem = ME_FindItemFwd(pNewPara, diStartRow); pItem = ME_FindItemFwd(pNewPara, diStartRow);
......
...@@ -211,6 +211,8 @@ int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN; ...@@ -211,6 +211,8 @@ int get_total_width(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void para_mark_rewrap( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN; void para_mark_rewrap( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN;
void para_mark_add( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN; void para_mark_add( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN;
void para_mark_remove( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN; void para_mark_remove( ME_TextEditor *editor, ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Paragraph *para_next( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_Paragraph *para_prev( 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;
static inline ME_DisplayItem *para_get_di(ME_Paragraph *para) static inline ME_DisplayItem *para_get_di(ME_Paragraph *para)
{ {
...@@ -273,9 +275,9 @@ ME_DisplayItem *ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor, ...@@ -273,9 +275,9 @@ 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_DisplayItem *ME_GetTableRowEnd(ME_DisplayItem *para) DECLSPEC_HIDDEN; ME_Paragraph *table_row_end( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para) DECLSPEC_HIDDEN; ME_Paragraph *table_row_start( ME_Paragraph *para ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_GetOuterParagraph(ME_DisplayItem *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; ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row) DECLSPEC_HIDDEN;
......
...@@ -778,10 +778,10 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph) ...@@ -778,10 +778,10 @@ static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
if (atBottom) { if (atBottom) {
int oldLeft = rc.left; int oldLeft = rc.left;
width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1); width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1);
paraAfterRow = ME_GetTableRowEnd(paragraph)->member.para.next_para; paraAfterRow = table_row_end( &paragraph->member.para )->next_para;
if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) { if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) {
ME_DisplayItem *nextEndCell; ME_DisplayItem *nextEndCell;
nextEndCell = ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow), diCell); nextEndCell = ME_FindItemBack( para_get_di( table_row_end( &paraAfterRow->member.para ) ), diCell );
assert(nextEndCell && !nextEndCell->member.cell.next_cell); assert(nextEndCell && !nextEndCell->member.cell.next_cell);
rc.left = c->pt.x + nextEndCell->member.cell.pt.x; rc.left = c->pt.x + nextEndCell->member.cell.pt.x;
/* FIXME: Native draws FROM the bottom of the table rather than /* FIXME: Native draws FROM the bottom of the table rather than
......
...@@ -55,6 +55,19 @@ void destroy_para(ME_TextEditor *editor, ME_DisplayItem *item) ...@@ -55,6 +55,19 @@ void destroy_para(ME_TextEditor *editor, ME_DisplayItem *item)
ME_DestroyDisplayItem(item); ME_DestroyDisplayItem(item);
} }
/* Note para_next/prev will return the start and end doc nodes */
ME_Paragraph *para_next( ME_Paragraph *para )
{
if (para->next_para) return &para->next_para->member.para;
return NULL;
}
ME_Paragraph *para_prev( ME_Paragraph *para )
{
if (para->prev_para) return &para->prev_para->member.para;
return NULL;
}
int get_total_width(ME_TextEditor *editor) int get_total_width(ME_TextEditor *editor)
{ {
ME_Paragraph *para; ME_Paragraph *para;
......
...@@ -133,52 +133,46 @@ ME_DisplayItem* ME_InsertTableRowEndFromCursor(ME_TextEditor *editor) ...@@ -133,52 +133,46 @@ ME_DisplayItem* ME_InsertTableRowEndFromCursor(ME_TextEditor *editor)
return para->member.para.prev_para; return para->member.para.prev_para;
} }
ME_DisplayItem* ME_GetTableRowEnd(ME_DisplayItem *para) ME_Paragraph* table_row_end( ME_Paragraph *para )
{ {
ME_DisplayItem *cell; ME_DisplayItem *cell;
assert(para); assert( para );
if (para->member.para.nFlags & MEPF_ROWEND) if (para->nFlags & MEPF_ROWEND) return para;
return para; if (para->nFlags & MEPF_ROWSTART) para = para_next( para );
if (para->member.para.nFlags & MEPF_ROWSTART) cell = para->pCell;
para = para->member.para.next_para;
cell = para->member.para.pCell;
assert(cell && cell->type == diCell); assert(cell && cell->type == diCell);
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_FindItemFwd(cell, diParagraph); para = &ME_FindItemFwd( cell, diParagraph )->member.para;
assert(para && para->member.para.nFlags & MEPF_ROWEND); assert( para && para->nFlags & MEPF_ROWEND );
return para; return para;
} }
ME_DisplayItem* ME_GetTableRowStart(ME_DisplayItem *para) ME_Paragraph* table_row_start( ME_Paragraph *para )
{ {
ME_DisplayItem *cell; ME_DisplayItem *cell;
assert(para); assert( para );
if (para->member.para.nFlags & MEPF_ROWSTART) if (para->nFlags & MEPF_ROWSTART) return para;
return para; if (para->nFlags & MEPF_ROWEND) para = para_prev( para );
if (para->member.para.nFlags & MEPF_ROWEND) cell = para->pCell;
para = para->member.para.prev_para;
cell = para->member.para.pCell;
assert(cell && cell->type == diCell); assert(cell && cell->type == diCell);
while (cell->member.cell.prev_cell) while (cell->member.cell.prev_cell)
cell = cell->member.cell.prev_cell; cell = cell->member.cell.prev_cell;
para = ME_FindItemBack(cell, diParagraph); para = &ME_FindItemBack( cell, diParagraph )->member.para;
assert(para && para->member.para.nFlags & MEPF_ROWSTART); assert( para && para->nFlags & MEPF_ROWSTART );
return para; return para;
} }
ME_DisplayItem* ME_GetOuterParagraph(ME_DisplayItem *para) ME_Paragraph* table_outer_para( ME_Paragraph *para )
{ {
if (para->member.para.nFlags & MEPF_ROWEND) if (para->nFlags & MEPF_ROWEND) para = para_prev( para );
para = para->member.para.prev_para; while (para->pCell)
while (para->member.para.pCell)
{ {
para = ME_GetTableRowStart(para); para = table_row_start( para );
if (!para->member.para.pCell) if (!para->pCell) break;
break; para = &ME_FindItemBack( para->pCell, diParagraph )->member.para;
para = ME_FindItemBack(para->member.para.pCell, diParagraph);
} }
return para; return para;
} }
...@@ -330,7 +324,7 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nC ...@@ -330,7 +324,7 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nC
while (!bTruancateDeletion && while (!bTruancateDeletion &&
next_para->member.para.nFlags & MEPF_ROWSTART) next_para->member.para.nFlags & MEPF_ROWSTART)
{ {
next_para = ME_GetTableRowEnd(next_para)->member.para.next_para; next_para = table_row_end( &next_para->member.para )->next_para;
if (next_para->member.para.nCharOfs > nOfs + *nChars) if (next_para->member.para.nCharOfs > nOfs + *nChars)
{ {
/* End of deletion is not past the end of the table row. */ /* End of deletion is not past the end of the table row. */
...@@ -416,8 +410,8 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ...@@ -416,8 +410,8 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
assert(table_row->type == diParagraph); assert(table_row->type == diParagraph);
if (!editor->bEmulateVersion10) { /* v4.1 */ if (!editor->bEmulateVersion10) { /* v4.1 */
ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd; ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd;
cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell); cell = ME_FindItemFwd( para_get_di( table_row_start( &table_row->member.para ) ), diCell );
prevTableEnd = ME_GetTableRowEnd(table_row); prevTableEnd = para_get_di( table_row_end( &table_row->member.para ) );
para = prevTableEnd->member.para.next_para; para = prevTableEnd->member.para.next_para;
run = ME_FindItemFwd(para, diRun); run = ME_FindItemFwd(para, diRun);
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para;
...@@ -484,15 +478,14 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -484,15 +478,14 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
{ {
cell = cell->member.cell.next_cell; cell = cell->member.cell.next_cell;
} else { } else {
para = ME_GetTableRowEnd(ME_FindItemFwd(cell, diParagraph)); para = table_row_end( &ME_FindItemFwd( cell, diParagraph )->member.para )->next_para;
para = para->member.para.next_para;
assert(para); assert(para);
if (para->member.para.nFlags & MEPF_ROWSTART) { if (para->member.para.nFlags & MEPF_ROWSTART) {
cell = para->member.para.next_para->member.para.pCell; cell = para->member.para.next_para->member.para.pCell;
} else { } else {
/* Insert row */ /* Insert row */
para = para->member.para.prev_para; para = para->member.para.prev_para;
para = ME_AppendTableRow(editor, ME_GetTableRowStart(para)); para = ME_AppendTableRow( editor, para_get_di( table_row_start( &para->member.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->member.para.next_para;
editor->pCursors[0].pPara = para; editor->pCursors[0].pPara = para;
......
...@@ -209,7 +209,7 @@ static void ME_BeginRow(ME_WrapContext *wc) ...@@ -209,7 +209,7 @@ static void ME_BeginRow(ME_WrapContext *wc)
width -= cell->prev_cell->member.cell.nRightBoundary; width -= cell->prev_cell->member.cell.nRightBoundary;
if (!cell->prev_cell) if (!cell->prev_cell)
{ {
int rowIndent = ME_GetTableRowEnd( para_get_di( wc->para ) )->member.para.fmt.dxStartIndent; int rowIndent = table_row_end( wc->para )->fmt.dxStartIndent;
width -= rowIndent; width -= rowIndent;
} }
cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0); cell->nWidth = max(ME_twips2pointsX(wc->context, width), 0);
...@@ -843,8 +843,7 @@ static void ME_WrapTextParagraph( ME_TextEditor *editor, ME_Context *c, ME_Parag ...@@ -843,8 +843,7 @@ static void ME_WrapTextParagraph( ME_TextEditor *editor, ME_Context *c, ME_Parag
else else
{ {
int dxStartIndent = para->fmt.dxStartIndent; int dxStartIndent = para->fmt.dxStartIndent;
if (para->pCell) if (para->pCell) dxStartIndent += table_row_end( para )->fmt.dxOffset;
dxStartIndent += ME_GetTableRowEnd( para_get_di( para ) )->member.para.fmt.dxOffset;
wc.nLeftMargin = ME_twips2pointsX( c, dxStartIndent + para->fmt.dxOffset ); wc.nLeftMargin = ME_twips2pointsX( c, dxStartIndent + para->fmt.dxOffset );
wc.nFirstMargin = ME_twips2pointsX( c, dxStartIndent ); wc.nFirstMargin = ME_twips2pointsX( c, dxStartIndent );
...@@ -1101,8 +1100,8 @@ void ME_InvalidateParagraphRange(ME_TextEditor *editor, ...@@ -1101,8 +1100,8 @@ void ME_InvalidateParagraphRange(ME_TextEditor *editor,
if (start_para) if (start_para)
{ {
start_para = ME_GetOuterParagraph(start_para); start_para = para_get_di( table_outer_para( &start_para->member.para ) );
last_para = ME_GetOuterParagraph(last_para); last_para = para_get_di( table_outer_para( &last_para->member.para ) );
rc.top += start_para->member.para.pt.y - ofs; rc.top += start_para->member.para.pt.y - ofs;
} else { } else {
rc.top += editor->nTotalLength - ofs; rc.top += editor->nTotalLength - ofs;
......
...@@ -400,8 +400,8 @@ ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream, ...@@ -400,8 +400,8 @@ ME_StreamOutRTFTableProps(ME_TextEditor *editor, ME_OutStream *pStream,
if (!ME_StreamOutPrint(pStream, "\\trowd")) if (!ME_StreamOutPrint(pStream, "\\trowd"))
return FALSE; return FALSE;
if (!editor->bEmulateVersion10) { /* v4.1 */ if (!editor->bEmulateVersion10) { /* v4.1 */
PARAFORMAT2 *pFmt = &ME_GetTableRowEnd(para)->member.para.fmt; PARAFORMAT2 *pFmt = &table_row_end( &para->member.para )->fmt;
para = ME_GetTableRowStart(para); para = para_get_di( table_row_start( &para->member.para ) );
cell = para->member.para.next_para->member.para.pCell; cell = para->member.para.next_para->member.para.pCell;
assert(cell); assert(cell);
if (pFmt->dxOffset) if (pFmt->dxOffset)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment