sw/inc/redline.hxx                                      |   10 +--
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    6 +
 sw/source/core/doc/DocumentRedlineManager.cxx           |    7 +-
 sw/source/core/doc/docfmt.cxx                           |    5 +
 sw/source/core/doc/docredln.cxx                         |   53 +++++++---------
 sw/source/core/text/redlnitr.cxx                        |    6 -
 sw/source/core/unocore/unocrsrhelper.cxx                |    5 +
 sw/source/core/unocore/unoredline.cxx                   |    4 -
 sw/source/filter/ww8/docxattributeoutput.cxx            |    4 -
 sw/source/uibase/misc/redlndlg.cxx                      |    4 -
 10 files changed, 58 insertions(+), 46 deletions(-)

New commits:
commit fbf69202c071acf317bc6a9d549d35defb2c2df2
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Jun 12 13:03:26 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Aug 20 10:53:10 2025 +0200

    SwRangeRedline::GetDescr can be const
    
    Avoids some const_casts.
    And moving some code working with PaM to a separate function allowed
    to restructure it, and avoid initializing the description variable
    with non-trivial DenoteSpecialCharacters(rPaM.GetText().replace(...)),
    in cases when it had to be immediately replaced with something else.
    
    Change-Id: I3b213ca3daa31ae491f067a823443c70f6b1d22c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186415
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189925

diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 1b605715d2ec..616b57f73436 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -278,7 +278,7 @@ public:
 
        bSimplified = simplified shortened text to show deletions on margin
      */
-    SW_DLLPUBLIC OUString GetDescr(bool bSimplified = false);
+    SW_DLLPUBLIC OUString GetDescr(bool bSimplified = false) const;
 
     bool operator<( const SwRangeRedline& ) const;
     void dumpAsXml(xmlTextWriterPtr pWriter) const;
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index de8ed4117d4f..d480258b75cf 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -2390,34 +2390,36 @@ const SwRedlineData & 
SwRangeRedline::GetRedlineData(const sal_uInt16 nPos) cons
     return *pCur;
 }
 
