diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h index 9722f366cf8..4401498ab1b 100644 --- a/dlls/riched20/editor.h +++ b/dlls/riched20/editor.h @@ -140,7 +140,6 @@ ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN; void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN; -int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run) DECLSPEC_HIDDEN; /* this one accounts for 1/2 char tolerance */ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run) DECLSPEC_HIDDEN; int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) DECLSPEC_HIDDEN; diff --git a/dlls/riched20/run.c b/dlls/riched20/run.c index aaa6300a893..6f9d5b59cb6 100644 --- a/dlls/riched20/run.c +++ b/dlls/riched20/run.c @@ -403,56 +403,6 @@ void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) run->nFlags &= ~(MERF_WHITESPACE | MERF_STARTWHITE | MERF_ENDWHITE); } -/****************************************************************************** - * ME_CharFromPoint - * - * Returns a character position inside the run given a run-relative - * 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). - */ -int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run) -{ - int fit = 0; - HGDIOBJ hOldFont; - SIZE sz; - if (!run->len || cx <= 0) - return 0; - - if (run->nFlags & MERF_TAB || - (run->nFlags & (MERF_ENDCELL|MERF_ENDPARA)) == MERF_ENDCELL) - { - if (cx < run->nWidth/2) - return 0; - return 1; - } - if (run->nFlags & MERF_GRAPHICS) - { - SIZE sz; - ME_GetOLEObjectSize(c, run, &sz); - if (cx < sz.cx) - return 0; - return 1; - } - hOldFont = ME_SelectStyleFont(c, run->style); - - if (c->editor->cPasswordMask) - { - ME_String *strMasked = ME_MakeStringR(c->editor->cPasswordMask, run->len); - GetTextExtentExPointW(c->hDC, strMasked->szData, run->len, - cx, &fit, NULL, &sz); - ME_DestroyString(strMasked); - } - else - { - GetTextExtentExPointW(c->hDC, get_text( run, 0 ), run->len, - cx, &fit, NULL, &sz); - } - - ME_UnselectStyleFont(c, run->style, hOldFont); - - return fit; -} - /****************************************************************************** * ME_CharFromPointCursor * diff --git a/dlls/riched20/wrap.c b/dlls/riched20/wrap.c index 97598e78d61..0531c971b15 100644 --- a/dlls/riched20/wrap.c +++ b/dlls/riched20/wrap.c @@ -80,6 +80,51 @@ static ME_DisplayItem *split_run_extents(ME_WrapContext *wc, ME_DisplayItem *ite return cursor.pRun; } +/****************************************************************************** + * find_split_point + * + * Returns a character position to split inside the run given a run-relative + * 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). + */ +static int find_split_point( ME_Context *c, int cx, ME_Run *run ) +{ + int fit = 0; + HGDIOBJ hOldFont; + SIZE sz; + + if (!run->len || cx <= 0) return 0; + + if (run->nFlags & MERF_TAB || + (run->nFlags & (MERF_ENDCELL|MERF_ENDPARA)) == MERF_ENDCELL) + { + if (cx < run->nWidth / 2) return 0; + return 1; + } + if (run->nFlags & MERF_GRAPHICS) + { + SIZE sz; + ME_GetOLEObjectSize( c, run, &sz ); + if (cx < sz.cx) return 0; + return 1; + } + hOldFont = ME_SelectStyleFont( c, run->style ); + + if (c->editor->cPasswordMask) + { + ME_String *strMasked = ME_MakeStringR( c->editor->cPasswordMask, run->len ); + GetTextExtentExPointW( c->hDC, strMasked->szData, run->len, cx, &fit, NULL, &sz ); + ME_DestroyString( strMasked ); + } + else + { + GetTextExtentExPointW( c->hDC, get_text( run, 0 ), run->len, cx, &fit, NULL, &sz ); + } + + ME_UnselectStyleFont( c, run->style, hOldFont ); + + return fit; +} static ME_DisplayItem *ME_MakeRow(int height, int baseline, int width) { @@ -337,7 +382,7 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem int i, idesp, len; ME_Run *run = &p->member.run; - idesp = i = ME_CharFromPoint(wc->context, loc, run); + idesp = i = find_split_point( wc->context, loc, run ); len = run->len; assert(len>0); assert(i