Blame SOURCES/0196-sc-tiled-rendering-implement-LOK_CALLBACK_SEARCH_RES.patch

135360
From 88384ac6a550a05ab944fd4b56f0222ab57c4498 Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Thu, 8 Oct 2015 11:49:13 +0200
135360
Subject: [PATCH 196/398] sc tiled rendering: implement
135360
 LOK_CALLBACK_SEARCH_RESULT_SELECTION
135360
135360
Change-Id: Iaca2c1807a6e92cf7a87b0843000d65aea45fe7b
135360
(cherry picked from commit a42f582e0e8ee4118415632795184620c6b8058c)
135360
---
135360
 desktop/qa/desktop_lib/test_desktop_lib.cxx | 13 +++++++++++++
135360
 sc/source/ui/inc/gridwin.hxx                |  2 ++
135360
 sc/source/ui/view/gridwin.cxx               | 23 +++++++++++++++++++---
135360
 sc/source/ui/view/viewfun2.cxx              | 30 ++++++++++++++++++++++++++---
135360
 4 files changed, 62 insertions(+), 6 deletions(-)
135360
135360
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
index 3e00e597c314..e77bc8984bbf 100644
135360
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
135360
@@ -73,6 +73,7 @@ public:
135360
 
135360
     uno::Reference<lang::XComponent> mxComponent;
135360
     OString m_aTextSelection;
135360
+    std::vector<OString> m_aSearchResultSelection;
135360
 };
135360
 
135360
 LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType)
135360
@@ -123,6 +124,16 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload)
135360
         m_aTextSelection = pPayload;
135360
     }
135360
     break;
135360
+    case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
135360
+    {
135360
+        m_aSearchResultSelection.clear();
135360
+        boost::property_tree::ptree aTree;
135360
+        std::stringstream aStream(pPayload);
135360
+        boost::property_tree::read_json(aStream, aTree);
135360
+        for (boost::property_tree::ptree::value_type& rValue : aTree.get_child("searchResultSelection"))
135360
+            m_aSearchResultSelection.push_back(rValue.second.data().c_str());
135360
+    }
135360
+    break;
135360
     }
135360
 }
135360
 
135360
@@ -256,6 +267,8 @@ void DesktopLOKTest::testSearchCalc()
135360
     } while (nIndex >= 0);
135360
     // This was 1, find-all only found one match.
135360
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aSelections.size());
135360
+    // Make sure that we get exactly as many rectangle lists as matches.
135360
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), m_aSearchResultSelection.size());
135360
 
135360
     closeDoc();
135360
     comphelper::LibreOfficeKit::setActive(false);
135360
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
135360
index e4bb56aac1f0..b8425a8e34c3 100644
135360
--- a/sc/source/ui/inc/gridwin.hxx
135360
+++ b/sc/source/ui/inc/gridwin.hxx
135360
@@ -337,6 +337,8 @@ public:
135360
     /// @see vcl::ITiledRenderable::setTextSelection() for the values of nType.
135360
     /// Coordinates are in pixels.
135360
     void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY);
135360
+    /// Get the cell selection, coordinates are in logic units.
135360
+    void GetCellSelection(std::vector<Rectangle>& rLogicRects);
135360
 
135360
     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
135360
 
135360
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
135360
index 1320e27cb104..f24b42f3b27e 100644
135360
--- a/sc/source/ui/view/gridwin.cxx
135360
+++ b/sc/source/ui/view/gridwin.cxx
135360
@@ -5890,8 +5890,12 @@ void ScGridWindow::UpdateCopySourceOverlay()
135360
         SetMapMode( aOldMode );
135360
 }
135360
 
135360
-/// Turn the selection ranges rRectangles into the LibreOfficeKit selection, and call the callback.
135360
-static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pDrawLayer, const std::vector<Rectangle>& rRectangles)
135360
+/**
135360
+ * Turn the selection ranges rRectangles into the LibreOfficeKit selection, and call the callback.
135360
+ *
135360
+ * @param pLogicRects - if not 0, then don't invoke the callback, just collect the rectangles in the pointed vector.
135360
+ */
135360
+static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pDrawLayer, const std::vector<Rectangle>& rRectangles, std::vector<Rectangle>* pLogicRects = 0)
135360
 {
135360
     if (!pDrawLayer->isTiledRendering())
135360
         return;
135360
@@ -5911,9 +5915,15 @@ static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pD
135360
 
135360
         Rectangle aRect(aRectangle.Left() / nPPTX, aRectangle.Top() / nPPTY,
135360
                 aRectangle.Right() / nPPTX, aRectangle.Bottom() / nPPTY);
135360
-        aRectangles.push_back(aRect.toString());
135360
+        if (pLogicRects)
135360
+            pLogicRects->push_back(aRect);
135360
+        else
135360
+            aRectangles.push_back(aRect.toString());
135360
     }
