[Libreoffice-commits] .: Branch 'feature/unlimited-number-of-sheets' - 2 commits - sc/inc sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Thu May 26 20:19:17 PDT 2011


 sc/inc/cell.hxx                  |    2 
 sc/inc/column.hxx                |    4 -
 sc/inc/compiler.hxx              |    2 
 sc/inc/document.hxx              |    4 +
 sc/inc/rangenam.hxx              |    4 -
 sc/inc/table.hxx                 |    2 
 sc/source/core/data/cell2.cxx    |    2 
 sc/source/core/data/column.cxx   |   13 ++-
 sc/source/core/data/document.cxx |  144 +++++++++++++++++++++++++++++++++++++--
 sc/source/core/data/table1.cxx   |    5 -
 sc/source/core/tool/compiler.cxx |    2 
 sc/source/core/tool/rangenam.cxx |    8 +-
 sc/source/ui/inc/undotab.hxx     |    4 -
 sc/source/ui/inc/viewfunc.hxx    |    2 
 sc/source/ui/undo/undotab.cxx    |   20 +----
 sc/source/ui/view/tabvwshf.cxx   |    8 +-
 sc/source/ui/view/viewfun2.cxx   |   53 ++++----------
 17 files changed, 198 insertions(+), 81 deletions(-)

New commits:
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!
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index 94d6797..d9a5c37 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -391,7 +391,7 @@ sal_Bool ScRangeData::IsValidReference( ScRange& rRange ) const
     return false;
 }
 
-void ScRangeData::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable)
+void ScRangeData::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets)
 {
     pCode->Reset();
     if( pCode->GetNextReference() )
@@ -403,7 +403,7 @@ void ScRangeData::UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTabl
         switch (nFlag)
         {
             case 1:										// einfache InsertTab (doc.cxx)
-                pRangeData = aComp.UpdateInsertTab(nOldTable, sal_True );	// und CopyTab (doc2.cxx)
+                pRangeData = aComp.UpdateInsertTab(nOldTable, sal_True, nNewSheets );	// und CopyTab (doc2.cxx)
                 break;
             case 2:										// einfaches delete (doc.cxx)
                 pRangeData = aComp.UpdateDeleteTab(nOldTable, false, sal_True, bChanged);
@@ -784,11 +784,11 @@ void ScRangeName::UpdateReference(
         itr->UpdateReference(eUpdateRefMode, rRange, nDx, nDy, nDz);
 }
 
-void ScRangeName::UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable)
+void ScRangeName::UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets)
 {
     DataType::iterator itr = maData.begin(), itrEnd = maData.end();
     for (; itr != itrEnd; ++itr)
-        itr->UpdateTabRef(nTable, nFlag, nNewTable);
+        itr->UpdateTabRef(nTable, nFlag, nNewTable, nNewSheets);
 }
 
 void ScRangeName::UpdateTranspose(const ScRange& rSource, const ScAddress& rDest)
diff --git a/sc/source/ui/inc/undotab.hxx b/sc/source/ui/inc/undotab.hxx
index ba2ff38..c89ba95 100644
--- a/sc/source/ui/inc/undotab.hxx
+++ b/sc/source/ui/inc/undotab.hxx
@@ -94,7 +94,7 @@ public:
                             ScDocShell* pNewDocShell,
                             SCTAB nTabNum,
                             sal_Bool bApp,
-                            SvStrings *pNewNameList);
+                            std::vector<rtl::OUString>& newNameList);
     virtual			~ScUndoInsertTables();
 
     virtual void	Undo();
@@ -107,7 +107,7 @@ public:
 private:
 
     SdrUndoAction*	pDrawUndo;
-    SvStrings*		pNameList;
+    std::vector<rtl::OUString>		aNameList;
     sal_uLong			nStartChangeAction;
     sal_uLong			nEndChangeAction;
     SCTAB			nTab;
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index deca468..a36c5bf 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -260,7 +260,7 @@ public:
     void			TabOp( const ScTabOpParam& rParam,  sal_Bool bRecord = sal_True );
 
     sal_Bool			InsertTable( const String& rName, SCTAB nTabNr, sal_Bool bRecord = sal_True );
