Blame SOURCES/0266-sc-lok-allow-requesting-row-headers-only-for-a-logic.patch

135360
From b9bafd8ec0d8725350c4f00bcb9e60d2b06b976c Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Tue, 3 Nov 2015 15:05:37 +0100
135360
Subject: [PATCH 266/398] sc lok: allow requesting row headers only for a logic
135360
 area
135360
135360
So that for large documents it's not needed to query all of them on
135360
load, but (similar to tiled rendering itself) it's possible to query the
135360
data that affects the visible area.
135360
135360
One catch is that the row sizes are relative, so there is a placeholder
135360
row in case the visible area is not the top left corner, and
135360
constructing its size needs special care. Normally the handed out twip
135360
values have to be floored after twip->px conversion, but this one is
135360
already rounded (as the total is a sum of px values, again becase of the
135360
previous floor rule), so need to play the +0.5 trick to allow clients
135360
always just flooring the logic conversion result they get.
135360
135360
Change-Id: I64a155582acdee7b2acc741d77a2c462409b91a8
135360
(cherry picked from commit 75303695eb4bfe6c8fdea2cad0d3ed3f912f95c9)
135360
---
135360
 desktop/source/lib/init.cxx                        | 45 +++++++++++++++++++++-
135360
 include/vcl/ITiledRenderable.hxx                   |  5 ++-
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 12 +++++-
135360
 sc/inc/docuno.hxx                                  |  2 +-
135360
 sc/source/ui/inc/tabview.hxx                       |  2 +-
135360
 sc/source/ui/unoobj/docuno.cxx                     |  4 +-
135360
 sc/source/ui/view/tabview.cxx                      | 36 ++++++++++++++---
135360
 7 files changed, 92 insertions(+), 14 deletions(-)
135360
135360
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
135360
index 9ba26c414d8c..b9aeedd5e21c 100644
135360
--- a/desktop/source/lib/init.cxx
135360
+++ b/desktop/source/lib/init.cxx
135360
@@ -1204,6 +1204,9 @@ static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
135360
 
135360
 static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
