Blame SOURCES/0014-lokdocview-Add-support-for-editing-documents.patch

135360
From 34a8ad7556a7a69f70a87d4d4e3dab328cff33de Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@gnome.org>
135360
Date: Thu, 4 Jun 2015 03:32:18 +0530
135360
Subject: [PATCH 014/398] lokdocview: Add support for editing documents
135360
135360
Change-Id: I8637d99e6fa59129af207e667bcdf03dc212efeb
135360
(cherry picked from commit 82a208a08fdfa8b6dab4f1577931f5e4f037276c)
135360
---
135360
 libreofficekit/source/gtk/lokdocview.cxx | 50 ++++++++++++++--
135360
 libreofficekit/source/gtk/tilebuffer.cxx | 99 ++++++++++++++++++--------------
135360
 libreofficekit/source/gtk/tilebuffer.hxx | 68 +++++++++++-----------
135360
 3 files changed, 136 insertions(+), 81 deletions(-)
135360
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 413054cf873c..3b894f765faa 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -821,7 +821,7 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
 
135360
             if (bPaint)
135360
             {
135360
-                g_info("gettile: (%d %d)", nRow, nColumn);
135360
+                //                g_info("gettile: (%d %d)", nRow, nColumn);
135360
 
135360
                 Tile& currentTile = m_pTileBuffer->tile_buffer_get_tile(nRow, nColumn);
135360
                 GdkPixbuf* pPixBuf = currentTile.tile_get_buffer();
135360
@@ -934,17 +934,50 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
135360
         if (pCallback->m_aPayload != "EMPTY")
135360
         {
135360
             GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
135360
-            renderDocument(&aRectangle);
135360
+            GdkRectangle aRectanglePixels;
135360
+            aRectanglePixels.x = twipToPixel(aRectangle.x);
135360
+            aRectanglePixels.y = twipToPixel(aRectangle.y);
135360
+            aRectanglePixels.width = twipToPixel(aRectangle.width);
135360
+            aRectanglePixels.height = twipToPixel(aRectangle.height);
135360
+            int rowStart = aRectanglePixels.y / nTileSizePixels;
135360
+            int colStart = aRectanglePixels.x / nTileSizePixels;
135360
+            int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
135360
+            int colEnd = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
135360
+            int i,j;
135360
+            for (i = rowStart; i < rowEnd; i++) {
135360
+                for (j = colStart; j < colEnd; j++) {
135360
+                    m_pTileBuffer->tile_buffer_set_invalid(i, j);
135360
+                }
135360
+            }
135360
+            renderDocument(0);
135360
         }
135360
         else
135360
+        {
135360
+            m_pTileBuffer->tile_buffer_reset_all_tiles();
135360
             renderDocument(0);
135360
+        }
135360
     }
135360
     break;
135360
     case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
135360
     {
135360
         m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
135360
         m_bCursorOverlayVisible = true;
135360
-        gtk_widget_queue_draw(GTK_WIDGET(m_pDrawingArea));
135360
+        GdkRectangle aRectanglePixels;
135360
+        aRectanglePixels.x = twipToPixel(m_aVisibleCursor.x);
135360
+        aRectanglePixels.y = twipToPixel(m_aVisibleCursor.y);
135360
+        aRectanglePixels.width = twipToPixel(m_aVisibleCursor.width);
135360
+        aRectanglePixels.height = twipToPixel(m_aVisibleCursor.height);
135360
+        int rowStart = aRectanglePixels.y / nTileSizePixels;
135360
+        int colStart = aRectanglePixels.x / nTileSizePixels;
135360
+        int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
135360
+        int colEnd = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
135360
+        int i,j;
135360
+        for (i = rowStart; i < rowEnd; i++) {
135360
+            for (j = colStart; j < colEnd; j++) {
135360
+                m_pTileBuffer->tile_buffer_set_invalid(i, j);
135360
+            }
135360
+        }
135360
+        renderDocument(0);
135360
     }
135360
     break;
135360
     case LOK_CALLBACK_TEXT_SELECTION:
135360
@@ -961,7 +994,6 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
135360
         }
135360
         else
135360
             memset(&m_aHandleMiddleRect, 0, sizeof(m_aHandleMiddleRect));
135360
-        gtk_widget_queue_draw(GTK_WIDGET(m_pDrawingArea));
135360
     }
135360
     break;
135360
     case LOK_CALLBACK_TEXT_SELECTION_START:
135360
@@ -1144,6 +1176,16 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer )
135360
     g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
135360
                      "expose-event",
135360
                      GTK_SIGNAL_FUNC(LOKDocView_Impl::on_exposed), pDocView);
