From 00d74a5e0291a40e532b2a0f51fdd5a3e1f487ed Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Wed, 11 Aug 2021 17:36:12 +0300 Subject: Use more o3tl::convert in sc Change-Id: I624b6c570eff8b6cdc83ffcb2d0dbadf848715b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120330 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- sc/source/ui/docshell/docsh4.cxx | 12 ++++++------ sc/source/ui/inc/printfun.hxx | 4 ++-- sc/source/ui/unoobj/docuno.cxx | 8 ++++---- sc/source/ui/view/output2.cxx | 1 + sc/source/ui/view/printfun.cxx | 5 ++--- sc/source/ui/view/viewdata.cxx | 1 + 6 files changed, 16 insertions(+), 15 deletions(-) (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 1c32a670baf1..289c66f756d9 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -1692,7 +1692,7 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange ) tools::Long nBlkTwipsX = 0; if (bHeaders) - nBlkTwipsX += tools::Long(PRINT_HEADER_WIDTH); + nBlkTwipsX += PRINT_HEADER_WIDTH; SCCOL nStartCol = rRange.aStart.Col(); SCCOL nEndCol = rRange.aEnd.Col(); if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() ) @@ -1710,7 +1710,7 @@ bool ScDocShell::AdjustPrintZoom( const ScRange& rRange ) tools::Long nBlkTwipsY = 0; if (bHeaders) - nBlkTwipsY += tools::Long(PRINT_HEADER_HEIGHT); + nBlkTwipsY += PRINT_HEADER_HEIGHT; SCROW nStartRow = rRange.aStart.Row(); SCROW nEndRow = rRange.aEnd.Row(); if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() ) @@ -2259,7 +2259,7 @@ namespace { tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCCOL& rStartCol ) { SCCOL nCol = 0; - tools::Long nTwips = static_cast(nVal / HMM_PER_TWIPS); + tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip); tools::Long nSnap = 0; while ( nCol( nSnap * HMM_PER_TWIPS ); + nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100); rStartCol = nCol; return nVal; } @@ -2281,7 +2281,7 @@ tools::Long SnapHorizontal( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, SCROW& rStartRow ) { SCROW nRow = 0; - tools::Long nTwips = static_cast(nVal / HMM_PER_TWIPS); + tools::Long nTwips = o3tl::convert(nVal, o3tl::Length::mm100, o3tl::Length::twip); tools::Long nSnap = 0; bool bFound = false; @@ -2310,7 +2310,7 @@ tools::Long SnapVertical( const ScDocument& rDoc, SCTAB nTab, tools::Long nVal, if (!bFound) nRow = rDoc.MaxRow(); // all hidden down to the bottom - nVal = static_cast( nSnap * HMM_PER_TWIPS ); + nVal = o3tl::convert(nSnap, o3tl::Length::twip, o3tl::Length::mm100); rStartRow = nRow; return nVal; } diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx index 9ad5c27e547b..b58acd9f4c52 100644 --- a/sc/source/ui/inc/printfun.hxx +++ b/sc/source/ui/inc/printfun.hxx @@ -42,8 +42,8 @@ class FmFormView; #define RANGENO_NORANGE USHRT_MAX -#define PRINT_HEADER_WIDTH (1.0 * TWIPS_PER_CM) -#define PRINT_HEADER_HEIGHT (12.8 * TWIPS_PER_POINT) +constexpr sal_Int64 PRINT_HEADER_WIDTH = o3tl::toTwips(1, o3tl::Length::cm); +constexpr sal_Int64 PRINT_HEADER_HEIGHT = o3tl::toTwips(12.8, o3tl::Length::pt); // Settings for headers/footers struct ScPrintHFParam diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 11016aafb202..162eb706c1ae 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -533,8 +533,8 @@ void ScModelObj::paintTile( VirtualDevice& rDevice, return; ScViewData* pActiveViewData = &pViewShell->GetViewData(); - Fraction aFracX(tools::Long(nOutputWidth * TWIPS_PER_PIXEL), nTileWidth); - Fraction aFracY(tools::Long(nOutputHeight * TWIPS_PER_PIXEL), nTileHeight); + Fraction aFracX(o3tl::toTwips(nOutputWidth, o3tl::Length::px), nTileWidth); + Fraction aFracY(o3tl::toTwips(nOutputHeight, o3tl::Length::px), nTileHeight); // Try to find a view that matches the tile-zoom requested by iterating over // first few shells. This is to avoid switching of zooms in ScGridWindow::PaintTile @@ -980,8 +980,8 @@ void ScModelObj::setClientZoom(int nTilePixelWidth_, int nTilePixelHeight_, int // Doing this in ScTabViewShell init code does not work because callbacks do not work at that point for the first view. lcl_sendLOKDocumentBackground(pViewData); - const Fraction newZoomX(nTilePixelWidth_ * TWIPS_PER_PIXEL, nTileTwipWidth_); - const Fraction newZoomY(nTilePixelHeight_ * TWIPS_PER_PIXEL, nTileTwipHeight_); + const Fraction newZoomX(o3tl::toTwips(nTilePixelWidth_, o3tl::Length::px), nTileTwipWidth_); + const Fraction newZoomY(o3tl::toTwips(nTilePixelHeight_, o3tl::Length::px), nTileTwipHeight_); if (pViewData->GetZoomX() == newZoomX && pViewData->GetZoomY() == newZoomY) return; diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx index 8da5ec78118a..31b0076bc0bc 100644 --- a/sc/source/ui/view/output2.cxx +++ b/sc/source/ui/view/output2.cxx @@ -91,6 +91,7 @@ using namespace com::sun::star; #define DRAWTEXT_MAX 32767 const sal_uInt16 SC_SHRINKAGAIN_MAX = 7; +constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); class ScDrawStringsVars { diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx index eb7de664694b..ccd015552074 100644 --- a/sc/source/ui/view/printfun.cxx +++ b/sc/source/ui/view/printfun.cxx @@ -1564,9 +1564,7 @@ void ScPrintFunc::LocateArea( SCCOL nX1, SCROW nY1, SCCOL nX2, SCROW nY2, aTwipOffset.AdjustX( -(rDoc.GetColWidth( nCol, nPrintTab )) ); aTwipOffset.AdjustY( -sal_Int32(rDoc.GetRowHeight( 0, nY1-1, nPrintTab )) ); - Point aMMOffset( aTwipOffset ); - aMMOffset.setX( static_cast(aMMOffset.X() * HMM_PER_TWIPS) ); - aMMOffset.setY( static_cast(aMMOffset.Y() * HMM_PER_TWIPS) ); + Point aMMOffset(o3tl::convert(aTwipOffset, o3tl::Length::twip, o3tl::Length::mm100)); aMMOffset += Point( nLogStX, nLogStY ); MapMode aDrawMapMode( MapUnit::Map100thMM, aMMOffset, aLogicMode.GetScaleX(), aLogicMode.GetScaleY() ); @@ -2597,6 +2595,7 @@ void ScPrintFunc::InitModes() // set MapModes from nZoom etc. aOffset = Point( aSrcOffset.X()*100/nZoom, aSrcOffset.Y()*100/nZoom ); tools::Long nEffZoom = nZoom * static_cast(nManualZoom); + constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); nScaleX = nScaleY = HMM_PER_TWIPS; // output in 1/100 mm Fraction aZoomFract( nEffZoom,10000 ); diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index d4b4092291a1..6ac95430a84e 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -1730,6 +1730,7 @@ void ScViewData::SetEditEngine( ScSplitPos eWhich, // (and same line breaks) as for output. Fraction aFract(1,1); + constexpr auto HMM_PER_TWIPS = o3tl::convert(1.0, o3tl::Length::twip, o3tl::Length::mm100); tools::Rectangle aUtilRect = ScEditUtil(&mrDoc, nNewX, nNewY, nTabNo, Point(0, 0), pWin->GetOutDev(), HMM_PER_TWIPS, HMM_PER_TWIPS, aFract, aFract ).GetEditArea( pPattern, false ); aPaperSize.setWidth( aUtilRect.GetWidth() ); -- cgit