From 99f05d9947db2dd0676fafa66106d17e4d8eea6d Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 15 Jul 2016 15:37:51 +0200 Subject: gtktiledviewer: allow testing of destroyView() By calling it when we're not the last window. Change-Id: I6fd4763243fc088ccfe015b6c03b6b3f25146fac --- .../qa/gtktiledviewer/gtktiledviewer.cxx | 2 +- libreofficekit/source/gtk/lokdocview.cxx | 28 +++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'libreofficekit') diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index f0aabdfc9b84..f80b506a0432 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -1206,7 +1206,7 @@ static GtkWidget* createWindow(TiledWindow& rWindow) GtkWidget *pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(pWindow), "LibreOfficeKit GTK Tiled Viewer"); gtk_window_set_default_size(GTK_WINDOW(pWindow), 1280, 720); - g_signal_connect(pWindow, "destroy", G_CALLBACK(gtk_main_quit), 0); + g_signal_connect(pWindow, "destroy", G_CALLBACK(gtk_widget_destroy), pWindow); rWindow.m_pVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_container_add(GTK_CONTAINER(pWindow), rWindow.m_pVBox); diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 613a909f1c0d..0c9d13535d08 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -155,6 +155,9 @@ struct LOKDocViewPrivateImpl GdkRectangle m_aVisibleArea; bool m_bVisibleAreaSet; + /// Event source ID for handleTimeout() of this widget. + guint m_nTimeoutId; + LOKDocViewPrivateImpl() : m_aLOPath(nullptr), m_pUserProfileURL(nullptr), @@ -196,11 +199,17 @@ struct LOKDocViewPrivateImpl m_nViewId(0), m_nTileSizeTwips(0), m_aVisibleArea({0, 0, 0, 0}), - m_bVisibleAreaSet(false) + m_bVisibleAreaSet(false), + m_nTimeoutId(0) { memset(&m_aGraphicHandleRects, 0, sizeof(m_aGraphicHandleRects)); memset(&m_bInDragGraphicHandles, 0, sizeof(m_bInDragGraphicHandles)); } + + ~LOKDocViewPrivateImpl() + { + g_source_remove(m_nTimeoutId); + } }; /// Wrapper around LOKDocViewPrivateImpl, managed by malloc/memset/free. @@ -873,7 +882,7 @@ static gboolean postDocumentLoad(gpointer pData) 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(); - g_timeout_add(600, handleTimeout, pLOKDocView); + priv->m_nTimeoutId = g_timeout_add(600, handleTimeout, pLOKDocView); float zoom = priv->m_fZoom; long nDocumentWidthTwips = priv->m_nDocumentWidthTwips; @@ -2385,10 +2394,17 @@ static void lok_doc_view_finalize (GObject* object) LOKDocView* pDocView = LOK_DOC_VIEW (object); LOKDocViewPrivate& priv = getPrivate(pDocView); - if (priv->m_pDocument) - priv->m_pDocument->pClass->destroy (priv->m_pDocument); - if (priv->m_pOffice) - priv->m_pOffice->pClass->destroy (priv->m_pOffice); + if (priv->m_pDocument && priv->m_pDocument->pClass->getViews(priv->m_pDocument) > 1) + { + priv->m_pDocument->pClass->destroyView(priv->m_pDocument, priv->m_nViewId); + } + else + { + if (priv->m_pDocument) + priv->m_pDocument->pClass->destroy (priv->m_pDocument); + if (priv->m_pOffice) + priv->m_pOffice->pClass->destroy (priv->m_pOffice); + } delete priv.m_pImpl; priv.m_pImpl = nullptr; -- cgit