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

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