diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-12-03 17:35:34 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-12-16 12:35:37 +0100 |
commit | bac7e3cf4f4129616439220271009f0baaee5078 (patch) | |
tree | a53499c724b2ca3c9180d492018276d724672cab /sc/source/ui/view/gridwin.cxx | |
parent | 23767ab2922f243b4e11db27a2f368dfedea6a24 (diff) |
lok: calc - send other views our selection in their co-ordinates.
Change-Id: If48b5adb9b8b03310d2d2c4e4fefab84ad8bb149
Reviewed-on: https://gerrit.libreoffice.org/84370
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/85085
Tested-by: Jenkins
Diffstat (limited to 'sc/source/ui/view/gridwin.cxx')
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 1d0a86481f3b..b358d9605caf 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -5868,22 +5868,16 @@ void ScGridWindow::UpdateCopySourceOverlay() SetMapMode( aOldMode ); } -/** - * 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(const ScViewData* pViewData, const std::vector<tools::Rectangle>& rRectangles, std::vector<tools::Rectangle>* pLogicRects = nullptr) +static std::vector<tools::Rectangle> convertPixelToLogical( + const ScViewData* pViewData, + const std::vector<tools::Rectangle>& rRectangles, + tools::Rectangle &rBoundingBox) { - if (!comphelper::LibreOfficeKit::isActive()) - return; + std::vector<tools::Rectangle> aLogicRects; double nPPTX = pViewData->GetPPTX(); double nPPTY = pViewData->GetPPTY(); - tools::Rectangle aBoundingBox; - std::vector<OString> aRectangles; - for (const auto& rRectangle : rRectangles) { // We explicitly create a copy, since we need to expand @@ -5892,31 +5886,74 @@ static void updateLibreOfficeKitSelection(const ScViewData* pViewData, const std aRectangle.AdjustRight(1 ); aRectangle.AdjustBottom(1 ); - aBoundingBox.Union(aRectangle); - tools::Rectangle aRect(aRectangle.Left() / nPPTX, aRectangle.Top() / nPPTY, aRectangle.Right() / nPPTX, aRectangle.Bottom() / nPPTY); - if (pLogicRects) - pLogicRects->push_back(aRect); - else - aRectangles.push_back(aRect.toString()); + + rBoundingBox.Union(aRect); + aLogicRects.push_back(aRect); } + return aLogicRects; +} - if (pLogicRects) +static OString rectanglesToString(const std::vector<tools::Rectangle> &rLogicRects) +{ + bool bFirst = true; + OStringBuffer aRects; + for (const auto &rRect : rLogicRects) + { + if (!bFirst) + aRects.append("; "); + bFirst = false; + aRects.append(rRect.toString()); + } + return aRects.makeStringAndClear(); +} + +/** + * Turn the selection ranges rRectangles into the LibreOfficeKit selection, and call the callback. + * + * @param pLogicRects - if set then don't invoke the callback, just collect the rectangles in the pointed vector. + */ +void ScGridWindow::UpdateKitSelection(const std::vector<tools::Rectangle>& rRectangles, std::vector<tools::Rectangle>* pLogicRects) +{ + if (!comphelper::LibreOfficeKit::isActive()) return; - // selection start handle - tools::Rectangle aRectangle( - aBoundingBox.Left() / nPPTX, aBoundingBox.Top() / nPPTY, - aBoundingBox.Right() / nPPTX, aBoundingBox.Bottom() / nPPTY); + tools::Rectangle aBoundingBox; + std::vector<tools::Rectangle> aLogicRects; - // the selection itself - OString aSelection = comphelper::string::join("; ", aRectangles).getStr(); + aLogicRects = convertPixelToLogical(pViewData, rRectangles, aBoundingBox); + if (pLogicRects) + { + *pLogicRects = aLogicRects; + return; + } ScTabViewShell* pViewShell = pViewData->GetViewShell(); - pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_SELECTION_AREA, aRectangle.toString().getStr()); - pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, aSelection.getStr()); - SfxLokHelper::notifyOtherViews(pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", aSelection.getStr()); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_SELECTION_AREA, aBoundingBox.toString().getStr()); + pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, rectanglesToString(aLogicRects).getStr()); + + for (SfxViewShell* it = SfxViewShell::GetFirst(); it; + it = SfxViewShell::GetNext(*it)) + { + if (it == pViewShell) + continue; + auto pOther = dynamic_cast<const ScTabViewShell *>(it); + assert(pOther); + if (!pOther) + return; + + const ScGridWindow *pGrid = pOther->GetViewData().GetActiveWin(); + assert(pGrid); + + // Fetch pixels & convert for each view separately. + tools::Rectangle aDummyBBox; + std::vector<tools::Rectangle> aPixelRects; + pGrid->GetPixelRectsFor(pViewData->GetMarkData() /* ours */, aPixelRects); + auto aOtherLogicRects = convertPixelToLogical(&pOther->GetViewData(), aPixelRects, aDummyBBox); + SfxLokHelper::notifyOtherView(pViewShell, pOther, LOK_CALLBACK_TEXT_VIEW_SELECTION, + "selection", rectanglesToString(aOtherLogicRects).getStr()); + } } namespace @@ -6110,7 +6147,7 @@ void ScGridWindow::GetCellSelection(std::vector<tools::Rectangle>& rLogicRects) { std::vector<tools::Rectangle> aPixelRects; GetSelectionRects(aPixelRects); - updateLibreOfficeKitSelection(pViewData, aPixelRects, &rLogicRects); + UpdateKitSelection(aPixelRects, &rLogicRects); } void ScGridWindow::DeleteSelectionOverlay() @@ -6136,7 +6173,7 @@ void ScGridWindow::UpdateSelectionOverlay() if (comphelper::LibreOfficeKit::isActive()) { // notify the LibreOfficeKit too - updateLibreOfficeKitSelection(pViewData, aPixelRects); + UpdateKitSelection(aPixelRects); } else if (xOverlayManager.is()) { |