Blob Blame History Raw
From d7f30799b250c8ffd3d25307e9efb5e7f13ce8b0 Mon Sep 17 00:00:00 2001
From: Pranav Kant <pranavk@gnome.org>
Date: Thu, 4 Jun 2015 14:15:58 +0530
Subject: [PATCH 016/398] lokdocview: wrap a functionality inside a member
 function

Lets use a member function to set invalid tiles that come under the
given GdkRectangle.

Change-Id: I440336ddf3c5fd9094f35bb89479aa76a42477fa
(cherry picked from commit ad0a404ef3097d92cf9a0e861e076a72074a5258)
---
 libreofficekit/source/gtk/lokdocview.cxx | 54 ++++++++++++++------------------
 1 file changed, 24 insertions(+), 30 deletions(-)

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index bfb414f0909c..cfa71a357f22 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -212,6 +212,8 @@ struct LOKDocView_Impl
     void searchNotFound(const std::string& rPayload);
     /// LOK decided to change parts, need to update UI.
     void setPart(const std::string& rPayload);
+    /// Sets the tiles enclosed by rRectangle as invalid in m_pTileBuffer
+    void setTilesInvalid(const GdkRectangle& rRectangle);
 };
 
 namespace {
@@ -646,6 +648,26 @@ bool LOKDocView_Impl::isEmptyRectangle(const GdkRectangle& rRectangle)
     return rRectangle.x == 0 && rRectangle.y == 0 && rRectangle.width == 0 && rRectangle.height == 0;
 }
 
+void LOKDocView_Impl::setTilesInvalid(const GdkRectangle& rRectangle)
+{
+    GdkRectangle aRectanglePixels;
+    GdkPoint aStart, aEnd;
+
+    aRectanglePixels.x = twipToPixel(rRectangle.x, m_fZoom);
+    aRectanglePixels.y = twipToPixel(rRectangle.y, m_fZoom);
+    aRectanglePixels.width = twipToPixel(rRectangle.width, m_fZoom);
+    aRectanglePixels.height = twipToPixel(rRectangle.height, m_fZoom);
+
+    aStart.x = aRectanglePixels.y / nTileSizePixels;
+    aStart.y = aRectanglePixels.x / nTileSizePixels;
+    aEnd.x = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
+    aEnd.y = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
+
+    for (int i = aStart.x; i < aEnd.x; i++)
+        for (int j = aStart.y; j < aEnd.y; j++)
+            m_pTileBuffer->tile_buffer_set_invalid(i, j);
+}
+
 void LOKDocView_Impl::renderHandle(cairo_t* pCairo, const GdkRectangle& rCursor, cairo_surface_t* pHandle, GdkRectangle& rRectangle)
 {
     GdkPoint aCursorBottom;
@@ -915,21 +937,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
         if (pCallback->m_aPayload != "EMPTY")
         {
             GdkRectangle aRectangle = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
-            GdkRectangle aRectanglePixels;
-            aRectanglePixels.x = twipToPixel(aRectangle.x, m_fZoom);
-            aRectanglePixels.y = twipToPixel(aRectangle.y, m_fZoom);
-            aRectanglePixels.width = twipToPixel(aRectangle.width, m_fZoom);
-            aRectanglePixels.height = twipToPixel(aRectangle.height, m_fZoom);
-            int rowStart = aRectanglePixels.y / nTileSizePixels;
-            int colStart = aRectanglePixels.x / nTileSizePixels;
-            int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
-            int colEnd = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
-            int i,j;
-            for (i = rowStart; i < rowEnd; i++) {
-                for (j = colStart; j < colEnd; j++) {
-                    m_pTileBuffer->tile_buffer_set_invalid(i, j);
-                }
-            }
+            setTilesInvalid(aRectangle);
             renderDocument(0);
         }
         else
@@ -943,21 +951,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
     {
         m_aVisibleCursor = LOKDocView_Impl::payloadToRectangle(pCallback->m_aPayload.c_str());
         m_bCursorOverlayVisible = true;
-        GdkRectangle aRectanglePixels;
-        aRectanglePixels.x = twipToPixel(m_aVisibleCursor.x, m_fZoom);
-        aRectanglePixels.y = twipToPixel(m_aVisibleCursor.y, m_fZoom);
-        aRectanglePixels.width = twipToPixel(m_aVisibleCursor.width, m_fZoom);
-        aRectanglePixels.height = twipToPixel(m_aVisibleCursor.height, m_fZoom);
-        int rowStart = aRectanglePixels.y / nTileSizePixels;
-        int colStart = aRectanglePixels.x / nTileSizePixels;
-        int rowEnd = (aRectanglePixels.y + aRectanglePixels.height + nTileSizePixels) / nTileSizePixels;
-        int colEnd = (aRectanglePixels.x + aRectanglePixels.width + nTileSizePixels) / nTileSizePixels;
-        int i,j;
-        for (i = rowStart; i < rowEnd; i++) {
-            for (j = colStart; j < colEnd; j++) {
-                m_pTileBuffer->tile_buffer_set_invalid(i, j);
-            }
-        }
+        setTilesInvalid(m_aVisibleCursor);
         renderDocument(0);
     }
     break;
-- 
2.12.0