a5fe07f
From 2f35fa5c95a3a6ae28ef15af88eabe8ba3e586bc Mon Sep 17 00:00:00 2001
a5fe07f
Message-Id: <2f35fa5c95a3a6ae28ef15af88eabe8ba3e586bc.1480426428.git.erack@redhat.com>
a5fe07f
From: Eike Rathke <erack@redhat.com>
a5fe07f
Date: Sat, 26 Nov 2016 11:23:24 +0100
a5fe07f
Subject: [PATCH] Resolves: tdf#103493 copying note captions needs a completed
a5fe07f
 destination sheet
a5fe07f
MIME-Version: 1.0
a5fe07f
Content-Type: multipart/mixed; boundary="------------erAck-patch-parts"
a5fe07f
a5fe07f
This is a multi-part message in MIME format.
a5fe07f
--------------erAck-patch-parts
a5fe07f
Content-Type: text/plain; charset=UTF-8; format=fixed
a5fe07f
Content-Transfer-Encoding: 8bit
a5fe07f
a5fe07f
a5fe07f
If a copied sheet's destination position is before its source position, the
a5fe07f
source's ScColumn::nTab members still pointed to the original source position
a5fe07f
when the captions were created, which led to the wrong drawing layer page being
a5fe07f
used and at the end the drawing shapes not being correctly assigned.
a5fe07f
a5fe07f
(cherry picked from commit 0a2a7436b4041bb34b01a183b9264af8488d1af3)
a5fe07f
a5fe07f
Backported.
a5fe07f
a5fe07f
 Conflicts:
a5fe07f
	sc/inc/table.hxx
a5fe07f
	sc/source/core/data/documen2.cxx
a5fe07f
	sc/source/core/data/table2.cxx
a5fe07f
a5fe07f
Change-Id: I9c3cc97d8b4486756023b9ab02da28079a1d0627
a5fe07f
---
a5fe07f
 sc/inc/table.hxx                 |  5 ++++-
a5fe07f
 sc/source/core/data/documen2.cxx | 11 +++++++++--
a5fe07f
 sc/source/core/data/table2.cxx   | 23 ++++++++++++++++-------
a5fe07f
 3 files changed, 29 insertions(+), 10 deletions(-)
a5fe07f
a5fe07f
a5fe07f
--------------erAck-patch-parts
a5fe07f
Content-Type: text/x-patch; name="0001-Resolves-tdf-103493-copying-note-captions-needs-a-co.patch"
a5fe07f
Content-Transfer-Encoding: 8bit
a5fe07f
Content-Disposition: attachment; filename="0001-Resolves-tdf-103493-copying-note-captions-needs-a-co.patch"
a5fe07f
a5fe07f
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
a5fe07f
index ead8ba4..bf7c63e 100644
a5fe07f
--- a/sc/inc/table.hxx
a5fe07f
+++ b/sc/inc/table.hxx
a5fe07f
@@ -444,7 +444,10 @@ public:
a5fe07f
     void CopyToTable(
a5fe07f
         sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
a5fe07f
         InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab,
a5fe07f
-        const ScMarkData* pMarkData = nullptr, bool bAsLink = false, bool bColRowFlags = true );
a5fe07f
+        const ScMarkData* pMarkData = nullptr, bool bAsLink = false, bool bColRowFlags = true,
a5fe07f
+        bool bCopyCaptions = true );
a5fe07f
+
a5fe07f
+    void CopyCaptionsToTable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab, bool bCloneCaption );
a5fe07f
 
