summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2014-03-21 22:20:06 +0100
committerEike Rathke <erack@redhat.com>2014-03-21 22:21:59 +0100
commitfc58d7ae8e45dc45988ee247b5a1b8ad5adeb8ac (patch)
treebba7cfdcd0eeccbb29a1b17d3cfb630983f91b56 /sc
parent0536356202f9bbee4272731dca887c12594aa470 (diff)
write enhanced protection to .xls BIFF8 0x0868 Feat records
We now have a roundtrip of the EnhancedProtection feature. Change-Id: Ib13b4d23a10dd51d9328de872e076bf58ee3127d
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/excel/excdoc.cxx14
-rw-r--r--sc/source/filter/excel/xladdress.cxx20
-rw-r--r--sc/source/filter/inc/xcl97rec.hxx19
-rw-r--r--sc/source/filter/inc/xladdress.hxx6
-rw-r--r--sc/source/filter/xcl97/xcl97rec.cxx40
5 files changed, 85 insertions, 14 deletions
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index 87b17aa871e4..40ed956b624e 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 237d0f71b6ef..829523de9268 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 2dff81099930..ff3b51e29397 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 9748885a1de5..ef7d6d84b36b 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 19dd891b8374..ef67dcc38246 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);
+ }
+}