diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-06-03 06:03:40 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2011-06-03 06:03:40 +0200 |
commit | ea7fe02f4d149466bb2170b4bf0a45676936112b (patch) | |
tree | 4487bf54ce2f85345bce570cf6e21a9b8a9d570f /sc/source/ui | |
parent | d4a8a64c218a4640e9701356aa87701d5a80589b (diff) |
improve performance of ScUndoInsertTables::Undo
we can now insert several sheets and then undo in nearly no time
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/inc/uiitems.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/inc/viewdata.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/inc/viewfunc.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/undo/undotab.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwsh5.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/view/viewdata.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 45 |
7 files changed, 68 insertions, 8 deletions
diff --git a/sc/source/ui/inc/uiitems.hxx b/sc/source/ui/inc/uiitems.hxx index f65c5a0f9542..7f71a152684e 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 f09069d040c8..d0160ba2708e 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 a0914aa49899..bfec3eee672d 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 95b524b47a1c..5d61267fd3e8 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 4b47f9610108..1bc112d13e78 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 17d7acde30c3..551dffbb2b67 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 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<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()) |