-    sal_Bool			InsertTables(SvStrings *pNames, SCTAB nTab, SCTAB nCount, sal_Bool bRecord = sal_True);
+    sal_Bool			InsertTables(std::vector<rtl::OUString>& aNames, SCTAB nTab, SCTAB nCount, sal_Bool bRecord = sal_True);
 
 
     sal_Bool			AppendTable( const String& rName, sal_Bool bRecord = sal_True );
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 549a893..0ba6e9b 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -193,13 +193,13 @@ sal_Bool ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
 
 ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
                                         SCTAB nTabNum,
-                                        sal_Bool bApp,SvStrings *pNewNameList) :
+                                        sal_Bool bApp,std::vector<rtl::OUString>& newNameList) :
     ScSimpleUndo( pNewDocShell ),
     pDrawUndo( NULL ),
+    aNameList( newNameList ),
     nTab( nTabNum ),
     bAppend( bApp )
 {
-    pNameList =	pNewNameList;
     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
 
     SetChangeTrack();
@@ -208,16 +208,6 @@ ScUndoInsertTables::ScUndoInsertTables( ScDocShell* pNewDocShell,
 ScUndoInsertTables::~ScUndoInsertTables()
 {
     String *pStr=NULL;
-    if(pNameList!=NULL)
-    {
-        for(int i=0;i<pNameList->Count();i++)
-        {
-            pStr=pNameList->GetObject(sal::static_int_cast<sal_uInt16>(i));
-            delete pStr;
-        }
-        pNameList->Remove(0,pNameList->Count());
-        delete pNameList;
-    }
     DeleteSdrUndoAction( pDrawUndo );
 }
 
@@ -234,7 +224,7 @@ void ScUndoInsertTables::SetChangeTrack()
         nStartChangeAction = pChangeTrack->GetActionMax() + 1;
         nEndChangeAction = 0;
         ScRange aRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
-        for( int i = 0; i < pNameList->Count(); i++ )
+        for( int 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 ) );
@@ -255,7 +245,7 @@ void ScUndoInsertTables::Undo()
     bDrawIsInUndo = sal_True;
 
     vector<SCTAB> TheTabs;
-    for(int i=0; i<pNameList->Count(); ++i)
+    for(int i=0; i< aNameList.size(); ++i)
     {
         TheTabs.push_back(nTab+i);
     }
@@ -284,7 +274,7 @@ void ScUndoInsertTables::Redo()
     pDocShell->SetInUndo( sal_True );				//! BeginRedo
     bDrawIsInUndo = sal_True;
     pViewShell->SetTabNo(nTab);
-    pViewShell->InsertTables( pNameList, nTab, static_cast<SCTAB>(pNameList->Count()),false );
+    pViewShell->InsertTables( aNameList, nTab, static_cast<SCTAB>(aNameList.size()),false );
 
     bDrawIsInUndo = false;
     pDocShell->SetInUndo( false );				//! EndRedo
diff --git a/sc/source/ui/view/tabvwshf.cxx b/sc/source/ui/view/tabvwshf.cxx
index f33a562..a4f8379 100644
--- a/sc/source/ui/view/tabvwshf.cxx
+++ b/sc/source/ui/view/tabvwshf.cxx
@@ -300,7 +300,10 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                                     InsertTable( *pDlg->GetFirstTable(), nTabNr );
                                 }
                                 else
