diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-06-30 13:09:32 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-06-30 14:00:30 +0200 |
commit | b6cefd5e8b5086619e591385a0d7a6ffcd9783b9 (patch) | |
tree | 4657b6ffacdf5fc427001c03c6d932e266879d2c | |
parent | 6c76a0a84785b48c29687e6d31b8229a230563d8 (diff) |
sw: avoid layout recursion when loading documents with charts...
... that have a Writer table as data source, such as ooo38798-1.sxw.
The problem is that during layouting, the SwWrtShell::CalcAndSetScale()
wants to call setVisualAreaSize() on the embedded chart object.
This switches the state of the object to RUNNING, which loads it from
the file, and during that the ODF filter calls into SwChartDataProvider
and that uses a UnoActionRemoveContext; unfortunately that ends all
pending Actions, so we get a recursive layout action.
Apparently the UnoActionRemoveContext is required to call
SwUnoTableCrsr::MakeBoxSels() for old-style tables, which need layout
frames for selection?!?
Try to avoid the problem by disabling UnoActionRemoveContext in case a
new-style table will be selected, which can be done without layout.
Change-Id: I097991ffb2e78ddf011db7575f7bb63ae8aa7005
-rw-r--r-- | sw/inc/unobaseclass.hxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unochart.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/unocore/unoobj2.cxx | 40 | ||||
-rw-r--r-- | sw/source/core/unocore/unosect.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unotbl.cxx | 63 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxvw.cxx | 2 |
6 files changed, 76 insertions, 39 deletions
diff --git a/sw/inc/unobaseclass.hxx b/sw/inc/unobaseclass.hxx index bfbc9be95f4b..17ac71c081b6 100644 --- a/sw/inc/unobaseclass.hxx +++ b/sw/inc/unobaseclass.hxx @@ -29,6 +29,7 @@ class SfxPoolItem; class SwClient; class SwDoc; +class SwUnoTableCrsr; typedef ::cppu::WeakImplHelper < ::com::sun::star::lang::XServiceInfo @@ -70,6 +71,8 @@ class UnoActionContext /* interrupt Actions for a little while + FIXME: this is a vile abomination that may cause recursive layout actions! + C'thulhu fhtagn. */ class UnoActionRemoveContext { @@ -78,6 +81,7 @@ class UnoActionRemoveContext public: UnoActionRemoveContext(SwDoc *const pDoc); + UnoActionRemoveContext(SwUnoTableCrsr const& rCursor); ~UnoActionRemoveContext(); }; diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx index d03ed3cce029..c92ccaea272b 100644 --- a/sw/source/core/unocore/unochart.cxx +++ b/sw/source/core/unocore/unochart.cxx @@ -405,8 +405,6 @@ static void GetFormatAndCreateCursorFromRangeRep( pTable ? pTable->GetTableBox( aStartCell, true ) : 0; if(pTLBox) { - // The Actions need to be removed here - UnoActionRemoveContext aRemoveContext(pTableFormat->GetDoc()); const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); @@ -425,6 +423,8 @@ static void GetFormatAndCreateCursorFromRangeRep( pUnoCrsr->Move( fnMoveForward, fnGoNode ); SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr.get()); + // HACK: remove pending actions for old style tables + UnoActionRemoveContext aRemoveContext(*pCrsr); pCrsr->MakeBoxSels(); rpUnoCrsr = pUnoCrsr; } diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx index 0c238248c876..0bab22047f18 100644 --- a/sw/source/core/unocore/unoobj2.cxx +++ b/sw/source/core/unocore/unoobj2.cxx @@ -265,22 +265,50 @@ UnoActionContext::~UnoActionContext() } } -UnoActionRemoveContext::UnoActionRemoveContext(SwDoc *const pDoc) - : m_pDoc(pDoc) +static void lcl_RemoveImpl(SwDoc *const pDoc) { - SwRootFrm *const pRootFrm = m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + assert(pDoc); + SwRootFrm *const pRootFrm = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); if (pRootFrm) { pRootFrm->UnoRemoveAllActions(); } } +UnoActionRemoveContext::UnoActionRemoveContext(SwDoc *const pDoc) + : m_pDoc(pDoc) +{ + lcl_RemoveImpl(m_pDoc); +} + +static SwDoc * lcl_IsNewStyleTable(SwUnoTableCrsr const& rCursor) +{ + SwTableNode *const pTableNode = rCursor.GetNode().FindTableNode(); + return (pTableNode && !pTableNode->GetTable().IsNewModel()) + ? rCursor.GetDoc() + : nullptr; +} + +UnoActionRemoveContext::UnoActionRemoveContext(SwUnoTableCrsr const& rCursor) + : m_pDoc(lcl_IsNewStyleTable(rCursor)) +{ + // this insanity is only necessary for old-style tables + // because SwRootFrm::MakeTableCrsrs() creates the table cursor for these + if (m_pDoc) + { + lcl_RemoveImpl(m_pDoc); + } +} + UnoActionRemoveContext::~UnoActionRemoveContext() { - SwRootFrm *const pRootFrm = m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); - if (pRootFrm) + if (m_pDoc) { - pRootFrm->UnoRestoreAllActions(); + SwRootFrm *const pRootFrm = m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + if (pRootFrm) + { + pRootFrm->UnoRestoreAllActions(); + } } } diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx index b3f93d399b72..a54e79415494 100644 --- a/sw/source/core/unocore/unosect.cxx +++ b/sw/source/core/unocore/unosect.cxx @@ -531,6 +531,7 @@ lcl_UpdateSection(SwSectionFormat *const pFormat, pDoc->IsInReading()); { // temporarily remove actions to allow cursor update + // TODO: why? no table cursor here! UnoActionRemoveContext aRemoveContext( pDoc ); } @@ -1702,6 +1703,7 @@ throw (uno::RuntimeException, std::exception) } { // temporarily remove actions to allow cursor update + // TODO: why? no table cursor here! UnoActionRemoveContext aRemoveContext( pFormat->GetDoc() ); } } diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index a82ce75bb5ac..49d43ca926b7 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -1594,11 +1594,12 @@ sal_Bool SwXTextTableCursor::mergeRange() SwUnoCrsr* pUnoCrsr = GetCrsr(); if(!pUnoCrsr) return false; + + SwUnoTableCrsr& rTableCrsr = dynamic_cast<SwUnoTableCrsr&>(*pUnoCrsr); { - // The Actions need to be revoked here - UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc()); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(rTableCrsr); } - SwUnoTableCrsr& rTableCrsr = dynamic_cast<SwUnoTableCrsr&>(*pUnoCrsr); rTableCrsr.MakeBoxSels(); bool bResult; { @@ -1624,11 +1625,11 @@ sal_Bool SwXTextTableCursor::splitRange(sal_Int16 Count, sal_Bool Horizontal) SwUnoCrsr* pUnoCrsr = GetCrsr(); if(!pUnoCrsr) return false; + SwUnoTableCrsr& rTableCrsr = dynamic_cast<SwUnoTableCrsr&>(*pUnoCrsr); { - // here, all actions need to be revoked - UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc()); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(rTableCrsr); } - SwUnoTableCrsr& rTableCrsr = dynamic_cast<SwUnoTableCrsr&>(*pUnoCrsr); rTableCrsr.MakeBoxSels(); bool bResult; { @@ -2225,8 +2226,6 @@ uno::Reference<table::XCellRange> SwXTextTable::GetRangeByName(SwFrameFormat* p const SwTableBox* pTLBox = pTable->GetTableBox(rTLName); if(!pTLBox) return nullptr; - // invalidate all actions - UnoActionRemoveContext aRemoveContext(pFormat->GetDoc()); const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); // set cursor to the upper-left cell of the range @@ -2240,6 +2239,8 @@ uno::Reference<table::XCellRange> SwXTextTable::GetRangeByName(SwFrameFormat* p pUnoCrsr->GetPoint()->nNode = *pBRBox->GetSttNd(); pUnoCrsr->Move( fnMoveForward, fnGoNode ); SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr.get()); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(*pCrsr); pCrsr->MakeBoxSels(); // pUnoCrsr will be provided and will not be deleted return new SwXCellRange(pUnoCrsr, *pFormat, rDesc); @@ -2601,8 +2602,6 @@ void SwXTextTable::setPropertyValue(const OUString& rPropertyName, const uno::An SwTable* pTable = SwTable::FindTable( pFormat ); SwTableLines &rLines = pTable->GetTabLines(); - // invalidate all actions - UnoActionRemoveContext aRemoveContext(pDoc); const SwTableBox* pTLBox = lcl_FindCornerTableBox(rLines, true); const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); @@ -2616,6 +2615,8 @@ void SwXTextTable::setPropertyValue(const OUString& rPropertyName, const uno::An pUnoCrsr->GetPoint()->nNode = *pBRBox->GetSttNd(); pUnoCrsr->Move( fnMoveForward, fnGoNode ); SwUnoTableCrsr& rCrsr = dynamic_cast<SwUnoTableCrsr&>(*pUnoCrsr); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(rCrsr); rCrsr.MakeBoxSels(); SfxItemSet aSet(pDoc->GetAttrPool(), @@ -2790,8 +2791,6 @@ uno::Any SwXTextTable::getPropertyValue(const OUString& rPropertyName) SwTable* pTable = SwTable::FindTable( pFormat ); SwTableLines &rLines = pTable->GetTabLines(); - // invalidate all actions - UnoActionRemoveContext aRemoveContext(pDoc); const SwTableBox* pTLBox = lcl_FindCornerTableBox(rLines, true); const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); @@ -2807,6 +2806,8 @@ uno::Any SwXTextTable::getPropertyValue(const OUString& rPropertyName) pUnoCrsr->Move( fnMoveForward, fnGoNode ); SwUnoTableCrsr& rCrsr = dynamic_cast<SwUnoTableCrsr&>(*pUnoCrsr); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(rCrsr); rCrsr.MakeBoxSels(); SfxItemSet aSet(pDoc->GetAttrPool(), @@ -3240,8 +3241,6 @@ uno::Reference< table::XCellRange > SwXCellRange::getCellRangeByPosition( const SwTableBox* pTLBox = pTable->GetTableBox( sTLName ); if(pTLBox) { - // invalidate all actions - UnoActionRemoveContext aRemoveContext(pFormat->GetDoc()); const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); // set cursor in the upper-left cell of the range @@ -3255,6 +3254,8 @@ uno::Reference< table::XCellRange > SwXCellRange::getCellRangeByPosition( pUnoCrsr->GetPoint()->nNode = *pBRBox->GetSttNd(); pUnoCrsr->Move( fnMoveForward, fnGoNode ); SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr.get()); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(*pCrsr); pCrsr->MakeBoxSels(); // pUnoCrsr will be provided and will not be deleted SwXCellRange* pCellRange = new SwXCellRange(pUnoCrsr, *pFormat, aNewDesc); @@ -3312,11 +3313,11 @@ void SwXCellRange::setPropertyValue(const OUString& rPropertyName, const uno::An throw beans::PropertyVetoException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); SwDoc* pDoc = m_pTableCrsr->GetDoc(); + SwUnoTableCrsr& rCrsr = dynamic_cast<SwUnoTableCrsr&>(*m_pTableCrsr); { - // remove actions to enable box selection - UnoActionRemoveContext aRemoveContext(pDoc); + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(rCrsr); } - SwUnoTableCrsr& rCrsr = dynamic_cast<SwUnoTableCrsr&>(*m_pTableCrsr); rCrsr.MakeBoxSels(); switch(pEntry->nWID ) { @@ -3856,10 +3857,12 @@ void SwXTableRows::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount) SwPosition aPos(*pSttNd); // set cursor to the upper-left cell of the range UnoActionContext aAction(pFrameFormat->GetDoc()); - auto pUnoCrsr(pFrameFormat->GetDoc()->CreateUnoCrsr(aPos, true)); + std::shared_ptr<SwUnoTableCrsr> const pUnoCrsr( + std::dynamic_pointer_cast<SwUnoTableCrsr>( + pFrameFormat->GetDoc()->CreateUnoCrsr(aPos, true))); pUnoCrsr->Move( fnMoveForward, fnGoNode ); { - // remove actions + // remove actions - TODO: why? UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc()); } pFrameFormat->GetDoc()->InsertRow(*pUnoCrsr, (sal_uInt16)nCount, bAppend); @@ -3879,10 +3882,6 @@ void SwXTableRows::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) const SwTableBox* pTLBox = pTable->GetTableBox(sTLName); if(!pTLBox) throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this)); - { - // invalidate all actions - UnoActionRemoveContext aRemoveContext(pFrameFormat->GetDoc()); - } const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); // set cursor to the upper-left cell of the range @@ -3897,6 +3896,10 @@ void SwXTableRows::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) pUnoCrsr->GetPoint()->nNode = *pBLBox->GetSttNd(); pUnoCrsr->Move(fnMoveForward, fnGoNode); SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr.get()); + { + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(*pCrsr); + } pCrsr->MakeBoxSels(); { // these braces are important UnoActionContext aAction(pFrameFormat->GetDoc()); @@ -3904,7 +3907,7 @@ void SwXTableRows::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) pUnoCrsr.reset(); } { - // invalidate all actions + // invalidate all actions - TODO: why? UnoActionRemoveContext aRemoveContext(pFrameFormat->GetDoc()); } } @@ -3998,7 +4001,7 @@ void SwXTableColumns::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount) pUnoCrsr->Move(fnMoveForward, fnGoNode); { - // remove actions + // remove actions - TODO: why? UnoActionRemoveContext aRemoveContext(pUnoCrsr->GetDoc()); } @@ -4020,10 +4023,6 @@ void SwXTableColumns::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) const SwTableBox* pTLBox = pTable->GetTableBox( sTLName ); if(!pTLBox) throw uno::RuntimeException("Cell not found", static_cast<cppu::OWeakObject*>(this)); - { - // invalidate all actions - UnoActionRemoveContext aRemoveContext(pFrameFormat->GetDoc()); - } const SwStartNode* pSttNd = pTLBox->GetSttNd(); SwPosition aPos(*pSttNd); // set cursor to the upper-left cell of the range @@ -4038,6 +4037,10 @@ void SwXTableColumns::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) pUnoCrsr->GetPoint()->nNode = *pTRBox->GetSttNd(); pUnoCrsr->Move(fnMoveForward, fnGoNode); SwUnoTableCrsr* pCrsr = dynamic_cast<SwUnoTableCrsr*>(pUnoCrsr.get()); + { + // HACK: remove pending actions for selecting old style tables + UnoActionRemoveContext aRemoveContext(*pCrsr); + } pCrsr->MakeBoxSels(); { // these braces are important UnoActionContext aAction(pFrameFormat->GetDoc()); @@ -4045,7 +4048,7 @@ void SwXTableColumns::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount) pUnoCrsr.reset(); } { - // invalidate all actions + // invalidate all actions - TODO: why? UnoActionRemoveContext aRemoveContext(pFrameFormat->GetDoc()); } } diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx index 82d8a3f348d3..631e6efe23a0 100644 --- a/sw/source/uibase/uno/unotxvw.cxx +++ b/sw/source/uibase/uno/unotxvw.cxx @@ -283,7 +283,7 @@ sal_Bool SwXTextView::select(const uno::Any& aInterface) } else if (pTableCursor) { - UnoActionRemoveContext const aContext(pDoc); + UnoActionRemoveContext const aContext(*pTableCursor); rSh.EnterStdMode(); rSh.SetSelection(*pTableCursor); return sal_True; |