include/LibreOfficeKit/LibreOfficeKitGtk.h | 10 +++-- libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 3 + libreofficekit/source/gtk/lokdocview.cxx | 35 ++++++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-)
New commits: commit dd6006be974ce808f276c550d32f1bc01582aaf3 Author: Pranav Kant <pran...@libreoffice.org> Date: Thu Dec 17 21:03:47 2015 +0530 lokdocview: Return if no document is set For example, when document has been destroyed using lok_doc_view_destroy_document() Change-Id: I531b85018ffa25bcf88fb101c912b9f11b489a97 Reviewed-on: https://gerrit.libreoffice.org/20779 Reviewed-by: David Tardon <dtar...@redhat.com> Tested-by: David Tardon <dtar...@redhat.com> (cherry picked from commit df4a196b8f1e97d8a45d1d517942e01bd13182e7) Reviewed-on: https://gerrit.libreoffice.org/21267 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Pranav Kant <pran...@gnome.org> diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h index 62d2e7f..911bbdf 100644 --- a/include/LibreOfficeKit/LibreOfficeKitGtk.h +++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h @@ -125,7 +125,7 @@ gfloat lok_doc_view_get_zoom (LOKDocView* * @pDocView: The #LOKDocView instance * * Returns: Part refers to either individual sheets in a Calc, or slides in Impress, - * and has no relevance for Writer. + * and has no relevance for Writer. Returns -1 if no document is set currently. */ gint lok_doc_view_get_parts (LOKDocView* pDocView); @@ -133,7 +133,7 @@ gint lok_doc_view_get_parts (LOKDocView* * lok_doc_view_get_part: * @pDocView: The #LOKDocView instance * - * Returns: Current part number of the document + * Returns: Current part number of the document. Returns -1 if no document is set currently. */ gint lok_doc_view_get_part (LOKDocView* pDocView); @@ -150,7 +150,8 @@ void lok_doc_view_set_part (LOKDocView* * @pDocView: The #LOKDocView instance * @nPart: * - * Returns: Get current part name of loaded document + * Returns: Get current part name of loaded document. Returns null if no + * document is set, or document has been destroyed using lok_doc_view_destroy_document. */ gchar* lok_doc_view_get_part_name (LOKDocView* pDocView, int nPart); @@ -248,7 +249,8 @@ void lok_doc_view_highlight_all (LOKDocView* * @pUsedMimeType: (out): output parameter to inform about the determined format * (suggested or plain text). * - * Returns: Selected text. The caller must free the returned buffer after use. + * Returns: Selected text. The caller must free the returned buffer after + * use. Returns null if no document is set. */ gchar* lok_doc_view_copy_selection (LOKDocView* pDocView, const gchar* pMimeType, diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index b4dbe16..fb886ef 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -549,7 +549,10 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/) TiledWindow& rWindow = lcl_getTiledWindow(pButton); LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView); char* pUsedFormat = nullptr; + // TODO: Should check `text-selection` signal before trying to copy char* pSelection = lok_doc_view_copy_selection(pLOKDocView, "text/html", &pUsedFormat); + if (!pSelection) + return; GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(rWindow.m_pDocView), GDK_SELECTION_CLIPBOARD); std::string aUsedFormat(pUsedFormat); diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index eb20aab..ae8e52a 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -342,6 +342,9 @@ doSearch(LOKDocView* pDocView, const char* pText, bool bBackwards, bool highligh cairo_rectangle_int_t cairoVisRect; int x, y; + if (!priv->m_pDocument) + return; + cairo_region_get_rectangle(cairoVisRegion, 0, &cairoVisRect); x = pixelToTwip (cairoVisRect.x, priv->m_fZoom); y = pixelToTwip (cairoVisRect.y, priv->m_fZoom); @@ -1630,8 +1633,6 @@ setClientZoomInThread(gpointer data) LOKDocViewPrivate& priv = getPrivate(pDocView); LOEvent* pLOEvent = static_cast<LOEvent*>(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, @@ -2520,6 +2521,9 @@ SAL_DLLPUBLIC_EXPORT gint lok_doc_view_get_parts (LOKDocView* pDocView) { LOKDocViewPrivate& priv = getPrivate(pDocView); + if (!priv->m_pDocument) + return -1; + priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId); return priv->m_pDocument->pClass->getParts( priv->m_pDocument ); } @@ -2528,6 +2532,9 @@ SAL_DLLPUBLIC_EXPORT gint lok_doc_view_get_part (LOKDocView* pDocView) { LOKDocViewPrivate& priv = getPrivate(pDocView); + if (!priv->m_pDocument) + return -1; + priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId); return priv->m_pDocument->pClass->getPart( priv->m_pDocument ); } @@ -2540,6 +2547,9 @@ lok_doc_view_set_part (LOKDocView* pDocView, int nPart) LOEvent* pLOEvent = new LOEvent(LOK_SET_PART); GError* error = nullptr; + if (!priv->m_pDocument) + return; + pLOEvent->m_nPart = nPart; g_task_set_task_data(task, pLOEvent, LOEvent::destroy); @@ -2556,6 +2566,10 @@ SAL_DLLPUBLIC_EXPORT gchar* lok_doc_view_get_part_name (LOKDocView* pDocView, int nPart) { LOKDocViewPrivate& priv = getPrivate(pDocView); + + if (!priv->m_pDocument) + return nullptr; + priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId); return priv->m_pDocument->pClass->getPartName( priv->m_pDocument, nPart ); } @@ -2568,6 +2582,10 @@ lok_doc_view_set_partmode(LOKDocView* pDocView, GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr); LOEvent* pLOEvent = new LOEvent(LOK_SET_PARTMODE); GError* error = nullptr; + + if (!priv->m_pDocument) + return; + pLOEvent->m_nPartMode = nPartMode; g_task_set_task_data(task, pLOEvent, LOEvent::destroy); @@ -2634,6 +2652,10 @@ lok_doc_view_set_edit(LOKDocView* pDocView, GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr); LOEvent* pLOEvent = new LOEvent(LOK_SET_EDIT); GError* error = nullptr; + + if (!priv->m_pDocument) + return; + pLOEvent->m_bEdit = bEdit; g_task_set_task_data(task, pLOEvent, LOEvent::destroy); @@ -2660,6 +2682,10 @@ lok_doc_view_post_command (LOKDocView* pDocView, gboolean bNotifyWhenFinished) { LOKDocViewPrivate& priv = getPrivate(pDocView); + + if (!priv->m_pDocument) + return; + if (priv->m_bEdit) LOKPostCommand(pDocView, pCommand, pArguments, bNotifyWhenFinished); else @@ -2695,6 +2721,8 @@ lok_doc_view_copy_selection (LOKDocView* pDocView, gchar** pUsedMimeType) { LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pDocView); + if (!pDocument) + return nullptr; return pDocument->pClass->getTextSelection(pDocument, pMimeType, pUsedMimeType); } @@ -2708,6 +2736,9 @@ lok_doc_view_paste (LOKDocView* pDocView, LibreOfficeKitDocument* pDocument = priv->m_pDocument; gboolean ret = 0; + if (!pDocument) + return false; + if (!priv->m_bEdit) { g_info ("ignoring paste in view-only mode"); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits