Blame SOURCES/0387-tdf-96513-Limit-LOKDocView-s-zoom-in-0.25-5.0.patch

f325b2
From b94feb218000f0c0a1e156cb868531295763b68d Mon Sep 17 00:00:00 2001
f325b2
From: Pranav Kant <pranavk@libreoffice.org>
f325b2
Date: Sat, 19 Dec 2015 20:36:47 +0530
f325b2
Subject: [PATCH 387/398] tdf#96513: Limit LOKDocView's zoom in [0.25, 5.0]
f325b2
f325b2
Change-Id: Ibee485909dca1ea4a3774fca7a840afbf2d9883c
f325b2
Reviewed-on: https://gerrit.libreoffice.org/20819
f325b2
Tested-by: Jenkins <ci@libreoffice.org>
f325b2
Reviewed-by: David Tardon <dtardon@redhat.com>
f325b2
(cherry picked from commit ba539fa91f9c3316107dcdf4a95718a49335d92e)
f325b2
Reviewed-on: https://gerrit.libreoffice.org/21347
f325b2
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
f325b2
(cherry picked from commit bd85600aa4a81fba19c98e0a1c2d5ccdcb8fb3fc)
f325b2
---
f325b2
 include/LibreOfficeKit/LibreOfficeKitGtk.h |  4 +++-
f325b2
 libreofficekit/source/gtk/lokdocview.cxx   | 29 +++++++++++++++++++++++++++--
f325b2
 2 files changed, 30 insertions(+), 3 deletions(-)
f325b2
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
f325b2
index 911bbdfa6049..e06d154f772e 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
f325b2
@@ -107,7 +107,9 @@ LibreOfficeKitDocument*        lok_doc_view_get_document           (LOKDocView*
f325b2
  * @pDocView: The #LOKDocView instance
f325b2
  * @fZoom: The new zoom level that pDocView must set it into.
f325b2
  *
f325b2
- * Sets the new zoom level for the widget.
f325b2
+ * Sets the new zoom level for the widget. Does nothing if fZoom is equal to
f325b2
+ * existing zoom level. Values outside the range [0.25, 5.0] are clamped into
f325b2
+ * the nearest allowed value in the interval.
f325b2
  */
f325b2
 void                           lok_doc_view_set_zoom               (LOKDocView* pDocView,
f325b2
                                                                     float fZoom);
f325b2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
index 9774acacad83..d2c66b951b7d 100644
f325b2
--- a/libreofficekit/source/gtk/lokdocview.cxx
f325b2
+++ b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
@@ -39,6 +39,10 @@
f325b2
 #define CURSOR_HANDLE_DIR "android/experimental/LOAndroid3/res/drawable/"
f325b2
 // Number of handles around a graphic selection.
f325b2
 #define GRAPHIC_HANDLE_COUNT 8
f325b2
+// Maximum Zoom allowed
f325b2
+#define MAX_ZOOM 5.0f
f325b2
+// Minimum Zoom allowed
f325b2
+#define MIN_ZOOM 0.25f
f325b2
 
f325b2
 /// Private struct used by this GObject type
f325b2
 struct LOKDocViewPrivateImpl
f325b2
@@ -125,8 +129,8 @@ struct LOKDocViewPrivateImpl
f325b2
         m_aDocPath(nullptr),
f325b2
         m_nLoadProgress(0),
f325b2
         m_bIsLoading(false),
f325b2
-        m_bCanZoomIn(false),
f325b2
-        m_bCanZoomOut(false),
f325b2
+        m_bCanZoomIn(true),
f325b2
+        m_bCanZoomOut(true),
f325b2
         m_pOffice(nullptr),
f325b2
         m_pDocument(nullptr),
f325b2
         lokThreadPool(nullptr),
f325b2
@@ -2473,6 +2477,13 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
f325b2
     LOKDocViewPrivate& priv = getPrivate(pDocView);
f325b2
     GError* error = nullptr;
f325b2
 
f325b2
+    // Clamp the input value in [MIN_ZOOM, MAX_ZOOM]
f325b2
+    fZoom = fZoom < MIN_ZOOM ? MIN_ZOOM : fZoom;
f325b2
+    fZoom = fZoom > MAX_ZOOM ? MAX_ZOOM : fZoom;
f325b2
+
f325b2
+    if (fZoom == priv->m_fZoom)
f325b2
+        return;
f325b2
+
f325b2
     priv->m_fZoom = fZoom;
f325b2
     long nDocumentWidthPixels = twipToPixel(priv->m_nDocumentWidthTwips, fZoom);
f325b2
     long nDocumentHeightPixels = twipToPixel(priv->m_nDocumentHeightTwips, fZoom);
f325b2
@@ -2487,6 +2498,20 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
f325b2
 
f325b2
     g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_ZOOM]);
f325b2
 
f325b2
+    // set properties to indicate if view can be further zoomed in/out
f325b2
+    bool bCanZoomIn  = priv->m_fZoom < MAX_ZOOM;
f325b2
+    bool bCanZoomOut = priv->m_fZoom > MIN_ZOOM;
f325b2
+    if (bCanZoomIn != priv->m_bCanZoomIn)
f325b2
+    {
f325b2
+        priv->m_bCanZoomIn = bCanZoomIn;
f325b2
+        g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_CAN_ZOOM_IN]);
f325b2
+    }
f325b2
+    if (bCanZoomOut != priv->m_bCanZoomOut)
f325b2
+    {
f325b2
+        priv->m_bCanZoomOut = bCanZoomOut;
f325b2
+        g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_CAN_ZOOM_OUT]);
f325b2
+    }
f325b2
+
f325b2
     // Update the client's view size
f325b2
     GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr);
f325b2
     LOEvent* pLOEvent = new LOEvent(LOK_SET_CLIENT_ZOOM);
f325b2
-- 
f325b2
2.12.0
f325b2