From 7609c0b6832553fa66685466331866061368c9a4 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Wed, 25 Mar 2015 13:15:17 +0100 Subject: sc tiled editing: Implement cell selections. Change-Id: Ic09572ac133c1bb473d716ec600ddb444948aa8e --- sc/source/ui/view/gridwin.cxx | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index acb6bd2c4459..7e58e51f4a90 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -134,6 +134,9 @@ #include #include +#define LOK_USE_UNSTABLE_API +#include + #include #include @@ -5742,6 +5745,44 @@ void ScGridWindow::UpdateCopySourceOverlay() SetMapMode( aOldMode ); } +/// Turn the selection ranges rRanges into the LibreOfficeKit selection, and call the callback. +static void updateLibreOfficeKitSelection(ScDrawLayer* pDrawLayer, const std::vector& rRanges) +{ + if (!pDrawLayer->isTiledRendering()) + return; + + basegfx::B2DRange aBoundingBox; + std::stringstream ss; + + bool bIsFirst = true; + for (const auto& rRange : rRanges) + { + aBoundingBox.expand(rRange); + + if (bIsFirst) + bIsFirst = false; + else + ss << "; "; + + Rectangle aRect(rRange.getMinX() / HMM_PER_TWIPS, rRange.getMinY() / HMM_PER_TWIPS, + rRange.getMaxX() / HMM_PER_TWIPS, rRange.getMaxY() / HMM_PER_TWIPS); + ss << aRect.toString().getStr(); + } + + // selection start handle + Rectangle aStart(aBoundingBox.getMinX() / HMM_PER_TWIPS, aBoundingBox.getMinY() / HMM_PER_TWIPS, + aBoundingBox.getMinX() / HMM_PER_TWIPS, (aBoundingBox.getMinY() / HMM_PER_TWIPS) + 256); + pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_START, aStart.toString().getStr()); + + // selection end handle + Rectangle aEnd(aBoundingBox.getMaxX() / HMM_PER_TWIPS, (aBoundingBox.getMaxY() / HMM_PER_TWIPS) - 256, + aBoundingBox.getMaxX() / HMM_PER_TWIPS, aBoundingBox.getMaxY() / HMM_PER_TWIPS); + pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr()); + + // the selection itself + pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, ss.str().c_str()); +} + void ScGridWindow::UpdateCursorOverlay() { MapMode aDrawMode = GetDrawMapMode(); @@ -5891,6 +5932,15 @@ void ScGridWindow::UpdateCursorOverlay() xOverlayManager->add(*pOverlay); mpOOCursors.reset(new sdr::overlay::OverlayObjectList); mpOOCursors->append(*pOverlay); + + // notify the LibreOfficeKit too, but only if there's no + // selection yet, to avoid setting the LOK selection twice + // (once for the cell only, and then for the selection) + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + if (pDrawLayer->isTiledRendering() && !pViewData->GetMarkData().IsMarked() && !pViewData->GetMarkData().IsMultiMarked()) + { + updateLibreOfficeKitSelection(pDrawLayer, aRanges); + } } } @@ -5957,6 +6007,9 @@ void ScGridWindow::UpdateSelectionOverlay() xOverlayManager->add(*pOverlay); mpOOSelection.reset(new sdr::overlay::OverlayObjectList); mpOOSelection->append(*pOverlay); + + // notify the LibreOfficeKit too + updateLibreOfficeKitSelection(pDoc->GetDrawLayer(), aRanges); } } -- cgit