Commit 84bb3722 authored by Phil Krylov's avatar Phil Krylov Committed by Alexandre Julliard

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).
parent d03f32b1
...@@ -192,6 +192,8 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, ...@@ -192,6 +192,8 @@ void ME_InternalDeleteText(ME_TextEditor *editor, int nOfs,
/* ME_SkipAndPropagateCharOffset(p->pRun, shift); */ /* ME_SkipAndPropagateCharOffset(p->pRun, shift); */
ME_CheckCharOffsets(editor); ME_CheckCharOffsets(editor);
nChars--; nChars--;
if (editor->bEmulateVersion10 && nChars)
nChars--;
continue; continue;
} }
else else
...@@ -455,19 +457,24 @@ static BOOL ME_ArrowLeft(ME_TextEditor *editor, ME_Cursor *p) ...@@ -455,19 +457,24 @@ static BOOL ME_ArrowLeft(ME_TextEditor *editor, ME_Cursor *p)
static BOOL ME_ArrowRight(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); ME_DisplayItem *pRun;
if (new_ofs<p->pRun->member.run.strText->nLen) {
p->nOffset = new_ofs; if (!(p->pRun->member.run.nFlags & MERF_ENDPARA))
}
else
{ {
ME_DisplayItem *pRun = ME_FindItemFwd(p->pRun, diRun); int new_ofs = ME_StrRelPos2(p->pRun->member.run.strText, p->nOffset, 1);
if (pRun) {
p->pRun = pRun; if (new_ofs<p->pRun->member.run.strText->nLen)
assert(p->pRun->type == diRun); {
p->nOffset = 0; 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; return TRUE;
} }
......
...@@ -720,6 +720,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) { ...@@ -720,6 +720,7 @@ ME_TextEditor *ME_MakeEditor(HWND hWnd) {
HDC hDC; HDC hDC;
int i; int i;
ed->hWnd = hWnd; ed->hWnd = hWnd;
ed->bEmulateVersion10 = FALSE;
ed->pBuffer = ME_MakeText(); ed->pBuffer = ME_MakeText();
hDC = GetDC(hWnd); hDC = GetDC(hWnd);
ME_MakeFirstParagraph(hDC, ed->pBuffer); ME_MakeFirstParagraph(hDC, ed->pBuffer);
...@@ -1577,8 +1578,18 @@ LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP ...@@ -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 WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
LRESULT result;
/* FIXME: this is NOT the same as 2.0 version */ /* 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) void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
......
...@@ -247,6 +247,7 @@ typedef struct tagME_FontCacheItem ...@@ -247,6 +247,7 @@ typedef struct tagME_FontCacheItem
typedef struct tagME_TextEditor typedef struct tagME_TextEditor
{ {
HWND hWnd; HWND hWnd;
BOOL bEmulateVersion10;
BOOL bCaretShown; BOOL bCaretShown;
ME_TextBuffer *pBuffer; ME_TextBuffer *pBuffer;
ME_Cursor *pCursors; ME_Cursor *pCursors;
......
...@@ -101,6 +101,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME ...@@ -101,6 +101,7 @@ 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);
assert(run->type == diRun); assert(run->type == diRun);
...@@ -122,7 +123,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME ...@@ -122,7 +123,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ME
pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd); pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd);
} }
new_para->member.para.nCharOfs = ME_GetParagraph(run)->member.para.nCharOfs+ofs; 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) */ new_para->member.para.nFlags = MEPF_REWRAP; /* FIXME copy flags (if applicable) */
/* FIXME initialize format style and call ME_SetParaFormat blah blah */ /* 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 ...@@ -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; 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 */ /* 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++; editor->nParagraphs++;
return new_para; return new_para;
...@@ -161,6 +162,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) ...@@ -161,6 +162,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);
assert(tp->type == diParagraph); assert(tp->type == diParagraph);
assert(tp->member.para.next_para); assert(tp->member.para.next_para);
...@@ -172,17 +174,17 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) ...@@ -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 */ /* null char format operation to store the original char format for the ENDPARA run */
CHARFORMAT2W fmt; CHARFORMAT2W fmt;
ME_InitCharFormat2W(&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); undo = ME_AddUndoItem(editor, diUndoSplitParagraph, NULL);
if (undo) 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)); assert(pNext->member.para.pFmt->cbSize == sizeof(PARAFORMAT2));
CopyMemory(undo->di.member.para.pFmt, pNext->member.para.pFmt, 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); pRun = ME_FindItemBack(pNext, diRunOrParagraph);
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph); pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
...@@ -218,7 +220,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp) ...@@ -218,7 +220,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp)
ME_Remove(pNext); ME_Remove(pNext);
ME_DestroyDisplayItem(pNext); ME_DestroyDisplayItem(pNext);
ME_PropagateCharOffset(tp->member.para.next_para, -1); ME_PropagateCharOffset(tp->member.para.next_para, -end_len);
ME_CheckCharOffsets(editor); ME_CheckCharOffsets(editor);
......
...@@ -97,7 +97,10 @@ void ME_CheckCharOffsets(ME_TextEditor *editor) ...@@ -97,7 +97,10 @@ void ME_CheckCharOffsets(ME_TextEditor *editor)
p->member.run.nFlags, p->member.run.nFlags,
p->member.run.style->fmt.dwMask & p->member.run.style->fmt.dwEffects); p->member.run.style->fmt.dwMask & p->member.run.style->fmt.dwEffects);
assert(ofs == p->member.run.nCharOfs); 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; break;
default: default:
assert(0); assert(0);
......
...@@ -764,6 +764,8 @@ ME_StreamOutText(ME_TextEditor *editor, int nStart, int nChars, DWORD dwFormat) ...@@ -764,6 +764,8 @@ ME_StreamOutText(ME_TextEditor *editor, int nStart, int nChars, DWORD dwFormat)
} }
nChars -= nLen; nChars -= nLen;
if (editor->bEmulateVersion10 && nChars && item->member.run.nFlags & MERF_ENDPARA)
nChars--;
nStart = 0; nStart = 0;
item = ME_FindItemFwd(item, diRun); item = ME_FindItemFwd(item, diRun);
} }
......
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