richedit: Removed ME_StrRelPos, ME_StrRelPos2, & ME_PosToVPos functions.

These functions were just being used for addition, so it was simpler to
remove the functions and modify the places it was used.

The ME_StrRelPos2 and ME_PosToVPos were just simple wrappers around
ME_StrRelPos, and ME_PosToVPos wasn't being used.
This commit is contained in:
Dylan Smith 2009-02-07 13:21:29 -05:00 committed by Alexandre Julliard
parent 1eb0f73ab0
commit c8b4455565
5 changed files with 26 additions and 66 deletions

View File

@ -576,7 +576,7 @@ static BOOL
ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs)
{
ME_DisplayItem *pRun = pCursor->pRun;
if (nRelOfs == -1)
{
if (!pCursor->nOffset)
@ -608,17 +608,17 @@ ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *pCursor, int nRelOfs)
else
pCursor->nOffset = pRun->member.run.strText->nLen;
}
if (pCursor->nOffset)
pCursor->nOffset = ME_StrRelPos2(pCursor->pRun->member.run.strText, pCursor->nOffset, nRelOfs);
pCursor->nOffset = pCursor->nOffset + nRelOfs;
return TRUE;
}
else
{
if (!(pRun->member.run.nFlags & MERF_ENDPARA))
{
int new_ofs = ME_StrRelPos2(pRun->member.run.strText, pCursor->nOffset, nRelOfs);
int new_ofs = pCursor->nOffset + nRelOfs;
if (new_ofs < pRun->member.run.strText->nLen)
{
pCursor->nOffset = new_ofs;

View File

@ -100,9 +100,6 @@ int ME_IsSplitable(const ME_String *s);
int ME_FindNonWhitespaceV(const ME_String *s, int nVChar);
int ME_FindWhitespaceV(ME_String *s, int nVChar);
int ME_CallWordBreakProc(ME_TextEditor *editor, ME_String *str, INT start, INT code);
int ME_StrRelPos(const ME_String *s, int nVChar, int *pRelChars);
int ME_StrRelPos2(const ME_String *s, int nVChar, int nRelChars);
int ME_PosToVPos(const ME_String *s, int nPos);
void ME_StrDeleteV(ME_String *s, int nVChar, int nChars);
/* smart helpers for A<->W conversions, they reserve/free memory and call MultiByte<->WideChar functions */
LPWSTR ME_ToUnicode(BOOL unicode, LPVOID psz);

View File

@ -500,21 +500,21 @@ int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
/******************************************************************************
* ME_CharFromPointCursor
*
*
* Returns a character position inside the run given a run-relative
* pixel horizontal position. This version rounds to the nearest character edge
* (ie. if the second character is at pixel position 8, then for cx=0..3
* pixel horizontal position. This version rounds to the nearest character edge
* (ie. if the second character is at pixel position 8, then for cx=0..3
* it returns 0, and for cx=4..7 it returns 1).
*
*
* It is used for mouse click handling, for better usability (and compatibility
* with the native control).
*/
* with the native control).
*/
int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
{
ME_String *strRunText;
/* This could point to either the run's real text, or it's masked form in a password control */
int fit = 0, fit1 = 0;
int fit = 0;
ME_Context c;
HGDIOBJ hOldFont;
SIZE sz, sz2, sz3;
@ -548,18 +548,15 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
cx, &fit, NULL, &sz);
if (fit != strRunText->nLen)
{
int chars = 1;
GetTextExtentPoint32W(c.hDC, strRunText->szData, fit, &sz2);
fit1 = ME_StrRelPos(strRunText, fit, &chars);
GetTextExtentPoint32W(c.hDC, strRunText->szData, fit1, &sz3);
GetTextExtentPoint32W(c.hDC, strRunText->szData, fit + 1, &sz3);
if (cx >= (sz2.cx+sz3.cx)/2)
fit = fit1;
fit = fit + 1;
}
if (editor->cPasswordMask)
ME_DestroyString(strRunText);
ME_UnselectStyleFont(&c, run->style, hOldFont);
ME_DestroyContext(&c);
return fit;

View File

@ -141,49 +141,17 @@ int ME_IsSplitable(const ME_String *s)
return 0;
}
int ME_StrRelPos(const ME_String *s, int nVChar, int *pRelChars)
{
int nRelChars = *pRelChars;
TRACE("%s,%d,&%d\n", debugstr_w(s->szData), nVChar, *pRelChars);
assert(*pRelChars);
if (!nRelChars)
return nVChar;
if (nRelChars>0)
nRelChars = min(*pRelChars, s->nLen - nVChar);
else
nRelChars = max(*pRelChars, -nVChar);
nVChar += nRelChars;
*pRelChars -= nRelChars;
return nVChar;
}
int ME_StrRelPos2(const ME_String *s, int nVChar, int nRelChars)
{
return ME_StrRelPos(s, nVChar, &nRelChars);
}
int ME_PosToVPos(const ME_String *s, int nPos)
{
if (!nPos)
return 0;
return ME_StrRelPos2(s, 0, nPos);
}
void ME_StrDeleteV(ME_String *s, int nVChar, int nChars)
{
int end_ofs;
assert(nVChar >=0 && nVChar <= s->nLen);
int end_ofs = nVChar + nChars;
assert(nChars >= 0);
assert(nVChar+nChars <= s->nLen);
end_ofs = ME_StrRelPos2(s, nVChar, nChars);
assert(nVChar >= 0);
assert(end_ofs <= s->nLen);
memmove(s->szData+nVChar, s->szData+end_ofs, 2*(s->nLen+1-end_ofs));
s->nLen -= (end_ofs - nVChar);
memmove(s->szData + nVChar, s->szData + end_ofs,
(s->nLen - end_ofs + 1) * sizeof(WCHAR));
s->nLen -= nChars;
}
int ME_FindNonWhitespaceV(const ME_String *s, int nVChar) {

View File

@ -316,11 +316,9 @@ static ME_DisplayItem *ME_SplitByBacktracking(ME_WrapContext *wc, ME_DisplayItem
else
{
/* split point inside first character - no choice but split after that char */
int chars = 1;
int pos2 = ME_StrRelPos(run->strText, 0, &chars);
if (pos2 != len) {
if (len != 1) {
/* the run is more than 1 char, so we may split */
return ME_SplitRun(wc, piter, pos2);
return ME_SplitRun(wc, piter, 1);
}
/* the run is one char, can't split it */
return piter;