kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

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

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