[Libreoffice-commits] core.git: 15 commits - sw/inc sw/source
Matteo Casalin
matteo.casalin at yahoo.com
Sun Apr 5 02:32:23 PDT 2015
sw/inc/docary.hxx | 6 -
sw/inc/section.hxx | 2
sw/source/core/doc/docredln.cxx | 140 ++++++++++-------------
sw/source/core/doc/doctxm.cxx | 139 +++++++++++------------
sw/source/core/doc/tblcpy.cxx | 110 ++++++++----------
sw/source/core/doc/tblrwcl.cxx | 221 +++++++++++++++++--------------------
sw/source/core/docnode/section.cxx | 3
sw/source/ui/dialog/uiregionsw.cxx | 31 ++---
8 files changed, 304 insertions(+), 348 deletions(-)
New commits:
commit 91c7343da2400ea1ebf4fef3c309e8e7b8558b77
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Wed Mar 25 22:08:38 2015 +0100
Use more proper integer types and range-for loops, reduce scope
Change-Id: Ibcf9d404b2f189fb486c5a26c2b8cfe198860b73
diff --git a/sw/source/core/doc/tblrwcl.cxx b/sw/source/core/doc/tblrwcl.cxx
index 1cee55f..2fed3d8 100644
--- a/sw/source/core/doc/tblrwcl.cxx
+++ b/sw/source/core/doc/tblrwcl.cxx
@@ -326,7 +326,7 @@ static void lcl_CopyCol( _FndBox & rFndBox, _CpyPara *const pCpyPara)
// The first Line should be enough
_FndBoxes const& rFndBoxes = pCmpLine->GetBoxes();
long nSz = 0;
- for( sal_uInt16 n = rFndBoxes.size(); n; )
+ for( auto n = rFndBoxes.size(); n; )
{
nSz += rFndBoxes[--n].GetBox()->
GetFrmFmt()->GetFrmSize().GetWidth();
@@ -459,8 +459,8 @@ static void lcl_InsCol( _FndLine* pFndLn, _CpyPara& rCpyPara, sal_uInt16 nCpyCnt
!( pFBox = &pFndLn->GetBoxes()[0] )->GetBox()->GetSttNd() )
{
// A Box with multiple Lines, so insert into these Lines
- for( sal_uInt16 n = 0; n < pFBox->GetLines().size(); ++n )
- lcl_InsCol( &pFBox->GetLines()[ n ], rCpyPara, nCpyCnt, bBehind );
+ for( auto &rLine : pFBox->GetLines() )
+ lcl_InsCol( &rLine, rCpyPara, nCpyCnt, bBehind );
}
else
{
@@ -528,8 +528,8 @@ bool SwTable::InsertCol( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 nCnt,
_CpyTabFrms aTabFrmArr;
_CpyPara aCpyPara( pTblNd, nCnt, aTabFrmArr );
- for( sal_uInt16 n = 0; n < aFndBox.GetLines().size(); ++n )
- lcl_InsCol( &aFndBox.GetLines()[ n ], aCpyPara, nCnt, bBehind );
+ for( auto &rLine : aFndBox.GetLines() )
+ lcl_InsCol( &rLine, aCpyPara, nCnt, bBehind );
// clean up this Line's structure once again, generally all of them
GCLines();
@@ -656,9 +656,8 @@ static void lcl_LastBoxSetWidth( SwTableBoxes &rBoxes, const long nOffset,
static void lcl_LastBoxSetWidthLine( SwTableLines &rLines, const long nOffset,
bool bFirst, SwShareBoxFmts& rShareFmts )
{
- for ( sal_uInt16 i = 0; i < rLines.size(); ++i )
- ::lcl_LastBoxSetWidth( rLines[i]->GetTabBoxes(), nOffset, bFirst,
- rShareFmts );
+ for ( auto pLine : rLines )
+ ::lcl_LastBoxSetWidth( pLine->GetTabBoxes(), nOffset, bFirst, rShareFmts );
}
static void lcl_LastBoxSetWidth( SwTableBoxes &rBoxes, const long nOffset,
@@ -852,14 +851,17 @@ lcl_FndNxtPrvDelBox( const SwTableLines& rTblLns,
SwTableLine* pLine = rTblLns[ nLinePos ];
SwTwips nFndBoxWidth = 0;
SwTwips nFndWidth = nBoxStt + nBoxWidth;
- sal_uInt16 nBoxCnt = pLine->GetTabBoxes().size();
pFndBox = pLine->GetTabBoxes()[ 0 ];
- for( sal_uInt16 n = 0; 0 < nFndWidth && n < nBoxCnt; ++n )
+ for( auto pBox : pLine->GetTabBoxes() )
{
- pFndBox = pLine->GetTabBoxes()[ n ];
- nFndWidth -= (nFndBoxWidth = pFndBox->GetFrmFmt()->
- GetFrmSize().GetWidth());
+ if ( nFndWidth <= 0 )
+ {
+ break;
+ }
+ pFndBox = pBox;
+ nFndBoxWidth = pFndBox->GetFrmFmt()->GetFrmSize().GetWidth();
+ nFndWidth -= nFndBoxWidth;
}
// Find the first ContentBox
@@ -1207,7 +1209,6 @@ bool SwTable::SplitCol( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 nCnt )
_CpyTabFrms aFrmArr;
std::vector<SwTableBoxFmt*> aLastBoxArr;
- sal_uInt16 nFndPos;
for (size_t n = 0; n < aSelBoxes.size(); ++n)
{
SwTableBox* pSelBox = aSelBoxes[n];
@@ -1225,7 +1226,7 @@ bool SwTable::SplitCol( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 nCnt )
SwTableBoxFmt* pLastBoxFmt;
_CpyTabFrm aFindFrm( static_cast<SwTableBoxFmt*>(pSelBox->GetFrmFmt()) );
_CpyTabFrms::const_iterator itFind = aFrmArr.lower_bound( aFindFrm );
- nFndPos = itFind - aFrmArr.begin();
+ const size_t nFndPos = itFind - aFrmArr.begin();
if( itFind == aFrmArr.end() || !(*itFind == aFindFrm) )
{
// Change the FrmFmt
@@ -1273,7 +1274,7 @@ bool SwTable::SplitCol( SwDoc* pDoc, const SwSelBoxes& rBoxes, sal_uInt16 nCnt )
aFindFrm.pNewFrmFmt->SetFmtAttr( aTmp );
// Remove the Format from the "cache"
- for( sal_uInt16 i = aFrmArr.size(); i; )
+ for( auto i = aFrmArr.size(); i; )
{
const _CpyTabFrm& rCTF = aFrmArr[ --i ];
if( rCTF.pNewFrmFmt == aFindFrm.pNewFrmFmt ||
@@ -1346,8 +1347,8 @@ static void lcl_CalcWidth( SwTableBox* pBox )
OSL_ENSURE( pLine, "Box is not within a Line" );
long nWidth = 0;
- for( sal_uInt16 n = 0; n < pLine->GetTabBoxes().size(); ++n )
- nWidth += pLine->GetTabBoxes()[n]->GetFrmFmt()->GetFrmSize().GetWidth();
+ for( auto pTabBox : pLine->GetTabBoxes() )
+ nWidth += pTabBox->GetFrmFmt()->GetFrmSize().GetWidth();
pFmt->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE, nWidth, 0 ));
@@ -1618,7 +1619,7 @@ bool SwTable::OldMerge( SwDoc* pDoc, const SwSelBoxes& rBoxes,
lcl_Merge_MoveBox(*it, &aPara);
}
aPara.SetLower( pInsLine );
- sal_uInt16 nEnd = pFndBox->GetLines().size()-1;
+ const auto nEnd = pFndBox->GetLines().size()-1;
rLineBoxes = pFndBox->GetLines()[nEnd].GetBoxes();
for (_FndBoxes::iterator it = rLineBoxes.begin(); it != rLineBoxes.end(); ++it)
{
@@ -1670,15 +1671,14 @@ bool SwTable::OldMerge( SwDoc* pDoc, const SwSelBoxes& rBoxes,
static void lcl_CheckRowSpan( SwTable &rTbl )
{
- sal_uInt16 nLineCount = rTbl.GetTabLines().size();
- sal_uInt16 nMaxSpan = nLineCount;
+ const long nLineCount = static_cast<long>(rTbl.GetTabLines().size());
+ long nMaxSpan = nLineCount;
long nMinSpan = 1;
while( nMaxSpan )
{
SwTableLine* pLine = rTbl.GetTabLines()[ nLineCount - nMaxSpan ];
- for( sal_uInt16 nBox = 0; nBox < pLine->GetTabBoxes().size(); ++nBox )
+ for( auto pBox : pLine->GetTabBoxes() )
{
- SwTableBox* pBox = pLine->GetTabBoxes()[nBox];
long nRowSpan = pBox->getRowSpan();
if( nRowSpan > nMaxSpan )
pBox->setRowSpan( nMaxSpan );
@@ -1702,9 +1702,12 @@ static sal_uInt16 lcl_GetBoxOffset( const _FndBox& rBox )
const SwTableBox* pBox = pFirstBox->GetBox();
do {
const SwTableBoxes& rBoxes = pBox->GetUpper()->GetTabBoxes();
- const SwTableBox* pCmp;
- for( sal_uInt16 n = 0; pBox != ( pCmp = rBoxes[ n ] ); ++n )
+ for( auto pCmp : rBoxes )
+ {
+ if (pBox==pCmp)
+ break;
nRet = nRet + (sal_uInt16) pCmp->GetFrmFmt()->GetFrmSize().GetWidth();
+ }
pBox = pBox->GetUpper()->GetUpper();
} while( pBox );
return nRet;
@@ -1713,7 +1716,7 @@ static sal_uInt16 lcl_GetBoxOffset( const _FndBox& rBox )
static sal_uInt16 lcl_GetLineWidth( const _FndLine& rLine )
{
sal_uInt16 nRet = 0;
- for( sal_uInt16 n = rLine.GetBoxes().size(); n; )
+ for( auto n = rLine.GetBoxes().size(); n; )
{
nRet = nRet + static_cast<sal_uInt16>(rLine.GetBoxes()[--n].GetBox()
->GetFrmFmt()->GetFrmSize().GetWidth());
@@ -1724,14 +1727,14 @@ static sal_uInt16 lcl_GetLineWidth( const _FndLine& rLine )
static void lcl_CalcNewWidths( const _FndLines& rFndLines, _CpyPara& rPara )
{
rPara.pWidths.reset();
- sal_uInt16 nLineCount = rFndLines.size();
+ const size_t nLineCount = rFndLines.size();
if( nLineCount )
{
rPara.pWidths = boost::shared_ptr< std::vector< std::vector< sal_uLong > > >
( new std::vector< std::vector< sal_uLong > >( nLineCount ));
// First we collect information about the left/right borders of all
// selected cells
- for( sal_uInt16 nLine = 0; nLine < nLineCount; ++nLine )
+ for( size_t nLine = 0; nLine < nLineCount; ++nLine )
{
std::vector< sal_uLong > &rWidth = (*rPara.pWidths.get())[ nLine ];
const _FndLine *pFndLine = &rFndLines[ nLine ];
@@ -1740,12 +1743,12 @@ static void lcl_CalcNewWidths( const _FndLines& rFndLines, _CpyPara& rPara )
const SwTableLine *pLine = pFndLine->GetLine();
if( pLine && !pLine->GetTabBoxes().empty() )
{
- sal_uInt16 nBoxCount = pLine->GetTabBoxes().size();
+ size_t nBoxCount = pLine->GetTabBoxes().size();
sal_uLong nPos = 0;
// The first selected box...
const SwTableBox *const pSel =
pFndLine->GetBoxes().front().GetBox();
- sal_uInt16 nBox = 0;
+ size_t nBox = 0;
// Sum up the width of all boxes before the first selected box
while( nBox < nBoxCount )
{
@@ -1782,15 +1785,15 @@ static void lcl_CalcNewWidths( const _FndLines& rFndLines, _CpyPara& rPara )
sal_uLong nSelSize = rPara.nMaxRight - rPara.nMinLeft;
if( nSelSize )
{
- for( sal_uInt16 nLine = 0; nLine < nLineCount; ++nLine )
+ for( size_t nLine = 0; nLine < nLineCount; ++nLine )
{
std::vector< sal_uLong > &rWidth = (*rPara.pWidths.get())[ nLine ];
- sal_uInt16 nCount = (sal_uInt16)rWidth.size();
+ const size_t nCount = rWidth.size();
if( nCount > 2 )
{
rWidth[ nCount - 1 ] = rPara.nMaxRight;
sal_uLong nLastPos = 0;
- for( sal_uInt16 nBox = 0; nBox < nCount; ++nBox )
+ for( size_t nBox = 0; nBox < nCount; ++nBox )
{
sal_uInt64 nNextPos = rWidth[ nBox ];
nNextPos -= rPara.nMinLeft;
@@ -1846,7 +1849,7 @@ static void lcl_CopyBoxToDoc(_FndBox const& rFndBox, _CpyPara *const pCpyPara)
SwFmtFrmSize aFrmSz;
_CpyTabFrms::const_iterator itFind = pCpyPara->rTabFrmArr.lower_bound( aFindFrm );
- sal_uInt16 nFndPos = itFind - pCpyPara->rTabFrmArr.begin();
+ const _CpyTabFrms::size_type nFndPos = itFind - pCpyPara->rTabFrmArr.begin();
if( itFind == pCpyPara->rTabFrmArr.end() || !(*itFind == aFindFrm) ||
( aFrmSz = ( aFindFrm = pCpyPara->rTabFrmArr[ nFndPos ]).pNewFrmFmt->
GetFrmSize()).GetWidth() != (SwTwips)nSize )
@@ -1984,10 +1987,9 @@ lcl_CopyLineToDoc(const _FndLine& rFndLine, _CpyPara *const pCpyPara)
}
else
// Calculate it
- for( sal_uInt16 n = 0; n < rFndLine.GetBoxes().size(); ++n )
+ for( auto &rBox : rFndLine.GetBoxes() )
{
- aPara.nOldSize += rFndLine.GetBoxes()[n]
- .GetBox()->GetFrmFmt()->GetFrmSize().GetWidth();
+ aPara.nOldSize += rBox.GetBox()->GetFrmFmt()->GetFrmSize().GetWidth();
}
const _FndBoxes& rBoxes = rFndLine.GetBoxes();
@@ -2031,11 +2033,9 @@ bool SwTable::CopyHeadlineIntoTable( SwTableNode& rTblNd )
if( rTblNd.GetTable().IsNewModel() )
{ // The copied line must not contain any row span attributes > 1
SwTableLine* pLine = rTblNd.GetTable().GetTabLines()[0];
- sal_uInt16 nColCount = pLine->GetTabBoxes().size();
- OSL_ENSURE( nColCount, "Empty Table Line" );
- for( sal_uInt16 nCurrCol = 0; nCurrCol < nColCount; ++nCurrCol )
+ OSL_ENSURE( !pLine->GetTabBoxes().empty(), "Empty Table Line" );
+ for( auto pTableBox : pLine->GetTabBoxes() )
{
- SwTableBox* pTableBox = pLine->GetTabBoxes()[nCurrCol];
OSL_ENSURE( pTableBox, "Missing Table Box" );
pTableBox->setRowSpan( 1 );
}
@@ -2357,9 +2357,8 @@ static bool lcl_SetSelBoxWidth( SwTableLine* pLine, CR_SetBoxWidth& rParam,
SwTwips nDist, bool bCheck )
{
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
- for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
+ for( auto pBox : rBoxes )
{
- SwTableBox* pBox = rBoxes[ n ];
SwFrmFmt* pFmt = pBox->GetFrmFmt();
const SwFmtFrmSize& rSz = pFmt->GetFrmSize();
SwTwips nWidth = rSz.GetWidth();
@@ -2367,9 +2366,8 @@ static bool lcl_SetSelBoxWidth( SwTableLine* pLine, CR_SetBoxWidth& rParam,
if( bCheck )
{
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
- if( !::lcl_SetSelBoxWidth( pBox->GetTabLines()[ i ], rParam,
- nDist, true ))
+ for( auto pLn : pBox->GetTabLines() )
+ if( !::lcl_SetSelBoxWidth( pLn, rParam, nDist, true ))
return false;
// Collect all "ContentBoxes"
@@ -2396,10 +2394,10 @@ static bool lcl_SetSelBoxWidth( SwTableLine* pLine, CR_SetBoxWidth& rParam,
else
{
SwTwips nLowerDiff = 0, nOldLower = rParam.nLowerDiff;
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
+ for( auto pLn : pBox->GetTabLines() )
{
rParam.nLowerDiff = 0;
- lcl_SetSelBoxWidth( pBox->GetTabLines()[ i ], rParam, nDist, false );
+ lcl_SetSelBoxWidth( pLn, rParam, nDist, false );
if( nLowerDiff < rParam.nLowerDiff )
nLowerDiff = rParam.nLowerDiff;
@@ -2457,18 +2455,16 @@ static bool lcl_SetOtherBoxWidth( SwTableLine* pLine, CR_SetBoxWidth& rParam,
SwTwips nDist, bool bCheck )
{
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
- for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
+ for( auto pBox : rBoxes )
{
- SwTableBox* pBox = rBoxes[ n ];
SwFrmFmt* pFmt = pBox->GetFrmFmt();
const SwFmtFrmSize& rSz = pFmt->GetFrmSize();
SwTwips nWidth = rSz.GetWidth();
if( bCheck )
{
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
- if( !::lcl_SetOtherBoxWidth( pBox->GetTabLines()[ i ],
- rParam, nDist, true ))
+ for( auto pLn : pBox->GetTabLines() )
+ if( !::lcl_SetOtherBoxWidth( pLn, rParam, nDist, true ))
return false;
if( rParam.bBigger && ( TBLFIX_CHGABS == rParam.nMode
@@ -2495,11 +2491,10 @@ static bool lcl_SetOtherBoxWidth( SwTableLine* pLine, CR_SetBoxWidth& rParam,
else
{
SwTwips nLowerDiff = 0, nOldLower = rParam.nLowerDiff;
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
+ for( auto pLn : pBox->GetTabLines() )
{
rParam.nLowerDiff = 0;
- lcl_SetOtherBoxWidth( pBox->GetTabLines()[ i ], rParam,
- nDist, false );
+ lcl_SetOtherBoxWidth( pLn, rParam, nDist, false );
if( nLowerDiff < rParam.nLowerDiff )
nLowerDiff = rParam.nLowerDiff;
@@ -2551,14 +2546,15 @@ static bool lcl_InsSelBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
SwTwips nDist, bool bCheck )
{
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
- sal_uInt16 n, nCmp;
- for( n = 0; n < rBoxes.size(); ++n )
+ for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
{
SwTableBox* pBox = rBoxes[ n ];
SwTableBoxFmt* pFmt = static_cast<SwTableBoxFmt*>(pBox->GetFrmFmt());
const SwFmtFrmSize& rSz = pFmt->GetFrmSize();
SwTwips nWidth = rSz.GetWidth();
+ int nCmp {0};
+
if( bCheck )
{
for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
@@ -2572,8 +2568,6 @@ static bool lcl_InsSelBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
nCmp = 1;
else if( nDist + ( rParam.bLeft ? 0 : nWidth/2 ) > rParam.nSide )
nCmp = 2;
- else
- nCmp = 0;
if( nCmp )
{
@@ -2597,10 +2591,10 @@ static bool lcl_InsSelBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
else
{
SwTwips nLowerDiff = 0, nOldLower = rParam.nLowerDiff;
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
+ for( auto pLn : pBox->GetTabLines() )
{
rParam.nLowerDiff = 0;
- lcl_InsSelBox( pBox->GetTabLines()[ i ], rParam, nDist, false );
+ lcl_InsSelBox( pLn, rParam, nDist, false );
if( nLowerDiff < rParam.nLowerDiff )
nLowerDiff = rParam.nLowerDiff;
@@ -2614,8 +2608,6 @@ static bool lcl_InsSelBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
nCmp = 2;
else if( nDist + nWidth / 2 > rParam.nSide )
nCmp = 3;
- else
- nCmp = 0;
if( nCmp )
{
@@ -2690,7 +2682,6 @@ static bool lcl_InsOtherBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
return true;
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
- sal_uInt16 n;
// Table fixed, proportional
if( !rParam.nRemainWidth && TBLFIX_CHGPROP == rParam.nMode )
@@ -2698,9 +2689,9 @@ static bool lcl_InsOtherBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
// Find the right width to which the relative width adjustment
// corresponds to
SwTwips nTmpDist = nDist;
- for( n = 0; n < rBoxes.size(); ++n )
+ for( auto pBox : rBoxes )
{
- SwTwips nWidth = rBoxes[ n ]->GetFrmFmt()->GetFrmSize().GetWidth();
+ SwTwips nWidth = pBox->GetFrmFmt()->GetFrmSize().GetWidth();
if( (nTmpDist + nWidth / 2 ) > rParam.nSide )
{
rParam.nRemainWidth = rParam.bLeft
@@ -2712,7 +2703,7 @@ static bool lcl_InsOtherBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
}
}
- for( n = 0; n < rBoxes.size(); ++n )
+ for( SwTableBoxes::size_type n = 0; n < rBoxes.size(); ++n )
{
SwTableBox* pBox = rBoxes[ n ];
SwFrmFmt* pFmt = pBox->GetFrmFmt();
@@ -2721,9 +2712,8 @@ static bool lcl_InsOtherBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
if( bCheck )
{
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
- if( !::lcl_InsOtherBox( pBox->GetTabLines()[ i ],
- rParam, nDist, true ))
+ for( auto pLn : pBox->GetTabLines() )
+ if( !::lcl_InsOtherBox( pLn, rParam, nDist, true ))
return false;
if(
@@ -2776,11 +2766,10 @@ static bool lcl_InsOtherBox( SwTableLine* pLine, CR_SetBoxWidth& rParam,
else
{
SwTwips nLowerDiff = 0, nOldLower = rParam.nLowerDiff;
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
+ for( auto pLn : pBox->GetTabLines() )
{
rParam.nLowerDiff = 0;
- lcl_InsOtherBox( pBox->GetTabLines()[ i ], rParam,
- nDist, false );
+ lcl_InsOtherBox( pLn, rParam, nDist, false );
if( nLowerDiff < rParam.nLowerDiff )
nLowerDiff = rParam.nLowerDiff;
@@ -2878,15 +2867,14 @@ static void lcl_DelSelBox_CorrLowers( SwTableLine& rLine, CR_SetBoxWidth& rParam
// 1. step: Calculate own width
SwTableBoxes& rBoxes = rLine.GetTabBoxes();
SwTwips nBoxWidth = 0;
- sal_uInt16 n;
- for( n = rBoxes.size(); n; )
+ for( auto n = rBoxes.size(); n; )
nBoxWidth += rBoxes[ --n ]->GetFrmFmt()->GetFrmSize().GetWidth();
if( COLFUZZY < std::abs( nWidth - nBoxWidth ))
{
// Thus, they need to be adjusted
- for( n = rBoxes.size(); n; )
+ for( auto n = rBoxes.size(); n; )
{
SwTableBox* pBox = rBoxes[ --n ];
SwFmtFrmSize aNew( pBox->GetFrmFmt()->GetFrmSize() );
@@ -2900,7 +2888,7 @@ static void lcl_DelSelBox_CorrLowers( SwTableLine& rLine, CR_SetBoxWidth& rParam
if( !pBox->GetSttNd() )
{
// Has Lower itself, so also adjust that
- for( sal_uInt16 i = pBox->GetTabLines().size(); i; )
+ for( auto i = pBox->GetTabLines().size(); i; )
::lcl_DelSelBox_CorrLowers( *pBox->GetTabLines()[ --i ],
rParam, nDiff );
}
@@ -2961,7 +2949,7 @@ static void lcl_ChgBoxSize( SwTableBox& rBox, CR_SetBoxWidth& rParam,
rParam.aShareFmts.SetSize( rBox, aNew );
// Change the Lower once again
- for( sal_uInt16 i = rBox.GetTabLines().size(); i; )
+ for( auto i = rBox.GetTabLines().size(); i; )
::lcl_DelSelBox_CorrLowers( *rBox.GetTabLines()[ --i ], rParam,
aNew.GetWidth() );
}
@@ -2991,10 +2979,10 @@ static bool lcl_DeleteBox_Recursive( CR_SetBoxWidth& rParam, SwTableBox& rBox,
else
{
// We need to delete these sequentially via the ContentBoxes
- for( sal_uInt16 i = rBox.GetTabLines().size(); i; )
+ for( auto i = rBox.GetTabLines().size(); i; )
{
SwTableLine& rLine = *rBox.GetTabLines()[ --i ];
- for( sal_uInt16 n = rLine.GetTabBoxes().size(); n; )
+ for( auto n = rLine.GetTabBoxes().size(); n; )
{
if (!::lcl_DeleteBox_Recursive( rParam,
*rLine.GetTabBoxes()[ --n ], bCheck ))
@@ -3011,7 +2999,10 @@ static bool lcl_DelSelBox( SwTableLine* pTabLine, CR_SetBoxWidth& rParam,
SwTwips nDist, bool bCheck )
{
SwTableBoxes& rBoxes = pTabLine->GetTabBoxes();
- sal_uInt16 n, nCntEnd, nBoxChkStt, nBoxChkEnd, nDelWidth = 0;
+ SwTableBoxes::size_type n;
+ SwTableBoxes::size_type nCntEnd;
+
+ sal_uInt16 nBoxChkStt, nBoxChkEnd, nDelWidth = 0;
if( rParam.bLeft )
{
n = rBoxes.size();
@@ -3149,9 +3140,8 @@ static bool lcl_DelSelBox( SwTableLine* pTabLine, CR_SetBoxWidth& rParam,
long nLowerDiff = 0;
long nOldLower = rParam.nLowerDiff;
sal_uInt16 nOldRemain = rParam.nRemainWidth;
- sal_uInt16 i;
- for( i = pBox->GetTabLines().size(); i; )
+ for( auto i = pBox->GetTabLines().size(); i; )
{
rParam.nLowerDiff = nDelWidth + nOldLower;
rParam.nRemainWidth = nOldRemain;
@@ -3260,7 +3250,7 @@ static bool lcl_DelSelBox( SwTableLine* pTabLine, CR_SetBoxWidth& rParam,
if( bCorrLowers )
{
// Adapt the Lower once again
- for( i = pBox->GetTabLines().size(); i; )
+ for( auto i = pBox->GetTabLines().size(); i; )
::lcl_DelSelBox_CorrLowers( *pBox->
GetTabLines()[ --i ], rParam, aNew.GetWidth() );
}
@@ -3286,10 +3276,8 @@ static bool lcl_DelOtherBox( SwTableLine* , CR_SetBoxWidth& , SwTwips , bool )
static void lcl_AjustLines( SwTableLine* pLine, CR_SetBoxWidth& rParam )
{
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
- for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
+ for( auto pBox : rBoxes )
{
- SwTableBox* pBox = rBoxes[ n ];
-
SwFmtFrmSize aSz( pBox->GetFrmFmt()->GetFrmSize() );
SwTwips nWidth = aSz.GetWidth();
nWidth *= rParam.nDiff;
@@ -3297,8 +3285,8 @@ static void lcl_AjustLines( SwTableLine* pLine, CR_SetBoxWidth& rParam )
aSz.SetWidth( nWidth );
rParam.aShareFmts.SetSize( *pBox, aSz );
- for( sal_uInt16 i = 0; i < pBox->GetTabLines().size(); ++i )
- ::lcl_AjustLines( pBox->GetTabLines()[ i ], rParam );
+ for( auto pLn : pBox->GetTabLines() )
+ ::lcl_AjustLines( pLn, rParam );
}
}
@@ -3315,8 +3303,8 @@ void _CheckBoxWidth( const SwTableLine& rLine, SwTwips nSize )
const SwTwips nBoxW = pBox->GetFrmFmt()->GetFrmSize().GetWidth();
nAktSize += nBoxW;
- for( sal_uInt16 j = 0; j < pBox->GetTabLines().size(); ++j )
- _CheckBoxWidth( *pBox->GetTabLines()[ j ], nBoxW );
+ for( auto pLn : pBox->GetTabLines() )
+ _CheckBoxWidth( *pLn, nBoxW );
}
if (sal::static_int_cast< unsigned long >(std::abs(nAktSize - nSize)) >
@@ -3337,11 +3325,11 @@ static _FndBox* lcl_SaveInsDelData( CR_SetBoxWidth& rParam, SwUndo** ppUndo,
{
// Get the Boxes
if( rParam.bBigger )
- for( sal_uInt16 n = 0; n < rTbl.GetTabLines().size(); ++n )
- ::lcl_DelSelBox( rTbl.GetTabLines()[ n ], rParam, nDistStt, true );
+ for( auto pLn : rTbl.GetTabLines() )
+ ::lcl_DelSelBox( pLn, rParam, nDistStt, true );
else
- for( sal_uInt16 n = 0; n < rTbl.GetTabLines().size(); ++n )
- ::lcl_InsSelBox( rTbl.GetTabLines()[ n ], rParam, nDistStt, true );
+ for( auto pLn : rTbl.GetTabLines() )
+ ::lcl_InsSelBox( pLn, rParam, nDistStt, true );
}
// Prevent deleting the whole Table
@@ -3751,8 +3739,8 @@ bool SwTable::SetColWidth( SwTableBox& rAktBox, sal_uInt16 eType,
SwTableLine* pLine = rAktBox.GetUpper();
while( pLine->GetUpper() )
{
- sal_uInt16 nPos = pLine->GetTabBoxes().GetPos( pBox );
- if( bLeft ? nPos != 0 : nPos + 1 != (sal_uInt16)pLine->GetTabBoxes().size() )
+ const SwTableBoxes::size_type nPos = pLine->GetTabBoxes().GetPos( pBox );
+ if( bLeft ? nPos != 0 : nPos + 1 != pLine->GetTabBoxes().size() )
break;
pBox = pLine->GetUpper();
@@ -3930,12 +3918,10 @@ void SetLineHeight( SwTableLine& rLine, SwTwips nOldHeight, SwTwips nNewHeight,
pFmt->SetFmtAttr( SwFmtFrmSize( eSize, 0, nMyNewH ) );
// First adapt all internal ones
- SwTableBoxes& rBoxes = rLine.GetTabBoxes();
- for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
+ for( auto pBox : rLine.GetTabBoxes() )
{
- SwTableBox& rBox = *rBoxes[ n ];
- for( sal_uInt16 i = 0; i < rBox.GetTabLines().size(); ++i )
- SetLineHeight( *rBox.GetTabLines()[ i ], nMyOldH, nMyNewH, bMinSize );
+ for( auto pLine : pBox->GetTabLines() )
+ SetLineHeight( *pLine, nMyOldH, nMyNewH, bMinSize );
}
}
@@ -4054,7 +4040,7 @@ static bool lcl_InsDelSelLine( SwTableLine* pLine, CR_SetLineHeight& rParam,
// And once again calculate the Box count
SwTableBoxes& rNewBoxes = pNewLine->GetTabBoxes();
- for( sal_uInt16 n = 0; n < rBoxes.size(); ++n )
+ for( SwTableBoxes::size_type n = 0; n < rBoxes.size(); ++n )
{
SwTwips nWidth = 0;
SwTableBox* pOld = rBoxes[ n ];
@@ -4090,7 +4076,7 @@ static bool lcl_InsDelSelLine( SwTableLine* pLine, CR_SetLineHeight& rParam,
{
// Collect Boxes!
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
- for( sal_uInt16 n = rBoxes.size(); n; )
+ for( auto n = rBoxes.size(); n; )
{
SwTableBox* pBox = rBoxes[ --n ];
if( pBox->GetFrmFmt()->GetProtect().IsCntntProtected() )
@@ -4102,7 +4088,7 @@ static bool lcl_InsDelSelLine( SwTableLine* pLine, CR_SetLineHeight& rParam,
}
else
{
- for( sal_uInt16 i = pBox->GetTabLines().size(); i; )
+ for( auto i = pBox->GetTabLines().size(); i; )
lcl_InsDelSelLine( pBox->GetTabLines()[ --i ],
rParam, 0, true );
}
@@ -4127,7 +4113,7 @@ bool SwTable::SetRowHeight( SwTableBox& rAktBox, sal_uInt16 eType,
bTop = nsTblChgWidthHeightType::WH_ROW_TOP == ( eType & 0xff ) ||
nsTblChgWidthHeightType::WH_CELL_TOP == ( eType & 0xff ),
bInsDel = 0 != (eType & nsTblChgWidthHeightType::WH_FLAG_INSDEL );
- sal_uInt16 n, nBaseLinePos = GetTabLines().GetPos( pBaseLine );
+ sal_uInt16 nBaseLinePos = GetTabLines().GetPos( pBaseLine );
sal_uLong nBoxIdx = rAktBox.GetSttIdx();
CR_SetLineHeight aParam( eType,
@@ -4208,7 +4194,8 @@ bool SwTable::SetRowHeight( SwTableBox& rAktBox, sal_uInt16 eType,
else
{
bRet = true;
- sal_uInt16 nStt, nEnd;
+ SwTableLines::size_type nStt;
+ SwTableLines::size_type nEnd;
if( bTop )
nStt = 0, nEnd = nBaseLinePos;
else
@@ -4217,7 +4204,7 @@ bool SwTable::SetRowHeight( SwTableBox& rAktBox, sal_uInt16 eType,
// Get the current Lines' height
if( TBLFIX_CHGPROP == eTblChgMode )
{
- for( n = nStt; n < nEnd; ++n )
+ for( auto n = nStt; n < nEnd; ++n )
{
SwLayoutFrm* pLineFrm = GetRowFrm( *(*pLines)[ n ] );
OSL_ENSURE( pLineFrm, "Where is the Frame from the SwTableLine??" );
@@ -4244,7 +4231,7 @@ bool SwTable::SetRowHeight( SwTableBox& rAktBox, sal_uInt16 eType,
{
if( bBigger )
{
- for( n = nStt; n < nEnd; ++n )
+ for( auto n = nStt; n < nEnd; ++n )
{
if( !(*fnOtherLine)( (*pLines)[ n ], aParam,
nAbsDiff, true ))
@@ -4291,13 +4278,13 @@ bool SwTable::SetRowHeight( SwTableBox& rAktBox, sal_uInt16 eType,
{
(*fnSelLine)( (*pLines)[ nBaseLinePos ], aParam,
nAbsDiff, false );
- for( n = nStt; n < nEnd; ++n )
+ for( auto n = nStt; n < nEnd; ++n )
(*fnOtherLine)( (*pLines)[ n ], aParam1,
nAbsDiff, false );
}
else
{
- for( n = nStt; n < nEnd; ++n )
+ for( auto n = nStt; n < nEnd; ++n )
(*fnOtherLine)( (*pLines)[ n ], aParam1,
nAbsDiff, false );
(*fnSelLine)( (*pLines)[ nBaseLinePos ], aParam,
@@ -4351,7 +4338,7 @@ bool SwTable::SetRowHeight( SwTableBox& rAktBox, sal_uInt16 eType,
SwFrmFmt* SwShareBoxFmt::GetFormat( long nWidth ) const
{
SwFrmFmt *pRet = 0, *pTmp;
- for( sal_uInt16 n = aNewFmts.size(); n; )
+ for( auto n = aNewFmts.size(); n; )
if( ( pTmp = aNewFmts[ --n ])->GetFrmSize().GetWidth()
== nWidth )
{
@@ -4367,7 +4354,7 @@ SwFrmFmt* SwShareBoxFmt::GetFormat( const SfxPoolItem& rItem ) const
sal_uInt16 nWhich = rItem.Which();
SwFrmFmt *pRet = 0, *pTmp;
const SfxPoolItem& rFrmSz = pOldFmt->GetFmtAttr( RES_FRM_SIZE, false );
- for( sal_uInt16 n = aNewFmts.size(); n; )
+ for( auto n = aNewFmts.size(); n; )
if( SfxItemState::SET == ( pTmp = aNewFmts[ --n ])->
GetItemState( nWhich, false, &pItem ) && *pItem == rItem &&
pTmp->GetFmtAttr( RES_FRM_SIZE, false ) == rFrmSz )
@@ -4500,7 +4487,7 @@ void SwShareBoxFmts::SetAttr( SwTableLine& rLine, const SfxPoolItem& rItem )
void SwShareBoxFmts::RemoveFormat( const SwFrmFmt& rFmt )
{
- for( sal_uInt16 i = aShareArr.size(); i; )
+ for( auto i = aShareArr.size(); i; )
if( aShareArr[ --i ].RemoveFormat( rFmt ))
aShareArr.erase( aShareArr.begin() + i );
}
@@ -4508,13 +4495,13 @@ void SwShareBoxFmts::RemoveFormat( const SwFrmFmt& rFmt )
bool SwShareBoxFmts::Seek_Entry( const SwFrmFmt& rFmt, sal_uInt16* pPos ) const
{
sal_uLong nIdx = reinterpret_cast<sal_uLong>(&rFmt);
- sal_uInt16 nO = aShareArr.size(), nM, nU = 0;
+ _SwShareBoxFmts::size_type nO = aShareArr.size(), nU = 0;
if( nO > 0 )
{
nO--;
while( nU <= nO )
{
- nM = nU + ( nO - nU ) / 2;
+ const auto nM = nU + ( nO - nU ) / 2;
sal_uLong nFmt = reinterpret_cast<sal_uLong>(&aShareArr[ nM ].GetOldFormat());
if( nFmt == nIdx )
{
commit 89e72ed96725142587e9f762d917dcecc591b877
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 8 00:39:32 2015 +0100
Reduce scope and improve readability
Change-Id: I4bf1e2c0f928644e6f85acd75b88685303c4ac06
diff --git a/sw/source/core/doc/tblcpy.cxx b/sw/source/core/doc/tblcpy.cxx
index 4650a83..d4b39c2 100644
--- a/sw/source/core/doc/tblcpy.cxx
+++ b/sw/source/core/doc/tblcpy.cxx
@@ -815,7 +815,7 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
SwTblNumFmtMerge aTNFM( *pCpyDoc, *pDoc );
- SwTableBox *pTmpBox, *pSttBox = (SwTableBox*)rSelBoxes[0];
+ SwTableBox *pSttBox = (SwTableBox*)rSelBoxes[0];
_FndLine *pFLine, *pInsFLine = 0;
_FndBox aFndBox( 0, 0 );
@@ -872,8 +872,7 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
// Test for nesting
for( SwTableBoxes::size_type nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
- if( !( pTmpBox = pLastLn->GetTabBoxes()[ nSttBox + nBx ])
- ->GetSttNd() )
+ if( !pLastLn->GetTabBoxes()[ nSttBox + nBx ]->GetSttNd() )
return false;
}
// We have enough space for the to-be-copied, so insert new
@@ -929,8 +928,8 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
// Test for nesting
for( _FndBoxes::size_type nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
{
- if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
- ->GetSttNd() )
+ SwTableBox *pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ];
+ if( !pTmpBox->GetSttNd() )
{
delete pInsFLine;
return false;
@@ -951,8 +950,8 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
// Test for nesting
for( SwTableBoxes::size_type nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
{
- if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
- ->GetSttNd() )
+ SwTableBox *pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ];
+ if( !pTmpBox->GetSttNd() )
return false;
// if Ok, insert the Box into the FndLine
if( nBx == pFLine->GetBoxes().size() )
commit ac0aeeaa31402a5c934bab58104498bbb6057fca
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 8 00:24:42 2015 +0100
Use +=
Change-Id: I280a5ee0d63cabba7482164132b092f4087814bd
diff --git a/sw/source/core/doc/tblcpy.cxx b/sw/source/core/doc/tblcpy.cxx
index 2c751f3..4650a83 100644
--- a/sw/source/core/doc/tblcpy.cxx
+++ b/sw/source/core/doc/tblcpy.cxx
@@ -237,7 +237,7 @@ namespace
mnStartCol = 0;
while( nIdx && pC != pEnd )
{
- mnStartCol = mnStartCol + pC->mnColSpan;
+ mnStartCol += pC->mnColSpan;
--nIdx;
++pC;
}
@@ -426,8 +426,7 @@ namespace
if( nCurrStartCol < USHRT_MAX )
{
if( pFirstBox->mnColSpan > nFirstStartCol )
- nCurrStartCol = pFirstBox->mnColSpan - nFirstStartCol
- + nCurrStartCol;
+ nCurrStartCol += pFirstBox->mnColSpan - nFirstStartCol;
}
++pFirstBox;
}
@@ -441,7 +440,7 @@ namespace
for( BoxStructure::size_type nBox = 0; nBox < nBoxCount; ++nBox )
{
BoxSpanInfo& rInfo = rBox[nBox];
- nCol = nCol + rInfo.mnColSpan;
+ nCol += rInfo.mnColSpan;
if( rInfo.mbSelected || nCol > nCurrStartCol )
{
rInfo.mpCopy = pCurrBox->mpBox;
commit 048bf35e825f87fb0422664bc51fb5febc8f80ab
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 8 00:18:48 2015 +0100
Use more proper integer types and range-for loops
Change-Id: I66d2d469a6dc03b3e6ad3609b5a04ac670f6e000
diff --git a/sw/source/core/doc/tblcpy.cxx b/sw/source/core/doc/tblcpy.cxx
index 42e0548..2c751f3 100644
--- a/sw/source/core/doc/tblcpy.cxx
+++ b/sw/source/core/doc/tblcpy.cxx
@@ -111,8 +111,8 @@ namespace
{
if( !rBox.GetTabLines().empty() )
{
- SubTable::difference_type nSize = std::distance( pStartLn, pEndLn );
- if( nSize < (sal_uInt16)rBox.GetTabLines().size() )
+ SubTable::size_type nSize = static_cast<SubTable::size_type>(std::distance( pStartLn, pEndLn ));
+ if( nSize < rBox.GetTabLines().size() )
{
SubLine aSubLine;
SubLine::iterator pBox = pStartLn->begin();
@@ -128,11 +128,10 @@ namespace
do
{
rSubTable.insert( pEndLn, aSubLine );
- } while( ++nSize < (sal_uInt16)rBox.GetTabLines().size() );
+ } while( ++nSize < rBox.GetTabLines().size() );
}
- for( sal_uInt16 nLine = 0; nLine < rBox.GetTabLines().size(); ++nLine )
- pStartLn = insertSubLine( rSubTable, *rBox.GetTabLines()[nLine],
- pStartLn );
+ for( auto pLine : rBox.GetTabLines() )
+ pStartLn = insertSubLine( rSubTable, *pLine, pStartLn );
OSL_ENSURE( pStartLn == pEndLn, "Sub line confusion" );
}
else
@@ -156,10 +155,9 @@ namespace
SubTable::iterator pMax = pStartLn;
++pMax;
SubTable::difference_type nMax = 1;
- for( sal_uInt16 nBox = 0; nBox < rLine.GetTabBoxes().size(); ++nBox )
+ for( auto pBox : rLine.GetTabBoxes() )
{
- SubTable::iterator pTmp = insertSubBox( rSubTable,
- *rLine.GetTabBoxes()[nBox], pStartLn, pMax );
+ SubTable::iterator pTmp = insertSubBox( rSubTable, *pBox, pStartLn, pMax );
SubTable::difference_type nTmp = std::distance( pStartLn, pTmp );
if( nTmp > nMax )
{
@@ -175,10 +173,9 @@ namespace
mnAddLine(0)
{
maCols.push_front(0);
- const SwTableLines &rLines = rTable.GetTabLines();
sal_uInt16 nCnt = 0;
- for( sal_uInt16 nLine = 0; nLine < rLines.size(); ++nLine )
- addLine( nCnt, rLines[nLine]->GetTabBoxes(), 0, rTable.IsNewModel() );
+ for( auto pLine : rTable.GetTabLines() )
+ addLine( nCnt, pLine->GetTabBoxes(), 0, rTable.IsNewModel() );
}
TableStructure::TableStructure( const SwTable& rTable,
@@ -192,7 +189,7 @@ namespace
_FndLines &rFndLines = rFndBox.GetLines();
maCols.push_front(0);
const SwTableLine* pLine = rFndLines.front().GetLine();
- sal_uInt16 nStartLn = rTable.GetTabLines().GetPos( pLine );
+ const sal_uInt16 nStartLn = rTable.GetTabLines().GetPos( pLine );
sal_uInt16 nEndLn = nStartLn;
if( rFndLines.size() > 1 )
{
@@ -203,9 +200,9 @@ namespace
{
const SwTableLines &rLines = rTable.GetTabLines();
if( bNoSelection &&
- (sal_uInt16)nMinSize > nEndLn - nStartLn + 1 )
+ nMinSize > static_cast<LineStructure::size_type>(nEndLn - nStartLn + 1) )
{
- sal_uInt16 nNewEndLn = nStartLn + (sal_uInt16)nMinSize - 1;
+ LineStructure::size_type nNewEndLn = nStartLn + nMinSize - 1;
if( nNewEndLn >= rLines.size() )
{
mnAddLine = nNewEndLn - rLines.size() + 1;
@@ -255,7 +252,7 @@ namespace
{
bool bComplex = false;
if( !bNewModel )
- for( sal_uInt16 nBox = 0; !bComplex && nBox < rBoxes.size(); ++nBox )
+ for( SwTableBoxes::size_type nBox = 0; !bComplex && nBox < rBoxes.size(); ++nBox )
bComplex = !rBoxes[nBox]->GetTabLines().empty();
if( bComplex )
{
@@ -264,8 +261,8 @@ namespace
aSubTable.push_back( aSubLine );
SubTable::iterator pStartLn = aSubTable.begin();
SubTable::iterator pEndLn = aSubTable.end();
- for( sal_uInt16 nBox = 0; nBox < rBoxes.size(); ++nBox )
- insertSubBox( aSubTable, *rBoxes[nBox], pStartLn, pEndLn );
+ for( auto pBox : rBoxes )
+ insertSubBox( aSubTable, *pBox, pStartLn, pEndLn );
SubTable::size_type nSize = aSubTable.size();
if( nSize )
{
@@ -299,8 +296,8 @@ namespace
maLines[rLine].reserve( rBoxes.size() );
ColumnStructure::iterator pCol = maCols.begin();
BoxStructure::iterator pSel = maLines[rLine].end();
- for( sal_uInt16 nBox = 0; nBox < rBoxes.size(); ++nBox )
- addBox( rLine, pSelBoxes, rBoxes[nBox], nBorder, nCol,
+ for( auto pBox : rBoxes )
+ addBox( rLine, pSelBoxes, pBox, nBorder, nCol,
pCol, pSel, bSelected, false );
++rLine;
}
@@ -329,7 +326,7 @@ namespace
else
aInfo.mbSelected = false;
rnBorder += pBox->GetFrmFmt()->GetFrmSize().GetWidth();
- sal_uInt16 nLeftCol = rnCol;
+ const sal_uInt16 nLeftCol = rnCol;
while( rpCol != maCols.end() && *rpCol < rnBorder )
{
++rnCol;
@@ -369,7 +366,7 @@ namespace
if( mnAddLine )
{
const SwTableLines &rLines = rTable.GetTabLines();
- sal_uInt16 nLineCount = rLines.size();
+ const sal_uInt16 nLineCount = rLines.size();
if( nLineCount < mnAddLine )
mnAddLine = nLineCount;
sal_uInt16 nLine = (sal_uInt16)maLines.size();
@@ -561,9 +558,8 @@ static void lcl_CpyBox( const SwTable& rCpyTbl, const SwTableBox* pCpyBox,
}
// If we still have FlyFrames hanging around, delete them too
- for( sal_uInt16 n = 0; n < pDoc->GetSpzFrmFmts()->size(); ++n )
+ for( const auto pFly : *pDoc->GetSpzFrmFmts() )
{
- SwFrmFmt *const pFly = (*pDoc->GetSpzFrmFmts())[n];
SwFmtAnchor const*const pAnchor = &pFly->GetAnchor();
SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
if (pAPos &&
@@ -604,7 +600,7 @@ static void lcl_CpyBox( const SwTable& rCpyTbl, const SwTableBox* pCpyBox,
SwTxtNode *const pTxtNd = aSavePos.GetNode().GetTxtNode();
if( pTxtNd )
{
- sal_uInt16 nPoolId = pTxtNd->GetTxtColl()->GetPoolFmtId();
+ const sal_uInt16 nPoolId = pTxtNd->GetTxtColl()->GetPoolFmtId();
if( bReplaceColl &&
(( 1 < rDstTbl.GetTabLines().size() &&
pLine == rDstTbl.GetTabLines().front() )
@@ -757,11 +753,10 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwNodeIndex& rSttBox,
bool bDelCntnt = true;
const SwTableBox* pTmp;
- for( sal_uInt16 nLines = 0; nLines < rCpyTbl.GetTabLines().size(); ++nLines )
+ for( auto pLine : rCpyTbl.GetTabLines() )
{
// Get the first from the CopyLine
- const SwTableBox* pCpyBox = rCpyTbl.GetTabLines()[nLines]
- ->GetTabBoxes().front();
+ const SwTableBox* pCpyBox = pLine->GetTabBoxes().front();
while( !pCpyBox->GetTabLines().empty() )
pCpyBox = pCpyBox->GetTabLines().front()->GetTabBoxes().front();
@@ -785,14 +780,14 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwNodeIndex& rSttBox,
SwTableLine* pNxtLine = pMyBox->GetUpper();
while( pNxtLine->GetUpper() )
pNxtLine = pNxtLine->GetUpper()->GetUpper();
- sal_uInt16 nPos = GetTabLines().GetPos( pNxtLine );
+ const SwTableLines::size_type nPos = GetTabLines().GetPos( pNxtLine ) + 1;
// Is there a next?
- if( nPos + 1 >= (sal_uInt16)GetTabLines().size() )
+ if( nPos >= GetTabLines().size() )
bDelCntnt = false; // there is none, all goes into the last Box
else
{
// Find the next Box with content
- pNxtLine = GetTabLines()[ nPos+1 ];
+ pNxtLine = GetTabLines()[ nPos ];
pMyBox = pNxtLine->GetTabBoxes().front();
while( !pMyBox->GetTabLines().empty() )
pMyBox = pMyBox->GetTabLines().front()->GetTabBoxes().front();
@@ -823,7 +818,6 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
SwTableBox *pTmpBox, *pSttBox = (SwTableBox*)rSelBoxes[0];
- sal_uInt16 nLn, nBx;
_FndLine *pFLine, *pInsFLine = 0;
_FndBox aFndBox( 0, 0 );
// Find all Boxes/Lines
@@ -838,12 +832,12 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
{
_FndBox* pFndBox;
- sal_uInt16 nFndCnt = aFndBox.GetLines().size();
+ const _FndLines::size_type nFndCnt = aFndBox.GetLines().size();
if( !nFndCnt )
return false;
// Check if we have enough space for all Lines and Boxes
- sal_uInt16 nTstLns = 0;
+ SwTableLines::size_type nTstLns = 0;
pFLine = &aFndBox.GetLines().front();
sal_uInt16 nSttLine = GetTabLines().GetPos( pFLine->GetLine() );
// Do we have as many rows, actually?
@@ -859,15 +853,15 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
if( 1 < rSelBoxes.size() )
return false;
- sal_uInt16 nNewLns = rCpyTbl.GetTabLines().size() -
+ const sal_uInt16 nNewLns = rCpyTbl.GetTabLines().size() -
(GetTabLines().size() - nSttLine );
// See if the Box count is high enough for the Lines
SwTableLine* pLastLn = GetTabLines().back();
pSttBox = pFLine->GetBoxes()[0].GetBox();
- sal_uInt16 nSttBox = pFLine->GetLine()->GetTabBoxes().GetPos( pSttBox );
- for( sal_uInt16 n = rCpyTbl.GetTabLines().size() - nNewLns;
+ const SwTableBoxes::size_type nSttBox = pFLine->GetLine()->GetTabBoxes().GetPos( pSttBox );
+ for( SwTableLines::size_type n = rCpyTbl.GetTabLines().size() - nNewLns;
n < rCpyTbl.GetTabLines().size(); ++n )
{
SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[ n ];
@@ -878,7 +872,7 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
return false;
// Test for nesting
- for( nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
+ for( SwTableBoxes::size_type nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
if( !( pTmpBox = pLastLn->GetTabBoxes()[ nSttBox + nBx ])
->GetSttNd() )
return false;
@@ -905,13 +899,13 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
else
return false; // not enough space for the rows
- for( nLn = 0; nLn < nTstLns; ++nLn )
+ for( SwTableLines::size_type nLn = 0; nLn < nTstLns; ++nLn )
{
// We have enough rows, so check the Boxes per row
pFLine = &aFndBox.GetLines()[ nLn % nFndCnt ];
SwTableLine* pLine = pFLine->GetLine();
pSttBox = pFLine->GetBoxes()[0].GetBox();
- sal_uInt16 nSttBox = pLine->GetTabBoxes().GetPos( pSttBox );
+ const SwTableBoxes::size_type nSttBox = pLine->GetTabBoxes().GetPos( pSttBox );
if( nLn >= nFndCnt )
{
// We have more rows in the ClipBoard than we have selected
@@ -927,16 +921,14 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
{
// We insert a new row into the FndBox
if( pLine->GetTabBoxes().size() < nSttBox ||
- sal::static_int_cast< sal_uInt16 >(
- pLine->GetTabBoxes().size() - nSttBox ) <
- pFLine->GetBoxes().size() )
+ pLine->GetTabBoxes().size() - nSttBox < pFLine->GetBoxes().size() )
{
delete pInsFLine;
return false;
}
// Test for nesting
- for( nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
+ for( _FndBoxes::size_type nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
{
if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
->GetSttNd() )
@@ -958,7 +950,7 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
return false;
// Test for nesting
- for( nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
+ for( SwTableBoxes::size_type nBx = 0; nBx < pCpyLn->GetTabBoxes().size(); ++nBx )
{
if( !( pTmpBox = pLine->GetTabBoxes()[ nSttBox + nBx ])
->GetSttNd() )
@@ -980,8 +972,8 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
return false;
// Test for nesting
- for( nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
- if (!pFLine->GetBoxes()[nBx].GetBox()->GetSttNd())
+ for( auto &rBox : pFLine->GetBoxes() )
+ if (!rBox.GetBox()->GetSttNd())
return false;
}
}
@@ -1012,12 +1004,12 @@ bool SwTable::InsTable( const SwTable& rCpyTbl, const SwSelBoxes& rSelBoxes,
}
}
else
- for( nLn = 0; nLn < aFndBox.GetLines().size(); ++nLn )
+ for( _FndLines::size_type nLn = 0; nLn < aFndBox.GetLines().size(); ++nLn )
{
pFLine = &aFndBox.GetLines()[ nLn ];
SwTableLine* pCpyLn = rCpyTbl.GetTabLines()[
nLn % rCpyTbl.GetTabLines().size() ];
- for( nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
+ for( _FndBoxes::size_type nBx = 0; nBx < pFLine->GetBoxes().size(); ++nBx )
{
// Copy the pCpyBox into pMyBox
lcl_CpyBox( rCpyTbl, pCpyLn->GetTabBoxes()[
commit 5d8121f1c93a09733b357ee84c5a88de7dd93ce2
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 22:21:12 2015 +0100
Use indexes in OUString::getToken
Change-Id: Id30c5d094688d29e36e4ead8c58b59705b6bc91b
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index cf611c3..0c61cb4 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -1231,18 +1231,20 @@ void SwTOXBaseSection::UpdateTemplate( const SwTxtNode* pOwnChapterNode )
for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
{
const OUString sTmpStyleNames = GetStyleNames(i);
- sal_uInt16 nTokenCount = comphelper::string::getTokenCount(sTmpStyleNames, TOX_STYLE_DELIMITER);
- for( sal_uInt16 nStyle = 0; nStyle < nTokenCount; ++nStyle )
+ if (sTmpStyleNames.isEmpty())
+ continue;
+
+ sal_Int32 nIndex = 0;
+ while (nIndex >= 0)
{
SwTxtFmtColl* pColl = pDoc->FindTxtFmtCollByName(
- sTmpStyleNames.getToken( nStyle,
- TOX_STYLE_DELIMITER ));
+ sTmpStyleNames.getToken( 0, TOX_STYLE_DELIMITER, nIndex ));
//TODO: no outline Collections in content indexes if OutlineLevels are already included
if( !pColl ||
( TOX_CONTENT == SwTOXBase::GetType() &&
GetCreateType() & nsSwTOXElement::TOX_OUTLINELEVEL &&
pColl->IsAssignedToListLevelOfOutlineStyle()) )
- continue;
+ continue;
SwIterator<SwTxtNode,SwFmtColl> aIter( *pColl );
for( SwTxtNode* pTxtNd = aIter.First(); pTxtNd; pTxtNd = aIter.Next() )
commit 451b26c8e91b57336210a6f47aab9a039f83b62f
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 21:14:48 2015 +0100
Simplify
Change-Id: I2f8c55fb82ac6d161d942b3d7b96c8d3996037e1
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 613e85b..cf611c3 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -1739,15 +1739,14 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
if ( nCount >= 1 )
aNumStr += rIntl.GetFollowingText( nCount > 1 );
}
- else
+ else if (nCount) //#58127# If nCount == 0, then the only PageNumber is already in aNumStr!
{
- if(nCount >= 2 )
- aNumStr += "-";
- else if(nCount == 1 )
+ if (nCount == 1 )
aNumStr += S_PAGE_DELI;
- //#58127# If nCount == 0, then the only PageNumber is already in aNumStr!
- if(nCount)
- aNumStr += aType.GetNumStr( nBeg + nCount );
+ else
+ aNumStr += "-";
+
+ aNumStr += aType.GetNumStr( nBeg + nCount );
}
// Create new String
commit ba88c3aed88739cdffc0a140415afab40266615e
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 21:09:03 2015 +0100
Reduce OUString temporaries
Change-Id: I7ad78a1d7b544326570abac77122055a9cf3c57c
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 825fd2a7..613e85b 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -360,11 +360,7 @@ SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos,
SwTxtNode* pHeadNd = GetNodes().MakeTxtNode( aIdx,
getIDocumentStylePoolAccess().GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) );
- OUString sNm( pNewSection->GetTOXName() );
- // ??Resource
- sNm += "_Head";
-
- SwSectionData headerData( TOX_HEADER_SECTION, sNm );
+ SwSectionData headerData( TOX_HEADER_SECTION, pNewSection->GetTOXName()+"_Head" );
SwNodeIndex aStt( *pHeadNd ); --aIdx;
SwSectionFmt* pSectFmt = MakeSectionFmt( 0 );
@@ -393,7 +389,7 @@ const SwTOXBaseSection* SwDoc::InsertTableOf( sal_uLong nSttNd, sal_uLong nEndNd
pSectNd = pSectNd->StartOfSectionNode()->FindSectionNode();
}
- OUString sSectNm = GetUniqueTOXBaseName(*rTOX.GetTOXType(), rTOX.GetTOXName());
+ const OUString sSectNm = GetUniqueTOXBaseName(*rTOX.GetTOXType(), rTOX.GetTOXName());
SwSectionData aSectionData( TOX_CONTENT_SECTION, sSectNm );
@@ -683,15 +679,14 @@ bool SwDoc::SetTOXBaseName(const SwTOXBase& rTOXBase, const OUString& rName)
"no TOXBaseSection!" );
SwTOXBaseSection* pTOX = const_cast<SwTOXBaseSection*>(static_cast<const SwTOXBaseSection*>(&rTOXBase));
- OUString sTmp = GetUniqueTOXBaseName(*rTOXBase.GetTOXType(), rName);
- bool bRet = sTmp == rName;
- if(bRet)
+ if (GetUniqueTOXBaseName(*rTOXBase.GetTOXType(), rName) == rName)
{
pTOX->SetTOXName(rName);
pTOX->SetSectionName(rName);
getIDocumentState().SetModified();
+ return true;
}
- return bRet;
+ return false;
}
static const SwTxtNode* lcl_FindChapterNode( const SwNode& rNd, sal_uInt8 nLvl = 0 )
@@ -900,11 +895,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
GetTxtFmtColl( FORM_TITLE ) );
pHeadNd->InsertText( GetTitle(), SwIndex( pHeadNd ) );
- OUString sNm( GetTOXName() );
- // ??Resource
- sNm += "_Head";
-
- SwSectionData headerData( TOX_HEADER_SECTION, sNm );
+ SwSectionData headerData( TOX_HEADER_SECTION, GetTOXName()+"_Head" );
SwNodeIndex aStt( *pHeadNd ); --aIdx;
SwSectionFmt* pSectFmt = pDoc->MakeSectionFmt( 0 );
@@ -1048,7 +1039,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
{
SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
- OUString sDeli, sLastDeli;
+ OUString sLastDeli;
SwTOXSortTabBases::size_type i = 0;
while( i < aSortArr.size() )
{
@@ -1060,7 +1051,7 @@ void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
if( nLevel == FORM_ALPHA_DELIMITTER )
continue;
- sDeli = rIntl.GetIndexKey( aSortArr[i]->GetTxt(),
+ const OUString sDeli = rIntl.GetIndexKey( aSortArr[i]->GetTxt(),
aSortArr[i]->GetLocale() );
// Do we already have a Delimitter?
@@ -1239,7 +1230,7 @@ void SwTOXBaseSection::UpdateTemplate( const SwTxtNode* pOwnChapterNode )
SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
{
- OUString sTmpStyleNames = GetStyleNames(i);
+ const OUString sTmpStyleNames = GetStyleNames(i);
sal_uInt16 nTokenCount = comphelper::string::getTokenCount(sTmpStyleNames, TOX_STYLE_DELIMITER);
for( sal_uInt16 nStyle = 0; nStyle < nTokenCount; ++nStyle )
{
@@ -1296,9 +1287,9 @@ void SwTOXBaseSection::UpdateSequence( const SwTxtNode* pOwnChapterNode )
::lcl_FindChapterNode( rTxtNode, 0 ) == pOwnChapterNode ) )
{
const SwSetExpField& rSeqField = dynamic_cast<const SwSetExpField&>(*(pFmtFld->GetField()));
- OUString sName = GetSequenceName();
- sName += OUString( cSequenceMarkSeparator );
- sName += OUString::number( rSeqField.GetSeqNumber() );
+ const OUString sName = GetSequenceName()
+ + OUString( cSequenceMarkSeparator )
+ + OUString::number( rSeqField.GetSeqNumber() );
SwTOXPara * pNew = new SwTOXPara( rTxtNode, nsSwTOXElement::TOX_SEQUENCE, 1, sName );
// set indexes if the number or the reference text are to be displayed
if( GetCaptionDisplay() == CAPTION_TEXT )
commit a72ba7b18ec6e6c71577c747bb90bfc76afd0597
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 20:53:55 2015 +0100
Use more proper types and range-for loops
Change-Id: I2bb9f1536e37f1662c0bb8554459d25532ff648e
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 5b2002b..825fd2a7 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -585,8 +585,8 @@ bool SwDoc::DeleteTOX( const SwTOXBase& rTOXBase, bool bDelNodes )
sal_uInt16 SwDoc::GetTOXTypeCount(TOXTypes eTyp) const
{
sal_uInt16 nCnt = 0;
- for( sal_uInt16 n = 0; n < mpTOXTypes->size(); ++n )
- if( eTyp == (*mpTOXTypes)[n]->GetType() )
+ for( auto pTOXType : *mpTOXTypes )
+ if( eTyp == pTOXType->GetType() )
++nCnt;
return nCnt;
}
@@ -594,9 +594,9 @@ sal_uInt16 SwDoc::GetTOXTypeCount(TOXTypes eTyp) const
const SwTOXType* SwDoc::GetTOXType( TOXTypes eTyp, sal_uInt16 nId ) const
{
sal_uInt16 nCnt = 0;
- for( sal_uInt16 n = 0; n < mpTOXTypes->size(); ++n )
- if( eTyp == (*mpTOXTypes)[n]->GetType() && nCnt++ == nId )
- return (*mpTOXTypes)[n];
+ for( auto pTOXType : *mpTOXTypes )
+ if( eTyp == pTOXType->GetType() && nCnt++ == nId )
+ return pTOXType;
return 0;
}
@@ -624,14 +624,14 @@ OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
const OUString aName( rType.GetTypeName() );
const sal_Int32 nNmLen = aName.getLength();
- sal_uInt16 nNum = 0;
- const sal_uInt16 nFlagSize = ( mpSectionFmtTbl->size() / 8 ) +2;
+ SwSectionFmts::size_type nNum = 0;
+ const SwSectionFmts::size_type nFlagSize = ( mpSectionFmtTbl->size() / 8 ) +2;
sal_uInt8* pSetFlags = new sal_uInt8[ nFlagSize ];
memset( pSetFlags, 0, nFlagSize );
- for( sal_uInt16 n = 0; n < mpSectionFmtTbl->size(); ++n )
+ for( auto pSectionFmt : *mpSectionFmtTbl )
{
- const SwSectionNode *pSectNd = (*mpSectionFmtTbl)[ n ]->GetSectionNode( false );
+ const SwSectionNode *pSectNd = pSectionFmt->GetSectionNode( false );
if ( !pSectNd )
continue;
@@ -642,7 +642,7 @@ OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
if ( aName.startsWith(rNm) )
{
// Calculate number and set the Flag
- nNum = (sal_uInt16)rNm.copy( nNmLen ).toInt32();
+ nNum = rNm.copy( nNmLen ).toInt32();
if( nNum-- && nNum < mpSectionFmtTbl->size() )
pSetFlags[ nNum / 8 ] |= (0x01 << ( nNum & 0x07 ));
}
@@ -655,9 +655,9 @@ OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
{
// All Numbers have been flagged accordingly, so get the right Number
nNum = mpSectionFmtTbl->size();
- for( sal_uInt16 n = 0; n < nFlagSize; ++n )
+ for( SwSectionFmts::size_type n = 0; n < nFlagSize; ++n )
{
- sal_uInt16 nTmp = pSetFlags[ n ];
+ sal_uInt8 nTmp = pSetFlags[ n ];
if( nTmp != 0xff )
{
// so get the Number
@@ -955,7 +955,7 @@ void SwTOXBaseSection::Update(const SfxItemSet* pAttr,
// Sort the List of all TOC Marks and TOC Sections
std::vector<SwTxtFmtColl*> aCollArr( GetTOXForm().GetFormMax(), 0 );
SwNodeIndex aInsPos( *pFirstEmptyNd, 1 );
- for( sal_uInt16 nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
+ for( SwTOXSortTabBases::size_type nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
{
::SetProgressState( 0, pDoc->GetDocShell() );
@@ -1049,7 +1049,7 @@ void SwTOXBaseSection::InsertAlphaDelimitter( const SwTOXInternational& rIntl )
{
SwDoc* pDoc = (SwDoc*)GetFmt()->GetDoc();
OUString sDeli, sLastDeli;
- sal_uInt16 i = 0;
+ SwTOXSortTabBases::size_type i = 0;
while( i < aSortArr.size() )
{
::SetProgressState( 0, pDoc->GetDocShell() );
@@ -1215,10 +1215,10 @@ void SwTOXBaseSection::UpdateOutline( const SwTxtNode* pOwnChapterNode )
SwNodes& rNds = pDoc->GetNodes();
const SwOutlineNodes& rOutlNds = rNds.GetOutLineNds();
- for( sal_uInt16 n = 0; n < rOutlNds.size(); ++n )
+ for( auto pOutlineNode : rOutlNds )
{
::SetProgressState( 0, pDoc->GetDocShell() );
- SwTxtNode* pTxtNd = rOutlNds[ n ]->GetTxtNode();
+ SwTxtNode* pTxtNd = pOutlineNode->GetTxtNode();
if( pTxtNd && pTxtNd->Len() && pTxtNd->HasWriterListeners() &&
sal_uInt16( pTxtNd->GetAttrOutlineLevel()) <= GetLevel() &&
pTxtNd->getLayoutFrm( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() ) &&
@@ -1507,11 +1507,11 @@ void SwTOXBaseSection::UpdateTable( const SwTxtNode* pOwnChapterNode )
SwNodes& rNds = pDoc->GetNodes();
const SwFrmFmts& rArr = *pDoc->GetTblFrmFmts();
- for( sal_uInt16 n = 0; n < rArr.size(); ++n )
+ for( auto pFrmFmt : rArr )
{
::SetProgressState( 0, pDoc->GetDocShell() );
- SwTable* pTmpTbl = SwTable::FindTable( rArr[ n ] );
+ SwTable* pTmpTbl = SwTable::FindTable( pFrmFmt );
SwTableBox* pFBox;
if( pTmpTbl && 0 != (pFBox = pTmpTbl->GetTabSortBoxes()[0] ) &&
pFBox->GetSttNd() && pFBox->GetSttNd()->GetNodes().IsDocNodes() )
@@ -1564,7 +1564,7 @@ void SwTOXBaseSection::UpdatePageNum()
GetOptions() : 0,
GetSortAlgorithm() );
- for( size_t nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
+ for( SwTOXSortTabBases::size_type nCnt = 0; nCnt < aSortArr.size(); ++nCnt )
{
// Loop over all SourceNodes
std::vector<sal_uInt16> aNums; // the PageNumber
@@ -1572,7 +1572,7 @@ void SwTOXBaseSection::UpdatePageNum()
std::vector<sal_uInt16> *pMainNums = 0; // contains page numbers of main entries
// process run in lines
- sal_uInt16 nRange = 0;
+ SwTOXSortTabBases::size_type nRange = 0;
if(GetTOXForm().IsCommaSeparated() &&
aSortArr[nCnt]->GetType() == TOX_SORT_INDEX)
{
@@ -1590,7 +1590,7 @@ void SwTOXBaseSection::UpdatePageNum()
else
nRange = 1;
- for(sal_uInt16 nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; nRunInEntry++)
+ for(SwTOXSortTabBases::size_type nRunInEntry = nCnt; nRunInEntry < nCnt + nRange; ++nRunInEntry)
{
SwTOXSortTabBase* pSortBase = aSortArr[nRunInEntry];
size_t nSize = pSortBase->aTOXSources.size();
@@ -1622,7 +1622,7 @@ void SwTOXBaseSection::UpdatePageNum()
}
// Insert as sorted
- sal_uInt16 i;
+ std::vector<sal_uInt16>::size_type i;
for( i = 0; i < aNums.size() && aNums[i] < nPage; ++i )
;
@@ -1665,8 +1665,11 @@ void SwTOXBaseSection::UpdatePageNum()
/// of main entry page numbers.
static bool lcl_HasMainEntry( const std::vector<sal_uInt16>* pMainEntryNums, sal_uInt16 nToFind )
{
- for(sal_uInt16 i = 0; pMainEntryNums && i < pMainEntryNums->size(); ++i)
- if(nToFind == (*pMainEntryNums)[i])
+ if (!pMainEntryNums)
+ return false;
+
+ for( auto nMainEntry : *pMainEntryNums )
+ if (nToFind == nMainEntry)
return true;
return false;
}
@@ -1686,7 +1689,6 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
sSrchStr = OUStringBuffer().append(C_NUM_REPL).
append(C_END_PAGE_NUM).makeStringAndClear();
sal_Int32 nEndPos = pNd->GetTxt().indexOf(sSrchStr);
- sal_uInt16 i;
if (-1 == nEndPos || rNums.empty())
return;
@@ -1701,8 +1703,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
GetNumStr( nBeg ) );
if( xCharStyleIdx && lcl_HasMainEntry( pMainEntryNums, nBeg ))
{
- sal_uInt16 nTemp = 0;
- xCharStyleIdx->push_back( nTemp );
+ xCharStyleIdx->push_back( 0 );
}
// Delete place holder
@@ -1724,6 +1725,7 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
}
pNd->EraseText(aPos, nEndPos - nStartPos + 2);
+ std::vector<sal_uInt16>::size_type i;
for( i = 1; i < rNums.size(); ++i)
{
SvxNumberType aType( rDescs[i]->GetNumType() );
@@ -1772,8 +1774,8 @@ void SwTOXBaseSection::_UpdatePageNum( SwTxtNode* pNd,
}
else
{ // Insert all Numbers
- aNumStr += aType.GetNumStr( sal_uInt16(rNums[i]) );
- if(i != (rNums.size()-1))
+ aNumStr += aType.GetNumStr( rNums[i] );
+ if (i+1 != rNums.size())
aNumStr += S_PAGE_DELI;
}
}
@@ -1939,10 +1941,10 @@ Range SwTOXBaseSection::GetKeyRange(const OUString& rStr, const OUString& rStrRe
OSL_ENSURE(rRange.Min() >= 0 && rRange.Max() >= 0, "Min Max < 0");
- const sal_uInt16 nMin = (sal_uInt16)rRange.Min();
- const sal_uInt16 nMax = (sal_uInt16)rRange.Max();
+ const long nMin = rRange.Min();
+ const long nMax = rRange.Max();
- sal_uInt16 i;
+ long i;
for( i = nMin; i < nMax; ++i)
{
@@ -1964,15 +1966,15 @@ Range SwTOXBaseSection::GetKeyRange(const OUString& rStr, const OUString& rStrRe
}
aSortArr.insert(aSortArr.begin() + i, pKey);
}
- sal_uInt16 nStart = i+1;
- sal_uInt16 nEnd = aSortArr.size();
+ const long nStart = i+1;
+ const long nEnd = aSortArr.size();
// Find end of range
- for(i = nStart; i < aSortArr.size(); ++i)
+ for(i = nStart; i < nEnd; ++i)
{
if(aSortArr[i]->GetLevel() <= nLevel)
- { nEnd = i;
- break;
+ {
+ return Range(nStart, i);
}
}
return Range(nStart, nEnd);
commit bf5577fb086b0e6779dc4a6b5a0acc19e960b326
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 19:10:46 2015 +0100
Filled vector already provides nuber of items
But taking advantages of range-for loops is even better
Change-Id: I79c6721ca63482c0ed40dad828ba736eeae92b6c
diff --git a/sw/inc/section.hxx b/sw/inc/section.hxx
index 70b2128..a3080ab 100644
--- a/sw/inc/section.hxx
+++ b/sw/inc/section.hxx
@@ -314,7 +314,7 @@ public:
// All sections that are derived from this one:
// - sorted according to name or position or unsorted
// - all of them or only those that are in the normal Nodes-array.
- sal_uInt16 GetChildSections( SwSections& rArr,
+ void GetChildSections( SwSections& rArr,
SectionSort eSort = SORTSECT_NOT,
bool bAllSections = true ) const;
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 6133106..5b2002b 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -562,10 +562,9 @@ bool SwDoc::DeleteTOX( const SwTOXBase& rTOXBase, bool bDelNodes )
if( !bDelNodes )
{
SwSections aArr( 0 );
- sal_uInt16 nCnt = pFmt->GetChildSections( aArr, SORTSECT_NOT, false );
- for( sal_uInt16 n = 0; n < nCnt; ++n )
+ pFmt->GetChildSections( aArr, SORTSECT_NOT, false );
+ for( const auto pSect : aArr )
{
- SwSection* pSect = aArr[ n ];
if( TOX_HEADER_SECTION == pSect->GetType() )
{
DelSectionFmt( pSect->GetFmt(), bDelNodes );
diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx
index 48b2a21..70bb3b8 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -896,7 +896,7 @@ static bool lcl_SectionCmpNm( const SwSection *pFSect, const SwSection *pSSect)
}
// get all Sections that have been derived from this one
-sal_uInt16 SwSectionFmt::GetChildSections( SwSections& rArr,
+void SwSectionFmt::GetChildSections( SwSections& rArr,
SectionSort eSort,
bool bAllSections ) const
{
@@ -929,7 +929,6 @@ sal_uInt16 SwSectionFmt::GetChildSections( SwSections& rArr,
case SORTSECT_NOT: break;
}
}
- return rArr.size();
}
// See whether the Section is within the Nodes or the UndoNodes array
diff --git a/sw/source/ui/dialog/uiregionsw.cxx b/sw/source/ui/dialog/uiregionsw.cxx
index 9210d30..8f4c712 100644
--- a/sw/source/ui/dialog/uiregionsw.cxx
+++ b/sw/source/ui/dialog/uiregionsw.cxx
@@ -71,14 +71,14 @@ static void lcl_ReadSections( SfxMedium& rMedium, ComboBox& rBox );
static void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAvailNames, const SwSectionFmt* pNewFmt )
{
- const SwSectionFmt* pFmt;
if( !pNewFmt )
{
const sal_uInt16 nCount = rSh.GetSectionFmtCount();
for(sal_uInt16 i=0;i<nCount;i++)
{
SectionType eTmpType;
- if( !(pFmt = &rSh.GetSectionFmt(i))->GetParent() &&
+ const SwSectionFmt* pFmt = &rSh.GetSectionFmt(i);
+ if( !pFmt->GetParent() &&
pFmt->IsInNodesArr() &&
(eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
&& TOX_HEADER_SECTION != eTmpType )
@@ -94,12 +94,14 @@ static void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAva
else
{
SwSections aTmpArr;
- const sal_uInt16 nCnt = pNewFmt->GetChildSections(aTmpArr,SORTSECT_POS);
- if( nCnt )
+ pNewFmt->GetChildSections(aTmpArr, SORTSECT_POS);
+ if( !aTmpArr.empty() )
{
SectionType eTmpType;
- for( sal_uInt16 n = 0; n < nCnt; ++n )
- if( (pFmt = aTmpArr[n]->GetFmt())->IsInNodesArr()&&
+ for( const auto pSect : aTmpArr )
+ {
+ const SwSectionFmt* pFmt = pSect->GetFmt();
+ if( pFmt->IsInNodesArr()&&
(eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
&& TOX_HEADER_SECTION != eTmpType )
{
@@ -109,6 +111,7 @@ static void lcl_FillList( SwWrtShell& rSh, ComboBox& rSubRegions, ComboBox* pAva
rSubRegions.InsertEntry(sString);
lcl_FillList( rSh, rSubRegions, pAvailNames, pFmt );
}
+ }
}
}
}
@@ -438,7 +441,6 @@ bool SwEditRegionDlg::CheckPasswd(CheckBox* pBox)
// recursively look for child-sections
void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pEntry )
{
- SwSection* pSect = 0;
SvTreeListEntry* pSelEntry = 0;
if (!pFmt)
{
@@ -451,8 +453,8 @@ void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pE
(eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
&& TOX_HEADER_SECTION != eTmpType )
{
- SectRepr* pSectRepr = new SectRepr( n,
- *(pSect=pFmt->GetSection()) );
+ SwSection *pSect = pFmt->GetSection();
+ SectRepr* pSectRepr = new SectRepr( n, *pSect );
Image aImg = BuildBitmap( pSect->IsProtect(),pSect->IsHidden());
pEntry = m_pTree->InsertEntry(pSect->GetSectionName(), aImg, aImg);
pEntry->SetUserData(pSectRepr);
@@ -468,18 +470,17 @@ void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pE
{
SwSections aTmpArr;
SvTreeListEntry* pNEntry;
- const sal_uInt16 nCnt = pFmt->GetChildSections(aTmpArr,SORTSECT_POS);
- if( nCnt )
+ pFmt->GetChildSections(aTmpArr, SORTSECT_POS);
+ if( !aTmpArr.empty() )
{
- for( sal_uInt16 n = 0; n < nCnt; ++n )
+ for( const auto pSect : aTmpArr )
{
SectionType eTmpType;
- pFmt = aTmpArr[n]->GetFmt();
+ pFmt = pSect->GetFmt();
if( pFmt->IsInNodesArr() &&
(eTmpType = pFmt->GetSection()->GetType()) != TOX_CONTENT_SECTION
&& TOX_HEADER_SECTION != eTmpType )
{
- pSect=aTmpArr[n];
SectRepr* pSectRepr=new SectRepr(
FindArrPos( pSect->GetFmt() ), *pSect );
Image aImage = BuildBitmap( pSect->IsProtect(),
@@ -487,7 +488,7 @@ void SwEditRegionDlg::RecurseList( const SwSectionFmt* pFmt, SvTreeListEntry* pE
pNEntry = m_pTree->InsertEntry(
pSect->GetSectionName(), aImage, aImage, pEntry);
pNEntry->SetUserData(pSectRepr);
- RecurseList( aTmpArr[n]->GetFmt(), pNEntry );
+ RecurseList( pSect->GetFmt(), pNEntry );
if( pNEntry->HasChildren())
m_pTree->Expand(pNEntry);
if (pCurrSect==pSect)
commit 98cd6327e00e075170f8f9df4893b724a6e857d7
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 12:37:18 2015 +0100
Fix my previous commits
4c80589cf22934b6809f159917a1f8499544f8fc
6d0de28ae04d3386dca0360df28c5317c80fc53c
Change-Id: I965650388530317588b3a591e8b51f162924af36
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 0d1c3e6..edc074a1 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -538,7 +538,7 @@ sal_uInt16 SwRedlineTbl::FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nRet = USHRT_MAX;
if( nSeqNo && nSttPos < size() )
{
- const size_t nEnd = 0;
+ size_t nEnd = 0;
if( nLookahead && nSttPos > nLookahead )
nEnd = nSttPos - nLookahead;
@@ -1562,7 +1562,7 @@ bool SwRangeRedline::operator<( const SwRangeRedline& rCmp ) const
if (*Start() < *rCmp.Start())
return true;
- return *Start() == *rCmp.Start() && *End() < *rCmp.End()
+ return *Start() == *rCmp.Start() && *End() < *rCmp.End();
}
const SwRedlineData & SwRangeRedline::GetRedlineData(sal_uInt16 nPos) const
commit a4704cb0d0a3c4469256c6c5aa10d396b8b52676
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 09:22:13 2015 +0100
Some OUString simplifications
Change-Id: I6bdb45e5a4b84d0c851f07c4063b7d6d58d54a44
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 1d1e7bc..0d1c3e6 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -845,11 +845,7 @@ void SwRedlineData::SetExtraData( const SwRedlineExtraData* pData )
OUString SwRedlineData::GetDescr() const
{
- OUString aResult;
-
- aResult += SW_RES(STR_REDLINE_INSERT + GetType());
-
- return aResult;
+ return SW_RES(STR_REDLINE_INSERT + GetType());
}
SwRangeRedline::SwRangeRedline(RedlineType_t eTyp, const SwPaM& rPam )
@@ -1587,10 +1583,8 @@ const SwRedlineData & SwRangeRedline::GetRedlineData(sal_uInt16 nPos) const
OUString SwRangeRedline::GetDescr(sal_uInt16 nPos)
{
- OUString aResult;
-
// get description of redline data (e.g.: "insert $1")
- aResult = GetRedlineData(nPos).GetDescr();
+ OUString aResult = GetRedlineData(nPos).GetDescr();
SwPaM * pPaM = NULL;
bool bDeletePaM = false;
@@ -1608,11 +1602,9 @@ OUString SwRangeRedline::GetDescr(sal_uInt16 nPos)
}
// replace $1 in description by description of the redlines text
- OUString aTmpStr;
- aTmpStr += SW_RES(STR_START_QUOTE);
- aTmpStr += ShortenString(pPaM->GetTxt(), nUndoStringLength,
- OUString(SW_RES(STR_LDOTS)));
- aTmpStr += SW_RES(STR_END_QUOTE);
+ const OUString aTmpStr = SW_RESSTR(STR_START_QUOTE)
+ + ShortenString(pPaM->GetTxt(), nUndoStringLength, SW_RESSTR(STR_LDOTS))
+ + SW_RESSTR(STR_END_QUOTE);
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, aTmpStr);
commit 7d26404c45576eb5aa8ac18038539f0f7a902fa6
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 09:18:50 2015 +0100
Simplify
Change-Id: I09a9a4f3873fc64f4236d131b091087cadb9cf17
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 3d7c4f7..1d1e7bc 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -288,40 +288,34 @@ bool SwExtraRedlineTbl::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& r
bool SwRedlineTbl::Insert( SwRangeRedline* p, bool bIns )
{
- bool bRet = false;
if( p->HasValidRange() )
{
std::pair<_SwRedlineTbl::const_iterator, bool> rv = insert( p );
size_t nP = rv.first - begin();
- bRet = rv.second;
p->CallDisplayFunc(0, nP);
+ return rv.second;
}
- else if( bIns )
- bRet = InsertWithValidRanges( p );
- else
- {
- OSL_ENSURE( false, "Redline: wrong range" );
- }
- return bRet;
+ if( bIns )
+ return InsertWithValidRanges( p );
+
+ OSL_ENSURE( false, "Redline: wrong range" );
+ return false;
}
bool SwRedlineTbl::Insert( SwRangeRedline* p, sal_uInt16& rP, bool bIns )
{
- bool bRet = false;
if( p->HasValidRange() )
{
std::pair<_SwRedlineTbl::const_iterator, bool> rv = insert( p );
rP = rv.first - begin();
- bRet = rv.second;
p->CallDisplayFunc(0, rP);
+ return rv.second;
}
- else if( bIns )
- bRet = InsertWithValidRanges( p, &rP );
- else
- {
- OSL_ENSURE( false, "Redline: wrong range" );
- }
- return bRet;
+ if( bIns )
+ return InsertWithValidRanges( p, &rP );
+
+ OSL_ENSURE( false, "Redline: wrong range" );
+ return false;
}
bool SwRedlineTbl::InsertWithValidRanges( SwRangeRedline* p, sal_uInt16* pInsPos )
@@ -455,10 +449,11 @@ sal_uInt16 SwRedlineTbl::GetPos(const SwRangeRedline* p) const
bool SwRedlineTbl::Remove( const SwRangeRedline* p )
{
- sal_uInt16 nPos = GetPos(p);
- if (nPos != USHRT_MAX)
- Remove(nPos);
- return nPos != USHRT_MAX;
+ const sal_uInt16 nPos = GetPos(p);
+ if (nPos == USHRT_MAX)
+ return false;
+ Remove(nPos);
+ return true;
}
void SwRedlineTbl::Remove( sal_uInt16 nP )
@@ -732,18 +727,18 @@ void SwRedlineExtraData_Format::Reject( SwPaM& rPam ) const
bool SwRedlineExtraData_Format::operator == ( const SwRedlineExtraData& rCmp ) const
{
- bool nRet = true;
- size_t nEnd = aWhichIds.size();
+ const size_t nEnd = aWhichIds.size();
if( nEnd != static_cast<const SwRedlineExtraData_Format&>(rCmp).aWhichIds.size() )
- nRet = false;
- else
- for( size_t n = 0; n < nEnd; ++n )
- if( static_cast<const SwRedlineExtraData_Format&>(rCmp).aWhichIds[n] != aWhichIds[n])
- {
- nRet = false;
- break;
- }
- return nRet;
+ return false;
+
+ for( size_t n = 0; n < nEnd; ++n )
+ {
+ if( static_cast<const SwRedlineExtraData_Format&>(rCmp).aWhichIds[n] != aWhichIds[n])
+ {
+ return false;
+ }
+ }
+ return true;
}
SwRedlineExtraData_FormattingChanges::SwRedlineExtraData_FormattingChanges( const SfxItemSet* pItemSet )
@@ -1531,8 +1526,8 @@ bool SwRangeRedline::PopData()
sal_uInt16 SwRangeRedline::GetStackCount() const
{
sal_uInt16 nRet = 1;
- for( SwRedlineData* pCur = pRedlineData; pCur->pNext; ++nRet )
- pCur = pCur->pNext;
+ for( SwRedlineData* pCur = pRedlineData; pCur->pNext; pCur = pCur->pNext )
+ ++nRet;
return nRet;
}
@@ -1568,15 +1563,10 @@ bool SwRangeRedline::operator==( const SwRangeRedline& rCmp ) const
bool SwRangeRedline::operator<( const SwRangeRedline& rCmp ) const
{
- bool nResult = false;
-
if (*Start() < *rCmp.Start())
- nResult = true;
- else if (*Start() == *rCmp.Start())
- if (*End() < *rCmp.End())
- nResult = true;
+ return true;
- return nResult;
+ return *Start() == *rCmp.Start() && *End() < *rCmp.End()
}
const SwRedlineData & SwRangeRedline::GetRedlineData(sal_uInt16 nPos) const
commit dfa894f25b3d46f2aa2bb57578f1bf9b548b6eff
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 08:47:53 2015 +0100
Avoid two special values as "whole array" flag
Keep 0, which is used in all call places, and remove the unused (and
data-type sensible) USHRT_MAX
Change-Id: I5258ce0d684723e4cf90444314ef55cc2f826f9d
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 676ac4e..93590f6 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -212,7 +212,7 @@ public:
sal_uInt16 FindPrevOfSeqNo( sal_uInt16 nSttPos ) const;
/** Search next or previous Redline with the same Seq. No.
Search can be restricted via Lookahead.
- Using 0 or USHRT_MAX makes search the whole array. */
+ Using 0 makes search the whole array. */
sal_uInt16 FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nLookahead = 20 ) const;
sal_uInt16 FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index 5c4f228..3d7c4f7 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -496,9 +496,6 @@ void SwRedlineTbl::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
pSh->InvalidateWindows( SwRect( 0, 0, SAL_MAX_INT32, SAL_MAX_INT32 ) );
}
-/// Find the next or preceding Redline with the same seq.no.
-/// We can limit the search using look ahead.
-/// 0 or USHRT_MAX searches the whole array.
sal_uInt16 SwRedlineTbl::FindNextOfSeqNo( sal_uInt16 nSttPos ) const
{
return static_cast<size_t>(nSttPos) + 1 < size()
@@ -512,6 +509,8 @@ sal_uInt16 SwRedlineTbl::FindPrevOfSeqNo( sal_uInt16 nSttPos ) const
: USHRT_MAX;
}
+/// Find the next or preceding Redline with the same seq.no.
+/// We can limit the search using look ahead (0 searches the whole array).
sal_uInt16 SwRedlineTbl::FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nLookahead ) const
{
@@ -519,7 +518,7 @@ sal_uInt16 SwRedlineTbl::FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
if( nSeqNo && nSttPos < size() )
{
size_t nEnd = size();
- if( nLookahead && USHRT_MAX != nLookahead )
+ if( nLookahead )
{
const size_t nTmp = static_cast<size_t>(nSttPos)+ static_cast<size_t>(nLookahead);
if (nTmp < nEnd)
@@ -545,7 +544,7 @@ sal_uInt16 SwRedlineTbl::FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
if( nSeqNo && nSttPos < size() )
{
const size_t nEnd = 0;
- if( nLookahead && USHRT_MAX != nLookahead && nSttPos > nLookahead )
+ if( nLookahead && nSttPos > nLookahead )
nEnd = nSttPos - nLookahead;
++nSttPos;
commit 16fe1b047db11718de9a15f3b24a23fd51ef3a31
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 08:37:07 2015 +0100
Default value of nLookahead is never overridden
Change-Id: I3341b307f56f5bcdde7a667aa3968c1444376705
diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 8768cc0..676ac4e 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -208,11 +208,11 @@ public:
void dumpAsXml(struct _xmlTextWriter* pWriter) const;
+ sal_uInt16 FindNextOfSeqNo( sal_uInt16 nSttPos ) const;
+ sal_uInt16 FindPrevOfSeqNo( sal_uInt16 nSttPos ) const;
/** Search next or previous Redline with the same Seq. No.
Search can be restricted via Lookahead.
Using 0 or USHRT_MAX makes search the whole array. */
- sal_uInt16 FindNextOfSeqNo( sal_uInt16 nSttPos, sal_uInt16 nLookahead = 20 ) const;
- sal_uInt16 FindPrevOfSeqNo( sal_uInt16 nSttPos, sal_uInt16 nLookahead = 20 ) const;
sal_uInt16 FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nLookahead = 20 ) const;
sal_uInt16 FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index cc8c193..5c4f228 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -499,16 +499,16 @@ void SwRedlineTbl::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
/// Find the next or preceding Redline with the same seq.no.
/// We can limit the search using look ahead.
/// 0 or USHRT_MAX searches the whole array.
-sal_uInt16 SwRedlineTbl::FindNextOfSeqNo( sal_uInt16 nSttPos, sal_uInt16 nLookahead ) const
+sal_uInt16 SwRedlineTbl::FindNextOfSeqNo( sal_uInt16 nSttPos ) const
{
return static_cast<size_t>(nSttPos) + 1 < size()
- ? FindNextSeqNo( operator[]( nSttPos )->GetSeqNo(), nSttPos+1, nLookahead )
+ ? FindNextSeqNo( operator[]( nSttPos )->GetSeqNo(), nSttPos+1 )
: USHRT_MAX;
}
-sal_uInt16 SwRedlineTbl::FindPrevOfSeqNo( sal_uInt16 nSttPos, sal_uInt16 nLookahead ) const
+sal_uInt16 SwRedlineTbl::FindPrevOfSeqNo( sal_uInt16 nSttPos ) const
{
- return nSttPos ? FindPrevSeqNo( operator[]( nSttPos )->GetSeqNo(), nSttPos-1, nLookahead )
+ return nSttPos ? FindPrevSeqNo( operator[]( nSttPos )->GetSeqNo(), nSttPos-1 )
: USHRT_MAX;
}
commit 65a87350bc0b69a83a43fe012e2abe6778a17010
Author: Matteo Casalin <matteo.casalin at yahoo.com>
Date: Sun Mar 1 08:11:22 2015 +0100
Use more proper integer types
Change-Id: I8c3ffee5a11c239902b972dd58618db9943c6989
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index dd02534..cc8c193 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -151,7 +151,7 @@ bool SwExtraRedlineTbl::DeleteAllTableRedlines( SwDoc* pDoc, const SwTable& rTab
{
// Redline for this table
const SwRedlineData& aRedlineData = pTableCellRedline->GetRedlineData();
- sal_uInt16 nRedlineType = aRedlineData.GetType();
+ const RedlineType_t nRedlineType = aRedlineData.GetType();
// Check if this redline object type should be deleted
if( USHRT_MAX != nRedlineTypeToDelete && nRedlineTypeToDelete != nRedlineType )
@@ -173,7 +173,7 @@ bool SwExtraRedlineTbl::DeleteAllTableRedlines( SwDoc* pDoc, const SwTable& rTab
{
// Redline for this table
const SwRedlineData& aRedlineData = pTableRowRedline->GetRedlineData();
- sal_uInt16 nRedlineType = aRedlineData.GetType();
+ const RedlineType_t nRedlineType = aRedlineData.GetType();
// Check if this redline object type should be deleted
if( USHRT_MAX != nRedlineTypeToDelete && nRedlineTypeToDelete != nRedlineType )
@@ -222,7 +222,7 @@ bool SwExtraRedlineTbl::DeleteTableRowRedline( SwDoc* pDoc, const SwTableLine& r
{
// Redline for this table row
const SwRedlineData& aRedlineData = pTableRowRedline->GetRedlineData();
- sal_uInt16 nRedlineType = aRedlineData.GetType();
+ const RedlineType_t nRedlineType = aRedlineData.GetType();
// Check if this redline object type should be deleted
if( USHRT_MAX != nRedlineTypeToDelete && nRedlineTypeToDelete != nRedlineType )
@@ -269,7 +269,7 @@ bool SwExtraRedlineTbl::DeleteTableCellRedline( SwDoc* pDoc, const SwTableBox& r
{
// Redline for this table cell
const SwRedlineData& aRedlineData = pTableCellRedline->GetRedlineData();
- sal_uInt16 nRedlineType = aRedlineData.GetType();
+ const RedlineType_t nRedlineType = aRedlineData.GetType();
// Check if this redline object type should be deleted
if( USHRT_MAX != nRedlineTypeToDelete && nRedlineTypeToDelete != nRedlineType )
@@ -501,7 +501,7 @@ void SwRedlineTbl::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL )
/// 0 or USHRT_MAX searches the whole array.
sal_uInt16 SwRedlineTbl::FindNextOfSeqNo( sal_uInt16 nSttPos, sal_uInt16 nLookahead ) const
{
- return nSttPos + 1 < (sal_uInt16)size()
+ return static_cast<size_t>(nSttPos) + 1 < size()
? FindNextSeqNo( operator[]( nSttPos )->GetSeqNo(), nSttPos+1, nLookahead )
: USHRT_MAX;
}
@@ -515,13 +515,18 @@ sal_uInt16 SwRedlineTbl::FindPrevOfSeqNo( sal_uInt16 nSttPos, sal_uInt16 nLookah
sal_uInt16 SwRedlineTbl::FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nLookahead ) const
{
- sal_uInt16 nRet = USHRT_MAX, nEnd;
+ sal_uInt16 nRet = USHRT_MAX;
if( nSeqNo && nSttPos < size() )
{
- nEnd = size();
- if( nLookahead && USHRT_MAX != nLookahead &&
- static_cast<size_t>(nSttPos + nLookahead) < size() )
- nEnd = nSttPos + nLookahead;
+ size_t nEnd = size();
+ if( nLookahead && USHRT_MAX != nLookahead )
+ {
+ const size_t nTmp = static_cast<size_t>(nSttPos)+ static_cast<size_t>(nLookahead);
+ if (nTmp < nEnd)
+ {
+ nEnd = nTmp;
+ }
+ }
for( ; nSttPos < nEnd; ++nSttPos )
if( nSeqNo == operator[]( nSttPos )->GetSeqNo() )
@@ -536,10 +541,10 @@ sal_uInt16 SwRedlineTbl::FindNextSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 SwRedlineTbl::FindPrevSeqNo( sal_uInt16 nSeqNo, sal_uInt16 nSttPos,
sal_uInt16 nLookahead ) const
{
- sal_uInt16 nRet = USHRT_MAX, nEnd;
+ sal_uInt16 nRet = USHRT_MAX;
if( nSeqNo && nSttPos < size() )
{
- nEnd = 0;
+ const size_t nEnd = 0;
if( nLookahead && USHRT_MAX != nLookahead && nSttPos > nLookahead )
nEnd = nSttPos - nLookahead;
@@ -587,7 +592,7 @@ void SwRedlineTbl::dumpAsXml(xmlTextWriterPtr pWriter) const
xmlTextWriterStartElement(pWriter, BAD_CAST("swRedlineTbl"));
xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
- for (sal_uInt16 nCurRedlinePos = 0; nCurRedlinePos < size(); ++nCurRedlinePos)
+ for (SwRedlineTbl::size_type nCurRedlinePos = 0; nCurRedlinePos < size(); ++nCurRedlinePos)
operator[](nCurRedlinePos)->dumpAsXml(pWriter);
xmlTextWriterEndElement(pWriter);
@@ -1312,7 +1317,7 @@ void SwRangeRedline::DelCopyOfSection(size_t nMyPos)
// bDelLastPara condition above), only redlines before the
// current ones can be affected.
const SwRedlineTbl& rTbl = pDoc->getIDocumentRedlineAccess().GetRedlineTbl();
- sal_uInt16 n = nMyPos;
+ size_t n = nMyPos;
OSL_ENSURE( n != USHRT_MAX, "How strange. We don't exist!" );
for( bool bBreak = false; !bBreak && n > 0; )
{
More information about the Libreoffice-commits
mailing list