richedit: Add support for encoding number of CR and LF contained within a line break.

This commit is contained in:
Alex Villacís Lasso 2008-04-26 13:29:53 -05:00 committed by Alexandre Julliard
parent 09af64cb83
commit d47f66191e
6 changed files with 36 additions and 11 deletions

View File

@ -531,7 +531,15 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
} }
tmp_style = ME_GetInsertStyle(editor, nCursor); tmp_style = ME_GetInsertStyle(editor, nCursor);
/* ME_SplitParagraph increases style refcount */ /* ME_SplitParagraph increases style refcount */
tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style);
/* TODO: move here and fix logic for pos updating according to emulation,
so that number of CR and LF encoded are a result of such logic, instead
of hardcoded as below.
*/
if (editor->bEmulateVersion10)
tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style, 1, 1);
else
tp = ME_SplitParagraph(editor, p->pRun, p->pRun->member.run.style, 1, 0);
p->pRun = ME_FindItemFwd(tp, diRun); p->pRun = ME_FindItemFwd(tp, diRun);
end_run = ME_FindItemBack(tp, diRun); end_run = ME_FindItemBack(tp, diRun);
ME_ReleaseStyle(end_run->member.run.style); ME_ReleaseStyle(end_run->member.run.style);

View File

@ -220,7 +220,7 @@ int ME_twips2pointsY(ME_Context *c, int y);
ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run); ME_DisplayItem *ME_GetParagraph(ME_DisplayItem *run);
void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end); void ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayItem **para_end);
void ME_MakeFirstParagraph(ME_TextEditor *editor); void ME_MakeFirstParagraph(ME_TextEditor *editor);
ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *rp, ME_Style *style); ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *rp, ME_Style *style, int numCR, int numLF);
ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp); ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp);
void ME_DumpParaStyle(ME_Paragraph *s); void ME_DumpParaStyle(ME_Paragraph *s);
void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]); void ME_DumpParaStyleToBuf(const PARAFORMAT2 *pFmt, char buf[2048]);

View File

@ -148,6 +148,7 @@ typedef struct tagME_Run
POINT pt; /* relative to para's position */ POINT pt; /* relative to para's position */
struct tagME_TableCell *pCell; /* for MERF_CELL: points to respective cell in ME_Paragraph */ struct tagME_TableCell *pCell; /* for MERF_CELL: points to respective cell in ME_Paragraph */
REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */ REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
int nCR; int nLF; /* for MERF_ENDPARA: number of \r and \n characters encoded by run */
} ME_Run; } ME_Run;
typedef struct tagME_Document { typedef struct tagME_Document {
@ -217,6 +218,7 @@ typedef struct tagME_UndoItem
{ {
ME_DisplayItem di; ME_DisplayItem di;
int nStart, nLen; int nStart, nLen;
int nCR, nLF; /* used by diUndoSplitParagraph */
} ME_UndoItem; } ME_UndoItem;
typedef struct tagME_TextBuffer typedef struct tagME_TextBuffer

View File

@ -200,6 +200,8 @@ void ME_DumpDocument(ME_TextBuffer *buffer)
case diRun: case diRun:
TRACE(" - Run(\"%s\", %d)\n", debugstr_w(pItem->member.run.strText->szData), TRACE(" - Run(\"%s\", %d)\n", debugstr_w(pItem->member.run.strText->szData),
pItem->member.run.nCharOfs); pItem->member.run.nCharOfs);
if (pItem->member.run.nFlags & MERF_ENDPARA)
TRACE(" - Paragraph end: %d CR, %d LF\n", pItem->member.run.nCR, pItem->member.run.nLF);
break; break;
case diTextEnd: case diTextEnd:
TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs); TRACE("End(ofs=%d)\n", pItem->member.para.nCharOfs);

View File

@ -110,7 +110,7 @@ void ME_MarkForPainting(ME_TextEditor *editor, ME_DisplayItem *first, const ME_D
} }
/* split paragraph at the beginning of the run */ /* split paragraph at the beginning of the run */
ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME_Style *style) ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME_Style *style, int numCR, int numLF)
{ {
ME_DisplayItem *next_para = NULL; ME_DisplayItem *next_para = NULL;
ME_DisplayItem *run_para = NULL; ME_DisplayItem *run_para = NULL;
@ -119,10 +119,12 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME
ME_UndoItem *undo = NULL; ME_UndoItem *undo = NULL;
int ofs; int ofs;
ME_DisplayItem *pp; ME_DisplayItem *pp;
int end_len = (editor->bEmulateVersion10 ? 2 : 1); int end_len = numCR + numLF;
assert(run->type == diRun); assert(run->type == diRun);
end_run->member.run.nCR = numCR;
end_run->member.run.nLF = numLF;
run_para = ME_GetParagraph(run); run_para = ME_GetParagraph(run);
assert(run_para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); assert(run_para->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
@ -204,7 +206,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp; ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp;
int i, shift; int i, shift;
ME_UndoItem *undo = NULL; ME_UndoItem *undo = NULL;
int end_len = (editor->bEmulateVersion10 ? 2 : 1); int end_len;
assert(tp->type == diParagraph); assert(tp->type == diParagraph);
assert(tp->member.para.next_para); assert(tp->member.para.next_para);
@ -212,6 +214,15 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
pNext = tp->member.para.next_para; pNext = tp->member.para.next_para;
/* Need to locate end-of-paragraph run here, in order to know end_len */
pRun = ME_FindItemBack(pNext, diRunOrParagraph);
assert(pRun);
assert(pRun->type == diRun);
assert(pRun->member.run.nFlags & MERF_ENDPARA);
end_len = pRun->member.run.nCR + pRun->member.run.nLF;
{ {
/* null char format operation to store the original char format for the ENDPARA run */ /* null char format operation to store the original char format for the ENDPARA run */
CHARFORMAT2W fmt; CHARFORMAT2W fmt;
@ -222,18 +233,16 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
if (undo) if (undo)
{ {
undo->nStart = pNext->member.para.nCharOfs - end_len; undo->nStart = pNext->member.para.nCharOfs - end_len;
undo->nCR = pRun->member.run.nCR;
undo->nLF = pRun->member.run.nLF;
assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
*undo->di.member.para.pFmt = *pNext->member.para.pFmt; *undo->di.member.para.pFmt = *pNext->member.para.pFmt;
} }
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len; shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
pRun = ME_FindItemBack(pNext, diRunOrParagraph);
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph); pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
assert(pRun);
assert(pRun->type == diRun);
assert(pRun->member.run.nFlags & MERF_ENDPARA);
assert(pFirstRunInNext->type == diRun); assert(pFirstRunInNext->type == diRun);
/* if some cursor points at end of paragraph, make it point to the first /* if some cursor points at end of paragraph, make it point to the first

View File

@ -56,6 +56,7 @@ ME_UndoItem *ME_AddUndoItem(ME_TextEditor *editor, ME_DIType type, const ME_Disp
else else
{ {
ME_DisplayItem *pItem = (ME_DisplayItem *)ALLOC_OBJ(ME_UndoItem); ME_DisplayItem *pItem = (ME_DisplayItem *)ALLOC_OBJ(ME_UndoItem);
((ME_UndoItem *)pItem)->nCR = ((ME_UndoItem *)pItem)->nLF = -1;
switch(type) switch(type)
{ {
case diUndoEndTransaction: case diUndoEndTransaction:
@ -225,7 +226,10 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
if (tmp.nOffset) if (tmp.nOffset)
tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset); tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
new_para = ME_SplitParagraph(editor, tmp.pRun, tmp.pRun->member.run.style); assert(pUItem->nCR >= 0);
assert(pUItem->nLF >= 0);
new_para = ME_SplitParagraph(editor, tmp.pRun, tmp.pRun->member.run.style,
pUItem->nCR, pUItem->nLF);
assert(pItem->member.para.pFmt->cbSize == sizeof(PARAFORMAT2)); assert(pItem->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
*new_para->member.para.pFmt = *pItem->member.para.pFmt; *new_para->member.para.pFmt = *pItem->member.para.pFmt;
break; break;