replace std::min(std::max()) with std::clamp

Change-Id: I76e34e8020d98292e8ffde387542b7029f85a42d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105754
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/avmedia/source/framework/MediaControlBase.cxx b/avmedia/source/framework/MediaControlBase.cxx
index 7c3450d..60faa27 100644
--- a/avmedia/source/framework/MediaControlBase.cxx
+++ b/avmedia/source/framework/MediaControlBase.cxx
@@ -27,7 +27,7 @@

using ::rtl::OUString;

#define AVMEDIA_DB_RANGE            -40
constexpr sal_Int32 AVMEDIA_DB_RANGE = -40;
#define AVMEDIA_LINEINCREMENT       1.0
#define AVMEDIA_PAGEINCREMENT       10.0

@@ -64,8 +64,7 @@ void MediaControlBase::UpdateVolumeSlider( MediaItem const & aMediaItem )
    {
        mxVolumeSlider->set_sensitive(true);
        const sal_Int32 nVolumeDB = aMediaItem.getVolumeDB();
        mxVolumeSlider->set_value( std::min( std::max( nVolumeDB, static_cast< sal_Int32 >( AVMEDIA_DB_RANGE ) ),
                                                static_cast< sal_Int32 >( 0 ) ) );
        mxVolumeSlider->set_value( std::clamp( nVolumeDB, sal_Int32(0), AVMEDIA_DB_RANGE ) );
    }
}

diff --git a/basegfx/source/polygon/b3dpolypolygontools.cxx b/basegfx/source/polygon/b3dpolypolygontools.cxx
index 3badd68..ad2dd5b 100644
--- a/basegfx/source/polygon/b3dpolypolygontools.cxx
+++ b/basegfx/source/polygon/b3dpolypolygontools.cxx
@@ -221,7 +221,7 @@ namespace basegfx::utils
            }

            // min/max limitations
            nHorSeg = std::min(nMaxSegments, std::max(nMinSegments, nHorSeg));
            nHorSeg = std::clamp(nHorSeg, nMinSegments, nMaxSegments);

            if(!nVerSeg)
            {
@@ -229,7 +229,7 @@ namespace basegfx::utils
            }

            // min/max limitations
            nVerSeg = std::min(nMaxSegments, std::max(nMinSegments, nVerSeg));
            nVerSeg = std::clamp(nVerSeg, nMinSegments, nMaxSegments);

            // create constants
            const double fVerDiffPerStep((fVerStop - fVerStart) / static_cast<double>(nVerSeg));
@@ -320,7 +320,7 @@ namespace basegfx::utils
            }

            // min/max limitations
            nHorSeg = std::min(nMaxSegments, std::max(nMinSegments, nHorSeg));
            nHorSeg = std::clamp(nHorSeg, nMinSegments, nMaxSegments);

            if(!nVerSeg)
            {
@@ -328,7 +328,7 @@ namespace basegfx::utils
            }

            // min/max limitations
            nVerSeg = std::min(nMaxSegments, std::max(nMinSegments, nVerSeg));
            nVerSeg = std::clamp(nVerSeg, nMinSegments, nMaxSegments);

            // vertical loop
            for(sal_uInt32 a(0); a < nVerSeg; a++)
diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx
index dc9e0ab..d07442b 100644
--- a/comphelper/source/misc/backupfilehelper.cxx
+++ b/comphelper/source/misc/backupfilehelper.cxx
@@ -1558,7 +1558,7 @@ namespace comphelper
            const sal_uInt16 nConfigNumCopies(static_cast<sal_uInt16>(sTokenOut.toUInt32()));

            // limit to range [1..mnMaxAllowedBackups]
            mnNumBackups = std::min(std::max(nConfigNumCopies, mnNumBackups), mnMaxAllowedBackups);
            mnNumBackups = std::clamp(mnNumBackups, nConfigNumCopies, mnMaxAllowedBackups);
        }

        if (mbActive && rtl::Bootstrap::get("SecureUserConfigMode", sTokenOut))
