kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0316-LOK-setClientZoom-sets-the-client-zoom-level.patch

f325b2
From 4918619e165b7869731e594bf514932cdec10d8e Mon Sep 17 00:00:00 2001
f325b2
From: Mihai Varga <mihai.varga@collabora.com>
f325b2
Date: Fri, 6 Nov 2015 14:34:28 +0200
f325b2
Subject: [PATCH 316/398] LOK: setClientZoom() - sets the client zoom level
f325b2
f325b2
We need to know the client's view level to correctly handle the mouse
f325b2
events in calc. PaintTile() set a zoom level that corresponds to the
f325b2
requested tiles and previously postMouseEvent would call SetZoom(1,1).
f325b2
Now we can make use of knowing the client's view level and call
f325b2
SetZoom() with the correct parameters
f325b2
f325b2
Conflicts:
f325b2
	sc/source/ui/unoobj/docuno.cxx
f325b2
(cherry picked from commit 96cd2abd748ed24e5aba50cc4c300cf06e512db3)
f325b2
f325b2
Change-Id: I34b5afcdcc06a671a8ac92c03e87404e42adf4cd
f325b2
---
f325b2
 desktop/source/lib/init.cxx               | 20 +++++++++++++++-
f325b2
 include/LibreOfficeKit/LibreOfficeKit.h   |  7 ++++++
f325b2
 include/LibreOfficeKit/LibreOfficeKit.hxx | 17 ++++++++++++++
f325b2
 include/vcl/ITiledRenderable.hxx          | 18 +++++++++++++++
f325b2
 libreofficekit/source/gtk/lokdocview.cxx  | 38 +++++++++++++++++++++++++++++++
f325b2
 libreofficekit/source/gtk/tilebuffer.hxx  | 11 ++++++++-
f325b2
 sc/inc/docuno.hxx                         |  3 +++
f325b2
 sc/source/ui/unoobj/docuno.cxx            | 18 ++++++++++++++-
f325b2
 8 files changed, 129 insertions(+), 3 deletions(-)
f325b2
f325b2
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
f325b2
index 04a902780e6c..4ee862d21cd0 100644
f325b2
--- a/desktop/source/lib/init.cxx
f325b2
+++ b/desktop/source/lib/init.cxx
f325b2
@@ -317,7 +317,11 @@ static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
f325b2
                                   int nY);
f325b2
 static void doc_resetSelection (LibreOfficeKitDocument* pThis);
f325b2
 static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
f325b2
-
f325b2
+static void doc_setClientZoom(LibreOfficeKitDocument* pThis,
f325b2
+                                    int nTilePixelWidth,
f325b2
+                                    int nTilePixelHeight,
f325b2
+                                    int nTileTwipWidth,
f325b2
+                                    int nTileTwipHeight);
f325b2
 static int doc_createView(LibreOfficeKitDocument* pThis);
f325b2
 static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
f325b2
 static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
f325b2
@@ -357,6 +361,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference 
f325b2
         m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
f325b2
         m_pDocumentClass->resetSelection = doc_resetSelection;
f325b2
         m_pDocumentClass->getCommandValues = doc_getCommandValues;
f325b2
+        m_pDocumentClass->setClientZoom = doc_setClientZoom;
f325b2
 
f325b2
         m_pDocumentClass->createView = doc_createView;
f325b2
         m_pDocumentClass->destroyView = doc_destroyView;
f325b2
@@ -1470,6 +1475,19 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
f325b2
     }
f325b2
 }
f325b2
 
