sw/inc/cmdid.h                          |    1 +
 sw/inc/formatlinebreak.hxx              |    1 -
 sw/inc/textlinebreak.hxx                |    2 --
 sw/inc/unoprnms.hxx                     |    1 +
 sw/qa/core/unocore/unocore.cxx          |   31 +++++++++++++++++++++++++++++++
 sw/source/core/inc/unolinebreak.hxx     |    3 ++-
 sw/source/core/inc/unoport.hxx          |    9 ++++++++-
 sw/source/core/unocore/unocoll.cxx      |    4 ++--
 sw/source/core/unocore/unolinebreak.cxx |   26 ++++++++++++++++++--------
 sw/source/core/unocore/unomap1.cxx      |    1 +
 sw/source/core/unocore/unoport.cxx      |    6 ++++++
 sw/source/core/unocore/unoportenum.cxx  |   16 ++++++++++++++++
 12 files changed, 86 insertions(+), 15 deletions(-)

New commits:
commit a9975bf6bbeccc69c812135285669ebfe2eea821
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Mar 3 12:24:33 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 28 08:45:01 2022 +0200

    sw clearing breaks: include this in the UNO API text portion enum
    
    Which is how UNO API clients (e.g. ODT export) will be able to read
    RES_TXTATR_LINEBREAK.
    
    (cherry picked from commit a0f86d94e23e8ae0129780745deb2d3526b4fbfa)
    
    Conflicts:
            sw/inc/cmdid.h
    
    Change-Id: I44d2058fd8b4a4fefce3dacc49d3bb3da6060756
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132108
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index 687f5980d81d..324fa46142ef 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -634,6 +634,7 @@
 
 #define FN_UNO_TRANSFORMED_GRAPHIC          (FN_EXTRA2 + 127)
 #define FN_UNO_GRAPHIC_PREVIEW              (FN_EXTRA2 + 128)
+#define FN_UNO_LINEBREAK (FN_EXTRA2 + 129)
 
 // Area: Help
 // Region: Traveling & Selection
diff --git a/sw/inc/formatlinebreak.hxx b/sw/inc/formatlinebreak.hxx
index c3a2b0164f86..f20fa46f78c7 100644
--- a/sw/inc/formatlinebreak.hxx
+++ b/sw/inc/formatlinebreak.hxx
@@ -23,7 +23,6 @@
 #include <svl/eitem.hxx>
 #include "calbck.hxx"
 
-#include <rtl/ustring.hxx>
 #include <cppuhelper/weakref.hxx>
 #include <com/sun/star/text/XTextContent.hpp>
 
diff --git a/sw/inc/textlinebreak.hxx b/sw/inc/textlinebreak.hxx
index 33401972f60b..5b5e8c6854c3 100644
--- a/sw/inc/textlinebreak.hxx
+++ b/sw/inc/textlinebreak.hxx
@@ -21,8 +21,6 @@
 
 #include "txatbase.hxx"
 
-#include "ndindex.hxx"
-
 class SwFormatLineBreak;
 
 /**
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index c291742a1641..bd1c6e957ac5 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -867,6 +867,7 @@
 #define UNO_NAME_RESOLVED "Resolved"
 #define UNO_NAME_ALLOW_OVERLAP "AllowOverlap"
 #define UNO_NAME_CLEAR "Clear"
+#define UNO_NAME_LINEBREAK "LineBreak"
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/unocore/unocore.cxx b/sw/qa/core/unocore/unocore.cxx
index d8c9f9559bd9..d971e57d77e3 100644
--- a/sw/qa/core/unocore/unocore.cxx
+++ b/sw/qa/core/unocore/unocore.cxx
@@ -250,6 +250,37 @@ CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, 
testLineBreakInsert)
     CPPUNIT_ASSERT_EQUAL(SwLineBreakClear::ALL, rFormatLineBreak.GetValue());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreUnocoreTest, testLineBreakTextPortionEnum)
+{
+    // Given a document with a clearing break:
+    createSwDoc();
+    uno::Reference<lang::XMultiServiceFactory> xMSF(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XTextContent> xLineBreak(
+        xMSF->createInstance("com.sun.star.text.LineBreak"), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xLineBreakProps(xLineBreak, 
uno::UNO_QUERY);
+    auto eClear = static_cast<sal_Int16>(SwLineBreakClear::ALL);
+    xLineBreakProps->setPropertyValue("Clear", uno::makeAny(eClear));
+    uno::Reference<text::XText> xText = xTextDocument->getText();
+    uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor();
+    xText->insertTextContent(xCursor, xLineBreak, /*bAbsorb=*/false);
+
+    // When enumerating the text portions of the only paragraph in the 
document:
+    uno::Reference<css::text::XTextRange> xTextPortion = 
getRun(getParagraph(1), 1);
+
+    // Then make sure that the text portion type is correct + the clear type 
can be read:
+    auto aPortionType = getProperty<OUString>(xTextPortion, "TextPortionType");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: LineBreak
+    // - Actual  : Text
+    // i.e. a line break with properties was part of the normal Text portion, 
making it impossible
+    // to get those properties.
+    CPPUNIT_ASSERT_EQUAL(OUString("LineBreak"), aPortionType);
+    xLineBreak = getProperty<uno::Reference<text::XTextContent>>(xTextPortion, 
"LineBreak");
+    eClear = getProperty<sal_Int16>(xLineBreak, "Clear");
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(SwLineBreakClear::ALL), 
eClear);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/inc/unolinebreak.hxx 
b/sw/source/core/inc/unolinebreak.hxx
index 1eb939e24b68..0a87753c5e34 100644
--- a/sw/source/core/inc/unolinebreak.hxx
+++ b/sw/source/core/inc/unolinebreak.hxx
@@ -44,7 +44,8 @@ class SwXLineBreak final
     ~SwXLineBreak() override;
 
 public:
