[PATCH 2/2] riched20: Implement ITextSelection::GetChar.

Jactry Zeng wine at jactry.com
Tue May 20 18:47:38 CDT 2014


-- 
Regards,
Jactry Zeng

-------------- next part --------------
From 02b5a9e32bd317478114486c90a2ef21ae6e8393 Mon Sep 17 00:00:00 2001
From: Jactry Zeng <wine at jactry.com>
Date: Mon, 5 May 2014 07:50:37 +0800
Subject: riched20: Implement ITextSelection::GetChar.

---
 dlls/riched20/editor.h        |  1 +
 dlls/riched20/richole.c       | 21 +++++++++++++++++++--
 dlls/riched20/tests/richole.c | 44 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/dlls/riched20/editor.h b/dlls/riched20/editor.h
index 23f3d4e..83ddc05 100644
--- a/dlls/riched20/editor.h
+++ b/dlls/riched20/editor.h
@@ -246,6 +246,7 @@ void ME_GetOLEObjectSize(const ME_Context *c, ME_Run *run, SIZE *pSize) DECLSPEC
 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;
+HRESULT ME_ITextGetChar(ME_TextEditor *editor, ME_Cursor *point, LONG *pch) 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 65edb04..d4738af 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -808,11 +808,16 @@ static HRESULT WINAPI ITextSelection_fnSetText(ITextSelection *me, BSTR bstr)
 static HRESULT WINAPI ITextSelection_fnGetChar(ITextSelection *me, LONG *pch)
 {
     ITextSelectionImpl *This = impl_from_ITextSelection(me);
+    ME_Cursor *start = NULL, *end = NULL;
+
+    TRACE("%p\n", pch);
     if (!This->reOle)
         return CO_E_RELEASED;
+    if (!pch)
+        return E_INVALIDARG;
 
-    FIXME("not implemented\n");
-    return E_NOTIMPL;
+    ME_GetSelection(This->reOle->editor, &start, &end);
+    return ME_ITextGetChar(This->reOle->editor, start, pch);
 }
 
 static HRESULT WINAPI ITextSelection_fnSetChar(ITextSelection *me, LONG ch)
@@ -1757,3 +1762,15 @@ HRESULT ME_ITextGetText(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end,
 
     return S_OK;
 }
+
+HRESULT ME_ITextGetChar(ME_TextEditor *editor, ME_Cursor *point, LONG *pch)
+{
+    WCHAR wch[2];
+
+    ME_GetTextW(editor, wch, 1, point, 1, 0);
+    if (wch[0])
+        *pch = wch[0];
+    else
+        *pch = '\r';
+    return S_OK;
+}
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index efbcbdb..eed8605 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -461,6 +461,49 @@ static void test_ITextSelection_GetText(void)
   release_interfaces(&w, &reOle, &txtDoc, &txtSel);
 }
 
+static void test_ITextSelection_GetChar(void)
+{
+  HWND w;
+  IRichEditOle *reOle = NULL;
+  ITextDocument *txtDoc = NULL;
+  ITextSelection *txtSel = NULL;
+  HRESULT hres;
+  LONG pch = 0xdeadbeef;
+  int first, lim;
+  static const CHAR test_text1[] = "TestSomeText";
+
+  create_interfaces(&w, &reOle, &txtDoc, &txtSel);
+  SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
+
+  first = 0, lim = 4;
+  SendMessageA(w, EM_SETSEL, first, lim);
+  pch = 0xdeadbeef;
+  hres = ITextSelection_GetChar(txtSel, &pch);
+  ok(hres == S_OK, "ITextSelection_GetChar\n");
+  ok(pch == 'T', "got wrong char: %c\n", pch);
+
+  /* the position of the first character is zero */
+  first = 0, lim = 0;
+  SendMessageA(w, EM_SETSEL, first, lim);
+  pch = 0xdeadbeef;
+  hres = ITextSelection_GetChar(txtSel, &pch);
+  ok(hres == S_OK, "ITextSelection_GetChar\n");
+  ok(pch == 'T', "got wrong char: %c\n", pch);
+
+  /* get a '\r' at the end of the story */
+  first = 12, lim = 12;
+  SendMessageA(w, EM_SETSEL, first, lim);
+  pch = 0xdeadbeef;
+  hres = ITextSelection_GetChar(txtSel, &pch);
+  ok(hres == S_OK, "ITextSelection_GetChar\n");
+  ok(pch == '\r', "got wrong char: %c\n", pch);
+
+  hres = ITextSelection_GetChar(txtSel, NULL);
+  ok(hres == E_INVALIDARG, "ITextSelection_GetChar\n");
+
+  release_interfaces(&w, &reOle, &txtDoc, &txtSel);
+}
+
 START_TEST(richole)
 {
   /* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -471,4 +514,5 @@ START_TEST(richole)
   test_Interfaces();
   test_ITextDocument_Open();
   test_ITextSelection_GetText();
+  test_ITextSelection_GetChar();
 }
-- 
1.8.5.2 (Apple Git-48)



More information about the wine-patches mailing list