From c70b1baac5b6b85048c894c206b8024e1eb537f3 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 27 May 2011 05:16:37 +0200 Subject: 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 --- sc/source/ui/view/viewfun2.cxx | 53 +++++++++++++----------------------------- 1 file changed, 16 insertions(+), 37 deletions(-) (limited to 'sc/source/ui/view/viewfun2.cxx') diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 17bf069f274d..c803177f340f 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& 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;iGetObject(static_cast(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;iBroadcast( 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 { -- cgit From ca9b2b5b3bb8c92bd9d901ff23f92e04e2830175 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 27 May 2011 07:01:52 +0200 Subject: 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 --- sc/source/ui/view/viewfun2.cxx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'sc/source/ui/view/viewfun2.cxx') diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index c803177f340f..a5bbae6c4fe4 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& aNames, SCTAB nTab } if (pDoc->InsertTabs(nTab, aNames, false)) { - for (SCTAB i=0;iBroadcast( ScTablesHint( SC_TAB_INSERTED, nTab+i ) ); - } + pDocSh->Broadcast( ScTablesHint( SC_TABS_INSERTED, nTab, nCount ) ); bFlag = true; } -- cgit From ea7fe02f4d149466bb2170b4bf0a45676936112b Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 3 Jun 2011 06:03:40 +0200 Subject: improve performance of ScUndoInsertTables::Undo we can now insert several sheets and then undo in nearly no time --- sc/source/ui/view/viewfun2.cxx | 45 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'sc/source/ui/view/viewfun2.cxx') diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index a5bbae6c4fe4..16402be06c35 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 &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()) -- cgit