-    static css::uno::Reference<css::text::XTextContent> CreateXLineBreak();
+    static css::uno::Reference<css::text::XTextContent>
+    CreateXLineBreak(SwFormatLineBreak* pLineBreakFormat);
 
     // XPropertySet
     css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL 
getPropertySetInfo() override;
diff --git a/sw/source/core/inc/unoport.hxx b/sw/source/core/inc/unoport.hxx
index ee862925eb29..76cf877db70b 100644
--- a/sw/source/core/inc/unoport.hxx
+++ b/sw/source/core/inc/unoport.hxx
@@ -74,7 +74,8 @@ enum SwTextPortionType
     PORTION_FIELD_END,
     PORTION_FIELD_START_END,
     PORTION_ANNOTATION,
-    PORTION_ANNOTATION_END
+    PORTION_ANNOTATION_END,
+    PORTION_LINEBREAK
 };
 
 class SwXTextPortion : public cppu::WeakImplHelper
@@ -107,6 +108,7 @@ private:
         m_xTextField;
     css::uno::Reference< css::text::XTextContent >
         m_xMeta;
+    css::uno::Reference<css::text::XTextContent> m_xLineBreak;
     std::unique_ptr< css::uno::Any > m_pRubyText;
     std::unique_ptr< css::uno::Any > m_pRubyStyle;
     std::unique_ptr< css::uno::Any > m_pRubyAdjust;
@@ -222,6 +224,11 @@ public:
     void SetMeta( css::uno::Reference< css::text::XTextContent > const & xMeta)
     { m_xMeta = xMeta; }
 
+    void SetLineBreak(css::uno::Reference<css::text::XTextContent> const& 
xLineBreak)
+    {
+        m_xLineBreak = xLineBreak;
+    }
+
     void SetCollapsed(bool bSet)        { m_bIsCollapsed = bSet;}
 
     SwTextPortionType GetTextPortionType() const { return m_ePortionType; }
diff --git a/sw/source/core/unocore/unocoll.cxx 
b/sw/source/core/unocore/unocoll.cxx
index cb7a0bbb390f..fd10e33424f2 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -826,8 +826,8 @@ SwXServiceProvider::MakeInstance(SwServiceType nObjectType, 
SwDoc & rDoc)
             xRet = SwXMeta::CreateXMeta(rDoc, true);
         break;
         case SwServiceType::LineBreak:
-            xRet = SwXLineBreak::CreateXLineBreak();
-        break;
+            xRet = SwXLineBreak::CreateXLineBreak(nullptr);
+            break;
         default:
             throw uno::RuntimeException();
     }
diff --git a/sw/source/core/unocore/unolinebreak.cxx 
b/sw/source/core/unocore/unolinebreak.cxx
index 1c5aeba9152e..2e8ee454eccb 100644
--- a/sw/source/core/unocore/unolinebreak.cxx
+++ b/sw/source/core/unocore/unolinebreak.cxx
@@ -109,14 +109,25 @@ SwXLineBreak::SwXLineBreak()
 
 SwXLineBreak::~SwXLineBreak() {}
 
-uno::Reference<text::XTextContent> SwXLineBreak::CreateXLineBreak()
+uno::Reference<text::XTextContent>
+SwXLineBreak::CreateXLineBreak(SwFormatLineBreak* pLineBreakFormat)
 {
     uno::Reference<text::XTextContent> xLineBreak;
-
-    rtl::Reference<SwXLineBreak> pLineBreak(new SwXLineBreak);
-    xLineBreak.set(pLineBreak);
-    pLineBreak->m_pImpl->m_wThis = xLineBreak;
-
+    if (pLineBreakFormat)
+    {
+        xLineBreak = pLineBreakFormat->GetXTextContent();
+    }
+    if (!xLineBreak.is())
+    {
+        SwXLineBreak* const pLineBreak(pLineBreakFormat ? new 
SwXLineBreak(*pLineBreakFormat)
+                                                        : new SwXLineBreak);
+        xLineBreak.set(pLineBreak);
+        if (pLineBreakFormat)
+        {
+            pLineBreakFormat->SetXLineBreak(xLineBreak);
+        }
+        pLineBreak->m_pImpl->m_wThis = xLineBreak;
+    }
     return xLineBreak;
 }
 
