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

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