summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-11-18 09:05:12 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-11-20 09:15:57 +0000
commitdd28346b4f9bd116616cd4e574f74aa5745aca60 (patch)
tree9ec4dc43cbc9976006b1e45cad6a5e0b99a992f2
parent685b6922351756b8caabcf4648fc3d7b274d398c (diff)
fdo#86131 SwXTextField::getAnchor: handle postit field with annotation mark
(cherry picked from commit 2608512056b706bab57e36765e15f5c00668577a) Conflicts: sw/qa/extras/uiwriter/uiwriter.cxx Change-Id: I3881c4577375a2eda053f64800d0991de6f009ad Reviewed-on: https://gerrit.libreoffice.org/12979 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/extras/uiwriter/data/commented-word.odtbin0 -> 9953 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx15
-rw-r--r--sw/source/core/unocore/unofield.cxx14
3 files changed, 29 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/data/commented-word.odt b/sw/qa/extras/uiwriter/data/commented-word.odt
new file mode 100644
index 000000000000..ab423faa2226
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/commented-word.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 6ec70b658806..53f967a8d875 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -37,6 +37,7 @@ public:
void testFdo75898();
void testFdo74981();
void testCp1000071();
+ void testCommentedWord();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -49,6 +50,7 @@ public:
CPPUNIT_TEST(testFdo75898);
CPPUNIT_TEST(testFdo74981);
CPPUNIT_TEST(testCp1000071);
+ CPPUNIT_TEST(testCommentedWord);
CPPUNIT_TEST_SUITE_END();
private:
@@ -306,6 +308,19 @@ void SwUiWriterTest::testCp1000071()
CPPUNIT_ASSERT_EQUAL( redlineEnd1Index, rTbl[ 1 ]->End()->nContent.GetIndex());
}
+void SwUiWriterTest::testCommentedWord()
+{
+ // This word is commented. <- string in document
+ createDoc("commented-word.odt");
+
+ // Test that getAnchor() points to "word", not to an empty string.
+ uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+ uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+ uno::Reference<text::XTextContent> xField(xFields->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("word"), xField->getAnchor()->getString());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 56be0c0a8184..f409712e6e24 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -2036,6 +2036,20 @@ SwXTextField::getAnchor() throw (uno::RuntimeException, std::exception)
if (pPamForTxtFld.get() == NULL)
return 0;
+ // If this is a postit field, then return the range of its annotation mark if it has one.
+ if (const SwPostItField* pPostItField = dynamic_cast<const SwPostItField*>(pField))
+ {
+ IDocumentMarkAccess* pMarkAccess = m_pImpl->m_pDoc->getIDocumentMarkAccess();
+ for (IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAnnotationMarksBegin(); ppMark != pMarkAccess->getAnnotationMarksEnd(); ++ppMark)
+ {
+ if (ppMark->get()->GetName() == pPostItField->GetName())
+ {
+ pPamForTxtFld.reset(new SwPaM(ppMark->get()->GetMarkStart(), ppMark->get()->GetMarkEnd()));
+ break;
+ }
+ }
+ }
+
uno::Reference<text::XTextRange> xRange = SwXTextRange::CreateXTextRange(
*m_pImpl->m_pDoc, *(pPamForTxtFld->GetPoint()), pPamForTxtFld->GetMark());
return xRange;