[Libreoffice-commits] .: 31 commits - sc/0001-add-unit-test-for-ScDocument-MoveTab.patch sc/inc sc/qa sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Mon Jun 6 20:10:34 PDT 2011


 sc/0001-add-unit-test-for-ScDocument-MoveTab.patch |   90 +
 sc/inc/address.hxx                                 |    2 
 sc/inc/appoptio.hxx                                |    6 
 sc/inc/cell.hxx                                    |    4 
 sc/inc/column.hxx                                  |    6 
 sc/inc/compiler.hxx                                |    4 
 sc/inc/document.hxx                                |   15 
 sc/inc/markdata.hxx                                |    9 
 sc/inc/rangenam.hxx                                |    4 
 sc/inc/sheetdata.hxx                               |   16 
 sc/inc/table.hxx                                   |    6 
 sc/qa/unit/ucalc.cxx                               |    2 
 sc/source/core/data/cell2.cxx                      |   22 
 sc/source/core/data/column.cxx                     |   22 
 sc/source/core/data/dociter.cxx                    |   55 -
 sc/source/core/data/documen2.cxx                   |  138 +-
 sc/source/core/data/documen3.cxx                   |  166 +--
 sc/source/core/data/documen4.cxx                   |   87 -
 sc/source/core/data/documen5.cxx                   |   16 
 sc/source/core/data/documen7.cxx                   |    8 
 sc/source/core/data/documen8.cxx                   |   16 
 sc/source/core/data/documen9.cxx                   |   31 
 sc/source/core/data/document.cxx                   | 1122 +++++++++++++--------
 sc/source/core/data/markdata.cxx                   |   95 +
 sc/source/core/data/table1.cxx                     |   19 
 sc/source/core/tool/compiler.cxx                   |   30 
 sc/source/core/tool/rangenam.cxx                   |    8 
 sc/source/filter/inc/scflt.hxx                     |    6 
 sc/source/filter/xml/XMLTableSourceContext.cxx     |    4 
 sc/source/filter/xml/sheetdata.cxx                 |   24 
 sc/source/filter/xml/xmlcoli.cxx                   |    8 
 sc/source/filter/xml/xmlimprt.cxx                  |    2 
 sc/source/filter/xml/xmlimprt.hxx                  |    4 
 sc/source/filter/xml/xmlrowi.cxx                   |    8 
 sc/source/filter/xml/xmlsceni.cxx                  |    2 
 sc/source/filter/xml/xmlstyli.cxx                  |    4 
 sc/source/filter/xml/xmlstyli.hxx                  |    6 
 sc/source/filter/xml/xmlsubti.cxx                  |   20 
 sc/source/filter/xml/xmlsubti.hxx                  |    6 
 sc/source/filter/xml/xmltabi.cxx                   |    8 
 sc/source/ui/app/scmod.cxx                         |   11 
 sc/source/ui/app/transobj.cxx                      |    6 
 sc/source/ui/docshell/docsh.cxx                    |   13 
 sc/source/ui/docshell/docsh5.cxx                   |    9 
 sc/source/ui/inc/pfuncache.hxx                     |    4 
 sc/source/ui/inc/preview.hxx                       |    6 
 sc/source/ui/inc/uiitems.hxx                       |    2 
 sc/source/ui/inc/undotab.hxx                       |    4 
 sc/source/ui/inc/viewdata.hxx                      |    4 
 sc/source/ui/inc/viewfunc.hxx                      |    3 
 sc/source/ui/undo/undotab.cxx                      |   44 
 sc/source/ui/vba/vbaquerytable.cxx                 |    6 
 sc/source/ui/view/cellsh3.cxx                      |    2 
 sc/source/ui/view/gridwin.cxx                      |    9 
 sc/source/ui/view/pfuncache.cxx                    |   17 
 sc/source/ui/view/preview.cxx                      |   22 
 sc/source/ui/view/tabvwsh5.cxx                     |   14 
 sc/source/ui/view/tabvwshf.cxx                     |   29 
 sc/source/ui/view/viewdata.cxx                     |  139 +-
 sc/source/ui/view/viewfun2.cxx                     |  101 +
 sc/source/ui/view/viewfun3.cxx                     |    4 
 61 files changed, 1541 insertions(+), 1009 deletions(-)

New commits:
commit 875256988eb473971160e445ace665b8dc701030
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Jun 7 05:07:19 2011 +0200

    enable unit test testSheetMove

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index fca7947..446e734 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -277,9 +277,7 @@ public:
     CPPUNIT_TEST(testDataPilot);
     CPPUNIT_TEST(testDataPilotFilters);
     CPPUNIT_TEST(testSheetCopy);
-#if 0 // Disabled, first problem with ScProgress in ScDocument::MoveTab must be solved
     CPPUNIT_TEST(testSheetMove);
-#endif
     CPPUNIT_TEST(testExternalRef);
     CPPUNIT_TEST(testDataArea);
     CPPUNIT_TEST(testGraphicsInGroup);
commit d4e075d119acd7d88e42fd13188e259a2f1130c4
Merge: c29bbab... c93818d...
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Jun 7 05:04:57 2011 +0200

    Merge branch 'feature/unlimited-number-of-sheets'
    
    Conflicts:
    	sc/source/core/data/dociter.cxx
    	sc/source/core/data/table1.cxx
    	sc/source/ui/view/preview.cxx

