Blame SOURCES/0011-lokdocview-use-GtkDrawingArea-for-drawing-tiles.patch

135360
From 0750e69cc4483cbcf22789d25d4518396e13fc13 Mon Sep 17 00:00:00 2001
135360
From: Pranav Kant <pranavk@gnome.org>
135360
Date: Wed, 3 Jun 2015 20:52:49 +0530
135360
Subject: [PATCH 011/398] lokdocview: use GtkDrawingArea for drawing tiles
135360
135360
Change-Id: I1a3d8a9229f416418f0f3e9c720b78af09b35978
135360
(cherry picked from commit a13d4671bf1f557b3104e745277554ed11b3e6da)
135360
---
135360
 libreofficekit/source/gtk/lokdocview.cxx | 77 +++++++++++++-------------------
135360
 1 file changed, 30 insertions(+), 47 deletions(-)
135360
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 8fa351add6a9..c487ac8dd906 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -65,6 +65,9 @@ struct LOKDocView_Impl
135360
     GtkWidget* m_pEventBox;
135360
     GtkWidget* m_pTable;
135360
     GtkWidget** m_pCanvas;
135360
+    GtkWidget *darea;
135360
+
135360
+    TileBuffer *mTileBuffer;
135360
 
135360
     float m_fZoom;
135360
 
135360
@@ -140,6 +143,8 @@ struct LOKDocView_Impl
135360
     ~LOKDocView_Impl();
135360
     /// Connected to the destroy signal of LOKDocView, deletes its LOKDocView_Impl.
135360
     static void destroy(LOKDocView* pDocView, gpointer pData);
135360
+    /// Connected to the expose-event of the GtkDrawingArea
135360
+    static void on_exposed(GtkWidget *widget, GdkEvent *event, gpointer user_data);
135360
     /// Converts from screen pixels to document coordinates.
135360
     float pixelToTwip(float fInput);
135360
     /// Converts from document coordinates to screen pixels.
135360
@@ -258,6 +263,7 @@ LOKDocView_Impl::CallbackData::CallbackData(int nType, const std::string& rPaylo
135360
 LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView)
135360
     : m_pDocView(pDocView),
135360
     m_pEventBox(gtk_event_box_new()),
135360
+    darea(gtk_drawing_area_new()),
135360
     m_pTable(0),
135360
     m_pCanvas(0),
135360
     m_fZoom(1),
135360
@@ -307,6 +313,12 @@ void LOKDocView_Impl::destroy(LOKDocView* pDocView, gpointer /*pData*/)
135360
     delete pDocView->m_pImpl;
135360
 }
135360
 
135360
+void LOKDocView_Impl::on_exposed(GtkWidget *widget, GdkEvent *event, gpointer userdata)
135360
+{
135360
+    LOKDocView *pDocView = LOK_DOCVIEW (userdata);
135360
+    pDocView->m_pImpl->renderDocument(0);
135360
+}
135360
+
135360
 float LOKDocView_Impl::pixelToTwip(float fInput)