diff --git a/include/oox/helper/helper.hxx b/include/oox/helper/helper.hxx
index 9d6befb..da28c88 100644
--- a/include/oox/helper/helper.hxx
+++ b/include/oox/helper/helper.hxx
@@ -108,7 +108,7 @@ const sal_Int8 API_ESCAPEHEIGHT_DEFAULT     = 58;       ///< Relative character 
template< typename ReturnType, typename Type >
inline ReturnType getLimitedValue( Type nValue, Type nMin, Type nMax )
{
    return static_cast< ReturnType >( ::std::min( ::std::max( nValue, nMin ), nMax ) );
    return static_cast< ReturnType >( ::std::clamp( nValue, nMin, nMax ) );
}

template< typename ReturnType, typename Type >
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 491f79e..5f9a35b 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -4113,7 +4113,7 @@ void ChartExport::exportMarker(const Reference< XPropertySet >& xPropSet)

        nSize = nSize/250.0*7.0 + 1; // just guessed based on some test cases,
        //the value is always 1 less than the actual value.
        nSize = std::min<sal_Int32>( 72, std::max<sal_Int32>( 2, nSize ) );
        nSize = std::clamp( int(nSize), 2, 72 );
        pFS->singleElement(FSNS(XML_c, XML_size), XML_val, OString::number(nSize));

        pFS->startElement(FSNS(XML_c, XML_spPr));
diff --git a/sc/source/filter/excel/xltools.cxx b/sc/source/filter/excel/xltools.cxx
index 8654ed5..ca0aeb2 100644
--- a/sc/source/filter/excel/xltools.cxx
+++ b/sc/source/filter/excel/xltools.cxx
@@ -274,7 +274,7 @@ XclBoolError XclTools::ErrorToEnum( double& rfDblValue, bool bErrOrBool, sal_uIn
sal_uInt16 XclTools::GetTwipsFromInch( double fInches )
{
    return static_cast< sal_uInt16 >(
        ::std::min( ::std::max( (fInches * EXC_TWIPS_PER_INCH + 0.5), 0.0 ), 65535.0 ) );
        ::std::clamp( fInches * EXC_TWIPS_PER_INCH + 0.5, 0.0, 65535.0 ) );
}

sal_uInt16 XclTools::GetTwipsFromHmm( sal_Int32 nHmm )
diff --git a/sc/source/ui/Accessibility/AccessibleCsvControl.cxx b/sc/source/ui/Accessibility/AccessibleCsvControl.cxx
index b16095d..5842675 100644
--- a/sc/source/ui/Accessibility/AccessibleCsvControl.cxx
+++ b/sc/source/ui/Accessibility/AccessibleCsvControl.cxx
@@ -391,7 +391,7 @@ sal_Int32 SAL_CALL ScAccessibleCsvRuler::getIndexAtPoint( const css::awt::Point&
    ensureAlive();
    ScCsvRuler& rRuler = implGetRuler();
    // use object's coordinate system, convert to API position
    return lcl_GetApiPos( ::std::min( ::std::max( rRuler.GetPosFromX( rPoint.X ), static_cast<sal_Int32>(0) ), rRuler.GetPosCount() ) );
    return lcl_GetApiPos( ::std::clamp( rRuler.GetPosFromX( rPoint.X ), sal_Int32(0), rRuler.GetPosCount() ) );
}

