diff options
author | Daisuke Nishino <niboshi000@gmail.com> | 2011-11-23 13:12:43 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-11-23 13:56:37 +0000 |
commit | 858b5b4f36a357fe7192e7c2ed9cc3cdfc81fd8f (patch) | |
tree | 963b3823812f1d3cdb1301036f50c8d194edefcb /sw/source/core/table/swnewtable.cxx | |
parent | a9edd1267e42ba4e7814102bcaab6610d14bc3b8 (diff) |
SwSelBoxes: svarray -> std::map
Diffstat (limited to 'sw/source/core/table/swnewtable.cxx')
-rw-r--r-- | sw/source/core/table/swnewtable.cxx | 167 |
1 files changed, 84 insertions, 83 deletions
diff --git a/sw/source/core/table/swnewtable.cxx b/sw/source/core/table/swnewtable.cxx index 24cedcb60fba..d7d8d87b3390 100644 --- a/sw/source/core/table/swnewtable.cxx +++ b/sw/source/core/table/swnewtable.cxx @@ -409,7 +409,7 @@ SwBoxSelection* SwTable::CollectBoxSelection( const SwPaM& rPam ) const { if( nCurrBox ) { - pBoxes->Insert( pBox ); + pBoxes->insert( pBox ); pInnerBox = pBox; pLeftBox = pLine->GetTabBoxes()[nCurrBox-1]; nDiff = nMin - nLeft; @@ -440,7 +440,7 @@ SwBoxSelection* SwTable::CollectBoxSelection( const SwPaM& rPam ) const } else if( nRight <= nMax ) { - pBoxes->Insert( pBox ); + pBoxes->insert( pBox ); if( nRow == nTop && nRowSpan < 0 ) { bOkay = false; @@ -459,7 +459,7 @@ SwBoxSelection* SwTable::CollectBoxSelection( const SwPaM& rPam ) const { if( nCurrBox+1 < nCount ) { - pBoxes->Insert( pBox ); + pBoxes->insert( pBox ); pInnerBox = pBox; pRightBox = pLine->GetTabBoxes()[nCurrBox+1]; nDiff = nRight - nMax; @@ -612,11 +612,11 @@ long lcl_InsertPosition( SwTable &rTable, std::vector<sal_uInt16>& rInsPos, { sal_Int32 nAddWidth = 0; long nCount = 0; - for( sal_uInt16 j = 0; j < rBoxes.Count(); ++j ) + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { - SwTableBox *pBox = rBoxes[j]; + SwTableBox *pBox = it->second; SwTableLine* pLine = pBox->GetUpper(); - long nWidth = rBoxes[j]->GetFrmFmt()->GetFrmSize().GetWidth(); + long nWidth = pBox->GetFrmFmt()->GetFrmSize().GetWidth(); nAddWidth += nWidth; sal_uInt16 nCurrBox = pLine->GetTabBoxes().C40_GETPOS(SwTableBox, pBox ); sal_uInt16 nCurrLine = rTable.GetTabLines().C40_GETPOS(SwTableLine, pLine ); @@ -816,7 +816,7 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, if( !bNewModel ) { ::GetMergeSel( rPam, rBoxes, ppMergeBox, pUndo ); - return rBoxes.Count() > 1; + return rBoxes.size() > 1; } CHECK_TABLE( *this ) // We have to assert a "rectangular" box selection before we start to merge @@ -827,7 +827,7 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, // i.e. contiguous cells in contiguous rows bool bMerge = false; // will be set if any content is transferred from // a "not already overlapped" cell into the new master cell. - SwTableBox *pMergeBox = (*pSel->aBoxes[0])[0]; // the master cell box + SwTableBox *pMergeBox = pSel->aBoxes[0]->begin()->second; // the master cell box if( !pMergeBox ) return false; (*ppMergeBox) = pMergeBox; @@ -854,16 +854,16 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, { // The selected boxes in the current line const SwSelBoxes* pBoxes = pSel->aBoxes[ nCurrLine ]; - sal_uInt16 nColCount = pBoxes->Count(); + SwSelBoxes::const_iterator itTail = pBoxes->end(); --itTail; // Iteration over the selected cell in the current row - for( sal_uInt16 nCurrCol = 0; nCurrCol < nColCount; ++nCurrCol ) + for( SwSelBoxes::const_iterator it = pBoxes->begin(); it != pBoxes->end(); ++it ) { - SwTableBox* pBox = (*pBoxes)[nCurrCol]; - rMerged.Insert( pBox ); + SwTableBox* pBox = it->second; + rMerged.insert( pBox ); // Only the first selected cell in every row will be alive, // the other will be deleted => put into rBoxes - if( nCurrCol ) - rBoxes.Insert( pBox ); + if( it != pBoxes->begin() ) + rBoxes.insert( pBox ); else { if( nCurrLine == 1 ) @@ -876,7 +876,7 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, bool bDoMerge = pBox != pMergeBox && pBox->getRowSpan() > 0; // The last box has to be in the last "column" of the selection // and it has to be a master cell - if( nCurrCol+1 == nColCount && pBox->getRowSpan() > 0 ) + if( it == itTail && pBox->getRowSpan() > 0 ) pLastBox = pBox; if( bDoMerge ) { @@ -914,7 +914,7 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, } // Only the cell of the first selected column will stay alive // and got a new row span - if( !nCurrCol ) + if( it == pBoxes->begin() ) pBox->setRowSpan( nRowSpan ); } if( nRowSpan > 0 ) // the master cell is done, from now on we set @@ -932,11 +932,10 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, for( sal_uInt16 nCurrLine = 0; nCurrLine < nLineCount; ++nCurrLine ) { const SwSelBoxes* pBoxes = pSel->aBoxes[ nCurrLine ]; - sal_uInt16 nColCount = pBoxes->Count(); - for( sal_uInt16 nCurrCol = 0; nCurrCol < nColCount; ++nCurrCol ) + for( SwSelBoxes::const_iterator it = pBoxes->begin(); it != pBoxes->end(); ++it ) { - SwTableBox* pBox = (*pBoxes)[nCurrCol]; - if( nCurrCol ) + SwTableBox* pBox = it->second; + if( it != pBoxes->begin() ) { // Even this box will be deleted soon, // we have to correct the width to avoid side effects @@ -944,7 +943,7 @@ bool SwTable::PrepareMerge( const SwPaM& rPam, SwSelBoxes& rBoxes, pFmt->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE, 0, 0 ) ); } else - pBox->ChgFrmFmt( (SwTableBoxFmt*)pNewFmt ); + pBox->ChgFrmFmt( static_cast<SwTableBoxFmt*>(pNewFmt) ); } } if( pLastBox ) // Robust @@ -974,10 +973,10 @@ void SwTable::_FindSuperfluousRows( SwSelBoxes& rBoxes, { if( !pFirstLn || !pLastLn ) { - if( !rBoxes.Count() ) + if( rBoxes.empty() ) return; - pFirstLn = rBoxes[0]->GetUpper(); - pLastLn = rBoxes[ rBoxes.Count() - 1 ]->GetUpper(); + pFirstLn = rBoxes.begin()->second->GetUpper(); + pLastLn = rBoxes.rbegin()->second->GetUpper(); } sal_uInt16 nFirstLn = GetTabLines().C40_GETPOS(SwTableLine, pFirstLn ); sal_uInt16 nLastLn = GetTabLines().C40_GETPOS(SwTableLine, pLastLn ); @@ -991,7 +990,7 @@ void SwTable::_FindSuperfluousRows( SwSelBoxes& rBoxes, { SwTableBox *pBox = pLine->GetTabBoxes()[nCol]; if( pBox->getRowSpan() > 0 && - USHRT_MAX == rBoxes.GetPos( pBox ) ) + 0 == rBoxes.count( pBox ) ) { bSuperfl = false; break; @@ -1002,7 +1001,7 @@ void SwTable::_FindSuperfluousRows( SwSelBoxes& rBoxes, for( sal_uInt16 nCol = 0; nCol < nCols; ++nCol ) { SwTableBox* pBox = pLine->GetTabBoxes()[nCol]; - rBoxes.Insert( pBox ); + rBoxes.insert( pBox ); } } } @@ -1070,7 +1069,7 @@ void lcl_getAllMergedBoxes( const SwTable& rTable, SwSelBoxes& rBoxes, SwTableBo { SwTableBox* pBox = &rBox; OSL_ENSURE( pBox == &rBox.FindStartOfRowSpan( rTable, USHRT_MAX ), "Not a master box" ); - rBoxes.Insert( pBox ); + rBoxes.insert( pBox ); if( pBox->getRowSpan() == 1 ) return; const SwTableLine* pMyUpper = pBox->GetUpper(); @@ -1081,7 +1080,7 @@ void lcl_getAllMergedBoxes( const SwTable& rTable, SwSelBoxes& rBoxes, SwTableBo { pBox = lcl_LeftBorder2Box( nLeftBorder, rTable.GetTabLines()[nLine] ); if( pBox ) - rBoxes.Insert( pBox ); + rBoxes.insert( pBox ); }; } @@ -1094,7 +1093,7 @@ void lcl_UnMerge( const SwTable& rTable, SwTableBox& rBox, sal_uInt16 nCnt, { SwSelBoxes aBoxes; lcl_getAllMergedBoxes( rTable, aBoxes, rBox ); - sal_uInt16 nCount = aBoxes.Count(); + sal_uInt16 nCount = aBoxes.size(); if( nCount < 2 ) return; if( nCnt > nCount ) @@ -1102,14 +1101,15 @@ void lcl_UnMerge( const SwTable& rTable, SwTableBox& rBox, sal_uInt16 nCnt, sal_uInt16 *pSplitIdx = new sal_uInt16[ nCnt ]; if( bSameHeight ) { - SwTwips *pHeights = new SwTwips[ nCount ]; + std::vector<SwTwips> aHeights; SwTwips nHeight = 0; - for( sal_uInt16 i = 0; i < nCount; ++i ) + for( SwSelBoxes::const_iterator it = aBoxes.begin(); it != aBoxes.end(); ++it ) { - SwTableLine* pLine = aBoxes[ i ]->GetUpper(); + SwTableLine* pLine = it->second->GetUpper(); SwFrmFmt *pRowFmt = pLine->GetFrmFmt(); - pHeights[ i ] = pRowFmt->GetFrmSize().GetHeight(); - nHeight += pHeights[ i ]; + SwTwips nH = pRowFmt->GetFrmSize().GetHeight(); + aHeights.push_back( nH ); + nHeight += nH; } SwTwips nSumH = 0; sal_uInt16 nIdx = 0; @@ -1117,24 +1117,29 @@ void lcl_UnMerge( const SwTable& rTable, SwTableBox& rBox, sal_uInt16 nCnt, { SwTwips nSplit = ( i * nHeight ) / nCnt; while( nSumH < nSplit && nIdx < nCount ) - nSumH += pHeights[ nIdx++ ]; + nSumH += aHeights[ nIdx++ ]; pSplitIdx[ i - 1 ] = nIdx; } - delete[] pHeights; } else { - for( long i = 1; i <= nCnt; ++i ) - pSplitIdx[ i - 1 ] = (sal_uInt16)( ( i * nCount ) / nCnt ); + for( sal_uInt32 i = 1; i <= nCnt; ++i ) + pSplitIdx[ i - 1 ] = static_cast<sal_uInt16>( ( i * nCount ) / nCnt ); } sal_uInt16 nIdx = 0; - for( long i = 0; i < nCnt; ++i ) + SwSelBoxes::const_iterator it = aBoxes.begin(); + for( sal_uInt16 i = 0; i < nCnt; ++i ) { sal_uInt16 nNextIdx = pSplitIdx[ i ]; - aBoxes[ nIdx ]->setRowSpan( nNextIdx - nIdx ); - lcl_InvalidateCellFrm( *aBoxes[ nIdx ] ); - while( ++nIdx < nNextIdx ) - aBoxes[ nIdx ]->setRowSpan( nIdx - nNextIdx ); + it->second->setRowSpan( nNextIdx - nIdx ); + lcl_InvalidateCellFrm( *it->second ); + while( true ) { + ++nIdx; + ++it; + if( nIdx >= nNextIdx ) + break; + it->second->setRowSpan( nIdx - nNextIdx ); + } } delete[] pSplitIdx; } @@ -1147,7 +1152,7 @@ void lcl_FillSelBoxes( SwSelBoxes &rBoxes, SwTableLine &rLine ) sal_uInt16 nBoxCount = rLine.GetTabBoxes().Count(); sal_uInt16 nCurrBox; for( nCurrBox = 0; nCurrBox < nBoxCount; ++nCurrBox ) - rBoxes.Insert( rLine.GetTabBoxes()[nCurrBox] ); + rBoxes.insert( rLine.GetTabBoxes()[nCurrBox] ); } /** SwTable::InsertSpannedRow(..) inserts "superfluous" rows, i.e. rows containig @@ -1209,9 +1214,9 @@ void lcl_SophisticatedFillLineIndices( SwLineOffsetArray &rArr, { std::list< SwLineOffset > aBoxes; SwLineOffset aLnOfs( USHRT_MAX, USHRT_MAX ); - for( sal_uInt16 i = 0; i < rBoxes.Count(); ++i ) + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { // Collect all end line indices and the row spans - const SwTableBox &rBox = rBoxes[ i ]->FindStartOfRowSpan( rTable ); + const SwTableBox &rBox = it->second->FindStartOfRowSpan( rTable ); OSL_ENSURE( rBox.getRowSpan() > 0, "Didn't I say 'StartOfRowSpan' ??" ); if( nCnt > rBox.getRowSpan() ) { @@ -1308,9 +1313,9 @@ sal_uInt16 lcl_CalculateSplitLineHeights( SwSplitLines &rCurr, SwSplitLines &rNe SwLineOffset aLnOfs( USHRT_MAX, USHRT_MAX ); sal_uInt16 nFirst = USHRT_MAX; // becomes the index of the first line sal_uInt16 nLast = 0; // becomes the index of the last line of the splitting - for( sal_uInt16 i = 0; i < rBoxes.Count(); ++i ) + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { // Collect all pairs (start+end) of line indices to split - const SwTableBox &rBox = rBoxes[ i ]->FindStartOfRowSpan( rTable ); + const SwTableBox &rBox = it->second->FindStartOfRowSpan( rTable ); OSL_ENSURE( rBox.getRowSpan() > 0, "Didn't I say 'StartOfRowSpan' ??" ); const SwTableLine *pLine = rBox.GetUpper(); const sal_uInt16 nStart = rTable.GetTabLines().C40_GETPOS( SwTableLine, pLine ); @@ -1365,10 +1370,10 @@ sal_uInt16 lcl_LineIndex( const SwTable& rTable, const SwSelBoxes& rBoxes, { sal_uInt16 nDirect = USHRT_MAX; sal_uInt16 nSpan = USHRT_MAX; - for( sal_uInt16 i = 0; i < rBoxes.Count(); ++i ) + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { - SwTableBox *pBox = rBoxes[i]; - const SwTableLine* pLine = rBoxes[i]->GetUpper(); + const SwTableBox* pBox = it->second; + const SwTableLine* pLine = pBox->GetUpper(); sal_uInt16 nPos = rTable.GetTabLines().C40_GETPOS( SwTableLine, pLine ); if( USHRT_MAX != nPos ) { @@ -1461,17 +1466,18 @@ sal_Bool SwTable::NewSplitRow( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 } } - std::set< sal_uInt16> aIndices; - for( sal_uInt16 i = 0; i < rBoxes.Count(); ++i ) + std::vector<SwTableBox*> aBoxes; + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { - OSL_ENSURE( rBoxes[i]->getRowSpan() != 1, "Forgot to split?" ); - if( rBoxes[i]->getRowSpan() > 1 ) - aIndices.insert( i ); + OSL_ENSURE( it->second->getRowSpan() != 1, "Forgot to split?" ); + if( it->second->getRowSpan() > 1 ) + aBoxes.push_back( it->second ); } - std::set< sal_uInt16 >::iterator pCurrBox = aIndices.begin(); - while( pCurrBox != aIndices.end() ) - lcl_UnMerge( *this, *rBoxes[*pCurrBox++], nCnt, bSameHeight ); + for( std::vector<SwTableBox*>::const_iterator it = aBoxes.begin(); it != aBoxes.end(); ++it ) + { + lcl_UnMerge( *this, **it, nCnt, bSameHeight ); + } CHECK_TABLE( *this ) //Layout updaten @@ -1550,9 +1556,9 @@ void SwTable::PrepareDelBoxes( const SwSelBoxes& rBoxes ) { if( IsNewModel() ) { - for( sal_uInt16 i = 0; i < rBoxes.Count(); ++i ) + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { - SwTableBox* pBox = rBoxes[i]; + SwTableBox* pBox = it->second; long nRowSpan = pBox->getRowSpan(); if( nRowSpan != 1 && pBox->GetFrmFmt()->GetFrmSize().GetWidth() ) { @@ -1630,9 +1636,9 @@ void lcl_SearchSelBox( const SwTable &rTable, SwSelBoxes& rBoxes, long nMin, lon ( !bChkProtected || !pBox->GetFrmFmt()->GetProtect().IsCntntProtected() ) ) { - sal_uInt16 nOldCnt = rBoxes.Count(); - rBoxes.Insert( pBox ); - if( bColumn && nRowSpan != 1 && nOldCnt < rBoxes.Count() ) + sal_uInt16 nOldCnt = rBoxes.size(); + rBoxes.insert( pBox ); + if( bColumn && nRowSpan != 1 && nOldCnt < rBoxes.size() ) { SwTableBox *pMasterBox = pBox->getRowSpan() > 0 ? pBox : &pBox->FindStartOfRowSpan( rTable, USHRT_MAX ); @@ -1669,12 +1675,8 @@ void SwTable::CreateSelection( const SwPaM& rPam, SwSelBoxes& rBoxes, void SwTable::CreateSelection( const SwNode* pStartNd, const SwNode* pEndNd, SwSelBoxes& rBoxes, const SearchType eSearch, bool bChkProtected ) const { - // SwSelBoxes aKeepBoxes; - if( rBoxes.Count() ) - { - // aKeepBoxes.Insert( &rBoxes ); - rBoxes.Remove( sal_uInt16(0), rBoxes.Count() ); - } + rBoxes.clear(); + // Looking for start and end of the selection given by SwNode-pointer sal_uInt16 nLines = aLines.Count(); // nTop becomes the line number of the upper box @@ -1701,7 +1703,7 @@ void SwTable::CreateSelection( const SwNode* pStartNd, const SwNode* pEndNd, { if( !bChkProtected || !pBox->GetFrmFmt()->GetProtect().IsCntntProtected() ) - rBoxes.Insert( pBox ); + rBoxes.insert( pBox ); if( nFound ) { nBottom = nRow; @@ -1744,7 +1746,7 @@ void SwTable::CreateSelection( const SwNode* pStartNd, const SwNode* pEndNd, OSL_ENSURE( pBox, "Missing table box" ); if( pBox->getRowSpan() > 0 && ( !bChkProtected || !pBox->GetFrmFmt()->GetProtect().IsCntntProtected() ) ) - rBoxes.Insert( pBox ); + rBoxes.insert( pBox ); } } return; @@ -1806,13 +1808,12 @@ void SwTable::ExpandColumnSelection( SwSelBoxes& rBoxes, long &rMin, long &rMax OSL_ENSURE( bNewModel, "Don't call me for old tables" ); rMin = 0; rMax = 0; - if( !aLines.Count() || !rBoxes.Count() ) + if( !aLines.Count() || rBoxes.empty() ) return; sal_uInt16 nLineCnt = aLines.Count(); - sal_uInt16 nBoxCnt = rBoxes.Count(); - sal_uInt16 nBox = 0; - for( sal_uInt16 nRow = 0; nRow < nLineCnt && nBox < nBoxCnt; ++nRow ) + SwSelBoxes::iterator it = rBoxes.begin(); + for( sal_uInt16 nRow = 0; nRow < nLineCnt && it != rBoxes.end(); ++nRow ) { SwTableLine* pLine = aLines[nRow]; OSL_ENSURE( pLine, "Missing table line" ); @@ -1821,15 +1822,15 @@ void SwTable::ExpandColumnSelection( SwSelBoxes& rBoxes, long &rMin, long &rMax { SwTableBox* pBox = pLine->GetTabBoxes()[nCol]; OSL_ENSURE( pBox, "Missing table box" ); - if( pBox == rBoxes[nBox] ) + if( pBox == it->second ) { - lcl_CheckMinMax( rMin, rMax, *pLine, nCol, nBox == 0 ); - if( ++nBox >= nBoxCnt ) + lcl_CheckMinMax( rMin, rMax, *pLine, nCol, it == rBoxes.begin() ); + if( ++it == rBoxes.end() ) break; } } } - nBox = 0; + for( sal_uInt16 nRow = 0; nRow < nLineCnt; ++nRow ) { SwTableLine* pLine = aLines[nRow]; @@ -1842,7 +1843,7 @@ void SwTable::ExpandColumnSelection( SwSelBoxes& rBoxes, long &rMin, long &rMax SwTableBox* pBox = pLine->GetTabBoxes()[nCurrBox]; nRight += pBox->GetFrmFmt()->GetFrmSize().GetWidth(); if( nLeft >= rMin && nRight <= rMax ) - rBoxes.Insert( pBox ); + rBoxes.insert( pBox ); } } } @@ -1904,9 +1905,9 @@ void SwTable::PrepareDeleteCol( long nMin, long nMax ) void SwTable::ExpandSelection( SwSelBoxes& rBoxes ) const { - for( sal_uInt16 i = 0; i < rBoxes.Count(); ++i ) + for( SwSelBoxes::const_iterator it = rBoxes.begin(); it != rBoxes.end(); ++it ) { - SwTableBox *pBox = rBoxes[i]; + SwTableBox *pBox = it->second; long nRowSpan = pBox->getRowSpan(); if( nRowSpan != 1 ) { |