sc/source/ui/inc/viewdata.hxx  |    7 +
 sc/source/ui/inc/viewfunc.hxx  |    5 
 sc/source/ui/view/viewdata.cxx |   50 +++++++
 sc/source/ui/view/viewfunc.cxx |  274 ++++++++++++++++++++---------------------
 4 files changed, 199 insertions(+), 137 deletions(-)

New commits:
commit 380737e363ea7608f1472305977ec5a16622a779
Author: Marco Cecchetti <marco.cecche...@collabora.com>
Date:   Wed May 3 22:37:02 2017 +0200

    lok: sc: insert a row affects another view's selection on another tab
    
    Problem:
    - Open a spreadsheet with two views.
    - With view A select a cell on 2nd sheet (H10 for example).
    - With view B delete a row above H10.
    
    => View A's selection moves up. Similarly with insertion and with
       columns.
    
    The new solution takes care of the current tab each view is
    displaying.
    
    Change-Id: I47272ec7ef68471b530868dab57fa92091277324
    Reviewed-on: https://gerrit.libreoffice.org/37258
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/sc/source/ui/inc/viewdata.hxx b/sc/source/ui/inc/viewdata.hxx
index 2271321f400d..6fc2d748a670 100644
--- a/sc/source/ui/inc/viewdata.hxx
+++ b/sc/source/ui/inc/viewdata.hxx
@@ -333,6 +333,8 @@ public:
     SCROW           GetPosY( ScVSplitPos eWhich ) const     { return 
pThisTab->nPosY[eWhich]; }
     SCCOL           GetCurX() const                         { return 
pThisTab->nCurX; }
     SCROW           GetCurY() const                         { return 
pThisTab->nCurY; }
+    SCCOL           GetCurXForTab( SCTAB nTabIndex ) const;
+    SCROW           GetCurYForTab( SCTAB nTabIndex ) const;
     SCCOL           GetOldCurX() const;
     SCROW           GetOldCurY() const;
     SCCOL           GetLOKOldCurX() const                   { return 
pThisTab->nLOKOldCurX; }
@@ -343,6 +345,9 @@ public:
     ScPositionHelper& GetLOKWidthHelper()                   { return 
pThisTab->aWidthHelper; }
     ScPositionHelper& GetLOKHeightHelper()                  { return 
pThisTab->aHeightHelper; }
 
+    ScPositionHelper* GetLOKWidthHelper(SCTAB nTabIndex);
+    ScPositionHelper* GetLOKHeightHelper(SCTAB nTabIndex);
+
     ScSplitMode     GetHSplitMode() const                   { return 
pThisTab->eHSplitMode; }
     ScSplitMode     GetVSplitMode() const                   { return 
pThisTab->eVSplitMode; }
     long            GetHSplitPos() const                    { return 
pThisTab->nHSplitPos; }
@@ -360,6 +365,8 @@ public:
     void            SetPosY( ScVSplitPos eWhich, SCROW nNewPosY );
     void            SetCurX( SCCOL nNewCurX )                       { 
pThisTab->nCurX = nNewCurX; }
     void            SetCurY( SCROW nNewCurY )                       { 
pThisTab->nCurY = nNewCurY; }
+    void            SetCurXForTab( SCCOL nNewCurX, SCTAB nTabIndex );
+    void            SetCurYForTab( SCCOL nNewCurY, SCTAB nTabIndex );
     void            SetOldCursor( SCCOL nNewX, SCROW nNewY );
     void            ResetOldCursor();
     void            SetLOKOldCurX( SCCOL nCurX )                    { 
pThisTab->nLOKOldCurX = nCurX; }
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 30f402625405..489c606d9bc5 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -320,6 +320,11 @@ public:
                                      std::vector<VclPtr<Edit> >& aEdits,
                                      sal_uInt16 aColLength );
     void            UpdateSelectionArea( const ScMarkData& rSel, 
ScPatternAttr* pAttr = nullptr );
+
+    void            OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset);
+    void            OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset);
+    void            OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth);
+
                                                 // Internal helper functions
 protected:
     static void     UpdateLineAttrs( ::editeng::SvxBorderLine&        rLine,
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index 309528e3619d..d90886368522 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -1122,6 +1122,38 @@ void ScViewData::ResetOldCursor()
     pThisTab->mbOldCursorValid = false;
 }
 
