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 | |
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
-rw-r--r-- | sc/source/ui/inc/gridwin.hxx | 7 | ||||
-rw-r--r-- | sc/source/ui/inc/tabview.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/inc/viewdata.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 95 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin4.cxx | 11 |
5 files changed, 82 insertions, 35 deletions
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index 375e6e3cad2b..faea326a7cc1 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -286,8 +286,11 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, public DropTargetHel void SelectForContextMenu( const Point& rPosPixel, SCCOL nCellX, SCROW nCellY ); - void GetSelectionRects( ::std::vector< tools::Rectangle >& rPixelRects ); - + void GetSelectionRects( ::std::vector< tools::Rectangle >& rPixelRects ) const; + void GetPixelRectsFor( const ScMarkData &rMarkData, + ::std::vector< tools::Rectangle >& rPixelRects ) const; + void UpdateKitSelection(const std::vector<tools::Rectangle>& rRectangles, + std::vector<tools::Rectangle>* pLogicRects = nullptr); protected: virtual void PrePaint(vcl::RenderContext& rRenderContext) override; diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index 80888efebccb..e12e53f65473 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -377,7 +377,7 @@ public: void FakeButtonUp( ScSplitPos eWhich ); ScGridWindow* GetActiveWin(); - vcl::Window* GetWindowByPos( ScSplitPos ePos ) { return pGridWin[ePos]; } + vcl::Window* GetWindowByPos( ScSplitPos ePos ) const { return pGridWin[ePos]; } ScSplitPos FindWindow( const vcl::Window* pWindow ) const; diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx index 162ff01492ea..c691d2816814 100644 --- a/sc/source/ui/inc/viewdata.hxx +++ b/sc/source/ui/inc/viewdata.hxx @@ -601,7 +601,7 @@ public: /// return json for our cursor position. OString describeCellCursor() const { return describeCellCursorAt(GetCurX(), GetCurY()); } - OString describeCellCursorAt(SCCOL nCol, SCROW nRow) const; + OString describeCellCursorAt( SCCOL nCol, SCROW nRow ) const; SCCOL CellsAtX( SCCOL nPosX, SCCOL nDir, ScHSplitPos eWhichX, sal_uInt16 nScrSizeY = SC_SIZE_NONE ) const; SCROW CellsAtY( SCROW nPosY, SCROW nDir, ScVSplitPos eWhichY, sal_uInt16 nScrSizeX = SC_SIZE_NONE ) const; 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()) { diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx index 7ed91bdac886..7cf261cecf02 100644 --- a/sc/source/ui/view/gridwin4.cxx +++ b/sc/source/ui/view/gridwin4.cxx @@ -1802,9 +1802,16 @@ bool ScGridWindow::IsAutoFilterActive( SCCOL nCol, SCROW nRow, SCTAB nTab ) return ( bSimpleQuery && bColumnFound ); } -void ScGridWindow::GetSelectionRects( ::std::vector< tools::Rectangle >& rPixelRects ) +void ScGridWindow::GetSelectionRects( ::std::vector< tools::Rectangle >& rPixelRects ) const { - ScMarkData aMultiMark( pViewData->GetMarkData() ); + GetPixelRectsFor( pViewData->GetMarkData(), rPixelRects ); +} + +/// convert rMarkData into pixel rectangles for this view +void ScGridWindow::GetPixelRectsFor( const ScMarkData &rMarkData, + ::std::vector< tools::Rectangle >& rPixelRects ) const +{ + ScMarkData aMultiMark( rMarkData ); aMultiMark.SetMarking( false ); aMultiMark.MarkToMulti(); ScDocument* pDoc = pViewData->GetDocument(); |