diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-03-28 04:05:19 +0100 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-03-28 22:14:20 +0100 |
commit | 1cef3995f626c9bc826f79756d0518f75ba12f14 (patch) | |
tree | 84de400559526131e4e092d4ed70be86c2d6127b | |
parent | f6bc8126de857c4cb52cb85a07eac0b93b30d19d (diff) |
use Notify instead of SwIterator<>
Change-Id: Id9e0bcaf2e961e2d797e4c180aa782cb0e418bcf
-rw-r--r-- | sw/inc/unotbl.hxx | 5 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 44 |
2 files changed, 33 insertions, 16 deletions
diff --git a/sw/inc/unotbl.hxx b/sw/inc/unotbl.hxx index a3526770dc96..5cc66b41252c 100644 --- a/sw/inc/unotbl.hxx +++ b/sw/inc/unotbl.hxx @@ -64,7 +64,7 @@ cppu::WeakImplHelper4 ::com::sun::star::container::XEnumerationAccess > SwXCellBaseClass; -class SwXCell : public SwXCellBaseClass, +class SwXCell SAL_FINAL : public SwXCellBaseClass, public SwXText, public SwClient { @@ -94,7 +94,8 @@ protected: virtual ~SwXCell(); //SwClient - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; + virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) SAL_OVERRIDE; + virtual void SwClientNotify(const SwModify&, const SfxHint&) SAL_OVERRIDE; public: SwXCell(SwFrmFmt* pTblFmt, SwTableBox* pBox, size_t nPos = NOTFOUND); diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index be839f5fe3b4..a875f14ffa81 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -1244,26 +1244,42 @@ void SwXCell::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) ClientModify(this, pOld, pNew); } +namespace sw +{ + struct FindXCellHint SAL_FINAL : SfxHint + { + FindXCellHint(SwTableBox* pTableBox) : m_pTableBox(pTableBox), m_pCell(nullptr) {}; + void SetCell(SwXCell* pCell) const { m_pCell = pCell; }; + const SwTableBox* const m_pTableBox; + mutable SwXCell* m_pCell; + }; +} + +void SwXCell::SwClientNotify(const SwModify& rModify, const SfxHint& rHint) +{ + if(typeid(sw::FindXCellHint) == typeid(rHint)) + { + auto* pFindHint(static_cast<const sw::FindXCellHint*>(&rHint)); + if(!pFindHint->m_pCell && pFindHint->m_pTableBox == GetTblBox()) + pFindHint->m_pCell = this; + } + else + SwClient::SwClientNotify(rModify, rHint); +} + SwXCell* SwXCell::CreateXCell(SwFrmFmt* pTblFmt, SwTableBox* pBox, SwTable *pTable ) { if(!pTblFmt || !pBox) return nullptr; - if( !pTable ) - pTable = SwTable::FindTable( pTblFmt ); - SwTableSortBoxes::const_iterator it = pTable->GetTabSortBoxes().find( pBox ); - if( it == pTable->GetTabSortBoxes().end() ) + if(!pTable) + pTable = SwTable::FindTable(pTblFmt); + SwTableSortBoxes::const_iterator it = pTable->GetTabSortBoxes().find(pBox); + if(it == pTable->GetTabSortBoxes().end()) return nullptr; - // if the box exists, then return a cell - SwIterator<SwXCell,SwFmt> aIter( *pTblFmt ); - for(SwXCell* pXCell = aIter.First(); pXCell; pXCell = aIter.Next()) - { - // is there already a proper cell? - if(pXCell->GetTblBox() == pBox) - return pXCell; - } - // otherwise create it size_t const nPos = it - pTable->GetTabSortBoxes().begin(); - return new SwXCell(pTblFmt, pBox, nPos); + sw::FindXCellHint aHint{pBox}; + pTblFmt->CallSwClientNotify(aHint); + return aHint.m_pCell ? aHint.m_pCell : new SwXCell(pTblFmt, pBox, nPos); } /** search if a box exists in a table |