Blob Blame History Raw
From b3c590099965fbe3adb89a1b40e8d346f82d3d76 Mon Sep 17 00:00:00 2001
From: Miklos Vajna <vmiklos@collabora.co.uk>
Date: Wed, 4 Nov 2015 10:32:23 +0100
Subject: [PATCH 273/398] sc lok: return absolute positions for row/column
 headers

This simplifies both LOK API implementation and client code, and also
clients are no longer required to floor() the twip -> pixel conversion
result.

Change-Id: I63dbc05f53e8f7582b964c43d5da3aad51ede10d
(cherry picked from commit 84dedf4ff8e7267efa95674e6545c80c9b995cb2)
---
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 36 ++++++++--------------
 sc/source/ui/view/tabview.cxx                      | 26 ++++------------
 2 files changed, 19 insertions(+), 43 deletions(-)

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index ae9f2600440c..6ebd5bcc6ef5 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -192,16 +192,16 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo)
 {
     cairo_set_source_rgb(pCairo, 0, 0, 0);
 
-    int nTotal = 0;
+    int nPrevious = 0;
     for (const Header& rHeader : m_aHeaders)
     {
         GdkRectangle aRectangle;
         if (m_eType == ROW)
         {
             aRectangle.x = 0;
-            aRectangle.y = nTotal - 1;
+            aRectangle.y = nPrevious - 1;
             aRectangle.width = ROW_HEADER_WIDTH - 1;
-            aRectangle.height = rHeader.m_nSize;
+            aRectangle.height = rHeader.m_nSize - nPrevious;
             // Left line.
             cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, 1, aRectangle.height);
             cairo_fill(pCairo);
@@ -214,9 +214,9 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo)
         }
         else
         {
-            aRectangle.x = nTotal - 1;
+            aRectangle.x = nPrevious - 1;
             aRectangle.y = 0;
-            aRectangle.width = rHeader.m_nSize;
+            aRectangle.width = rHeader.m_nSize - nPrevious;
             aRectangle.height = COLUMN_HEADER_HEIGHT - 1;
             // Top line.
             cairo_rectangle(pCairo, aRectangle.x, aRectangle.y, aRectangle.width, 1);
@@ -229,8 +229,8 @@ gboolean TiledRowColumnBar::drawImpl(GtkWidget* /*pWidget*/, cairo_t* pCairo)
             cairo_fill(pCairo);
         }
         drawText(pCairo, aRectangle, rHeader.m_aText);
-        nTotal += rHeader.m_nSize;
-        if (nTotal > m_nSizePixel)
+        nPrevious = rHeader.m_nSize;
+        if (rHeader.m_nSize > m_nSizePixel)
             break;
     }
 
@@ -275,39 +275,29 @@ gboolean TiledRowColumnBar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfi
         gtk_widget_show(rWindow.m_pCornerButton->m_pDrawingArea);
 
         rWindow.m_pRowBar->m_aHeaders.clear();
-        int nTotal = 0;
         for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("rows"))
         {
-            int nSize = lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()));
-            int nScrolledSize = nSize;
-            if (nTotal + nSize >= rWindow.m_pRowBar->m_nPositionPixel)
+            int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str())));
+            if (nSize >= rWindow.m_pRowBar->m_nPositionPixel)
             {
-                if (nTotal < rWindow.m_pRowBar->m_nPositionPixel)
-                    // First visible row: reduce height because the row is only partially visible.
-                    nScrolledSize = nTotal + nSize - rWindow.m_pRowBar->m_nPositionPixel;
+                int nScrolledSize = nSize - rWindow.m_pRowBar->m_nPositionPixel;
                 Header aHeader(nScrolledSize, rValue.second.get<std::string>("text"));
                 rWindow.m_pRowBar->m_aHeaders.push_back(aHeader);
             }
-            nTotal += nSize;
         }
         gtk_widget_show(rWindow.m_pRowBar->m_pDrawingArea);
         gtk_widget_queue_draw(rWindow.m_pRowBar->m_pDrawingArea);
 
         rWindow.m_pColumnBar->m_aHeaders.clear();
-        nTotal = 0;
         for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("columns"))
         {
-            int nSize = lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str()));
-            int nScrolledSize = nSize;
-            if (nTotal + nSize >= rWindow.m_pColumnBar->m_nPositionPixel)
+            int nSize = std::round(lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), std::atof(rValue.second.get<std::string>("size").c_str())));
+            if (nSize >= rWindow.m_pColumnBar->m_nPositionPixel)
             {
-                if (nTotal < rWindow.m_pColumnBar->m_nPositionPixel)
-                    // First visible column: reduce width because the column is only partially visible.
-                    nScrolledSize = nTotal + nSize - rWindow.m_pColumnBar->m_nPositionPixel;
+                int nScrolledSize = nSize - rWindow.m_pColumnBar->m_nPositionPixel;
                 Header aHeader(nScrolledSize, rValue.second.get<std::string>("text"));
                 rWindow.m_pColumnBar->m_aHeaders.push_back(aHeader);
             }
-            nTotal += nSize;
         }
         gtk_widget_show(rWindow.m_pColumnBar->m_pDrawingArea);
         gtk_widget_queue_draw(rWindow.m_pColumnBar->m_pDrawingArea);
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 8edec1b22f3a..d8fcd4ff4a73 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -2319,6 +2319,7 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
     for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
     {
         sal_uInt16 nSize = pDoc->GetOriginalHeight(nRow, aViewData.GetTabNo());
+        long nSizePixels = ScViewData::ToPixel(nSize, aViewData.GetPPTY());
         OUString aText = pRowBar[SC_SPLIT_BOTTOM]->GetEntryText(nRow);
 
         bool bSkip = false;
@@ -2332,22 +2333,13 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
         }
         if (!bSkip)
         {
-            if (aRows.empty() && nTotal > 0)
-            {
-                // The sizes are relative sizes, so include the total skipped size before the real items.
-                boost::property_tree::ptree aRow;
-                // Client is required to floor(), rather than round() the sizes in general, so add 0.5 here to have rounding.
-                aRow.put("size", OString::number(long((nTotalPixels + 0.5) / aViewData.GetPPTY())).getStr());
-                aRow.put("text", "");
-                aRows.push_back(std::make_pair("", aRow));
-            }
             boost::property_tree::ptree aRow;
-            aRow.put("size", OString::number(nSize).getStr());
+            aRow.put("size", OString::number((nTotalPixels + nSizePixels) / aViewData.GetPPTY()).getStr());
             aRow.put("text", aText.toUtf8().getStr());
             aRows.push_back(std::make_pair("", aRow));
         }
         nTotal += nSize;
-        nTotalPixels += long(nSize * aViewData.GetPPTY());
+        nTotalPixels += nSizePixels;
     }
 
     boost::property_tree::ptree aCols;
@@ -2356,6 +2348,7 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
     for (SCCOL nCol = 0; nCol <= nEndCol; ++nCol)
     {
         sal_uInt16 nSize = pDoc->GetColWidth(nCol, aViewData.GetTabNo());
+        long nSizePixels = ScViewData::ToPixel(nSize, aViewData.GetPPTX());
         OUString aText = pColBar[SC_SPLIT_LEFT]->GetEntryText(nCol);
 
         bool bSkip = false;
@@ -2369,20 +2362,13 @@ OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
         }
         if (!bSkip)
         {
-            if (aCols.empty() && nTotal > 0)
-            {
-                boost::property_tree::ptree aCol;
-                aCol.put("size", OString::number(long((nTotalPixels + 0.5) / aViewData.GetPPTX())).getStr());
-                aCol.put("text", "");
-                aCols.push_back(std::make_pair("", aCol));
-            }
             boost::property_tree::ptree aCol;
-            aCol.put("size", OString::number(nSize).getStr());
+            aCol.put("size", OString::number((nTotalPixels + nSizePixels) / aViewData.GetPPTX()).getStr());
             aCol.put("text", aText.toUtf8().getStr());
             aCols.push_back(std::make_pair("", aCol));
         }
         nTotal += nSize;
-        nTotalPixels += long(nSize * aViewData.GetPPTX());
+        nTotalPixels += nSizePixels;
     }
 
     boost::property_tree::ptree aTree;
-- 
2.12.0