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

Miklos Vajna vmiklos at collabora.co.uk
Thu Jul 27 13:32:29 UTC 2017


 offapi/com/sun/star/text/TextRangeContentProperties.idl |    6 ++++
 sw/inc/cmdid.h                                          |    1 
 sw/inc/unoprnms.hxx                                     |    1 
 sw/qa/extras/uiwriter/data/paragraph-of-text-range.odt  |binary
 sw/qa/extras/uiwriter/uiwriter.cxx                      |   23 ++++++++++++++++
 sw/source/core/unocore/unocrsrhelper.cxx                |   13 +++++++++
 sw/source/core/unocore/unomapproperties.hxx             |    1 
 7 files changed, 45 insertions(+)

New commits:
commit 7ed402ba648dd0f3de3b0dadebc13403b2c0a620
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jul 27 13:59:01 2017 +0200

    sw: add new TextParagraph property to XTextRange
    
    A text range represents a selection or cursor position, so similar to
    sections or tables, it makes sense to expose the containing paragraph as
    well. This new property does exactly that.
    
    Change-Id: If92a3b5e61f13c7c14ca52bc8593a2b286a596cc
    Reviewed-on: https://gerrit.libreoffice.org/40483
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/offapi/com/sun/star/text/TextRangeContentProperties.idl b/offapi/com/sun/star/text/TextRangeContentProperties.idl
index 042b4d5b3736..9daad2e139dc 100644
--- a/offapi/com/sun/star/text/TextRangeContentProperties.idl
+++ b/offapi/com/sun/star/text/TextRangeContentProperties.idl
@@ -81,6 +81,12 @@ service TextRangeContentProperties
     [optional, readonly, property] com::sun::star::text::XTextContent
         NestedTextContent;
 
+    /** Paragraph for the start of this range.
+
+        @since LibreOffice 6.0
+     */
+    [optional, readonly, property] com::sun::star::text::XTextContent TextParagraph;
+
 };
 
 
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 29ca700b6f59..4edb28028e82 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -514,6 +514,7 @@
 #define FN_UNO_FOOTER                       (FN_EXTRA2 + 38)
 #define FN_UNO_FOOTER_LEFT                  (FN_EXTRA2 + 39)
 #define FN_UNO_FOOTER_RIGHT                 (FN_EXTRA2 + 40)
+#define FN_UNO_TEXT_PARAGRAPH               (FN_EXTRA2 + 41)
 #define FN_UNO_FOLLOW_STYLE                 (FN_EXTRA2 + 59)
 
 #define FN_API_CALL                         (FN_EXTRA2 + 60)
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index c78f08bf5577..ecb8dfbc88a5 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -391,6 +391,7 @@
 #define UNO_NAME_FOOTER_BODY_DISTANCE "FooterBodyDistance"
 #define UNO_NAME_FOOTER_IS_DYNAMIC_HEIGHT "FooterIsDynamicHeight"
 #define UNO_NAME_FOOTER_IS_SHARED "FooterIsShared"
+#define UNO_NAME_TEXT_PARAGRAPH "TextParagraph"
 
 #define UNO_NAME_FOOTER_HEIGHT "FooterHeight"
 #define UNO_NAME_FOOTER_IS_ON "FooterIsOn"
diff --git a/sw/qa/extras/uiwriter/data/paragraph-of-text-range.odt b/sw/qa/extras/uiwriter/data/paragraph-of-text-range.odt
new file mode 100644
index 000000000000..52cdb0be1ff2
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/paragraph-of-text-range.odt differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index 603df05f0bf0..c0888a007a6f 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -261,6 +261,7 @@ public:
     void testTableInNestedSection();
     void testLinesInSectionInTable();
     void testLinesMoveBackwardsInSectionInTable();
+    void testParagraphOfTextRange();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest);
     CPPUNIT_TEST(testReplaceForward);
@@ -410,6 +411,7 @@ public:
     CPPUNIT_TEST(testLinesMoveBackwardsInSectionInTable);
 #endif
     CPPUNIT_TEST(testLinesInSectionInTable);
