[Libreoffice-commits] core.git: sc/source

Caolán McNamara caolanm at redhat.com
Mon Jun 20 23:31:13 UTC 2016


 sc/source/ui/app/transobj.cxx |   15 +++++++++++++++
 sc/source/ui/inc/transobj.hxx |    8 +++++++-
 sc/source/ui/view/gridwin.cxx |   14 ++++++++++++--
 sc/source/ui/view/select.cxx  |    1 +
 sc/source/ui/view/tabcont.cxx |    2 ++
 5 files changed, 37 insertions(+), 3 deletions(-)

New commits:
commit f9b46bbd2446a6c9a0aaab31016536bda4a77294
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Jun 20 12:13:02 2016 +0100

    tdf#96540 dragging between sheets can change the current cursor position
    
    so the at position at time of drop may not be that at the start of
    the drag.
    
    So set the current cursor position to ScTransferObj when the drag starts
    and retrieve it later
    
    Related to:
    
    commit ac3b66057ba677903b6de354317417b267be0fa0
    Author: Kohei Yoshida <kyoshida at novell.com>
    Date:   Thu Sep 16 11:09:29 2010 +0200
    
        calc-selection-fixed-cursor.diff: Migrated
    
        n#502717, i#21869, i#97093, when making selection, don't move the cursor position
    
    and
    
    commit c433fa0639ccf5caeb0c128c8a3794322e2a1c81
    Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Date:   Fri Jul 6 02:04:44 2012 +0200
    
        adjust the calculation of the cursor pos if ALT is used, fdo#48869
    
        Change-Id: I6316717c860d999270aa7f0fb50af5f6dfc7efd7
    
    I haven't used SetSourceCursorPos everywhere a ScTransferObj is created, just
    where its created through a drag event
    
    Change-Id: I50c36b4a2ba45426edebc1f1dfa5e262db3c5d03
    Reviewed-on: https://gerrit.libreoffice.org/26512
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index 016e0e4..802533f 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -119,6 +119,8 @@ ScTransferObj::ScTransferObj( ScDocument* pClipDoc, const TransferableObjectDesc
     aObjDesc( rDesc ),
     nDragHandleX( 0 ),
     nDragHandleY( 0 ),
+    nSourceCursorX( MAXCOL + 1 ),
+    nSourceCursorY( MAXROW + 1 ),
     nDragSourceFlags( 0 ),
     bDragWasInternal( false ),
     bUsedForLink( false ),
@@ -524,6 +526,19 @@ void ScTransferObj::SetDragHandlePos( SCCOL nX, SCROW nY )
     nDragHandleY = nY;
 }
 
