sw/inc/unosett.hxx                                 |    5 +--
 sw/qa/extras/unowriter/unowriter.cxx               |   33 +++++++++++++++++++++
 sw/source/core/unocore/unosett.cxx                 |   22 ++++++++------
 sw/source/uibase/config/StoredChapterNumbering.cxx |    2 -
 4 files changed, 51 insertions(+), 11 deletions(-)

New commits:
commit 2a71eac9027b3838f675ad20c91320abca8bb884
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed May 12 14:59:43 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue May 18 10:53:14 2021 +0200

    tdf#137810 sw: fix SwXNumberingRules setting CharStyleName
    
    During ODF import, due to removal of the pDocShell parameter, this hits
    
                else
                    rCharStyleName = sCharFormatName;
    
    while setting the "CharStyleName" property and later
    GetNumberingRuleByIndex() prefers m_sNewCharStyleNames over the
    format set in the SwCharFormat??
    
    Also, "BulletFontName" has a similar problem; otoh "HeadingStyleName"
    only makes sense on chapter numbering.
    
    The m_pDoc and m_pDocShell members are such a WTF.
    
    (regression from ae0e4a6ba9be2fa99ac2be8e20157806e36209b2)
    
    Change-Id: I9d4d4cd7aeb7e6e29221d53facaff213fd4e35a5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115495
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit c5e5467f6a13aba68b4706a4d7feb130e824bcc6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115291
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/inc/unosett.hxx b/sw/inc/unosett.hxx
index c1bba2b64bb3..4b3f177fb034 100644
--- a/sw/inc/unosett.hxx
+++ b/sw/inc/unosett.hxx
@@ -147,16 +147,16 @@ private:
     OUString                    m_sNewCharStyleNames[MAXLEVEL];
     OUString                    m_sNewBulletFontNames[MAXLEVEL];
     OUString                    m_sCreatedNumRuleName; //connects to a 
numbering in SwDoc
-    SwDoc*                      m_pDoc;
+    SwDoc*                      m_pDoc; // Only if *not* used as chapter 
numbering.
     SwDocShell*                 m_pDocShell; // Only if used as chapter 
numbering.
     SwNumRule*                  m_pNumRule;
     const SfxItemPropertySet*   m_pPropertySet;
     bool                        m_bOwnNumRuleCreated;
 protected:
+    SwXNumberingRules(SwDocShell& rDocSh);  // chapter numbering
     virtual ~SwXNumberingRules() override;
 
 public:
-    SwXNumberingRules(SwDocShell& rDocSh);  // chapter numbering
     SwXNumberingRules(const SwNumRule& rRule, SwDoc* doc = nullptr); // 
NumRule for paragraphs, numbering styles
     SwXNumberingRules(SwDoc& rDoc); //create a new instance
 
@@ -218,6 +218,7 @@ public:
             OUString *const pHeadingStyleName,
             OUString *const pParagraphStyleName,
             SwDoc *const pDoc,
+            SwDocShell *const pDocShell,
             css::uno::Sequence<css::beans::PropertyValue> const& rProperties);
 
 };