+SCCOL ScViewData::GetCurXForTab( SCTAB nTabIndex ) const
+{
+    if (!ValidTab(nTabIndex) || !(nTabIndex < 
static_cast<SCTAB>(maTabData.size())))
+        return -1;
+
+    return maTabData[nTabIndex]->nCurX;
+}
+
+SCROW ScViewData::GetCurYForTab( SCTAB nTabIndex ) const
+{
+    if (!ValidTab(nTabIndex) || !(nTabIndex < 
static_cast<SCTAB>(maTabData.size())))
+            return -1;
+
+    return maTabData[nTabIndex]->nCurY;
+}
+
+void ScViewData::SetCurXForTab( SCCOL nNewCurX, SCTAB nTabIndex )
+{
+    if (!ValidTab(nTabIndex) || !(nTabIndex < 
static_cast<SCTAB>(maTabData.size())))
+            return;
+
+    maTabData[nTabIndex]->nCurX = nNewCurX;
+}
+
+void ScViewData::SetCurYForTab( SCCOL nNewCurY, SCTAB nTabIndex )
+{
+    if (!ValidTab(nTabIndex) || !(nTabIndex < 
static_cast<SCTAB>(maTabData.size())))
+            return;
+
+    maTabData[nTabIndex]->nCurY = nNewCurY;
+}
+
 void ScViewData::SetMaxTiledCol( SCCOL nNewMaxCol )
 {
     if (nNewMaxCol < 0)
@@ -1826,6 +1858,24 @@ void ScViewData::SetTabNo( SCTAB nNewTab )
     RecalcPixPos();     //! not always needed!
 }
 
+ScPositionHelper* ScViewData::GetLOKWidthHelper(SCTAB nTabIndex)
+{
+    if (!ValidTab(nTabIndex) || !(nTabIndex < 
static_cast<SCTAB>(maTabData.size())))
+    {
+        return nullptr;
+    }
+    return &(maTabData[nTabIndex]->aWidthHelper);
+}
+
+ScPositionHelper* ScViewData::GetLOKHeightHelper(SCTAB nTabIndex)
+{
+    if (!ValidTab(nTabIndex) || !(nTabIndex < 
static_cast<SCTAB>(maTabData.size())))
+    {
+        return nullptr;
+    }
+    return &(maTabData[nTabIndex]->aHeightHelper);
+}
+
 void ScViewData::SetActivePart( ScSplitPos eNewActive )
 {
     pThisTab->eWhichActive = eNewActive;
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 939c577a26d8..3d5db7ee48db 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -1451,6 +1451,128 @@ void ScViewFunc::UpdateStyleSheetInUse( const 
SfxStyleSheetBase* pStyleSheet )
         pHdl->ForgetLastPattern();
 }
 
