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 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);