summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-05-18 12:09:54 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-05-18 12:11:50 -0400
commit1735044e9f693cde1af0d905d264c849e3fce311 (patch)
tree7fb0343daf6daded818e37f170ea1984ba01f391 /sc
parentdd15b51ddaf4a143d494076a6dd554a059d91489 (diff)
Adjust sheet fields in cells when sheet structure changes.
Change-Id: I0aff738968e286df57ef7dd5b67780108cdc6c89
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/cell.hxx3
-rw-r--r--sc/inc/column.hxx8
-rw-r--r--sc/source/core/data/cell2.cxx10
-rw-r--r--sc/source/core/data/column.cxx130
4 files changed, 106 insertions, 45 deletions
diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 3bf2dfe7d87f..de4d1ad7e72b 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -258,6 +258,9 @@ public:
/** Removes character attribute based on new pattern attributes. */
void RemoveCharAttribs( const ScPatternAttr& rAttr );
+
+ /** Update field items if any. */
+ void UpdateFields(SCTAB nTab);
};
class ScEditDataArray
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 4988ffcf6616..446f4de5e4e9 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -281,9 +281,9 @@ public:
SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
ScDocument* pUndoDoc = NULL );
- void UpdateInsertTab( SCTAB nTable, SCTAB nNewSheets = 1);
- void UpdateInsertTabOnlyCells( SCTAB nTable, SCTAB nNewSheets = 1);
- void UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo = NULL, SCTAB nSheets = 1 );
+ void UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets = 1);
+ void UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets = 1);
+ void UpdateDeleteTab(SCTAB nDelPos, bool bIsMove, ScColumn* pRefUndo = NULL, SCTAB nSheets = 1);
void UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
void UpdateCompile( bool bForceIfNameInUse = false );
void UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
@@ -373,7 +373,7 @@ public:
void GetFilterEntries(SCROW nStartRow, SCROW nEndRow, std::vector<ScTypedStrData>& rStrings, bool& rHasDates);
bool GetDataEntries(SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit);
- void UpdateInsertTabAbs(SCTAB nNewPos);
+ void UpdateInsertTabAbs(SCTAB nNewPos);
bool TestTabRefAbs(SCTAB nTable);
bool GetNextSpellingCell(SCROW& nRow, bool bInSel, const ScMarkData& rData) const;
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index c8c6b9b8af06..1e0dcbe6728a 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -78,9 +78,7 @@ ScEditCell::ScEditCell(const ScEditCell& rCell, ScDocument& rDoc, const ScAddres
ScBaseCell(rCell), pString(NULL), pDoc(&rDoc)
{
SetTextObject( rCell.pData, rCell.pDoc->GetEditPool() );
-
- editeng::FieldUpdater aUpdater = pData->GetFieldUpdater();
- aUpdater.updateTableFields(rDestPos.Tab());
+ UpdateFields(rDestPos.Tab());
}
ScEditCell::ScEditCell( const rtl::OUString& rString, ScDocument* pDocP ) :
@@ -166,6 +164,12 @@ void ScEditCell::RemoveCharAttribs( const ScPatternAttr& rAttr )
}
}
+void ScEditCell::UpdateFields(SCTAB nTab)
+{
+ editeng::FieldUpdater aUpdater = pData->GetFieldUpdater();
+ aUpdater.updateTableFields(nTab);
+}
+
void ScEditCell::SetTextObject( const EditTextObject* pObject,
const SfxItemPool* pFromPool )
{
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 9ae787b33986..eebb17ae649f 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1668,72 +1668,102 @@ void ScColumn::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
}
-void ScColumn::UpdateInsertTab( SCTAB nTable, SCTAB nNewSheets )
+void ScColumn::UpdateInsertTab(SCTAB nInsPos, SCTAB nNewSheets)
{
- if (nTab >= nTable)
+ if (nTab >= nInsPos)
{
nTab += nNewSheets;
pAttrArray->SetTab(nTab);
}
- if ( !maItems.empty() )
- UpdateInsertTabOnlyCells( nTable, nNewSheets );
-}
+ UpdateInsertTabOnlyCells(nInsPos, nNewSheets);
+}
-void ScColumn::UpdateInsertTabOnlyCells( SCTAB nTable, SCTAB nNewSheets )
+void ScColumn::UpdateInsertTabOnlyCells(SCTAB nInsPos, SCTAB nNewSheets)
{
- if ( !maItems.empty() )
- for (SCSIZE i = 0; i < maItems.size(); i++)
+ if (maItems.empty())
+ return;
+
+ for (size_t i = 0; i < maItems.size(); ++i)
+ {
+ switch (maItems[i].pCell->GetCellType())
{
- ScFormulaCell* pCell = (ScFormulaCell*) maItems[i].pCell;
- if( pCell->GetCellType() == CELLTYPE_FORMULA)
+ case CELLTYPE_FORMULA:
{
SCROW nRow = maItems[i].nRow;
- pCell->UpdateInsertTab(nTable, nNewSheets);
- if ( nRow != maItems[i].nRow )
- Search( nRow, i ); // Listener geloescht/eingefuegt?
+ ScFormulaCell* p = static_cast<ScFormulaCell*>(maItems[i].pCell);
+ p->UpdateInsertTab(nInsPos, nNewSheets);
+ if (nRow != maItems[i].nRow)
+ Search(nRow, i); // Listener deleted/inserted?
+ }
+ break;
+ case CELLTYPE_EDIT:
+ {
+ ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
+ p->UpdateFields(nTab);
}
+ break;
+ default:
+ ;
}
+ }
}
-
-void ScColumn::UpdateInsertTabAbs(SCTAB nTable)
+void ScColumn::UpdateInsertTabAbs(SCTAB nNewPos)
{
- if ( !maItems.empty() )
- for (SCSIZE i = 0; i < maItems.size(); i++)
+ if (maItems.empty())
+ return;
+
+ for (size_t i = 0; i < maItems.size(); ++i)
+ {
+ switch (maItems[i].pCell->GetCellType())
{
- ScFormulaCell* pCell = (ScFormulaCell*) maItems[i].pCell;
- if( pCell->GetCellType() == CELLTYPE_FORMULA)
+ case CELLTYPE_FORMULA:
{
SCROW nRow = maItems[i].nRow;
- pCell->UpdateInsertTabAbs(nTable);
- if ( nRow != maItems[i].nRow )
- Search( nRow, i ); // Listener geloescht/eingefuegt?
+ ScFormulaCell* p = static_cast<ScFormulaCell*>(maItems[i].pCell);
+ p->UpdateInsertTabAbs(nNewPos);
+ if (nRow != maItems[i].nRow)
+ Search(nRow, i); // Listener deleted/inserted?
}
+ break;
+ case CELLTYPE_EDIT:
+ {
+ ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
+ p->UpdateFields(nTab);
+ }
+ break;
+ default:
+ ;
}
+ }
}
-
-void ScColumn::UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo, SCTAB nSheets )
+void ScColumn::UpdateDeleteTab(SCTAB nDelPos, bool bIsMove, ScColumn* pRefUndo, SCTAB nSheets)
{
- if (nTab > nTable)
+ if (nTab > nDelPos)
{
nTab -= nSheets;
pAttrArray->SetTab(nTab);
}
- if ( !maItems.empty() )
- for (SCSIZE i = 0; i < maItems.size(); i++)
- if ( maItems[i].pCell->GetCellType() == CELLTYPE_FORMULA )
+ if (maItems.empty())
+ return;
+
+ for (size_t i = 0; i < maItems.size(); ++i)
+ {
+ switch (maItems[i].pCell->GetCellType())
+ {
+ case CELLTYPE_FORMULA:
{
SCROW nRow = maItems[i].nRow;
- ScFormulaCell* pOld = (ScFormulaCell*)maItems[i].pCell;
+ ScFormulaCell* pOld = static_cast<ScFormulaCell*>(maItems[i].pCell);
/* Do not copy cell note to the undo document. Undo will copy
back the formula cell while keeping the original note. */
ScBaseCell* pSave = pRefUndo ? pOld->Clone( *pDocument ) : 0;
- bool bChanged = pOld->UpdateDeleteTab(nTable, bIsMove, nSheets);
+ bool bChanged = pOld->UpdateDeleteTab(nDelPos, bIsMove, nSheets);
if ( nRow != maItems[i].nRow )
Search( nRow, i ); // Listener geloescht/eingefuegt?
@@ -1745,25 +1775,49 @@ void ScColumn::UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo,
pSave->Delete();
}
}
+ break;
+ case CELLTYPE_EDIT:
+ {
+ ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
+ p->UpdateFields(nTab);
+ }
+ break;
+ default:
+ ;
+ }
+ }
}
-
void ScColumn::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo )
{
nTab = nTabNo;
pAttrArray->SetTab( nTabNo );
- if ( !maItems.empty() )
- for (SCSIZE i = 0; i < maItems.size(); i++)
+ if (maItems.empty())
+ return;
+
+ for (size_t i = 0; i < maItems.size(); ++i)
+ {
+ switch (maItems[i].pCell->GetCellType())
{
- ScFormulaCell* pCell = (ScFormulaCell*) maItems[i].pCell;
- if ( pCell->GetCellType() == CELLTYPE_FORMULA )
+ case CELLTYPE_FORMULA:
{
+ ScFormulaCell* p = static_cast<ScFormulaCell*>(maItems[i].pCell);
SCROW nRow = maItems[i].nRow;
- pCell->UpdateMoveTab( nOldPos, nNewPos, nTabNo );
- if ( nRow != maItems[i].nRow )
- Search( nRow, i ); // Listener geloescht/eingefuegt?
+ p->UpdateMoveTab(nOldPos, nNewPos, nTabNo);
+ if (nRow != maItems[i].nRow)
+ Search(nRow, i); // Listener deleted/inserted?
}
+ break;
+ case CELLTYPE_EDIT:
+ {
+ ScEditCell* p = static_cast<ScEditCell*>(maItems[i].pCell);
+ p->UpdateFields(nTab);
+ }
+ break;
+ default:
+ ;
}
+ }
}