a5fe07f
     void UndoToTable(
a5fe07f
         sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
a5fe07f
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
a5fe07f
index 57ee5f4..949cd55 100644
a5fe07f
--- a/sc/source/core/data/documen2.cxx
a5fe07f
+++ b/sc/source/core/data/documen2.cxx
a5fe07f
@@ -874,8 +874,9 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
a5fe07f
     {
a5fe07f
         SetNoListening( true );     // noch nicht bei CopyToTable/Insert
a5fe07f
         sc::CopyToDocContext aCopyDocCxt(*this);
a5fe07f
-        maTabs[nOldPos]->CopyToTable(aCopyDocCxt, 0, 0, MAXCOL, MAXROW, InsertDeleteFlags::ALL, (pOnlyMarked != nullptr),
a5fe07f
-                                        maTabs[nNewPos], pOnlyMarked );
a5fe07f
+        maTabs[nOldPos]->CopyToTable(aCopyDocCxt, 0, 0, MAXCOL, MAXROW, InsertDeleteFlags::ALL,
a5fe07f
+                (pOnlyMarked != nullptr), maTabs[nNewPos], pOnlyMarked,
a5fe07f
+                false /*bAsLink*/, true /*bColRowFlags*/, false /*bCopyCaptions*/ );
a5fe07f
         maTabs[nNewPos]->SetTabBgColor(maTabs[nOldPos]->GetTabBgColor());
a5fe07f
 
a5fe07f
         SCTAB nDz = nNewPos - nOldPos;
a5fe07f
@@ -913,6 +914,12 @@ bool ScDocument::CopyTab( SCTAB nOldPos, SCTAB nNewPos, const ScMarkData* pOnlyM
a5fe07f
         // Copy the RTL settings
a5fe07f
         maTabs[nNewPos]->SetLayoutRTL(maTabs[nOldPos]->IsLayoutRTL());
a5fe07f
         maTabs[nNewPos]->SetLoadingRTL(maTabs[nOldPos]->IsLoadingRTL());
a5fe07f
+
a5fe07f
+        // Finally copy the note captions, which need
a5fe07f
+        // 1. the updated source ScColumn::nTab members if nNewPos <= nOldPos
a5fe07f
+        // 2. row heights and column widths of the destination
a5fe07f
+        // 3. RTL settings of the destination
a5fe07f
+        maTabs[nOldPos]->CopyCaptionsToTable( 0, 0, MAXCOL, MAXROW, maTabs[nNewPos], true /*bCloneCaption*/);
a5fe07f
     }
a5fe07f
 
a5fe07f
     return bValid;
a5fe07f
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
a5fe07f
index 5d43a37..629743c 100644
a5fe07f
--- a/sc/source/core/data/table2.cxx
a5fe07f
+++ b/sc/source/core/data/table2.cxx
a5fe07f
@@ -1090,7 +1090,7 @@ void ScTable::StartListeningFormulaCells(
a5fe07f
 void ScTable::CopyToTable(
a5fe07f
     sc::CopyToDocContext& rCxt, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
a5fe07f
     InsertDeleteFlags nFlags, bool bMarked, ScTable* pDestTab, const ScMarkData* pMarkData,
a5fe07f
-    bool bAsLink, bool bColRowFlags )
a5fe07f
+    bool bAsLink, bool bColRowFlags, bool bCopyCaptions )
a5fe07f
 {
a5fe07f
     if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
a5fe07f
         return;
a5fe07f
@@ -1210,14 +1210,23 @@ void ScTable::CopyToTable(
a5fe07f
     if(nFlags & InsertDeleteFlags::OUTLINE) // also only when bColRowFlags
a5fe07f
         pDestTab->SetOutlineTable( pOutlineTable );
a5fe07f
 
a5fe07f
-    if (nFlags & (InsertDeleteFlags::NOTE|InsertDeleteFlags::ADDNOTES))
a5fe07f
+    if (bCopyCaptions && (nFlags & (InsertDeleteFlags::NOTE | InsertDeleteFlags::ADDNOTES)))
a5fe07f
     {
a5fe07f
         bool bCloneCaption = (nFlags & InsertDeleteFlags::NOCAPTIONS) == InsertDeleteFlags::NONE;
a5fe07f
-        for (SCCOL i = nCol1; i <= nCol2; i++)
a5fe07f
-        {
a5fe07f
-            aCol[i].CopyCellNotesToDocument(nRow1, nRow2, pDestTab->aCol[i], bCloneCaption);
a5fe07f
-            pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2);
a5fe07f
-        }
a5fe07f
+        CopyCaptionsToTable( nCol1, nRow1, nCol2, nRow2, pDestTab, bCloneCaption);
a5fe07f
+    }
a5fe07f
+}
a5fe07f
+
a5fe07f
+void ScTable::CopyCaptionsToTable( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScTable* pDestTab,
a5fe07f
+        bool bCloneCaption )
a5fe07f
+{
a5fe07f
+    if (!ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2))
a5fe07f
+        return;
a5fe07f
+
a5fe07f
+    for (SCCOL i = nCol1; i <= nCol2; i++)
a5fe07f
+    {
a5fe07f
+        aCol[i].CopyCellNotesToDocument(nRow1, nRow2, pDestTab->aCol[i], bCloneCaption);
a5fe07f
+        pDestTab->aCol[i].UpdateNoteCaptions(nRow1, nRow2);
a5fe07f
     }
a5fe07f
 }
a5fe07f
 
a5fe07f
a5fe07f
--------------erAck-patch-parts--
a5fe07f
a5fe07f