sc/source/ui/inc/tabview.hxx  |    4 ++++
 sc/source/ui/view/tabview.cxx |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

New commits:
commit 7f1f6a929335552e5adb7caba78333e44f6213c3
Author:     Povilas Kanapickas <povi...@radix.lt>
AuthorDate: Wed Dec 7 03:13:29 2022 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Dec 15 19:34:14 2022 +0000

    sc: React to touchpad zoom gestures in ScTabView
    
    Change-Id: I9a946c0caf3aab03a2055740a4f467210dc07b6a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143756
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144230
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index f62b2c4f9cba..7fdb0cc3c2c2 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -214,6 +214,9 @@ private:
     bool                bBlockRows:1;             // are whole rows selected?
     bool                mbInlineWithScrollbar:1;  // should inline with 
scrollbar?
 
+    double              mfLastZoomScale = 0;
+    double              mfAccumulatedZoom = 0;
+
     void            Init();
 
     void            DoAddWin( ScGridWindow* pWin );
@@ -458,6 +461,7 @@ public:
     SC_DLLPUBLIC void           ScrollLines( tools::Long nDeltaX, tools::Long 
nDeltaY );              // active
 
     bool            ScrollCommand( const CommandEvent& rCEvt, ScSplitPos ePos 
);
+    bool            GestureZoomCommand(const CommandEvent& rCEvt);
 
     void            ScrollToObject( const SdrObject* pDrawObj );
     void            MakeVisible( const tools::Rectangle& rHMMRect );
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index f12327b04a5d..5b2c44ee4875 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -992,6 +992,48 @@ bool ScTabView::ScrollCommand( const CommandEvent& rCEvt, 
ScSplitPos ePos )
     return bDone;
 }
 
+bool ScTabView::GestureZoomCommand(const CommandEvent& rCEvt)
+{
+    HideNoteMarker();
+
+    const CommandGestureZoomData* pData = rCEvt.GetGestureZoomData();
+    if (!pData)
+        return false;
+
+    if (aViewData.GetViewShell()->GetViewFrame()->GetFrame().IsInPlace())
+        return false;
+
+    if (pData->meEventType == GestureEventZoomType::Begin)
+    {
+        mfLastZoomScale = pData->mfScaleDelta;
+        return true;
+    }
+
+    if (pData->meEventType == GestureEventZoomType::Update)
+    {
+        double deltaBetweenEvents = (pData->mfScaleDelta - mfLastZoomScale) / 
mfLastZoomScale;
+        mfLastZoomScale = pData->mfScaleDelta;
+
+        // Accumulate fractional zoom to avoid small zoom changes from being 
ignored
+        mfAccumulatedZoom += deltaBetweenEvents;
+        int nZoomChangePercent = mfAccumulatedZoom * 100;
+        mfAccumulatedZoom -= nZoomChangePercent / 100.0;
+
+        const Fraction& rOldY = aViewData.GetZoomY();
+        sal_uInt16 nOld = static_cast<tools::Long>(rOldY * 100);
+        sal_uInt16 nNew = nOld + nZoomChangePercent;
+        nNew = std::clamp<sal_uInt16>(nNew, MINZOOM, MAXZOOM);
+
+        if (nNew != nOld)
+        {
+            SetZoomPercentFromCommand(nNew);
+        }
+
+        return true;
+    }
+    return true;
+}
+
 IMPL_LINK_NOARG(ScTabView, HScrollLeftHdl, weld::Scrollbar&, void)
 {
     ScrollHdl(aHScrollLeft.get());

Reply via email to