135360
+    g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pDrawingArea),
135360
+                     "expose-event",
135360
+                     GTK_SIGNAL_FUNC(LOKDocView_Impl::renderOverlay), pDocView);
135360
+    gtk_widget_add_events(pDocView->m_pImpl->m_pDrawingArea,
135360
+                          GDK_BUTTON_PRESS_MASK
135360
+                          | GDK_BUTTON_RELEASE_MASK
135360
+                          | GDK_BUTTON_MOTION_MASK);
135360
+    g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "button-press-event", G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
135360
+    g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "button-release-event", G_CALLBACK(LOKDocView_Impl::signalButton), pDocView);
135360
+    g_signal_connect(G_OBJECT(pDocView->m_pImpl->m_pDrawingArea), "motion-notify-event", G_CALLBACK(LOKDocView_Impl::signalMotion), pDocView);
135360
 
135360
     gtk_signal_connect(GTK_OBJECT(pDocView), "destroy", GTK_SIGNAL_FUNC(LOKDocView_Impl::destroy), 0);
135360
 }
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx
135360
index e1b5b3294cc5..e13f5b034c1d 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.cxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.cxx
135360
@@ -23,69 +23,82 @@ static float twipToPixel(float fInput, float zoom)
135360
 
135360
 GdkPixbuf* Tile::tile_get_buffer()
135360
 {
135360
-  return m_pBuffer;
135360
+    return m_pBuffer;
135360
 }
135360
 
135360
 void Tile::tile_release()
135360
 {
135360
-  gdk_pixbuf_unref(m_pBuffer);
135360
-  m_pBuffer = NULL;
135360
+    g_object_unref (m_pBuffer);
135360
+    m_pBuffer = NULL;
135360
 }
135360
 
135360
 void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns)
135360
 {
135360
-  m_fZoomFactor = newZoomFactor;
135360
+    m_fZoomFactor = newZoomFactor;
135360
 
135360
-  tile_buffer_reset_all_tiles();
135360
+    tile_buffer_reset_all_tiles();
135360
 
135360
-  // set new buffer width and height
135360
-  m_nWidth = columns;
135360
-  m_nHeight = rows;
135360
+    // set new buffer width and height
135360
+    m_nWidth = columns;
135360
+    m_nHeight = rows;
135360
 }
135360
 
135360
 void TileBuffer::tile_buffer_reset_all_tiles()
135360
 {
135360
-  std::map<int, Tile>::iterator it = m_mTiles.begin();
135360
-  for (; it != m_mTiles.end(); it++)
135360
-    {
135360
-       it->second.tile_release();
135360
-    }
135360
-  m_mTiles.clear();
135360
+    std::map<int, Tile>::iterator it = m_mTiles.begin();
135360
+    for (; it != m_mTiles.end(); it++)
135360
+        {
135360
+            it->second.tile_release();
135360
+        }
135360
+    m_mTiles.clear();
135360
+}
135360
+
135360
+void TileBuffer::tile_buffer_set_invalid(int x, int y)
135360
+{
135360
+    int index = x * m_nWidth + y;
135360
+    g_info("setting invalid : %d %d",x, y);
135360
+    if (m_mTiles.find(index) != m_mTiles.end())
135360
+        {
135360
+            m_mTiles[index].valid = 0;
135360
+            m_mTiles[index].tile_release();
135360
+            m_mTiles.erase(index);
135360
+        }
135360
 }
135360
 
135360
 Tile& TileBuffer::tile_buffer_get_tile(int x, int y)
135360
 {
135360
-  int index = x * m_nWidth + y;
135360
-  if(m_mTiles.find(index) == m_mTiles.end())
135360
-    {
135360
-      GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
135360
-      if (!pPixBuf){
135360
-        g_info ("error allocating memory to pixbuf");
135360
-      }
135360
-      unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
135360
-      GdkRectangle aTileRectangle;
135360
-      aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y;
135360
-      aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x;
135360
-
135360
-      g_info ("rendering (%d %d)", x, y);
135360
-      m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
135360
-                                        // Buffer and its size, depends on the position only.
135360
-                                        pBuffer,
135360
-                                        m_nTileSize, m_nTileSize,
135360
-                                        // Position of the tile.
135360
-                                        aTileRectangle.x, aTileRectangle.y,
135360
-                                        // Size of the tile, depends on the zoom factor and the tile position only.
135360
-                                        pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor));
135360
-
135360
-      //create a mapping for it
135360
-      m_mTiles[index].tile_set_pixbuf(pPixBuf);
135360
-      m_mTiles[index].valid = 1;
135360
-    }
135360
-
135360
-  return m_mTiles[index];
135360
+    int index = x * m_nWidth + y;
135360
+    if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
135360
+        {
135360
+
135360
+            GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize);
135360
+            if (!pPixBuf){
135360
+                g_info ("error allocating memory to pixbuf");
135360
+            }
135360
+            unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
135360
+            GdkRectangle aTileRectangle;
135360
+            aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y;
135360
+            aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x;
135360
+
135360
+            g_info ("rendering (%d %d)", x, y);
135360
+            m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
135360
+                                              // Buffer and its size, depends on the position only.
135360
+                                              pBuffer,
135360
+                                              m_nTileSize, m_nTileSize,
135360
+                                              // Position of the tile.
135360
+                                              aTileRectangle.x, aTileRectangle.y,
135360
+                                              // Size of the tile, depends on the zoom factor and the tile position only.
135360
+                                              pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor));
135360
+
135360
+            //create a mapping for it
135360
+            m_mTiles[index].tile_set_pixbuf(pPixBuf);
135360
+            m_mTiles[index].valid = 1;
135360
+        }
135360
+
135360
+    return m_mTiles[index];
135360
 }