f325b2
+static void doc_setClientZoom(LibreOfficeKitDocument* pThis, int nTilePixelWidth, int nTilePixelHeight,
f325b2
+        int nTileTwipWidth, int nTileTwipHeight)
f325b2
+{
f325b2
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
f325b2
+    if (!pDoc)
f325b2
+    {
f325b2
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
f325b2
+        return;
f325b2
+    }
f325b2
+
f325b2
+    pDoc->setClientZoom(nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
f325b2
+}
f325b2
+
f325b2
 static int doc_createView(LibreOfficeKitDocument* /*pThis*/)
f325b2
 {
f325b2
     SolarMutexGuard aGuard;
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
f325b2
index c887f5f64b8a..03210376c61e 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKit.h
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
f325b2
@@ -181,6 +181,13 @@ struct _LibreOfficeKitDocumentClass
f325b2
     /// @see lok::Document::getCommandValues().
f325b2
     char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand);
f325b2
 
f325b2
+    /// @see lok::Document::setClientZoom().
f325b2
+    void (*setClientZoom) (LibreOfficeKitDocument* pThis,
f325b2
+            int nTilePixelWidth,
f325b2
+            int nTilePixelHeight,
f325b2
+            int nTileTwipWidth,
f325b2
+            int nTileTwipHeight);
f325b2
+
f325b2
     /// @see lok::Document::createView().
f325b2
     int (*createView) (LibreOfficeKitDocument* pThis);
f325b2
     /// @see lok::Document::destroyView().
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
f325b2
index 601d3bc147a5..c474195de213 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
f325b2
@@ -294,6 +294,23 @@ public:
f325b2
     }
f325b2
 
f325b2
     /**
f325b2
+     * Save the client's view so that we can compute the right zoom level
f325b2
+     * for the mouse events. This only affects CALC.
f325b2
+     * @param nTilePixelWidth - tile width in pixels
f325b2
+     * @param nTilePixelHeight - tile height in pixels
f325b2
+     * @param nTileTwipWidth - tile width in twips
f325b2
+     * @param nTileTwipHeight - tile height in twips
f325b2
+     */
f325b2
+    inline void setClientZoom(
f325b2
+            int nTilePixelWidth,
f325b2
+            int nTilePixelHeight,
f325b2
+            int nTileTwipWidth,
f325b2
+            int nTileTwipHeight)
f325b2
+    {
f325b2
+        mpDoc->pClass->setClientZoom(mpDoc, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
f325b2
+    }
f325b2
+
f325b2
+    /**
f325b2
      * Create a new view for an existing document.
f325b2
      * By default a loaded document has 1 view.
f325b2
      * @return the ID of the new view.
f325b2
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
f325b2
index bf0aa55e32a6..fa85b39399b3 100644
f325b2
--- a/include/vcl/ITiledRenderable.hxx
f325b2
+++ b/include/vcl/ITiledRenderable.hxx
f325b2
@@ -22,6 +22,9 @@ namespace vcl
f325b2
 
f325b2
 class VCL_DLLPUBLIC ITiledRenderable
f325b2
 {
f325b2
+protected:
f325b2
+    int nTilePixelWidth, nTilePixelHeight;
f325b2
+    int nTileTwipWidth, nTileTwipHeight;
f325b2
 public:
f325b2
     virtual ~ITiledRenderable();
f325b2
 
f325b2
@@ -179,6 +182,21 @@ public:
f325b2
 
f325b2
     /// If the current contents of the clipboard is something we can paste.
f325b2
     virtual bool isMimeTypeSupported() = 0;
f325b2
+
f325b2
+    /**
f325b2
+     * Save the client's view so that we can compute the right zoom level
f325b2
+     * for the mouse events.
f325b2
+     * @param nTilePixelWidth - tile width in pixels
f325b2
+     * @param nTilePixelHeight - tile height in pixels
f325b2
+     * @param nTileTwipWidth - tile width in twips
f325b2
+     * @param nTileTwipHeight - tile height in twips
f325b2
+     */
f325b2
+    virtual void setClientZoom(int /*nTilePixelWidth*/,
f325b2
+                               int /*nTilePixelHeight*/,
f325b2
+                               int /*nTileTwipWidth*/,
f325b2
+                               int /*nTileTwipHeight*/)
f325b2
+    {
f325b2
+    }
f325b2
 };
f325b2
 
f325b2
 } // namespace vcl
f325b2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
index 687323d6ca11..db71f80e39c8 100644
f325b2
--- a/libreofficekit/source/gtk/lokdocview.cxx
f325b2
+++ b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
@@ -1506,6 +1506,23 @@ setGraphicSelectionInThread(gpointer data)
f325b2
 }
f325b2
 
f325b2
 static void
