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

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