135360
 
135360
 void Tile::tile_set_pixbuf(GdkPixbuf *buffer)
135360
 {
135360
-  m_pBuffer = buffer;
135360
+    m_pBuffer = buffer;
135360
 }
135360
diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx
135360
index 0bc2d38dd641..088df93ca6b6 100644
135360
--- a/libreofficekit/source/gtk/tilebuffer.hxx
135360
+++ b/libreofficekit/source/gtk/tilebuffer.hxx
135360
@@ -25,18 +25,17 @@
135360
 */
135360
 class Tile
135360
 {
135360
-public:
135360
-  Tile() : valid(0) {}
135360
-  ~Tile() {
135360
-    tile_release();
135360
-  }
135360
+ public:
135360
+ Tile() : valid(0) {}
135360
+    ~Tile() {
135360
+    }
135360
 
135360
-  GdkPixbuf* tile_get_buffer();
135360
-  void tile_release();
135360
-  void tile_set_pixbuf(GdkPixbuf*);
135360
-  bool valid;
135360
-private:
135360
-  GdkPixbuf *m_pBuffer;
135360
+    GdkPixbuf* tile_get_buffer();
135360
+    void tile_release();
135360
+    void tile_set_pixbuf(GdkPixbuf*);
135360
+    bool valid;
135360
+ private:
135360
+    GdkPixbuf *m_pBuffer;
135360
 };
135360
 
135360
 /*
135360
@@ -45,32 +44,33 @@ private:
135360
 */
135360
 class TileBuffer
135360
 {
135360
-public:
135360
-  TileBuffer(LibreOfficeKitDocument *document,
135360
-             int tileSize,
135360
-             int rows,
135360
-             int columns)
135360
-    : m_pLOKDocument(document)
135360
-    , m_nTileSize(tileSize)
135360
-    , m_fZoomFactor(1)
135360
-    , m_nWidth(columns)
135360
-    , m_nHeight(rows)
135360
+ public:
135360
+ TileBuffer(LibreOfficeKitDocument *document,
135360
+            int tileSize,
135360
+            int rows,
135360
+            int columns)
135360
+     : m_pLOKDocument(document)
135360
+        , m_nTileSize(tileSize)
135360
+        , m_fZoomFactor(1)
135360
+        , m_nWidth(columns)
135360
+        , m_nHeight(rows)
135360
     {  }
135360
 
135360
-  ~TileBuffer() {}
135360
+    ~TileBuffer() {}
135360
 
135360
-  void tile_buffer_set_zoom(float zoomFactor, int rows, int columns);
135360
-  Tile& tile_buffer_get_tile(int x, int y);
135360
-  void tile_buffer_update();
135360
-  void tile_buffer_reset_all_tiles();
135360
-private:
135360
-  LibreOfficeKitDocument *m_pLOKDocument;
135360
-  int m_nTileSize;
135360
-  float m_fZoomFactor;
135360
-  std::map<int, Tile> m_mTiles;
135360
-  //TODO: Also set width and height when document size changes
135360
-  int m_nWidth;
135360
-  int m_nHeight;
135360
+    void tile_buffer_set_zoom(float zoomFactor, int rows, int columns);
135360
+    Tile& tile_buffer_get_tile(int x, int y);
135360
+    void tile_buffer_update();
135360
+    void tile_buffer_reset_all_tiles();
135360
+    void tile_buffer_set_invalid(int x, int y);
135360
+ private:
135360
+    LibreOfficeKitDocument *m_pLOKDocument;
135360
+    int m_nTileSize;
135360
+    float m_fZoomFactor;
135360
+    std::map<int, Tile> m_mTiles;
135360
+    //TODO: Also set width and height when document size changes
135360
+    int m_nWidth;
135360
+    int m_nHeight;
135360
 };
135360
 
135360
 #endif // INCLUDED_TILEBUFFER_HXX
135360
-- 
135360
2.12.0
135360