sc/inc/cell.hxx                |    3 
 sc/inc/column.hxx              |    8 +-
 sc/source/core/data/cell2.cxx  |   10 ++-
 sc/source/core/data/column.cxx |  130 +++++++++++++++++++++++++++++------------
 4 files changed, 106 insertions(+), 45 deletions(-)

New commits:
commit 1735044e9f693cde1af0d905d264c849e3fce311
Author: Kohei Yoshida <kohei.yosh...@gmail.com>
Date:   Fri May 18 12:09:54 2012 -0400

    Adjust sheet fields in cells when sheet structure changes.
    
    Change-Id: I0aff738968e286df57ef7dd5b67780108cdc6c89

diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 3bf2dfe..de4d1ad 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 4988ffc..446f4de 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 c8c6b9b..1e0dcbe 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 9ae787b..eebb17a 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:
+                ;
         }
+    }
 }
 
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to