Blame SOURCES/0081-lokdocview-Use-only-one-ctor-for-instantiating-LOEve.patch

135360
From a9ed2a81b472091a2f255cf1ffba6f48001f46d6 Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@gnome.org>
135360
Date: Sun, 26 Jul 2015 18:24:02 +0530
135360
Subject: [PATCH 081/398] lokdocview: Use only one ctor for instantiating
135360
 LOEvent
135360
135360
... and set each member variable manually.
135360
135360
Additionally, improves documentation of the struct LOEvent.
135360
135360
Change-Id: I2e8e1dc70298dc85943769e2f01c6127eedb8207
135360
(cherry picked from commit 4fb3d2e6be39fb3a7323b11a02adf853ed37a3ca)
135360
---
135360
 libreofficekit/source/gtk/lokdocview.cxx | 41 +++++++++++++++---------
135360
 libreofficekit/source/gtk/tilebuffer.cxx | 17 +++++++---
135360
 libreofficekit/source/gtk/tilebuffer.hxx | 54 +++++++++++++++-----------------
135360
 3 files changed, 65 insertions(+), 47 deletions(-)
135360
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index e44f9b96886a..6bee2f513ae9 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -39,8 +39,8 @@
135360
 /// Private struct used by this GObject type
135360
 struct _LOKDocViewPrivate
135360
 {
135360
-    gchar* m_aLOPath;
135360
-    gchar* m_aDocPath;
135360
+    const gchar* m_aLOPath;
135360
+    const gchar* m_aDocPath;
135360
     gdouble m_nLoadProgress;
135360
     gboolean m_bIsLoading;
135360
     gboolean m_bCanZoomIn;
135360
@@ -302,7 +302,10 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
135360
     if (pEvent->type == GDK_KEY_RELEASE)
135360
     {
135360
         GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
135360
+        LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY);
135360
+        pLOEvent->m_nKeyEvent = LOK_KEYEVENT_KEYUP;
135360
+        pLOEvent->m_nCharCode = nCharCode;
135360
+        pLOEvent->m_nKeyCode  = nKeyCode;
135360
         g_task_set_task_data(task, pLOEvent, g_free);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
         g_object_unref(task);
135360
@@ -310,7 +313,10 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent)
135360
     else
135360
     {
135360
         GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
135360
+        LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY);
135360
+        pLOEvent->m_nKeyEvent = LOK_KEYEVENT_KEYINPUT;
135360
+        pLOEvent->m_nCharCode = nCharCode;
135360
+        pLOEvent->m_nKeyCode  = nKeyCode;
135360
         g_task_set_task_data(task, pLOEvent, g_free);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
         g_object_unref(task);
135360
@@ -1163,7 +1169,7 @@ paintTileInThread (gpointer data)
135360
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
135360
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
135360
     TileBuffer& buffer = priv->m_aTileBuffer;
135360
-    int index = pLOEvent->m_nX * buffer.m_nWidth + pLOEvent->m_nY;
135360
+    int index = pLOEvent->m_nPaintTileX * buffer.m_nWidth + pLOEvent->m_nPaintTileY;
135360
     if (buffer.m_mTiles.find(index) != buffer.m_mTiles.end() &&
135360
         buffer.m_mTiles[index].valid)
135360
         return;
135360
@@ -1177,21 +1183,21 @@ paintTileInThread (gpointer data)
135360
 
135360
     unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
135360
     GdkRectangle aTileRectangle;
135360
-    aTileRectangle.x = pixelToTwip(nTileSizePixels, pLOEvent->m_fZoom) * pLOEvent->m_nY;
135360
-    aTileRectangle.y = pixelToTwip(nTileSizePixels, pLOEvent->m_fZoom) * pLOEvent->m_nX;
135360
+    aTileRectangle.x = pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom) * pLOEvent->m_nPaintTileY;
135360
+    aTileRectangle.y = pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom) * pLOEvent->m_nPaintTileX;
135360
 
135360
     g_test_timer_start();
135360
     priv->m_pDocument->pClass->paintTile(priv->m_pDocument,
135360
                                          pBuffer,
135360
                                          nTileSizePixels, nTileSizePixels,
135360
                                          aTileRectangle.x, aTileRectangle.y,
135360
-                                         pixelToTwip(nTileSizePixels, pLOEvent->m_fZoom),
135360
-                                         pixelToTwip(nTileSizePixels, pLOEvent->m_fZoom));
135360
+                                         pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom),
135360
+                                         pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom));
135360
 
135360
     double elapsedTime = g_test_timer_elapsed();
135360
     g_info ("Rendered (%d, %d) in %f seconds",
135360
-            pLOEvent->m_nX,
135360
-            pLOEvent->m_nY,
135360
+            pLOEvent->m_nPaintTileX,
135360
+            pLOEvent->m_nPaintTileY,
135360
             elapsedTime);
135360
 
135360
     //create a mapping for it
135360
@@ -1674,9 +1680,12 @@ lok_doc_view_open_document (LOKDocView* pDocView,
135360
                             gpointer userdata)