-                                    InsertTables( NULL, nTabNr,nCount );
+                                {
+                                    std::vector<rtl::OUString> aNames(0);
+                                    InsertTables( aNames, nTabNr,nCount );
+                                }
                             }
                             else
                             {
@@ -336,7 +339,8 @@ void ScTabViewShell::ExecuteTable( SfxRequest& rReq )
                                 }
                                 else
                                 {
-                                    InsertTables( NULL, nTabAfter,nCount);
+                                    std::vector<rtl::OUString> aNames(0);
+                                    InsertTables( aNames, nTabAfter,nCount);
                                 }
                             }
                         }
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index ec16f0f..53d4796 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -1989,70 +1989,49 @@ sal_Bool ScViewFunc::InsertTable( const String& rName, SCTAB nTab, sal_Bool bRec
 //----------------------------------------------------------------------------
 //	Insert tables
 
-sal_Bool ScViewFunc::InsertTables(SvStrings *pNames, SCTAB nTab,
+sal_Bool ScViewFunc::InsertTables(std::vector<rtl::OUString>& aNames, SCTAB nTab,
                                             SCTAB nCount, sal_Bool bRecord )
 {
-    ScDocShell* pDocSh	= GetViewData()->GetDocShell();
-    ScDocument* pDoc 	= pDocSh->GetDocument();
+    ScDocShell* pDocSh    = GetViewData()->GetDocShell();
+    ScDocument* pDoc     = pDocSh->GetDocument();
     if (bRecord && !pDoc->IsUndoEnabled())
         bRecord = false;
 
-    SvStrings *pNameList= NULL;
-
     WaitObject aWait( GetFrameWin() );
 
     if (bRecord)
     {
-        pNameList= new SvStrings;
-        pDoc->BeginDrawUndo();							//	InsertTab creates a SdrUndoNewPage
+        pDoc->BeginDrawUndo();                            //    InsertTab creates a SdrUndoNewPage
     }
 
-    sal_Bool bFlag=false;
-
-    String aValTabName;
-    String *pStr;
+    bool bFlag=false;
 
-    for(SCTAB i=0;i<nCount;i++)
+    if(aNames.empty())
     {
-        if(pNames!=NULL)
-        {
-            pStr=pNames->GetObject(static_cast<sal_uInt16>(i));
-        }
-        else
-        {
-            aValTabName.Erase();
-            pDoc->CreateValidTabName( aValTabName);
-            pStr=&aValTabName;
-        }
-
-        if(pDoc->InsertTab( nTab+i,*pStr))
+        pDoc->CreateValidTabNames(aNames, nCount);
+    }
+    if (pDoc->InsertTabs(nTab, aNames, false))
+    {
+        for (SCTAB i=0;i<nCount; i++)
         {
-            bFlag=sal_True;
             pDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab+i ) );
         }
-        else
-        {
-            break;
-        }
-
-        if(pNameList!=NULL)
-            pNameList->Insert(new String(*pStr),pNameList->Count());
-
+        bFlag = true;
     }
 
     if (bFlag)
     {
         if (bRecord)
             pDocSh->GetUndoManager()->AddUndoAction(
-                        new ScUndoInsertTables( pDocSh, nTab, false, pNameList));
+                        new ScUndoInsertTables( pDocSh, nTab, false, aNames));
 
-        //	Update views
+        //    Update views
 
-        SetTabNo( nTab, sal_True );
+        SetTabNo( nTab, true );
         pDocSh->PostPaintExtras();
         pDocSh->SetDocumentModified();
         SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
-        return sal_True;
+        return true;
     }
     else
     {
commit a469086c254bdc1375aa2f4f3f8283d3af484f7a
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri May 27 05:14:53 2011 +0200

    add methods for performance improvements

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 94f5ec8..8e6180d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -572,9 +572,13 @@ public:
     static SC_DLLPUBLIC bool ValidTabName( const String& rName );
 
     SC_DLLPUBLIC sal_Bool			ValidNewTabName( const String& rName ) const;
+    SC_DLLPUBLIC bool			    ValidNewTabName( const std::vector<String>& rName ) const;
     SC_DLLPUBLIC void			CreateValidTabName(String& rName) const;
+    SC_DLLPUBLIC void			CreateValidTabNames(std::vector<rtl::OUString>& aNames, SCTAB nCount) const;
     SC_DLLPUBLIC sal_Bool			InsertTab( SCTAB nPos, const String& rName,
                                 sal_Bool bExternalDocument = false );
+    SC_DLLPUBLIC bool			InsertTabs( SCTAB nPos, const std::vector<rtl::OUString>& rNames,
+                                bool bExternalDocument = false, bool bNamesValid = false );
     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/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 28d794c..c52c69c 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -294,6 +294,29 @@ sal_Bool ScDocument::ValidNewTabName( const String& rName ) const
 }
 
 
