[PATCH 1/2] riched20: Implement ITextSelection::GetText.
Jactry Zeng
wine at jactry.com
Tue May 20 18:47:22 CDT 2014
--
Regards,
Jactry Zeng
-------------- next part --------------
From fdbabf9349e95042be9180af93dead58b08c2c10 Mon Sep 17 00:00:00 2001
From: Jactry Zeng <wine at jactry.com>
Date: Mon, 5 May 2014 07:36:49 +0800
Subject: riched20: Implement ITextSelection::GetText.
---
dlls/riched20/editor.h | 1 +
dlls/riched20/richole.c | 34 +++++++++++++++++--
dlls/riched20/tests/richole.c | 79 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 111 insertions(+), 3 deletions(-)
diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index af7291f..23f3d4e 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -245,6 +245,7 @@ void ME_DrawOLE(ME_Context *c, int x, int y, ME_Run* run, ME_Paragraph *para, BO
void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize) DECLSPEC_HIDDEN;
void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src) DECLSPEC_HIDDEN;
void ME_DeleteReObject(REOBJECT* reo) DECLSPEC_HIDDEN;
+HRESULT ME_ITextGetText(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, BSTR *pb) DECLSPEC_HIDDEN;
/* editor.c */
ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10) DECLSPEC_HIDDEN;
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 6f2d579..65edb04 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -783,11 +783,16 @@ static HRESULT WINAPI ITextSelection_fnInvoke(
static HRESULT WINAPI ITextSelection_fnGetText(ITextSelection *me, BSTR *pbstr)
{
ITextSelectionImpl *This = impl_from_ITextSelection(me);
+ ME_Cursor *start = NULL, *end = NULL;
+
+ TRACE("%p\n", pbstr);
if (!This->reOle)
return CO_E_RELEASED;
+ if (!pbstr)
+ return E_INVALIDARG;
- FIXME("not implemented\n");
- return E_NOTIMPL;
+ ME_GetSelection(This->reOle->editor, &start, &end);
+ return ME_ITextGetText(This->reOle->editor, start, end, pbstr);
}
static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
@@ -1727,3 +1732,28 @@ void ME_CopyReObject(REOBJECT* dst, const REOBJECT* src)
if (dst->pstg) IStorage_AddRef(dst->pstg);
if (dst->polesite) IOleClientSite_AddRef(dst->polesite);
}
+
+HRESULT ME_ITextGetText(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, BSTR *pb)
+{
+ LPWSTR buffer = NULL;
+ int nChars = ME_GetCursorOfs(end) - ME_GetCursorOfs(start);
+
+ TRACE("%p, %p, %p, %p\n", editor, start, end, pb);
+ if (!nChars)
+ {
+ *pb = NULL;
+ return S_OK;
+ }
+ buffer = heap_alloc((nChars + 1) * sizeof(WCHAR));
+ if (!buffer)
+ return E_OUTOFMEMORY;
+ ME_GetTextW(editor, buffer, nChars, start, nChars, 0);
+ buffer[nChars] = 0;
+ /* FIXME: a '\r' should be appended at the end of a story */
+ *pb = SysAllocString(buffer);
+ heap_free(buffer);
+
+ TRACE("%s\n", wine_dbgstr_w(*pb));
+
+ return S_OK;
+}
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 5a3ffbe..efbcbdb 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -86,10 +86,11 @@ static void create_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txt
static void release_interfaces(HWND *w, IRichEditOle **reOle, ITextDocument **txtDoc,
ITextSelection **txtSel)
{
+ if(txtSel)
+ ITextSelection_Release(*txtSel);
ITextDocument_Release(*txtDoc);
IRichEditOle_Release(*reOle);
DestroyWindow(*w);
- ITextSelection_Release(*txtSel);
}
static void test_Interfaces(void)
@@ -385,6 +386,81 @@ static void test_ITextDocument_Open(void)
VariantClear(&testfile);
}
+static void test_ITextSelection_GetText(void)
+{
+ HWND w;
+ IRichEditOle *reOle = NULL;
+ ITextDocument *txtDoc = NULL;
+ ITextSelection *txtSel = NULL;
+ HRESULT hres;
+ BSTR bstr = NULL;
+ int first, lim;
+ static const CHAR test_text1[] = "TestSomeText";
+ static const WCHAR bufW1[] = {'T', 'e', 's', 't', 0};
+ static const WCHAR bufW2[] = {'T', 'e', 'x', 't', '\r', 0};
+ static const WCHAR bufW3[] = {'T', 'e', 'x', 't', 0};
+ static const WCHAR bufW4[] = {'T', 'e', 's', 't', 'S', 'o', 'm',
+ 'e', 'T', 'e', 'x', 't', '\r', 0};
+ static const WCHAR bufW5[] = {'\r', 0};
+
+ create_interfaces(&w, &reOle, &txtDoc, &txtSel);
+ SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
+
+ first = 0, lim = 4;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ first = 4, lim = 0;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ ok(!lstrcmpW(bstr, bufW1), "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ first = 1, lim = 1;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ hres = ITextSelection_GetText(txtSel, NULL);
+ ok(hres == E_INVALIDARG, "ITextSelection_GetText\n");
+
+ first = 8, lim = 12;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ ok(!lstrcmpW(bstr, bufW3), "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ /* FIXME: a '\r' should be appended at the end of a story */
+ first = 8, lim = 13;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ todo_wine ok(!lstrcmpW(bstr, bufW2), "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ first = 12, lim = 13;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ todo_wine ok(!lstrcmpW(bstr, bufW5), "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ first = 0, lim = -1;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ todo_wine ok(!lstrcmpW(bstr, bufW4), "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ first = -1, lim = 9;
+ SendMessageA(w, EM_SETSEL, first, lim);
+ hres = ITextSelection_GetText(txtSel, &bstr);
+ ok(hres == S_OK, "ITextSelection_GetText\n");
+ ok(!bstr, "got wrong text: %s\n", wine_dbgstr_w(bstr));
+
+ release_interfaces(&w, &reOle, &txtDoc, &txtSel);
+}
+
START_TEST(richole)
{
/* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -394,4 +470,5 @@ START_TEST(richole)
test_Interfaces();
test_ITextDocument_Open();
+ test_ITextSelection_GetText();
}
--
1.8.5.2 (Apple Git-48)
More information about the wine-patches
mailing list