[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 4 commits - sc/source

Jan Holesovsky kendy at collabora.com
Wed Mar 25 14:01:37 PDT 2015


 sc/source/ui/inc/gridwin.hxx   |    5 +++
 sc/source/ui/unoobj/docuno.cxx |   54 ++++++++++++++++++++++++--------------
 sc/source/ui/view/gridwin.cxx  |   35 ++++++++++++++----------
 sc/source/ui/view/gridwin4.cxx |   58 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 117 insertions(+), 35 deletions(-)

New commits:
commit b63955e990bee1049d6f000eaf17689d259d3c35
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Mar 25 21:59:03 2015 +0100

    sc tiled editing: Make the selections work with zoom too.
    
    Change-Id: I22d95fb2328acb81b8ece45e140da4094fc10026

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 90fca3d..392218d 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5745,38 +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<basegfx::B2DRange>& rRanges)
+/// 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)
 {
     if (!pDrawLayer->isTiledRendering())
         return;
 
-    basegfx::B2DRange aBoundingBox;
+    double nPPTX = pViewData->GetPPTX();
+    double nPPTY = pViewData->GetPPTY();
+
+    Rectangle aBoundingBox;
     std::stringstream ss;
 
     bool bIsFirst = true;
-    for (const auto& rRange : rRanges)
+    for (auto aRectangle : rRectangles)
     {
-        aBoundingBox.expand(rRange);
+        aRectangle.Right() += 1;
+        aRectangle.Bottom() += 1;
+
+        aBoundingBox.Union(aRectangle);
 
         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);
+        Rectangle aRect(aRectangle.Left() / nPPTX, aRectangle.Top() / nPPTY,
+                aRectangle.Right() / nPPTX, aRectangle.Bottom() / nPPTY);
         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);
+    Rectangle aStart(aBoundingBox.Left() / nPPTX, aBoundingBox.Top() / nPPTY,
+            aBoundingBox.Left() / nPPTX, (aBoundingBox.Top() / nPPTY) + 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);
+    Rectangle aEnd(aBoundingBox.Right() / nPPTX, (aBoundingBox.Bottom() / nPPTY) - 256,
+            aBoundingBox.Right() / nPPTX, aBoundingBox.Bottom() / nPPTY);
     pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, aEnd.toString().getStr());
 
     // the selection itself
@@ -5938,7 +5944,7 @@ void ScGridWindow::UpdateCursorOverlay()
             // (once for the cell only, and then for the selection)
             if (!pViewData->GetMarkData().IsMarked() && !pViewData->GetMarkData().IsMultiMarked())
             {
-                updateLibreOfficeKitSelection(pDoc->GetDrawLayer(), aRanges);
+                updateLibreOfficeKitSelection(pViewData, pDoc->GetDrawLayer(), aPixelRects);
             }
         }
     }
@@ -6008,7 +6014,7 @@ void ScGridWindow::UpdateSelectionOverlay()
             mpOOSelection->append(*pOverlay);
 
             // notify the LibreOfficeKit too
-            updateLibreOfficeKitSelection(pDoc->GetDrawLayer(), aRanges);
+            updateLibreOfficeKitSelection(pViewData, pDoc->GetDrawLayer(), aPixelRects);
         }
     }
 
commit ed4b08d7bde98cad3464a31de752f57c8553f211
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Mar 25 21:21:28 2015 +0100

    sc tiled editing: Allow resizing the cell selection using the handles.
    
    Change-Id: I53e5a43ba4f0ba4783a524751985adb3f4610d84

diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 36a7e5c..3cf3e36 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -330,6 +330,11 @@ public:
     /// Same as MouseButtonUp(), but coordinates are in logic unit.
     void LogicMouseButtonUp(const MouseEvent& rMouseEvent);
 
+    /// Update the cell selection according to what handles have been dragged.
+    /// Uses the same parameteres as vcl::ITiledRenderable::setTextSelection()
+    /// (ie. they are in twips here).
+    void SetCellSelection(int nType, int nX, int nY);
+
     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
 
     void            FakeButtonUp();
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index e0ac5ee..88ecd77 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -589,7 +589,16 @@ void ScModelObj::setTextSelection(int nType, int nX, int nY)
     else
     {
         // moving the cell selection handles
-        // TODO
+
+        // There seems to be no clear way of getting the grid window for this
+        // particular document, hence we need to hope we get the right window.
+        ScViewData* pViewData = ScDocShell::GetViewData();
+        ScGridWindow* pGridWindow = pViewData->GetActiveWin();
+
+        if (!pGridWindow)
+            return;
+
+        pGridWindow->SetCellSelection(nType, nX, nY);
     }
 }
 
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index ac2cd85..e204b97 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -991,6 +991,64 @@ void ScGridWindow::LogicInvalidate(const Rectangle* pRectangle)
     pViewData->GetDocument()->GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
 }
 