+bool ScDocument::ValidNewTabName( const std::vector<String>& rNames ) const//TODO:FIXME what is if there are duplicates in rNames
+{
+    bool bValid = true;
+    std::vector<String>::const_iterator nameIter = rNames.begin();
+    for (;nameIter != rNames.end() && bValid; ++nameIter)
+    {
+        bValid = ValidTabName(*nameIter);
+    }
+    TableContainer::const_iterator it = pTab.begin();
+    for (; it != pTab.end() && bValid; ++it)
+        if ( *it )
+        {
+            for (nameIter = rNames.begin(); nameIter != rNames.end(); ++nameIter)
+            {
+                String aOldName;
+                (*it)->GetName(aOldName);
+                bValid = !ScGlobal::GetpTransliteration()->isEqual( *nameIter, aOldName );
+            }
+        }
+    return bValid;
+}
+
+
 void ScDocument::CreateValidTabName(String& rName) const
 {
     if ( !ValidTabName(rName) )
@@ -308,7 +331,7 @@ void ScDocument::CreateValidTabName(String& rName) const
         OSL_ENSURE(bPrefix, "Invalid Table Name");
         SCTAB nDummy;
 
-        for ( SCTAB i = pTab.size()+1; !bOk ; i++ )
+        for ( SCTAB i = static_cast<SCTAB>(pTab.size())+1; !bOk ; i++ )
         {
             rName  = aStrTable;
             rName += String::CreateFromInt32(i);
@@ -318,9 +341,6 @@ void ScDocument::CreateValidTabName(String& rName) const
                 bOk = !GetTable( rName, nDummy );
         }
 
-        OSL_ENSURE(bOk, "No Valid Table name found.");
-        if ( !bOk )
-            rName = aStrTable;
     }
     else
     {
@@ -344,6 +364,38 @@ void ScDocument::CreateValidTabName(String& rName) const
 }
 
 
