summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorPranav Kant <pranavk@libreoffice.org>2015-12-19 20:36:47 +0530
committerDavid Tardon <dtardon@redhat.com>2016-01-11 11:34:54 +0000
commitba539fa91f9c3316107dcdf4a95718a49335d92e (patch)
tree1585e8bf69142c30327c9f8a15b7352a7196f5a2 /libreofficekit
parent4200a678fb54f0fa5d2f0c26c655252f9267a527 (diff)
tdf#96513: Limit LOKDocView's zoom in [0.25, 5.0]
Change-Id: Ibee485909dca1ea4a3774fca7a840afbf2d9883c Reviewed-on: https://gerrit.libreoffice.org/20819 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx29
1 files changed, 27 insertions, 2 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index c1f550ae2829..383f35f98a7c 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -38,6 +38,10 @@
#define CURSOR_HANDLE_DIR "/android/source/res/drawable/"
// Number of handles around a graphic selection.
#define GRAPHIC_HANDLE_COUNT 8
+// Maximum Zoom allowed
+#define MAX_ZOOM 5.0f
+// Minimum Zoom allowed
+#define MIN_ZOOM 0.25f
/// Private struct used by this GObject type
struct LOKDocViewPrivateImpl
@@ -124,8 +128,8 @@ struct LOKDocViewPrivateImpl
m_aDocPath(nullptr),
m_nLoadProgress(0),
m_bIsLoading(false),
- m_bCanZoomIn(false),
- m_bCanZoomOut(false),
+ m_bCanZoomIn(true),
+ m_bCanZoomOut(true),
m_pOffice(nullptr),
m_pDocument(nullptr),
lokThreadPool(nullptr),
@@ -2475,6 +2479,13 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
LOKDocViewPrivate& priv = getPrivate(pDocView);
GError* error = nullptr;
+ // Clamp the input value in [MIN_ZOOM, MAX_ZOOM]
+ fZoom = fZoom < MIN_ZOOM ? MIN_ZOOM : fZoom;
+ fZoom = fZoom > MAX_ZOOM ? MAX_ZOOM : fZoom;
+
+ if (fZoom == priv->m_fZoom)
+ return;
+
priv->m_fZoom = fZoom;
long nDocumentWidthPixels = twipToPixel(priv->m_nDocumentWidthTwips, fZoom);
long nDocumentHeightPixels = twipToPixel(priv->m_nDocumentHeightTwips, fZoom);
@@ -2489,6 +2500,20 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_ZOOM]);
+ // set properties to indicate if view can be further zoomed in/out
+ bool bCanZoomIn = priv->m_fZoom < MAX_ZOOM;
+ bool bCanZoomOut = priv->m_fZoom > MIN_ZOOM;
+ if (bCanZoomIn != priv->m_bCanZoomIn)
+ {
+ priv->m_bCanZoomIn = bCanZoomIn;
+ g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_CAN_ZOOM_IN]);
+ }
+ if (bCanZoomOut != priv->m_bCanZoomOut)
+ {
+ priv->m_bCanZoomOut = bCanZoomOut;
+ g_object_notify_by_pspec(G_OBJECT(pDocView), properties[PROP_CAN_ZOOM_OUT]);
+ }
+
// Update the client's view size
GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr);
LOEvent* pLOEvent = new LOEvent(LOK_SET_CLIENT_ZOOM);