richedit: Don't recreate the DC all the time, but use uniformely a ME_Context structure where needed.
This commit is contained in:
parent
4cecb5dc70
commit
475b45d8ab
|
@ -150,7 +150,7 @@ ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor,
|
||||||
void ME_CheckCharOffsets(ME_TextEditor *editor);
|
void ME_CheckCharOffsets(ME_TextEditor *editor);
|
||||||
void ME_PropagateCharOffset(ME_DisplayItem *p, int shift);
|
void ME_PropagateCharOffset(ME_DisplayItem *p, int shift);
|
||||||
void ME_GetGraphicsSize(ME_TextEditor *editor, ME_Run *run, SIZE *pSize);
|
void ME_GetGraphicsSize(ME_TextEditor *editor, ME_Run *run, SIZE *pSize);
|
||||||
int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run);
|
int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run);
|
||||||
/* this one accounts for 1/2 char tolerance */
|
/* this one accounts for 1/2 char tolerance */
|
||||||
int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run);
|
int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run);
|
||||||
int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset);
|
int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset);
|
||||||
|
|
|
@ -487,11 +487,10 @@ void ME_GetGraphicsSize(ME_TextEditor *editor, ME_Run *run, SIZE *pSize)
|
||||||
* pixel horizontal position. This version rounds left (ie. if the second
|
* pixel horizontal position. This version rounds left (ie. if the second
|
||||||
* character is at pixel position 8, then for cx=0..7 it returns 0).
|
* character is at pixel position 8, then for cx=0..7 it returns 0).
|
||||||
*/
|
*/
|
||||||
int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run)
|
int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
|
||||||
{
|
{
|
||||||
int fit = 0;
|
int fit = 0;
|
||||||
HGDIOBJ hOldFont;
|
HGDIOBJ hOldFont;
|
||||||
HDC hDC;
|
|
||||||
SIZE sz;
|
SIZE sz;
|
||||||
if (!run->strText->nLen)
|
if (!run->strText->nLen)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -505,29 +504,28 @@ int ME_CharFromPoint(ME_TextEditor *editor, int cx, ME_Run *run)
|
||||||
if (run->nFlags & MERF_GRAPHICS)
|
if (run->nFlags & MERF_GRAPHICS)
|
||||||
{
|
{
|
||||||
SIZE sz;
|
SIZE sz;
|
||||||
ME_GetGraphicsSize(editor, run, &sz);
|
ME_GetGraphicsSize(c->editor, run, &sz);
|
||||||
if (cx < sz.cx)
|
if (cx < sz.cx)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
hDC = GetDC(editor->hWnd);
|
hOldFont = ME_SelectStyleFont(c->editor, c->hDC, run->style);
|
||||||
hOldFont = ME_SelectStyleFont(editor, hDC, run->style);
|
|
||||||
|
|
||||||
if (editor->cPasswordMask)
|
if (c->editor->cPasswordMask)
|
||||||
{
|
{
|
||||||
ME_String *strMasked = ME_MakeStringR(editor->cPasswordMask,ME_StrVLen(run->strText));
|
ME_String *strMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
|
||||||
GetTextExtentExPointW(hDC, strMasked->szData, run->strText->nLen,
|
GetTextExtentExPointW(c->hDC, strMasked->szData, run->strText->nLen,
|
||||||
cx, &fit, NULL, &sz);
|
cx, &fit, NULL, &sz);
|
||||||
ME_DestroyString(strMasked);
|
ME_DestroyString(strMasked);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetTextExtentExPointW(hDC, run->strText->szData, run->strText->nLen,
|
GetTextExtentExPointW(c->hDC, run->strText->szData, run->strText->nLen,
|
||||||
cx, &fit, NULL, &sz);
|
cx, &fit, NULL, &sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
ME_UnselectStyleFont(editor, hDC, run->style, hOldFont);
|
ME_UnselectStyleFont(c->editor, c->hDC, run->style, hOldFont);
|
||||||
ReleaseDC(editor->hWnd, hDC);
|
|
||||||
return fit;
|
return fit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
|
||||||
int i, idesp, len;
|
int i, idesp, len;
|
||||||
ME_Run *run = &p->member.run;
|
ME_Run *run = &p->member.run;
|
||||||
|
|
||||||
idesp = i = ME_CharFromPoint(wc->context->editor, loc, run);
|
idesp = i = ME_CharFromPoint(wc->context, loc, run);
|
||||||
len = ME_StrVLen(run->strText);
|
len = ME_StrVLen(run->strText);
|
||||||
assert(len>0);
|
assert(len>0);
|
||||||
assert(i<len);
|
assert(i<len);
|
||||||
|
|
Loading…
Reference in New Issue