sw/inc/pagedesc.hxx                |    2 ++
 sw/source/core/doc/poolfmt.cxx     |   20 +++++++++++++++++++-
 sw/source/core/layout/pagedesc.cxx |   15 ++++++++-------
 sw/source/uibase/app/docstyle.cxx  |    7 ++++---
 4 files changed, 33 insertions(+), 11 deletions(-)

New commits:
commit 70343b21babe9d6b3d565ddfd505e35e9e68641f
Author:     Bjoern Michaelsen <bjoern.michael...@libreoffice.org>
AuthorDate: Sat Jul 27 02:00:52 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Aug 20 16:17:50 2024 +0200

    tdf#158504: fix 'applied' for page styles
    
    Here is how checking for a used page style used to work before 
140079362502408c75ceee67e86d779f61c0ac1b:
    - SwDocStyleSheet::IsUsed called SwDoc::IsUsed on the page style
    - ... that used to call GetInfo on the SwPageDesc
    - ... which then called GetInfo on Master, Left, ... (SwFrameFormats)
    - ... which then ends up in a SwPageFrame which confirms the page style
      to be in use
    
    To get this to work again after 140079362502408c75ceee67e86d779f61c0ac1b,
    one would need to reimplement the forwarding in SwFrameFormat (and the
    other intermediates). However, instead of replicating that encapsulation
    breaking maintenance nightmare, we instead:
    - introduce a properly named SwPageDesc::IsUsed
    - which directly calls SwFrameFormat::IsUsed
    - use that in SwDocStyleSheet::IsUsed
    - and then assert in SwDoc::IsUsed if called on random types (as
      essentially most of Writer derives from sw::BroadcastingModify in some
      way)
    
    Change-Id: I4ca300af61a1f2af383ef2b7ded32ddbee6ec975
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171088
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 06dec3ba4f508798822b63aeae46e8b0ec6d6d70)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172127
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/inc/pagedesc.hxx b/sw/inc/pagedesc.hxx
index a8241f15f6f0..205848fe2f2d 100644
--- a/sw/inc/pagedesc.hxx
+++ b/sw/inc/pagedesc.hxx
@@ -41,6 +41,7 @@ using namespace ::com::sun::star;
 class SfxPoolItem;
 class SwTextFormatColl;
 class SwNode;
+class SwNodes;
 class SwPageDescs;
 typedef struct _xmlTextWriter* xmlTextWriterPtr;
 
@@ -193,6 +194,7 @@ class SW_DLLPUBLIC SwPageDesc final
     virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
 
 public:
+    bool IsUsed() const;
     const OUString& GetName() const { return m_StyleName; }
     bool SetName(const OUString& rNewName);
 
diff --git a/sw/source/core/doc/poolfmt.cxx b/sw/source/core/doc/poolfmt.cxx
index b5533f192d9d..d1adc4421034 100644
--- a/sw/source/core/doc/poolfmt.cxx
+++ b/sw/source/core/doc/poolfmt.cxx
@@ -17,6 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <cassert>
+
 #include <hintids.hxx>
 #include <i18nlangtag/mslangid.hxx>
 #include <editeng/boxitem.hxx>
@@ -81,9 +83,25 @@ SvxFrameDirection GetDefaultFrameDirection(LanguageType 
nLanguage)
             SvxFrameDirection::Horizontal_RL_TB : 
SvxFrameDirection::Horizontal_LR_TB;
 }
 
