Blame SOURCES/0273-sc-lok-return-absolute-positions-for-row-column-head.patch

135360
From b3c590099965fbe3adb89a1b40e8d346f82d3d76 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Wed, 4 Nov 2015 10:32:23 +0100
135360
Subject: [PATCH 273/398] sc lok: return absolute positions for row/column
135360
 headers
135360
135360
This simplifies both LOK API implementation and client code, and also
135360
clients are no longer required to floor() the twip -> pixel conversion
135360
result.
135360
135360
Change-Id: I63dbc05f53e8f7582b964c43d5da3aad51ede10d
135360
(cherry picked from commit 84dedf4ff8e7267efa95674e6545c80c9b995cb2)
135360
---
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 36 ++++++++--------------
135360
 sc/source/ui/view/tabview.cxx                      | 26 ++++------------
135360
 2 files changed, 19 insertions(+), 43 deletions(-)
135360
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index ae9f2600440c..6ebd5bcc6ef5 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -192,16 +192,16 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo)
135360
 {
135360
     cairo_set_source_rgb(pCairo, 0, 0, 0);
135360
 
135360
-    int nTotal = 0;
135360
+    int nPrevious = 0;
135360
     for (const Header& rHeader : m_aHeaders)
135360
     {
135360
         GdkRectangle aRectangle;
135360
         if (m_eType == ROW)
135360
         {
135360
             aRectangle.x = 0;
135360
-            aRectangle.y = nTotal - 1;
135360
+            aRectangle.y = nPrevious - 1;
135360
             aRectangle.width = ROW_HEADER_WIDTH - 1;
135360
-            aRectangle.height = rHeader.m_nSize;
135360
+            aRectangle.height = rHeader.m_nSize - nPrevious;
135360
             // Left line.
135360
             cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, 1, aRectangle.height);
135360
             cairo_fill(pCairo);
135360
@@ -214,9 +214,9 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo)
135360
         }
135360
         else
135360
         {
135360
-            aRectangle.x = nTotal - 1;
135360
+            aRectangle.x = nPrevious - 1;
135360
             aRectangle.y = 0;
135360
-            aRectangle.width = rHeader.m_nSize;
135360
+            aRectangle.width = rHeader.m_nSize - nPrevious;
135360
             aRectangle.height = COLUMN_HEADER_HEIGHT - 1;
135360
             // Top line.
135360
             cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, aRectangle.width, 1);
135360
@@ -229,8 +229,8 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo)
135360
             cairo_fill(pCairo);
135360
         }
135360
         drawText(pCairo, aRectangle, rHeader.m_aText);
135360
-        nTotal += rHeader.m_nSize;
135360
-        if (nTotal > m_nSizePixel)
135360
+        nPrevious = rHeader.m_nSize;
135360
+        if (rHeader.m_nSize > m_nSizePixel)
135360
             break;
135360
     }
135360
 
135360
@@ -275,39 +275,29 @@ gboolean TiledRowColumnBar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfi
135360
         gtk_widget_show(rWindow.m_pCornerButton->m_pDrawingArea);
135360
 
135360
         rWindow.m_pRowBar->m_aHeaders.clear();
135360
-        int nTotal = 0;
135360
         for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("rows"))
135360
         {
135360
-            int nSize = lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()));
135360
-            int nScrolledSize = nSize;
135360
-            if (nTotal + nSize >= rWindow.m_pRowBar->m_nPositionPixel)
135360
+            int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str())));
135360
+            if (nSize >= rWindow.m_pRowBar->m_nPositionPixel)
135360
             {
135360
-                if (nTotal < rWindow.m_pRowBar->m_nPositionPixel)
135360
-                    // First visible row: reduce height because the row is only partially visible.
135360
-                    nScrolledSize = nTotal + nSize - rWindow.m_pRowBar->m_nPositionPixel;
135360
+                int nScrolledSize = nSize - rWindow.m_pRowBar->m_nPositionPixel;
135360
                 Header aHeader(nScrolledSize, rValue.second.get<std::string>("text"));
135360
                 rWindow.m_pRowBar->m_aHeaders.push_back(aHeader);
135360
             }
135360
-            nTotal += nSize;
135360
         }
135360
         gtk_widget_show(rWindow.m_pRowBar->m_pDrawingArea);
135360
         gtk_widget_queue_draw(rWindow.m_pRowBar->m_pDrawingArea);
135360
 
135360
         rWindow.m_pColumnBar->m_aHeaders.clear();
135360
-        nTotal = 0;
135360
         for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("columns"))