135360
 {
135360
     GTask* task = g_task_new(pDocView, cancellable, callback, userdata);
135360
-    LOEvent* pLOEvent = new LOEvent(LOK_LOAD_DOC, pPath);
135360
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
135360
-    priv->m_aDocPath = g_strdup(pPath);
135360
+
135360
+    LOEvent* pLOEvent = new LOEvent(LOK_LOAD_DOC);
135360
+    pLOEvent->m_pPath = pPath;
135360
+
135360
+    priv->m_aDocPath = pPath;
135360
     g_task_set_task_data(task, pLOEvent, g_free);
135360
 
135360
     g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
@@ -1836,9 +1845,11 @@ lok_doc_view_post_command (LOKDocView* pDocView,
135360
 {
135360
 
135360
     GTask* task = g_task_new(pDocView, NULL, NULL, NULL);
135360
-    LOEvent* pLOEvent = new LOEvent(LOK_POST_COMMAND, pCommand, pArguments);
135360
-    g_task_set_task_data(task, pLOEvent, g_free);
135360
+    LOEvent* pLOEvent = new LOEvent(LOK_POST_COMMAND);
135360
+    pLOEvent->m_pCommand = pCommand;
135360
+    pLOEvent->m_pArguments  = pArguments;
135360
 
135360
+    g_task_set_task_data(task, pLOEvent, g_free);
135360
     g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
     g_object_unref(task);
135360
 }
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
135360
index a8594fc916f0..21ea58b0faff 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.cxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
135360
@@ -70,26 +70,35 @@ void TileBuffer::setInvalid(int x, int y, float fZoom, GTask* task)
135360
     {
135360
         m_mTiles[index].valid = false;
135360
 
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE, x, y, fZoom);
135360
+        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
135360
+        pLOEvent->m_nPaintTileX = x;
135360
+        pLOEvent->m_nPaintTileY = y;
135360
+        pLOEvent->m_fPaintTileZoom = fZoom;
135360
         g_task_set_task_data(task, pLOEvent, g_free);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
     }
135360
 }
135360
 
135360
-Tile& TileBuffer::getTile(int x, int y, float aZoom, GTask* task)
135360
+Tile& TileBuffer::getTile(int x, int y, float fZoom, GTask* task)
135360
 {
135360
     int index = x * m_nWidth + y;
135360
 
135360
     if (m_mTiles.find(index) != m_mTiles.end() && !m_mTiles[index].valid)
135360
     {
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE, x, y, aZoom);
135360
+        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
135360
+        pLOEvent->m_nPaintTileX = x;
135360
+        pLOEvent->m_nPaintTileY = y;
135360
+        pLOEvent->m_fPaintTileZoom = fZoom;
135360
         g_task_set_task_data(task, pLOEvent, g_free);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
         return m_mTiles[index];
135360
     }
135360
     else if(m_mTiles.find(index) == m_mTiles.end())
135360
     {
135360
-        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE, x, y, aZoom);
135360
+        LOEvent* pLOEvent = new LOEvent(LOK_PAINT_TILE);
135360
+        pLOEvent->m_nPaintTileX = x;
135360
+        pLOEvent->m_nPaintTileY = y;
135360
+        pLOEvent->m_fPaintTileZoom = fZoom;
135360
         g_task_set_task_data(task, pLOEvent, g_free);
135360
         g_thread_pool_push(lokThreadPool, g_object_ref(task), NULL);
135360
         return m_DummyTile;
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
135360
index f23b02330616..6e57d2fe8bd5 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.hxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
135360
@@ -152,46 +152,44 @@ struct LOEvent
135360
 {
135360
     /// To identify the type of LOK call
135360
     int m_nType;
135360
+
135360
+    /// @name post_command parameters
135360
+    ///@{
135360
     const gchar* m_pCommand;
135360
     const gchar* m_pArguments;
135360
-    gchar* m_pPath;
135360
+    ///@}
135360
+
135360
+    /// @name open_document parameter
135360
+    ///@{
135360
+    const gchar* m_pPath;
135360
+    ///@}
135360
+
135360
+    /// set_edit parameter
135360
     gboolean m_bEdit;
135360
+
135360
+    /// set_partmode parameter
135360
     int m_nPartMode;
135360
+
135360
+    /// set_part parameter
135360
     int m_nPart;
135360
+
135360
+    /// @name postKeyEvent parameters
135360
+    ///@{
135360
     int m_nKeyEvent;
135360
     int m_nCharCode;
135360
     int m_nKeyCode;
135360
+    ///@}
135360
 
135360
-    int m_nX;
135360
-    int m_nY;
135360
-    float m_fZoom;
135360
+    /// @name paintTile parameters
135360
+    ///@{
135360
+    int m_nPaintTileX;
135360
+    int m_nPaintTileY;
135360
+    float m_fPaintTileZoom;
135360
+    ///@}
135360
 
135360
-    /// Constructor to easily instantiate an object for LOK call of `type' type.
135360
+    /// Constructor to instantiate an object of type `type`.
135360
     LOEvent(int type)
135360
         : m_nType(type) {}
135360
-
135360
-    LOEvent(int type, const gchar* pCommand, const gchar* pArguments)
135360
-        : m_nType(type),
135360
-          m_pCommand(pCommand),
135360
-          m_pArguments(pArguments) {}
135360
-
135360
-    LOEvent(int type, const gchar* pPath)
135360
-        : m_nType(type)
135360
-    {
135360
-        m_pPath = g_strdup(pPath);
135360
-    }
135360
-
135360
-    LOEvent(int type, int nKeyEvent, int nCharCode, int nKeyCode)
135360
-        : m_nType(type),
135360
-          m_nKeyEvent(nKeyEvent),
135360
-          m_nCharCode(nCharCode),
135360
-          m_nKeyCode(nKeyCode) {}
135360
-
135360
-    LOEvent(int type, int x, int y, float zoom)
135360
-        : m_nType(type),
135360
-          m_nX(x),
135360
-          m_nY(y),
135360
-          m_fZoom(zoom) {}
135360
 };
135360
 
135360
 #endif // INCLUDED_TILEBUFFER_HXX
135360
-- 
135360
2.12.0
135360