basegfx/source/tools/zoomtools.cxx     |   16 ++++++++--------
 include/basegfx/utils/zoomtools.hxx    |    5 ++---
 sc/inc/global.hxx                      |    4 ++--
 sc/source/ui/view/prevwsh.cxx          |   10 +++++-----
 sc/source/ui/view/tabview.cxx          |    8 ++++----
 sc/source/ui/view/tabvwsh3.cxx         |    8 ++++----
 sd/source/ui/view/viewshel.cxx         |    8 ++++----
 svx/source/stbctrls/zoomsliderctrl.cxx |    4 ++--
 sw/source/uibase/uiview/view2.cxx      |    2 +-
 sw/source/uibase/uiview/viewport.cxx   |    6 +++---
 10 files changed, 35 insertions(+), 36 deletions(-)

New commits:
commit ac2a6ee9618e377806e529ed641f67e88684f7e7
Author:     Chris Sherlock <chris.sherloc...@gmail.com>
AuthorDate: Mon Jun 13 17:20:15 2022 +1000
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Wed Jul 13 18:54:28 2022 +0200

    basegfx: zoomIn() and zoomOut() should be sal_uInt16
    
    All zoom functions use sal_uInt16 values. For some reason, basegfx used
    long when zoomIn and zoomOut were created in 2012 (see commit
    315d2ddc16: "optimized zoom to use more common intervals"), this then
    got mass converted to tools::Long in commit 387a88fa25: "use tools::Long
    in basegfx..chart2".
    
    So fix is to change zoomIn/Out() to use sal_uInt16.
    
    Change-Id: I2a56d6f58e14f77aeb8741d332fe9bc282eb969f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135715
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/basegfx/source/tools/zoomtools.cxx 
b/basegfx/source/tools/zoomtools.cxx
index 4fedb8ee848c..dd4c7a6cbbd3 100644
--- a/basegfx/source/tools/zoomtools.cxx
+++ b/basegfx/source/tools/zoomtools.cxx
@@ -26,7 +26,7 @@ const double ZOOM_FACTOR = 1.12246205;
 * @param nCurrent current value
 * @param nMultiple multiple against which the current value is rounded
 */