diff --cc sc/0001-add-unit-test-for-ScDocument-MoveTab.patch
index 0000000,0000000..005e6e5
new file mode 100644
--- /dev/null
+++ b/sc/0001-add-unit-test-for-ScDocument-MoveTab.patch
@@@ -1,0 -1,0 +1,90 @@@
++From e8c376c207e89f0b6155e4bbcd0f46421db116ea Mon Sep 17 00:00:00 2001
++From: Markus Mohrhard <markus.mohrhard at googlemail.com>
++Date: Thu, 26 May 2011 19:12:43 +0200
++Subject: [PATCH] add unit test for ScDocument::MoveTab
++
++this unit test is disabled for now because there is a problem with ScProgress in ScDocument::MoveTab during unit tests
++---
++ sc/qa/unit/ucalc.cxx |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++
++ 1 files changed, 52 insertions(+), 0 deletions(-)
++
++diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
++index a55fbbf..c43eb01 100644
++--- a/sc/qa/unit/ucalc.cxx
+++++ b/sc/qa/unit/ucalc.cxx
++@@ -236,6 +236,7 @@ public:
++     void testDataPilot();
++     void testDataPilotFilters();
++     void testSheetCopy();
+++    void testSheetMove();
++     void testExternalRef();
++     void testDataArea();
++ 
++@@ -276,6 +277,9 @@ public:
++     CPPUNIT_TEST(testDataPilot);
++     CPPUNIT_TEST(testDataPilotFilters);
++     CPPUNIT_TEST(testSheetCopy);
+++#if 0 // Disabled, first problem with ScProgress in ScDocument::MoveTab must be solved
+++    CPPUNIT_TEST(testSheetMove);
+++#endif
++     CPPUNIT_TEST(testExternalRef);
++     CPPUNIT_TEST(testDataArea);
++     CPPUNIT_TEST(testGraphicsInGroup);
++@@ -1238,6 +1242,54 @@ void Test::testSheetCopy()
++     CPPUNIT_ASSERT_MESSAGE("rows 5 - 10 should be hidden", bHidden && nRow1 == 5 && nRow2 == 10);
++     bHidden = m_pDoc->RowHidden(11, 1, &nRow1, &nRow2);
++     CPPUNIT_ASSERT_MESSAGE("rows 11 - maxrow should be visible", !bHidden && nRow1 == 11 && nRow2 == MAXROW);
+++    m_pDoc->DeleteTab(1);
+++    m_pDoc->DeleteTab(0);
+++}
+++
+++void Test::testSheetMove()
+++{
+++    OUString aTabName(RTL_CONSTASCII_USTRINGPARAM("TestTab1"));
+++    m_pDoc->InsertTab(0, aTabName);
+++    CPPUNIT_ASSERT_MESSAGE("document should have one sheet to begin with.", m_pDoc->GetTableCount() == 1);
+++    SCROW nRow1, nRow2;
+++    bool bHidden = m_pDoc->RowHidden(0, 0, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("new sheet should have all rows visible", !bHidden && nRow1 == 0 && nRow2 == MAXROW);
+++
+++    //test if inserting before another sheet works
+++    m_pDoc->InsertTab(0, OUString(RTL_CONSTASCII_USTRINGPARAM("TestTab2")));
+++    CPPUNIT_ASSERT_MESSAGE("document should have two sheets", m_pDoc->GetTableCount() == 2);
+++    bHidden = m_pDoc->RowHidden(0, 0, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("new sheet should have all rows visible", !bHidden && nRow1 == 0 && nRow2 == MAXROW);
+++
+++    // Move and test the result.
+++    m_pDoc->MoveTab(0, 1);
+++    CPPUNIT_ASSERT_MESSAGE("document now should have two sheets.", m_pDoc->GetTableCount() == 2);
+++    bHidden = m_pDoc->RowHidden(0, 1, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("copied sheet should also have all rows visible as the original.", !bHidden && nRow1 == 0 && nRow2 == MAXROW);
+++    String aName;
+++    m_pDoc->GetName(0, aName);
+++    CPPUNIT_ASSERT_MESSAGE("sheets should have changed places", aName.EqualsAscii("TestTab1"));
+++
+++    m_pDoc->SetRowHidden(5, 10, 0, true);
+++    bHidden = m_pDoc->RowHidden(0, 0, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("rows 0 - 4 should be visible", !bHidden && nRow1 == 0 && nRow2 == 4);
+++    bHidden = m_pDoc->RowHidden(5, 0, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("rows 5 - 10 should be hidden", bHidden && nRow1 == 5 && nRow2 == 10);
+++    bHidden = m_pDoc->RowHidden(11, 0, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("rows 11 - maxrow should be visible", !bHidden && nRow1 == 11 && nRow2 == MAXROW);
+++
+++    // Move the sheet once again.
+++    m_pDoc->MoveTab(1, 0);
+++    CPPUNIT_ASSERT_MESSAGE("document now should have two sheets.", m_pDoc->GetTableCount() == 2);
+++    bHidden = m_pDoc->RowHidden(0, 1, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("rows 0 - 4 should be visible", !bHidden && nRow1 == 0 && nRow2 == 4);
+++    bHidden = m_pDoc->RowHidden(5, 1, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("rows 5 - 10 should be hidden", bHidden && nRow1 == 5 && nRow2 == 10);
+++    bHidden = m_pDoc->RowHidden(11, 1, &nRow1, &nRow2);
+++    CPPUNIT_ASSERT_MESSAGE("rows 11 - maxrow should be visible", !bHidden && nRow1 == 11 && nRow2 == MAXROW);
+++    m_pDoc->GetName(0, aName);
+++    CPPUNIT_ASSERT_MESSAGE("sheets should have changed places", aName.EqualsAscii("TestTab2"));
+++    m_pDoc->DeleteTab(1);
++     m_pDoc->DeleteTab(0);
++ }
++ 
++-- 
++1.7.2.5
++
diff --cc sc/source/core/data/dociter.cxx
index 543a2b9,9b11985..f625e4c
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@@ -1747,7 -1772,9 +1772,9 @@@ ScHorizontalAttrIterator::ScHorizontalA
      nEndCol( nCol2 ),
      nEndRow( nRow2 )
  {
+     if (nTab >= pDoc->GetTableCount())
+         OSL_FAIL("try to access index out of bounds, FIX IT");
 -    DBG_ASSERT( pDoc->pTab[nTab], "Tabelle nicht da" );
 +    OSL_ENSURE( pDoc->pTab[nTab], "Tabelle nicht da" );
  
      SCCOL i;
  
diff --cc sc/source/core/data/documen5.cxx
index a983a24,07ea3cd..485ac6c
--- a/sc/source/core/data/documen5.cxx
+++ b/sc/source/core/data/documen5.cxx
@@@ -130,12 -130,13 +130,12 @@@ void ScDocument::UpdateAllCharts(
      if ( !pDrawLayer || !pShell )
          return;
  
 -    sal_uInt16 nDataCount = pChartCollection->GetCount();
 -    if ( !nDataCount )
 +    if (pChartCollection->empty())
          return ;		// nothing to do
  
 -    sal_uInt16 nPos;
 +    size_t nDataCount = pChartCollection->size();
  
-     for (SCTAB nTab=0; nTab<=MAXTAB; nTab++)
+     for (SCTAB nTab=0; nTab< static_cast<SCTAB>(pTab.size()); nTab++)
      {
          if (pTab[nTab])
          {
@@@ -205,10 -206,10 +205,10 @@@
  
  sal_Bool ScDocument::HasChartAtPoint( SCTAB nTab, const Point& rPos, String* pName )
  {
-     if (pDrawLayer && pTab[nTab])
+     if (pDrawLayer && nTab < static_cast<SCTAB>(pTab.size()) && pTab[nTab])
      {
          SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
 -        DBG_ASSERT(pPage,"Page ?");
 +        OSL_ENSURE(pPage,"Page ?");
  
          SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
          SdrObject* pObject = aIter.Next();
@@@ -251,10 -252,10 +251,10 @@@ uno::Reference< chart2::XChartDocument 
      if (pDrawLayer)
      {
          sal_uInt16 nCount = pDrawLayer->GetPageCount();
-         for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
+         for (sal_uInt16 nTab=0; nTab<nCount&& nTab < static_cast<SCTAB>(pTab.size()); nTab++)
          {
              SdrPage* pPage = pDrawLayer->GetPage(nTab);
 -            DBG_ASSERT(pPage,"Page ?");
 +            OSL_ENSURE(pPage,"Page ?");
  
              SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
              SdrObject* pObject = aIter.Next();
@@@ -316,10 -317,10 +316,10 @@@ void ScDocument::GetOldChartParameters
          return;
  
      sal_uInt16 nCount = pDrawLayer->GetPageCount();
-     for (sal_uInt16 nTab=0; nTab<nCount; nTab++)
+     for (sal_uInt16 nTab=0; nTab<nCount && nTab < static_cast<SCTAB>(pTab.size()); nTab++)
      {
          SdrPage* pPage = pDrawLayer->GetPage(nTab);
 -        DBG_ASSERT(pPage,"Page ?");
 +        OSL_ENSURE(pPage,"Page ?");
  
          SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
          SdrObject* pObject = aIter.Next();
@@@ -363,10 -364,10 +363,10 @@@ void ScDocument::UpdateChartArea( cons
      if (!pDrawLayer)
          return;
  
-     for (SCTAB nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++)
+     for (SCTAB nTab=0; nTab< static_cast<SCTAB>(pTab.size()) && pTab[nTab]; nTab++)
      {
          SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
 -        DBG_ASSERT(pPage,"Page ?");
 +        OSL_ENSURE(pPage,"Page ?");
  
          SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
          SdrObject* pObject = aIter.Next();
@@@ -598,10 -599,10 +598,10 @@@ void ScDocument::SetChartRangeList( con
      if (!pDrawLayer)
          return;
  
-     for (SCTAB nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++)
+     for (SCTAB nTab=0; nTab< static_cast<SCTAB>(pTab.size()) && pTab[nTab]; nTab++)
      {
          SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
 -        DBG_ASSERT(pPage,"Page ?");
 +        OSL_ENSURE(pPage,"Page ?");
  
          SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
          SdrObject* pObject = aIter.Next();
diff --cc sc/source/core/data/documen7.cxx
index 3009dbc,88955a4..6abb6de
--- a/sc/source/core/data/documen7.cxx
+++ b/sc/source/core/data/documen7.cxx
@@@ -191,18 -191,18 +191,18 @@@ void ScDocument::DelBroadcastAreasInRan
  void ScDocument::StartListeningCell( const ScAddress& rAddress,
                                              SvtListener* pListener )
  {
 -    DBG_ASSERT(pListener, "StartListeningCell: pListener Null");
 +    OSL_ENSURE(pListener, "StartListeningCell: pListener Null");
      SCTAB nTab = rAddress.Tab();
-     if (pTab[nTab])
+     if (nTab < static_cast<SCTAB>(pTab.size()) && pTab[nTab])
          pTab[nTab]->StartListening( rAddress, pListener );
  }
  
  void ScDocument::EndListeningCell( const ScAddress& rAddress,
                                              SvtListener* pListener )
  {
 -    DBG_ASSERT(pListener, "EndListeningCell: pListener Null");
 +    OSL_ENSURE(pListener, "EndListeningCell: pListener Null");
      SCTAB nTab = rAddress.Tab();
-     if (pTab[nTab])
+     if (nTab < static_cast<SCTAB>(pTab.size()) && pTab[nTab])
          pTab[nTab]->EndListening( rAddress, pListener );
  }
  
diff --cc sc/source/core/data/documen9.cxx
index dcfef9a,03602e9..b15984c
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@@ -426,10 -426,10 +426,10 @@@ SdrObject* ScDocument::GetObjectAtPoint
      //	fuer Drag&Drop auf Zeichenobjekt
  
      SdrObject* pFound = NULL;
-     if (pDrawLayer && pTab[nTab])
+     if (pDrawLayer && nTab < static_cast<SCTAB>(pTab.size()) && pTab[nTab])
      {
          SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
 -        DBG_ASSERT(pPage,"Page ?");
 +        OSL_ENSURE(pPage,"Page ?");
          if (pPage)
          {
              SdrObjListIter aIter( *pPage, IM_FLAT );
diff --cc sc/source/core/data/document.cxx
index 7fd34ec,1d1808e..c4ae55d
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@@ -162,9 -168,10 +169,9 @@@ sal_Bool ScDocument::HasTable( SCTAB nT
      return false;
  }
  
 -
 -sal_Bool ScDocument::GetName( SCTAB nTab, String& rName ) const
 +bool ScDocument::GetName( SCTAB nTab, String& rName ) const
  {
-     if (VALIDTAB(nTab))
+     if (VALIDTAB(nTab) && nTab < static_cast<SCTAB>(pTab.size()))
          if (pTab[nTab])
          {
              pTab[nTab]->GetName( rName );
@@@ -174,17 -181,9 +181,17 @@@
      return false;
  }
  
 +bool ScDocument::GetName( SCTAB nTab, OUString& rName ) const
 +{
 +    String aTmp;
 +    bool bRet = GetName(nTab, aTmp);
 +    rName = aTmp;
 +    return bRet;
 +}
 +
  sal_Bool ScDocument::SetCodeName( SCTAB nTab, const String& rName )
  {
-     if (VALIDTAB(nTab))
+     if (VALIDTAB(nTab) && nTab < static_cast<SCTAB>(pTab.size()))
      {
          if (pTab[nTab])
          {
@@@ -3160,11 -3422,13 +3430,13 @@@ void ScDocument::CompileXML(
                  STR_PROGRESS_CALCULATING ), GetXMLImportedFormulaCount() );
  
      // set AutoNameCache to speed up automatic name lookup
 -    DBG_ASSERT( !pAutoNameCache, "AutoNameCache already set" );
 +    OSL_ENSURE( !pAutoNameCache, "AutoNameCache already set" );
      pAutoNameCache = new ScAutoNameCache( this );
  
-     for (SCTAB i=0; i<=MAXTAB; i++)
-         if (pTab[i]) pTab[i]->CompileXML( aProgress );
+     TableContainer::iterator it = pTab.begin();
+     for (; it != pTab.end(); ++it)
+         if (*it)
+             (*it)->CompileXML( aProgress );
  
      DELETEZ( pAutoNameCache );  // valid only during CompileXML, where cell contents don't change
  
diff --cc sc/source/core/data/table1.cxx
index e3dde65,e92a626..0d0f572
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@@ -1398,28 -1398,20 +1398,28 @@@ void ScTable::UpdateGrow( const ScRange
          aCol[i].UpdateGrow( rArea, nGrowX, nGrowY );
  }
  
- void ScTable::UpdateInsertTab(SCTAB nTable)
+ void ScTable::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
  {
      if (nTab >= nTable)
 +    {
-         nTab++;
+         nTab += nNewSheets;
 +        if (pDBDataNoName)
 +            pDBDataNoName->UpdateMoveTab(nTab - 1 ,nTab);
 +    }
-     for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable);
+     for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable, nNewSheets);
  
      if (IsStreamValid())
          SetStreamValid(false);
  }
  
- void ScTable::UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo )
+ void ScTable::UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo, SCTAB nSheets )
  {
      if (nTab > nTable)
 +    {
-         nTab--;
+         nTab -= nSheets;
 +        if (pDBDataNoName)
 +            pDBDataNoName->UpdateMoveTab(nTab + 1,nTab);
 +    }
  
      SCCOL i;
      if (pRefUndo)
diff --cc sc/source/filter/xml/XMLTableSourceContext.cxx
index 331d24a,b34da4d..a18e5f3
--- a/sc/source/filter/xml/XMLTableSourceContext.cxx
+++ b/sc/source/filter/xml/XMLTableSourceContext.cxx
@@@ -118,10 -118,10 +118,10 @@@ void ScXMLTableSourceContext::EndElemen
          if (xLinkable.is() && pDoc)
          {
              ScXMLImport::MutexGuard aGuard(GetScImport());
-             if (pDoc->RenameTab( static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet()),
+             if (pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
                  GetScImport().GetTables().GetCurrentSheetName(), false, sal_True))
              {
 -                 String aFileString(sLink);
 +                String aFileString(sLink);
                  String aFilterString(sFilterName);
                  String aOptString(sFilterOptions);
                  String aSheetString(sTableName);
diff --cc sc/source/filter/xml/sheetdata.cxx
index c2f08e7,f5dd79c..5f1be87
--- a/sc/source/filter/xml/sheetdata.cxx
+++ b/sc/source/filter/xml/sheetdata.cxx
@@@ -127,9 -128,9 +127,9 @@@ void ScSheetSaveData::AddStreamPos( SCT
      maStreamEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
  }
  
- void ScSheetSaveData::StartStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset )
+ void ScSheetSaveData::StartStreamPos( SCTAB nTab, sal_Int32 nStartOffset )
  {
 -    DBG_ASSERT( mnStartTab < 0, "StartStreamPos without EndStreamPos" );
 +    OSL_ENSURE( mnStartTab < 0, "StartStreamPos without EndStreamPos" );
  
      mnStartTab = nTab;
      mnStartOffset = nStartOffset;
diff --cc sc/source/filter/xml/xmlrowi.cxx
index 3628a91,8978dd7..1bb96e6
--- a/sc/source/filter/xml/xmlrowi.cxx
+++ b/sc/source/filter/xml/xmlrowi.cxx
@@@ -167,9 -167,9 +167,9 @@@ void ScXMLTableRowContext::EndElement(
      {
          for (sal_Int32 i = 0; i < nRepeatedRows - 1; ++i) //one row is always added
              GetScImport().GetTables().AddRow();
 -        DBG_ERRORFILE("it seems here is a nonvalid file; possible missing of table:table-cell element");
 +        OSL_FAIL("it seems here is a nonvalid file; possible missing of table:table-cell element");
      }
-     sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
+     SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
      sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
      uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
      if(xSheet.is())
diff --cc sc/source/ui/view/preview.cxx
index 40c690e,0c46da9..32a3314
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@@ -190,10 -193,10 +192,10 @@@ void ScPreview::TestLastPage(
          if (nTotalPages)
          {
              nPageNo = nTotalPages - 1;
-             nTab = nTabCount - 1;
+             nTab = static_cast<SCTAB>(nPages.size()) -1;
              while (nTab > 0 && !nPages[nTab])		// letzte nicht leere Tabelle
                  --nTab;
-             OSL_ENSURE(nPages[nTab],"alle Tabellen leer?");
 -            DBG_ASSERT(0 < static_cast<SCTAB>(nPages.size()),"alle Tabellen leer?");
++            OSL_ENSURE(0 < static_cast<SCTAB>(nPages.size()),"alle Tabellen leer?");
              nTabPage = nPages[nTab] - 1;
              nTabStart = 0;
              for (sal_uInt16 i=0; i<nTab; i++)
diff --cc sc/source/ui/view/viewdata.cxx
index 739dfde,50abac1..ecaf101
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@@ -2605,10 -2631,9 +2631,9 @@@ void ScViewData::WriteUserDataSequence(
          SvXMLUnitConverter::convertNumber(sBuffer, static_cast<sal_Int32>(nViewID));
          pSettings[SC_VIEW_ID].Value <<= sBuffer.makeStringAndClear();
  
-         SCTAB nTabCount (pDoc->GetTableCount());
          uno::Reference<lang::XMultiServiceFactory> xServiceFactory =
                                          comphelper::getProcessServiceFactory();
 -        DBG_ASSERT( xServiceFactory.is(), "got no service manager" );
 +        OSL_ENSURE( xServiceFactory.is(), "got no service manager" );
          if( xServiceFactory.is() )
          {
              rtl::OUString sName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.NamedPropertyValues"));
commit c93818d47a2f267db53458f9a8bbc55369770ae3
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue Jun 7 03:37:19 2011 +0200

    fix selection problem
    
    the old implemantation inserted an false value and not an positive value, an entry in the set represents now a positive value

diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx
index 81a4115..a9951e1 100644
--- a/sc/source/core/data/markdata.cxx
+++ b/sc/source/core/data/markdata.cxx
@@ -603,7 +603,6 @@ sal_Bool ScMarkData::HasAnyMultiMarks() const
 void ScMarkData::InsertTab( SCTAB nTab )
 {
     std::set<SCTAB> tabMarked(maTabMarked.begin(), maTabMarked.upper_bound(nTab));
-    tabMarked.insert( nTab );
     std::set<SCTAB>::iterator it = maTabMarked.upper_bound(nTab);
     for (; it != maTabMarked.end(); ++it)
         tabMarked.insert(*it + 1);
commit f5bbfc04b64d61b773d8ccfa22d260024db17436
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon Jun 6 22:35:01 2011 +0200

    move ScProgress out of ScDocument::MoveTab

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index c3d7e2d..f8a18a6 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -584,7 +584,7 @@ public:
     SC_DLLPUBLIC sal_Bool			RenameTab( SCTAB nTab, const String& rName,
                                 sal_Bool bUpdateRef = sal_True,
                                 sal_Bool bExternalDocument = false );
-    sal_Bool			MoveTab( SCTAB nOldPos, SCTAB nNewPos );
+    sal_Bool			MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress = NULL );
     sal_Bool			CopyTab( SCTAB nOldPos, SCTAB nNewPos,
                                 const ScMarkData* pOnlyMarked = NULL );
     SC_DLLPUBLIC sal_uLong			TransferTab(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDestPos,
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index ea60345..6d02ad5 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -478,7 +478,7 @@ public:
 
     void		UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1);
     void 		UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo = NULL, SCTAB nSheets = 1 );
-    void		UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, ScProgress& );
+    void		UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, ScProgress* pProgress );
     void		UpdateCompile( sal_Bool bForceIfNameInUse = false );
     void		SetTabNo(SCTAB nNewTab);
     sal_Bool		IsRangeNameInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 7378d2f..c1252ba 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -729,23 +729,21 @@ sal_Bool ScDocument::GetDataStart( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRo
     return false;
 }
 
-sal_Bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos )
+sal_Bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos, ScProgress* pProgress )
 {
     if (nOldPos == nNewPos) return false;
     sal_Bool bValid = false;
-    if (VALIDTAB(nOldPos) && nOldPos < static_cast<SCTAB>(pTab.size()))
+    SCTAB nTabCount = static_cast<SCTAB>(pTab.size());
+    if (VALIDTAB(nOldPos) && nOldPos < nTabCount )
     {
         if (pTab[nOldPos])
         {
-            SCTAB nTabCount = static_cast<SCTAB>(pTab.size());
             if (nTabCount > 1)
             {
                 sal_Bool bOldAutoCalc = GetAutoCalc();
                 SetAutoCalc( false );	// Mehrfachberechnungen vermeiden
                 SetNoListening( sal_True );
-                ScProgress* pProgress = new ScProgress( GetDocumentShell(),
-                    ScGlobal::GetRscString(STR_UNDO_MOVE_TAB), GetCodeCount() );
-                if (nNewPos == SC_TAB_APPEND || nNewPos >= static_cast<SCTAB>(pTab.size()))
+                if (nNewPos == SC_TAB_APPEND || nNewPos >= nTabCount)
                     nNewPos = nTabCount-1;
 
                 //	Referenz-Updaterei
@@ -777,10 +775,9 @@ sal_Bool ScDocument::MoveTab( SCTAB nOldPos, SCTAB nNewPos )
                 pTab.erase(pTab.begin()+nOldPos);
                 pTab.insert(pTab.begin()+nNewPos, pSaveTab);
                 TableContainer::iterator it = pTab.begin();
-                for (SCTAB i = 0; i < static_cast<SCTAB>(pTab.size()); i++)
+                for (SCTAB i = 0; i < nTabCount; i++)
                     if (pTab[i])
-                        pTab[i]->UpdateMoveTab( nOldPos, nNewPos, i, *pProgress );
-                delete pProgress;	// freimachen fuer evtl. andere
+                        pTab[i]->UpdateMoveTab( nOldPos, nNewPos, i, pProgress );
                 it = pTab.begin();
                 for (; it != pTab.end(); ++it)
                     if (*it)
diff --git a/sc/source/core/data/markdata.cxx b/sc/source/core/data/markdata.cxx
index edd5a6d..81a4115 100644
--- a/sc/source/core/data/markdata.cxx
+++ b/sc/source/core/data/markdata.cxx
@@ -414,7 +414,7 @@ void ScMarkData::FillRangeListWithMarks( ScRangeList* pList, sal_Bool bClear ) c
         pList->Append( aMarkRange );
 }
 
-void ScMarkData::ExtendRangeListTables( ScRangeList* pList ) const//TODO:FIXME
+void ScMarkData::ExtendRangeListTables( ScRangeList* pList ) const
 {
     if (!pList)
         return;
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 1fb4447..e92a626 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1424,13 +1424,14 @@ void ScTable::UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo
 }
 
 void ScTable::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo,
-        ScProgress& rProgress )
+        ScProgress* pProgress )
 {
     nTab = nTabNo;
     for ( SCCOL i=0; i <= MAXCOL; i++ )
     {
         aCol[i].UpdateMoveTab( nOldPos, nNewPos, nTabNo );
-        rProgress.SetState( rProgress.GetState() + aCol[i].GetCodeCount() );
+        if (pProgress)
+            pProgress->SetState(pProgress->GetState() + aCol[i].GetCodeCount());
     }
 
     if (IsStreamValid())
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index da2bf45..4bc5ba6 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -59,6 +59,7 @@
 #include "dbdocfun.hxx"
 #include "consoli.hxx"
 #include "dbdata.hxx"
+#include "progress.hxx"
 #include "olinetab.hxx"
 #include "patattr.hxx"
 #include "attrib.hxx"
@@ -973,8 +974,14 @@ sal_Bool ScDocShell::MoveTable( SCTAB nSrcTab, SCTAB nDestTab, sal_Bool bCopy, s
             return sal_True;	// nothing to do, but valid
         }
 
-        if (!aDocument.MoveTab( nSrcTab, nDestTab ))
+        ScProgress* pProgress = new ScProgress(this, ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
+                                                aDocument.GetCodeCount());
+        bool bDone = aDocument.MoveTab( nSrcTab, nDestTab, pProgress );
+        delete pProgress;
+        if (!bDone)
+        {
             return false;
+        }
         else if (bRecord)
         {
             auto_ptr< vector<SCTAB> > pSrcList(new vector<SCTAB>(1, nSrcTab));
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 3e110fb..144640a 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -49,6 +49,7 @@
 #include "chgtrack.hxx"
 #include "tabprotection.hxx"
 #include "viewdata.hxx"
+#include "progress.hxx"
 
 // for ScUndoRenameObject - might me moved to another file later
 #include <svx/svditer.hxx>
@@ -553,14 +554,17 @@ void ScUndoMoveTab::DoChange( sal_Bool bUndo ) const
 
     if (bUndo)										// UnDo
     {
-        for (size_t i = mpNewTabs->size(); i > 0; --i)
+        size_t i = mpNewTabs->size();
+        ScProgress* pProgress = new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
+                                                i * pDoc->GetCodeCount());
+        for (; i > 0; --i)
         {
             SCTAB nDestTab = (*mpNewTabs)[i-1];
             SCTAB nOldTab = (*mpOldTabs)[i-1];
             if (nDestTab > MAXTAB)							// angehaengt ?
                 nDestTab = pDoc->GetTableCount() - 1;
 
-            pDoc->MoveTab( nDestTab, nOldTab );
+            pDoc->MoveTab( nDestTab, nOldTab, pProgress );
             pViewShell->GetViewData()->MoveTab( nDestTab, nOldTab );
             pViewShell->SetTabNo( nOldTab, true );
             if (mpOldNames)
@@ -569,10 +573,14 @@ void ScUndoMoveTab::DoChange( sal_Bool bUndo ) const
                 pDoc->RenameTab(nOldTab, rOldName);
             }
         }
+        delete pProgress;
     }
     else
     {
-        for (size_t i = 0, n = mpNewTabs->size(); i < n; ++i)
+        size_t n = mpNewTabs->size();
+        ScProgress* pProgress = new ScProgress(pDocShell , ScGlobal::GetRscString(STR_UNDO_MOVE_TAB),
+                                                n * pDoc->GetCodeCount());
+        for (size_t i = 0; i < n; ++i)
         {
             SCTAB nDestTab = (*mpNewTabs)[i];
             SCTAB nNewTab = nDestTab;
@@ -580,7 +588,7 @@ void ScUndoMoveTab::DoChange( sal_Bool bUndo ) const
             if (nDestTab > MAXTAB)							// angehaengt ?
                 nDestTab = pDoc->GetTableCount() - 1;
 
-            pDoc->MoveTab( nOldTab, nNewTab );
+            pDoc->MoveTab( nOldTab, nNewTab, pProgress );
             pViewShell->GetViewData()->MoveTab( nOldTab, nNewTab );
             pViewShell->SetTabNo( nDestTab, true );
             if (mpNewNames)
@@ -589,6 +597,7 @@ void ScUndoMoveTab::DoChange( sal_Bool bUndo ) const
                 pDoc->RenameTab(nNewTab, rNewName);
             }
         }
+        delete pProgress;
     }
 
     SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );	// Navigator
commit ecd1ad1ac757e3b2ca79de1838b12a4e61145d8f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Jun 3 06:03:40 2011 +0200

    improve performance of ScUndoInsertTables::Undo
    
    we can now insert several sheets and then undo in nearly no time

diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 34e9781..92fcd92 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -444,7 +444,7 @@ public:
 
     void			UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1);
     void 			UpdateInsertTabAbs(SCTAB nTable);
-    sal_Bool			UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove = false);
+    sal_Bool			UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove = false, SCTAB nSheets = 1);
     void			UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
     void			UpdateRenameTab(SCTAB nTable, const String& rName);
     sal_Bool 			TestTabRefAbs(SCTAB nTable);
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index d3ea6ad..af0f898 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -292,7 +292,7 @@ public:
                                      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 );
+    void        UpdateDeleteTab( SCTAB nTable, 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,
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 5d6cb6c..1646479 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -445,7 +445,7 @@ public:
                                   SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
 
     ScRangeData* UpdateInsertTab(SCTAB nTable, sal_Bool bIsName, SCTAB nNewSheets = 1 );
-    ScRangeData* UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove, sal_Bool bIsName, sal_Bool& bCompile);
+    ScRangeData* UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove, sal_Bool bIsName, sal_Bool& bCompile, SCTAB nSheets = 1);
     ScRangeData* UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, sal_Bool bIsName );
 
     bool HasModifiedRange();
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 8e6180d..c3d7e2d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -579,6 +579,7 @@ public:
                                 sal_Bool bExternalDocument = false );
     SC_DLLPUBLIC bool			InsertTabs( SCTAB nPos, const std::vector<rtl::OUString>& rNames,
                                 bool bExternalDocument = false, bool bNamesValid = false );
+    SC_DLLPUBLIC bool           DeleteTabs( SCTAB nTab, SCTAB nSheets, ScDocument* pRefUndoDoc = NULL );
     SC_DLLPUBLIC sal_Bool            DeleteTab( SCTAB nTab, ScDocument* pRefUndoDoc = NULL );
     SC_DLLPUBLIC sal_Bool			RenameTab( SCTAB nTab, const String& rName,
                                 sal_Bool bUpdateRef = sal_True,
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index c559181..ea60345 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -477,7 +477,7 @@ public:
     void		UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
 
     void		UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1);
-    void 		UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo = NULL );
+    void 		UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo = NULL, SCTAB nSheets = 1 );
     void		UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, ScProgress& );
     void		UpdateCompile( sal_Bool bForceIfNameInUse = false );
     void		SetTabNo(SCTAB nNewTab);
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index aaa03a8..0d3de34 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -1142,7 +1142,7 @@ void ScFormulaCell::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
         ScRangeData* pRangeData;
         ScCompiler aComp(pDocument, aPos, *pCode);
         aComp.SetGrammar(pDocument->GetGrammar());
-        pRangeData = aComp.UpdateInsertTab( nTable, false );
+        pRangeData = aComp.UpdateInsertTab( nTable, false, nNewSheets );
         if (pRangeData)                     // Shared Formula gegen echte Formel
         {                                   // austauschen
             sal_Bool bRefChanged;
@@ -1152,10 +1152,10 @@ void ScFormulaCell::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
             ScCompiler aComp2(pDocument, aPos, *pCode);
             aComp2.SetGrammar(pDocument->GetGrammar());
             aComp2.MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow());
-            aComp2.UpdateInsertTab( nTable, false );
+            aComp2.UpdateInsertTab( nTable, false, nNewSheets );
             // If the shared formula contained a named range/formula containing
             // an absolute reference to a sheet, those have to be readjusted.
-            aComp2.UpdateDeleteTab( nTable, false, sal_True, bRefChanged );
+            aComp2.UpdateDeleteTab( nTable, false, sal_True, bRefChanged, nNewSheets );
             bCompile = sal_True;
         }
         // kein StartListeningTo weil pTab[nTab] noch nicht existiert!
@@ -1164,21 +1164,21 @@ void ScFormulaCell::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
         aPos.IncTab();
 }
 
-sal_Bool ScFormulaCell::UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove)
+sal_Bool ScFormulaCell::UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove, SCTAB nSheets)
 {
     sal_Bool bRefChanged = false;
-    sal_Bool bPosChanged = ( aPos.Tab() > nTable ? sal_True : false );
+    sal_Bool bPosChanged = ( aPos.Tab() > nTable + nSheets ? sal_True : false );
     pCode->Reset();
     if( pCode->GetNextReferenceRPN() && !pDocument->IsClipOrUndo() )
     {
         EndListeningTo( pDocument );
         // IncTab _nach_ EndListeningTo und _vor_ Compiler UpdateDeleteTab !
         if ( bPosChanged )
-            aPos.IncTab(-1);
+            aPos.IncTab(-1*nSheets);
         ScRangeData* pRangeData;
         ScCompiler aComp(pDocument, aPos, *pCode);
         aComp.SetGrammar(pDocument->GetGrammar());
-        pRangeData = aComp.UpdateDeleteTab(nTable, bIsMove, false, bRefChanged);
+        pRangeData = aComp.UpdateDeleteTab(nTable, bIsMove, false, bRefChanged, nSheets);
         if (pRangeData)                     // Shared Formula gegen echte Formel
         {                                   // austauschen
             pDocument->RemoveFromFormulaTree( this );   // update formula count
@@ -1188,10 +1188,10 @@ sal_Bool ScFormulaCell::UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove)
             aComp2.SetGrammar(pDocument->GetGrammar());
             aComp2.CompileTokenArray();
             aComp2.MoveRelWrap(pRangeData->GetMaxCol(), pRangeData->GetMaxRow());
-            aComp2.UpdateDeleteTab( nTable, false, false, bRefChanged );
+            aComp2.UpdateDeleteTab( nTable, false, false, bRefChanged, nSheets );
             // If the shared formula contained a named range/formula containing
             // an absolute reference to a sheet, those have to be readjusted.
-            aComp2.UpdateInsertTab( nTable,sal_True );
+            aComp2.UpdateInsertTab( nTable,sal_True, nSheets );
             // bRefChanged kann beim letzten UpdateDeleteTab zurueckgesetzt worden sein
             bRefChanged = sal_True;
             bCompile = sal_True;
@@ -1199,7 +1199,7 @@ sal_Bool ScFormulaCell::UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove)
         // kein StartListeningTo weil pTab[nTab] noch nicht korrekt!
     }
     else if ( bPosChanged )
-        aPos.IncTab(-1);
+        aPos.IncTab(-1*nSheets);
 
     return bRefChanged;
 }
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 2bd2019..421ba6b 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1769,10 +1769,13 @@ void ScColumn::UpdateInsertTabAbs(SCTAB nTable)
 }
 
 
-void ScColumn::UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo )
+void ScColumn::UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo, SCTAB nSheets )
 {
     if (nTab > nTable)
-        pAttrArray->SetTab(--nTab);
+    {
+        nTab -= nSheets;
+        pAttrArray->SetTab(nTab);
+    }
 
     if (pItems)
         for (SCSIZE i = 0; i < nCount; i++)
@@ -1785,7 +1788,7 @@ void ScColumn::UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo )
                     back the formula cell while keeping the original note. */
                 ScBaseCell* pSave = pRefUndo ? pOld->CloneWithoutNote( *pDocument ) : 0;
 
-                bool bChanged = pOld->UpdateDeleteTab(nTable, bIsMove);
+                bool bChanged = pOld->UpdateDeleteTab(nTable, bIsMove, nSheets);
                 if ( nRow != pItems[i].nRow )
                     Search( nRow, i );		// Listener geloescht/eingefuegt?
 
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index f6f197b..1d1808e 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -595,7 +595,7 @@ sal_Bool ScDocument::DeleteTab( SCTAB nTab, ScDocument* pRefUndoDoc )
 
                 // normal reference update
 
-                aRange.aEnd.SetTab( static_cast<SCTAB>(pTab.size()) );
+                aRange.aEnd.SetTab( static_cast<SCTAB>(pTab.size())-1 );
                 xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 );
                 xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1 );
                 if (pRangeName)
@@ -651,6 +651,93 @@ sal_Bool ScDocument::DeleteTab( SCTAB nTab, ScDocument* pRefUndoDoc )
 }
 
 
+bool ScDocument::DeleteTabs( SCTAB nTab, SCTAB nSheets, ScDocument* pRefUndoDoc )
+{
+    bool bValid = false;
+    if (VALIDTAB(nTab) && (nTab + nSheets) < static_cast<SCTAB>(pTab.size()))
+    {
+        if (pTab[nTab])
+        {
+            SCTAB nTabCount = static_cast<SCTAB>(pTab.size());
+            if (nTabCount > nSheets)
+            {
+                bool bOldAutoCalc = GetAutoCalc();
+                SetAutoCalc( false );	// avoid multiple calculations
+                for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
+                {
+                    ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab + aTab );
+                    DelBroadcastAreasInRange( aRange );
+
+                    // #i8180# remove database ranges etc. that are on the deleted tab
+                    // (restored in undo with ScRefUndoData)
+
+                    xColNameRanges->DeleteOnTab( nTab + aTab );
+                    xRowNameRanges->DeleteOnTab( nTab + aTab );
+                    pDBCollection->DeleteOnTab( nTab + aTab );
+                    if (pDPCollection)
+                        pDPCollection->DeleteOnTab( nTab + aTab );
+                    if (pDetOpList)
+                        pDetOpList->DeleteOnTab( nTab + aTab );
+                    DeleteAreaLinksOnTab( nTab + aTab );
+                    if (pRangeName)
+                        pRangeName->UpdateTabRef( nTab + aTab, 2 );
+                }
+                // normal reference update
+
+                ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTabCount - 1 );
+                xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1*nSheets );
+                xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,-1*nSheets );
+                pDBCollection->UpdateReference(
+                                    URM_INSDEL, 0,0,nTab, MAXCOL,MAXROW,MAXTAB, 0,0,-1*nSheets );
+                if (pDPCollection)
+                    pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,-1*nSheets );
+                if (pDetOpList)
+                    pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,-1*nSheets );
+                UpdateChartRef( URM_INSDEL, 0,0,nTab, MAXCOL,MAXROW,MAXTAB, 0,0,-1*nSheets );
+                UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0,-1*nSheets );
+                if ( pCondFormList )
+                    pCondFormList->UpdateReference( URM_INSDEL, aRange, 0,0,-1*nSheets );
+                if ( pValidationList )
+                    pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,-1*nSheets );
+                if ( pUnoBroadcaster )
+                    pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,-1*nSheets ) );
+
+                SCTAB i;
+                for (i=0; i< static_cast<SCTAB>(pTab.size()); i++)
+                    if (pTab[i])
+                        pTab[i]->UpdateDeleteTab(nTab,false,
+                                    pRefUndoDoc ? pRefUndoDoc->pTab[i] : 0,nSheets);
+                pTab.erase(pTab.begin()+ nTab, pTab.begin() + nTab + nSheets);
+                // UpdateBroadcastAreas must be called between UpdateDeleteTab,
+                // which ends listening, and StartAllListeners, to not modify
+                // areas that are to be inserted by starting listeners.
+                UpdateBroadcastAreas( URM_INSDEL, aRange, 0,0,-1*nSheets);
+                TableContainer::iterator it = pTab.begin();
+                for (; it != pTab.end(); ++it)
+                    if ( *it )
+                        (*it)->UpdateCompile();
+                // Excel-Filter deletes some Tables while loading, Listeners will
+                // only be triggered after the loading is done.
+                if ( !bInsertingFromOtherDoc )
+                {
+                    it = pTab.begin();
+                    for (; it != pTab.end(); ++it)
+                        if ( *it )
+                            (*it)->StartAllListeners();
+                    SetDirty();
+                }
+                // sheet names of references are not valid until sheet is deleted
+                pChartListenerCollection->UpdateScheduledSeriesRanges();
+
+                SetAutoCalc( bOldAutoCalc );
+                bValid = true;
+            }
+        }
+    }
+    return bValid;
+}
+
+
 sal_Bool ScDocument::RenameTab( SCTAB nTab, const String& rName, sal_Bool /* bUpdateRef */,
         sal_Bool bExternalDocument )
 {
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index de71a26..1fb4447 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1402,21 +1402,22 @@ void ScTable::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
 {
     if (nTab >= nTable)
         nTab += nNewSheets;
-    for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable);
+    for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable, nNewSheets);
 
     if (IsStreamValid())
         SetStreamValid(false);
 }
 