135360
         {
135360
-            int nSize = lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()));
135360
-            int nScrolledSize = nSize;
135360
-            if (nTotal + nSize >= rWindow.m_pColumnBar->m_nPositionPixel)
135360
+            int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str())));
135360
+            if (nSize >= rWindow.m_pColumnBar->m_nPositionPixel)
135360
             {
135360
-                if (nTotal < rWindow.m_pColumnBar->m_nPositionPixel)
135360
-                    // First visible column: reduce width because the column is only partially visible.
135360
-                    nScrolledSize = nTotal + nSize - rWindow.m_pColumnBar->m_nPositionPixel;
135360
+                int nScrolledSize = nSize - rWindow.m_pColumnBar->m_nPositionPixel;
135360
                 Header aHeader(nScrolledSize, rValue.second.get<std::string>("text"));
135360
                 rWindow.m_pColumnBar->m_aHeaders.push_back(aHeader);
135360
             }
135360
-            nTotal += nSize;
135360
         }
135360
         gtk_widget_show(rWindow.m_pColumnBar->m_pDrawingArea);
135360
         gtk_widget_queue_draw(rWindow.m_pColumnBar->m_pDrawingArea);
135360
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
135360
index 8edec1b22f3a..d8fcd4ff4a73 100644
135360
--- a/sc/source/ui/view/tabview.cxx
135360
+++ b/sc/source/ui/view/tabview.cxx
135360
@@ -2319,6 +2319,7 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
135360
     for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
135360
     {
135360
         sal_uInt16 nSize = pDoc->GetOriginalHeight(nRow, aViewData.GetTabNo());
135360
+        long nSizePixels = ScViewData::ToPixel(nSize, aViewData.GetPPTY());
135360
         OUString aText = pRowBar[SC_SPLIT_BOTTOM]->GetEntryText(nRow);
135360
 
135360
         bool bSkip = false;
135360
@@ -2332,22 +2333,13 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
135360
         }
135360
         if (!bSkip)
135360
         {
135360
-            if (aRows.empty() && nTotal > 0)
135360
-            {
135360
-                // The sizes are relative sizes, so include the total skipped size before the real items.
135360
-                boost::property_tree::ptree aRow;
135360
-                // Client is required to floor(), rather than round() the sizes in general, so add 0.5 here to have rounding.
135360
-                aRow.put("size", OString::number(long((nTotalPixels + 0.5) / aViewData.GetPPTY())).getStr());
135360
-                aRow.put("text", "");
135360
-                aRows.push_back(std::make_pair("", aRow));
135360
-            }
135360
             boost::property_tree::ptree aRow;
135360
-            aRow.put("size", OString::number(nSize).getStr());
135360
+            aRow.put("size", OString::number((nTotalPixels + nSizePixels) / aViewData.GetPPTY()).getStr());
135360
             aRow.put("text", aText.toUtf8().getStr());
135360
             aRows.push_back(std::make_pair("", aRow));
135360
         }
135360
         nTotal += nSize;
135360
-        nTotalPixels += long(nSize * aViewData.GetPPTY());
135360
+        nTotalPixels += nSizePixels;
135360
     }
135360
 
135360
     boost::property_tree::ptree aCols;
135360
@@ -2356,6 +2348,7 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
135360
     for (SCCOL nCol = 0; nCol <= nEndCol; ++nCol)
135360
     {
135360
         sal_uInt16 nSize = pDoc->GetColWidth(nCol, aViewData.GetTabNo());
135360
+        long nSizePixels = ScViewData::ToPixel(nSize, aViewData.GetPPTX());
135360
         OUString aText = pColBar[SC_SPLIT_LEFT]->GetEntryText(nCol);
135360
 
135360
         bool bSkip = false;
135360
@@ -2369,20 +2362,13 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
135360
         }
135360
         if (!bSkip)
135360
         {
135360
-            if (aCols.empty() && nTotal > 0)
135360
-            {
135360
-                boost::property_tree::ptree aCol;
135360
-                aCol.put("size", OString::number(long((nTotalPixels + 0.5) / aViewData.GetPPTX())).getStr());
135360
-                aCol.put("text", "");
135360
-                aCols.push_back(std::make_pair("", aCol));
135360
-            }
135360
             boost::property_tree::ptree aCol;
135360
-            aCol.put("size", OString::number(nSize).getStr());
135360
+            aCol.put("size", OString::number((nTotalPixels + nSizePixels) / aViewData.GetPPTX()).getStr());
135360
             aCol.put("text", aText.toUtf8().getStr());
135360
             aCols.push_back(std::make_pair("", aCol));
135360
         }
135360
         nTotal += nSize;
135360
-        nTotalPixels += long(nSize * aViewData.GetPPTX());
135360
+        nTotalPixels += nSizePixels;
135360
     }
135360
 
135360
     boost::property_tree::ptree aTree;
135360
-- 
135360
2.12.0
135360