+void ScDocument::CreateValidTabNames(std::vector<rtl::OUString>& aNames, SCTAB nCount) const
+{
+    aNames.clear();//ensure that the vector is empty
+
+    const String aStrTable( ScResId(SCSTR_TABLE) );
+    String rName;
+    bool		 bOk   = false;
+
+    // First test if the prefix is valid, if so only avoid doubles
+    sal_Bool bPrefix = ValidTabName( aStrTable );
+    OSL_ENSURE(bPrefix, "Invalid Table Name");
+    SCTAB nDummy;
+    SCTAB i = static_cast<SCTAB>(pTab.size())+1;
+
+    for (SCTAB j = 0; j < nCount; ++j)
+    {
+        bOk = false;
+        while(!bOk)
+        {
+            rName = aStrTable;
+            rName += String::CreateFromInt32(i);
+            if (bPrefix)
+                bOk = ValidNewTabName( rName );
+            else
+                bOk = !GetTable( rName, nDummy );
+            i++;
+        }
+        aNames.push_back(rtl::OUString(rName));
+    }
+}
+
+
 sal_Bool ScDocument::InsertTab( SCTAB nPos, const String& rName,
             sal_Bool bExternalDocument )
 {
@@ -427,6 +479,90 @@ sal_Bool ScDocument::InsertTab( SCTAB nPos, const String& rName,
 }
 
 
+bool ScDocument::InsertTabs( SCTAB nPos, const std::vector<rtl::OUString>& rNames,
+            bool bExternalDocument, bool bNamesValid )
+{
+    SCTAB   nNewSheets = static_cast<SCTAB>(rNames.size());
+    SCTAB    nTabCount = static_cast<SCTAB>(pTab.size());
+    bool    bValid = bNamesValid || ValidTab(nTabCount+nNewSheets);
+//    if ( !bExternalDocument )    // else test rName == "'Doc'!Tab" first
+//        bValid = (bValid && ValidNewTabName(rNames));
+    if (bValid)
+    {
+        if (nPos == SC_TAB_APPEND || nPos >= nTabCount)
+        {
+            for ( SCTAB i = 0; i < nNewSheets; ++i )
+            {
+                pTab.push_back( new ScTable(this, nTabCount + i, rNames.at(i)) );
+                pTab[nTabCount+i]->SetCodeName( rNames.at(i) );
+                if ( bExternalDocument )
+                    pTab[nTabCount+i]->SetVisible( false );
+            }
+        }
+        else
+        {
+            if (VALIDTAB(nPos) && (nPos < nTabCount))
+            {
+                ScRange aRange( 0,0,nPos, MAXCOL,MAXROW,MAXTAB );
+                xColNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,nNewSheets );
+                xRowNameRanges->UpdateReference( URM_INSDEL, this, aRange, 0,0,nNewSheets );
+                if (pRangeName)
+                    pRangeName->UpdateTabRef( nPos, 1, 0, nNewSheets);
+                pDBCollection->UpdateReference(
+                                    URM_INSDEL, 0,0,nPos, MAXCOL,MAXROW,MAXTAB, 0,0,nNewSheets );
+                if (pDPCollection)
+                    pDPCollection->UpdateReference( URM_INSDEL, aRange, 0,0,nNewSheets );
+                if (pDetOpList)
+                    pDetOpList->UpdateReference( this, URM_INSDEL, aRange, 0,0,nNewSheets );
+                UpdateChartRef( URM_INSDEL, 0,0,nPos, MAXCOL,MAXROW,MAXTAB, 0,0,nNewSheets );
+                UpdateRefAreaLinks( URM_INSDEL, aRange, 0,0, nNewSheets );
+                if ( pUnoBroadcaster )
+                    pUnoBroadcaster->Broadcast( ScUpdateRefHint( URM_INSDEL, aRange, 0,0,nNewSheets ) );
+
+                TableContainer::iterator it = pTab.begin();
+                for (; it != pTab.end(); ++it)
+                    if ( *it )
+                        (*it)->UpdateInsertTab(nPos, nNewSheets);
+                pTab.resize(nTabCount + nNewSheets, NULL);
+                for (SCTAB i = 0; i < nNewSheets; ++i)
+                {
+                    pTab[nPos + i] = new ScTable(this, nPos + i, rNames.at(i));
+                    pTab[nPos + i]->SetCodeName( rNames.at(i) );
+                }
+
+                // UpdateBroadcastAreas must be called between UpdateInsertTab,
+                // which ends listening, and StartAllListeners, to not modify
+                // areas that are to be inserted by starting listeners.
+                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 )
+                        (*it)->StartAllListeners();
+
+                //    update conditional formats after table is inserted
+                if ( pCondFormList )
+                    pCondFormList->UpdateReference( URM_INSDEL, aRange, 0,0,nNewSheets);
+                if ( pValidationList )
+                    pValidationList->UpdateReference( URM_INSDEL, aRange, 0,0,nNewSheets );
+                // sheet names of references are not valid until sheet is inserted
+                if ( pChartListenerCollection )
+                    pChartListenerCollection->UpdateScheduledSeriesRanges();
+
+                SetDirty();
+                bValid = true;
+            }
+            else
+                bValid = false;
+        }
+    }
+    return bValid;
+}
+
+
 sal_Bool ScDocument::DeleteTab( SCTAB nTab, ScDocument* pRefUndoDoc )
 {
     sal_Bool bValid = false;


More information about the Libreoffice-commits mailing list