diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-11-18 09:05:12 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-11-23 14:32:33 +0100 |
commit | 038b574e68e91c1422418d870649065934cd4620 (patch) | |
tree | 1fdfc06df4a1590787e89a88283901299e77827b /sw | |
parent | 62d65c56457b65f09528ffcfe9e49dd77e0f2f7b (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>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/data/commented-word.odt | bin | 0 -> 9953 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 15 | ||||
-rw-r--r-- | sw/source/core/unocore/unofield.cxx | 14 |
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 Binary files differnew file mode 100644 index 000000000000..ab423faa2226 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/commented-word.odt 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; |