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