+
+void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset)
+{
+    if (!comphelper::LibreOfficeKit::isActive() || nOffset == 0)
+        return;
+
+    SCTAB nCurrentTabIndex = GetViewData().GetTabNo();
+    SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
+        if (pTabViewShell)
+        {
+            
pTabViewShell->GetViewData().GetLOKWidthHelper(nCurrentTabIndex)->invalidateByIndex(nStartCol);
+
+            // if we remove a column the cursor position  and the current 
selection
+            // in other views could need to be moved on the left by one column.
+            if (pTabViewShell != this)
+            {
+                if (pTabViewShell->getPart() == nCurrentTabIndex)
+                {
+                    SCCOL nX = pTabViewShell->GetViewData().GetCurX();
+                    if (nX > nStartCol || (nX == nStartCol && nOffset > 0))
+                    {
+                        SCROW nY = pTabViewShell->GetViewData().GetCurY();
+                        pTabViewShell->SetCursor(nX + nOffset, nY);
+                    }
+
+                    ScMarkData aMultiMark( 
pTabViewShell->GetViewData().GetMarkData() );
+                    aMultiMark.SetMarking( false );
+                    aMultiMark.MarkToMulti();
+                    if (aMultiMark.IsMultiMarked())
+                    {
+                        aMultiMark.ShiftCols(nStartCol, nOffset);
+                        pTabViewShell->SetMarkData(aMultiMark);
+                    }
+                }
+                else
+                {
+                    SCROW nX = 
pTabViewShell->GetViewData().GetCurXForTab(nCurrentTabIndex);
+                    if (nX > nStartCol || (nX == nStartCol && nOffset > 0))
+                    {
+                        pTabViewShell->GetViewData().SetCurXForTab(nX + 
nOffset, nCurrentTabIndex);
+                    }
+                }
+            }
+        }
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
+void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset)
+{
+    if (!comphelper::LibreOfficeKit::isActive() || nOffset == 0)
+        return;
+
+    SCTAB nCurrentTabIndex = GetViewData().GetTabNo();
+    SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
+        if (pTabViewShell)
+        {
+            
pTabViewShell->GetViewData().GetLOKHeightHelper(nCurrentTabIndex)->invalidateByIndex(nStartRow);
+
+            // if we remove a row the cursor position and the current selection
+            // in other views could need to be moved up by one row.
+            if (pTabViewShell != this)
+            {
+                if (pTabViewShell->getPart() == nCurrentTabIndex)
+                {
+                    SCROW nY = pTabViewShell->GetViewData().GetCurY();
+                    if (nY > nStartRow || (nY == nStartRow && nOffset > 0))
+                    {
+                        SCCOL nX = pTabViewShell->GetViewData().GetCurX();
+                        pTabViewShell->SetCursor(nX, nY + nOffset);
+                    }
+
+                    ScMarkData aMultiMark( 
pTabViewShell->GetViewData().GetMarkData() );
+                    aMultiMark.SetMarking( false );
+                    aMultiMark.MarkToMulti();
+                    if (aMultiMark.IsMultiMarked())
+                    {
+                        aMultiMark.ShiftRows(nStartRow, nOffset);
+                        pTabViewShell->SetMarkData(aMultiMark);
+                    }
+                }
+                else
+                {
+                    SCROW nY = 
pTabViewShell->GetViewData().GetCurYForTab(nCurrentTabIndex);
+                    if (nY > nStartRow || (nY == nStartRow && nOffset > 0))
+                    {
+                        pTabViewShell->GetViewData().SetCurYForTab(nY + 
nOffset, nCurrentTabIndex);
+                    }
+                }
+            }
+        }
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
+void ScViewFunc::OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth)
+{
+    if (!comphelper::LibreOfficeKit::isActive())
+        return;
+
+    SCTAB nCurTab = GetViewData().GetTabNo();
+    SfxViewShell* pViewShell = SfxViewShell::GetFirst();
+    while (pViewShell)
+    {
+        ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
+        if (pTabViewShell)
+        {
+            if (bWidth)
+                
pTabViewShell->GetViewData().GetLOKWidthHelper(nCurTab)->invalidateByIndex(nStart);
+            else
+                
pTabViewShell->GetViewData().GetLOKHeightHelper(nCurTab)->invalidateByIndex(nStart);
+        }
+        pViewShell = SfxViewShell::GetNext(*pViewShell);
+    }
+}
+
 //  insert cells - undo OK
 
 bool ScViewFunc::InsertCells( InsCellCmd eCmd, bool bRecord, bool bPartOfPaste 
)
@@ -1458,7 +1580,6 @@ bool ScViewFunc::InsertCells( InsCellCmd eCmd, bool 
bRecord, bool bPartOfPaste )
     ScRange aRange;
     if (GetViewData().GetSimpleArea(aRange) == SC_MARK_SIMPLE)
     {
-
         ScDocShell* pDocSh = GetViewData().GetDocShell();
         const ScMarkData& rMark = GetViewData().GetMarkData();
         bool bSuccess = pDocSh->GetDocFunc().InsertCells( aRange, &rMark, 
eCmd, bRecord, false, bPartOfPaste );
@@ -1466,69 +1587,17 @@ bool ScViewFunc::InsertCells( InsCellCmd eCmd, bool 
bRecord, bool bPartOfPaste )
         {
             bool bInsertCols = ( eCmd == INS_INSCOLS_BEFORE || eCmd == 
INS_INSCOLS_AFTER);
             bool bInsertRows = ( eCmd == INS_INSROWS_BEFORE || eCmd == 
INS_INSROWS_AFTER );
-            if (comphelper::LibreOfficeKit::isActive())
-            {
-                SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-                while (pViewShell)
-                {
-                    ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
-                    if (pTabViewShell)
-                    {
-                        if (bInsertCols)
-                        {
-                            
pTabViewShell->GetViewData().GetLOKWidthHelper().invalidateByIndex(aRange.aStart.Col());
 
-                            // if we insert a column the cursor position and 
the current selection
-                            // in other views could need to be moved on the 
right by one column.
-                            if (pTabViewShell != this)
-                            {
-                                SCCOL nX = 
pTabViewShell->GetViewData().GetCurX();
-                                if (nX >= aRange.aStart.Col())
-                                {
-                                    SCROW nY = 
pTabViewShell->GetViewData().GetCurY();
-                                    pTabViewShell->SetCursor(nX+1, nY);
-                                }
-
-                                ScMarkData aMultiMark( 
pTabViewShell->GetViewData().GetMarkData() );
-                                aMultiMark.SetMarking( false );
-                                aMultiMark.MarkToMulti();
-                                if (aMultiMark.IsMultiMarked())
-                                {
-                                    aMultiMark.ShiftCols(aRange.aStart.Col(), 
1);
-                                    pTabViewShell->SetMarkData(aMultiMark);
-                                }
-                            }
-                        }
-
-                        if (bInsertRows)
-                        {
-                            
pTabViewShell->GetViewData().GetLOKHeightHelper().invalidateByIndex(aRange.aStart.Row());
+            if (bInsertCols)
+            {
+                OnLOKInsertDeleteColumn(aRange.aStart.Col(), 1);
+            }
 
-                            // if we insert a row the cursor position and the 
current selection
-                            // in other views could need to be moved down by 
one row.
-                            if (pTabViewShell != this)
-                            {
-                                SCROW nY = 
pTabViewShell->GetViewData().GetCurY();
-                                if (nY >= aRange.aStart.Row())
-                                {
-                                    SCCOL nX = 
pTabViewShell->GetViewData().GetCurX();
-                                    pTabViewShell->SetCursor(nX, nY+1);
-                                }
-
-                                ScMarkData aMultiMark( 
pTabViewShell->GetViewData().GetMarkData() );
-                                aMultiMark.SetMarking( false );
-                                aMultiMark.MarkToMulti();
-                                if (aMultiMark.IsMultiMarked())
-                                {
-                                    aMultiMark.ShiftRows(aRange.aStart.Row(), 
1);
-                                    pTabViewShell->SetMarkData(aMultiMark);
-                                }
-                            }
-                        }
-                    }
-                    pViewShell = SfxViewShell::GetNext(*pViewShell);
-                }
+            if (bInsertRows)
+            {
+                OnLOKInsertDeleteRow(aRange.aStart.Row(), 1);
             }
+
             pDocSh->UpdateOle(&GetViewData());
             CellContentChanged();
             ResetAutoSpell();
@@ -1595,68 +1664,14 @@ void ScViewFunc::DeleteCells( DelCellCmd eCmd )
             pDocSh->GetDocFunc().DeleteCells( aRange, &rMark, eCmd, false );
         }
 
-        if (comphelper::LibreOfficeKit::isActive())
+        if (eCmd == DEL_DELCOLS)
         {
-            SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-            while (pViewShell)
-            {
-                ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
-                if (pTabViewShell)
-                {
-                    if (eCmd == DEL_DELCOLS)
-                    {
-                        
pTabViewShell->GetViewData().GetLOKWidthHelper().invalidateByIndex(aRange.aStart.Col());
-
-                        // if we remove a column the cursor position  and the 
current selection
-                        // in other views could need to be moved on the left 
by one column.
-                        if (pTabViewShell != this)
-                        {
-                            SCCOL nX = pTabViewShell->GetViewData().GetCurX();
-                            if (nX >= aRange.aStart.Col())
-                            {
-                                SCROW nY = 
pTabViewShell->GetViewData().GetCurY();
-                                pTabViewShell->SetCursor(nX-1, nY);
-                            }
-
-                            ScMarkData aMultiMark( 
pTabViewShell->GetViewData().GetMarkData() );
-                            aMultiMark.SetMarking( false );
-                            aMultiMark.MarkToMulti();
-                            if (aMultiMark.IsMultiMarked())
-                            {
-                                aMultiMark.ShiftCols(aRange.aStart.Col(), -1);
-                                pTabViewShell->SetMarkData(aMultiMark);
-                            }
-                        }
-                    }
-
-                    if (eCmd == DEL_DELROWS)
-                    {
-                        
pTabViewShell->GetViewData().GetLOKHeightHelper().invalidateByIndex(aRange.aStart.Row());
-
-                        // if we remove a row the cursor position and the 
current selection
-                        // in other views could need to be moved up by one row.
-                        if (pTabViewShell != this)
-                        {
-                            SCROW nY = pTabViewShell->GetViewData().GetCurY();
-                            if (nY >= aRange.aStart.Row())
-                            {
-                                SCCOL nX = 
pTabViewShell->GetViewData().GetCurX();
-                                pTabViewShell->SetCursor(nX, nY-1);
-                            }
+            OnLOKInsertDeleteColumn(aRange.aStart.Col(), -1);
+        }
 
-                            ScMarkData aMultiMark( 
pTabViewShell->GetViewData().GetMarkData() );
-                            aMultiMark.SetMarking( false );
-                            aMultiMark.MarkToMulti();
-                            if (aMultiMark.IsMultiMarked())
-                            {
-                                aMultiMark.ShiftRows(aRange.aStart.Row(), -1);
-                                pTabViewShell->SetMarkData(aMultiMark);
-                            }
-                        }
-                    }
-                }
-                pViewShell = SfxViewShell::GetNext(*pViewShell);
-            }
+        if (eCmd == DEL_DELROWS)
+        {
+            OnLOKInsertDeleteRow(aRange.aStart.Row(), -1);
         }
 
         pDocSh->UpdateOle(&GetViewData());
@@ -2028,22 +2043,7 @@ void ScViewFunc::SetWidthOrHeight(
     SCCOLROW nStart = rRanges.front().mnStart;
     SCCOLROW nEnd = rRanges.back().mnEnd;
 
-    if (comphelper::LibreOfficeKit::isActive())
-    {
-        SfxViewShell* pViewShell = SfxViewShell::GetFirst();
-        while (pViewShell)
-        {
-            ScTabViewShell* pTabViewShell = 
dynamic_cast<ScTabViewShell*>(pViewShell);
-            if (pTabViewShell)
-            {
-                if (bWidth)
-                    
pTabViewShell->GetViewData().GetLOKWidthHelper().invalidateByIndex(nStart);
-                else
-                    
pTabViewShell->GetViewData().GetLOKHeightHelper().invalidateByIndex(nStart);
-            }
-            pViewShell = SfxViewShell::GetNext(*pViewShell);
-        }
-    }
+    OnLOKSetWidthOrHeight(nStart, bWidth);
 
     bool bFormula = false;
     if ( eMode == SC_SIZE_OPTIMAL )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to