-static tools::Long roundMultiple(tools::Long nCurrent, int nMultiple)
+static sal_uInt16 roundMultiple(sal_uInt16 nCurrent, int nMultiple)
 {
     // round zoom to a multiple of nMultiple
     return (( nCurrent + nMultiple / 2 ) - ( nCurrent + nMultiple / 2 ) % 
nMultiple);
@@ -39,10 +39,10 @@ static tools::Long roundMultiple(tools::Long nCurrent, int 
nMultiple)
 *
 * @param nCurrent current zoom factor
 */
-static tools::Long roundZoom(double nCurrent)
+static sal_uInt16 roundZoom(double nCurrent)
 {
     // convert nCurrent properly to int
-    tools::Long nNew = nCurrent + 0.5;
+    sal_uInt16 nNew = nCurrent + 0.5;
 
     // round to more common numbers above 50
     if (nNew > 1000) {
@@ -66,7 +66,7 @@ static tools::Long roundZoom(double nCurrent)
 * @param nPrevious previous zoom factor
 * @param nStep step which shouldn't be skipped
 */
-static tools::Long enforceStep(tools::Long nCurrent, tools::Long nPrevious, 
int nStep)
+static sal_uInt16 enforceStep(sal_uInt16 nCurrent, sal_uInt16 nPrevious, 
unsigned int nStep)
 {
     if ((( nCurrent > nStep ) && ( nPrevious < nStep ))
     || (( nCurrent < nStep ) && ( nPrevious > nStep )))
@@ -80,9 +80,9 @@ static tools::Long enforceStep(tools::Long nCurrent, 
tools::Long nPrevious, int
 *
 * @param nCurrent current zoom factor
 */
-tools::Long zoomIn(tools::Long nCurrent)
+sal_uInt16 zoomIn(sal_uInt16 nCurrent)
 {
-    tools::Long nNew = roundZoom( nCurrent * ZOOM_FACTOR );
+    sal_uInt16 nNew = roundZoom( nCurrent * ZOOM_FACTOR );
     // make sure some values are not skipped
     nNew = enforceStep(nNew, nCurrent, 200);
     nNew = enforceStep(nNew, nCurrent, 100);
@@ -97,9 +97,9 @@ tools::Long zoomIn(tools::Long nCurrent)
 *
 * @param nCurrent current zoom factor
 */
-tools::Long zoomOut(tools::Long nCurrent)
+sal_uInt16 zoomOut(sal_uInt16 nCurrent)
 {
-    tools::Long nNew = roundZoom( nCurrent / ZOOM_FACTOR );
+    sal_uInt16 nNew = roundZoom( nCurrent / ZOOM_FACTOR );
     // make sure some values are not skipped
     nNew = enforceStep(nNew, nCurrent, 200);
     nNew = enforceStep(nNew, nCurrent, 100);
diff --git a/include/basegfx/utils/zoomtools.hxx 
b/include/basegfx/utils/zoomtools.hxx
index 242c10e6dafc..16a36448af49 100644
--- a/include/basegfx/utils/zoomtools.hxx
+++ b/include/basegfx/utils/zoomtools.hxx
@@ -10,14 +10,13 @@
 #pragma once
 
 #include <basegfx/basegfxdllapi.h>
-#include <tools/long.hxx>
 
 namespace basegfx::zoomtools
 {
 /** This namespace provides functions for optimized geometric zooming
 */
-BASEGFX_DLLPUBLIC tools::Long zoomOut(tools::Long nCurrent);
-BASEGFX_DLLPUBLIC tools::Long zoomIn(tools::Long nCurrent);
+BASEGFX_DLLPUBLIC sal_uInt16 zoomOut(sal_uInt16 nCurrent);
+BASEGFX_DLLPUBLIC sal_uInt16 zoomIn(sal_uInt16 nCurrent);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx
index 47b93c845296..8401ca4c6f7e 100644
--- a/sc/inc/global.hxx
+++ b/sc/inc/global.hxx
@@ -75,8 +75,8 @@ const sal_Unicode CHAR_NNBSP    = 0x202F; //NARROW NO-BREAK 
SPACE
 #define MINDOUBLE   1.7e-307
 #define MAXDOUBLE   1.7e307
 
-#define MINZOOM     20
-#define MAXZOOM     400
+const sal_uInt16 MINZOOM = 20;
+const sal_uInt16 MAXZOOM = 400;
 
 const SCSIZE MAXSUBTOTAL        = 3;
 
diff --git a/sc/source/ui/view/prevwsh.cxx b/sc/source/ui/view/prevwsh.cxx
index d38b4311f143..4552062b624a 100644
--- a/sc/source/ui/view/prevwsh.cxx
+++ b/sc/source/ui/view/prevwsh.cxx
@@ -478,17 +478,17 @@ bool ScPreviewShell::ScrollCommand( const CommandEvent& 
rCEvt )
     const CommandWheelData* pData = rCEvt.GetWheelData();
     if ( pData && pData->GetMode() == CommandWheelMode::ZOOM )
     {
-        tools::Long nOld = pPreview->GetZoom();
-        tools::Long nNew;
+        sal_uInt16 nOld = pPreview->GetZoom();
+        sal_uInt16 nNew;
         if ( pData->GetDelta() < 0 )
-            nNew = std::max( tools::Long(MINZOOM), 
basegfx::zoomtools::zoomOut( nOld ));
+            nNew = std::max( MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
         else
-            nNew = std::min( tools::Long(MAXZOOM), basegfx::zoomtools::zoomIn( 
nOld ));
+            nNew = std::min( MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
 
         if ( nNew != nOld )
         {
             eZoom = SvxZoomType::PERCENT;
-            pPreview->SetZoom( static_cast<sal_uInt16>(nNew) );
+            pPreview->SetZoom( nNew );
         }
 
         bDone = true;
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 4e66be551f8b..898181c49f6e 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -959,12 +959,12 @@ bool ScTabView::ScrollCommand( const CommandEvent& rCEvt, 
ScSplitPos ePos )
             //  and can't be changed directly
 
             const Fraction& rOldY = aViewData.GetZoomY();
-            tools::Long nOld = static_cast<tools::Long>( rOldY * 100 );
-            tools::Long nNew;
+            sal_uInt16 nOld = static_cast<tools::Long>( rOldY * 100 );
+            sal_uInt16 nNew;
             if ( pData->GetDelta() < 0 )
-                nNew = std::max( tools::Long(MINZOOM), 
basegfx::zoomtools::zoomOut( nOld ));
+                nNew = std::max( MINZOOM, basegfx::zoomtools::zoomOut( nOld ));
             else
-                nNew = std::min( tools::Long(MAXZOOM), 
basegfx::zoomtools::zoomIn( nOld ));
+                nNew = std::min( MAXZOOM, basegfx::zoomtools::zoomIn( nOld ));
             if ( nNew != nOld )
             {
                 // scroll wheel doesn't set the AppOptions default
diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx
index 766f6c7621d4..ec19d4c1d4a6 100644
--- a/sc/source/ui/view/tabvwsh3.cxx
+++ b/sc/source/ui/view/tabvwsh3.cxx
@@ -754,12 +754,12 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
                     //  and can't be changed directly
 
                     const Fraction& rOldY = GetViewData().GetZoomY();
-                    tools::Long nOld = tools::Long(rOldY * 100);
-                    tools::Long nNew;
+                    sal_uInt16 nOld = tools::Long(rOldY * 100);
+                    sal_uInt16 nNew;
                     if (SID_ZOOM_OUT == nSlot)
-                        nNew = std::max(tools::Long(MINZOOM), 
basegfx::zoomtools::zoomOut(nOld));
+                        nNew = std::max(MINZOOM, 
basegfx::zoomtools::zoomOut(nOld));
                     else
-                        nNew = std::min(tools::Long(MAXZOOM), 
basegfx::zoomtools::zoomIn(nOld));
+                        nNew = std::min(MAXZOOM, 
basegfx::zoomtools::zoomIn(nOld));
                     if ( nNew != nOld)
                     {
                         bool bSyncZoom = 
SC_MOD()->GetAppOptions().GetSynchronizeZoom();
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 866b794611bb..c74a2b57e64d 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -717,14 +717,14 @@ bool ViewShell::HandleScrollCommand(const CommandEvent& 
rCEvt, ::sd::Window* pWi
                 {
                     if( !GetDocSh()->IsUIActive() )
                     {
-                        const ::tools::Long  nOldZoom = 
GetActiveWindow()->GetZoom();
-                        ::tools::Long        nNewZoom;
+                        const sal_uInt16  nOldZoom = 
GetActiveWindow()->GetZoom();
+                        sal_uInt16        nNewZoom;
                         Point aOldMousePos = 
GetActiveWindow()->PixelToLogic(rCEvt.GetMousePosPixel());
 
                         if( pData->GetDelta() < 0 )
-                            nNewZoom = std::max<::tools::Long>( 
pWin->GetMinZoom(), basegfx::zoomtools::zoomOut( nOldZoom ));
+                            nNewZoom = std::max<sal_uInt16>( 
pWin->GetMinZoom(), basegfx::zoomtools::zoomOut( nOldZoom ));
                         else
-                            nNewZoom = std::min<::tools::Long>( 
pWin->GetMaxZoom(), basegfx::zoomtools::zoomIn( nOldZoom ));
+                            nNewZoom = std::min<sal_uInt16>( 
pWin->GetMaxZoom(), basegfx::zoomtools::zoomIn( nOldZoom ));
 
                         SetZoom( nNewZoom );
                         // Keep mouse at same doc point before zoom
diff --git a/svx/source/stbctrls/zoomsliderctrl.cxx 
b/svx/source/stbctrls/zoomsliderctrl.cxx
index c0790b07458a..215c0556fc87 100644
--- a/svx/source/stbctrls/zoomsliderctrl.cxx
+++ b/svx/source/stbctrls/zoomsliderctrl.cxx
@@ -296,11 +296,11 @@ bool SvxZoomSliderControl::MouseButtonDown( const 
MouseEvent & rEvt )
 
     // click to - button
     if ( nXDiff >= nButtonLeftOffset && nXDiff <= nButtonRightOffset )
-        mxImpl->mnCurrentZoom = basegfx::zoomtools::zoomOut( 
static_cast<int>(mxImpl->mnCurrentZoom) );
+        mxImpl->mnCurrentZoom = basegfx::zoomtools::zoomOut( 
mxImpl->mnCurrentZoom );
     // click to + button
     else if ( nXDiff >= aControlRect.GetWidth() - nSliderXOffset + 
nButtonLeftOffset &&
               nXDiff <= aControlRect.GetWidth() - nSliderXOffset + 
nButtonRightOffset )
-        mxImpl->mnCurrentZoom = basegfx::zoomtools::zoomIn( 
static_cast<int>(mxImpl->mnCurrentZoom) );
+        mxImpl->mnCurrentZoom = basegfx::zoomtools::zoomIn( 
mxImpl->mnCurrentZoom );
     // click to slider
     else if( nXDiff >= nSliderXOffset && nXDiff <= aControlRect.GetWidth() - 
nSliderXOffset )
     {
diff --git a/sw/source/uibase/uiview/view2.cxx 
b/sw/source/uibase/uiview/view2.cxx
index e716c96b31f6..0e3fb80bad1f 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -589,7 +589,7 @@ void SwView::Execute(SfxRequest &rReq)
         case SID_ZOOM_IN:
         case SID_ZOOM_OUT:
         {
-            tools::Long nFact = m_pWrtShell->GetViewOptions()->GetZoom();
+            sal_uInt16 nFact = m_pWrtShell->GetViewOptions()->GetZoom();
             if (SID_ZOOM_IN == nSlot)
                 nFact = basegfx::zoomtools::zoomIn(nFact);
             else
diff --git a/sw/source/uibase/uiview/viewport.cxx 
b/sw/source/uibase/uiview/viewport.cxx
index af80d856daed..bea8c23d1deb 100644
--- a/sw/source/uibase/uiview/viewport.cxx
+++ b/sw/source/uibase/uiview/viewport.cxx
@@ -1203,11 +1203,11 @@ bool SwView::HandleWheelCommands( const CommandEvent& 
rCEvt )
     const CommandWheelData* pWData = rCEvt.GetWheelData();
     if (pWData && CommandWheelMode::ZOOM == pWData->GetMode())
     {
-        tools::Long nFact = m_pWrtShell->GetViewOptions()->GetZoom();
+        sal_uInt16 nFact = m_pWrtShell->GetViewOptions()->GetZoom();
         if( 0L > pWData->GetDelta() )
-            nFact = std::max( tools::Long(20), basegfx::zoomtools::zoomOut( 
nFact ));
+            nFact = std::max( static_cast<sal_uInt16>(20), 
basegfx::zoomtools::zoomOut( nFact ));
         else
-            nFact = std::min( tools::Long(600), basegfx::zoomtools::zoomIn( 
nFact ));
+            nFact = std::min( static_cast<sal_uInt16>(600), 
basegfx::zoomtools::zoomIn( nFact ));
 
         SetZoom( SvxZoomType::PERCENT, nFact );
         bOk = true;

Reply via email to