+    CPPUNIT_TEST(testParagraphOfTextRange);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -5063,6 +5065,27 @@ void SwUiWriterTest::testTableInNestedSection()
 }
 #endif
 
+void SwUiWriterTest::testParagraphOfTextRange()
+{
+    SwDoc* pDoc = createDoc("paragraph-of-text-range.odt");
+
+    // Enter the table.
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false);
+    CPPUNIT_ASSERT(pWrtShell->IsCursorInTable());
+    // Enter the section.
+    pWrtShell->Down(/*bSelect=*/false);
+    CPPUNIT_ASSERT(pWrtShell->IsDirectlyInSection());
+
+    // Assert that we get the right paragraph object.
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XTextViewCursorSupplier> xController(xModel->getCurrentController(), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xViewCursor(xController->getViewCursor(), uno::UNO_QUERY);
+    // This failed as there were no TextParagraph property.
+    auto xParagraph = getProperty< uno::Reference<text::XTextRange> >(xViewCursor->getStart(), "TextParagraph");
+    CPPUNIT_ASSERT_EQUAL(OUString("In section"), xParagraph->getString());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index eec234294340..805d919ea3e7 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -86,6 +86,7 @@
 #include <SwNodeNum.hxx>
 #include <fmtmeta.hxx>
 #include <txtfld.hxx>
+#include <unoparagraph.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -593,6 +594,18 @@ bool getCursorPropertyValue(const SfxItemPropertySimpleEntry& rEntry
                 eNewState = PropertyState_DEFAULT_VALUE;
         }
         break;
+        case FN_UNO_TEXT_PARAGRAPH:
+        {
+            SwTextNode* pTextNode = rPam.GetPoint()->nNode.GetNode().GetTextNode();
+            if (pTextNode)
+            {
+                uno::Reference<text::XTextContent> xParagraph = SwXParagraph::CreateXParagraph(*pTextNode->GetDoc(), pTextNode);
+                *pAny <<= xParagraph;
+            }
+            else
+                eNewState = PropertyState_DEFAULT_VALUE;
+        }
+        break;
         case FN_UNO_ENDNOTE:
         case FN_UNO_FOOTNOTE:
         {
diff --git a/sw/source/core/unocore/unomapproperties.hxx b/sw/source/core/unocore/unomapproperties.hxx
index 633fd3db3e2e..b9825ff4a8d2 100644
--- a/sw/source/core/unocore/unomapproperties.hxx
+++ b/sw/source/core/unocore/unomapproperties.hxx
@@ -88,6 +88,7 @@
         { OUString(UNO_NAME_CELL), FN_UNO_CELL,         cppu::UnoType<css::table::XCell>::get(),         PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY ,0 },                     \
         { OUString(UNO_NAME_TEXT_FRAME), FN_UNO_TEXT_FRAME,     cppu::UnoType<css::text::XTextFrame>::get(),        PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY ,0 },                     \
         { OUString(UNO_NAME_TEXT_SECTION), FN_UNO_TEXT_SECTION, cppu::UnoType<css::text::XTextSection>::get(),  PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY ,0 },                    \
+        { OUString(UNO_NAME_TEXT_PARAGRAPH), FN_UNO_TEXT_PARAGRAPH, cppu::UnoType<css::text::XTextContent>::get(),  PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY ,0 },                    \
         { OUString(UNO_NAME_PARA_CHAPTER_NUMBERING_LEVEL), FN_UNO_PARA_CHAPTER_NUMBERING_LEVEL,cppu::UnoType<sal_Int8>::get(), PROPERTY_NONE, 0},                                                     \
         { OUString(UNO_NAME_PARA_CONDITIONAL_STYLE_NAME), FN_UNO_PARA_CONDITIONAL_STYLE_NAME, cppu::UnoType<OUString>::get(),      PropertyAttribute::READONLY, 0},                                                     \
         { OUString(UNO_NAME_LIST_ID), FN_UNO_LIST_ID, cppu::UnoType<OUString>::get(), PropertyAttribute::MAYBEVOID, 0}, \


More information about the Libreoffice-commits mailing list