@@ -140,7 +151,6 @@ void SAL_CALL SwXLineBreak::attach(const 
uno::Reference<text::XTextRange>& xText
         throw uno::RuntimeException();
     }
 
-    uno::Reference<lang::XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
     auto pRange = dynamic_cast<SwXTextRange*>(xTextRange.get());
     if (!pRange)
     {
@@ -248,7 +258,7 @@ uno::Any SAL_CALL SwXLineBreak::getPropertyValue(const 
OUString& rPropertyName)
     }
     else
     {
-        m_pImpl->m_pFormatLineBreak->QueryValue(aRet, 0);
+        aRet <<= m_pImpl->m_pFormatLineBreak->GetEnumValue();
     }
     return aRet;
 }
diff --git a/sw/source/core/unocore/unomap1.cxx 
b/sw/source/core/unocore/unomap1.cxx
index 21a1b206c7ad..a4ff8cea84c4 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -989,6 +989,7 @@ const SfxItemPropertyMapEntry*  
SwUnoPropertyMapProvider::GetTextPortionExtensio
         //REDLINE_PROPERTIES
         {u"" UNO_NAME_TEXT_PORTION_TYPE, FN_UNO_TEXT_PORTION_TYPE, 
cppu::UnoType<OUString>::get(),                        
PropertyAttribute::READONLY, 0},
         {u"" UNO_NAME_META, FN_UNO_META, 
cppu::UnoType<css::text::XTextContent>::get(), 
PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY, 0 },
+        { u"" UNO_NAME_LINEBREAK, FN_UNO_LINEBREAK, 
cppu::UnoType<css::text::XTextContent>::get(),  
PropertyAttribute::MAYBEVOID|PropertyAttribute::READONLY ,0 },
         { u"", 0, css::uno::Type(), 0, 0 }
     };
 
diff --git a/sw/source/core/unocore/unoport.cxx 
b/sw/source/core/unocore/unoport.cxx
index 2342f5b6649a..fdc90023e41d 100644
--- a/sw/source/core/unocore/unoport.cxx
+++ b/sw/source/core/unocore/unoport.cxx
@@ -250,6 +250,9 @@ void SwXTextPortion::GetPropertyValue(
             case PORTION_ANNOTATION_END:
                 pRet = "AnnotationEnd";
                 break;
+            case PORTION_LINEBREAK:
+                pRet = "LineBreak";
+                break;
             default:
                 pRet = nullptr;
             }
@@ -280,6 +283,9 @@ void SwXTextPortion::GetPropertyValue(
         case FN_UNO_META:
             rVal <<= m_xMeta;
         break;
+        case FN_UNO_LINEBREAK:
+            rVal <<= m_xLineBreak;
+            break;
         case FN_UNO_IS_COLLAPSED:
         {
             switch (m_ePortionType)
diff --git a/sw/source/core/unocore/unoportenum.cxx 
b/sw/source/core/unocore/unoportenum.cxx
index b53d1d79c520..a16ace3fa373 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -42,6 +42,7 @@
 #include <unobookmark.hxx>
 #include <unofield.hxx>
 #include <unometa.hxx>
+#include <unolinebreak.hxx>
 #include <fmtfld.hxx>
 #include <fldbas.hxx>
 #include <fmtmeta.hxx>
@@ -952,6 +953,21 @@ lcl_ExportHints(
                         }
                     }
                 break;
+                case RES_TXTATR_LINEBREAK:
+                    if (!bRightMoveForbidden)
+                    {
+                        pUnoCursor->Right(1);
+                        if (*pUnoCursor->GetMark() == *pUnoCursor->GetPoint())
+                            break;
+                        rtl::Reference<SwXTextPortion> pPortion
+                            = new SwXTextPortion(pUnoCursor, xParent, 
PORTION_LINEBREAK);
+                        xRef = pPortion;
+                        uno::Reference<text::XTextContent> xLineBreak
+                            = SwXLineBreak::CreateXLineBreak(
+                                
&const_cast<SwFormatLineBreak&>(pAttr->GetLineBreak()));
+                        pPortion->SetLineBreak(xLineBreak);
+                    }
+                    break;
                 case RES_TXTATR_AUTOFMT:
                 case RES_TXTATR_INETFMT:
                 case RES_TXTATR_CHARFMT:

Reply via email to