From ba539fa91f9c3316107dcdf4a95718a49335d92e Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Sat, 19 Dec 2015 20:36:47 +0530 Subject: tdf#96513: Limit LOKDocView's zoom in [0.25, 5.0] Change-Id: Ibee485909dca1ea4a3774fca7a840afbf2d9883c Reviewed-on: https://gerrit.libreoffice.org/20819 Tested-by: Jenkins Reviewed-by: David Tardon --- libreofficekit/source/gtk/lokdocview.cxx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'libreofficekit/source/gtk') 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); -- cgit