Blob Blame History Raw
From 3bb042ae678b26e234d19913846d695e8bfd8927 Mon Sep 17 00:00:00 2001
From: Pranav Kant <pranavk@gnome.org>
Date: Sun, 26 Jul 2015 22:39:43 +0530
Subject: [PATCH 083/398] lokdocview: setGraphicSelection in another thread

Change-Id: Ib7a6bf63ee6f300c6c5d50d02a3465d0a075a5be
(cherry picked from commit 7c45a57081a921b8f56812dd37c2fcd4b86d2a1a)
---
 libreofficekit/source/gtk/lokdocview.cxx | 68 ++++++++++++++++++++++++++++----
 libreofficekit/source/gtk/tilebuffer.hxx | 10 ++++-
 2 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index d23ac1af2fc1..edd2179495f0 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -889,7 +889,17 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
             {
                 g_info("LOKDocView_Impl::signalButton: end of drag graphic handle #%d", i);
                 priv->m_bInDragGraphicHandles[i] = false;
-                priv->m_pDocument->pClass->setGraphicSelection(priv->m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x, priv->m_fZoom), pixelToTwip(pEvent->y, priv->m_fZoom));
+
+                GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
+                LOEvent* pLOEvent = new LOEvent(LOK_SET_GRAPHIC_SELECTION);
+                pLOEvent->m_nSetGraphicSelectionType = LOK_SETGRAPHICSELECTION_END;
+                pLOEvent->m_nSetGraphicSelectionX = pixelToTwip(pEvent->x, priv->m_fZoom);
+                pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(pEvent->y, priv->m_fZoom);
+                g_task_set_task_data(task, pLOEvent, g_free);
+
+                g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
+                g_object_unref(task);
+
                 return FALSE;
             }
         }
@@ -898,7 +908,17 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
         {
             g_info("LOKDocView_Impl::signalButton: end of drag graphic selection");
             priv->m_bInDragGraphicSelection = false;
-            priv->m_pDocument->pClass->setGraphicSelection(priv->m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x, priv->m_fZoom), pixelToTwip(pEvent->y, priv->m_fZoom));
+
+            GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
+            LOEvent* pLOEvent = new LOEvent(LOK_SET_GRAPHIC_SELECTION);
+            pLOEvent->m_nSetGraphicSelectionType = LOK_SETGRAPHICSELECTION_END;
+            pLOEvent->m_nSetGraphicSelectionX = pixelToTwip(pEvent->x, priv->m_fZoom);
+            pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(pEvent->y, priv->m_fZoom);
+            g_task_set_task_data(task, pLOEvent, g_free);
+
+            g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
+            g_object_unref(task);
+
             return FALSE;
         }
     }
@@ -937,10 +957,17 @@ lok_doc_view_signal_button(GtkWidget* pWidget, GdkEventButton* pEvent)
                 {
                     g_info("LOKDocView_Impl::signalButton: start of drag graphic handle #%d", i);
                     priv->m_bInDragGraphicHandles[i] = true;
-                    priv->m_pDocument->pClass->setGraphicSelection(priv->m_pDocument,
-                                                             LOK_SETGRAPHICSELECTION_START,
-                                                             pixelToTwip(priv->m_aGraphicHandleRects[i].x + priv->m_aGraphicHandleRects[i].width / 2, priv->m_fZoom),
-                                                             pixelToTwip(priv->m_aGraphicHandleRects[i].y + priv->m_aGraphicHandleRects[i].height / 2, priv->m_fZoom));
+
+                    GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
+                    LOEvent* pLOEvent = new LOEvent(LOK_SET_GRAPHIC_SELECTION);
+                    pLOEvent->m_nSetGraphicSelectionType = LOK_SETGRAPHICSELECTION_START;
+                    pLOEvent->m_nSetGraphicSelectionX = pixelToTwip(priv->m_aGraphicHandleRects[i].x + priv->m_aGraphicHandleRects[i].width / 2, priv->m_fZoom);
+                    pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(priv->m_aGraphicHandleRects[i].y + priv->m_aGraphicHandleRects[i].height / 2, priv->m_fZoom);
+                    g_task_set_task_data(task, pLOEvent, g_free);
+
+                    g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
+                    g_object_unref(task);
+
                     return FALSE;
                 }
             }
@@ -1063,7 +1090,17 @@ lok_doc_view_signal_motion (GtkWidget* pWidget, GdkEventMotion* pEvent)
     {
         g_info("lcl_signalMotion: start of drag graphic selection");
         priv->m_bInDragGraphicSelection = true;
-        priv->m_pDocument->pClass->setGraphicSelection(priv->m_pDocument, LOK_SETGRAPHICSELECTION_START, pixelToTwip(pEvent->x, priv->m_fZoom), pixelToTwip(pEvent->y, priv->m_fZoom));
+
+        GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
+        LOEvent* pLOEvent = new LOEvent(LOK_SET_GRAPHIC_SELECTION);
+        pLOEvent->m_nSetGraphicSelectionType = LOK_SETGRAPHICSELECTION_START;
+        pLOEvent->m_nSetGraphicSelectionX = pixelToTwip(pEvent->x, priv->m_fZoom);
+        pLOEvent->m_nSetGraphicSelectionY = pixelToTwip(pEvent->y, priv->m_fZoom);
+        g_task_set_task_data(task, pLOEvent, g_free);
+
+        g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
+        g_object_unref(task);
+
         return FALSE;
     }
 
@@ -1084,6 +1121,20 @@ lok_doc_view_signal_motion (GtkWidget* pWidget, GdkEventMotion* pEvent)
 }
 
 static void
+setGraphicSelectionInThread(gpointer data)
+{
+    GTask* task = G_TASK(data);
+    LOKDocView* pDocView = LOK_DOC_VIEW(g_task_get_source_object(task));
+    LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
+    LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
+
+    priv->m_pDocument->pClass->setGraphicSelection(priv->m_pDocument,
+                                                   pLOEvent->m_nSetGraphicSelectionType,
+                                                   pLOEvent->m_nSetGraphicSelectionX,
+                                                   pLOEvent->m_nSetGraphicSelectionY);
+}
+
+static void
 postMouseEventInThread(gpointer data)
 {
     GTask* task = G_TASK(data);
@@ -1282,6 +1333,9 @@ lokThreadFunc(gpointer data, gpointer /*user_data*/)
     case LOK_POST_MOUSE_EVENT:
         postMouseEventInThread(task);
         break;
+    case LOK_SET_GRAPHIC_SELECTION:
+        setGraphicSelectionInThread(task);
+        break;
     }
 
     g_object_unref(task);
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
index aa496aaf3e8f..d2451b6c2290 100644
--- a/libreofficekit/source/gtk/tilebuffer.hxx
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
@@ -139,7 +139,8 @@ enum
     LOK_SET_PART,
     LOK_POST_KEY,
     LOK_PAINT_TILE,
-    LOK_POST_MOUSE_EVENT
+    LOK_POST_MOUSE_EVENT,
+    LOK_SET_GRAPHIC_SELECTION
 };
 
 /**
@@ -196,6 +197,13 @@ struct LOEvent
     int m_nPostMouseEventCount;
     ///@}
 
+    /// @name setGraphicSelection parameters
+    ///@{
+    int m_nSetGraphicSelectionType;
+    int m_nSetGraphicSelectionX;
+    int m_nSetGraphicSelectionY;
+    ///@}
+
     /// Constructor to instantiate an object of type `type`.
     LOEvent(int type)
         : m_nType(type) {}
-- 
2.12.0