[PATCH] riched20: Implement ITextRange::SetRange.
Vijay Kiran Kamuju
infyquest at gmail.com
Wed May 1 00:06:58 CDT 2019
Rewrite the tests
From: Jactry Zeng <wine at jactry.com>
Signed-off-by: Vijay Kiran Kamuju <infyquest at gmail.com>
---
dlls/riched20/richole.c | 41 +++++++++++++++++++------------
dlls/riched20/tests/richole.c | 46 +++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 16 deletions(-)
diff --git a/dlls/riched20/richole.c b/dlls/riched20/richole.c
index 4b47310a8e..871d58a78a 100644
--- a/dlls/riched20/richole.c
+++ b/dlls/riched20/richole.c
@@ -2026,6 +2026,23 @@ 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 +2052,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 +4132,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 40feb76f2b..8fd8ef47f6 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)
+{
+ HWND w;
+ IRichEditOle *reOle = NULL;
+ ITextDocument *txtDoc = NULL;
+ ITextRange *txtRge = NULL;
+ HRESULT hres;
+ static const CHAR test_text1[] = "TestSomeText";
+
+ create_interfaces(&w, &reOle, &txtDoc, NULL);
+ SendMessageA(w, WM_SETTEXT, 0, (LPARAM)test_text1);
+ ITextDocument_Range(txtDoc, 0, 0, &txtRge);
+
+ hres = ITextRange_SetRange(txtRge, 2, 4);
+ ok(hres == S_OK, "ITextRange_SetRange\n");
+ CHECK_RANGE(txtRge, 2, 4);
+
+ hres = ITextRange_SetRange(txtRge, 2, 4);
+ ok(hres == S_FALSE, "ITextRange_SetRange\n");
+ CHECK_RANGE(txtRge, 2, 4);
+
+ hres = ITextRange_SetRange(txtRge, 4, 2);
+ ok(hres == S_FALSE, "ITextRange_SetRange\n");
+ CHECK_RANGE(txtRge, 2, 4);
+
+ hres = ITextRange_SetRange(txtRge, 14, 14);
+ ok(hres == S_OK, "ITextRange_SetRange\n");
+ CHECK_RANGE(txtRge, 12, 12);
+
+ hres = ITextRange_SetRange(txtRge, 15, 15);
+ ok(hres == S_FALSE, "ITextRange_SetRange\n");
+ CHECK_RANGE(txtRge, 12, 12);
+
+ hres = ITextRange_SetRange(txtRge, 14, 1);
+ ok(hres == S_OK, "ITextRange_SetRange\n");
+ CHECK_RANGE(txtRge, 1, 13);
+
+ hres = ITextRange_SetRange(txtRge, -1, 4);
+ ok(hres == S_OK, "ITextRange_SetRange\n");
+ 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();
--
2.21.0
More information about the wine-devel
mailing list