135360
 
135360
+    if (pLogicRects)
135360
+        return;
135360
+
135360
     // selection start handle
135360
     Rectangle aStart(aBoundingBox.Left() / nPPTX, aBoundingBox.Top() / nPPTY,
135360
             aBoundingBox.Left() / nPPTX, (aBoundingBox.Top() / nPPTY) + 256);
135360
@@ -6097,6 +6107,13 @@ void ScGridWindow::UpdateCursorOverlay()
135360
         SetMapMode( aOldMode );
135360
 }
135360
 
135360
+void ScGridWindow::GetCellSelection(std::vector<Rectangle>& rLogicRects)
135360
+{
135360
+    std::vector<Rectangle> aPixelRects;
135360
+    GetSelectionRects(aPixelRects);
135360
+    updateLibreOfficeKitSelection(pViewData, pViewData->GetDocument()->GetDrawLayer(), aPixelRects, &rLogicRects);
135360
+}
135360
+
135360
 void ScGridWindow::DeleteSelectionOverlay()
135360
 {
135360
     mpOOSelection.reset();
135360
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
135360
index 555492f17538..2be84a4c8e39 100644
135360
--- a/sc/source/ui/view/viewfun2.cxx
135360
+++ b/sc/source/ui/view/viewfun2.cxx
135360
@@ -91,6 +91,7 @@
135360
 #include <boost/scoped_ptr.hpp>
135360
 #include <vector>
135360
 #include <memory>
135360
+#include <boost/property_tree/json_parser.hpp>
135360
 
135360
 using namespace com::sun::star;
135360
 using ::editeng::SvxBorderLine;
135360
@@ -1838,20 +1839,43 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
135360
         AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
135360
         SetCursor( nCol, nRow, true );
135360
 
135360
-        // Don't move cell selection handles for find-all: selection of all but the first result would be lost.
135360
-        if (rDoc.GetDrawLayer()->isTiledRendering() && nCommand == SvxSearchCmd::FIND)
135360
+        if (rDoc.GetDrawLayer()->isTiledRendering())
135360
         {
135360
             Point aCurPos = GetViewData().GetScrPos(nCol, nRow, GetViewData().GetActivePart());
135360
 
135360
             // just update the cell selection
135360
             ScGridWindow* pGridWindow = GetViewData().GetActiveWin();
135360
-            if (pGridWindow)
135360
+            // Don't move cell selection handles for find-all: selection of all but the first result would be lost.
135360
+            if (pGridWindow && nCommand == SvxSearchCmd::FIND)
135360
             {
135360
                 // move the cell selection handles
135360
                 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_RESET, aCurPos.X(), aCurPos.Y());
135360
                 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_START, aCurPos.X(), aCurPos.Y());
135360
                 pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_END, aCurPos.X(), aCurPos.Y());
135360
             }
135360
+
135360
+            if (pGridWindow)
135360
+            {
135360
+                std::vector<Rectangle> aLogicRects;
135360
+                pGridWindow->GetCellSelection(aLogicRects);
135360
+
135360
+                boost::property_tree::ptree aTree;
135360
+                aTree.put("searchString", pSearchItem->GetSearchString().toUtf8().getStr());
135360
+
135360
+                boost::property_tree::ptree aSelections;
135360
+                for (const Rectangle& rLogicRect : aLogicRects)
135360
+                {
135360
+                    boost::property_tree::ptree aSelection;
135360
+                    aSelection.put("", rLogicRect.toString().getStr());
135360
+                    aSelections.push_back(std::make_pair("", aSelection));
135360
+                }
135360
+                aTree.add_child("searchResultSelection", aSelections);
135360
+
135360
+                std::stringstream aStream;
135360
+                boost::property_tree::write_json(aStream, aTree);
135360
+                OString aPayload = aStream.str().c_str();
135360
+                rDoc.GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
135360
+            }
135360
         }
135360
 
135360
         if (   nCommand == SvxSearchCmd::REPLACE
135360
-- 
135360
2.12.0
135360