ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar)
{
ME_TextEditor *editor = wc->context->editor;
- ME_DisplayItem *item2 = NULL;
ME_Run *run, *run2;
- ME_Paragraph *para = &ME_GetParagraph(item)->member.para;
+ ME_Paragraph *para = &wc->pPara->member.para;
+ ME_Cursor cursor = {wc->pPara, item, nVChar};
assert(item->member.run.nCharOfs != -1);
if(TRACE_ON(richedit))
TRACE("Before split: %s(%d, %d)\n", debugstr_w(run->strText->szData),
run->pt.x, run->pt.y);
- item2 = ME_SplitRunSimple(editor, item, nVChar);
+ ME_SplitRunSimple(editor, &cursor);
- run2 = &item2->member.run;
+ run2 = &cursor.pRun->member.run;
ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run);
- ME_CalcRunExtent(wc->context, para, wc->nRow ? wc->nLeftMargin : wc->nFirstMargin, run2);
run2->pt.x = run->pt.x+run->nWidth;
run2->pt.y = run->pt.y;
debugstr_w(run2->strText->szData), run2->pt.x, run2->pt.y);
}
- return item2;
+ return cursor.pRun;
}
/******************************************************************************
* ME_SplitRunSimple
- *
+ *
* Does the most basic job of splitting a run into two - it does not
- * update the positions and extents.
- */
-ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_DisplayItem *item, int nVChar)
+ * update the positions and extents.
+ */
+ME_DisplayItem *ME_SplitRunSimple(ME_TextEditor *editor, ME_Cursor *cursor)
{
- ME_Run *run = &item->member.run;
- ME_DisplayItem *item2;
- ME_Run *run2;
+ ME_DisplayItem *run = cursor->pRun;
+ ME_DisplayItem *new_run;
int i;
- assert(nVChar > 0 && nVChar < run->strText->nLen);
- assert(item->type == diRun);
- assert(!(item->member.run.nFlags & MERF_NONTEXT));
- assert(item->member.run.nCharOfs != -1);
+ int nOffset = cursor->nOffset;
- item2 = ME_MakeRun(run->style,
- ME_VSplitString(run->strText, nVChar), run->nFlags&MERF_SPLITMASK);
+ assert(!(run->member.run.nFlags & MERF_NONTEXT));
- item2->member.run.nCharOfs = item->member.run.nCharOfs + nVChar;
+ new_run = ME_MakeRun(run->member.run.style,
+ ME_VSplitString(run->member.run.strText, nOffset),
+ run->member.run.nFlags & MERF_SPLITMASK);
- run2 = &item2->member.run;
- ME_InsertBefore(item->next, item2);
+ new_run->member.run.nCharOfs = run->member.run.nCharOfs + nOffset;
+ cursor->pRun = new_run;
+ cursor->nOffset = 0;
- ME_UpdateRunFlags(editor, run);
- ME_UpdateRunFlags(editor, run2);
- for (i=0; i<editor->nCursors; i++) {
- if (editor->pCursors[i].pRun == item &&
- editor->pCursors[i].nOffset >= nVChar) {
- assert(item2->type == diRun);
- editor->pCursors[i].pRun = item2;
- editor->pCursors[i].nOffset -= nVChar;
+ ME_InsertBefore(run->next, new_run);
+
+ ME_UpdateRunFlags(editor, &run->member.run);
+ ME_UpdateRunFlags(editor, &new_run->member.run);
+ for (i = 0; i < editor->nCursors; i++) {
+ if (editor->pCursors[i].pRun == run &&
+ editor->pCursors[i].nOffset >= nOffset) {
+ editor->pCursors[i].pRun = new_run;
+ editor->pCursors[i].nOffset -= nOffset;
}
}
- ME_GetParagraph(item)->member.para.nFlags |= MEPF_REWRAP;
- return item2;
+ cursor->pPara->member.para.nFlags |= MEPF_REWRAP;
+ return run;
}
/******************************************************************************
ME_DisplayItem *pDI;
ME_UndoItem *pUI;
- if (cursor->nOffset) {
- /* We're inserting at the middle of the existing run, which means that
- * that run must be split. It isn't always necessary, but */
- cursor->pRun = ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
- cursor->nOffset = 0;
- }
+ if (cursor->nOffset)
+ ME_SplitRunSimple(editor, cursor);
pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
if (pUI) {
{
/* SplitRunSimple may or may not update the cursors, depending on whether they
* are selection cursors, but we need to make sure they are valid. */
- ME_DisplayItem *split_run = start->pRun;
int split_offset = start->nOffset;
- start->pRun = ME_SplitRunSimple(editor, split_run, split_offset);
- start->nOffset = 0;
+ ME_DisplayItem *split_run = ME_SplitRunSimple(editor, start);
if (end && end->pRun == split_run)
{
end->pRun = start->pRun;
}
if (end && end->nOffset)
- {
- end_run = end->pRun = ME_SplitRunSimple(editor, end->pRun, end->nOffset);
- end->nOffset = 0;
- } else if (end) {
- end_run = end->pRun;
- }
+ ME_SplitRunSimple(editor, end);
+ end_run = end ? end->pRun : NULL;
run = start->pRun;
para = start->pPara;
do {
/* FIXME add more style feature comparisons */
- int nAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE;
- int nEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT;
+ DWORD dwAttribs = CFM_SIZE | CFM_FACE | CFM_COLOR | CFM_UNDERLINETYPE;
+ DWORD dwEffects = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_PROTECTED | CFM_LINK | CFM_SUPERSCRIPT;
run = ME_FindItemFwd(run, diRun);
tmp.cbSize = sizeof(tmp);
ME_GetRunCharFormat(editor, run, &tmp);
- assert((tmp.dwMask & nAttribs) == nAttribs);
+ assert((tmp.dwMask & dwAttribs) == dwAttribs);
/* reset flags that differ */
if (pFmt->yHeight != tmp.yHeight)
}
}
- pFmt->dwMask &= ~((pFmt->dwEffects ^ tmp.dwEffects) & nEffects);
+ pFmt->dwMask &= ~((pFmt->dwEffects ^ tmp.dwEffects) & dwEffects);
pFmt->dwEffects = tmp.dwEffects;
} while(run != run_end);