diff options
Diffstat (limited to 'sc/source/ui/view/viewdata.cxx')
-rw-r--r-- | sc/source/ui/view/viewdata.cxx | 139 |
1 files changed, 82 insertions, 57 deletions
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index c82bd6e8ccc2..019cf107735e 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -296,7 +296,8 @@ void ScViewDataTable::ReadUserDataSequence(const uno::Sequence <beans::PropertyV } ScViewData::ScViewData( ScDocShell* pDocSh, ScTabViewShell* pViewSh ) - : pDocShell ( pDocSh ), + : pTabData(), + pDocShell ( pDocSh ), pDoc ( NULL ), pView ( pViewSh ), pViewShell ( pViewSh ), @@ -331,9 +332,7 @@ ScViewData::ScViewData( ScDocShell* pDocSh, ScTabViewShell* pViewSh ) aScrSize = Size( (long) ( STD_COL_WIDTH * PIXEL_PER_TWIPS * OLE_STD_CELLS_X ), (long) ( ScGlobal::nStdRowHeight * PIXEL_PER_TWIPS * OLE_STD_CELLS_Y ) ); - pTabData[0] = new ScViewDataTable; - for ( SCTAB i = 1; i <= MAXTAB; i++ ) - pTabData[i] = NULL; + pTabData.push_back( new ScViewDataTable() ); pThisTab = pTabData[nTabNo]; for (sal_uInt16 j=0; j<4; j++) { @@ -355,9 +354,11 @@ ScViewData::ScViewData( ScDocShell* pDocSh, ScTabViewShell* pViewSh ) if (pDoc && !pDoc->IsVisible(nTabNo)) { while ( !pDoc->IsVisible(nTabNo) && pDoc->HasTable(nTabNo+1) ) + { ++nTabNo; - - pTabData[nTabNo] = new ScViewDataTable; + pTabData.push_back(NULL); + } + pTabData[nTabNo] = new ScViewDataTable() ; pThisTab = pTabData[nTabNo]; } @@ -365,7 +366,8 @@ ScViewData::ScViewData( ScDocShell* pDocSh, ScTabViewShell* pViewSh ) } ScViewData::ScViewData( const ScViewData& rViewData ) - : pDocShell ( rViewData.pDocShell ), + : pTabData( rViewData.pTabData ), + pDocShell ( rViewData.pDocShell ), pDoc ( rViewData.pDoc ), pView ( rViewData.pView ), pViewShell ( rViewData.pViewShell ), @@ -398,11 +400,7 @@ ScViewData::ScViewData( const ScViewData& rViewData ) SetOutlineMode ( rViewData.IsOutlineMode() ); aScrSize = rViewData.aScrSize; - for ( SCTAB i = 0; i <= MAXTAB; i++ ) - if (rViewData.pTabData[i]) - pTabData[i] = new ScViewDataTable( *rViewData.pTabData[i] ); - else - pTabData[i] = NULL; + pThisTab = pTabData[nTabNo]; for (sal_uInt16 j=0; j<4; j++) { @@ -436,10 +434,6 @@ ScDocument* ScViewData::GetDocument() const ScViewData::~ScViewData() { - for (SCTAB i=0; i<=MAXTAB; i++) - if (pTabData[i]) - delete pTabData[i]; - KillEditView(); delete pOptions; } @@ -454,7 +448,9 @@ void ScViewData::UpdateThis() if (nTabNo>0) --nTabNo; else - pThisTab = pTabData[0] = new ScViewDataTable; + { + pThisTab = pTabData[0] = new ScViewDataTable(); + } // hier keine Assertion, weil sonst Paints kommen, bevor alles initialisiert ist! } @@ -464,29 +460,52 @@ void ScViewData::UpdateThis() void ScViewData::InsertTab( SCTAB nTab ) { - delete pTabData[MAXTAB]; - - for (SCTAB i=MAXTAB; i>nTab; i--) - pTabData[i] = pTabData[i-1]; - - pTabData[nTab] = NULL; // force creating new + 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]; - for (SCTAB i=nTab; i<MAXTAB; i++) - pTabData[i] = pTabData[i+1]; + pTabData.erase(pTabData.begin() + nTab); + UpdateThis(); + aMarkData.DeleteTab( nTab ); +} - pTabData[MAXTAB] = NULL; +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(); - aMarkData.DeleteTab( nTab ); + } void ScViewData::CopyTab( SCTAB nSrcTab, SCTAB nDestTab ) @@ -500,15 +519,15 @@ void ScViewData::CopyTab( SCTAB nSrcTab, SCTAB nDestTab ) return; } - delete pTabData[MAXTAB]; - - for (SCTAB i=MAXTAB; i>nDestTab; i--) - pTabData[i] = pTabData[i-1]; + if (nSrcTab >= static_cast<SCTAB>(pTabData.size())) + OSL_FAIL("pTabData out of bounds, FIX IT"); + while( nDestTab >= static_cast<SCTAB>(pTabData.size())) + pTabData.push_back(NULL); if ( pTabData[nSrcTab] ) - pTabData[nDestTab] = new ScViewDataTable( *pTabData[nSrcTab] ); + pTabData.insert(pTabData.begin() + nDestTab, new ScViewDataTable( *pTabData[nSrcTab] )); else - pTabData[nDestTab] = NULL; + pTabData.insert(pTabData.begin() + nDestTab, NULL); UpdateThis(); aMarkData.InsertTab( nDestTab ); @@ -518,26 +537,27 @@ void ScViewData::MoveTab( SCTAB nSrcTab, SCTAB nDestTab ) { if (nDestTab==SC_TAB_APPEND) nDestTab = pDoc->GetTableCount() - 1; - - SCTAB i; - ScViewDataTable* pTab = pTabData[nSrcTab]; - - SCTAB nInsTab = nDestTab; - if ( nSrcTab < nDestTab ) + ScViewDataTable* pTab; + if (nSrcTab < static_cast<SCTAB>(pTabData.size())) { - --nInsTab; - for (i=nSrcTab; i<nDestTab; i++) - pTabData[i] = pTabData[i+1]; + pTab = pTabData[nSrcTab]; + pTabData.erase( pTabData.begin() + nSrcTab ); } else - for (i=nSrcTab; i>nDestTab; i--) - pTabData[i] = pTabData[i-1]; + pTab = NULL; - pTabData[nDestTab] = pTab; + if (nDestTab < static_cast<SCTAB>(pTabData.size())) + pTabData.insert( pTabData.begin() + nDestTab, pTab ); + else + { + while (nDestTab > static_cast<SCTAB>(pTabData.size())) + pTabData.push_back(NULL); + pTabData.push_back(pTab); + } UpdateThis(); aMarkData.DeleteTab( nSrcTab ); - aMarkData.InsertTab( nInsTab ); // ggf. angepasst + aMarkData.InsertTab( nDestTab ); // ggf. angepasst } void ScViewData::CreateTabData( std::vector< SCTAB >& rvTabs ) @@ -557,7 +577,7 @@ void ScViewData::SetZoomType( SvxZoomType eNew, std::vector< SCTAB >& tabs ) if ( bAll ) { - for ( SCTAB i = 0; i <= MAXTAB; ++i ) + for ( SCTAB i = 0; i < static_cast<SCTAB>(pTabData.size()); ++i ) { if ( pTabData[i] ) pTabData[i]->eZoomType = eNew; @@ -571,7 +591,7 @@ void ScViewData::SetZoomType( SvxZoomType eNew, std::vector< SCTAB >& tabs ) for ( ; it != it_end; ++it ) { SCTAB i = *it; - if ( pTabData[i] ) + if ( *it < static_cast<SCTAB>(pTabData.size()) && pTabData[i] ) pTabData[i]->eZoomType = eNew; } } @@ -614,7 +634,7 @@ void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, std::vec if ( bAll ) { - for ( SCTAB i = 0; i <= MAXTAB; ++i ) + for ( SCTAB i = 0; i < static_cast<SCTAB>(pTabData.size()); ++i ) { if ( pTabData[i] ) { @@ -648,7 +668,7 @@ void ScViewData::SetZoom( const Fraction& rNewX, const Fraction& rNewY, std::vec for ( ; it != it_end; ++it ) { SCTAB i = *it; - if ( pTabData[i] ) + if ( i < static_cast<SCTAB>(pTabData.size()) && pTabData[i] ) { if ( bPagebreak ) { @@ -1409,6 +1429,8 @@ void ScViewData::GetEditView( ScSplitPos eWhich, EditView*& rViewPtr, SCCOL& rCo void ScViewData::CreateTabData( SCTAB nNewTab ) { + while(nNewTab >= static_cast<SCTAB>(pTabData.size())) + pTabData.push_back(NULL); if (!pTabData[nNewTab]) { pTabData[nNewTab] = new ScViewDataTable; @@ -1423,7 +1445,7 @@ void ScViewData::CreateTabData( SCTAB nNewTab ) void ScViewData::CreateSelectedTabData() { - SCTAB nTabCount = pDoc->GetTableCount(); + SCTAB nTabCount = aMarkData.GetLastSelected(); for (SCTAB i=0; i<nTabCount; i++) if ( aMarkData.GetTableSelect(i) && !pTabData[i] ) CreateTabData( i ); @@ -2181,7 +2203,7 @@ void ScViewData::WriteUserData(String& rData) for (SCTAB i=0; i<nTabCount; i++) { rData += ';'; // Numerierung darf auf keinen Fall durcheinanderkommen - if (pTabData[i]) + if (i < static_cast<SCTAB>(pTabData.size()) && pTabData[i]) { sal_Unicode cTabSep = SC_OLD_TABSEP; // wie 3.1 if ( pTabData[i]->nCurY > MAXROW_30 || @@ -2280,6 +2302,10 @@ void ScViewData::ReadUserData(const String& rData) while ( nCount > nPos+nTabStart ) { aTabOpt = rData.GetToken(static_cast<xub_StrLen>(nPos+nTabStart)); + while(nPos >= static_cast<SCTAB>(pTabData.size())) + { + pTabData.push_back(NULL); + } if (!pTabData[nPos]) pTabData[nPos] = new ScViewDataTable; @@ -2356,7 +2382,7 @@ void ScViewData::WriteExtOptions( ScExtDocOptions& rDocOpt ) const rDocSett.mfTabBarWidth = pView->GetRelTabBarWidth(); // sheet settings - for( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab ) + for( SCTAB nTab = 0; nTab < static_cast<SCTAB>(pTabData.size()); ++nTab ) { if( const ScViewDataTable* pViewTab = pTabData[ nTab ] ) { @@ -2458,7 +2484,7 @@ void ScViewData::ReadExtOptions( const ScExtDocOptions& rDocOpt ) pView->SetPendingRelTabBarWidth( rDocSett.mfTabBarWidth ); // sheet settings - for( SCTAB nTab = 0, nTabCount = pDoc->GetTableCount(); nTab < nTabCount; ++nTab ) + for( SCTAB nTab = 0; nTab < static_cast<SCTAB>(pTabData.size()); ++nTab ) { if( const ScExtTabSettings* pTabSett = rDocOpt.GetTabSettings( nTab ) ) { @@ -2605,7 +2631,6 @@ void ScViewData::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>& rSe 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(); OSL_ENSURE( xServiceFactory.is(), "got no service manager" ); @@ -2615,7 +2640,7 @@ void ScViewData::WriteUserDataSequence(uno::Sequence <beans::PropertyValue>& rSe uno::Reference<container::XNameContainer> xNameContainer = uno::Reference<container::XNameContainer>(xServiceFactory->createInstance(sName), uno::UNO_QUERY); if (xNameContainer.is()) { - for (SCTAB nTab=0; nTab<nTabCount; nTab++) + for (SCTAB nTab=0; nTab<static_cast<SCTAB>(pTabData.size()); nTab++) { if (pTabData[nTab]) { @@ -2855,7 +2880,7 @@ void ScViewData::ReadUserDataSequence(const uno::Sequence <beans::PropertyValue> } // copy default zoom to sheets where a different one wasn't specified - for (SCTAB nZoomTab=0; nZoomTab<=MAXTAB; ++nZoomTab) + for (SCTAB nZoomTab=0; nZoomTab< static_cast<SCTAB>(pTabData.size()); ++nZoomTab) if (pTabData[nZoomTab] && ( nZoomTab >= static_cast<SCTAB>(aHasZoomVect.size()) || !aHasZoomVect[nZoomTab] )) { pTabData[nZoomTab]->eZoomType = eDefZoomType; |