-void ScTable::UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo )
+void ScTable::UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo, SCTAB nSheets )
 {
-    if (nTab > nTable) nTab--;
+    if (nTab > nTable)
+        nTab -= nSheets;
 
     SCCOL i;
     if (pRefUndo)
-        for (i=0; i <= MAXCOL; i++) aCol[i].UpdateDeleteTab(nTable, bIsMove, &pRefUndo->aCol[i]);
+        for (i=0; i <= MAXCOL; i++) aCol[i].UpdateDeleteTab(nTable, bIsMove, &pRefUndo->aCol[i], nSheets);
     else
-        for (i=0; i <= MAXCOL; i++) aCol[i].UpdateDeleteTab(nTable, bIsMove, NULL);
+        for (i=0; i <= MAXCOL; i++) aCol[i].UpdateDeleteTab(nTable, bIsMove, NULL, nSheets);
 
     if (IsStreamValid())
         SetStreamValid(false);
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index ab282c8..8bfc35a 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4484,7 +4484,7 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB
 {
     ScRangeData* pRangeData = NULL;
     SCTAB nPosTab = aPos.Tab();     // _after_ incremented!
-    SCTAB nOldPosTab = ((nPosTab > nTable) ? (nPosTab - 1) : nPosTab);
+    SCTAB nOldPosTab = ((nPosTab > nTable) ? (nPosTab - nNewSheets) : nPosTab);
     sal_Bool bIsRel = false;
     ScToken* t;
     pArr->Reset();
@@ -4515,7 +4515,7 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB
                         rRef.nTab = sal::static_int_cast<SCsTAB>( rRef.nTab + pDoc->GetTableCount() );  // was a wrap
                 }
                 if (nTable <= rRef.nTab)
-                    ++rRef.nTab;
+                    rRef.nTab += nNewSheets;
                 rRef.nRelTab = rRef.nTab - nPosTab;
             }
             else
