summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel <noelgrandin@gmail.com>2020-11-12 15:38:13 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-11-16 07:53:49 +0100
commitbf4bbc3c2174b21577b8878bc3197923ba44a029 (patch)
tree22ec4b4da1bc2b86b6b27776fd64fd2b89a9ed3e /sc
parentb977a8786ff39f1348bafdbf2dd83e7008ed3086 (diff)
replace std::max(std::min()) with std::clamp
Change-Id: I890d19f5e2177294dc1175c90c98b964347f9e85 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105751 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/documen7.cxx4
-rw-r--r--sc/source/core/data/postit.cxx4
-rw-r--r--sc/source/core/data/table1.cxx2
-rw-r--r--sc/source/filter/html/htmlpars.cxx2
-rw-r--r--sc/source/filter/inc/ftools.hxx3
-rw-r--r--sc/source/ui/dbgui/csvgrid.cxx2
-rw-r--r--sc/source/ui/dbgui/csvruler.cxx2
-rw-r--r--sc/source/ui/docshell/impex.cxx12
-rw-r--r--sc/source/ui/inc/csvtablebox.hxx4
9 files changed, 18 insertions, 17 deletions
diff --git a/sc/source/core/data/documen7.cxx b/sc/source/core/data/documen7.cxx
index 747b3e46997f..d56cea74f3f5 100644
--- a/sc/source/core/data/documen7.cxx
+++ b/sc/source/core/data/documen7.cxx
@@ -106,8 +106,8 @@ bool ScDocument::LimitRangeToAvailableSheets( const ScRange& rRange, ScRange& o_
// Limit the sheet range to bounds.
o_bEntirelyOutOfBounds = false;
- nTab1 = std::max<SCTAB>( 0, std::min( nMaxTab, nTab1));
- nTab2 = std::max<SCTAB>( 0, std::min( nMaxTab, nTab2));
+ nTab1 = std::clamp<SCTAB>( nTab1, 0, nMaxTab);
+ nTab2 = std::clamp<SCTAB>( nTab2, 0, nMaxTab);
o_rRange = rRange;
o_rRange.aStart.SetTab(nTab1);
o_rRange.aEnd.SetTab(nTab2);
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index a5fe92ca91a0..bafd2e9e901b 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -237,8 +237,8 @@ void ScCaptionCreator::FitCaptionToRect( const tools::Rectangle* pVisRect )
// tail position
Point aTailPos = mxCaption->GetTailPos();
- aTailPos.setX( ::std::max( ::std::min( aTailPos.X(), rVisRect.Right() ), rVisRect.Left() ) );
- aTailPos.setY( ::std::max( ::std::min( aTailPos.Y(), rVisRect.Bottom() ), rVisRect.Top() ) );
+ aTailPos.setX( ::std::clamp( aTailPos.X(), rVisRect.Left(), rVisRect.Right() ) );
+ aTailPos.setY( ::std::clamp( aTailPos.Y(), rVisRect.Top(), rVisRect.Bottom() ) );
mxCaption->SetTailPos( aTailPos );
// caption rectangle
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 79638f5ffa31..d0451b4f2542 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1164,7 +1164,7 @@ void ScTable::LimitChartArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol
SCROW lastDataPos = 0;
for (SCCOL i=rStartCol; i<=rEndCol; i++)
lastDataPos = std::max(lastDataPos, aCol[i].GetLastDataPos());
- rEndRow = std::max( rStartRow, std::min(rEndRow, lastDataPos));
+ rEndRow = std::clamp( rEndRow, rStartRow, lastDataPos );
}
SCCOL ScTable::FindNextVisibleCol( SCCOL nCol, bool bRight ) const
diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx
index 5490c494fff0..315d180b82af 100644
--- a/sc/source/filter/html/htmlpars.cxx
+++ b/sc/source/filter/html/htmlpars.cxx
@@ -1640,7 +1640,7 @@ void ScHTMLLayoutParser::ProcToken( HtmlImportInfo* pInfo )
template< typename Type >
static Type getLimitedValue( const Type& rValue, const Type& rMin, const Type& rMax )
-{ return std::max( std::min( rValue, rMax ), rMin ); }
+{ return std::clamp( rValue, rMin, rMax ); }
ScHTMLEntry::ScHTMLEntry( const SfxItemSet& rItemSet, ScHTMLTableId nTableId ) :
ScEEParseEntry( rItemSet ),
diff --git a/sc/source/filter/inc/ftools.hxx b/sc/source/filter/inc/ftools.hxx
index be871273486b..dc216a502cb2 100644
--- a/sc/source/filter/inc/ftools.hxx
+++ b/sc/source/filter/inc/ftools.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_SC_SOURCE_FILTER_INC_FTOOLS_HXX
#define INCLUDED_SC_SOURCE_FILTER_INC_FTOOLS_HXX
+#include <algorithm>
#include <vector>
#include <limits>
#include <tools/ref.hxx>
@@ -59,7 +60,7 @@ inline ReturnType ulimit_cast( Type nValue )
/** Returns the value, if it is not less than nMin and not greater than nMax, otherwise one of the limits. */
template< typename ReturnType, typename Type >
inline ReturnType limit_cast( Type nValue, ReturnType nMin, ReturnType nMax )
-{ return static_cast< ReturnType >( ::std::max< Type >( ::std::min< Type >( nValue, nMax ), nMin ) ); }
+{ return static_cast< ReturnType >( ::std::clamp< Type >( nValue, nMin, nMax ) ); }
/** Returns the value, if it fits into ReturnType, otherwise one of the limits of ReturnType. */
template< typename ReturnType, typename Type >
diff --git a/sc/source/ui/dbgui/csvgrid.cxx b/sc/source/ui/dbgui/csvgrid.cxx
index 056bf4022a11..1fd2cea6de69 100644
--- a/sc/source/ui/dbgui/csvgrid.cxx
+++ b/sc/source/ui/dbgui/csvgrid.cxx
@@ -929,7 +929,7 @@ bool ScCsvGrid::MouseMove( const MouseEvent& rMEvt )
sal_Int32 nPos = (rMEvt.GetPosPixel().X() - GetFirstX()) / GetCharWidth() + GetFirstVisPos();
// on mouse tracking: keep position valid
- nPos = std::max( std::min( nPos, GetPosCount() - sal_Int32( 1 ) ), sal_Int32( 0 ) );
+ nPos = std::clamp( nPos, sal_Int32(0), GetPosCount() - 1 );
Execute( CSVCMD_MAKEPOSVISIBLE, nPos );
sal_uInt32 nColIx = GetColumnFromPos( nPos );
diff --git a/sc/source/ui/dbgui/csvruler.cxx b/sc/source/ui/dbgui/csvruler.cxx
index 94e733ee7c1b..95e042290185 100644
--- a/sc/source/ui/dbgui/csvruler.cxx
+++ b/sc/source/ui/dbgui/csvruler.cxx
@@ -432,7 +432,7 @@ bool ScCsvRuler::MouseMove( const MouseEvent& rMEvt )
if( mbTracking )
{
// on mouse tracking: keep position valid
- nPos = std::max( std::min( nPos, GetPosCount() - sal_Int32( 1 ) ), sal_Int32( 1 ) );
+ nPos = std::clamp( nPos, sal_Int32(1), GetPosCount() - 1 );
MoveMouseTracking( nPos );
}
else
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 8b09e45b3ba8..4db43588af50 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1825,7 +1825,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
if (bFail || nCol < 0 || rDoc.MaxCol() < nCol)
{
SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;X invalid nCol=" << nCol);
- nCol = std::max<SCCOL>(0, std::min<SCCOL>(nCol, rDoc.MaxCol()));
+ nCol = std::clamp<SCCOL>(nCol, 0, rDoc.MaxCol());
bInvalidCol = bOverflowCol = true;
}
break;
@@ -1837,7 +1837,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
if (bFail || nRow < 0 || nMaxImportRow < nRow)
{
SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;Y invalid nRow=" << nRow);
- nRow = std::max<SCROW>(0, std::min<SCROW>(nRow, nMaxImportRow));
+ nRow = std::clamp<SCROW>(nRow, 0, nMaxImportRow);
bInvalidRow = bOverflowRow = true;
}
break;
@@ -1849,7 +1849,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
if (bFail || nRefCol < 0 || rDoc.MaxCol() < nRefCol)
{
SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;C invalid nRefCol=" << nRefCol);
- nRefCol = std::max<SCCOL>(0, std::min<SCCOL>(nRefCol, rDoc.MaxCol()));
+ nRefCol = std::clamp<SCCOL>(nRefCol, 0, rDoc.MaxCol());
bInvalidRefCol = bOverflowCol = true;
}
break;
@@ -1861,7 +1861,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
if (bFail || nRefRow < 0 || nMaxImportRow < nRefRow)
{
SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;R invalid nRefRow=" << nRefRow);
- nRefRow = std::max<SCROW>(0, std::min<SCROW>(nRefRow, nMaxImportRow));
+ nRefRow = std::clamp<SCROW>(nRefRow, 0, nMaxImportRow);
bInvalidRefRow = bOverflowRow = true;
}
break;
@@ -1986,7 +1986,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
if (bFail || nCol < 0 || rDoc.MaxCol() < nCol)
{
SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;X invalid nCol=" << nCol);
- nCol = std::max<SCCOL>(0, std::min<SCCOL>(nCol, rDoc.MaxCol()));
+ nCol = std::clamp<SCCOL>(nCol, 0, rDoc.MaxCol());
bInvalidCol = bOverflowCol = true;
}
break;
@@ -1998,7 +1998,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm )
if (bFail || nRow < 0 || nMaxImportRow < nRow)
{
SAL_WARN("sc.ui","ScImportExport::Sylk2Doc - ;Y invalid nRow=" << nRow);
- nRow = std::max<SCROW>(0, std::min<SCROW>(nRow, nMaxImportRow));
+ nRow = std::clamp<SCROW>(nRow, 0, nMaxImportRow);
bInvalidRow = bOverflowRow = true;
}
break;
diff --git a/sc/source/ui/inc/csvtablebox.hxx b/sc/source/ui/inc/csvtablebox.hxx
index 67506f1604ba..28c0f362c7b2 100644
--- a/sc/source/ui/inc/csvtablebox.hxx
+++ b/sc/source/ui/inc/csvtablebox.hxx
@@ -92,10 +92,10 @@ private:
/** Calculates and sets valid position offset nearest to nPos. */
SAL_DLLPRIVATE void ImplSetPosOffset( sal_Int32 nPos )
- { maData.mnPosOffset = std::max( std::min( nPos, mxGrid->GetMaxPosOffset() ), sal_Int32( 0 ) ); }
+ { maData.mnPosOffset = std::clamp( nPos, sal_Int32(0), mxGrid->GetMaxPosOffset() ); }
/** Calculates and sets valid line offset nearest to nLine. */
SAL_DLLPRIVATE void ImplSetLineOffset( sal_Int32 nLine )
- { maData.mnLineOffset = std::max( std::min( nLine, mxGrid->GetMaxLineOffset() ), sal_Int32( 0 ) ); }
+ { maData.mnLineOffset = std::clamp( nLine, sal_Int32(0), mxGrid->GetMaxLineOffset() ); }
/** Moves controls (not cursors!) so that nPos becomes visible. */
SAL_DLLPRIVATE void MakePosVisible( sal_Int32 nPos );