Blob Blame History Raw
From b7bd1b66287d9d337234ac1b9b50a1fafba7dd1e Mon Sep 17 00:00:00 2001
From: Kohei Yoshida <kohei.yoshida@collabora.com>
Date: Mon, 14 Jul 2014 15:24:19 -0400
Subject: [PATCH 042/137] Preserve the "end of list" flag for xls
 round-tripping.

This "end of list" flag determines whether the row insertion was an
automatic insertion at the bottom.  Calc doesn't use this at the moment
but Excel uses it to differentiate a normal row insertion from an
automatic one.

(cherry picked from commit adf0d7b1fb8eed88f4fcd6d31662ae6f59d00812)
Signed-off-by: Andras Timar <andras.timar@collabora.com>

Conflicts:
	sc/inc/chgtrack.hxx
	sc/source/filter/xcl97/XclExpChangeTrack.cxx

Change-Id: I6b28669d816c54d1dc1e4c106918ba688415788d
(cherry picked from commit 8fd0951429bfa00a054ebbc195a480f89af9f912)
Signed-off-by: Andras Timar <andras.timar@collabora.com>
---
 sc/inc/chgtrack.hxx                          | 26 ++++++++++------
 sc/source/core/tool/chgtrack.cxx             | 46 +++++++++++++++++-----------
 sc/source/filter/inc/XclExpChangeTrack.hxx   |  5 +--
 sc/source/filter/inc/XclImpChangeTrack.hxx   |  2 +-
 sc/source/filter/xcl97/XclExpChangeTrack.cxx | 17 ++++++++--
 sc/source/filter/xcl97/XclImpChangeTrack.cxx | 11 ++++---
 6 files changed, 68 insertions(+), 39 deletions(-)

diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx
index 1f6ddcd..2e57437 100644
--- a/sc/inc/chgtrack.hxx
+++ b/sc/inc/chgtrack.hxx
@@ -402,7 +402,9 @@ class ScChangeActionIns : public ScChangeAction
 {
     friend class ScChangeTrack;
 
-                                ScChangeActionIns( const ScRange& rRange );
+    bool mbEndOfList; /// whether or not a row was auto-inserted at the bottom.
+
+    ScChangeActionIns( const ScRange& rRange, bool bEndOfList = false );
     virtual                     ~ScChangeActionIns();
 
     virtual void                AddContent( ScChangeActionContent* ) {}
@@ -413,17 +415,21 @@ class ScChangeActionIns : public ScChangeAction
     virtual const ScChangeTrack*    GetChangeTrack() const { return 0; }
 
 public:
-    ScChangeActionIns(const sal_uLong nActionNumber,
-            const ScChangeActionState eState,
-            const sal_uLong nRejectingNumber,
-            const ScBigRange& aBigRange,
-            const OUString& aUser,
-            const DateTime& aDateTime,
-            const OUString &sComment,
-            const ScChangeActionType eType); // only to use in the XML import
+    ScChangeActionIns(
+        const sal_uLong nActionNumber,
+        const ScChangeActionState eState,
+        const sal_uLong nRejectingNumber,
+        const ScBigRange& aBigRange,
+        const OUString& aUser,
+        const DateTime& aDateTime,
+        const OUString &sComment,
+        const ScChangeActionType eType,
+        bool bEndOfList = false );
 
     virtual void GetDescription(
         OUString& rStr, ScDocument* pDoc, bool bSplitRange = false, bool bWarning = true) const;
+
+    SC_DLLPUBLIC bool IsEndOfList() const;
 };
 
 //  ScChangeActionDel
@@ -1123,7 +1129,7 @@ public:
     // Only use the following two if there is no different solution! (Assign
     // string for NewValue or creation of a formula respectively)
 
-    SC_DLLPUBLIC void AppendInsert( const ScRange& );
+    SC_DLLPUBLIC void AppendInsert( const ScRange& rRange, bool bEndOfList = false );
 
                                 // pRefDoc may be NULL => no lookup of contents
                                 // => no generation of deleted contents
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index 1ebb30d..ff261ca 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -660,8 +660,9 @@ void ScChangeAction::AddDependent( sal_uLong nActionNumber,
 }
 
 //  ScChangeActionIns
