From 192a19277531a36bccadde67fbf307eebe60b3ea Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Thu, 17 Dec 2015 21:03:47 +0530 Subject: [PATCH 377/398] 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 Tested-by: David Tardon (cherry picked from commit df4a196b8f1e97d8a45d1d517942e01bd13182e7) Reviewed-on: https://gerrit.libreoffice.org/21267 Tested-by: Jenkins Reviewed-by: Pranav Kant (cherry picked from commit dd6006be974ce808f276c550d32f1bc01582aaf3) --- include/LibreOfficeKit/LibreOfficeKitGtk.h | 10 ++++--- .../qa/gtktiledviewer/gtktiledviewer.cxx | 3 ++ libreofficekit/source/gtk/lokdocview.cxx | 35 ++++++++++++++++++++-- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h index 62d2e7f29247..911bbdfa6049 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 d064c4ce3e47..e867e1b239a7 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 9d7f0740595e..858f08b66890 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(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, @@ -2518,6 +2519,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 ); } @@ -2526,6 +2530,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 ); } @@ -2538,6 +2545,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); @@ -2554,6 +2564,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 ); } @@ -2566,6 +2580,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); @@ -2632,6 +2650,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); @@ -2658,6 +2680,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 @@ -2693,6 +2719,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); } @@ -2706,6 +2734,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"); -- 2.12.0