-// See if the Paragraph/Character/Frame/Page style is in use
+namespace {
+#ifndef NDEBUG
+    bool lcl_isValidUsedStyle(const sw::BroadcastingModify* pModify)
+    {
+        const bool isParaStyle = dynamic_cast<const 
SwTextFormatColl*>(pModify);
+        const bool isCharStyle = dynamic_cast<const SwCharFormat*>(pModify);
+        const bool isFrameStyle = dynamic_cast<const SwFrameFormat*>(pModify);
+        const bool isFieldType = dynamic_cast<const SwFieldType*>(pModify); // 
just for insanity's sake, this is also used on FieldTypes
+        return isParaStyle || isCharStyle || isFrameStyle || isFieldType;
+    }
+#endif
+}
+
+
+// See if the Paragraph/Character/Frame style or Field Type is in use
 bool SwDoc::IsUsed( const sw::BroadcastingModify& rModify ) const
 {
+    assert(lcl_isValidUsedStyle(&rModify));
+
     // Check if we have dependent ContentNodes in the Nodes array
     // (also indirect ones for derived Formats)
     bool isUsed = false;
diff --git a/sw/source/core/layout/pagedesc.cxx 
b/sw/source/core/layout/pagedesc.cxx
index 8471cb62ebc4..511a0539aa88 100644
--- a/sw/source/core/layout/pagedesc.cxx
+++ b/sw/source/core/layout/pagedesc.cxx
@@ -144,6 +144,14 @@ SwPageDesc::~SwPageDesc()
 {
 }
 
+bool SwPageDesc::IsUsed() const
+{
+    for(const auto pFrameFormat: { &GetMaster(), &GetLeft(), 
&GetFirstMaster(), &GetFirstLeft() })
+        if(pFrameFormat->IsUsed())
+            return true;
+    return false;
+}
+
 bool SwPageDesc::SetName( const OUString& rNewName )
 {
     bool renamed = true;
@@ -297,13 +305,6 @@ void SwPageDesc::SwClientNotify(const SwModify& rModify, 
const SfxHint& rHint)
                 || (RES_PARATR_LINESPACING == nWhich))
             RegisterChange();
     }
-    else if(rHint.GetId() == SfxHintId::SwAutoFormatUsedHint)
-    {
-        m_Master.SwClientNotify(rModify, rHint);
-        m_Left.SwClientNotify(rModify, rHint);
-        m_FirstMaster.SwClientNotify(rModify, rHint);
-        m_FirstLeft.SwClientNotify(rModify, rHint);
-    }
     else if(rHint.GetId() == SfxHintId::SwModifyChanged)
     {
         auto pModifyChangedHint = static_cast<const 
sw::ModifyChangedHint*>(&rHint);
diff --git a/sw/source/uibase/app/docstyle.cxx 
b/sw/source/uibase/app/docstyle.cxx
index f71002c09d13..c2ceb63c6edb 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -2428,7 +2428,7 @@ SwFrameFormat* SwDocStyleSheet::GetFrameFormat()
     return m_pFrameFormat;
 }
 
-bool  SwDocStyleSheet::IsUsed() const
+bool SwDocStyleSheet::IsUsed() const
 {
     if( !m_bPhysical )
     {
@@ -2445,7 +2445,8 @@ bool  SwDocStyleSheet::IsUsed() const
     case SfxStyleFamily::Char : pMod = m_pCharFormat;   break;
     case SfxStyleFamily::Para : pMod = m_pColl;      break;
     case SfxStyleFamily::Frame: pMod = m_pFrameFormat;    break;
-    case SfxStyleFamily::Page : pMod = m_pDesc;      break;
+    case SfxStyleFamily::Page:
+            return m_pDesc->IsUsed();
 
     case SfxStyleFamily::Pseudo:
             return m_pNumRule && m_rDoc.IsUsed(*m_pNumRule);
@@ -3131,7 +3132,7 @@ SfxStyleSheetBase*  SwStyleSheetIterator::First()
         {
             const SwPageDesc& rDesc = rDoc.GetPageDesc(i);
             const sal_uInt16 nId = rDesc.GetPoolFormatId();
-            bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(rDesc));
+            bool bUsed = bIsSearchUsed && ( bOrganizer || rDesc.IsUsed() );
             if( !bUsed )
             {
                 if ( ( !bSearchHidden && rDesc.IsHidden() ) ||

Reply via email to