OUString SAL_CALL ScAccessibleCsvRuler::getSelectedText()
diff --git a/sdext/source/presenter/PresenterScrollBar.cxx b/sdext/source/presenter/PresenterScrollBar.cxx
index 6aab458..d811c92 100644
--- a/sdext/source/presenter/PresenterScrollBar.cxx
+++ b/sdext/source/presenter/PresenterScrollBar.cxx
@@ -659,7 +659,7 @@ void PresenterVerticalScrollBar::UpdateBorders()
    else
    {
        const double nThumbSize = ::std::min(mnThumbSize,mnTotalSize);
        const double nThumbPosition = ::std::min(::std::max(0.0,mnThumbPosition), mnTotalSize - nThumbSize);
        const double nThumbPosition = ::std::clamp(mnThumbPosition, 0.0, mnTotalSize - nThumbSize);
        maBox[Thumb] = geometry::RealRectangle2D(
            0, nThumbPosition / mnTotalSize * nPagerHeight,
            aWindowBox.Width,
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 9bf6a30..abd8323 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -575,7 +575,7 @@ void SmGraphicWindow::Command(const CommandEvent& rCEvt)

void SmGraphicWindow::SetZoom(sal_uInt16 Factor)
{
    nZoom = std::min(std::max(Factor, MINZOOM), MAXZOOM);
    nZoom = std::clamp(Factor, MINZOOM, MAXZOOM);
    Fraction   aFraction (nZoom, 100);
    SetMapMode( MapMode(MapUnit::Map100thMM, Point(), aFraction, aFraction) );
    SetTotalSize();
diff --git a/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx
index aaa0f3d..76af6c2 100644
--- a/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx
+++ b/svx/source/sdr/primitive2d/sdrframeborderprimitive2d.cxx
@@ -458,7 +458,7 @@ namespace
                            nBaseIndex = bUpper ? nVisEdgeUp : nVisEdgeDn;
                        }

                        const size_t nSecuredIndex(std::min(nNumCutSets - 1, std::max(nBaseIndex, static_cast< size_t >(0))));
                        const size_t nSecuredIndex(std::clamp(nBaseIndex, size_t(0), size_t(nNumCutSets - 1)));
                        const CutSet& rCutSet(aCutSets[nSecuredIndex]);
                        ExtendSet& rExt(rExtendSet[my]);

diff --git a/svx/source/table/tablehandles.cxx b/svx/source/table/tablehandles.cxx
index 222624c..4322bf2 100644
--- a/svx/source/table/tablehandles.cxx
+++ b/svx/source/table/tablehandles.cxx
@@ -86,7 +86,7 @@ PointerStyle TableEdgeHdl::GetPointer() const

sal_Int32 TableEdgeHdl::GetValidDragOffset( const SdrDragStat& rDrag ) const
{
    return std::min( std::max( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin ), mnMax );
    return std::clamp( static_cast<sal_Int32>(mbHorizontal ? rDrag.GetDY() : rDrag.GetDX()), mnMin, mnMax );
}

basegfx::B2DPolyPolygon TableEdgeHdl::getSpecialDragPoly(const SdrDragStat& rDrag) const
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index c389b4d..3bd8b72 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3049,7 +3049,7 @@ namespace

sal_uInt16 lcl_BoundListLevel(const int nActualLevel)
{
    return static_cast<sal_uInt16>( std::min( std::max(nActualLevel, 0), MAXLEVEL-1 ) );
    return static_cast<sal_uInt16>( std::clamp( nActualLevel, 0, MAXLEVEL-1 ) );
}

}
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index dd6c556..6d02526 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -529,7 +529,7 @@ static Graphic ImpGetScaledGraphic( const Graphic& rGraphic, FilterConfigItem& r
                MapMode     aMap( MapUnit::Map100thInch );

                sal_Int32   nDPI = rConfigItem.ReadInt32( "Resolution", 75 );
                Fraction    aFrac( 1, std::min( std::max( nDPI, sal_Int32( 75 ) ), sal_Int32( 600 ) ) );
                Fraction    aFrac( 1, std::clamp( nDPI, sal_Int32(75), sal_Int32(600) ) );

                aMap.SetScaleX( aFrac );
                aMap.SetScaleY( aFrac );
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 7a6615f..7d3d648 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1361,7 +1361,7 @@ void OutputDevice::DrawTransformedBitmapEx(
    const Size& rOriginalSizePixel(rBitmapEx.GetSizePixel());
    const double fOrigArea(rOriginalSizePixel.Width() * rOriginalSizePixel.Height() * 0.5);
    const double fOrigAreaScaled(fOrigArea * 1.44);
    double fMaximumArea(std::min(4500000.0, std::max(1000000.0, fOrigAreaScaled)));
    double fMaximumArea(std::clamp(fOrigAreaScaled, 1000000.0, 4500000.0));
    // tdf#130768 CAUTION(!) using GetViewTransformation() is *not* enough here, it may
    // be that mnOutOffX/mnOutOffY is used - see AOO bug 75163, mentioned at
    // ImplGetDeviceTransformation declaration