[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sc/source

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Wed Dec 4 08:00:02 UTC 2019


 sc/source/ui/inc/gridwin.hxx   |    7 ++-
 sc/source/ui/inc/tabview.hxx   |    2 
 sc/source/ui/inc/viewdata.hxx  |    2 
 sc/source/ui/view/gridwin.cxx  |   95 ++++++++++++++++++++++++++++-------------
 sc/source/ui/view/gridwin4.cxx |   11 +++-
 5 files changed, 82 insertions(+), 35 deletions(-)

New commits:
commit ab07df7ee12aef8bb3770e69d22ecb272d379ece
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Dec 3 17:35:34 2019 +0000
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed Dec 4 08:59:15 2019 +0100

    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 at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 050ce492fe1e..0f24ca05ee41 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -284,8 +284,11 @@ class ScGridWindow : public vcl::Window, public DropTargetHelper, public DragSou
 
     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 d53480945284..88739484633b 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 1c8fa028f355..14ec8584b86f 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -598,7 +598,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 a4ce729b3e2f..f00681cc0427 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5813,22 +5813,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
@@ -5837,31 +5831,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
@@ -6055,7 +6092,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()
@@ -6081,7 +6118,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 ac970535d72c..91b5415b9510 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1787,9 +1787,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();


More information about the Libreoffice-commits mailing list