riched20: Implement SetText() for selection range.

This commit is contained in:
Nikolay Sivov 2015-05-27 01:17:41 +03:00 committed by Alexandre Julliard
parent d27234617c
commit 251e168590
3 changed files with 42 additions and 22 deletions

View File

@ -3134,6 +3134,30 @@ static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM
}
}
void ME_ReplaceSel(ME_TextEditor *editor, BOOL can_undo, const WCHAR *str, int len)
{
int from, to, nStartCursor;
ME_Style *style;
nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
style = ME_GetSelectionInsertStyle(editor);
ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
ME_InsertTextFromCursor(editor, 0, str, len, style);
ME_ReleaseStyle(style);
/* drop temporary style if line end */
/*
* FIXME question: does abc\n mean: put abc,
* clear temp style, put \n? (would require a change)
*/
if (len>0 && str[len-1] == '\n')
ME_ClearTempStyle(editor);
ME_CommitUndo(editor);
ME_UpdateSelectionLinkAttribute(editor);
if (!can_undo)
ME_EmptyUndoStack(editor);
ME_UpdateRepaint(editor, FALSE);
}
#define UNSUPPORTED_MSG(e) \
case e: \
FIXME(#e ": stub\n"); \
@ -3609,31 +3633,14 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case EM_REPLACESEL:
{
int from, to, nStartCursor;
ME_Style *style;
int len = 0;
LONG codepage = unicode ? CP_UNICODE : CP_ACP;
LPWSTR wszText = ME_ToUnicode(codepage, (void *)lParam, &len);
TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
style = ME_GetSelectionInsertStyle(editor);
ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
ME_ReleaseStyle(style);
/* drop temporary style if line end */
/*
* FIXME question: does abc\n mean: put abc,
* clear temp style, put \n? (would require a change)
*/
if (len>0 && wszText[len-1] == '\n')
ME_ClearTempStyle(editor);
ME_ReplaceSel(editor, !!wParam, wszText, len);
ME_EndToUnicode(codepage, wszText);
ME_CommitUndo(editor);
ME_UpdateSelectionLinkAttribute(editor);
if (!wParam)
ME_EmptyUndoStack(editor);
ME_UpdateRepaint(editor, FALSE);
return len;
}
case EM_SCROLLCARET:

View File

@ -262,6 +262,7 @@ void ME_RTFTblAttrHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
void ME_RTFSpecialCharHook(struct _RTF_Info *info) DECLSPEC_HIDDEN;
void ME_StreamInFill(ME_InStream *stream) DECLSPEC_HIDDEN;
extern BOOL me_debug DECLSPEC_HIDDEN;
void ME_ReplaceSel(ME_TextEditor *editor, BOOL can_undo, const WCHAR *str, int len) DECLSPEC_HIDDEN;
/* table.c */
BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN;

View File

@ -3860,14 +3860,26 @@ static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
return S_OK;
}
static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR str)
{
ITextSelectionImpl *This = impl_from_ITextSelection(me);
ME_TextEditor *editor;
int len, to, from;
TRACE("(%p)->(%s)\n", This, debugstr_w(str));
if (!This->reOle)
return CO_E_RELEASED;
FIXME("not implemented\n");
return E_NOTIMPL;
editor = This->reOle->editor;
len = strlenW(str);
ME_GetSelectionOfs(editor, &from, &to);
ME_ReplaceSel(editor, FALSE, str, len);
if (len < to - from)
textranges_update_ranges(This->reOle, from, len, RANGE_UPDATE_DELETE);
return S_OK;
}
static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)