diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index 6542ddce525..f1c87db24d0 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -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_ofspRun->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_ofspRun->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; } diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 0e1cc830b1f..592c63ed84b 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -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) diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h index ae7a0cd995e..40384900c9a 100644 --- a/dlls/riched20/editstr.h +++ b/dlls/riched20/editstr.h @@ -247,6 +247,7 @@ typedef struct tagME_FontCacheItem typedef struct tagME_TextEditor { HWND hWnd; + BOOL bEmulateVersion10; BOOL bCaretShown; ME_TextBuffer *pBuffer; ME_Cursor *pCursors; diff --git a/dlls/riched20/para.c b/dlls/riched20/para.c index 4b1947ce797..a6a548f1e5c 100644 --- a/dlls/riched20/para.c +++ b/dlls/riched20/para.c @@ -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); diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c index 2c8edb2b851..1830ba3dc5f 100644 --- a/dlls/riched20/run.c +++ b/dlls/riched20/run.c @@ -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); diff --git a/dlls/riched20/writer.c b/dlls/riched20/writer.c index 837285c323e..65d41e33d4d 100644 --- a/dlls/riched20/writer.c +++ b/dlls/riched20/writer.c @@ -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); }