+void ScGridWindow::SetCellSelection(int nType, int nX, int nY)
+{
+    ScTabView* pTabView = pViewData->GetView();
+
+    if (nType == LOK_SETTEXTSELECTION_RESET)
+    {
+        pTabView->DoneBlockMode();
+        return;
+    }
+
+    // obtain the current selection
+    ScRangeList aRangeList = pViewData->GetMarkData().GetMarkedRanges();
+
+    SCCOL nCol1, nCol2;
+    SCROW nRow1, nRow2;
+    SCTAB nTab1, nTab2;
+
+    if (aRangeList.empty())
+    {
+        nCol1 = nCol2 = pViewData->GetCurX();
+        nRow1 = nRow2 = pViewData->GetCurY();
+    }
+    else
+        aRangeList.Combine().GetVars(nCol1, nRow1, nTab1, nCol2, nRow2, nTab2);
+
+    // convert the coordinates to column/row
+    SCsCOL nNewPosX;
+    SCsROW nNewPosY;
+    SCTAB nTab = pViewData->GetTabNo();
+    pViewData->GetPosFromPixel(nX * pViewData->GetPPTX(), nY * pViewData->GetPPTY(), eWhich, nNewPosX, nNewPosY);
+
+    // change the selection
+    switch (nType)
+    {
+        case LOK_SETTEXTSELECTION_START:
+            if (nNewPosX != nCol1 || nNewPosY != nRow1)
+            {
+                pTabView->SetCursor(nNewPosX, nNewPosY);
+                pTabView->DoneBlockMode();
+                pTabView->InitBlockMode(nNewPosX, nNewPosY, nTab, true);
+                pTabView->MarkCursor(nCol2, nRow2, nTab);
+            }
+            break;
+        case LOK_SETTEXTSELECTION_END:
+            if (nNewPosX != nCol2 || nNewPosY != nRow2)
+            {
+                pTabView->SetCursor(nCol1, nRow1);
+                pTabView->DoneBlockMode();
+                pTabView->InitBlockMode(nCol1, nRow1, nTab, true);
+                pTabView->MarkCursor(nNewPosX, nNewPosY, nTab);
+            }
+            break;
+        default:
+            assert(false);
+            break;
+    }
+}
+
 void ScGridWindow::CheckNeedsRepaint()
 {
     //  called at the end of painting, and from timer after background text width calculation
commit 2ba6e646b306b8a5225c1aa295d49c5b5ab40107
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Mar 25 15:45:32 2015 +0100

    sc tiled editing: Small refactor, preparing for moving cell selections.
    
    Change-Id: I61e98357a4d7248bd805907c8b37c94900259297

diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index c34f0f7..e0ac5ee 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -563,28 +563,33 @@ void ScModelObj::setTextSelection(int nType, int nX, int nY)
     ScViewData* pViewData = ScDocShell::GetViewData();
     ScInputHandler* pInputHandler = SC_MOD()->GetInputHdl(pViewData->GetViewShell());
 
-    if (!pInputHandler)
-        return;
-
-    EditView* pTableView = pInputHandler->GetTableView();
-    if (!pTableView)
-        return;
+    if (pInputHandler && pInputHandler->IsInputMode())
+    {
+        // forwarding to editeng - we are editing a cell content
+        EditView* pTableView = pInputHandler->GetTableView();
+        assert(pTableView);
 
-    Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
-    switch (nType)
+        Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
+        switch (nType)
+        {
+            case LOK_SETTEXTSELECTION_START:
+                pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
+                break;
+            case LOK_SETTEXTSELECTION_END:
+                pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
+                break;
+            case LOK_SETTEXTSELECTION_RESET:
+                pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
+                break;
+            default:
+                assert(false);
+                break;
+        }
+    }
+    else
     {
-    case LOK_SETTEXTSELECTION_START:
-        pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
-        break;
-    case LOK_SETTEXTSELECTION_END:
-        pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
-        break;
-    case LOK_SETTEXTSELECTION_RESET:
-        pTableView->SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
-        break;
-    default:
-        assert(false);
-        break;
+        // moving the cell selection handles
+        // TODO
     }
 }
 
commit c39f30285469678faa9c15a142b0de45d63f925a
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Mar 25 15:44:52 2015 +0100

    These checks are cheap, simplify.
    
    Change-Id: I20a5eba0c52499d9898a7ba2f5d68c5fe3bee610

diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index dd34e30..90fca3d 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5936,10 +5936,9 @@ void ScGridWindow::UpdateCursorOverlay()
             // 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())
+            if (!pViewData->GetMarkData().IsMarked() && !pViewData->GetMarkData().IsMultiMarked())
             {
-                updateLibreOfficeKitSelection(pDrawLayer, aRanges);
+                updateLibreOfficeKitSelection(pDoc->GetDrawLayer(), aRanges);
             }
         }
     }


More information about the Libreoffice-commits mailing list