135360
 {
135360
+    OString aCommand(pCommand);
135360
+    static const OString aViewRowColumnHeaders(".uno:ViewRowColumnHeaders");
135360
+
135360
     if (!strcmp(pCommand, ".uno:CharFontName"))
135360
     {
135360
         return getFonts(pCommand);
135360
@@ -1212,7 +1215,7 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
135360
     {
135360
         return getStyles(pThis, pCommand);
135360
     }
135360
-    else if (OString(pCommand) == ".uno:ViewRowColumnHeaders")
135360
+    else if (aCommand.startsWith(aViewRowColumnHeaders))
135360
     {
135360
         ITiledRenderable* pDoc = getTiledRenderable(pThis);
135360
         if (!pDoc)
135360
@@ -1221,7 +1224,45 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
135360
             return 0;
135360
         }
135360
 
135360
-        OUString aHeaders = pDoc->getRowColumnHeaders();
135360
+        Rectangle aRectangle;
135360
+        if (aCommand.getLength() > aViewRowColumnHeaders.getLength())
135360
+        {
135360
+            // Command has parameters.
135360
+            int nX = 0;
135360
+            int nY = 0;
135360
+            int nWidth = 0;
135360
+            int nHeight = 0;
135360
+            OString aArguments = aCommand.copy(aViewRowColumnHeaders.getLength() + 1);
135360
+            sal_Int32 nParamIndex = 0;
135360
+            do
135360
+            {
135360
+                OString aParamToken = aArguments.getToken(0, '&', nParamIndex);
135360
+                sal_Int32 nIndex = 0;
135360
+                OString aKey;
135360
+                OString aValue;
135360
+                do
135360
+                {
135360
+                    OString aToken = aParamToken.getToken(0, '=', nIndex);
135360
+                    if (!aKey.getLength())
135360
+                        aKey = aToken;
135360
+                    else
135360
+                        aValue = aToken;
135360
+                }
135360
+                while (nIndex >= 0);
135360
+                if (aKey == "x")
135360
+                    nX = aValue.toInt32();
135360
+                else if (aKey == "y")
135360
+                    nY = aValue.toInt32();
135360
+                else if (aKey == "width")
135360
+                    nWidth = aValue.toInt32();
135360
+                else if (aKey == "height")
135360
+                    nHeight = aValue.toInt32();
135360
+            }
135360
+            while (nParamIndex >= 0);
135360
+            aRectangle = Rectangle(nX, nY, nX + nWidth, nY + nHeight);
135360
+        }
135360
+
135360
+        OUString aHeaders = pDoc->getRowColumnHeaders(aRectangle);
135360
         OString aString = OUStringToOString(aHeaders, RTL_TEXTENCODING_UTF8);
135360
         char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
135360
         strcpy(pMemory, aString.getStr());
135360
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
135360
index 48a13ffc1275..efa9bc272b40 100644
135360
--- a/include/vcl/ITiledRenderable.hxx
135360
+++ b/include/vcl/ITiledRenderable.hxx
135360
@@ -150,8 +150,11 @@ public:
135360
 
135360
     /**
135360
      * Get position and content of row/column headers of Calc documents.
135360
+     *
135360
+     * @param rRectangle - if not empty, then limit the output only to the area of this rectangle
135360
+     * @return a JSON describing position/content of rows/columns
135360
      */
135360
-    virtual OUString getRowColumnHeaders()
135360
+    virtual OUString getRowColumnHeaders(const Rectangle& /*rRectangle*/)
135360
     {
135360
         return OUString();
135360
     }
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index 96a69fcf64f8..953eeb0f1db2 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -256,8 +256,16 @@ gboolean TiledRowColumnBar::docConfigureEvent(GtkWidget* pDocView, GdkEventConfi
135360
     LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pDocView));
135360
     if (pDocument && pDocument->pClass->getDocumentType(pDocument) == LOK_DOCTYPE_SPREADSHEET)
135360
     {
135360
-        g_info("lok::Document::getCommandValues(.uno:ViewRowColumnHeaders)");
135360
-        char* pValues = pDocument->pClass->getCommandValues(pDocument, ".uno:ViewRowColumnHeaders");
135360
+        std::stringstream aCommand;
135360
+        aCommand << ".uno:ViewRowColumnHeaders";
135360
+        aCommand << "?x=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pColumnBar->m_nPositionPixel));
135360
+        aCommand << "&width=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pColumnBar->m_nSizePixel));
135360
+        aCommand << "&y=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pRowBar->m_nPositionPixel));
135360
+        aCommand << "&height=" << int(lok_doc_view_pixel_to_twip(LOK_DOC_VIEW(pDocView), rWindow.m_pRowBar->m_nSizePixel));
135360
+        std::stringstream ss;
135360
+        ss << "lok::Document::getCommandValues(" << aCommand.str() << ")";
135360
+        g_info(ss.str().c_str());
135360
+        char* pValues = pDocument->pClass->getCommandValues(pDocument, aCommand.str().c_str());
135360
         std::stringstream aStream(pValues);
135360
         free(pValues);
135360
         assert(!aStream.str().empty());
135360
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
135360
index b4711c54c883..828fc1af7ea0 100644
135360
--- a/sc/inc/docuno.hxx
135360
+++ b/sc/inc/docuno.hxx
135360
@@ -423,7 +423,7 @@ public:
135360
     virtual bool isMimeTypeSupported() override;
135360
 
135360
     /// @see vcl::ITiledRenderable::getRowColumnHeaders().
135360
-    virtual OUString getRowColumnHeaders() override;
135360
+    virtual OUString getRowColumnHeaders(const Rectangle& rRectangle) override;
135360
 };
135360
 
135360
 class ScDrawPagesObj : public cppu::WeakImplHelper2<
135360
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
135360
index 5b0852041108..548742c6c22b 100644
135360
--- a/sc/source/ui/inc/tabview.hxx
135360
+++ b/sc/source/ui/inc/tabview.hxx
135360
@@ -521,7 +521,7 @@ public:
135360
     void ResetAutoSpell();
135360
     void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const std::vector<editeng::MisspellRanges>* pRanges );
