diff options
-rw-r--r-- | sc/inc/externalrefmgr.hxx | 7 | ||||
-rw-r--r-- | sc/inc/formulacell.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 18 | ||||
-rw-r--r-- | sc/source/ui/docshell/externalrefmgr.cxx | 35 |
4 files changed, 57 insertions, 6 deletions
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx index 369066b6dd1d..792c0059c3b9 100644 --- a/sc/inc/externalrefmgr.hxx +++ b/sc/inc/externalrefmgr.hxx @@ -699,6 +699,12 @@ public: bool containsUnsavedReferences() const { return !maUnsavedDocShells.empty(); } void insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell); + /** + * Add a cell to reference the same files as the template cell. + */ + void insertRefCellFromTemplate( ScFormulaCell* pTemplateCell, ScFormulaCell* pCell ); + + bool hasCellExternalReference(const ScAddress& rCell); void enableDocTimer( bool bEnable ); @@ -788,6 +794,7 @@ private: */ void transformUnsavedRefToSavedRef( SfxObjectShell* pShell ); + void insertRefCell(RefCellMap::iterator& itr, ScFormulaCell* pCell); private: ScDocument* mpDoc; diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx index 8e84e00e4898..66f4c9b03cc5 100644 --- a/sc/inc/formulacell.hxx +++ b/sc/inc/formulacell.hxx @@ -143,6 +143,7 @@ private: bool bNeedListening : 1; // Listeners need to be re-established after UpdateReference bool mbNeedsNumberFormat : 1; // set the calculated number format as hard number format bool mbPostponedDirty : 1; // if cell needs to be set dirty later + bool mbIsExtRef : 1; // has references in ScExternalRefManager; never cleared after set enum ScInterpretTailParameter { @@ -426,6 +427,8 @@ public: void SyncSharedCode(); bool IsPostponedDirty() const { return mbPostponedDirty;} + + void SetIsExtRef() { mbIsExtRef = true; } }; #endif diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 33499badc26a..6352dce6c81d 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -608,6 +608,7 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos ) : bNeedListening(false), mbNeedsNumberFormat(false), mbPostponedDirty(false), + mbIsExtRef(false), aPos(rPos) { SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this); @@ -638,7 +639,8 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos, bNeedListening( false ), mbNeedsNumberFormat( false ), mbPostponedDirty(false), - aPos( rPos ) + mbIsExtRef(false), + aPos(rPos) { SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this); @@ -672,7 +674,8 @@ ScFormulaCell::ScFormulaCell( bNeedListening( false ), mbNeedsNumberFormat( false ), mbPostponedDirty(false), - aPos( rPos ) + mbIsExtRef(false), + aPos(rPos) { SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this); assert(pArray); // Never pass a NULL pointer here. @@ -721,7 +724,8 @@ ScFormulaCell::ScFormulaCell( bNeedListening( false ), mbNeedsNumberFormat( false ), mbPostponedDirty(false), - aPos( rPos ) + mbIsExtRef(false), + aPos(rPos) { SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this); @@ -770,7 +774,8 @@ ScFormulaCell::ScFormulaCell( bNeedListening( false ), mbNeedsNumberFormat( false ), mbPostponedDirty(false), - aPos( rPos ) + mbIsExtRef(false), + aPos(rPos) { SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this); @@ -801,7 +806,8 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons bNeedListening( false ), mbNeedsNumberFormat( false ), mbPostponedDirty(false), - aPos( rPos ) + mbIsExtRef(false), + aPos(rPos) { SAL_INFO( "sc.core.formulacell", "ScFormulaCell ctor this " << this); @@ -1294,6 +1300,8 @@ void ScFormulaCell::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rPr bSkipCompile = true; pCode = pPreviousCell->pCode; + if (pPreviousCell->mbIsExtRef) + pDocument->GetExternalRefManager()->insertRefCellFromTemplate( pPreviousCell, this ); SAL_INFO( "sc", "merged '" << aFormula << "' == '" << aShouldBe << "'extend group to " << xGroup->mnLength ); diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx index be0f447af37e..442ff2f0a366 100644 --- a/sc/source/ui/docshell/externalrefmgr.cxx +++ b/sc/source/ui/docshell/externalrefmgr.cxx @@ -2038,6 +2038,15 @@ void ScExternalRefManager::refreshAllRefCells(sal_uInt16 nFileId) pVShell->PaintGrid(); } +void ScExternalRefManager::insertRefCell(RefCellMap::iterator& itr, ScFormulaCell* pCell) +{ + if (pCell) + { + itr->second.insert(pCell); + pCell->SetIsExtRef(); + } +} + void ScExternalRefManager::insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell) { RefCellMap::iterator itr = maRefCells.find(nFileId); @@ -2053,9 +2062,33 @@ void ScExternalRefManager::insertRefCell(sal_uInt16 nFileId, const ScAddress& rC itr = r.first; } + insertRefCell(itr, mpDoc->GetFormulaCell(rCell)); +} + +void ScExternalRefManager::insertRefCellFromTemplate( ScFormulaCell* pTemplateCell, ScFormulaCell* pCell ) +{ + if (!pTemplateCell || !pCell) + return; + + for (RefCellMap::iterator itr = maRefCells.begin(); itr != maRefCells.end(); ++itr) + { + if (itr->second.find(pTemplateCell) != itr->second.end()) + insertRefCell(itr, pCell); + } +} + +bool ScExternalRefManager::hasCellExternalReference(const ScAddress& rCell) +{ ScFormulaCell* pCell = mpDoc->GetFormulaCell(rCell); + if (pCell) - itr->second.insert(pCell); + for (RefCellMap::iterator itr = maRefCells.begin(); itr != maRefCells.end(); ++itr) + { + if (itr->second.find(pCell) != itr->second.end()) + return true; + } + + return false; } void ScExternalRefManager::enableDocTimer( bool bEnable ) |