kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

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

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