summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Kant <pranavk@libreoffice.org>2015-12-19 20:36:47 +0530
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2016-01-12 21:17:52 +0000
commitbd85600aa4a81fba19c98e0a1c2d5ccdcb8fb3fc (patch)
tree1fe5dfe5e01d0f90d61a9aad934d592870811047
parent1a12a6e4cc608b6517655eb6339ceb829c3318bc (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> (cherry picked from commit ba539fa91f9c3316107dcdf4a95718a49335d92e) Reviewed-on: https://gerrit.libreoffice.org/21347 Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitGtk.h4
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx29
2 files changed, 30 insertions, 3 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 911bbdfa6049..e06d154f772e 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -107,7 +107,9 @@ LibreOfficeKitDocument* lok_doc_view_get_document (LOKDocView*
* @pDocView: The #LOKDocView instance
* @fZoom: The new zoom level that pDocView must set it into.
*
- * Sets the new zoom level for the widget.
+ * Sets the new zoom level for the widget. Does nothing if fZoom is equal to
+ * existing zoom level. Values outside the range [0.25, 5.0] are clamped into
+ * the nearest allowed value in the interval.
*/
void lok_doc_view_set_zoom (LOKDocView* pDocView,
float fZoom);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 21232df7a933..2ece638dd99e 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -39,6 +39,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
@@ -125,8 +129,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);