+void ScTransferObj::SetSourceCursorPos( SCCOL nX, SCROW nY )
+{
+    nSourceCursorX = nX;
+    nSourceCursorY = nY;
+}
+
+bool ScTransferObj::WasSourceCursorInSelection() const
+{
+    return
+        nSourceCursorX >= aBlock.aStart.Col() && nSourceCursorX <= aBlock.aEnd.Col() &&
+        nSourceCursorY >= aBlock.aStart.Row() && nSourceCursorY <= aBlock.aEnd.Row();
+}
+
 void ScTransferObj::SetVisibleTab( SCTAB nNew )
 {
     nVisibleTab = nNew;
diff --git a/sc/source/ui/inc/transobj.hxx b/sc/source/ui/inc/transobj.hxx
index b33c88b..9e2e823 100644
--- a/sc/source/ui/inc/transobj.hxx
+++ b/sc/source/ui/inc/transobj.hxx
@@ -48,6 +48,8 @@ private:
     css::uno::Reference<css::sheet::XSheetCellRanges> xDragSourceRanges;
     SCCOL                           nDragHandleX;
     SCROW                           nDragHandleY;
+    SCCOL                           nSourceCursorX;
+    SCROW                           nSourceCursorY;
     SCTAB                           nVisibleTab;
     sal_uInt16                      nDragSourceFlags;
     bool                            bDragWasInternal;
@@ -82,8 +84,11 @@ public:
     SCROW               GetNonFilteredRows() const { return nNonFiltered; }
     SCCOL               GetDragHandleX() const  { return nDragHandleX; }
     SCROW               GetDragHandleY() const  { return nDragHandleY; }
+    bool                WasSourceCursorInSelection() const;
+    SCCOL               GetSourceCursorX() const  { return nSourceCursorX; }
+    SCROW               GetSourceCursorY() const  { return nSourceCursorY; }
     SCTAB               GetVisibleTab() const   { return nVisibleTab; }
-    sal_uInt16              GetDragSourceFlags() const  { return nDragSourceFlags; }
+    sal_uInt16          GetDragSourceFlags() const  { return nDragSourceFlags; }
     bool                HasFilteredRows() const { return bHasFiltered; }
     bool                GetUseInApi() const     { return bUseInApi; }
     ScDocShell*         GetSourceDocShell();
@@ -92,6 +97,7 @@ public:
 
     void                SetDrawPersist( const SfxObjectShellRef& rRef );
     void                SetDragHandlePos( SCCOL nX, SCROW nY );
+    void                SetSourceCursorPos( SCCOL nX, SCROW nY );
     void                SetVisibleTab( SCTAB nNew );
     void                SetDragSource( ScDocShell* pSourceShell, const ScMarkData& rMark );
     void                SetDragSourceFlags( sal_uInt16 nFlags );
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 5e46be7..6fb3966 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -4210,8 +4210,18 @@ sal_Int8 ScGridWindow::DropTransferObj( ScTransferObj* pTransObj, SCCOL nDestPos
                 {
                     pView->MarkRange( aDest, false );
 
-                    SCCOL nDCol = pViewData->GetCurX() - aSource.aStart.Col() + nCorrectCursorPosCol;
-                    SCROW nDRow = pViewData->GetCurY() - aSource.aStart.Row() + nCorrectCursorPosRow;
+                    SCCOL nDCol;
+                    SCROW nDRow;
+                    if (pTransObj->WasSourceCursorInSelection())
+                    {
+                        nDCol = pTransObj->GetSourceCursorX() - aSource.aStart.Col() + nCorrectCursorPosCol;
+                        nDRow = pTransObj->GetSourceCursorY() - aSource.aStart.Row() + nCorrectCursorPosRow;
+                    }
+                    else
+                    {
+                        nDCol = 0;
+                        nDRow = 0;
+                    }
                     pView->SetCursor( aDest.aStart.Col() + nDCol, aDest.aStart.Row() + nDRow );
                 }
 
diff --git a/sc/source/ui/view/select.cxx b/sc/source/ui/view/select.cxx
index bcceb4a..221bfb0 100644
--- a/sc/source/ui/view/select.cxx
+++ b/sc/source/ui/view/select.cxx
@@ -196,6 +196,7 @@ void ScViewFunctionSet::BeginDrag()
                 SCCOL nHandleX = (nPosX >= (SCsCOL) nStartX) ? nPosX - nStartX : 0;
                 SCROW nHandleY = (nPosY >= (SCsROW) nStartY) ? nPosY - nStartY : 0;
                 pTransferObj->SetDragHandlePos( nHandleX, nHandleY );
+                pTransferObj->SetSourceCursorPos( pViewData->GetCurX(), pViewData->GetCurY() );
                 pTransferObj->SetVisibleTab( nTab );
 
                 pTransferObj->SetDragSource( pDocSh, rMark );
diff --git a/sc/source/ui/view/tabcont.cxx b/sc/source/ui/view/tabcont.cxx
index 139a4ff..6fa034c 100644
--- a/sc/source/ui/view/tabcont.cxx
+++ b/sc/source/ui/view/tabcont.cxx
@@ -492,6 +492,8 @@ void ScTabControl::DoDrag( const vcl::Region& /* rRegion */ )
 
     pTransferObj->SetDragSource( pDocSh, aTabMark );
 
+    pTransferObj->SetSourceCursorPos( pViewData->GetCurX(), pViewData->GetCurY() );
+
     vcl::Window* pWindow = pViewData->GetActiveWin();
     SC_MOD()->SetDragObject( pTransferObj, nullptr );      // for internal D&D
     pTransferObj->StartDrag( pWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );


More information about the Libreoffice-commits mailing list