From d20e057d8e3f2aa72d31baa935bb90786ffc0a71 Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Fri, 6 Feb 2009 01:09:51 -0500 Subject: [PATCH] richedit: Accept paragraph as parameter for ME_CharOfsFromRunOfs. Rather than get the paragraph from the run, the function allows the caller to provide the paragraph, since it is already available. This reduces unnecessary traversals of lists that take longer as more runs and rows are in the paragraph. --- dlls/riched20/caret.c | 4 +++- dlls/riched20/editor.c | 42 ++++++++++++++++-------------------------- dlls/riched20/editor.h | 2 +- dlls/riched20/run.c | 22 ++++++++-------------- 4 files changed, 28 insertions(+), 42 deletions(-) diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index e9010951cd5..0e42f10c34d 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -42,7 +42,9 @@ void ME_GetSelection(ME_TextEditor *editor, int *from, int *to) int ME_GetTextLength(ME_TextEditor *editor) { - return ME_CharOfsFromRunOfs(editor, ME_FindItemBack(editor->pBuffer->pLast, diRun), 0); + ME_DisplayItem *pLast = editor->pBuffer->pLast; + return ME_CharOfsFromRunOfs(editor, pLast->member.para.prev_para, + ME_FindItemBack(pLast, diRun), 0); } diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 285ec04b6a6..2721745884a 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2907,23 +2907,20 @@ get_msg_name(UINT msg) void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam) { int x,y; - ME_Cursor tmpCursor; + ME_DisplayItem *para, *run; BOOL isExact; int nCharOfs; /* The start of the clicked text. Absolute character offset */ - ME_Run *tmpRun; - ENLINK info; x = (short)LOWORD(lParam); y = (short)HIWORD(lParam); nCharOfs = ME_CharFromPos(editor, x, y, &isExact); if (!isExact) return; - ME_CursorFromCharOfs(editor, nCharOfs, &tmpCursor); - tmpRun = &tmpCursor.pRun->member.run; + ME_RunOfsFromCharOfs(editor, nCharOfs, ¶, &run, NULL); - if ((tmpRun->style->fmt.dwMask & CFM_LINK) - && (tmpRun->style->fmt.dwEffects & CFE_LINK)) + if ((run->member.run.style->fmt.dwMask & CFM_LINK) + && (run->member.run.style->fmt.dwEffects & CFE_LINK)) { /* The clicked run has CFE_LINK set */ info.nmhdr.hwndFrom = editor->hWnd; info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID); @@ -2931,8 +2928,8 @@ void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam info.msg = msg; info.wParam = wParam; info.lParam = lParam; - info.chrg.cpMin = ME_CharOfsFromRunOfs(editor,tmpCursor.pRun,0); - info.chrg.cpMax = info.chrg.cpMin + ME_StrVLen(tmpRun->strText); + info.chrg.cpMin = ME_CharOfsFromRunOfs(editor, para, run, 0); + info.chrg.cpMax = info.chrg.cpMin + run->member.run.strText->nLen; SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,info.nmhdr.idFrom, (LPARAM)&info); } } @@ -3709,7 +3706,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, { ME_DisplayItem *item, *item_end; int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0; - ME_Cursor cursor; + ME_DisplayItem *para, *run; if (wParam > ME_GetTextLength(editor)) return 0; @@ -3718,23 +3715,16 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam, FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n"); return 0; } - ME_CursorFromCharOfs(editor, wParam, &cursor); - item = ME_RowStart(cursor.pRun); - nThisLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item, diRun), 0); + ME_RunOfsFromCharOfs(editor, wParam, ¶, &run, NULL); + item = ME_RowStart(run); + nThisLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item, diRun), 0); item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd); - if (item_end->type == diStartRow) - nNextLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item_end, diRun), 0); - else - { - ME_DisplayItem *endPara; - - nNextLineOfs = ME_FindItemFwd(item, diParagraphOrEnd)->member.para.nCharOfs; - endPara = ME_FindItemFwd(item, diParagraphOrEnd); - endPara = ME_FindItemBack(endPara, diRun); - assert(endPara); - assert(endPara->type == diRun); - assert(endPara->member.run.nFlags & MERF_ENDPARA); - nNextLineOfs -= endPara->member.run.strText->nLen; + if (item_end->type == diStartRow) { + nNextLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item_end, diRun), 0); + } else { + ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun); + assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA); + nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.strText->nLen; } nChars = nNextLineOfs - nThisLineOfs; TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars); diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 8af49756b8d..1312363bb2d 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -163,7 +163,7 @@ void ME_CalcRunExtent(ME_Context *c, const ME_Paragraph *para, int startx, ME_Ru SIZE ME_GetRunSize(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, int startx); void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor); void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppPara, ME_DisplayItem **ppRun, int *pOfs); -int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs); +int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, const ME_DisplayItem *pRun, int nOfs); void ME_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift); void ME_SetCharFormat(ME_TextEditor *editor, int nFrom, int nLen, CHARFORMAT2W *pFmt); void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt); diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c index f71e119d9b2..fae7603428a 100644 --- a/dlls/riched20/run.c +++ b/dlls/riched20/run.c @@ -141,23 +141,17 @@ void ME_CheckCharOffsets(ME_TextEditor *editor) /****************************************************************************** * ME_CharOfsFromRunOfs - * + * * Converts a character position relative to the start of the run, to a * character position relative to the start of the document. - * Kind of a "local to global" offset conversion. - */ -int ME_CharOfsFromRunOfs(ME_TextEditor *editor, ME_DisplayItem *pRun, int nOfs) + * Kind of a "local to global" offset conversion. + */ +int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, + const ME_DisplayItem *pRun, int nOfs) { - ME_DisplayItem *pPara; - - assert(pRun->type == diRun); - assert(pRun->member.run.nCharOfs != -1); - - pPara = ME_FindItemBack(pRun, diParagraph); - assert(pPara); - assert(pPara->type==diParagraph); - return pPara->member.para.nCharOfs + pRun->member.run.nCharOfs - + ME_VPosToPos(pRun->member.run.strText, nOfs); + assert(pRun && pRun->type == diRun); + assert(pPara && pPara->type == diParagraph); + return pPara->member.para.nCharOfs + pRun->member.run.nCharOfs + nOfs; } /******************************************************************************