@@ -4532,7 +4532,7 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB
                             rRef.nTab = sal::static_int_cast<SCsTAB>( rRef.nTab + pDoc->GetTableCount() );  // was a wrap
                     }
                     if (nTable <= rRef.nTab)
-                        ++rRef.nTab;
+                        rRef.nTab += nNewSheets;
                     rRef.nRelTab = rRef.nTab - nPosTab;
                 }
                 else
@@ -4563,7 +4563,7 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB
                             rRef1.nTab = sal::static_int_cast<SCsTAB>( rRef1.nTab + pDoc->GetTableCount() );  // was a wrap
                     }
                     if (nTable <= rRef1.nTab)
-                        ++rRef1.nTab;
+                        rRef1.nTab += nNewSheets;
                     rRef1.nRelTab = rRef1.nTab - nPosTab;
                 }
                 if ( t->GetType() == svDoubleRef )
@@ -4578,7 +4578,7 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB
                                 rRef2.nTab = sal::static_int_cast<SCsTAB>( rRef2.nTab + pDoc->GetTableCount() );  // was a wrap
                         }
                         if (nTable <= rRef2.nTab)
-                            ++rRef2.nTab;
+                            rRef2.nTab += nNewSheets;
                         rRef2.nRelTab = rRef2.nTab - nPosTab;
                     }
                 }
@@ -4589,12 +4589,12 @@ ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB
 }
 
 ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, sal_Bool /* bIsMove */, sal_Bool bIsName,