-ScChangeActionIns::ScChangeActionIns( const ScRange& rRange )
-        : ScChangeAction( SC_CAT_NONE, rRange )
+ScChangeActionIns::ScChangeActionIns( const ScRange& rRange, bool bEndOfList ) :
+    ScChangeAction(SC_CAT_NONE, rRange),
+    mbEndOfList(bEndOfList)
 {
     if ( rRange.aStart.Col() == 0 && rRange.aEnd.Col() == MAXCOL )
     {
@@ -692,8 +693,10 @@ ScChangeActionIns::ScChangeActionIns(
     const sal_uLong nActionNumber, const ScChangeActionState eStateP,
     const sal_uLong nRejectingNumber, const ScBigRange& aBigRangeP,
     const OUString& aUserP, const DateTime& aDateTimeP,
-    const OUString& sComment, const ScChangeActionType eTypeP) :
-    ScChangeAction(eTypeP, aBigRangeP, nActionNumber, nRejectingNumber, eStateP, aDateTimeP, aUserP, sComment)
+    const OUString& sComment, const ScChangeActionType eTypeP,
+    bool bEndOfList ) :
+    ScChangeAction(eTypeP, aBigRangeP, nActionNumber, nRejectingNumber, eStateP, aDateTimeP, aUserP, sComment),
+    mbEndOfList(bEndOfList)
 {
 }
 
@@ -736,6 +739,11 @@ void ScChangeActionIns::GetDescription(
     }
 }
 