diff --git a/sw/qa/extras/unowriter/unowriter.cxx 
b/sw/qa/extras/unowriter/unowriter.cxx
index 895728bd412f..d7f986a0bd59 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -751,6 +751,39 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testImageCommentAtChar)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testChapterNumberingCharStyle)
+{
+    loadURL("private:factory/swriter", nullptr);
+
+    uno::Reference<lang::XMultiServiceFactory> xDoc(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xStyle(
+        xDoc->createInstance("com.sun.star.style.CharacterStyle"), 
uno::UNO_QUERY);
+    uno::Reference<container::XNamed> xStyleN(xStyle, uno::UNO_QUERY);
+    xStyle->setPropertyValue("CharColor", uno::makeAny(sal_Int32(0x00FF0000)));
+    uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XNameContainer> xStyles(
+        xSFS->getStyleFamilies()->getByName("CharacterStyles"), 
uno::UNO_QUERY);
+    xStyles->insertByName("red", uno::makeAny(xStyle));
+
+    uno::Reference<text::XChapterNumberingSupplier> xCNS(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexReplace> 
xOutline(xCNS->getChapterNumberingRules());
+    {
+        comphelper::SequenceAsHashMap hashMap(xOutline->getByIndex(0));
+        hashMap["CharStyleName"] <<= OUString("red");
+        uno::Sequence<beans::PropertyValue> props;
+        hashMap >> props;
+        xOutline->replaceByIndex(0, uno::makeAny(props));
+    }
+    // now rename the style
+    xStyleN->setName("reddishred");
+    {
+        comphelper::SequenceAsHashMap hashMap(xOutline->getByIndex(0));
+
+        // tdf#137810 this failed, was old value "red"
+        CPPUNIT_ASSERT_EQUAL(OUString("reddishred"), 
hashMap["CharStyleName"].get<OUString>());
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUnoWriter, testViewCursorPageStyle)
 {
     // Load a document with 2 pages, but a single paragraph.
diff --git a/sw/source/core/unocore/unosett.cxx 
b/sw/source/core/unocore/unosett.cxx
index 26905258e56b..b36bc88a7bef 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -1140,6 +1140,7 @@ void SwXNumberingRules::replaceByIndex(sal_Int32 nIndex, 
const uno::Any& rElemen
         SwXNumberingRules::SetNumberingRuleByIndex( aNumRule,
                             *rProperties, nIndex);
         // set character format if needed
+        // this code appears to be dead - except when a style is assigned for 
BITMAP numbering?
         const SwCharFormats* pFormats = 
m_pDocShell->GetDoc()->GetCharFormats();
         const size_t nChCount = pFormats->size();
         for(sal_uInt16 i = 0; i < MAXLEVEL;i++)
@@ -1486,7 +1487,7 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
     SetPropertiesToNumFormat(aFormat, m_sNewCharStyleNames[nIndex],
         &m_sNewBulletFontNames[nIndex],
         &sHeadingStyleName, &sParagraphStyleName,
-        m_pDoc, rProperties);
+        m_pDoc, m_pDocShell, rProperties);
 
 
     if (m_pDoc && !sParagraphStyleName.isEmpty())
@@ -1533,8 +1534,11 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
         OUString *const pHeadingStyleName,
         OUString *const pParagraphStyleName,
         SwDoc *const pDoc,
+        SwDocShell *const pDocShell,
         const uno::Sequence<beans::PropertyValue>& rProperties)
 {
+    assert(pDoc == nullptr || pDocShell == nullptr); // can't be both ordinary 
and chapter numbering
+
     bool bWrongArg = false;
     std::unique_ptr<SvxBrushItem> pSetBrush;
     std::unique_ptr<Size> pSetSize;
@@ -1582,14 +1586,15 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
             rProp.Value >>= uTmp;
             OUString sCharFormatName;
             SwStyleNameMapper::FillUIName( uTmp, sCharFormatName, 
SwGetPoolIdFromName::ChrFmt );
+            SwDoc *const pLocalDoc = pDocShell ? pDocShell->GetDoc() : pDoc;
             if (sCharFormatName == UNO_NAME_CHARACTER_FORMAT_NONE)
             {
                 rCharStyleName = aInvalidStyle;
                 aFormat.SetCharFormat(nullptr);
             }
-            else if(pDoc)
+            else if (pLocalDoc)
             {
-                const SwCharFormats* pFormats = pDoc->GetCharFormats();
+                const SwCharFormats* pFormats = pLocalDoc->GetCharFormats();
                 const size_t nChCount = pFormats->size();
 
                 SwCharFormat* pCharFormat = nullptr;
@@ -1608,7 +1613,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
                     {
 
                         SfxStyleSheetBase* pBase;
-                        SfxStyleSheetBasePool* pPool = 
pDoc->GetDocShell()->GetStyleSheetPool();
+                        SfxStyleSheetBasePool* pPool = 
pLocalDoc->GetDocShell()->GetStyleSheetPool();
                         pBase = pPool->Find(sCharFormatName, 
SfxStyleFamily::Char);
                         if(!pBase)
                             pBase = &pPool->Make(sCharFormatName, 
SfxStyleFamily::Char);
@@ -1620,7 +1625,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
                 // If the character format has been found its name should not 
be in the
                 // char style names array
                 rCharStyleName.clear();
-                }
+            }
             else
                 rCharStyleName = sCharFormatName;
         }
@@ -1773,8 +1778,8 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
         {
             OUString sBulletFontName;
             rProp.Value >>= sBulletFontName;
-            SwDocShell* pLclDocShell = nullptr;
-            if( !sBulletFontName.isEmpty() && pDoc && (pLclDocShell = 
pDoc->GetDocShell()) )
+            SwDocShell *const pLclDocShell = pDocShell ? pDocShell : pDoc ? 
pDoc->GetDocShell() : nullptr;
+            if (!sBulletFontName.isEmpty() && pLclDocShell)
             {
                 const SvxFontListItem* pFontListItem =
                         static_cast<const SvxFontListItem* >(pLclDocShell
@@ -1873,7 +1878,8 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
             }
             pSetVOrient->PutValue(rProp.Value, MID_VERTORIENT_ORIENT);
         }
-        else if (rProp.Name == UNO_NAME_HEADING_STYLE_NAME)
+        else if (rProp.Name == UNO_NAME_HEADING_STYLE_NAME
+                && pDocShell) // only on chapter numbering
         {
             if (pHeadingStyleName)
             {
diff --git a/sw/source/uibase/config/StoredChapterNumbering.cxx 
b/sw/source/uibase/config/StoredChapterNumbering.cxx
index 07e68841ed93..4833a6af0b7b 100644
--- a/sw/source/uibase/config/StoredChapterNumbering.cxx
+++ b/sw/source/uibase/config/StoredChapterNumbering.cxx
@@ -149,7 +149,7 @@ public:
         SwXNumberingRules::SetPropertiesToNumFormat(
             aNumberFormat,
             charStyleName,
-            nullptr, nullptr, nullptr, nullptr,
+            nullptr, nullptr, nullptr, nullptr, nullptr,
             props);
         SwNumRulesWithName *const pRules(GetOrCreateRules());
         pRules->SetNumFormat(nIndex, aNumberFormat, charStyleName);
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to