f325b2
+setClientZoomInThread(gpointer data)
f325b2
+{
f325b2
+    GTask* task = G_TASK(data);
f325b2
+    LOKDocView* pDocView = LOK_DOC_VIEW(g_task_get_source_object(task));
f325b2
+    LOKDocViewPrivate& priv = getPrivate(pDocView);
f325b2
+    LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
f325b2
+
f325b2
+    if (!priv->m_pDocument)
f325b2
+        return;
f325b2
+    priv->m_pDocument->pClass->setClientZoom(priv->m_pDocument,
f325b2
+                                             pLOEvent->m_nTilePixelWidth,
f325b2
+                                             pLOEvent->m_nTilePixelHeight,
f325b2
+                                             pLOEvent->m_nTileTwipWidth,
f325b2
+                                             pLOEvent->m_nTileTwipHeight);
f325b2
+}
f325b2
+
f325b2
+static void
f325b2
 postMouseEventInThread(gpointer data)
f325b2
 {
f325b2
     GTask* task = G_TASK(data);
f325b2
@@ -1721,6 +1738,9 @@ lokThreadFunc(gpointer data, gpointer /*user_data*/)
f325b2
     case LOK_SET_GRAPHIC_SELECTION:
f325b2
         setGraphicSelectionInThread(task);
f325b2
         break;
f325b2
+    case LOK_SET_CLIENT_ZOOM:
f325b2
+        setClientZoomInThread(task);
f325b2
+        break;
f325b2
     }
f325b2
 
f325b2
     g_object_unref(task);
f325b2
@@ -2301,6 +2321,7 @@ SAL_DLLPUBLIC_EXPORT void
f325b2
 lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
f325b2
 {
f325b2
     LOKDocViewPrivate& priv = getPrivate(pDocView);
f325b2
+    GError* error = NULL;
f325b2
 
f325b2
     priv->m_fZoom = fZoom;
f325b2
     long nDocumentWidthPixels = twipToPixel(priv->m_nDocumentWidthTwips, fZoom);
f325b2
@@ -2313,6 +2334,23 @@ lok_doc_view_set_zoom (LOKDocView* pDocView, float fZoom)
f325b2
     gtk_widget_set_size_request(GTK_WIDGET(pDocView),
f325b2
                                 nDocumentWidthPixels,
f325b2
                                 nDocumentHeightPixels);
f325b2
+
f325b2
+    // Update the client's view size
f325b2
+    GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
f325b2
+    LOEvent* pLOEvent = new LOEvent(LOK_SET_CLIENT_ZOOM);
f325b2
+    pLOEvent->m_nTilePixelWidth = nTileSizePixels;
f325b2
+    pLOEvent->m_nTilePixelHeight = nTileSizePixels;
f325b2
+    pLOEvent->m_nTileTwipWidth = pixelToTwip(nTileSizePixels, fZoom);
f325b2
+    pLOEvent->m_nTileTwipHeight = pixelToTwip(nTileSizePixels, fZoom);
f325b2
+    g_task_set_task_data(task, pLOEvent, LOEvent::destroy);
f325b2
+
f325b2
+    g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error);
f325b2
+    if (error != NULL)
f325b2
+    {
f325b2
+        g_warning("Unable to call LOK_SET_CLIENT_ZOOM: %s", error->message);
f325b2
+        g_clear_error(&error);
f325b2
+    }
f325b2
+    g_object_unref(task);
f325b2
 }
f325b2
 
f325b2
 SAL_DLLPUBLIC_EXPORT float
f325b2
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
index 5482ea2b2825..244ca882d051 100644
f325b2
--- a/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
f325b2
@@ -159,7 +159,8 @@ enum
f325b2
     LOK_POST_KEY,
f325b2
     LOK_PAINT_TILE,
f325b2
     LOK_POST_MOUSE_EVENT,
f325b2
-    LOK_SET_GRAPHIC_SELECTION
f325b2
+    LOK_SET_GRAPHIC_SELECTION,
f325b2
+    LOK_SET_CLIENT_ZOOM
f325b2
 };
f325b2
 
f325b2
 enum
f325b2
@@ -233,6 +234,14 @@ struct LOEvent
f325b2
     int m_nSetGraphicSelectionY;
f325b2
     ///@}
f325b2
 
