ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor, ME_DisplayItem *para) { ME_DisplayItem *prev_para, *end_para; ME_Cursor savedCursor = editor->pCursors[0]; ME_DisplayItem *startRowPara; editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].nOffset = 0; editor->pCursors[1] = editor->pCursors[0]; startRowPara = ME_InsertTableRowStartFromCursor(editor); editor->pCursors[0] = savedCursor; editor->pCursors[1] = editor->pCursors[0]; end_para = ME_GetParagraph(editor->pCursors[0].pRun)->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.pFmt->dwMask |= PFM_TABLE|PFM_TABLEROWDELIMITER; para->member.para.pFmt->wEffects |= PFE_TABLE; para->member.para.pFmt->wEffects &= ~PFE_TABLEROWDELIMITER; prev_para = para; para = para->member.para.next_para; } return startRowPara; }
ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row) { WCHAR endl = '\r', tab = '\t'; ME_DisplayItem *run; PARAFORMAT2 *pFmt; int i; assert(table_row); assert(table_row->type == diParagraph); if (!editor->bEmulateVersion10) { /* v4.1 */ ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd; cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell); prevTableEnd = ME_GetTableRowEnd(table_row); para = prevTableEnd->member.para.next_para; run = ME_FindItemFwd(para, diRun); editor->pCursors[0].pPara = para; editor->pCursors[0].pRun = run; editor->pCursors[0].nOffset = 0; editor->pCursors[1] = editor->pCursors[0]; para = ME_InsertTableRowStartFromCursor(editor); insertedCell = ME_FindItemFwd(para, diCell); /* Copy cell properties */ insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary; insertedCell->member.cell.border = cell->member.cell.border; while (cell->member.cell.next_cell) { cell = cell->member.cell.next_cell; para = ME_InsertTableCellFromCursor(editor); insertedCell = ME_FindItemBack(para, diCell); /* Copy cell properties */ insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary; insertedCell->member.cell.border = cell->member.cell.border; }; para = ME_InsertTableRowEndFromCursor(editor); *para->member.para.pFmt = *prevTableEnd->member.para.pFmt; /* return the table row start for the inserted paragraph */ return ME_FindItemFwd(cell, diParagraph)->member.para.next_para; } else { /* v1.0 - 3.0 */ run = ME_FindItemBack(table_row->member.para.next_para, diRun); pFmt = table_row->member.para.pFmt; assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE); editor->pCursors[0].pPara = table_row; editor->pCursors[0].pRun = run; editor->pCursors[0].nOffset = 0; editor->pCursors[1] = editor->pCursors[0]; ME_InsertTextFromCursor(editor, 0, &endl, 1, run->member.run.style); run = editor->pCursors[0].pRun; for (i = 0; i < pFmt->cTabCount; i++) { ME_InsertTextFromCursor(editor, 0, &tab, 1, run->member.run.style); } return table_row->member.para.next_para; } }