summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-09-27 13:14:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-09-27 14:20:24 +0200
commitc2ab40af9efd19d386a486a934986731b7a80d6d (patch)
tree2692c068e59d5933fde5cb3d36c2c6405e8db2fc
parent5484007fceb8099f771a544472ba66f49631fe4f (diff)
pass SwAttrSet around explicitly
instead of using SfxItemSet and static_cast'ing it everywhere Change-Id: I12d1a6bd2dec7035fa16206ea01346a3a73c1457 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157309 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sw/inc/istyleaccess.hxx5
-rw-r--r--sw/inc/node.hxx4
-rw-r--r--sw/source/core/doc/swstylemanager.cxx15
-rw-r--r--sw/source/core/docnode/node.cxx50
4 files changed, 47 insertions, 27 deletions
diff --git a/sw/inc/istyleaccess.hxx b/sw/inc/istyleaccess.hxx
index b547d55bac56..755f10bf15d8 100644
--- a/sw/inc/istyleaccess.hxx
+++ b/sw/inc/istyleaccess.hxx
@@ -23,6 +23,8 @@
#include <memory>
#include <vector>
+class SwAttrSet;
+
// Management of (automatic) styles
class IStyleAccess
{
@@ -40,6 +42,9 @@ public:
virtual std::shared_ptr<SfxItemSet> getAutomaticStyle( const SfxItemSet& rSet,
SwAutoStyleFamily eFamily,
const OUString* pParentName = nullptr ) = 0;
+ virtual std::shared_ptr<SwAttrSet> getAutomaticStyle( const SwAttrSet& rSet,
+ SwAutoStyleFamily eFamily,
+ const OUString* pParentName = nullptr ) = 0;
virtual void getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
SwAutoStyleFamily eFamily ) = 0;
/** It's slow to iterate through a stylepool looking for a special name, but if
diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index 79d1a3792935..de7e24a0b152 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -410,7 +410,7 @@ protected:
/** Attribute-set for all auto attributes of a ContentNode.
(e.g. TextNode or NoTextNode). */
- std::shared_ptr<const SfxItemSet> mpAttrSet;
+ std::shared_ptr<const SwAttrSet> mpAttrSet;
/// Make respective nodes create the specific AttrSets.
virtual void NewAttrSet( SwAttrPool& ) = 0;
@@ -490,7 +490,7 @@ public:
/** Does node has already its own auto-attributes?
Access to SwAttrSet. */
inline const SwAttrSet &GetSwAttrSet() const;
- const SwAttrSet *GetpSwAttrSet() const { return static_cast<const SwAttrSet*>(mpAttrSet.get()); }
+ const SwAttrSet *GetpSwAttrSet() const { return mpAttrSet.get(); }
bool HasSwAttrSet() const { return mpAttrSet != nullptr; }
virtual SwFormatColl* ChgFormatColl( SwFormatColl* );
diff --git a/sw/source/core/doc/swstylemanager.cxx b/sw/source/core/doc/swstylemanager.cxx
index 7f73555fc8ff..6372ab10c89d 100644
--- a/sw/source/core/doc/swstylemanager.cxx
+++ b/sw/source/core/doc/swstylemanager.cxx
@@ -72,6 +72,9 @@ public:
virtual std::shared_ptr<SfxItemSet> getAutomaticStyle( const SfxItemSet& rSet,
IStyleAccess::SwAutoStyleFamily eFamily,
const OUString* pParentName = nullptr ) override;
+ virtual std::shared_ptr<SwAttrSet> getAutomaticStyle( const SwAttrSet& rSet,
+ IStyleAccess::SwAutoStyleFamily eFamily,
+ const OUString* pParentName = nullptr ) override;
virtual std::shared_ptr<SfxItemSet> getByName( const OUString& rName,
IStyleAccess::SwAutoStyleFamily eFamily ) override;
virtual void getAllStyles( std::vector<std::shared_ptr<SfxItemSet>> &rStyles,
@@ -104,6 +107,18 @@ std::shared_ptr<SfxItemSet> SwStyleManager::getAutomaticStyle( const SfxItemSet&
return rAutoPool.insertItemSet( rSet, pParentName );
}
+std::shared_ptr<SwAttrSet> SwStyleManager::getAutomaticStyle( const SwAttrSet& rSet,
+ IStyleAccess::SwAutoStyleFamily eFamily,
+ const OUString* pParentName )
+{
+ StylePool& rAutoPool
+ = eFamily == IStyleAccess::AUTO_STYLE_CHAR ? m_aAutoCharPool : m_aAutoParaPool;
+ std::shared_ptr<SfxItemSet> pItemSet = rAutoPool.insertItemSet( rSet, pParentName );
+ std::shared_ptr<SwAttrSet> pAttrSet = std::dynamic_pointer_cast<SwAttrSet>(pItemSet);
+ assert(bool(pItemSet) == bool(pAttrSet) && "types do not match");
+ return pAttrSet;
+}
+
std::shared_ptr<SfxItemSet> SwStyleManager::cacheAutomaticStyle( const SfxItemSet& rSet,
IStyleAccess::SwAutoStyleFamily eFamily )
{
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index c9abe227643a..6cfab7801f43 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -96,36 +96,34 @@ void AccessibilityCheckStatus::reset()
namespace AttrSetHandleHelper
{
-static void GetNewAutoStyle( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static void GetNewAutoStyle( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode,
SwAttrSet const & rNewAttrSet )
{
- const SwAttrSet* pAttrSet = static_cast<const SwAttrSet*>(rpAttrSet.get());
if( rNode.GetModifyAtAttr() )
- const_cast<SwAttrSet*>(pAttrSet)->SetModifyAtAttr( nullptr );
- IStyleAccess& rSA = pAttrSet->GetPool()->GetDoc()->GetIStyleAccess();
+ const_cast<SwAttrSet*>(rpAttrSet.get())->SetModifyAtAttr( nullptr );
+ IStyleAccess& rSA = rpAttrSet->GetPool()->GetDoc()->GetIStyleAccess();
rpAttrSet = rSA.getAutomaticStyle( rNewAttrSet, rNode.IsTextNode() ?
IStyleAccess::AUTO_STYLE_PARA :
IStyleAccess::AUTO_STYLE_NOTXT );
- const bool bSetModifyAtAttr = const_cast<SwAttrSet*>(static_cast<const SwAttrSet*>(rpAttrSet.get()))->SetModifyAtAttr( &rNode );
+ const bool bSetModifyAtAttr = const_cast<SwAttrSet*>(rpAttrSet.get())->SetModifyAtAttr( &rNode );
rNode.SetModifyAtAttr( bSetModifyAtAttr );
}
-static void SetParent( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static void SetParent( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode,
const SwFormat* pParentFormat,
const SwFormat* pConditionalFormat )
{
- const SwAttrSet* pAttrSet = static_cast<const SwAttrSet*>(rpAttrSet.get());
- OSL_ENSURE( pAttrSet, "no SwAttrSet" );
+ OSL_ENSURE( rpAttrSet, "no SwAttrSet" );
OSL_ENSURE( pParentFormat || !pConditionalFormat, "ConditionalFormat without ParentFormat?" );
const SwAttrSet* pParentSet = pParentFormat ? &pParentFormat->GetAttrSet() : nullptr;
- if ( pParentSet == pAttrSet->GetParent() )
+ if ( pParentSet == rpAttrSet->GetParent() )
return;
- SwAttrSet aNewSet( *pAttrSet );
+ SwAttrSet aNewSet( *rpAttrSet );
aNewSet.SetParent( pParentSet );
aNewSet.ClearItem( RES_FRMATR_STYLE_NAME );
aNewSet.ClearItem( RES_FRMATR_CONDITIONAL_STYLE_NAME );
@@ -147,21 +145,21 @@ static void SetParent( std::shared_ptr<const SfxItemSet>& rpAttrSet,
GetNewAutoStyle( rpAttrSet, rNode, aNewSet );
}
-static const SfxPoolItem* Put( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static const SfxPoolItem* Put( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode,
const SfxPoolItem& rAttr )
{
- SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) );
+ SwAttrSet aNewSet( *rpAttrSet );
const SfxPoolItem* pRet = aNewSet.Put( rAttr );
if ( pRet )
GetNewAutoStyle( rpAttrSet, rNode, aNewSet );
return pRet;
}
-static bool Put( std::shared_ptr<const SfxItemSet>& rpAttrSet, const SwContentNode& rNode,
+static bool Put( std::shared_ptr<const SwAttrSet>& rpAttrSet, const SwContentNode& rNode,
const SfxItemSet& rSet )
{
- SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) );
+ SwAttrSet aNewSet( *rpAttrSet );
// #i76273# Robust
std::optional<SfxItemSetFixed<RES_FRMATR_STYLE_NAME, RES_FRMATR_CONDITIONAL_STYLE_NAME>> pStyleNames;
@@ -185,11 +183,11 @@ static bool Put( std::shared_ptr<const SfxItemSet>& rpAttrSet, const SwContentNo
return bRet;
}
-static bool Put_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static bool Put_BC( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode, const SfxPoolItem& rAttr,
SwAttrSet* pOld, SwAttrSet* pNew )
{
- SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) );
+ SwAttrSet aNewSet( *rpAttrSet );
// for a correct broadcast, we need to do a SetModifyAtAttr with the items
// from aNewSet. The 'regular' SetModifyAtAttr is done in GetNewAutoStyle
@@ -204,11 +202,11 @@ static bool Put_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
return bRet;
}
-static bool Put_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static bool Put_BC( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode, const SfxItemSet& rSet,
SwAttrSet* pOld, SwAttrSet* pNew )
{
- SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) );
+ SwAttrSet aNewSet( *rpAttrSet );
// #i76273# Robust
std::optional<SfxItemSetFixed<RES_FRMATR_STYLE_NAME, RES_FRMATR_CONDITIONAL_STYLE_NAME>> pStyleNames;
@@ -237,11 +235,11 @@ static bool Put_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
return bRet;
}
-static sal_uInt16 ClearItem_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static sal_uInt16 ClearItem_BC( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode, sal_uInt16 nWhich,
SwAttrSet* pOld, SwAttrSet* pNew )
{
- SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) );
+ SwAttrSet aNewSet( *rpAttrSet );
if( rNode.GetModifyAtAttr() )
aNewSet.SetModifyAtAttr( &rNode );
const sal_uInt16 nRet = aNewSet.ClearItem_BC( nWhich, pOld, pNew );
@@ -250,12 +248,12 @@ static sal_uInt16 ClearItem_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
return nRet;
}
-static sal_uInt16 ClearItem_BC( std::shared_ptr<const SfxItemSet>& rpAttrSet,
+static sal_uInt16 ClearItem_BC( std::shared_ptr<const SwAttrSet>& rpAttrSet,
const SwContentNode& rNode,
sal_uInt16 nWhich1, sal_uInt16 nWhich2,
SwAttrSet* pOld, SwAttrSet* pNew )
{
- SwAttrSet aNewSet( static_cast<const SwAttrSet&>(*rpAttrSet) );
+ SwAttrSet aNewSet( *rpAttrSet );
if( rNode.GetModifyAtAttr() )
aNewSet.SetModifyAtAttr( &rNode );
const sal_uInt16 nRet = aNewSet.ClearItem_BC( nWhich1, nWhich2, pOld, pNew );
@@ -1108,7 +1106,7 @@ SwContentNode::~SwContentNode()
m_pCondColl = nullptr;
if ( mpAttrSet && mbSetModifyAtAttr )
- const_cast<SwAttrSet*>(static_cast<const SwAttrSet*>(mpAttrSet.get()))->SetModifyAtAttr( nullptr );
+ const_cast<SwAttrSet*>(mpAttrSet.get())->SetModifyAtAttr( nullptr );
InvalidateInSwCache(RES_OBJECTDYING);
}
void SwContentNode::UpdateAttr(const SwUpdateAttr& rUpdate)
@@ -1627,7 +1625,9 @@ bool SwContentNode::SetAttr( const SfxItemSet& rSet )
}
else
{
- mpAttrSet = pFnd->GetStyleHandle();
+ std::shared_ptr<SfxItemSet> pItemSet = pFnd->GetStyleHandle();
+ mpAttrSet = std::dynamic_pointer_cast<SwAttrSet>(pItemSet);
+ assert(bool(pItemSet) == bool(mpAttrSet) && "types do not match");
}
if ( bSetParent )
@@ -1645,7 +1645,7 @@ bool SwContentNode::SetAttr( const SfxItemSet& rSet )
pNameItem->GetValue().isEmpty() )
AttrSetHandleHelper::SetParent( mpAttrSet, *this, &GetAnyFormatColl(), GetFormatColl() );
else
- const_cast<SfxItemSet*>(mpAttrSet.get())->SetParent( &GetFormatColl()->GetAttrSet() );
+ const_cast<SwAttrSet*>(mpAttrSet.get())->SetParent( &GetFormatColl()->GetAttrSet() );
}
return true;