-                                 sal_Bool& rChanged)
+                                 sal_Bool& rChanged, SCTAB nSheets)
 {
     ScRangeData* pRangeData = NULL;
     SCTAB nTab, nTab2;
     SCTAB nPosTab = aPos.Tab();          // _after_ decremented!
-    SCTAB nOldPosTab = ((nPosTab >= nTable) ? (nPosTab + 1) : nPosTab);
+    SCTAB nOldPosTab = ((nPosTab >= nTable) ? (nPosTab + nSheets) : nPosTab);
     rChanged = false;
     sal_Bool bIsRel = false;
     ScToken* t;
@@ -4626,7 +4626,7 @@ ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, sal_Bool /* bIsMove */, s
                     nTab = rRef.nTab;
                 if ( nTable < nTab )
                 {
-                    rRef.nTab = nTab - 1;
+                    rRef.nTab = nTab - nSheets;
                     rChanged = sal_True;
                 }
                 else if ( nTable == nTab )
@@ -4639,7 +4639,7 @@ ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, sal_Bool /* bIsMove */, s
                         else
                             nTab2 = rRef2.nTab;
                         if ( nTab == nTab2
-                          || (nTab+1) >= pDoc->GetTableCount() )
+                          || (nTab+nSheets) >= pDoc->GetTableCount() )
                         {
                             rRef.nTab = MAXTAB+1;
                             rRef.SetTabDeleted( sal_True );
@@ -4669,13 +4669,13 @@ ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, sal_Bool /* bIsMove */, s
                         nTab = rRef.nTab;
                     if ( nTable < nTab )
                     {
-                        rRef.nTab = nTab - 1;
+                        rRef.nTab = nTab - nSheets;
                         rChanged = sal_True;
                     }
                     else if ( nTable == nTab )
                     {
                         if ( !t->GetDoubleRef().Ref1.IsTabDeleted() )
-                            rRef.nTab = nTab - 1;   // shrink area
+                            rRef.nTab = nTab - nSheets;   // shrink area
                         else
                         {
                             rRef.nTab = MAXTAB+1;
@@ -4712,7 +4712,7 @@ ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, sal_Bool /* bIsMove */, s
                         nTab = rRef1.nTab;
                     if ( nTable < nTab )
                     {
-                        rRef1.nTab = nTab - 1;
+                        rRef1.nTab = nTab - nSheets;
                         rChanged = sal_True;
                     }
                     else if ( nTable == nTab )
@@ -4753,13 +4753,13 @@ ScRangeData* ScCompiler::UpdateDeleteTab(SCTAB nTable, sal_Bool /* bIsMove */, s
                             nTab = rRef2.nTab;
                         if ( nTable < nTab )
                         {
-                            rRef2.nTab = nTab - 1;
+                            rRef2.nTab = nTab - nSheets;
                             rChanged = sal_True;
                         }
                         else if ( nTable == nTab )
                         {
                             if ( !rRef1.IsTabDeleted() )
-                                rRef2.nTab = nTab - 1;  // shrink area
+                                rRef2.nTab = nTab - nSheets;  // shrink area
                             else
                             {
                                 rRef2.nTab = MAXTAB+1;
diff --git a/sc/source/ui/inc/uiitems.hxx b/sc/source/ui/inc/uiitems.hxx
index aaa8903..14b0ef9 100644
--- a/sc/source/ui/inc/uiitems.hxx
+++ b/sc/source/ui/inc/uiitems.hxx
@@ -93,6 +93,7 @@ public:
 #define SC_TAB_COPIED		4
 #define SC_TAB_HIDDEN		5
 #define SC_TABS_INSERTED    6
+#define SC_TABS_DELETED     7
 
 class ScTablesHint : public SfxHint
 {
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 303ca6e..39f3428 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -279,6 +279,7 @@ public:
     void			InsertTab( SCTAB nTab );
     void			InsertTabs( SCTAB nTab, SCTAB nNewSheets );
     void			DeleteTab( SCTAB nTab );
+    void            DeleteTabs( SCTAB nTab, SCTAB nSheets );
     void			CopyTab( SCTAB nSrcTab, SCTAB nDestTab );
     void			MoveTab( SCTAB nSrcTab, SCTAB nDestTab );
 
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index a36c5bf..c3adb6c 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -267,6 +267,7 @@ public:
 
     sal_Bool			DeleteTable( SCTAB nTabNr, sal_Bool bRecord = true );
     sal_Bool			DeleteTables(const std::vector<SCTAB>& TheTabs, sal_Bool bRecord = true );
+    bool                DeleteTables(SCTAB nTab, SCTAB nSheets);
 
     sal_Bool			RenameTable( const String& rName, SCTAB nTabNr );
     void			MoveTable( sal_uInt16 nDestDocNo, SCTAB nDestTab, sal_Bool bCopy, const String* pNewTabName = NULL );
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 0842c93..3e110fb 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -243,13 +243,7 @@ void ScUndoInsertTables::Undo()
     pDocShell->SetInUndo( sal_True );				//! BeginUndo
     bDrawIsInUndo = sal_True;
 
-    vector<SCTAB> TheTabs;
-    for(SCTAB i=0; i< static_cast<SCTAB>(aNameList.size()); ++i)
-    {
-        TheTabs.push_back(nTab+i);
-    }
-    pViewShell->DeleteTables( TheTabs, false );
-    TheTabs.clear();
+    pViewShell->DeleteTables( nTab, static_cast<SCTAB>(aNameList.size()) );
 
     bDrawIsInUndo = false;
     pDocShell->SetInUndo( false );				//! EndUndo
diff --git a/sc/source/ui/view/tabvwsh5.cxx b/sc/source/ui/view/tabvwsh5.cxx
index 5625dc4..db10e3b 100644
--- a/sc/source/ui/view/tabvwsh5.cxx
+++ b/sc/source/ui/view/tabvwsh5.cxx
@@ -242,6 +242,9 @@ void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
             case SC_TABS_INSERTED:
                 GetViewData()->InsertTabs( nTab1, nTab2 );
                 break;
+            case SC_TABS_DELETED:
+                GetViewData()->DeleteTabs( nTab1, nTab2 );
+                break;
             default:
                 OSL_FAIL("unbekannter ScTablesHint");
         }
@@ -289,6 +292,10 @@ void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
                 if ( nTab1 <= nNewTab )
                     nNewTab += nTab2;
                 break;
+            case SC_TABS_DELETED:
+                if ( nTab1 < nNewTab )
+                    nNewTab -= nTab2;
+                break;
         }
 
         ScDocument* pDoc = GetViewData()->GetDocument();
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 88ddd7c..50abac1 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -495,6 +495,19 @@ void ScViewData::DeleteTab( SCTAB nTab )
     aMarkData.DeleteTab( nTab );
 }
 
+void ScViewData::DeleteTabs( SCTAB nTab, SCTAB nSheets )
+{
+    for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
+    {
+        aMarkData.DeleteTab( nTab + aTab );
+        delete pTabData[nTab + aTab];
+    }
+
+    pTabData.erase(pTabData.begin() + nTab, pTabData.begin()+ nTab+nSheets);
+    UpdateThis();
+
+}
+
 void ScViewData::CopyTab( SCTAB nSrcTab, SCTAB nDestTab )
 {
     if (nDestTab==SC_TAB_APPEND)
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 7b53ffc..f1c678d 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2089,11 +2089,54 @@ sal_Bool ScViewFunc::DeleteTable( SCTAB nTab, sal_Bool bRecord )
     return bSuccess;
 }
 
+//only use this method for undo for now, all sheets must be connected
+//this method doesn't support undo for now, merge it when it with the other method later
+bool ScViewFunc::DeleteTables( const SCTAB nTab, SCTAB nSheets )
+{
+    ScDocShell* pDocSh = GetViewData()->GetDocShell();
+    ScDocument* pDoc 	= pDocSh->GetDocument();
+    bool bVbaEnabled = pDoc->IsInVBAMode();
+    SCTAB		nNewTab = nTab;
+    WaitObject aWait( GetFrameWin() );
+
+    while ( nNewTab > 0 && !pDoc->IsVisible( nNewTab ) )
+        --nNewTab;
+
+    if (pDoc->DeleteTabs(nTab, nSheets, NULL))
+    {
+        if( bVbaEnabled )
+        {
+            for (SCTAB aTab = 0; aTab < nSheets; ++aTab)
+            {
+                String sCodeName;
+                bool bHasCodeName = pDoc->GetCodeName( nTab + aTab, sCodeName );
+                if ( bHasCodeName )
+                    VBA_DeleteModule( *pDocSh, sCodeName );
+            }
+        }
+
+        pDocSh->Broadcast( ScTablesHint( SC_TABS_DELETED, nTab, nSheets ) );
+        if ( nNewTab >= pDoc->GetTableCount() )
+            nNewTab = pDoc->GetTableCount() - 1;
+        SetTabNo( nNewTab, sal_True );
+
+        pDocSh->PostPaintExtras();
+        pDocSh->SetDocumentModified();
+
+        SfxApplication* pSfxApp = SFX_APP();                                // Navigator
+        pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
+        pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
+        pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
+        return true;
+    }
+    return false;
+}
+
 sal_Bool ScViewFunc::DeleteTables(const vector<SCTAB> &TheTabs, sal_Bool bRecord )
 {
     ScDocShell* pDocSh	= GetViewData()->GetDocShell();
     ScDocument* pDoc 	= pDocSh->GetDocument();
-    sal_Bool bVbaEnabled = pDoc ? pDoc->IsInVBAMode() : false;
+    sal_Bool bVbaEnabled = pDoc->IsInVBAMode();
     SCTAB		nNewTab = TheTabs[0];
     WaitObject aWait( GetFrameWin() );
     if (bRecord && !pDoc->IsUndoEnabled())
commit bb2a073cc9f6ca99c30e45d30211603e07b5212e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Jun 1 21:38:53 2011 +0200

    change to SCTAB from sal_Int16 and sal_Int32 for sheet index

diff --git a/sc/inc/appoptio.hxx b/sc/inc/appoptio.hxx
index a31080c..e10b1e6 100644
--- a/sc/inc/appoptio.hxx
+++ b/sc/inc/appoptio.hxx
@@ -46,8 +46,8 @@ public:
     void		SetDefaults();
 
     // Set or get the initial tab count for new spreadsheet, it is used by VBA API currently.
-    void	SetTabCountInNewSpreadsheet( sal_Int16 nCount )  { nTabCountInNewSpreadsheet = nCount; }
-    sal_Int16	GetTabCountInNewSpreadsheet() const              { return nTabCountInNewSpreadsheet;   }
+    void	SetTabCountInNewSpreadsheet( SCTAB nCount )  { nTabCountInNewSpreadsheet = nCount; }
+    SCTAB	GetTabCountInNewSpreadsheet() const              { return nTabCountInNewSpreadsheet;   }
 
     void		SetAppMetric( FieldUnit eUnit )	{ eMetric = eUnit;		}
     FieldUnit	GetAppMetric() const			{ return eMetric;		}
@@ -92,7 +92,7 @@ public:
     const ScAppOptions&	operator=	( const ScAppOptions& rOpt );
 
 private:
-    sal_Int16	nTabCountInNewSpreadsheet;
+    SCTAB	nTabCountInNewSpreadsheet;
     FieldUnit	eMetric;
     sal_uInt16		nLRUFuncCount;
     sal_uInt16*		pLRUList;
diff --git a/sc/inc/sheetdata.hxx b/sc/inc/sheetdata.hxx
index 7a17b50..a64322a 100644
--- a/sc/inc/sheetdata.hxx
+++ b/sc/inc/sheetdata.hxx
@@ -128,7 +128,7 @@ class ScSheetSaveData
     std::vector<bool>          maBlocked;
     std::vector<ScStreamEntry> maStreamEntries;
     std::vector<ScStreamEntry> maSaveEntries;
-    sal_Int32   mnStartTab;
+    SCTAB   mnStartTab;
     sal_Int32   mnStartOffset;
 
     ScNoteStyleEntry    maPreviousNote;
@@ -149,20 +149,20 @@ public:
 
     void        AddTextStyle( const rtl::OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection );
 
-    void        BlockSheet( sal_Int32 nTab );
-    bool        IsSheetBlocked( sal_Int32 nTab ) const;
+    void        BlockSheet( SCTAB nTab );
+    bool        IsSheetBlocked( SCTAB nTab ) const;
 
-    void        AddStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset );
-    void        GetStreamPos( sal_Int32 nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const;
-    bool        HasStreamPos( sal_Int32 nTab ) const;
+    void        AddStreamPos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset );
+    void        GetStreamPos( SCTAB nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const;
+    bool        HasStreamPos( SCTAB nTab ) const;
 
-    void        StartStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset );
+    void        StartStreamPos( SCTAB nTab, sal_Int32 nStartOffset );
     void        EndStreamPos( sal_Int32 nEndOffset );
 
     bool        HasStartPos() const { return mnStartTab >= 0; }
 
     void        ResetSaveEntries();
-    void        AddSavePos( sal_Int32 nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset );
+    void        AddSavePos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset );
     void        UseSaveEntries();
 
     void        StoreInitialNamespaces( const SvXMLNamespaceMap& rNamespaces );
diff --git a/sc/source/filter/inc/scflt.hxx b/sc/source/filter/inc/scflt.hxx
index 950e70f..24459c1 100644
--- a/sc/source/filter/inc/scflt.hxx
+++ b/sc/source/filter/inc/scflt.hxx
@@ -247,7 +247,7 @@ struct Sc10BlockRect
 struct Sc10DataBaseRec
 {
     sal_Char		Name[32];
-    sal_Int16			Tab;
+    SCTAB			Tab;
     Sc10BlockRect	Block;
     sal_uInt8			RowHeader;
     sal_Int16			SortField0;
@@ -319,7 +319,7 @@ struct Sc10PageFormat
     sal_Char			PrintAreaName[32];
     Sc10BlockRect		PrintArea;
     sal_Char			PrnZoom[6]; // Pascal 6 Byte Realzahl
-    sal_uInt16				FirstPageNo;
+    SCTAB				FirstPageNo;
     sal_Int16				RowRepeatStart;
     sal_Int16				RowRepeatEnd;
     sal_Int16				ColRepeatStart;
@@ -731,7 +731,7 @@ class Sc10Import
     Sc10PatternCollection*	pPatternCollection;
     Sc10DataBaseCollection*	pDataBaseCollection;
     sal_uLong                   nError;
-    sal_Int16					TabCount;
+    SCTAB					TabCount;
     SCTAB					nShowTab;
     ScViewOptions			aSc30ViewOpt;
     ScfStreamProgressBar*   pPrgrsBar;
diff --git a/sc/source/filter/xml/XMLTableSourceContext.cxx b/sc/source/filter/xml/XMLTableSourceContext.cxx
index 08cda1f..b34da4d 100644
--- a/sc/source/filter/xml/XMLTableSourceContext.cxx
+++ b/sc/source/filter/xml/XMLTableSourceContext.cxx
@@ -118,7 +118,7 @@ void ScXMLTableSourceContext::EndElement()
         if (xLinkable.is() && pDoc)
         {
             ScXMLImport::MutexGuard aGuard(GetScImport());
-            if (pDoc->RenameTab( static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet()),
+            if (pDoc->RenameTab( GetScImport().GetTables().GetCurrentSheet(),
                 GetScImport().GetTables().GetCurrentSheetName(), false, sal_True))
             {
                  String aFileString(sLink);
@@ -136,7 +136,7 @@ void ScXMLTableSourceContext::EndElement()
                 else if ( nMode == sheet::SheetLinkMode_VALUE )
                     nLinkMode = SC_LINK_VALUE;
 
-                pDoc->SetLink( static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet()),
+                pDoc->SetLink( GetScImport().GetTables().GetCurrentSheet(),
                     nLinkMode, aFileString, aFilterString, aOptString,
                     aSheetString, nRefresh );
             }
diff --git a/sc/source/filter/xml/sheetdata.cxx b/sc/source/filter/xml/sheetdata.cxx
index 5d36ef0..f5dd79c 100644
--- a/sc/source/filter/xml/sheetdata.cxx
+++ b/sc/source/filter/xml/sheetdata.cxx
@@ -104,31 +104,31 @@ void ScSheetSaveData::AddTextStyle( const rtl::OUString& rName, const ScAddress&
     maTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
 }
 
-void ScSheetSaveData::BlockSheet( sal_Int32 nTab )
+void ScSheetSaveData::BlockSheet( SCTAB nTab )
 {
-    if ( nTab >= (sal_Int32)maBlocked.size() )
+    if ( nTab >= static_cast<SCTAB>(maBlocked.size()) )
         maBlocked.resize( nTab + 1, false );        // fill vector with "false" entries
 
     maBlocked[nTab] = true;
 }
 
-bool ScSheetSaveData::IsSheetBlocked( sal_Int32 nTab ) const
+bool ScSheetSaveData::IsSheetBlocked( SCTAB nTab ) const
 {
-    if ( nTab < (sal_Int32)maBlocked.size() )
+    if ( nTab < static_cast<SCTAB>(maBlocked.size()) )
         return maBlocked[nTab];
     else
         return false;
 }
 
-void ScSheetSaveData::AddStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
+void ScSheetSaveData::AddStreamPos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
 {
-    if ( nTab >= (sal_Int32)maStreamEntries.size() )
+    if ( nTab >= static_cast<SCTAB>(maStreamEntries.size()) )
         maStreamEntries.resize( nTab + 1 );
 
     maStreamEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
 }
 
-void ScSheetSaveData::StartStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset )
+void ScSheetSaveData::StartStreamPos( SCTAB nTab, sal_Int32 nStartOffset )
 {
     DBG_ASSERT( mnStartTab < 0, "StartStreamPos without EndStreamPos" );
 
@@ -146,9 +146,9 @@ void ScSheetSaveData::EndStreamPos( sal_Int32 nEndOffset )
     }
 }
 
-void ScSheetSaveData::GetStreamPos( sal_Int32 nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const
+void ScSheetSaveData::GetStreamPos( SCTAB nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const
 {
-    if ( nTab < (sal_Int32)maStreamEntries.size() )
+    if ( nTab < static_cast<SCTAB>(maStreamEntries.size()) )
     {
         const ScStreamEntry& rEntry = maStreamEntries[nTab];
         rStartOffset = rEntry.mnStartOffset;
@@ -158,7 +158,7 @@ void ScSheetSaveData::GetStreamPos( sal_Int32 nTab, sal_Int32& rStartOffset, sal
         rStartOffset = rEndOffset = -1;
 }
 
-bool ScSheetSaveData::HasStreamPos( sal_Int32 nTab ) const
+bool ScSheetSaveData::HasStreamPos( SCTAB nTab ) const
 {
     sal_Int32 nStartOffset = -1;
     sal_Int32 nEndOffset = -1;
@@ -171,9 +171,9 @@ void ScSheetSaveData::ResetSaveEntries()
     maSaveEntries.clear();
 }
 
-void ScSheetSaveData::AddSavePos( sal_Int32 nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
+void ScSheetSaveData::AddSavePos( SCTAB nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
 {
-    if ( nTab >= (sal_Int32)maSaveEntries.size() )
+    if ( nTab >= static_cast<SCTAB>(maSaveEntries.size()) )
         maSaveEntries.resize( nTab + 1 );
 
     maSaveEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
diff --git a/sc/source/filter/xml/xmlcoli.cxx b/sc/source/filter/xml/xmlcoli.cxx
index 7333dfa..963673c 100644
--- a/sc/source/filter/xml/xmlcoli.cxx
+++ b/sc/source/filter/xml/xmlcoli.cxx
@@ -121,7 +121,7 @@ SvXMLImportContext *ScXMLTableColContext::CreateChildContext( sal_uInt16 nPrefix
 void ScXMLTableColContext::EndElement()
 {
     ScXMLImport& rXMLImport = GetScImport();
-    sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
+    SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColumn();
     uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
     if(xSheet.is())
@@ -151,7 +151,7 @@ void ScXMLTableColContext::EndElement()
                             if ( nSheet != pStyle->GetLastSheet() )
                             {
                                 ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
-                                pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, (SCTAB)nSheet ) );
+                                pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, nSheet ) );
                                 pStyle->SetLastSheet(nSheet);
                             }
                         }
@@ -288,7 +288,7 @@ void ScXMLTableColsContext::EndElement()
     }
     else if (bGroup)
     {
-        sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
+        SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
         nGroupEndCol = rXMLImport.GetTables().GetCurrentColumn();
         nGroupEndCol--;
         if (nGroupStartCol <= nGroupEndCol)
@@ -297,7 +297,7 @@ void ScXMLTableColsContext::EndElement()
             if (pDoc)
             {
                 ScXMLImport::MutexGuard aGuard(GetScImport());
-                ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(nSheet), sal_True);
+                ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, sal_True);
                 ScOutlineArray* pColArray = pOutlineTable ? pOutlineTable->GetColArray() : NULL;
                 if (pColArray)
                 {
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index e047ef6..a1c580d 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -3006,7 +3006,7 @@ void ScXMLImport::ProgressBarIncrement(sal_Bool bEditCell, sal_Int32 nInc)
     }
 }
 
-sal_Int32 ScXMLImport::GetVisibleSheet()
+SCTAB ScXMLImport::GetVisibleSheet()
 {
     // Get the visible sheet number from model's view data (after settings were loaded),
     // or 0 (default: first sheet) if no settings available.
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index 28862bb..cdde3be 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -617,7 +617,7 @@ class SolarMutexGuard;
 
 struct tScMyCellRange
 {
-    sal_Int16 Sheet;
+    SCTAB Sheet;
     sal_Int32 StartColumn, EndColumn;
     sal_Int32 StartRow, EndRow;
 };
@@ -1009,7 +1009,7 @@ public:
     void SetLabelRanges();
     void AddDefaultNote( const com::sun::star::table::CellAddress& aCell );
 
-    sal_Int32   GetVisibleSheet();
+    SCTAB   GetVisibleSheet();
     /** Extracts the formula string, the formula grammar namespace URL, and a
         grammar enum value from the passed formula attribute value.
 
diff --git a/sc/source/filter/xml/xmlrowi.cxx b/sc/source/filter/xml/xmlrowi.cxx
index 173aec3..8978dd7 100644
--- a/sc/source/filter/xml/xmlrowi.cxx
+++ b/sc/source/filter/xml/xmlrowi.cxx
@@ -169,7 +169,7 @@ void ScXMLTableRowContext::EndElement()
             GetScImport().GetTables().AddRow();
         DBG_ERRORFILE("it seems here is a nonvalid file; possible missing of table:table-cell element");
     }
-    sal_Int32 nSheet = rXMLImport.GetTables().GetCurrentSheet();
+    SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
     sal_Int32 nCurrentRow(rXMLImport.GetTables().GetCurrentRow());
     uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
     if(xSheet.is())
@@ -202,7 +202,7 @@ void ScXMLTableRowContext::EndElement()
                                 if ( nSheet != pStyle->GetLastSheet() )
                                 {
                                     ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
-                                    pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, (SCTAB)nSheet ) );
+                                    pSheetData->AddRowStyle( sStyleName, ScAddress( 0, (SCROW)nFirstRow, nSheet ) );
                                     pStyle->SetLastSheet(nSheet);
                                 }
                             }
@@ -343,14 +343,14 @@ void ScXMLTableRowsContext::EndElement()
     else if (bGroup)
     {
         nGroupEndRow = rXMLImport.GetTables().GetCurrentRow();
-        sal_Int32 nSheet(rXMLImport.GetTables().GetCurrentSheet());
+        SCTAB nSheet(rXMLImport.GetTables().GetCurrentSheet());
         if (nGroupStartRow <= nGroupEndRow)
         {
             ScDocument* pDoc(GetScImport().GetDocument());
             if (pDoc)
             {
                 ScXMLImport::MutexGuard aGuard(GetScImport());
-                ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(static_cast<SCTAB>(nSheet), sal_True));
+                ScOutlineTable* pOutlineTable(pDoc->GetOutlineTable(nSheet, sal_True));
                 ScOutlineArray* pRowArray(pOutlineTable->GetRowArray());
                 sal_Bool bResized;
                 pRowArray->Insert(static_cast<SCROW>(nGroupStartRow), static_cast<SCROW>(nGroupEndRow), bResized, !bGroupDisplay, sal_True);
diff --git a/sc/source/filter/xml/xmlsceni.cxx b/sc/source/filter/xml/xmlsceni.cxx
index d072ea1..77a4220 100644
--- a/sc/source/filter/xml/xmlsceni.cxx
+++ b/sc/source/filter/xml/xmlsceni.cxx
@@ -146,7 +146,7 @@ SvXMLImportContext *ScXMLTableScenarioContext::CreateChildContext(
 
 void ScXMLTableScenarioContext::EndElement()
 {
-    SCTAB nCurrTable( sal::static_int_cast<SCTAB>( GetScImport().GetTables().GetCurrentSheet() ) );
+    SCTAB nCurrTable( GetScImport().GetTables().GetCurrentSheet() );
     ScDocument*	pDoc(GetScImport().GetDocument());
     if (pDoc)
     {
diff --git a/sc/source/filter/xml/xmlstyli.cxx b/sc/source/filter/xml/xmlstyli.cxx
index c4c31d8..2e11348 100644
--- a/sc/source/filter/xml/xmlstyli.cxx
+++ b/sc/source/filter/xml/xmlstyli.cxx
@@ -1060,14 +1060,14 @@ void ScCellTextStyleContext::FillPropertySet( const uno::Reference<beans::XPrope
     if (pCellImp)
     {
         ScAddress aPos = pCellImp->GetCellObj().GetPosition();
-        if ( static_cast<sal_Int32>(aPos.Tab()) != nLastSheet )
+        if ( aPos.Tab() != nLastSheet )
         {
             ESelection aSel = pCellImp->GetSelection();
 
             ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
             pSheetData->AddTextStyle( GetName(), aPos, aSel );
 
-            nLastSheet = static_cast<sal_Int32>(aPos.Tab());
+            nLastSheet = aPos.Tab();
         }
     }
     else if ( rXMLImport.GetTables().GetCurrentSheet() != nLastSheet )
diff --git a/sc/source/filter/xml/xmlstyli.hxx b/sc/source/filter/xml/xmlstyli.hxx
index 288bbe9..1521630 100644
--- a/sc/source/filter/xml/xmlstyli.hxx
+++ b/sc/source/filter/xml/xmlstyli.hxx
@@ -102,7 +102,7 @@ class XMLTableStyleContext : public XMLPropStyleContext
     std::vector<ScXMLMapContent>	aMaps;
     com::sun::star::uno::Any	aConditionalFormat;
     sal_Int32					nNumberFormat;
-    sal_Int32                   nLastSheet;
+    SCTAB                       nLastSheet;
     sal_Bool					bConditionalFormatCreated;
     sal_Bool					bParentSet;
 
@@ -160,8 +160,8 @@ public:
 
     sal_Int32 GetNumberFormat();// { return nNumberFormat; }
 
-    sal_Int32 GetLastSheet() const       { return nLastSheet; }
-    void SetLastSheet(sal_Int32 nNew)    { nLastSheet = nNew; }
+    SCTAB GetLastSheet() const       { return nLastSheet; }
+    void SetLastSheet(SCTAB nNew)    { nLastSheet = nNew; }
 
 private:
     using XMLPropStyleContext::SetStyle;
diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx
index 4b1316e..02b0467 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -67,14 +67,14 @@ using ::std::auto_ptr;
 
 using namespace com::sun::star;
 
-ScMyTableData::ScMyTableData(sal_Int32 nSheet, sal_Int32 nCol, sal_Int32 nRow)
+ScMyTableData::ScMyTableData(SCTAB nSheet, sal_Int32 nCol, sal_Int32 nRow)
     : 	nColsPerCol(nDefaultColCount, 1),
         nRealCols(nDefaultColCount + 1, 0),
         nRowsPerRow(nDefaultRowCount, 1),
         nRealRows(nDefaultRowCount + 1, 0),
         nChangedCols()
 {
-    aTableCellPos.Sheet = sal::static_int_cast<sal_Int16>( nSheet );
+    aTableCellPos.Sheet = nSheet;
     aTableCellPos.Column = nCol;
     aTableCellPos.Row = nRow;
 
@@ -192,7 +192,7 @@ void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString&
                 {
                     try
                     {
-                        xSheets->insertNewByName(sTableName, sal::static_int_cast<sal_Int16>(nCurrentSheet));
+                        xSheets->insertNewByName(sTableName, nCurrentSheet);
                     }
                     catch ( uno::RuntimeException& )
                     {
@@ -203,7 +203,7 @@ void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString&
                             String sTabName(String::CreateFromAscii("Table"));
                             pDoc->CreateValidTabName(sTabName);
                             rtl::OUString sOUTabName(sTabName);
-                            xSheets->insertNewByName(sOUTabName, sal::static_int_cast<sal_Int16>(nCurrentSheet));
+                            xSheets->insertNewByName(sOUTabName, nCurrentSheet);
                         }
                     }
                 }
@@ -260,7 +260,7 @@ void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString&
                                         pStyle->FillPropertySet(xProperties);
 
                                         ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData();
-                                        pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, (SCTAB)nCurrentSheet ) );
+                                        pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, nCurrentSheet ) );
                                     }
                                 }
                             }
@@ -608,7 +608,7 @@ void ScMyTables::UpdateRowHeights()
             SCTAB nCount = pDoc->GetTableCount();
             ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
 
-            SCTAB nVisible = static_cast<SCTAB>( rImport.GetVisibleSheet() );
+            SCTAB nVisible = rImport.GetVisibleSheet();
 
             ScMarkData aUpdateSheets;
             for (SCTAB nTab=0; nTab<nCount; ++nTab)
@@ -667,7 +667,7 @@ void ScMyTables::DeleteTable()
         pProtect->setPasswordHash(aHash, maProtectionData.meHash1, maProtectionData.meHash2);
         pProtect->setOption(ScTableProtection::SELECT_LOCKED_CELLS,   maProtectionData.mbSelectProtectedCells);
         pProtect->setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, maProtectionData.mbSelectUnprotectedCells);
-        rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), pProtect.get());
+        rImport.GetDocument()->SetTabProtection(nCurrentSheet, pProtect.get());
     }
 
     //#95582#; find out whether it was possible to set the sheet name
@@ -679,7 +679,7 @@ void ScMyTables::DeleteTable()
         rtl::OUString sCurrentName(xNamed->getName());
         if (sCurrentName != sCurrentSheetName && rImport.GetDocument())
         {
-            rImport.GetDocument()->RenameTab( static_cast<SCTAB>(nCurrentSheet),
+            rImport.GetDocument()->RenameTab( nCurrentSheet,
                 sCurrentSheetName, false, sal_True);
         }
     }
@@ -699,7 +699,7 @@ table::CellAddress ScMyTables::GetRealCellPos()
 
     aRealCellPos.Row = nRow;
     aRealCellPos.Column = nCol;
-    aRealCellPos.Sheet = sal::static_int_cast<sal_Int16>(nCurrentSheet);
+    aRealCellPos.Sheet = nCurrentSheet;
     return aRealCellPos;
 }
 
@@ -769,7 +769,7 @@ void ScMyTables::AddMatrixRange(
     aRange.StartRow = nStartRow;
     aRange.EndColumn = nEndColumn;
     aRange.EndRow = nEndRow;
-    aRange.Sheet = sal::static_int_cast<sal_Int16>(nCurrentSheet);
+    aRange.Sheet = nCurrentSheet;
     ScMatrixRange aMRange(aRange, rFormula, rFormulaNmsp, eGrammar);
     aMatrixRangeList.push_back(aMRange);
 }
diff --git a/sc/source/filter/xml/xmlsubti.hxx b/sc/source/filter/xml/xmlsubti.hxx
index e0a8d9a..794a132 100644
--- a/sc/source/filter/xml/xmlsubti.hxx
+++ b/sc/source/filter/xml/xmlsubti.hxx
@@ -67,7 +67,7 @@ private:
     sal_Int32							nSubTableSpanned;
     ScMysalIntList						nChangedCols;
 public:
-                                        ScMyTableData(sal_Int32 nSheet = -1, sal_Int32 nCol = -1, sal_Int32 nRow = -1);
+                                        ScMyTableData(SCTAB nSheet = -1, sal_Int32 nCol = -1, sal_Int32 nRow = -1);
                                         ~ScMyTableData();
     com::sun::star::table::CellAddress 	GetCellPos() const { return aTableCellPos; }
     sal_Int32							GetRow() const { return aTableCellPos.Row; }
@@ -142,7 +142,7 @@ private:
     sal_Int32							nCurrentColStylePos;
     sal_Int16							nCurrentDrawPage;
     sal_Int16							nCurrentXShapes;
-    sal_Int32							nCurrentSheet;
+    SCTAB							    nCurrentSheet;
 
     sal_Bool 							IsMerged (const com::sun::star::uno::Reference <com::sun::star::table::XCellRange>& xCellRange,
                                                 const sal_Int32 nCol, const sal_Int32 nRow,
@@ -172,7 +172,7 @@ public:
     void								AddColStyle(const sal_Int32 nRepeat, const rtl::OUString& rCellStyleName);
     ScXMLTabProtectionData&             GetCurrentProtectionData() { return maProtectionData; }
     rtl::OUString						GetCurrentSheetName() const { return sCurrentSheetName; }
-    sal_Int32							GetCurrentSheet() const { return nCurrentSheet; }
+    SCTAB							    GetCurrentSheet() const { return nCurrentSheet; }
     sal_Int32							GetCurrentColumn() const { return maTables.back().GetColCount(); }
     sal_Int32							GetCurrentRow() const { return maTables.back().GetRow(); }
     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
diff --git a/sc/source/filter/xml/xmltabi.cxx b/sc/source/filter/xml/xmltabi.cxx
index 8c2f084..de55886 100644
--- a/sc/source/filter/xml/xmltabi.cxx
+++ b/sc/source/filter/xml/xmltabi.cxx
@@ -285,8 +285,8 @@ SvXMLImportContext *ScXMLTableContext::CreateChildContext( sal_uInt16 nPrefix,
         ScDocument* pDoc = GetScImport().GetDocument();
         if (pDoc)
         {
-            sal_Int32 nTab = GetScImport().GetTables().GetCurrentSheet();
-            ScRangeName* pRN = pDoc->GetRangeName(static_cast<SCTAB>(nTab));
+            SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
+            ScRangeName* pRN = pDoc->GetRangeName(nTab);
             if (pRN)
             {
                 pContext = new ScXMLNamedExpressionsContext( 
@@ -381,7 +381,7 @@ void ScXMLTableContext::EndElement()
     if (!pDoc)
         return;
 
-    SCTAB nCurTab = static_cast<SCTAB>(GetScImport().GetTables().GetCurrentSheet());
+    SCTAB nCurTab = GetScImport().GetTables().GetCurrentSheet();
     if (sPrintRanges.getLength())
     {
         Reference< sheet::XPrintAreas > xPrintAreas(
@@ -446,7 +446,7 @@ void ScXMLTableContext::EndElement()
     if (!pExternalRefInfo.get() && nStartOffset >= 0 /* && nEndOffset >= 0 */)
     {
         ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetScImport().GetModel())->GetSheetSaveData();
-        sal_Int32 nTab = GetScImport().GetTables().GetCurrentSheet();
+        SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
         // pSheetData->AddStreamPos( nTab, nStartOffset, nEndOffset );
         pSheetData->StartStreamPos( nTab, nStartOffset );
     }
diff --git a/sc/source/ui/vba/vbaquerytable.cxx b/sc/source/ui/vba/vbaquerytable.cxx
index 159c7b7..03e734a 100644
--- a/sc/source/ui/vba/vbaquerytable.cxx
+++ b/sc/source/ui/vba/vbaquerytable.cxx
@@ -59,9 +59,9 @@ ScVbaQueryTable::Refresh( const ::com::sun::star::uno::Any& /*aBackgroundQuery*/
 {
 
     //Get parent Info
-    sal_Int32 nRow = m_pParent->getRow();
-    sal_Int32 nClm = m_pParent->getColumn();
-    sal_Int16 nTab = m_pParent->getWorksheet()->getIndex() - 1; //The vba index begin from 1.
+    SCROW nRow = m_pParent->getRow();
+    SCCOL nClm = m_pParent->getColumn();
+    SCTAB nTab = m_pParent->getWorksheet()->getIndex() - 1; //The vba index begin from 1.
     ScAddress crrRngAddr(nClm, nRow, nTab);
 
     //Get link info
commit f4009279e0c97184a37422e42d929d51a4c13f10
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Wed Jun 1 21:37:42 2011 +0200

    we cant't check for 2*MAXTAB anymore, this is out of bounds

diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 9ea2068..741b7da 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -458,7 +458,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
                                 bValid = !pDoc->GetTable( aName, nDummy );
                             ++i;
                         }
-                        while ( !bValid && i <= 2*MAXTAB );
+                        while ( !bValid && i <= MAXTAB + 2 );
 
                         if ( pReqArgs != NULL )
                         {
commit 63203e86f81b9e8f57294347ba76840de0770d39
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue May 31 21:44:01 2011 +0200

    some minor performance improvements

diff --git a/sc/source/ui/view/tabvwsh5.cxx b/sc/source/ui/view/tabvwsh5.cxx
index fffc035..5625dc4 100644
--- a/sc/source/ui/view/tabvwsh5.cxx
+++ b/sc/source/ui/view/tabvwsh5.cxx
@@ -241,6 +241,7 @@ void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
                 break;
             case SC_TABS_INSERTED:
                 GetViewData()->InsertTabs( nTab1, nTab2 );
+                break;
             default:
                 OSL_FAIL("unbekannter ScTablesHint");
         }
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index a4f8379..9179407 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -308,15 +308,7 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                             else
                             {
                                 SCTAB	nTabAfter	 = nTabNr+1;
-                                SCTAB nSelHigh=0;
-
-                                for(SCTAB i=0;i<nTabCount;i++)
-                                {
-                                    if(rMark.GetTableSelect(i))
-                                    {
-                                        nSelHigh=i;
-                                    }
-                                }
+                                SCTAB nSelHigh = rMark.GetLastSelected();
 
                                 for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
                                 {
commit 878899b8a99fb969bf941e7e457a52c00e8254b6
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Tue May 31 21:39:52 2011 +0200

    set table limit to 32000
    
    the performance of the insert algorithm allows now to create more than 10000 sheets in a reasonable time

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index ddc38f4..29c96c3 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -91,7 +91,7 @@ const SCSIZE   SCSIZE_MAX   = ::std::numeric_limits<SCSIZE>::max();
 // Count values
 const SCROW       MAXROWCOUNT    = MAXROWCOUNT_DEFINE;
 const SCCOL       MAXCOLCOUNT    = MAXCOLCOUNT_DEFINE;
-const SCTAB       MAXTABCOUNT    = 10000;
+const SCTAB       MAXTABCOUNT    = 32000;
 const SCCOLROW    MAXCOLROWCOUNT = MAXROWCOUNT;
 // Maximum values
 const SCROW       MAXROW         = MAXROWCOUNT - 1;
commit 92ca4e867935c935935208f597c0ebc1cda8a894
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Mon May 30 20:38:52 2011 +0200

    fix segv when inserting multiple sheets

diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index c52c69c..f6f197b 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -523,7 +523,8 @@ bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<rtl::OUString>& rName
                 for (; it != pTab.end(); ++it)
                     if ( *it )
                         (*it)->UpdateInsertTab(nPos, nNewSheets);
-                pTab.resize(nTabCount + nNewSheets, NULL);
+                it = pTab.begin();
+                pTab.insert(it+nPos,nNewSheets, NULL);
                 for (SCTAB i = 0; i < nNewSheets; ++i)
                 {
                     pTab[nPos + i] = new ScTable(this, nPos + i, rNames.at(i));
@@ -536,8 +537,10 @@ bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<rtl::OUString>& rName
                 UpdateBroadcastAreas( URM_INSDEL, aRange, 0,0,nNewSheets);
                 it = pTab.begin();
                 for (; it != pTab.end(); ++it)
+                {
                     if ( *it )
                         (*it)->UpdateCompile();
+                }
                 it = pTab.begin();
                 for (; it != pTab.end(); ++it)
                     if ( *it )
commit 2579dc3be9ab0f2d502f30551629510d17ceb2ae
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun May 29 20:22:30 2011 +0200

    notify vba correctly about inserting of several worksheets

diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 5a23b08..7671d55 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -542,6 +542,15 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
                 aArgs[0] <<= rScHint.GetTab1();
                 xVbaEvents->processVbaEvent( WORKBOOK_NEWSHEET, aArgs );
             }
+            else if (rScHint.GetId() == SC_TABS_INSERTED)
+            {
+                for (SCTAB i = 0; i < rScHint.GetTab2(); ++i)
+                {
+                    uno::Sequence< uno::Any > aArgs( 1 );
+                    aArgs[0] <<= rScHint.GetTab1() + i;
+                    xVbaEvents->processVbaEvent( WORKBOOK_NEWSHEET, aArgs );
+                }
+            }
         }
         else if ( rHint.ISA( SfxEventHint ) )
         {
commit 10d8872ce3a9f20a4d05a77266df4a19a11490dc
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 27 07:01:52 2011 +0200

    some performance improvements for inserting sheets
    
    only update the viewshell once instead of every time, this allows the creation of a large amount of sheets nearly immediately

diff --git a/sc/source/ui/inc/uiitems.hxx b/sc/source/ui/inc/uiitems.hxx
index 3e64b48..aaa8903 100644
--- a/sc/source/ui/inc/uiitems.hxx
+++ b/sc/source/ui/inc/uiitems.hxx
@@ -92,6 +92,7 @@ public:
 #define SC_TAB_MOVED		3
 #define SC_TAB_COPIED		4
 #define SC_TAB_HIDDEN		5
+#define SC_TABS_INSERTED    6
 
 class ScTablesHint : public SfxHint
 {
diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index c1a5448..303ca6e 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -277,6 +277,7 @@ public:
     void			UpdateThis();
 
     void			InsertTab( SCTAB nTab );
+    void			InsertTabs( SCTAB nTab, SCTAB nNewSheets );
     void			DeleteTab( SCTAB nTab );
     void			CopyTab( SCTAB nSrcTab, SCTAB nDestTab );
     void			MoveTab( SCTAB nSrcTab, SCTAB nDestTab );
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 0ba6e9b..0842c93 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -207,7 +207,6 @@ ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
 
 ScUndoInsertTables::~ScUndoInsertTables()
 {
-    String *pStr=NULL;
     DeleteSdrUndoAction( pDrawUndo );
 }
 
@@ -224,7 +223,7 @@ void ScUndoInsertTables::SetChangeTrack()
         nStartChangeAction = pChangeTrack->GetActionMax() + 1;
         nEndChangeAction = 0;
         ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
-        for( int i = 0; i < aNameList.size(); i++ )
+        for( size_t i = 0; i < aNameList.size(); i++ )
         {
             aRange.aStart.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
             aRange.aEnd.SetTab( sal::static_int_cast<SCTAB>( nTab + i ) );
@@ -245,7 +244,7 @@ void ScUndoInsertTables::Undo()
     bDrawIsInUndo = sal_True;
 
     vector<SCTAB> TheTabs;
-    for(int i=0; i< aNameList.size(); ++i)
+    for(SCTAB i=0; i< static_cast<SCTAB>(aNameList.size()); ++i)
     {
         TheTabs.push_back(nTab+i);
     }
diff --git a/sc/source/ui/view/tabvwsh5.cxx b/sc/source/ui/view/tabvwsh5.cxx
index e6d849e..fffc035 100644
--- a/sc/source/ui/view/tabvwsh5.cxx
+++ b/sc/source/ui/view/tabvwsh5.cxx
@@ -239,6 +239,8 @@ void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
                 break;
             case SC_TAB_HIDDEN:
                 break;
+            case SC_TABS_INSERTED:
+                GetViewData()->InsertTabs( nTab1, nTab2 );
             default:
                 OSL_FAIL("unbekannter ScTablesHint");
         }
@@ -282,6 +284,10 @@ void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
                 if ( nTab1 == nNewTab )				// aktuelle ausgeblendet
                     bStayOnActiveTab = false;
                 break;
+            case SC_TABS_INSERTED:
+                if ( nTab1 <= nNewTab )
+                    nNewTab += nTab2;
+                break;
         }
 
         ScDocument* pDoc = GetViewData()->GetDocument();
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 575eb3c..88ddd7c 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -460,15 +460,32 @@ void ScViewData::UpdateThis()
 
 void ScViewData::InsertTab( SCTAB nTab )
 {
-    while( nTab >= static_cast<SCTAB>(pTabData.size()))
-        pTabData.push_back(NULL);
-    pTabData.insert( pTabData.begin() + nTab, NULL );
+    if( nTab >= static_cast<SCTAB>(pTabData.size()))
+        pTabData.resize(nTab+1, NULL);
+    else
+        pTabData.insert( pTabData.begin() + nTab, NULL );
     CreateTabData( nTab );
 
     UpdateThis();
     aMarkData.InsertTab( nTab );
 }
 
+void ScViewData::InsertTabs( SCTAB nTab, SCTAB nNewSheets )
+{
+    if( nTab+nNewSheets >= static_cast<SCTAB>(pTabData.size()))
+        pTabData.resize(nTab+nNewSheets, NULL);
+    else
+    {
+        pTabData.insert( pTabData.begin() + nTab, nNewSheets, NULL );
+    }
+    for (SCTAB aTab = nTab; aTab < nTab + nNewSheets; ++aTab)
+    {
+        CreateTabData( aTab );
+        aMarkData.InsertTab( aTab );
+    }
+    UpdateThis();
+}
+
 void ScViewData::DeleteTab( SCTAB nTab )
 {
     delete pTabData[nTab];
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 53d4796..7b53ffc 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -2012,10 +2012,7 @@ sal_Bool ScViewFunc::InsertTables(std::vector<rtl::OUString>& aNames, SCTAB nTab
     }
     if (pDoc->InsertTabs(nTab, aNames, false))
     {
-        for (SCTAB i=0;i<nCount; i++)
-        {
-            pDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab+i ) );
-        }
+        pDocSh->Broadcast( ScTablesHint( SC_TABS_INSERTED, nTab, nCount ) );
         bFlag = true;
     }
 
commit 3cd8167ef8e78343106abd2d908a28310769718e
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 27 05:16:37 2011 +0200

    rework some other methods for performance improvements
    
    inserting several sheets now happens at once and not for every sheet seperately, this accelerates inserting of sheets at all positions dramatically

diff --git a/sc/inc/cell.hxx b/sc/inc/cell.hxx
index 36d66a0..34e9781 100644
--- a/sc/inc/cell.hxx
+++ b/sc/inc/cell.hxx
@@ -442,7 +442,7 @@ public:
 
     void			UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
 
-    void			UpdateInsertTab(SCTAB nTable);
+    void			UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1);
     void 			UpdateInsertTabAbs(SCTAB nTable);
     sal_Bool			UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove = false);
     void			UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index dcd7b64..d3ea6ad 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -290,8 +290,8 @@ public:
                                      SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
                                      SCsCOL nDx, SCsROW nDy, SCsTAB nDz,
                                      ScDocument* pUndoDoc = NULL );
-    void        UpdateInsertTab( SCTAB nTable);
-    void        UpdateInsertTabOnlyCells( SCTAB nTable);
+    void        UpdateInsertTab( SCTAB nTable, SCTAB nNewSheets = 1);
+    void        UpdateInsertTabOnlyCells( SCTAB nTable, SCTAB nNewSheets = 1);
     void        UpdateDeleteTab( SCTAB nTable, bool bIsMove, ScColumn* pRefUndo = NULL );
     void        UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo);
     void        UpdateCompile( bool bForceIfNameInUse = false );
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx
index 407b580..5d6cb6c 100644
--- a/sc/inc/compiler.hxx
+++ b/sc/inc/compiler.hxx
@@ -444,7 +444,7 @@ public:
                                   const ScAddress& rOldPos, const ScRange&,
                                   SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
 
-    ScRangeData* UpdateInsertTab(SCTAB nTable, sal_Bool bIsName );
+    ScRangeData* UpdateInsertTab(SCTAB nTable, sal_Bool bIsName, SCTAB nNewSheets = 1 );
     ScRangeData* UpdateDeleteTab(SCTAB nTable, sal_Bool bIsMove, sal_Bool bIsName, sal_Bool& bCompile);
     ScRangeData* UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, sal_Bool bIsName );
 
diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index c6a64a7..a891535 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -146,7 +146,7 @@ public:
     SC_DLLPUBLIC sal_Bool			IsValidReference( ScRange& rRef ) const;
     sal_Bool			IsRangeAtBlock( const ScRange& ) const;
 
-    void 			UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable);
+    void 			UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets);
     void			TransferTabRef( SCTAB nOldTab, SCTAB nNewTab );
 
     void			ValidateTabRefs();
@@ -199,7 +199,7 @@ public:
     SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i);
     void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange,
                          SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
-    void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0);
+    void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0, SCTAB nNewSheets = 1);
     void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
     void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 49c705f..c559181 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -476,7 +476,7 @@ public:
 
     void		UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
 
-    void		UpdateInsertTab(SCTAB nTable);
+    void		UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets = 1);
     void 		UpdateDeleteTab( SCTAB nTable, sal_Bool bIsMove, ScTable* pRefUndo = NULL );
     void		UpdateMoveTab(SCTAB nOldPos, SCTAB nNewPos, SCTAB nTabNo, ScProgress& );
     void		UpdateCompile( sal_Bool bForceIfNameInUse = false );
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index 5bac8e3..aaa03a8 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -1129,7 +1129,7 @@ bool ScFormulaCell::UpdateReference(UpdateRefMode eUpdateRefMode,
     return bCellStateChanged;
 }
 
-void ScFormulaCell::UpdateInsertTab(SCTAB nTable)
+void ScFormulaCell::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
 {
     sal_Bool bPosChanged = ( aPos.Tab() >= nTable ? sal_True : false );
     pCode->Reset();
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 471c0dc..2bd2019 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1723,16 +1723,19 @@ void ScColumn::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
 }
 
 
-void ScColumn::UpdateInsertTab( SCTAB nTable)
+void ScColumn::UpdateInsertTab( SCTAB nTable, SCTAB nNewSheets )
 {
     if (nTab >= nTable)
-        pAttrArray->SetTab(++nTab);
+    {
+        nTab += nNewSheets;
+        pAttrArray->SetTab(nTab);
+    }
     if( pItems )
-        UpdateInsertTabOnlyCells( nTable );
+        UpdateInsertTabOnlyCells( nTable, nNewSheets );
 }
 
 
-void ScColumn::UpdateInsertTabOnlyCells( SCTAB nTable)
+void ScColumn::UpdateInsertTabOnlyCells( SCTAB nTable, SCTAB nNewSheets )
 {
     if (pItems)
         for (SCSIZE i = 0; i < nCount; i++)
@@ -1741,7 +1744,7 @@ void ScColumn::UpdateInsertTabOnlyCells( SCTAB nTable)
             if( pCell->GetCellType() == CELLTYPE_FORMULA)
             {
                 SCROW nRow = pItems[i].nRow;
-                pCell->UpdateInsertTab(nTable);
+                pCell->UpdateInsertTab(nTable, nNewSheets);
                 if ( nRow != pItems[i].nRow )
                     Search( nRow, i );		// Listener geloescht/eingefuegt?
             }
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 779fcb7..de71a26 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1398,9 +1398,10 @@ void ScTable::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
         aCol[i].UpdateGrow( rArea, nGrowX, nGrowY );
 }
 
-void ScTable::UpdateInsertTab(SCTAB nTable)
+void ScTable::UpdateInsertTab(SCTAB nTable, SCTAB nNewSheets)
 {
-    if (nTab >= nTable) nTab++;
+    if (nTab >= nTable)
+        nTab += nNewSheets;
     for (SCCOL i=0; i <= MAXCOL; i++) aCol[i].UpdateInsertTab(nTable);
 
     if (IsStreamValid())
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 70a20b5..ab282c8 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4480,7 +4480,7 @@ void ScCompiler::UpdateSharedFormulaReference( UpdateRefMode eUpdateRefMode,
 }
 
 
-ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName )
+ScRangeData* ScCompiler::UpdateInsertTab( SCTAB nTable, sal_Bool bIsName , SCTAB nNewSheets)
 {
     ScRangeData* pRangeData = NULL;
     SCTAB nPosTab = aPos.Tab();     // _after_ incremented!

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list