135360
     /// @see ScModelObj::getRowColumnHeaders().
135360
-    OUString getRowColumnHeaders();
135360
+    OUString getRowColumnHeaders(const Rectangle& rRectangle);
135360
 };
135360
 
135360
 #endif
135360
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
135360
index 267798d4e949..1316fd73d328 100644
135360
--- a/sc/source/ui/unoobj/docuno.cxx
135360
+++ b/sc/source/ui/unoobj/docuno.cxx
135360
@@ -873,7 +873,7 @@ bool ScModelObj::isMimeTypeSupported()
135360
     return EditEngine::HasValidData(aDataHelper.GetTransferable());
135360
 }
135360
 
135360
-OUString ScModelObj::getRowColumnHeaders()
135360
+OUString ScModelObj::getRowColumnHeaders(const Rectangle& rRectangle)
135360
 {
135360
     ScViewData* pViewData = ScDocShell::GetViewData();
135360
     if (!pViewData)
135360
@@ -883,7 +883,7 @@ OUString ScModelObj::getRowColumnHeaders()
135360
     if (!pTabView)
135360
         return OUString();
135360
 
135360
-    return pTabView->getRowColumnHeaders();
135360
+    return pTabView->getRowColumnHeaders(rRectangle);
135360
 }
135360
 
135360
 void ScModelObj::initializeForTiledRendering()
135360
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
135360
index 2d886bca6003..1cb869cbd432 100644
135360
--- a/sc/source/ui/view/tabview.cxx
135360
+++ b/sc/source/ui/view/tabview.cxx
135360
@@ -2303,7 +2303,7 @@ void ScTabView::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const std::vector
135360
     }
135360
 }
135360
 
135360
-OUString ScTabView::getRowColumnHeaders()
135360
+OUString ScTabView::getRowColumnHeaders(const Rectangle& rRectangle)
135360
 {
135360
     ScDocument* pDoc = aViewData.GetDocument();
135360
     if (!pDoc)
135360
@@ -2314,14 +2314,40 @@ OUString ScTabView::getRowColumnHeaders()
135360
     pDoc->GetTiledRenderingArea(aViewData.GetTabNo(), nEndCol, nEndRow);
135360
 
135360
     boost::property_tree::ptree aRows;
135360
+    long nTotal = 0;
135360
+    long nTotalPixels = 0;
135360
     for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
135360
     {
135360
-        boost::property_tree::ptree aRow;
135360
         sal_uInt16 nSize = pDoc->GetOriginalHeight(nRow, aViewData.GetTabNo());
135360
-        aRow.put("size", OString::number(nSize).getStr());
135360
         OUString aText = pRowBar[SC_SPLIT_BOTTOM]->GetEntryText(nRow);
135360
-        aRow.put("text", aText.toUtf8().getStr());
135360
-        aRows.push_back(std::make_pair("", aRow));
135360
+
135360
+        bool bSkip = false;
135360
+        if (!rRectangle.IsEmpty())
135360
+        {
135360
+            long nTop = std::max(rRectangle.Top(), nTotal);
135360
+            long nBottom = std::min(rRectangle.Bottom(), nTotal + nSize);
135360
+            if (nBottom < nTop)
135360
+                // They do not intersect.
135360
+                bSkip = true;
135360
+        }
135360
+        if (!bSkip)
135360
+        {
135360
+            if (aRows.empty())
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("text", aText.toUtf8().getStr());
135360
+            aRows.push_back(std::make_pair("", aRow));
135360
+        }
135360
+        nTotal += nSize;
135360
+        nTotalPixels += long(nSize * aViewData.GetPPTY());
135360
     }
135360
 
135360
     boost::property_tree::ptree aCols;
135360
-- 
135360
2.12.0
135360