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