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.
This commit is contained in:
parent
12ca50db7a
commit
d20e057d8e
|
@ -42,7 +42,9 @@ void ME_GetSelection(ME_TextEditor *editor, int *from, int *to)
|
||||||
|
|
||||||
int ME_GetTextLength(ME_TextEditor *editor)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2907,23 +2907,20 @@ get_msg_name(UINT msg)
|
||||||
void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
|
void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
int x,y;
|
int x,y;
|
||||||
ME_Cursor tmpCursor;
|
ME_DisplayItem *para, *run;
|
||||||
BOOL isExact;
|
BOOL isExact;
|
||||||
int nCharOfs; /* The start of the clicked text. Absolute character offset */
|
int nCharOfs; /* The start of the clicked text. Absolute character offset */
|
||||||
|
|
||||||
ME_Run *tmpRun;
|
|
||||||
|
|
||||||
ENLINK info;
|
ENLINK info;
|
||||||
x = (short)LOWORD(lParam);
|
x = (short)LOWORD(lParam);
|
||||||
y = (short)HIWORD(lParam);
|
y = (short)HIWORD(lParam);
|
||||||
nCharOfs = ME_CharFromPos(editor, x, y, &isExact);
|
nCharOfs = ME_CharFromPos(editor, x, y, &isExact);
|
||||||
if (!isExact) return;
|
if (!isExact) return;
|
||||||
|
|
||||||
ME_CursorFromCharOfs(editor, nCharOfs, &tmpCursor);
|
ME_RunOfsFromCharOfs(editor, nCharOfs, ¶, &run, NULL);
|
||||||
tmpRun = &tmpCursor.pRun->member.run;
|
|
||||||
|
|
||||||
if ((tmpRun->style->fmt.dwMask & CFM_LINK)
|
if ((run->member.run.style->fmt.dwMask & CFM_LINK)
|
||||||
&& (tmpRun->style->fmt.dwEffects & CFE_LINK))
|
&& (run->member.run.style->fmt.dwEffects & CFE_LINK))
|
||||||
{ /* The clicked run has CFE_LINK set */
|
{ /* The clicked run has CFE_LINK set */
|
||||||
info.nmhdr.hwndFrom = editor->hWnd;
|
info.nmhdr.hwndFrom = editor->hWnd;
|
||||||
info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
|
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.msg = msg;
|
||||||
info.wParam = wParam;
|
info.wParam = wParam;
|
||||||
info.lParam = lParam;
|
info.lParam = lParam;
|
||||||
info.chrg.cpMin = ME_CharOfsFromRunOfs(editor,tmpCursor.pRun,0);
|
info.chrg.cpMin = ME_CharOfsFromRunOfs(editor, para, run, 0);
|
||||||
info.chrg.cpMax = info.chrg.cpMin + ME_StrVLen(tmpRun->strText);
|
info.chrg.cpMax = info.chrg.cpMin + run->member.run.strText->nLen;
|
||||||
SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,info.nmhdr.idFrom, (LPARAM)&info);
|
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;
|
ME_DisplayItem *item, *item_end;
|
||||||
int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
|
int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
|
||||||
ME_Cursor cursor;
|
ME_DisplayItem *para, *run;
|
||||||
|
|
||||||
if (wParam > ME_GetTextLength(editor))
|
if (wParam > ME_GetTextLength(editor))
|
||||||
return 0;
|
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");
|
FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ME_CursorFromCharOfs(editor, wParam, &cursor);
|
ME_RunOfsFromCharOfs(editor, wParam, ¶, &run, NULL);
|
||||||
item = ME_RowStart(cursor.pRun);
|
item = ME_RowStart(run);
|
||||||
nThisLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item, diRun), 0);
|
nThisLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item, diRun), 0);
|
||||||
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
|
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
|
||||||
if (item_end->type == diStartRow)
|
if (item_end->type == diStartRow) {
|
||||||
nNextLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item_end, diRun), 0);
|
nNextLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item_end, diRun), 0);
|
||||||
else
|
} else {
|
||||||
{
|
ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
|
||||||
ME_DisplayItem *endPara;
|
assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
|
||||||
|
nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.strText->nLen;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
nChars = nNextLineOfs - nThisLineOfs;
|
nChars = nNextLineOfs - nThisLineOfs;
|
||||||
TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
|
TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
|
||||||
|
|
|
@ -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);
|
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_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);
|
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_SkipAndPropagateCharOffset(ME_DisplayItem *p, int shift);
|
||||||
void ME_SetCharFormat(ME_TextEditor *editor, int nFrom, int nLen, CHARFORMAT2W *pFmt);
|
void ME_SetCharFormat(ME_TextEditor *editor, int nFrom, int nLen, CHARFORMAT2W *pFmt);
|
||||||
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt);
|
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt);
|
||||||
|
|
|
@ -146,18 +146,12 @@ void ME_CheckCharOffsets(ME_TextEditor *editor)
|
||||||
* character position relative to the start of the document.
|
* character position relative to the start of the document.
|
||||||
* Kind of a "local to global" offset conversion.
|
* Kind of a "local to global" offset conversion.
|
||||||
*/
|
*/
|
||||||
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)
|
||||||
{
|
{
|
||||||
ME_DisplayItem *pPara;
|
assert(pRun && pRun->type == diRun);
|
||||||
|
assert(pPara && pPara->type == diParagraph);
|
||||||
assert(pRun->type == diRun);
|
return pPara->member.para.nCharOfs + pRun->member.run.nCharOfs + nOfs;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
|
Loading…
Reference in New Issue