sw/inc/view.hxx                      |    3 +++
 sw/source/uibase/uiview/viewport.cxx |   30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

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

    sw: React to touchpad zoom gestures in SwView
    
    Change-Id: I337e5d6873f9cf6d78cb53b2ffdb59a33a9465f9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143753
    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/+/144227
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index caaa808b6a24..c3ed0f5808d7 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -235,6 +235,8 @@ class SW_DLLPUBLIC SwView: public SfxViewShell
     SvxSearchCmd        m_eLastSearchCommand;
 
     bool m_bWheelScrollInProgress;
+    double          m_fLastZoomScale = 0;
+    double          m_fAccumulatedZoom = 0;
 
     bool            m_bCenterCursor : 1,
                     m_bTopCursor : 1,
@@ -470,6 +472,7 @@ public:
     static void     SetActMark(sal_Int32 nSet);
 
     bool            HandleWheelCommands( const CommandEvent& );
+    bool            HandleGestureZoomCommand(const CommandEvent&);
 
     // insert frames
     void            InsFrameMode(sal_uInt16 nCols);
diff --git a/sw/source/uibase/uiview/viewport.cxx 
b/sw/source/uibase/uiview/viewport.cxx
index ff4c918c9619..2c66c52a0c96 100644
--- a/sw/source/uibase/uiview/viewport.cxx
+++ b/sw/source/uibase/uiview/viewport.cxx
@@ -1230,4 +1230,34 @@ bool SwView::HandleWheelCommands( const CommandEvent& 
rCEvt )
     return bOk;
 }
 
+bool SwView::HandleGestureZoomCommand(const CommandEvent& rCEvt)
+{
+    const CommandGestureZoomData* pData = rCEvt.GetGestureZoomData();
+
+    if (pData->meEventType == GestureEventZoomType::Begin)
+    {
+        m_fLastZoomScale = pData->mfScaleDelta;
+        return true;
+    }
+
+    if (pData->meEventType == GestureEventZoomType::Update)
+    {
+        double deltaBetweenEvents = (pData->mfScaleDelta - m_fLastZoomScale) / 
m_fLastZoomScale;
+        m_fLastZoomScale = pData->mfScaleDelta;
+
+        // Accumulate fractional zoom to avoid small zoom changes from being 
ignored
+        m_fAccumulatedZoom += deltaBetweenEvents;
+        int nZoomChangePercent = m_fAccumulatedZoom * 100;
+        m_fAccumulatedZoom -= nZoomChangePercent / 100.0;
+
+        sal_uInt16 nFact = m_pWrtShell->GetViewOptions()->GetZoom();
+        nFact += nZoomChangePercent;
+        nFact = std::clamp<sal_uInt16>(nFact, MIN_ZOOM_PERCENT, 
MAX_ZOOM_PERCENT);
+        SetZoom(SvxZoomType::PERCENT, nFact);
+
+        return true;
+    }
+    return true;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to