[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Nov 18 00:06:06 PST 2014


 sw/qa/extras/uiwriter/uiwriter.cxx  |    7 +++++++
 sw/source/core/unocore/unofield.cxx |   14 ++++++++++++++
 2 files changed, 21 insertions(+)

New commits:
commit 2608512056b706bab57e36765e15f5c00668577a
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 18 09:05:12 2014 +0100

    fdo#86131 SwXTextField::getAnchor: handle postit field with annotation mark
    
    Change-Id: I3881c4577375a2eda053f64800d0991de6f009ad

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 3165de7..4fa1680 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -443,6 +443,13 @@ void SwUiWriterTest::testCommentedWord()
     SwShellCrsr* pShellCrsr = pWrtShell->getShellCrsr(false);
     // This was 9, only "word", not "word<anchor character>" was selected.
     CPPUNIT_ASSERT_EQUAL(sal_Int32(10), pShellCrsr->End()->nContent.GetIndex());
+
+    // 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());
 }
 
 
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index fce4fff..07a996c 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -2078,6 +2078,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;


More information about the Libreoffice-commits mailing list