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

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