-OUString SwRangeRedline::GetDescr(bool bSimplified)
+static OUString getRedlineDescrFromPaM(const SwPaM& rPaM, bool bSimplified)
+{
+    if (const SwTextNode* pTextNode = rPaM.GetPointNode().GetTextNode())
+    {
+        if (const SwTextAttr* pTextAttr = pTextNode->GetFieldTextAttrAt(
+                rPaM.GetPoint()->GetContentIndex() - 1, 
::sw::GetTextAttrMode::Default))
+        {
+            OUString result = 
pTextAttr->GetFormatField().GetField()->GetFieldName();
+            return bSimplified ? result
+                               : SwResId(STR_START_QUOTE) + result + 
SwResId(STR_END_QUOTE);
+        }
+    }
+    return DenoteSpecialCharacters(rPaM.GetText().replace('
', ' '), /*bQuoted=*/!bSimplified);
+}
+
+OUString SwRangeRedline::GetDescr(bool bSimplified) const
 {
     // get description of redline data (e.g.: "insert $1")
     OUString aResult = GetRedlineData().GetDescr();
 
-    SwPaM * pPaM = nullptr;
-    bool bDeletePaM = false;
-
+    OUString sDescr;
     // if this redline is visible the content is in this PaM
     if (!m_oContentSect.has_value())
     {
-        pPaM = this;
+        sDescr = getRedlineDescrFromPaM(*this, bSimplified);
     }
     else // otherwise it is saved in pContentSect
     {
-        pPaM = new SwPaM( m_oContentSect->GetNode(), 
*m_oContentSect->GetNode().EndOfSectionNode() );
-        bDeletePaM = true;
-    }
-
-    OUString sDescr = DenoteSpecialCharacters(pPaM->GetText().replace('
', ' '), /*bQuoted=*/!bSimplified);
-    if (const SwTextNode *pTextNode = pPaM->GetPointNode().GetTextNode())
-    {
-        if (const SwTextAttr* pTextAttr = 
pTextNode->GetFieldTextAttrAt(pPaM->GetPoint()->GetContentIndex() - 1, 
::sw::GetTextAttrMode::Default))
-        {
-            sDescr = ( bSimplified ? u""_ustr : SwResId(STR_START_QUOTE) )
-                + pTextAttr->GetFormatField().GetField()->GetFieldName()
-                + ( bSimplified ? u""_ustr : SwResId(STR_END_QUOTE) );
-        }
+        const SwNode& rNode = m_oContentSect->GetNode();
+        sDescr = getRedlineDescrFromPaM(SwPaM(rNode, 
*rNode.EndOfSectionNode()), bSimplified);
     }
 
     // replace $1 in description by description of the redlines text
@@ -2439,9 +2441,6 @@ OUString SwRangeRedline::GetDescr(bool bSimplified)
             aResult = aTmpStr.copy(0, nPos + SwResId(STR_LDOTS).getLength());
     }
 
-    if (bDeletePaM)
-        delete pPaM;
-
     return aResult;
 }
 
diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx
index 2c2a30a8a396..87564e2a3fbb 100644
--- a/sw/source/core/text/redlnitr.cxx
+++ b/sw/source/core/text/redlnitr.cxx
@@ -1144,7 +1144,7 @@ bool SwRedlineItr::CheckLine(
                 // start to collect text of invisible redlines for 
ChangesInMargin layout
                 if (rRedlineText.isEmpty() && !pRedline->IsVisible())
                 {
-                    rRedlineText = 
const_cast<SwRangeRedline*>(pRedline)->GetDescr(/*bSimplified=*/true);
+                    rRedlineText = pRedline->GetDescr(/*bSimplified=*/true);
                     pPrevRedline = pRedline;
                     isExtendText = true;
                 }
@@ -1153,7 +1153,7 @@ bool SwRedlineItr::CheckLine(
                 else if (pPrevRedline && !pRedline->IsVisible() &&
                     *pRedline->Start() == *pPrevRedline->Start() && 
*pRedline->End() == *pPrevRedline->End() )
                 {
-                    OUString 
sExtendText(const_cast<SwRangeRedline*>(pRedline)->GetDescr(/*bSimplified=*/true));
+                    OUString 
sExtendText(pRedline->GetDescr(/*bSimplified=*/true));
                     if (!sExtendText.isEmpty())
                     {
                         if (rRedlineText.getLength() < 12)
@@ -1161,7 +1161,7 @@ bool SwRedlineItr::CheckLine(
                             // TODO: remove extra space from GetDescr(true),
                             // but show deletion of paragraph or line break
                             rRedlineText = rRedlineText +
-                                    
const_cast<SwRangeRedline*>(pRedline)->GetDescr(/*bSimplified=*/true).subView(1);
+                                    
pRedline->GetDescr(/*bSimplified=*/true).subView(1);
                         }
                         else
                             rRedlineText = 
OUString::Concat(rRedlineText.subView(0, rRedlineText.getLength() - 3)) + "...";
diff --git a/sw/source/core/unocore/unoredline.cxx 
b/sw/source/core/unocore/unoredline.cxx
index f9783e4cd318..b4070ae2f03c 100644
--- a/sw/source/core/unocore/unoredline.cxx
+++ b/sw/source/core/unocore/unoredline.cxx
@@ -274,7 +274,7 @@ uno::Any  SwXRedlinePortion::GetPropertyValue( 
std::u16string_view rPropertyName
     else if (rPropertyName == UNO_NAME_REDLINE_COMMENT)
         aRet <<= rRedline.GetComment();
     else if(rPropertyName == UNO_NAME_REDLINE_DESCRIPTION)
-        aRet <<= const_cast<SwRangeRedline&>(rRedline).GetDescr();
+        aRet <<= rRedline.GetDescr();
     else if(rPropertyName == UNO_NAME_REDLINE_TYPE)
     {
         aRet <<= SwRedlineTypeToOUString(rRedline.GetType());
@@ -315,7 +315,7 @@ uno::Sequence< beans::PropertyValue > 
SwXRedlinePortion::CreateRedlineProperties
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_COMMENT;
     pRet[nPropIdx++].Value <<= rRedline.GetComment();
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_DESCRIPTION;
-    pRet[nPropIdx++].Value <<= 
const_cast<SwRangeRedline&>(rRedline).GetDescr();
+    pRet[nPropIdx++].Value <<= rRedline.GetDescr();
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_TYPE;
     pRet[nPropIdx++].Value <<= SwRedlineTypeToOUString(rRedline.GetType());
     pRet[nPropIdx].Name = UNO_NAME_REDLINE_IDENTIFIER;
diff --git a/sw/source/uibase/misc/redlndlg.cxx 
b/sw/source/uibase/misc/redlndlg.cxx
index dfe34011b081..327d73e5e284 100644
--- a/sw/source/uibase/misc/redlndlg.cxx
+++ b/sw/source/uibase/misc/redlndlg.cxx
@@ -572,7 +572,7 @@ void SwRedlineAcceptDlg::Activate()
             bool bShowDeletedTextAsComment = bIsShowChangesInMargin &&
                 RedlineType::Delete == rRedln.GetType() && 
rRedln.GetComment().isEmpty();
             const OUString sComment = bShowDeletedTextAsComment
-                    ? const_cast<SwRangeRedline&>(rRedln).GetDescr()
+                    ? rRedln.GetDescr()
                     : rRedln.GetComment();
             if (pParent->xTLBParent)
             {
@@ -1022,7 +1022,7 @@ void 
SwRedlineAcceptDlg::InsertParents(SwRedlineTable::size_type nStart, SwRedli
         bool bShowDeletedTextAsComment = bIsShowChangesInMargin &&
                 RedlineType::Delete == rRedln.GetType() && 
rRedln.GetComment().isEmpty();
         const OUString sComment = bShowDeletedTextAsComment
-                    ? const_cast<SwRangeRedline&>(rRedln).GetDescr()
+                    ? rRedln.GetDescr()
                     : rRedln.GetComment();
         pRedlineParent->sComment = sComment.replace('
', ' ');
         m_RedlineParents.insert(m_RedlineParents.begin() + i,
commit 0c0d1ecd47237a80971e30cc315f41ddd1c8b621
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Aug 13 09:40:40 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Aug 20 10:53:01 2025 +0200

    tdf#167761 sw format redline: register the item set in the autostyle pool
    
    Load the DOCX bugdoc, save to ODT, open it, go to the 36pt font size
    format redline, click reject, should be 24th, but it's now 12pt instead.
    
    What happens is that SwRedlineExtraData_FormatColl SfxItemSet is not
    part of the autoformat mechanism, so the ODF markup can't even refer to
    it. So reject works correctly after DOCX open, but not after ODF
    roundtrip.
    
    The first step here is to replace the std::unique_ptr<SfxItemSet> with a
    shared pointer, similar to what SwFormatAutoFormat does for normal
    character direct formatting (the redline just stores the old direct
    formatting).
    
    This allows producing the std::shared_ptr<SfxItemSet> in the autostyle
    pool, so the ODF export will be able to export the old direct formatting
    as a next step (not yet done here.)
    
    Change-Id: I1f7a8083ce766bd2ec06bb8e19bfce0eaebfe405
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189509
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189524

diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 71ebcebbe37c..1b605715d2ec 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -52,20 +52,20 @@ public:
 class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final : public 
SwRedlineExtraData
 {
     UIName m_sFormatNm;
-    std::unique_ptr<SfxItemSet> m_pSet;
+    std::shared_ptr<SfxItemSet> m_pSet;
     sal_uInt16 m_nPoolId;
     bool m_bFormatAll; // don't strip the last paragraph mark
 public:
     SwRedlineExtraData_FormatColl( UIName aColl, sal_uInt16 nPoolFormatId,
-                                const SfxItemSet* pSet = nullptr, bool 
bFormatAll = true );
+                                const std::shared_ptr<SfxItemSet>& pSet = 
nullptr, bool bFormatAll = true );
     virtual ~SwRedlineExtraData_FormatColl() override;
     virtual SwRedlineExtraData* CreateNew() const override;
     virtual void Reject( SwPaM& rPam ) const override;
     virtual bool operator == ( const SwRedlineExtraData& ) const override;
 
     const UIName& GetFormatName() const        { return m_sFormatNm; }
-    void SetItemSet( const SfxItemSet& rSet );
-    SfxItemSet* GetItemSet( ) const { return m_pSet.get(); }
+    void SetItemSet( const std::shared_ptr<SfxItemSet>& pSet );
+    std::shared_ptr<SfxItemSet> GetItemSet( ) const { return m_pSet; }
     void SetFormatAll( bool bAll )               { m_bFormatAll = bAll; }
 };
 
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index c85591483dc9..912ea1eb33cd 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -1281,7 +1281,7 @@ namespace //local functions originally from docfmt.cxx
                         if (pFormattingChanges)
                         {
                             // Get the item set that holds all the changes 
properties
-                            const SfxItemSet *pChangesSet = 
pFormattingChanges->GetItemSet();
+                            std::shared_ptr<SfxItemSet> pChangesSet = 
pFormattingChanges->GetItemSet();
                             xExtra.reset(new 
SwRedlineExtraData_FormatColl(UIName(u""_ustr), USHRT_MAX, pChangesSet));
                             break;
                         }
@@ -1318,7 +1318,9 @@ namespace //local functions originally from docfmt.cxx
             // which doesn't handle invalid/dontcare items so clear them here
             aSet.ClearInvalidItems();
 
-            xExtra.reset(new SwRedlineExtraData_FormatColl(UIName(u""_ustr), 
USHRT_MAX, &aSet));
+            IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
+            std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aSet, IStyleAccess::AUTO_STYLE_CHAR);
+            xExtra.reset(new SwRedlineExtraData_FormatColl(UIName(u""_ustr), 
USHRT_MAX, pAutoStyle));
         }
 
         pRedline->SetExtraData(xExtra.get() );
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 9771d1bbbd66..d05a4b38b013 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -43,6 +43,7 @@
 #include <editeng/prntitem.hxx>
 #include <comphelper/lok.hxx>
 #include <svl/itemiter.hxx>
+#include <istyleaccess.hxx>
 
 using namespace com::sun::star;
 
@@ -454,7 +455,11 @@ namespace
             if (bCopy && !bSameSet)
                 rDoc.getIDocumentContentOperations().InsertItemSet(aPam, 
aTmp2);
             else if (!bCopy && (!bSameSet || pFromColl != pToColl))
-                return std::make_unique<SwRedlineExtraData_FormatColl>( 
pFromColl->GetName(), USHRT_MAX, &aTmp2 );
+            {
+                IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
+                std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aTmp2, IStyleAccess::AUTO_STYLE_CHAR);
+                return std::make_unique<SwRedlineExtraData_FormatColl>( 
pFromColl->GetName(), USHRT_MAX, pAutoStyle );
+            }
         }
         return nullptr;
     }
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 959c2bf901b9..51c8e7f9f8a4 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -80,6 +80,7 @@
 #include <memory>
 #include <algorithm>
 #include <functional>
+#include <istyleaccess.hxx>
 
 using namespace ::com::sun::star::i18n;
 using namespace ::com::sun::star::uno;
@@ -1831,7 +1832,9 @@ void SwDoc::SetTextFormatCollByAutoFormat( const 
SwPosition& rPos, sal_uInt16 nP
             if( SfxItemState::SET == pTNd->GetpSwAttrSet()->GetItemState(
                     RES_PARATR_ADJUST, false, &pItem ))
                 aTmp.Put( *pItem );
-            aExtraData.SetItemSet( aTmp );
+            IStyleAccess& rStyleAccess = pTNd->GetDoc().GetIStyleAccess();
+            std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aTmp, IStyleAccess::AUTO_STYLE_CHAR);
+            aExtraData.SetItemSet( pAutoStyle );
         }
         pRedl->SetExtraData( &aExtraData );
 
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 295728c8f1d6..de8ed4117d4f 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -1121,12 +1121,12 @@ bool SwRedlineExtraData::operator == ( const 
SwRedlineExtraData& ) const
 
 SwRedlineExtraData_FormatColl::SwRedlineExtraData_FormatColl( UIName aColl,
                                                 sal_uInt16 nPoolFormatId,
-                                                const SfxItemSet* pItemSet,
+                                                const 
std::shared_ptr<SfxItemSet>& pItemSet,
                                                 bool bFormatAll )
     : m_sFormatNm(std::move(aColl)), m_nPoolId(nPoolFormatId), 
m_bFormatAll(bFormatAll)
 {
     if( pItemSet && pItemSet->Count() )
-        m_pSet.reset( new SfxItemSet( *pItemSet ) );
+        m_pSet = pItemSet;
 }
 
 SwRedlineExtraData_FormatColl::~SwRedlineExtraData_FormatColl()
@@ -1135,7 +1135,7 @@ 
SwRedlineExtraData_FormatColl::~SwRedlineExtraData_FormatColl()
 
 SwRedlineExtraData* SwRedlineExtraData_FormatColl::CreateNew() const
 {
-    return new SwRedlineExtraData_FormatColl( m_sFormatNm, m_nPoolId, 
m_pSet.get(), m_bFormatAll );
+    return new SwRedlineExtraData_FormatColl( m_sFormatNm, m_nPoolId, m_pSet, 
m_bFormatAll );
 }
 
 void SwRedlineExtraData_FormatColl::Reject( SwPaM& rPam ) const
@@ -1193,10 +1193,10 @@ bool SwRedlineExtraData_FormatColl::operator == ( const 
SwRedlineExtraData& r) c
                ( m_pSet && rCmp.m_pSet && *m_pSet == *rCmp.m_pSet ) );
 }
 
-void SwRedlineExtraData_FormatColl::SetItemSet( const SfxItemSet& rSet )
+void SwRedlineExtraData_FormatColl::SetItemSet( const 
std::shared_ptr<SfxItemSet>& pSet )
 {
-    if( rSet.Count() )
-        m_pSet.reset( new SfxItemSet( rSet ) );
+    if( pSet && pSet->Count() )
+        m_pSet = pSet;
     else
         m_pSet.reset();
 }
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx 
b/sw/source/core/unocore/unocrsrhelper.cxx
index 70ed8f835b78..6e4992be12be 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -94,6 +94,7 @@
 #include <paratr.hxx>
 #include <sal/log.hxx>
 #include <names.hxx>
+#include <istyleaccess.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -1392,8 +1393,10 @@ void makeRedline( SwPaM const & rPaM,
                 // tdf#149747 Get UI style name from programmatic style name
                 SwStyleNameMapper::FillUIName(ProgName(sParaStyleName), 
sUIStyle,
                                               SwGetPoolIdFromName::TxtColl);
+                IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
+                std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aItemSet, IStyleAccess::AUTO_STYLE_CHAR);
                 xRedlineExtraData.reset(new SwRedlineExtraData_FormatColl(
-                    sUIStyle.isEmpty() ? UIName(sParaStyleName) : 
std::move(sUIStyle), nStylePoolId, &aItemSet));
+                    sUIStyle.isEmpty() ? UIName(sParaStyleName) : 
std::move(sUIStyle), nStylePoolId, pAutoStyle));
             }
             else if (eType == RedlineType::ParagraphFormat)
                 xRedlineExtraData.reset(new SwRedlineExtraData_FormatColl( 
UIName(u""_ustr), RES_POOLCOLL_STANDARD, nullptr ));
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index d1c000cf20ac..adb4dc9aa819 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4209,7 +4209,7 @@ void DocxAttributeOutput::Redline( const SwRedlineData* 
pRedlineData)
             if (pFormattingChanges)
             {
                  // Get the item set that holds all the changes properties
-                const SfxItemSet *pChangesSet = 
pFormattingChanges->GetItemSet();
+                std::shared_ptr<SfxItemSet> pChangesSet = 
pFormattingChanges->GetItemSet();
                 if (pChangesSet)
                 {
                     m_pSerializer->mark(Tag_Redline_1);
@@ -4252,7 +4252,7 @@ void DocxAttributeOutput::Redline( const SwRedlineData* 
pRedlineData)
             if (pFormattingChanges)
             {
                 // Get the item set that holds all the changes properties
-                const SfxItemSet *pChangesSet = 
pFormattingChanges->GetItemSet();
+                std::shared_ptr<SfxItemSet> pChangesSet = 
pFormattingChanges->GetItemSet();
                 const UIName & sParaStyleName = 
pFormattingChanges->GetFormatName();
                 if (pChangesSet || !sParaStyleName.isEmpty())
                 {

Reply via email to