Kaydet (Commit) df4a196b authored tarafından Pranav Kant's avatar Pranav Kant Kaydeden (comit) David Tardon

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/20779Reviewed-by: 's avatarDavid Tardon <dtardon@redhat.com>
Tested-by: 's avatarDavid Tardon <dtardon@redhat.com>
üst d1385731
......@@ -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,
......
......@@ -562,7 +562,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);
......
......@@ -341,6 +341,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);
......@@ -1629,8 +1632,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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment