Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is

being used. This emulation (introduced in M$ RichEdit 3.0) counts
paragraph endings as 2 characters (CR+LF) instead of 1 (CR).
This commit is contained in:
Phil Krylov 2005-07-21 10:33:32 +00:00 committed by Alexandre Julliard
parent d03f32b15b
commit 84bb372239
6 changed files with 44 additions and 18 deletions

View file

@ -192,6 +192,8 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs,
/* ME_SkipAndPropagateCharOffset(p->pRun, shift); */
ME_CheckCharOffsets(editor);
nChars--;
if (editor->bEmulateVersion10 && nChars)
nChars--;
continue;
}
else
@ -455,19 +457,24 @@ static BOOL ME_ArrowLeft(ME_TextEditor *editor, ME_Cursor *p)
static BOOL ME_ArrowRight(ME_TextEditor *editor, ME_Cursor *p)
{
int new_ofs = ME_StrRelPos2(p->pRun->member.run.strText, p->nOffset, 1);
if (new_ofs<p->pRun->member.run.strText->nLen) {
p->nOffset = new_ofs;
}
else
ME_DisplayItem *pRun;
if (!(p->pRun->member.run.nFlags & MERF_ENDPARA))
{
ME_DisplayItem *pRun = ME_FindItemFwd(p->pRun, diRun);
if (pRun) {
p->pRun = pRun;
assert(p->pRun->type == diRun);
p->nOffset = 0;
int new_ofs = ME_StrRelPos2(p->pRun->member.run.strText, p->nOffset, 1);
if (new_ofs<p->pRun->member.run.strText->nLen)
{
p->nOffset = new_ofs;
return TRUE;
}
}
pRun = ME_FindItemFwd(p->pRun, diRun);
if (pRun) {
p->pRun = pRun;
assert(p->pRun->type == diRun);
p->nOffset = 0;
}
return TRUE;
}

View file

@ -720,6 +720,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) {
HDC hDC;
int i;
ed->hWnd = hWnd;
ed->bEmulateVersion10 = FALSE;
ed->pBuffer = ME_MakeText();
hDC = GetDC(hWnd);
ME_MakeFirstParagraph(hDC, ed->pBuffer);
@ -1577,8 +1578,18 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
*/
LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
LRESULT result;
/* FIXME: this is NOT the same as 2.0 version */
return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
result = RichEditANSIWndProc(hWnd, msg, wParam, lParam);
if (msg == WM_NCCREATE)
{
ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongW(hWnd, 0);
editor->bEmulateVersion10 = TRUE;
editor->pBuffer->pLast->member.para.nCharOfs = 2;
}
return result;
}
void ME_SendOldNotify(ME_TextEditor *editor, int nCode)

View file

@ -247,6 +247,7 @@ typedef struct tagME_FontCacheItem
typedef struct tagME_TextEditor
{
HWND hWnd;
BOOL bEmulateVersion10;
BOOL bCaretShown;
ME_TextBuffer *pBuffer;
ME_Cursor *pCursors;

View file

@ -101,6 +101,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME
ME_UndoItem *undo = NULL;
int ofs;
ME_DisplayItem *pp;
int end_len = (editor->bEmulateVersion10 ? 2 : 1);
assert(run->type == diRun);
@ -122,7 +123,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME
pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd);
}
new_para->member.para.nCharOfs = ME_GetParagraph(run)->member.para.nCharOfs+ofs;
new_para->member.para.nCharOfs += 1;
new_para->member.para.nCharOfs += end_len;
new_para->member.para.nFlags = MEPF_REWRAP; /* FIXME copy flags (if applicable) */
/* FIXME initialize format style and call ME_SetParaFormat blah blah */
@ -148,7 +149,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME
new_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
/* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
ME_PropagateCharOffset(next_para, 1);
ME_PropagateCharOffset(next_para, end_len);
editor->nParagraphs++;
return new_para;
@ -161,6 +162,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
ME_DisplayItem *pNext, *pFirstRunInNext, *pRun, *pTmp;
int i, shift;
ME_UndoItem *undo = NULL;
int end_len = (editor->bEmulateVersion10 ? 2 : 1);
assert(tp->type == diParagraph);
assert(tp->member.para.next_para);
@ -172,17 +174,17 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
/* null char format operation to store the original char format for the ENDPARA run */
CHARFORMAT2W fmt;
ME_InitCharFormat2W(&fmt);
ME_SetCharFormat(editor, pNext->member.para.nCharOfs-1, 1, &fmt);
ME_SetCharFormat(editor, pNext->member.para.nCharOfs - end_len, end_len, &fmt);
}
undo = ME_AddUndoItem(editor, diUndoSplitParagraph, NULL);
if (undo)
{
undo->nStart = pNext->member.para.nCharOfs-1;
undo->nStart = pNext->member.para.nCharOfs - end_len;
assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
CopyMemory(undo->di.member.para.pFmt, pNext->member.para.pFmt, sizeof(PARAFORMAT2));
}
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - 1;
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
pRun = ME_FindItemBack(pNext, diRunOrParagraph);
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
@ -218,7 +220,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
ME_Remove(pNext);
ME_DestroyDisplayItem(pNext);
ME_PropagateCharOffset(tp->member.para.next_para, -1);
ME_PropagateCharOffset(tp->member.para.next_para, -end_len);
ME_CheckCharOffsets(editor);

View file

@ -97,7 +97,10 @@ void ME_CheckCharOffsets(ME_TextEditor *editor)
p->member.run.nFlags,
p->member.run.style->fmt.dwMask & p->member.run.style->fmt.dwEffects);
assert(ofs == p->member.run.nCharOfs);
ofs += ME_StrLen(p->member.run.strText);
if (p->member.run.nFlags & MERF_ENDPARA)
ofs += (editor->bEmulateVersion10 ? 2 : 1);
else
ofs += ME_StrLen(p->member.run.strText);
break;
default:
assert(0);

View file

@ -764,6 +764,8 @@ ME_StreamOutText(ME_TextEditor *editor, int nStart, int nChars, DWORD dwFormat)
}
nChars -= nLen;
if (editor->bEmulateVersion10 && nChars && item->member.run.nFlags & MERF_ENDPARA)
nChars--;
nStart = 0;
item = ME_FindItemFwd(item, diRun);
}