f325b2
+    /// @name setClientView parameters
f325b2
+    ///@{
f325b2
+    int m_nTilePixelWidth;
f325b2
+    int m_nTilePixelHeight;
f325b2
+    int m_nTileTwipWidth;
f325b2
+    int m_nTileTwipHeight;
f325b2
+    ///@}
f325b2
+
f325b2
     /// Constructor to instantiate an object of type `type`.
f325b2
     LOEvent(int type)
f325b2
         : m_nType(type)
f325b2
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
f325b2
index b73eb12704be..7e00b7549733 100644
f325b2
--- a/sc/inc/docuno.hxx
f325b2
+++ b/sc/inc/docuno.hxx
f325b2
@@ -422,6 +422,9 @@ public:
f325b2
     /// @see vcl::ITiledRenderable::isMimeTypeSupported().
f325b2
     virtual bool isMimeTypeSupported() override;
f325b2
 
f325b2
+    /// @see vcl::ITiledRenderable::setClientZoom().
f325b2
+    virtual void setClientZoom(int nTilePixelWidth, int nTilePixelHeight, int nTileTwipWidth, int nTileTwipHeight) override;
f325b2
+
f325b2
     /// @see vcl::ITiledRenderable::getRowColumnHeaders().
f325b2
     virtual OUString getRowColumnHeaders(const Rectangle& rRectangle) override;
f325b2
 
f325b2
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
f325b2
index 0e5396e5910e..c5a96e1e8255 100644
f325b2
--- a/sc/source/ui/unoobj/docuno.cxx
f325b2
+++ b/sc/source/ui/unoobj/docuno.cxx
f325b2
@@ -604,7 +604,8 @@ void ScModelObj::postMouseEvent(int nType, int nX, int nY, int nCount, int nButt
f325b2
         return;
f325b2
 
f325b2
     // update the aLogicMode in ScViewData to something predictable
f325b2
-    pViewData->SetZoom(Fraction(1, 1), Fraction(1, 1), true);
f325b2
+    pViewData->SetZoom(Fraction(nTilePixelWidth * TWIPS_PER_PIXEL, nTileTwipWidth),
f325b2
+                       Fraction(nTilePixelHeight * TWIPS_PER_PIXEL, nTileTwipHeight), true);
f325b2
 
f325b2
     // Calc operates in pixels...
f325b2
     MouseEvent aEvent(Point(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY()), nCount,
f325b2
@@ -873,6 +874,14 @@ bool ScModelObj::isMimeTypeSupported()
f325b2
     return EditEngine::HasValidData(aDataHelper.GetTransferable());
f325b2
 }
f325b2
 
f325b2
+void ScModelObj::setClientZoom(int nTilePixelWidth_, int nTilePixelHeight_, int nTileTwipWidth_, int nTileTwipHeight_)
f325b2
+{
f325b2
+    nTilePixelWidth = nTilePixelWidth_;
f325b2
+    nTilePixelHeight = nTilePixelHeight_;
f325b2
+    nTileTwipWidth = nTileTwipWidth_;
f325b2
+    nTileTwipHeight = nTileTwipHeight_;
f325b2
+}
f325b2
+
f325b2
 OUString ScModelObj::getRowColumnHeaders(const Rectangle& rRectangle)
f325b2
 {
f325b2
     ScViewData* pViewData = ScDocShell::GetViewData();
f325b2
@@ -931,6 +940,13 @@ void ScModelObj::initializeForTiledRendering()
f325b2
     // tdf#93154: in tiled rendering LO doesn't always detect changes
f325b2
     SvtMiscOptions aMiscOpt;
f325b2
     aMiscOpt.SetSaveAlwaysAllowed(true);
f325b2
+
f325b2
+    // default tile size in pixels
f325b2
+    nTilePixelWidth = 256;
f325b2
+    nTilePixelHeight = 256;
f325b2
+    // the default zoom level will be 1
f325b2
+    nTileTwipWidth = nTilePixelWidth * TWIPS_PER_PIXEL;
f325b2
+    nTileTwipHeight = nTilePixelHeight * TWIPS_PER_PIXEL;
f325b2
 }
f325b2
 
f325b2
 uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType )
f325b2
-- 
f325b2
2.12.0
f325b2