riched20: Add a helper to retrieve the run text.
This commit is contained in:
parent
c17af77b5c
commit
27578f8bb6
|
@ -380,7 +380,7 @@ BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start,
|
|||
|
||||
/* nOfs is a character offset (from the start of the document
|
||||
to the current (deleted) run */
|
||||
add_undo_insert_run( editor, nOfs + nChars, run->strText->szData + c.nOffset, nCharsToDelete, run->nFlags, run->style );
|
||||
add_undo_insert_run( editor, nOfs + nChars, get_text( run, c.nOffset ), nCharsToDelete, run->nFlags, run->style );
|
||||
|
||||
TRACE("Post deletion string: %s (%d)\n", debugstr_run( run ), run->strText->nLen);
|
||||
TRACE("Shift value: %d\n", shift);
|
||||
|
|
|
@ -1723,7 +1723,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
if ((flags & FR_WHOLEWORD) && nMin)
|
||||
{
|
||||
ME_CursorFromCharOfs(editor, nMin - 1, &cursor);
|
||||
wLastChar = cursor.pRun->member.run.strText->szData[cursor.nOffset];
|
||||
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
|
||||
ME_MoveCursorChars(editor, &cursor, 1);
|
||||
} else {
|
||||
ME_CursorFromCharOfs(editor, nMin, &cursor);
|
||||
|
@ -1735,7 +1735,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
int nCurStart = cursor.nOffset;
|
||||
int nMatched = 0;
|
||||
|
||||
while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurStart + nMatched], text[nMatched], (flags & FR_MATCHCASE)))
|
||||
while (pCurItem && ME_CharCompare( *get_text( &pCurItem->member.run, nCurStart + nMatched ), text[nMatched], (flags & FR_MATCHCASE)))
|
||||
{
|
||||
if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar))
|
||||
break;
|
||||
|
@ -1757,7 +1757,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
}
|
||||
|
||||
if (pNextItem)
|
||||
wNextChar = pNextItem->member.run.strText->szData[nNextStart + nMatched];
|
||||
wNextChar = *get_text( &pNextItem->member.run, nNextStart + nMatched );
|
||||
else
|
||||
wNextChar = ' ';
|
||||
|
||||
|
@ -1781,7 +1781,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
}
|
||||
}
|
||||
if (pCurItem)
|
||||
wLastChar = pCurItem->member.run.strText->szData[nCurStart + nMatched];
|
||||
wLastChar = *get_text( &pCurItem->member.run, nCurStart + nMatched );
|
||||
else
|
||||
wLastChar = ' ';
|
||||
|
||||
|
@ -1799,7 +1799,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
if ((flags & FR_WHOLEWORD) && nMax < nTextLen - 1)
|
||||
{
|
||||
ME_CursorFromCharOfs(editor, nMax + 1, &cursor);
|
||||
wLastChar = cursor.pRun->member.run.strText->szData[cursor.nOffset];
|
||||
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
|
||||
ME_MoveCursorChars(editor, &cursor, -1);
|
||||
} else {
|
||||
ME_CursorFromCharOfs(editor, nMax, &cursor);
|
||||
|
@ -1818,7 +1818,8 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
nCurEnd = pCurItem->member.run.strText->nLen + nMatched;
|
||||
}
|
||||
|
||||
while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
|
||||
while (pCurItem && ME_CharCompare( *get_text( &pCurItem->member.run, nCurEnd - nMatched - 1 ),
|
||||
text[nLen - nMatched - 1], (flags & FR_MATCHCASE) ))
|
||||
{
|
||||
if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar))
|
||||
break;
|
||||
|
@ -1842,7 +1843,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
}
|
||||
|
||||
if (pPrevItem)
|
||||
wPrevChar = pPrevItem->member.run.strText->szData[nPrevEnd - nMatched - 1];
|
||||
wPrevChar = *get_text( &pPrevItem->member.run, nPrevEnd - nMatched - 1 );
|
||||
else
|
||||
wPrevChar = ' ';
|
||||
|
||||
|
@ -1869,7 +1870,7 @@ ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCH
|
|||
}
|
||||
}
|
||||
if (pCurItem)
|
||||
wLastChar = pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1];
|
||||
wLastChar = *get_text( &pCurItem->member.run, nCurEnd - nMatched - 1 );
|
||||
else
|
||||
wLastChar = ' ';
|
||||
|
||||
|
@ -3704,16 +3705,15 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
|||
while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow))
|
||||
&& run->type == diRun)
|
||||
{
|
||||
WCHAR *str = get_text( &run->member.run, 0 );
|
||||
unsigned int nCopy;
|
||||
ME_String *strText;
|
||||
|
||||
strText = run->member.run.strText;
|
||||
nCopy = min(nCharsLeft, strText->nLen);
|
||||
nCopy = min(nCharsLeft, run->member.run.strText->nLen);
|
||||
|
||||
if (unicode)
|
||||
memcpy(dest, strText->szData, nCopy * sizeof(WCHAR));
|
||||
memcpy(dest, str, nCopy * sizeof(WCHAR));
|
||||
else
|
||||
nCopy = WideCharToMultiByte(CP_ACP, 0, strText->szData, nCopy, dest,
|
||||
nCopy = WideCharToMultiByte(CP_ACP, 0, str, nCopy, dest,
|
||||
nCharsLeft, NULL, NULL);
|
||||
dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
|
||||
nCharsLeft -= nCopy;
|
||||
|
@ -3756,7 +3756,7 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
|||
if (editor->bEmulateVersion10 && prev_para &&
|
||||
last_para->member.run.nCharOfs == 0 &&
|
||||
prev_para->member.run.strText->nLen == 1 &&
|
||||
prev_para->member.run.strText->szData[0] == '\r')
|
||||
*get_text( &prev_para->member.run, 0 ) == '\r')
|
||||
{
|
||||
/* In 1.0 emulation, the last solitary \r at the very end of the text
|
||||
(if one exists) is NOT a line break.
|
||||
|
@ -4605,7 +4605,7 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
|
|||
pNextRun = ME_FindItemFwd(pRun, diRun);
|
||||
|
||||
nLen = pRun->member.run.strText->nLen - start->nOffset;
|
||||
str = pRun->member.run.strText->szData + start->nOffset;
|
||||
str = get_text( &pRun->member.run, start->nOffset );
|
||||
|
||||
/* No '\r' is appended to the last paragraph. */
|
||||
while (srcChars && buflen && pNextRun)
|
||||
|
@ -4637,7 +4637,7 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
|
|||
pNextRun = ME_FindItemFwd(pRun, diRun);
|
||||
|
||||
nLen = pRun->member.run.strText->nLen;
|
||||
str = pRun->member.run.strText->szData;
|
||||
str = get_text( &pRun->member.run, 0 );
|
||||
}
|
||||
*buffer = 0;
|
||||
return buffer - pStart;
|
||||
|
@ -4777,7 +4777,7 @@ static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor,
|
|||
|
||||
while (nChars > 0)
|
||||
{
|
||||
WCHAR *strStart = cursor.pRun->member.run.strText->szData;
|
||||
WCHAR *strStart = get_text( &cursor.pRun->member.run, 0 );
|
||||
WCHAR *str = strStart + cursor.nOffset;
|
||||
int nLen = cursor.pRun->member.run.strText->nLen - cursor.nOffset;
|
||||
nChars -= nLen;
|
||||
|
|
|
@ -56,7 +56,15 @@ static inline void * __WINE_ALLOC_SIZE(2) heap_realloc( void *ptr, size_t len )
|
|||
(fe).lindex=-1;\
|
||||
};
|
||||
|
||||
static inline const char *debugstr_run( const ME_Run *run ) { return debugstr_w( run->strText->szData ); }
|
||||
static inline WCHAR *get_text( const ME_Run *run, int offset )
|
||||
{
|
||||
return run->strText->szData + offset;
|
||||
}
|
||||
|
||||
static inline const char *debugstr_run( const ME_Run *run )
|
||||
{
|
||||
return debugstr_w( get_text( run, 0 ) );
|
||||
}
|
||||
|
||||
/* style.c */
|
||||
ME_Style *ME_MakeStyle(CHARFORMAT2W *style) DECLSPEC_HIDDEN;
|
||||
|
|
|
@ -435,7 +435,7 @@ static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Pa
|
|||
}
|
||||
else
|
||||
ME_DrawTextWithStyle(c, x, y,
|
||||
run->strText->szData, run->strText->nLen, run->style, run->nWidth,
|
||||
get_text( run, 0 ), run->strText->nLen, run->style, run->nWidth,
|
||||
nSelFrom-runofs,nSelTo-runofs,
|
||||
c->pt.y + para->pt.y + start->member.row.pt.y,
|
||||
start->member.row.nHeight);
|
||||
|
@ -947,13 +947,12 @@ static void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph)
|
|||
c->pt.y + para->pt.y + run->pt.y + baseline, p, para);
|
||||
if (me_debug)
|
||||
{
|
||||
/* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
|
||||
const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
|
||||
WCHAR buf[2560];
|
||||
POINT pt;
|
||||
pt.x = c->pt.x + run->pt.x;
|
||||
pt.y = c->pt.y + para->pt.y + run->pt.y;
|
||||
wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
|
||||
wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, get_text( &p->member.run, 0 ));
|
||||
ME_DebugWrite(c->hDC, &pt, buf);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -461,7 +461,7 @@ int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
|
|||
}
|
||||
else
|
||||
{
|
||||
GetTextExtentExPointW(c->hDC, run->strText->szData, run->strText->nLen,
|
||||
GetTextExtentExPointW(c->hDC, get_text( run, 0 ), run->strText->nLen,
|
||||
cx, &fit, NULL, &sz);
|
||||
}
|
||||
|
||||
|
@ -483,10 +483,9 @@ int ME_CharFromPoint(ME_Context *c, int cx, ME_Run *run)
|
|||
*/
|
||||
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;
|
||||
ME_String *mask_text = NULL;
|
||||
WCHAR *str;
|
||||
int fit = 0, len;
|
||||
ME_Context c;
|
||||
HGDIOBJ hOldFont;
|
||||
SIZE sz, sz2, sz3;
|
||||
|
@ -510,24 +509,27 @@ int ME_CharFromPointCursor(ME_TextEditor *editor, int cx, ME_Run *run)
|
|||
return 1;
|
||||
}
|
||||
|
||||
len = run->strText->nLen;
|
||||
if (editor->cPasswordMask)
|
||||
strRunText = ME_MakeStringR(editor->cPasswordMask, run->strText->nLen);
|
||||
{
|
||||
mask_text = ME_MakeStringR( editor->cPasswordMask, len );
|
||||
str = mask_text->szData;
|
||||
}
|
||||
else
|
||||
strRunText = run->strText;
|
||||
str = get_text( run, 0 );
|
||||
|
||||
hOldFont = ME_SelectStyleFont(&c, run->style);
|
||||
GetTextExtentExPointW(c.hDC, strRunText->szData, strRunText->nLen,
|
||||
GetTextExtentExPointW(c.hDC, str, len,
|
||||
cx, &fit, NULL, &sz);
|
||||
if (fit != strRunText->nLen)
|
||||
if (fit != len)
|
||||
{
|
||||
GetTextExtentPoint32W(c.hDC, strRunText->szData, fit, &sz2);
|
||||
GetTextExtentPoint32W(c.hDC, strRunText->szData, fit + 1, &sz3);
|
||||
GetTextExtentPoint32W(c.hDC, str, fit, &sz2);
|
||||
GetTextExtentPoint32W(c.hDC, str, fit + 1, &sz3);
|
||||
if (cx >= (sz2.cx+sz3.cx)/2)
|
||||
fit = fit + 1;
|
||||
}
|
||||
|
||||
if (editor->cPasswordMask)
|
||||
ME_DestroyString(strRunText);
|
||||
ME_DestroyString( mask_text );
|
||||
|
||||
ME_UnselectStyleFont(&c, run->style, hOldFont);
|
||||
ME_DestroyContext(&c);
|
||||
|
@ -562,8 +564,9 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
|
|||
{
|
||||
SIZE size;
|
||||
ME_Context c;
|
||||
ME_String *strRunText;
|
||||
/* This could point to either the run's real text, or it's masked form in a password control */
|
||||
ME_String *mask_text = NULL;
|
||||
WCHAR *str;
|
||||
int len;
|
||||
|
||||
ME_InitContext(&c, editor, ITextHost_TxGetDC(editor->texthost));
|
||||
if (pRun->nFlags & MERF_GRAPHICS)
|
||||
|
@ -576,15 +579,18 @@ int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
|
|||
nOffset = 0;
|
||||
}
|
||||
|
||||
len = pRun->strText->nLen;
|
||||
if (editor->cPasswordMask)
|
||||
strRunText = ME_MakeStringR(editor->cPasswordMask, pRun->strText->nLen);
|
||||
{
|
||||
mask_text = ME_MakeStringR(editor->cPasswordMask, len);
|
||||
str = mask_text->szData;
|
||||
}
|
||||
else
|
||||
strRunText = pRun->strText;
|
||||
str = get_text( pRun, 0 );
|
||||
|
||||
ME_GetTextExtent(&c, strRunText->szData, nOffset, pRun->style, &size);
|
||||
ME_GetTextExtent(&c, str, nOffset, pRun->style, &size);
|
||||
ME_DestroyContext(&c);
|
||||
if (editor->cPasswordMask)
|
||||
ME_DestroyString(strRunText);
|
||||
ME_DestroyString( mask_text );
|
||||
return size.cx;
|
||||
}
|
||||
|
||||
|
@ -616,7 +622,7 @@ static SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run
|
|||
}
|
||||
else
|
||||
{
|
||||
ME_GetTextExtent(c, run->strText->szData, nLen, run->style, &size);
|
||||
ME_GetTextExtent(c, get_text( run, 0 ), nLen, run->style, &size);
|
||||
}
|
||||
*pAscent = run->style->tm.tmAscent;
|
||||
*pDescent = run->style->tm.tmDescent;
|
||||
|
|
|
@ -112,7 +112,7 @@ static void ME_InsertRowStart(ME_WrapContext *wc, const ME_DisplayItem *pEnd)
|
|||
* Other whitespace or delimiters are not treated this way. */
|
||||
SIZE sz;
|
||||
int len = p->member.run.strText->nLen;
|
||||
WCHAR *text = p->member.run.strText->szData + len - 1;
|
||||
WCHAR *text = get_text( &p->member.run, len - 1 );
|
||||
|
||||
assert (len);
|
||||
if (~p->member.run.nFlags & MERF_GRAPHICS)
|
||||
|
|
|
@ -885,7 +885,7 @@ static BOOL ME_StreamOutRTF(ME_TextEditor *editor, ME_OutStream *pStream,
|
|||
return FALSE;
|
||||
|
||||
nEnd = (cursor.pRun == endCur.pRun) ? endCur.nOffset : cursor.pRun->member.run.strText->nLen;
|
||||
if (!ME_StreamOutRTFText(pStream, cursor.pRun->member.run.strText->szData + cursor.nOffset,
|
||||
if (!ME_StreamOutRTFText(pStream, get_text( &cursor.pRun->member.run, cursor.nOffset ),
|
||||
nEnd - cursor.nOffset))
|
||||
return FALSE;
|
||||
cursor.nOffset = 0;
|
||||
|
@ -932,19 +932,19 @@ static BOOL ME_StreamOutText(ME_TextEditor *editor, ME_OutStream *pStream,
|
|||
success = ME_StreamOutMove(pStream, "\r\n", 2);
|
||||
} else {
|
||||
if (dwFormat & SF_UNICODE)
|
||||
success = ME_StreamOutMove(pStream, (const char *)(cursor.pRun->member.run.strText->szData + cursor.nOffset),
|
||||
success = ME_StreamOutMove(pStream, (const char *)(get_text( &cursor.pRun->member.run, cursor.nOffset )),
|
||||
sizeof(WCHAR) * nLen);
|
||||
else {
|
||||
int nSize;
|
||||
|
||||
nSize = WideCharToMultiByte(nCodePage, 0, cursor.pRun->member.run.strText->szData + cursor.nOffset,
|
||||
nSize = WideCharToMultiByte(nCodePage, 0, get_text( &cursor.pRun->member.run, cursor.nOffset ),
|
||||
nLen, NULL, 0, NULL, NULL);
|
||||
if (nSize > nBufLen) {
|
||||
FREE_OBJ(buffer);
|
||||
buffer = ALLOC_N_OBJ(char, nSize);
|
||||
nBufLen = nSize;
|
||||
}
|
||||
WideCharToMultiByte(nCodePage, 0, cursor.pRun->member.run.strText->szData + cursor.nOffset,
|
||||
WideCharToMultiByte(nCodePage, 0, get_text( &cursor.pRun->member.run, cursor.nOffset ),
|
||||
nLen, buffer, nSize, NULL, NULL);
|
||||
success = ME_StreamOutMove(pStream, buffer, nSize);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue