diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-09-15 15:36:51 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-09-21 07:30:19 +0200 |
commit | e6e5c248e52524ddaddc6d1a2627f10f169d0167 (patch) | |
tree | c39185568e6e1e3c5eb0d634cc8e46ce462399f9 /libreofficekit | |
parent | c1d72145314be0e53d5f93e3b639715c9fbba8b0 (diff) |
lokdocview: avoid GTK+ calls in openDocumentInThread()
GTK+ calls should be made from the main thread.
Change-Id: Idcfa46d427d6e35fc544246a691bafc72f75a74c
Diffstat (limited to 'libreofficekit')
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index b185de3980e0..ff9b2cd9a9a8 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -143,6 +143,7 @@ enum static guint doc_view_signals[LAST_SIGNAL] = { 0 }; static void lok_doc_view_initable_iface_init (GInitableIface *iface); +static void callbackWorker (int nType, const char* pPayload, void* pData); SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type(); #ifdef __GNUC__ @@ -380,6 +381,37 @@ static gboolean queueDraw(gpointer pData) return G_SOURCE_REMOVE; } +/// Set up LOKDocView after the document is loaded, invoked on the main thread by openDocumentInThread() running in a thread. +static gboolean postDocumentLoad(gpointer pData) +{ + LOKDocView* pLOKDocView = static_cast<LOKDocView*>(pData); + LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView)); + + priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument); + priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView); + priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips); + 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((double)nDocumentWidthPixels / nTileSizePixels); + + + priv->m_aTileBuffer = TileBuffer(priv->m_pDocument, + 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)); + + return G_SOURCE_REMOVE; +} + /// Implementation of the global callback handler, invoked by globalCallback(); static gboolean globalCallback (gpointer pData) @@ -617,8 +649,7 @@ callback (gpointer pData) return G_SOURCE_REMOVE; } -static void -callbackWorker (int nType, const char* pPayload, void* pData) +static void callbackWorker (int nType, const char* pPayload, void* pData) { LOKDocView* pDocView = LOK_DOC_VIEW (pData); @@ -1193,27 +1224,7 @@ openDocumentInThread (gpointer data) } else { - priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument); - priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pDocView); - priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips); - g_timeout_add(600, handleTimeout, pDocView); - - 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((double)nDocumentWidthPixels / nTileSizePixels); - - - priv->m_aTileBuffer = TileBuffer(priv->m_pDocument, - nColumns); - gtk_widget_set_size_request(GTK_WIDGET(pDocView), - nDocumentWidthPixels, - nDocumentHeightPixels); - gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE); - gtk_widget_grab_focus(GTK_WIDGET(pDocView)); + gdk_threads_add_idle(postDocumentLoad, pDocView); g_task_return_boolean (task, true); } } |