From bd4704280d2d5d884476c85531c9dfd566ac601e Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Thu, 13 Aug 2009 08:44:18 -0400 Subject: [PATCH] richedit: Replace offsets arg with ME_Cursor for ME_InternalDeleteText. Offsets are still used within the function, but this patch reduces the use of it at the entry to the function. --- dlls/riched20/caret.c | 15 +++++----- dlls/riched20/editor.c | 65 +++++++++++++++++++++++------------------- dlls/riched20/editor.h | 4 +-- dlls/riched20/table.c | 19 ++++++------ dlls/riched20/txtsrv.c | 6 ++-- dlls/riched20/undo.c | 4 ++- 6 files changed, 62 insertions(+), 51 deletions(-) diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index fe594a0f02c..11c3f1f65c6 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -281,23 +281,22 @@ void ME_HideCaret(ME_TextEditor *ed) } } -BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars, - BOOL bForce) +BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start, + int nChars, BOOL bForce) { - ME_Cursor c; + ME_Cursor c = *start; + int nOfs = ME_GetCursorOfs(start); int shift = 0; int totalChars = nChars; ME_DisplayItem *start_para; /* Prevent deletion past last end of paragraph run. */ nChars = min(nChars, ME_GetTextLength(editor) - nOfs); - - ME_CursorFromCharOfs(editor, nOfs, &c); start_para = c.pPara; if (!bForce) { - ME_ProtectPartialTableDeletion(editor, nOfs, &nChars); + ME_ProtectPartialTableDeletion(editor, &c, &nChars); if (nChars == 0) return FALSE; } @@ -444,11 +443,11 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars, } BOOL ME_DeleteTextAtCursor(ME_TextEditor *editor, int nCursor, int nChars) -{ +{ assert(nCursor>=0 && nCursornCursors); /* text operations set modified state */ editor->nModifyStep = 1; - return ME_InternalDeleteText(editor, ME_GetCursorOfs(&editor->pCursors[nCursor]), + return ME_InternalDeleteText(editor, &editor->pCursors[nCursor], nChars, FALSE); } diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index e56d8d4fde9..f3753b4ea3d 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -1015,7 +1015,8 @@ void ME_RTFSpecialCharHook(RTF_Info *info) info->editor->pCursors[1].nOffset = 0; nOfs = ME_GetCursorOfs(&info->editor->pCursors[1]); nChars = ME_GetCursorOfs(&info->editor->pCursors[0]) - nOfs; - ME_InternalDeleteText(info->editor, nOfs, nChars, TRUE); + ME_InternalDeleteText(info->editor, &info->editor->pCursors[1], + nChars, TRUE); } para = ME_InsertTableRowEndFromCursor(info->editor); @@ -1389,15 +1390,18 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre int nEventMask = editor->nEventMask; ME_InStream inStream; BOOL invalidRTF = FALSE; + ME_Cursor *selStart, *selEnd; TRACE("stream==%p editor==%p format==0x%X\n", stream, editor, format); editor->nEventMask = 0; ME_GetSelectionOfs(editor, &from, &to); - if ((format & SFF_SELECTION) && (editor->mode & TM_RICHTEXT)) { + if (format & SFF_SELECTION && editor->mode & TM_RICHTEXT) + { + ME_GetSelection(editor, &selStart, &selEnd); style = ME_GetSelectionInsertStyle(editor); - ME_InternalDeleteText(editor, from, to-from, FALSE); + ME_InternalDeleteText(editor, selStart, to - from, FALSE); /* Don't insert text at the end of the table row */ if (!editor->bEmulateVersion10) { /* v4.1 */ @@ -1422,12 +1426,12 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre ME_IsInTable(editor->pCursors[0].pRun)) return 0; } - } - else { + } else { style = editor->pBuffer->pDefaultStyle; ME_AddRefStyle(style); ME_SetSelection(editor, 0, 0); - ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE); + ME_InternalDeleteText(editor, &editor->pCursors[1], + ME_GetTextLength(editor), FALSE); from = to = 0; ME_ClearTempStyle(editor); ME_SetDefaultParaFormat(editor->pCursors[0].pPara->member.para.pFmt); @@ -1518,7 +1522,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre editor->pCursors[1].nOffset = 0; nOfs = ME_GetCursorOfs(&editor->pCursors[1]); nChars = ME_GetCursorOfs(&editor->pCursors[0]) - nOfs; - ME_InternalDeleteText(editor, nOfs, nChars, TRUE); + ME_InternalDeleteText(editor, &editor->pCursors[1], nChars, TRUE); if (parser.tableDef) parser.tableDef->tableRowStart = NULL; } @@ -1544,17 +1548,18 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre are converted according to the standard rules: \r for 2.0, \r\n for 1.0 */ if (stripLastCR) { - int newfrom, newto; - ME_GetSelectionOfs(editor, &newfrom, &newto); + int newto; + ME_GetSelection(editor, &selStart, &selEnd); + newto = ME_GetCursorOfs(selEnd); if (newto > to + (editor->bEmulateVersion10 ? 1 : 0)) { WCHAR lastchar[3] = {'\0', '\0'}; int linebreakSize = editor->bEmulateVersion10 ? 2 : 1; - ME_Cursor linebreakCursor; + ME_Cursor linebreakCursor = *selEnd; - ME_CursorFromCharOfs(editor, newto - linebreakSize, &linebreakCursor); + ME_MoveCursorChars(editor, &linebreakCursor, -linebreakSize); ME_GetTextW(editor, lastchar, 2, &linebreakCursor, linebreakSize, 0); if (lastchar[0] == '\r' && (lastchar[1] == '\n' || lastchar[1] == '\0')) { - ME_InternalDeleteText(editor, newto - linebreakSize, linebreakSize, FALSE); + ME_InternalDeleteText(editor, &linebreakCursor, linebreakSize, FALSE); } } } @@ -2284,7 +2289,7 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey) result = ME_Copy(editor, selStart, nChars); if (result && nKey == 'X') { - ME_InternalDeleteText(editor, nOfs, nChars, FALSE); + ME_InternalDeleteText(editor, selStart, nChars, FALSE); ME_CommitUndo(editor); ME_UpdateRepaint(editor); } @@ -3222,11 +3227,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, bSelection = (pStruct->flags & ST_SELECTION) != 0; if (bSelection) { - ME_GetSelectionOfs(editor, &from, &to); + int nStartCursor = ME_GetSelectionOfs(editor, &from, &to); style = ME_GetSelectionInsertStyle(editor); - ME_InternalDeleteText(editor, from, to - from, FALSE); + ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to - from, FALSE); } else { - ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE); + ME_Cursor start; + ME_SetCursorToStart(editor, &start); + ME_InternalDeleteText(editor, &start, ME_GetTextLength(editor), FALSE); style = editor->pBuffer->pDefaultStyle; } @@ -3417,23 +3424,23 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case WM_CLEAR: { int from, to; - ME_GetSelectionOfs(editor, &from, &to); - ME_InternalDeleteText(editor, from, to-from, FALSE); + int nStartCursor = ME_GetSelectionOfs(editor, &from, &to); + ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE); ME_CommitUndo(editor); ME_UpdateRepaint(editor); return 0; } case EM_REPLACESEL: { - int from, to; + int from, to, nStartCursor; ME_Style *style; LPWSTR wszText = lParam ? ME_ToUnicode(unicode, (void *)lParam) : NULL; size_t len = wszText ? lstrlenW(wszText) : 0; TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText)); - ME_GetSelectionOfs(editor, &from, &to); + nStartCursor = ME_GetSelectionOfs(editor, &from, &to); style = ME_GetSelectionInsertStyle(editor); - ME_InternalDeleteText(editor, from, to-from, FALSE); + ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE); ME_InsertTextFromCursor(editor, 0, wszText, len, style); ME_ReleaseStyle(style); /* drop temporary style if line end */ @@ -3482,8 +3489,9 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, } case WM_SETTEXT: { - ME_Cursor updateLinksStart; - ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor), FALSE); + ME_Cursor cursor; + ME_SetCursorToStart(editor, &cursor); + ME_InternalDeleteText(editor, &cursor, ME_GetTextLength(editor), FALSE); if (lParam) { TRACE("WM_SETTEXT lParam==%lx\n",lParam); @@ -3517,8 +3525,8 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, } else TRACE("WM_SETTEXT - NULL\n"); - ME_SetCursorToStart(editor, &updateLinksStart); - ME_UpdateLinkAttribute(editor, &updateLinksStart, INT_MAX); + ME_SetCursorToStart(editor, &cursor); + ME_UpdateLinkAttribute(editor, &cursor, INT_MAX); ME_SetSelection(editor, 0, 0); editor->nModifyStep = 0; ME_CommitUndo(editor); @@ -3541,14 +3549,13 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, case WM_CUT: case WM_COPY: { - int nOfs, nChars; - int nStartCur = ME_GetSelectionOfs(editor, &nOfs, &nChars); + int nFrom, nTo, nStartCur = ME_GetSelectionOfs(editor, &nFrom, &nTo); + int nChars = nTo - nFrom; ME_Cursor *selStart = &editor->pCursors[nStartCur]; - nChars -= nOfs; if (ME_Copy(editor, selStart, nChars) && msg == WM_CUT) { - ME_InternalDeleteText(editor, nOfs, nChars, FALSE); + ME_InternalDeleteText(editor, selStart, nChars, FALSE); ME_CommitUndo(editor); ME_UpdateRepaint(editor); } diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 6a916391be3..04572398cd8 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -177,7 +177,7 @@ BOOL ME_IsSelection(ME_TextEditor *editor); void ME_DeleteSelection(ME_TextEditor *editor); void ME_SendSelChange(ME_TextEditor *editor); void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT* reo, int nCursor); -BOOL ME_InternalDeleteText(ME_TextEditor *editor, int nOfs, int nChars, BOOL bForce); +BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start, int nChars, BOOL bForce); int ME_GetTextLength(ME_TextEditor *editor); int ME_GetTextLengthEx(ME_TextEditor *editor, const GETTEXTLENGTHEX *how); ME_Style *ME_GetSelectionInsertStyle(ME_TextEditor *editor); @@ -264,7 +264,7 @@ ME_DisplayItem *ME_InsertTableRowEndFromCursor(ME_TextEditor *editor); ME_DisplayItem *ME_GetTableRowEnd(ME_DisplayItem *para); ME_DisplayItem *ME_GetTableRowStart(ME_DisplayItem *para); void ME_CheckTablesForCorruption(ME_TextEditor *editor); -void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars); +void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nChars); ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row); void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow); void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor); diff --git a/dlls/riched20/table.c b/dlls/riched20/table.c index be42930fe82..cbfa2b3f771 100644 --- a/dlls/riched20/table.c +++ b/dlls/riched20/table.c @@ -275,13 +275,14 @@ BOOL ME_IsInTable(ME_DisplayItem *pItem) } /* Table rows should either be deleted completely or not at all. */ -void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars) +void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, ME_Cursor *c, int *nChars) { - ME_Cursor c, c2; - ME_DisplayItem *this_para, *end_para; - ME_CursorFromCharOfs(editor, nOfs, &c); - this_para = c.pPara; - ME_CursorFromCharOfs(editor, nOfs + *nChars, &c2); + int nOfs = ME_GetCursorOfs(c); + ME_Cursor c2 = *c; + ME_DisplayItem *this_para = c->pPara; + ME_DisplayItem *end_para; + + ME_MoveCursorChars(editor, &c2, *nChars); end_para = c2.pPara; if (c2.pRun->member.run.nFlags & MERF_ENDPARA) { /* End offset might be in the middle of the end paragraph run. @@ -357,13 +358,13 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars) this_para->member.para.pFmt->dwMask & PFM_TABLE && this_para->member.para.pFmt->wEffects & PFE_TABLE) { - pRun = c.pRun; + pRun = c->pRun; /* Find the next tab or end paragraph to use as a delete boundary */ while (!(pRun->member.run.nFlags & (MERF_TAB|MERF_ENDPARA))) pRun = ME_FindItemFwd(pRun, diRun); nCharsToBoundary = pRun->member.run.nCharOfs - - c.pRun->member.run.nCharOfs - - c.nOffset; + - c->pRun->member.run.nCharOfs + - c->nOffset; *nChars = min(*nChars, nCharsToBoundary); } else if (end_para->member.para.pFmt->dwMask & PFM_TABLE && end_para->member.para.pFmt->wEffects & PFE_TABLE) diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c index 605d38d1a95..4006acda0b8 100644 --- a/dlls/riched20/txtsrv.c +++ b/dlls/riched20/txtsrv.c @@ -312,9 +312,11 @@ HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR pszText) { ICOM_THIS_MULTI(ITextServicesImpl, lpVtbl, iface); + ME_Cursor cursor; - ME_InternalDeleteText(This->editor, 0, ME_GetTextLength(This->editor), - FALSE); + ME_SetCursorToStart(This->editor, &cursor); + ME_InternalDeleteText(This->editor, &cursor, + ME_GetTextLength(This->editor), FALSE); ME_InsertTextFromCursor(This->editor, 0, pszText, -1, This->editor->pBuffer->pDefaultStyle); ME_SetSelection(This->editor, 0, 0); diff --git a/dlls/riched20/undo.c b/dlls/riched20/undo.c index e3ebbfb0431..8db971186ca 100644 --- a/dlls/riched20/undo.c +++ b/dlls/riched20/undo.c @@ -317,7 +317,9 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) } case diUndoDeleteRun: { - ME_InternalDeleteText(editor, pUItem->nStart, pUItem->nLen, TRUE); + ME_Cursor tmp; + ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); + ME_InternalDeleteText(editor, &tmp, pUItem->nLen, TRUE); break; } case diUndoJoinParagraphs: