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

Eike Rathke erack at redhat.com
Fri Mar 21 14:22:28 PDT 2014


 sc/source/core/data/tabprotection.cxx |    3 +-
 sc/source/filter/excel/excdoc.cxx     |   14 ++++++++++-
 sc/source/filter/excel/xladdress.cxx  |   20 ++++++++++-------
 sc/source/filter/inc/xcl97rec.hxx     |   19 +++++++++++++++-
 sc/source/filter/inc/xladdress.hxx    |    6 ++---
 sc/source/filter/xcl97/xcl97rec.cxx   |   40 ++++++++++++++++++++++++++++++++++
 6 files changed, 87 insertions(+), 15 deletions(-)

New commits:
commit fc58d7ae8e45dc45988ee247b5a1b8ad5adeb8ac
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Mar 21 22:20:06 2014 +0100

    write enhanced protection to .xls BIFF8 0x0868 Feat records
    
    We now have a roundtrip of the EnhancedProtection feature.
    
    Change-Id: Ib13b4d23a10dd51d9328de872e076bf58ee3127d

diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index 87b17aa..40ed956 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -419,8 +419,7 @@ void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
     //export cell notes
     std::vector<sc::NoteEntry> aNotes;
     rDoc.GetAllNoteEntries(aNotes);
-    std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end();
-    for (; it != itEnd; ++it)
+    for (std::vector<sc::NoteEntry>::const_iterator it = aNotes.begin(), itEnd = aNotes.end(); it != itEnd; ++it)
     {
         if (it->maPos.Tab() != mnScTab)
             continue;
@@ -510,6 +509,17 @@ void ExcTable::FillAsTable( SCTAB nCodeNameIdx )
         // sheet protection options
         Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
 
+        // enhanced protections if there are
+        if (pTabProtect)
+        {
+            const ::std::vector<ScEnhancedProtection>& rProts( pTabProtect->getEnhancedProtection());
+            for (::std::vector<ScEnhancedProtection>::const_iterator it( rProts.begin()), itEnd( rProts.end());
+                    it != itEnd; ++it)
+            {
+                Add( new XclExpSheetEnhancedProtection( GetRoot(), *it));
+            }
+        }
+
         // web queries
         Add( new XclExpWebQueryBuffer( GetRoot() ) );
 
diff --git a/sc/source/filter/excel/xladdress.cxx b/sc/source/filter/excel/xladdress.cxx
index 237d0f7..829523d 100644
--- a/sc/source/filter/excel/xladdress.cxx
+++ b/sc/source/filter/excel/xladdress.cxx
@@ -93,11 +93,11 @@ XclRange XclRangeList::GetEnclosingRange() const
     return aXclRange;
 }
 
-void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit, sal_uInt16 nRefs )
+void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit, sal_uInt16 nCountInStream )
 {
     sal_uInt16 nCount;
-    if (nRefs)
-        nCount = nRefs;
+    if (nCountInStream)
+        nCount = nCountInStream;
     else
         rStrm >> nCount;
     size_t nOldSize = size();
@@ -106,17 +106,21 @@ void XclRangeList::Read( XclImpStream& rStrm, bool bCol16Bit, sal_uInt16 nRefs )
         aIt->Read( rStrm, bCol16Bit );
 }
 
-void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit ) const
+void XclRangeList::Write( XclExpStream& rStrm, bool bCol16Bit, sal_uInt16 nCountInStream ) const
 {
-    WriteSubList( rStrm, 0, size(), bCol16Bit );
+    WriteSubList( rStrm, 0, size(), bCol16Bit, nCountInStream );
 }
 
-void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit ) const
+void XclRangeList::WriteSubList( XclExpStream& rStrm, size_t nBegin, size_t nCount, bool bCol16Bit,
+        sal_uInt16 nCountInStream ) const
 {
     OSL_ENSURE( nBegin <= size(), "XclRangeList::WriteSubList - invalid start position" );
     size_t nEnd = ::std::min< size_t >( nBegin + nCount, size() );
-    sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
-    rStrm << nXclCount;
+    if (!nCountInStream)
+    {
+        sal_uInt16 nXclCount = ulimit_cast< sal_uInt16 >( nEnd - nBegin );
+        rStrm << nXclCount;
+    }
     rStrm.SetSliceSize( bCol16Bit ? 8 : 6 );
     for( const_iterator aIt = begin() + nBegin, aEnd = begin() + nEnd; aIt != aEnd; ++aIt )
         aIt->Write( rStrm, bCol16Bit );
diff --git a/sc/source/filter/inc/xcl97rec.hxx b/sc/source/filter/inc/xcl97rec.hxx
index 2dff810..ff3b51e 100644
--- a/sc/source/filter/inc/xcl97rec.hxx
+++ b/sc/source/filter/inc/xcl97rec.hxx
@@ -23,6 +23,7 @@
 #include "excrecds.hxx"
 #include "xcl97esc.hxx"
 #include "xlstyle.hxx"
+#include "tabprotection.hxx"
 
 
 
@@ -435,7 +436,7 @@ public:
 
 
 
-/** Represents a SHEETPROTECTION record that stores sheet protection
+/** Represents a FEATHDR (SHEETPROTECTION) record that stores sheet protection
     options.  Note that a sheet still needs to save its sheet protection
     options even when it's not protected. */
 class XclExpSheetProtectOptions : public XclExpRecord
@@ -451,6 +452,22 @@ private:
 };
 
 
+/** Represents one EnhancedProtection feature in a FEAT record.
+    To be written only if such feature exists. */
+class XclExpSheetEnhancedProtection : public XclExpRecord
+{
+public:
+    explicit            XclExpSheetEnhancedProtection( const XclExpRoot& rRoot, const ScEnhancedProtection& rProt );
+
+private:
+    virtual void        WriteBody( XclExpStream& rStrm );
+
+private:
+    const XclExpRoot&       mrRoot;
+    ScEnhancedProtection    maEnhancedProtection;
+};
+
+
 
 class XclCalccount : public ExcRecord
 {
diff --git a/sc/source/filter/inc/xladdress.hxx b/sc/source/filter/inc/xladdress.hxx
index 9748885..ef7d6d8 100644
--- a/sc/source/filter/inc/xladdress.hxx
+++ b/sc/source/filter/inc/xladdress.hxx
@@ -126,10 +126,10 @@ public:
 
     XclRange            GetEnclosingRange() const;
 
-    void                Read( XclImpStream& rStrm, bool bCol16Bit = true, sal_uInt16 nRefs = 0 );
-    void                Write( XclExpStream& rStrm, bool bCol16Bit = true ) const;
+    void                Read( XclImpStream& rStrm, bool bCol16Bit = true, sal_uInt16 nCountInStream = 0 );
+    void                Write( XclExpStream& rStrm, bool bCol16Bit = true, sal_uInt16 nCountInStream = 0 ) const;
     void                WriteSubList( XclExpStream& rStrm,
-                            size_t nBegin, size_t nCount, bool bCol16Bit = true ) const;
+                            size_t nBegin, size_t nCount, bool bCol16Bit = true, sal_uInt16 nCountInStream = 0 ) const;
 };
 
 inline XclImpStream& operator>>( XclImpStream& rStrm, XclRangeList& rXclRanges )
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index 19dd891..ef67dcc 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -1480,6 +1480,46 @@ void XclExpSheetProtectOptions::WriteBody( XclExpStream& rStrm )
 
 
 
+XclExpSheetEnhancedProtection::XclExpSheetEnhancedProtection( const XclExpRoot& rRoot,
+        const ScEnhancedProtection & rProt ) :
+    XclExpRecord( 0x0868 ),
+    mrRoot( rRoot ),
+    maEnhancedProtection( rProt )
+{
+}
+
+void XclExpSheetEnhancedProtection::WriteBody( XclExpStream& rStrm )
+{
+    sal_uInt16 nRecordType = 0x0868;
+    rStrm << nRecordType;                   // frtHeader rt
+    rStrm.WriteZeroBytesToRecord(10);       // frtHeader unused
+    rStrm << EXC_ISFPROTECTION;             // isf
+    rStrm.WriteZeroBytesToRecord(5);        // reserved1 (1 bytes) and reserved2 (4 bytes)
+
+    XclRangeList aRefs;
+    if (maEnhancedProtection.maRangeList.Is())
+        mrRoot.GetAddressConverter().ConvertRangeList( aRefs, *maEnhancedProtection.maRangeList, false);
+    sal_uInt16 nCref = ulimit_cast<sal_uInt16>(aRefs.size());
+    rStrm << nCref;                         // cref
+    rStrm.WriteZeroBytesToRecord(6);        // cbFeatData if EXC_ISFFEC2 (4 bytes) and reserved3 (2 bytes)
+    aRefs.Write( rStrm, true, nCref);       // refs
+
+    // FeatProtection structure
+    rStrm << maEnhancedProtection.mnAreserved;              // 1 bit A and 31 bits reserved
+    rStrm << maEnhancedProtection.mnPasswordVerifier;       // wPassword
+    rStrm << XclExpString( maEnhancedProtection.maTitle);   // stTitle
+    bool bSDContainer = ((maEnhancedProtection.mnAreserved & 0x80000000) == 0x80000000);
+    sal_uInt32 nCbSD = maEnhancedProtection.maSecurityDescriptor.size();
+    SAL_WARN_IF( bSDContainer && nCbSD < 20, "sc.filter",
+            "XclExpSheetEnhancedProtection A flag indicates container but cbSD < 20");
+    SAL_WARN_IF( !bSDContainer && nCbSD > 0, "sc.filter",
+            "XclExpSheetEnhancedProtection A flag indicates no container but cbSD > 0");
+    if (bSDContainer)
+    {
+        rStrm << nCbSD;
+        rStrm.Write( &maEnhancedProtection.maSecurityDescriptor.front(), nCbSD);
+    }
+}
 
 
 
commit 0536356202f9bbee4272731dca887c12594aa470
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Mar 21 21:47:14 2014 +0100

    copy-construct maEnhancedProtection in ScTableProtectionImpl
    
    Change-Id: Ia1f7415b853f9e5ac585f89cbc938c2464c33fe5

diff --git a/sc/source/core/data/tabprotection.cxx b/sc/source/core/data/tabprotection.cxx
index 7accb27..8b4aa7c 100644
--- a/sc/source/core/data/tabprotection.cxx
+++ b/sc/source/core/data/tabprotection.cxx
@@ -188,7 +188,8 @@ ScTableProtectionImpl::ScTableProtectionImpl(const ScTableProtectionImpl& r) :
     mbEmptyPass(r.mbEmptyPass),
     mbProtected(r.mbProtected),
     meHash1(r.meHash1),
-    meHash2(r.meHash2)
+    meHash2(r.meHash2),
+    maEnhancedProtection(r.maEnhancedProtection)
 {
 }
 


More information about the Libreoffice-commits mailing list