+bool ScChangeActionIns::IsEndOfList() const
+{
+    return mbEndOfList;
+}
+
 bool ScChangeActionIns::Reject( ScDocument* pDoc )
 {
     if ( !aBigRange.IsValid( pDoc ) )
@@ -2826,9 +2834,9 @@ ScChangeActionContent* ScChangeTrack::AppendContentOnTheFly(
     return pAct;
 }
 
-void ScChangeTrack::AppendInsert( const ScRange& rRange )
+void ScChangeTrack::AppendInsert( const ScRange& rRange, bool bEndOfList )
 {
-    ScChangeActionIns* pAct = new ScChangeActionIns( rRange );
+    ScChangeActionIns* pAct = new ScChangeActionIns(rRange, bEndOfList);
     Append( pAct );
 }
 
@@ -4458,18 +4466,20 @@ ScChangeTrack* ScChangeTrack::Clone( ScDocument* pDocument ) const
             case SC_CAT_INSERT_COLS:
             case SC_CAT_INSERT_ROWS:
             case SC_CAT_INSERT_TABS:
-                {
-                    pClonedAction = new ScChangeActionIns(
-                        pAction->GetActionNumber(),
-                        pAction->GetState(),
-                        pAction->GetRejectAction(),
-                        pAction->GetBigRange(),
-                        pAction->GetUser(),
-                        pAction->GetDateTimeUTC(),
-                        pAction->GetComment(),
-                        pAction->GetType() );
-                }
-                break;
+            {
+                bool bEndOfList = static_cast<const ScChangeActionIns*>(pAction)->IsEndOfList();
+                pClonedAction = new ScChangeActionIns(
+                    pAction->GetActionNumber(),
+                    pAction->GetState(),
+                    pAction->GetRejectAction(),
+                    pAction->GetBigRange(),
+                    pAction->GetUser(),
+                    pAction->GetDateTimeUTC(),
+                    pAction->GetComment(),
+                    pAction->GetType(),
+                    bEndOfList );
+            }
+            break;
             case SC_CAT_DELETE_COLS:
             case SC_CAT_DELETE_ROWS:
             case SC_CAT_DELETE_TABS:
diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx b/sc/source/filter/inc/XclExpChangeTrack.hxx
index 72b7066..c7ee389 100644
--- a/sc/source/filter/inc/XclExpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclExpChangeTrack.hxx
@@ -516,11 +516,12 @@ public:
 
 class XclExpChTrInsert : public XclExpChTrAction
 {
+    bool mbEndOfList;
+
 protected:
     ScRange                     aRange;
 
-                                XclExpChTrInsert( const XclExpChTrInsert& rCopy ) :
-                                    XclExpChTrAction( rCopy ), aRange( rCopy.aRange ) {}
+    XclExpChTrInsert( const XclExpChTrInsert& rCopy );
 
     virtual void                SaveActionData( XclExpStream& rStrm ) const;
     virtual void                PrepareSaveAction( XclExpStream& rStrm ) const;
diff --git a/sc/source/filter/inc/XclImpChangeTrack.hxx b/sc/source/filter/inc/XclImpChangeTrack.hxx
index ffce967..c1b06d6 100644
--- a/sc/source/filter/inc/XclImpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclImpChangeTrack.hxx
@@ -73,7 +73,7 @@ private:
     void                        DoAcceptRejectAction( ScChangeAction* pAction );
     void                        DoAcceptRejectAction( sal_uInt32 nFirst, sal_uInt32 nLast );
 
-    void                        DoInsertRange( const ScRange& rRange );
+    void DoInsertRange( const ScRange& rRange, bool bEndOfList );
     void                        DoDeleteRange( const ScRange& rRange );
 
     inline sal_uInt8            LookAtuInt8();
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index aed0322..fe27e92 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -1118,7 +1118,10 @@ void XclExpChTrCellContent::SaveXml( XclExpXmlStream& rRevisionLogStrm )
     pStream->endElement( XML_rcc );
 }
 
-//___________________________________________________________________
+XclExpChTrInsert::XclExpChTrInsert( const XclExpChTrInsert& rCopy ) :
+    XclExpChTrAction(rCopy),
+    mbEndOfList(rCopy.mbEndOfList),
+    aRange(rCopy.aRange) {}
 
 XclExpChTrInsert::XclExpChTrInsert(
         const ScChangeAction& rAction,
@@ -1126,13 +1129,20 @@ XclExpChTrInsert::XclExpChTrInsert(
         const XclExpChTrTabIdBuffer& rTabIdBuffer,
         ScChangeTrack& rChangeTrack ) :
     XclExpChTrAction( rAction, rRoot, rTabIdBuffer ),
+    mbEndOfList(false),
     aRange( rAction.GetBigRange().MakeRange() )
 {
     nLength = 0x00000030;
     switch( rAction.GetType() )
     {
         case SC_CAT_INSERT_COLS:    nOpCode = EXC_CHTR_OP_INSCOL;   break;
-        case SC_CAT_INSERT_ROWS:    nOpCode = EXC_CHTR_OP_INSROW;   break;
+        case SC_CAT_INSERT_ROWS:
+        {
+            const ScChangeActionIns& rIns = static_cast<const ScChangeActionIns&>(rAction);
+            mbEndOfList = rIns.IsEndOfList();
+            nOpCode = EXC_CHTR_OP_INSROW;
+        }
+        break;
         case SC_CAT_DELETE_COLS:    nOpCode = EXC_CHTR_OP_DELCOL;   break;
         case SC_CAT_DELETE_ROWS:    nOpCode = EXC_CHTR_OP_DELROW;   break;
         default:
@@ -1164,7 +1174,8 @@ XclExpChTrInsert::~XclExpChTrInsert()
 void XclExpChTrInsert::SaveActionData( XclExpStream& rStrm ) const
 {
     WriteTabId( rStrm, aRange.aStart.Tab() );
-    rStrm   << (sal_uInt16) 0x0000;
+    sal_uInt16 nFlagVal = mbEndOfList ? 0x0001 : 0x0000;
+    rStrm << nFlagVal;
     Write2DRange( rStrm, aRange );
     rStrm   << (sal_uInt32) 0x00000000;
 }
diff --git a/sc/source/filter/xcl97/XclImpChangeTrack.cxx b/sc/source/filter/xcl97/XclImpChangeTrack.cxx
index 58c2540..cf1babc 100644
--- a/sc/source/filter/xcl97/XclImpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclImpChangeTrack.cxx
@@ -95,10 +95,10 @@ void XclImpChangeTrack::DoAcceptRejectAction( sal_uInt32 nFirst, sal_uInt32 nLas
         DoAcceptRejectAction( pChangeTrack->GetAction( nIndex ) );
 }
 
-void XclImpChangeTrack::DoInsertRange( const ScRange& rRange )
+void XclImpChangeTrack::DoInsertRange( const ScRange& rRange, bool bEndOfList )
 {
     sal_uInt32 nFirst = pChangeTrack->GetActionMax() + 1;
-    pChangeTrack->AppendInsert( rRange );
+    pChangeTrack->AppendInsert(rRange, bEndOfList);
     sal_uInt32 nLast = pChangeTrack->GetActionMax();
     DoAcceptRejectAction( nFirst, nLast );
 }
@@ -299,7 +299,8 @@ void XclImpChangeTrack::ReadChTrInsert()
         ScRange aRange;
         aRange.aStart.SetTab( ReadTabNum() );
         aRange.aEnd.SetTab( aRange.aStart.Tab() );
-        pStrm->Ignore( 2 );
+        sal_uInt16 nFlags = pStrm->ReaduInt16();
+        bool bEndOfList = (nFlags & 0x0001); // row auto-inserted at the bottom.
         Read2DRange( aRange );
 
         if( aRecHeader.nOpCode & EXC_CHTR_OP_COLFLAG )
@@ -316,7 +317,7 @@ void XclImpChangeTrack::ReadChTrInsert()
             if( aRecHeader.nOpCode & EXC_CHTR_OP_DELFLAG )
                 DoDeleteRange( aRange );
             else
-                DoInsertRange( aRange );
+                DoInsertRange(aRange, bEndOfList);
         }
     }
 }
@@ -428,7 +429,7 @@ void XclImpChangeTrack::ReadChTrInsertTab()
         if( pStrm->IsValid() )
         {
             nTabIdCount++;
-            DoInsertRange( ScRange( 0, 0, nTab, MAXCOL, MAXROW, nTab ) );
+            DoInsertRange(ScRange(0, 0, nTab, MAXCOL, MAXROW, nTab), false);
         }
     }
 }
-- 
1.9.3