Jactry Zeng : riched20: Implement ITextRange::SetRange.
Alexandre Julliard
julliard at winehq.org
Tue May 28 15:06:50 CDT 2019
Module: wine
Branch: master
Commit: fec6920638cbd2b41b3af3940bb9226c69b12763
URL: https://source.winehq.org/git/wine.git/?a=commit;h=fec6920638cbd2b41b3af3940bb9226c69b12763
Author: Jactry Zeng <jzeng at codeweavers.com>
Date: Mon May 27 11:07:45 2019 +0800
riched20: Implement ITextRange::SetRange.
Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/riched20/richole.c | 42 ++++++++++++++++++++++++---------------
dlls/riched20/tests/richole.c | 46 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 16 deletions(-)
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 4b47310..c111920 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -2026,6 +2026,24 @@ static HRESULT WINAPI ITextRange_fnSetIndex(ITextRange *me, LONG unit, LONG inde
return E_NOTIMPL;
}
+static void cp2range(ME_TextEditor *editor, LONG *cp1, LONG *cp2)
+{
+ int len = ME_GetTextLength(editor) + 1;
+
+ *cp1 = max(*cp1, 0);
+ *cp2 = max(*cp2, 0);
+ *cp1 = min(*cp1, len);
+ *cp2 = min(*cp2, len);
+ if (*cp1 > *cp2)
+ {
+ int tmp = *cp1;
+ *cp1 = *cp2;
+ *cp2 = tmp;
+ }
+ if (*cp1 == len)
+ *cp1 = *cp2 = len - 1;
+}
+
static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG active)
{
ITextRangeImpl *This = impl_from_ITextRange(me);
@@ -2035,7 +2053,13 @@ static HRESULT WINAPI ITextRange_fnSetRange(ITextRange *me, LONG anchor, LONG ac
if (!This->child.reole)
return CO_E_RELEASED;
- return E_NOTIMPL;
+ cp2range(This->child.reole->editor, &anchor, &active);
+ if (anchor == This->start && active == This->end)
+ return S_FALSE;
+
+ This->start = anchor;
+ This->end = active;
+ return S_OK;
}
static HRESULT textrange_inrange(LONG start, LONG end, ITextRange *range, LONG *ret)
@@ -4109,26 +4133,12 @@ static HRESULT WINAPI ITextDocument2Old_fnRange(ITextDocument2Old *iface, LONG c
ITextRange **ppRange)
{
IRichEditOleImpl *This = impl_from_ITextDocument2Old(iface);
- const int len = ME_GetTextLength(This->editor) + 1;
TRACE("%p %p %d %d\n", This, ppRange, cp1, cp2);
if (!ppRange)
return E_INVALIDARG;
- cp1 = max(cp1, 0);
- cp2 = max(cp2, 0);
- cp1 = min(cp1, len);
- cp2 = min(cp2, len);
- if (cp1 > cp2)
- {
- LONG tmp;
- tmp = cp1;
- cp1 = cp2;
- cp2 = tmp;
- }
- if (cp1 == len)
- cp1 = cp2 = len - 1;
-
+ cp2range(This->editor, &cp1, &cp2);
return CreateITextRange(This, cp1, cp2, ppRange);
}
diff --git a/dlls/riched20/tests/richole.c b/dlls/riched20/tests/richole.c
index 40feb76..7064620 100644
--- a/dlls/riched20/tests/richole.c
+++ b/dlls/riched20/tests/richole.c
@@ -3590,6 +3590,51 @@ static void _check_selection(ITextSelection *selection, LONG expected_start, LON
expected_end, value);
}
+static void test_ITextRange_SetRange(void)
+{
+ static const CHAR test_text1[] = "TestSomeText";
+ ITextDocument *txtDoc = NULL;
+ IRichEditOle *reOle = NULL;
+ ITextRange *txtRge = NULL;
+ HRESULT hr;
+ HWND w;
+
+ create_interfaces(&w, &reOle, &txtDoc, NULL);
+ SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
+ ITextDocument_Range(txtDoc, 0, 0, &txtRge);
+
+ hr = ITextRange_SetRange(txtRge, 2, 4);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 2, 4);
+
+ hr = ITextRange_SetRange(txtRge, 2, 4);
+ ok(hr == S_FALSE, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 2, 4);
+
+ hr = ITextRange_SetRange(txtRge, 4, 2);
+ ok(hr == S_FALSE, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 2, 4);
+
+ hr = ITextRange_SetRange(txtRge, 14, 14);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 12, 12);
+
+ hr = ITextRange_SetRange(txtRge, 15, 15);
+ ok(hr == S_FALSE, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 12, 12);
+
+ hr = ITextRange_SetRange(txtRge, 14, 1);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 1, 13);
+
+ hr = ITextRange_SetRange(txtRge, -1, 4);
+ ok(hr == S_OK, "got 0x%08x.\n", hr);
+ CHECK_RANGE(txtRge, 0, 4);
+
+ ITextRange_Release(txtRge);
+ release_interfaces(&w, &reOle, &txtDoc, NULL);
+}
+
static void test_Expand(void)
{
static const char test_text1[] = "TestSomeText";
@@ -3780,6 +3825,7 @@ START_TEST(richole)
test_ITextRange_GetChar();
test_ITextRange_ScrollIntoView();
test_ITextRange_GetStart_GetEnd();
+ test_ITextRange_SetRange();
test_ITextRange_GetDuplicate();
test_ITextRange_Collapse();
test_GetClientSite();
More information about the wine-cvs
mailing list