diff options
Diffstat (limited to 'sc')
92 files changed, 1074 insertions, 949 deletions
diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx index a7e1c08a9f49..c1f9195e6445 100644 --- a/sc/inc/attarray.hxx +++ b/sc/inc/attarray.hxx @@ -67,24 +67,38 @@ struct ScLineFlags struct ScMergePatternState { std::optional<SfxItemSet> pItemSet; - const ScPatternAttr* pOld1; ///< existing objects, temporary - const ScPatternAttr* pOld2; + CellAttributeHolder aOld1; ///< existing objects, temporary + CellAttributeHolder aOld2; bool mbValidPatternId; sal_uInt64 mnPatternId; - ScMergePatternState() : pOld1(nullptr), pOld2(nullptr), + ScMergePatternState() : aOld1(), aOld2(), mbValidPatternId(true), mnPatternId(0) {} }; // we store an array of these where the pattern applies to all rows up till nEndRow -struct ScAttrEntry +class ScAttrEntry { + CellAttributeHolder aPattern; + +public: + ScAttrEntry() + : aPattern() + , nEndRow(0) + {} + SCROW nEndRow; - const ScPatternAttr* pPattern; + + const CellAttributeHolder& getCellAttributeHolder() const { return aPattern; } + void setCellAttributeHolder(const CellAttributeHolder& rNew) { aPattern = rNew; } + + const ScPatternAttr* getScPatternAttr() const { return aPattern.getScPatternAttr(); } + void setScPatternAttr(const ScPatternAttr* pNew, bool bPassingOwnership = false) { aPattern.setScPatternAttr(pNew, bPassingOwnership); } + bool operator==( const ScAttrEntry& other ) const { - return nEndRow == other.nEndRow && SfxPoolItem::areSame(pPattern, other.pPattern); + return nEndRow == other.nEndRow && CellAttributeHolder::areSame(&aPattern, &other.aPattern); } }; @@ -125,7 +139,7 @@ public: #if DEBUG_SC_TESTATTRARRAY void TestData() const; #endif - void Reset( const ScPatternAttr* pPattern); + void Reset(const CellAttributeHolder& rPattern); bool Concat(SCSIZE nPos); const ScPatternAttr* GetPattern( SCROW nRow ) const; @@ -144,18 +158,12 @@ public: void ApplyBlockFrame(const SvxBoxItem& rLineOuter, const SvxBoxInfoItem* pLineInner, SCROW nStartRow, SCROW nEndRow, bool bLeft, SCCOL nDistRight); - void SetPattern( SCROW nRow, const ScPatternAttr* pPattern, bool bPutToPool = false ) - { SetPatternAreaImpl(nRow, nRow, pPattern, bPutToPool, nullptr, /*bPassingOwnership*/false); } - const ScPatternAttr* SetPattern( SCROW nRow, std::unique_ptr<ScPatternAttr> pPattern, bool bPutToPool = false ) - { return SetPatternAreaImpl(nRow, nRow, pPattern.release(), bPutToPool, nullptr, /*bPassingOwnership*/true); } - void SetPatternArea( SCROW nStartRow, SCROW nEndRow, std::unique_ptr<ScPatternAttr> pPattern, - bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr) - { SetPatternAreaImpl(nStartRow, nEndRow, pPattern.release(), bPutToPool, pDataArray, /*bPassingOwnership*/true); } - void SetPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr* pPattern, - bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr) - { SetPatternAreaImpl(nStartRow, nEndRow, pPattern, bPutToPool, pDataArray, /*bPassingOwnership*/false); } + void SetPattern( SCROW nRow, const CellAttributeHolder& rPattern ) + { SetPatternAreaImpl(nRow, nRow, rPattern, nullptr); } + void SetPatternArea( SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& rPattern, ScEditDataArray* pDataArray = nullptr) + { SetPatternAreaImpl(nStartRow, nEndRow, rPattern, pDataArray); } void ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleSheet& rStyle ); - void ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCache* pCache, + void ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCache& rCache, ScEditDataArray* pDataArray = nullptr, bool* const pIsChanged = nullptr ); void SetAttrEntries(std::vector<ScAttrEntry> && vNewData); void ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow, @@ -196,8 +204,7 @@ public: void FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBoolRowSegments& rUsedRows, bool bReset ); bool IsStyleSheetUsed( const ScStyleSheet& rStyle ) const; - void SetPatternAreaSafe( SCROW nStartRow, SCROW nEndRow, - const ScPatternAttr* pWantedPattern, bool bDefault ); + void SetPatternAreaSafe( SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& rWantedPattern ); void CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, ScAttrArray& rAttrArray ); bool IsEmpty() const; @@ -227,9 +234,8 @@ public: SCSIZE Count( SCROW nRow1, SCROW nRow2 ) const; private: - const ScPatternAttr* SetPatternAreaImpl( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr* pPattern, - bool bPutToPool = false, ScEditDataArray* pDataArray = nullptr, - bool bPassingPatternOwnership = false ); + const ScPatternAttr* SetPatternAreaImpl( + SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& rPattern, ScEditDataArray* pDataArray = nullptr); }; // Iterator for attributes @@ -287,7 +293,7 @@ inline const ScPatternAttr* ScAttrIterator::Next( SCROW& rTop, SCROW& rBottom ) { rTop = nRow; rBottom = std::min( pArray->mvData[nPos].nEndRow, nEndRow ); - pRet = pArray->mvData[nPos].pPattern; + pRet = pArray->mvData[nPos].getScPatternAttr(); nRow = rBottom + 1; ++nPos; } diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 914199be25b5..87273f0f83ba 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -100,7 +100,8 @@ struct ScInterpreterContext; struct ScNeededSizeOptions { - const ScPatternAttr* pPattern; + CellAttributeHolder aPattern; + bool bFormula; bool bSkipMerged; bool bGetFont; @@ -144,7 +145,7 @@ public: const ScPatternAttr* GetPattern( SCROW nRow ) const; const ScPatternAttr* GetMostUsedPattern( SCROW nStartRow, SCROW nEndRow ) const; - SCROW ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged, + SCROW ApplySelectionCache( ScItemPoolCache& rCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged, SCCOL nCol ); void ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr, ScEditDataArray* pDataArray = nullptr, @@ -541,9 +542,9 @@ public: void ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr ); void ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr ); - const ScPatternAttr* SetPattern( SCROW nRow, std::unique_ptr<ScPatternAttr> ); - void SetPattern( SCROW nRow, const ScPatternAttr& ); - void SetPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& ); + void SetPattern( SCROW nRow, const CellAttributeHolder& rHolder ); + void SetPattern( SCROW nRow, const ScPatternAttr& rPattern ); + void SetPatternArea( SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& ); void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange, const ScPatternAttr& rPattern, SvNumFormatType nNewType ); @@ -575,7 +576,7 @@ public: void RemoveProtected( SCROW nStartRow, SCROW nEndRow ); - SCROW ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged ); + SCROW ApplySelectionCache( ScItemPoolCache& rCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged ); void DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rMark, bool bBroadcast ); void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark ); @@ -1031,20 +1032,19 @@ inline void ScColumn::ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt pAttrArray->ClearItems( nStartRow, nEndRow, pWhich ); } -inline const ScPatternAttr* ScColumn::SetPattern( SCROW nRow, std::unique_ptr<ScPatternAttr> pPatAttr ) +inline void ScColumn::SetPattern( SCROW nRow, const CellAttributeHolder& rHolder ) { - return pAttrArray->SetPattern( nRow, std::move(pPatAttr), true/*bPutToPool*/ ); + return pAttrArray->SetPattern( nRow, rHolder ); } -inline void ScColumn::SetPattern( SCROW nRow, const ScPatternAttr& rPatAttr ) +inline void ScColumn::SetPattern( SCROW nRow, const ScPatternAttr& rPattern ) { - pAttrArray->SetPattern( nRow, &rPatAttr, true/*bPutToPool*/ ); + pAttrArray->SetPattern( nRow, CellAttributeHolder(&rPattern) ); } -inline void ScColumn::SetPatternArea( SCROW nStartRow, SCROW nEndRow, - const ScPatternAttr& rPatAttr ) +inline void ScColumn::SetPatternArea( SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& rHolder ) { - pAttrArray->SetPatternArea( nStartRow, nEndRow, &rPatAttr, true/*bPutToPool*/ ); + pAttrArray->SetPatternArea( nStartRow, nEndRow, rHolder ); } inline void ScColumnData::SetAttrEntries(std::vector<ScAttrEntry> && vNewData) diff --git a/sc/inc/docpool.hxx b/sc/inc/docpool.hxx index c73d034f2fb2..614e3d4229b8 100644 --- a/sc/inc/docpool.hxx +++ b/sc/inc/docpool.hxx @@ -29,7 +29,6 @@ class ScDocument; class SC_DLLPUBLIC ScDocumentPool final : public SfxItemPool { std::vector<SfxPoolItem*> mvPoolDefaults; - sal_uInt64 mnCurrentMaxKey; public: ScDocumentPool(); @@ -40,15 +39,10 @@ public: virtual rtl::Reference<SfxItemPool> Clone() const override; virtual MapUnit GetMetric( sal_uInt16 nWhich ) const override; - void StyleDeleted( const ScStyleSheet* pStyle ); // delete templates(?) in organizer - void CellStyleCreated( std::u16string_view rName, const ScDocument& rDoc ); virtual bool GetPresentation( const SfxPoolItem& rItem, MapUnit ePresentationMetric, OUString& rText, const IntlWrapper& rIntl ) const override; -private: - virtual void newItem_Callback(const SfxPoolItem& rItem) const override; - virtual bool newItem_UseDirect(const SfxPoolItem& rItem) const override; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 11b65e9262c0..d94b0ef4fb53 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -356,6 +356,14 @@ public: }; private: + // needs to be shared to allow the bIsClip/bIsUndo mechanism to + // do the right thing (SCDOCMODE_CLIP, SCDOCMODE_UNDO) + mutable std::shared_ptr<CellAttributeHelper> mpCellAttributeHelper; + +public: + SC_DLLPUBLIC CellAttributeHelper& getCellAttributeHelper() const; + +private: rtl::Reference<ScPoolHelper> mxPoolHelper; std::shared_ptr<svl::SharedStringPool> mpCellStringPool; @@ -1939,8 +1947,8 @@ public: SCTAB nTab, ScMF nFlags ); SC_DLLPUBLIC void SetPattern( const ScAddress&, const ScPatternAttr& rAttr ); - SC_DLLPUBLIC const ScPatternAttr* SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPatternAttr> pAttr ); - SC_DLLPUBLIC const ScPatternAttr* SetPattern( const ScAddress& rPos, std::unique_ptr<ScPatternAttr> pAttr ); + SC_DLLPUBLIC void SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, const CellAttributeHolder& rHolder ); + SC_DLLPUBLIC void SetPattern( const ScAddress& rPos, const CellAttributeHolder& rHolder ); SC_DLLPUBLIC void SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, const ScPatternAttr& rAttr ); void AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, @@ -2090,7 +2098,6 @@ public: void StripHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2, SCTAB nTab ); void ExtendHidden( SCCOL& rX1, SCROW& rY1, SCCOL& rX2, SCROW& rY2, SCTAB nTab ); - SC_DLLPUBLIC ScPatternAttr* GetDefPattern() const; SC_DLLPUBLIC ScDocumentPool* GetPool(); SC_DLLPUBLIC ScStyleSheetPool* GetStyleSheetPool() const; void GetUnprotectedCells( ScRangeList& rRange, SCTAB nTab ) const; @@ -2142,9 +2149,6 @@ public: SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero = true ) const; SC_DLLPUBLIC ScRange GetRange( SCTAB nTab, const tools::Rectangle& rMMRect, bool bHiddenAsZero = true ) const; - void UpdStlShtPtrsFrmNms(); - void StylesToNames(); - SC_DLLPUBLIC void CopyStdStylesFrom( const ScDocument& rSrcDoc ); static sal_uInt16 GetSrcVersion() { return nSrcVer; } diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index fe7b8bb407b2..1539858434bc 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -603,7 +603,7 @@ public: static void InitAddIns(); SC_DLLPUBLIC static void Clear(); // at the end of the program - static void InitTextHeight(const SfxItemPool* pPool); + static void InitTextHeight(SfxItemPool& rPool); static SvxBrushItem* GetEmptyBrushItem() { return xEmptyBrushItem.get(); } static SvxBrushItem* GetButtonBrushItem(); diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx index d6536551f965..361ed40cd25b 100644 --- a/sc/inc/patattr.hxx +++ b/sc/inc/patattr.hxx @@ -21,13 +21,14 @@ #include <optional> -#include <svl/setitem.hxx> #include <svl/itemset.hxx> #include <svl/languageoptions.hxx> #include <tools/degree.hxx> #include <editeng/svxenum.hxx> #include "scdllapi.h" #include "fonthelper.hxx" +#include "scitems.hxx" +#include <unordered_set> namespace vcl { class Font; } namespace model { class ComplexColor; } @@ -50,43 +51,106 @@ enum class ScAutoFontColorMode IgnoreAll ///< like DISPLAY, but ignore stored font and background colors }; -class SC_DLLPUBLIC ScPatternAttr final : public SfxSetItem +class ScPatternAttr; + +class SC_DLLPUBLIC CellAttributeHelper final { - std::optional<OUString> pName; - mutable std::optional<bool> mxVisible; - ScStyleSheet* pStyle; - sal_uInt64 mnPAKey; + friend class CellAttributeHolder; + + SfxItemPool& mrSfxItemPool; + mutable ScPatternAttr* mpDefaultCellAttribute; + mutable std::unordered_set<const ScPatternAttr*> maRegisteredCellAttributes; + mutable const ScPatternAttr* mpLastHit; + mutable sal_uInt64 mnCurrentMaxKey; + + // only to be used from CellAttributeHolder, so private + const ScPatternAttr* registerAndCheck(const ScPatternAttr& rCandidate, bool bPassingOwnership) const; + void doUnregister(const ScPatternAttr& rCandidate); + public: - ScPatternAttr(SfxItemSet&& pItemSet, const OUString& rStyleName); - ScPatternAttr(SfxItemSet&& pItemSet); - ScPatternAttr(SfxItemPool* pItemPool); - ScPatternAttr(const ScPatternAttr& rPatternAttr); + explicit CellAttributeHelper(SfxItemPool& rSfxItemPool); + ~CellAttributeHelper(); + + const ScPatternAttr& getDefaultCellAttribute() const; + SfxItemPool& GetPool() const { return mrSfxItemPool; } - virtual ScPatternAttr* Clone( SfxItemPool *pPool = nullptr ) const override; + void CellStyleDeleted(const ScStyleSheet& rStyle); + void CellStyleCreated(ScDocument& rDoc, std::u16string_view rName); + void UpdateAllStyleSheets(ScDocument& rDoc); + void AllStylesToNames(); +}; - virtual bool operator==(const SfxPoolItem& rCmp) const override; +class SC_DLLPUBLIC CellAttributeHolder final +{ + const ScPatternAttr* mpScPatternAttr; - const SfxPoolItem& GetItem( sal_uInt16 nWhichP ) const - { return GetItemSet().Get(nWhichP); } - template<class T> const T& GetItem( TypedWhichId<T> nWhich ) const - { return static_cast<const T&>(GetItem(sal_uInt16(nWhich))); } +public: + CellAttributeHolder(const ScPatternAttr* pScPatternAttr = nullptr, bool bPassingOwnership = false); + CellAttributeHolder(const CellAttributeHolder& rHolder); + ~CellAttributeHolder(); - static const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet ); - template<class T> static const T& GetItem( TypedWhichId<T> nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet ) - { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), rItemSet, pCondSet)); } + const CellAttributeHolder& operator=(const CellAttributeHolder& rHolder); + bool operator==(const CellAttributeHolder& rHolder) const; - const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet* pCondSet ) const; - template<class T> const T& GetItem( TypedWhichId<T> nWhich, const SfxItemSet* pCondSet ) const - { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), pCondSet)); } + const ScPatternAttr* getScPatternAttr() const { return mpScPatternAttr; } + void setScPatternAttr(const ScPatternAttr* pNew, bool bPassingOwnership = false); - /// @param pWhich are no ranges, but single IDs, 0-terminated - bool HasItemsSet( const sal_uInt16* pWhich ) const; - void ClearItems( const sal_uInt16* pWhich ); + bool operator!() const { return nullptr == mpScPatternAttr; } + explicit operator bool() const { return nullptr != mpScPatternAttr; } - void DeleteUnchanged( const ScPatternAttr* pOldAttrs ); + // version that allows nullptrs + static bool areSame(const CellAttributeHolder* p1, const CellAttributeHolder* p2); +}; + +class SC_DLLPUBLIC ScPatternAttr final +{ + friend class CellAttributeHelper; + + SfxItemSet maLocalSfxItemSet; + std::optional<OUString> pName; + mutable std::optional<bool> mxVisible; + ScStyleSheet* pStyle; + CellAttributeHelper* pCellAttributeHelper; + sal_uInt64 mnPAKey; + mutable size_t mnRefCount; +#ifdef DBG_UTIL + sal_uInt32 m_nSerialNumber; + bool m_bDeleted; +#endif + +public: + ScPatternAttr(CellAttributeHelper& rHelper, const SfxItemSet* pItemSet = nullptr, const OUString* pStyleName = nullptr); + ScPatternAttr(const ScPatternAttr& rPatternAttr); + ~ScPatternAttr(); + + virtual bool operator==(const ScPatternAttr& rCmp) const; + + // version that allows nullptrs + static bool areSame(const ScPatternAttr* pItem1, const ScPatternAttr* pItem2); + bool isRegistered() const { return 0 != mnRefCount; } + bool isDefault() const { return this == &pCellAttributeHelper->getDefaultCellAttribute(); } + CellAttributeHelper& getCellAttributeHelper() const { return *pCellAttributeHelper; } + + const SfxItemSet& GetItemSet() const { return maLocalSfxItemSet; } + SfxItemSet& GetItemSet() { return maLocalSfxItemSet; } + + const SfxPoolItem& GetItem(sal_uInt16 nWhichP) const { return maLocalSfxItemSet.Get(nWhichP); } + template<class T> const T& GetItem( TypedWhichId<T> nWhich ) const + { return static_cast<const T&>(GetItem(sal_uInt16(nWhich))); } + static const SfxPoolItem& GetItem(sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet); + template<class T> static const T& GetItem(TypedWhichId<T> nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet) + { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), rItemSet, pCondSet)); } + const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet* pCondSet ) const; + template<class T> const T& GetItem(TypedWhichId<T> nWhich, const SfxItemSet* pCondSet) const + { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), pCondSet)); } + + /// @param pWhich are no ranges, but single IDs, 0-terminated + bool HasItemsSet( const sal_uInt16* pWhich ) const; + void ClearItems( const sal_uInt16* pWhich ); + void DeleteUnchanged( const ScPatternAttr* pOldAttrs ); static SvxCellOrientation GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet ); - SvxCellOrientation GetCellOrientation( const SfxItemSet* pCondSet = nullptr ) const; + SvxCellOrientation GetCellOrientation( const SfxItemSet* pCondSet = nullptr ) const; /** Static helper function to fill a font object from the passed item set. */ static void fillFontOnly(vcl::Font& rFont, const SfxItemSet& rItemSet, @@ -119,7 +183,7 @@ public: const Color* pBackConfigColor = nullptr, const Color* pTextConfigColor = nullptr) const { - fillColor(rComplexColor, GetItemSet(), eAutoMode, pCondSet, pBackConfigColor, pTextConfigColor); + fillColor(rComplexColor, maLocalSfxItemSet, eAutoMode, pCondSet, pBackConfigColor, pTextConfigColor); } void fillFontOnly(vcl::Font& rFont, @@ -128,7 +192,7 @@ public: const SfxItemSet* pCondSet = nullptr, SvtScriptType nScript = SvtScriptType::NONE) const { - fillFontOnly(rFont, GetItemSet(), pOutDev, pScale, pCondSet, nScript); + fillFontOnly(rFont, maLocalSfxItemSet, pOutDev, pScale, pCondSet, nScript); } /** Fills a font object from the own item set. */ @@ -140,7 +204,7 @@ public: const Color* pBackConfigColor = nullptr, const Color* pTextConfigColor = nullptr) const { - fillFont(rFont, GetItemSet(), eAutoMode, pOutDev, pScale, pCondSet, nScript, pBackConfigColor, pTextConfigColor); + fillFont(rFont, maLocalSfxItemSet, eAutoMode, pOutDev, pScale, pCondSet, nScript, pBackConfigColor, pTextConfigColor); } /** Converts all Calc items contained in rSrcSet to edit engine items and puts them into rEditSet. */ @@ -155,7 +219,7 @@ public: void FillEditParaItems( SfxItemSet* pSet ) const; - ScPatternAttr* PutInPool( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const; + CellAttributeHolder MigrateToDocument( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const; void SetStyleSheet(ScStyleSheet* pNewStyle, bool bClearDirectFormat = true); const ScStyleSheet* GetStyleSheet() const { return pStyle; } @@ -180,12 +244,6 @@ public: void SetPAKey(sal_uInt64 nKey); sal_uInt64 GetPAKey() const; - // TODO: tdf#135215: This is a band-aid to detect changes and invalidate the hash, - // a proper way would be probably to override SfxItemSet::Changed(), but 6cb400f41df0dd10 - // hardcoded SfxSetItem to contain SfxItemSet. - SfxItemSet& GetItemSet() { mxVisible.reset(); return SfxSetItem::GetItemSet(); } - using SfxSetItem::GetItemSet; - private: bool CalcVisible() const; }; diff --git a/sc/inc/poolcach.hxx b/sc/inc/poolcach.hxx index 6e3c3deda916..5b9057b7faf3 100644 --- a/sc/inc/poolcach.hxx +++ b/sc/inc/poolcach.hxx @@ -19,35 +19,33 @@ #pragma once #include "scdllapi.h" +#include "patattr.hxx" #include <vector> -class SfxItemPool; +class CellAttributeHelper; class SfxItemSet; class SfxPoolItem; -class ScPatternAttr; class ScItemPoolCache { struct SfxItemModifyImpl { - const ScPatternAttr *pOrigItem; - ScPatternAttr *pPoolItem; + const CellAttributeHolder aOriginal; + const CellAttributeHolder aModified; + SfxItemModifyImpl(const CellAttributeHolder& a, const CellAttributeHolder &b) : aOriginal(a), aModified(b) {} }; - SfxItemPool *pPool; - std::vector<SfxItemModifyImpl> - m_aCache; - const SfxItemSet *pSetToPut; - const SfxPoolItem *pItemToPut; + CellAttributeHelper& rHelper; + std::vector<SfxItemModifyImpl> m_aCache; + const SfxItemSet* pSetToPut; + const SfxPoolItemHolder aItemToPut; public: - ScItemPoolCache( SfxItemPool *pPool, - const SfxPoolItem *pPutItem ); - ScItemPoolCache( SfxItemPool *pPool, - const SfxItemSet *pPutSet ); - ~ScItemPoolCache(); + ScItemPoolCache( CellAttributeHelper& rHelper, const SfxPoolItem& rPutItem ); + ScItemPoolCache( CellAttributeHelper& rHelper, const SfxItemSet& rPutSet ); + ~ScItemPoolCache(); - const ScPatternAttr& ApplyTo( const ScPatternAttr& rSetItem ); + const CellAttributeHolder& ApplyTo( const CellAttributeHolder& rSetItem ); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/inc/scitems.hxx b/sc/inc/scitems.hxx index dd91e2f63a3c..538624e4c5cb 100644 --- a/sc/inc/scitems.hxx +++ b/sc/inc/scitems.hxx @@ -162,48 +162,46 @@ constexpr TypedWhichId<ScCondFormatItem> ATTR_CONDITIONAL (154); constexpr TypedWhichId<SfxStringItem> ATTR_HYPERLINK (155); constexpr sal_uInt16 ATTR_PATTERN_END(155); // end cell-attribute-pattern - -constexpr TypedWhichId<ScPatternAttr> ATTR_PATTERN (156); // page attributes -constexpr TypedWhichId<SvxLRSpaceItem> ATTR_LRSPACE (157); // editor: PageDesc-TabPage -constexpr TypedWhichId<SvxULSpaceItem> ATTR_ULSPACE (158); -constexpr TypedWhichId<SvxPageItem> ATTR_PAGE (159); -constexpr TypedWhichId<SvxPaperBinItem> ATTR_PAGE_PAPERBIN (160); -constexpr TypedWhichId<SvxSizeItem> ATTR_PAGE_SIZE (161); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_HORCENTER (162); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_VERCENTER (163); - -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_ON (164); // editor: header/footer-page -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_DYNAMIC (165); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_SHARED (166); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_SHARED_FIRST (167); - -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_NOTES (168); // editor: table -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_GRID (169); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_HEADERS (170); -constexpr TypedWhichId<ScViewObjectModeItem> ATTR_PAGE_CHARTS (171); -constexpr TypedWhichId<ScViewObjectModeItem> ATTR_PAGE_OBJECTS (172); -constexpr TypedWhichId<ScViewObjectModeItem> ATTR_PAGE_DRAWINGS (173); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_TOPDOWN (174); -constexpr TypedWhichId<SfxUInt16Item> ATTR_PAGE_SCALE (175); -constexpr TypedWhichId<SfxUInt16Item> ATTR_PAGE_SCALETOPAGES (176); -constexpr TypedWhichId<SfxUInt16Item> ATTR_PAGE_FIRSTPAGENO (177); - -constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_HEADERLEFT (178); // contents of header/ -constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_FOOTERLEFT (179); // footer (left) -constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_HEADERRIGHT (180); // contents of header/ -constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_FOOTERRIGHT (181); // footer (right) -constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_HEADERFIRST (182); // contents of header/ -constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_FOOTERFIRST (183); // footer (first page) -constexpr TypedWhichId<SvxSetItem> ATTR_PAGE_HEADERSET (184); // the corresponding sets -constexpr TypedWhichId<SvxSetItem> ATTR_PAGE_FOOTERSET (185); - -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_FORMULAS (186); -constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_NULLVALS (187); - -constexpr TypedWhichId<ScPageScaleToItem> ATTR_PAGE_SCALETO (188); // #i8868# scale printout to width/height - -constexpr TypedWhichId<SfxBoolItem> ATTR_HIDDEN (189); +constexpr TypedWhichId<SvxLRSpaceItem> ATTR_LRSPACE (156); // editor: PageDesc-TabPage +constexpr TypedWhichId<SvxULSpaceItem> ATTR_ULSPACE (157); +constexpr TypedWhichId<SvxPageItem> ATTR_PAGE (158); +constexpr TypedWhichId<SvxPaperBinItem> ATTR_PAGE_PAPERBIN (159); +constexpr TypedWhichId<SvxSizeItem> ATTR_PAGE_SIZE (160); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_HORCENTER (161); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_VERCENTER (162); + +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_ON (163); // editor: header/footer-page +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_DYNAMIC (164); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_SHARED (165); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_SHARED_FIRST (166); + +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_NOTES (167); // editor: table +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_GRID (168); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_HEADERS (169); +constexpr TypedWhichId<ScViewObjectModeItem> ATTR_PAGE_CHARTS (170); +constexpr TypedWhichId<ScViewObjectModeItem> ATTR_PAGE_OBJECTS (171); +constexpr TypedWhichId<ScViewObjectModeItem> ATTR_PAGE_DRAWINGS (172); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_TOPDOWN (173); +constexpr TypedWhichId<SfxUInt16Item> ATTR_PAGE_SCALE (174); +constexpr TypedWhichId<SfxUInt16Item> ATTR_PAGE_SCALETOPAGES (175); +constexpr TypedWhichId<SfxUInt16Item> ATTR_PAGE_FIRSTPAGENO (176); + +constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_HEADERLEFT (177); // contents of header/ +constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_FOOTERLEFT (178); // footer (left) +constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_HEADERRIGHT (179); // contents of header/ +constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_FOOTERRIGHT (180); // footer (right) +constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_HEADERFIRST (181); // contents of header/ +constexpr TypedWhichId<ScPageHFItem> ATTR_PAGE_FOOTERFIRST (182); // footer (first page) +constexpr TypedWhichId<SvxSetItem> ATTR_PAGE_HEADERSET (183); // the corresponding sets +constexpr TypedWhichId<SvxSetItem> ATTR_PAGE_FOOTERSET (184); + +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_FORMULAS (185); +constexpr TypedWhichId<SfxBoolItem> ATTR_PAGE_NULLVALS (186); + +constexpr TypedWhichId<ScPageScaleToItem> ATTR_PAGE_SCALETO (187); // #i8868# scale printout to width/height + +constexpr TypedWhichId<SfxBoolItem> ATTR_HIDDEN (188); constexpr sal_uInt16 ATTR_ENDINDEX(ATTR_HIDDEN); // end of pool-range diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 3b47a52c0ab8..72e78b195986 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -780,7 +780,7 @@ public: void SetAttrEntries( SCCOL nStartCol, SCCOL nEndCol, std::vector<ScAttrEntry> && vNewData); void SetPattern( const ScAddress& rPos, const ScPatternAttr& rAttr ); - const ScPatternAttr* SetPattern( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPatternAttr> ); + void SetPattern( SCCOL nCol, SCROW nRow, const CellAttributeHolder& rHolder ); void SetPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr ); void ApplyPatternIfNumberformatIncompatible( const ScRange& rRange, const ScPatternAttr& rPattern, SvNumFormatType nNewType ); @@ -810,7 +810,7 @@ public: bool ApplyFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags ); bool RemoveFlags( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScMF nFlags ); - void ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = nullptr, bool* const pIsChanged = nullptr ); + void ApplySelectionCache( ScItemPoolCache& rCache, const ScMarkData& rMark, ScEditDataArray* pDataArray = nullptr, bool* const pIsChanged = nullptr ); void DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rMark, bool bBroadcast = true ); void ClearSelectionItems( const sal_uInt16* pWhich, const ScMarkData& rMark ); diff --git a/sc/qa/unit/subsequent_export_test.cxx b/sc/qa/unit/subsequent_export_test.cxx index 30600191d54a..4fc83ab7df9f 100644 --- a/sc/qa/unit/subsequent_export_test.cxx +++ b/sc/qa/unit/subsequent_export_test.cxx @@ -1740,7 +1740,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest, testRichTextExportODS) pEditText = pDoc->GetEditText(ScAddress(1, 8, 0)); CPPUNIT_ASSERT_MESSAGE("Incorrect B9 value.", aCheckFunc.checkB9(pEditText)); - ScPatternAttr aCellFontColor(pDoc->GetPool()); + ScPatternAttr aCellFontColor(pDoc->getCellAttributeHelper()); aCellFontColor.GetItemSet().Put(SvxColorItem(COL_BLUE, ATTR_FONT_COLOR)); // Set font color of B10 to blue. pDoc->ApplyPattern(1, 9, 0, aCellFontColor); diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index 95c7057aef2d..41d76cc9698d 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -223,7 +223,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testTdf143979) sal_uInt32 nFormat; SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); pFormatter->PutEntry(aCode, nCheckPos, nType, nFormat); - ScPatternAttr aNewAttrs(pDoc->GetPool()); + ScPatternAttr aNewAttrs(pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); pDoc->ApplyPattern(0, 0, 0, aNewAttrs); @@ -1418,7 +1418,7 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testWholeRowBold) ScDocument* pDoc = getScDoc(); // Make entire second row bold. - ScPatternAttr boldAttr(pDoc->GetPool()); + ScPatternAttr boldAttr(pDoc->getCellAttributeHelper()); boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT)); pDoc->ApplyPatternAreaTab(0, 1, pDoc->MaxCol(), 1, 0, boldAttr); } diff --git a/sc/qa/unit/subsequent_filters_test2.cxx b/sc/qa/unit/subsequent_filters_test2.cxx index 22339c010e8f..31dae9282166 100644 --- a/sc/qa/unit/subsequent_filters_test2.cxx +++ b/sc/qa/unit/subsequent_filters_test2.cxx @@ -1637,10 +1637,10 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest2, testBackColorFilter) createScDoc(); ScDocument* pDoc = getScDoc(); - ScPatternAttr aPattern1(pDoc->GetPool()); + ScPatternAttr aPattern1(pDoc->getCellAttributeHelper()); aPattern1.GetItemSet().Put(SvxBrushItem(aBackColor1, ATTR_BACKGROUND)); - ScPatternAttr aPattern2(pDoc->GetPool()); + ScPatternAttr aPattern2(pDoc->getCellAttributeHelper()); aPattern2.GetItemSet().Put(SvxBrushItem(aBackColor2, ATTR_BACKGROUND)); // Apply the pattern to cell A1:A2 diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index c75742eabdfc..370f2d1f5c80 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -1187,7 +1187,7 @@ CPPUNIT_TEST_FIXTURE(Test, testHorizontalAttrIterator) m_pDoc->InsertTab(0, "Test"); // Set the background color of B2:C3,D2,E3,C4:D4,B5:D5 to blue - ScPatternAttr aCellBackColor(m_pDoc->GetPool()); + ScPatternAttr aCellBackColor(m_pDoc->getCellAttributeHelper()); aCellBackColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND)); m_pDoc->ApplyPatternAreaTab(1, 1, 2, 2, 0, aCellBackColor); m_pDoc->ApplyPatternAreaTab(3, 1, 3, 1, 0, aCellBackColor); @@ -1210,7 +1210,7 @@ CPPUNIT_TEST_FIXTURE(Test, testHorizontalAttrIterator) size_t nCheckPos = 0; for (const ScPatternAttr* pAttr = aIter.GetNext(nCol1, nCol2, nRow); pAttr; pAttr = aIter.GetNext(nCol1, nCol2, nRow)) { - if (SfxPoolItem::areSame( pAttr, m_pDoc->GetDefPattern())) + if (pAttr->isDefault()) continue; CPPUNIT_ASSERT_MESSAGE("Iteration longer than expected.", nCheckPos < nCheckLen); CPPUNIT_ASSERT_EQUAL(aChecks[nCheckPos][0], static_cast<int>(nCol1)); @@ -1235,7 +1235,7 @@ CPPUNIT_TEST_FIXTURE(Test, testIteratorsUnallocatedColumnsAttributes) CPPUNIT_ASSERT_EQUAL(allocatedColsCount, m_pDoc->GetAllocatedColumnsCount(0)); // Make entire second row and third row bold. - ScPatternAttr boldAttr(m_pDoc->GetPool()); + ScPatternAttr boldAttr(m_pDoc->getCellAttributeHelper()); boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT)); m_pDoc->ApplyPatternAreaTab(0, 1, m_pDoc->MaxCol(), 2, 0, boldAttr); @@ -1293,15 +1293,15 @@ CPPUNIT_TEST_FIXTURE(Test, testIteratorsDefPattern) // Set cells as bold, default allocated, bold, default unallocated. SCCOL firstCol = 100; SCCOL lastCol = 103; - ScPatternAttr boldAttr(m_pDoc->GetPool()); + ScPatternAttr boldAttr(m_pDoc->getCellAttributeHelper()); boldAttr.GetItemSet().Put(SvxWeightItem(WEIGHT_BOLD, ATTR_FONT_WEIGHT)); m_pDoc->ApplyPattern(100, 0, 0, boldAttr); m_pDoc->ApplyPattern(102, 0, 0, boldAttr); CPPUNIT_ASSERT_EQUAL(SCCOL(102 + 1), m_pDoc->GetAllocatedColumnsCount(0)); const ScPatternAttr* pattern = m_pDoc->GetPattern(100, 0, 0); - const ScPatternAttr* defPattern = m_pDoc->GetDefPattern(); - CPPUNIT_ASSERT(!SfxPoolItem::areSame(pattern, defPattern)); + const ScPatternAttr* defPattern(&m_pDoc->getCellAttributeHelper().getDefaultCellAttribute()); //GetDefPattern(); + CPPUNIT_ASSERT(!ScPatternAttr::areSame(pattern, defPattern)); CPPUNIT_ASSERT_EQUAL(pattern, m_pDoc->GetPattern(102, 0, 0)); CPPUNIT_ASSERT_EQUAL(defPattern, m_pDoc->GetPattern(101, 0, 0)); CPPUNIT_ASSERT_EQUAL(defPattern, m_pDoc->GetPattern(103, 0, 0)); @@ -3481,7 +3481,7 @@ CPPUNIT_TEST_FIXTURE(Test, testAutoFilterTimeValue) // Apply the "hour:minute:second" format to A2:A3. SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); sal_uInt32 nFormat = pFormatter->GetFormatIndex(NF_TIME_HH_MMSS, LANGUAGE_ENGLISH_US); - ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); @@ -3634,7 +3634,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf76441) SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat ); - ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); { @@ -3672,7 +3672,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf76836) SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat ); - ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); @@ -3705,7 +3705,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf142186) SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat ); - ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); { @@ -3759,7 +3759,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf126342) SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); pFormatter->PutEntry( aCode, nCheckPos, nType, nFormat ); - ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); m_pDoc->ApplyPattern(0, 0, 0, aNewAttrs); @@ -3892,7 +3892,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateFilterContains) // Set the fields as dates. SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable(); sal_uInt32 nFormat = pFormatter->GetFormatIndex(NF_DATE_DIN_YYMMDD, LANGUAGE_ENGLISH_US); - ScPatternAttr aNewAttrs(m_pDoc->GetPool()); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); m_pDoc->ApplyPatternAreaTab(0, 1, 0, 5, 0, aNewAttrs); // apply it to A1:A6 @@ -6657,7 +6657,7 @@ CPPUNIT_TEST_FIXTURE(Test, testProtectedSheetEditByRow) { // Remove protected flags from rows 2-5. - ScPatternAttr aAttr(m_pDoc->GetPool()); + ScPatternAttr aAttr(m_pDoc->getCellAttributeHelper()); aAttr.GetItemSet().Put(ScProtectionAttr(false)); m_pDoc->ApplyPatternAreaTab(0, 1, m_pDoc->MaxCol(), 4, 0, aAttr); @@ -6733,7 +6733,7 @@ CPPUNIT_TEST_FIXTURE(Test, testProtectedSheetEditByColumn) { // Remove protected flags from columns B to E. - ScPatternAttr aAttr(m_pDoc->GetPool()); + ScPatternAttr aAttr(m_pDoc->getCellAttributeHelper()); aAttr.GetItemSet().Put(ScProtectionAttr(false)); m_pDoc->ApplyPatternAreaTab(1, 0, 4, m_pDoc->MaxRow(), 0, aAttr); diff --git a/sc/qa/unit/ucalc_DocumentThemes.cxx b/sc/qa/unit/ucalc_DocumentThemes.cxx index d0bd29052c16..2a05badedc65 100644 --- a/sc/qa/unit/ucalc_DocumentThemes.cxx +++ b/sc/qa/unit/ucalc_DocumentThemes.cxx @@ -57,7 +57,7 @@ CPPUNIT_TEST_FIXTURE(DocumentThemesTest, testChangeTheme) auto eBackgroundThemeType = model::ThemeColorType::Accent5; auto eCellTextThemeType = model::ThemeColorType::Accent2; - ScPatternAttr aNewPattern(m_pDoc->GetPool()); + ScPatternAttr aNewPattern(m_pDoc->getCellAttributeHelper()); { model::ComplexColor aComplexColor; aComplexColor.setThemeColor(eBackgroundThemeType); diff --git a/sc/qa/unit/ucalc_copypaste.cxx b/sc/qa/unit/ucalc_copypaste.cxx index bec9bb499b94..b673ad7de3a1 100644 --- a/sc/qa/unit/ucalc_copypaste.cxx +++ b/sc/qa/unit/ucalc_copypaste.cxx @@ -1609,7 +1609,7 @@ void TestCopyPaste::executeCopyPasteSpecial(const SCTAB srcSheet, const SCTAB de m_pDoc->SetString(10, 17, srcSheet, "=SUM(Range_aCa5_aCa10)"); // add patterns - ScPatternAttr aCellBlueColor(m_pDoc->GetPool()); + ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper()); aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND)); m_pDoc->ApplyPatternAreaTab(1, 2, 1, 4, srcSheet, aCellBlueColor); @@ -1624,12 +1624,12 @@ void TestCopyPaste::executeCopyPasteSpecial(const SCTAB srcSheet, const SCTAB de CPPUNIT_ASSERT_MESSAGE("SrcSheet.B6 has no pattern", !pItem); // row 2 on empty cell - ScPatternAttr aCellGreenColor(m_pDoc->GetPool()); + ScPatternAttr aCellGreenColor(m_pDoc->getCellAttributeHelper()); aCellGreenColor.GetItemSet().Put(SvxBrushItem(COL_GREEN, ATTR_BACKGROUND)); m_pDoc->ApplyPatternAreaTab(5, 4, 5, 4, srcSheet, aCellGreenColor); // row 4 for multi range row selection - ScPatternAttr aCellRedColor(m_pDoc->GetPool()); + ScPatternAttr aCellRedColor(m_pDoc->getCellAttributeHelper()); aCellRedColor.GetItemSet().Put(SvxBrushItem(COL_RED, ATTR_BACKGROUND)); m_pDoc->ApplyPatternAreaTab(3, 6, 4, 6, srcSheet, aCellRedColor); @@ -9345,7 +9345,7 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, testCopyPasteSkipEmpty) m_pDoc->SetString(ScAddress(1, 4, 0), "E"); // Set the background color of B1:B5 to blue. - ScPatternAttr aCellBackColor(m_pDoc->GetPool()); + ScPatternAttr aCellBackColor(m_pDoc->getCellAttributeHelper()); aCellBackColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND)); m_pDoc->ApplyPatternAreaTab(1, 0, 1, 4, 0, aCellBackColor); @@ -10723,7 +10723,7 @@ CPPUNIT_TEST_FIXTURE(TestCopyPaste, testUndoBackgroundColor) m_pDoc->SetValue(ScAddress(3, 4, 0), 3.0); // D5 // Add patterns - ScPatternAttr aCellBlueColor(m_pDoc->GetPool()); + ScPatternAttr aCellBlueColor(m_pDoc->getCellAttributeHelper()); aCellBlueColor.GetItemSet().Put(SvxBrushItem(COL_BLUE, ATTR_BACKGROUND)); m_pDoc->ApplyPatternAreaTab(0, 3, m_pDoc->MaxCol(), 3, 0, aCellBlueColor); diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index feb0e8fef22a..105c7e4a772d 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -4257,8 +4257,7 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFormulaRefUpdateValidity) sal_uInt32 nIndex = m_pDoc->AddValidationEntry(aData); SfxUInt32Item aItem(ATTR_VALIDDATA, nIndex); - ScPatternAttr aNewAttrs( - SfxItemSet(*m_pDoc->GetPool(), svl::Items<ATTR_PATTERN_START, ATTR_PATTERN_END>)); + ScPatternAttr aNewAttrs(m_pDoc->getCellAttributeHelper()); aNewAttrs.GetItemSet().Put(aItem); m_pDoc->ApplyPattern(0, 1, 0, aNewAttrs); diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 7124e78be37e..4b9bbc7a4e2c 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -62,11 +62,11 @@ ScAttrArray::ScAttrArray( SCCOL nNewCol, SCTAB nNewTab, ScDocument& rDoc, ScAttr for ( size_t nIdx = 0; nIdx < pDefaultColAttrArray->mvData.size(); ++nIdx ) { mvData[nIdx].nEndRow = pDefaultColAttrArray->mvData[nIdx].nEndRow; - ScPatternAttr aNewPattern( *(pDefaultColAttrArray->mvData[nIdx].pPattern) ); - mvData[nIdx].pPattern = &rDocument.GetPool()->DirectPutItemInPool( aNewPattern ); + mvData[nIdx].setScPatternAttr(pDefaultColAttrArray->mvData[nIdx].getScPatternAttr()); bool bNumFormatChanged = false; if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged, - mvData[nIdx].pPattern->GetItemSet(), rDocument.GetDefPattern()->GetItemSet() ) ) + mvData[nIdx].getScPatternAttr()->GetItemSet(), + rDocument.getCellAttributeHelper().getDefaultCellAttribute().GetItemSet() ) ) { aAdrStart.SetRow( nIdx ? mvData[nIdx-1].nEndRow+1 : 0 ); aAdrEnd.SetRow( mvData[nIdx].nEndRow ); @@ -80,10 +80,6 @@ ScAttrArray::~ScAttrArray() #if DEBUG_SC_TESTATTRARRAY TestData(); #endif - - ScDocumentPool* pDocPool = rDocument.GetPool(); - for (auto const & rEntry : mvData) - pDocPool->DirectRemoveItemFromPool(*rEntry.pPattern); } #if DEBUG_SC_TESTATTRARRAY @@ -97,8 +93,6 @@ void ScAttrArray::TestData() const if (nPos > 0) if (mvData[nPos].pPattern == mvData[nPos-1].pPattern || mvData[nPos].nRow <= mvData[nPos-1].nRow) ++nErr; - if (mvData[nPos].pPattern->Which() != ATTR_PATTERN) - ++nErr; } if ( nPos && mvData[nPos-1].nRow != rDocument.MaxRow() ) ++nErr; @@ -116,19 +110,22 @@ void ScAttrArray::SetDefaultIfNotInit( SCSIZE nNeeded ) mvData.reserve( nNewLimit ); mvData.emplace_back(); mvData[0].nEndRow = rDocument.MaxRow(); - mvData[0].pPattern = rDocument.GetDefPattern(); // no put + mvData[0].setScPatternAttr(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); // no put } -void ScAttrArray::Reset( const ScPatternAttr* pPattern ) +void ScAttrArray::Reset(const CellAttributeHolder& rPattern) { - ScDocumentPool* pDocPool = rDocument.GetPool(); + const ScPatternAttr* pPattern(rPattern.getScPatternAttr()); + if (nullptr == pPattern) + return; + ScAddress aAdrStart( nCol, 0, nTab ); ScAddress aAdrEnd ( nCol, 0, nTab ); for (SCSIZE i=0; i<mvData.size(); i++) { // ensure that attributing changes text width of cell - const ScPatternAttr* pOldPattern = mvData[i].pPattern; + const ScPatternAttr* pOldPattern(mvData[i].getScPatternAttr()); if ( nCol != -1 ) { bool bNumFormatChanged; @@ -140,16 +137,14 @@ void ScAttrArray::Reset( const ScPatternAttr* pPattern ) rDocument.InvalidateTextWidth( &aAdrStart, &aAdrEnd, bNumFormatChanged ); } } - pDocPool->DirectRemoveItemFromPool(*pOldPattern); } mvData.resize(0); rDocument.SetStreamValid(nTab, false); mvData.resize(1); - const ScPatternAttr* pNewPattern = &pDocPool->DirectPutItemInPool(*pPattern); mvData[0].nEndRow = rDocument.MaxRow(); - mvData[0].pPattern = pNewPattern; + mvData[0].setScPatternAttr(pPattern); } bool ScAttrArray::Concat(SCSIZE nPos) @@ -159,10 +154,9 @@ bool ScAttrArray::Concat(SCSIZE nPos) { if (nPos > 0) { - if (SfxPoolItem::areSame(mvData[nPos - 1].pPattern, mvData[nPos].pPattern)) + if (ScPatternAttr::areSame(mvData[nPos - 1].getScPatternAttr(), mvData[nPos].getScPatternAttr())) { mvData[nPos - 1].nEndRow = mvData[nPos].nEndRow; - rDocument.GetPool()->DirectRemoveItemFromPool(*mvData[nPos].pPattern); mvData.erase(mvData.begin() + nPos); nPos--; bRet = true; @@ -170,10 +164,9 @@ bool ScAttrArray::Concat(SCSIZE nPos) } if (nPos + 1 < mvData.size()) { - if (SfxPoolItem::areSame(mvData[nPos + 1].pPattern, mvData[nPos].pPattern)) + if (ScPatternAttr::areSame(mvData[nPos + 1].getScPatternAttr(), mvData[nPos].getScPatternAttr())) { mvData[nPos].nEndRow = mvData[nPos + 1].nEndRow; - rDocument.GetPool()->DirectRemoveItemFromPool(*mvData[nPos].pPattern); mvData.erase(mvData.begin() + nPos + 1); bRet = true; } @@ -246,11 +239,11 @@ const ScPatternAttr* ScAttrArray::GetPattern( SCROW nRow ) const { if ( !rDocument.ValidRow(nRow) ) return nullptr; - return rDocument.GetDefPattern(); + return &rDocument.getCellAttributeHelper().getDefaultCellAttribute(); } SCSIZE i; if (Search( nRow, i )) - return mvData[i].pPattern; + return mvData[i].getScPatternAttr(); else return nullptr; } @@ -264,7 +257,7 @@ const ScPatternAttr* ScAttrArray::GetPatternRange( SCROW& rStartRow, return nullptr; rStartRow = 0; rEndRow = rDocument.MaxRow(); - return rDocument.GetDefPattern(); + return &rDocument.getCellAttributeHelper().getDefaultCellAttribute(); } SCSIZE nIndex; if ( Search( nRow, nIndex ) ) @@ -274,7 +267,7 @@ const ScPatternAttr* ScAttrArray::GetPatternRange( SCROW& rStartRow, else rStartRow = 0; rEndRow = mvData[nIndex].nEndRow; - return mvData[nIndex].pPattern; + return mvData[nIndex].getScPatternAttr(); } return nullptr; } @@ -296,7 +289,7 @@ void ScAttrArray::AddCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nInd // changed to create pNewPattern only if needed, else use already // existing pPattern. This shows by example how to avoid that special - // handling of ATTR_PATTERN/ScPatternAttr in SC and massive + // handling of ScPatternAttr in SC and massive // incarnations/destructions of that Item (which contains an ItemSet) std::unique_ptr<ScPatternAttr> pNewPattern; if(pPattern) @@ -329,16 +322,16 @@ void ScAttrArray::AddCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 nInd } else { - pNewPattern.reset( new ScPatternAttr( rDocument.GetPool() ) ); + pNewPattern.reset( new ScPatternAttr( rDocument.getCellAttributeHelper() ) ); ScCondFormatItem aItem(nIndex); pNewPattern->GetItemSet().Put( aItem ); nTempEndRow = nEndRow; } if (pNewPattern) - SetPatternArea( nTempStartRow, nTempEndRow, std::move(pNewPattern), true ); + SetPatternArea( nTempStartRow, nTempEndRow, CellAttributeHolder(pNewPattern.release(), true) ); else - SetPatternArea( nTempStartRow, nTempEndRow, pPattern, true ); + SetPatternArea( nTempStartRow, nTempEndRow, CellAttributeHolder(pPattern) ); nTempStartRow = nTempEndRow + 1; } @@ -370,12 +363,12 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 n nTempEndRow = std::min<SCROW>( nPatternEndRow, nEndRow ); if (const ScCondFormatItem* pItem = pPattern->GetItemSet().GetItemIfSet( ATTR_CONDITIONAL )) { - auto pPatternAttr = std::make_unique<ScPatternAttr>( *pPattern ); if (nIndex == 0) { ScCondFormatItem aItem; - pPatternAttr->GetItemSet().Put( aItem ); - SetPatternArea( nTempStartRow, nTempEndRow, std::move(pPatternAttr), true ); + ScPatternAttr* pTemp(new ScPatternAttr(*pPattern)); + pTemp->GetItemSet().Put( aItem ); + SetPatternArea( nTempStartRow, nTempEndRow, CellAttributeHolder(pTemp, true) ); } else { @@ -386,8 +379,9 @@ void ScAttrArray::RemoveCondFormat( SCROW nStartRow, SCROW nEndRow, sal_uInt32 n ScCondFormatIndexes aNewCondFormatData(rCondFormatData); aNewCondFormatData.erase_at(std::distance(rCondFormatData.begin(), itr)); ScCondFormatItem aItem( std::move(aNewCondFormatData) ); - pPatternAttr->GetItemSet().Put( aItem ); - SetPatternArea( nTempStartRow, nTempEndRow, std::move(pPatternAttr), true ); + ScPatternAttr* pTemp(new ScPatternAttr(*pPattern)); + pTemp->GetItemSet().Put( aItem ); + SetPatternArea( nTempStartRow, nTempEndRow, CellAttributeHolder(pTemp, true) ); } } } @@ -441,7 +435,7 @@ bool ScAttrArray::Reserve( SCSIZE nReserve ) mvData.reserve(nReserve); mvData.emplace_back(); mvData[0].nEndRow = rDocument.MaxRow(); - mvData[0].pPattern = rDocument.GetDefPattern(); // no put + mvData[0].setScPatternAttr(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); // no put return true; } catch (std::bad_alloc const &) { return false; @@ -460,20 +454,17 @@ bool ScAttrArray::Reserve( SCSIZE nReserve ) return false; } -const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEndRow, const ScPatternAttr* pPattern, - bool bPutToPool, ScEditDataArray* pDataArray, bool bPassingOwnership ) +const ScPatternAttr* ScAttrArray::SetPatternAreaImpl( + SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& rPattern, ScEditDataArray* pDataArray) { + const ScPatternAttr* pPattern(rPattern.getScPatternAttr()); + if (nullptr == pPattern) + return nullptr; + if (rDocument.ValidRow(nStartRow) && rDocument.ValidRow(nEndRow)) { - if (bPutToPool) - { - if (bPassingOwnership) - pPattern = &rDocument.GetPool()->DirectPutItemInPool(std::unique_ptr<ScPatternAttr>(const_cast<ScPatternAttr*>(pPattern))); - else - pPattern = &rDocument.GetPool()->DirectPutItemInPool(*pPattern); - } if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow())) - Reset(pPattern); + Reset(rPattern); else { SCSIZE nNeeded = mvData.size() + 2; @@ -507,7 +498,7 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd if ( nCol != -1 && !bIsLoading ) { const SfxItemSet& rNewSet = pPattern->GetItemSet(); - const SfxItemSet& rOldSet = mvData[nx].pPattern->GetItemSet(); + const SfxItemSet& rOldSet = mvData[nx].getScPatternAttr()->GetItemSet(); bool bNumFormatChanged; if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged, rNewSet, rOldSet ) ) @@ -529,7 +520,7 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd if ( nStartRow > 0 ) { nInsert = rDocument.MaxRow() + 1; - if ( !SfxPoolItem::areSame(mvData[ni].pPattern, pPattern ) ) + if ( !ScPatternAttr::areSame(mvData[ni].getScPatternAttr(), pPattern ) ) { if ( ni == 0 || (mvData[ni-1].nEndRow < nStartRow - 1) ) { // may be a split or a simple insert or just a shrink, @@ -542,7 +533,7 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd else if (mvData[ni - 1].nEndRow == nStartRow - 1) nInsert = ni; } - if ( ni > 0 && SfxPoolItem::areSame(mvData[ni-1].pPattern, pPattern) ) + if ( ni > 0 && ScPatternAttr::areSame(mvData[ni-1].getScPatternAttr(), pPattern) ) { // combine mvData[ni-1].nEndRow = nEndRow; nInsert = rDocument.MaxRow() + 1; @@ -557,11 +548,11 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd nj++; if ( !bSplit ) { - if ( nj < mvData.size() && SfxPoolItem::areSame(mvData[nj].pPattern, pPattern ) ) + if ( nj < mvData.size() && ScPatternAttr::areSame(mvData[nj].getScPatternAttr(), pPattern ) ) { // combine if ( ni > 0 ) { - if ( SfxPoolItem::areSame(mvData[ni-1].pPattern, pPattern ) ) + if ( ScPatternAttr::areSame(mvData[ni-1].getScPatternAttr(), pPattern ) ) { // adjacent entries mvData[ni-1].nEndRow = mvData[nj].nEndRow; nj++; @@ -575,21 +566,12 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd else if ( ni > 0 && ni == nInsert ) mvData[ni-1].nEndRow = nStartRow - 1; // shrink } - ScDocumentPool* pDocPool = rDocument.GetPool(); - if ( bSplit ) - { // duplicate split entry in pool - pDocPool->DirectPutItemInPool( *mvData[ni-1].pPattern ); - } if ( ni < nj ) { // remove middle entries - for ( SCSIZE nk=ni; nk<nj; nk++) - { // remove entries from pool - pDocPool->DirectRemoveItemFromPool( *mvData[nk].pPattern ); - } if ( !bCombined ) { // replace one entry mvData[ni].nEndRow = nEndRow; - mvData[ni].pPattern = pPattern; + mvData[ni].setScPatternAttr(pPattern); ni++; nInsert = rDocument.MaxRow() + 1; } @@ -614,7 +596,7 @@ const ScPatternAttr* ScAttrArray::SetPatternAreaImpl(SCROW nStartRow, SCROW nEnd if ( nInsert ) mvData[nInsert-1].nEndRow = nStartRow - 1; mvData[nInsert].nEndRow = nEndRow; - mvData[nInsert].pPattern = pPattern; + mvData[nInsert].setScPatternAttr(pPattern); // Remove character attributes from these cells if the pattern // is applied during normal session. @@ -651,7 +633,7 @@ void ScAttrArray::ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleS do { - const ScPatternAttr* pOldPattern = mvData[nPos].pPattern; + const ScPatternAttr* pOldPattern = mvData[nPos].getScPatternAttr(); std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr(*pOldPattern)); pNewPattern->SetStyleSheet(const_cast<ScStyleSheet*>(&rStyle)); SCROW nY1 = nStart; @@ -668,7 +650,7 @@ void ScAttrArray::ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleS { if (nY1 < nStartRow) nY1=nStartRow; if (nY2 > nEndRow) nY2=nEndRow; - SetPatternArea( nY1, nY2, std::move(pNewPattern), true ); + SetPatternArea( nY1, nY2, CellAttributeHolder(pNewPattern.release(), true) ); Search( nStart, nPos ); } else @@ -690,8 +672,7 @@ void ScAttrArray::ApplyStyleArea( SCROW nStartRow, SCROW nEndRow, const ScStyleS } } - rDocument.GetPool()->DirectRemoveItemFromPool(*mvData[nPos].pPattern); - mvData[nPos].pPattern = &rDocument.GetPool()->DirectPutItemInPool(*pNewPattern); + mvData[nPos].setScPatternAttr(pNewPattern.release(), true); if (Concat(nPos)) Search(nStart, nPos); else @@ -746,7 +727,7 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow, do { - const ScPatternAttr* pOldPattern = mvData[nPos].pPattern; + const ScPatternAttr* pOldPattern = mvData[nPos].getScPatternAttr(); const SfxItemSet& rOldSet = pOldPattern->GetItemSet(); const SvxBoxItem* pBoxItem = rOldSet.GetItemIfSet( ATTR_BORDER ); const SvxLineItem* pTLBRItem = rOldSet.GetItemIfSet( ATTR_BORDER_TLBR ); @@ -821,15 +802,13 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow, { if (nY1 < nStartRow) nY1=nStartRow; if (nY2 > nEndRow) nY2=nEndRow; - SetPatternArea( nY1, nY2, std::move(pNewPattern), true ); + SetPatternArea( nY1, nY2, CellAttributeHolder(pNewPattern.release(), true) ); Search( nStart, nPos ); } else { // remove from pool ? - rDocument.GetPool()->DirectRemoveItemFromPool(*mvData[nPos].pPattern); - mvData[nPos].pPattern = - &rDocument.GetPool()->DirectPutItemInPool(std::move(pNewPattern)); + mvData[nPos].setScPatternAttr(pNewPattern.release(), true); if (Concat(nPos)) Search(nStart, nPos); @@ -846,7 +825,7 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow, while ((nStart <= nEndRow) && (nPos < mvData.size())); } -void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCache* pCache, ScEditDataArray* pDataArray, bool* const pIsChanged ) +void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCache& rCache, ScEditDataArray* pDataArray, bool* const pIsChanged ) { #if DEBUG_SC_TESTATTRARRAY TestData(); @@ -869,9 +848,10 @@ void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCach do { - const ScPatternAttr& rOldPattern = *mvData[nPos].pPattern; - const ScPatternAttr& rNewPattern = pCache->ApplyTo( rOldPattern ); - if (!SfxPoolItem::areSame(rNewPattern, rOldPattern)) + const CellAttributeHolder& rOldPattern(mvData[nPos].getCellAttributeHolder()); + const CellAttributeHolder& rNewPattern(rCache.ApplyTo( rOldPattern )); + + if (!CellAttributeHolder::areSame(&rNewPattern, &rOldPattern)) { SCROW nY1 = nStart; SCROW nY2 = mvData[nPos].nEndRow; @@ -884,7 +864,7 @@ void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCach { if (nY1 < nStartRow) nY1=nStartRow; if (nY2 > nEndRow) nY2=nEndRow; - SetPatternArea( nY1, nY2, &rNewPattern, false, pDataArray ); + SetPatternArea( nY1, nY2, rNewPattern, pDataArray ); Search( nStart, nPos ); } else @@ -893,8 +873,8 @@ void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCach { // ensure attributing changes text-width of cell - const SfxItemSet& rNewSet = rNewPattern.GetItemSet(); - const SfxItemSet& rOldSet = rOldPattern.GetItemSet(); + const SfxItemSet& rNewSet = rNewPattern.getScPatternAttr()->GetItemSet(); + const SfxItemSet& rOldSet = rOldPattern.getScPatternAttr()->GetItemSet(); bool bNumFormatChanged; if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged, @@ -906,8 +886,7 @@ void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCach } } - rDocument.GetPool()->DirectRemoveItemFromPool(*mvData[nPos].pPattern); - mvData[nPos].pPattern = &rNewPattern; + mvData[nPos].setCellAttributeHolder(rNewPattern); if (Concat(nPos)) Search(nStart, nPos); else @@ -931,10 +910,6 @@ void ScAttrArray::ApplyCacheArea( SCROW nStartRow, SCROW nEndRow, ScItemPoolCach void ScAttrArray::SetAttrEntries(std::vector<ScAttrEntry> && vNewData) { - ScDocumentPool* pDocPool = rDocument.GetPool(); - for (auto const & rEntry : mvData) - pDocPool->DirectRemoveItemFromPool(*rEntry.pPattern); - mvData = std::move(vNewData); #ifdef DBG_UTIL @@ -1000,12 +975,12 @@ void ScAttrArray::MergePatternArea( SCROW nStartRow, SCROW nEndRow, do { // similar patterns must not be repeated - const ScPatternAttr* pPattern = nullptr; + const ScPatternAttr* pPattern(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); if ( !mvData.empty() ) - pPattern = mvData[nPos].pPattern; - else - pPattern = rDocument.GetDefPattern(); - if ( !SfxPoolItem::areSame(pPattern, rState.pOld1) && !SfxPoolItem::areSame(pPattern, rState.pOld2) ) + pPattern = mvData[nPos].getScPatternAttr(); + + if ( !ScPatternAttr::areSame(pPattern, rState.aOld1.getScPatternAttr()) + && !ScPatternAttr::areSame(pPattern, rState.aOld2.getScPatternAttr()) ) { const SfxItemSet& rThisSet = pPattern->GetItemSet(); if (rState.pItemSet) @@ -1024,8 +999,8 @@ void ScAttrArray::MergePatternArea( SCROW nStartRow, SCROW nEndRow, rState.mnPatternId = pPattern->GetPAKey(); } - rState.pOld2 = rState.pOld1; - rState.pOld1 = pPattern; + rState.aOld2 = rState.aOld1; + rState.aOld1 = pPattern; } if ( !mvData.empty() ) @@ -1156,7 +1131,7 @@ void ScAttrArray::MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLine Search( nEndRow-1, nEndIndex ); for (SCSIZE i=nStartIndex; i<=nEndIndex; i++) { - pPattern = mvData[i].pPattern; + pPattern = mvData[i].getScPatternAttr(); lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, pPattern, bLeft, nDistRight, false, nEndRow - std::min( mvData[i].nEndRow, static_cast<SCROW>(nEndRow-1) ) ); // nDistBottom here always > 0 @@ -1167,7 +1142,7 @@ void ScAttrArray::MergeBlockFrame( SvxBoxItem* pLineOuter, SvxBoxInfoItem* pLine } else { - lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, rDocument.GetDefPattern(), bLeft, nDistRight, true, 0 ); + lcl_MergeToFrame( pLineOuter, pLineInner, rFlags, &rDocument.getCellAttributeHelper().getDefaultCellAttribute(), bLeft, nDistRight, true, 0 ); } } @@ -1237,8 +1212,8 @@ bool ScAttrArray::ApplyFrame( const SvxBoxItem& rBoxItem, } else { - ScItemPoolCache aCache( rDocument.GetPool(), &aNewFrame ); - ApplyCacheArea( nStartRow, nEndRow, &aCache ); + ScItemPoolCache aCache( rDocument.getCellAttributeHelper(), aNewFrame ); + ApplyCacheArea( nStartRow, nEndRow, aCache ); return true; } @@ -1410,7 +1385,7 @@ bool ScAttrArray::HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) cons { if (mvData.empty()) { - return HasAttrib_Impl(rDocument.GetDefPattern(), nMask, 0, rDocument.MaxRow(), 0); + return HasAttrib_Impl(&rDocument.getCellAttributeHelper().getDefaultCellAttribute(), nMask, 0, rDocument.MaxRow(), 0); } SCSIZE nStartIndex; @@ -1424,7 +1399,7 @@ bool ScAttrArray::HasAttrib( SCROW nRow1, SCROW nRow2, HasAttrFlags nMask ) cons for (SCSIZE i=nStartIndex; i<=nEndIndex && !bFound; i++) { - const ScPatternAttr* pPattern = mvData[i].pPattern; + const ScPatternAttr* pPattern = mvData[i].getScPatternAttr(); bFound = HasAttrib_Impl(pPattern, nMask, nRow1, nRow2, i); } @@ -1439,7 +1414,7 @@ bool ScAttrArray::HasAttrib( SCROW nRow, HasAttrFlags nMask, SCROW* nStartRow, S *nStartRow = 0; if( nEndRow ) *nEndRow = rDocument.MaxRow(); - return HasAttrib_Impl(rDocument.GetDefPattern(), nMask, 0, rDocument.MaxRow(), 0); + return HasAttrib_Impl(&rDocument.getCellAttributeHelper().getDefaultCellAttribute(), nMask, 0, rDocument.MaxRow(), 0); } SCSIZE nIndex; @@ -1448,7 +1423,7 @@ bool ScAttrArray::HasAttrib( SCROW nRow, HasAttrFlags nMask, SCROW* nStartRow, S *nStartRow = nIndex > 0 ? mvData[nIndex-1].nEndRow+1 : 0; if( nEndRow ) *nEndRow = mvData[nIndex].nEndRow; - const ScPatternAttr* pPattern = mvData[nIndex].pPattern; + const ScPatternAttr* pPattern = mvData[nIndex].getScPatternAttr(); return HasAttrib_Impl(pPattern, nMask, nRow, nRow, nIndex); } @@ -1458,12 +1433,12 @@ bool ScAttrArray::IsMerged( SCROW nRow ) const { SCSIZE nIndex; Search(nRow, nIndex); - const ScMergeAttr& rItem = mvData[nIndex].pPattern->GetItem(ATTR_MERGE); + const ScMergeAttr& rItem = mvData[nIndex].getScPatternAttr()->GetItem(ATTR_MERGE); return rItem.IsMerged(); } - return rDocument.GetDefPattern()->GetItem(ATTR_MERGE).IsMerged(); + return rDocument.getCellAttributeHelper().getDefaultCellAttribute().GetItem(ATTR_MERGE).IsMerged(); } /** @@ -1485,7 +1460,7 @@ bool ScAttrArray::ExtendMerge( SCCOL nThisCol, SCROW nStartRow, SCROW nEndRow, for (SCSIZE i=nStartIndex; i<=nEndIndex; i++) { - pPattern = mvData[i].pPattern; + pPattern = mvData[i].getScPatternAttr(); pItem = &pPattern->GetItem( ATTR_MERGE ); SCCOL nCountX = pItem->GetColMerge(); SCROW nCountY = pItem->GetRowMerge(); @@ -1541,7 +1516,7 @@ void ScAttrArray::RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow) if (nThisEnd > nEndRow) nThisEnd = nEndRow; - pPattern = mvData[nIndex].pPattern; + pPattern = mvData[nIndex].getScPatternAttr(); pItem = &pPattern->GetItem( ATTR_MERGE ); SCCOL nCountX = pItem->GetColMerge(); SCROW nCountY = pItem->GetRowMerge(); @@ -1560,7 +1535,7 @@ void ScAttrArray::RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow) for (SCROW nThisRow = nThisStart; nThisRow <= nThisEnd; nThisRow++) rDocument.ApplyAttr( nThisCol, nThisRow, nTab, *pAttr ); - ScPatternAttr aNewPattern( rDocument.GetPool() ); + ScPatternAttr aNewPattern( rDocument.getCellAttributeHelper() ); SfxItemSet* pSet = &aNewPattern.GetItemSet(); pSet->Put( *pFlagAttr ); rDocument.ApplyPatternAreaTab( nThisCol, nThisStart, nMergeEndCol, nMergeEndRow, @@ -1577,51 +1552,40 @@ void ScAttrArray::RemoveAreaMerge(SCROW nStartRow, SCROW nEndRow) } } -void ScAttrArray::SetPatternAreaSafe( SCROW nStartRow, SCROW nEndRow, - const ScPatternAttr* pWantedPattern, bool bDefault ) +void ScAttrArray::SetPatternAreaSafe(SCROW nStartRow, SCROW nEndRow, const CellAttributeHolder& rWantedPattern) { SetDefaultIfNotInit(); - const ScPatternAttr* pOldPattern; - const ScMergeFlagAttr* pItem; + const ScMergeFlagAttr* pItem; SCSIZE nIndex; SCROW nRow; SCROW nThisRow; - bool bFirstUse = true; Search( nStartRow, nIndex ); nThisRow = (nIndex>0) ? mvData[nIndex-1].nEndRow+1 : 0; while ( nThisRow <= nEndRow ) { - pOldPattern = mvData[nIndex].pPattern; - if (!SfxPoolItem::areSame(pOldPattern, pWantedPattern)) // FIXME: else-branch? + const CellAttributeHolder& rOldPattern(mvData[nIndex].getCellAttributeHolder()); + if (!CellAttributeHolder::areSame(&rOldPattern, &rWantedPattern)) // FIXME: else-branch? { if (nThisRow < nStartRow) nThisRow = nStartRow; nRow = mvData[nIndex].nEndRow; SCROW nAttrRow = std::min( nRow, nEndRow ); - pItem = &pOldPattern->GetItem( ATTR_MERGE_FLAG ); + pItem = &rOldPattern.getScPatternAttr()->GetItem( ATTR_MERGE_FLAG ); if (pItem->IsOverlapped() || pItem->HasAutoFilter()) { // default-constructing a ScPatternAttr for DeleteArea doesn't work // because it would have no cell style information. - // Instead, the document's GetDefPattern is copied. Since it is passed as + // Instead, the document's getCellAttributeHelper().getDefaultCellAttribute() is copied. Since it is passed as // pWantedPattern, no special treatment of default is needed here anymore. - std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr( *pWantedPattern )); + ScPatternAttr* pNewPattern(new ScPatternAttr(*rWantedPattern.getScPatternAttr())); pNewPattern->GetItemSet().Put( *pItem ); - SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true ); + SetPatternArea( nThisRow, nAttrRow, CellAttributeHolder(pNewPattern, true) ); } else { - if ( !bDefault ) - { - if (bFirstUse) - bFirstUse = false; - else - // it's in the pool - rDocument.GetPool()->DirectPutItemInPool( *pWantedPattern ); - } - SetPatternArea( nThisRow, nAttrRow, pWantedPattern ); + SetPatternArea(nThisRow, nAttrRow, rWantedPattern); } Search( nThisRow, nIndex ); // data changed @@ -1649,15 +1613,15 @@ bool ScAttrArray::ApplyFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags ) while ( nThisRow <= nEndRow ) { - pOldPattern = mvData[nIndex].pPattern; + pOldPattern = mvData[nIndex].getScPatternAttr(); nOldValue = pOldPattern->GetItem( ATTR_MERGE_FLAG ).GetValue(); if ( (nOldValue | nFlags) != nOldValue ) { nRow = mvData[nIndex].nEndRow; SCROW nAttrRow = std::min( nRow, nEndRow ); - auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern)); pNewPattern->GetItemSet().Put( ScMergeFlagAttr( nOldValue | nFlags ) ); - SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true ); + SetPatternArea( nThisRow, nAttrRow, CellAttributeHolder(pNewPattern, true) ); Search( nThisRow, nIndex ); // data changed bChanged = true; } @@ -1686,15 +1650,15 @@ bool ScAttrArray::RemoveFlags( SCROW nStartRow, SCROW nEndRow, ScMF nFlags ) while ( nThisRow <= nEndRow ) { - pOldPattern = mvData[nIndex].pPattern; + pOldPattern = mvData[nIndex].getScPatternAttr(); nOldValue = pOldPattern->GetItem( ATTR_MERGE_FLAG ).GetValue(); if ( (nOldValue & ~nFlags) != nOldValue ) { nRow = mvData[nIndex].nEndRow; SCROW nAttrRow = std::min( nRow, nEndRow ); - auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern)); pNewPattern->GetItemSet().Put( ScMergeFlagAttr( nOldValue & ~nFlags ) ); - SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true ); + SetPatternArea( nThisRow, nAttrRow, CellAttributeHolder(pNewPattern, true) ); Search( nThisRow, nIndex ); // data changed bChanged = true; } @@ -1719,15 +1683,15 @@ void ScAttrArray::ClearItems( SCROW nStartRow, SCROW nEndRow, const sal_uInt16* while ( nThisRow <= nEndRow ) { - const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern; + const ScPatternAttr* pOldPattern = mvData[nIndex].getScPatternAttr(); if ( pOldPattern->HasItemsSet( pWhich ) ) { - auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern)); pNewPattern->ClearItems( pWhich ); nRow = mvData[nIndex].nEndRow; SCROW nAttrRow = std::min( nRow, nEndRow ); - SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true ); + SetPatternArea( nThisRow, nAttrRow, CellAttributeHolder(pNewPattern, true) ); Search( nThisRow, nIndex ); // data changed } @@ -1746,7 +1710,7 @@ void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement while ( nThisStart <= nEndRow ) { - const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern; + const ScPatternAttr* pOldPattern = mvData[nIndex].getScPatternAttr(); const SfxItemSet& rOldSet = pOldPattern->GetItemSet(); const SvxHorJustifyItem* pItem; @@ -1782,12 +1746,12 @@ void ScAttrArray::ChangeIndent( SCROW nStartRow, SCROW nEndRow, bool bIncrement { SCROW nThisEnd = mvData[nIndex].nEndRow; SCROW nAttrRow = std::min( nThisEnd, nEndRow ); - auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern)); pNewPattern->GetItemSet().Put( ScIndentItem( nNewValue ) ); if ( bNeedJust ) pNewPattern->GetItemSet().Put( SvxHorJustifyItem( SvxCellHorJustify::Left, ATTR_HOR_JUSTIFY ) ); - SetPatternArea( nThisStart, nAttrRow, std::move(pNewPattern), true ); + SetPatternArea( nThisStart, nAttrRow, CellAttributeHolder(pNewPattern, true) ); nThisStart = nThisEnd + 1; Search( nThisStart, nIndex ); // data changed @@ -1815,8 +1779,7 @@ SCROW ScAttrArray::GetNextUnprotected( SCROW nRow, bool bUp ) const SCSIZE nIndex; Search(nRow, nIndex); - while (mvData[nIndex].pPattern-> - GetItem(ATTR_PROTECTION).GetProtection()) + while (mvData[nIndex].getScPatternAttr()->GetItem(ATTR_PROTECTION).GetProtection()) { if (bUp) { @@ -1845,20 +1808,19 @@ void ScAttrArray::FindStyleSheet( const SfxStyleSheetBase* pStyleSheet, ScFlatBo while (nPos < mvData.size()) { SCROW nEnd = mvData[nPos].nEndRow; - if (mvData[nPos].pPattern->GetStyleSheet() == pStyleSheet) + if (mvData[nPos].getScPatternAttr()->GetStyleSheet() == pStyleSheet) { rUsedRows.setTrue(nStart, nEnd); if (bReset) { - ScPatternAttr aNewPattern(*mvData[nPos].pPattern); - rDocument.GetPool()->DirectRemoveItemFromPool(*mvData[nPos].pPattern); - aNewPattern.SetStyleSheet( static_cast<ScStyleSheet*>( + ScPatternAttr* pNewPattern(new ScPatternAttr(*mvData[nPos].getScPatternAttr())); + pNewPattern->SetStyleSheet( static_cast<ScStyleSheet*>( rDocument.GetStyleSheetPool()-> Find( ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Para, SfxStyleSearchBits::Auto | SfxStyleSearchBits::ScStandard ) ) ); - mvData[nPos].pPattern = &rDocument.GetPool()->DirectPutItemInPool(aNewPattern); + mvData[nPos].setScPatternAttr(pNewPattern, true); if (Concat(nPos)) { @@ -1876,7 +1838,7 @@ bool ScAttrArray::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const { if ( mvData.empty() ) { - const ScStyleSheet* pStyle = rDocument.GetDefPattern()->GetStyleSheet(); + const ScStyleSheet* pStyle = rDocument.getCellAttributeHelper().getDefaultCellAttribute().GetStyleSheet(); if ( pStyle ) { pStyle->SetUsage( ScStyleSheet::Usage::USED ); @@ -1891,7 +1853,7 @@ bool ScAttrArray::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const while ( nPos < mvData.size() ) { - const ScStyleSheet* pStyle = mvData[nPos].pPattern->GetStyleSheet(); + const ScStyleSheet* pStyle = mvData[nPos].getScPatternAttr()->GetStyleSheet(); if ( pStyle ) { pStyle->SetUsage( ScStyleSheet::Usage::USED ); @@ -1913,7 +1875,7 @@ bool ScAttrArray::IsEmpty() const if (mvData.size() == 1) { - return SfxPoolItem::areSame(mvData[0].pPattern, rDocument.GetDefPattern()); + return mvData[0].getScPatternAttr()->isDefault(); } else return false; @@ -1931,14 +1893,14 @@ bool ScAttrArray::GetFirstVisibleAttr( SCROW& rFirstRow ) const // Entries at the end are not skipped, GetFirstVisibleAttr may be larger than GetLastVisibleAttr. SCSIZE nVisStart = 1; - while ( nVisStart < mvData.size() && mvData[nVisStart].pPattern->IsVisibleEqual(*mvData[nVisStart-1].pPattern) ) + while ( nVisStart < mvData.size() && mvData[nVisStart].getScPatternAttr()->IsVisibleEqual(*mvData[nVisStart-1].getScPatternAttr()) ) ++nVisStart; if ( nVisStart >= mvData.size() || mvData[nVisStart-1].nEndRow > 0 ) // more than 1 row? nStart = nVisStart; while ( nStart < mvData.size() && !bFound ) { - if ( mvData[nStart].pPattern->IsVisible() ) + if ( mvData[nStart].getScPatternAttr()->IsVisible() ) { rFirstRow = nStart ? ( mvData[nStart-1].nEndRow + 1 ) : 0; bFound = true; @@ -1995,7 +1957,7 @@ bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData, bool bSk // find range of visually equal formats SCSIZE nEndPos = nPos; while ( nEndPos < mvData.size()-1 && - mvData[nEndPos].pPattern->IsVisibleEqual(*mvData[nEndPos+1].pPattern)) + mvData[nEndPos].getScPatternAttr()->IsVisibleEqual(*mvData[nEndPos+1].getScPatternAttr())) ++nEndPos; SCROW nAttrStartRow = ( nPos > 0 ) ? ( mvData[nPos-1].nEndRow + 1) : 0; if ( nAttrStartRow <= nLastData ) @@ -2003,7 +1965,7 @@ bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData, bool bSk SCROW nAttrSize = mvData[nEndPos].nEndRow + 1 - nAttrStartRow; if ( nAttrSize >= SC_VISATTR_STOP ) break; // while, ignore this range and below - else if ( mvData[nEndPos].pPattern->IsVisible() ) + else if ( mvData[nEndPos].getScPatternAttr()->IsVisible() ) { rLastRow = mvData[nEndPos].nEndRow; bFound = true; @@ -2013,8 +1975,8 @@ bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData, bool bSk } else { - if ((nPos > 0 && mvData[nPos-1].pPattern->IsVisible()) - || (nPos > 1 && !mvData[nPos-1].pPattern->IsVisibleEqual(*mvData[nPos-2].pPattern))) + if ((nPos > 0 && mvData[nPos-1].getScPatternAttr()->IsVisible()) + || (nPos > 1 && !mvData[nPos-1].getScPatternAttr()->IsVisibleEqual(*mvData[nPos-2].getScPatternAttr()))) { rLastRow = mvData[nPos-1].nEndRow; return true; @@ -2027,7 +1989,7 @@ bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData, bool bSk bool ScAttrArray::HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const { if ( mvData.empty() ) - return rDocument.GetDefPattern()->IsVisible(); + return rDocument.getCellAttributeHelper().getDefaultCellAttribute().IsVisible(); SCSIZE nIndex; Search( nStartRow, nIndex ); @@ -2035,7 +1997,7 @@ bool ScAttrArray::HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const bool bFound = false; while ( nIndex < mvData.size() && nThisStart <= nEndRow && !bFound ) { - if ( mvData[nIndex].pPattern->IsVisible() ) + if ( mvData[nIndex].getScPatternAttr()->IsVisible() ) bFound = true; nThisStart = mvData[nIndex].nEndRow + 1; @@ -2050,9 +2012,9 @@ bool ScAttrArray::IsVisibleEqual( const ScAttrArray& rOther, { if ( mvData.empty() && rOther.mvData.empty() ) { - const ScPatternAttr* pDefPattern1 = rDocument.GetDefPattern(); - const ScPatternAttr* pDefPattern2 = rOther.rDocument.GetDefPattern(); - return ( SfxPoolItem::areSame(pDefPattern1, pDefPattern2) || pDefPattern1->IsVisibleEqual( *pDefPattern2 ) ); + const ScPatternAttr* pDefPattern1(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); + const ScPatternAttr* pDefPattern2(&rOther.rDocument.getCellAttributeHelper().getDefaultCellAttribute()); + return ( ScPatternAttr::areSame(pDefPattern1, pDefPattern2) || pDefPattern1->IsVisibleEqual( *pDefPattern2 ) ); } { @@ -2062,13 +2024,13 @@ bool ScAttrArray::IsVisibleEqual( const ScAttrArray& rOther, if ( mvData.empty() && !rOther.mvData.empty() ) { pNonDefault = &rOther; - pDefPattern = rDocument.GetDefPattern(); + pDefPattern = &rDocument.getCellAttributeHelper().getDefaultCellAttribute(); bDefNonDefCase = true; } else if ( !mvData.empty() && rOther.mvData.empty() ) { pNonDefault = this; - pDefPattern = rOther.rDocument.GetDefPattern(); + pDefPattern = &rOther.rDocument.getCellAttributeHelper().getDefaultCellAttribute(); bDefNonDefCase = true; } @@ -2081,9 +2043,8 @@ bool ScAttrArray::IsVisibleEqual( const ScAttrArray& rOther, while ( nPos < pNonDefault->Count() && bEqual ) { - const ScPatternAttr* pNonDefPattern = pNonDefault->mvData[nPos].pPattern; - bEqual = ( SfxPoolItem::areSame(pNonDefPattern, pDefPattern) || - pNonDefPattern->IsVisibleEqual( *pDefPattern ) ); + const ScPatternAttr* pNonDefPattern = pNonDefault->mvData[nPos].getScPatternAttr(); + bEqual = ScPatternAttr::areSame(pNonDefPattern, pDefPattern) || pNonDefPattern->IsVisibleEqual( *pDefPattern ); if ( pNonDefault->mvData[nPos].nEndRow >= nEndRow ) break; ++nPos; @@ -2105,10 +2066,9 @@ bool ScAttrArray::IsVisibleEqual( const ScAttrArray& rOther, { SCROW nThisRow = mvData[nThisPos].nEndRow; SCROW nOtherRow = rOther.mvData[nOtherPos].nEndRow; - const ScPatternAttr* pThisPattern = mvData[nThisPos].pPattern; - const ScPatternAttr* pOtherPattern = rOther.mvData[nOtherPos].pPattern; - bEqual = ( SfxPoolItem::areSame(pThisPattern, pOtherPattern) || - pThisPattern->IsVisibleEqual(*pOtherPattern) ); + const ScPatternAttr* pThisPattern = mvData[nThisPos].getScPatternAttr(); + const ScPatternAttr* pOtherPattern = rOther.mvData[nOtherPos].getScPatternAttr(); + bEqual = ( ScPatternAttr::areSame(pThisPattern, pOtherPattern) || pThisPattern->IsVisibleEqual(*pOtherPattern) ); if ( nThisRow >= nOtherRow ) { @@ -2130,9 +2090,9 @@ bool ScAttrArray::IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW // summarised with IsVisibleEqual if ( mvData.empty() && rOther.mvData.empty() ) { - const ScPatternAttr* pDefPattern1 = rDocument.GetDefPattern(); - const ScPatternAttr* pDefPattern2 = rOther.rDocument.GetDefPattern(); - return SfxPoolItem::areSame(pDefPattern1, pDefPattern2); + const ScPatternAttr* pDefPattern1(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); + const ScPatternAttr* pDefPattern2(&rOther.rDocument.getCellAttributeHelper().getDefaultCellAttribute()); + return ScPatternAttr::areSame(pDefPattern1, pDefPattern2); } { @@ -2142,13 +2102,13 @@ bool ScAttrArray::IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW if ( mvData.empty() && !rOther.mvData.empty() ) { pNonDefault = &rOther; - pDefPattern = rDocument.GetDefPattern(); + pDefPattern = &rDocument.getCellAttributeHelper().getDefaultCellAttribute(); bDefNonDefCase = true; } else if ( !mvData.empty() && rOther.mvData.empty() ) { pNonDefault = this; - pDefPattern = rOther.rDocument.GetDefPattern(); + pDefPattern = &rOther.rDocument.getCellAttributeHelper().getDefaultCellAttribute(); bDefNonDefCase = true; } @@ -2161,8 +2121,8 @@ bool ScAttrArray::IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW while ( nPos < pNonDefault->Count() && bEqual ) { - const ScPatternAttr* pNonDefPattern = pNonDefault->mvData[nPos].pPattern; - bEqual = SfxPoolItem::areSame( pNonDefPattern, pDefPattern ); + const ScPatternAttr* pNonDefPattern = pNonDefault->mvData[nPos].getScPatternAttr(); + bEqual = ScPatternAttr::areSame( pNonDefPattern, pDefPattern ); if ( pNonDefault->mvData[nPos].nEndRow >= nEndRow ) break; ++nPos; @@ -2184,9 +2144,9 @@ bool ScAttrArray::IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW { SCROW nThisRow = mvData[nThisPos].nEndRow; SCROW nOtherRow = rOther.mvData[nOtherPos].nEndRow; - const ScPatternAttr* pThisPattern = mvData[nThisPos].pPattern; - const ScPatternAttr* pOtherPattern = rOther.mvData[nOtherPos].pPattern; - bEqual = SfxPoolItem::areSame( pThisPattern, pOtherPattern ); + const ScPatternAttr* pThisPattern = mvData[nThisPos].getScPatternAttr(); + const ScPatternAttr* pOtherPattern = rOther.mvData[nOtherPos].getScPatternAttr(); + bEqual = ScPatternAttr::areSame( pThisPattern, pOtherPattern ); if ( nThisRow >= nOtherRow ) { @@ -2217,8 +2177,7 @@ bool ScAttrArray::TestInsertCol( SCROW nStartRow, SCROW nEndRow) const for ( ; nIndex < mvData.size(); nIndex++ ) { - if ( mvData[nIndex].pPattern-> - GetItem(ATTR_MERGE_FLAG).IsHorOverlapped() ) + if ( mvData[nIndex].getScPatternAttr()->GetItem(ATTR_MERGE_FLAG).IsHorOverlapped() ) { bTest = false; // may not be pushed out break; @@ -2237,15 +2196,13 @@ bool ScAttrArray::TestInsertRow( SCSIZE nSize ) const // rDocument.MaxRow() + 1 - nSize = 1st row pushed out if ( mvData.empty() ) - return !rDocument.GetDefPattern()-> - GetItem(ATTR_MERGE_FLAG).IsVerOverlapped(); + return !rDocument.getCellAttributeHelper().getDefaultCellAttribute().GetItem(ATTR_MERGE_FLAG).IsVerOverlapped(); SCSIZE nFirstLost = mvData.size()-1; while ( nFirstLost && mvData[nFirstLost-1].nEndRow >= sal::static_int_cast<SCROW>(rDocument.MaxRow() + 1 - nSize) ) --nFirstLost; - return !mvData[nFirstLost].pPattern-> - GetItem(ATTR_MERGE_FLAG).IsVerOverlapped(); + return !mvData[nFirstLost].getScPatternAttr()->GetItem(ATTR_MERGE_FLAG).IsVerOverlapped(); } void ScAttrArray::InsertRow( SCROW nStartRow, SCSIZE nSize ) @@ -2258,7 +2215,7 @@ void ScAttrArray::InsertRow( SCROW nStartRow, SCSIZE nSize ) // set ScMergeAttr may not be extended (so behind delete again) - bool bDoMerge = mvData[nIndex].pPattern->GetItem(ATTR_MERGE).IsMerged(); + bool bDoMerge = mvData[nIndex].getScPatternAttr()->GetItem(ATTR_MERGE).IsMerged(); assert( !bDoMerge || nCol != -1 ); @@ -2332,7 +2289,7 @@ void ScAttrArray::DeleteRow( SCROW nStartRow, SCSIZE nSize ) { DeleteRange( nStartIndex, nEndIndex ); if (nStartIndex > 0) - if ( SfxPoolItem::areSame( mvData[nStartIndex-1].pPattern, mvData[nStartIndex].pPattern ) ) + if ( ScPatternAttr::areSame( mvData[nStartIndex-1].getScPatternAttr(), mvData[nStartIndex].getScPatternAttr() ) ) DeleteRange( nStartIndex-1, nStartIndex-1 ); } } @@ -2348,10 +2305,6 @@ void ScAttrArray::DeleteRow( SCROW nStartRow, SCSIZE nSize ) void ScAttrArray::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex ) { SetDefaultIfNotInit(); - ScDocumentPool* pDocPool = rDocument.GetPool(); - for (SCSIZE i = nStartIndex; i <= nEndIndex; i++) - pDocPool->DirectRemoveItemFromPool(*mvData[i].pPattern); - mvData.erase(mvData.begin() + nStartIndex, mvData.begin() + nEndIndex + 1); } @@ -2361,16 +2314,18 @@ void ScAttrArray::DeleteArea(SCROW nStartRow, SCROW nEndRow) if ( nCol != -1 ) RemoveAreaMerge( nStartRow, nEndRow ); // remove from combined flags + const CellAttributeHolder aDefHolder(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); + if ( !HasAttrib( nStartRow, nEndRow, HasAttrFlags::Overlapped | HasAttrFlags::AutoFilter) ) - SetPatternArea( nStartRow, nEndRow, rDocument.GetDefPattern() ); + SetPatternArea( nStartRow, nEndRow, aDefHolder ); else - SetPatternAreaSafe( nStartRow, nEndRow, rDocument.GetDefPattern(), true ); // leave merge flags + SetPatternAreaSafe( nStartRow, nEndRow, aDefHolder ); // leave merge flags } void ScAttrArray::DeleteHardAttr(SCROW nStartRow, SCROW nEndRow) { SetDefaultIfNotInit(); - const ScPatternAttr* pDefPattern = rDocument.GetDefPattern(); + const ScPatternAttr* pDefPattern(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); SCSIZE nIndex; SCROW nRow; @@ -2382,23 +2337,28 @@ void ScAttrArray::DeleteHardAttr(SCROW nStartRow, SCROW nEndRow) while ( nThisRow <= nEndRow ) { - const ScPatternAttr* pOldPattern = mvData[nIndex].pPattern; + const ScPatternAttr* pOldPattern = mvData[nIndex].getScPatternAttr(); if ( pOldPattern->GetItemSet().Count() ) // hard attributes ? { nRow = mvData[nIndex].nEndRow; SCROW nAttrRow = std::min( nRow, nEndRow ); - auto pNewPattern = std::make_unique<ScPatternAttr>(*pOldPattern); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern)); SfxItemSet& rSet = pNewPattern->GetItemSet(); for (sal_uInt16 nId = ATTR_PATTERN_START; nId <= ATTR_PATTERN_END; nId++) if (nId != ATTR_MERGE && nId != ATTR_MERGE_FLAG) rSet.ClearItem(nId); if ( *pNewPattern == *pDefPattern ) + { + delete pNewPattern; SetPatternArea( nThisRow, nAttrRow, pDefPattern ); + } else - SetPatternArea( nThisRow, nAttrRow, std::move(pNewPattern), true ); + { + SetPatternArea( nThisRow, nAttrRow, CellAttributeHolder(pNewPattern, true) ); + } Search( nThisRow, nIndex ); // data changed } @@ -2420,8 +2380,7 @@ void ScAttrArray::MoveTo(SCROW nStartRow, SCROW nEndRow, ScAttrArray& rAttrArray if ((mvData[i].nEndRow >= nStartRow) && (i == 0 || mvData[i-1].nEndRow < nEndRow)) { // copy (bPutToPool=TRUE) - rAttrArray.SetPatternArea( nStart, std::min( mvData[i].nEndRow, nEndRow ), - mvData[i].pPattern, true ); + rAttrArray.SetPatternArea( nStart, std::min( mvData[i].nEndRow, nEndRow ), mvData[i].getCellAttributeHolder() ); } nStart = std::max( nStart, mvData[i].nEndRow + 1 ); } @@ -2439,14 +2398,11 @@ void ScAttrArray::CopyArea( SCROW nDestStart = std::max(static_cast<tools::Long>(static_cast<tools::Long>(nStartRow) + nDy), tools::Long(0)); SCROW nDestEnd = std::min(static_cast<tools::Long>(static_cast<tools::Long>(nEndRow) + nDy), tools::Long(rDocument.MaxRow())); - - ScDocumentPool* pSourceDocPool = rDocument.GetPool(); - ScDocumentPool* pDestDocPool = rAttrArray.rDocument.GetPool(); - bool bSamePool = (pSourceDocPool==pDestDocPool); + const bool bSameCellAttributeHelper(&rDocument.getCellAttributeHelper() == &rAttrArray.rDocument.getCellAttributeHelper()); if ( mvData.empty() ) { - const ScPatternAttr* pNewPattern = &pDestDocPool->GetDefaultItem( ATTR_PATTERN ); + const ScPatternAttr* pNewPattern = &rAttrArray.rDocument.getCellAttributeHelper().getDefaultCellAttribute(); rAttrArray.SetPatternArea(nDestStart, nDestEnd, pNewPattern); return; } @@ -2455,42 +2411,44 @@ void ScAttrArray::CopyArea( { if (mvData[i].nEndRow >= nStartRow) { - const ScPatternAttr* pOldPattern = mvData[i].pPattern; - const ScPatternAttr* pNewPattern; + const ScPatternAttr* pOldPattern = mvData[i].getScPatternAttr(); + CellAttributeHolder aNewPattern; - if (IsDefaultItem( pOldPattern )) + if (ScPatternAttr::areSame(&rDocument.getCellAttributeHelper().getDefaultCellAttribute(), pOldPattern )) { // default: nothing changed - - pNewPattern = &pDestDocPool->GetDefaultItem( ATTR_PATTERN ); + aNewPattern.setScPatternAttr(&rAttrArray.rDocument.getCellAttributeHelper().getDefaultCellAttribute()); } else if ( nStripFlags != ScMF::NONE ) { - ScPatternAttr aTmpPattern( *pOldPattern ); + ScPatternAttr* pTmpPattern(new ScPatternAttr(*pOldPattern )); ScMF nNewFlags = ScMF::NONE; if ( nStripFlags != ScMF::All ) - nNewFlags = aTmpPattern.GetItem(ATTR_MERGE_FLAG).GetValue() & ~nStripFlags; + nNewFlags = pTmpPattern->GetItem(ATTR_MERGE_FLAG).GetValue() & ~nStripFlags; if ( nNewFlags != ScMF::NONE ) - aTmpPattern.GetItemSet().Put( ScMergeFlagAttr( nNewFlags ) ); + pTmpPattern->GetItemSet().Put( ScMergeFlagAttr( nNewFlags ) ); else - aTmpPattern.GetItemSet().ClearItem( ATTR_MERGE_FLAG ); + pTmpPattern->GetItemSet().ClearItem( ATTR_MERGE_FLAG ); - if (bSamePool) - pNewPattern = &pDestDocPool->DirectPutItemInPool(aTmpPattern); + if (bSameCellAttributeHelper) + aNewPattern.setScPatternAttr(pTmpPattern, true); else - pNewPattern = aTmpPattern.PutInPool( &rAttrArray.rDocument, &rDocument ); + { + aNewPattern = pTmpPattern->MigrateToDocument( &rAttrArray.rDocument, &rDocument ); + delete pTmpPattern; + } } else { - if (bSamePool) - pNewPattern = &pDestDocPool->DirectPutItemInPool(*pOldPattern); + if (bSameCellAttributeHelper) + aNewPattern.setScPatternAttr(pOldPattern); else - pNewPattern = pOldPattern->PutInPool( &rAttrArray.rDocument, &rDocument ); + aNewPattern = pOldPattern->MigrateToDocument( &rAttrArray.rDocument, &rDocument ); } rAttrArray.SetPatternArea(nDestStart, - std::min(static_cast<SCROW>(mvData[i].nEndRow + nDy), nDestEnd), pNewPattern); + std::min(static_cast<SCROW>(mvData[i].nEndRow + nDy), nDestEnd), aNewPattern.getScPatternAttr()); } // when pasting from clipboard and skipping filtered rows, the adjusted @@ -2517,19 +2475,17 @@ void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, return; } - ScDocumentPool* pSourceDocPool = rDocument.GetPool(); - ScDocumentPool* pDestDocPool = rAttrArray.rDocument.GetPool(); - bool bSamePool = (pSourceDocPool==pDestDocPool); + const bool bSameCellAttributeHelper(&rDocument.getCellAttributeHelper() == &rAttrArray.rDocument.getCellAttributeHelper()); if ( mvData.empty() ) { - const ScPatternAttr* pNewPattern; - if (bSamePool) - pNewPattern = &pDestDocPool->DirectPutItemInPool(*rDocument.GetDefPattern()); + CellAttributeHolder aNewPattern; + if (bSameCellAttributeHelper) + aNewPattern.setScPatternAttr(&rDocument.getCellAttributeHelper().getDefaultCellAttribute()); else - pNewPattern = rDocument.GetDefPattern()->PutInPool( &rAttrArray.rDocument, &rDocument ); + aNewPattern = rDocument.getCellAttributeHelper().getDefaultCellAttribute().MigrateToDocument( &rAttrArray.rDocument, &rDocument ); - rAttrArray.SetPatternAreaSafe(nDestStart, nDestEnd, pNewPattern, false); + rAttrArray.SetPatternAreaSafe(nDestStart, nDestEnd, aNewPattern); return; } @@ -2538,16 +2494,16 @@ void ScAttrArray::CopyAreaSafe( SCROW nStartRow, SCROW nEndRow, tools::Long nDy, { if (mvData[i].nEndRow >= nStartRow) { - const ScPatternAttr* pOldPattern = mvData[i].pPattern; - const ScPatternAttr* pNewPattern; + const ScPatternAttr* pOldPattern = mvData[i].getScPatternAttr(); + CellAttributeHolder aNewPattern; - if (bSamePool) - pNewPattern = &pDestDocPool->DirectPutItemInPool(*pOldPattern); + if (bSameCellAttributeHelper) + aNewPattern.setScPatternAttr(pOldPattern); else - pNewPattern = pOldPattern->PutInPool( &rAttrArray.rDocument, &rDocument ); + aNewPattern = pOldPattern->MigrateToDocument( &rAttrArray.rDocument, &rDocument ); rAttrArray.SetPatternAreaSafe(nDestStart, - std::min(static_cast<SCROW>(mvData[i].nEndRow + nDy), nDestEnd), pNewPattern, false); + std::min(static_cast<SCROW>(mvData[i].nEndRow + nDy), nDestEnd), aNewPattern); } // when pasting from clipboard and skipping filtered rows, the adjusted @@ -2571,7 +2527,7 @@ SCROW ScAttrArray::SearchStyle( if ( mvData.empty() ) { - if (rDocument.GetDefPattern()->GetStyleSheet() == pSearchStyle) + if (rDocument.getCellAttributeHelper().getDefaultCellAttribute().GetStyleSheet() == pSearchStyle) return nRow; nRow = bUp ? -1 : rDocument.MaxRow() + 1; @@ -2580,7 +2536,7 @@ SCROW ScAttrArray::SearchStyle( SCSIZE nIndex; Search(nRow, nIndex); - const ScPatternAttr* pPattern = mvData[nIndex].pPattern; + const ScPatternAttr* pPattern = mvData[nIndex].getScPatternAttr(); while (nIndex < mvData.size() && !bFound) { @@ -2610,7 +2566,7 @@ SCROW ScAttrArray::SearchStyle( { --nIndex; nRow = mvData[nIndex].nEndRow; - pPattern = mvData[nIndex].pPattern; + pPattern = mvData[nIndex].getScPatternAttr(); } } else @@ -2618,7 +2574,7 @@ SCROW ScAttrArray::SearchStyle( nRow = mvData[nIndex].nEndRow+1; ++nIndex; if (nIndex<mvData.size()) - pPattern = mvData[nIndex].pPattern; + pPattern = mvData[nIndex].getScPatternAttr(); } } } diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index 9052c6d098b6..198e56fb7158 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -76,7 +76,7 @@ bool IsAmbiguousScriptNonZero( SvtScriptType nScript ) } ScNeededSizeOptions::ScNeededSizeOptions() : - pPattern(nullptr), bFormula(false), bSkipMerged(true), bGetFont(true), bTotalSize(false) + aPattern(), bFormula(false), bSkipMerged(true), bGetFont(true), bTotalSize(false) { } @@ -341,7 +341,7 @@ const ScPatternAttr* ScColumnData::GetMostUsedPattern( SCROW nStartRow, SCROW nE const ScPatternAttr* pMaxPattern = nullptr; size_t nMaxCount = 0; - ScAttrIterator aAttrIter( pAttrArray.get(), nStartRow, nEndRow, GetDoc().GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), nStartRow, nEndRow, &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); const ScPatternAttr* pPattern; SCROW nAttrRow1 = 0, nAttrRow2 = 0; @@ -375,13 +375,13 @@ sal_uInt32 ScColumnData::GetNumberFormat( SCROW nStartRow, SCROW nEndRow ) const return nFormat; } -SCROW ScColumn::ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, +SCROW ScColumn::ApplySelectionCache( ScItemPoolCache& rCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged ) { - return ScColumnData::ApplySelectionCache( pCache, rMark, pDataArray, pIsChanged, nCol ); + return ScColumnData::ApplySelectionCache( rCache, rMark, pDataArray, pIsChanged, nCol ); } -SCROW ScColumnData::ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, +SCROW ScColumnData::ApplySelectionCache( ScItemPoolCache& rCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged, SCCOL nCol ) { SCROW nTop = 0; @@ -393,7 +393,7 @@ SCROW ScColumnData::ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkDa ScMultiSelIter aMultiIter( rMark.GetMultiSelData(), nCol ); while (aMultiIter.Next( nTop, nBottom )) { - pAttrArray->ApplyCacheArea( nTop, nBottom, pCache, pDataArray, pIsChanged ); + pAttrArray->ApplyCacheArea( nTop, nBottom, rCache, pDataArray, pIsChanged ); bFound = true; } } @@ -468,31 +468,31 @@ void ScColumn::DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rM void ScColumn::ApplyPattern( SCROW nRow, const ScPatternAttr& rPatAttr ) { const SfxItemSet* pSet = &rPatAttr.GetItemSet(); - ScItemPoolCache aCache( GetDoc().GetPool(), pSet ); + ScItemPoolCache aCache( GetDoc().getCellAttributeHelper(), *pSet ); - const ScPatternAttr* pPattern = pAttrArray->GetPattern( nRow ); + const CellAttributeHolder aPattern(pAttrArray->GetPattern( nRow )); // true = keep old content - const ScPatternAttr& rNewPattern = aCache.ApplyTo( *pPattern ); + const CellAttributeHolder& rNewPattern = aCache.ApplyTo( aPattern ); - if (!SfxPoolItem::areSame(rNewPattern, *pPattern)) - pAttrArray->SetPattern( nRow, &rNewPattern ); + if (!CellAttributeHolder::areSame(&rNewPattern, &aPattern)) + pAttrArray->SetPattern( nRow, rNewPattern ); } void ScColumnData::ApplyPatternArea( SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rPatAttr, ScEditDataArray* pDataArray, bool* const pIsChanged ) { const SfxItemSet* pSet = &rPatAttr.GetItemSet(); - ScItemPoolCache aCache( GetDoc().GetPool(), pSet ); - pAttrArray->ApplyCacheArea( nStartRow, nEndRow, &aCache, pDataArray, pIsChanged ); + ScItemPoolCache aCache( GetDoc().getCellAttributeHelper(), *pSet ); + pAttrArray->ApplyCacheArea( nStartRow, nEndRow, aCache, pDataArray, pIsChanged ); } void ScColumn::ApplyPatternIfNumberformatIncompatible( const ScRange& rRange, const ScPatternAttr& rPattern, SvNumFormatType nNewType ) { const SfxItemSet* pSet = &rPattern.GetItemSet(); - ScItemPoolCache aCache( GetDoc().GetPool(), pSet ); + ScItemPoolCache aCache( GetDoc().getCellAttributeHelper(), *pSet ); SvNumberFormatter* pFormatter = GetDoc().GetFormatTable(); SCROW nEndRow = rRange.aEnd.Row(); for ( SCROW nRow = rRange.aStart.Row(); nRow <= nEndRow; nRow++ ) @@ -508,7 +508,7 @@ void ScColumn::ApplyPatternIfNumberformatIncompatible( const ScRange& rRange, { SCROW nNewRow1 = std::max( nRow1, nRow ); SCROW nNewRow2 = std::min( nRow2, nEndRow ); - pAttrArray->ApplyCacheArea( nNewRow1, nNewRow2, &aCache ); + pAttrArray->ApplyCacheArea( nNewRow1, nNewRow2, aCache ); nRow = nNewRow2; } } @@ -517,9 +517,9 @@ void ScColumn::ApplyPatternIfNumberformatIncompatible( const ScRange& rRange, void ScColumn::ApplyStyle( SCROW nRow, const ScStyleSheet* rStyle ) { const ScPatternAttr* pPattern = pAttrArray->GetPattern(nRow); - std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr(*pPattern)); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pPattern)); pNewPattern->SetStyleSheet(const_cast<ScStyleSheet*>(rStyle)); - pAttrArray->SetPattern(nRow, std::move(pNewPattern), true); + pAttrArray->SetPattern(nRow, CellAttributeHolder(pNewPattern, true)); } void ScColumn::ApplySelectionStyle(const ScStyleSheet& rStyle, const ScMarkData& rMark) @@ -572,7 +572,7 @@ const ScStyleSheet* ScColumn::GetSelectionStyle( const ScMarkData& rMark, bool& SCROW nBottom; while (bEqual && aMultiIter.Next( nTop, nBottom )) { - ScAttrIterator aAttrIter( pAttrArray.get(), nTop, nBottom, rDocument.GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), nTop, nBottom, &rDocument.getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nRow; SCROW nDummy; while (bEqual) @@ -600,7 +600,7 @@ const ScStyleSheet* ScColumn::GetAreaStyle( bool& rFound, SCROW nRow1, SCROW nRo const ScStyleSheet* pStyle = nullptr; const ScStyleSheet* pNewStyle; - ScAttrIterator aAttrIter( pAttrArray.get(), nRow1, nRow2, GetDoc().GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), nRow1, nRow2, &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nRow; SCROW nDummy; while (bEqual) @@ -623,17 +623,14 @@ void ScColumn::ApplyAttr( SCROW nRow, const SfxPoolItem& rAttr ) // in order to only create a new SetItem, we don't need SfxItemPoolCache. //TODO: Warning: ScItemPoolCache seems to create too many Refs for the new SetItem ?? - ScDocumentPool* pDocPool = GetDoc().GetPool(); + const ScPatternAttr* pOldPattern(pAttrArray->GetPattern(nRow)); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pOldPattern)); + pNewPattern->GetItemSet().Put(rAttr); - const ScPatternAttr* pOldPattern = pAttrArray->GetPattern( nRow ); - ScPatternAttr aTemp(*pOldPattern); - aTemp.GetItemSet().Put(rAttr); - const ScPatternAttr* pNewPattern = &pDocPool->DirectPutItemInPool( aTemp ); - - if (!SfxPoolItem::areSame( pNewPattern, pOldPattern )) - pAttrArray->SetPattern( nRow, pNewPattern ); + if (!ScPatternAttr::areSame( pNewPattern, pOldPattern )) + pAttrArray->SetPattern( nRow, CellAttributeHolder(pNewPattern, true) ); else - pDocPool->DirectRemoveItemFromPool( *pNewPattern ); // free up resources + delete pNewPattern; } ScRefCellValue ScColumn::GetCellValue( SCROW nRow ) const @@ -1623,12 +1620,10 @@ void ScColumn::CopyToColumn( // e.g. DIF and RTF Clipboard-Import for ( SCROW nRow = nRow1; nRow <= nRow2; nRow++ ) { - const ScStyleSheet* pStyle = - rColumn.pAttrArray->GetPattern( nRow )->GetStyleSheet(); - const ScPatternAttr* pPattern = pAttrArray->GetPattern( nRow ); - std::unique_ptr<ScPatternAttr> pNewPattern(new ScPatternAttr( *pPattern )); - pNewPattern->SetStyleSheet( const_cast<ScStyleSheet*>(pStyle) ); - rColumn.pAttrArray->SetPattern( nRow, std::move(pNewPattern), true ); + const ScStyleSheet* pStyle(rColumn.pAttrArray->GetPattern( nRow )->GetStyleSheet()); + ScPatternAttr* pNewPattern(new ScPatternAttr(*pAttrArray->GetPattern(nRow))); + pNewPattern->SetStyleSheet(const_cast<ScStyleSheet*>(pStyle)); + rColumn.pAttrArray->SetPattern(nRow, CellAttributeHolder(pNewPattern, true)); } } else @@ -1700,7 +1695,7 @@ void ScColumn::CopyScenarioFrom( const ScColumn& rSrcCol ) { // This is the scenario table, the data is copied into it ScDocument& rDocument = GetDoc(); - ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), rDocument.GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), &rDocument.getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nStart = -1, nEnd = -1; const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd ); while (pPattern) @@ -1729,7 +1724,7 @@ void ScColumn::CopyScenarioTo( ScColumn& rDestCol ) const { // This is the scenario table, the data is copied to the other ScDocument& rDocument = GetDoc(); - ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), rDocument.GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), &rDocument.getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nStart = -1, nEnd = -1; const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd ); while (pPattern) @@ -1754,7 +1749,7 @@ void ScColumn::CopyScenarioTo( ScColumn& rDestCol ) const bool ScColumn::TestCopyScenarioTo( const ScColumn& rDestCol ) const { bool bOk = true; - ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), GetDoc().GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nStart = 0, nEnd = 0; const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd ); while (pPattern && bOk) @@ -1772,7 +1767,7 @@ void ScColumn::MarkScenarioIn( ScMarkData& rDestMark ) const { ScRange aRange( nCol, 0, nTab ); - ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), GetDoc().GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), 0, GetDoc().MaxRow(), &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nStart = -1, nEnd = -1; const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd ); while (pPattern) diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 28d928cacea1..4b50d060eec5 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -109,7 +109,7 @@ tools::Long ScColumn::GetNeededSize( return bInPrintTwips ? nMeasure : static_cast<tools::Long>(nMeasure * fScale); }; - const ScPatternAttr* pPattern = rOptions.pPattern; + const ScPatternAttr* pPattern = rOptions.aPattern.getScPatternAttr(); if (!pPattern) pPattern = pAttrArray->GetPattern( nRow ); @@ -193,7 +193,7 @@ tools::Long ScColumn::GetNeededSize( // result may set a number format. In which case there's also the // General format not set anymore... bool bMayInvalidatePattern = (aCell.getType() == CELLTYPE_FORMULA); - const ScPatternAttr* pOldPattern = pPattern; + const CellAttributeHolder aOldPattern(pPattern); bool bNumeric = aCell.hasNumeric(); if (bMayInvalidatePattern) { @@ -203,7 +203,7 @@ tools::Long ScColumn::GetNeededSize( } if (bNumeric) { - if (!bMayInvalidatePattern || SfxPoolItem::areSame(pPattern, pOldPattern)) + if (!bMayInvalidatePattern || ScPatternAttr::areSame(pPattern, aOldPattern.getScPatternAttr())) bBreak = false; else { @@ -772,7 +772,7 @@ sal_uInt16 ScColumn::GetOptimalColWidth( // Or again in case there was a leading sep=";" row or two header // rows.. const ScPatternAttr* pNextPattern = GetPattern( ++nRow ); - if (!SfxPoolItem::areSame(pNextPattern, pPattern)) + if (!ScPatternAttr::areSame(pNextPattern, pPattern)) nFormat = pNextPattern->GetNumberFormat( pFormatter ); } OUString aLongStr; @@ -829,8 +829,8 @@ sal_uInt16 ScColumn::GetOptimalColWidth( nScript = ScGlobal::GetDefaultScriptType(); const ScPatternAttr* pPattern = GetPattern(nRow); - aOptions.pPattern = pPattern; - aOptions.bGetFont = (!SfxPoolItem::areSame(pPattern, pOldPattern) || nScript != SvtScriptType::NONE); + aOptions.aPattern.setScPatternAttr(pPattern); + aOptions.bGetFont = (!ScPatternAttr::areSame(pPattern, pOldPattern) || nScript != SvtScriptType::NONE); pOldPattern = pPattern; sal_uInt16 nThis = static_cast<sal_uInt16>(GetNeededSize( nRow, pDev, nPPTX, nPPTY, rZoomX, rZoomY, true, aOptions, &pOldPattern)); @@ -893,7 +893,7 @@ void ScColumn::GetOptimalHeight( { ScDocument& rDocument = GetDoc(); RowHeightsArray& rHeights = rCxt.getHeightArray(); - ScAttrIterator aIter( pAttrArray.get(), nStartRow, nEndRow, rDocument.GetDefPattern() ); + ScAttrIterator aIter( pAttrArray.get(), nStartRow, nEndRow, &rDocument.getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nStart = -1; SCROW nEnd = -1; @@ -1068,8 +1068,8 @@ void ScColumn::GetOptimalHeight( if (rCxt.isForceAutoSize() || !(rDocument.GetRowFlags(nRow, nTab) & CRFlags::ManualSize) ) { - aOptions.pPattern = pPattern; - const ScPatternAttr* pOldPattern = pPattern; + aOptions.aPattern.setScPatternAttr(pPattern); + const CellAttributeHolder aOldPattern(pPattern); sal_uInt16 nHeight = static_cast<sal_uInt16>( std::min( GetNeededSize( nRow, rCxt.getOutputDevice(), rCxt.getPPTX(), rCxt.getPPTY(), @@ -1078,8 +1078,9 @@ void ScColumn::GetOptimalHeight( double(std::numeric_limits<sal_uInt16>::max()))); if (nHeight > rHeights.GetValue(nRow)) rHeights.SetValue(nRow, nRow, nHeight); + // Pattern changed due to calculation? => sync. - if (!SfxPoolItem::areSame(pPattern, pOldPattern)) + if (!ScPatternAttr::areSame(pPattern, aOldPattern.getScPatternAttr())) { pPattern = aIter.Resync( nRow, nStart, nEnd); nNextEnd = 0; diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index a0b0c639a003..5e3411b71b4c 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2046,7 +2046,7 @@ void ScColumn::MixData( std::unique_ptr<ScAttrIterator> ScColumnData::CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const { - return std::make_unique<ScAttrIterator>( pAttrArray.get(), nStartRow, nEndRow, GetDoc().GetDefPattern() ); + return std::make_unique<ScAttrIterator>( pAttrArray.get(), nStartRow, nEndRow, &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); } namespace { @@ -2097,7 +2097,7 @@ namespace { void applyTextNumFormat( ScColumn& rCol, SCROW nRow, SvNumberFormatter* pFormatter ) { sal_uInt32 nFormat = pFormatter->GetStandardFormat(SvNumFormatType::TEXT); - ScPatternAttr aNewAttrs(rCol.GetDoc().GetPool()); + ScPatternAttr aNewAttrs(rCol.GetDoc().getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put(SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat)); rCol.ApplyPattern(nRow, aNewAttrs); @@ -2995,7 +2995,7 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow ) FormulaToValueHandler aFunc; sc::CellStoreType::const_iterator itPos = maCells.begin(); - ScAttrIterator aAttrIter( pAttrArray.get(), nStartRow, nEndRow, GetDoc().GetDefPattern() ); + ScAttrIterator aAttrIter( pAttrArray.get(), nStartRow, nEndRow, &GetDoc().getCellAttributeHelper().getDefaultCellAttribute() ); SCROW nTop = -1; SCROW nBottom = -1; const ScPatternAttr* pPattern = aAttrIter.Next( nTop, nBottom ); diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index 324e54be2a92..3ddec747b7ef 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -135,7 +135,7 @@ void ScColumn::DeleteBeforeCopyFromClip( if (rCxt.isTableProtected()) { - ScPatternAttr aPattern(rDocument.GetPool()); + ScPatternAttr aPattern(rDocument.getCellAttributeHelper()); aPattern.GetItemSet().Put(ScProtectionAttr(false)); ApplyPatternArea(aRange.mnRow1, aRange.mnRow2, aPattern); } @@ -230,7 +230,7 @@ void ScColumn::DeleteBeforeCopyFromClip( if (rCxt.isTableProtected()) { - ScPatternAttr aPattern(rDocument.GetPool()); + ScPatternAttr aPattern(rDocument.getCellAttributeHelper()); aPattern.GetItemSet().Put(ScProtectionAttr(false)); ApplyPatternArea(nRow1, nRow2, aPattern); } @@ -265,10 +265,13 @@ void ScColumn::CopyOneCellFromClip( sc::CopyFromClipContext& rCxt, SCROW nRow1, { if (!rCxt.isSkipEmptyCells() || rSrcCell.getType() != CELLTYPE_NONE) { - const ScPatternAttr* pAttr = (bSameDocPool ? rCxt.getSingleCellPattern(nColOffset) : - rCxt.getSingleCellPattern(nColOffset)->PutInPool( &rDocument, rCxt.getClipDoc())); + CellAttributeHolder aNewPattern; + if (bSameDocPool) + aNewPattern.setScPatternAttr(rCxt.getSingleCellPattern(nColOffset)); + else + aNewPattern = rCxt.getSingleCellPattern(nColOffset)->MigrateToDocument( &rDocument, rCxt.getClipDoc()); - pAttrArray->SetPatternArea(nRow1, nRow2, pAttr, true); + pAttrArray->SetPatternArea(nRow1, nRow2, aNewPattern); } } @@ -1248,10 +1251,9 @@ void ScColumn::Swap( ScColumn& rOther, SCROW nRow1, SCROW nRow2, bool bPattern ) { const ScPatternAttr* pPat1 = GetPattern(nRow); const ScPatternAttr* pPat2 = rOther.GetPattern(nRow); - if (!SfxPoolItem::areSame(pPat1, pPat2)) + if (!ScPatternAttr::areSame(pPat1, pPat2)) { - if (pPat1->GetRefCount() == 1) - pPat1 = &rOther.GetDoc().GetPool()->DirectPutItemInPool(*pPat1); + CellAttributeHolder aTemp(pPat1); SetPattern(nRow, *pPat2); rOther.SetPattern(nRow, *pPat1); } diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index 222a8f1fba26..4fcbcb792cd9 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -74,7 +74,7 @@ static void ScAttrArray_IterGetNumberFormat( sal_uInt32& nFormat, const ScAttrAr const ScPatternAttr* pPattern = pNewArr->GetPatternRange( nRowStart, nRowEnd, nRow ); if( !pPattern ) { - pPattern = rDoc.GetDefPattern(); + pPattern = &rDoc.getCellAttributeHelper().getDefaultCellAttribute(); nRowEnd = rDoc.MaxRow(); } @@ -1402,11 +1402,11 @@ void ScHorizontalAttrIterator::InitForNextRow(bool bInitialization) { pNextEnd[nPos] = rDoc.MaxRow(); assert( pNextEnd[nPos] >= nRow && "Sequence out of order" ); - ppPatterns[nPos] = rDoc.GetDefPattern(); + ppPatterns[nPos] = &rDoc.getCellAttributeHelper().getDefaultCellAttribute(); } else if ( nIndex < pArray.Count() ) { - const ScPatternAttr* pPattern = pArray.mvData[nIndex].pPattern; + const ScPatternAttr* pPattern = pArray.mvData[nIndex].getScPatternAttr(); SCROW nThisEnd = pArray.mvData[nIndex].nEndRow; pNextEnd[nPos] = nThisEnd; assert( pNextEnd[nPos] >= nRow && "Sequence out of order" ); @@ -1424,7 +1424,7 @@ void ScHorizontalAttrIterator::InitForNextRow(bool bInitialization) nMinNextEnd = pNextEnd[nPos]; // store positions of ScHorizontalAttrIterator elements (minimizing expensive ScPatternAttr comparisons) - if (i > nStartCol && !SfxPoolItem::areSame(ppPatterns[nThisHead], ppPatterns[nPos])) + if (i > nStartCol && !ScPatternAttr::areSame(ppPatterns[nThisHead], ppPatterns[nPos])) { pHorizEnd[nThisHead] = i - 1; nThisHead = nPos; // start position of the next horizontal group diff --git a/sc/source/core/data/docpool.cxx b/sc/source/core/data/docpool.cxx index 05dd88958288..d540c9939380 100644 --- a/sc/source/core/data/docpool.cxx +++ b/sc/source/core/data/docpool.cxx @@ -28,6 +28,7 @@ #include <vcl/settings.hxx> #include <svl/itemiter.hxx> #include <svl/stritem.hxx> +#include <svl/voiditem.hxx> #include <svx/algitem.hxx> #include <editeng/boxitem.hxx> #include <editeng/lineitem.hxx> @@ -145,7 +146,6 @@ SfxItemInfo const aItemInfos[] = { 0, false, true }, // ATTR_VALIDDATA { 0, false, true }, // ATTR_CONDITIONAL { 0, false, true }, // ATTR_HYPERLINK - { 0, true, true }, // ATTR_PATTERN { SID_ATTR_LRSPACE, false, true }, // ATTR_LRSPACE { SID_ATTR_ULSPACE, false, true }, // ATTR_ULSPACE { SID_ATTR_PAGE, false, true }, // ATTR_PAGE @@ -184,12 +184,8 @@ static_assert( SAL_N_ELEMENTS(aItemInfos) == ATTR_ENDINDEX - ATTR_STARTINDEX + 1, "these must match"); ScDocumentPool::ScDocumentPool() - - : SfxItemPool ( "ScDocumentPool", - ATTR_STARTINDEX, ATTR_ENDINDEX, - aItemInfos, nullptr ), - mvPoolDefaults(ATTR_ENDINDEX-ATTR_STARTINDEX+1), - mnCurrentMaxKey(0) +: SfxItemPool ( "ScDocumentPool", ATTR_STARTINDEX, ATTR_ENDINDEX, aItemInfos, nullptr ) +, mvPoolDefaults(ATTR_ENDINDEX-ATTR_STARTINDEX+1) { LanguageType nDefLang, nCjkLang, nCtlLang; @@ -274,20 +270,6 @@ ScDocumentPool::ScDocumentPool() mvPoolDefaults[ ATTR_VALIDDATA - ATTR_STARTINDEX ] = new SfxUInt32Item( ATTR_VALIDDATA, 0 ); mvPoolDefaults[ ATTR_CONDITIONAL - ATTR_STARTINDEX ] = new ScCondFormatItem; mvPoolDefaults[ ATTR_HYPERLINK - ATTR_STARTINDEX ] = new SfxStringItem( ATTR_HYPERLINK, OUString() ) ; - - // GetRscString only works after ScGlobal::Init (indicated by the EmptyBrushItem) - // TODO: Write additional method ScGlobal::IsInit() or somesuch - // or detect whether this is the Secondary Pool for a MessagePool - if ( ScGlobal::GetEmptyBrushItem() ) - - mvPoolDefaults[ ATTR_PATTERN - ATTR_STARTINDEX ] = - new ScPatternAttr( SfxItemSetFixed<ATTR_PATTERN_START, ATTR_PATTERN_END>( *this ), - ScResId(STR_STYLENAME_STANDARD) ); - else - mvPoolDefaults[ ATTR_PATTERN - ATTR_STARTINDEX ] = - new ScPatternAttr( SfxItemSetFixed<ATTR_PATTERN_START, ATTR_PATTERN_END>( *this ), - STRING_STANDARD ); // FIXME: without name? - mvPoolDefaults[ ATTR_LRSPACE - ATTR_STARTINDEX ] = new SvxLRSpaceItem( ATTR_LRSPACE ); mvPoolDefaults[ ATTR_ULSPACE - ATTR_STARTINDEX ] = new SvxULSpaceItem( ATTR_ULSPACE ); mvPoolDefaults[ ATTR_PAGE - ATTR_STARTINDEX ] = new SvxPageItem( ATTR_PAGE ); @@ -337,51 +319,6 @@ ScDocumentPool::~ScDocumentPool() } } -void ScDocumentPool::newItem_Callback(const SfxPoolItem& rItem) const -{ - if (ATTR_PATTERN == rItem.Which() && 1 == rItem.GetRefCount()) - { - const_cast<ScDocumentPool*>(this)->mnCurrentMaxKey++; - const_cast<ScPatternAttr&>(static_cast<const ScPatternAttr&>(rItem)).SetPAKey(mnCurrentMaxKey); - } -} - -bool ScDocumentPool::newItem_UseDirect(const SfxPoolItem& rItem) const -{ - // I have evaluated that this is currently needed for ATTR_PATTERN/ScPatternAttr to work, - // so this needs to stay at ptr-compare - return (ATTR_PATTERN == rItem.Which() && areSfxPoolItemPtrsEqual(&rItem, mvPoolDefaults[ATTR_PATTERN - ATTR_STARTINDEX])); -} - -void ScDocumentPool::StyleDeleted( const ScStyleSheet* pStyle ) -{ - for (const SfxPoolItem* pItem : GetItemSurrogates( ATTR_PATTERN )) - { - ScPatternAttr* pPattern = const_cast<ScPatternAttr*>(dynamic_cast<const ScPatternAttr*>(pItem)); - if ( pPattern && pPattern->GetStyleSheet() == pStyle ) - pPattern->StyleToName(); - } -} - -void ScDocumentPool::CellStyleCreated( std::u16string_view rName, const ScDocument& rDoc ) -{ - // If a style was created, don't keep any pattern with its name string in the pool, - // because it would compare equal to a pattern with a pointer to the new style. - // Calling StyleSheetChanged isn't enough because the pool may still contain items - // for undo or clipboard content. - - for (const SfxPoolItem* pItem : GetItemSurrogates( ATTR_PATTERN )) - { - auto pPattern = const_cast<ScPatternAttr*>(dynamic_cast<const ScPatternAttr*>(pItem)); - if ( pPattern && pPattern->GetStyleSheet() == nullptr ) - { - const OUString* pStyleName = pPattern->GetStyleName(); - if ( pStyleName && *pStyleName == rName ) - pPattern->UpdateStyleSheet(rDoc); // find and store style pointer - } - } -} - rtl::Reference<SfxItemPool> ScDocumentPool::Clone() const { return new SfxItemPool (*this, true); diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index 3b9b24cfec49..026b2e1b9956 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -90,6 +90,7 @@ #include <drwlayer.hxx> #include <sharedstringpoolpurge.hxx> #include <dociter.hxx> +#include <docpool.hxx> #include <config_features.h> using namespace com::sun::star; @@ -111,7 +112,21 @@ ScSheetLimits ScSheetLimits::CreateDefault() return ScSheetLimits(MAXCOL, MAXROW); } +CellAttributeHelper& ScDocument::getCellAttributeHelper() const +{ + if (!mpCellAttributeHelper) + { + assert(!IsClipOrUndo() && "CellAttributeHelper needs to be shared using SharePooledResources, not created (!)"); + SfxItemPool* pPool(const_cast<ScDocument*>(this)->GetPool()); + assert(nullptr != pPool && "No SfxItemPool for this ScDocument (!)"); + mpCellAttributeHelper.reset(new CellAttributeHelper(*pPool)); + } + + return *mpCellAttributeHelper; +} + ScDocument::ScDocument( ScDocumentMode eMode, ScDocShell* pDocShell ) : + mpCellAttributeHelper(), mpCellStringPool(std::make_shared<svl::SharedStringPool>(ScGlobal::getCharClass())), mpDocLinkMgr(new sc::DocumentLinkManager(pDocShell)), mbFormulaGroupCxtBlockDiscard(false), @@ -216,6 +231,7 @@ ScDocument::ScDocument( ScDocumentMode eMode, ScDocShell* pDocShell ) : { pChartListenerCollection = nullptr; } + pDBCollection.reset( new ScDBCollection(*this) ); pSelectionAttr = nullptr; apTemporaryChartLock.reset( new ScTemporaryChartLock(this) ); @@ -503,7 +519,7 @@ ScNoteEditEngine& ScDocument::GetNoteEngine() mpNoteEngine->EnableUndo( false ); mpNoteEngine->SetRefMapMode(MapMode(MapUnit::Map100thMM)); ApplyAsianEditSettings( *mpNoteEngine ); - const SfxItemSet& rItemSet = GetDefPattern()->GetItemSet(); + const SfxItemSet& rItemSet(getCellAttributeHelper().getDefaultCellAttribute().GetItemSet()); SfxItemSet aEEItemSet( mpNoteEngine->GetEmptyItemSet() ); ScPatternAttr::FillToEditItemSet( aEEItemSet, rItemSet ); mpNoteEngine->SetDefaults( std::move(aEEItemSet) ); // edit engine takes ownership diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index e9a4fea132f2..e62956771cb7 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -739,8 +739,7 @@ sal_uLong ScDocument::AddValidationEntry( const ScValidationData& rNew ) nMax = nKey; } - // might be called from ScPatternAttr::PutInPool; thus clone (real copy) - + // might be called from ScPatternAttr::MigrateToDocument; thus clone (real copy) sal_uLong nNewKey = nMax + 1; std::unique_ptr<ScValidationData> pInsert(rNew.Clone(this)); pInsert->SetKey( nNewKey ); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 6a51d364d9ce..aafd4271e5d1 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -5017,29 +5017,28 @@ bool ScDocument::RemoveFlagsTab( SCCOL nStartCol, SCROW nStartRow, return false; } -const ScPatternAttr* ScDocument::SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, std::unique_ptr<ScPatternAttr> pAttr ) +void ScDocument::SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, const CellAttributeHolder& rHolder ) { if (ScTable* pTable = FetchTable(nTab)) - return pTable->SetPattern(nCol, nRow, std::move(pAttr)); - return nullptr; + pTable->SetPattern(nCol, nRow, rHolder); } -const ScPatternAttr* ScDocument::SetPattern( const ScAddress& rPos, std::unique_ptr<ScPatternAttr> pAttr ) +void ScDocument::SetPattern( const ScAddress& rPos, const CellAttributeHolder& rHolder ) { - return SetPattern(rPos.Col(), rPos.Row(), rPos.Tab(), std::move(pAttr)); + SetPattern(rPos.Col(), rPos.Row(), rPos.Tab(), rHolder); } void ScDocument::SetPattern( SCCOL nCol, SCROW nRow, SCTAB nTab, const ScPatternAttr& rAttr ) { if (ScTable* pTable = FetchTable(nTab)) - pTable->SetPattern(nCol, nRow, rAttr); + pTable->SetPattern(nCol, nRow, CellAttributeHolder(&rAttr)); } void ScDocument::SetPattern( const ScAddress& rPos, const ScPatternAttr& rAttr ) { SCTAB nTab = rPos.Tab(); if (ScTable* pTable = FetchTable(nTab)) - pTable->SetPattern(rPos, rAttr); + pTable->SetPattern(rPos, rAttr); } std::unique_ptr<ScPatternAttr> ScDocument::CreateSelectionPattern( const ScMarkData& rMark, bool bDeep ) @@ -5075,14 +5074,14 @@ std::unique_ptr<ScPatternAttr> ScDocument::CreateSelectionPattern( const ScMarkD OSL_ENSURE( aState.pItemSet, "SelectionPattern Null" ); if (aState.pItemSet) { - std::unique_ptr<ScPatternAttr> pPattern(new ScPatternAttr( std::move(*aState.pItemSet) )); + std::unique_ptr<ScPatternAttr> pPattern(new ScPatternAttr(getCellAttributeHelper(), &aState.pItemSet.value())); if (aState.mbValidPatternId) pPattern->SetPAKey(aState.mnPatternId); return pPattern; } else - return std::unique_ptr<ScPatternAttr>(new ScPatternAttr( GetPool() )); // empty + return std::unique_ptr<ScPatternAttr>(new ScPatternAttr(getCellAttributeHelper())); // empty } const ScPatternAttr* ScDocument::GetSelectionPattern( const ScMarkData& rMark ) @@ -5522,9 +5521,10 @@ void ScDocument::ExtendOverlapped( SCCOL& rStartCol, SCROW& rStartRow, bool bHorOverlapped; if ( pAttrArray.Count() ) - bHorOverlapped = pAttrArray.mvData[nIndex].pPattern->GetItem(ATTR_MERGE_FLAG).IsHorOverlapped(); + bHorOverlapped = pAttrArray.mvData[nIndex].getScPatternAttr()->GetItem(ATTR_MERGE_FLAG).IsHorOverlapped(); else - bHorOverlapped = GetDefPattern()->GetItem(ATTR_MERGE_FLAG).IsHorOverlapped(); + bHorOverlapped = getCellAttributeHelper().getDefaultCellAttribute().GetItem(ATTR_MERGE_FLAG).IsHorOverlapped(); + if ( bHorOverlapped ) { SCROW nEndRowSeg = (pAttrArray.Count()) ? pAttrArray.mvData[nIndex].nEndRow : MaxRow(); @@ -5912,14 +5912,14 @@ void ScDocument::ApplySelectionPattern( const ScPatternAttr& rAttr, const ScMark } else { - ScItemPoolCache aCache( mxPoolHelper->GetDocPool(), pSet ); + ScItemPoolCache aCache( getCellAttributeHelper(), *pSet ); SCTAB nMax = GetTableCount(); for (const auto& rTab : rMark) { if (rTab >= nMax) break; if (maTabs[rTab]) - maTabs[rTab]->ApplySelectionCache( &aCache, rMark, pDataArray, pIsChanged ); + maTabs[rTab]->ApplySelectionCache( aCache, rMark, pDataArray, pIsChanged ); } } } @@ -6072,11 +6072,6 @@ void ScDocument::DeleteSelectionTab( } } -ScPatternAttr* ScDocument::GetDefPattern() const -{ - return const_cast<ScPatternAttr*>(&mxPoolHelper->GetDocPool()->GetDefaultItem(ATTR_PATTERN)); -} - ScDocumentPool* ScDocument::GetPool() { return mxPoolHelper ? mxPoolHelper->GetDocPool() : nullptr; @@ -6126,32 +6121,6 @@ void ScDocument::GetNextPos( SCCOL& rCol, SCROW& rRow, SCTAB nTab, SCCOL nMovX, // Data operations -void ScDocument::UpdStlShtPtrsFrmNms() -{ - ScDocumentPool* pPool = mxPoolHelper->GetDocPool(); - - for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(ATTR_PATTERN)) - { - auto pPattern = const_cast<ScPatternAttr*>(dynamic_cast<const ScPatternAttr*>(pItem)); - if (pPattern) - pPattern->UpdateStyleSheet(*this); - } - const_cast<ScPatternAttr&>(pPool->GetDefaultItem(ATTR_PATTERN)).UpdateStyleSheet(*this); -} - -void ScDocument::StylesToNames() -{ - ScDocumentPool* pPool = mxPoolHelper->GetDocPool(); - - for (const SfxPoolItem* pItem : pPool->GetItemSurrogates(ATTR_PATTERN)) - { - auto pPattern = const_cast<ScPatternAttr*>(dynamic_cast<const ScPatternAttr*>(pItem)); - if (pPattern) - pPattern->StyleToName(); - } - const_cast<ScPatternAttr&>(pPool->GetDefaultItem(ATTR_PATTERN)).StyleToName(); -} - sal_uInt64 ScDocument::GetCellCount() const { sal_uInt64 nCellCount = 0; diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index acf0f27672b0..08c4886d5e61 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -332,6 +332,10 @@ void ScDocument::SharePooledResources( const ScDocument* pSrcDoc ) ScMutationGuard aGuard(*this, ScMutationGuardFlags::CORE); mxPoolHelper = pSrcDoc->mxPoolHelper; mpCellStringPool = pSrcDoc->mpCellStringPool; + + // force lazy creation/existance in source document *before* sharing + pSrcDoc->getCellAttributeHelper(); + mpCellAttributeHelper = pSrcDoc->mpCellAttributeHelper; } void ScDocument::UpdateScriptTypes( const ScAddress& rPos, SCCOL nColSize, SCROW nRowSize ) diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 3f98fc770a6b..2570bcd214d8 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -398,7 +398,7 @@ void ScDrawLayer::CreateDefaultStyles() // text formatting SfxItemSet aEditSet(GetItemPool()); - ScPatternAttr::FillToEditItemSet(aEditSet, pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN).GetItemSet()); + ScPatternAttr::FillToEditItemSet(aEditSet, pDoc->getCellAttributeHelper().getDefaultCellAttribute().GetItemSet()); pSet->Put(aEditSet.Get(EE_CHAR_FONTINFO)); pSet->Put(aEditSet.Get(EE_CHAR_FONTINFO_CJK)); diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx index 4a573e1c21da..544c58a65e46 100644 --- a/sc/source/core/data/fillinfo.cxx +++ b/sc/source/core/data/fillinfo.cxx @@ -473,12 +473,12 @@ void ScDocument::FillInfo( if ( pThisAttrArr->Count() ) { nThisRow = pThisAttrArr->mvData[nIndex].nEndRow; // End of range - pPattern = pThisAttrArr->mvData[nIndex].pPattern; + pPattern = pThisAttrArr->mvData[nIndex].getScPatternAttr(); } else { nThisRow = MaxRow(); - pPattern = GetDefPattern(); + pPattern = &getCellAttributeHelper().getDefaultCellAttribute(); } const SvxBrushItem* pBackground = &pPattern->GetItem(ATTR_BACKGROUND); diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index 29a616c6b6e8..18094086c50f 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -510,21 +510,19 @@ void ScGlobal::SetClipDocName( const OUString& rNew ) aStrClipDocName = rNew; } -void ScGlobal::InitTextHeight(const SfxItemPool* pPool) +void ScGlobal::InitTextHeight(SfxItemPool& rPool) { - if (!pPool) - { - OSL_FAIL("ScGlobal::InitTextHeight: No Pool"); - return; - } - - const ScPatternAttr& rPattern = pPool->GetDefaultItem(ATTR_PATTERN); + // this gets handed over the m_pMessagePool in ScModule::ScModule, so + // the previously used item ScPatternAttr is unchanged. This allows to + // just use an temporary incarnation of a CellAttributeHelper here + const CellAttributeHelper aTempHelper(rPool); + const ScPatternAttr& rDefaultCellAttribute(aTempHelper.getDefaultCellAttribute()); OutputDevice* pDefaultDev = Application::GetDefaultDevice(); ScopedVclPtrInstance< VirtualDevice > pVirtWindow( *pDefaultDev ); pVirtWindow->SetMapMode(MapMode(MapUnit::MapPixel)); vcl::Font aDefFont; - rPattern.fillFontOnly(aDefFont, pVirtWindow); // Font color doesn't matter here + rDefaultCellAttribute.fillFontOnly(aDefFont, pVirtWindow); // Font color doesn't matter here pVirtWindow->SetFont(aDefFont); sal_uInt16 nTest = static_cast<sal_uInt16>( pVirtWindow->PixelToLogic(Size(0, pVirtWindow->GetTextHeight()), MapMode(MapUnit::MapTwip)).Height()); @@ -532,7 +530,7 @@ void ScGlobal::InitTextHeight(const SfxItemPool* pPool) if (nTest > nDefFontHeight) nDefFontHeight = nTest; - const SvxMarginItem& rMargin = rPattern.GetItem(ATTR_MARGIN); + const SvxMarginItem& rMargin(rDefaultCellAttribute.GetItem(ATTR_MARGIN)); nTest = static_cast<sal_uInt16>(nDefFontHeight + rMargin.GetTopMargin() + rMargin.GetBottomMargin() - STD_ROWHEIGHT_DIFF); diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index 4bb79828da13..871095ec7bf1 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -68,62 +68,272 @@ #include <comphelper/lok.hxx> #include <tabvwsh.hxx> -const WhichRangesContainer aScPatternAttrSchema(svl::Items<ATTR_PATTERN_START, ATTR_PATTERN_END>); +CellAttributeHelper::CellAttributeHelper(SfxItemPool& rSfxItemPool) +: mrSfxItemPool(rSfxItemPool) +, mpDefaultCellAttribute(nullptr) +, maRegisteredCellAttributes() +, mpLastHit(nullptr) +, mnCurrentMaxKey(0) +{ +} -ScPatternAttr::ScPatternAttr( SfxItemSet&& pItemSet, const OUString& rStyleName ) - : SfxSetItem ( ATTR_PATTERN, std::move(pItemSet) ), - pName ( rStyleName ), - pStyle ( nullptr ), - mnPAKey(0) +CellAttributeHelper::~CellAttributeHelper() { - setExceptionalSCItem(); + delete mpDefaultCellAttribute; +} - // We need to ensure that ScPatternAttr is using the correct WhichRange, - // see comments in commit message. This does transfers the items with - // minimized overhead, too - if (GetItemSet().GetRanges() != aScPatternAttrSchema) - GetItemSet().SetRanges(aScPatternAttrSchema); +const ScPatternAttr* CellAttributeHelper::registerAndCheck(const ScPatternAttr& rCandidate, bool bPassingOwnership) const +{ + if (&rCandidate == &getDefaultCellAttribute()) + return &rCandidate; + + assert(rCandidate.pCellAttributeHelper == this && "WRONG CellAttributeHelper in ScPatternAttr (!)"); + + if (rCandidate.isRegistered()) + { + assert(!bPassingOwnership && "Trying to register an already registered CellAttribute with ownership change (!)"); + rCandidate.mnRefCount++; + return &rCandidate; + } + + if (nullptr != mpLastHit && ScPatternAttr::areSame(mpLastHit, &rCandidate)) + { + // hit for single-entry cache, make use of it + mpLastHit->mnRefCount++; + if (bPassingOwnership) + delete &rCandidate; + return mpLastHit; + } + + for (const ScPatternAttr* pCheck : maRegisteredCellAttributes) + { + if (ScPatternAttr::areSame(pCheck, &rCandidate)) + { + pCheck->mnRefCount++; + if (bPassingOwnership) + delete &rCandidate; + mpLastHit = pCheck; + return pCheck; + } + } + + const ScPatternAttr* pCandidate(bPassingOwnership ? &rCandidate : new ScPatternAttr(rCandidate)); + pCandidate->mnRefCount++; + const_cast<ScPatternAttr*>(pCandidate)->SetPAKey(mnCurrentMaxKey++); + maRegisteredCellAttributes.insert(pCandidate); + mpLastHit = pCandidate; + return pCandidate; } -ScPatternAttr::ScPatternAttr( SfxItemSet&& pItemSet ) - : SfxSetItem ( ATTR_PATTERN, std::move(pItemSet) ), - pStyle ( nullptr ), - mnPAKey(0) +void CellAttributeHelper::doUnregister(const ScPatternAttr& rCandidate) { - setExceptionalSCItem(); + if (&rCandidate == &getDefaultCellAttribute()) + return; - // We need to ensure that ScPatternAttr is using the correct WhichRange, - // see comments in commit message. This does transfers the items with - // minimized overhead, too - if (GetItemSet().GetRanges() != aScPatternAttrSchema) - GetItemSet().SetRanges(aScPatternAttrSchema); + assert(rCandidate.isRegistered()); + rCandidate.mnRefCount--; + + if (0 != rCandidate.mnRefCount) + return; + + if (mpLastHit == &rCandidate) + mpLastHit = nullptr; + + maRegisteredCellAttributes.erase(&rCandidate); + delete &rCandidate; } -ScPatternAttr::ScPatternAttr( SfxItemPool* pItemPool ) - : SfxSetItem ( ATTR_PATTERN, SfxItemSetFixed<ATTR_PATTERN_START, ATTR_PATTERN_END>( *pItemPool ) ), - pStyle ( nullptr ), - mnPAKey(0) +const ScPatternAttr& CellAttributeHelper::getDefaultCellAttribute() const { - setExceptionalSCItem(); + // *have* to create on-demand due to mrScDocument.GetPool() *can* be nullptr + // since mxPoolHelper is *only* created for SCDOCMODE_DOCUMENT and + // SCDOCMODE_FUNCTIONACCESS (!) + if (!mpDefaultCellAttribute) + { + // GetRscString only works after ScGlobal::Init (indicated by the EmptyBrushItem) + // TODO: Write additional method ScGlobal::IsInit() or somesuch + // or detect whether this is the Secondary Pool for a MessagePool + if (ScGlobal::GetEmptyBrushItem()) + { + const OUString aInitialStyle(ScResId(STR_STYLENAME_STANDARD)); + mpDefaultCellAttribute = new ScPatternAttr( + *const_cast<CellAttributeHelper*>(this), + nullptr, // no SfxItemSet + &aInitialStyle); + } + else + { + mpDefaultCellAttribute = new ScPatternAttr(*const_cast<CellAttributeHelper*>(this)); + } + } + return *mpDefaultCellAttribute; } -ScPatternAttr::ScPatternAttr( const ScPatternAttr& rPatternAttr ) - : SfxSetItem ( rPatternAttr ), - pName ( rPatternAttr.pName ), - pStyle ( rPatternAttr.pStyle ), - mnPAKey(rPatternAttr.mnPAKey) +void CellAttributeHelper::CellStyleDeleted(const ScStyleSheet& rStyle) { - setExceptionalSCItem(); + for (const ScPatternAttr* pCheck : maRegisteredCellAttributes) + { + if (&rStyle == pCheck->GetStyleSheet()) + const_cast<ScPatternAttr*>(pCheck)->StyleToName(); + } } -ScPatternAttr* ScPatternAttr::Clone( SfxItemPool *pPool ) const +void CellAttributeHelper::CellStyleCreated(ScDocument& rDoc, std::u16string_view rName) { - ScPatternAttr* pPattern = new ScPatternAttr( GetItemSet().CloneAsValue(true, pPool) ); + // If a style was created, don't keep any pattern with its name string in the pool, + // because it would compare equal to a pattern with a pointer to the new style. + // Calling StyleSheetChanged isn't enough because the pool may still contain items + // for undo or clipboard content. + for (const ScPatternAttr* pCheck : maRegisteredCellAttributes) + { + if (nullptr == pCheck->GetStyleSheet() && rName == *pCheck->GetStyleName()) + const_cast<ScPatternAttr*>(pCheck)->UpdateStyleSheet(rDoc); // find and store style pointer + } +} - pPattern->pStyle = pStyle; - pPattern->pName = pName; +void CellAttributeHelper::UpdateAllStyleSheets(ScDocument& rDoc) +{ + for (const ScPatternAttr* pCheck : maRegisteredCellAttributes) + const_cast<ScPatternAttr*>(pCheck)->UpdateStyleSheet(rDoc); - return pPattern; + // force existance, then access + getDefaultCellAttribute(); + mpDefaultCellAttribute->UpdateStyleSheet(rDoc); +} + +void CellAttributeHelper::AllStylesToNames() +{ + for (const ScPatternAttr* pCheck : maRegisteredCellAttributes) + const_cast<ScPatternAttr*>(pCheck)->StyleToName(); + + // force existance, then access + getDefaultCellAttribute(); + mpDefaultCellAttribute->StyleToName(); +} + +CellAttributeHolder::CellAttributeHolder(const ScPatternAttr* pNew, bool bPassingOwnership) +: mpScPatternAttr(nullptr) +{ + if (nullptr != pNew) + mpScPatternAttr = pNew->getCellAttributeHelper().registerAndCheck(*pNew, bPassingOwnership); +} + +CellAttributeHolder::CellAttributeHolder(const CellAttributeHolder& rHolder) +: mpScPatternAttr(nullptr) +{ + if (rHolder.getScPatternAttr()) + mpScPatternAttr = rHolder.getScPatternAttr()->getCellAttributeHelper().registerAndCheck(*rHolder.getScPatternAttr(), false); +} + +CellAttributeHolder::~CellAttributeHolder() +{ + if (nullptr != mpScPatternAttr) + mpScPatternAttr->getCellAttributeHelper().doUnregister(*mpScPatternAttr); +} + +const CellAttributeHolder& CellAttributeHolder::operator=(const CellAttributeHolder& rHolder) +{ + if (nullptr != mpScPatternAttr) + mpScPatternAttr->getCellAttributeHelper().doUnregister(*mpScPatternAttr); + + mpScPatternAttr = nullptr; + + if (rHolder.getScPatternAttr()) + mpScPatternAttr = rHolder.getScPatternAttr()->getCellAttributeHelper().registerAndCheck(*rHolder.getScPatternAttr(), false); + + return *this; +} + +bool CellAttributeHolder::operator==(const CellAttributeHolder& rHolder) const +{ + // here we have registered entries, so no need to test for equality + return mpScPatternAttr == rHolder.mpScPatternAttr; +} + +void CellAttributeHolder::setScPatternAttr(const ScPatternAttr* pNew, bool bPassingOwnership) +{ + if (nullptr != mpScPatternAttr) + mpScPatternAttr->getCellAttributeHelper().doUnregister(*mpScPatternAttr); + + mpScPatternAttr = nullptr; + + if (nullptr != pNew) + mpScPatternAttr = pNew->getCellAttributeHelper().registerAndCheck(*pNew, bPassingOwnership); +} + +bool CellAttributeHolder::areSame(const CellAttributeHolder* p1, const CellAttributeHolder* p2) +{ + if (p1 == p2) + // pointer compare, this handles already + // nullptr and if indeed handed over twice + return true; + + if (nullptr == p1 || nullptr == p2) + // one ptr is nullptr, not both, that would + // have triggered above + return false; + + // return content compare using operator== at last + return *p1 == *p2; +} + +#ifdef DBG_UTIL +static size_t nUsedScPatternAttr(0); +#endif + +const WhichRangesContainer aScPatternAttrSchema(svl::Items<ATTR_PATTERN_START, ATTR_PATTERN_END>); + +ScPatternAttr::ScPatternAttr(CellAttributeHelper& rHelper, const SfxItemSet* pItemSet, const OUString* pStyleName) +: maLocalSfxItemSet(rHelper.GetPool(), aScPatternAttrSchema) +, pName() +, mxVisible() +, pStyle(nullptr) +, pCellAttributeHelper(&rHelper) +, mnPAKey(0) +, mnRefCount(0) +#ifdef DBG_UTIL +, m_nSerialNumber(nUsedScPatternAttr++) +, m_bDeleted(false) +#endif +{ + if (nullptr != pStyleName) + pName = *pStyleName; + + // We need to ensure that ScPatternAttr is using the correct WhichRange, + // see comments in commit message. This does transfers the items with + // minimized overhead, too + if (nullptr != pItemSet) + { + // CAUTION: Use bInvalidAsDefault == false for the ::Put, + // we *need* to take over also Items/Slots in state + // SfxItemState::DONTCARE aka IsInvalidItem, this is a precious + // value/information e.g. in ScDocument::CreateSelectionPattern + maLocalSfxItemSet.Put(*pItemSet, false); + } +} + +ScPatternAttr::ScPatternAttr(const ScPatternAttr& rPatternAttr) +: maLocalSfxItemSet(rPatternAttr.maLocalSfxItemSet) +, pName(rPatternAttr.pName) +, mxVisible() +, pStyle(rPatternAttr.pStyle) +, pCellAttributeHelper(rPatternAttr.pCellAttributeHelper) +, mnPAKey(rPatternAttr.mnPAKey) +, mnRefCount(0) +#ifdef DBG_UTIL +, m_nSerialNumber(nUsedScPatternAttr++) +, m_bDeleted(false) +#endif +{ +} + +ScPatternAttr::~ScPatternAttr() +{ +#ifdef DBG_UTIL + m_bDeleted = true; +#endif + // should no longer be referenced, complain if not so + assert(!isRegistered()); } static bool StrCmp( const OUString* pStr1, const OUString* pStr2 ) @@ -139,37 +349,26 @@ static bool StrCmp( const OUString* pStr1, const OUString* pStr2 ) constexpr size_t compareSize = ATTR_PATTERN_END - ATTR_PATTERN_START + 1; -bool ScPatternAttr::operator==( const SfxPoolItem& rCmp ) const +bool ScPatternAttr::operator==(const ScPatternAttr& rCmp) const { // check if same incarnation if (this == &rCmp) return true; - // check SfxPoolItem base class - if (!SfxPoolItem::operator==(rCmp) ) - return false; - // check everything except the SfxItemSet from base class SfxSetItem - const ScPatternAttr& rOther(static_cast<const ScPatternAttr&>(rCmp)); - if (!StrCmp(GetStyleName(), rOther.GetStyleName())) + if (!StrCmp(GetStyleName(), rCmp.GetStyleName())) return false; // here we need to compare the SfxItemSet. We *know* that these are // all simple (one range, same range) - const SfxItemSet& rSet1(GetItemSet()); - const SfxItemSet& rSet2(rOther.GetItemSet()); + const SfxItemSet& rSet1(maLocalSfxItemSet); + const SfxItemSet& rSet2(rCmp.maLocalSfxItemSet); // the former method 'FastEqualPatternSets' mentioned: // "Actually test_tdf133629 from UITest_calc_tests9 somehow manages to have // a different range (and I don't understand enough why), so better be safe and compare fully." // in that case the hash code above would already fail, too - if (rSet1.TotalCount() != compareSize || rSet2.TotalCount() != compareSize) - { - // assert this for now, should not happen. If it does, look for it and evtl. - // enable SfxItemSet::operator== below - assert(false); - return rSet1 == rSet2; - } + assert(rSet1.TotalCount() == compareSize && rSet2.TotalCount() == compareSize); // check pools, do not accept different pools if (rSet1.GetPool() != rSet2.GetPool()) @@ -179,6 +378,10 @@ bool ScPatternAttr::operator==( const SfxPoolItem& rCmp ) const if (rSet1.Count() != rSet2.Count()) return false; + // both have no items, done + if (0 == rSet1.Count()) + return true; + // compare each item separately const SfxPoolItem **ppItem1(rSet1.GetItems_Impl()); const SfxPoolItem **ppItem2(rSet2.GetItems_Impl()); @@ -198,6 +401,22 @@ bool ScPatternAttr::operator==( const SfxPoolItem& rCmp ) const return true; } +bool ScPatternAttr::areSame(const ScPatternAttr* pItem1, const ScPatternAttr* pItem2) +{ + if (pItem1 == pItem2) + // pointer compare, this handles already + // nullptr and if indeed handed over twice + return true; + + if (nullptr == pItem1 || nullptr == pItem2) + // one ptr is nullptr, not both, that would + // have triggered above + return false; + + // return content compare using operator== at last + return *pItem1 == *pItem2; +} + SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet ) { SvxCellOrientation eOrient = SvxCellOrientation::Standard; @@ -1134,15 +1353,13 @@ static SfxStyleSheetBase* lcl_CopyStyleToPool return pDestStyle; } -ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const +CellAttributeHolder ScPatternAttr::MigrateToDocument( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const { const SfxItemSet* pSrcSet = &GetItemSet(); - - ScPatternAttr aDestPattern( pDestDoc->GetPool() ); - SfxItemSet* pDestSet = &aDestPattern.GetItemSet(); + ScPatternAttr* pDestPattern(new ScPatternAttr(pDestDoc->getCellAttributeHelper())); + SfxItemSet* pDestSet(&pDestPattern->GetItemSet()); // Copy cell pattern style to other document: - if ( pDestDoc != pSrcDoc ) { OSL_ENSURE( pStyle, "Missing Pattern-Style! :-/" ); @@ -1155,7 +1372,7 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD pDestDoc->GetStyleSheetPool(), pDestDoc->GetFormatExchangeList() ); - aDestPattern.SetStyleSheet( static_cast<ScStyleSheet*>(pStyleCpy) ); + pDestPattern->SetStyleSheet( static_cast<ScStyleSheet*>(pStyleCpy) ); } for ( sal_uInt16 nAttrId = ATTR_PATTERN_START; nAttrId <= ATTR_PATTERN_END; nAttrId++ ) @@ -1203,8 +1420,7 @@ ScPatternAttr* ScPatternAttr::PutInPool( ScDocument* pDestDoc, ScDocument* pSrcD } } - ScPatternAttr* pPatternAttr = const_cast<ScPatternAttr*>( &pDestDoc->GetPool()->DirectPutItemInPool(aDestPattern) ); - return pPatternAttr; + return CellAttributeHolder(pDestPattern, true); } bool ScPatternAttr::IsVisible() const diff --git a/sc/source/core/data/poolcach.cxx b/sc/source/core/data/poolcach.cxx index d929933d0e96..3ab41d416c49 100644 --- a/sc/source/core/data/poolcach.cxx +++ b/sc/source/core/data/poolcach.cxx @@ -18,94 +18,61 @@ */ -#include <svl/itempool.hxx> #include <svl/itemset.hxx> -#include <svl/setitem.hxx> #include <poolcach.hxx> #include <tools/debug.hxx> #include <patattr.hxx> -ScItemPoolCache::ScItemPoolCache( SfxItemPool *pItemPool, - const SfxPoolItem *pPutItem ): - pPool(pItemPool), - pSetToPut( nullptr ), - pItemToPut( &pItemPool->DirectPutItemInPool(*pPutItem) ) +ScItemPoolCache::ScItemPoolCache(CellAttributeHelper& _rHelper, const SfxPoolItem& rPutItem) +: rHelper(_rHelper) +, pSetToPut(nullptr) +, aItemToPut(_rHelper.GetPool(), &rPutItem) { - DBG_ASSERT(pItemPool, "No Pool provided"); } - -ScItemPoolCache::ScItemPoolCache( SfxItemPool *pItemPool, - const SfxItemSet *pPutSet ): - pPool(pItemPool), - pSetToPut( pPutSet ), - pItemToPut( nullptr ) +ScItemPoolCache::ScItemPoolCache(CellAttributeHelper& _rHelper, const SfxItemSet& rPutSet) +: rHelper(_rHelper) +, pSetToPut(&rPutSet) +, aItemToPut() { - DBG_ASSERT(pItemPool, "No Pool provided"); } - ScItemPoolCache::~ScItemPoolCache() { - for (const SfxItemModifyImpl & rImpl : m_aCache) { - pPool->DirectRemoveItemFromPool( *rImpl.pPoolItem ); - pPool->DirectRemoveItemFromPool( *rImpl.pOrigItem ); - } - - if ( pItemToPut ) - pPool->DirectRemoveItemFromPool( *pItemToPut ); } - -const ScPatternAttr& ScItemPoolCache::ApplyTo( const ScPatternAttr &rOrigItem ) +const CellAttributeHolder& ScItemPoolCache::ApplyTo(const CellAttributeHolder& rOrigItem) { - DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" ); - DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ), - "original not in pool" ); + const ScPatternAttr* pAttr(rOrigItem.getScPatternAttr()); + if (nullptr == pAttr) + return rOrigItem; + + DBG_ASSERT(&rHelper.GetPool() == pAttr->GetItemSet().GetPool(), "invalid Pool (!)"); // Find whether this Transformations ever occurred for (const SfxItemModifyImpl & rMapEntry : m_aCache) { - // use Item PtrCompare OK - if ( areSfxPoolItemPtrsEqual(rMapEntry.pOrigItem, &rOrigItem) ) + // ptr compare: same used rOrigItem? + if (rMapEntry.aOriginal.getScPatternAttr() == pAttr) { - // Did anything change at all? use Item PtrCompare OK - if ( !areSfxPoolItemPtrsEqual(rMapEntry.pPoolItem, &rOrigItem) ) - { - rMapEntry.pPoolItem->AddRef(2); // One for the cache - pPool->DirectPutItemInPool( rOrigItem ); //FIXME: AddRef? - } - return *rMapEntry.pPoolItem; + return rMapEntry.aModified; } } // Insert the new attributes in a new Set - std::unique_ptr<ScPatternAttr> pNewItem(rOrigItem.Clone()); - if ( pItemToPut ) + ScPatternAttr* pNewItem(new ScPatternAttr(*pAttr)); + + if (nullptr != aItemToPut.getItem()) { - pNewItem->GetItemSet().Put( *pItemToPut ); - DBG_ASSERT( areSfxPoolItemPtrsEqual(&pNewItem->GetItemSet().Get( pItemToPut->Which() ), pItemToPut), - "wrong item in temporary set" ); + pNewItem->GetItemSet().Put(*aItemToPut.getItem()); } else - pNewItem->GetItemSet().Put( *pSetToPut ); - const ScPatternAttr* pNewPoolItem = &pPool->DirectPutItemInPool( std::move(pNewItem) ); - - // Adapt refcount; one each for the cache - pNewPoolItem->AddRef( !areSfxPoolItemPtrsEqual(pNewPoolItem, &rOrigItem) ? 2 : 1 ); - pPool->DirectPutItemInPool( rOrigItem ); //FIXME: AddRef? - - // Add the transformation to the cache - SfxItemModifyImpl aModify; - aModify.pOrigItem = &rOrigItem; - aModify.pPoolItem = const_cast<ScPatternAttr*>(pNewPoolItem); - m_aCache.push_back( aModify ); - - DBG_ASSERT( !pItemToPut || - areSfxPoolItemPtrsEqual(&pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ), pItemToPut), - "wrong item in resulting set" ); + { + pNewItem->GetItemSet().Put(*pSetToPut); + } - return *pNewPoolItem; + m_aCache.emplace_back(rOrigItem, CellAttributeHolder(pNewItem, true)); + return m_aCache.back().aModified; } diff --git a/sc/source/core/data/stlpool.cxx b/sc/source/core/data/stlpool.cxx index 6fa08b8112de..53413b9f5234 100644 --- a/sc/source/core/data/stlpool.cxx +++ b/sc/source/core/data/stlpool.cxx @@ -120,7 +120,8 @@ void ScStyleSheetPool::Remove( SfxStyleSheetBase* pStyle ) OSL_ENSURE( SfxStyleSearchBits::UserDefined & pStyle->GetMask(), "SfxStyleSearchBits::UserDefined not set!" ); - static_cast<ScDocumentPool&>(rPool).StyleDeleted(static_cast<ScStyleSheet*>(pStyle)); + assert(nullptr != pDoc); + pDoc->getCellAttributeHelper().CellStyleDeleted(static_cast<ScStyleSheet&>(*pStyle)); SfxStyleSheetPool::Remove(pStyle); } } diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index ec7f96731ac6..b995aec2e7b4 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -439,7 +439,7 @@ void ScTable::DeleteArea( if ( IsProtected() && (nDelFlag & InsertDeleteFlags::ATTRIB) ) { - ScPatternAttr aPattern(rDocument.GetPool()); + ScPatternAttr aPattern(rDocument.getCellAttributeHelper()); aPattern.GetItemSet().Put( ScProtectionAttr( false ) ); ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern ); } @@ -476,11 +476,10 @@ void ScTable::DeleteSelection( InsertDeleteFlags nDelFlag, const ScMarkData& rMa if ( IsProtected() && (nDelFlag & InsertDeleteFlags::ATTRIB) ) { - ScDocumentPool* pPool = rDocument.GetPool(); - SfxItemSetFixed<ATTR_PATTERN_START, ATTR_PATTERN_END> aSet( *pPool ); + SfxItemSetFixed<ATTR_PATTERN_START, ATTR_PATTERN_END> aSet(*rDocument.GetPool()); aSet.Put( ScProtectionAttr( false ) ); - ScItemPoolCache aCache( pPool, &aSet ); - ApplySelectionCache( &aCache, rMark ); + ScItemPoolCache aCache(rDocument.getCellAttributeHelper(), aSet ); + ApplySelectionCache( aCache, rMark ); } // TODO: In the future we may want to check if the table has been @@ -773,7 +772,7 @@ void ScTable::CopyFromClip( // Do not set protected cell in a protected sheet if (IsProtected() && (rCxt.getInsertFlag() & InsertDeleteFlags::ATTRIB)) { - ScPatternAttr aPattern(rDocument.GetPool()); + ScPatternAttr aPattern(rDocument.getCellAttributeHelper()); aPattern.GetItemSet().Put( ScProtectionAttr( false ) ); ApplyPatternArea( nCol1, nRow1, nCol2, nRow2, aPattern ); } @@ -1057,7 +1056,8 @@ void ScTable::TransposeColPatterns(ScTable* pTransClip, SCCOL nCol1, SCCOL nCol, std::unique_ptr<ScAttrIterator> pAttrIter(aCol[nCol].CreateAttrIterator( nRow1, nRow2 )); while ( (pPattern = pAttrIter->Next( nAttrRow1, nAttrRow2 )) != nullptr ) { - if ( !IsDefaultItem( pPattern ) ) + // ptr compare OK, was so before + if (&rDocument.getCellAttributeHelper().getDefaultCellAttribute() != pPattern) { const SfxItemSet& rSet = pPattern->GetItemSet(); if ( rSet.GetItemState( ATTR_MERGE, false ) == SfxItemState::DEFAULT && @@ -2932,13 +2932,11 @@ void ScTable::ApplyPatternArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, namespace { - std::vector<ScAttrEntry> duplicateScAttrEntries(ScDocument& rDocument, const std::vector<ScAttrEntry>& rOrigData) + std::vector<ScAttrEntry> duplicateScAttrEntries(const std::vector<ScAttrEntry>& rOrigData) { + // this can now just be copied, will do the right thing with the + // ref-counted ScAttrEntry instances std::vector<ScAttrEntry> aData(rOrigData); - for (size_t nIdx = 0; nIdx < aData.size(); ++nIdx) - { - aData[nIdx].pPattern = &rDocument.GetPool()->DirectPutItemInPool(*aData[nIdx].pPattern); - } return aData; } } @@ -2954,7 +2952,7 @@ void ScTable::SetAttrEntries( SCCOL nStartCol, SCCOL nEndCol, std::vector<ScAttr // If we would like set all columns to same attrs, then change only attrs for not existing columns nEndCol = aCol.size() - 1; for (SCCOL i = nStartCol; i <= nEndCol; i++) - aCol[i].SetAttrEntries(duplicateScAttrEntries(rDocument, vNewData)); + aCol[i].SetAttrEntries(duplicateScAttrEntries(vNewData)); aDefaultColData.SetAttrEntries(std::move(vNewData)); } else @@ -2967,7 +2965,7 @@ void ScTable::SetAttrEntries( SCCOL nStartCol, SCCOL nEndCol, std::vector<ScAttr { CreateColumnIfNotExists( nEndCol ); for (SCCOL i = nStartCol; i < nEndCol; i++) // all but last need a copy - aCol[i].SetAttrEntries(duplicateScAttrEntries(rDocument, vNewData)); + aCol[i].SetAttrEntries(duplicateScAttrEntries(vNewData)); aCol[nEndCol].SetAttrEntries( std::move(vNewData)); } } @@ -3021,7 +3019,7 @@ void ScTable::RemoveCondFormatData( const ScRangeList& rRangeList, sal_uInt32 nI void ScTable::SetPatternAreaCondFormat( SCCOL nCol, SCROW nStartRow, SCROW nEndRow, const ScPatternAttr& rAttr, const ScCondFormatIndexes& rCondFormatIndexes ) { - CreateColumnIfNotExists(nCol).SetPatternArea( nStartRow, nEndRow, rAttr); + CreateColumnIfNotExists(nCol).SetPatternArea( nStartRow, nEndRow, CellAttributeHolder(&rAttr)); for (const auto& rIndex : rCondFormatIndexes) { @@ -3217,11 +3215,10 @@ void ScTable::SetPattern( const ScAddress& rPos, const ScPatternAttr& rAttr ) CreateColumnIfNotExists(rPos.Col()).SetPattern(rPos.Row(), rAttr); } -const ScPatternAttr* ScTable::SetPattern( SCCOL nCol, SCROW nRow, std::unique_ptr<ScPatternAttr> pAttr ) +void ScTable::SetPattern( SCCOL nCol, SCROW nRow, const CellAttributeHolder& rHolder ) { if (ValidColRow(nCol,nRow)) - return CreateColumnIfNotExists(nCol).SetPattern(nRow, std::move(pAttr)); - return nullptr; + CreateColumnIfNotExists(nCol).SetPattern(nRow, rHolder); } void ScTable::SetPattern( SCCOL nCol, SCROW nRow, const ScPatternAttr& rAttr ) @@ -3236,7 +3233,7 @@ void ScTable::ApplyAttr( SCCOL nCol, SCROW nRow, const SfxPoolItem& rAttr ) CreateColumnIfNotExists(nCol).ApplyAttr( nRow, rAttr ); } -void ScTable::ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rMark, +void ScTable::ApplySelectionCache( ScItemPoolCache& rCache, const ScMarkData& rMark, ScEditDataArray* pDataArray, bool* const pIsChanged ) { if(!rMark.GetTableSelect(nTab)) @@ -3248,7 +3245,7 @@ void ScTable::ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rM lastChangeCol = rMark.GetStartOfEqualColumns( GetDoc().MaxCol(), aCol.size()) - 1; if( lastChangeCol >= 0 ) CreateColumnIfNotExists(lastChangeCol); // Allocate needed different columns before changing the default. - aDefaultColData.ApplySelectionCache( pCache, rMark, pDataArray, pIsChanged, GetDoc().MaxCol()); + aDefaultColData.ApplySelectionCache( rCache, rMark, pDataArray, pIsChanged, GetDoc().MaxCol()); } else // need to allocate all columns affected { @@ -3257,7 +3254,7 @@ void ScTable::ApplySelectionCache( ScItemPoolCache* pCache, const ScMarkData& rM } for (SCCOL i=0; i <= lastChangeCol; i++) - aCol[i].ApplySelectionCache( pCache, rMark, pDataArray, pIsChanged ); + aCol[i].ApplySelectionCache( rCache, rMark, pDataArray, pIsChanged ); } void ScTable::ChangeSelectionIndent( bool bIncrement, const ScMarkData& rMark ) diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index 359cc5dcc4f5..05be5597d60a 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -238,9 +238,9 @@ public: const sc::CellTextAttr* mpAttr; const ScPostIt* mpNote; std::vector<SdrObject*> maDrawObjects; - const ScPatternAttr* mpPattern; + CellAttributeHolder maPattern; - Cell() : mpAttr(nullptr), mpNote(nullptr), mpPattern(nullptr) {} + Cell() : mpAttr(nullptr), mpNote(nullptr), maPattern() {} }; struct Row @@ -441,7 +441,7 @@ void initDataRows( rCell.maDrawObjects = aRowDrawObjects[nRow]; if (!bUniformPattern && bPattern) - rCell.mpPattern = rCol.GetPattern(nRow); + rCell.maPattern.setScPatternAttr(rCol.GetPattern(nRow)); } } @@ -543,7 +543,7 @@ namespace { struct SortedColumn { - typedef mdds::flat_segment_tree<SCROW, const ScPatternAttr*> PatRangeType; + typedef mdds::flat_segment_tree<SCROW, CellAttributeHolder> PatRangeType; sc::CellStoreType maCells; sc::CellTextAttrStoreType maCellTextAttrs; @@ -565,9 +565,9 @@ struct SortedColumn maPatterns(0, rSheetLimits.GetMaxRowCount(), nullptr), miPatternPos(maPatterns.begin()) {} - void setPattern( SCROW nRow, const ScPatternAttr* pPat ) + void setPattern( SCROW nRow, const CellAttributeHolder& rPat ) { - miPatternPos = maPatterns.insert(miPatternPos, nRow, nRow+1, pPat).first; + miPatternPos = maPatterns.insert(miPatternPos, nRow, nRow+1, rPat).first; } }; @@ -611,10 +611,10 @@ struct PatternSpan { SCROW mnRow1; SCROW mnRow2; - const ScPatternAttr* mpPattern; + CellAttributeHolder maPattern; - PatternSpan( SCROW nRow1, SCROW nRow2, const ScPatternAttr* pPat ) : - mnRow1(nRow1), mnRow2(nRow2), mpPattern(pPat) {} + PatternSpan( SCROW nRow1, SCROW nRow2, const CellAttributeHolder& rPat ) : + mnRow1(nRow1), mnRow2(nRow2), maPattern(rPat) {} }; } @@ -809,8 +809,8 @@ void fillSortedColumnArray( // Add cell anchored images aSortedCols.at(j)->maCellDrawObjects.push_back(rCell.maDrawObjects); - if (rCell.mpPattern) - aSortedCols.at(j)->setPattern(nRow, rCell.mpPattern); + if (rCell.maPattern) + aSortedCols.at(j)->setPattern(nRow, rCell.maPattern); } if (!bOnlyDataAreaExtras && pArray->IsKeepQuery()) @@ -1186,19 +1186,12 @@ void ScTable::SortReorderByRow( ScSortInfoArray* pArray, SCCOL nCol1, SCCOL nCol { // Get all row spans where the pattern is not NULL. std::vector<PatternSpan> aSpans = - sc::toSpanArrayWithValue<SCROW,const ScPatternAttr*,PatternSpan>( + sc::toSpanArrayWithValue<SCROW, CellAttributeHolder, PatternSpan>( aSortedCols[i]->maPatterns); for (const auto& rSpan : aSpans) { - assert(rSpan.mpPattern); // should never be NULL. - rDocument.GetPool()->DirectPutItemInPool(*rSpan.mpPattern); - } - - for (const auto& rSpan : aSpans) - { - aCol[nThisCol].SetPatternArea(rSpan.mnRow1, rSpan.mnRow2, *rSpan.mpPattern); - rDocument.GetPool()->DirectRemoveItemFromPool(*rSpan.mpPattern); + aCol[nThisCol].SetPatternArea(rSpan.mnRow1, rSpan.mnRow2, rSpan.maPattern); } } @@ -1387,19 +1380,12 @@ void ScTable::SortReorderByRowRefUpdate( { // Get all row spans where the pattern is not NULL. std::vector<PatternSpan> aSpans = - sc::toSpanArrayWithValue<SCROW,const ScPatternAttr*,PatternSpan>( + sc::toSpanArrayWithValue<SCROW, CellAttributeHolder, PatternSpan>( aSortedCols[i]->maPatterns); for (const auto& rSpan : aSpans) { - assert(rSpan.mpPattern); // should never be NULL. - rDocument.GetPool()->DirectPutItemInPool(*rSpan.mpPattern); - } - - for (const auto& rSpan : aSpans) - { - aCol[nThisCol].SetPatternArea(rSpan.mnRow1, rSpan.mnRow2, *rSpan.mpPattern); - rDocument.GetPool()->DirectRemoveItemFromPool(*rSpan.mpPattern); + aCol[nThisCol].SetPatternArea(rSpan.mnRow1, rSpan.mnRow2, rSpan.maPattern); } } @@ -2045,11 +2031,11 @@ static void lcl_RemoveNumberFormat( ScTable* pTab, SCCOL nCol, SCROW nRow ) if ( pPattern->GetItemSet().GetItemState( ATTR_VALUE_FORMAT, false ) == SfxItemState::SET ) { - auto pNewPattern = std::make_unique<ScPatternAttr>( *pPattern ); + ScPatternAttr* pNewPattern(new ScPatternAttr( *pPattern )); SfxItemSet& rSet = pNewPattern->GetItemSet(); rSet.ClearItem( ATTR_VALUE_FORMAT ); rSet.ClearItem( ATTR_LANGUAGE_FORMAT ); - pTab->SetPattern( nCol, nRow, std::move(pNewPattern) ); + pTab->SetPattern( nCol, nRow, CellAttributeHolder(pNewPattern, true) ); } } diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 2d53f46337ae..e7cc13734511 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -1006,7 +1006,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, if ( bVertical && nISrcStart == nISrcEnd && !bHasFiltered ) { // set all attributes at once (en bloc) - if (pNewPattern || !SfxPoolItem::areSame(pSrcPattern, rDocument.GetDefPattern())) + if (pNewPattern || !pSrcPattern->isDefault()) { // Default is already present (DeleteArea) SCROW nY1 = static_cast<SCROW>(std::min( nIStart, nIEnd )); @@ -1037,7 +1037,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, DeleteArea(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), InsertDeleteFlags::AUTOFILL); - if ( !SfxPoolItem::areSame(pSrcPattern, aCol[nCol].GetPattern( static_cast<SCROW>(nRow) ) ) ) + if ( !ScPatternAttr::areSame(pSrcPattern, aCol[nCol].GetPattern( static_cast<SCROW>(nRow) ) ) ) { // Transfer template too //TODO: Merge ApplyPattern to AttrArray ?? @@ -2697,7 +2697,7 @@ void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW std::unique_ptr<ScPatternAttr> pPatternAttrs[16]; for (sal_uInt8 i = 0; i < 16; ++i) { - pPatternAttrs[i].reset(new ScPatternAttr(rDocument.GetPool())); + pPatternAttrs[i].reset(new ScPatternAttr(rDocument.getCellAttributeHelper())); pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSet(), rDocument); } diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index a46b09986b3d..9d97fe48c109 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -791,7 +791,7 @@ sal_uLong lclGetCellFormat( const ScDocument& rDoc, const ScAddress& rPos ) { const ScPatternAttr* pPattern = rDoc.GetPattern( rPos.Col(), rPos.Row(), rPos.Tab() ); if( !pPattern ) - pPattern = rDoc.GetDefPattern(); + pPattern = &rDoc.getCellAttributeHelper().getDefaultCellAttribute(); return pPattern->GetNumberFormat( rDoc.GetFormatTable() ); } diff --git a/sc/source/core/tool/ddelink.cxx b/sc/source/core/tool/ddelink.cxx index 5000e0bf8769..4c854321509e 100644 --- a/sc/source/core/tool/ddelink.cxx +++ b/sc/source/core/tool/ddelink.cxx @@ -168,9 +168,7 @@ sfx2::SvBaseLink::UpdateResult ScDdeLink::DataChanged( sal_uLong nStdFormat = 0; if ( nMode == SC_DDE_DEFAULT ) { - ScPatternAttr* pDefPattern = rDoc.GetDefPattern(); // contains standard template - if ( pDefPattern ) - nStdFormat = pDefPattern->GetNumberFormat( pFormatter ); + nStdFormat = rDoc.getCellAttributeHelper().getDefaultCellAttribute().GetNumberFormat( pFormatter ); } else if ( nMode == SC_DDE_ENGLISH ) nStdFormat = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US); diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 57e93d513866..33fa00f8cc9a 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -741,7 +741,8 @@ ScTabEditEngine::ScTabEditEngine( ScDocument* pDoc ) : ScFieldEditEngine( pDoc, pDoc->GetEnginePool() ) { SetEditTextObjectPool( pDoc->GetEditPool() ); - Init(pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)); + const ScPatternAttr& rScPatternAttr(pDoc->getCellAttributeHelper().getDefaultCellAttribute()); + Init(rScPatternAttr); } ScTabEditEngine::ScTabEditEngine( const ScPatternAttr& rPattern, diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index e372228721e3..eeb4cc6b1b9e 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -2416,7 +2416,7 @@ void ScInterpreter::ScCell() pPrinter->SetMapMode(MapMode(MapUnit::MapTwip)); // font color doesn't matter here - mrDoc.GetDefPattern()->fillFontOnly(aDefFont, pPrinter); + mrDoc.getCellAttributeHelper().getDefaultCellAttribute().fillFontOnly(aDefFont, pPrinter); pPrinter->SetFont(aDefFont); tools::Long nZeroWidth = pPrinter->GetTextWidth( OUString( '0' ) ); assert(nZeroWidth != 0); diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx index 224cb998fb1a..4007d6f66511 100644 --- a/sc/source/filter/dif/difimp.cxx +++ b/sc/source/filter/dif/difimp.cxx @@ -629,7 +629,7 @@ void DifColumn::NewEntry( const SCROW nPos, const sal_uInt32 nNumFormat ) void DifColumn::Apply( ScDocument& rDoc, const SCCOL nCol, const SCTAB nTab ) { - ScPatternAttr aAttr( rDoc.GetPool() ); + ScPatternAttr aAttr(rDoc.getCellAttributeHelper()); SfxItemSet &rItemSet = aAttr.GetItemSet(); for (const auto& rEntry : maEntries) diff --git a/sc/source/filter/excel/xehelper.cxx b/sc/source/filter/excel/xehelper.cxx index aa21902dfb73..649219f89bdb 100644 --- a/sc/source/filter/excel/xehelper.cxx +++ b/sc/source/filter/excel/xehelper.cxx @@ -373,7 +373,9 @@ XclExpStringRef lclCreateFormattedString( // font buffer and cell item set XclExpFontBuffer& rFontBuffer = rRoot.GetFontBuffer(); - const SfxItemSet& rItemSet = pCellAttr ? pCellAttr->GetItemSet() : rRoot.GetDoc().GetDefPattern()->GetItemSet(); + const SfxItemSet& rItemSet = pCellAttr ? + pCellAttr->GetItemSet() : + rRoot.GetDoc().getCellAttributeHelper().getDefaultCellAttribute().GetItemSet(); // process all script portions sal_Int32 nPortionPos = 0; @@ -587,7 +589,9 @@ XclExpStringRef XclExpStringHelper::CreateCellString( bool bOldUpdateMode = rEE.SetUpdateLayout( true ); // default items - const SfxItemSet& rItemSet = pCellAttr ? pCellAttr->GetItemSet() : rRoot.GetDoc().GetDefPattern()->GetItemSet(); + const SfxItemSet& rItemSet = pCellAttr ? + pCellAttr->GetItemSet() : + rRoot.GetDoc().getCellAttributeHelper().getDefaultCellAttribute().GetItemSet(); auto pEEItemSet = std::make_unique<SfxItemSet>( rEE.GetEmptyItemSet() ); ScPatternAttr::FillToEditItemSet( *pEEItemSet, rItemSet ); rEE.SetDefaults( std::move(pEEItemSet) ); // edit engine takes ownership diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx index 678327bd1a58..6ee407c369f9 100644 --- a/sc/source/filter/excel/xestyle.cxx +++ b/sc/source/filter/excel/xestyle.cxx @@ -2810,12 +2810,11 @@ XclExpXFBuffer::FindKey XclExpXFBuffer::ToFindKey(XclExpXF const & rRec) sal_uInt32 XclExpXFBuffer::InsertCellXF( const ScPatternAttr* pPattern, sal_Int16 nScript, sal_uInt32 nForceScNumFmt, sal_uInt16 nForceXclFont, bool bForceLineBreak ) { - const ScPatternAttr* pDefPattern = GetDoc().GetDefPattern(); if( !pPattern ) - pPattern = pDefPattern; + pPattern = &GetDoc().getCellAttributeHelper().getDefaultCellAttribute(); // special handling for default cell formatting - if( SfxPoolItem::areSame(pPattern, pDefPattern) && !bForceLineBreak && + if ( pPattern->isDefault() && !bForceLineBreak && (nForceScNumFmt == NUMBERFORMAT_ENTRY_NOT_FOUND) && (nForceXclFont == EXC_FONT_NOTFOUND) ) { diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index 32a6ec04a4d8..014ada4d9490 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -942,7 +942,7 @@ void XclImpValidationManager::Apply() DVItem& rItem = *rxDVItem; // set the handle ID sal_uInt32 nHandle = rDoc.AddValidationEntry( rItem.maValidData ); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nHandle ) ); // apply all ranges diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx index 21b86a4ed4fa..15ce0ce667c4 100644 --- a/sc/source/filter/excel/xistyle.cxx +++ b/sc/source/filter/excel/xistyle.cxx @@ -1249,7 +1249,7 @@ const ScPatternAttr& XclImpXF::CreatePattern( bool bSkipPoolDefs ) return *mpPattern; // create new pattern attribute set - mpPattern.reset( new ScPatternAttr( GetDoc().GetPool() ) ); + mpPattern.reset( new ScPatternAttr(GetDoc().getCellAttributeHelper()) ); SfxItemSet& rItemSet = mpPattern->GetItemSet(); XclImpXF* pParentXF = IsCellXF() ? GetXFBuffer().GetXF( mnParent ) : nullptr; @@ -1376,7 +1376,7 @@ void XclImpXF::ApplyPatternToAttrVector( if (nForceScNumFmt != NUMBERFORMAT_ENTRY_NOT_FOUND) { - ScPatternAttr aNumPat(rDoc.GetPool()); + ScPatternAttr aNumPat(rDoc.getCellAttributeHelper()); GetNumFmtBuffer().FillScFmtToItemSet(aNumPat.GetItemSet(), nForceScNumFmt); rPat.GetItemSet().Put(aNumPat.GetItemSet()); } @@ -1399,13 +1399,13 @@ void XclImpXF::ApplyPatternToAttrVector( // Fill this gap with the default pattern. ScAttrEntry aEntry; aEntry.nEndRow = nRow1 - 1; - aEntry.pPattern = rDoc.GetDefPattern(); + aEntry.setScPatternAttr(&rDoc.getCellAttributeHelper().getDefaultCellAttribute()); rAttrs.push_back(aEntry); } ScAttrEntry aEntry; aEntry.nEndRow = nRow2; - aEntry.pPattern = &rDoc.GetPool()->DirectPutItemInPool(rPat); + aEntry.setScPatternAttr(&rPat, false); rAttrs.push_back(aEntry); } @@ -2022,7 +2022,7 @@ void XclImpXFRangeBuffer::Finalize() { ScAttrEntry aEntry; aEntry.nEndRow = rDoc.MaxRow(); - aEntry.pPattern = rDoc.GetDefPattern(); + aEntry.setScPatternAttr(&rDoc.getCellAttributeHelper().getDefaultCellAttribute()); aAttrs.push_back(aEntry); } diff --git a/sc/source/filter/inc/xistyle.hxx b/sc/source/filter/inc/xistyle.hxx index b4e5250dc37f..b7ed707f9822 100644 --- a/sc/source/filter/inc/xistyle.hxx +++ b/sc/source/filter/inc/xistyle.hxx @@ -29,7 +29,7 @@ class ScPatternAttr; struct XclRange; -struct ScAttrEntry; +class ScAttrEntry; enum class SvxBoxItemLine; /* ============================================================================ diff --git a/sc/source/filter/lotus/lotattr.cxx b/sc/source/filter/lotus/lotattr.cxx index 458e3c677b62..995e244f4c7b 100644 --- a/sc/source/filter/lotus/lotattr.cxx +++ b/sc/source/filter/lotus/lotattr.cxx @@ -88,7 +88,7 @@ const ScPatternAttr& LotAttrCache::GetPattAttr( const LotAttrWK3& rAttr ) return *((*iter)->pPattAttr); // generate new Pattern Attribute - ScPatternAttr* pNewPatt = new ScPatternAttr(pDocPool); + ScPatternAttr* pNewPatt = new ScPatternAttr(mrContext.rDoc.getCellAttributeHelper()); SfxItemSet& rItemSet = pNewPatt->GetItemSet(); ENTRY *pCurrent = new ENTRY( std::unique_ptr<ScPatternAttr>(pNewPatt) ); @@ -189,7 +189,7 @@ void LotAttrCol::SetAttr( const ScDocument* pDoc, const SCROW nRow, const ScPatt if(iterLast != aEntries.rend()) { - if( ( (*iterLast)->nLastRow == nRow - 1 ) && SfxPoolItem::areSame( &rAttr, (*iterLast)->pPattAttr ) ) + if( ( (*iterLast)->nLastRow == nRow - 1 ) && ScPatternAttr::areSame( &rAttr, (*iterLast)->pPattAttr ) ) (*iterLast)->nLastRow = nRow; else { diff --git a/sc/source/filter/lotus/op.cxx b/sc/source/filter/lotus/op.cxx index 58007a518325..c1f11736e8f3 100644 --- a/sc/source/filter/lotus/op.cxx +++ b/sc/source/filter/lotus/op.cxx @@ -535,7 +535,7 @@ void OP_CreatePattern123(LotusContext& rContext, SvStream& r, sal_uInt16 n) { sal_uInt16 nCode; - ScPatternAttr aPattern(rContext.rDoc.GetPool()); + ScPatternAttr aPattern(rContext.rDoc.getCellAttributeHelper()); SfxItemSet& rItemSet = aPattern.GetItemSet(); r.ReadUInt16( nCode ); diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx index 98d50c2a05c3..f42694f5623a 100644 --- a/sc/source/filter/oox/sheetdatabuffer.cxx +++ b/sc/source/filter/oox/sheetdatabuffer.cxx @@ -508,7 +508,7 @@ void SheetDataBuffer::finalizeImport() nScRow++; } if ( !pDefPattern || nScRow == rDoc.MaxRow() ) - pDefPattern = rDoc.GetDefPattern(); + pDefPattern = &rDoc.getCellAttributeHelper().getDefaultCellAttribute(); Xf::AttrList aAttrs(pDefPattern); for ( const auto& rRowStyle : rRowStyles ) @@ -523,11 +523,10 @@ void SheetDataBuffer::finalizeImport() { ScAttrEntry aEntry; aEntry.nEndRow = rDoc.MaxRow(); - aEntry.pPattern = pDefPattern; - rDoc.GetPool()->DirectPutItemInPool(*aEntry.pPattern); + aEntry.setScPatternAttr(pDefPattern, false); aAttrs.maAttrs.push_back(aEntry); - if (!sc::NumFmtUtil::isLatinScript(*aEntry.pPattern, rDoc)) + if (!sc::NumFmtUtil::isLatinScript(*aEntry.getScPatternAttr(), rDoc)) aAttrs.mbLatinNumFmtOnly = false; } diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index f31cde38bcff..22ebb2025833 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -2140,7 +2140,7 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal } if ( !pCachedPattern && nNumFmtId >= 0 ) { - ScPatternAttr aNumPat(rDoc.GetPool()); + ScPatternAttr aNumPat(rDoc.getCellAttributeHelper()); mnScNumFmt = getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId, false ); rPat.GetItemSet().Put(aNumPat.GetItemSet()); } @@ -2166,24 +2166,24 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal // Fill this gap with the default pattern. ScAttrEntry aEntry; aEntry.nEndRow = nRow1 - 1; - aEntry.pPattern = &rDoc.GetPool()->DirectPutItemInPool(*rAttrs.mpDefPattern); + aEntry.setScPatternAttr(rAttrs.mpDefPattern, false); rAttrs.maAttrs.push_back(aEntry); // Check if the default pattern is 'General'. - if (!rDocImport.isLatinScript(*aEntry.pPattern)) + if (!rDocImport.isLatinScript(*aEntry.getScPatternAttr())) rAttrs.mbLatinNumFmtOnly = false; } ScAttrEntry aEntry; aEntry.nEndRow = nRow2; - aEntry.pPattern = &rDoc.GetPool()->DirectPutItemInPool(rPat); + aEntry.setScPatternAttr(&rPat, false); // Put the allocated pattern to cache if (!pCachedPattern) - rCache.add(nXfId, nNumFmtId, const_cast<ScPatternAttr*>(aEntry.pPattern)); + rCache.add(nXfId, nNumFmtId, const_cast<ScPatternAttr*>(aEntry.getScPatternAttr())); rAttrs.maAttrs.push_back(aEntry); - if (!rDocImport.isLatinScript(*aEntry.pPattern)) + if (!rDocImport.isLatinScript(*aEntry.getScPatternAttr())) rAttrs.mbLatinNumFmtOnly = false; } @@ -2218,7 +2218,7 @@ Xf::createPattern( bool bSkipPoolDefs ) { if( mpPattern ) return *mpPattern; - mpPattern.reset( new ::ScPatternAttr( getScDocument().GetPool() ) ); + mpPattern.reset( new ::ScPatternAttr(getScDocument().getCellAttributeHelper()) ); SfxItemSet& rItemSet = mpPattern->GetItemSet(); /* Enables the used flags, if the formatting attributes differ from the style XF. In cell XFs Excel uses the cell attributes, if they differ diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index f9e78e27f4b1..af425079708d 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -1255,7 +1255,7 @@ void ScOrcusSheet::set_format(os::row_t row, os::col_t col, size_t xf_index) { SAL_INFO("sc.orcus.style", "set format: " << xf_index); - ScPatternAttr aPattern(mrDoc.getDoc().GetPool()); + ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper()); mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index); mrDoc.getDoc().ApplyPattern(col, row, mnTab, aPattern); } @@ -1264,7 +1264,7 @@ void ScOrcusSheet::set_format(os::row_t row_start, os::col_t col_start, os::row_t row_end, os::col_t col_end, size_t xf_index) { SAL_INFO("sc.orcus.style", "set format range: " << xf_index); - ScPatternAttr aPattern(mrDoc.getDoc().GetPool()); + ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper()); mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index); mrDoc.getDoc().ApplyPatternAreaTab(col_start, row_start, col_end, row_end, mnTab, aPattern); } @@ -1272,7 +1272,7 @@ void ScOrcusSheet::set_format(os::row_t row_start, os::col_t col_start, void ScOrcusSheet::set_column_format( os::col_t col, os::col_t col_span, std::size_t xf_index) { - ScPatternAttr aPattern(mrDoc.getDoc().GetPool()); + ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper()); mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index); mrDoc.getDoc().ApplyPatternAreaTab( @@ -1281,7 +1281,7 @@ void ScOrcusSheet::set_column_format( void ScOrcusSheet::set_row_format(os::row_t row, std::size_t xf_index) { - ScPatternAttr aPattern(mrDoc.getDoc().GetPool()); + ScPatternAttr aPattern(mrDoc.getDoc().getCellAttributeHelper()); mrStyles.applyXfToItemSet(aPattern.GetItemSet(), xf_index); mrDoc.getDoc().ApplyPatternAreaTab( diff --git a/sc/source/filter/qpro/qprostyle.cxx b/sc/source/filter/qpro/qprostyle.cxx index a23187c477b2..5889e5f1c8d1 100644 --- a/sc/source/filter/qpro/qprostyle.cxx +++ b/sc/source/filter/qpro/qprostyle.cxx @@ -40,7 +40,7 @@ void ScQProStyle::SetFormat( ScDocument *pDoc, sal_uInt8 nCol, sal_uInt16 nRow, if (nStyle >= maxsize) return; - ScPatternAttr aPattern(pDoc->GetPool()); + ScPatternAttr aPattern(pDoc->getCellAttributeHelper()); SfxItemSet& rItemSet = aPattern.GetItemSet(); sal_uInt8 nTmp = maAlign[ nStyle ]; diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx index 70562308120f..446f6850f4da 100644 --- a/sc/source/filter/rtf/eeimpars.cxx +++ b/sc/source/filter/rtf/eeimpars.cxx @@ -143,7 +143,6 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu // Automatic language option selected. Check for the global 'use US English' option. bNumbersEnglishUS = officecfg::Office::Common::Filter::HTML::Import::NumbersEnglishUS::get(); } - ScDocumentPool* pDocPool = mpDoc->GetPool(); ScRangeName* pRangeNames = mpDoc->GetRangeName(); for ( size_t i = 0, n = mpParser->ListSize(); i < n; ++i ) { @@ -218,7 +217,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu } // Set attributes - auto pAttr = std::make_unique<ScPatternAttr>( pDocPool ); + ScPatternAttr* pAttr(new ScPatternAttr(mpDoc->getCellAttributeHelper())); pAttr->GetFromEditItemSet( &aSet ); SfxItemSet* pAttrItemSet = &pAttr->GetItemSet(); if (!aNumStr.isEmpty()) @@ -325,7 +324,9 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu const ScStyleSheet* pStyleSheet = mpDoc->GetPattern( nCol, nRow, nTab )->GetStyleSheet(); pAttr->SetStyleSheet( const_cast<ScStyleSheet*>(pStyleSheet) ); - auto rAttrItemSet2 = mpDoc->SetPattern( nCol, nRow, nTab, std::move(pAttr) )->GetItemSet(); + CellAttributeHolder aHolder(pAttr, true); + mpDoc->SetPattern( nCol, nRow, nTab, aHolder); + const SfxItemSet& rAttrItemSet2(aHolder.getScPatternAttr()->GetItemSet()); // Add data if (bSimple) diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index 6c739dc42304..c7d21dfc3a17 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -795,7 +795,7 @@ void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange ) sal_uInt32 nIndex = pDoc->AddValidationEntry( aScValidationData ); - ScPatternAttr aPattern( pDoc->GetPool() ); + ScPatternAttr aPattern(pDoc->getCellAttributeHelper()); aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) ); if( rScRange.aStart == rScRange.aEnd ) //for a single cell { diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 60fa7ba71741..ea1445450a19 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -605,8 +605,8 @@ void ScXMLImport::ExamineDefaultStyle() // #i62435# after inserting the styles, check if the default style has a latin-script-only // number format (then, value cells can be pre-initialized with western script type) - const ScPatternAttr* pDefPattern = pDoc->GetDefPattern(); - if (pDefPattern && sc::NumFmtUtil::isLatinScript(*pDefPattern, *pDoc)) + const ScPatternAttr& rDefPattern(pDoc->getCellAttributeHelper().getDefaultCellAttribute()); + if (sc::NumFmtUtil::isLatinScript(rDefPattern, *pDoc)) mpDocImport->setDefaultNumericScript(SvtScriptType::LATIN); } } diff --git a/sc/source/ui/Accessibility/AccessibleText.cxx b/sc/source/ui/Accessibility/AccessibleText.cxx index 3f7ff57f8f4a..52d5257af8cc 100644 --- a/sc/source/ui/Accessibility/AccessibleText.cxx +++ b/sc/source/ui/Accessibility/AccessibleText.cxx @@ -1131,15 +1131,29 @@ SvxTextForwarder* ScAccessibleHeaderTextData::GetTextForwarder() // default font must be set, independently of document // -> use global pool from module + std::unique_ptr<CellAttributeHelper> pTmp; + const ScPatternAttr* pCellAttributeDefault(nullptr); + + if (nullptr != mpDocSh) + { + // we can use default CellAttribute from ScDocument + pCellAttributeDefault = &mpDocSh->GetDocument().getCellAttributeHelper().getDefaultCellAttribute(); + } + else + { + // no access to ScDocument, use temporary CellAttributeHelper. + // also see ScHeaderFooterTextData::GetTextForwarder for more comments + pTmp.reset(new CellAttributeHelper(SC_MOD()->GetPool())); + pCellAttributeDefault = &pTmp->getDefaultCellAttribute(); + } SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() ); - const ScPatternAttr& rPattern = SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN); - rPattern.FillEditItemSet( &aDefaults ); + pCellAttributeDefault->FillEditItemSet( &aDefaults ); // FillEditItemSet adjusts font height to 1/100th mm, // but for header/footer twips is needed, as in the PatternAttr: - aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) ); - aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ); - aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) ); + aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) ); + aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ); + aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) ); aDefaults.Put( SvxAdjustItem( meAdjust, EE_PARA_JUST ) ); pHdrEngine->SetDefaults( aDefaults ); diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 809ba8520e33..4c627e4bac6a 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -2541,7 +2541,7 @@ bool ScInputHandler::StartTable( sal_Unicode cTyped, bool bFromCommand, bool bIn const ScPatternAttr* pPattern = rDoc.GetPattern( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab() ); - if (!SfxPoolItem::areSame(pPattern, pLastPattern)) + if (!ScPatternAttr::areSame(pPattern, pLastPattern)) { // Percent format? const SfxItemSet& rAttrSet = pPattern->GetItemSet(); @@ -3292,7 +3292,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode, bool bBeforeSavingInL if ( pCommonAttrs ) { ScDocument& rDoc = pActiveViewSh->GetViewData().GetDocument(); - pCellAttrs = std::make_unique<ScPatternAttr>(rDoc.GetPool()); + pCellAttrs = std::make_unique<ScPatternAttr>(rDoc.getCellAttributeHelper()); pCellAttrs->GetFromEditItemSet( &*pCommonAttrs ); } } diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index d31cfc675b64..3755aa7f7748 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -150,7 +150,8 @@ ScModule::ScModule( SfxObjectFactory* pFact ) : m_pMessagePool = new ScMessagePool; m_pMessagePool->FreezeIdRanges(); SetPool( m_pMessagePool.get() ); - ScGlobal::InitTextHeight( m_pMessagePool.get() ); + + ScGlobal::InitTextHeight( *m_pMessagePool ); StartListening( *SfxGetpApp() ); // for SfxHintId::Deinitializing diff --git a/sc/source/ui/cctrl/dpcontrol.cxx b/sc/source/ui/cctrl/dpcontrol.cxx index cbb1aaa456c8..3815aeb8cf69 100644 --- a/sc/source/ui/cctrl/dpcontrol.cxx +++ b/sc/source/ui/cctrl/dpcontrol.cxx @@ -138,7 +138,7 @@ void ScDPFieldButton::draw() { // use ScPatternAttr::GetFont only for font size vcl::Font aAttrFont; - mpDoc->GetPool()->GetDefaultItem(ATTR_PATTERN).fillFontOnly(aAttrFont, mpOutDev, &maZoomY); + mpDoc->getCellAttributeHelper().getDefaultCellAttribute().fillFontOnly(aAttrFont, mpOutDev, &maZoomY); aTextFont.SetFontSize(aAttrFont.GetFontSize()); } mpOutDev->SetFont(aTextFont); diff --git a/sc/source/ui/docshell/arealink.cxx b/sc/source/ui/docshell/arealink.cxx index 26e076bd1cdf..31636bd148af 100644 --- a/sc/source/ui/docshell/arealink.cxx +++ b/sc/source/ui/docshell/arealink.cxx @@ -389,7 +389,7 @@ bool ScAreaLink::Refresh( const OUString& rNewFile, const OUString& rNewFilter, { //! ResetAttrib at document !!! - ScPatternAttr aPattern( rSrcDoc.GetPool() ); + ScPatternAttr aPattern( rSrcDoc.getCellAttributeHelper() ); aPattern.GetItemSet().Put( ScMergeAttr() ); // Defaults aPattern.GetItemSet().Put( ScMergeFlagAttr() ); aClipDoc.ApplyPatternAreaTab( 0,0, rDoc.MaxCol(),rDoc.MaxRow(), nSrcTab, aPattern ); diff --git a/sc/source/ui/docshell/dbdocimp.cxx b/sc/source/ui/docshell/dbdocimp.cxx index 5b4dec1731bf..fb9f7909f24a 100644 --- a/sc/source/ui/docshell/dbdocimp.cxx +++ b/sc/source/ui/docshell/dbdocimp.cxx @@ -452,7 +452,7 @@ bool ScDBDocFunc::DoImport( SCTAB nTab, const ScImportParam& rParam, // don't set cell protection attribute if table is protected if (rDoc.IsTabProtected(nTab)) { - ScPatternAttr aPattern(pImportDoc->GetPool()); + ScPatternAttr aPattern(pImportDoc->getCellAttributeHelper()); aPattern.GetItemSet().Put( ScProtectionAttr( false,false,false,false ) ); pImportDoc->ApplyPatternAreaTab( 0,0,rDoc.MaxCol(),rDoc.MaxRow(), nTab, aPattern ); } diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 50dc53ec546f..73c3f6dd6738 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -1224,7 +1224,7 @@ void ScDocFunc::PutData( const ScAddress& rPos, ScEditEngineDefaulter& rEngine, return; const SfxItemSet& rEditAttr = aTester.GetAttribs(); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetFromEditItemSet( &rEditAttr ); aPattern.DeleteUnchanged( rDoc.GetPattern( rPos.Col(), rPos.Row(), rPos.Tab() ) ); aPattern.GetItemSet().ClearItem( ATTR_HOR_JUSTIFY ); // wasn't removed above if no edit object @@ -2770,7 +2770,7 @@ bool ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark, // #i51445# old merge flag attributes must be deleted also for single cells, // not only for whole columns/rows - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( ScMergeFlagAttr() ); rDoc.ApplyPatternArea( nExtendStartCol, nExtendStartRow, nMergeTestEndCol, nMergeTestEndRow, aMark, aPattern ); @@ -5096,7 +5096,7 @@ bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, bool bRecord, Sc } const SfxPoolItem& rDefAttr = rDoc.GetPool()->GetDefaultItem( ATTR_MERGE ); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( rDefAttr ); rDoc.ApplyPatternAreaTab( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), nTab, diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index a5638e6bfed2..826d8d7d995e 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -629,7 +629,7 @@ bool ScDocShell::Load( SfxMedium& rMedium ) // (for ConvertFrom, InitNew is called before) m_pDocument->MakeTable(0); m_pDocument->GetStyleSheetPool()->CreateStandardStyles(); - m_pDocument->UpdStlShtPtrsFrmNms(); + m_pDocument->getCellAttributeHelper().UpdateAllStyleSheets(*m_pDocument); /* Create styles that are imported through Orcus */ diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx index cf77e01774e5..5a8d161ff245 100644 --- a/sc/source/ui/docshell/docsh2.cxx +++ b/sc/source/ui/docshell/docsh2.cxx @@ -61,7 +61,7 @@ bool ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor ) if (ScStyleSheetPool* pStyleSheetPool = m_pDocument->GetStyleSheetPool()) { pStyleSheetPool->CreateStandardStyles(); - m_pDocument->UpdStlShtPtrsFrmNms(); + m_pDocument->getCellAttributeHelper().UpdateAllStyleSheets(*m_pDocument); /* Create styles that are imported through Orcus */ diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx index 96546d11a5fe..7cc56770c113 100644 --- a/sc/source/ui/docshell/docsh3.cxx +++ b/sc/source/ui/docshell/docsh3.cxx @@ -375,7 +375,7 @@ void ScDocShell::CalcOutputFactor() OUString aTestString( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789"); tools::Long nPrinterWidth = 0; - const ScPatternAttr* pPattern = &m_pDocument->GetPool()->GetDefaultItem(ATTR_PATTERN); + const ScPatternAttr& rPattern(m_pDocument->getCellAttributeHelper().getDefaultCellAttribute()); vcl::Font aDefFont; OutputDevice* pRefDev = GetRefDevice(); @@ -383,7 +383,7 @@ void ScDocShell::CalcOutputFactor() vcl::Font aOldFont = pRefDev->GetFont(); pRefDev->SetMapMode(MapMode(MapUnit::MapPixel)); - pPattern->fillFontOnly(aDefFont, pRefDev); // font color doesn't matter here + rPattern.fillFontOnly(aDefFont, pRefDev); // font color doesn't matter here pRefDev->SetFont(aDefFont); nPrinterWidth = pRefDev->PixelToLogic(Size(pRefDev->GetTextWidth(aTestString), 0), MapMode(MapUnit::Map100thMM)).Width(); pRefDev->SetFont(aOldFont); @@ -391,7 +391,7 @@ void ScDocShell::CalcOutputFactor() ScopedVclPtrInstance< VirtualDevice > pVirtWindow( *Application::GetDefaultDevice() ); pVirtWindow->SetMapMode(MapMode(MapUnit::MapPixel)); - pPattern->fillFontOnly(aDefFont, pVirtWindow); // font color doesn't matter here + rPattern.fillFontOnly(aDefFont, pVirtWindow); // font color doesn't matter here pVirtWindow->SetFont(aDefFont); double nWindowWidth = pVirtWindow->GetTextWidth(aTestString) / ScGlobal::nScreenPPTX; nWindowWidth = o3tl::convert(nWindowWidth, o3tl::Length::twip, o3tl::Length::mm100); diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx index e4cec9200c01..bb29a6ef6b76 100644 --- a/sc/source/ui/docshell/docsh5.cxx +++ b/sc/source/ui/docshell/docsh5.cxx @@ -829,11 +829,11 @@ SCTAB ScDocShell::MakeScenario( SCTAB nTab, const OUString& rName, const OUStrin //! test for filter / buttons / merging - ScPatternAttr aProtPattern( m_pDocument->GetPool() ); + ScPatternAttr aProtPattern(m_pDocument->getCellAttributeHelper()); aProtPattern.GetItemSet().Put( ScProtectionAttr( true ) ); m_pDocument->ApplyPatternAreaTab( 0,0, m_pDocument->MaxCol(),m_pDocument->MaxRow(), nNewTab, aProtPattern ); - ScPatternAttr aPattern( m_pDocument->GetPool() ); + ScPatternAttr aPattern(m_pDocument->getCellAttributeHelper()); aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) ); aPattern.GetItemSet().Put( ScProtectionAttr( true ) ); m_pDocument->ApplySelectionPattern( aPattern, aDestMark ); diff --git a/sc/source/ui/docshell/docsh6.cxx b/sc/source/ui/docshell/docsh6.cxx index caefdfc0fed3..4467182cee24 100644 --- a/sc/source/ui/docshell/docsh6.cxx +++ b/sc/source/ui/docshell/docsh6.cxx @@ -228,12 +228,12 @@ static void lcl_AdjustPool( SfxStyleSheetBasePool* pStylePool ) void ScDocShell::LoadStyles( SfxObjectShell &rSource ) { - m_pDocument->StylesToNames(); + m_pDocument->getCellAttributeHelper().AllStylesToNames(); SfxObjectShell::LoadStyles(rSource); lcl_AdjustPool( GetStyleSheetPool() ); // adjust SetItems - m_pDocument->UpdStlShtPtrsFrmNms(); + m_pDocument->getCellAttributeHelper().UpdateAllStyleSheets(*m_pDocument); UpdateAllRowHeights(); diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx index cc0be89a4bd6..2b75ccc7d626 100644 --- a/sc/source/ui/docshell/docsh8.cxx +++ b/sc/source/ui/docshell/docsh8.cxx @@ -261,7 +261,7 @@ static void lcl_setScalesToColumns(ScDocument& rDoc, const vector<tools::Long>& continue; } - ScPatternAttr aNewAttrs( rDoc.GetPool() ); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) ); rDoc.ApplyPatternAreaTab(i, 0, i, rDoc.MaxRow(), 0, aNewAttrs); diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 159a4639e666..bc87bdb4ba4e 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -1038,7 +1038,7 @@ static bool lcl_PutString( // This is only necessary for ScDocumentImport, // ScDocument::SetTextCell() forces it by ScSetStringParam. sal_uInt32 nFormat = rDoc.GetFormatTable()->GetStandardFormat(SvNumFormatType::TEXT); - ScPatternAttr aNewAttrs(rDoc.GetPool()); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nFormat) ); rDoc.ApplyPattern(nCol, nRow, nTab, aNewAttrs); diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx index 9bda36a1e176..523b48963a25 100644 --- a/sc/source/ui/inc/undoblk.hxx +++ b/sc/source/ui/inc/undoblk.hxx @@ -345,9 +345,10 @@ private: std::unique_ptr<ScEditDataArray> mpDataArray; ScDocumentUniquePtr pUndoDoc; bool bMulti; - ScPatternAttr* pApplyPattern; - SvxBoxItem* pLineOuter; - SvxBoxInfoItem* pLineInner; + const CellAttributeHolder aApplyPattern; + + SfxPoolItemHolder maLineOuter; + SfxPoolItemHolder maLineInner; void DoChange( const bool bUndo ); void ChangeEditData( const bool bUndo ); diff --git a/sc/source/ui/inc/undocell.hxx b/sc/source/ui/inc/undocell.hxx index bfc82abe97f6..ec465e75e646 100644 --- a/sc/source/ui/inc/undocell.hxx +++ b/sc/source/ui/inc/undocell.hxx @@ -58,13 +58,13 @@ private: SCCOL nCol; SCROW nRow; SCTAB nTab; - ScPatternAttr* pOldPattern; - ScPatternAttr* pNewPattern; - ScPatternAttr* pApplyPattern; + const CellAttributeHolder aOldPattern; + const CellAttributeHolder aNewPattern; + const CellAttributeHolder aApplyPattern; std::unique_ptr<EditTextObject> pOldEditData; std::unique_ptr<EditTextObject> pNewEditData; - void DoChange( const ScPatternAttr* pWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const; + void DoChange( const CellAttributeHolder& rWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const; }; class ScUndoEnterData: public ScSimpleUndo diff --git a/sc/source/ui/pagedlg/scuitphfedit.cxx b/sc/source/ui/pagedlg/scuitphfedit.cxx index d82c923e56c4..e087370f84cd 100644 --- a/sc/source/ui/pagedlg/scuitphfedit.cxx +++ b/sc/source/ui/pagedlg/scuitphfedit.cxx @@ -80,8 +80,8 @@ ScHFEditPage::ScHFEditPage(weld::Container* pPage, weld::DialogController* pCont //! use default style from current document? //! if font color is used, header/footer background color must be set - - ScPatternAttr aPatAttr( rCoreAttrs.GetPool() ); + const CellAttributeHelper aTempHelper(*rCoreAttrs.GetPool()); + const ScPatternAttr& rDefaultCellAttribute(aTempHelper.getDefaultCellAttribute()); m_xLbDefined->connect_popup_toggled( LINK( this, ScHFEditPage, ListToggleHdl_Impl) ); m_xLbDefined->connect_changed( LINK( this, ScHFEditPage, ListHdl_Impl ) ); @@ -109,9 +109,9 @@ ScHFEditPage::ScHFEditPage(weld::Container* pPage, weld::DialogController* pCont m_xWndLeftWnd->set_grid_left_attach(nOldRightAttach); m_xWndRightWnd->set_grid_left_attach(nOldLeftAttach); } - m_xWndLeft->SetFont( aPatAttr ); - m_xWndCenter->SetFont( aPatAttr ); - m_xWndRight->SetFont( aPatAttr ); + m_xWndLeft->SetFont( rDefaultCellAttribute ); + m_xWndCenter->SetFont( rDefaultCellAttribute ); + m_xWndRight->SetFont( rDefaultCellAttribute ); m_xWndLeft->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) ); m_xWndCenter->SetObjectSelectHdl( LINK(this,ScHFEditPage,ObjectSelectHdl) ); diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx index d352ba143ba8..ef46e1b7e7c2 100644 --- a/sc/source/ui/undo/undoblk.cxx +++ b/sc/source/ui/undo/undoblk.cxx @@ -475,7 +475,7 @@ void ScUndoDeleteCells::DoChange( const bool bUndo ) aWorkRange.aEnd.SetRow(rDoc.MaxRow()); ScMarkData aMarkData(rDoc.GetSheetLimits()); aMarkData.SelectOneTable( aWorkRange.aStart.Tab() ); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( ScMergeFlagAttr() ); rDoc.ApplyPatternArea( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), aWorkRange.aEnd.Col(), aWorkRange.aEnd.Row(), @@ -2308,7 +2308,7 @@ void ScUndoRemoveMerge::Redo() ScRange aRange = rOption.getSingleRange(nTab); const SfxPoolItem& rDefAttr = rDoc.GetPool()->GetDefaultItem( ATTR_MERGE ); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( rDefAttr ); rDoc.ApplyPatternAreaTab( rOption.mnStartCol, rOption.mnStartRow, rOption.mnEndCol, rOption.mnEndRow, nTab, diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx index bc967d96d47f..82d381d2f9ae 100644 --- a/sc/source/ui/undo/undoblk3.cxx +++ b/sc/source/ui/undo/undoblk3.cxx @@ -352,31 +352,23 @@ ScUndoSelectionAttr::ScUndoSelectionAttr( ScDocShell* pNewDocShell, aRange ( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ), mpDataArray(new ScEditDataArray), pUndoDoc ( std::move(pNewUndoDoc) ), - bMulti ( bNewMulti ) + bMulti ( bNewMulti ), + aApplyPattern( pNewApply ), + maLineOuter(*pDocShell->GetDocument().GetPool(), pNewOuter), + maLineInner(*pDocShell->GetDocument().GetPool(), pNewInner) { - ScDocumentPool* pPool = pDocShell->GetDocument().GetPool(); - pApplyPattern = const_cast<ScPatternAttr*>(&pPool->DirectPutItemInPool( *pNewApply )); - pLineOuter = pNewOuter ? const_cast<SvxBoxItem*>( &pPool->DirectPutItemInPool( *pNewOuter ) ) : nullptr; - pLineInner = pNewInner ? const_cast<SvxBoxInfoItem*>( &pPool->DirectPutItemInPool( *pNewInner ) ) : nullptr; aRangeCover = pRangeCover ? *pRangeCover : aRange; } ScUndoSelectionAttr::~ScUndoSelectionAttr() { - ScDocumentPool* pPool = pDocShell->GetDocument().GetPool(); - pPool->DirectRemoveItemFromPool(*pApplyPattern); - if (pLineOuter) - pPool->DirectRemoveItemFromPool(*pLineOuter); - if (pLineInner) - pPool->DirectRemoveItemFromPool(*pLineInner); - pUndoDoc.reset(); } OUString ScUndoSelectionAttr::GetComment() const { //"Attribute" "/Lines" - return ScResId( pLineOuter ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR ); + return ScResId( maLineOuter.getItem() ? STR_UNDO_SELATTRLINES : STR_UNDO_SELATTR ); } ScEditDataArray* ScUndoSelectionAttr::GetDataArray() @@ -410,11 +402,13 @@ void ScUndoSelectionAttr::DoChange( const bool bUndo ) else // only for Redo { aMarkData.MarkToMulti(); - rDoc.ApplySelectionPattern( *pApplyPattern, aMarkData ); + rDoc.ApplySelectionPattern( *aApplyPattern.getScPatternAttr(), aMarkData ); aMarkData.MarkToSimple(); - if (pLineOuter) - rDoc.ApplySelectionFrame(aMarkData, *pLineOuter, pLineInner); + if (maLineOuter.getItem()) + rDoc.ApplySelectionFrame(aMarkData, + *static_cast<const SvxBoxItem*>(maLineOuter.getItem()), + static_cast<const SvxBoxInfoItem*>(maLineInner.getItem())); } ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell(); @@ -469,10 +463,12 @@ void ScUndoSelectionAttr::Repeat(SfxRepeatTarget& rTarget) if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget)) { ScTabViewShell& rViewShell = *pViewTarget->GetViewShell(); - if (pLineOuter) - rViewShell.ApplyPatternLines(*pApplyPattern, *pLineOuter, pLineInner); + if (maLineOuter.getItem()) + rViewShell.ApplyPatternLines(*aApplyPattern.getScPatternAttr(), + *static_cast<const SvxBoxItem*>(maLineOuter.getItem()), + static_cast<const SvxBoxInfoItem*>(maLineInner.getItem())); else - rViewShell.ApplySelectionPattern( *pApplyPattern ); + rViewShell.ApplySelectionPattern( *aApplyPattern.getScPatternAttr() ); } } diff --git a/sc/source/ui/undo/undocell.cxx b/sc/source/ui/undo/undocell.cxx index 84e4a95bcb1e..c83acc3afcbc 100644 --- a/sc/source/ui/undo/undocell.cxx +++ b/sc/source/ui/undo/undocell.cxx @@ -80,21 +80,16 @@ ScUndoCursorAttr::ScUndoCursorAttr( ScDocShell* pNewDocShell, nCol( nNewCol ), nRow( nNewRow ), nTab( nNewTab ), + aOldPattern( pOldPat ), + aNewPattern( pNewPat ), + aApplyPattern( pApplyPat ), pOldEditData( static_cast<EditTextObject*>(nullptr) ), pNewEditData( static_cast<EditTextObject*>(nullptr) ) { - ScDocumentPool* pPool = pDocShell->GetDocument().GetPool(); - pNewPattern = const_cast<ScPatternAttr*>( &pPool->DirectPutItemInPool( *pNewPat ) ); - pOldPattern = const_cast<ScPatternAttr*>( &pPool->DirectPutItemInPool( *pOldPat ) ); - pApplyPattern = const_cast<ScPatternAttr*>( &pPool->DirectPutItemInPool( *pApplyPat ) ); } ScUndoCursorAttr::~ScUndoCursorAttr() { - ScDocumentPool* pPool = pDocShell->GetDocument().GetPool(); - pPool->DirectRemoveItemFromPool(*pNewPattern); - pPool->DirectRemoveItemFromPool(*pOldPattern); - pPool->DirectRemoveItemFromPool(*pApplyPattern); } OUString ScUndoCursorAttr::GetComment() const @@ -109,11 +104,11 @@ void ScUndoCursorAttr::SetEditData( std::unique_ptr<EditTextObject> pOld, std::u pNewEditData = std::move(pNew); } -void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const +void ScUndoCursorAttr::DoChange( const CellAttributeHolder& rWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const { ScDocument& rDoc = pDocShell->GetDocument(); ScAddress aPos(nCol, nRow, nTab); - rDoc.SetPattern( nCol, nRow, nTab, *pWhichPattern ); + rDoc.SetPattern( nCol, nRow, nTab, rWhichPattern ); if (rDoc.GetCellType(aPos) == CELLTYPE_EDIT && pEditData) rDoc.SetEditText(aPos, *pEditData, nullptr); @@ -126,7 +121,7 @@ void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const std:: pViewShell->AdjustBlockHeight(); } - const SfxItemSet& rApplySet = pApplyPattern->GetItemSet(); + const SfxItemSet& rApplySet = aApplyPattern.getScPatternAttr()->GetItemSet(); bool bPaintExt = ( rApplySet.GetItemState( ATTR_SHADOW ) != SfxItemState::DEFAULT || rApplySet.GetItemState( ATTR_CONDITIONAL ) != SfxItemState::DEFAULT ); bool bPaintRows = ( rApplySet.GetItemState( ATTR_HOR_JUSTIFY ) != SfxItemState::DEFAULT ); @@ -142,21 +137,21 @@ void ScUndoCursorAttr::DoChange( const ScPatternAttr* pWhichPattern, const std:: void ScUndoCursorAttr::Undo() { BeginUndo(); - DoChange(pOldPattern, pOldEditData); + DoChange(aOldPattern, pOldEditData); EndUndo(); } void ScUndoCursorAttr::Redo() { BeginRedo(); - DoChange(pNewPattern, pNewEditData); + DoChange(aNewPattern, pNewEditData); EndRedo(); } void ScUndoCursorAttr::Repeat(SfxRepeatTarget& rTarget) { if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget)) - pViewTarget->GetViewShell()->ApplySelectionPattern( *pApplyPattern ); + pViewTarget->GetViewShell()->ApplySelectionPattern( *aApplyPattern.getScPatternAttr() ); } bool ScUndoCursorAttr::CanRepeat(SfxRepeatTarget& rTarget) const @@ -252,9 +247,9 @@ void ScUndoEnterData::Undo() SfxUInt32Item(ATTR_VALUE_FORMAT, rVal.mnFormat)); else { - auto pPattern = std::make_unique<ScPatternAttr>(*rDoc.GetPattern(maPos.Col(), maPos.Row(), rVal.mnTab)); + ScPatternAttr* pPattern(new ScPatternAttr(*rDoc.GetPattern(maPos.Col(), maPos.Row(), rVal.mnTab))); pPattern->GetItemSet().ClearItem( ATTR_VALUE_FORMAT ); - rDoc.SetPattern(maPos.Col(), maPos.Row(), rVal.mnTab, std::move(pPattern)); + rDoc.SetPattern(maPos.Col(), maPos.Row(), rVal.mnTab, CellAttributeHolder(pPattern, true)); } pDocShell->PostPaintCell(maPos.Col(), maPos.Row(), rVal.mnTab); } diff --git a/sc/source/ui/undo/undostyl.cxx b/sc/source/ui/undo/undostyl.cxx index 0c1ab96c2b16..696855188830 100644 --- a/sc/source/ui/undo/undostyl.cxx +++ b/sc/source/ui/undo/undostyl.cxx @@ -143,7 +143,7 @@ void ScUndoModifyStyle::DoChange( ScDocShell* pDocSh, const OUString& rName, pStyle = &pStlPool->Make( aNewName, eStyleFamily, SfxStyleSearchBits::UserDefined ); if ( eStyleFamily == SfxStyleFamily::Para ) - rDoc.GetPool()->CellStyleCreated( aNewName, rDoc ); + rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, aNewName); } if ( pStyle ) diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 3325b0bbcf6c..d5f69cd7d85f 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -1869,7 +1869,7 @@ uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault( const OUString& aPropert { if ( IsScItemWid( pEntry->nWID ) ) { - const ScPatternAttr* pPattern = rDoc.GetDefPattern(); + const ScPatternAttr* pPattern(&rDoc.getCellAttributeHelper().getDefaultCellAttribute()); if ( pPattern ) { const SfxItemSet& rSet = pPattern->GetItemSet(); @@ -1903,7 +1903,7 @@ uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault( const OUString& aPropert case SC_WID_UNO_TBLBORD: case SC_WID_UNO_TBLBORD2: { - const ScPatternAttr* pPattern = rDoc.GetDefPattern(); + const ScPatternAttr* pPattern(&rDoc.getCellAttributeHelper().getDefaultCellAttribute()); if ( pPattern ) { if (pEntry->nWID == SC_WID_UNO_TBLBORD2) @@ -2278,7 +2278,7 @@ void ScCellRangesBase::SetOnePropertyValue( const SfxItemPropertyMapEntry* pEntr sal_uInt32 nIndex = rDoc.AddValidationEntry( *pNewData ); pNewData.reset(); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) ); pDocShell->GetDocFunc().ApplyAttributes( *GetMarkData(), aPattern, true ); } @@ -2548,7 +2548,7 @@ void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< OUString { pOldPattern.reset(new ScPatternAttr( *GetCurrentAttrsDeep() )); pOldPattern->GetItemSet().ClearInvalidItems(); - pNewPattern.reset(new ScPatternAttr( rDoc.GetPool() )); + pNewPattern.reset(new ScPatternAttr(rDoc.getCellAttributeHelper())); } // collect items in pNewPattern, apply with one call after the loop @@ -2684,7 +2684,7 @@ uno::Sequence< beans::SetPropertyTolerantFailed > SAL_CALL ScCellRangesBase::set { pOldPattern.reset(new ScPatternAttr( *GetCurrentAttrsDeep() )); pOldPattern->GetItemSet().ClearInvalidItems(); - pNewPattern.reset(new ScPatternAttr( rDoc.GetPool() )); + pNewPattern.reset(new ScPatternAttr(rDoc.getCellAttributeHelper())); } // collect items in pNewPattern, apply with one call after the loop @@ -5884,7 +5884,7 @@ void ScCellObj::InputEnglishString( const OUString& rText ) sal_uInt32 nNewFormat = ScGlobal::GetStandardFormat(*pFormatter, nOldFormat, aRes.mnFormatType); if (nNewFormat != nOldFormat) { - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) ); // ATTR_LANGUAGE_FORMAT remains unchanged rFunc.ApplyAttributes( *GetMarkData(), aPattern, true ); @@ -7630,7 +7630,7 @@ void SAL_CALL ScTableSheetObj::addRanges( const uno::Sequence<table::CellRangeAd } // Scenario ranges are tagged with attribute - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) ); aPattern.GetItemSet().Put( ScProtectionAttr( true ) ); pDocSh->GetDocFunc().ApplyAttributes( aMarkData, aPattern, true ); diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 66f805b37c78..e1a70b742517 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -1031,8 +1031,7 @@ static void lcl_sendLOKDocumentBackground(const ScViewData* pViewData) { ScDocShell* pDocSh = pViewData->GetDocShell(); ScDocument& rDoc = pDocSh->GetDocument(); - const ScPatternAttr *pAttr = rDoc.GetDefPattern(); - const SfxPoolItem& rItem = pAttr->GetItem(ATTR_BACKGROUND); + const SfxPoolItem& rItem(rDoc.getCellAttributeHelper().getDefaultCellAttribute().GetItem(ATTR_BACKGROUND)); const SvxBrushItem& rBackground = static_cast<const SvxBrushItem&>(rItem); const Color& rColor = rBackground.GetColor(); diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx index 6f5226452bf7..3316450da370 100644 --- a/sc/source/ui/unoobj/funcuno.cxx +++ b/sc/source/ui/unoobj/funcuno.cxx @@ -152,7 +152,7 @@ static bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange, if ( pClipDoc->HasAttrib( 0,0,nSrcTab, pClipDoc->MaxCol(), pClipDoc->MaxRow(),nSrcTab, HasAttrFlags::Merged | HasAttrFlags::Overlapped ) ) { - ScPatternAttr aPattern( pSrcDoc->GetPool() ); + ScPatternAttr aPattern(pSrcDoc->getCellAttributeHelper()); aPattern.GetItemSet().Put( ScMergeAttr() ); // Defaults aPattern.GetItemSet().Put( ScMergeFlagAttr() ); pClipDoc->ApplyPatternAreaTab( 0,0, pClipDoc->MaxCol(), pClipDoc->MaxRow(), nSrcTab, aPattern ); diff --git a/sc/source/ui/unoobj/styleuno.cxx b/sc/source/ui/unoobj/styleuno.cxx index 8dd6fc58f86a..beef2e67f41b 100644 --- a/sc/source/ui/unoobj/styleuno.cxx +++ b/sc/source/ui/unoobj/styleuno.cxx @@ -720,7 +720,7 @@ void SAL_CALL ScStyleFamilyObj::insertByName( const OUString& aName, const uno:: (void)pStylePool->Make( aNameStr, eFamily, SfxStyleSearchBits::UserDefined ); if ( eFamily == SfxStyleFamily::Para && !rDoc.IsImportingXML() ) - rDoc.GetPool()->CellStyleCreated( aNameStr, rDoc ); + rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, aNameStr); pStyleObj->InitDoc( pDocShell, aNameStr ); // object can be used @@ -1140,7 +1140,7 @@ void SAL_CALL ScStyleObj::setName( const OUString& aNewName ) ScDocument& rDoc = pDocShell->GetDocument(); if ( eFamily == SfxStyleFamily::Para && !rDoc.IsImportingXML() ) - rDoc.GetPool()->CellStyleCreated( aNewName, rDoc ); + rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, aNewName); // cell styles = 2, drawing styles = 3, page styles = 4 sal_uInt16 nId = eFamily == SfxStyleFamily::Para ? SID_STYLE_FAMILY2 : diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx index 6102cdb9fac2..dea96fc2310d 100644 --- a/sc/source/ui/unoobj/textuno.cxx +++ b/sc/source/ui/unoobj/textuno.cxx @@ -172,16 +172,33 @@ SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder() pHdrEngine->SetRefMapMode(MapMode(MapUnit::MapTwip)); // default font must be set, independently of document - // -> use global pool from module + ScDocShell* pDocSh(dynamic_cast<ScDocShell*>(SfxObjectShell::Current())); + std::unique_ptr<CellAttributeHelper> pTmp; + const ScPatternAttr* pCellAttributeDefault(nullptr); + + if (nullptr != pDocSh) + { + // we can use default CellAttribute from ScDocument + pCellAttributeDefault = &pDocSh->GetDocument().getCellAttributeHelper().getDefaultCellAttribute(); + } + else + { + // no access to ScDocument, use temporary default CellAttributeHelper + // was: "use global pool from module" which is usually ScMessagePool + // and gets set in ScTabViewObj::SelectionChanged() by + // ScFormatShell::ScFormatShell which calls + // SetPool( &pTabViewShell->GetPool() ); + pTmp.reset(new CellAttributeHelper(SC_MOD()->GetPool())); + pCellAttributeDefault = &pTmp->getDefaultCellAttribute(); + } SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() ); - const ScPatternAttr& rPattern = SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN); - rPattern.FillEditItemSet( &aDefaults ); + pCellAttributeDefault->FillEditItemSet( &aDefaults ); // FillEditItemSet adjusts font height to 1/100th mm, // but for header/footer twips is needed, as in the PatternAttr: - aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) ); - aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ; - aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) ); + aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) ); + aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ; + aDefaults.Put( pCellAttributeDefault->GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) ); pHdrEngine->SetDefaults( aDefaults ); ScHeaderFieldData aData; diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index f1ce525daa2d..12d38b5e9b0b 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -3831,9 +3831,8 @@ static double getDefaultCharWidth( ScDocShell* pDocShell ) { ScDocument& rDoc = pDocShell->GetDocument(); OutputDevice* pRefDevice = rDoc.GetRefDevice(); - ScPatternAttr* pAttr = rDoc.GetDefPattern(); vcl::Font aDefFont; - pAttr->fillFontOnly(aDefFont, pRefDevice); + rDoc.getCellAttributeHelper().getDefaultCellAttribute().fillFontOnly(aDefFont, pRefDevice); pRefDevice->SetFont(aDefFont); tools::Long nCharWidth = pRefDevice->GetTextWidth( OUString( '0' ) ); // 1/100th mm return o3tl::convert<double>(nCharWidth, o3tl::Length::mm100, o3tl::Length::pt); diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index 9720bf7f4f9f..41c8d9e9e268 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -2086,7 +2086,7 @@ void ScDBFunc::ShowDataPilotSourceData( ScDPObject& rDPObj, const Sequence<sheet if (!(any >>= nNumFmt)) continue; - ScPatternAttr aPattern( pInsDoc->GetPool() ); + ScPatternAttr aPattern(pInsDoc->getCellAttributeHelper()); aPattern.GetItemSet().Put( SfxUInt32Item(ATTR_VALUE_FORMAT, static_cast<sal_uInt32>(nNumFmt)) ); pInsDoc->ApplyPatternAreaTab(nCol, 1, nCol, nRowSize-1, nNewTab, aPattern); } diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index 93a456e46b53..9c231f1d4b5a 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -191,7 +191,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) SfxItemSet aItemSet( GetPool() ); - ScPatternAttr aNewAttrs( GetViewData().GetDocument().GetPool() ); + ScPatternAttr aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper()); SfxItemSet& rNewSet = aNewAttrs.GetItemSet(); rNewSet.Put( aItemSet, false ); @@ -214,7 +214,7 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) SfxItemSet aItemSet( GetPool() ); - ScPatternAttr aNewAttrs( GetViewData().GetDocument().GetPool() ); + ScPatternAttr aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper()); SfxItemSet& rNewSet = aNewAttrs.GetItemSet(); rNewSet.Put( aItemSet, false ); rDoc.ApplySelectionPattern( aNewAttrs, aPreviewMark ); @@ -345,7 +345,7 @@ void ScFormatShell::ExecuteNumFormat( SfxRequest& rReq ) if ( nOldFormat != nNewFormat ) { const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat ); - ScPatternAttr aNewAttrs( rDoc.GetPool() ); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); LanguageType eNewLang = pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW; if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW ) @@ -1924,7 +1924,7 @@ void ScFormatShell::ExecuteTextDirection( const SfxRequest& rReq ) case SID_TEXTDIRECTION_TOP_TO_BOTTOM: { bool bVert = (nSlot == SID_TEXTDIRECTION_TOP_TO_BOTTOM); - ScPatternAttr aAttr( GetViewData().GetDocument().GetPool() ); + ScPatternAttr aAttr(GetViewData().GetDocument().getCellAttributeHelper()); SfxItemSet& rItemSet = aAttr.GetItemSet(); rItemSet.Put( ScVerticalStackCell( bVert ) ); rItemSet.Put( SfxBoolItem( ATTR_VERTICAL_ASIAN, bVert ) ); diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index 3639e8287698..218c98b12a6c 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -119,8 +119,7 @@ static void lcl_DrawOneFrame( vcl::RenderContext* pDev, const tools::Rectangle& // use ScPatternAttr::GetFont only for font size vcl::Font aAttrFont; - rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN). - fillFontOnly(aAttrFont, pDev, &rZoomY); + rDoc.getCellAttributeHelper().getDefaultCellAttribute().fillFontOnly(aAttrFont, pDev, &rZoomY); // everything else from application font vcl::Font aAppFont = pDev->GetSettings().GetStyleSettings().GetAppFont(); @@ -1916,7 +1915,7 @@ void ScGridWindow::DrawPagePreview( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, vcl::Font aFont; std::unique_ptr<ScEditEngineDefaulter> pEditEng; - const ScPatternAttr& rDefPattern = rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN); + const ScPatternAttr& rDefPattern(rDoc.getCellAttributeHelper().getDefaultCellAttribute()); if ( nPageScript == SvtScriptType::LATIN ) { // use single font and call DrawText directly diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index 473671ea1cf3..70c2f1904c7d 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -1025,7 +1025,7 @@ static bool StringDiffer( const ScPatternAttr*& rpOldPattern, const ScPatternAtt { OSL_ENSURE( pNewPattern, "pNewPattern" ); - if ( SfxPoolItem::areSame( pNewPattern, rpOldPattern ) ) + if ( ScPatternAttr::areSame( pNewPattern, rpOldPattern ) ) return false; else if ( !rpOldPattern ) return true; @@ -1714,7 +1714,7 @@ void ScOutputData::LayoutStrings(bool bPixelToLogic) if (nScript == SvtScriptType::NONE) nScript = ScGlobal::GetDefaultScriptType(); - if ( !SfxPoolItem::areSame(pPattern, pOldPattern) || pCondSet != pOldCondSet || + if ( !ScPatternAttr::areSame(pPattern, pOldPattern) || pCondSet != pOldCondSet || nScript != nOldScript || mbSyntaxMode ) { if ( StringDiffer(pOldPattern,pPattern) || @@ -2488,7 +2488,7 @@ void ScOutputData::DrawEditParam::setPatternToEngine(bool bUseStyleColor) // syntax highlighting mode is ignored here // StringDiffer doesn't look at hyphenate, language items - if (SfxPoolItem::areSame(mpPattern, mpOldPattern) && mpCondSet == mpOldCondSet && mpPreviewFontSet == mpOldPreviewFontSet ) + if (ScPatternAttr::areSame(mpPattern, mpOldPattern) && mpCondSet == mpOldCondSet && mpPreviewFontSet == mpOldPreviewFontSet ) return; Color nConfBackColor = SC_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor; @@ -4701,7 +4701,7 @@ void ScOutputData::DrawRotated(bool bPixelToLogic) // syntax mode is ignored here... // StringDiffer doesn't look at hyphenate, language items - if ( !SfxPoolItem::areSame(pPattern, pOldPattern) || pCondSet != pOldCondSet ) + if ( !ScPatternAttr::areSame(pPattern, pOldPattern) || pCondSet != pOldCondSet ) { auto pSet = std::make_unique<SfxItemSet>( mxOutputEditEngine->GetEmptyItemSet() ); pPattern->FillEditItemSet( pSet.get(), pCondSet ); diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx index 33430883da53..ac7de60f8fda 100644 --- a/sc/source/ui/view/preview.cxx +++ b/sc/source/ui/view/preview.cxx @@ -499,8 +499,7 @@ void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation ) GetOutDev()->SetFillColor(aBackColor); GetOutDev()->DrawRect(tools::Rectangle(0, 0, aWinEnd.X(), aWinEnd.Y())); - const ScPatternAttr& rDefPattern = - rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN); + const ScPatternAttr& rDefPattern(rDoc.getCellAttributeHelper().getDefaultCellAttribute()); std::unique_ptr<ScEditEngineDefaulter> pEditEng( new ScEditEngineDefaulter(EditEngine::CreatePool().get(), true)); diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx index 697a03f8a315..db81b8692849 100644 --- a/sc/source/ui/view/printfun.cxx +++ b/sc/source/ui/view/printfun.cxx @@ -1741,7 +1741,8 @@ void ScPrintFunc::MakeEditEngine() // Default-Set for alignment pEditDefaults.reset( new SfxItemSet( pEditEngine->GetEmptyItemSet() ) ); - const ScPatternAttr& rPattern = rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN); + const ScPatternAttr& rPattern(rDoc.getCellAttributeHelper().getDefaultCellAttribute()); + rPattern.FillEditItemSet( pEditDefaults.get() ); // FillEditItemSet adjusts font height to 1/100th mm, // but for header/footer twips is needed, as in the PatternAttr: @@ -1908,7 +1909,7 @@ tools::Long ScPrintFunc::DoNotes( tools::Long nNoteStart, bool bDoPrint, ScPrevi vcl::Font aMarkFont; ScAutoFontColorMode eColorMode = bUseStyleColor ? ScAutoFontColorMode::Display : ScAutoFontColorMode::Print; - rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN).fillFont(aMarkFont, eColorMode); + rDoc.getCellAttributeHelper().getDefaultCellAttribute().fillFont(aMarkFont, eColorMode); pDev->SetFont(aMarkFont); tools::Long nMarkLen = pDev->GetTextWidth("GW99999:"); // without Space-Char, because it rarely arrives there @@ -2320,7 +2321,7 @@ void ScPrintFunc::PrintPage( tools::Long nPageNo, SCCOL nX1, SCROW nY1, SCCOL nX pDev->SetMapMode(aOffsetMode); } - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); vcl::Font aFont; ScAutoFontColorMode eColorMode = bUseStyleColor ? ScAutoFontColorMode::Display : ScAutoFontColorMode::Print; aPattern.fillFont(aFont, eColorMode, pDev); diff --git a/sc/source/ui/view/spelleng.cxx b/sc/source/ui/view/spelleng.cxx index ae50d82930ee..0183e1e04f34 100644 --- a/sc/source/ui/view/spelleng.cxx +++ b/sc/source/ui/view/spelleng.cxx @@ -135,16 +135,16 @@ bool ScConversionEngineBase::FindNextConversionCell() // Set the new string and update the language with the cell. mrDoc.SetString(aPos, aNewStr); - const ScPatternAttr* pAttr = mrDoc.GetPattern(aPos); - std::unique_ptr<ScPatternAttr> pNewAttr; + const ScPatternAttr* pAttr(mrDoc.GetPattern(aPos)); + ScPatternAttr* pNewAttr(nullptr); - if (pAttr) - pNewAttr = std::make_unique<ScPatternAttr>(*pAttr); + if (nullptr != pAttr) + pNewAttr = new ScPatternAttr(*pAttr); else - pNewAttr = std::make_unique<ScPatternAttr>(mrDoc.GetPool()); + pNewAttr = new ScPatternAttr(mrDoc.getCellAttributeHelper()); pNewAttr->GetItemSet().Put(SvxLanguageItem(aLang.nLang, EE_CHAR_LANGUAGE), ATTR_FONT_LANGUAGE); - mrDoc.SetPattern(aPos, std::move(pNewAttr)); + mrDoc.SetPattern(aPos, CellAttributeHolder(pNewAttr, true)); } if (mpRedoDoc && !bEmptyCell) @@ -209,7 +209,7 @@ bool ScConversionEngineBase::FindNextConversionCell() { // GetPattern may implicitly allocates the column if not exists, pPattern = mrDoc.GetPattern( nNewCol, nNewRow, mnStartTab ); - if( pPattern && !SfxPoolItem::areSame(pPattern, pLastPattern) ) + if( pPattern && !ScPatternAttr::areSame(pPattern, pLastPattern) ) { pPattern->FillEditItemSet( &aEditDefaults ); SetDefaults( aEditDefaults ); diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index 46baa40875fb..52b815e34e16 100644 --- a/sc/source/ui/view/tabvwsha.cxx +++ b/sc/source/ui/view/tabvwsha.cxx @@ -1203,7 +1203,7 @@ void ScTabViewShell::ExecStyle( SfxRequest& rReq ) // style pointer to names before erase, // otherwise cells will get invalid pointer //!!! As it happens, a method that does it for a particular style - rDoc.StylesToNames(); + rDoc.getCellAttributeHelper().AllStylesToNames(); bConvertBack = true; pStylePool->Remove(pStyleSheet); } @@ -1219,9 +1219,9 @@ void ScTabViewShell::ExecStyle( SfxRequest& rReq ) if ( bConvertBack ) // Name to style pointer - rDoc.UpdStlShtPtrsFrmNms(); + rDoc.getCellAttributeHelper().UpdateAllStyleSheets(rDoc); else - rDoc.GetPool()->CellStyleCreated( aStyleName, rDoc ); + rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, aStyleName); // Adopt attribute and use style pStyleSheet->GetItemSet().Put( aAttrSet ); @@ -1598,7 +1598,7 @@ void ScTabViewShell::ExecStyle( SfxRequest& rReq ) pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) ); } - rDoc.GetPool()->CellStyleCreated( pStyleSheet->GetName(), rDoc ); + rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, pStyleSheet->GetName()); } else if ( SfxStyleFamily::Page == eFam ) { diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 5cb800fe8ce1..ea896d6423f0 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -958,7 +958,7 @@ void ScViewFunc::EnterBlock( const OUString& rString, const EditTextObject* pDat { // set number format if incompatible // MarkData was already MarkToSimple'ed in PasteFromClip const ScRange& aRange = rMark.GetMarkArea(); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( *pItem ); SvNumFormatType nNewType = rDoc.GetFormatTable()->GetType( pItem->GetValue() ); rDoc.ApplyPatternIfNumberformatIncompatible( aRange, rMark, @@ -2379,7 +2379,7 @@ void ScViewFunc::ExtendScenario() // Undo: apply attributes ScDocument& rDoc = GetViewData().GetDocument(); - ScPatternAttr aPattern( rDoc.GetPool() ); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( ScMergeFlagAttr( ScMF::Scenario ) ); aPattern.GetItemSet().Put( ScProtectionAttr( true ) ); ApplySelectionPattern(aPattern); diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 0b8b0865f0fc..2958f13cd2eb 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -627,7 +627,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, const SvNumberformat* pEntry = pFormatter->GetEntry( nIndex); const LanguageType nLang = (pEntry ? pEntry->GetLanguage() : ScGlobal::eLnge); const sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::NUMBER, nLang); - ScPatternAttr aPattern( rDoc.GetPool()); + ScPatternAttr aPattern(rDoc.getCellAttributeHelper()); aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nFormat)); ScMarkData aMark(rDoc.GetSheetLimits()); aMark.SelectTable( i, true); @@ -1005,8 +1005,9 @@ void ScViewFunc::ApplyAttributes( const SfxItemSet& rDialogSet, return; } - ScPatternAttr aOldAttrs(( SfxItemSet(rOldSet) )); - ScPatternAttr aNewAttrs(( SfxItemSet(rDialogSet) )); + ScDocument& rDoc = GetViewData().GetDocument(); + ScPatternAttr aOldAttrs(rDoc.getCellAttributeHelper(), &rOldSet); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper(), &rDialogSet); aNewAttrs.DeleteUnchanged( &aOldAttrs ); if ( rDialogSet.GetItemState( ATTR_VALUE_FORMAT ) == SfxItemState::SET ) @@ -1115,8 +1116,8 @@ void ScViewFunc::ApplyAttr( const SfxPoolItem& rAttrItem, bool bAdjustBlockHeigh return; } - ScPatternAttr aNewAttrs( - SfxItemSetFixed<ATTR_PATTERN_START, ATTR_PATTERN_END>( *GetViewData().GetDocument().GetPool() ) ); + ScDocument& rDoc = GetViewData().GetDocument(); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); aNewAttrs.GetItemSet().Put( rAttrItem ); // if justify is set (with Buttons), always indentation 0 @@ -1426,7 +1427,7 @@ void ScViewFunc::ApplyUserItemSet( const SfxItemSet& rItemSet ) return; } - ScPatternAttr aNewAttrs( GetViewData().GetDocument().GetPool() ); + ScPatternAttr aNewAttrs(GetViewData().GetDocument().getCellAttributeHelper()); SfxItemSet& rNewSet = aNewAttrs.GetItemSet(); rNewSet.Put( rItemSet, false ); ApplySelectionPattern( aNewAttrs ); @@ -2781,7 +2782,7 @@ void ScViewFunc::SetNumberFormat( SvNumFormatType nFormatType, sal_uLong nAdd ) ScDocument& rDoc = rViewData.GetDocument(); SvNumberFormatter* pNumberFormatter = rDoc.GetFormatTable(); LanguageType eLanguage = ScGlobal::eLnge; - ScPatternAttr aNewAttrs( rDoc.GetPool() ); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); // always take language from cursor position, even if there is a selection @@ -2837,7 +2838,7 @@ void ScViewFunc::SetNumFmtByStr( const OUString& rCode ) if ( bOk ) // valid format? { - ScPatternAttr aNewAttrs( rDoc.GetPool() ); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumberFormat ) ); rSet.Put( SvxLanguageItem( eLanguage, ATTR_LANGUAGE_FORMAT ) ); @@ -2970,7 +2971,7 @@ void ScViewFunc::ChangeNumFmtDecimals( bool bIncrement ) if (!bError) { - ScPatternAttr aNewAttrs( rDoc.GetPool() ); + ScPatternAttr aNewAttrs(rDoc.getCellAttributeHelper()); SfxItemSet& rSet = aNewAttrs.GetItemSet(); rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) ); // ATTR_LANGUAGE_FORMAT not |