135360
 {
135360
     return (fInput / DPI / m_fZoom) * 1440.0f;
135360
@@ -771,40 +783,17 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
 {
135360
     const int nTileSizePixels = 256;
135360
 
135360
+    GdkRectangle visibleArea;
135360
+    lok_docview_get_visarea (m_pDocView, &visibleArea);
135360
+
135360
     long nDocumentWidthPixels = twipToPixel(m_nDocumentWidthTwips);
135360
     long nDocumentHeightPixels = twipToPixel(m_nDocumentHeightTwips);
135360
     // Total number of rows / columns in this document.
135360
     guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
135360
     guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
135360
 
135360
-    // Set up our table and the tile pointers.
135360
-    if (!m_pTable)
135360
-        pPartial = 0;
135360
-    if (pPartial)
135360
-    {
135360
-        // Same as nRows / nColumns, but from the previous renderDocument() call.
135360
-        guint nOldRows, nOldColumns;
135360
-
135360
-#if GTK_CHECK_VERSION(2,22,0)
135360
-        gtk_table_get_size(GTK_TABLE(m_pTable), &nOldRows, &nOldColumns);
135360
-        if (nOldRows != nRows || nOldColumns != nColumns)
135360
-            // Can't do partial rendering, document size changed.
135360
-            pPartial = 0;
135360
-#else
135360
-        pPartial = 0;
135360
-#endif
135360
-    }
135360
-    if (!pPartial)
135360
-    {
135360
-        if (m_pTable)
135360
-            gtk_container_remove(GTK_CONTAINER(m_pEventBox), m_pTable);
135360
-        m_pTable = gtk_table_new(nRows, nColumns, FALSE);
135360
-        gtk_container_add(GTK_CONTAINER(m_pEventBox), m_pTable);
135360
-        gtk_widget_show(m_pTable);
135360
-        if (m_pCanvas)
135360
-            g_free(m_pCanvas);
135360
-        m_pCanvas = static_cast<GtkWidget**>(g_malloc0(sizeof(GtkWidget*) * nRows * nColumns));
135360
-    }
135360
+    gtk_widget_set_size_request(darea, nDocumentWidthPixels, nDocumentHeightPixels);
135360
+    cairo_t *pcairo = gdk_cairo_create(darea->window);
135360
 
135360
     // Render the tiles.
135360
     for (guint nRow = 0; nRow < nRows; ++nRow)
135360
@@ -830,7 +819,10 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
             aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width);
135360
             aTileRectangleTwips.height = pixelToTwip(aTileRectanglePixels.height);
135360
             if (pPartial && !gdk_rectangle_intersect(pPartial, &aTileRectangleTwips, 0))
135360
-                    bPaint = false;
135360
+                bPaint = false;
135360
+
135360
+            if (!gdk_rectangle_intersect(&visibleArea, &aTileRectangleTwips, 0))
135360
+                bPaint = false;
135360
 
135360
             if (bPaint)
135360
             {
135360
@@ -849,21 +841,16 @@ void LOKDocView_Impl::renderDocument(GdkRectangle* pPartial)
135360
                                                // Size of the tile, depends on the zoom factor and the tile position only.
135360
                                                aTileRectangleTwips.width, aTileRectangleTwips.height);
135360
 
135360
-                if (m_pCanvas[nTile])
135360
-                    gtk_widget_destroy(GTK_WIDGET(m_pCanvas[nTile]));
135360
-                m_pCanvas[nTile] = gtk_image_new();
135360
-                gtk_image_set_from_pixbuf(GTK_IMAGE(m_pCanvas[nTile]), pPixBuf);
135360
-                g_object_unref(G_OBJECT(pPixBuf));
135360
-                gtk_widget_show(m_pCanvas[nTile]);
135360
-                gtk_table_attach(GTK_TABLE(m_pTable),
135360
-                                 m_pCanvas[nTile],
135360
-                                 nColumn, nColumn + 1, nRow, nRow + 1,
135360
-                                 GTK_SHRINK, GTK_SHRINK, 0, 0);
135360
+                gdk_cairo_set_source_pixbuf (pcairo, pPixBuf, twipToPixel(aTileRectangleTwips.x), twipToPixel(aTileRectangleTwips.y));
135360
+                cairo_paint(pcairo);
135360
             }
135360
         }
135360
     }
135360
+
135360
+    cairo_destroy(pcairo);
135360
 }
135360
 
135360
+
135360
 GdkRectangle LOKDocView_Impl::payloadToRectangle(const char* pPayload)
135360
 {
135360
     GdkRectangle aRet;
135360
@@ -1167,17 +1154,13 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer )
135360
 
135360
     pDocView->m_pImpl = new LOKDocView_Impl(pDocView);
135360
     gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
135360
-                                           pDocView->m_pImpl->m_pEventBox );
135360
-
135360
-    gtk_widget_set_events(pDocView->m_pImpl->m_pEventBox, GDK_BUTTON_PRESS_MASK); // So that drag doesn't try to move the whole window.
135360
-    gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "button-press-event", GTK_SIGNAL_FUNC(LOKDocView_Impl::signalButton), pDocView);
135360
-    gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "button-release-event", GTK_SIGNAL_FUNC(LOKDocView_Impl::signalButton), pDocView);
135360
-    gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "motion-notify-event", GTK_SIGNAL_FUNC(LOKDocView_Impl::signalMotion), pDocView);
135360
+                                           pDocView->m_pImpl->darea );
135360
 
135360
-    gtk_widget_show( pDocView->m_pImpl->m_pEventBox );
135360
+    g_signal_connect(GTK_OBJECT(pDocView->m_pImpl->darea),
135360
+                     "expose-event",
135360
+                     GTK_SIGNAL_FUNC(LOKDocView_Impl::on_exposed), pDocView);
135360
 
135360
     gtk_signal_connect(GTK_OBJECT(pDocView), "destroy", GTK_SIGNAL_FUNC(LOKDocView_Impl::destroy), 0);
135360
-    g_signal_connect_after(pDocView->m_pImpl->m_pEventBox, "expose-event", G_CALLBACK(LOKDocView_Impl::renderOverlay), pDocView);
135360
 }
135360
 
135360
 SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
135360
-- 
135360
2.12.0
135360