Kaydet (Commit) a42f582e authored tarafından Miklos Vajna's avatar Miklos Vajna

sc tiled rendering: implement LOK_CALLBACK_SEARCH_RESULT_SELECTION

Change-Id: Iaca2c1807a6e92cf7a87b0843000d65aea45fe7b
üst 06d253ef
...@@ -73,6 +73,7 @@ public: ...@@ -73,6 +73,7 @@ public:
uno::Reference<lang::XComponent> mxComponent; uno::Reference<lang::XComponent> mxComponent;
OString m_aTextSelection; OString m_aTextSelection;
std::vector<OString> m_aSearchResultSelection;
}; };
LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType) LibLODocument_Impl* DesktopLOKTest::loadDoc(const char* pName, LibreOfficeKitDocumentType eType)
...@@ -123,6 +124,16 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload) ...@@ -123,6 +124,16 @@ void DesktopLOKTest::callbackImpl(int nType, const char* pPayload)
m_aTextSelection = pPayload; m_aTextSelection = pPayload;
} }
break; 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() ...@@ -256,6 +267,8 @@ void DesktopLOKTest::testSearchCalc()
} while (nIndex >= 0); } while (nIndex >= 0);
// This was 1, find-all only found one match. // This was 1, find-all only found one match.
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aSelections.size()); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aSelections.size());
// Make sure that we get exactly as many rectangle lists as matches.
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), m_aSearchResultSelection.size());
closeDoc(); closeDoc();
comphelper::LibreOfficeKit::setActive(false); comphelper::LibreOfficeKit::setActive(false);
......
...@@ -336,6 +336,8 @@ public: ...@@ -336,6 +336,8 @@ public:
/// @see vcl::ITiledRenderable::setTextSelection() for the values of nType. /// @see vcl::ITiledRenderable::setTextSelection() for the values of nType.
/// Coordinates are in pixels. /// Coordinates are in pixels.
void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY); void SetCellSelectionPixel(int nType, int nPixelX, int nPixelY);
/// Get the cell selection, coordinates are in logic units.
void GetCellSelection(std::vector<Rectangle>& rLogicRects);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE; virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
......
...@@ -5886,8 +5886,12 @@ void ScGridWindow::UpdateCopySourceOverlay() ...@@ -5886,8 +5886,12 @@ void ScGridWindow::UpdateCopySourceOverlay()
SetMapMode( aOldMode ); 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<Rectangle>& 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<Rectangle>& rRectangles, std::vector<Rectangle>* pLogicRects = 0)
{ {
if (!pDrawLayer->isTiledRendering()) if (!pDrawLayer->isTiledRendering())
return; return;
...@@ -5907,9 +5911,15 @@ static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pD ...@@ -5907,9 +5911,15 @@ static void updateLibreOfficeKitSelection(ScViewData* pViewData, ScDrawLayer* pD
Rectangle aRect(aRectangle.Left() / nPPTX, aRectangle.Top() / nPPTY, Rectangle aRect(aRectangle.Left() / nPPTX, aRectangle.Top() / nPPTY,
aRectangle.Right() / nPPTX, aRectangle.Bottom() / nPPTY); aRectangle.Right() / nPPTX, aRectangle.Bottom() / nPPTY);
if (pLogicRects)
pLogicRects->push_back(aRect);
else
aRectangles.push_back(aRect.toString()); aRectangles.push_back(aRect.toString());
} }
if (pLogicRects)
return;
// selection start handle // selection start handle
Rectangle aStart(aBoundingBox.Left() / nPPTX, aBoundingBox.Top() / nPPTY, Rectangle aStart(aBoundingBox.Left() / nPPTX, aBoundingBox.Top() / nPPTY,
aBoundingBox.Left() / nPPTX, (aBoundingBox.Top() / nPPTY) + 256); aBoundingBox.Left() / nPPTX, (aBoundingBox.Top() / nPPTY) + 256);
...@@ -6093,6 +6103,13 @@ void ScGridWindow::UpdateCursorOverlay() ...@@ -6093,6 +6103,13 @@ void ScGridWindow::UpdateCursorOverlay()
SetMapMode( aOldMode ); SetMapMode( aOldMode );
} }
void ScGridWindow::GetCellSelection(std::vector<Rectangle>& rLogicRects)
{
std::vector<Rectangle> aPixelRects;
GetSelectionRects(aPixelRects);
updateLibreOfficeKitSelection(pViewData, pViewData->GetDocument()->GetDrawLayer(), aPixelRects, &rLogicRects);
}
void ScGridWindow::DeleteSelectionOverlay() void ScGridWindow::DeleteSelectionOverlay()
{ {
mpOOSelection.reset(); mpOOSelection.reset();
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <boost/property_tree/json_parser.hpp>
using namespace com::sun::star; using namespace com::sun::star;
using ::editeng::SvxBorderLine; using ::editeng::SvxBorderLine;
...@@ -1837,20 +1838,43 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem, ...@@ -1837,20 +1838,43 @@ bool ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem,
AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP ); AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
SetCursor( nCol, nRow, true ); 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())
if (rDoc.GetDrawLayer()->isTiledRendering() && nCommand == SvxSearchCmd::FIND)
{ {
Point aCurPos = GetViewData().GetScrPos(nCol, nRow, GetViewData().GetActivePart()); Point aCurPos = GetViewData().GetScrPos(nCol, nRow, GetViewData().GetActivePart());
// just update the cell selection // just update the cell selection
ScGridWindow* pGridWindow = GetViewData().GetActiveWin(); 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 // move the cell selection handles
pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_RESET, aCurPos.X(), aCurPos.Y()); pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_RESET, aCurPos.X(), aCurPos.Y());
pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_START, aCurPos.X(), aCurPos.Y()); pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_START, aCurPos.X(), aCurPos.Y());
pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_END, aCurPos.X(), aCurPos.Y()); pGridWindow->SetCellSelectionPixel(LOK_SETTEXTSELECTION_END, aCurPos.X(), aCurPos.Y());
} }
if (pGridWindow)
{
std::vector<Rectangle> 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 if ( nCommand == SvxSearchCmd::REPLACE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment