From 1da4f8048fb478a60b8ccd05bace17ce540a0c9a Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Tue, 12 Nov 2019 21:19:25 +0000 Subject: lokdocview: refresh tile buffer on resize to avoid UI breakage. Otherwise we get tiles in the wrong locations based on incorrrect widths. Change-Id: I1c76bc6eaabd8af4c283e421bf8901e7d64b4efa Reviewed-on: https://gerrit.libreoffice.org/82574 Tested-by: Jenkins Reviewed-by: Michael Meeks --- libreofficekit/source/gtk/lokdocview.cxx | 58 ++++++++++++-------------------- 1 file changed, 21 insertions(+), 37 deletions(-) (limited to 'libreofficekit/source/gtk/lokdocview.cxx') diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 2c2951637f01..5dd0457479af 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -355,22 +355,6 @@ struct CallbackData m_pDocView(pDocView) {} }; -static void -payloadToSize(const char* pPayload, long& rWidth, long& rHeight) -{ - rWidth = rHeight = 0; - gchar** ppCoordinates = g_strsplit(pPayload, ", ", 2); - gchar** ppCoordinate = ppCoordinates; - if (!*ppCoordinate) - return; - rWidth = atoi(*ppCoordinate); - ++ppCoordinate; - if (!*ppCoordinate) - return; - rHeight = atoi(*ppCoordinate); - g_strfreev(ppCoordinates); -} - static void LOKPostCommand (LOKDocView* pDocView, const gchar* pCommand, @@ -867,6 +851,25 @@ static std::string getAuthorRenderingArgument(LOKDocViewPrivate& priv) /// Author string <-> View ID map static std::map g_aAuthorViews; +static void refreshSize(LOKDocView* pDocView) +{ + LOKDocViewPrivate& priv = getPrivate(pDocView); + + priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips); + float zoom = priv->m_fZoom; + long nDocumentWidthTwips = priv->m_nDocumentWidthTwips; + long nDocumentHeightTwips = priv->m_nDocumentHeightTwips; + long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom); + long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom); + + // Total number of columns in this document. + guint nColumns = ceil(static_cast(nDocumentWidthPixels) / nTileSizePixels); + priv->m_pTileBuffer = std::make_unique(nColumns); + gtk_widget_set_size_request(GTK_WIDGET(pDocView), + nDocumentWidthPixels, + nDocumentHeightPixels); +} + /// Set up LOKDocView after the document is loaded, invoked on the main thread by openDocumentInThread() running in a thread. static gboolean postDocumentLoad(gpointer pData) { @@ -878,23 +881,12 @@ static gboolean postDocumentLoad(gpointer pData) priv->m_nViewId = priv->m_pDocument->pClass->getView(priv->m_pDocument); g_aAuthorViews[getAuthorRenderingArgument(priv)] = priv->m_nViewId; priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView); - priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips); priv->m_nParts = priv->m_pDocument->pClass->getParts(priv->m_pDocument); aGuard.unlock(); priv->m_nTimeoutId = g_timeout_add(600, handleTimeout, pLOKDocView); - float zoom = priv->m_fZoom; - long nDocumentWidthTwips = priv->m_nDocumentWidthTwips; - long nDocumentHeightTwips = priv->m_nDocumentHeightTwips; - long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom); - long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom); - // Total number of columns in this document. - guint nColumns = ceil(static_cast(nDocumentWidthPixels) / nTileSizePixels); + refreshSize(pLOKDocView); - priv->m_pTileBuffer = std::make_unique(nColumns); - gtk_widget_set_size_request(GTK_WIDGET(pLOKDocView), - nDocumentWidthPixels, - nDocumentHeightPixels); gtk_widget_set_can_focus(GTK_WIDGET(pLOKDocView), TRUE); gtk_widget_grab_focus(GTK_WIDGET(pLOKDocView)); lok_doc_view_set_zoom(pLOKDocView, 1.0); @@ -1220,15 +1212,7 @@ callback (gpointer pData) break; case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED: { - if (!pCallback->m_aPayload.empty()) - payloadToSize(pCallback->m_aPayload.c_str(), priv->m_nDocumentWidthTwips, priv->m_nDocumentHeightTwips); - else - priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips); - - gtk_widget_set_size_request(GTK_WIDGET(pDocView), - twipToPixel(priv->m_nDocumentWidthTwips, priv->m_fZoom), - twipToPixel(priv->m_nDocumentHeightTwips, priv->m_fZoom)); - + refreshSize(pDocView); g_signal_emit(pDocView, doc_view_signals[SIZE_CHANGED], 0, nullptr); } break; -- cgit