ooo-build r14700 - in trunk: . patches/dev300 patches/vba



Author: kyoshida
Date: Tue Dec  2 22:39:33 2008
New Revision: 14700
URL: http://svn.gnome.org/viewvc/ooo-build?rev=14700&view=rev

Log:
2008-12-02  Kohei Yoshida  <kyoshida novell com>

	* patches/dev300/apply:
	* patches/dev300/calc-external-defined-names-sc.diff:
	* patches/dev300/cws-scsheetprotection02-sc.diff:
	* patches/dev300/cws-scsheetprotection02-sfx2.diff:
	* patches/dev300/cws-scsheetprotection02-svx.diff:
	* patches/vba/vba-workbook-worksheet-events.diff: fixed these patches.
	I'm not entirely finished with my patch repair work yet.  This may not
	even build.

	* patches/dev300/calc-fix-datapilot-date-filter.diff: removed as this
	patch has been upstreamed.


Removed:
   trunk/patches/dev300/calc-fix-datapilot-date-filter.diff
Modified:
   trunk/ChangeLog
   trunk/patches/dev300/apply
   trunk/patches/dev300/calc-external-defined-names-sc.diff
   trunk/patches/dev300/cws-scsheetprotection02-sc.diff
   trunk/patches/dev300/cws-scsheetprotection02-sfx2.diff
   trunk/patches/dev300/cws-scsheetprotection02-svx.diff
   trunk/patches/vba/vba-workbook-worksheet-events.diff

Modified: trunk/patches/dev300/apply
==============================================================================
--- trunk/patches/dev300/apply	(original)
+++ trunk/patches/dev300/apply	Tue Dec  2 22:39:33 2008
@@ -735,9 +735,9 @@
 # and use that information to constrain cell cursor movement when the sheet is
 # protected.  Also to support encryption on Excel file export.
 # FIXME 2008-11-26: don't apply to dev300-m35
-#cws-scsheetprotection02-sc.diff,   i#60305, i#71468, i#84766, kohei
-#cws-scsheetprotection02-sfx2.diff, i#60305, i#71468, i#84766, kohei
-#cws-scsheetprotection02-svx.diff,  i#60305, i#71468, i#84766, kohei
+cws-scsheetprotection02-sc.diff,   i#60305, i#71468, i#84766, kohei
+cws-scsheetprotection02-sfx2.diff, i#60305, i#71468, i#84766, kohei
+cws-scsheetprotection02-svx.diff,  i#60305, i#71468, i#84766, kohei
 
 # Ensure that Print Preview is consistent with Print output.
 sc-print-selected-sheets.diff, n#335684, i#45497, jonp
@@ -833,9 +833,6 @@
 calc-dp-pivotcache-fix.diff, n#433658, i#96326, kohei
 
 [ CalcFixes ]
-# Fix a regression on filtering by page field.
-# FIXME 2008-11-26: lots of failed chunks for dev300-m35
-#calc-fix-datapilot-date-filter.diff, i#90022, kohei
 
 # make biffdumper build
 fix-biffdumper.diff, noelpwer
@@ -1827,14 +1824,14 @@
 
 # Implement external range names.
 # FIXME 2008-11-26: doesn't apply to dev300-m35
-#calc-external-defined-names-sc.diff, i#3740, i#4385, n#355685, kohei
-#calc-external-defined-names-offapi.diff, i#3740, i#4385, n#355685, kohei
-#calc-external-defined-names-officecfg.diff, i#3740, i#4385, n#355685, kohei
-#calc-external-defined-names-svtools.diff, i#3740, i#4385, n#355685, kohei
+calc-external-defined-names-sc.diff, i#3740, i#4385, n#355685, kohei
+calc-external-defined-names-offapi.diff, i#3740, i#4385, n#355685, kohei
+calc-external-defined-names-officecfg.diff, i#3740, i#4385, n#355685, kohei
+calc-external-defined-names-svtools.diff, i#3740, i#4385, n#355685, kohei
 
 # Additional fix for the external range name implementation.
 # FIXME 2008-11-26: doesn't apply to dev300-m35
-#calc-external-defined-names-sc-fixes.diff, i#3740, i#4385, n#355685, kohei
+calc-external-defined-names-sc-fixes.diff, i#3740, i#4385, n#355685, kohei
 
 # Don't adjust row height on xls load for better layout preservation and
 # faster file load.

Modified: trunk/patches/dev300/calc-external-defined-names-sc.diff
==============================================================================
--- trunk/patches/dev300/calc-external-defined-names-sc.diff	(original)
+++ trunk/patches/dev300/calc-external-defined-names-sc.diff	Tue Dec  2 22:39:33 2008
@@ -160,15 +160,15 @@
          USHORT       nIndex;                // index into name collection
          sal_Unicode  cStr[ MAXSTRLEN+1 ];   // string (up to 255 characters + 0)
 @@ -180,6 +192,9 @@ public:
-     void SetDouble( double fVal );
-     void SetInt( int nVal );
+ //UNUSED2008-05  ComplRefData& GetReference();
+ //UNUSED2008-05  void SetReference( ComplRefData& rRef );
      void SetName( USHORT n );
 +    void SetExternalSingleRef( sal_uInt16 nFileId, const String& rTabName, const SingleRefData& rRef );
 +    void SetExternalDoubleRef( sal_uInt16 nFileId, const String& rTabName, const ComplRefData& rRef );
 +    void SetExternalName( sal_uInt16 nFileId, const String& rName );
-     void SetMatrix( ScMatrix* p );
      void SetExternal(const sal_Unicode* pStr);
-     // These methods are ok to use, reference count not cleared.
+ 
+     ScRawToken* Clone() const;      // real copy!
 @@ -228,6 +243,24 @@ public:
                                     xub_StrLen nSrcPos,
                                     const CharClass* pCharClass) const = 0;
@@ -1207,15 +1207,6 @@
 index fc6df5f..b49a9fd 100644
 --- sc/source/core/data/cell2.cxx
 +++ sc/source/core/data/cell2.cxx
-@@ -7,7 +7,7 @@
-  * OpenOffice.org - a multi-platform office productivity suite
-  *
-  * $RCSfile: cell2.cxx,v $
-- * $Revision: 1.34 $
-+ * $Revision: 1.34.108.4 $
-  *
-  * This file is part of OpenOffice.org.
-  *
 @@ -51,6 +51,7 @@
  #include "indexmap.hxx"
  #include "scitems.hxx"
@@ -1384,15 +1375,6 @@
 index 886156d..6183449 100644
 --- sc/source/core/data/document.cxx
 +++ sc/source/core/data/document.cxx
-@@ -7,7 +7,7 @@
-  * OpenOffice.org - a multi-platform office productivity suite
-  *
-  * $RCSfile: document.cxx,v $
-- * $Revision: 1.90 $
-+ * $Revision: 1.90.44.2 $
-  *
-  * This file is part of OpenOffice.org.
-  *
 @@ -91,6 +91,7 @@
  #include "bcaslot.hxx"
  #include "postit.hxx"
@@ -1429,15 +1411,6 @@
 index b9dd766..3a85852 100644
 --- sc/source/core/inc/interpre.hxx
 +++ sc/source/core/inc/interpre.hxx
-@@ -7,7 +7,7 @@
-  * OpenOffice.org - a multi-platform office productivity suite
-  *
-  * $RCSfile: interpre.hxx,v $
-- * $Revision: 1.35 $
-+ * $Revision: 1.35.44.1 $
-  *
-  * This file is part of OpenOffice.org.
-  *
 @@ -505,6 +505,7 @@ BOOL SetSbxVariable( SbxVariable* pVar, SCCOL nCol, SCROW nRow, SCTAB nTab );
  void ScErrorType();
  void ScDBArea();
@@ -3865,15 +3838,6 @@
 index 5f6faa3..c70d42d 100644
 --- sc/source/core/tool/interpr4.cxx
 +++ sc/source/core/tool/interpr4.cxx
-@@ -7,7 +7,7 @@
-  * OpenOffice.org - a multi-platform office productivity suite
-  *
-  * $RCSfile: interpr4.cxx,v $
-- * $Revision: 1.57 $
-+ * $Revision: 1.57.92.1 $
-  *
-  * This file is part of OpenOffice.org.
-  *
 @@ -74,6 +74,7 @@
  #include "addinlis.hxx"
  #include "jumpmatrix.hxx"
@@ -4047,9 +4011,9 @@
 +    extname.cName[n] = 0;
 +}
 +
- ComplRefData& ScRawToken::GetReference()
- {
-     DBG_ASSERT( lcl_IsReference( eOp, GetType() ), "GetReference: no Ref" );
+ //UNUSED2008-05  void ScRawToken::SetInt(int rVal)
+ //UNUSED2008-05  {
+ //UNUSED2008-05      eOp   = ocPush;
 @@ -260,22 +304,34 @@ ScRawToken* ScRawToken::Clone() const
          static USHORT nOffset = lcl_ScRawTokenOffset();     // offset of sbyte
          USHORT n = nOffset;

Modified: trunk/patches/dev300/cws-scsheetprotection02-sc.diff
==============================================================================
--- trunk/patches/dev300/cws-scsheetprotection02-sc.diff	(original)
+++ trunk/patches/dev300/cws-scsheetprotection02-sc.diff	Tue Dec  2 22:39:33 2008
@@ -1,2567 +1,1927 @@
-? sc/sc.vpj
-Index: sc/inc/document.hxx
+Index: source/filter/excel/xeroot.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/inc/document.hxx,v
-retrieving revision 1.115
-diff -u -I $Revision.*$ -I $Author.*$ -r1.115 document.hxx
---- sc/inc/document.hxx	8 Jul 2008 07:19:13 -0000	1.115
-+++ sc/inc/document.hxx	14 Aug 2008 17:05:40 -0000
-@@ -89,6 +89,7 @@
- class ScDetOpData;
- class ScDetOpList;
- class ScDocOptions;
-+class ScDocProtection;
- class ScDocumentPool;
- class ScDrawLayer;
- class ScExtDocOptions;
-@@ -104,6 +105,7 @@
- class ScStyleSheet;
- class ScStyleSheetPool;
- class ScTable;
-+class ScTableProtection;
- class ScTokenArray;
- class ScValidationData;
- class ScValidationDataList;
-@@ -276,7 +278,7 @@
- 
- 	ScFieldEditEngine*	pCacheFieldEditEngine;
- 
--	com::sun::star::uno::Sequence<sal_Int8>	aProtectPass;
-+    ::std::auto_ptr<ScDocProtection> pDocProtection;
- 	String              aDocName;                       // opt: Dokumentname
- 	ScRangePairListRef	xColNameRanges;
- 	ScRangePairListRef	xRowNameRanges;
-@@ -340,7 +342,6 @@
+--- sc/source/filter/excel/xeroot.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xeroot.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -32,7 +32,11 @@
+ #include "precompiled_sc.hxx"
+ #include "xeroot.hxx"
+ #include <sfx2/docfile.hxx>
++#include <sfx2/sfxsids.hrc>
+ #include <svtools/saveopt.hxx>
++#include <svtools/itemset.hxx>
++#include <svtools/stritem.hxx>
++#include <svtools/eitem.hxx>
+ #include "xltracer.hxx"
+ #include "xehelper.hxx"
+ #include "xeformula.hxx"
+@@ -42,8 +46,10 @@
+ #include "xecontent.hxx"
+ #include "xepivot.hxx"
  
- 	ScLkUpdMode			eLinkMode;
+-// for filter manager
+-#include "excrecds.hxx"
++#include "excrecds.hxx"  // for filter manager
++#include "tabprotection.hxx"
++#include "document.hxx"
++#include "scextopt.hxx"
  
--	BOOL				bProtected;
- 	BOOL				bAutoCalc;						// Automatisch Berechnen
- 	BOOL				bAutoCalcShellDisabled;			// in/von/fuer ScDocShell disabled
- 	// ob noch ForcedFormulas berechnet werden muessen,
-@@ -524,13 +525,16 @@
- 	inline SCTAB	GetTableCount() const { return nMaxTableNumber; }
- 	SvNumberFormatterIndexTable* GetFormatExchangeList() const { return pFormatExchangeList; }
+ // Global data ================================================================
  
--	void			SetDocProtection( BOOL bProtect, const com::sun::star::uno::Sequence <sal_Int8>& aPass );
--	void			SetTabProtection( SCTAB nTab, BOOL bProtect, const com::sun::star::uno::Sequence <sal_Int8>& aPass );
-+    ScDocProtection* GetDocProtection() const;
-+    void            SetDocProtection(bool bProtect, const String& aPassText);
-+    void            SetDocProtection(const ScDocProtection* pProtect);
- 	BOOL			IsDocProtected() const;
- 	BOOL			IsDocEditable() const;
- 	BOOL			IsTabProtected( SCTAB nTab ) const;
--	const com::sun::star::uno::Sequence <sal_Int8>&	GetDocPassword() const;
--	const com::sun::star::uno::Sequence <sal_Int8>&	GetTabPassword( SCTAB nTab ) const;
-+    SC_DLLPUBLIC ScTableProtection* GetTabProtection( SCTAB nTab ) const;
-+    void            SetTabProtection(SCTAB nTab, bool bProtect, const String& aPassText);
-+    void            SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect);
-+    void            CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest);
+@@ -221,6 +227,40 @@
+     return xRec;
+ }
  
- 	void			LockTable(SCTAB nTab);
- 	void			UnlockTable(SCTAB nTab);
-@@ -1495,6 +1499,8 @@
++bool XclExpRoot::IsDocumentEncrypted() const
++{
++    // We need to encrypt the content when the document structure is protected.
++    const ScDocProtection* pDocProt = GetDoc().GetDocProtection();
++    if (pDocProt && pDocProt->isProtected() && pDocProt->isOptionEnabled(ScDocProtection::STRUCTURE))
++        return true;
++
++    if (GetPassword().Len() > 0)
++        // Password is entered directly into the save dialog.
++        return true;
++
++    return false;
++}
++
++const String XclExpRoot::GetPassword() const
++{
++    SfxItemSet* pSet = GetMedium().GetItemSet();
++    if (!pSet)
++        return String();
++
++    const SfxPoolItem* pItem = NULL;
++    if (SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pItem))
++    {
++        const SfxStringItem* pStrItem = dynamic_cast<const SfxStringItem*>(pItem);
++        if (pStrItem)
++        {
++            // Password from the save dialog.
++            return pStrItem->GetValue();
++        }
++    }
++
++    return String();
++}
++
+ XclExpRootData::XclExpLinkMgrRef XclExpRoot::GetLocalLinkMgrRef() const
+ {
+     return IsInGlobals() ? mrExpData.mxGlobLinkMgr : mrExpData.mxLocLinkMgr;
+Index: source/filter/excel/xiroot.cxx
+===================================================================
+--- sc/source/filter/excel/xiroot.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xiroot.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -52,6 +52,7 @@
+ XclImpRootData::XclImpRootData( XclBiff eBiff, SfxMedium& rMedium,
+         SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
+     XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ),
++    mbPassQueried( false ),
+     mbHasCodePage( false )
+ {
+ }
+@@ -86,6 +87,8 @@
+         GetOldRoot().pAutoFilterBuffer = new XclImpAutoFilterBuffer;
+         mrImpData.mxWebQueryBfr.reset( new XclImpWebQueryBuffer( GetRoot() ) );
+         mrImpData.mxPTableMgr.reset( new XclImpPivotTableManager( GetRoot() ) );
++        mrImpData.mxTabProtect.reset( new XclImpSheetProtectBuffer( GetRoot() ) );
++        mrImpData.mxDocProtect.reset( new XclImpDocProtectBuffer( GetRoot() ) );
+     }
  
+     mrImpData.mxPageSett.reset( new XclImpPageSettings( GetRoot() ) );
+@@ -232,6 +235,18 @@
+     return *mrImpData.mxPTableMgr;
+ }
  
- private:
-+    ScDocument(const ScDocument& r); // disabled with no definition
++XclImpSheetProtectBuffer& XclImpRoot::GetSheetProtectBuffer() const
++{
++    DBG_ASSERT( mrImpData.mxTabProtect.is(), "XclImpRoot::GetSheetProtectBuffer - invalid call, wrong BIFF" );
++    return *mrImpData.mxTabProtect;
++}
 +
- 	void				SetAutoFilterFlags();
- 	void				FindMaxRotCol( SCTAB nTab, RowInfo* pRowInfo, SCSIZE nArrCount,
- 										SCCOL nX1, SCCOL nX2 ) const;
-Index: sc/inc/sc.hrc
-===================================================================
-RCS file: /cvs/sc/sc/inc/sc.hrc,v
-retrieving revision 1.63
-retrieving revision 1.62.30.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.63 -r1.62.30.4
---- sc/inc/sc.hrc	1 Jul 2008 16:22:11 -0000	1.63
-+++ sc/inc/sc.hrc	17 Jul 2008 00:59:45 -0000	1.62.30.4
-@@ -1626,7 +1626,12 @@
- #define RID_SCDLG_CONFLICTS             (SC_DIALOGS_START + 145)
- #define RID_SCDLG_SHAREDOCUMENT         (SC_DIALOGS_START + 146)
++XclImpDocProtectBuffer& XclImpRoot::GetDocProtectBuffer() const
++{
++    DBG_ASSERT( mrImpData.mxDocProtect.is(), "XclImpRoot::GetDocProtectBuffer - invalid call, wrong BIFF" );
++    return *mrImpData.mxDocProtect;
++}
++
+ XclImpPageSettings& XclImpRoot::GetPageSettings() const
+ {
+     return *mrImpData.mxPageSett;
+@@ -255,5 +270,18 @@
+     return rXclName;
+ }
  
--#define SC_DIALOGS_END          (SC_DIALOGS_START + 150)
-+#define RID_SCDLG_TABPROTECTION         (SC_DIALOGS_START + 147)
-+#define RID_SCDLG_DOCPROTECTION         (SC_DIALOGS_START + 148)
-+#define RID_SCDLG_RETYPEPASS            (SC_DIALOGS_START + 149)
-+#define RID_SCDLG_RETYPEPASS_INPUT      (SC_DIALOGS_START + 150)
++const String& XclImpRoot::QueryPassword() const
++{
++    if( !mrImpData.mbPassQueried )
++    {
++        mrImpData.maPassw = ScfApiHelper::QueryPasswordForMedium( GetMedium() );
++        // set to true, even if dialog has been cancelled (never ask twice)
++        mrImpData.mbPassQueried = true;
++        fprintf(stdout, "XclImpRoot::QueryPassword: password = '%s'\n",
++                OUStringToOString(rtl::OUString(mrImpData.maPassw), RTL_TEXTENCODING_UTF8).getStr());fflush(stdout);
++    }
++    return mrImpData.maPassw;
++}
 +
-+#define SC_DIALOGS_END          (SC_DIALOGS_START + 151)
+ // ============================================================================
  
- #ifndef STD_MASKCOLOR
- #define STD_MASKCOLOR Color { Red = 0xFF00; Green = 0x0000; Blue = 0xFF00; }
-Index: sc/inc/scextopt.hxx
+Index: source/filter/excel/xlroot.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/inc/scextopt.hxx,v
-retrieving revision 1.13
-retrieving revision 1.12.694.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.13 -r1.12.694.4
---- sc/inc/scextopt.hxx	10 Apr 2008 18:50:45 -0000	1.13
-+++ sc/inc/scextopt.hxx	22 May 2008 21:44:02 -0000	1.12.694.4
-@@ -46,8 +46,6 @@
-     double              mfTabBarWidth;      /// Width of the tabbar, relative to frame window width (0.0 ... 1.0).
-     sal_uInt32          mnLinkCnt;          /// Recursive counter for loading external documents.
-     SCTAB               mnDisplTab;         /// Index of displayed sheet.
--    bool                mbWinProtected;     /// true = Window properties are protected.
--    bool                mbEncrypted;        /// true = Imported file was encrypted.
+--- sc/source/filter/excel/xlroot.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xlroot.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -91,8 +91,7 @@
+     mxRD( new RootData ),//!
+     mnCharWidth( 110 ),
+     mnScTab( 0 ),
+-    mbExport( bExport ),
+-    mbHasPassw( false )
++    mbExport( bExport )
+ {
+     // default script type, e.g. for empty cells
+     switch( ScGlobal::GetDefaultScriptType() )
+@@ -198,17 +197,6 @@
+     }
+ }
  
-     explicit            ScExtDocSettings();
- };
-Index: sc/inc/table.hxx
+-const String& XclRoot::QueryPassword() const
+-{
+-    if( !mrData.mbHasPassw )
+-    {
+-        mrData.maPassw = ScfApiHelper::QueryPasswordForMedium( GetMedium() );
+-        // set to true, even if dialog has been cancelled (never ask twice)
+-        mrData.mbHasPassw = true;
+-    }
+-    return mrData.maPassw;
+-}
+-
+ bool XclRoot::HasVbaStorage() const
+ {
+     SotStorageRef xRootStrg = GetRootStorage();
+Index: source/filter/excel/xilink.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/inc/table.hxx,v
-retrieving revision 1.35
-retrieving revision 1.34.28.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.35 -r1.34.28.3
---- sc/inc/table.hxx	10 Apr 2008 18:57:06 -0000	1.35
-+++ sc/inc/table.hxx	8 May 2008 23:23:38 -0000	1.34.28.3
-@@ -39,6 +39,8 @@
- #include "sortparam.hxx"
- #include "compressedarray.hxx"
- 
-+#include <memory>
-+
- namespace utl {
- 	class SearchParam;
- 	class TextSearch;
-@@ -65,6 +67,7 @@
- class ScSortInfoArray;
- class ScStyleSheet;
- class ScTableLink;
-+class ScTableProtection;
- class ScUserListData;
- class ScIndexMap;
- struct RowInfo;
-@@ -102,8 +105,7 @@
- 	SCROW			nRepeatStartY;
- 	SCROW			nRepeatEndY;
- 
--	BOOL			bProtected;
--	com::sun::star::uno::Sequence<sal_Int8>	aProtectPass;
-+    ::std::auto_ptr<ScTableProtection> pTabProtection;
+--- sc/source/filter/excel/xilink.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xilink.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -264,6 +264,7 @@
+     DBG_ASSERT_BIFF( rStrm.GetRoot().GetBiff() == EXC_BIFF8 );
+     if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
+     {
++        rStrm.EnableDecryption();
+         sal_Size nReadCount = rStrm.GetRecLeft() / 2;
+         DBG_ASSERT( nReadCount <= 0xFFFF, "XclImpTabInfo::ReadTabid - record too long" );
+         maTabIdVec.clear();
+Index: source/filter/excel/excdoc.cxx
+===================================================================
+--- sc/source/filter/excel/excdoc.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/excdoc.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -67,11 +67,11 @@
+ #include "convuno.hxx"
+ #include "patattr.hxx"
+ #include "docoptio.hxx"
++#include "tabprotection.hxx"
  
- 	USHORT*			pColWidth;
- 	ScSummableCompressedArray< SCROW, USHORT>*  pRowHeight;
-@@ -218,10 +220,11 @@
- 	void			SetPageStyle( const String& rName );
- 	void			PageStyleModified( const String& rNewName );
+ #include "excdoc.hxx"
+ #include "namebuff.hxx"
  
--	BOOL			IsProtected() const						{ return bProtected; }
--	const com::sun::star::uno::Sequence<sal_Int8>&	GetPassword() const						{ return aProtectPass; }
--	void			SetProtection( BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd )
--										{ bProtected = bProtect; aProtectPass = rPasswd; }
-+    BOOL            IsProtected() const;
-+    void            SetProtection(BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd);
-+    void            SetProtection(bool bProtect, const String& aPassText);
-+    void            SetProtection(const ScTableProtection* pProtect);
-+    ScTableProtection* GetProtection();
+-#include "xcl97dum.hxx"
+ #include "xcl97rec.hxx"
+ #include "xcl97esc.hxx"
+ #include "xetable.hxx"
+@@ -150,7 +150,16 @@
+ 		Add( new ExcDummy_00 );
+ 	else
+ 	{
+-		Add( new ExcDummy8_00a );
++        if ( IsDocumentEncrypted() )
++            Add( new XclExpFilePass(GetRoot()) );
++
++        Add( new XclExpInterfaceHdr );
++        Add( new XclExpMMS );
++        Add( new XclExpInterfaceEnd );
++        Add( new XclExpWriteAccess );
++        Add( new XclExpCodePage );
++        Add( new XclExpDSF );
++        Add( new XclExpExcel9File );
+ 		rR.pTabId = new XclExpChTrTabId( Max( nExcTabCount, nCodenames ) );
+ 		Add( rR.pTabId );
+         if( HasVbaStorage() )
+@@ -160,7 +169,8 @@
+             if( rCodeName.Len() )
+                 Add( new XclCodename( rCodeName ) );
+ 		}
+-		Add( new ExcDummy8_00b );
++
++        Add( new XclExpFnGroupCount );
+ 	}
  
- 	Size			GetPageSize() const;
- 	void			SetPageSize( const Size& rSize );
-Index: sc/inc/tabprotection.hxx
-===================================================================
-RCS file: sc/inc/tabprotection.hxx
-diff -N sc/inc/tabprotection.hxx
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/inc/tabprotection.hxx	13 Aug 2008 20:55:29 -0000	1.1.4.5
-@@ -0,0 +1,178 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ *
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: tabprotection.hxx,v $
-+ * $Revision: 1.1.4.5 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
+ 	// erst Namen- und Tabellen-Eintraege aufbauen
+@@ -180,15 +190,29 @@
+         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
+     }
+ 
+-    aRecList.AppendNewRecord( new XclExpWindowProtection( GetExtDocOptions().GetDocSettings().mbWinProtected ) );
+-    aRecList.AppendNewRecord( new XclExpDocProtection( rDoc.IsDocProtected() ) );
+-    aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_PASSWORD, false ) );
++    // document protection options
++    const ScDocProtection* pProtect = GetDoc().GetDocProtection();
++    if (pProtect && pProtect->isProtected())
++    {
++        Add( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
++        Add( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
++        Add( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
++    }
+ 
+     if( GetBiff() == EXC_BIFF8 )
+-        Add( new ExcDummy8_040 );
++    {
++        Add( new XclExpProt4Rev );
++        Add( new XclExpProt4RevPass );
++    }
+ 
+     aRecList.AppendNewRecord( new XclExpWindow1( GetRoot() ) );
+ 
++    if ( GetBiff() == EXC_BIFF8 )
++    {
++        Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
++        Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
++    }
 +
-+#ifndef SC_TAB_PROTECTION_HXX
-+#define SC_TAB_PROTECTION_HXX
+     if( GetBiff() <= EXC_BIFF5 )
+     {
+ 		Add( new ExcDummy_040 );
+@@ -197,9 +221,11 @@
+     }
+     else
+     {
++        // BIFF8
+         Add( new Exc1904( rDoc ) );
+         Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
+-        Add( new ExcDummy8_041 );
++        Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
++        Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
+     }
+ 
+     // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
+@@ -258,10 +284,14 @@
+         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
+         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
+ 
++        Add( new XclExpUnknown01C1 );
 +
-+#include "sal/types.h"
-+#include <com/sun/star/uno/Sequence.hxx>
+ 		// MSODRAWINGGROUP per-document data
+ 		Add( new XclMsodrawinggroup( rR, ESCHER_DggContainer ) );
+         // Shared string table: SST, EXTSST
+         aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
 +
-+#include "global.hxx"
-+#include <vector>
++        Add( new XclExpUnknown0863 );
+ 	}
+ 
+ 	Add( new ExcEof );
+@@ -303,7 +333,7 @@
+         Add( new XclRefmode( rDoc ) );
+         Add( new XclIteration( rDoc ) );
+         Add( new XclDelta( rDoc ) );
+-        Add( new ExcDummy8_02 );
++        Add( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
+     }
+ 
+     // GUTS (count & size of outline icons)
+@@ -320,8 +350,14 @@
+     // page settings (SETUP and various other records)
+     aRecList.AppendRecord( xPageSett );
+ 
+-    if( rDoc.IsTabProtected( mnScTab ) )
+-		Add( new XclProtection() );
++    const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
++    if (pTabProtect && pTabProtect->isProtected())
++    {
++        Add( new XclExpProtection(true) );
++        Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
++        Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
++        Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
++    }
+ 
+     // local link table: EXTERNCOUNT, EXTERNSHEET
+     if( eBiff <= EXC_BIFF5 )
+@@ -367,6 +403,9 @@
+ 
+     if( eBiff == EXC_BIFF8 )
+ 	{
++        // sheet protection options
++        Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
++
+ 		// web queries
+         Add( new XclExpWebQueryBuffer( GetRoot() ) );
+ 
+Index: source/filter/excel/xicontent.cxx
+===================================================================
+--- sc/source/filter/excel/xicontent.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xicontent.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -41,6 +41,7 @@
+ #include "scitems.hxx"
+ #include <svx/eeitem.hxx>
+ #include <svtools/intitem.hxx>
++#include <svtools/stritem.hxx>
+ #include <svx/flditem.hxx>
+ #include <svx/fhgtitem.hxx>
+ #include <svx/wghtitem.hxx>
+@@ -67,7 +68,13 @@
+ #include "xiname.hxx"
+ 
+ #include "excform.hxx"
++#include "tabprotection.hxx"
+ 
 +#include <memory>
 +
-+class ScDocument;
-+class ScTableProtectionImpl;
++using ::com::sun::star::uno::Sequence;
++using ::std::auto_ptr;
 +
-+enum ScPasswordHash
-+{
-+    PASSHASH_OOO = 0,
-+    PASSHASH_XL
-+};
+ // Shared string table ========================================================
+ 
+ XclImpSst::XclImpSst( const XclImpRoot& rRoot ) :
+@@ -1091,11 +1098,182 @@
+     };
+     // set decrypter at import stream
+     rStrm.SetDecrypter( xDecr );
+-    // remember encryption for export
+-    rStrm.GetRoot().GetExtDocOptions().GetDocSettings().mbEncrypted = true;
+ 
++    // Store the document password for export.
++    SfxItemSet* pSet = rStrm.GetRoot().GetDocShell()->GetMedium()->GetItemSet();
++    if (pSet)
++    {
++        String aPass = xDecr->GetPassword();
++        pSet->Put( SfxStringItem(SID_PASSWORD, aPass) );
++    }
 +
-+class ScPassHashHelper
-+{
-+public:
-+    /** Check for the compatibility of all password hashes.  If there is at
-+        least one hash that needs to be regenerated, it returns true.  If all
-+        hash values are compatible with the specified hash type, then it
-+        returns false. */
-+    static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash);
+     return xDecr.is() ? xDecr->GetError() : EXC_ENCR_ERROR_UNSUPP_CRYPT;
+ }
+ 
++// Document protection ========================================================
 +
-+private:
-+    ScPassHashHelper();
-+    ~ScPassHashHelper();
-+};
++XclImpDocProtectBuffer::XclImpDocProtectBuffer( const XclImpRoot& rRoot ) :
++    XclImpRoot( rRoot ),
++    mnPassHash(0x0000),
++    mbDocProtect(false),
++    mbWinProtect(false)
++{
++}
 +
-+// ============================================================================
++void XclImpDocProtectBuffer::ReadDocProtect( XclImpStream& rStrm )
++{
++    mbDocProtect = rStrm.ReaduInt16() ? true : false;
++}
 +
-+class SAL_NO_VTABLE ScPassHashProtectable
++void XclImpDocProtectBuffer::ReadWinProtect( XclImpStream& rStrm )
 +{
-+public:
-+    virtual ~ScPassHashProtectable() = 0;
++    mbWinProtect = rStrm.ReaduInt16() ? true : false;
++}
 +
-+    virtual bool isProtected() const = 0;
-+    virtual bool isProtectedWithPass() const = 0;
-+    virtual void setProtected(bool bProtected) = 0;
++void XclImpDocProtectBuffer::ReadPasswordHash( XclImpStream& rStrm )
++{
++    rStrm.EnableDecryption();
++    mnPassHash = rStrm.ReaduInt16();
++}
 +
-+    virtual bool isPasswordEmpty() const = 0;
-+    virtual bool hasPasswordHash(ScPasswordHash eHash) const = 0;
-+    virtual void setPassword(const String& aPassText) = 0;
-+    virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const = 0;
-+    virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 
-+                                 ScPasswordHash eHash = PASSHASH_OOO) = 0;
-+    virtual bool verifyPassword(const String& aPassText) const = 0;
-+};
++void XclImpDocProtectBuffer::Apply() const
++{
++    if (!mbDocProtect && !mbWinProtect)
++        // Excel requires either the structure or windows protection is set.
++        // If neither is set then the document is not protected at all.
++        return;
 +
-+// ============================================================================
++    auto_ptr<ScDocProtection> pProtect(new ScDocProtection);
++    pProtect->setProtected(true);
 +
-+class ScDocProtection : public ScPassHashProtectable
-+{
-+public:
-+    enum Option
++    if (mnPassHash)
 +    {
-+        STRUCTURE = 0,
-+        WINDOWS,
-+        CONTENT,
-+        NONE        // last item - used to resize the vector
-+    };
++        // 16-bit password pash.
++        Sequence<sal_Int8> aPass(2);
++        aPass[0] = (mnPassHash >> 8) & 0xFF;
++        aPass[1] = mnPassHash & 0xFF;
++        pProtect->setPasswordHash(aPass, PASSHASH_XL);
++    }
 +
-+    explicit ScDocProtection();
-+    explicit ScDocProtection(const ScDocProtection& r);
-+    virtual ~ScDocProtection();
++    // document protection options
++    pProtect->setOption(ScDocProtection::STRUCTURE, mbDocProtect);
++    pProtect->setOption(ScDocProtection::WINDOWS,   mbWinProtect);
 +
-+    virtual bool isProtected() const;
-+    virtual bool isProtectedWithPass() const;
-+    virtual void setProtected(bool bProtected);
-+            
-+    virtual bool isPasswordEmpty() const;
-+    virtual bool hasPasswordHash(ScPasswordHash eHash) const;
-+    virtual void setPassword(const String& aPassText);
-+    virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
-+    virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 
-+                                 ScPasswordHash eHash = PASSHASH_OOO);
-+    virtual bool verifyPassword(const String& aPassText) const;
-+    
-+    bool isOptionEnabled(Option eOption) const;
-+    void setOption(Option eOption, bool bEnabled);
++    GetDoc().SetDocProtection(pProtect.get());
++}
 +
-+private:
-+    ::std::auto_ptr<ScTableProtectionImpl> mpImpl;
-+};
++// Sheet Protection ===========================================================
 +
-+// ============================================================================
++XclImpSheetProtectBuffer::Sheet::Sheet() :
++    mbProtected(false),
++    mnPasswordHash(0x0000),
++    mnOptions(0x4400)
++{
++}
 +
-+/** sheet protection state container
-+    
-+    This class stores sheet's protection state: 1) whether the protection
-+    is on, 2) password and/or password hash, and 3) any associated
-+    protection options.  This class is also used as a protection state
-+    container for the undo/redo stack, in which case the password, hash and
-+    the options need to be preserved even when the protection flag is
-+    off. */
-+class ScTableProtection : public ScPassHashProtectable
++// ----------------------------------------------------------------------------
++
++XclImpSheetProtectBuffer::Sheet::Sheet(const Sheet& r) :
++    mbProtected(r.mbProtected),
++    mnPasswordHash(r.mnPasswordHash),
++    mnOptions(r.mnOptions)
 +{
-+public:
-+    enum Option
++}
++
++XclImpSheetProtectBuffer::XclImpSheetProtectBuffer( const XclImpRoot& rRoot ) :
++    XclImpRoot( rRoot )
++{
++}
++
++void XclImpSheetProtectBuffer::ReadProtect( XclImpStream& rStrm, SCTAB nTab )
++{
++    if ( rStrm.ReaduInt16() )
 +    {
-+        AUTOFILTER = 0,
-+        DELETE_COLUMNS,
-+        DELETE_ROWS,
-+        FORMAT_CELLS,
-+        FORMAT_COLUMNS,
-+        FORMAT_ROWS,
-+        INSERT_COLUMNS,
-+        INSERT_HYPERLINKS,
-+        INSERT_ROWS,
-+        OBJECTS,
-+        PIVOT_TABLES,
-+        SCENARIOS,
-+        SELECT_LOCKED_CELLS,
-+        SELECT_UNLOCKED_CELLS,
-+        SHEET,
-+        SORT,
-+        NONE        // last item - used to resize the vector
-+    };
++        Sheet* pSheet = GetSheetItem(nTab);
++        if (pSheet)
++            pSheet->mbProtected = true;
++    }
++}
 +
-+    explicit ScTableProtection();
-+    explicit ScTableProtection(const ScTableProtection& r);
-+    virtual ~ScTableProtection();
++void XclImpSheetProtectBuffer::ReadOptions( XclImpStream& rStrm, SCTAB nTab )
++{
++    rStrm.Ignore(19);
++    sal_uInt16 nOptions;
++    rStrm >> nOptions;
 +
-+    virtual bool isProtected() const;
-+    virtual bool isProtectedWithPass() const;
-+    virtual void setProtected(bool bProtected);
-+            
-+    virtual bool isPasswordEmpty() const;
-+    virtual bool hasPasswordHash(ScPasswordHash eHash) const;
-+    virtual void setPassword(const String& aPassText);
-+    virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
-+    virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 
-+                                 ScPasswordHash eHash = PASSHASH_OOO);
-+    virtual bool verifyPassword(const String& aPassText) const;
-+    
-+    SC_DLLPUBLIC bool isOptionEnabled(Option eOption) const;
-+    SC_DLLPUBLIC void setOption(Option eOption, bool bEnabled);
++    Sheet* pSheet = GetSheetItem(nTab);
++    if (pSheet)
++        pSheet->mnOptions = nOptions;
++}
 +
-+private:
-+    ::std::auto_ptr<ScTableProtectionImpl> mpImpl;
-+};
++void XclImpSheetProtectBuffer::ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab )
++{
++    sal_uInt16 nHash;
++    rStrm >> nHash;
++    Sheet* pSheet = GetSheetItem(nTab);
++    if (pSheet)
++        pSheet->mnPasswordHash = nHash;
++}
 +
++void XclImpSheetProtectBuffer::Apply() const
++{
++    for (ProtectedSheetMap::const_iterator itr = maProtectedSheets.begin(), itrEnd = maProtectedSheets.end();
++         itr != itrEnd; ++itr)
++    {
++        if (!itr->second.mbProtected)
++            // This sheet is (for whatever reason) not protected.
++            continue;
 +
-+#endif
-Index: sc/inc/warnpassword.hxx
-===================================================================
-RCS file: /cvs/sc/sc/inc/warnpassword.hxx,v
-retrieving revision 1.4
-retrieving revision 1.4.30.1
-diff -u -I $Revision.*$ -I $Author.*$ -r1.4 -r1.4.30.1
---- sc/inc/warnpassword.hxx	10 Apr 2008 19:02:48 -0000	1.4
-+++ sc/inc/warnpassword.hxx	22 May 2008 21:47:09 -0000	1.4.30.1
-@@ -31,7 +31,7 @@
- #ifndef SC_WARNPASSWORD_HXX
- #define SC_WARNPASSWORD_HXX
- 
--
-+#if 0
- 
- class SfxMedium; 
- /** Static API helper functions. */
-@@ -46,6 +46,7 @@
-     static bool        WarningOnPassword( SfxMedium& rMedium );
- };
- 
-+#endif
- 
- #endif
++        auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
++        pProtect->setProtected(true);
++
++        // 16-bit hash password
++        const sal_uInt16 nHash = itr->second.mnPasswordHash;
++        if (nHash)
++        {
++            Sequence<sal_Int8> aPass(2);
++            aPass[0] = (nHash >> 8) & 0xFF;
++            aPass[1] = nHash & 0xFF;
++            pProtect->setPasswordHash(aPass, PASSHASH_XL);
++        }
++
++        // sheet protection options
++        const sal_uInt16 nOptions = itr->second.mnOptions;
++        pProtect->setOption( ScTableProtection::OBJECTS,               (nOptions & 0x0001) );
++        pProtect->setOption( ScTableProtection::SCENARIOS,             (nOptions & 0x0002) );
++        pProtect->setOption( ScTableProtection::FORMAT_CELLS,          (nOptions & 0x0004) );
++        pProtect->setOption( ScTableProtection::FORMAT_COLUMNS,        (nOptions & 0x0008) );
++        pProtect->setOption( ScTableProtection::FORMAT_ROWS,           (nOptions & 0x0010) );
++        pProtect->setOption( ScTableProtection::INSERT_COLUMNS,        (nOptions & 0x0020) );
++        pProtect->setOption( ScTableProtection::INSERT_ROWS,           (nOptions & 0x0040) );
++        pProtect->setOption( ScTableProtection::INSERT_HYPERLINKS,     (nOptions & 0x0080) );
++        pProtect->setOption( ScTableProtection::DELETE_COLUMNS,        (nOptions & 0x0100) );
++        pProtect->setOption( ScTableProtection::DELETE_ROWS,           (nOptions & 0x0200) );
++        pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS,   (nOptions & 0x0400) );
++        pProtect->setOption( ScTableProtection::SORT,                  (nOptions & 0x0800) );
++        pProtect->setOption( ScTableProtection::AUTOFILTER,            (nOptions & 0x1000) );
++        pProtect->setOption( ScTableProtection::PIVOT_TABLES,          (nOptions & 0x2000) );
++        pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, (nOptions & 0x4000) );
++
++        // all done.  now commit.
++        GetDoc().SetTabProtection(itr->first, pProtect.get());
++    }
++}
++
++XclImpSheetProtectBuffer::Sheet* XclImpSheetProtectBuffer::GetSheetItem( SCTAB nTab )
++{
++    ProtectedSheetMap::iterator itr = maProtectedSheets.find(nTab);
++    if (itr == maProtectedSheets.end())
++    {
++        // new sheet
++        if ( !maProtectedSheets.insert( ProtectedSheetMap::value_type(nTab, Sheet()) ).second )
++            return NULL;
++
++        itr = maProtectedSheets.find(nTab);
++    }
++
++    return &itr->second;
++}
++
+ // ============================================================================
  
-Index: sc/source/core/data/documen2.cxx
+Index: source/filter/excel/excimp8.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/core/data/documen2.cxx,v
-retrieving revision 1.75
-retrieving revision 1.71.28.7
-diff -u -I $Revision.*$ -I $Author.*$ -r1.75 -r1.71.28.7
---- sc/source/core/data/documen2.cxx	22 Jul 2008 14:43:18 -0000	1.75
-+++ sc/source/core/data/documen2.cxx	14 Aug 2008 17:04:31 -0000	1.71.28.7
-@@ -93,6 +93,7 @@
- #include "listenercalls.hxx"
- #include "recursionhelper.hxx"
- #include "lookupcache.hxx"
-+#include "tabprotection.hxx"
+--- sc/source/filter/excel/excimp8.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/excimp8.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -160,12 +160,6 @@
+ }
  
- // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
- // dtor plus helpers are convenient.
-@@ -150,6 +151,7 @@
- 		pChangeViewSettings( NULL ),
- 		pScriptTypeData( NULL ),
-         pCacheFieldEditEngine( NULL ),
-+        pDocProtection( NULL ),
- 		pViewOptions( NULL ),
- 		pDocOptions( NULL ),
- 		pExtDocOptions( NULL ),
-@@ -173,7 +175,6 @@
- 		nHardRecalcState(0),
- 		nVisibleTab( 0 ),
- 		eLinkMode(LM_UNKNOWN),
--		bProtected( FALSE ),
- 		bAutoCalc( eMode == SCDOCMODE_DOCUMENT ),
- 		bAutoCalcShellDisabled( FALSE ),
- 		bForcedFormulaPending( FALSE ),
-@@ -614,6 +615,7 @@
  
- BOOL ScDocument::Load( SvStream& rStream, ScProgress* pProgress )
+-void ImportExcel8:: WinProtection( void )
+-{
+-    if( aIn.ReaduInt16() != 0 )
+-        GetExtDocOptions().GetDocSettings().mbWinProtected = true;
+-}
+-
+ void ImportExcel8::Boundsheet( void )
  {
-+#if 0
- 	bLoadingDone = FALSE;
- 
- 	//----------------------------------------------------
-@@ -968,10 +970,13 @@
- 	bLoadingDone = TRUE;
- 
- 	return !bError;
-+#endif
-+    return false;
+ 	UINT8			nLen;
+@@ -249,6 +243,11 @@
+ 	}
  }
  
- BOOL ScDocument::Save( SvStream& rStream, ScProgress* pProgress ) const
++void ImportExcel8::SheetProtection( void )
++{
++    GetSheetProtectBuffer().ReadOptions( aIn, GetCurrScTab() );
++}
++
+ bool lcl_hasVBAEnabled()
  {
-+#if 0
- 	((ScDocument*)this)->bLoadingDone = FALSE;		// nicht zwischendrin reinpfuschen lassen
- 
- 	((ScDocument*)this)->bLostData = FALSE;			// wird beim Speichern gesetzt
-@@ -1205,6 +1210,8 @@
- 	((ScDocument*)this)->bLoadingDone = TRUE;
+ 	uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY);
+@@ -295,6 +294,8 @@
+         pExcRoot->pAutoFilterBuffer->Apply();
  
- 	return ( rStream.GetError() == SVSTREAM_OK );
-+#endif
-+    return false;
- }
- 
- void ScDocument::SetLostData()
-Index: sc/source/core/data/documen3.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/core/data/documen3.cxx,v
-retrieving revision 1.42
-retrieving revision 1.40.80.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.42 -r1.40.80.3
---- sc/source/core/data/documen3.cxx	14 May 2008 09:51:05 -0000	1.42
-+++ sc/source/core/data/documen3.cxx	23 May 2008 01:50:53 -0000	1.40.80.3
-@@ -78,6 +78,8 @@
- #include "listenercalls.hxx"
- #include "editutil.hxx"    // ScPostIt EditTextObject
- #include "postit.hxx"
-+#include "svtools/PasswordHelper.hxx"
-+#include "tabprotection.hxx"
+     GetWebQueryBuffer().Apply();    //! test if extant
++    GetSheetProtectBuffer().Apply();
++    GetDocProtectBuffer().Apply();
  
- using namespace com::sun::star;
+ 	ImportExcel::PostDocLoad();
  
-@@ -1690,28 +1692,37 @@
-         ScDrawLayer::MirrorRectRTL( rRect );        // back to real rectangle
- }
+Index: source/filter/excel/impop.cxx
+===================================================================
+--- sc/source/filter/excel/impop.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/impop.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -84,6 +84,7 @@
+ #include "xiview.hxx"
+ #include "xilink.hxx"
+ #include "xiescher.hxx"
++#include "xicontent.hxx"
  
--void ScDocument::SetDocProtection( BOOL bProtect, const uno::Sequence<sal_Int8>& rPasswd )
-+ScDocProtection* ScDocument::GetDocProtection() const
- {
--	bProtected = bProtect;
--	aProtectPass = rPasswd;
-+    return pDocProtection.get();
+ #include "excimp8.hxx"
+ #include "excform.hxx"
+@@ -418,14 +419,12 @@
  }
  
--void ScDocument::SetTabProtection( SCTAB nTab, BOOL bProtect, const uno::Sequence<sal_Int8>& rPasswd )
-+void ScDocument::SetDocProtection(bool bProtect, const String& aPassText)
- {
--	if (VALIDTAB(nTab))
--		if (pTab[nTab])
--			pTab[nTab]->SetProtection( bProtect, rPasswd );
-+    if (!pDocProtection.get())
-+        pDocProtection.reset(new ScDocProtection);
-+
-+    pDocProtection->setProtected(bProtect);
-+    pDocProtection->setPassword(aPassText);
-+}
-+
-+void ScDocument::SetDocProtection(const ScDocProtection* pProtect)
-+{
-+    if (pProtect)
-+        pDocProtection.reset(new ScDocProtection(*pProtect));
-+    else
-+        pDocProtection.reset(NULL);
- }
  
- BOOL ScDocument::IsDocProtected() const
+-BOOL ImportExcel::Password( void )
++void ImportExcel::SheetPassword( void )
  {
--	return bProtected;
-+    return pDocProtection.get() && pDocProtection->isProtected();
- }
+-	// POST: return = TRUE, wenn Password <> 0
+-	UINT16 nPasswd;
++    if (GetRoot().GetBiff() != EXC_BIFF8)
++        return;
  
- BOOL ScDocument::IsDocEditable() const
- {
-     // import into read-only document is possible
--    return !bProtected && ( bImportingXML || mbChangeReadOnlyEnabled || !pShell || !pShell->IsReadOnly() );
-+    return !IsDocProtected() && ( bImportingXML || mbChangeReadOnlyEnabled || !pShell || !pShell->IsReadOnly() );
+-	aIn >> nPasswd;
+-
+-	return nPasswd != 0x0000;
++    GetRoot().GetSheetProtectBuffer().ReadPasswordHash( aIn, GetCurrScTab() );
  }
  
- BOOL ScDocument::IsTabProtected( SCTAB nTab ) const
-@@ -1724,19 +1735,34 @@
- 	return FALSE;
- }
  
--const uno::Sequence<sal_Int8>& ScDocument::GetDocPassword() const
-+ScTableProtection* ScDocument::GetTabProtection( SCTAB nTab ) const
- {
--	return aProtectPass;
-+    if (VALIDTAB(nTab) && pTab[nTab])
-+        return pTab[nTab]->GetProtection();
-+
-+    return NULL;
+@@ -439,6 +438,15 @@
  }
  
--const uno::Sequence<sal_Int8>& ScDocument::GetTabPassword( SCTAB nTab ) const
-+void ScDocument::SetTabProtection(SCTAB nTab, bool bProtect, const String& aPassText)
- {
--	if (VALIDTAB(nTab))
--		if (pTab[nTab])
--			return pTab[nTab]->GetPassword();
-+    if (ValidTab(nTab) && pTab[nTab])
-+        pTab[nTab]->SetProtection(bProtect, aPassText);
-+}
  
--	DBG_ERROR("Falsche Tabellennummer");
--	return aProtectPass;
-+void ScDocument::SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect)
++void ImportExcel:: WinProtection( void )
 +{
-+    if (!ValidTab(nTab))
++    if (GetRoot().GetBiff() != EXC_BIFF8)
 +        return;
 +
-+    pTab[nTab]->SetProtection(pProtect);
++    GetRoot().GetDocProtectBuffer().ReadWinProtect( aIn );
 +}
 +
-+void ScDocument::CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest)
-+{
-+    if (!ValidTab(nTabSrc) || !ValidTab(nTabDest))
-+        return;
 +
-+    pTab[nTabDest]->SetProtection( pTab[nTabSrc]->GetProtection() );
+ void ImportExcel::Columndefault( void )
+ {// Default Cell Attributes
+ 	UINT16	nColMic, nColMac;
+@@ -570,27 +578,33 @@
  }
  
- const ScDocOptions& ScDocument::GetDocOptions() const
-Index: sc/source/core/data/document.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/core/data/document.cxx,v
-retrieving revision 1.90
-retrieving revision 1.86.28.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.90 -r1.86.28.3
---- sc/source/core/data/document.cxx	8 Jul 2008 07:19:49 -0000	1.90
-+++ sc/source/core/data/document.cxx	17 Jul 2008 01:00:23 -0000	1.86.28.3
-@@ -90,6 +90,7 @@
- #include "autonamecache.hxx"
- #include "bcaslot.hxx"
- #include "postit.hxx"
-+#include "tabprotection.hxx"
  
- struct ScDefaultAttr
+-void ImportExcel::Protect( void )
++void ImportExcel::SheetProtect( void )
  {
-Index: sc/source/core/data/makefile.mk
-===================================================================
-RCS file: /cvs/sc/sc/source/core/data/makefile.mk,v
-retrieving revision 1.26
-retrieving revision 1.23.26.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.26 -r1.23.26.3
---- sc/source/core/data/makefile.mk	23 May 2008 08:35:53 -0000	1.26
-+++ sc/source/core/data/makefile.mk	7 Jun 2008 03:36:43 -0000	1.23.26.3
-@@ -108,6 +108,7 @@
- 	$(SLO)$/table4.obj \
- 	$(SLO)$/table5.obj \
- 	$(SLO)$/table6.obj \
-+	$(SLO)$/tabprotection.obj \
- 	$(SLO)$/userdat.obj \
- 	$(SLO)$/validat.obj \
- 	$(SLO)$/postit.obj
-Index: sc/source/core/data/table1.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/core/data/table1.cxx,v
-retrieving revision 1.25
-retrieving revision 1.24.28.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.25 -r1.24.28.2
---- sc/source/core/data/table1.cxx	10 Apr 2008 19:34:43 -0000	1.25
-+++ sc/source/core/data/table1.cxx	6 May 2008 23:27:26 -0000	1.24.28.2
-@@ -114,6 +114,7 @@
- #include "progress.hxx"
- #include "hints.hxx"		// fuer Paint-Broadcast
- #include "prnsave.hxx"
-+#include "tabprotection.hxx"
- 
- // STATIC DATA -----------------------------------------------------------
- 
-@@ -132,7 +133,7 @@
- 	bPageSizeValid( FALSE ),
- 	nRepeatStartX( SCCOL_REPEAT_NONE ),
- 	nRepeatStartY( SCROW_REPEAT_NONE ),
--	bProtected( FALSE ),
-+    pTabProtection( NULL ),
- 	pColWidth( NULL ),
- 	pRowHeight( NULL ),
- 	pColFlags( NULL ),
-Index: sc/source/core/data/table2.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/core/data/table2.cxx,v
-retrieving revision 1.40
-retrieving revision 1.39.78.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.40 -r1.39.78.2
---- sc/source/core/data/table2.cxx	10 Apr 2008 19:35:09 -0000	1.40
-+++ sc/source/core/data/table2.cxx	6 May 2008 23:27:37 -0000	1.39.78.2
-@@ -294,7 +294,7 @@
- 			// Zellschutz auf geschuetzter Tabelle nicht setzen
- 			//
+-    if( aIn.ReaduInt16() )
+-    {
+-        uno::Sequence<sal_Int8> aEmptyPass;
+-        GetDoc().SetTabProtection( GetCurrScTab(), TRUE, aEmptyPass );
+-    }
++    if (GetRoot().GetBiff() != EXC_BIFF8)
++        return;
++
++    GetRoot().GetSheetProtectBuffer().ReadProtect( aIn, GetCurrScTab() );
+ }
  
--		if ( bProtected && (nDelFlag & IDF_ATTRIB) )
-+		if ( IsProtected() && (nDelFlag & IDF_ATTRIB) )
- 		{
- 			ScPatternAttr aPattern(pDocument->GetPool());
- 			aPattern.GetItemSet().Put( ScProtectionAttr( FALSE ) );
-@@ -320,7 +320,7 @@
- 		// Zellschutz auf geschuetzter Tabelle nicht setzen
- 		//
+ void ImportExcel::DocProtect( void )
+ {
+-    if( aIn.ReaduInt16() )
+-    {
+-        uno::Sequence<sal_Int8> aEmptyPass;
+-        GetDoc().SetDocProtection( TRUE, aEmptyPass );
+-    }
++    if (GetRoot().GetBiff() != EXC_BIFF8)
++        return;
++
++    GetRoot().GetDocProtectBuffer().ReadDocProtect( aIn );
+ }
  
--	if ( bProtected && (nDelFlag & IDF_ATTRIB) )
-+	if ( IsProtected() && (nDelFlag & IDF_ATTRIB) )
- 	{
- 		ScDocumentPool* pPool = pDocument->GetPool();
- 		SfxItemSet aSet( *pPool, ATTR_PATTERN_START, ATTR_PATTERN_END );
-@@ -363,7 +363,7 @@
++void ImportExcel::DocPasssword( void )
++{
++    if (GetRoot().GetBiff() != EXC_BIFF8)
++        return;
  
- 		//	ggf. Formeln durch Werte ersetzen
++    GetRoot().GetDocProtectBuffer().ReadPasswordHash( aIn );
++}
++
+ void ImportExcel::Codepage( void )
+ {
++    maStrm.EnableDecryption();
+     SetCodePage( maStrm.ReaduInt16() );
+ }
  
--		if (bProtected)
-+		if ( IsProtected() )
- 			for (i = nCol1; i <= nCol2; i++)
- 				pTable->aCol[i].RemoveProtected(nRow1, nRow2);
- 	}
-@@ -408,7 +408,7 @@
- 				// Zellschutz auf geschuetzter Tabelle nicht setzen
- 				//
+Index: source/filter/excel/xestream.cxx
+===================================================================
+--- sc/source/filter/excel/xestream.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xestream.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -34,7 +34,10 @@
+ #include "xlstring.hxx"
+ #include "xeroot.hxx"
  
--			if ( bProtected && (nInsFlag & IDF_ATTRIB) )
-+			if ( IsProtected() && (nInsFlag & IDF_ATTRIB) )
- 			{
- 				ScPatternAttr aPattern(pDocument->GetPool());
- 				aPattern.GetItemSet().Put( ScProtectionAttr( FALSE ) );
-@@ -1438,7 +1438,7 @@
- 	BOOL bIsEditable = TRUE;
- 	if ( nLockCount )
- 		bIsEditable = FALSE;
--    else if ( bProtected && !pDocument->IsScenario(nTab) )
-+    else if ( IsProtected() && !pDocument->IsScenario(nTab) )
-     {
-         if((bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, HASATTR_PROTECTED )) != FALSE)
-         {
-@@ -1505,7 +1505,7 @@
- 	BOOL bIsEditable = TRUE;
- 	if ( nLockCount )
- 		bIsEditable = FALSE;
--    else if ( bProtected && !pDocument->IsScenario(nTab))
-+    else if ( IsProtected() && !pDocument->IsScenario(nTab) )
-     {
-         if((bIsEditable = !HasAttribSelection( rMark, HASATTR_PROTECTED )) != FALSE)
-         {
-@@ -2809,11 +2809,16 @@
- 					rStream >> bScenario;
- 					rStream.ReadByteString( aComment, rStream.GetStreamCharSet() );
- 
-+                    BOOL bProtected;
- 					rStream >> bProtected;
- 					String aPass;
- 					rStream.ReadByteString( aPass, rStream.GetStreamCharSet() );
- 					if (aPass.Len())
-+                    {
-+                        ::com::sun::star::uno::Sequence<sal_Int8> aProtectPass;
- 						SvPasswordHelper::GetHashPassword(aProtectPass, aPass);
-+                        SetProtection(bProtected, aProtectPass);
-+                    }
- 
- 					BOOL bOutline;
- 					rStream >> bOutline;
-@@ -3085,6 +3090,7 @@
- 		rStream << bScenario;
- 		rStream.WriteByteString( aComment, rStream.GetStreamCharSet() );
- 
-+        BOOL bProtected = IsProtected();
- 		rStream << bProtected;
- 		String aPass;
- 		//rStream.WriteByteString( aProtectPass, rStream.GetStreamCharSet() );
-Index: sc/source/core/data/table5.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/core/data/table5.cxx,v
-retrieving revision 1.14
-retrieving revision 1.13.324.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.14 -r1.13.324.3
---- sc/source/core/data/table5.cxx	10 Apr 2008 19:36:13 -0000	1.14
-+++ sc/source/core/data/table5.cxx	8 May 2008 23:23:44 -0000	1.13.324.3
-@@ -51,8 +51,11 @@
- #include "stlpool.hxx"
- #include "stlsheet.hxx"
- #include "brdcst.hxx"
-+#include "tabprotection.hxx"
- #include "globstr.hrc"
++#define DEBUG_XL_ENCRYPTION 0
  
-+using ::com::sun::star::uno::Sequence;
++using ::std::vector;
 +
- // STATIC DATA -----------------------------------------------------------
+ // ============================================================================
  
- #define GET_SCALEVALUE(set,id) 	((const SfxUInt16Item&)(set.Get( id ))).GetValue()
-@@ -273,6 +276,42 @@
- 		bPageSizeValid = FALSE;
+ XclExpStream::XclExpStream( SvStream& rOutStrm, const XclExpRoot& rRoot, sal_uInt16 nMaxRecSize ) :
+@@ -63,16 +66,19 @@
+ void XclExpStream::StartRecord( sal_uInt16 nRecId, sal_Size nRecSize )
+ {
+     DBG_ASSERT( !mbInRec, "XclExpStream::StartRecord - another record still open" );
++    DisableEncryption();
+     mnMaxContSize = mnCurrMaxSize = mnMaxRecSize;
+     mnPredictSize = nRecSize;
+     mbInRec = true;
+     InitRecord( nRecId );
+     SetSliceSize( 0 );
++    EnableEncryption();
  }
  
-+BOOL ScTable::IsProtected() const
-+{
-+    return pTabProtection.get() && pTabProtection->isProtected();
-+}
-+
-+void ScTable::SetProtection(BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd)
-+{
-+    if (!pTabProtection.get())
-+        pTabProtection.reset(new ScTableProtection);
-+
-+    pTabProtection->setProtected( bProtect );
-+    pTabProtection->setPasswordHash(rPasswd, PASSHASH_OOO);
+ void XclExpStream::EndRecord()
+ {
+     DBG_ASSERT( mbInRec, "XclExpStream::EndRecord - no record open" );
++    DisableEncryption();
+     UpdateRecSize();
+     mrStrm.Seek( STREAM_SEEK_TO_END );
+     mbInRec = false;
+@@ -84,6 +90,86 @@
+     mnSliceSize = 0;
+ }
+ 
++XclExpStream& XclExpStream::operator<<( sal_Int8 nValue )
++{
++    PrepareWrite( 1 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, nValue);
++    else
++        mrStrm << nValue;
++    return *this;
 +}
 +
-+void ScTable::SetProtection(bool bProtect, const String& aPassText)
++XclExpStream& XclExpStream::operator<<( sal_uInt8 nValue )
 +{
-+    if (!pTabProtection.get())
-+        pTabProtection.reset(new ScTableProtection);
-+
-+    pTabProtection->setProtected( bProtect );
-+    pTabProtection->setPassword(aPassText);
++    PrepareWrite( 1 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, nValue);
++    else
++        mrStrm << nValue;
++    return *this;
 +}
 +
-+void ScTable::SetProtection(const ScTableProtection* pProtect)
++XclExpStream& XclExpStream::operator<<( sal_Int16 nValue )
 +{
-+    if (pProtect)
-+        pTabProtection.reset(new ScTableProtection(*pProtect));
++    PrepareWrite( 2 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, nValue);
 +    else
-+        pTabProtection.reset(NULL);
++        mrStrm << nValue;
++    return *this;
 +}
 +
-+ScTableProtection* ScTable::GetProtection()
++XclExpStream& XclExpStream::operator<<( sal_uInt16 nValue )
 +{
-+    return pTabProtection.get();
++    PrepareWrite( 2 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, nValue);
++    else
++        mrStrm << nValue;
++    return *this;
 +}
 +
- Size ScTable::GetPageSize() const
- {
- 	if ( bPageSizeValid )
-Index: sc/source/core/data/tabprotection.cxx
-===================================================================
-RCS file: sc/source/core/data/tabprotection.cxx
-diff -N sc/source/core/data/tabprotection.cxx
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/core/data/tabprotection.cxx	13 Aug 2008 20:55:29 -0000	1.1.4.7
-@@ -0,0 +1,463 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ *
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: tabprotection.cxx,v $
-+ * $Revision: 1.1.4.7 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+// MARKER(update_precomp.py): autogen include statement, do not remove
-+#include "precompiled_sc.hxx"
-+
-+// INCLUDE ---------------------------------------------------------------
-+
-+#include "tabprotection.hxx"
-+#include "tools/debug.hxx"
-+#include "svtools/PasswordHelper.hxx"
-+#include "document.hxx"
-+
-+#define DEBUG_TAB_PROTECTION 0
-+
-+using namespace ::com::sun::star;
-+using ::com::sun::star::uno::Sequence;
-+using ::rtl::OUString;
-+
-+// ============================================================================
-+
-+bool ScPassHashHelper::needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash)
++XclExpStream& XclExpStream::operator<<( sal_Int32 nValue )
 +{
-+    if (rDoc.IsDocProtected())
-+    {
-+        const ScDocProtection* p = rDoc.GetDocProtection();
-+        if (!p->isPasswordEmpty() && !p->hasPasswordHash(eHash))
-+            return true;
-+    }
-+
-+    SCTAB nTabCount = rDoc.GetTableCount();
-+    for (SCTAB i = 0; i < nTabCount; ++i)
-+    {
-+        const ScTableProtection* p = rDoc.GetTabProtection(i);
-+        if (!p || !p->isProtected())
-+            // Sheet not protected.  Skip it.
-+            continue;
-+
-+        if (!p->isPasswordEmpty() && !p->hasPasswordHash(eHash))
-+            return true;
-+    }
++    PrepareWrite( 4 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, nValue);
++    else
++        mrStrm << nValue;
++    return *this;
++}
 +
-+    return false;
++XclExpStream& XclExpStream::operator<<( sal_uInt32 nValue )
++{
++    PrepareWrite( 4 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, nValue);
++    else
++        mrStrm << nValue;
++    return *this;
 +}
 +
-+// ============================================================================
++XclExpStream& XclExpStream::operator<<( float fValue )
++{
++    PrepareWrite( 4 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, fValue);
++    else
++        mrStrm << fValue;
++    return *this;
++}
 +
-+ScPassHashProtectable::~ScPassHashProtectable()
++XclExpStream& XclExpStream::operator<<( double fValue )
 +{
++    PrepareWrite( 8 );
++    if (mbUseEncrypter && HasValidEncrypter())
++        mxEncrypter->Encrypt(mrStrm, fValue);
++    else
++        mrStrm << fValue;
++    return *this;
 +}
 +
-+// ============================================================================
+ sal_Size XclExpStream::Write( const void* pData, sal_Size nBytes )
+ {
+     sal_Size nRet = 0;
+@@ -98,9 +184,21 @@
+             while( bValid && (nBytesLeft > 0) )
+             {
+                 sal_Size nWriteLen = ::std::min< sal_Size >( PrepareWrite(), nBytesLeft );
+-                sal_Size nWriteRet = mrStrm.Write( pBuffer, nWriteLen );
++                sal_Size nWriteRet = nWriteLen;
++                if (mbUseEncrypter && HasValidEncrypter())
++                {
++                    DBG_ASSERT(nWriteLen > 0, "XclExpStream::Write: write length is 0!");
++                    vector<sal_uInt8> aBytes(nWriteLen);
++                    memcpy(&aBytes[0], pBuffer, nWriteLen);
++                    mxEncrypter->EncryptBytes(mrStrm, aBytes);
++                    // TODO: How do I check if all the bytes have been successfully written ?
++                }
++                else
++                {
++                    nWriteRet = mrStrm.Write( pBuffer, nWriteLen );
+                 bValid = (nWriteLen == nWriteRet);
+                 DBG_ASSERT( bValid, "XclExpStream::Write - stream write error" );
++                }
+                 pBuffer += nWriteRet;
+                 nRet += nWriteRet;
+                 nBytesLeft -= nWriteRet;
+@@ -236,6 +334,26 @@
+     Write( &rBuffer[ 0 ], rBuffer.size() );
+ }
+ 
++void XclExpStream::SetEncrypter( XclExpEncrypterRef xEncrypter )
++{
++    mxEncrypter = xEncrypter;
++}
 +
-+static sal_uInt16 lcl_getXLHashFromChar(const sal_Char* szPassword)
++bool XclExpStream::HasValidEncrypter() const
 +{
-+    sal_uInt16 cchPassword = strlen(szPassword);
-+    sal_uInt16 wPasswordHash = 0;
-+    if (!cchPassword)
-+        return wPasswordHash;
++    return mxEncrypter.is() && mxEncrypter->IsValid();
++}
 +
-+    const char* pch = &szPassword[cchPassword];
-+    while (pch-- != szPassword)
-+    {
-+        wPasswordHash = ((wPasswordHash >> 14) & 0x01) | 
-+                        ((wPasswordHash << 1) & 0x7fff);
-+        wPasswordHash ^= *pch;
-+    }
++void XclExpStream::EnableEncryption( bool bEnable )
++{
++    mbUseEncrypter = bEnable && HasValidEncrypter();
++}
 +
-+    wPasswordHash = ((wPasswordHash >> 14) & 0x01) | 
-+                    ((wPasswordHash << 1) & 0x7fff);
++void XclExpStream::DisableEncryption()
++{
++    EnableEncryption(false);
++}
 +
-+    wPasswordHash ^= (0x8000 | ('N' << 8) | 'K');
-+    wPasswordHash ^= cchPassword;
+ sal_Size XclExpStream::SetSvStreamPos( sal_Size nPos )
+ {
+     DBG_ASSERT( !mbInRec, "XclExpStream::SetSvStreamPos - not allowed inside of a record" );
+@@ -327,3 +445,187 @@
+ 
+ // ============================================================================
+ 
++XclExpBiff8Encrypter::XclExpBiff8Encrypter( const XclExpRoot& rRoot, const sal_uInt8 nDocId[16],
++                                            const sal_uInt8 nSalt[16] ) :
++    mrRoot(rRoot),
++    mnOldPos(STREAM_SEEK_TO_END),
++    mbValid(false)
++{
++    String aPass = rRoot.GetPassword();
++    if (aPass.Len() == 0)
++        // Empty password.  Get the default biff8 password.
++        aPass = XclCryptoHelper::GetBiff8WbProtPassword();
++    Init(aPass, nDocId, nSalt);
++}
 +
-+    return wPasswordHash;
++XclExpBiff8Encrypter::~XclExpBiff8Encrypter()
++{
 +}
 +
-+static Sequence<sal_Int8> lcl_getXLHash(const String& aPassText)
++bool XclExpBiff8Encrypter::IsValid() const
 +{
-+    const sal_Char* szBuf = OUStringToOString(OUString(aPassText), RTL_TEXTENCODING_UTF8).getStr();
-+    sal_uInt16 nHash = lcl_getXLHashFromChar(szBuf);
-+    Sequence<sal_Int8> aHash(2);
-+    aHash[0] = (nHash >> 8) & 0xFF;
-+    aHash[1] = nHash & 0xFF;
-+    return aHash;
++    return mbValid;
 +}
 +
-+class ScTableProtectionImpl
++void XclExpBiff8Encrypter::GetSaltDigest( sal_uInt8 nSaltDigest[16] ) const
 +{
-+public:
-+    static ::com::sun::star::uno::Sequence<sal_Int8> hashPassword(const String& aPassText, ScPasswordHash eHash = PASSHASH_OOO);
-+
-+    explicit ScTableProtectionImpl(SCSIZE nOptSize);
-+    explicit ScTableProtectionImpl(const ScTableProtectionImpl& r);
-+
-+    bool isProtected() const;
-+    bool isProtectedWithPass() const;
-+    void setProtected(bool bProtected);
-+
-+    bool isPasswordEmpty() const;
-+    bool hasPasswordHash(ScPasswordHash eHash) const;
-+    void setPassword(const String& aPassText);
-+    ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
-+    void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash = PASSHASH_OOO);
-+    bool verifyPassword(const String& aPassText) const;
-+    
-+    bool isOptionEnabled(SCSIZE nOptId) const;
-+    void setOption(SCSIZE nOptId, bool bEnabled);
-+
-+private:
-+    String maPassText;
-+    ::com::sun::star::uno::Sequence<sal_Int8>   maPassHash;
-+    ::std::vector<bool> maOptions;
-+    bool mbEmptyPass;
-+    bool mbProtected;
-+    ScPasswordHash meHash;
-+};
++    memcpy(nSaltDigest, mnSaltDigest, 16);
++}
 +
-+Sequence<sal_Int8> ScTableProtectionImpl::hashPassword(const String& aPassText, ScPasswordHash eHash)
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt8 nData )
 +{
-+    Sequence<sal_Int8> aHash;
-+    switch (eHash)
-+    {
-+        case PASSHASH_XL:
-+            aHash = lcl_getXLHash(aPassText);
-+        break;
-+        case PASSHASH_OOO:
-+        default:            
-+            SvPasswordHelper::GetHashPassword(aHash, aPassText);
-+        break;
-+    }
-+    return aHash;
++    vector<sal_uInt8> aByte(1);
++    aByte[0] = nData;
++    EncryptBytes(rStrm, aByte);
 +}
 +
-+ScTableProtectionImpl::ScTableProtectionImpl(SCSIZE nOptSize) :
-+    maOptions(nOptSize),
-+    mbEmptyPass(true),
-+    mbProtected(false),
-+    meHash(PASSHASH_OOO)
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt16 nData )
 +{
++    ::std::vector<sal_uInt8> pnBytes(2);
++    pnBytes[0] = nData & 0xFF;
++    pnBytes[1] = (nData >> 8) & 0xFF;
++    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+ScTableProtectionImpl::ScTableProtectionImpl(const ScTableProtectionImpl& r) :
-+    maPassText(r.maPassText),
-+    maPassHash(r.maPassHash),
-+    maOptions(r.maOptions),
-+    mbEmptyPass(r.mbEmptyPass),
-+    mbProtected(r.mbProtected),
-+    meHash(r.meHash)
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt32 nData )
 +{
++    ::std::vector<sal_uInt8> pnBytes(4);
++    pnBytes[0] = nData & 0xFF;
++    pnBytes[1] = (nData >>  8) & 0xFF;
++    pnBytes[2] = (nData >> 16) & 0xFF;
++    pnBytes[3] = (nData >> 24) & 0xFF;
++    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+bool ScTableProtectionImpl::isProtected() const
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, float fValue )
 +{
-+    return mbProtected;
++    ::std::vector<sal_uInt8> pnBytes(4);
++    memcpy(&pnBytes[0], &fValue, 4);
++    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+bool ScTableProtectionImpl::isProtectedWithPass() const
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, double fValue )
 +{
-+    if (!mbProtected)
-+        return false;
-+
-+    return maPassText.Len() || maPassHash.getLength();
++    ::std::vector<sal_uInt8> pnBytes(8);
++    memcpy(&pnBytes[0], &fValue, 8);
++    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+void ScTableProtectionImpl::setProtected(bool bProtected)
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int8 nData )
 +{
-+    mbProtected = bProtected;
-+    // We need to keep the old password even when the protection is off.  So, 
-+    // don't erase the password data here.
++    Encrypt(rStrm, static_cast<sal_uInt8>(nData));
 +}
 +
-+void ScTableProtectionImpl::setPassword(const String& aPassText)
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int16 nData )
 +{
-+    // We can't hash it here because we don't know whether this document will
-+    // get saved to Excel or ODF, depending on which we will need to use a
-+    // different hashing algorithm.  One alternative is to hash it using all
-+    // hash algorithms that we support, and store them all.
-+
-+    maPassText = aPassText;
-+    mbEmptyPass = aPassText.Len() == 0;
-+    if (mbEmptyPass)
-+    {
-+        maPassHash = Sequence<sal_Int8>();
-+    }
++    Encrypt(rStrm, static_cast<sal_uInt16>(nData));
 +}
 +
-+bool ScTableProtectionImpl::isPasswordEmpty() const
++void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int32 nData )
 +{
-+    return mbEmptyPass;
++    Encrypt(rStrm, static_cast<sal_uInt32>(nData));
 +}
 +
-+bool ScTableProtectionImpl::hasPasswordHash(ScPasswordHash eHash) const
++void XclExpBiff8Encrypter::Init( const String& aPass, const sal_uInt8 nDocId[16],
++                                 const sal_uInt8 nSalt[16] )
 +{
-+    if (mbEmptyPass)
-+        return true;
-+
-+    if (maPassText.Len())
-+        return true;
++    memset(mnSaltDigest, 0, sizeof(mnSaltDigest));
 +
-+    if (meHash == eHash)
-+        return true;
++    xub_StrLen nLen = aPass.Len();
++    bool bValid = (0 < nLen) && (nLen < 16);
++    if ( bValid )
++    {
++        // transform String to sal_uInt16 array
++        memset(mnPassw, 0, sizeof(mnPassw));
++        for (xub_StrLen nChar = 0; nChar < nLen; ++nChar)
++            mnPassw[nChar] = static_cast<sal_uInt16>(aPass.GetChar(nChar));
 +
-+    return false;
-+}
++        // copy document ID
++        memcpy(mnDocId, nDocId, sizeof(mnDocId));
 +
-+Sequence<sal_Int8> ScTableProtectionImpl::getPasswordHash(ScPasswordHash eHash) const
-+{
-+    if (mbEmptyPass)
-+        // Flaged as empty.
-+        return Sequence<sal_Int8>();
++        // init codec
++        maCodec.InitKey(mnPassw, mnDocId);
 +
-+    if (maPassText.Len())
-+        // Cleartext password exists.  Hash it.
-+        return hashPassword(maPassText, eHash);
++        // generate salt hash.
++        ::svx::MSCodec_Std97 aCodec;
++        aCodec.InitKey(mnPassw, mnDocId);
++        aCodec.CreateSaltDigest(nSalt, mnSaltDigest);
 +
-+    if (meHash == eHash)
-+        // Stored hash exists.
-+        return maPassHash;
++        // verify to make sure it's in good shape.
++        bValid = maCodec.VerifyKey(nSalt, mnSaltDigest);
++    }
 +
-+    // Failed to find a matching hash.
-+    return Sequence<sal_Int8>();
++    mbValid = bValid;
 +}
 +
-+void ScTableProtectionImpl::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
++sal_uInt32 XclExpBiff8Encrypter::GetBlockPos( sal_Size nStrmPos ) const
 +{
-+    sal_Int32 nLen = aPassword.getLength();
-+    mbEmptyPass = nLen <= 0 ? true : false;
-+    meHash = eHash;
-+    maPassHash = aPassword;
-+
-+#if DEBUG_TAB_PROTECTION
-+    for (sal_Int32 i = 0; i < nLen; ++i)
-+        printf("%2.2X ", static_cast<sal_uInt8>(aPassword[i]));
-+    printf("\n");
-+#endif
++    return static_cast<sal_uInt32>(nStrmPos / EXC_ENCR_BLOCKSIZE);
 +}
 +
-+bool ScTableProtectionImpl::verifyPassword(const String& aPassText) const
++sal_uInt16 XclExpBiff8Encrypter::GetOffsetInBlock( sal_Size nStrmPos ) const
 +{
-+#if DEBUG_TAB_PROTECTION    
-+    fprintf(stdout, "ScTableProtectionImpl::verifyPassword: input = '%s'\n",
-+            OUStringToOString(rtl::OUString(aPassText), RTL_TEXTENCODING_UTF8).getStr());
-+#endif    
++    return static_cast<sal_uInt16>(nStrmPos % EXC_ENCR_BLOCKSIZE);
++}
 +
-+    if (mbEmptyPass)
-+        return aPassText.Len() == 0;
++void XclExpBiff8Encrypter::EncryptBytes( SvStream& rStrm, vector<sal_uInt8>& aBytes )
++{
++    sal_Size nStrmPos = rStrm.Tell();
++    sal_uInt16 nBlockOffset = GetOffsetInBlock(nStrmPos);
++    sal_uInt16 nBlockPos = GetBlockPos(nStrmPos);
 +
-+    if (maPassText.Len())
-+        // Clear text password exists, and this one takes precedence.
-+        return aPassText.Equals(maPassText);
++#if DEBUG_XL_ENCRYPTION
++    fprintf(stdout, "XclExpBiff8Encrypter::EncryptBytes: stream pos = %ld  offset in block = %d  block pos = %ld\n",
++            nStrmPos, nBlockOffset, nBlockPos);
++#endif
 +
-+    Sequence<sal_Int8> aHash = hashPassword(aPassText, meHash);
++    sal_uInt16 nSize = aBytes.size();
++    if (nSize == 0)
++        return;
 +
-+#if DEBUG_TAB_PROTECTION    
-+    fprintf(stdout, "ScTableProtectionImpl::verifyPassword: hash = ");
-+    for (sal_Int32 i = 0; i < aHash.getLength(); ++i)
-+        printf("%2.2X ", static_cast<sal_uInt8>(aHash[i]));
-+    printf("\n");
++#if DEBUG_XL_ENCRYPTION    
++    fprintf(stdout, "RAW: ");
++    for (sal_uInt16 i = 0; i < nSize; ++i)
++        fprintf(stdout, "%2.2X ", aBytes[i]);
++    fprintf(stdout, "\n");
 +#endif    
 +
-+    return aHash == maPassHash;
-+}
-+
-+bool ScTableProtectionImpl::isOptionEnabled(SCSIZE nOptId) const
-+{
-+    if ( maOptions.size() <= static_cast<size_t>(nOptId) )
++    if (mnOldPos != nStrmPos)
 +    {
-+        DBG_ERROR("ScTableProtectionImpl::isOptionEnabled: wrong size");
-+        return false;
-+    }
++        sal_uInt16 nOldOffset = GetOffsetInBlock(mnOldPos);
++        sal_uInt16 nOldBlockPos = GetBlockPos(mnOldPos);
 +
-+    return maOptions[nOptId];
-+}
++        if ( (nBlockPos != nOldBlockPos) || (nBlockOffset < nOldOffset) )
++        {
++            maCodec.InitCipher(nBlockPos);
++            nOldOffset = 0;
++        }
 +
-+void ScTableProtectionImpl::setOption(SCSIZE nOptId, bool bEnabled)
-+{
-+    if ( maOptions.size() <= static_cast<size_t>(nOptId) )
-+    {
-+        DBG_ERROR("ScTableProtectionImpl::setOption: wrong size");
-+        return;
++        if (nBlockOffset > nOldOffset)
++            maCodec.Skip(nBlockOffset - nOldOffset);
 +    }
 +
-+    maOptions[nOptId] = bEnabled;
-+}
-+
-+// ============================================================================
++    sal_uInt16 nBytesLeft = nSize;
++    sal_uInt16 nPos = 0;
++    while (nBytesLeft > 0)
++    {
++        sal_uInt16 nBlockLeft = EXC_ENCR_BLOCKSIZE - nBlockOffset;
++        sal_uInt16 nEncBytes = ::std::min(nBlockLeft, nBytesLeft);
 +
-+ScDocProtection::ScDocProtection() :
-+    mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScDocProtection::NONE)))
-+{
-+}
++        bool bRet = maCodec.Encode(&aBytes[nPos], nEncBytes, &aBytes[nPos], nEncBytes);
++        DBG_ASSERT(bRet, "XclExpBiff8Encrypter::EncryptBytes: encryption failed!!");
 +
-+ScDocProtection::ScDocProtection(const ScDocProtection& r) :
-+    mpImpl(new ScTableProtectionImpl(*r.mpImpl.get()))
-+{
-+}
++        sal_Size nRet = rStrm.Write(&aBytes[nPos], nEncBytes);
++        DBG_ASSERT(nRet == nEncBytes, "XclExpBiff8Encrypter::EncryptBytes: fail to write to stream!!");
 +
-+ScDocProtection::~ScDocProtection()
-+{
-+}
-+
-+bool ScDocProtection::isProtected() const
-+{
-+    return mpImpl->isProtected();
-+}
-+
-+bool ScDocProtection::isProtectedWithPass() const
-+{
-+    return mpImpl->isProtectedWithPass();
-+}
-+
-+void ScDocProtection::setProtected(bool bProtected)
-+{
-+    mpImpl->setProtected(bProtected);
-+
-+    // Currently Calc doesn't support document protection options.  So, let's
-+    // assume that when the document is protected, its structure is protected.
-+    // We need to do this for Excel export.
-+    mpImpl->setOption(ScDocProtection::STRUCTURE, bProtected);
-+}
++        nStrmPos = rStrm.Tell();
++        nBlockOffset = GetOffsetInBlock(nStrmPos);
++        nBlockPos = GetBlockPos(nStrmPos);
++        if (nBlockOffset == 0)
++            maCodec.InitCipher(nBlockPos);
 +
-+bool ScDocProtection::isPasswordEmpty() const
-+{
-+    return mpImpl->isPasswordEmpty();
++        nBytesLeft -= nEncBytes;
++        nPos += nEncBytes;
++    }
++    mnOldPos = nStrmPos;
 +}
+Index: source/filter/excel/xistream.cxx
+===================================================================
+--- sc/source/filter/excel/xistream.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/xistream.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -36,6 +36,8 @@
+ #include "xlstring.hxx"
+ #include "xiroot.hxx"
+ 
++#include <vector>
 +
-+bool ScDocProtection::hasPasswordHash(ScPasswordHash eHash) const
+ // ============================================================================
+ // Decryption
+ // ============================================================================
+@@ -97,11 +99,21 @@
+     return nRet;
+ }
+ 
++const String XclImpDecrypter::GetPassword() const
 +{
-+    return mpImpl->hasPasswordHash(eHash);
++    return maPass;
 +}
 +
-+void ScDocProtection::setPassword(const String& aPassText)
+ void XclImpDecrypter::SetHasValidPassword( bool bValid )
+ {
+     mnError = bValid ? ERRCODE_NONE : EXC_ENCR_ERROR_WRONG_PASS;
+ }
+ 
++void XclImpDecrypter::SetPassword( const String& rPass )
 +{
-+    mpImpl->setPassword(aPassText);
++    maPass = rPass;
 +}
 +
-+uno::Sequence<sal_Int8> ScDocProtection::getPasswordHash(ScPasswordHash eHash) const
-+{
-+    return mpImpl->getPasswordHash(eHash);
-+}
+ // ----------------------------------------------------------------------------
+ 
+ XclImpBiff5Decrypter::XclImpBiff5Decrypter( const XclImpRoot& rRoot, sal_uInt16 nKey, sal_uInt16 nHash )
+@@ -157,6 +169,9 @@
+         // init codec
+         maCodec.InitKey( mpnPassw );
+         bValid = maCodec.VerifyKey( nKey, nHash );
 +
-+void ScDocProtection::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
-+{
-+    mpImpl->setPasswordHash(aPassword, eHash);
-+}
++        String aUniPass( rPass, RTL_TEXTENCODING_MS_1252 );
++        SetPassword( aUniPass );
+     }
+ 
+     SetHasValidPassword( bValid );
+@@ -255,6 +270,8 @@
+         // init codec
+         maCodec.InitKey( mpnPassw, mpnDocId );
+         bValid = maCodec.VerifyKey( pnSaltData, pnSaltHash );
 +
-+bool ScDocProtection::verifyPassword(const String& aPassText) const
++        SetPassword(rPass);
+     }
+ 
+     SetHasValidPassword( bValid );
+Index: source/filter/excel/excrecds.cxx
+===================================================================
+--- sc/source/filter/excel/excrecds.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/excrecds.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -99,6 +99,7 @@
+ #include "xcl97rec.hxx"
+ 
+ 
++using ::com::sun::star::uno::Sequence;
+ 
+ //--------------------------------------------------------- class ExcDummy_00 -
+ const BYTE		ExcDummy_00::pMyData[] = {
+@@ -418,7 +419,9 @@
+ void ExcBundlesheetBase::UpdateStreamPos( XclExpStream& rStrm )
+ {
+     rStrm.SetSvStreamPos( nOwnPos );
++    rStrm.DisableEncryption();
+ 	rStrm << static_cast<sal_uInt32>(nStrPos);
++    rStrm.EnableEncryption();
+ }
+ 
+ 
+@@ -494,19 +497,41 @@
+ // XclExpWindowProtection ===============================================================
+ 
+ XclExpWindowProtection::XclExpWindowProtection(bool bValue) :
+-	XclExpBoolRecord(EXC_ID_WINDOWPROTECT,bValue)
++	XclExpBoolRecord(EXC_ID_WINDOWPROTECT, bValue)
+ {
+ }
+ 
+ // XclExpDocProtection ===============================================================
+ 
+-XclExpDocProtection::XclExpDocProtection(bool bValue) :
+-	XclExpBoolRecord(EXC_ID_PROTECT,bValue)
++XclExpProtection::XclExpProtection(bool bValue) :
++	XclExpBoolRecord(EXC_ID_PROTECT, bValue)
+ {
+ }
+ 
+ // ============================================================================
+ 
++XclExpPassHash::XclExpPassHash(const Sequence<sal_Int8>& aHash) :
++    XclExpRecord(EXC_ID_PASSWORD, 2),
++    mnHash(0x0000)
 +{
-+    return mpImpl->verifyPassword(aPassText);
++    if (aHash.getLength() >= 2)
++    {
++        mnHash  = ((aHash[0] << 8) & 0xFFFF);
++        mnHash |= (aHash[1] & 0xFF);
++    }
 +}
 +
-+bool ScDocProtection::isOptionEnabled(Option eOption) const
++XclExpPassHash::~XclExpPassHash()
 +{
-+    return mpImpl->isOptionEnabled(eOption);
 +}
 +
-+void ScDocProtection::setOption(Option eOption, bool bEnabled)
++void XclExpPassHash::WriteBody(XclExpStream& rStrm)
 +{
-+    mpImpl->setOption(eOption, bEnabled);
++    rStrm << mnHash;
 +}
 +
 +// ============================================================================
 +
-+ScTableProtection::ScTableProtection() :
-+    mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScTableProtection::NONE)))
-+{
-+    // Set default values for the options.
-+    mpImpl->setOption(SELECT_LOCKED_CELLS,   true);
-+    mpImpl->setOption(SELECT_UNLOCKED_CELLS, true);
-+}
-+
-+ScTableProtection::ScTableProtection(const ScTableProtection& r) :
-+    mpImpl(new ScTableProtectionImpl(*r.mpImpl.get()))
-+{
-+}
-+
-+ScTableProtection::~ScTableProtection()
-+{
-+}
-+
-+bool ScTableProtection::isProtected() const
-+{
-+    return mpImpl->isProtected();
-+}
+ XclExpFiltermode::XclExpFiltermode() :
+     XclExpEmptyRecord( EXC_ID_FILTERMODE )
+ {
+Index: source/filter/excel/read.cxx
+===================================================================
+--- sc/source/filter/excel/read.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/excel/read.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -363,7 +363,7 @@
+                         Eof();
+ 						eAkt = Z_Ende;
+ 						break;
+-					case 0x12:  Protect(); break;       // SHEET PROTECTION
++					case 0x12:  SheetProtect(); break;       // SHEET PROTECTION
+                     case 0x14:
+                     case 0x15:  rPageSett.ReadHeaderFooter( maStrm );   break;
+ 					case 0x17:	Externsheet(); break;	// EXTERNSHEET	[ 2345]
+@@ -478,7 +478,7 @@
+                         Eof();
+                         eAkt = Z_Biff4E;
+                     break;
+-					case 0x12:  Protect(); break;       // SHEET PROTECTION
++					case 0x12:  SheetProtect(); break;       // SHEET PROTECTION
+                     case 0x14:
+                     case 0x15:  rPageSett.ReadHeaderFooter( maStrm );   break;
+                     case 0x1A:
+@@ -605,7 +605,7 @@
+                             eAkt = Z_Biff5T;
+                             aIn.SeekGlobalPosition(); // und zurueck an alte Position
+                             break;
+-                        case 0x12:  Protect(); break;       // SHEET PROTECTION
++                        case 0x12:  SheetProtect(); break;       // SHEET PROTECTION
+                         case 0x1A:
+                         case 0x1B:  rPageSett.ReadPageBreaks( maStrm );     break;
+                         case 0x1D:  rTabViewSett.ReadSelection( maStrm );   break;
+@@ -904,6 +904,7 @@
+                         }
+ 						break;
+ 					case 0x12:	DocProtect(); break;	// PROTECT		[    5678]
++                    case 0x13:  DocPasssword(); break;
+ 					case 0x19:  WinProtection(); break;
+ 					case 0x2F:							// FILEPASS		[ 2345   ]
+                         eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
+@@ -1048,7 +1049,8 @@
+                         eAkt = EXC_STATE_SHEET;
+                         aIn.SeekGlobalPosition();         // und zurueck an alte Position
+                         break;
+-                    case 0x12:  Protect(); break;
++                    case 0x12:  SheetProtect(); break;
++                    case 0x13:  SheetPassword(); break;
+                     case 0x42:  Codepage(); break;      // CODEPAGE     [ 2345   ]
+                     case 0x55:  DefColWidth(); break;
+                     case 0x7D:  Colinfo(); break;       // COLINFO      [  345   ]
+@@ -1064,6 +1066,7 @@
+                     case 0x0221: Array34(); break;      // ARRAY        [  34    ]
+                     case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[  345   ]
+                     case 0x04BC: Shrfmla(); break;      // SHRFMLA      [    5   ]
++                    case 0x0867: SheetProtection(); break; // SHEETPROTECTION
+                 }
+             }
+             break;
+Index: source/filter/xml/xmlexprt.cxx
+===================================================================
+--- sc/source/filter/xml/xmlexprt.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/xml/xmlexprt.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -67,6 +67,7 @@
+ #include "rangeutl.hxx"
+ #include "convuno.hxx"
+ #include "postit.hxx"
++#include "tabprotection.hxx"
+ 
+ #include <xmloff/xmltoken.hxx>
+ #include <xmloff/xmlnmspe.hxx>
+@@ -1399,7 +1400,11 @@
+ 	{
+ 		AddAttribute(XML_NAMESPACE_TABLE, XML_STRUCTURE_PROTECTED, XML_TRUE);
+ 		rtl::OUStringBuffer aBuffer;
+-		SvXMLUnitConverter::encodeBase64(aBuffer, pDoc->GetDocPassword());
++        uno::Sequence<sal_Int8> aPassHash;
++        const ScDocProtection* p = pDoc->GetDocProtection();
++        if (p)
++            aPassHash = p->getPasswordHash(PASSHASH_OOO);
++		SvXMLUnitConverter::encodeBase64(aBuffer, aPassHash);
+ 		if (aBuffer.getLength())
+ 			AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
+ 	}
+@@ -1417,11 +1422,13 @@
+ 		DBG_ERROR("no shared data setted");
+ 	}
+ 	ScXMLExportDatabaseRanges aExportDatabaseRanges(*this);
+-	if (GetModel().is())
+-	{
++	if (!GetModel().is())
++        return;
 +
-+bool ScTableProtection::isProtectedWithPass() const
-+{
-+    return mpImpl->isProtectedWithPass();
-+}
+ 		uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
+-		if ( xSpreadDoc.is() )
+-		{
++    if ( !xSpreadDoc.is() )
++        return;
 +
-+void ScTableProtection::setProtected(bool bProtected)
-+{
-+    mpImpl->setProtected(bProtected);
-+}
-+
-+bool ScTableProtection::isPasswordEmpty() const
-+{
-+    return mpImpl->isPasswordEmpty();
-+}
-+
-+bool ScTableProtection::hasPasswordHash(ScPasswordHash eHash) const
-+{
-+    return mpImpl->hasPasswordHash(eHash);
-+}
-+
-+void ScTableProtection::setPassword(const String& aPassText)
-+{
-+    mpImpl->setPassword(aPassText);
-+}
-+
-+Sequence<sal_Int8> ScTableProtection::getPasswordHash(ScPasswordHash eHash) const
-+{
-+    return mpImpl->getPasswordHash(eHash);
-+}
-+
-+void ScTableProtection::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
-+{
-+    mpImpl->setPasswordHash(aPassword, eHash);
-+}
-+
-+bool ScTableProtection::verifyPassword(const String& aPassText) const
-+{
-+    return mpImpl->verifyPassword(aPassText);
-+}
-+
-+bool ScTableProtection::isOptionEnabled(Option eOption) const
-+{
-+    return mpImpl->isOptionEnabled(eOption);
-+}
-+
-+void ScTableProtection::setOption(Option eOption, bool bEnabled)
-+{
-+    mpImpl->setOption(eOption, bEnabled);
-+}
-+
-Index: sc/source/filter/excel/excdoc.cxx
+ 			uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
+ 			if ( xIndex.is() )
+ 			{
+@@ -1471,7 +1478,11 @@
+ 								AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
+ 								rtl::OUStringBuffer aBuffer;
+ 								if (pDoc)
+-									SvXMLUnitConverter::encodeBase64(aBuffer, pDoc->GetTabPassword(static_cast<SCTAB>(nTable)));
++                                {
++                                    ScTableProtection* pProtect = pDoc->GetTabProtection(static_cast<SCTAB>(nTable));
++                                    if (pProtect)
++                                        SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_OOO));
++                                }
+ 								if (aBuffer.getLength())
+ 									AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
+ 							}
+@@ -1585,8 +1596,6 @@
+ 			aExportDDELinks.WriteDDELinks(xSpreadDoc);
+             IncrementProgressBar(sal_True, 0);
+ 			GetProgressBarHelper()->SetValue(GetProgressBarHelper()->GetReference());
+-		}
+-	}
+ }
+ 
+ void ScXMLExport::_ExportStyles( sal_Bool bUsed )
+Index: source/filter/xml/xmlsubti.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/excdoc.cxx,v
-retrieving revision 1.69
-retrieving revision 1.67.284.7
-diff -u -I $Revision.*$ -I $Author.*$ -r1.69 -r1.67.284.7
---- sc/source/filter/excel/excdoc.cxx	13 May 2008 12:07:58 -0000	1.69
-+++ sc/source/filter/excel/excdoc.cxx	23 May 2008 01:51:00 -0000	1.67.284.7
-@@ -73,7 +73,6 @@
- #include "excdoc.hxx"
- #include "namebuff.hxx"
+--- sc/source/filter/xml/xmlsubti.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/xml/xmlsubti.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -42,6 +42,7 @@
+ #include "docuno.hxx"
+ #include "cellsuno.hxx"
+ #include "XMLStylesImportHelper.hxx"
++#include "tabprotection.hxx"
  
--#include "xcl97dum.hxx"
- #include "xcl97rec.hxx"
- #include "xcl97esc.hxx"
- #include "xetable.hxx"
-@@ -86,6 +85,8 @@
- #include "xepivot.hxx"
- #include "XclExpChangeTrack.hxx"
+ #include <xmloff/xmltkmap.hxx>
+ #include <xmloff/nmspmap.hxx>
+@@ -58,6 +59,10 @@
+ #include <com/sun/star/util/XProtectable.hpp>
+ #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
  
-+#include "tabprotection.hxx"
++#include <memory>
 +
++using ::std::auto_ptr;
++
+ //------------------------------------------------------------------
  
- static String lcl_GetVbaTabName( SCTAB n )
- {
-@@ -151,7 +152,16 @@
- 		Add( new ExcDummy_00 );
- 	else
+ using namespace com::sun::star;
+@@ -615,13 +620,10 @@
  	{
--		Add( new ExcDummy8_00a );
-+        if ( IsDocumentEncrypted() )
-+            Add( new XclExpFilePass(GetRoot()) );
-+
-+        Add( new XclExpInterfaceHdr );
-+        Add( new XclExpMMS );
-+        Add( new XclExpInterfaceEnd );
-+        Add( new XclExpWriteAccess );
-+        Add( new XclExpCodePage );
-+        Add( new XclExpDSF );
-+        Add( new XclExpExcel9File );
- 		rR.pTabId = new XclExpChTrTabId( Max( nExcTabCount, nCodenames ) );
- 		Add( rR.pTabId );
-         if( HasVbaStorage() )
-@@ -161,7 +171,8 @@
-             if( rCodeName.Len() )
-                 Add( new XclCodename( rCodeName ) );
- 		}
--		Add( new ExcDummy8_00b );
-+
-+        Add( new XclExpFnGroupCount );
+ 		uno::Sequence<sal_Int8> aPass;
+ 		SvXMLUnitConverter::decodeBase64(aPass, sPassword);
+-		rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), bProtection, aPass);
+-		/*uno::Reference <util::XProtectable> xProtectable(xCurrentSheet, uno::UNO_QUERY);
+-		if (xProtectable.is())
+-		{
+-			rtl::OUString sKey;
+-			xProtectable->protect(sKey);
+-		}*/
++        auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
++        pProtect->setProtected(bProtection);
++        pProtect->setPasswordHash(aPass, PASSHASH_OOO);
++        rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), pProtect.get());
  	}
  
- 	// erst Namen- und Tabellen-Eintraege aufbauen
-@@ -181,15 +192,29 @@
-         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
-     }
- 
--    aRecList.AppendNewRecord( new XclExpWindowProtection( GetExtDocOptions().GetDocSettings().mbWinProtected ) );
--    aRecList.AppendNewRecord( new XclExpDocProtection( rDoc.IsDocProtected() ) );
--    aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_PASSWORD, false ) );
-+    // document protection options
-+    const ScDocProtection* pProtect = GetDoc().GetDocProtection();
-+    if (pProtect && pProtect->isProtected())
-+    {
-+        Add( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
-+        Add( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
-+        Add( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
-+    }
- 
-     if( GetBiff() == EXC_BIFF8 )
--        Add( new ExcDummy8_040 );
-+    {
-+        Add( new XclExpProt4Rev );
-+        Add( new XclExpProt4RevPass );
-+    }
+ 	rImport.UnlockSolarMutex();
+Index: source/filter/xml/xmlbodyi.cxx
+===================================================================
+--- sc/source/filter/xml/xmlbodyi.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/xml/xmlbodyi.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -52,6 +52,7 @@
+ #include "XMLTrackedChangesContext.hxx"
+ #include "XMLEmptyContext.hxx"
+ #include "scerrors.hxx"
++#include "tabprotection.hxx"
  
-     aRecList.AppendNewRecord( new XclExpWindow1( GetRoot() ) );
+ #include <xmloff/xmltkmap.hxx>
+ #include <xmloff/xmltoken.hxx>
+@@ -62,6 +63,8 @@
+ #include <sal/types.h>
+ #include <tools/debug.hxx>
  
-+    if ( GetBiff() == EXC_BIFF8 )
-+    {
-+        Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
-+        Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
-+    }
++#include <memory>
 +
-     if( GetBiff() <= EXC_BIFF5 )
-     {
- 		Add( new ExcDummy_040 );
-@@ -198,9 +223,11 @@
-     }
-     else
-     {
-+        // BIFF8
-         Add( new Exc1904( rDoc ) );
-         Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
--        Add( new ExcDummy8_041 );
-+        Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
-+        Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
-     }
- 
-     // Formatting: FONT, FORMAT, XF, STYLE, PALETTE
-@@ -259,10 +286,14 @@
-         aRecList.AppendRecord( CreateRecord( EXC_ID_EXTERNSHEET ) );
-         aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
+ using namespace com::sun::star;
+ using namespace xmloff::token;
  
-+        Add( new XclExpUnknown01C1 );
+@@ -280,10 +283,17 @@
+         // #i37959# handle document protection after the sheet settings
+ 		if (bProtected)
+ 		{
++            ::std::auto_ptr<ScDocProtection> pProtection(new ScDocProtection);
++            pProtection->setProtected(true);
 +
- 		// MSODRAWINGGROUP per-document data
- 		Add( new XclMsodrawinggroup( rR, ESCHER_DggContainer ) );
-         // Shared string table: SST, EXTSST
-         aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
+ 			uno::Sequence<sal_Int8> aPass;
+ 			if (sPassword.getLength())
++            {
+ 				SvXMLUnitConverter::decodeBase64(aPass, sPassword);
+-			pDoc->SetDocProtection(bProtected, aPass);
++                pProtection->setPasswordHash(aPass, PASSHASH_OOO);
++            }
 +
-+        Add( new XclExpUnknown0863 );
++            pDoc->SetDocProtection(pProtection.get());
+ 		}
  	}
+ 	GetScImport().UnlockSolarMutex();
+Index: source/filter/xcl97/XclExpChangeTrack.cxx
+===================================================================
+--- sc/source/filter/xcl97/XclExpChangeTrack.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/xcl97/XclExpChangeTrack.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -491,6 +491,7 @@
  
- 	Add( new ExcEof );
-@@ -304,7 +335,7 @@
-         Add( new XclRefmode( rDoc ) );
-         Add( new XclIteration( rDoc ) );
-         Add( new XclDelta( rDoc ) );
--        Add( new ExcDummy8_02 );
-+        Add( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
-     }
- 
-     // GUTS (count & size of outline icons)
-@@ -321,8 +352,14 @@
-     // page settings (SETUP and various other records)
-     aRecList.AppendRecord( xPageSett );
+ void XclExpChTrTabId::SaveCont( XclExpStream& rStrm )
+ {
++    rStrm.EnableEncryption();
+ 	if( pBuffer )
+ 		for( sal_uInt16* pElem = pBuffer; pElem < (pBuffer + nTabCount); pElem++ )
+ 			rStrm << *pElem;
+Index: source/filter/xcl97/xcl97rec.cxx
+===================================================================
+--- sc/source/filter/xcl97/xcl97rec.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/xcl97/xcl97rec.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -78,6 +78,7 @@
+ #include "scextopt.hxx"
+ #include "docoptio.hxx"
+ #include "patattr.hxx"
++#include "tabprotection.hxx"
  
--    if( rDoc.IsTabProtected( mnScTab ) )
--		Add( new XclProtection() );
-+    const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
-+    if (pTabProtect && pTabProtect->isProtected())
-+    {
-+        Add( new XclExpProtection(true) );
-+        Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
-+        Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
-+        Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
-+    }
+ using ::rtl::OUString;
+ using namespace ::com::sun::star;
+@@ -132,9 +133,9 @@
  
-     // local link table: EXTERNCOUNT, EXTERNSHEET
-     if( eBiff <= EXC_BIFF5 )
-@@ -368,6 +405,9 @@
+ // --- class XclMsodrawinggroup --------------------------------------
  
-     if( eBiff == EXC_BIFF8 )
- 	{
-+        // sheet protection options
-+        Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
-+
- 		// web queries
-         Add( new XclExpWebQueryBuffer( GetRoot() ) );
+-XclMsodrawinggroup::XclMsodrawinggroup( RootData& rRoot, UINT16 nEscherType )
+-		:
+-		XclMsodrawing_Base( *rRoot.pEscher )
++XclMsodrawinggroup::XclMsodrawinggroup( RootData& rRoot, UINT16 nEscherType ) :
++    XclMsodrawing_Base( *rRoot.pEscher ),
++    XclExpRecord(0x00EB, 2) // bogus record size since we don't know the actual size yet.
+ {
+ 	if ( nEscherType )
+ 	{
+@@ -179,7 +180,7 @@
+ }
  
-Index: sc/source/filter/excel/excimp8.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/excimp8.cxx,v
-retrieving revision 1.127
-retrieving revision 1.123.38.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.127 -r1.123.38.5
---- sc/source/filter/excel/excimp8.cxx	8 Jul 2008 07:21:58 -0000	1.127
-+++ sc/source/filter/excel/excimp8.cxx	17 Jul 2008 01:00:43 -0000	1.123.38.5
-@@ -161,12 +161,6 @@
+ 
+-void XclMsodrawinggroup::SaveCont( XclExpStream& rStrm )
++void XclMsodrawinggroup::WriteBody( XclExpStream& rStrm )
+ {
+     DBG_ASSERT( GetEscherEx()->GetStreamPos() == GetEscherEx()->GetOffsetFromMap( nStartPos ),
+ 		"XclMsodrawinggroup::SaveCont: Escher stream position mismatch" );
+@@ -187,23 +188,11 @@
  }
  
  
--void ImportExcel8:: WinProtection( void )
+-UINT16 XclMsodrawinggroup::GetNum() const
 -{
--    if( aIn.ReaduInt16() != 0 )
--        GetExtDocOptions().GetDocSettings().mbWinProtected = true;
+-	return 0x00EB;
+-}
+-
+-
+-sal_Size XclMsodrawinggroup::GetLen() const
+-{
+-    return GetDataLen();
 -}
 -
- void ImportExcel8::Note( void )
+-
+-
+ // --- class XclMsodrawing --------------------------------------
+ 
+ XclMsodrawing::XclMsodrawing( const XclExpRoot& rRoot, UINT16 nEscherType, sal_Size nInitialSize ) :
+-    XclMsodrawing_Base( *rRoot.GetOldRoot().pEscher, nInitialSize )
++    XclMsodrawing_Base( *rRoot.GetOldRoot().pEscher, nInitialSize ),
++    XclExpRecord( 0x00EC, nInitialSize )
  {
-     GetObjectManager().ReadNote( maStrm );
-@@ -256,6 +250,11 @@
- 	}
+ 	if ( nEscherType )
+ 	{
+@@ -229,7 +218,7 @@
  }
  
-+void ImportExcel8::SheetProtection( void )
-+{
-+    GetSheetProtectBuffer().ReadOptions( aIn, GetCurrScTab() );
-+}
-+
- bool lcl_hasVBAEnabled()
+ 
+-void XclMsodrawing::SaveCont( XclExpStream& rStrm )
++void XclMsodrawing::WriteBody( XclExpStream& rStrm )
  {
- 	uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY);
-@@ -302,6 +301,8 @@
-         pExcRoot->pAutoFilterBuffer->Apply();
+     DBG_ASSERT( GetEscherEx()->GetStreamPos() == GetEscherEx()->GetOffsetFromMap( nStartPos ),
+ 		"XclMsodrawing::SaveCont: Escher stream position mismatch" );
+@@ -237,18 +226,8 @@
+ }
  
-     GetWebQueryBuffer().Apply();    //! test if extant
-+    GetSheetProtectBuffer().Apply();
-+    GetDocProtectBuffer().Apply();
  
- 	ImportExcel::PostDocLoad();
+-UINT16 XclMsodrawing::GetNum() const
+-{
+-	return 0x00EC;
+-}
  
-Index: sc/source/filter/excel/excrecds.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/excrecds.cxx,v
-retrieving revision 1.88
-retrieving revision 1.87.286.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.88 -r1.87.286.4
---- sc/source/filter/excel/excrecds.cxx	10 Apr 2008 20:06:49 -0000	1.88
-+++ sc/source/filter/excel/excrecds.cxx	22 May 2008 23:33:21 -0000	1.87.286.4
-@@ -99,6 +99,7 @@
- #include "xcl97rec.hxx"
  
+-sal_Size XclMsodrawing::GetLen() const
+-{
+-    return GetDataLen();
+-}
+-
+-
+ // --- class XclObjList ----------------------------------------------
  
-+using ::com::sun::star::uno::Sequence;
+ XclObjList::XclObjList( const XclExpRoot& rRoot ) :
+@@ -883,6 +862,7 @@
  
- //--------------------------------------------------------- class ExcDummy_00 -
- const BYTE		ExcDummy_00::pMyData[] = {
-@@ -418,7 +419,9 @@
- void ExcBundlesheetBase::UpdateStreamPos( XclExpStream& rStrm )
+ void ExcBof8_Base::SaveCont( XclExpStream& rStrm )
  {
-     rStrm.SetSvStreamPos( nOwnPos );
 +    rStrm.DisableEncryption();
- 	rStrm << static_cast<sal_uInt32>(nStrPos);
+ 	rStrm	<< nVers << nDocType << nRupBuild << nRupYear
+ 			<< nFileHistory << nLowestBiffVer;
+ }
+@@ -936,7 +916,10 @@
+ {
+     nOwnPos = rStrm.GetSvStreamPos();
+     // write dummy position, real position comes later
+-    rStrm << sal_uInt32( 0 ) << nGrbit << aUnicodeName;
++    rStrm.DisableEncryption();
++    rStrm << sal_uInt32(0);
 +    rStrm.EnableEncryption();
++    rStrm << nGrbit << aUnicodeName;
  }
  
  
-@@ -494,19 +497,41 @@
- // XclExpWindowProtection ===============================================================
- 
- XclExpWindowProtection::XclExpWindowProtection(bool bValue) :
--	XclExpBoolRecord(EXC_ID_WINDOWPROTECT,bValue)
-+	XclExpBoolRecord(EXC_ID_WINDOWPROTECT, bValue)
- {
+@@ -1177,33 +1160,73 @@
+ 	return 8;
  }
  
- // XclExpDocProtection ===============================================================
++// ============================================================================
  
--XclExpDocProtection::XclExpDocProtection(bool bValue) :
--	XclExpBoolRecord(EXC_ID_PROTECT,bValue)
-+XclExpProtection::XclExpProtection(bool bValue) :
-+	XclExpBoolRecord(EXC_ID_PROTECT, bValue)
+-
+-// ---- class XclProtection ------------------------------------------
+-
+-const BYTE		XclProtection::pMyData[] =
++struct XclExpTabProtectOption
  {
- }
- 
- // ============================================================================
+-	0x12, 0x00, 0x02, 0x00, 0x01, 0x00,			// PROTECT
+-	0xDD, 0x00, 0x02, 0x00, 0x01, 0x00,			// SCENPROTECT
+-	0x63, 0x00, 0x02, 0x00, 0x01, 0x00			// OBJPROTECT
++    ScTableProtection::Option   eOption;
++    sal_uInt16                  nMask;
+ };
+-const sal_Size XclProtection::nMyLen = sizeof( XclProtection::pMyData );
  
-+XclExpPassHash::XclExpPassHash(const Sequence<sal_Int8>& aHash) :
-+    XclExpRecord(EXC_ID_PASSWORD, 2),
-+    mnHash(0x0000)
-+{
-+    if (aHash.getLength() >= 2)
+-sal_Size XclProtection::GetLen( void ) const
++XclExpSheetProtectOptions::XclExpSheetProtectOptions( const XclExpRoot& rRoot, SCTAB nTab ) :
++    XclExpRecord( 0x0867, 23 )
+ {
+-	return nMyLen;
+-}
++    static const XclExpTabProtectOption aTable[] =
 +    {
-+        mnHash  = ((aHash[0] << 8) & 0xFFFF);
-+        mnHash |= (aHash[1] & 0xFF);
-+    }
-+}
-+
-+XclExpPassHash::~XclExpPassHash()
-+{
-+}
-+
-+void XclExpPassHash::WriteBody(XclExpStream& rStrm)
-+{
-+    rStrm << mnHash;
-+}
++        { ScTableProtection::OBJECTS,               0x0001 },
++        { ScTableProtection::SCENARIOS,             0x0002 },
++        { ScTableProtection::FORMAT_CELLS,          0x0004 },
++        { ScTableProtection::FORMAT_COLUMNS,        0x0008 },
++        { ScTableProtection::FORMAT_ROWS,           0x0010 },
++        { ScTableProtection::INSERT_COLUMNS,        0x0020 },
++        { ScTableProtection::INSERT_ROWS,           0x0040 },
++        { ScTableProtection::INSERT_HYPERLINKS,     0x0080 },
+ 
++        { ScTableProtection::DELETE_COLUMNS,        0x0100 },
++        { ScTableProtection::DELETE_ROWS,           0x0200 },
++        { ScTableProtection::SELECT_LOCKED_CELLS,   0x0400 },
++        { ScTableProtection::SORT,                  0x0800 },
++        { ScTableProtection::AUTOFILTER,            0x1000 },
++        { ScTableProtection::PIVOT_TABLES,          0x2000 },
++        { ScTableProtection::SELECT_UNLOCKED_CELLS, 0x4000 },
+ 
+-const BYTE* XclProtection::GetData( void ) const
+-{
+-	return pMyData;
++        { ScTableProtection::NONE,                  0x0000 }
++    };
 +
-+// ============================================================================
++    mnOptions = 0x0000;
++    ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab);
++    if (!pProtect)
++        return;
 +
- XclExpFiltermode::XclExpFiltermode() :
-     XclExpEmptyRecord( EXC_ID_FILTERMODE )
- {
-Index: sc/source/filter/excel/impop.cxx
-diff --git sc/source/filter/excel/impop.cxx sc/source/filter/excel/impop.cxx
-index ab1ca87..b532a58 100644
---- sc/source/filter/excel/impop.cxx
-+++ sc/source/filter/excel/impop.cxx
-@@ -90,6 +90,7 @@
- #include "xiview.hxx"
- #include "xilink.hxx"
- #include "xiescher.hxx"
-+#include "xicontent.hxx"
- 
- #include "excimp8.hxx"
- #include "excform.hxx"
-@@ -418,14 +419,12 @@ void ImportExcel::Eof( void )
++    for (int i = 0; aTable[i].nMask != 0x0000; ++i)
++    {
++        if ( pProtect->isOptionEnabled(aTable[i].eOption) )
++            mnOptions |= aTable[i].nMask;
++    }
  }
  
++void XclExpSheetProtectOptions::WriteBody( XclExpStream& rStrm )
++{
++    sal_uInt16 nBytes = 0x0867;
++    rStrm << nBytes;
  
--BOOL ImportExcel::Password( void )
-+void ImportExcel::SheetPassword( void )
- {
--	// POST: return = TRUE, wenn Password <> 0
--	UINT16 nPasswd;
-+    if (GetRoot().GetBiff() != EXC_BIFF8)
-+        return;
++    sal_uChar nZero = 0x00;
++    for (int i = 0; i < 9; ++i)
++        rStrm << nZero;
  
--	aIn >> nPasswd;
--
--	return nPasswd != 0x0000;
-+    GetRoot().GetSheetProtectBuffer().ReadPasswordHash( aIn, GetCurrScTab() );
- }
++    nBytes = 0x0200;
++    rStrm << nBytes;
++    nBytes = 0x0100;
++    rStrm << nBytes;
++    nBytes = 0xFFFF;
++    rStrm << nBytes << nBytes;
  
++    rStrm << mnOptions;
++    nBytes = 0;
++    rStrm << nBytes;
++}
  
-@@ -439,6 +438,15 @@ void ImportExcel::Externsheet( void )
- }
++// ============================================================================
  
  
-+void ImportExcel:: WinProtection( void )
+ 
+@@ -1291,3 +1314,250 @@
+     XclExpBoolRecord( 0x000F, rDoc.GetAddressConvention() != ScAddress::CONV_XL_R1C1 )
+ {
+ }
++
++// ============================================================================
++
++XclExpFilePass::XclExpFilePass( const XclExpRoot& rRoot ) :
++    XclExpRecord(0x002F, 54),
++    mrRoot(rRoot)
 +{
-+    if (GetRoot().GetBiff() != EXC_BIFF8)
-+        return;
++}
 +
-+    GetRoot().GetDocProtectBuffer().ReadWinProtect( aIn );
++XclExpFilePass::~XclExpFilePass()
++{
 +}
 +
++void XclExpFilePass::WriteBody( XclExpStream& rStrm )
++{
++    static const sal_uInt8 nDocId[] = {
++        0x17, 0xf7, 0x01, 0x08, 0xea, 0xad, 0x30, 0x5c,
++        0x1a, 0x95, 0xa5, 0x75, 0xd6, 0x79, 0xcd, 0x8d };
 +
- void ImportExcel::Note( void )
- {
-     XclAddress aXclPos;
-@@ -584,27 +592,33 @@ void ImportExcel::Defrowheight2( void )
- }
- 
- 
--void ImportExcel::Protect( void )
-+void ImportExcel::SheetProtect( void )
- {
--    if( aIn.ReaduInt16() )
--    {
--        uno::Sequence<sal_Int8> aEmptyPass;
--        GetDoc().SetTabProtection( GetCurrScTab(), TRUE, aEmptyPass );
--    }
-+    if (GetRoot().GetBiff() != EXC_BIFF8)
-+        return;
 +
-+    GetRoot().GetSheetProtectBuffer().ReadProtect( aIn, GetCurrScTab() );
- }
- 
- void ImportExcel::DocProtect( void )
- {
--    if( aIn.ReaduInt16() )
--    {
--        uno::Sequence<sal_Int8> aEmptyPass;
--        GetDoc().SetDocProtection( TRUE, aEmptyPass );
--    }
-+    if (GetRoot().GetBiff() != EXC_BIFF8)
-+        return;
++    static const sal_uInt8 nSalt[] = {    
++        0xa4, 0x5b, 0xf7, 0xe9, 0x9f, 0x55, 0x21, 0xc5, 
++        0xc5, 0x56, 0xa8, 0x0d, 0x39, 0x05, 0x3a, 0xb4 };
 +
-+    GetRoot().GetDocProtectBuffer().ReadDocProtect( aIn );
- }
- 
-+void ImportExcel::DocPasssword( void )
-+{
-+    if (GetRoot().GetBiff() != EXC_BIFF8)
-+        return;
++    // 0x0000 - neither standard nor strong encryption
++    // 0x0001 - standard or strong encryption
++    rStrm << static_cast<sal_uInt16>(0x0001);
 +
-+    GetRoot().GetDocProtectBuffer().ReadPasswordHash( aIn );
-+}
- 
- void ImportExcel::Codepage( void )
- {
-+    maStrm.EnableDecryption();
-     SetCodePage( maStrm.ReaduInt16() );
- }
- 
-Index: sc/source/filter/excel/read.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/read.cxx,v
-retrieving revision 1.70
-retrieving revision 1.69.80.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.70 -r1.69.80.2
---- sc/source/filter/excel/read.cxx	10 Apr 2008 20:09:20 -0000	1.70
-+++ sc/source/filter/excel/read.cxx	6 May 2008 23:28:32 -0000	1.69.80.2
-@@ -363,7 +363,7 @@
-                         Eof();
- 						eAkt = Z_Ende;
- 						break;
--					case 0x12:  Protect(); break;       // SHEET PROTECTION
-+					case 0x12:  SheetProtect(); break;       // SHEET PROTECTION
-                     case 0x14:
-                     case 0x15:  rPageSett.ReadHeaderFooter( maStrm );   break;
- 					case 0x17:	Externsheet(); break;	// EXTERNSHEET	[ 2345]
-@@ -477,7 +477,7 @@
-                         Eof();
-                         eAkt = Z_Biff4E;
-                     break;
--					case 0x12:  Protect(); break;       // SHEET PROTECTION
-+					case 0x12:  SheetProtect(); break;       // SHEET PROTECTION
-                     case 0x14:
-                     case 0x15:  rPageSett.ReadHeaderFooter( maStrm );   break;
-                     case 0x1A:
-@@ -603,7 +603,7 @@
-                             eAkt = Z_Biff5T;
-                             aIn.SeekGlobalPosition(); // und zurueck an alte Position
-                             break;
--                        case 0x12:  Protect(); break;       // SHEET PROTECTION
-+                        case 0x12:  SheetProtect(); break;       // SHEET PROTECTION
-                         case 0x1A:
-                         case 0x1B:  rPageSett.ReadPageBreaks( maStrm );     break;
-                         case 0x1D:  rTabViewSett.ReadSelection( maStrm );   break;
-@@ -902,6 +902,7 @@
-                         }
- 						break;
- 					case 0x12:	DocProtect(); break;	// PROTECT		[    5678]
-+                    case 0x13:  DocPasssword(); break;
- 					case 0x19:  WinProtection(); break;
- 					case 0x2F:							// FILEPASS		[ 2345   ]
-                         eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
-@@ -1046,7 +1047,8 @@
-                         eAkt = EXC_STATE_SHEET;
-                         aIn.SeekGlobalPosition();         // und zurueck an alte Position
-                         break;
--                    case 0x12:  Protect(); break;
-+                    case 0x12:  SheetProtect(); break;
-+                    case 0x13:  SheetPassword(); break;
-                     case 0x42:  Codepage(); break;      // CODEPAGE     [ 2345   ]
-                     case 0x55:  DefColWidth(); break;
-                     case 0x7D:  Colinfo(); break;       // COLINFO      [  345   ]
-@@ -1062,6 +1064,7 @@
-                     case 0x0221: Array34(); break;      // ARRAY        [  34    ]
-                     case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[  345   ]
-                     case 0x04BC: Shrfmla(); break;      // SHRFMLA      [    5   ]
-+                    case 0x0867: SheetProtection(); break; // SHEETPROTECTION
-                 }
-             }
-             break;
-Index: sc/source/filter/excel/xecontent.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xecontent.cxx,v
-retrieving revision 1.23
-retrieving revision 1.22.80.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.23 -r1.22.80.4
-Index: sc/source/filter/excel/xeroot.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xeroot.cxx,v
-retrieving revision 1.23
-retrieving revision 1.22.152.6
-diff -u -I $Revision.*$ -I $Author.*$ -r1.23 -r1.22.152.6
---- sc/source/filter/excel/xeroot.cxx	10 Apr 2008 20:13:37 -0000	1.23
-+++ sc/source/filter/excel/xeroot.cxx	22 May 2008 21:42:34 -0000	1.22.152.6
-@@ -32,7 +32,11 @@
- #include "precompiled_sc.hxx"
- #include "xeroot.hxx"
- #include <sfx2/docfile.hxx>
-+#include <sfx2/sfxsids.hrc>
- #include <svtools/saveopt.hxx>
-+#include <svtools/itemset.hxx>
-+#include <svtools/stritem.hxx>
-+#include <svtools/eitem.hxx>
- #include "xltracer.hxx"
- #include "xehelper.hxx"
- #include "xeformula.hxx"
-@@ -42,8 +46,10 @@
- #include "xecontent.hxx"
- #include "xepivot.hxx"
- 
--// for filter manager
--#include "excrecds.hxx"
-+#include "excrecds.hxx"  // for filter manager
-+#include "tabprotection.hxx"
-+#include "document.hxx"
-+#include "scextopt.hxx"
- 
- // Global data ================================================================
- 
-@@ -221,6 +227,40 @@
-     return xRec;
- }
- 
-+bool XclExpRoot::IsDocumentEncrypted() const
-+{
-+    // We need to encrypt the content when the document structure is protected.
-+    const ScDocProtection* pDocProt = GetDoc().GetDocProtection();
-+    if (pDocProt && pDocProt->isProtected() && pDocProt->isOptionEnabled(ScDocProtection::STRUCTURE))
-+        return true;
++    // 0x0000 - non standard encryption
++    // 0x0001 - standard encryption
++    sal_uInt16 nStdEnc = 0x0001;
++    rStrm << nStdEnc << nStdEnc;
 +
-+    if (GetPassword().Len() > 0)
-+        // Password is entered directly into the save dialog.
-+        return true;
++    sal_uInt8 nSaltHash[16];
++    XclExpEncrypterRef xEnc( new XclExpBiff8Encrypter(mrRoot, nDocId, nSalt) );
++    xEnc->GetSaltDigest(nSaltHash);
 +
-+    return false;
++    rStrm.Write(nDocId, 16);
++    rStrm.Write(nSalt, 16);
++    rStrm.Write(nSaltHash, 16);
++
++    rStrm.SetEncrypter(xEnc);
 +}
 +
-+const String XclExpRoot::GetPassword() const
++// ============================================================================
++
++XclExpFnGroupCount::XclExpFnGroupCount() :
++    XclExpRecord(0x009C, 2)
 +{
-+    SfxItemSet* pSet = GetMedium().GetItemSet();
-+    if (!pSet)
-+        return String();
++}
 +
-+    const SfxPoolItem* pItem = NULL;
-+    if (SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pItem))
-+    {
-+        const SfxStringItem* pStrItem = dynamic_cast<const SfxStringItem*>(pItem);
-+        if (pStrItem)
-+        {
-+            // Password from the save dialog.
-+            return pStrItem->GetValue();
-+        }
-+    }
++XclExpFnGroupCount::~XclExpFnGroupCount()
++{
++}
 +
-+    return String();
++void XclExpFnGroupCount::WriteBody( XclExpStream& rStrm )
++{
++    rStrm << static_cast<sal_uInt16>(14);
 +}
 +
- XclExpRootData::XclExpLinkMgrRef XclExpRoot::GetLocalLinkMgrRef() const
- {
-     return IsInGlobals() ? mrExpData.mxGlobLinkMgr : mrExpData.mxLocLinkMgr;
-Index: sc/source/filter/excel/xestream.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xestream.cxx,v
-retrieving revision 1.11
-retrieving revision 1.10.324.6
-diff -u -I $Revision.*$ -I $Author.*$ -r1.11 -r1.10.324.6
---- sc/source/filter/excel/xestream.cxx	10 Apr 2008 20:13:53 -0000	1.11
-+++ sc/source/filter/excel/xestream.cxx	22 May 2008 23:34:37 -0000	1.10.324.6
-@@ -34,6 +34,9 @@
- #include "xlstring.hxx"
- #include "xeroot.hxx"
- 
-+#define DEBUG_XL_ENCRYPTION 0
++// ============================================================================
 +
-+using ::std::vector;
- 
- // ============================================================================
- 
-@@ -63,16 +66,19 @@
- void XclExpStream::StartRecord( sal_uInt16 nRecId, sal_Size nRecSize )
- {
-     DBG_ASSERT( !mbInRec, "XclExpStream::StartRecord - another record still open" );
-+    DisableEncryption();
-     mnMaxContSize = mnCurrMaxSize = mnMaxRecSize;
-     mnPredictSize = nRecSize;
-     mbInRec = true;
-     InitRecord( nRecId );
-     SetSliceSize( 0 );
-+    EnableEncryption();
- }
- 
- void XclExpStream::EndRecord()
- {
-     DBG_ASSERT( mbInRec, "XclExpStream::EndRecord - no record open" );
-+    DisableEncryption();
-     UpdateRecSize();
-     mrStrm.Seek( STREAM_SEEK_TO_END );
-     mbInRec = false;
-@@ -84,6 +90,86 @@
-     mnSliceSize = 0;
- }
- 
-+XclExpStream& XclExpStream::operator<<( sal_Int8 nValue )
++XclExpInterfaceHdr::XclExpInterfaceHdr() :
++    XclExpRecord(0x00E1, 2)
 +{
-+    PrepareWrite( 1 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, nValue);
-+    else
-+        mrStrm << nValue;
-+    return *this;
 +}
 +
-+XclExpStream& XclExpStream::operator<<( sal_uInt8 nValue )
++XclExpInterfaceHdr::~XclExpInterfaceHdr()
 +{
-+    PrepareWrite( 1 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, nValue);
-+    else
-+        mrStrm << nValue;
-+    return *this;
 +}
 +
-+XclExpStream& XclExpStream::operator<<( sal_Int16 nValue )
++void XclExpInterfaceHdr::WriteBody( XclExpStream& rStrm )
 +{
-+    PrepareWrite( 2 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, nValue);
-+    else
-+        mrStrm << nValue;
-+    return *this;
++    // The value must be the same value as the CODEPAGE record.
++    rStrm.DisableEncryption();
++    rStrm << static_cast<sal_uInt16>(0x04B0);
 +}
 +
-+XclExpStream& XclExpStream::operator<<( sal_uInt16 nValue )
++// ============================================================================
++
++XclExpInterfaceEnd::XclExpInterfaceEnd() :
++    XclExpRecord(0x00E2, 0)
 +{
-+    PrepareWrite( 2 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, nValue);
-+    else
-+        mrStrm << nValue;
-+    return *this;
 +}
 +
-+XclExpStream& XclExpStream::operator<<( sal_Int32 nValue )
++XclExpInterfaceEnd::~XclExpInterfaceEnd()
 +{
-+    PrepareWrite( 4 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, nValue);
-+    else
-+        mrStrm << nValue;
-+    return *this;
 +}
 +
-+XclExpStream& XclExpStream::operator<<( sal_uInt32 nValue )
++void XclExpInterfaceEnd::WriteBody( XclExpStream& /*rStrm*/ )
 +{
-+    PrepareWrite( 4 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, nValue);
-+    else
-+        mrStrm << nValue;
-+    return *this;
 +}
 +
-+XclExpStream& XclExpStream::operator<<( float fValue )
-+{
-+    PrepareWrite( 4 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, fValue);
-+    else
-+        mrStrm << fValue;
-+    return *this;
-+}
++// ============================================================================
 +
-+XclExpStream& XclExpStream::operator<<( double fValue )
++XclExpMMS::XclExpMMS() :
++    XclExpRecord(0x00C1, 2)
 +{
-+    PrepareWrite( 8 );
-+    if (mbUseEncrypter && HasValidEncrypter())
-+        mxEncrypter->Encrypt(mrStrm, fValue);
-+    else
-+        mrStrm << fValue;
-+    return *this;
 +}
 +
- sal_Size XclExpStream::Write( const void* pData, sal_Size nBytes )
- {
-     sal_Size nRet = 0;
-@@ -98,9 +184,21 @@
-             while( bValid && (nBytesLeft > 0) )
-             {
-                 sal_Size nWriteLen = ::std::min< sal_Size >( PrepareWrite(), nBytesLeft );
--                sal_Size nWriteRet = mrStrm.Write( pBuffer, nWriteLen );
-+                sal_Size nWriteRet = nWriteLen;
-+                if (mbUseEncrypter && HasValidEncrypter())
-+                {
-+                    DBG_ASSERT(nWriteLen > 0, "XclExpStream::Write: write length is 0!");
-+                    vector<sal_uInt8> aBytes(nWriteLen);
-+                    memcpy(&aBytes[0], pBuffer, nWriteLen);
-+                    mxEncrypter->EncryptBytes(mrStrm, aBytes);
-+                    // TODO: How do I check if all the bytes have been successfully written ?
-+                }
-+                else
-+                {
-+                    nWriteRet = mrStrm.Write( pBuffer, nWriteLen );
-                 bValid = (nWriteLen == nWriteRet);
-                 DBG_ASSERT( bValid, "XclExpStream::Write - stream write error" );
-+                }
-                 pBuffer += nWriteRet;
-                 nRet += nWriteRet;
-                 nBytesLeft -= nWriteRet;
-@@ -236,6 +334,26 @@
-     Write( &rBuffer[ 0 ], rBuffer.size() );
- }
- 
-+void XclExpStream::SetEncrypter( XclExpEncrypterRef xEncrypter )
++XclExpMMS::~XclExpMMS()
 +{
-+    mxEncrypter = xEncrypter;
 +}
 +
-+bool XclExpStream::HasValidEncrypter() const
++void XclExpMMS::WriteBody( XclExpStream& rStrm )
 +{
-+    return mxEncrypter.is() && mxEncrypter->IsValid();
++    rStrm << static_cast<sal_uInt16>(0x0000);
 +}
 +
-+void XclExpStream::EnableEncryption( bool bEnable )
++// ============================================================================
++
++XclExpWriteAccess::XclExpWriteAccess() :
++    XclExpRecord(0x005C, 112)
 +{
-+    mbUseEncrypter = bEnable && HasValidEncrypter();
 +}
 +
-+void XclExpStream::DisableEncryption()
++XclExpWriteAccess::~XclExpWriteAccess()
 +{
-+    EnableEncryption(false);
 +}
 +
- sal_Size XclExpStream::SetSvStreamPos( sal_Size nPos )
- {
-     DBG_ASSERT( !mbInRec, "XclExpStream::SetSvStreamPos - not allowed inside of a record" );
-@@ -327,3 +445,187 @@
- 
- // ============================================================================
- 
-+XclExpBiff8Encrypter::XclExpBiff8Encrypter( const XclExpRoot& rRoot, const sal_uInt8 nDocId[16],
-+                                            const sal_uInt8 nSalt[16] ) :
-+    mrRoot(rRoot),
-+    mnOldPos(STREAM_SEEK_TO_END),
-+    mbValid(false)
++void XclExpWriteAccess::WriteBody( XclExpStream& rStrm )
 +{
-+    String aPass = rRoot.GetPassword();
-+    if (aPass.Len() == 0)
-+        // Empty password.  Get the default biff8 password.
-+        aPass = XclCryptoHelper::GetBiff8WbProtPassword();
-+    Init(aPass, nDocId, nSalt);
++    static const sal_uInt8 aData[] = {
++        0x04, 0x00, 0x00,  'C',  'a',  'l',  'c', 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
++        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
++
++    sal_Size nDataSize = sizeof(aData);
++    for (sal_Size i = 0; i < nDataSize; ++i)
++        rStrm << aData[i];
 +}
 +
-+XclExpBiff8Encrypter::~XclExpBiff8Encrypter()
++// ============================================================================
++
++XclExpCodePage::XclExpCodePage() :
++    XclExpRecord(0x0042, 2)
 +{
 +}
 +
-+bool XclExpBiff8Encrypter::IsValid() const
++XclExpCodePage::~XclExpCodePage()
 +{
-+    return mbValid;
 +}
 +
-+void XclExpBiff8Encrypter::GetSaltDigest( sal_uInt8 nSaltDigest[16] ) const
++void XclExpCodePage::WriteBody( XclExpStream& rStrm )
 +{
-+    memcpy(nSaltDigest, mnSaltDigest, 16);
++    // 0x04B0 : UTF-16 (BIFF8)
++    rStrm << static_cast<sal_uInt16>(0x04B0);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt8 nData )
++// ============================================================================
++
++XclExpDSF::XclExpDSF() :
++    XclExpRecord(0x0161, 2)
 +{
-+    vector<sal_uInt8> aByte(1);
-+    aByte[0] = nData;
-+    EncryptBytes(rStrm, aByte);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt16 nData )
++XclExpDSF::~XclExpDSF()
 +{
-+    ::std::vector<sal_uInt8> pnBytes(2);
-+    pnBytes[0] = nData & 0xFF;
-+    pnBytes[1] = (nData >> 8) & 0xFF;
-+    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt32 nData )
++void XclExpDSF::WriteBody( XclExpStream& rStrm )
 +{
-+    ::std::vector<sal_uInt8> pnBytes(4);
-+    pnBytes[0] = nData & 0xFF;
-+    pnBytes[1] = (nData >>  8) & 0xFF;
-+    pnBytes[2] = (nData >> 16) & 0xFF;
-+    pnBytes[3] = (nData >> 24) & 0xFF;
-+    EncryptBytes(rStrm, pnBytes);
++    rStrm << static_cast<sal_uInt16>(0x0000);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, float fValue )
++// ============================================================================
++
++XclExpProt4Rev::XclExpProt4Rev() :
++    XclExpRecord(0x01AF, 2)
 +{
-+    ::std::vector<sal_uInt8> pnBytes(4);
-+    memcpy(&pnBytes[0], &fValue, 4);
-+    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, double fValue )
++XclExpProt4Rev::~XclExpProt4Rev()
 +{
-+    ::std::vector<sal_uInt8> pnBytes(8);
-+    memcpy(&pnBytes[0], &fValue, 8);
-+    EncryptBytes(rStrm, pnBytes);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int8 nData )
++void XclExpProt4Rev::WriteBody( XclExpStream& rStrm )
 +{
-+    Encrypt(rStrm, static_cast<sal_uInt8>(nData));
++    rStrm << static_cast<sal_uInt16>(0x0000);
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int16 nData )
++// ============================================================================
++
++XclExpProt4RevPass::XclExpProt4RevPass() :
++    XclExpRecord(0x01BC, 2)
 +{
-+    Encrypt(rStrm, static_cast<sal_uInt16>(nData));
 +}
 +
-+void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int32 nData )
++XclExpProt4RevPass::~XclExpProt4RevPass()
 +{
-+    Encrypt(rStrm, static_cast<sal_uInt32>(nData));
 +}
 +
-+void XclExpBiff8Encrypter::Init( const String& aPass, const sal_uInt8 nDocId[16],
-+                                 const sal_uInt8 nSalt[16] )
++void XclExpProt4RevPass::WriteBody( XclExpStream& rStrm )
 +{
-+    memset(mnSaltDigest, 0, sizeof(mnSaltDigest));
-+
-+    xub_StrLen nLen = aPass.Len();
-+    bool bValid = (0 < nLen) && (nLen < 16);
-+    if ( bValid )
-+    {
-+        // transform String to sal_uInt16 array
-+        memset(mnPassw, 0, sizeof(mnPassw));
-+        for (xub_StrLen nChar = 0; nChar < nLen; ++nChar)
-+            mnPassw[nChar] = static_cast<sal_uInt16>(aPass.GetChar(nChar));
-+
-+        // copy document ID
-+        memcpy(mnDocId, nDocId, sizeof(mnDocId));
-+
-+        // init codec
-+        maCodec.InitKey(mnPassw, mnDocId);
-+
-+        // generate salt hash.
-+        ::svx::MSCodec_Std97 aCodec;
-+        aCodec.InitKey(mnPassw, mnDocId);
-+        aCodec.CreateSaltDigest(nSalt, mnSaltDigest);
-+
-+        // verify to make sure it's in good shape.
-+        bValid = maCodec.VerifyKey(nSalt, mnSaltDigest);
-+    }
-+
-+    mbValid = bValid;
++    rStrm << static_cast<sal_uInt16>(0x0000);
 +}
 +
-+sal_uInt32 XclExpBiff8Encrypter::GetBlockPos( sal_Size nStrmPos ) const
++// ============================================================================
++
++XclExpExcel9File::XclExpExcel9File() :
++    XclExpRecord(0x01C0, 0)
 +{
-+    return static_cast<sal_uInt32>(nStrmPos / EXC_ENCR_BLOCKSIZE);
 +}
 +
-+sal_uInt16 XclExpBiff8Encrypter::GetOffsetInBlock( sal_Size nStrmPos ) const
++XclExpExcel9File::~XclExpExcel9File()
 +{
-+    return static_cast<sal_uInt16>(nStrmPos % EXC_ENCR_BLOCKSIZE);
 +}
 +
-+void XclExpBiff8Encrypter::EncryptBytes( SvStream& rStrm, vector<sal_uInt8>& aBytes )
++void XclExpExcel9File::WriteBody( XclExpStream& /*rStrm*/ )
 +{
-+    sal_Size nStrmPos = rStrm.Tell();
-+    sal_uInt16 nBlockOffset = GetOffsetInBlock(nStrmPos);
-+    sal_uInt16 nBlockPos = GetBlockPos(nStrmPos);
++}
 +
-+#if DEBUG_XL_ENCRYPTION
-+    fprintf(stdout, "XclExpBiff8Encrypter::EncryptBytes: stream pos = %ld  offset in block = %d  block pos = %ld\n",
-+            nStrmPos, nBlockOffset, nBlockPos);
-+#endif
++// ============================================================================
 +
-+    sal_uInt16 nSize = aBytes.size();
-+    if (nSize == 0)
-+        return;
++static const sal_uInt8 nData01C1[] = {
++    0xC1, 0x01, 0x00, 0x00, 0x54, 0x8D, 0x01, 0x00
++};
 +
-+#if DEBUG_XL_ENCRYPTION    
-+    fprintf(stdout, "RAW: ");
-+    for (sal_uInt16 i = 0; i < nSize; ++i)
-+        fprintf(stdout, "%2.2X ", aBytes[i]);
-+    fprintf(stdout, "\n");
-+#endif    
++XclExpUnknown01C1::XclExpUnknown01C1() :
++    XclExpDummyRecord(0x01C1, nData01C1, sizeof(nData01C1))
++{
++}
 +
-+    if (mnOldPos != nStrmPos)
-+    {
-+        sal_uInt16 nOldOffset = GetOffsetInBlock(mnOldPos);
-+        sal_uInt16 nOldBlockPos = GetBlockPos(mnOldPos);
++// ============================================================================
 +
-+        if ( (nBlockPos != nOldBlockPos) || (nBlockOffset < nOldOffset) )
-+        {
-+            maCodec.InitCipher(nBlockPos);
-+            nOldOffset = 0;
-+        }
++static const sal_uInt8 nData0863[] = {
++    0x63, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
++    0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
++    0x02
++};
 +
-+        if (nBlockOffset > nOldOffset)
-+            maCodec.Skip(nBlockOffset - nOldOffset);
-+    }
++XclExpUnknown0863::XclExpUnknown0863() :
++    XclExpDummyRecord(0x0863, nData0863, sizeof(nData0863))
++{
++}
 +
-+    sal_uInt16 nBytesLeft = nSize;
-+    sal_uInt16 nPos = 0;
-+    while (nBytesLeft > 0)
-+    {
-+        sal_uInt16 nBlockLeft = EXC_ENCR_BLOCKSIZE - nBlockOffset;
-+        sal_uInt16 nEncBytes = ::std::min(nBlockLeft, nBytesLeft);
-+
-+        bool bRet = maCodec.Encode(&aBytes[nPos], nEncBytes, &aBytes[nPos], nEncBytes);
-+        DBG_ASSERT(bRet, "XclExpBiff8Encrypter::EncryptBytes: encryption failed!!");
-+
-+        sal_Size nRet = rStrm.Write(&aBytes[nPos], nEncBytes);
-+        DBG_ASSERT(nRet == nEncBytes, "XclExpBiff8Encrypter::EncryptBytes: fail to write to stream!!");
-+
-+        nStrmPos = rStrm.Tell();
-+        nBlockOffset = GetOffsetInBlock(nStrmPos);
-+        nBlockPos = GetBlockPos(nStrmPos);
-+        if (nBlockOffset == 0)
-+            maCodec.InitCipher(nBlockPos);
-+
-+        nBytesLeft -= nEncBytes;
-+        nPos += nEncBytes;
-+    }
-+    mnOldPos = nStrmPos;
-+}
-Index: sc/source/filter/excel/xetable.cxx
+Index: source/filter/xcl97/makefile.mk
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xetable.cxx,v
-retrieving revision 1.18
-retrieving revision 1.17.80.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.18 -r1.17.80.3
-Index: sc/source/filter/excel/xicontent.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xicontent.cxx,v
-retrieving revision 1.32
-retrieving revision 1.30.80.7
-diff -u -I $Revision.*$ -I $Author.*$ -r1.32 -r1.30.80.7
---- sc/source/filter/excel/xicontent.cxx	8 Jul 2008 07:22:54 -0000	1.32
-+++ sc/source/filter/excel/xicontent.cxx	17 Jul 2008 01:00:50 -0000	1.30.80.7
-@@ -41,6 +41,7 @@
- #include "scitems.hxx"
- #include <svx/eeitem.hxx>
- #include <svtools/intitem.hxx>
-+#include <svtools/stritem.hxx>
- #include <svx/flditem.hxx>
- #include <svx/fhgtitem.hxx>
- #include <svx/wghtitem.hxx>
-@@ -67,6 +68,12 @@
- #include "xiname.hxx"
- 
- #include "excform.hxx"
-+#include "tabprotection.hxx"
-+
-+#include <memory>
-+
-+using ::com::sun::star::uno::Sequence;
-+using ::std::auto_ptr;
+--- sc/source/filter/xcl97/makefile.mk	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/xcl97/makefile.mk	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -50,7 +50,6 @@
+ # --- Files --------------------------------------------------------
  
- // Shared string table ========================================================
+ SLOFILES =									\
+-		$(SLO)$/xcl97dum.obj				\
+ 		$(SLO)$/xcl97esc.obj				\
+ 		$(SLO)$/xcl97rec.obj				\
+ 		$(SLO)$/XclImpChangeTrack.obj		\
+Index: source/filter/inc/imp_op.hxx
+===================================================================
+--- sc/source/filter/inc/imp_op.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/imp_op.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -135,9 +135,11 @@
+ 	void					Bof2( void );					// 0x09
+ 	void					Eof( void );					// 0x0A
+ 	void					DocProtect( void );             // 0x12
+-	void					Protect( void );				// 0x12	Sheet Protection
+-	BOOL					Password( void );				// 0x13
++    void                    SheetProtect( void );           // 0x12 Sheet Protection
++    void                    DocPasssword( void );           // 0x13 document password
++    void                    SheetPassword( void );               // 0x13 sheet password
+ 	void					Externsheet( void );			// 0x17
++    void                    WinProtection( void );          // 0x19
+ 	void					Columndefault( void );			// 0x20
+ 	void					Array25( void );				// 0x21
+ 	void					Rec1904( void );				// 0x22
+Index: source/filter/inc/xicontent.hxx
+===================================================================
+--- sc/source/filter/inc/xicontent.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xicontent.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -37,6 +37,8 @@
+ #include "xistring.hxx"
+ #include "xiroot.hxx"
  
-@@ -1069,11 +1076,182 @@
-     };
-     // set decrypter at import stream
-     rStrm.SetDecrypter( xDecr );
--    // remember encryption for export
--    rStrm.GetRoot().GetExtDocOptions().GetDocSettings().mbEncrypted = true;
++#include <map>
 +
-+    // Store the document password for export.
-+    SfxItemSet* pSet = rStrm.GetRoot().GetDocShell()->GetMedium()->GetItemSet();
-+    if (pSet)
-+    {
-+        String aPass = xDecr->GetPassword();
-+        pSet->Put( SfxStringItem(SID_PASSWORD, aPass) );
-+    }
+ /* ============================================================================
+ Classes to import the big Excel document contents (related to several cells or
+ globals for the document).
+@@ -249,5 +251,64 @@
  
-     return xDecr.is() ? xDecr->GetError() : EXC_ENCR_ERROR_UNSUPP_CRYPT;
- }
+ // ============================================================================
  
 +// Document protection ========================================================
 +
-+XclImpDocProtectBuffer::XclImpDocProtectBuffer( const XclImpRoot& rRoot ) :
-+    XclImpRoot( rRoot ),
-+    mnPassHash(0x0000),
-+    mbDocProtect(false),
-+    mbWinProtect(false)
-+{
-+}
-+
-+void XclImpDocProtectBuffer::ReadDocProtect( XclImpStream& rStrm )
-+{
-+    mbDocProtect = rStrm.ReaduInt16() ? true : false;
-+}
-+
-+void XclImpDocProtectBuffer::ReadWinProtect( XclImpStream& rStrm )
-+{
-+    mbWinProtect = rStrm.ReaduInt16() ? true : false;
-+}
-+
-+void XclImpDocProtectBuffer::ReadPasswordHash( XclImpStream& rStrm )
-+{
-+    rStrm.EnableDecryption();
-+    mnPassHash = rStrm.ReaduInt16();
-+}
-+
-+void XclImpDocProtectBuffer::Apply() const
++class XclImpDocProtectBuffer : protected XclImpRoot
 +{
-+    if (!mbDocProtect && !mbWinProtect)
-+        // Excel requires either the structure or windows protection is set.
-+        // If neither is set then the document is not protected at all.
-+        return;
-+
-+    auto_ptr<ScDocProtection> pProtect(new ScDocProtection);
-+    pProtect->setProtected(true);
-+
-+    if (mnPassHash)
-+    {
-+        // 16-bit password pash.
-+        Sequence<sal_Int8> aPass(2);
-+        aPass[0] = (mnPassHash >> 8) & 0xFF;
-+        aPass[1] = mnPassHash & 0xFF;
-+        pProtect->setPasswordHash(aPass, PASSHASH_XL);
-+    }
++public:
++    explicit            XclImpDocProtectBuffer( const XclImpRoot& rRoot );
 +
-+    // document protection options
-+    pProtect->setOption(ScDocProtection::STRUCTURE, mbDocProtect);
-+    pProtect->setOption(ScDocProtection::WINDOWS,   mbWinProtect);
++    /** document structure protection flag  */
++    void                ReadDocProtect( XclImpStream& rStrm );
 +
-+    GetDoc().SetDocProtection(pProtect.get());
-+}
++    /** document windows properties protection flag */
++    void                ReadWinProtect( XclImpStream& rStrm );
 +
-+// Sheet Protection ===========================================================
++    void                ReadPasswordHash( XclImpStream& rStrm );
 +
-+XclImpSheetProtectBuffer::Sheet::Sheet() :
-+    mbProtected(false),
-+    mnPasswordHash(0x0000),
-+    mnOptions(0x4400)
-+{
-+}
++    void                Apply() const;
 +
-+// ----------------------------------------------------------------------------
++private:
++    sal_uInt16      mnPassHash;
++    bool            mbDocProtect:1;
++    bool            mbWinProtect:1;
++};
 +
-+XclImpSheetProtectBuffer::Sheet::Sheet(const Sheet& r) :
-+    mbProtected(r.mbProtected),
-+    mnPasswordHash(r.mnPasswordHash),
-+    mnOptions(r.mnOptions)
-+{
-+}
++// Sheet protection ===========================================================
 +
-+XclImpSheetProtectBuffer::XclImpSheetProtectBuffer( const XclImpRoot& rRoot ) :
-+    XclImpRoot( rRoot )
++class XclImpSheetProtectBuffer : protected XclImpRoot
 +{
-+}
++public:
++    explicit            XclImpSheetProtectBuffer( const XclImpRoot& rRoot );
 +
-+void XclImpSheetProtectBuffer::ReadProtect( XclImpStream& rStrm, SCTAB nTab )
-+{
-+    if ( rStrm.ReaduInt16() )
-+    {
-+        Sheet* pSheet = GetSheetItem(nTab);
-+        if (pSheet)
-+            pSheet->mbProtected = true;
-+    }
-+}
++    void                ReadProtect( XclImpStream& rStrm, SCTAB nTab );
 +
-+void XclImpSheetProtectBuffer::ReadOptions( XclImpStream& rStrm, SCTAB nTab )
-+{
-+    rStrm.Ignore(19);
-+    sal_uInt16 nOptions;
-+    rStrm >> nOptions;
++    void                ReadOptions( XclImpStream& rStrm, SCTAB nTab );
 +
-+    Sheet* pSheet = GetSheetItem(nTab);
-+    if (pSheet)
-+        pSheet->mnOptions = nOptions;
-+}
++    void                ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab );
 +
-+void XclImpSheetProtectBuffer::ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab )
-+{
-+    sal_uInt16 nHash;
-+    rStrm >> nHash;
-+    Sheet* pSheet = GetSheetItem(nTab);
-+    if (pSheet)
-+        pSheet->mnPasswordHash = nHash;
-+}
++    void                Apply() const;
 +
-+void XclImpSheetProtectBuffer::Apply() const
-+{
-+    for (ProtectedSheetMap::const_iterator itr = maProtectedSheets.begin(), itrEnd = maProtectedSheets.end();
-+         itr != itrEnd; ++itr)
++private:
++    struct Sheet
 +    {
-+        if (!itr->second.mbProtected)
-+            // This sheet is (for whatever reason) not protected.
-+            continue;
++        bool        mbProtected;
++        sal_uInt16  mnPasswordHash;
++        sal_uInt16  mnOptions;
 +
-+        auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
-+        pProtect->setProtected(true);
++        Sheet();
++        Sheet(const Sheet& r);
++    };
 +
-+        // 16-bit hash password
-+        const sal_uInt16 nHash = itr->second.mnPasswordHash;
-+        if (nHash)
-+        {
-+            Sequence<sal_Int8> aPass(2);
-+            aPass[0] = (nHash >> 8) & 0xFF;
-+            aPass[1] = nHash & 0xFF;
-+            pProtect->setPasswordHash(aPass, PASSHASH_XL);
-+        }
++    Sheet* GetSheetItem( SCTAB nTab );
 +
-+        // sheet protection options
-+        const sal_uInt16 nOptions = itr->second.mnOptions;
-+        pProtect->setOption( ScTableProtection::OBJECTS,               (nOptions & 0x0001) );
-+        pProtect->setOption( ScTableProtection::SCENARIOS,             (nOptions & 0x0002) );
-+        pProtect->setOption( ScTableProtection::FORMAT_CELLS,          (nOptions & 0x0004) );
-+        pProtect->setOption( ScTableProtection::FORMAT_COLUMNS,        (nOptions & 0x0008) );
-+        pProtect->setOption( ScTableProtection::FORMAT_ROWS,           (nOptions & 0x0010) );
-+        pProtect->setOption( ScTableProtection::INSERT_COLUMNS,        (nOptions & 0x0020) );
-+        pProtect->setOption( ScTableProtection::INSERT_ROWS,           (nOptions & 0x0040) );
-+        pProtect->setOption( ScTableProtection::INSERT_HYPERLINKS,     (nOptions & 0x0080) );
-+        pProtect->setOption( ScTableProtection::DELETE_COLUMNS,        (nOptions & 0x0100) );
-+        pProtect->setOption( ScTableProtection::DELETE_ROWS,           (nOptions & 0x0200) );
-+        pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS,   (nOptions & 0x0400) );
-+        pProtect->setOption( ScTableProtection::SORT,                  (nOptions & 0x0800) );
-+        pProtect->setOption( ScTableProtection::AUTOFILTER,            (nOptions & 0x1000) );
-+        pProtect->setOption( ScTableProtection::PIVOT_TABLES,          (nOptions & 0x2000) );
-+        pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, (nOptions & 0x4000) );
++private:
++    typedef ::std::map<SCTAB, Sheet> ProtectedSheetMap;
++    ProtectedSheetMap   maProtectedSheets;
++};
 +
-+        // all done.  now commit.
-+        GetDoc().SetTabProtection(itr->first, pProtect.get());
-+    }
-+}
 +
-+XclImpSheetProtectBuffer::Sheet* XclImpSheetProtectBuffer::GetSheetItem( SCTAB nTab )
-+{
-+    ProtectedSheetMap::iterator itr = maProtectedSheets.find(nTab);
-+    if (itr == maProtectedSheets.end())
-+    {
-+        // new sheet
-+        if ( !maProtectedSheets.insert( ProtectedSheetMap::value_type(nTab, Sheet()) ).second )
-+            return NULL;
++// ============================================================================
 +
-+        itr = maProtectedSheets.find(nTab);
-+    }
-+
-+    return &itr->second;
-+}
-+
- // ============================================================================
- 
-Index: sc/source/filter/excel/xilink.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xilink.cxx,v
-retrieving revision 1.25
-retrieving revision 1.23.28.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.25 -r1.23.28.3
---- sc/source/filter/excel/xilink.cxx	8 Jul 2008 07:23:09 -0000	1.25
-+++ sc/source/filter/excel/xilink.cxx	17 Jul 2008 01:00:53 -0000	1.23.28.3
-@@ -264,6 +264,7 @@
-     DBG_ASSERT_BIFF( rStrm.GetRoot().GetBiff() == EXC_BIFF8 );
-     if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
-     {
-+        rStrm.EnableDecryption();
-         sal_Size nReadCount = rStrm.GetRecLeft() / 2;
-         DBG_ASSERT( nReadCount <= 0xFFFF, "XclImpTabInfo::ReadTabid - record too long" );
-         maTabIdVec.clear();
-Index: sc/source/filter/excel/xiroot.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xiroot.cxx,v
-retrieving revision 1.24
-retrieving revision 1.23.286.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.24 -r1.23.286.3
---- sc/source/filter/excel/xiroot.cxx	10 Apr 2008 20:18:01 -0000	1.24
-+++ sc/source/filter/excel/xiroot.cxx	6 May 2008 23:28:52 -0000	1.23.286.3
-@@ -52,6 +52,7 @@
- XclImpRootData::XclImpRootData( XclBiff eBiff, SfxMedium& rMedium,
-         SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
-     XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ),
-+    mbPassQueried( false ),
-     mbHasCodePage( false )
- {
- }
-@@ -86,6 +87,8 @@
-         GetOldRoot().pAutoFilterBuffer = new XclImpAutoFilterBuffer;
-         mrImpData.mxWebQueryBfr.reset( new XclImpWebQueryBuffer( GetRoot() ) );
-         mrImpData.mxPTableMgr.reset( new XclImpPivotTableManager( GetRoot() ) );
-+        mrImpData.mxTabProtect.reset( new XclImpSheetProtectBuffer( GetRoot() ) );
-+        mrImpData.mxDocProtect.reset( new XclImpDocProtectBuffer( GetRoot() ) );
-     }
- 
-     mrImpData.mxPageSett.reset( new XclImpPageSettings( GetRoot() ) );
-@@ -224,6 +227,18 @@
-     return *mrImpData.mxPTableMgr;
- }
- 
-+XclImpSheetProtectBuffer& XclImpRoot::GetSheetProtectBuffer() const
-+{
-+    DBG_ASSERT( mrImpData.mxTabProtect.is(), "XclImpRoot::GetSheetProtectBuffer - invalid call, wrong BIFF" );
-+    return *mrImpData.mxTabProtect;
-+}
-+
-+XclImpDocProtectBuffer& XclImpRoot::GetDocProtectBuffer() const
-+{
-+    DBG_ASSERT( mrImpData.mxDocProtect.is(), "XclImpRoot::GetDocProtectBuffer - invalid call, wrong BIFF" );
-+    return *mrImpData.mxDocProtect;
-+}
-+
- XclImpPageSettings& XclImpRoot::GetPageSettings() const
- {
-     return *mrImpData.mxPageSett;
-@@ -247,5 +262,16 @@
-     return rXclName;
- }
- 
-+const String& XclImpRoot::QueryPassword() const
-+{
-+    if( !mrImpData.mbPassQueried )
-+    {
-+        mrImpData.maPassw = ScfApiHelper::QueryPasswordForMedium( GetMedium() );
-+        // set to true, even if dialog has been cancelled (never ask twice)
-+        mrImpData.mbPassQueried = true;
-+    }
-+    return mrImpData.maPassw;
-+}
-+
- // ============================================================================
- 
-Index: sc/source/filter/excel/xistream.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xistream.cxx,v
-retrieving revision 1.22
-retrieving revision 1.21.322.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.22 -r1.21.322.5
---- sc/source/filter/excel/xistream.cxx	10 Apr 2008 20:18:15 -0000	1.22
-+++ sc/source/filter/excel/xistream.cxx	22 May 2008 23:56:02 -0000	1.21.322.5
-@@ -36,6 +36,8 @@
- #include "xlstring.hxx"
- #include "xiroot.hxx"
- 
-+#include <vector>
-+
- // ============================================================================
- // Decryption
- // ============================================================================
-@@ -97,11 +99,21 @@
-     return nRet;
- }
- 
-+const String XclImpDecrypter::GetPassword() const
-+{
-+    return maPass;
-+}
-+
- void XclImpDecrypter::SetHasValidPassword( bool bValid )
- {
-     mnError = bValid ? ERRCODE_NONE : EXC_ENCR_ERROR_WRONG_PASS;
- }
- 
-+void XclImpDecrypter::SetPassword( const String& rPass )
-+{
-+    maPass = rPass;
-+}
-+
- // ----------------------------------------------------------------------------
- 
- XclImpBiff5Decrypter::XclImpBiff5Decrypter( const XclImpRoot& rRoot, sal_uInt16 nKey, sal_uInt16 nHash )
-@@ -157,6 +169,9 @@
-         // init codec
-         maCodec.InitKey( mpnPassw );
-         bValid = maCodec.VerifyKey( nKey, nHash );
-+
-+        String aUniPass( rPass, RTL_TEXTENCODING_MS_1252 );
-+        SetPassword( aUniPass );
-     }
- 
-     SetHasValidPassword( bValid );
-@@ -255,6 +270,8 @@
-         // init codec
-         maCodec.InitKey( mpnPassw, mpnDocId );
-         bValid = maCodec.VerifyKey( pnSaltData, pnSaltHash );
-+
-+        SetPassword(rPass);
-     }
- 
-     SetHasValidPassword( bValid );
-Index: sc/source/filter/excel/xlroot.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/excel/xlroot.cxx,v
-retrieving revision 1.32
-retrieving revision 1.31.238.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.32 -r1.31.238.3
---- sc/source/filter/excel/xlroot.cxx	10 Apr 2008 20:22:11 -0000	1.32
-+++ sc/source/filter/excel/xlroot.cxx	6 May 2008 23:29:13 -0000	1.31.238.3
-@@ -91,8 +91,7 @@
-     mxRD( new RootData ),//!
-     mnCharWidth( 110 ),
-     mnScTab( 0 ),
--    mbExport( bExport ),
--    mbHasPassw( false )
-+    mbExport( bExport )
- {
-     // default script type, e.g. for empty cells
-     switch( ScGlobal::GetDefaultScriptType() )
-@@ -198,17 +197,6 @@
-     }
- }
- 
--const String& XclRoot::QueryPassword() const
--{
--    if( !mrData.mbHasPassw )
--    {
--        mrData.maPassw = ScfApiHelper::QueryPasswordForMedium( GetMedium() );
--        // set to true, even if dialog has been cancelled (never ask twice)
--        mrData.mbHasPassw = true;
--    }
--    return mrData.maPassw;
--}
--
- bool XclRoot::HasVbaStorage() const
- {
-     SotStorageRef xRootStrg = GetRootStorage();
-Index: sc/source/filter/inc/excimp8.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/excimp8.hxx,v
-retrieving revision 1.71
-retrieving revision 1.69.80.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.71 -r1.69.80.3
---- sc/source/filter/inc/excimp8.hxx	2 Jul 2008 09:11:00 -0000	1.71
-+++ sc/source/filter/inc/excimp8.hxx	17 Jul 2008 01:00:29 -0000	1.69.80.3
-@@ -62,7 +62,6 @@
- 		void					Delta( void );					// 0x10
- 		void					Iteration( void );				// 0x11
- 		void					Note( void );					// 0x1C
--		void					WinProtection(	void );         // 0x19
- 		void					Boundsheet( void );				// 0x85
- 		void					FilterMode( void );				// 0x9B
- 		void					AutoFilterInfo( void );			// 0x9D
-@@ -74,6 +73,7 @@
- 
- 		void					Hlink( void );					// 0x01B8
- 		void					Codename( BOOL bWBGlobals );	// 0x01BA
-+        void                    SheetProtection( void );        // 0x0867
+ #endif
  
-         virtual void            EndSheet( void );
- 		virtual void			PostDocLoad( void );
-Index: sc/source/filter/inc/excrecds.hxx
+Index: source/filter/inc/xetable.hxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/excrecds.hxx,v
-retrieving revision 1.51
-retrieving revision 1.49.324.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.51 -r1.49.324.3
---- sc/source/filter/inc/excrecds.hxx	2 Jul 2008 09:11:27 -0000	1.51
-+++ sc/source/filter/inc/excrecds.hxx	17 Jul 2008 01:00:26 -0000	1.49.324.3
-@@ -244,10 +244,23 @@
- };
- 
- // EXC_ID_PROTECT  Document Protection
--class XclExpDocProtection : public	XclExpBoolRecord
-+class XclExpProtection : public	XclExpBoolRecord
- {
- 	public:
--		XclExpDocProtection(bool bValue);
-+		XclExpProtection(bool bValue);
-+};
-+
-+class XclExpPassHash : public XclExpRecord
-+{
-+public:
-+    XclExpPassHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aHash);
-+    virtual ~XclExpPassHash();
-+
-+private:
-+    virtual void    WriteBody(XclExpStream& rStrm);
-+
-+private:
-+    sal_uInt16  mnHash;
+--- sc/source/filter/inc/xetable.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xetable.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -1069,7 +1069,5 @@
+     XclExpDvalRef       mxDval;             /// Data validation with DVAL and DV records.
  };
  
+-// ============================================================================
+-
+ #endif
  
-Index: sc/source/filter/inc/fdumper.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/fdumper.hxx,v
-retrieving revision 1.10
-retrieving revision 1.7.320.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.10 -r1.7.320.5
-Index: sc/source/filter/inc/imp_op.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/imp_op.hxx,v
-retrieving revision 1.43
-retrieving revision 1.41.286.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.43 -r1.41.286.3
---- sc/source/filter/inc/imp_op.hxx	2 Jul 2008 09:14:54 -0000	1.43
-+++ sc/source/filter/inc/imp_op.hxx	17 Jul 2008 01:00:35 -0000	1.41.286.3
-@@ -134,9 +134,11 @@
- 	void					Bof2( void );					// 0x09
- 	void					Eof( void );					// 0x0A
- 	void					DocProtect( void );             // 0x12
--	void					Protect( void );				// 0x12	Sheet Protection
--	BOOL					Password( void );				// 0x13
-+    void                    SheetProtect( void );           // 0x12 Sheet Protection
-+    void                    DocPasssword( void );           // 0x13 document password
-+    void                    SheetPassword( void );               // 0x13 sheet password
- 	void					Externsheet( void );			// 0x17
-+    void                    WinProtection( void );          // 0x19
- 	void					Note( void );					// 0x1C
- 	void					Columndefault( void );			// 0x20
- 	void					Array25( void );				// 0x21
-Index: sc/source/filter/inc/xcl97rec.hxx
+Index: source/filter/inc/xcl97rec.hxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xcl97rec.hxx,v
-retrieving revision 1.49
-retrieving revision 1.47.338.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.49 -r1.47.338.4
---- sc/source/filter/inc/xcl97rec.hxx	2 Jul 2008 09:24:16 -0000	1.49
-+++ sc/source/filter/inc/xcl97rec.hxx	17 Jul 2008 01:00:32 -0000	1.47.338.4
+--- sc/source/filter/inc/xcl97rec.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xcl97rec.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -35,6 +35,8 @@
  #include "xcl97esc.hxx"
  #include "xlstyle.hxx"
@@ -2615,7 +1975,7 @@
  };
  
  
-@@ -484,23 +480,24 @@
+@@ -456,23 +452,24 @@
      virtual sal_Size            GetLen() const;
  };
  
@@ -2651,12 +2011,12 @@
  
  class XclCalccount : public ExcRecord
  {
-@@ -556,5 +553,162 @@
+@@ -528,5 +525,162 @@
                                  XclRefmode( const ScDocument& );
  };
  
 +// ============================================================================
-+
+ 
 +class XclExpFilePass : public XclExpRecord
 +{
 +public:
@@ -2812,16 +2172,12 @@
 +    explicit XclExpUnknown0863();
 +};
 +
- 
++
  #endif // _XCL97REC_HXX
-Index: sc/source/filter/inc/xeroot.hxx
+Index: source/filter/inc/xeroot.hxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xeroot.hxx,v
-retrieving revision 1.21
-retrieving revision 1.20.380.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.21 -r1.20.380.5
---- sc/source/filter/inc/xeroot.hxx	10 Apr 2008 20:45:28 -0000	1.21
-+++ sc/source/filter/inc/xeroot.hxx	22 May 2008 21:42:40 -0000	1.20.380.5
+--- sc/source/filter/inc/xeroot.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xeroot.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -154,7 +154,12 @@
          @param nRecId  Identifier that specifies which record is returned. */
      XclExpRecordRef     CreateRecord( sal_uInt16 nRecId ) const;
@@ -2835,36 +2191,137 @@
      /** Returns the local or global link manager, depending on current context. */
      XclExpRootData::XclExpLinkMgrRef GetLocalLinkMgrRef() const;
  
-Index: sc/source/filter/inc/xestream.hxx
+Index: source/filter/inc/xiroot.hxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xestream.hxx,v
-retrieving revision 1.8
-retrieving revision 1.7.494.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.8 -r1.7.494.3
---- sc/source/filter/inc/xestream.hxx	10 Apr 2008 20:45:44 -0000	1.8
-+++ sc/source/filter/inc/xestream.hxx	6 May 2008 23:28:00 -0000	1.7.494.3
-@@ -35,6 +35,9 @@
+--- sc/source/filter/inc/xiroot.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xiroot.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -61,6 +61,8 @@
+ class XclImpPageSettings;
+ class XclImpDocViewSettings;
+ class XclImpTabViewSettings;
++class XclImpSheetProtectBuffer;
++class XclImpDocProtectBuffer;
  
- #include "xlstream.hxx"
+ class _ScRangeListTabs;
+ class ExcelToSc;
+@@ -87,6 +89,8 @@
+     typedef ScfRef< XclImpPageSettings >        XclImpPageSettRef;
+     typedef ScfRef< XclImpDocViewSettings >     XclImpDocViewSettRef;
+     typedef ScfRef< XclImpTabViewSettings >     XclImpTabViewSettRef;
++    typedef ScfRef< XclImpSheetProtectBuffer >  XclImpTabProtectRef;
++    typedef ScfRef< XclImpDocProtectBuffer >    XclImpDocProtectRef;
  
-+#include <svx/mscodec.hxx>
-+#include <vector>
+     XclImpAddrConvRef   mxAddrConv;         /// The address converter.
+     XclImpFmlaCompRef   mxFmlaComp;         /// The formula compiler.
+@@ -110,7 +114,12 @@
+     XclImpPageSettRef   mxPageSett;         /// Page settings for current sheet.
+     XclImpDocViewSettRef mxDocViewSett;     /// View settings for entire document.
+     XclImpTabViewSettRef mxTabViewSett;     /// View settings for current sheet.
++    XclImpTabProtectRef mxTabProtect;       /// Sheet protection options for current sheet.
++    XclImpDocProtectRef mxDocProtect;       /// Document protection options.
+ 
++    String              maPassw;            /// Entered password for stream decryption.
++    bool                mbPassQueried;      /// true = Password already querried.
 +
- /* ============================================================================
- Output stream class for Excel export
- - CONTINUE record handling
-@@ -42,6 +45,8 @@
- ============================================================================ */
+     bool                mbHasCodePage;      /// true = CODEPAGE record exists.
  
- class XclExpRoot;
-+class XclExpBiff8Encrypter;
-+typedef ScfRef< XclExpBiff8Encrypter > XclExpEncrypterRef;
+     explicit            XclImpRootData( XclBiff eBiff, SfxMedium& rMedium,
+@@ -181,6 +190,10 @@
+     XclImpWebQueryBuffer& GetWebQueryBuffer() const;
+     /** Returns the pivot table manager. */
+     XclImpPivotTableManager& GetPivotTableManager() const;
++    /** Returns the sheet protection options of the current sheet. */
++    XclImpSheetProtectBuffer& GetSheetProtectBuffer() const;
++    /** Returns the document protection options. */
++    XclImpDocProtectBuffer& GetDocProtectBuffer() const;
  
- /** This class is used to export Excel record streams.
-     @descr  An instance is constructed with an SvStream and the maximum size of Excel
-@@ -100,14 +105,14 @@
-     /** Sets data slice length. 0 = no slices. */
-     void                SetSliceSize( sal_uInt16 nSize );
+     /** Returns the page settings of the current sheet. */
+     XclImpPageSettings& GetPageSettings() const;
+@@ -192,6 +205,9 @@
+     /** Returns the Calc add-in function name for an Excel function name. */
+     String              GetScAddInName( const String& rXclName ) const;
+ 
++    /** Queries a password from the user and returns it (empty string -> input cancelled). */
++    const String&       QueryPassword() const;
++
+ private:
+     mutable XclImpRootData& mrImpData;      /// Reference to the global import data struct.
+ };
+Index: source/filter/inc/xlroot.hxx
+===================================================================
+--- sc/source/filter/inc/xlroot.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xlroot.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -91,7 +91,6 @@
+     ScDocument&         mrDoc;              /// The source or destination document.
+     String              maDocUrl;           /// Document URL of imported/exported file.
+     String              maBasePath;         /// Base path of imported/exported file (path of maDocUrl).
+-    String              maPassw;            /// Entered password for stream encryption/decryption.
+     rtl_TextEncoding    meTextEnc;          /// Text encoding to import/export byte strings.
+     LanguageType        meSysLang;          /// System language.
+     LanguageType        meDocLang;          /// Document language (import: from file, export: from system).
+@@ -115,7 +114,6 @@
+     long                mnCharWidth;        /// Width of '0' in default font (twips).
+     SCTAB               mnScTab;            /// Current Calc sheet index.
+     const bool          mbExport;           /// false = Import, true = Export.
+-    bool                mbHasPassw;         /// true = Password already querried.
+ 
+     explicit            XclRootData( XclBiff eBiff, SfxMedium& rMedium,
+                             SotStorageRef xRootStrg, ScDocument& rDoc,
+@@ -181,8 +179,6 @@
+     inline const String& GetDocUrl() const { return mrData.maDocUrl; }
+     /** Returns the base path of the imported/exported file. */
+     inline const String& GetBasePath() const { return mrData.maBasePath; }
+-    /** Queries a password from the user and returns it (empty string -> input cancelled). */
+-    const String&       QueryPassword() const;
+ 
+     /** Returns the OLE2 root storage of the imported/exported file.
+         @return  Pointer to root storage or 0, if the file is a simple stream. */
+Index: source/filter/inc/excimp8.hxx
+===================================================================
+--- sc/source/filter/inc/excimp8.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/excimp8.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -61,7 +61,6 @@
+         void                    Precision( void );              // 0x0E
+ 		void					Delta( void );					// 0x10
+ 		void					Iteration( void );				// 0x11
+-		void					WinProtection(	void );         // 0x19
+ 		void					Boundsheet( void );				// 0x85
+ 		void					FilterMode( void );				// 0x9B
+ 		void					AutoFilterInfo( void );			// 0x9D
+@@ -73,6 +72,7 @@
+ 
+ 		void					Hlink( void );					// 0x01B8
+ 		void					Codename( BOOL bWBGlobals );	// 0x01BA
++        void                    SheetProtection( void );        // 0x0867
+ 
+         virtual void            EndSheet( void );
+ 		virtual void			PostDocLoad( void );
+Index: source/filter/inc/xestream.hxx
+===================================================================
+--- sc/source/filter/inc/xestream.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xestream.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -35,6 +35,9 @@
+ 
+ #include "xlstream.hxx"
+ 
++#include <svx/mscodec.hxx>
++#include <vector>
++
+ /* ============================================================================
+ Output stream class for Excel export
+ - CONTINUE record handling
+@@ -42,6 +45,8 @@
+ ============================================================================ */
+ 
+ class XclExpRoot;
++class XclExpBiff8Encrypter;
++typedef ScfRef< XclExpBiff8Encrypter > XclExpEncrypterRef;
+ 
+ /** This class is used to export Excel record streams.
+     @descr  An instance is constructed with an SvStream and the maximum size of Excel
+@@ -100,14 +105,14 @@
+     /** Sets data slice length. 0 = no slices. */
+     void                SetSliceSize( sal_uInt16 nSize );
  
 -    inline XclExpStream& operator<<( sal_Int8 nValue );
 -    inline XclExpStream& operator<<( sal_uInt8 nValue );
@@ -2885,7 +2342,7 @@
  
      /** Writes nBytes bytes from memory. */
      sal_Size            Write( const void* pData, sal_Size nBytes );
-@@ -148,6 +153,14 @@
+@@ -150,6 +155,14 @@
      /** Returns the absolute position of the system stream. */
      inline sal_Size     GetSvStreamPos() const { return mrStrm.Tell(); }
  
@@ -2900,7 +2357,7 @@
  private:
      /** Writes header data, internal setup. */
      void                InitRecord( sal_uInt16 nRecId );
-@@ -170,6 +183,9 @@
+@@ -172,6 +185,9 @@
      SvStream&           mrStrm;         /// Reference to the system output stream.
      const XclExpRoot&   mrRoot;         /// Filter root data.
  
@@ -2910,7 +2367,7 @@
                          // length data
      sal_uInt16          mnMaxRecSize;   /// Maximum size of record content.
      sal_uInt16          mnMaxContSize;  /// Maximum size of CONTINUE content.
-@@ -187,64 +203,51 @@
+@@ -189,64 +205,51 @@
  
  // ----------------------------------------------------------------------------
  
@@ -2992,7 +2449,7 @@
 +private:
 +    void Init( const String& aPass, const sal_uInt8 nDocId[16], 
 +               const sal_uInt8 nSalt[16] );
-+
+ 
 +    sal_uInt32 GetBlockPos( sal_Size nStrmPos ) const;
 +    sal_uInt16 GetOffsetInBlock( sal_Size nStrmPos ) const;
 +
@@ -3007,174 +2464,13 @@
 +    sal_Size            mnOldPos;      /// Last known stream position
 +    bool                mbValid;
 +};
- 
- #endif
- 
-Index: sc/source/filter/inc/xetable.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xetable.hxx,v
-retrieving revision 1.11
-retrieving revision 1.10.80.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.11 -r1.10.80.2
---- sc/source/filter/inc/xetable.hxx	10 Apr 2008 20:46:38 -0000	1.11
-+++ sc/source/filter/inc/xetable.hxx	6 May 2008 23:27:41 -0000	1.10.80.2
-@@ -1069,7 +1069,5 @@
-     XclExpDvalRef       mxDval;             /// Data validation with DVAL and DV records.
- };
- 
--// ============================================================================
--
- #endif
- 
-Index: sc/source/filter/inc/xicontent.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xicontent.hxx,v
-retrieving revision 1.16
-retrieving revision 1.15.80.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.16 -r1.15.80.2
---- sc/source/filter/inc/xicontent.hxx	10 Apr 2008 20:47:26 -0000	1.16
-+++ sc/source/filter/inc/xicontent.hxx	6 May 2008 23:28:03 -0000	1.15.80.2
-@@ -37,6 +37,8 @@
- #include "xistring.hxx"
- #include "xiroot.hxx"
- 
-+#include <map>
-+
- /* ============================================================================
- Classes to import the big Excel document contents (related to several cells or
- globals for the document).
-@@ -249,5 +251,64 @@
- 
- // ============================================================================
- 
-+// Document protection ========================================================
-+
-+class XclImpDocProtectBuffer : protected XclImpRoot
-+{
-+public:
-+    explicit            XclImpDocProtectBuffer( const XclImpRoot& rRoot );
-+
-+    /** document structure protection flag  */
-+    void                ReadDocProtect( XclImpStream& rStrm );
-+
-+    /** document windows properties protection flag */
-+    void                ReadWinProtect( XclImpStream& rStrm );
-+
-+    void                ReadPasswordHash( XclImpStream& rStrm );
-+
-+    void                Apply() const;
-+
-+private:
-+    sal_uInt16      mnPassHash;
-+    bool            mbDocProtect:1;
-+    bool            mbWinProtect:1;
-+};
-+
-+// Sheet protection ===========================================================
-+
-+class XclImpSheetProtectBuffer : protected XclImpRoot
-+{
-+public:
-+    explicit            XclImpSheetProtectBuffer( const XclImpRoot& rRoot );
-+
-+    void                ReadProtect( XclImpStream& rStrm, SCTAB nTab );
-+
-+    void                ReadOptions( XclImpStream& rStrm, SCTAB nTab );
-+
-+    void                ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab );
-+
-+    void                Apply() const;
-+
-+private:
-+    struct Sheet
-+    {
-+        bool        mbProtected;
-+        sal_uInt16  mnPasswordHash;
-+        sal_uInt16  mnOptions;
-+
-+        Sheet();
-+        Sheet(const Sheet& r);
-+    };
-+
-+    Sheet* GetSheetItem( SCTAB nTab );
-+
-+private:
-+    typedef ::std::map<SCTAB, Sheet> ProtectedSheetMap;
-+    ProtectedSheetMap   maProtectedSheets;
-+};
-+
-+
-+// ============================================================================
 +
  #endif
  
-Index: sc/source/filter/inc/xiroot.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xiroot.hxx,v
-retrieving revision 1.22
-retrieving revision 1.21.380.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.22 -r1.21.380.3
---- sc/source/filter/inc/xiroot.hxx	10 Apr 2008 20:49:45 -0000	1.22
-+++ sc/source/filter/inc/xiroot.hxx	6 May 2008 23:28:11 -0000	1.21.380.3
-@@ -61,6 +61,8 @@
- class XclImpPageSettings;
- class XclImpDocViewSettings;
- class XclImpTabViewSettings;
-+class XclImpSheetProtectBuffer;
-+class XclImpDocProtectBuffer;
- 
- class _ScRangeListTabs;
- class ExcelToSc;
-@@ -87,6 +89,8 @@
-     typedef ScfRef< XclImpPageSettings >        XclImpPageSettRef;
-     typedef ScfRef< XclImpDocViewSettings >     XclImpDocViewSettRef;
-     typedef ScfRef< XclImpTabViewSettings >     XclImpTabViewSettRef;
-+    typedef ScfRef< XclImpSheetProtectBuffer >  XclImpTabProtectRef;
-+    typedef ScfRef< XclImpDocProtectBuffer >    XclImpDocProtectRef;
- 
-     XclImpAddrConvRef   mxAddrConv;         /// The address converter.
-     XclImpFmlaCompRef   mxFmlaComp;         /// The formula compiler.
-@@ -110,6 +114,11 @@
-     XclImpPageSettRef   mxPageSett;         /// Page settings for current sheet.
-     XclImpDocViewSettRef mxDocViewSett;     /// View settings for entire document.
-     XclImpTabViewSettRef mxTabViewSett;     /// View settings for current sheet.
-+    XclImpTabProtectRef mxTabProtect;       /// Sheet protection options for current sheet.
-+    XclImpDocProtectRef mxDocProtect;       /// Document protection options.
-+
-+    String              maPassw;            /// Entered password for stream decryption.
-+    bool                mbPassQueried;      /// true = Password already querried.
- 
-     bool                mbHasCodePage;      /// true = CODEPAGE record exists.
- 
-@@ -181,6 +190,10 @@
-     XclImpWebQueryBuffer& GetWebQueryBuffer() const;
-     /** Returns the pivot table manager. */
-     XclImpPivotTableManager& GetPivotTableManager() const;
-+    /** Returns the sheet protection options of the current sheet. */
-+    XclImpSheetProtectBuffer& GetSheetProtectBuffer() const;
-+    /** Returns the document protection options. */
-+    XclImpDocProtectBuffer& GetDocProtectBuffer() const;
- 
-     /** Returns the page settings of the current sheet. */
-     XclImpPageSettings& GetPageSettings() const;
-@@ -192,6 +205,9 @@
-     /** Returns the Calc add-in function name for an Excel function name. */
-     String              GetScAddInName( const String& rXclName ) const;
- 
-+    /** Queries a password from the user and returns it (empty string -> input cancelled). */
-+    const String&       QueryPassword() const;
-+
- private:
-     mutable XclImpRootData& mrImpData;      /// Reference to the global import data struct.
- };
-Index: sc/source/filter/inc/xistream.hxx
+Index: source/filter/inc/xistream.hxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xistream.hxx,v
-retrieving revision 1.13
-retrieving revision 1.12.324.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.13 -r1.12.324.4
---- sc/source/filter/inc/xistream.hxx	10 Apr 2008 20:50:03 -0000	1.13
-+++ sc/source/filter/inc/xistream.hxx	22 May 2008 23:56:25 -0000	1.12.324.4
+--- sc/source/filter/inc/xistream.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/xistream.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -73,6 +73,8 @@
          @return  Count of bytes really read. */
      sal_uInt16          Read( SvStream& rStrm, void* pData, sal_uInt16 nBytes );
@@ -3201,61 +2497,57 @@
      ErrCode             mnError;        /// Decrypter error code.
      sal_Size            mnOldPos;       /// Last known stream position.
      sal_uInt16          mnRecSize;      /// Current record size.
-Index: sc/source/filter/inc/xlroot.hxx
+Index: source/filter/inc/excrecds.hxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/inc/xlroot.hxx,v
-retrieving revision 1.31
-retrieving revision 1.30.238.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.31 -r1.30.238.2
---- sc/source/filter/inc/xlroot.hxx	10 Apr 2008 20:54:26 -0000	1.31
-+++ sc/source/filter/inc/xlroot.hxx	6 May 2008 23:27:47 -0000	1.30.238.2
-@@ -91,7 +91,6 @@
-     ScDocument&         mrDoc;              /// The source or destination document.
-     String              maDocUrl;           /// Document URL of imported/exported file.
-     String              maBasePath;         /// Base path of imported/exported file (path of maDocUrl).
--    String              maPassw;            /// Entered password for stream encryption/decryption.
-     rtl_TextEncoding    meTextEnc;          /// Text encoding to import/export byte strings.
-     LanguageType        meSysLang;          /// System language.
-     LanguageType        meDocLang;          /// Document language (import: from file, export: from system).
-@@ -115,7 +114,6 @@
-     long                mnCharWidth;        /// Width of '0' in default font (twips).
-     SCTAB               mnScTab;            /// Current Calc sheet index.
-     const bool          mbExport;           /// false = Import, true = Export.
--    bool                mbHasPassw;         /// true = Password already querried.
- 
-     explicit            XclRootData( XclBiff eBiff, SfxMedium& rMedium,
-                             SotStorageRef xRootStrg, ScDocument& rDoc,
-@@ -181,8 +179,6 @@
-     inline const String& GetDocUrl() const { return mrData.maDocUrl; }
-     /** Returns the base path of the imported/exported file. */
-     inline const String& GetBasePath() const { return mrData.maBasePath; }
--    /** Queries a password from the user and returns it (empty string -> input cancelled). */
--    const String&       QueryPassword() const;
+--- sc/source/filter/inc/excrecds.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/inc/excrecds.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -244,13 +244,26 @@
+ };
  
-     /** Returns the OLE2 root storage of the imported/exported file.
-         @return  Pointer to root storage or 0, if the file is a simple stream. */
-Index: sc/source/filter/starcalc/scflt.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/starcalc/scflt.cxx,v
-retrieving revision 1.25
-retrieving revision 1.24.26.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.25 -r1.24.26.2
---- sc/source/filter/starcalc/scflt.cxx	10 Apr 2008 21:04:01 -0000	1.25
-+++ sc/source/filter/starcalc/scflt.cxx	6 May 2008 23:29:31 -0000	1.24.26.2
-@@ -1148,9 +1148,9 @@
- 	//rStream.Read(&SheetProtect, sizeof(SheetProtect));
- 	lcl_ReadSheetProtect(rStream, SheetProtect);
- 	nError = rStream.GetError();
--	uno::Sequence<sal_Int8> aPass;
--	SvPasswordHelper::GetHashPassword(aPass, SC10TOSTRING( SheetProtect.PassWord ));
--	pDoc->SetDocProtection( SheetProtect.Protect,  aPass);
-+//  uno::Sequence<sal_Int8> aPass;
-+//  SvPasswordHelper::GetHashPassword(aPass, SC10TOSTRING( SheetProtect.PassWord ));
-+//  pDoc->SetDocProtection( SheetProtect.Protect, SC10TOSTRING( SheetProtect.PassWord ));
- }
+ // EXC_ID_PROTECT  Document Protection
+-class XclExpDocProtection : public	XclExpBoolRecord
++class XclExpProtection : public	XclExpBoolRecord
+ {
+ 	public:
+-		XclExpDocProtection(bool bValue);
++		XclExpProtection(bool bValue);
+ };
  
++class XclExpPassHash : public XclExpRecord
++{
++public:
++    XclExpPassHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aHash);
++    virtual ~XclExpPassHash();
+ 
++private:
++    virtual void    WriteBody(XclExpStream& rStrm);
++
++private:
++    sal_uInt16  mnHash;
++};
++
++
+ //-------------------------------------------------------- class ExcDummy_04x -
+ // PASSWORD to BOOKBOOL (see excrecds.cxx), no 1904
+ 
+Index: source/filter/starcalc/scflt.cxx
+===================================================================
+--- sc/source/filter/starcalc/scflt.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/filter/starcalc/scflt.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -1087,9 +1087,9 @@
+ 	//rStream.Read(&SheetProtect, sizeof(SheetProtect));
+ 	lcl_ReadSheetProtect(rStream, SheetProtect);
+ 	nError = rStream.GetError();
+-	uno::Sequence<sal_Int8> aPass;
+-	SvPasswordHelper::GetHashPassword(aPass, SC10TOSTRING( SheetProtect.PassWord ));
+-	pDoc->SetDocProtection( SheetProtect.Protect,  aPass);
++//  uno::Sequence<sal_Int8> aPass;
++//  SvPasswordHelper::GetHashPassword(aPass, SC10TOSTRING( SheetProtect.PassWord ));
++//  pDoc->SetDocProtection( SheetProtect.Protect, SC10TOSTRING( SheetProtect.PassWord ));
+ }
  
-@@ -1502,10 +1502,10 @@
+ 
+@@ -1441,10 +1441,10 @@
  
  		//rStream.Read(&TabProtect, sizeof(TabProtect));
  		lcl_ReadTabProtect(rStream, TabProtect);
@@ -3269,654 +2561,793 @@
  
  		rStream >> TabNo;
  
-Index: sc/source/filter/xcl97/XclExpChangeTrack.cxx
+Index: source/core/data/table1.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/xcl97/XclExpChangeTrack.cxx,v
-retrieving revision 1.26
-retrieving revision 1.25.324.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.26 -r1.25.324.2
---- sc/source/filter/xcl97/XclExpChangeTrack.cxx	10 Apr 2008 21:04:41 -0000	1.26
-+++ sc/source/filter/xcl97/XclExpChangeTrack.cxx	6 May 2008 23:29:27 -0000	1.25.324.2
-@@ -491,6 +491,7 @@
+--- sc/source/core/data/table1.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/table1.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -114,6 +114,7 @@
+ #include "progress.hxx"
+ #include "hints.hxx"		// fuer Paint-Broadcast
+ #include "prnsave.hxx"
++#include "tabprotection.hxx"
  
- void XclExpChTrTabId::SaveCont( XclExpStream& rStrm )
- {
-+    rStrm.EnableEncryption();
- 	if( pBuffer )
- 		for( sal_uInt16* pElem = pBuffer; pElem < (pBuffer + nTabCount); pElem++ )
- 			rStrm << *pElem;
-Index: sc/source/filter/xcl97/makefile.mk
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/xcl97/makefile.mk,v
-retrieving revision 1.16
-retrieving revision 1.15.324.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.16 -r1.15.324.2
---- sc/source/filter/xcl97/makefile.mk	10 Apr 2008 21:05:15 -0000	1.16
-+++ sc/source/filter/xcl97/makefile.mk	6 May 2008 23:29:23 -0000	1.15.324.2
-@@ -50,7 +50,6 @@
- # --- Files --------------------------------------------------------
+ // STATIC DATA -----------------------------------------------------------
  
- SLOFILES =									\
--		$(SLO)$/xcl97dum.obj				\
- 		$(SLO)$/xcl97esc.obj				\
- 		$(SLO)$/xcl97rec.obj				\
- 		$(SLO)$/XclImpChangeTrack.obj		\
-Index: sc/source/filter/xcl97/xcl97rec.cxx
+@@ -132,7 +133,7 @@
+ 	bPageSizeValid( FALSE ),
+ 	nRepeatStartX( SCCOL_REPEAT_NONE ),
+ 	nRepeatStartY( SCROW_REPEAT_NONE ),
+-	bProtected( FALSE ),
++    pTabProtection( NULL ),
+ 	pColWidth( NULL ),
+ 	pRowHeight( NULL ),
+ 	pColFlags( NULL ),
+Index: source/core/data/table2.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/xcl97/xcl97rec.cxx,v
-retrieving revision 1.88
-retrieving revision 1.86.292.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.88 -r1.86.292.4
---- sc/source/filter/xcl97/xcl97rec.cxx	2 Jul 2008 09:27:32 -0000	1.88
-+++ sc/source/filter/xcl97/xcl97rec.cxx	17 Jul 2008 01:00:57 -0000	1.86.292.4
-@@ -78,6 +78,7 @@
- #include "scextopt.hxx"
- #include "docoptio.hxx"
- #include "patattr.hxx"
-+#include "tabprotection.hxx"
- 
- using ::rtl::OUString;
- using namespace ::com::sun::star;
-@@ -132,9 +133,9 @@
+--- sc/source/core/data/table2.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/table2.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -292,7 +292,7 @@
+ 			// Zellschutz auf geschuetzter Tabelle nicht setzen
+ 			//
  
- // --- class XclMsodrawinggroup --------------------------------------
+-		if ( bProtected && (nDelFlag & IDF_ATTRIB) )
++		if ( IsProtected() && (nDelFlag & IDF_ATTRIB) )
+ 		{
+ 			ScPatternAttr aPattern(pDocument->GetPool());
+ 			aPattern.GetItemSet().Put( ScProtectionAttr( FALSE ) );
+@@ -318,7 +318,7 @@
+ 		// Zellschutz auf geschuetzter Tabelle nicht setzen
+ 		//
  
--XclMsodrawinggroup::XclMsodrawinggroup( RootData& rRoot, UINT16 nEscherType )
--		:
--		XclMsodrawing_Base( *rRoot.pEscher )
-+XclMsodrawinggroup::XclMsodrawinggroup( RootData& rRoot, UINT16 nEscherType ) :
-+    XclMsodrawing_Base( *rRoot.pEscher ),
-+    XclExpRecord(0x00EB, 2) // bogus record size since we don't know the actual size yet.
- {
- 	if ( nEscherType )
+-	if ( bProtected && (nDelFlag & IDF_ATTRIB) )
++	if ( IsProtected() && (nDelFlag & IDF_ATTRIB) )
  	{
-@@ -179,7 +180,7 @@
- }
+ 		ScDocumentPool* pPool = pDocument->GetPool();
+ 		SfxItemSet aSet( *pPool, ATTR_PATTERN_START, ATTR_PATTERN_END );
+@@ -361,7 +361,7 @@
  
+ 		//	ggf. Formeln durch Werte ersetzen
  
--void XclMsodrawinggroup::SaveCont( XclExpStream& rStrm )
-+void XclMsodrawinggroup::WriteBody( XclExpStream& rStrm )
- {
-     DBG_ASSERT( GetEscherEx()->GetStreamPos() == GetEscherEx()->GetOffsetFromMap( nStartPos ),
- 		"XclMsodrawinggroup::SaveCont: Escher stream position mismatch" );
-@@ -187,23 +188,11 @@
- }
+-		if (bProtected)
++		if ( IsProtected() )
+ 			for (i = nCol1; i <= nCol2; i++)
+ 				pTable->aCol[i].RemoveProtected(nRow1, nRow2);
+ 	}
+@@ -406,7 +406,7 @@
+ 				// Zellschutz auf geschuetzter Tabelle nicht setzen
+ 				//
  
+-			if ( bProtected && (nInsFlag & IDF_ATTRIB) )
++			if ( IsProtected() && (nInsFlag & IDF_ATTRIB) )
+ 			{
+ 				ScPatternAttr aPattern(pDocument->GetPool());
+ 				aPattern.GetItemSet().Put( ScProtectionAttr( FALSE ) );
+@@ -1436,7 +1436,7 @@
+ 	BOOL bIsEditable = TRUE;
+ 	if ( nLockCount )
+ 		bIsEditable = FALSE;
+-    else if ( bProtected && !pDocument->IsScenario(nTab) )
++    else if ( IsProtected() && !pDocument->IsScenario(nTab) )
+     {
+         if((bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, HASATTR_PROTECTED )) != FALSE)
+         {
+@@ -1503,7 +1503,7 @@
+ 	BOOL bIsEditable = TRUE;
+ 	if ( nLockCount )
+ 		bIsEditable = FALSE;
+-    else if ( bProtected && !pDocument->IsScenario(nTab))
++    else if ( IsProtected() && !pDocument->IsScenario(nTab) )
+     {
+         if((bIsEditable = !HasAttribSelection( rMark, HASATTR_PROTECTED )) != FALSE)
+         {
+Index: source/core/data/table5.cxx
+===================================================================
+--- sc/source/core/data/table5.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/table5.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -51,8 +51,11 @@
+ #include "stlpool.hxx"
+ #include "stlsheet.hxx"
+ #include "brdcst.hxx"
++#include "tabprotection.hxx"
+ #include "globstr.hrc"
  
--UINT16 XclMsodrawinggroup::GetNum() const
--{
--	return 0x00EB;
--}
--
--
--sal_Size XclMsodrawinggroup::GetLen() const
--{
--    return GetDataLen();
--}
--
--
--
- // --- class XclMsodrawing --------------------------------------
++using ::com::sun::star::uno::Sequence;
++
+ // STATIC DATA -----------------------------------------------------------
  
- XclMsodrawing::XclMsodrawing( const XclExpRoot& rRoot, UINT16 nEscherType, sal_Size nInitialSize ) :
--    XclMsodrawing_Base( *rRoot.GetOldRoot().pEscher, nInitialSize )
-+    XclMsodrawing_Base( *rRoot.GetOldRoot().pEscher, nInitialSize ),
-+    XclExpRecord( 0x00EC, nInitialSize )
- {
- 	if ( nEscherType )
- 	{
-@@ -229,7 +218,7 @@
+ #define GET_SCALEVALUE(set,id) 	((const SfxUInt16Item&)(set.Get( id ))).GetValue()
+@@ -273,6 +276,42 @@
+ 		bPageSizeValid = FALSE;
  }
  
- 
--void XclMsodrawing::SaveCont( XclExpStream& rStrm )
-+void XclMsodrawing::WriteBody( XclExpStream& rStrm )
++BOOL ScTable::IsProtected() const
++{
++    return pTabProtection.get() && pTabProtection->isProtected();
++}
++
++void ScTable::SetProtection(BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd)
++{
++    if (!pTabProtection.get())
++        pTabProtection.reset(new ScTableProtection);
++
++    pTabProtection->setProtected( bProtect );
++    pTabProtection->setPasswordHash(rPasswd, PASSHASH_OOO);
++}
++
++void ScTable::SetProtection(bool bProtect, const String& aPassText)
++{
++    if (!pTabProtection.get())
++        pTabProtection.reset(new ScTableProtection);
++
++    pTabProtection->setProtected( bProtect );
++    pTabProtection->setPassword(aPassText);
++}
++
++void ScTable::SetProtection(const ScTableProtection* pProtect)
++{
++    if (pProtect)
++        pTabProtection.reset(new ScTableProtection(*pProtect));
++    else
++        pTabProtection.reset(NULL);
++}
++
++ScTableProtection* ScTable::GetProtection()
++{
++    return pTabProtection.get();
++}
++
+ Size ScTable::GetPageSize() const
  {
-     DBG_ASSERT( GetEscherEx()->GetStreamPos() == GetEscherEx()->GetOffsetFromMap( nStartPos ),
- 		"XclMsodrawing::SaveCont: Escher stream position mismatch" );
-@@ -237,16 +226,6 @@
- }
- 
+ 	if ( bPageSizeValid )
+Index: source/core/data/documen2.cxx
+===================================================================
+--- sc/source/core/data/documen2.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/documen2.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -93,6 +93,7 @@
+ #include "listenercalls.hxx"
+ #include "recursionhelper.hxx"
+ #include "lookupcache.hxx"
++#include "tabprotection.hxx"
  
--UINT16 XclMsodrawing::GetNum() const
--{
--	return 0x00EC;
--}
--
--
--sal_Size XclMsodrawing::GetLen() const
--{
--    return GetDataLen();
--}
+ // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
+ // dtor plus helpers are convenient.
+@@ -150,6 +151,7 @@
+ 		pChangeViewSettings( NULL ),
+ 		pScriptTypeData( NULL ),
+         pCacheFieldEditEngine( NULL ),
++        pDocProtection( NULL ),
+ 		pViewOptions( NULL ),
+ 		pDocOptions( NULL ),
+ 		pExtDocOptions( NULL ),
+@@ -172,7 +174,6 @@
+ 		nHardRecalcState(0),
+ 		nVisibleTab( 0 ),
+ 		eLinkMode(LM_UNKNOWN),
+-		bProtected( FALSE ),
+ 		bAutoCalc( eMode == SCDOCMODE_DOCUMENT ),
+ 		bAutoCalcShellDisabled( FALSE ),
+ 		bForcedFormulaPending( FALSE ),
+Index: source/core/data/documen3.cxx
+===================================================================
+--- sc/source/core/data/documen3.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/documen3.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -78,6 +78,8 @@
+ #include "listenercalls.hxx"
+ #include "editutil.hxx"    // ScPostIt EditTextObject
+ #include "postit.hxx"
++#include "svtools/PasswordHelper.hxx"
++#include "tabprotection.hxx"
  
+ using namespace com::sun::star;
  
- // --- class XclObjList ----------------------------------------------
-@@ -883,6 +862,7 @@
+@@ -1689,28 +1691,37 @@
+         ScDrawLayer::MirrorRectRTL( rRect );        // back to real rectangle
+ }
  
- void ExcBof8_Base::SaveCont( XclExpStream& rStrm )
+-void ScDocument::SetDocProtection( BOOL bProtect, const uno::Sequence<sal_Int8>& rPasswd )
++ScDocProtection* ScDocument::GetDocProtection() const
  {
-+    rStrm.DisableEncryption();
- 	rStrm	<< nVers << nDocType << nRupBuild << nRupYear
- 			<< nFileHistory << nLowestBiffVer;
+-	bProtected = bProtect;
+-	aProtectPass = rPasswd;
++    return pDocProtection.get();
  }
-@@ -943,7 +923,10 @@
+ 
+-void ScDocument::SetTabProtection( SCTAB nTab, BOOL bProtect, const uno::Sequence<sal_Int8>& rPasswd )
++void ScDocument::SetDocProtection(bool bProtect, const String& aPassText)
  {
-     nOwnPos = rStrm.GetSvStreamPos();
-     // write dummy position, real position comes later
--    rStrm << sal_uInt32( 0 ) << nGrbit << aUnicodeName;
-+    rStrm.DisableEncryption();
-+    rStrm << sal_uInt32(0);
-+    rStrm.EnableEncryption();
-+    rStrm << nGrbit << aUnicodeName;
+-	if (VALIDTAB(nTab))
+-		if (pTab[nTab])
+-			pTab[nTab]->SetProtection( bProtect, rPasswd );
++    if (!pDocProtection.get())
++        pDocProtection.reset(new ScDocProtection);
++
++    pDocProtection->setProtected(bProtect);
++    pDocProtection->setPassword(aPassText);
  }
  
++void ScDocument::SetDocProtection(const ScDocProtection* pProtect)
++{
++    if (pProtect)
++        pDocProtection.reset(new ScDocProtection(*pProtect));
++    else
++        pDocProtection.reset(NULL);
++}
++
+ BOOL ScDocument::IsDocProtected() const
+ {
+-	return bProtected;
++    return pDocProtection.get() && pDocProtection->isProtected();
+ }
  
-@@ -1223,33 +1206,73 @@
- 	return 8;
+ BOOL ScDocument::IsDocEditable() const
+ {
+     // import into read-only document is possible
+-    return !bProtected && ( bImportingXML || mbChangeReadOnlyEnabled || !pShell || !pShell->IsReadOnly() );
++    return !IsDocProtected() && ( bImportingXML || mbChangeReadOnlyEnabled || !pShell || !pShell->IsReadOnly() );
  }
  
-+// ============================================================================
+ BOOL ScDocument::IsTabProtected( SCTAB nTab ) const
+@@ -1723,21 +1734,36 @@
+ 	return FALSE;
+ }
  
--
--// ---- class XclProtection ------------------------------------------
--
--const BYTE		XclProtection::pMyData[] =
-+struct XclExpTabProtectOption
+-const uno::Sequence<sal_Int8>& ScDocument::GetDocPassword() const
++ScTableProtection* ScDocument::GetTabProtection( SCTAB nTab ) const
  {
--	0x12, 0x00, 0x02, 0x00, 0x01, 0x00,			// PROTECT
--	0xDD, 0x00, 0x02, 0x00, 0x01, 0x00,			// SCENPROTECT
--	0x63, 0x00, 0x02, 0x00, 0x01, 0x00			// OBJPROTECT
-+    ScTableProtection::Option   eOption;
-+    sal_uInt16                  nMask;
- };
--const sal_Size XclProtection::nMyLen = sizeof( XclProtection::pMyData );
+-	return aProtectPass;
++    if (VALIDTAB(nTab) && pTab[nTab])
++        return pTab[nTab]->GetProtection();
++
++    return NULL;
+ }
  
--sal_Size XclProtection::GetLen( void ) const
-+XclExpSheetProtectOptions::XclExpSheetProtectOptions( const XclExpRoot& rRoot, SCTAB nTab ) :
-+    XclExpRecord( 0x0867, 23 )
+-const uno::Sequence<sal_Int8>& ScDocument::GetTabPassword( SCTAB nTab ) const
++void ScDocument::SetTabProtection(SCTAB nTab, bool bProtect, const String& aPassText)
  {
--	return nMyLen;
--}
--
-+    static const XclExpTabProtectOption aTable[] =
-+    {
-+        { ScTableProtection::OBJECTS,               0x0001 },
-+        { ScTableProtection::SCENARIOS,             0x0002 },
-+        { ScTableProtection::FORMAT_CELLS,          0x0004 },
-+        { ScTableProtection::FORMAT_COLUMNS,        0x0008 },
-+        { ScTableProtection::FORMAT_ROWS,           0x0010 },
-+        { ScTableProtection::INSERT_COLUMNS,        0x0020 },
-+        { ScTableProtection::INSERT_ROWS,           0x0040 },
-+        { ScTableProtection::INSERT_HYPERLINKS,     0x0080 },
-+
-+        { ScTableProtection::DELETE_COLUMNS,        0x0100 },
-+        { ScTableProtection::DELETE_ROWS,           0x0200 },
-+        { ScTableProtection::SELECT_LOCKED_CELLS,   0x0400 },
-+        { ScTableProtection::SORT,                  0x0800 },
-+        { ScTableProtection::AUTOFILTER,            0x1000 },
-+        { ScTableProtection::PIVOT_TABLES,          0x2000 },
-+        { ScTableProtection::SELECT_UNLOCKED_CELLS, 0x4000 },
-+
-+        { ScTableProtection::NONE,                  0x0000 }
-+    };
-+
-+    mnOptions = 0x0000;
-+    ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab);
-+    if (!pProtect)
-+        return;
+-	if (VALIDTAB(nTab))
+-		if (pTab[nTab])
+-			return pTab[nTab]->GetPassword();
++    if (ValidTab(nTab) && pTab[nTab])
++        pTab[nTab]->SetProtection(bProtect, aPassText);
++}
  
--const BYTE* XclProtection::GetData( void ) const
--{
--	return pMyData;
-+    for (int i = 0; aTable[i].nMask != 0x0000; ++i)
-+    {
-+        if ( pProtect->isOptionEnabled(aTable[i].eOption) )
-+            mnOptions |= aTable[i].nMask;
-+    }
+-	DBG_ERROR("Falsche Tabellennummer");
+-	return aProtectPass;
++void ScDocument::SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect)
++{
++    if (!ValidTab(nTab))
++        return;
++
++    pTab[nTab]->SetProtection(pProtect);
  }
  
-+void XclExpSheetProtectOptions::WriteBody( XclExpStream& rStrm )
++void ScDocument::CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest)
 +{
-+    sal_uInt16 nBytes = 0x0867;
-+    rStrm << nBytes;
- 
-+    sal_uChar nZero = 0x00;
-+    for (int i = 0; i < 9; ++i)
-+        rStrm << nZero;
- 
-+    nBytes = 0x0200;
-+    rStrm << nBytes;
-+    nBytes = 0x0100;
-+    rStrm << nBytes;
-+    nBytes = 0xFFFF;
-+    rStrm << nBytes << nBytes;
- 
-+    rStrm << mnOptions;
-+    nBytes = 0;
-+    rStrm << nBytes;
++    if (!ValidTab(nTabSrc) || !ValidTab(nTabDest))
++        return;
++
++    pTab[nTabDest]->SetProtection( pTab[nTabSrc]->GetProtection() );
 +}
++
+ const ScDocOptions& ScDocument::GetDocOptions() const
+ {
+ 	DBG_ASSERT( pDocOptions, "No DocOptions! :-(" );
+Index: source/core/data/document.cxx
+===================================================================
+--- sc/source/core/data/document.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/document.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -90,6 +90,7 @@
+ #include "autonamecache.hxx"
+ #include "bcaslot.hxx"
+ #include "postit.hxx"
++#include "tabprotection.hxx"
  
-+// ============================================================================
- 
- 
- 
-@@ -1337,3 +1360,250 @@
-     XclExpBoolRecord( 0x000F, rDoc.GetAddressConvention() != ScAddress::CONV_XL_R1C1 )
+ struct ScDefaultAttr
  {
- }
+Index: source/core/data/makefile.mk
+===================================================================
+--- sc/source/core/data/makefile.mk	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/core/data/makefile.mk	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -108,6 +108,7 @@
+ 	$(SLO)$/table4.obj \
+ 	$(SLO)$/table5.obj \
+ 	$(SLO)$/table6.obj \
++	$(SLO)$/tabprotection.obj \
+ 	$(SLO)$/userdat.obj \
+ 	$(SLO)$/validat.obj \
+ 	$(SLO)$/postit.obj
+Index: source/core/data/tabprotection.cxx
+===================================================================
+--- sc/source/core/data/tabprotection.cxx	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/core/data/tabprotection.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,463 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: tabprotection.cxx,v $
++ * $Revision: 1.1.4.7 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++// MARKER(update_precomp.py): autogen include statement, do not remove
++#include "precompiled_sc.hxx"
++
++// INCLUDE ---------------------------------------------------------------
++
++#include "tabprotection.hxx"
++#include "tools/debug.hxx"
++#include "svtools/PasswordHelper.hxx"
++#include "document.hxx"
++
++#define DEBUG_TAB_PROTECTION 0
++
++using namespace ::com::sun::star;
++using ::com::sun::star::uno::Sequence;
++using ::rtl::OUString;
 +
 +// ============================================================================
 +
-+XclExpFilePass::XclExpFilePass( const XclExpRoot& rRoot ) :
-+    XclExpRecord(0x002F, 54),
-+    mrRoot(rRoot)
++bool ScPassHashHelper::needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash)
 +{
++    if (rDoc.IsDocProtected())
++    {
++        const ScDocProtection* p = rDoc.GetDocProtection();
++        if (!p->isPasswordEmpty() && !p->hasPasswordHash(eHash))
++            return true;
++    }
++
++    SCTAB nTabCount = rDoc.GetTableCount();
++    for (SCTAB i = 0; i < nTabCount; ++i)
++    {
++        const ScTableProtection* p = rDoc.GetTabProtection(i);
++        if (!p || !p->isProtected())
++            // Sheet not protected.  Skip it.
++            continue;
++
++        if (!p->isPasswordEmpty() && !p->hasPasswordHash(eHash))
++            return true;
++    }
++
++    return false;
 +}
 +
-+XclExpFilePass::~XclExpFilePass()
++// ============================================================================
++
++ScPassHashProtectable::~ScPassHashProtectable()
 +{
 +}
 +
-+void XclExpFilePass::WriteBody( XclExpStream& rStrm )
-+{
-+    static const sal_uInt8 nDocId[] = {
-+        0x17, 0xf7, 0x01, 0x08, 0xea, 0xad, 0x30, 0x5c,
-+        0x1a, 0x95, 0xa5, 0x75, 0xd6, 0x79, 0xcd, 0x8d };
++// ============================================================================
 +
++static sal_uInt16 lcl_getXLHashFromChar(const sal_Char* szPassword)
++{
++    sal_uInt16 cchPassword = strlen(szPassword);
++    sal_uInt16 wPasswordHash = 0;
++    if (!cchPassword)
++        return wPasswordHash;
 +
-+    static const sal_uInt8 nSalt[] = {    
-+        0xa4, 0x5b, 0xf7, 0xe9, 0x9f, 0x55, 0x21, 0xc5, 
-+        0xc5, 0x56, 0xa8, 0x0d, 0x39, 0x05, 0x3a, 0xb4 };
-+
-+    // 0x0000 - neither standard nor strong encryption
-+    // 0x0001 - standard or strong encryption
-+    rStrm << static_cast<sal_uInt16>(0x0001);
++    const char* pch = &szPassword[cchPassword];
++    while (pch-- != szPassword)
++    {
++        wPasswordHash = ((wPasswordHash >> 14) & 0x01) | 
++                        ((wPasswordHash << 1) & 0x7fff);
++        wPasswordHash ^= *pch;
++    }
 +
-+    // 0x0000 - non standard encryption
-+    // 0x0001 - standard encryption
-+    sal_uInt16 nStdEnc = 0x0001;
-+    rStrm << nStdEnc << nStdEnc;
++    wPasswordHash = ((wPasswordHash >> 14) & 0x01) | 
++                    ((wPasswordHash << 1) & 0x7fff);
 +
-+    sal_uInt8 nSaltHash[16];
-+    XclExpEncrypterRef xEnc( new XclExpBiff8Encrypter(mrRoot, nDocId, nSalt) );
-+    xEnc->GetSaltDigest(nSaltHash);
++    wPasswordHash ^= (0x8000 | ('N' << 8) | 'K');
++    wPasswordHash ^= cchPassword;
 +
-+    rStrm.Write(nDocId, 16);
-+    rStrm.Write(nSalt, 16);
-+    rStrm.Write(nSaltHash, 16);
++    return wPasswordHash;
++}
 +
-+    rStrm.SetEncrypter(xEnc);
++static Sequence<sal_Int8> lcl_getXLHash(const String& aPassText)
++{
++    const sal_Char* szBuf = OUStringToOString(OUString(aPassText), RTL_TEXTENCODING_UTF8).getStr();
++    sal_uInt16 nHash = lcl_getXLHashFromChar(szBuf);
++    Sequence<sal_Int8> aHash(2);
++    aHash[0] = (nHash >> 8) & 0xFF;
++    aHash[1] = nHash & 0xFF;
++    return aHash;
 +}
 +
-+// ============================================================================
++class ScTableProtectionImpl
++{
++public:
++    static ::com::sun::star::uno::Sequence<sal_Int8> hashPassword(const String& aPassText, ScPasswordHash eHash = PASSHASH_OOO);
 +
-+XclExpFnGroupCount::XclExpFnGroupCount() :
-+    XclExpRecord(0x009C, 2)
++    explicit ScTableProtectionImpl(SCSIZE nOptSize);
++    explicit ScTableProtectionImpl(const ScTableProtectionImpl& r);
++
++    bool isProtected() const;
++    bool isProtectedWithPass() const;
++    void setProtected(bool bProtected);
++
++    bool isPasswordEmpty() const;
++    bool hasPasswordHash(ScPasswordHash eHash) const;
++    void setPassword(const String& aPassText);
++    ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
++    void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash = PASSHASH_OOO);
++    bool verifyPassword(const String& aPassText) const;
++    
++    bool isOptionEnabled(SCSIZE nOptId) const;
++    void setOption(SCSIZE nOptId, bool bEnabled);
++
++private:
++    String maPassText;
++    ::com::sun::star::uno::Sequence<sal_Int8>   maPassHash;
++    ::std::vector<bool> maOptions;
++    bool mbEmptyPass;
++    bool mbProtected;
++    ScPasswordHash meHash;
++};
++
++Sequence<sal_Int8> ScTableProtectionImpl::hashPassword(const String& aPassText, ScPasswordHash eHash)
 +{
++    Sequence<sal_Int8> aHash;
++    switch (eHash)
++    {
++        case PASSHASH_XL:
++            aHash = lcl_getXLHash(aPassText);
++        break;
++        case PASSHASH_OOO:
++        default:            
++            SvPasswordHelper::GetHashPassword(aHash, aPassText);
++        break;
++    }
++    return aHash;
 +}
 +
-+XclExpFnGroupCount::~XclExpFnGroupCount()
++ScTableProtectionImpl::ScTableProtectionImpl(SCSIZE nOptSize) :
++    maOptions(nOptSize),
++    mbEmptyPass(true),
++    mbProtected(false),
++    meHash(PASSHASH_OOO)
 +{
 +}
 +
-+void XclExpFnGroupCount::WriteBody( XclExpStream& rStrm )
++ScTableProtectionImpl::ScTableProtectionImpl(const ScTableProtectionImpl& r) :
++    maPassText(r.maPassText),
++    maPassHash(r.maPassHash),
++    maOptions(r.maOptions),
++    mbEmptyPass(r.mbEmptyPass),
++    mbProtected(r.mbProtected),
++    meHash(r.meHash)
 +{
-+    rStrm << static_cast<sal_uInt16>(14);
 +}
 +
-+// ============================================================================
-+
-+XclExpInterfaceHdr::XclExpInterfaceHdr() :
-+    XclExpRecord(0x00E1, 2)
++bool ScTableProtectionImpl::isProtected() const
 +{
++    return mbProtected;
 +}
 +
-+XclExpInterfaceHdr::~XclExpInterfaceHdr()
++bool ScTableProtectionImpl::isProtectedWithPass() const
 +{
++    if (!mbProtected)
++        return false;
++
++    return maPassText.Len() || maPassHash.getLength();
 +}
 +
-+void XclExpInterfaceHdr::WriteBody( XclExpStream& rStrm )
++void ScTableProtectionImpl::setProtected(bool bProtected)
 +{
-+    // The value must be the same value as the CODEPAGE record.
-+    rStrm.DisableEncryption();
-+    rStrm << static_cast<sal_uInt16>(0x04B0);
++    mbProtected = bProtected;
++    // We need to keep the old password even when the protection is off.  So, 
++    // don't erase the password data here.
 +}
 +
-+// ============================================================================
-+
-+XclExpInterfaceEnd::XclExpInterfaceEnd() :
-+    XclExpRecord(0x00E2, 0)
++void ScTableProtectionImpl::setPassword(const String& aPassText)
 +{
++    // We can't hash it here because we don't know whether this document will
++    // get saved to Excel or ODF, depending on which we will need to use a
++    // different hashing algorithm.  One alternative is to hash it using all
++    // hash algorithms that we support, and store them all.
++
++    maPassText = aPassText;
++    mbEmptyPass = aPassText.Len() == 0;
++    if (mbEmptyPass)
++    {
++        maPassHash = Sequence<sal_Int8>();
++    }
 +}
 +
-+XclExpInterfaceEnd::~XclExpInterfaceEnd()
++bool ScTableProtectionImpl::isPasswordEmpty() const
 +{
++    return mbEmptyPass;
 +}
 +
-+void XclExpInterfaceEnd::WriteBody( XclExpStream& /*rStrm*/ )
++bool ScTableProtectionImpl::hasPasswordHash(ScPasswordHash eHash) const
 +{
-+}
++    if (mbEmptyPass)
++        return true;
 +
-+// ============================================================================
++    if (maPassText.Len())
++        return true;
 +
-+XclExpMMS::XclExpMMS() :
-+    XclExpRecord(0x00C1, 2)
-+{
++    if (meHash == eHash)
++        return true;
++
++    return false;
 +}
 +
-+XclExpMMS::~XclExpMMS()
++Sequence<sal_Int8> ScTableProtectionImpl::getPasswordHash(ScPasswordHash eHash) const
 +{
++    if (mbEmptyPass)
++        // Flaged as empty.
++        return Sequence<sal_Int8>();
++
++    if (maPassText.Len())
++        // Cleartext password exists.  Hash it.
++        return hashPassword(maPassText, eHash);
++
++    if (meHash == eHash)
++        // Stored hash exists.
++        return maPassHash;
++
++    // Failed to find a matching hash.
++    return Sequence<sal_Int8>();
 +}
 +
-+void XclExpMMS::WriteBody( XclExpStream& rStrm )
++void ScTableProtectionImpl::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
 +{
-+    rStrm << static_cast<sal_uInt16>(0x0000);
-+}
++    sal_Int32 nLen = aPassword.getLength();
++    mbEmptyPass = nLen <= 0 ? true : false;
++    meHash = eHash;
++    maPassHash = aPassword;
 +
-+// ============================================================================
++#if DEBUG_TAB_PROTECTION
++    for (sal_Int32 i = 0; i < nLen; ++i)
++        printf("%2.2X ", static_cast<sal_uInt8>(aPassword[i]));
++    printf("\n");
++#endif
++}
 +
-+XclExpWriteAccess::XclExpWriteAccess() :
-+    XclExpRecord(0x005C, 112)
++bool ScTableProtectionImpl::verifyPassword(const String& aPassText) const
 +{
++#if DEBUG_TAB_PROTECTION    
++    fprintf(stdout, "ScTableProtectionImpl::verifyPassword: input = '%s'\n",
++            OUStringToOString(rtl::OUString(aPassText), RTL_TEXTENCODING_UTF8).getStr());
++#endif    
++
++    if (mbEmptyPass)
++        return aPassText.Len() == 0;
++
++    if (maPassText.Len())
++        // Clear text password exists, and this one takes precedence.
++        return aPassText.Equals(maPassText);
++
++    Sequence<sal_Int8> aHash = hashPassword(aPassText, meHash);
++
++#if DEBUG_TAB_PROTECTION    
++    fprintf(stdout, "ScTableProtectionImpl::verifyPassword: hash = ");
++    for (sal_Int32 i = 0; i < aHash.getLength(); ++i)
++        printf("%2.2X ", static_cast<sal_uInt8>(aHash[i]));
++    printf("\n");
++#endif    
++
++    return aHash == maPassHash;
 +}
 +
-+XclExpWriteAccess::~XclExpWriteAccess()
++bool ScTableProtectionImpl::isOptionEnabled(SCSIZE nOptId) const
 +{
++    if ( maOptions.size() <= static_cast<size_t>(nOptId) )
++    {
++        DBG_ERROR("ScTableProtectionImpl::isOptionEnabled: wrong size");
++        return false;
++    }
++
++    return maOptions[nOptId];
 +}
 +
-+void XclExpWriteAccess::WriteBody( XclExpStream& rStrm )
++void ScTableProtectionImpl::setOption(SCSIZE nOptId, bool bEnabled)
 +{
-+    static const sal_uInt8 aData[] = {
-+        0x04, 0x00, 0x00,  'C',  'a',  'l',  'c', 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
-+        0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
++    if ( maOptions.size() <= static_cast<size_t>(nOptId) )
++    {
++        DBG_ERROR("ScTableProtectionImpl::setOption: wrong size");
++        return;
++    }
 +
-+    sal_Size nDataSize = sizeof(aData);
-+    for (sal_Size i = 0; i < nDataSize; ++i)
-+        rStrm << aData[i];
++    maOptions[nOptId] = bEnabled;
 +}
 +
 +// ============================================================================
 +
-+XclExpCodePage::XclExpCodePage() :
-+    XclExpRecord(0x0042, 2)
++ScDocProtection::ScDocProtection() :
++    mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScDocProtection::NONE)))
 +{
 +}
 +
-+XclExpCodePage::~XclExpCodePage()
++ScDocProtection::ScDocProtection(const ScDocProtection& r) :
++    mpImpl(new ScTableProtectionImpl(*r.mpImpl.get()))
 +{
 +}
 +
-+void XclExpCodePage::WriteBody( XclExpStream& rStrm )
++ScDocProtection::~ScDocProtection()
 +{
-+    // 0x04B0 : UTF-16 (BIFF8)
-+    rStrm << static_cast<sal_uInt16>(0x04B0);
 +}
 +
-+// ============================================================================
-+
-+XclExpDSF::XclExpDSF() :
-+    XclExpRecord(0x0161, 2)
++bool ScDocProtection::isProtected() const
 +{
++    return mpImpl->isProtected();
 +}
 +
-+XclExpDSF::~XclExpDSF()
++bool ScDocProtection::isProtectedWithPass() const
 +{
++    return mpImpl->isProtectedWithPass();
 +}
 +
-+void XclExpDSF::WriteBody( XclExpStream& rStrm )
++void ScDocProtection::setProtected(bool bProtected)
 +{
-+    rStrm << static_cast<sal_uInt16>(0x0000);
++    mpImpl->setProtected(bProtected);
++
++    // Currently Calc doesn't support document protection options.  So, let's
++    // assume that when the document is protected, its structure is protected.
++    // We need to do this for Excel export.
++    mpImpl->setOption(ScDocProtection::STRUCTURE, bProtected);
 +}
 +
-+// ============================================================================
++bool ScDocProtection::isPasswordEmpty() const
++{
++    return mpImpl->isPasswordEmpty();
++}
 +
-+XclExpProt4Rev::XclExpProt4Rev() :
-+    XclExpRecord(0x01AF, 2)
++bool ScDocProtection::hasPasswordHash(ScPasswordHash eHash) const
 +{
++    return mpImpl->hasPasswordHash(eHash);
 +}
 +
-+XclExpProt4Rev::~XclExpProt4Rev()
++void ScDocProtection::setPassword(const String& aPassText)
 +{
++    mpImpl->setPassword(aPassText);
 +}
 +
-+void XclExpProt4Rev::WriteBody( XclExpStream& rStrm )
++uno::Sequence<sal_Int8> ScDocProtection::getPasswordHash(ScPasswordHash eHash) const
 +{
-+    rStrm << static_cast<sal_uInt16>(0x0000);
++    return mpImpl->getPasswordHash(eHash);
 +}
 +
-+// ============================================================================
++void ScDocProtection::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
++{
++    mpImpl->setPasswordHash(aPassword, eHash);
++}
 +
-+XclExpProt4RevPass::XclExpProt4RevPass() :
-+    XclExpRecord(0x01BC, 2)
++bool ScDocProtection::verifyPassword(const String& aPassText) const
 +{
++    return mpImpl->verifyPassword(aPassText);
 +}
 +
-+XclExpProt4RevPass::~XclExpProt4RevPass()
++bool ScDocProtection::isOptionEnabled(Option eOption) const
 +{
++    return mpImpl->isOptionEnabled(eOption);
 +}
 +
-+void XclExpProt4RevPass::WriteBody( XclExpStream& rStrm )
++void ScDocProtection::setOption(Option eOption, bool bEnabled)
 +{
-+    rStrm << static_cast<sal_uInt16>(0x0000);
++    mpImpl->setOption(eOption, bEnabled);
 +}
 +
 +// ============================================================================
 +
-+XclExpExcel9File::XclExpExcel9File() :
-+    XclExpRecord(0x01C0, 0)
++ScTableProtection::ScTableProtection() :
++    mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScTableProtection::NONE)))
 +{
++    // Set default values for the options.
++    mpImpl->setOption(SELECT_LOCKED_CELLS,   true);
++    mpImpl->setOption(SELECT_UNLOCKED_CELLS, true);
 +}
 +
-+XclExpExcel9File::~XclExpExcel9File()
++ScTableProtection::ScTableProtection(const ScTableProtection& r) :
++    mpImpl(new ScTableProtectionImpl(*r.mpImpl.get()))
 +{
 +}
 +
-+void XclExpExcel9File::WriteBody( XclExpStream& /*rStrm*/ )
++ScTableProtection::~ScTableProtection()
 +{
 +}
 +
-+// ============================================================================
++bool ScTableProtection::isProtected() const
++{
++    return mpImpl->isProtected();
++}
 +
-+static const sal_uInt8 nData01C1[] = {
-+    0xC1, 0x01, 0x00, 0x00, 0x54, 0x8D, 0x01, 0x00
-+};
++bool ScTableProtection::isProtectedWithPass() const
++{
++    return mpImpl->isProtectedWithPass();
++}
 +
-+XclExpUnknown01C1::XclExpUnknown01C1() :
-+    XclExpDummyRecord(0x01C1, nData01C1, sizeof(nData01C1))
++void ScTableProtection::setProtected(bool bProtected)
 +{
++    mpImpl->setProtected(bProtected);
 +}
 +
-+// ============================================================================
++bool ScTableProtection::isPasswordEmpty() const
++{
++    return mpImpl->isPasswordEmpty();
++}
 +
-+static const sal_uInt8 nData0863[] = {
-+    0x63, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-+    0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
-+    0x02
-+};
++bool ScTableProtection::hasPasswordHash(ScPasswordHash eHash) const
++{
++    return mpImpl->hasPasswordHash(eHash);
++}
 +
-+XclExpUnknown0863::XclExpUnknown0863() :
-+    XclExpDummyRecord(0x0863, nData0863, sizeof(nData0863))
++void ScTableProtection::setPassword(const String& aPassText)
 +{
++    mpImpl->setPassword(aPassText);
 +}
 +
-Index: sc/source/filter/xml/xmlbodyi.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/xml/xmlbodyi.cxx,v
-retrieving revision 1.32
-retrieving revision 1.29.324.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.32 -r1.29.324.4
---- sc/source/filter/xml/xmlbodyi.cxx	21 Jul 2008 12:03:57 -0000	1.32
-+++ sc/source/filter/xml/xmlbodyi.cxx	9 Aug 2008 21:48:56 -0000	1.29.324.4
-@@ -52,6 +52,7 @@
- #include "XMLTrackedChangesContext.hxx"
- #include "XMLEmptyContext.hxx"
- #include "scerrors.hxx"
-+#include "tabprotection.hxx"
- 
- #include <xmloff/xmltkmap.hxx>
- #include <xmloff/xmltoken.hxx>
-@@ -62,6 +63,8 @@
- #include <sal/types.h>
- #include <tools/debug.hxx>
- 
-+#include <memory>
++Sequence<sal_Int8> ScTableProtection::getPasswordHash(ScPasswordHash eHash) const
++{
++    return mpImpl->getPasswordHash(eHash);
++}
 +
- using namespace com::sun::star;
- using namespace xmloff::token;
- 
-@@ -280,10 +283,17 @@
-         // #i37959# handle document protection after the sheet settings
- 		if (bProtected)
- 		{
-+            ::std::auto_ptr<ScDocProtection> pProtection(new ScDocProtection);
-+            pProtection->setProtected(true);
++void ScTableProtection::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
++{
++    mpImpl->setPasswordHash(aPassword, eHash);
++}
 +
- 			uno::Sequence<sal_Int8> aPass;
- 			if (sPassword.getLength())
-+            {
- 				SvXMLUnitConverter::decodeBase64(aPass, sPassword);
--			pDoc->SetDocProtection(bProtected, aPass);
-+                pProtection->setPasswordHash(aPass, PASSHASH_OOO);
-+            }
++bool ScTableProtection::verifyPassword(const String& aPassText) const
++{
++    return mpImpl->verifyPassword(aPassText);
++}
 +
-+            pDoc->SetDocProtection(pProtection.get());
- 		}
- 	}
- 	GetScImport().UnlockSolarMutex();
-Index: sc/source/filter/xml/xmlexprt.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/filter/xml/xmlexprt.cxx,v
-retrieving revision 1.213
-retrieving revision 1.211.28.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.213 -r1.211.28.5
---- sc/source/filter/xml/xmlexprt.cxx	28 May 2008 10:18:09 -0000	1.213
-+++ sc/source/filter/xml/xmlexprt.cxx	13 Aug 2008 20:52:42 -0000	1.211.28.5
-@@ -67,6 +67,7 @@
- #include "rangeutl.hxx"
- #include "convuno.hxx"
- #include "postit.hxx"
-+#include "tabprotection.hxx"
- 
- #include <xmloff/xmltoken.hxx>
- #include <xmloff/xmlnmspe.hxx>
-@@ -1399,7 +1400,11 @@
- 	{
- 		AddAttribute(XML_NAMESPACE_TABLE, XML_STRUCTURE_PROTECTED, XML_TRUE);
- 		rtl::OUStringBuffer aBuffer;
--		SvXMLUnitConverter::encodeBase64(aBuffer, pDoc->GetDocPassword());
-+        uno::Sequence<sal_Int8> aPassHash;
-+        const ScDocProtection* p = pDoc->GetDocProtection();
-+        if (p)
-+            aPassHash = p->getPasswordHash(PASSHASH_OOO);
-+		SvXMLUnitConverter::encodeBase64(aBuffer, aPassHash);
- 		if (aBuffer.getLength())
- 			AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
- 	}
-@@ -1417,11 +1422,13 @@
- 		DBG_ERROR("no shared data setted");
- 	}
- 	ScXMLExportDatabaseRanges aExportDatabaseRanges(*this);
--	if (GetModel().is())
--	{
-+	if (!GetModel().is())
-+        return;
++bool ScTableProtection::isOptionEnabled(Option eOption) const
++{
++    return mpImpl->isOptionEnabled(eOption);
++}
 +
- 		uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
--		if ( xSpreadDoc.is() )
--		{
-+    if ( !xSpreadDoc.is() )
-+        return;
++void ScTableProtection::setOption(Option eOption, bool bEnabled)
++{
++    mpImpl->setOption(eOption, bEnabled);
++}
 +
- 			uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
- 			if ( xIndex.is() )
- 			{
-@@ -1471,7 +1478,11 @@
- 								AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
- 								rtl::OUStringBuffer aBuffer;
- 								if (pDoc)
--									SvXMLUnitConverter::encodeBase64(aBuffer, pDoc->GetTabPassword(static_cast<SCTAB>(nTable)));
-+                                {
-+                                    ScTableProtection* pProtect = pDoc->GetTabProtection(static_cast<SCTAB>(nTable));
-+                                    if (pProtect)
-+                                        SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_OOO));
-+                                }
- 								if (aBuffer.getLength())
- 									AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
- 							}
-@@ -1585,8 +1596,6 @@
- 			aExportDDELinks.WriteDDELinks(xSpreadDoc);
-             IncrementProgressBar(sal_True, 0);
- 			GetProgressBarHelper()->SetValue(GetProgressBarHelper()->GetReference());
--		}
--	}
- }
- 
- void ScXMLExport::_ExportStyles( sal_Bool bUsed )
-Index: sc/source/filter/xml/xmlsubti.cxx
+Index: source/ui/unoobj/warnpassword.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/filter/xml/xmlsubti.cxx,v
-retrieving revision 1.50
-retrieving revision 1.49.28.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.50 -r1.49.28.2
---- sc/source/filter/xml/xmlsubti.cxx	10 Apr 2008 21:36:36 -0000	1.50
-+++ sc/source/filter/xml/xmlsubti.cxx	6 May 2008 23:28:28 -0000	1.49.28.2
-@@ -42,6 +42,7 @@
- #include "docuno.hxx"
- #include "cellsuno.hxx"
- #include "XMLStylesImportHelper.hxx"
-+#include "tabprotection.hxx"
- 
- #include <xmloff/xmltkmap.hxx>
- #include <xmloff/nmspmap.hxx>
-@@ -58,6 +59,10 @@
- #include <com/sun/star/util/XProtectable.hpp>
- #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
+--- sc/source/ui/unoobj/warnpassword.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/unoobj/warnpassword.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -32,6 +32,9 @@
+ #include "precompiled_sc.hxx"
  
-+#include <memory>
+ // ============================================================================
 +
-+using ::std::auto_ptr;
++#if 0
 +
- //------------------------------------------------------------------
- 
- using namespace com::sun::star;
-@@ -639,13 +644,10 @@
- 	{
- 		uno::Sequence<sal_Int8> aPass;
- 		SvXMLUnitConverter::decodeBase64(aPass, sPassword);
--		rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), bProtection, aPass);
--		/*uno::Reference <util::XProtectable> xProtectable(xCurrentSheet, uno::UNO_QUERY);
--		if (xProtectable.is())
--		{
--			rtl::OUString sKey;
--			xProtectable->protect(sKey);
--		}*/
-+        auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
-+        pProtect->setProtected(bProtection);
-+        pProtect->setPasswordHash(aPass, PASSHASH_OOO);
-+        rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), pProtect.get());
- 	}
- 
- 	rImport.UnlockSolarMutex();
-Index: sc/source/ui/docshell/docfunc.cxx
+ #include "warnpassword.hxx"
+ #include <com/sun/star/task/XInteractionHandler.hpp>
+ #include <com/sun/star/task/XInteractionRequest.hpp>
+@@ -95,3 +98,5 @@
+     }
+     return bReturn;
+ }
++
++#endif
+Index: source/ui/docshell/docfunc.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/ui/docshell/docfunc.cxx,v
-retrieving revision 1.70
-retrieving revision 1.68.28.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.70 -r1.68.28.4
---- sc/source/ui/docshell/docfunc.cxx	14 May 2008 09:56:37 -0000	1.70
-+++ sc/source/ui/docshell/docfunc.cxx	23 May 2008 01:50:45 -0000	1.68.28.4
+--- sc/source/ui/docshell/docfunc.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/docshell/docfunc.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -92,7 +92,12 @@
  #include "editable.hxx"
  #include "compiler.hxx"
@@ -3938,7 +3369,9 @@
 -						const String& rPassword,
 -						uno::Sequence<sal_Int8>* pReturnOld = NULL )
 +void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
-+{
+ {
+-	uno::Sequence<sal_Int8> aOldPassword;
+-	if ( nTab == TABLEID_DOC )
 +    ScDocument* pDoc = rDocShell.GetDocument();
 +
 +    pDoc->SetTabProtection(nTab, &rProtect);
@@ -3963,9 +3396,7 @@
 +}
 +
 +BOOL ScDocFunc::Protect( SCTAB nTab, const String& rPassword, BOOL /*bApi*/ )
- {
--	uno::Sequence<sal_Int8> aOldPassword;
--	if ( nTab == TABLEID_DOC )
++{
 +    ScDocument* pDoc = rDocShell.GetDocument();
 +    if (nTab == TABLEID_DOC)
 +    {
@@ -4057,11 +3488,11 @@
 -	else if (!bApi)
 -	{
 -		//	different password was set before
--
--//!		rDocShell.ErrorMessage(...);
 +        // save the protection state before unprotect (for undo).
 +        ::std::auto_ptr<ScDocProtection> pProtectCopy(new ScDocProtection(*pDocProtect));
  
+-//!		rDocShell.ErrorMessage(...);
+-
 +        if (!pDocProtect->verifyPassword(rPassword))
 +        {
 +            if (!bApi)
@@ -4101,18 +3532,16 @@
 -	uno::Sequence<sal_Int8> aPass;
 -	BOOL bOk = lcl_ValidPassword( pDoc, nTab, rPassword, &aOldPassword );
 -	if ( bOk )
--	{
++        // save the protection state before unprotect (for undo).
++        ::std::auto_ptr<ScTableProtection> pProtectCopy(new ScTableProtection(*pTabProtect));
++
++        if (!pTabProtect->verifyPassword(rPassword))
+ 	{
 -		uno::Sequence<sal_Int8> aEmptyPass;
 -		if ( nTab == TABLEID_DOC )
 -			pDoc->SetDocProtection( FALSE, aEmptyPass );
 -		else
 -			pDoc->SetTabProtection( nTab, FALSE, aEmptyPass );
-+        // save the protection state before unprotect (for undo).
-+        ::std::auto_ptr<ScTableProtection> pProtectCopy(new ScTableProtection(*pTabProtect));
- 
--		if (bUndo)
-+        if (!pTabProtect->verifyPassword(rPassword))
-+	{
 +            if (!bApi)
 +            {
 +                InfoBox aBox( rDocShell.GetActiveDialogParent(), String( ScResId( SCSTR_WRONGPASSWORD ) ) );
@@ -4120,7 +3549,8 @@
 +            }
 +            return false;
 +        }
-+
+ 
+-		if (bUndo)
 +        pDoc->SetTabProtection(nTab, NULL);
 +        if (pDoc->IsUndoEnabled())
  		{
@@ -4139,24 +3569,33 @@
 -	else if (!bApi)
 -	{
 -//!		rDocShell.ErrorMessage(...);
--
+ 
 -		InfoBox aBox( rDocShell.GetActiveDialogParent(), String( ScResId( SCSTR_WRONGPASSWORD ) ) );
 -		aBox.Execute();
 -	}
- 
+-
 -	return bOk;
 +    return true;
  }
  
  //------------------------------------------------------------------------
-Index: sc/source/ui/docshell/docsh.cxx
+Index: source/ui/docshell/docsh5.cxx
+===================================================================
+--- sc/source/ui/docshell/docsh5.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/docshell/docsh5.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -827,7 +827,7 @@
+ 				++nAdjSource;				// new position of source table after CopyTab
+ 
+ 			if ( aDocument.IsTabProtected( nAdjSource ) )
+-				aDocument.SetTabProtection( nDestTab, TRUE, aDocument.GetTabPassword( nAdjSource ) );
++                aDocument.CopyTabProtection(nAdjSource, nDestTab);
+ 
+ 			if (bRecord)
+ 			{
+Index: source/ui/docshell/docsh.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/ui/docshell/docsh.cxx,v
-retrieving revision 1.103
-retrieving revision 1.98.28.8
-diff -u -I $Revision.*$ -I $Author.*$ -r1.103 -r1.98.28.8
---- sc/source/ui/docshell/docsh.cxx	8 Jul 2008 09:43:20 -0000	1.103
-+++ sc/source/ui/docshell/docsh.cxx	13 Aug 2008 20:55:29 -0000	1.98.28.8
+--- sc/source/ui/docshell/docsh.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/docshell/docsh.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -79,11 +79,6 @@
  #include <sot/formats.hxx>
  #define SOT_FORMATSTR_ID_STARCALC_30 SOT_FORMATSTR_ID_STARCALC
@@ -4185,7 +3624,7 @@
  
  #include "docsh.hxx"
  #include "docshimp.hxx"
-@@ -1496,6 +1491,14 @@
+@@ -1296,6 +1291,14 @@
  {
  	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::SaveAs" );
  
@@ -4200,7 +3639,7 @@
  	ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
  
  	//	DoEnterHandler hier nicht (wegen AutoSave), ist im ExecuteSave
-@@ -1970,7 +1973,6 @@
+@@ -1770,7 +1773,6 @@
  	rStream.SetNumberFormatInt( nOldNumberFormatInt );
  }
  
@@ -4208,7 +3647,7 @@
  BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed )
  {
  	RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ConvertTo" );
-@@ -2023,6 +2025,14 @@
+@@ -1823,6 +1825,14 @@
                  aDocument.SetExtDocOptions( pExtDocOpt = new ScExtDocOptions );
              pViewShell->GetViewData()->WriteExtOptions( *pExtDocOpt );
  
@@ -4223,7 +3662,7 @@
              /*  #115980 #If the imported document contained an encrypted password -
                  determine if we should save without it. */
              ScExtDocSettings& rDocSett = pExtDocOpt->GetDocSettings();
-@@ -2032,6 +2042,7 @@
+@@ -1832,6 +1842,7 @@
                  // #i42858# warn only on time
                  rDocSett.mbEncrypted = false;
              }
@@ -4231,2845 +3670,2667 @@
          }
  
          if( bDoSave )
-Index: sc/source/ui/docshell/docsh5.cxx
+Index: source/ui/undo/undotab.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/ui/docshell/docsh5.cxx,v
-retrieving revision 1.21
-retrieving revision 1.19.28.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.21 -r1.19.28.3
---- sc/source/ui/docshell/docsh5.cxx	11 Jul 2008 07:09:32 -0000	1.21
-+++ sc/source/ui/docshell/docsh5.cxx	17 Jul 2008 01:00:14 -0000	1.19.28.3
-@@ -821,7 +821,7 @@
- 				++nAdjSource;				// new position of source table after CopyTab
+--- sc/source/ui/undo/undotab.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/undo/undotab.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -61,6 +61,7 @@
+ #include "prnsave.hxx"
+ #include "printfun.hxx"
+ #include "chgtrack.hxx"
++#include "tabprotection.hxx"
  
- 			if ( aDocument.IsTabProtected( nAdjSource ) )
--				aDocument.SetTabProtection( nDestTab, TRUE, aDocument.GetTabPassword( nAdjSource ) );
-+                aDocument.CopyTabProtection(nAdjSource, nDestTab);
+ // for ScUndoRenameObject - might me moved to another file later
+ #include <svx/svditer.hxx>
+@@ -72,6 +73,8 @@
+ extern BOOL bDrawIsInUndo;			//! irgendwo als Member !!!
  
- 			if (bRecord)
- 			{
-Index: sc/source/ui/inc/docfunc.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/inc/docfunc.hxx,v
-retrieving revision 1.19
-retrieving revision 1.18.28.2
-diff -u -I $Revision.*$ -I $Author.*$ -r1.19 -r1.18.28.2
---- sc/source/ui/inc/docfunc.hxx	14 May 2008 09:58:47 -0000	1.19
-+++ sc/source/ui/inc/docfunc.hxx	23 May 2008 01:50:16 -0000	1.18.28.2
-@@ -47,7 +47,7 @@
- class ScBaseCell;
- class ScTokenArray;
- struct ScTabOpParam;
--
-+class ScTableProtection;
+ using namespace com::sun::star;
++using ::com::sun::star::uno::Sequence;
++using ::std::auto_ptr;
  
- // ---------------------------------------------------------------------------
+ // STATIC DATA -----------------------------------------------------------
  
-@@ -129,6 +129,8 @@
- 	BOOL			RemovePageBreak( BOOL bColumn, const ScAddress& rPos,
- 									BOOL bRecord, BOOL bSetModified, BOOL bApi );
+@@ -85,7 +88,6 @@
+ TYPEINIT1(ScUndoImportTab,		SfxUndoAction);
+ TYPEINIT1(ScUndoRemoveLink,		SfxUndoAction);
+ TYPEINIT1(ScUndoShowHideTab,	SfxUndoAction);
+-TYPEINIT1(ScUndoProtect,		SfxUndoAction);
+ TYPEINIT1(ScUndoPrintRange,		SfxUndoAction);
+ TYPEINIT1(ScUndoScenarioFlags,	SfxUndoAction);
+ TYPEINIT1(ScUndoRenameObject,	SfxUndoAction);
+@@ -112,12 +114,12 @@
+ 	SetChangeTrack();
+ }
  
-+    void            ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
-+
- 	BOOL			Protect( SCTAB nTab, const String& rPassword, BOOL bApi );
- 	BOOL			Unprotect( SCTAB nTab, const String& rPassword, BOOL bApi );
+-__EXPORT ScUndoInsertTab::~ScUndoInsertTab()
++ScUndoInsertTab::~ScUndoInsertTab()
+ {
+ 	DeleteSdrUndoAction( pDrawUndo );
+ }
  
-Index: sc/source/ui/inc/protectiondlg.hrc
-===================================================================
-RCS file: sc/source/ui/inc/protectiondlg.hrc
-diff -N sc/source/ui/inc/protectiondlg.hrc
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/inc/protectiondlg.hrc	7 May 2008 22:15:40 -0000	1.1.2.1
-@@ -0,0 +1,47 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: protectiondlg.hrc,v $
-+ * $Revision: 1.1.2.1 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#include <sc.hrc>
-+
-+#define BTN_OK					1
-+#define BTN_CANCEL				2
-+#define BTN_HELP				3
-+
-+#define BTN_PROTECT             4
-+#define FT_PASSWORD1            5
-+#define ED_PASSWORD1            6
-+#define FT_PASSWORD2            7
-+#define ED_PASSWORD2            8
-+#define FL_OPTIONS              9
-+#define FT_OPTIONS             10
-+#define CLB_OPTIONS            11
-+
-+#define ST_SELECT_LOCKED_CELLS          50
-+#define ST_SELECT_UNLOCKED_CELLS        51
-Index: sc/source/ui/inc/protectiondlg.hxx
-===================================================================
-RCS file: sc/source/ui/inc/protectiondlg.hxx
-diff -N sc/source/ui/inc/protectiondlg.hxx
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/inc/protectiondlg.hxx	23 May 2008 00:05:23 -0000	1.1.2.4
-@@ -0,0 +1,85 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: protectiondlg.hxx,v $
-+ * $Revision: 1.1.2.4 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#ifndef SC_UI_PROTECTION_DLG_HXX
-+#define SC_UI_PROTECTION_DLG_HXX
-+
-+#include <vcl/dialog.hxx>
-+#include <vcl/button.hxx>
-+#include <vcl/fixed.hxx>
-+#include <vcl/edit.hxx>
-+#include <svx/checklbx.hxx>
-+
-+class Window;
-+class ScTableProtection;
-+
-+class ScTableProtectionDlg : public ModalDialog
-+{
-+public:
-+    explicit ScTableProtectionDlg(Window* pParent);
-+    virtual ~ScTableProtectionDlg();
-+
-+    virtual short Execute();
-+
-+    void SetDialogData(const ScTableProtection& rData);
-+
-+    void WriteData(ScTableProtection& rData) const;
-+
-+private:
-+    ScTableProtectionDlg(); // disabled
-+
-+    void Init();
-+
-+    void EnableOptionalWidgets(bool bEnable = true);
-+
-+    CheckBox        maBtnProtect;
-+
-+    FixedText       maPassword1Text;
-+    Edit            maPassword1Edit;
-+    FixedText       maPassword2Text;
-+    Edit            maPassword2Edit;
-+
-+    FixedLine       maOptionsLine;
-+    FixedText       maOptionsText;
-+    SvxCheckListBox maOptionsListBox;
-+
-+    OKButton        maBtnOk;
-+    CancelButton    maBtnCancel;
-+    HelpButton      maBtnHelp;
-+
-+    String          maSelectLockedCells;
-+    String          maSelectUnlockedCells;
-+
-+    DECL_LINK( OKHdl, OKButton* );
-+    DECL_LINK( CheckBoxHdl, CheckBox* );
-+    DECL_LINK( PasswordModifyHdl, Edit* );
-+};
-+
-+#endif
-Index: sc/source/ui/inc/retypepassdlg.hrc
-===================================================================
-RCS file: sc/source/ui/inc/retypepassdlg.hrc
-diff -N sc/source/ui/inc/retypepassdlg.hrc
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/inc/retypepassdlg.hrc	20 May 2008 00:25:53 -0000	1.1.2.2
-@@ -0,0 +1,74 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: retypepassdlg.hrc,v $
-+ * $Revision: 1.1.2.2 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#include <sc.hrc>
-+
-+#define BTN_OK					 1
-+#define BTN_CANCEL				 2
-+#define BTN_HELP				 3
-+
-+#define FT_DESC                 10
-+#define FL_DOCUMENT             11
-+#define FT_DOCSTATUS            12
-+#define BTN_RETYPE_DOC          13
-+
-+#define FL_SHEET                112
-+
-+#define FT_SHEETNAME1           113
-+#define FT_SHEETSTATUS1         114
-+#define BTN_RETYPE_SHEET1       115
-+
-+#define FT_SHEETNAME2           116
-+#define FT_SHEETSTATUS2         117
-+#define BTN_RETYPE_SHEET2       118
-+
-+#define FT_SHEETNAME3           119
-+#define FT_SHEETSTATUS3         120
-+#define BTN_RETYPE_SHEET3       121
-+
-+#define FT_SHEETNAME4           122
-+#define FT_SHEETSTATUS4         123
-+#define BTN_RETYPE_SHEET4       124
-+
-+#define SB_SCROLL               190
-+
-+#define STR_NOT_PROTECTED       200
-+#define STR_NOT_PASS_PROTECTED  201
-+#define STR_HASH_BAD            202
-+#define STR_HASH_GOOD           203
-+#define STR_HASH_REGENERATED    204
-+
-+#define FT_PASSWORD1            301
-+#define ED_PASSWORD1            302
-+#define FT_PASSWORD2            303
-+#define ED_PASSWORD2            304
-+#define BTN_MATCH_OLD_PASSWORD  305
-+#define BTN_RETYPE_PASSWORD     306
-+#define BTN_REMOVE_PASSWORD     307
-Index: sc/source/ui/inc/retypepassdlg.hxx
-===================================================================
-RCS file: sc/source/ui/inc/retypepassdlg.hxx
-diff -N sc/source/ui/inc/retypepassdlg.hxx
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/inc/retypepassdlg.hxx	23 May 2008 00:09:48 -0000	1.1.2.7
-@@ -0,0 +1,177 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: retypepassdlg.hxx,v $
-+ * $Revision: 1.1.2.7 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#ifndef SC_UI_RETYPEPASS_DLG_HXX
-+#define SC_UI_RETYPEPASS_DLG_HXX
-+
-+#include <vcl/dialog.hxx>
-+#include <vcl/button.hxx>
-+#include <vcl/fixed.hxx>
-+#include <vcl/edit.hxx>
-+#include <vcl/scrbar.hxx>
-+#include <svx/checklbx.hxx>
-+#include <svtools/stdctrl.hxx>
-+
-+#include "tabprotection.hxx"
-+
-+#include <boost/shared_ptr.hpp>
-+
-+class Window;
-+class ScDocProtection;
-+class ScTableProtection;
-+class ScDocument;
-+
-+class ScRetypePassDlg : public ModalDialog
-+{
-+public:
-+    typedef ::boost::shared_ptr<ScDocProtection>    DocProtectionPtr;
-+    typedef ::boost::shared_ptr<ScTableProtection>  TabProtectionPtr;
-+
-+    explicit ScRetypePassDlg(Window* pParent);
-+    virtual ~ScRetypePassDlg();
-+
-+    virtual short Execute();
-+
-+    void SetData(const ScDocument& rDoc);
-+    void SetDesiredHash(ScPasswordHash eHash);
-+
-+    /** Write the new set of password data to the document instance to
-+        overwrite the current ones. */
-+    void WriteNewDataToDocument(ScDocument& rDoc) const;
-+
-+private:
-+    ScRetypePassDlg(); // disabled
-+
-+    void Init();
-+    void PopulateDialog();
-+    void SetDocData();
-+    void SetTableData(sal_uInt8 nRowPos, SCTAB nTab);
-+    void ResetTableRows();
-+
-+    /** Check the status of all hash values to see if it's okay to enable
-+        the OK button. */
-+    void CheckHashStatus();
-+
-+private:
-+    OKButton        maBtnOk;
-+    CancelButton    maBtnCancel;
-+    HelpButton      maBtnHelp;
-+
-+    FixedInfo       maTextDescription;
-+
-+    FixedLine       maLineDocument;
-+    FixedText       maTextDocStatus;
-+    PushButton      maBtnRetypeDoc;
-+
-+    FixedLine       maLineSheet;
-+    FixedText       maTextSheetName1;
-+    FixedText       maTextSheetStatus1;
-+    PushButton      maBtnRetypeSheet1;
-+
-+    FixedText       maTextSheetName2;
-+    FixedText       maTextSheetStatus2;
-+    PushButton      maBtnRetypeSheet2;
-+
-+    FixedText       maTextSheetName3;
-+    FixedText       maTextSheetStatus3;
-+    PushButton      maBtnRetypeSheet3;
-+
-+    FixedText       maTextSheetName4;
-+    FixedText       maTextSheetStatus4;
-+    PushButton      maBtnRetypeSheet4;
-+
-+    ScrollBar       maScrollBar;
-+
-+    String          maTextNotProtected;
-+    String          maTextNotPassProtected;
-+    String          maTextHashBad;
-+    String          maTextHashGood;
-+    String          maTextHashRegen;
-+
-+    DECL_LINK( OKHdl, OKButton* );
-+    DECL_LINK( RetypeBtnHdl, PushButton* );
-+    DECL_LINK( ScrollHdl, ScrollBar* );
-+
-+    struct TableItem
-+    {
-+        String              maName;
-+        TabProtectionPtr    mpProtect;
-+    };
-+    ::std::vector<TableItem> maTableItems;
-+
-+    DocProtectionPtr    mpDocItem;
-+    size_t              mnCurScrollPos;
-+    ScPasswordHash      meDesiredHash;
-+};
-+
-+// ============================================================================
-+
-+class ScRetypePassInputDlg : public ModalDialog
-+{
-+public:
-+    explicit ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected);
-+    virtual ~ScRetypePassInputDlg();
-+
-+    virtual short Execute();
-+
-+    bool IsRemovePassword() const;
-+    String GetNewPassword() const;
-+
-+private:
-+    ScRetypePassInputDlg(); // disabled
-+
-+    void Init();
-+    void CheckPasswordInput();
-+
-+private:
-+    OKButton        maBtnOk;
-+    CancelButton    maBtnCancel;
-+    HelpButton      maBtnHelp;
-+
-+    RadioButton     maBtnRetypePassword;
-+
-+    FixedText       maPassword1Text;
-+    Edit            maPassword1Edit;
-+    FixedText       maPassword2Text;
-+    Edit            maPassword2Edit;
-+
-+    CheckBox        maBtnMatchOldPass;
-+
-+    RadioButton     maBtnRemovePassword;
-+
-+    DECL_LINK( OKHdl, OKButton* );
-+    DECL_LINK( RadioBtnHdl, RadioButton* );
-+    DECL_LINK( CheckBoxHdl, CheckBox* );
-+    DECL_LINK( PasswordModifyHdl, Edit* );
-+
-+    ScPassHashProtectable* mpProtected;
-+};
-+
-+#endif
-Index: sc/source/ui/inc/tabvwsh.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/inc/tabvwsh.hxx,v
-retrieving revision 1.31
-retrieving revision 1.30.30.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.31 -r1.30.30.3
---- sc/source/ui/inc/tabvwsh.hxx	22 Jul 2008 14:44:01 -0000	1.31
-+++ sc/source/ui/inc/tabvwsh.hxx	9 Aug 2008 21:48:36 -0000	1.30.30.3
-@@ -38,6 +38,7 @@
- #include "target.hxx"
- #include "rangelst.hxx"			// ScRangeListRef
- #include "shellids.hxx"
-+#include "tabprotection.hxx" // for ScPasswordHash
- 
- class FmFormShell;
- class SbxObject;
-@@ -431,6 +432,8 @@
- 	void	BroadcastAccessibility( const SfxHint &rHint );
- 	BOOL	HasAccessibilityObjects();
+-String __EXPORT ScUndoInsertTab::GetComment() const
++String ScUndoInsertTab::GetComment() const
+ {
+ 	if (bAppend)
+ 		return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
+@@ -138,7 +140,7 @@
+ 		nEndChangeAction = 0;
+ }
  
-+    bool    ExecuteRetypePassDlg(ScPasswordHash eDesiredHash);
-+
-     using ScTabView::ShowCursor;
- };
+-void __EXPORT ScUndoInsertTab::Undo()
++void ScUndoInsertTab::Undo()
+ {
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ 	pViewShell->SetTabNo(nTab);
+@@ -159,7 +161,7 @@
+ 	pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
+ }
  
-Index: sc/source/ui/inc/undotab.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/inc/undotab.hxx,v
-retrieving revision 1.12
-retrieving revision 1.9.424.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.12 -r1.9.424.4
---- sc/source/ui/inc/undotab.hxx	11 Jul 2008 07:09:44 -0000	1.12
-+++ sc/source/ui/inc/undotab.hxx	17 Jul 2008 00:59:51 -0000	1.9.424.4
-@@ -52,11 +52,15 @@
+-void __EXPORT ScUndoInsertTab::Redo()
++void ScUndoInsertTab::Redo()
+ {
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
  
- #include <com/sun/star/uno/Sequence.hxx>
+@@ -180,14 +182,14 @@
+ 	SetChangeTrack();
+ }
  
-+#include <memory>
-+
- class ScDocShell;
- class ScDocument;
- class SdrUndoAction;
- class ScPrintRangeSaver;
- class SdrObject;
-+class ScDocProtection;
-+class ScTableProtection;
+-void __EXPORT ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
+ {
+ 	if (rTarget.ISA(ScTabViewTarget))
+ 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
+ 			Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
+ }
  
- //----------------------------------------------------------------------------
+-BOOL __EXPORT ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
+ {
+ 	return (rTarget.ISA(ScTabViewTarget));
+ }
+@@ -211,7 +213,7 @@
+ 	SetChangeTrack();
+ }
  
-@@ -335,14 +339,15 @@
- 	void DoChange( BOOL bShow ) const;
- };
+-__EXPORT ScUndoInsertTables::~ScUndoInsertTables()
++ScUndoInsertTables::~ScUndoInsertTables()
+ {
+ 	String *pStr=NULL;
+ 	if(pNameList!=NULL)
+@@ -227,7 +229,7 @@
+ 	DeleteSdrUndoAction( pDrawUndo );
+ }
  
-+// ============================================================================
+-String __EXPORT ScUndoInsertTables::GetComment() const
++String ScUndoInsertTables::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
+ }
+@@ -252,7 +254,7 @@
+ 		nStartChangeAction = nEndChangeAction = 0;
+ }
  
--class ScUndoProtect : public ScSimpleUndo
-+/** This class implements undo & redo of document protect & unprotect
-+    operations. */
-+class ScUndoDocProtect : public ScSimpleUndo
+-void __EXPORT ScUndoInsertTables::Undo()
++void ScUndoInsertTables::Undo()
  {
- public:
--					TYPEINFO();
--					ScUndoProtect( ScDocShell* pShell, SCTAB nNewTab,
--									BOOL bNewProtect, const com::sun::star::uno::Sequence<sal_Int8>& rNewPassword );
--	virtual			~ScUndoProtect();
-+                    ScUndoDocProtect(ScDocShell* pShell, ::std::auto_ptr<ScDocProtection> pProtectSettings);
-+	virtual			~ScUndoDocProtect();
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ 	pViewShell->SetTabNo(nTab);
+@@ -282,7 +284,7 @@
+ 	pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
+ }
  
- 	virtual void	Undo();
- 	virtual void	Redo();
-@@ -352,11 +357,34 @@
- 	virtual String	GetComment() const;
+-void __EXPORT ScUndoInsertTables::Redo()
++void ScUndoInsertTables::Redo()
+ {
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
  
- private:
--	SCTAB	nTab;
--	BOOL	bProtect;
--	com::sun::star::uno::Sequence<sal_Int8>	aPassword;
-+    ::std::auto_ptr<ScDocProtection> mpProtectSettings;
-+
-+	void	DoProtect(bool bProtect);
-+};
-+
-+// ============================================================================
-+
-+/** This class implements undo & redo of both protect and unprotect of
-+    sheet. */
-+class ScUndoTabProtect : public ScSimpleUndo
-+{
-+public:
-+                    ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, 
-+                                     ::std::auto_ptr<ScTableProtection> pProtectSettings);
-+	virtual			~ScUndoTabProtect();
-+
-+	virtual void	Undo();
-+	virtual void	Redo();
-+	virtual void	Repeat(SfxRepeatTarget& rTarget);
-+	virtual BOOL	CanRepeat(SfxRepeatTarget& rTarget) const;
-+
-+	virtual String	GetComment() const;
-+
-+private:
-+    SCTAB   mnTab;
-+    ::std::auto_ptr<ScTableProtection> mpProtectSettings;
+@@ -299,14 +301,14 @@
+ 	SetChangeTrack();
+ }
  
--	void	DoProtect( BOOL bDo );
-+	void	DoProtect(bool bProtect);
- };
+-void __EXPORT ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
+ {
+ 	if (rTarget.ISA(ScTabViewTarget))
+ 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
+ 			Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
+ }
  
+-BOOL __EXPORT ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
+ {
+ 	return (rTarget.ISA(ScTabViewTarget));
+ }
+@@ -327,12 +329,12 @@
+ 		SetChangeTrack();
+ }
  
-Index: sc/source/ui/inc/viewfunc.hxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/inc/viewfunc.hxx,v
-retrieving revision 1.34
-retrieving revision 1.34.30.1
-diff -u -I $Revision.*$ -I $Author.*$ -r1.34 -r1.34.30.1
---- sc/source/ui/inc/viewfunc.hxx	10 Apr 2008 23:37:14 -0000	1.34
-+++ sc/source/ui/inc/viewfunc.hxx	8 May 2008 21:53:47 -0000	1.34.30.1
-@@ -69,6 +69,7 @@
- class ScRangeList;
- class SvxHyperlinkItem;
- class ScTransferObj;
-+class ScTableProtection;
+-__EXPORT ScUndoDeleteTab::~ScUndoDeleteTab()
++ScUndoDeleteTab::~ScUndoDeleteTab()
+ {
+ 	theTabs.Remove(0,theTabs.Count());
+ }
  
- namespace com { namespace sun { namespace star { namespace datatransfer { class XTransferable; } } } }
+-String __EXPORT ScUndoDeleteTab::GetComment() const
++String ScUndoDeleteTab::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
+ }
+@@ -366,7 +368,7 @@
+ 	return nTab;
+ }
  
-@@ -199,6 +200,8 @@
+-void __EXPORT ScUndoDeleteTab::Undo()
++void ScUndoDeleteTab::Undo()
+ {
+ 	BeginUndo();
+ 	int i=0;
+@@ -414,7 +416,7 @@
+             pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
  
- 	void			ChangeIndent( BOOL bIncrement );
+             if ( pRefUndoDoc->IsTabProtected( nTab ) )
+-                pDoc->SetTabProtection( nTab, TRUE, pRefUndoDoc->GetTabPassword( nTab ) );
++                pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
  
-+	void			ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
-+
- 	void			Protect( SCTAB nTab, const String& rPassword );
- 	BOOL			Unprotect( SCTAB nTab, const String& rPassword );
+ 			//	Drawing-Layer passiert beim MoveUndo::EndUndo
+ 	//		pDoc->TransferDrawPage(pRefUndoDoc, nTab,nTab);
+@@ -450,7 +452,7 @@
+ //	EndUndo();
+ }
  
-Index: sc/source/ui/miscdlgs/makefile.mk
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/miscdlgs/makefile.mk,v
-retrieving revision 1.14
-retrieving revision 1.13.30.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.14 -r1.13.30.3
---- sc/source/ui/miscdlgs/makefile.mk	16 May 2008 10:09:52 -0000	1.14
-+++ sc/source/ui/miscdlgs/makefile.mk	23 May 2008 01:50:39 -0000	1.13.30.3
-@@ -78,7 +78,9 @@
- 	$(SLO)$/warnbox.obj	\
- 	$(SLO)$/scuiautofmt.obj     \
- 	$(SLO)$/conflictsdlg.obj    \
--	$(SLO)$/sharedocdlg.obj
-+	$(SLO)$/sharedocdlg.obj \
-+	$(SLO)$/protectiondlg.obj \
-+	$(SLO)$/retypepassdlg.obj
+-void __EXPORT ScUndoDeleteTab::Redo()
++void ScUndoDeleteTab::Redo()
+ {
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ 	pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs[0] ) );
+@@ -469,7 +471,7 @@
+ 	pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
+ }
  
- EXCEPTIONSFILES = \
-     $(SLO)$/acredlin.obj        \
-@@ -87,7 +89,9 @@
-     $(SLO)$/optsolver.obj       \
-     $(SLO)$/solveroptions.obj   \
-     $(SLO)$/crnrdlg.obj         \
--    $(SLO)$/solverutil.obj
-+    $(SLO)$/solverutil.obj \
-+    $(SLO)$/protectiondlg.obj \
-+    $(SLO)$/retypepassdlg.obj
+-void __EXPORT ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
+ {
+ 	if (rTarget.ISA(ScTabViewTarget))
+ 	{
+@@ -478,7 +480,7 @@
+ 	}
+ }
  
- SRS1NAME=$(TARGET)
- SRC1FILES = \
-@@ -96,7 +100,9 @@
- 	highred.src					\
- 	linkarea.src                \
- 	conflictsdlg.src            \
--	sharedocdlg.src
-+	sharedocdlg.src \
-+	protectiondlg.src \
-+	retypepassdlg.src
+-BOOL __EXPORT ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
+ {
+ 	return (rTarget.ISA(ScTabViewTarget));
+ }
+@@ -500,11 +502,11 @@
+ 	sNewName = rNewName;
+ }
  
- LIB1TARGET = $(SLB)$/$(TARGET).lib
+-__EXPORT ScUndoRenameTab::~ScUndoRenameTab()
++ScUndoRenameTab::~ScUndoRenameTab()
+ {
+ }
  
-@@ -116,7 +122,9 @@
- 	$(SLO)$/conflictsdlg.obj    \
- 	$(SLO)$/sharedocdlg.obj
- 	$(SLO)$/sharedocdlg.obj \
- 	$(SLO)$/scuiautofmt.obj			\
--	$(SLO)$/strindlg.obj            
-+	$(SLO)$/strindlg.obj \
-+    $(SLO)$/protectiondlg.obj \
-+    $(SLO)$/retypepassdlg.obj
+-String __EXPORT ScUndoRenameTab::GetComment() const
++String ScUndoRenameTab::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
+ }
+@@ -526,22 +528,22 @@
+ 		pViewShell->UpdateInputHandler();
+ }
  
- # --- Tagets -------------------------------------------------------
+-void __EXPORT ScUndoRenameTab::Undo()
++void ScUndoRenameTab::Undo()
+ {
+ 	DoChange(nTab, sOldName);
+ }
  
-Index: sc/source/ui/miscdlgs/protectiondlg.cxx
-===================================================================
-RCS file: sc/source/ui/miscdlgs/protectiondlg.cxx
-diff -N sc/source/ui/miscdlgs/protectiondlg.cxx
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/miscdlgs/protectiondlg.cxx	23 May 2008 17:39:36 -0000	1.1.2.6
-@@ -0,0 +1,161 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: protectiondlg.cxx,v $
-+ * $Revision: 1.1.2.6 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#include "protectiondlg.hxx"
-+#include "protectiondlg.hrc"
-+#include "scresid.hxx"
-+#include "tabprotection.hxx"
-+
-+#include <vcl/msgbox.hxx>
-+
-+
-+// The order must match that of the list box.
-+static const ScTableProtection::Option aOptions[] = {
-+    ScTableProtection::SELECT_LOCKED_CELLS,
-+    ScTableProtection::SELECT_UNLOCKED_CELLS,
-+};
-+static const USHORT nOptionCount = sizeof(aOptions)/sizeof(aOptions[0]);
-+
-+
-+ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) :
-+    ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)),
-+
-+    maBtnProtect    (this, ScResId(BTN_PROTECT)),
-+    maPassword1Text (this, ScResId(FT_PASSWORD1)),
-+    maPassword1Edit (this, ScResId(ED_PASSWORD1)),
-+    maPassword2Text (this, ScResId(FT_PASSWORD2)),
-+    maPassword2Edit (this, ScResId(ED_PASSWORD2)),
-+    maOptionsLine   (this, ScResId(FL_OPTIONS)),
-+    maOptionsText   (this, ScResId(FT_OPTIONS)),
-+    maOptionsListBox(this, ScResId(CLB_OPTIONS)),
-+
-+    maBtnOk     (this, ScResId(BTN_OK)),
-+    maBtnCancel (this, ScResId(BTN_CANCEL)),
-+    maBtnHelp   (this, ScResId(BTN_HELP)),
-+
-+    maSelectLockedCells(ScResId(ST_SELECT_LOCKED_CELLS)),
-+    maSelectUnlockedCells(ScResId(ST_SELECT_UNLOCKED_CELLS))
-+{
-+    Init();
-+    FreeResource();
-+}
-+
-+ScTableProtectionDlg::~ScTableProtectionDlg()
-+{
-+}
-+
-+short ScTableProtectionDlg::Execute()
-+{
-+    return ModalDialog::Execute();
-+}
-+
-+void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
-+{
-+    for (USHORT i = 0; i < nOptionCount; ++i)
-+        maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
-+}
-+
-+void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
-+{
-+    rData.setProtected(maBtnProtect.IsChecked());
-+
-+    // We assume that the two password texts match.
-+    rData.setPassword(maPassword1Edit.GetText());
-+
-+    for (USHORT i = 0; i < nOptionCount; ++i)
-+        rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i));
-+}
-+
-+void ScTableProtectionDlg::Init()
-+{
-+    Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
-+    maBtnProtect.SetClickHdl(aLink);
-+
-+    aLink = LINK( this, ScTableProtectionDlg, OKHdl );
-+    maBtnOk.SetClickHdl(aLink);
-+
-+    aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
-+    maPassword1Edit.SetModifyHdl(aLink);
-+    maPassword2Edit.SetModifyHdl(aLink);
-+
-+    maOptionsListBox.SetUpdateMode(false);
-+    maOptionsListBox.Clear();
-+
-+    maOptionsListBox.InsertEntry(maSelectLockedCells);
-+    maOptionsListBox.InsertEntry(maSelectUnlockedCells);
-+
-+    maOptionsListBox.CheckEntryPos(0, true);
-+    maOptionsListBox.CheckEntryPos(1, true);
-+
-+    maOptionsListBox.SetUpdateMode(true);
-+
-+    // Set the default state of the dialog.
-+    maBtnProtect.Check(true);
-+    maPassword1Edit.GrabFocus();
-+}
-+
-+void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
-+{
-+    maPassword1Text.Enable(bEnable);
-+    maPassword1Edit.Enable(bEnable);
-+    maPassword2Text.Enable(bEnable);
-+    maPassword2Edit.Enable(bEnable);
-+    maOptionsLine.Enable(bEnable);
-+    maOptionsText.Enable(bEnable);
-+
-+    maOptionsListBox.Enable(bEnable);
-+    maOptionsListBox.Invalidate();
-+}
-+
-+IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
-+{
-+    if (pBtn == &maBtnProtect)
-+    {
-+        bool bChecked = maBtnProtect.IsChecked();
-+        EnableOptionalWidgets(bChecked);
-+        maBtnOk.Enable(bChecked);
-+    }
-+
-+    return 0;
-+}
-+
-+IMPL_LINK( ScTableProtectionDlg, OKHdl, OKButton*, EMPTYARG )
-+{
-+    EndDialog(RET_OK);
-+    return 0;
-+}
-+
-+IMPL_LINK( ScTableProtectionDlg, PasswordModifyHdl, Edit*, EMPTYARG )
-+{
-+    String aPass1 = maPassword1Edit.GetText();
-+    String aPass2 = maPassword2Edit.GetText();
-+    maBtnOk.Enable(aPass1.Equals(aPass2));
-+    return 0;
-+}
-Index: sc/source/ui/miscdlgs/protectiondlg.src
-===================================================================
-RCS file: sc/source/ui/miscdlgs/protectiondlg.src
-diff -N sc/source/ui/miscdlgs/protectiondlg.src
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/miscdlgs/protectiondlg.src	23 May 2008 00:07:53 -0000	1.1.2.6
-@@ -0,0 +1,130 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: protectiondlg.src,v $
-+ * $Revision: 1.1.2.6 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#include "protectiondlg.hrc"
-+
-+ModalDialog RID_SCDLG_TABPROTECTION
-+{
-+    Text [ en-US ] = "Protect Sheet" ;
-+    Size = MAP_APPFONT ( 220 , 135 ) ;
-+    Moveable = TRUE ;
-+    Closeable = TRUE ;
-+
-+    OKButton BTN_OK
-+    {
-+        Pos = MAP_APPFONT ( 164 , 6 ) ;
-+        Size = MAP_APPFONT ( 50 , 14 ) ;
-+        DefButton = TRUE ;
-+    };
-+    CancelButton BTN_CANCEL
-+    {
-+        Pos = MAP_APPFONT ( 164 , 23 ) ;
-+        Size = MAP_APPFONT ( 50 , 14 ) ;
-+    };
-+    HelpButton BTN_HELP
-+    {
-+        Pos = MAP_APPFONT ( 164 , 43 ) ;
-+        Size = MAP_APPFONT ( 50 , 14 ) ;
-+    };
-+
-+    CheckBox BTN_PROTECT
-+    {
-+        Pos = MAP_APPFONT ( 6 , 6 ) ;
-+        Size = MAP_APPFONT ( 150 , 10 );
-+
-+        Text [ en-US ] = "P~rotect this sheet and the contents of locked cells" ;
-+    };
-+
-+    FixedText FT_PASSWORD1
-+    {
-+        Pos = MAP_APPFONT ( 11, 23 );
-+        Size = MAP_APPFONT ( 42, 10 );
-+
-+        Text [ en-US ] = "~Password" ;
-+    };
-+
-+    Edit ED_PASSWORD1
-+    {
-+        Border = TRUE;
-+        PassWord = TRUE;
-+        Pos = MAP_APPFONT ( 56, 22 );
-+        Size = MAP_APPFONT ( 75, 12 );
-+    };
-+
-+    FixedText FT_PASSWORD2
-+    {
-+        Pos = MAP_APPFONT ( 11, 40 );
-+        Size = MAP_APPFONT ( 42, 10 );
-+
-+        Text [ en-US ] = "~Confirm" ;
-+    };
-+
-+    Edit ED_PASSWORD2
-+    {
-+        Border = TRUE;
-+        PassWord = TRUE;
-+        Pos = MAP_APPFONT ( 56, 39 );
-+        Size = MAP_APPFONT ( 75, 12 );
-+    };
-+
-+    FixedLine FL_OPTIONS
-+    {
-+        Pos = MAP_APPFONT ( 6, 60 );
-+        Size = MAP_APPFONT ( 150, 8 );
-+
-+        Text [ en-US ] = "Options";
-+    };
-+
-+    FixedText FT_OPTIONS
-+    {
-+        Pos = MAP_APPFONT ( 11, 74 );
-+        Size = MAP_APPFONT ( 140, 8 );
-+
-+        Text [ en-US ] = "Allow all users of this sheet to:";
-+    };
-+
-+    Control CLB_OPTIONS
-+    {
-+        Pos = MAP_APPFONT ( 11, 85 );
-+        Size = MAP_APPFONT ( 140, 40 );
-+        Border = TRUE ;
-+        TabStop = TRUE ;
-+    };
-+
-+    String ST_SELECT_LOCKED_CELLS
-+    {
-+        Text [ en-US ] = "Select locked cells";
-+    };
-+
-+    String ST_SELECT_UNLOCKED_CELLS
-+    {
-+        Text [ en-US ] = "Select unlocked cells";
-+    };
-+};
-Index: sc/source/ui/miscdlgs/retypepassdlg.cxx
-===================================================================
-RCS file: sc/source/ui/miscdlgs/retypepassdlg.cxx
-diff -N sc/source/ui/miscdlgs/retypepassdlg.cxx
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/miscdlgs/retypepassdlg.cxx	23 May 2008 00:10:22 -0000	1.1.2.7
-@@ -0,0 +1,544 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: retypepassdlg.cxx,v $
-+ * $Revision: 1.1.2.7 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#include "retypepassdlg.hxx"
-+#include "retypepassdlg.hrc"
-+#include "scresid.hxx"
-+#include "document.hxx"
-+#include "tabprotection.hxx"
-+
-+#include <stdio.h>
-+
-+#include <vcl/msgbox.hxx>
-+
-+ScRetypePassDlg::ScRetypePassDlg(Window* pParent) :
-+    ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS)),
-+
-+    maBtnOk     (this, ScResId(BTN_OK)),
-+    maBtnCancel (this, ScResId(BTN_CANCEL)),
-+    maBtnHelp   (this, ScResId(BTN_HELP)),
-+
-+    maTextDescription(this, ScResId(FT_DESC)),
-+    maLineDocument(this, ScResId(FL_DOCUMENT)),
-+    maTextDocStatus(this, ScResId(FT_DOCSTATUS)),
-+    maBtnRetypeDoc(this, ScResId(BTN_RETYPE_DOC)),
-+
-+    maLineSheet(this, ScResId(FL_SHEET)),
-+    maTextSheetName1(this, ScResId(FT_SHEETNAME1)),
-+    maTextSheetStatus1(this, ScResId(FT_SHEETSTATUS1)),
-+    maBtnRetypeSheet1(this, ScResId(BTN_RETYPE_SHEET1)),
-+
-+    maTextSheetName2(this, ScResId(FT_SHEETNAME2)),
-+    maTextSheetStatus2(this, ScResId(FT_SHEETSTATUS2)),
-+    maBtnRetypeSheet2(this, ScResId(BTN_RETYPE_SHEET2)),
-+
-+    maTextSheetName3(this, ScResId(FT_SHEETNAME3)),
-+    maTextSheetStatus3(this, ScResId(FT_SHEETSTATUS3)),
-+    maBtnRetypeSheet3(this, ScResId(BTN_RETYPE_SHEET3)),
-+
-+    maTextSheetName4(this, ScResId(FT_SHEETNAME4)),
-+    maTextSheetStatus4(this, ScResId(FT_SHEETSTATUS4)),
-+    maBtnRetypeSheet4(this, ScResId(BTN_RETYPE_SHEET4)),
-+
-+    maScrollBar (this, ScResId(SB_SCROLL)),
-+
-+    maTextNotProtected(ScResId(STR_NOT_PROTECTED)),
-+    maTextNotPassProtected(ScResId(STR_NOT_PASS_PROTECTED)),
-+    maTextHashBad(ScResId(STR_HASH_BAD)),
-+    maTextHashGood(ScResId(STR_HASH_GOOD)),
-+    maTextHashRegen(ScResId(STR_HASH_REGENERATED)),
-+
-+    mpDocItem(static_cast<ScDocProtection*>(NULL)),
-+    mnCurScrollPos(0),
-+    meDesiredHash(PASSHASH_OOO)
-+{
-+    Init();
-+}
-+
-+ScRetypePassDlg::~ScRetypePassDlg()
-+{
-+}
-+
-+short ScRetypePassDlg::Execute()
-+{
-+    PopulateDialog();
-+    CheckHashStatus();
-+    return ModalDialog::Execute();
-+}
-+
-+void ScRetypePassDlg::SetData(const ScDocument& rDoc)
-+{
-+    const ScDocProtection* pDocProtect = rDoc.GetDocProtection();
-+    if (pDocProtect && pDocProtect->isProtected())
-+        mpDocItem.reset(new ScDocProtection(*pDocProtect));
-+
-+    SCTAB nTabCount = rDoc.GetTableCount();
-+    maTableItems.reserve(nTabCount);
-+    for (SCTAB i = 0; i < nTabCount; ++i)
-+    {
-+        TableItem aTabItem;
-+        rDoc.GetName(i, aTabItem.maName);
-+
-+        const ScTableProtection* pTabProtect = rDoc.GetTabProtection(i);
-+        if (pTabProtect && pTabProtect->isProtected())
-+            aTabItem.mpProtect.reset(new ScTableProtection(*pTabProtect));
-+
-+        maTableItems.push_back(aTabItem);
-+    }
-+}
-+
-+void ScRetypePassDlg::SetDesiredHash(ScPasswordHash eHash)
-+{
-+    meDesiredHash = eHash;
-+}
-+
-+void ScRetypePassDlg::WriteNewDataToDocument(ScDocument& rDoc) const
-+{
-+    if (mpDocItem.get())
-+        rDoc.SetDocProtection(mpDocItem.get());
-+
-+    SCTAB nTabCount = rDoc.GetTableCount();
-+    size_t n = maTableItems.size();
-+    for (size_t i = 0; i < n; ++i)
-+    {
-+        if (i >= nTabCount)
-+            break;
-+
-+        ScTableProtection* pTabProtect = maTableItems[i].mpProtect.get();
-+        if (pTabProtect)
-+            rDoc.SetTabProtection(static_cast<SCTAB>(i), pTabProtect);
-+    }
-+}
-+
-+void ScRetypePassDlg::Init()
-+{
-+    Link aLink = LINK( this, ScRetypePassDlg, OKHdl );
-+    maBtnOk.SetClickHdl(aLink);
-+
-+    aLink = LINK( this, ScRetypePassDlg, RetypeBtnHdl );
-+    maBtnRetypeDoc.SetClickHdl(aLink);
-+    maBtnRetypeSheet1.SetClickHdl(aLink);
-+    maBtnRetypeSheet2.SetClickHdl(aLink);
-+    maBtnRetypeSheet3.SetClickHdl(aLink);
-+    maBtnRetypeSheet4.SetClickHdl(aLink);
-+
-+    maTextDocStatus.SetText(maTextNotProtected);
-+    maTextSheetStatus1.SetText(maTextNotProtected);
-+    maTextSheetStatus2.SetText(maTextNotProtected);
-+    maTextSheetStatus3.SetText(maTextNotProtected);
-+    maTextSheetStatus4.SetText(maTextNotProtected);
-+    maBtnRetypeDoc.Disable();
-+
-+    // Make all sheet rows invisible.
-+
-+    maTextSheetName1.Show(false);
-+    maTextSheetStatus1.Show(false);
-+    maBtnRetypeSheet1.Show(false);
-+    maBtnRetypeSheet1.Disable();
-+    
-+    maTextSheetName2.Show(false);
-+    maTextSheetStatus2.Show(false);
-+    maBtnRetypeSheet2.Show(false);
-+    maBtnRetypeSheet2.Disable();
-+
-+    maTextSheetName3.Show(false);
-+    maTextSheetStatus3.Show(false);
-+    maBtnRetypeSheet3.Show(false);
-+    maBtnRetypeSheet3.Disable();
-+
-+    maTextSheetName4.Show(false);
-+    maTextSheetStatus4.Show(false);
-+    maBtnRetypeSheet4.Show(false);
-+    maBtnRetypeSheet4.Disable();
-+
-+    maScrollBar.Show(false);
-+
-+    maScrollBar.SetEndScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
-+    maScrollBar.SetScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
-+
-+    maScrollBar.SetPageSize(4);
-+    maScrollBar.SetVisibleSize(4);
-+    maScrollBar.SetLineSize(1);
-+}
-+
-+void ScRetypePassDlg::PopulateDialog()
-+{
-+    // Document protection first.
-+    SetDocData();
-+
-+    // Sheet protection next.  We're only interested in the first 4 sheets
-+    // (or less).
-+    size_t n = maTableItems.size();
-+    for (size_t i = 0; i < n && i < 4; ++i)
-+        SetTableData(i, i);
-+
-+    if (n > 4)
-+    {
-+        maScrollBar.Show(true);
-+        maScrollBar.SetRange(Range(0, n));
-+    }
-+}
-+
-+void ScRetypePassDlg::SetDocData()
-+{
-+    bool bBtnEnabled = false;
-+    if (mpDocItem.get() && mpDocItem->isProtected())
-+    {
-+        if (mpDocItem->isPasswordEmpty())
-+            maTextDocStatus.SetText(maTextNotPassProtected);
-+        else if (mpDocItem->hasPasswordHash(meDesiredHash))
-+            maTextDocStatus.SetText(maTextHashGood);
-+        else
-+        {
-+            // incompatible hash
-+            maTextDocStatus.SetText(maTextHashBad);
-+            bBtnEnabled = true;
-+        }
-+    }
-+    maBtnRetypeDoc.Enable(bBtnEnabled);
-+}
-+
-+void ScRetypePassDlg::SetTableData(sal_uInt8 nRowPos, SCTAB nTab)
-+{
-+    if (nRowPos >= 4)
-+        return;
-+
-+    FixedText* pName = NULL;
-+    FixedText* pStatus = NULL;
-+    PushButton* pBtn = NULL;
-+    switch (nRowPos)
-+    {
-+        case 0:
-+            pName = &maTextSheetName1;
-+            pStatus = &maTextSheetStatus1;
-+            pBtn = &maBtnRetypeSheet1;
-+        break;
-+        case 1:
-+            pName = &maTextSheetName2;
-+            pStatus = &maTextSheetStatus2;
-+            pBtn = &maBtnRetypeSheet2;
-+        break;
-+        case 2:
-+            pName = &maTextSheetName3;
-+            pStatus = &maTextSheetStatus3;
-+            pBtn = &maBtnRetypeSheet3;
-+        break;
-+        case 3:
-+            pName = &maTextSheetName4;
-+            pStatus = &maTextSheetStatus4;
-+            pBtn = &maBtnRetypeSheet4;
-+        break;
-+        default:
-+            return;
-+    }
-+
-+    bool bBtnEnabled = false;
-+    pName->SetText(maTableItems[nTab].maName);
-+    pName->Show(true);
-+    const ScTableProtection* pTabProtect = maTableItems[nTab].mpProtect.get();
-+    if (pTabProtect && pTabProtect->isProtected())
-+    {
-+        if (pTabProtect->isPasswordEmpty())
-+            pStatus->SetText(maTextNotPassProtected);
-+        else if (pTabProtect->hasPasswordHash(meDesiredHash))
-+            pStatus->SetText(maTextHashGood);
-+        else
-+        {
-+            // incompatible hash 
-+            pStatus->SetText(maTextHashBad);
-+            bBtnEnabled = true;
-+        }
-+    }
-+    else
-+        pStatus->SetText(maTextNotProtected);
-+
-+    pStatus->Show(true);
-+    pBtn->Show(true);
-+    pBtn->Enable(bBtnEnabled);
-+}
-+
-+void ScRetypePassDlg::ResetTableRows()
-+{
-+    long nScrollPos = maScrollBar.GetThumbPos();
-+    mnCurScrollPos = nScrollPos < 0 ? 0 : nScrollPos;
-+    size_t nRowCount = maTableItems.size() - nScrollPos;
-+    for (size_t i = 0; i < nRowCount; ++i)
-+        SetTableData(i, i + nScrollPos);
-+}
-+
-+bool lcl_IsInGoodStatus(ScPassHashProtectable* pProtected, ScPasswordHash eDesiredHash)
-+{
-+    if (!pProtected || !pProtected->isProtected())
-+        // Not protected.
-+        return true;
-+
-+    if (pProtected->isPasswordEmpty())
-+        return true;
-+
-+    if (pProtected->hasPasswordHash(eDesiredHash))
-+        return true;
-+
-+    return false;
-+}
-+
-+void ScRetypePassDlg::CheckHashStatus()
-+{
-+    do
-+    {
-+        if (!lcl_IsInGoodStatus(mpDocItem.get(), meDesiredHash))
-+            break;
-+
-+        bool bStatusGood = true;
-+        size_t nTabCount = maTableItems.size();
-+        for (size_t i = 0; i < nTabCount && bStatusGood; ++i)
-+        {
-+            if (!lcl_IsInGoodStatus(maTableItems[i].mpProtect.get(), meDesiredHash))
-+                bStatusGood = false;
-+        }
-+        if (!bStatusGood)
-+            break;
-+
-+        maBtnOk.Enable();
-+        return;
-+    }
-+    while (false);
-+
-+    maBtnOk.Disable();
-+}
-+
-+IMPL_LINK( ScRetypePassDlg, OKHdl, OKButton*, EMPTYARG )
-+{
-+    EndDialog(RET_OK);
-+    return 0;
-+}
-+
-+IMPL_LINK( ScRetypePassDlg, RetypeBtnHdl, PushButton*, pBtn )
-+{
-+    ScPassHashProtectable* pProtected = NULL;
-+    if (pBtn == &maBtnRetypeDoc)
-+    {
-+        // document protection.
-+        pProtected = mpDocItem.get();
-+    }
-+    else
-+    {
-+        // sheet protection.
-+        size_t nTabPos = mnCurScrollPos;
-+        if (pBtn == &maBtnRetypeSheet2)
-+            nTabPos += 1;
-+        else if (pBtn == &maBtnRetypeSheet3)
-+            nTabPos += 2;
-+        else if (pBtn == &maBtnRetypeSheet4)
-+            nTabPos += 3;
-+        else if (pBtn != &maBtnRetypeSheet1)
-+            // This should never happen !
-+            return 0;
-+
-+        if (nTabPos >= maTableItems.size())
-+            // Likewise, this should never happen !
-+            return 0;
-+
-+        pProtected = maTableItems[nTabPos].mpProtect.get();
-+    }
-+
-+    if (!pProtected)
-+        // What the ... !?
-+        return 0;
-+
-+    ScRetypePassInputDlg aDlg(this, pProtected);
-+    if (aDlg.Execute() == RET_OK)
-+    {
-+        // OK is pressed.  Update the protected item.
-+        if (aDlg.IsRemovePassword())
-+        {
-+            // Remove password from this item.
-+            pProtected->setPassword(String());
-+        }
-+        else
-+        {
-+            // Set a new password.
-+            String aNewPass = aDlg.GetNewPassword();
-+            pProtected->setPassword(aNewPass);
-+        }
-+
-+        SetDocData();
-+        ResetTableRows();
-+        CheckHashStatus();
-+    }
-+    return 0;
-+}
-+
-+IMPL_LINK( ScRetypePassDlg, ScrollHdl, ScrollBar*, EMPTYARG )
-+{
-+    ResetTableRows();
-+    return 0;
-+}
-+
-+// ============================================================================
-+
-+ScRetypePassInputDlg::ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected) :
-+    ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS_INPUT)),
-+
-+    maBtnOk     (this, ScResId(BTN_OK)),
-+    maBtnCancel (this, ScResId(BTN_CANCEL)),
-+    maBtnHelp   (this, ScResId(BTN_HELP)),
-+
-+    maBtnRetypePassword(this, ScResId(BTN_RETYPE_PASSWORD)),
-+
-+    maPassword1Text (this, ScResId(FT_PASSWORD1)),
-+    maPassword1Edit (this, ScResId(ED_PASSWORD1)),
-+    maPassword2Text (this, ScResId(FT_PASSWORD2)),
-+    maPassword2Edit (this, ScResId(ED_PASSWORD2)),
-+    maBtnMatchOldPass(this, ScResId(BTN_MATCH_OLD_PASSWORD)),
-+
-+    maBtnRemovePassword(this, ScResId(BTN_REMOVE_PASSWORD)),
-+
-+    mpProtected(pProtected)
-+{
-+    Init();
-+}
-+
-+ScRetypePassInputDlg::~ScRetypePassInputDlg()
-+{
-+}
-+
-+short ScRetypePassInputDlg::Execute()
-+{
-+    return ModalDialog::Execute();
-+}
-+
-+bool ScRetypePassInputDlg::IsRemovePassword() const
-+{
-+    return maBtnRemovePassword.IsChecked();
-+}
-+
-+String ScRetypePassInputDlg::GetNewPassword() const
-+{
-+    return maPassword1Edit.GetText();
-+}
-+
-+void ScRetypePassInputDlg::Init()
-+{
-+    Link aLink = LINK( this, ScRetypePassInputDlg, OKHdl );
-+    maBtnOk.SetClickHdl(aLink);
-+    aLink = LINK( this, ScRetypePassInputDlg, RadioBtnHdl );
-+    maBtnRetypePassword.SetClickHdl(aLink);
-+    maBtnRemovePassword.SetClickHdl(aLink);
-+    aLink = LINK( this, ScRetypePassInputDlg, CheckBoxHdl );
-+    maBtnMatchOldPass.SetClickHdl(aLink);
-+    aLink = LINK( this, ScRetypePassInputDlg, PasswordModifyHdl );
-+    maPassword1Edit.SetModifyHdl(aLink);
-+    maPassword2Edit.SetModifyHdl(aLink);
-+
-+    maBtnOk.Disable();
-+    maBtnRetypePassword.Check(true);
-+    maBtnMatchOldPass.Check(true);
-+    maPassword1Edit.GrabFocus();
-+}
-+
-+void ScRetypePassInputDlg::CheckPasswordInput()
-+{
-+    String aPass1 = maPassword1Edit.GetText();
-+    String aPass2 = maPassword2Edit.GetText();
-+
-+    if (!aPass1.Len() || !aPass2.Len())
-+    {
-+        // Empty password is not allowed.
-+        maBtnOk.Disable();
-+        return;
-+    }
-+
-+    if (!aPass1.Equals(aPass2))
-+    {
-+        // The two passwords differ.
-+        maBtnOk.Disable();
-+        return;
-+    }
-+
-+    if (!maBtnMatchOldPass.IsChecked())
-+    {
-+        maBtnOk.Enable();
-+        return;
-+    }
-+
-+    if (!mpProtected)
-+    {
-+        // This should never happen!
-+        maBtnOk.Disable();
-+        return;
-+    }
-+
-+    bool bPassGood = mpProtected->verifyPassword(aPass1);
-+    maBtnOk.Enable(bPassGood);
-+}
-+
-+IMPL_LINK( ScRetypePassInputDlg, OKHdl, OKButton*, EMPTYARG )
-+{
-+    EndDialog(RET_OK);
-+    return 0;
-+}
-+
-+IMPL_LINK( ScRetypePassInputDlg, RadioBtnHdl, RadioButton*, pBtn )
-+{
-+    if (pBtn == &maBtnRetypePassword)
-+    {
-+        maBtnRemovePassword.Check(false);
-+        maPassword1Text.Enable();
-+        maPassword1Edit.Enable();
-+        maPassword2Text.Enable();
-+        maPassword2Edit.Enable();
-+        maBtnMatchOldPass.Enable();
-+        CheckPasswordInput();
-+    }
-+    else if (pBtn == &maBtnRemovePassword)
-+    {
-+        maBtnRetypePassword.Check(false);
-+        maPassword1Text.Disable();
-+        maPassword1Edit.Disable();
-+        maPassword2Text.Disable();
-+        maPassword2Edit.Disable();
-+        maBtnMatchOldPass.Disable();
-+        maBtnOk.Enable();
-+    }
-+
-+    return 0;
-+}
-+
-+IMPL_LINK( ScRetypePassInputDlg, CheckBoxHdl, CheckBox*, pBtn )
-+{
-+    CheckPasswordInput();
-+    return 0;
-+}
-+
-+IMPL_LINK( ScRetypePassInputDlg, PasswordModifyHdl, Edit*, pEdit )
-+{
-+    CheckPasswordInput();
-+    return 0;
-+}
-Index: sc/source/ui/miscdlgs/retypepassdlg.src
-===================================================================
-RCS file: sc/source/ui/miscdlgs/retypepassdlg.src
-diff -N sc/source/ui/miscdlgs/retypepassdlg.src
---- /dev/null	1 Jan 1970 00:00:00 -0000
-+++ sc/source/ui/miscdlgs/retypepassdlg.src	23 May 2008 00:11:30 -0000	1.1.2.3
-@@ -0,0 +1,316 @@
-+/*************************************************************************
-+ *
-+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-+ * 
-+ * Copyright 2008 by Sun Microsystems, Inc.
-+ *
-+ * OpenOffice.org - a multi-platform office productivity suite
-+ *
-+ * $RCSfile: retypepassdlg.src,v $
-+ * $Revision: 1.1.2.3 $
-+ *
-+ * This file is part of OpenOffice.org.
-+ *
-+ * OpenOffice.org is free software: you can redistribute it and/or modify
-+ * it under the terms of the GNU Lesser General Public License version 3
-+ * only, as published by the Free Software Foundation.
-+ *
-+ * OpenOffice.org is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-+ * GNU Lesser General Public License version 3 for more details
-+ * (a copy is included in the LICENSE file that accompanied this code).
-+ *
-+ * You should have received a copy of the GNU Lesser General Public License
-+ * version 3 along with OpenOffice.org.  If not, see
-+ * <http://www.openoffice.org/license.html>
-+ * for a copy of the LGPLv3 License.
-+ *
-+ ************************************************************************/
-+
-+#include "retypepassdlg.hrc"
-+
-+
-+ModalDialog RID_SCDLG_RETYPEPASS
-+{
-+    Text [ en-US ] = "Re-type Password" ;
-+    Size = MAP_APPFONT ( 260 , 165 ) ;
-+    Moveable = TRUE ;
-+    Closeable = TRUE ;
-+
-+    OKButton BTN_OK
-+    {
-+        Pos = MAP_APPFONT ( 204, 6 ) ;
-+        Size = MAP_APPFONT ( 50, 14 ) ;
-+        DefButton = TRUE ;
-+    };
-+
-+    CancelButton BTN_CANCEL
-+    {
-+        Pos = MAP_APPFONT ( 204, 23 ) ;
-+        Size = MAP_APPFONT ( 50, 14 ) ;
-+    };
-+
-+    HelpButton BTN_HELP
-+    {
-+        Pos = MAP_APPFONT ( 204, 43 ) ;
-+        Size = MAP_APPFONT ( 50, 14 ) ;
-+    };
-+
-+    FixedText FT_DESC
-+    {
-+        Pos = MAP_APPFONT ( 6, 6 ) ;
-+        Size = MAP_APPFONT ( 190, 36 );
-+
-+        WordBreak = TRUE ;
-+
-+        Text [ en-US ] = "The document you are about to export has one or more protected items with password that cannot be exported.  Please re-type your password to be able to export your document." ;
-+    };
-+
-+    FixedLine FL_DOCUMENT
-+    {
-+        Pos = MAP_APPFONT ( 6, 48 );
-+        Size = MAP_APPFONT ( 190, 8 );
-+
-+        Text [ en-US ] = "Document protection" ;
-+    };
-+
-+    FixedText FT_DOCSTATUS
-+    {
-+        Pos = MAP_APPFONT ( 10, 62 );
-+        Size = MAP_APPFONT ( 140, 8 );
-+
-+        Text [ en-US ] = "Status unknown" ;
-+    };
-+
-+    PushButton BTN_RETYPE_DOC
-+    {
-+        Pos = MAP_APPFONT ( 158, 59 );
-+        Size = MAP_APPFONT ( 30, 14 );
-+
-+        Text [ en-US ] = "Re-type" ;
-+    };
-+
-+    FixedLine FL_SHEET
-+    {
-+        Pos = MAP_APPFONT ( 6, 83 );
-+        Size = MAP_APPFONT ( 190, 8 );
-+
-+        Text [ en-US ] = "Sheet protection" ;
-+    };
-+
-+    FixedText FT_SHEETNAME1
-+    {
-+        Pos = MAP_APPFONT ( 10, 97 );
-+        Size = MAP_APPFONT ( 68, 8 );
-+
-+        Text [ en-US ] = "Sheet1 has a really long name" ;
-+    };
-+
-+    FixedText FT_SHEETSTATUS1
-+    {
-+        Pos = MAP_APPFONT ( 82, 97 );
-+        Size = MAP_APPFONT ( 72, 8 );
-+
-+        Text [ en-US ] = "Status unknown" ;
-+    };
-+
-+    PushButton BTN_RETYPE_SHEET1
-+    {
-+        Pos = MAP_APPFONT ( 158, 94 );
-+        Size = MAP_APPFONT ( 30, 14 );
-+
-+        Text [ en-US ] = "Re-type" ;
-+    };
-+
-+    FixedText FT_SHEETNAME2
-+    {
-+        Pos = MAP_APPFONT ( 10, 113 );
-+        Size = MAP_APPFONT ( 68, 8 );
-+
-+        Text [ en-US ] = "Sheet2" ;
-+    };
-+
-+    FixedText FT_SHEETSTATUS2
-+    {
-+        Pos = MAP_APPFONT ( 82, 113 );
-+        Size = MAP_APPFONT ( 72, 8 );
-+
-+        Text [ en-US ] = "Status unknown" ;
-+    };
-+
-+    PushButton BTN_RETYPE_SHEET2
-+    {
-+        Pos = MAP_APPFONT ( 158, 110 );
-+        Size = MAP_APPFONT ( 30, 14 );
-+
-+        Text [ en-US ] = "Re-type" ;
-+    };
-+
-+    FixedText FT_SHEETNAME3
-+    {
-+        Pos = MAP_APPFONT ( 10, 129 );
-+        Size = MAP_APPFONT ( 68, 8 );
-+
-+        Text [ en-US ] = "Sheet3" ;
-+    };
-+
-+    FixedText FT_SHEETSTATUS3
-+    {
-+        Pos = MAP_APPFONT ( 82, 129 );
-+        Size = MAP_APPFONT ( 72, 8 );
-+
-+        Text [ en-US ] = "Status unknown" ;
-+    };
-+
-+    PushButton BTN_RETYPE_SHEET3
-+    {
-+        Pos = MAP_APPFONT ( 158, 126 );
-+        Size = MAP_APPFONT ( 30, 14 );
-+
-+        Text [ en-US ] = "Re-type" ;
-+    };
-+
-+    FixedText FT_SHEETNAME4
-+    {
-+        Pos = MAP_APPFONT ( 10, 145 );
-+        Size = MAP_APPFONT ( 68, 8 );
-+
-+        Text [ en-US ] = "Sheet4" ;
-+    };
-+
-+    FixedText FT_SHEETSTATUS4
-+    {
-+        Pos = MAP_APPFONT ( 82, 145 );
-+        Size = MAP_APPFONT ( 72, 8 );
-+
-+        Text [ en-US ] = "Status unknown" ;
-+    };
-+
-+    PushButton BTN_RETYPE_SHEET4
-+    {
-+        Pos = MAP_APPFONT ( 158, 142 );
-+        Size = MAP_APPFONT ( 30, 14 );
-+
-+        Text [ en-US ] = "Re-type" ;
-+    };
-+
-+    ScrollBar SB_SCROLL
-+    {
-+        Pos = MAP_APPFONT ( 190, 94 ) ;
-+        Size = MAP_APPFONT (  8, 61 ) ;
-+        VScroll = TRUE ;
-+    };
-+
-+    String STR_NOT_PROTECTED
-+    {
-+        Text [ en-US ] = "Not protected" ;
-+    };
-+
-+    String STR_NOT_PASS_PROTECTED
-+    {
-+        Text [ en-US ] = "Not password-protected" ;
-+    };
-+
-+    String STR_HASH_BAD
-+    {
-+        Text [ en-US ] = "Hash incompatible" ;
-+    };
-+
-+    String STR_HASH_GOOD
-+    {
-+        Text [ en-US ] = "Hash compatible" ;
-+    };
-+
-+    String STR_HASH_REGENERATED
-+    {
-+        Text [ en-US ] = "Hash re-generated" ;
-+    };
-+};
-+
-+// ----------------------------------------------------------------------------
-+
-+ModalDialog RID_SCDLG_RETYPEPASS_INPUT
-+{
-+    Text [ en-US ] = "Re-type Password" ;
-+    Size = MAP_APPFONT ( 230 , 110 ) ;
-+    Moveable = TRUE ;
-+    Closeable = TRUE ;
-+
-+    OKButton BTN_OK
-+    {
-+        Pos = MAP_APPFONT ( 174, 6 ) ;
-+        Size = MAP_APPFONT ( 50, 14 ) ;
-+        DefButton = TRUE ;
-+    };
-+
-+    CancelButton BTN_CANCEL
-+    {
-+        Pos = MAP_APPFONT ( 174, 23 ) ;
-+        Size = MAP_APPFONT ( 50, 14 ) ;
-+    };
-+
-+    HelpButton BTN_HELP
-+    {
-+        Pos = MAP_APPFONT ( 174, 43 ) ;
-+        Size = MAP_APPFONT ( 50, 14 ) ;
-+    };
-+
-+    RadioButton BTN_RETYPE_PASSWORD
-+    {
-+        Pos = MAP_APPFONT ( 11, 10 );
-+        Size = MAP_APPFONT ( 150, 10 );
-+
-+        Text [ en-US ] = "Re-type password" ;
-+    };
-+
-+    FixedText FT_PASSWORD1
-+    {
-+        Pos = MAP_APPFONT ( 20, 30 );
-+        Size = MAP_APPFONT ( 42, 10 );
-+
-+        Text [ en-US ] = "~Password" ;
-+    };
-+
-+    Edit ED_PASSWORD1
-+    {
-+        Border = TRUE;
-+        PassWord = TRUE;
-+        Pos = MAP_APPFONT ( 65, 29 );
-+        Size = MAP_APPFONT ( 75, 12 );
-+    };
-+
-+    FixedText FT_PASSWORD2
-+    {
-+        Pos = MAP_APPFONT ( 20, 45 );
-+        Size = MAP_APPFONT ( 42, 10 );
-+
-+        Text [ en-US ] = "~Confirm" ;
-+    };
-+
-+    Edit ED_PASSWORD2
-+    {
-+        Border = TRUE;
-+        PassWord = TRUE;
-+        Pos = MAP_APPFONT ( 65, 44 );
-+        Size = MAP_APPFONT ( 75, 12 );
-+    };
-+
-+    CheckBox BTN_MATCH_OLD_PASSWORD
-+    {
-+        Pos = MAP_APPFONT ( 20, 65 );
-+        Size = MAP_APPFONT ( 150, 10 );
-+
-+        Text [ en-US ] = "New password must match the original password." ;
-+    };
-+
-+    RadioButton BTN_REMOVE_PASSWORD
-+    {
-+        Pos = MAP_APPFONT ( 11, 90 );
-+        Size = MAP_APPFONT ( 150, 10 );
-+
-+        Text [ en-US ] = "Remove password from this protected item." ;
-+    };
-+};
-+
-+
-Index: sc/source/ui/undo/undotab.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/undo/undotab.cxx,v
-retrieving revision 1.21
-retrieving revision 1.18.56.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.21 -r1.18.56.5
---- sc/source/ui/undo/undotab.cxx	11 Jul 2008 07:09:57 -0000	1.21
-+++ sc/source/ui/undo/undotab.cxx	17 Jul 2008 00:59:55 -0000	1.18.56.5
-@@ -61,6 +61,7 @@
- #include "prnsave.hxx"
- #include "printfun.hxx"
- #include "chgtrack.hxx"
-+#include "tabprotection.hxx"
+-void __EXPORT ScUndoRenameTab::Redo()
++void ScUndoRenameTab::Redo()
+ {
+ 	DoChange(nTab, sNewName);
+ }
+ 
+-void __EXPORT ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
+ {
+ 	//	Repeat macht keinen Sinn
+ }
+ 
+-BOOL __EXPORT ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+ {
+ 	return FALSE;
+ }
+@@ -565,13 +567,13 @@
+         theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
+ }
+ 
+-__EXPORT ScUndoMoveTab::~ScUndoMoveTab()
++ScUndoMoveTab::~ScUndoMoveTab()
+ {
+ 	theNewTabs.Remove(0,theNewTabs.Count());
+ 	theOldTabs.Remove(0,theOldTabs.Count());
+ }
+ 
+-String __EXPORT ScUndoMoveTab::GetComment() const
++String ScUndoMoveTab::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
+ }
+@@ -618,22 +620,22 @@
+ 	pDocShell->PostDataChanged();
+ }
+ 
+-void __EXPORT ScUndoMoveTab::Undo()
++void ScUndoMoveTab::Undo()
+ {
+ 	DoChange( TRUE );
+ }
  
- // for ScUndoRenameObject - might me moved to another file later
- #include <svx/svditer.hxx>
-@@ -72,6 +73,8 @@
- extern BOOL bDrawIsInUndo;			//! irgendwo als Member !!!
+-void __EXPORT ScUndoMoveTab::Redo()
++void ScUndoMoveTab::Redo()
+ {
+ 	DoChange( FALSE );
+ }
  
- using namespace com::sun::star;
-+using ::com::sun::star::uno::Sequence;
-+using ::std::auto_ptr;
+-void __EXPORT ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
+ {
+ 		// kein Repeat ! ? !
+ }
  
- // STATIC DATA -----------------------------------------------------------
+-BOOL __EXPORT ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+ {
+ 	return FALSE;
+ }
+@@ -660,12 +662,12 @@
+         theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
+ }
  
-@@ -85,7 +88,6 @@
- TYPEINIT1(ScUndoImportTab,		SfxUndoAction);
- TYPEINIT1(ScUndoRemoveLink,		SfxUndoAction);
- TYPEINIT1(ScUndoShowHideTab,	SfxUndoAction);
--TYPEINIT1(ScUndoProtect,		SfxUndoAction);
- TYPEINIT1(ScUndoPrintRange,		SfxUndoAction);
- TYPEINIT1(ScUndoScenarioFlags,	SfxUndoAction);
- TYPEINIT1(ScUndoRenameObject,	SfxUndoAction);
-@@ -112,12 +114,12 @@
- 	SetChangeTrack();
+-__EXPORT ScUndoCopyTab::~ScUndoCopyTab()
++ScUndoCopyTab::~ScUndoCopyTab()
+ {
+ 	DeleteSdrUndoAction( pDrawUndo );
  }
  
--__EXPORT ScUndoInsertTab::~ScUndoInsertTab()
-+ScUndoInsertTab::~ScUndoInsertTab()
+-String __EXPORT ScUndoCopyTab::GetComment() const
++String ScUndoCopyTab::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
+ }
+@@ -684,7 +686,7 @@
+ 	pDocShell->PostDataChanged();
+ }
+ 
+-void __EXPORT ScUndoCopyTab::Undo()
++void ScUndoCopyTab::Undo()
+ {
+ 	ScDocument* pDoc = pDocShell->GetDocument();
+ 
+@@ -717,7 +719,7 @@
+ 	DoChange();
+ }
+ 
+-void __EXPORT ScUndoCopyTab::Redo()
++void ScUndoCopyTab::Redo()
+ {
+ 	ScDocument* pDoc = pDocShell->GetDocument();
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+@@ -756,7 +758,7 @@
+ 		}
+ 
+ 		if ( pDoc->IsTabProtected( nAdjSource ) )
+-			pDoc->SetTabProtection( nNewTab, TRUE, pDoc->GetTabPassword( nAdjSource ) );
++            pDoc->CopyTabProtection(nAdjSource, nNewTab);
+ 	}
+ 
+     RedoSdrUndoAction( pDrawUndo );             // after the sheets are inserted
+@@ -767,12 +769,12 @@
+ 
+ }
+ 
+-void __EXPORT ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
+ {
+ 		// kein Repeat ! ? !
+ }
+ 
+-BOOL __EXPORT ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+ {
+ 	return FALSE;
+ }
+@@ -801,17 +803,17 @@
+     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
+ }
+ 
+-__EXPORT ScUndoMakeScenario::~ScUndoMakeScenario()
++ScUndoMakeScenario::~ScUndoMakeScenario()
+ {
+     DeleteSdrUndoAction( pDrawUndo );
+ }
+ 
+-String __EXPORT ScUndoMakeScenario::GetComment() const
++String ScUndoMakeScenario::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
+ }
+ 
+-void __EXPORT ScUndoMakeScenario::Undo()
++void ScUndoMakeScenario::Undo()
+ {
+ 	ScDocument* pDoc = pDocShell->GetDocument();
+ 
+@@ -836,7 +838,7 @@
+     pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
+ }
+ 
+-void __EXPORT ScUndoMakeScenario::Redo()
++void ScUndoMakeScenario::Redo()
+ {
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ 	if (pViewShell)
+@@ -858,7 +860,7 @@
+ 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
+ }
+ 
+-void __EXPORT ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
+ {
+ 	if (rTarget.ISA(ScTabViewTarget))
+ 	{
+@@ -866,7 +868,7 @@
+ 	}
+ }
+ 
+-BOOL __EXPORT ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
+ {
+ 	return (rTarget.ISA(ScTabViewTarget));
+ }
+@@ -889,13 +891,13 @@
+ 	pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
+ }
+ 
+-__EXPORT ScUndoImportTab::~ScUndoImportTab()
++ScUndoImportTab::~ScUndoImportTab()
+ {
+ 	delete pRedoDoc;
+ 	DeleteSdrUndoAction( pDrawUndo );
+ }
+ 
+-String __EXPORT ScUndoImportTab::GetComment() const
++String ScUndoImportTab::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
+ }
+@@ -922,7 +924,7 @@
+ 								PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
+ }
+ 
+-void __EXPORT ScUndoImportTab::Undo()
++void ScUndoImportTab::Undo()
+ {
+ 	//!	eingefuegte Bereichsnamen etc.
+ 
+@@ -958,7 +960,7 @@
+ 			}
+ 
+ 			if ( pDoc->IsTabProtected( nTabPos ) )
+-				pRedoDoc->SetTabProtection( nTabPos, TRUE, pDoc->GetTabPassword( nTabPos ) );
++                pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
+ 		}
+ 
+ 	}
+@@ -973,7 +975,7 @@
+ 	DoChange();
+ }
+ 
+-void __EXPORT ScUndoImportTab::Redo()
++void ScUndoImportTab::Redo()
+ {
+ 	if (!pRedoDoc)
+ 	{
+@@ -1012,7 +1014,7 @@
+ 		}
+ 
+ 		if ( pRedoDoc->IsTabProtected( nTabPos ) )
+-			pDoc->SetTabProtection( nTabPos, TRUE, pRedoDoc->GetTabPassword( nTabPos ) );
++            pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
+ 	}
+ 
+     RedoSdrUndoAction( pDrawUndo );     // after the sheets are inserted
+@@ -1020,14 +1022,14 @@
+ 	DoChange();
+ }
+ 
+-void __EXPORT ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
+ {
+ 	if (rTarget.ISA(ScTabViewTarget))
+ 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
+ 			Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
+ }
+ 
+-BOOL __EXPORT ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
+ {
+ 	return (rTarget.ISA(ScTabViewTarget));
+ }
+@@ -1075,14 +1077,14 @@
+ 	}
+ }
+ 
+-__EXPORT ScUndoRemoveLink::~ScUndoRemoveLink()
++ScUndoRemoveLink::~ScUndoRemoveLink()
+ {
+ 	delete pTabs;
+ 	delete pModes;
+ 	delete[] pTabNames;
+ }
+ 
+-String __EXPORT ScUndoRemoveLink::GetComment() const
++String ScUndoRemoveLink::GetComment() const
+ {
+ 	return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
+ }
+@@ -1099,22 +1101,22 @@
+ 	pDocShell->UpdateLinks();
+ }
+ 
+-void __EXPORT ScUndoRemoveLink::Undo()
++void ScUndoRemoveLink::Undo()
+ {
+ 	DoChange( TRUE );
+ }
+ 
+-void __EXPORT ScUndoRemoveLink::Redo()
++void ScUndoRemoveLink::Redo()
+ {
+ 	DoChange( FALSE );
+ }
+ 
+-void __EXPORT ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
+ {
+ 	//	gippsnich
+ }
+ 
+-BOOL __EXPORT ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+ {
+ 	return FALSE;
+ }
+@@ -1132,7 +1134,7 @@
  {
- 	DeleteSdrUndoAction( pDrawUndo );
  }
  
--String __EXPORT ScUndoInsertTab::GetComment() const
-+String ScUndoInsertTab::GetComment() const
+-__EXPORT ScUndoShowHideTab::~ScUndoShowHideTab()
++ScUndoShowHideTab::~ScUndoShowHideTab()
  {
- 	if (bAppend)
- 		return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
-@@ -138,7 +140,7 @@
- 		nEndChangeAction = 0;
  }
  
--void __EXPORT ScUndoInsertTab::Undo()
-+void ScUndoInsertTab::Undo()
- {
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
- 	pViewShell->SetTabNo(nTab);
-@@ -159,7 +161,7 @@
- 	pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
+@@ -1149,17 +1151,17 @@
+ 	pDocShell->SetDocumentModified();
  }
  
--void __EXPORT ScUndoInsertTab::Redo()
-+void ScUndoInsertTab::Redo()
+-void __EXPORT ScUndoShowHideTab::Undo()
++void ScUndoShowHideTab::Undo()
  {
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ 	DoChange(!bShow);
+ }
  
-@@ -180,14 +182,14 @@
- 	SetChangeTrack();
+-void __EXPORT ScUndoShowHideTab::Redo()
++void ScUndoShowHideTab::Redo()
+ {
+ 	DoChange(bShow);
  }
  
--void __EXPORT ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
+-void __EXPORT ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
  {
  	if (rTarget.ISA(ScTabViewTarget))
  		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
- 			Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
+@@ -1167,53 +1169,44 @@
+ 								SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
  }
  
--BOOL __EXPORT ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
+-BOOL __EXPORT ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
  {
  	return (rTarget.ISA(ScTabViewTarget));
  }
-@@ -211,7 +213,7 @@
- 	SetChangeTrack();
- }
  
--__EXPORT ScUndoInsertTables::~ScUndoInsertTables()
-+ScUndoInsertTables::~ScUndoInsertTables()
+-String __EXPORT ScUndoShowHideTab::GetComment() const
++String ScUndoShowHideTab::GetComment() const
  {
- 	String *pStr=NULL;
- 	if(pNameList!=NULL)
-@@ -227,7 +229,7 @@
- 	DeleteSdrUndoAction( pDrawUndo );
+ 	USHORT nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
+ 	return ScGlobal::GetRscString( nId );
  }
  
--String __EXPORT ScUndoInsertTables::GetComment() const
-+String ScUndoInsertTables::GetComment() const
+-// -----------------------------------------------------------------------
+-//
+-//		Tabelle/Dokument schuetzen oder Schutz aufheben
+-//
++// ============================================================================
+ 
+-ScUndoProtect::ScUndoProtect( ScDocShell* pShell, SCTAB nNewTab,
+-							BOOL bNewProtect, const uno::Sequence<sal_Int8>& rNewPassword ) :
+-	ScSimpleUndo( pShell ),
+-	nTab( nNewTab ),
+-	bProtect( bNewProtect ),
+-	aPassword( rNewPassword )
++ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
++    ScSimpleUndo(pShell),
++    mpProtectSettings(pProtectSettings)
  {
- 	return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
- }
-@@ -252,7 +254,7 @@
- 		nStartChangeAction = nEndChangeAction = 0;
  }
  
--void __EXPORT ScUndoInsertTables::Undo()
-+void ScUndoInsertTables::Undo()
+-__EXPORT ScUndoProtect::~ScUndoProtect()
++ScUndoDocProtect::~ScUndoDocProtect()
  {
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
- 	pViewShell->SetTabNo(nTab);
-@@ -282,7 +284,7 @@
- 	pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
  }
  
--void __EXPORT ScUndoInsertTables::Redo()
-+void ScUndoInsertTables::Redo()
+-void ScUndoProtect::DoProtect( BOOL bDo )
++void ScUndoDocProtect::DoProtect(bool bProtect)
  {
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+ 	ScDocument* pDoc = pDocShell->GetDocument();
  
-@@ -299,14 +301,14 @@
- 	SetChangeTrack();
- }
+-	if (bDo)
++	if (bProtect)
+ 	{
+-		if ( nTab == TABLEID_DOC )
+-			pDoc->SetDocProtection( TRUE, aPassword );
+-		else
+-			pDoc->SetTabProtection( nTab, TRUE, aPassword );
++        // set protection.
++        auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
++        pCopy->setProtected(true);
++        pDoc->SetDocProtection(pCopy.get());
+ 	}
+ 	else
+ 	{
+-		uno::Sequence<sal_Int8> aEmptyPass;
+-		if ( nTab == TABLEID_DOC )
+-			pDoc->SetDocProtection( FALSE, aEmptyPass );
+-		else
+-			pDoc->SetTabProtection( nTab, FALSE, aEmptyPass );
++        // remove protection.
++        pDoc->SetDocProtection(NULL);
+ 	}
  
--void __EXPORT ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
- {
- 	if (rTarget.ISA(ScTabViewTarget))
- 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
- 			Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
+ 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+@@ -1226,37 +1219,103 @@
+ 	pDocShell->PostPaintGridAll();
  }
  
--BOOL __EXPORT ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
+-void __EXPORT ScUndoProtect::Undo()
++void ScUndoDocProtect::Undo()
  {
- 	return (rTarget.ISA(ScTabViewTarget));
- }
-@@ -327,12 +329,12 @@
- 		SetChangeTrack();
+ 	BeginUndo();
+-	DoProtect( !bProtect );
++	DoProtect(!mpProtectSettings->isProtected());
+ 	EndUndo();
  }
  
--__EXPORT ScUndoDeleteTab::~ScUndoDeleteTab()
-+ScUndoDeleteTab::~ScUndoDeleteTab()
+-void __EXPORT ScUndoProtect::Redo()
++void ScUndoDocProtect::Redo()
  {
- 	theTabs.Remove(0,theTabs.Count());
+ 	BeginRedo();
+-	DoProtect( bProtect );
++	DoProtect(mpProtectSettings->isProtected());
+ 	EndRedo();
  }
  
--String __EXPORT ScUndoDeleteTab::GetComment() const
-+String ScUndoDeleteTab::GetComment() const
+-void __EXPORT ScUndoProtect::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
  {
- 	return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
- }
-@@ -366,7 +368,7 @@
- 	return nTab;
+ 	//	gippsnich
  }
  
--void __EXPORT ScUndoDeleteTab::Undo()
-+void ScUndoDeleteTab::Undo()
+-BOOL __EXPORT ScUndoProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
  {
- 	BeginUndo();
- 	int i=0;
-@@ -414,7 +416,7 @@
-             pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
- 
-             if ( pRefUndoDoc->IsTabProtected( nTab ) )
--                pDoc->SetTabProtection( nTab, TRUE, pRefUndoDoc->GetTabPassword( nTab ) );
-+                pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
- 
- 			//	Drawing-Layer passiert beim MoveUndo::EndUndo
- 	//		pDoc->TransferDrawPage(pRefUndoDoc, nTab,nTab);
-@@ -450,7 +452,7 @@
- //	EndUndo();
+ 	return FALSE;		// gippsnich
  }
  
--void __EXPORT ScUndoDeleteTab::Redo()
-+void ScUndoDeleteTab::Redo()
+-String __EXPORT ScUndoProtect::GetComment() const
++String ScUndoDocProtect::GetComment() const
  {
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
- 	pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs[0] ) );
-@@ -469,7 +471,7 @@
- 	pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
+-	USHORT nId;
+-	if ( nTab == TABLEID_DOC )
+-		nId = bProtect ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
++    USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
++    return ScGlobal::GetRscString( nId );
++}
++
++// ============================================================================
++
++ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
++    ScSimpleUndo(pShell),
++    mnTab(nTab),
++    mpProtectSettings(pProtectSettings)
++{
++}
++
++ScUndoTabProtect::~ScUndoTabProtect()
++{
++}
++
++void ScUndoTabProtect::DoProtect(bool bProtect)
++{
++	ScDocument* pDoc = pDocShell->GetDocument();
++
++	if (bProtect)
++	{
++        // set protection.
++        auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
++        pCopy->setProtected(true);
++        pDoc->SetTabProtection(mnTab, pCopy.get());
++	}
+ 	else
+-		nId = bProtect ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
++	{
++        // remove protection.
++        pDoc->SetTabProtection(mnTab, NULL);
++	}
++
++	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
++	if (pViewShell)
++	{
++		pViewShell->UpdateLayerLocks();
++		pViewShell->UpdateInputHandler(TRUE);	// damit sofort wieder eingegeben werden kann
++	}
++
++	pDocShell->PostPaintGridAll();
++}
++
++void ScUndoTabProtect::Undo()
++{
++	BeginUndo();
++	DoProtect(!mpProtectSettings->isProtected());
++	EndUndo();
++}
++
++void ScUndoTabProtect::Redo()
++{
++	BeginRedo();
++	DoProtect(mpProtectSettings->isProtected());
++	EndRedo();
++}
++
++void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
++{
++	//	gippsnich
++}
++
++BOOL ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++{
++	return FALSE;		// gippsnich
++}
++
++String ScUndoTabProtect::GetComment() const
++{
++    USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
+ 	return ScGlobal::GetRscString( nId );
  }
  
--void __EXPORT ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
+@@ -1274,7 +1333,7 @@
  {
- 	if (rTarget.ISA(ScTabViewTarget))
- 	{
-@@ -478,7 +480,7 @@
- 	}
  }
  
--BOOL __EXPORT ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
+-__EXPORT ScUndoPrintRange::~ScUndoPrintRange()
++ScUndoPrintRange::~ScUndoPrintRange()
  {
- 	return (rTarget.ISA(ScTabViewTarget));
- }
-@@ -500,11 +502,11 @@
- 	sNewName = rNewName;
+ 	delete pOldRanges;
+ 	delete pNewRanges;
+@@ -1297,31 +1356,31 @@
+ 	pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
  }
  
--__EXPORT ScUndoRenameTab::~ScUndoRenameTab()
-+ScUndoRenameTab::~ScUndoRenameTab()
+-void __EXPORT ScUndoPrintRange::Undo()
++void ScUndoPrintRange::Undo()
  {
+ 	BeginUndo();
+ 	DoChange( TRUE );
+ 	EndUndo();
  }
  
--String __EXPORT ScUndoRenameTab::GetComment() const
-+String ScUndoRenameTab::GetComment() const
+-void __EXPORT ScUndoPrintRange::Redo()
++void ScUndoPrintRange::Redo()
  {
- 	return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
- }
-@@ -526,22 +528,22 @@
- 		pViewShell->UpdateInputHandler();
+ 	BeginRedo();
+ 	DoChange( FALSE );
+ 	EndRedo();
  }
  
--void __EXPORT ScUndoRenameTab::Undo()
-+void ScUndoRenameTab::Undo()
+-void __EXPORT ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
  {
- 	DoChange(nTab, sOldName);
+ 	//	gippsnich
  }
  
--void __EXPORT ScUndoRenameTab::Redo()
-+void ScUndoRenameTab::Redo()
+-BOOL __EXPORT ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
  {
- 	DoChange(nTab, sNewName);
+ 	return FALSE;		// gippsnich
  }
  
--void __EXPORT ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
+-String __EXPORT ScUndoPrintRange::GetComment() const
++String ScUndoPrintRange::GetComment() const
  {
- 	//	Repeat macht keinen Sinn
+ 	return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
  }
- 
--BOOL __EXPORT ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+@@ -1350,16 +1409,16 @@
  {
- 	return FALSE;
- }
-@@ -565,13 +567,13 @@
-         theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
  }
  
--__EXPORT ScUndoMoveTab::~ScUndoMoveTab()
-+ScUndoMoveTab::~ScUndoMoveTab()
+-__EXPORT ScUndoScenarioFlags::~ScUndoScenarioFlags()
++ScUndoScenarioFlags::~ScUndoScenarioFlags()
  {
- 	theNewTabs.Remove(0,theNewTabs.Count());
- 	theOldTabs.Remove(0,theOldTabs.Count());
  }
  
--String __EXPORT ScUndoMoveTab::GetComment() const
-+String ScUndoMoveTab::GetComment() const
+-String __EXPORT ScUndoScenarioFlags::GetComment() const
++String ScUndoScenarioFlags::GetComment() const
  {
- 	return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
- }
-@@ -618,22 +620,22 @@
- 	pDocShell->PostDataChanged();
+ 	return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
  }
  
--void __EXPORT ScUndoMoveTab::Undo()
-+void ScUndoMoveTab::Undo()
+-void __EXPORT ScUndoScenarioFlags::Undo()
++void ScUndoScenarioFlags::Undo()
  {
- 	DoChange( TRUE );
+ 	ScDocument* pDoc = pDocShell->GetDocument();
+ 
+@@ -1376,7 +1435,7 @@
+ 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
  }
  
--void __EXPORT ScUndoMoveTab::Redo()
-+void ScUndoMoveTab::Redo()
+-void __EXPORT ScUndoScenarioFlags::Redo()
++void ScUndoScenarioFlags::Redo()
  {
- 	DoChange( FALSE );
+ 	ScDocument* pDoc = pDocShell->GetDocument();
+ 
+@@ -1393,12 +1452,12 @@
+ 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
  }
  
--void __EXPORT ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
+-void __EXPORT ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
  {
- 		// kein Repeat ! ? !
+ 	//	Repeat macht keinen Sinn
  }
  
--BOOL __EXPORT ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+-BOOL __EXPORT ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
++BOOL ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
  {
  	return FALSE;
  }
-@@ -660,12 +662,12 @@
-         theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
- }
- 
--__EXPORT ScUndoCopyTab::~ScUndoCopyTab()
-+ScUndoCopyTab::~ScUndoCopyTab()
+@@ -1498,7 +1557,7 @@
  {
- 	DeleteSdrUndoAction( pDrawUndo );
  }
  
--String __EXPORT ScUndoCopyTab::GetComment() const
-+String ScUndoCopyTab::GetComment() const
+-__EXPORT ScUndoLayoutRTL::~ScUndoLayoutRTL()
++ScUndoLayoutRTL::~ScUndoLayoutRTL()
  {
- 	return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
- }
-@@ -684,7 +686,7 @@
- 	pDocShell->PostDataChanged();
  }
  
--void __EXPORT ScUndoCopyTab::Undo()
-+void ScUndoCopyTab::Undo()
- {
- 	ScDocument* pDoc = pDocShell->GetDocument();
- 
-@@ -717,7 +719,7 @@
- 	DoChange();
+@@ -1518,29 +1577,29 @@
+ 	pDocShell->SetInUndo( FALSE );
  }
  
--void __EXPORT ScUndoCopyTab::Redo()
-+void ScUndoCopyTab::Redo()
+-void __EXPORT ScUndoLayoutRTL::Undo()
++void ScUndoLayoutRTL::Undo()
  {
- 	ScDocument* pDoc = pDocShell->GetDocument();
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
-@@ -756,7 +758,7 @@
- 		}
- 
- 		if ( pDoc->IsTabProtected( nAdjSource ) )
--			pDoc->SetTabProtection( nNewTab, TRUE, pDoc->GetTabPassword( nAdjSource ) );
-+            pDoc->CopyTabProtection(nAdjSource, nNewTab);
- 	}
- 
-     RedoSdrUndoAction( pDrawUndo );             // after the sheets are inserted
-@@ -767,12 +769,12 @@
- 
+ 	DoChange(!bRTL);
  }
  
--void __EXPORT ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
+-void __EXPORT ScUndoLayoutRTL::Redo()
++void ScUndoLayoutRTL::Redo()
  {
- 		// kein Repeat ! ? !
+ 	DoChange(bRTL);
  }
  
--BOOL __EXPORT ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
+-void __EXPORT ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
++void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
  {
- 	return FALSE;
- }
-@@ -801,17 +803,17 @@
-     pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
+ 	if (rTarget.ISA(ScTabViewTarget))
+ 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
+ 			Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
  }
  
--__EXPORT ScUndoMakeScenario::~ScUndoMakeScenario()
-+ScUndoMakeScenario::~ScUndoMakeScenario()
+-BOOL __EXPORT ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
  {
-     DeleteSdrUndoAction( pDrawUndo );
+ 	return (rTarget.ISA(ScTabViewTarget));
  }
  
--String __EXPORT ScUndoMakeScenario::GetComment() const
-+String ScUndoMakeScenario::GetComment() const
+-String __EXPORT ScUndoLayoutRTL::GetComment() const
++String ScUndoLayoutRTL::GetComment() const
  {
- 	return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
+ 	return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
+ }
+@@ -1560,7 +1619,7 @@
+     meOldGrammar = pDocShell->GetDocument()->GetGrammar();
  }
  
--void __EXPORT ScUndoMakeScenario::Undo()
-+void ScUndoMakeScenario::Undo()
+-__EXPORT ScUndoSetGrammar::~ScUndoSetGrammar()
++ScUndoSetGrammar::~ScUndoSetGrammar()
  {
- 	ScDocument* pDoc = pDocShell->GetDocument();
- 
-@@ -836,7 +838,7 @@
-     pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
  }
  
--void __EXPORT ScUndoMakeScenario::Redo()
-+void ScUndoMakeScenario::Redo()
- {
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
- 	if (pViewShell)
-@@ -858,7 +860,7 @@
- 	SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
+@@ -1573,17 +1632,17 @@
+     pDocShell->SetInUndo( FALSE );
  }
  
--void __EXPORT ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
+-void __EXPORT ScUndoSetGrammar::Undo()
++void ScUndoSetGrammar::Undo()
  {
- 	if (rTarget.ISA(ScTabViewTarget))
- 	{
-@@ -866,7 +868,7 @@
- 	}
+     DoChange( meOldGrammar );
  }
  
--BOOL __EXPORT ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
+-void __EXPORT ScUndoSetGrammar::Redo()
++void ScUndoSetGrammar::Redo()
  {
- 	return (rTarget.ISA(ScTabViewTarget));
- }
-@@ -889,13 +891,13 @@
- 	pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
+     DoChange( meNewGrammar );
  }
  
--__EXPORT ScUndoImportTab::~ScUndoImportTab()
-+ScUndoImportTab::~ScUndoImportTab()
+-void __EXPORT ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
++void ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
  {
- 	delete pRedoDoc;
- 	DeleteSdrUndoAction( pDrawUndo );
+ #if 0
+ // erAck: 2006-09-07T23:00+0200  commented out in CWS scr1c1
+@@ -1593,12 +1652,12 @@
+ #endif
  }
  
--String __EXPORT ScUndoImportTab::GetComment() const
-+String ScUndoImportTab::GetComment() const
+-BOOL __EXPORT ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
++BOOL ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
  {
- 	return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
- }
-@@ -922,7 +924,7 @@
- 								PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
+     return (rTarget.ISA(ScTabViewTarget));
  }
  
--void __EXPORT ScUndoImportTab::Undo()
-+void ScUndoImportTab::Undo()
+-String __EXPORT ScUndoSetGrammar::GetComment() const
++String ScUndoSetGrammar::GetComment() const
  {
- 	//!	eingefuegte Bereichsnamen etc.
- 
-@@ -958,7 +960,7 @@
- 			}
- 
- 			if ( pDoc->IsTabProtected( nTabPos ) )
--				pRedoDoc->SetTabProtection( nTabPos, TRUE, pDoc->GetTabPassword( nTabPos ) );
-+                pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
- 		}
- 
- 	}
-@@ -973,7 +975,7 @@
- 	DoChange();
+     return ScGlobal::GetRscString( STR_UNDO_TAB_R1C1 );
  }
+Index: source/ui/miscdlgs/retypepassdlg.src
+===================================================================
+--- sc/source/ui/miscdlgs/retypepassdlg.src	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/miscdlgs/retypepassdlg.src	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,316 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: retypepassdlg.src,v $
++ * $Revision: 1.1.2.3 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#include "retypepassdlg.hrc"
++
++
++ModalDialog RID_SCDLG_RETYPEPASS
++{
++    Text [ en-US ] = "Re-type Password" ;
++    Size = MAP_APPFONT ( 260 , 165 ) ;
++    Moveable = TRUE ;
++    Closeable = TRUE ;
++
++    OKButton BTN_OK
++    {
++        Pos = MAP_APPFONT ( 204, 6 ) ;
++        Size = MAP_APPFONT ( 50, 14 ) ;
++        DefButton = TRUE ;
++    };
++
++    CancelButton BTN_CANCEL
++    {
++        Pos = MAP_APPFONT ( 204, 23 ) ;
++        Size = MAP_APPFONT ( 50, 14 ) ;
++    };
++
++    HelpButton BTN_HELP
++    {
++        Pos = MAP_APPFONT ( 204, 43 ) ;
++        Size = MAP_APPFONT ( 50, 14 ) ;
++    };
++
++    FixedText FT_DESC
++    {
++        Pos = MAP_APPFONT ( 6, 6 ) ;
++        Size = MAP_APPFONT ( 190, 36 );
++
++        WordBreak = TRUE ;
++
++        Text [ en-US ] = "The document you are about to export has one or more protected items with password that cannot be exported.  Please re-type your password to be able to export your document." ;
++    };
++
++    FixedLine FL_DOCUMENT
++    {
++        Pos = MAP_APPFONT ( 6, 48 );
++        Size = MAP_APPFONT ( 190, 8 );
++
++        Text [ en-US ] = "Document protection" ;
++    };
++
++    FixedText FT_DOCSTATUS
++    {
++        Pos = MAP_APPFONT ( 10, 62 );
++        Size = MAP_APPFONT ( 140, 8 );
++
++        Text [ en-US ] = "Status unknown" ;
++    };
++
++    PushButton BTN_RETYPE_DOC
++    {
++        Pos = MAP_APPFONT ( 158, 59 );
++        Size = MAP_APPFONT ( 30, 14 );
++
++        Text [ en-US ] = "Re-type" ;
++    };
++
++    FixedLine FL_SHEET
++    {
++        Pos = MAP_APPFONT ( 6, 83 );
++        Size = MAP_APPFONT ( 190, 8 );
++
++        Text [ en-US ] = "Sheet protection" ;
++    };
++
++    FixedText FT_SHEETNAME1
++    {
++        Pos = MAP_APPFONT ( 10, 97 );
++        Size = MAP_APPFONT ( 68, 8 );
++
++        Text [ en-US ] = "Sheet1 has a really long name" ;
++    };
++
++    FixedText FT_SHEETSTATUS1
++    {
++        Pos = MAP_APPFONT ( 82, 97 );
++        Size = MAP_APPFONT ( 72, 8 );
++
++        Text [ en-US ] = "Status unknown" ;
++    };
++
++    PushButton BTN_RETYPE_SHEET1
++    {
++        Pos = MAP_APPFONT ( 158, 94 );
++        Size = MAP_APPFONT ( 30, 14 );
++
++        Text [ en-US ] = "Re-type" ;
++    };
++
++    FixedText FT_SHEETNAME2
++    {
++        Pos = MAP_APPFONT ( 10, 113 );
++        Size = MAP_APPFONT ( 68, 8 );
++
++        Text [ en-US ] = "Sheet2" ;
++    };
++
++    FixedText FT_SHEETSTATUS2
++    {
++        Pos = MAP_APPFONT ( 82, 113 );
++        Size = MAP_APPFONT ( 72, 8 );
++
++        Text [ en-US ] = "Status unknown" ;
++    };
++
++    PushButton BTN_RETYPE_SHEET2
++    {
++        Pos = MAP_APPFONT ( 158, 110 );
++        Size = MAP_APPFONT ( 30, 14 );
++
++        Text [ en-US ] = "Re-type" ;
++    };
++
++    FixedText FT_SHEETNAME3
++    {
++        Pos = MAP_APPFONT ( 10, 129 );
++        Size = MAP_APPFONT ( 68, 8 );
++
++        Text [ en-US ] = "Sheet3" ;
++    };
++
++    FixedText FT_SHEETSTATUS3
++    {
++        Pos = MAP_APPFONT ( 82, 129 );
++        Size = MAP_APPFONT ( 72, 8 );
++
++        Text [ en-US ] = "Status unknown" ;
++    };
++
++    PushButton BTN_RETYPE_SHEET3
++    {
++        Pos = MAP_APPFONT ( 158, 126 );
++        Size = MAP_APPFONT ( 30, 14 );
++
++        Text [ en-US ] = "Re-type" ;
++    };
++
++    FixedText FT_SHEETNAME4
++    {
++        Pos = MAP_APPFONT ( 10, 145 );
++        Size = MAP_APPFONT ( 68, 8 );
++
++        Text [ en-US ] = "Sheet4" ;
++    };
++
++    FixedText FT_SHEETSTATUS4
++    {
++        Pos = MAP_APPFONT ( 82, 145 );
++        Size = MAP_APPFONT ( 72, 8 );
++
++        Text [ en-US ] = "Status unknown" ;
++    };
++
++    PushButton BTN_RETYPE_SHEET4
++    {
++        Pos = MAP_APPFONT ( 158, 142 );
++        Size = MAP_APPFONT ( 30, 14 );
++
++        Text [ en-US ] = "Re-type" ;
++    };
++
++    ScrollBar SB_SCROLL
++    {
++        Pos = MAP_APPFONT ( 190, 94 ) ;
++        Size = MAP_APPFONT (  8, 61 ) ;
++        VScroll = TRUE ;
++    };
++
++    String STR_NOT_PROTECTED
++    {
++        Text [ en-US ] = "Not protected" ;
++    };
++
++    String STR_NOT_PASS_PROTECTED
++    {
++        Text [ en-US ] = "Not password-protected" ;
++    };
++
++    String STR_HASH_BAD
++    {
++        Text [ en-US ] = "Hash incompatible" ;
++    };
++
++    String STR_HASH_GOOD
++    {
++        Text [ en-US ] = "Hash compatible" ;
++    };
++
++    String STR_HASH_REGENERATED
++    {
++        Text [ en-US ] = "Hash re-generated" ;
++    };
++};
++
++// ----------------------------------------------------------------------------
++
++ModalDialog RID_SCDLG_RETYPEPASS_INPUT
++{
++    Text [ en-US ] = "Re-type Password" ;
++    Size = MAP_APPFONT ( 230 , 110 ) ;
++    Moveable = TRUE ;
++    Closeable = TRUE ;
++
++    OKButton BTN_OK
++    {
++        Pos = MAP_APPFONT ( 174, 6 ) ;
++        Size = MAP_APPFONT ( 50, 14 ) ;
++        DefButton = TRUE ;
++    };
++
++    CancelButton BTN_CANCEL
++    {
++        Pos = MAP_APPFONT ( 174, 23 ) ;
++        Size = MAP_APPFONT ( 50, 14 ) ;
++    };
++
++    HelpButton BTN_HELP
++    {
++        Pos = MAP_APPFONT ( 174, 43 ) ;
++        Size = MAP_APPFONT ( 50, 14 ) ;
++    };
++
++    RadioButton BTN_RETYPE_PASSWORD
++    {
++        Pos = MAP_APPFONT ( 11, 10 );
++        Size = MAP_APPFONT ( 150, 10 );
++
++        Text [ en-US ] = "Re-type password" ;
++    };
++
++    FixedText FT_PASSWORD1
++    {
++        Pos = MAP_APPFONT ( 20, 30 );
++        Size = MAP_APPFONT ( 42, 10 );
++
++        Text [ en-US ] = "~Password" ;
++    };
++
++    Edit ED_PASSWORD1
++    {
++        Border = TRUE;
++        PassWord = TRUE;
++        Pos = MAP_APPFONT ( 65, 29 );
++        Size = MAP_APPFONT ( 75, 12 );
++    };
++
++    FixedText FT_PASSWORD2
++    {
++        Pos = MAP_APPFONT ( 20, 45 );
++        Size = MAP_APPFONT ( 42, 10 );
++
++        Text [ en-US ] = "~Confirm" ;
++    };
++
++    Edit ED_PASSWORD2
++    {
++        Border = TRUE;
++        PassWord = TRUE;
++        Pos = MAP_APPFONT ( 65, 44 );
++        Size = MAP_APPFONT ( 75, 12 );
++    };
++
++    CheckBox BTN_MATCH_OLD_PASSWORD
++    {
++        Pos = MAP_APPFONT ( 20, 65 );
++        Size = MAP_APPFONT ( 150, 10 );
++
++        Text [ en-US ] = "New password must match the original password." ;
++    };
++
++    RadioButton BTN_REMOVE_PASSWORD
++    {
++        Pos = MAP_APPFONT ( 11, 90 );
++        Size = MAP_APPFONT ( 150, 10 );
++
++        Text [ en-US ] = "Remove password from this protected item." ;
++    };
++};
++
++
+Index: source/ui/miscdlgs/makefile.mk
+===================================================================
+--- sc/source/ui/miscdlgs/makefile.mk	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/miscdlgs/makefile.mk	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -78,7 +78,9 @@
+ 	$(SLO)$/warnbox.obj	\
+ 	$(SLO)$/scuiautofmt.obj     \
+ 	$(SLO)$/conflictsdlg.obj    \
+-	$(SLO)$/sharedocdlg.obj
++	$(SLO)$/sharedocdlg.obj \
++	$(SLO)$/protectiondlg.obj \
++	$(SLO)$/retypepassdlg.obj
  
--void __EXPORT ScUndoImportTab::Redo()
-+void ScUndoImportTab::Redo()
- {
- 	if (!pRedoDoc)
- 	{
-@@ -1012,7 +1014,7 @@
- 		}
+ EXCEPTIONSFILES = \
+     $(SLO)$/acredlin.obj        \
+@@ -87,7 +89,9 @@
+     $(SLO)$/optsolver.obj       \
+     $(SLO)$/solveroptions.obj   \
+     $(SLO)$/crnrdlg.obj         \
+-    $(SLO)$/solverutil.obj
++    $(SLO)$/solverutil.obj \
++    $(SLO)$/protectiondlg.obj \
++    $(SLO)$/retypepassdlg.obj
  
- 		if ( pRedoDoc->IsTabProtected( nTabPos ) )
--			pDoc->SetTabProtection( nTabPos, TRUE, pRedoDoc->GetTabPassword( nTabPos ) );
-+            pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
- 	}
+ SRS1NAME=$(TARGET)
+ SRC1FILES = \
+@@ -96,7 +100,9 @@
+ 	highred.src					\
+ 	linkarea.src                \
+ 	conflictsdlg.src            \
+-	sharedocdlg.src
++	sharedocdlg.src \
++	protectiondlg.src \
++	retypepassdlg.src
  
-     RedoSdrUndoAction( pDrawUndo );     // after the sheets are inserted
-@@ -1020,14 +1022,14 @@
- 	DoChange();
- }
+ LIB1TARGET = $(SLB)$/$(TARGET).lib
  
--void __EXPORT ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
- {
- 	if (rTarget.ISA(ScTabViewTarget))
- 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
- 			Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
- }
+@@ -116,7 +122,9 @@
+	$(SLO)$/conflictsdlg.obj    \
+	$(SLO)$/sharedocdlg.obj     \
+	$(SLO)$/scuiautofmt.obj			\
+-	$(SLO)$/strindlg.obj            
++	$(SLO)$/strindlg.obj \
++    $(SLO)$/protectiondlg.obj \
++    $(SLO)$/retypepassdlg.obj
  
--BOOL __EXPORT ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
- {
- 	return (rTarget.ISA(ScTabViewTarget));
- }
-@@ -1075,14 +1077,14 @@
- 	}
- }
+ # --- Tagets -------------------------------------------------------
  
--__EXPORT ScUndoRemoveLink::~ScUndoRemoveLink()
-+ScUndoRemoveLink::~ScUndoRemoveLink()
- {
- 	delete pTabs;
- 	delete pModes;
- 	delete[] pTabNames;
- }
+Index: source/ui/miscdlgs/retypepassdlg.cxx
+===================================================================
+--- sc/source/ui/miscdlgs/retypepassdlg.cxx	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/miscdlgs/retypepassdlg.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,544 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: retypepassdlg.cxx,v $
++ * $Revision: 1.1.2.7 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#include "retypepassdlg.hxx"
++#include "retypepassdlg.hrc"
++#include "scresid.hxx"
++#include "document.hxx"
++#include "tabprotection.hxx"
++
++#include <stdio.h>
++
++#include <vcl/msgbox.hxx>
++
++ScRetypePassDlg::ScRetypePassDlg(Window* pParent) :
++    ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS)),
++
++    maBtnOk     (this, ScResId(BTN_OK)),
++    maBtnCancel (this, ScResId(BTN_CANCEL)),
++    maBtnHelp   (this, ScResId(BTN_HELP)),
++
++    maTextDescription(this, ScResId(FT_DESC)),
++    maLineDocument(this, ScResId(FL_DOCUMENT)),
++    maTextDocStatus(this, ScResId(FT_DOCSTATUS)),
++    maBtnRetypeDoc(this, ScResId(BTN_RETYPE_DOC)),
++
++    maLineSheet(this, ScResId(FL_SHEET)),
++    maTextSheetName1(this, ScResId(FT_SHEETNAME1)),
++    maTextSheetStatus1(this, ScResId(FT_SHEETSTATUS1)),
++    maBtnRetypeSheet1(this, ScResId(BTN_RETYPE_SHEET1)),
++
++    maTextSheetName2(this, ScResId(FT_SHEETNAME2)),
++    maTextSheetStatus2(this, ScResId(FT_SHEETSTATUS2)),
++    maBtnRetypeSheet2(this, ScResId(BTN_RETYPE_SHEET2)),
++
++    maTextSheetName3(this, ScResId(FT_SHEETNAME3)),
++    maTextSheetStatus3(this, ScResId(FT_SHEETSTATUS3)),
++    maBtnRetypeSheet3(this, ScResId(BTN_RETYPE_SHEET3)),
++
++    maTextSheetName4(this, ScResId(FT_SHEETNAME4)),
++    maTextSheetStatus4(this, ScResId(FT_SHEETSTATUS4)),
++    maBtnRetypeSheet4(this, ScResId(BTN_RETYPE_SHEET4)),
++
++    maScrollBar (this, ScResId(SB_SCROLL)),
++
++    maTextNotProtected(ScResId(STR_NOT_PROTECTED)),
++    maTextNotPassProtected(ScResId(STR_NOT_PASS_PROTECTED)),
++    maTextHashBad(ScResId(STR_HASH_BAD)),
++    maTextHashGood(ScResId(STR_HASH_GOOD)),
++    maTextHashRegen(ScResId(STR_HASH_REGENERATED)),
++
++    mpDocItem(static_cast<ScDocProtection*>(NULL)),
++    mnCurScrollPos(0),
++    meDesiredHash(PASSHASH_OOO)
++{
++    Init();
++}
++
++ScRetypePassDlg::~ScRetypePassDlg()
++{
++}
++
++short ScRetypePassDlg::Execute()
++{
++    PopulateDialog();
++    CheckHashStatus();
++    return ModalDialog::Execute();
++}
++
++void ScRetypePassDlg::SetData(const ScDocument& rDoc)
++{
++    const ScDocProtection* pDocProtect = rDoc.GetDocProtection();
++    if (pDocProtect && pDocProtect->isProtected())
++        mpDocItem.reset(new ScDocProtection(*pDocProtect));
++
++    SCTAB nTabCount = rDoc.GetTableCount();
++    maTableItems.reserve(nTabCount);
++    for (SCTAB i = 0; i < nTabCount; ++i)
++    {
++        TableItem aTabItem;
++        rDoc.GetName(i, aTabItem.maName);
++
++        const ScTableProtection* pTabProtect = rDoc.GetTabProtection(i);
++        if (pTabProtect && pTabProtect->isProtected())
++            aTabItem.mpProtect.reset(new ScTableProtection(*pTabProtect));
++
++        maTableItems.push_back(aTabItem);
++    }
++}
++
++void ScRetypePassDlg::SetDesiredHash(ScPasswordHash eHash)
++{
++    meDesiredHash = eHash;
++}
++
++void ScRetypePassDlg::WriteNewDataToDocument(ScDocument& rDoc) const
++{
++    if (mpDocItem.get())
++        rDoc.SetDocProtection(mpDocItem.get());
++
++    SCTAB nTabCount = rDoc.GetTableCount();
++    size_t n = maTableItems.size();
++    for (size_t i = 0; i < n; ++i)
++    {
++        if (i >= nTabCount)
++            break;
++
++        ScTableProtection* pTabProtect = maTableItems[i].mpProtect.get();
++        if (pTabProtect)
++            rDoc.SetTabProtection(static_cast<SCTAB>(i), pTabProtect);
++    }
++}
++
++void ScRetypePassDlg::Init()
++{
++    Link aLink = LINK( this, ScRetypePassDlg, OKHdl );
++    maBtnOk.SetClickHdl(aLink);
++
++    aLink = LINK( this, ScRetypePassDlg, RetypeBtnHdl );
++    maBtnRetypeDoc.SetClickHdl(aLink);
++    maBtnRetypeSheet1.SetClickHdl(aLink);
++    maBtnRetypeSheet2.SetClickHdl(aLink);
++    maBtnRetypeSheet3.SetClickHdl(aLink);
++    maBtnRetypeSheet4.SetClickHdl(aLink);
++
++    maTextDocStatus.SetText(maTextNotProtected);
++    maTextSheetStatus1.SetText(maTextNotProtected);
++    maTextSheetStatus2.SetText(maTextNotProtected);
++    maTextSheetStatus3.SetText(maTextNotProtected);
++    maTextSheetStatus4.SetText(maTextNotProtected);
++    maBtnRetypeDoc.Disable();
++
++    // Make all sheet rows invisible.
++
++    maTextSheetName1.Show(false);
++    maTextSheetStatus1.Show(false);
++    maBtnRetypeSheet1.Show(false);
++    maBtnRetypeSheet1.Disable();
++    
++    maTextSheetName2.Show(false);
++    maTextSheetStatus2.Show(false);
++    maBtnRetypeSheet2.Show(false);
++    maBtnRetypeSheet2.Disable();
++
++    maTextSheetName3.Show(false);
++    maTextSheetStatus3.Show(false);
++    maBtnRetypeSheet3.Show(false);
++    maBtnRetypeSheet3.Disable();
++
++    maTextSheetName4.Show(false);
++    maTextSheetStatus4.Show(false);
++    maBtnRetypeSheet4.Show(false);
++    maBtnRetypeSheet4.Disable();
++
++    maScrollBar.Show(false);
++
++    maScrollBar.SetEndScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
++    maScrollBar.SetScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
++
++    maScrollBar.SetPageSize(4);
++    maScrollBar.SetVisibleSize(4);
++    maScrollBar.SetLineSize(1);
++}
++
++void ScRetypePassDlg::PopulateDialog()
++{
++    // Document protection first.
++    SetDocData();
++
++    // Sheet protection next.  We're only interested in the first 4 sheets
++    // (or less).
++    size_t n = maTableItems.size();
++    for (size_t i = 0; i < n && i < 4; ++i)
++        SetTableData(i, i);
++
++    if (n > 4)
++    {
++        maScrollBar.Show(true);
++        maScrollBar.SetRange(Range(0, n));
++    }
++}
++
++void ScRetypePassDlg::SetDocData()
++{
++    bool bBtnEnabled = false;
++    if (mpDocItem.get() && mpDocItem->isProtected())
++    {
++        if (mpDocItem->isPasswordEmpty())
++            maTextDocStatus.SetText(maTextNotPassProtected);
++        else if (mpDocItem->hasPasswordHash(meDesiredHash))
++            maTextDocStatus.SetText(maTextHashGood);
++        else
++        {
++            // incompatible hash
++            maTextDocStatus.SetText(maTextHashBad);
++            bBtnEnabled = true;
++        }
++    }
++    maBtnRetypeDoc.Enable(bBtnEnabled);
++}
++
++void ScRetypePassDlg::SetTableData(sal_uInt8 nRowPos, SCTAB nTab)
++{
++    if (nRowPos >= 4)
++        return;
++
++    FixedText* pName = NULL;
++    FixedText* pStatus = NULL;
++    PushButton* pBtn = NULL;
++    switch (nRowPos)
++    {
++        case 0:
++            pName = &maTextSheetName1;
++            pStatus = &maTextSheetStatus1;
++            pBtn = &maBtnRetypeSheet1;
++        break;
++        case 1:
++            pName = &maTextSheetName2;
++            pStatus = &maTextSheetStatus2;
++            pBtn = &maBtnRetypeSheet2;
++        break;
++        case 2:
++            pName = &maTextSheetName3;
++            pStatus = &maTextSheetStatus3;
++            pBtn = &maBtnRetypeSheet3;
++        break;
++        case 3:
++            pName = &maTextSheetName4;
++            pStatus = &maTextSheetStatus4;
++            pBtn = &maBtnRetypeSheet4;
++        break;
++        default:
++            return;
++    }
++
++    bool bBtnEnabled = false;
++    pName->SetText(maTableItems[nTab].maName);
++    pName->Show(true);
++    const ScTableProtection* pTabProtect = maTableItems[nTab].mpProtect.get();
++    if (pTabProtect && pTabProtect->isProtected())
++    {
++        if (pTabProtect->isPasswordEmpty())
++            pStatus->SetText(maTextNotPassProtected);
++        else if (pTabProtect->hasPasswordHash(meDesiredHash))
++            pStatus->SetText(maTextHashGood);
++        else
++        {
++            // incompatible hash 
++            pStatus->SetText(maTextHashBad);
++            bBtnEnabled = true;
++        }
++    }
++    else
++        pStatus->SetText(maTextNotProtected);
++
++    pStatus->Show(true);
++    pBtn->Show(true);
++    pBtn->Enable(bBtnEnabled);
++}
++
++void ScRetypePassDlg::ResetTableRows()
++{
++    long nScrollPos = maScrollBar.GetThumbPos();
++    mnCurScrollPos = nScrollPos < 0 ? 0 : nScrollPos;
++    size_t nRowCount = maTableItems.size() - nScrollPos;
++    for (size_t i = 0; i < nRowCount; ++i)
++        SetTableData(i, i + nScrollPos);
++}
++
++bool lcl_IsInGoodStatus(ScPassHashProtectable* pProtected, ScPasswordHash eDesiredHash)
++{
++    if (!pProtected || !pProtected->isProtected())
++        // Not protected.
++        return true;
++
++    if (pProtected->isPasswordEmpty())
++        return true;
++
++    if (pProtected->hasPasswordHash(eDesiredHash))
++        return true;
++
++    return false;
++}
++
++void ScRetypePassDlg::CheckHashStatus()
++{
++    do
++    {
++        if (!lcl_IsInGoodStatus(mpDocItem.get(), meDesiredHash))
++            break;
++
++        bool bStatusGood = true;
++        size_t nTabCount = maTableItems.size();
++        for (size_t i = 0; i < nTabCount && bStatusGood; ++i)
++        {
++            if (!lcl_IsInGoodStatus(maTableItems[i].mpProtect.get(), meDesiredHash))
++                bStatusGood = false;
++        }
++        if (!bStatusGood)
++            break;
++
++        maBtnOk.Enable();
++        return;
++    }
++    while (false);
++
++    maBtnOk.Disable();
++}
++
++IMPL_LINK( ScRetypePassDlg, OKHdl, OKButton*, EMPTYARG )
++{
++    EndDialog(RET_OK);
++    return 0;
++}
++
++IMPL_LINK( ScRetypePassDlg, RetypeBtnHdl, PushButton*, pBtn )
++{
++    ScPassHashProtectable* pProtected = NULL;
++    if (pBtn == &maBtnRetypeDoc)
++    {
++        // document protection.
++        pProtected = mpDocItem.get();
++    }
++    else
++    {
++        // sheet protection.
++        size_t nTabPos = mnCurScrollPos;
++        if (pBtn == &maBtnRetypeSheet2)
++            nTabPos += 1;
++        else if (pBtn == &maBtnRetypeSheet3)
++            nTabPos += 2;
++        else if (pBtn == &maBtnRetypeSheet4)
++            nTabPos += 3;
++        else if (pBtn != &maBtnRetypeSheet1)
++            // This should never happen !
++            return 0;
++
++        if (nTabPos >= maTableItems.size())
++            // Likewise, this should never happen !
++            return 0;
++
++        pProtected = maTableItems[nTabPos].mpProtect.get();
++    }
++
++    if (!pProtected)
++        // What the ... !?
++        return 0;
++
++    ScRetypePassInputDlg aDlg(this, pProtected);
++    if (aDlg.Execute() == RET_OK)
++    {
++        // OK is pressed.  Update the protected item.
++        if (aDlg.IsRemovePassword())
++        {
++            // Remove password from this item.
++            pProtected->setPassword(String());
++        }
++        else
++        {
++            // Set a new password.
++            String aNewPass = aDlg.GetNewPassword();
++            pProtected->setPassword(aNewPass);
++        }
++
++        SetDocData();
++        ResetTableRows();
++        CheckHashStatus();
++    }
++    return 0;
++}
++
++IMPL_LINK( ScRetypePassDlg, ScrollHdl, ScrollBar*, EMPTYARG )
++{
++    ResetTableRows();
++    return 0;
++}
++
++// ============================================================================
++
++ScRetypePassInputDlg::ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected) :
++    ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS_INPUT)),
++
++    maBtnOk     (this, ScResId(BTN_OK)),
++    maBtnCancel (this, ScResId(BTN_CANCEL)),
++    maBtnHelp   (this, ScResId(BTN_HELP)),
++
++    maBtnRetypePassword(this, ScResId(BTN_RETYPE_PASSWORD)),
++
++    maPassword1Text (this, ScResId(FT_PASSWORD1)),
++    maPassword1Edit (this, ScResId(ED_PASSWORD1)),
++    maPassword2Text (this, ScResId(FT_PASSWORD2)),
++    maPassword2Edit (this, ScResId(ED_PASSWORD2)),
++    maBtnMatchOldPass(this, ScResId(BTN_MATCH_OLD_PASSWORD)),
++
++    maBtnRemovePassword(this, ScResId(BTN_REMOVE_PASSWORD)),
++
++    mpProtected(pProtected)
++{
++    Init();
++}
++
++ScRetypePassInputDlg::~ScRetypePassInputDlg()
++{
++}
++
++short ScRetypePassInputDlg::Execute()
++{
++    return ModalDialog::Execute();
++}
++
++bool ScRetypePassInputDlg::IsRemovePassword() const
++{
++    return maBtnRemovePassword.IsChecked();
++}
++
++String ScRetypePassInputDlg::GetNewPassword() const
++{
++    return maPassword1Edit.GetText();
++}
++
++void ScRetypePassInputDlg::Init()
++{
++    Link aLink = LINK( this, ScRetypePassInputDlg, OKHdl );
++    maBtnOk.SetClickHdl(aLink);
++    aLink = LINK( this, ScRetypePassInputDlg, RadioBtnHdl );
++    maBtnRetypePassword.SetClickHdl(aLink);
++    maBtnRemovePassword.SetClickHdl(aLink);
++    aLink = LINK( this, ScRetypePassInputDlg, CheckBoxHdl );
++    maBtnMatchOldPass.SetClickHdl(aLink);
++    aLink = LINK( this, ScRetypePassInputDlg, PasswordModifyHdl );
++    maPassword1Edit.SetModifyHdl(aLink);
++    maPassword2Edit.SetModifyHdl(aLink);
++
++    maBtnOk.Disable();
++    maBtnRetypePassword.Check(true);
++    maBtnMatchOldPass.Check(true);
++    maPassword1Edit.GrabFocus();
++}
++
++void ScRetypePassInputDlg::CheckPasswordInput()
++{
++    String aPass1 = maPassword1Edit.GetText();
++    String aPass2 = maPassword2Edit.GetText();
++
++    if (!aPass1.Len() || !aPass2.Len())
++    {
++        // Empty password is not allowed.
++        maBtnOk.Disable();
++        return;
++    }
++
++    if (!aPass1.Equals(aPass2))
++    {
++        // The two passwords differ.
++        maBtnOk.Disable();
++        return;
++    }
++
++    if (!maBtnMatchOldPass.IsChecked())
++    {
++        maBtnOk.Enable();
++        return;
++    }
++
++    if (!mpProtected)
++    {
++        // This should never happen!
++        maBtnOk.Disable();
++        return;
++    }
++
++    bool bPassGood = mpProtected->verifyPassword(aPass1);
++    maBtnOk.Enable(bPassGood);
++}
++
++IMPL_LINK( ScRetypePassInputDlg, OKHdl, OKButton*, EMPTYARG )
++{
++    EndDialog(RET_OK);
++    return 0;
++}
++
++IMPL_LINK( ScRetypePassInputDlg, RadioBtnHdl, RadioButton*, pBtn )
++{
++    if (pBtn == &maBtnRetypePassword)
++    {
++        maBtnRemovePassword.Check(false);
++        maPassword1Text.Enable();
++        maPassword1Edit.Enable();
++        maPassword2Text.Enable();
++        maPassword2Edit.Enable();
++        maBtnMatchOldPass.Enable();
++        CheckPasswordInput();
++    }
++    else if (pBtn == &maBtnRemovePassword)
++    {
++        maBtnRetypePassword.Check(false);
++        maPassword1Text.Disable();
++        maPassword1Edit.Disable();
++        maPassword2Text.Disable();
++        maPassword2Edit.Disable();
++        maBtnMatchOldPass.Disable();
++        maBtnOk.Enable();
++    }
++
++    return 0;
++}
++
++IMPL_LINK( ScRetypePassInputDlg, CheckBoxHdl, CheckBox*, pBtn )
++{
++    CheckPasswordInput();
++    return 0;
++}
++
++IMPL_LINK( ScRetypePassInputDlg, PasswordModifyHdl, Edit*, pEdit )
++{
++    CheckPasswordInput();
++    return 0;
++}
+Index: source/ui/miscdlgs/protectiondlg.src
+===================================================================
+--- sc/source/ui/miscdlgs/protectiondlg.src	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/miscdlgs/protectiondlg.src	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,130 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: protectiondlg.src,v $
++ * $Revision: 1.1.2.6 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#include "protectiondlg.hrc"
++
++ModalDialog RID_SCDLG_TABPROTECTION
++{
++    Text [ en-US ] = "Protect Sheet" ;
++    Size = MAP_APPFONT ( 220 , 135 ) ;
++    Moveable = TRUE ;
++    Closeable = TRUE ;
++
++    OKButton BTN_OK
++    {
++        Pos = MAP_APPFONT ( 164 , 6 ) ;
++        Size = MAP_APPFONT ( 50 , 14 ) ;
++        DefButton = TRUE ;
++    };
++    CancelButton BTN_CANCEL
++    {
++        Pos = MAP_APPFONT ( 164 , 23 ) ;
++        Size = MAP_APPFONT ( 50 , 14 ) ;
++    };
++    HelpButton BTN_HELP
++    {
++        Pos = MAP_APPFONT ( 164 , 43 ) ;
++        Size = MAP_APPFONT ( 50 , 14 ) ;
++    };
++
++    CheckBox BTN_PROTECT
++    {
++        Pos = MAP_APPFONT ( 6 , 6 ) ;
++        Size = MAP_APPFONT ( 150 , 10 );
++
++        Text [ en-US ] = "P~rotect this sheet and the contents of locked cells" ;
++    };
++
++    FixedText FT_PASSWORD1
++    {
++        Pos = MAP_APPFONT ( 11, 23 );
++        Size = MAP_APPFONT ( 42, 10 );
++
++        Text [ en-US ] = "~Password" ;
++    };
++
++    Edit ED_PASSWORD1
++    {
++        Border = TRUE;
++        PassWord = TRUE;
++        Pos = MAP_APPFONT ( 56, 22 );
++        Size = MAP_APPFONT ( 75, 12 );
++    };
++
++    FixedText FT_PASSWORD2
++    {
++        Pos = MAP_APPFONT ( 11, 40 );
++        Size = MAP_APPFONT ( 42, 10 );
++
++        Text [ en-US ] = "~Confirm" ;
++    };
++
++    Edit ED_PASSWORD2
++    {
++        Border = TRUE;
++        PassWord = TRUE;
++        Pos = MAP_APPFONT ( 56, 39 );
++        Size = MAP_APPFONT ( 75, 12 );
++    };
++
++    FixedLine FL_OPTIONS
++    {
++        Pos = MAP_APPFONT ( 6, 60 );
++        Size = MAP_APPFONT ( 150, 8 );
++
++        Text [ en-US ] = "Options";
++    };
++
++    FixedText FT_OPTIONS
++    {
++        Pos = MAP_APPFONT ( 11, 74 );
++        Size = MAP_APPFONT ( 140, 8 );
++
++        Text [ en-US ] = "Allow all users of this sheet to:";
++    };
++
++    Control CLB_OPTIONS
++    {
++        Pos = MAP_APPFONT ( 11, 85 );
++        Size = MAP_APPFONT ( 140, 40 );
++        Border = TRUE ;
++        TabStop = TRUE ;
++    };
++
++    String ST_SELECT_LOCKED_CELLS
++    {
++        Text [ en-US ] = "Select locked cells";
++    };
++
++    String ST_SELECT_UNLOCKED_CELLS
++    {
++        Text [ en-US ] = "Select unlocked cells";
++    };
++};
+Index: source/ui/miscdlgs/protectiondlg.cxx
+===================================================================
+--- sc/source/ui/miscdlgs/protectiondlg.cxx	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/miscdlgs/protectiondlg.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,161 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: protectiondlg.cxx,v $
++ * $Revision: 1.1.2.6 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#include "protectiondlg.hxx"
++#include "protectiondlg.hrc"
++#include "scresid.hxx"
++#include "tabprotection.hxx"
++
++#include <vcl/msgbox.hxx>
++
++
++// The order must match that of the list box.
++static const ScTableProtection::Option aOptions[] = {
++    ScTableProtection::SELECT_LOCKED_CELLS,
++    ScTableProtection::SELECT_UNLOCKED_CELLS,
++};
++static const USHORT nOptionCount = sizeof(aOptions)/sizeof(aOptions[0]);
++
++
++ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) :
++    ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)),
++
++    maBtnProtect    (this, ScResId(BTN_PROTECT)),
++    maPassword1Text (this, ScResId(FT_PASSWORD1)),
++    maPassword1Edit (this, ScResId(ED_PASSWORD1)),
++    maPassword2Text (this, ScResId(FT_PASSWORD2)),
++    maPassword2Edit (this, ScResId(ED_PASSWORD2)),
++    maOptionsLine   (this, ScResId(FL_OPTIONS)),
++    maOptionsText   (this, ScResId(FT_OPTIONS)),
++    maOptionsListBox(this, ScResId(CLB_OPTIONS)),
++
++    maBtnOk     (this, ScResId(BTN_OK)),
++    maBtnCancel (this, ScResId(BTN_CANCEL)),
++    maBtnHelp   (this, ScResId(BTN_HELP)),
++
++    maSelectLockedCells(ScResId(ST_SELECT_LOCKED_CELLS)),
++    maSelectUnlockedCells(ScResId(ST_SELECT_UNLOCKED_CELLS))
++{
++    Init();
++    FreeResource();
++}
++
++ScTableProtectionDlg::~ScTableProtectionDlg()
++{
++}
++
++short ScTableProtectionDlg::Execute()
++{
++    return ModalDialog::Execute();
++}
++
++void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
++{
++    for (USHORT i = 0; i < nOptionCount; ++i)
++        maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
++}
++
++void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
++{
++    rData.setProtected(maBtnProtect.IsChecked());
++
++    // We assume that the two password texts match.
++    rData.setPassword(maPassword1Edit.GetText());
++
++    for (USHORT i = 0; i < nOptionCount; ++i)
++        rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i));
++}
++
++void ScTableProtectionDlg::Init()
++{
++    Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
++    maBtnProtect.SetClickHdl(aLink);
++
++    aLink = LINK( this, ScTableProtectionDlg, OKHdl );
++    maBtnOk.SetClickHdl(aLink);
++
++    aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
++    maPassword1Edit.SetModifyHdl(aLink);
++    maPassword2Edit.SetModifyHdl(aLink);
++
++    maOptionsListBox.SetUpdateMode(false);
++    maOptionsListBox.Clear();
++
++    maOptionsListBox.InsertEntry(maSelectLockedCells);
++    maOptionsListBox.InsertEntry(maSelectUnlockedCells);
++
++    maOptionsListBox.CheckEntryPos(0, true);
++    maOptionsListBox.CheckEntryPos(1, true);
++
++    maOptionsListBox.SetUpdateMode(true);
++
++    // Set the default state of the dialog.
++    maBtnProtect.Check(true);
++    maPassword1Edit.GrabFocus();
++}
++
++void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
++{
++    maPassword1Text.Enable(bEnable);
++    maPassword1Edit.Enable(bEnable);
++    maPassword2Text.Enable(bEnable);
++    maPassword2Edit.Enable(bEnable);
++    maOptionsLine.Enable(bEnable);
++    maOptionsText.Enable(bEnable);
++
++    maOptionsListBox.Enable(bEnable);
++    maOptionsListBox.Invalidate();
++}
++
++IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
++{
++    if (pBtn == &maBtnProtect)
++    {
++        bool bChecked = maBtnProtect.IsChecked();
++        EnableOptionalWidgets(bChecked);
++        maBtnOk.Enable(bChecked);
++    }
++
++    return 0;
++}
++
++IMPL_LINK( ScTableProtectionDlg, OKHdl, OKButton*, EMPTYARG )
++{
++    EndDialog(RET_OK);
++    return 0;
++}
++
++IMPL_LINK( ScTableProtectionDlg, PasswordModifyHdl, Edit*, EMPTYARG )
++{
++    String aPass1 = maPassword1Edit.GetText();
++    String aPass2 = maPassword2Edit.GetText();
++    maBtnOk.Enable(aPass1.Equals(aPass2));
++    return 0;
++}
+Index: source/ui/inc/retypepassdlg.hrc
+===================================================================
+--- sc/source/ui/inc/retypepassdlg.hrc	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/inc/retypepassdlg.hrc	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,74 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: retypepassdlg.hrc,v $
++ * $Revision: 1.1.2.2 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#include <sc.hrc>
++
++#define BTN_OK					 1
++#define BTN_CANCEL				 2
++#define BTN_HELP				 3
++
++#define FT_DESC                 10
++#define FL_DOCUMENT             11
++#define FT_DOCSTATUS            12
++#define BTN_RETYPE_DOC          13
++
++#define FL_SHEET                112
++
++#define FT_SHEETNAME1           113
++#define FT_SHEETSTATUS1         114
++#define BTN_RETYPE_SHEET1       115
++
++#define FT_SHEETNAME2           116
++#define FT_SHEETSTATUS2         117
++#define BTN_RETYPE_SHEET2       118
++
++#define FT_SHEETNAME3           119
++#define FT_SHEETSTATUS3         120
++#define BTN_RETYPE_SHEET3       121
++
++#define FT_SHEETNAME4           122
++#define FT_SHEETSTATUS4         123
++#define BTN_RETYPE_SHEET4       124
++
++#define SB_SCROLL               190
++
++#define STR_NOT_PROTECTED       200
++#define STR_NOT_PASS_PROTECTED  201
++#define STR_HASH_BAD            202
++#define STR_HASH_GOOD           203
++#define STR_HASH_REGENERATED    204
++
++#define FT_PASSWORD1            301
++#define ED_PASSWORD1            302
++#define FT_PASSWORD2            303
++#define ED_PASSWORD2            304
++#define BTN_MATCH_OLD_PASSWORD  305
++#define BTN_RETYPE_PASSWORD     306
++#define BTN_REMOVE_PASSWORD     307
+Index: source/ui/inc/tabvwsh.hxx
+===================================================================
+--- sc/source/ui/inc/tabvwsh.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/inc/tabvwsh.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -38,6 +38,7 @@
+ #include "target.hxx"
+ #include "rangelst.hxx"			// ScRangeListRef
+ #include "shellids.hxx"
++#include "tabprotection.hxx" // for ScPasswordHash
  
--String __EXPORT ScUndoRemoveLink::GetComment() const
-+String ScUndoRemoveLink::GetComment() const
- {
- 	return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
- }
-@@ -1099,22 +1101,22 @@
- 	pDocShell->UpdateLinks();
- }
+ class FmFormShell;
+ class SbxObject;
+@@ -428,6 +429,8 @@
+ 	void	BroadcastAccessibility( const SfxHint &rHint );
+ 	BOOL	HasAccessibilityObjects();
  
--void __EXPORT ScUndoRemoveLink::Undo()
-+void ScUndoRemoveLink::Undo()
- {
- 	DoChange( TRUE );
- }
++    bool    ExecuteRetypePassDlg(ScPasswordHash eDesiredHash);
++
+     using ScTabView::ShowCursor;
+ };
  
--void __EXPORT ScUndoRemoveLink::Redo()
-+void ScUndoRemoveLink::Redo()
- {
- 	DoChange( FALSE );
- }
+Index: source/ui/inc/undotab.hxx
+===================================================================
+--- sc/source/ui/inc/undotab.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/inc/undotab.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -52,11 +52,15 @@
  
--void __EXPORT ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
- {
- 	//	gippsnich
- }
+ #include <com/sun/star/uno/Sequence.hxx>
  
--BOOL __EXPORT ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
- {
- 	return FALSE;
- }
-@@ -1132,7 +1134,7 @@
- {
- }
++#include <memory>
++
+ class ScDocShell;
+ class ScDocument;
+ class SdrUndoAction;
+ class ScPrintRangeSaver;
+ class SdrObject;
++class ScDocProtection;
++class ScTableProtection;
  
--__EXPORT ScUndoShowHideTab::~ScUndoShowHideTab()
-+ScUndoShowHideTab::~ScUndoShowHideTab()
- {
- }
+ //----------------------------------------------------------------------------
  
-@@ -1149,17 +1151,17 @@
- 	pDocShell->SetDocumentModified();
- }
+@@ -335,14 +339,15 @@
+ 	void DoChange( BOOL bShow ) const;
+ };
  
--void __EXPORT ScUndoShowHideTab::Undo()
-+void ScUndoShowHideTab::Undo()
- {
- 	DoChange(!bShow);
- }
++// ============================================================================
  
--void __EXPORT ScUndoShowHideTab::Redo()
-+void ScUndoShowHideTab::Redo()
+-class ScUndoProtect : public ScSimpleUndo
++/** This class implements undo & redo of document protect & unprotect
++    operations. */
++class ScUndoDocProtect : public ScSimpleUndo
  {
- 	DoChange(bShow);
- }
+ public:
+-					TYPEINFO();
+-					ScUndoProtect( ScDocShell* pShell, SCTAB nNewTab,
+-									BOOL bNewProtect, const com::sun::star::uno::Sequence<sal_Int8>& rNewPassword );
+-	virtual			~ScUndoProtect();
++                    ScUndoDocProtect(ScDocShell* pShell, ::std::auto_ptr<ScDocProtection> pProtectSettings);
++	virtual			~ScUndoDocProtect();
  
--void __EXPORT ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
- {
- 	if (rTarget.ISA(ScTabViewTarget))
- 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
-@@ -1167,53 +1169,44 @@
- 								SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
- }
+ 	virtual void	Undo();
+ 	virtual void	Redo();
+@@ -352,14 +357,37 @@
+ 	virtual String	GetComment() const;
  
--BOOL __EXPORT ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
- {
- 	return (rTarget.ISA(ScTabViewTarget));
- }
+ private:
+-	SCTAB	nTab;
+-	BOOL	bProtect;
+-	com::sun::star::uno::Sequence<sal_Int8>	aPassword;
++    ::std::auto_ptr<ScDocProtection> mpProtectSettings;
  
--String __EXPORT ScUndoShowHideTab::GetComment() const
-+String ScUndoShowHideTab::GetComment() const
- {
- 	USHORT nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
- 	return ScGlobal::GetRscString( nId );
- }
+-	void	DoProtect( BOOL bDo );
++	void	DoProtect(bool bProtect);
+ };
  
--// -----------------------------------------------------------------------
--//
--//		Tabelle/Dokument schuetzen oder Schutz aufheben
--//
 +// ============================================================================
  
--ScUndoProtect::ScUndoProtect( ScDocShell* pShell, SCTAB nNewTab,
--							BOOL bNewProtect, const uno::Sequence<sal_Int8>& rNewPassword ) :
--	ScSimpleUndo( pShell ),
--	nTab( nNewTab ),
--	bProtect( bNewProtect ),
--	aPassword( rNewPassword )
-+ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
-+    ScSimpleUndo(pShell),
-+    mpProtectSettings(pProtectSettings)
++/** This class implements undo & redo of both protect and unprotect of
++    sheet. */
++class ScUndoTabProtect : public ScSimpleUndo
++{
++public:
++                    ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, 
++                                     ::std::auto_ptr<ScTableProtection> pProtectSettings);
++	virtual			~ScUndoTabProtect();
++
++	virtual void	Undo();
++	virtual void	Redo();
++	virtual void	Repeat(SfxRepeatTarget& rTarget);
++	virtual BOOL	CanRepeat(SfxRepeatTarget& rTarget) const;
++
++	virtual String	GetComment() const;
++
++private:
++    SCTAB   mnTab;
++    ::std::auto_ptr<ScTableProtection> mpProtectSettings;
++
++	void	DoProtect(bool bProtect);
++};
++
++
+ class ScUndoPrintRange : public ScSimpleUndo
  {
- }
+ public:
+Index: source/ui/inc/viewfunc.hxx
+===================================================================
+--- sc/source/ui/inc/viewfunc.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/inc/viewfunc.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -69,6 +69,7 @@
+ class ScRangeList;
+ class SvxHyperlinkItem;
+ class ScTransferObj;
++class ScTableProtection;
  
--__EXPORT ScUndoProtect::~ScUndoProtect()
-+ScUndoDocProtect::~ScUndoDocProtect()
- {
- }
+ namespace com { namespace sun { namespace star { namespace datatransfer { class XTransferable; } } } }
  
--void ScUndoProtect::DoProtect( BOOL bDo )
-+void ScUndoDocProtect::DoProtect(bool bProtect)
- {
- 	ScDocument* pDoc = pDocShell->GetDocument();
+@@ -199,6 +200,8 @@
  
--	if (bDo)
-+	if (bProtect)
- 	{
--		if ( nTab == TABLEID_DOC )
--			pDoc->SetDocProtection( TRUE, aPassword );
--		else
--			pDoc->SetTabProtection( nTab, TRUE, aPassword );
-+        // set protection.
-+        auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
-+        pCopy->setProtected(true);
-+        pDoc->SetDocProtection(pCopy.get());
- 	}
- 	else
- 	{
--		uno::Sequence<sal_Int8> aEmptyPass;
--		if ( nTab == TABLEID_DOC )
--			pDoc->SetDocProtection( FALSE, aEmptyPass );
--		else
--			pDoc->SetTabProtection( nTab, FALSE, aEmptyPass );
-+        // remove protection.
-+        pDoc->SetDocProtection(NULL);
- 	}
+ 	void			ChangeIndent( BOOL bIncrement );
  
- 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
-@@ -1226,37 +1219,103 @@
- 	pDocShell->PostPaintGridAll();
- }
++	void			ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
++
+ 	void			Protect( SCTAB nTab, const String& rPassword );
+ 	BOOL			Unprotect( SCTAB nTab, const String& rPassword );
  
--void __EXPORT ScUndoProtect::Undo()
-+void ScUndoDocProtect::Undo()
- {
- 	BeginUndo();
--	DoProtect( !bProtect );
-+	DoProtect(!mpProtectSettings->isProtected());
- 	EndUndo();
- }
+Index: source/ui/inc/protectiondlg.hxx
+===================================================================
+--- sc/source/ui/inc/protectiondlg.hxx	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/inc/protectiondlg.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,85 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: protectiondlg.hxx,v $
++ * $Revision: 1.1.2.4 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#ifndef SC_UI_PROTECTION_DLG_HXX
++#define SC_UI_PROTECTION_DLG_HXX
++
++#include <vcl/dialog.hxx>
++#include <vcl/button.hxx>
++#include <vcl/fixed.hxx>
++#include <vcl/edit.hxx>
++#include <svx/checklbx.hxx>
++
++class Window;
++class ScTableProtection;
++
++class ScTableProtectionDlg : public ModalDialog
++{
++public:
++    explicit ScTableProtectionDlg(Window* pParent);
++    virtual ~ScTableProtectionDlg();
++
++    virtual short Execute();
++
++    void SetDialogData(const ScTableProtection& rData);
++
++    void WriteData(ScTableProtection& rData) const;
++
++private:
++    ScTableProtectionDlg(); // disabled
++
++    void Init();
++
++    void EnableOptionalWidgets(bool bEnable = true);
++
++    CheckBox        maBtnProtect;
++
++    FixedText       maPassword1Text;
++    Edit            maPassword1Edit;
++    FixedText       maPassword2Text;
++    Edit            maPassword2Edit;
++
++    FixedLine       maOptionsLine;
++    FixedText       maOptionsText;
++    SvxCheckListBox maOptionsListBox;
++
++    OKButton        maBtnOk;
++    CancelButton    maBtnCancel;
++    HelpButton      maBtnHelp;
++
++    String          maSelectLockedCells;
++    String          maSelectUnlockedCells;
++
++    DECL_LINK( OKHdl, OKButton* );
++    DECL_LINK( CheckBoxHdl, CheckBox* );
++    DECL_LINK( PasswordModifyHdl, Edit* );
++};
++
++#endif
+Index: source/ui/inc/docfunc.hxx
+===================================================================
+--- sc/source/ui/inc/docfunc.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/inc/docfunc.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -47,8 +47,8 @@
+ class ScBaseCell;
+ class ScTokenArray;
+ struct ScTabOpParam;
++class ScTableProtection;
  
--void __EXPORT ScUndoProtect::Redo()
-+void ScUndoDocProtect::Redo()
- {
- 	BeginRedo();
--	DoProtect( bProtect );
-+	DoProtect(mpProtectSettings->isProtected());
- 	EndRedo();
- }
+-
+ // ---------------------------------------------------------------------------
  
--void __EXPORT ScUndoProtect::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
- {
- 	//	gippsnich
- }
+ class ScDocFunc
+@@ -129,6 +129,8 @@
+ 	BOOL			RemovePageBreak( BOOL bColumn, const ScAddress& rPos,
+ 									BOOL bRecord, BOOL bSetModified, BOOL bApi );
  
--BOOL __EXPORT ScUndoProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
- {
- 	return FALSE;		// gippsnich
- }
++    void            ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
++
+ 	BOOL			Protect( SCTAB nTab, const String& rPassword, BOOL bApi );
+ 	BOOL			Unprotect( SCTAB nTab, const String& rPassword, BOOL bApi );
  
--String __EXPORT ScUndoProtect::GetComment() const
-+String ScUndoDocProtect::GetComment() const
-+{
-+    USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
-+    return ScGlobal::GetRscString( nId );
-+}
+Index: source/ui/inc/protectiondlg.hrc
+===================================================================
+--- sc/source/ui/inc/protectiondlg.hrc	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/inc/protectiondlg.hrc	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,47 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: protectiondlg.hrc,v $
++ * $Revision: 1.1.2.1 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
 +
-+// ============================================================================
++#include <sc.hrc>
 +
-+ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
-+    ScSimpleUndo(pShell),
-+    mnTab(nTab),
-+    mpProtectSettings(pProtectSettings)
-+{
-+}
++#define BTN_OK					1
++#define BTN_CANCEL				2
++#define BTN_HELP				3
 +
-+ScUndoTabProtect::~ScUndoTabProtect()
- {
--	USHORT nId;
--	if ( nTab == TABLEID_DOC )
--		nId = bProtect ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
-+}
++#define BTN_PROTECT             4
++#define FT_PASSWORD1            5
++#define ED_PASSWORD1            6
++#define FT_PASSWORD2            7
++#define ED_PASSWORD2            8
++#define FL_OPTIONS              9
++#define FT_OPTIONS             10
++#define CLB_OPTIONS            11
 +
-+void ScUndoTabProtect::DoProtect(bool bProtect)
++#define ST_SELECT_LOCKED_CELLS          50
++#define ST_SELECT_UNLOCKED_CELLS        51
+Index: source/ui/inc/retypepassdlg.hxx
+===================================================================
+--- sc/source/ui/inc/retypepassdlg.hxx	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/source/ui/inc/retypepassdlg.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,177 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ * 
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: retypepassdlg.hxx,v $
++ * $Revision: 1.1.2.7 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#ifndef SC_UI_RETYPEPASS_DLG_HXX
++#define SC_UI_RETYPEPASS_DLG_HXX
++
++#include <vcl/dialog.hxx>
++#include <vcl/button.hxx>
++#include <vcl/fixed.hxx>
++#include <vcl/edit.hxx>
++#include <vcl/scrbar.hxx>
++#include <svx/checklbx.hxx>
++#include <svtools/stdctrl.hxx>
++
++#include "tabprotection.hxx"
++
++#include <boost/shared_ptr.hpp>
++
++class Window;
++class ScDocProtection;
++class ScTableProtection;
++class ScDocument;
++
++class ScRetypePassDlg : public ModalDialog
 +{
-+	ScDocument* pDoc = pDocShell->GetDocument();
++public:
++    typedef ::boost::shared_ptr<ScDocProtection>    DocProtectionPtr;
++    typedef ::boost::shared_ptr<ScTableProtection>  TabProtectionPtr;
++
++    explicit ScRetypePassDlg(Window* pParent);
++    virtual ~ScRetypePassDlg();
++
++    virtual short Execute();
++
++    void SetData(const ScDocument& rDoc);
++    void SetDesiredHash(ScPasswordHash eHash);
++
++    /** Write the new set of password data to the document instance to
++        overwrite the current ones. */
++    void WriteNewDataToDocument(ScDocument& rDoc) const;
++
++private:
++    ScRetypePassDlg(); // disabled
++
++    void Init();
++    void PopulateDialog();
++    void SetDocData();
++    void SetTableData(sal_uInt8 nRowPos, SCTAB nTab);
++    void ResetTableRows();
++
++    /** Check the status of all hash values to see if it's okay to enable
++        the OK button. */
++    void CheckHashStatus();
++
++private:
++    OKButton        maBtnOk;
++    CancelButton    maBtnCancel;
++    HelpButton      maBtnHelp;
++
++    FixedInfo       maTextDescription;
++
++    FixedLine       maLineDocument;
++    FixedText       maTextDocStatus;
++    PushButton      maBtnRetypeDoc;
 +
-+	if (bProtect)
-+	{
-+        // set protection.
-+        auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
-+        pCopy->setProtected(true);
-+        pDoc->SetTabProtection(mnTab, pCopy.get());
-+	}
- 	else
--		nId = bProtect ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
-+	{
-+        // remove protection.
-+        pDoc->SetTabProtection(mnTab, NULL);
-+	}
++    FixedLine       maLineSheet;
++    FixedText       maTextSheetName1;
++    FixedText       maTextSheetStatus1;
++    PushButton      maBtnRetypeSheet1;
 +
-+	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
-+	if (pViewShell)
-+	{
-+		pViewShell->UpdateLayerLocks();
-+		pViewShell->UpdateInputHandler(TRUE);	// damit sofort wieder eingegeben werden kann
-+	}
++    FixedText       maTextSheetName2;
++    FixedText       maTextSheetStatus2;
++    PushButton      maBtnRetypeSheet2;
 +
-+	pDocShell->PostPaintGridAll();
-+}
++    FixedText       maTextSheetName3;
++    FixedText       maTextSheetStatus3;
++    PushButton      maBtnRetypeSheet3;
 +
-+void ScUndoTabProtect::Undo()
-+{
-+	BeginUndo();
-+	DoProtect(!mpProtectSettings->isProtected());
-+	EndUndo();
-+}
++    FixedText       maTextSheetName4;
++    FixedText       maTextSheetStatus4;
++    PushButton      maBtnRetypeSheet4;
 +
-+void ScUndoTabProtect::Redo()
-+{
-+	BeginRedo();
-+	DoProtect(mpProtectSettings->isProtected());
-+	EndRedo();
-+}
++    ScrollBar       maScrollBar;
 +
-+void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
-+{
-+	//	gippsnich
-+}
++    String          maTextNotProtected;
++    String          maTextNotPassProtected;
++    String          maTextHashBad;
++    String          maTextHashGood;
++    String          maTextHashRegen;
 +
-+BOOL ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+{
-+	return FALSE;		// gippsnich
-+}
++    DECL_LINK( OKHdl, OKButton* );
++    DECL_LINK( RetypeBtnHdl, PushButton* );
++    DECL_LINK( ScrollHdl, ScrollBar* );
 +
-+String ScUndoTabProtect::GetComment() const
-+{
-+    USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
- 	return ScGlobal::GetRscString( nId );
- }
- 
-@@ -1274,7 +1333,7 @@
- {
- }
- 
--__EXPORT ScUndoPrintRange::~ScUndoPrintRange()
-+ScUndoPrintRange::~ScUndoPrintRange()
- {
- 	delete pOldRanges;
- 	delete pNewRanges;
-@@ -1297,31 +1356,31 @@
- 	pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
- }
- 
--void __EXPORT ScUndoPrintRange::Undo()
-+void ScUndoPrintRange::Undo()
- {
- 	BeginUndo();
- 	DoChange( TRUE );
- 	EndUndo();
- }
- 
--void __EXPORT ScUndoPrintRange::Redo()
-+void ScUndoPrintRange::Redo()
- {
- 	BeginRedo();
- 	DoChange( FALSE );
- 	EndRedo();
- }
- 
--void __EXPORT ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
- {
- 	//	gippsnich
- }
- 
--BOOL __EXPORT ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
- {
- 	return FALSE;		// gippsnich
- }
- 
--String __EXPORT ScUndoPrintRange::GetComment() const
-+String ScUndoPrintRange::GetComment() const
- {
- 	return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
- }
-@@ -1350,16 +1409,16 @@
- {
- }
- 
--__EXPORT ScUndoScenarioFlags::~ScUndoScenarioFlags()
-+ScUndoScenarioFlags::~ScUndoScenarioFlags()
- {
- }
- 
--String __EXPORT ScUndoScenarioFlags::GetComment() const
-+String ScUndoScenarioFlags::GetComment() const
- {
- 	return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
- }
- 
--void __EXPORT ScUndoScenarioFlags::Undo()
-+void ScUndoScenarioFlags::Undo()
- {
- 	ScDocument* pDoc = pDocShell->GetDocument();
- 
-@@ -1376,7 +1435,7 @@
- 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
- }
- 
--void __EXPORT ScUndoScenarioFlags::Redo()
-+void ScUndoScenarioFlags::Redo()
- {
- 	ScDocument* pDoc = pDocShell->GetDocument();
- 
-@@ -1393,12 +1452,12 @@
- 		SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
- }
- 
--void __EXPORT ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
- {
- 	//	Repeat macht keinen Sinn
- }
- 
--BOOL __EXPORT ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
-+BOOL ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
- {
- 	return FALSE;
- }
-@@ -1498,7 +1557,7 @@
- {
- }
- 
--__EXPORT ScUndoLayoutRTL::~ScUndoLayoutRTL()
-+ScUndoLayoutRTL::~ScUndoLayoutRTL()
- {
- }
- 
-@@ -1518,29 +1577,29 @@
- 	pDocShell->SetInUndo( FALSE );
- }
- 
--void __EXPORT ScUndoLayoutRTL::Undo()
-+void ScUndoLayoutRTL::Undo()
- {
- 	DoChange(!bRTL);
- }
- 
--void __EXPORT ScUndoLayoutRTL::Redo()
-+void ScUndoLayoutRTL::Redo()
- {
- 	DoChange(bRTL);
- }
- 
--void __EXPORT ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
-+void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
- {
- 	if (rTarget.ISA(ScTabViewTarget))
- 		((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
- 			Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
- }
- 
--BOOL __EXPORT ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
- {
- 	return (rTarget.ISA(ScTabViewTarget));
- }
- 
--String __EXPORT ScUndoLayoutRTL::GetComment() const
-+String ScUndoLayoutRTL::GetComment() const
- {
- 	return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
- }
-@@ -1560,7 +1619,7 @@
-     meOldGrammar = pDocShell->GetDocument()->GetGrammar();
- }
- 
--__EXPORT ScUndoSetGrammar::~ScUndoSetGrammar()
-+ScUndoSetGrammar::~ScUndoSetGrammar()
- {
- }
- 
-@@ -1573,17 +1632,17 @@
-     pDocShell->SetInUndo( FALSE );
- }
- 
--void __EXPORT ScUndoSetGrammar::Undo()
-+void ScUndoSetGrammar::Undo()
- {
-     DoChange( meOldGrammar );
- }
- 
--void __EXPORT ScUndoSetGrammar::Redo()
-+void ScUndoSetGrammar::Redo()
- {
-     DoChange( meNewGrammar );
- }
- 
--void __EXPORT ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
-+void ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
- {
- #if 0
- // erAck: 2006-09-07T23:00+0200  commented out in CWS scr1c1
-@@ -1593,12 +1652,12 @@
- #endif
- }
- 
--BOOL __EXPORT ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
-+BOOL ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
- {
-     return (rTarget.ISA(ScTabViewTarget));
- }
- 
--String __EXPORT ScUndoSetGrammar::GetComment() const
-+String ScUndoSetGrammar::GetComment() const
- {
-     return ScGlobal::GetRscString( STR_UNDO_TAB_R1C1 );
- }
-Index: sc/source/ui/unoobj/warnpassword.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/unoobj/warnpassword.cxx,v
-retrieving revision 1.5
-retrieving revision 1.5.30.1
-diff -u -I $Revision.*$ -I $Author.*$ -r1.5 -r1.5.30.1
---- sc/source/ui/unoobj/warnpassword.cxx	11 Apr 2008 00:46:26 -0000	1.5
-+++ sc/source/ui/unoobj/warnpassword.cxx	22 May 2008 21:47:22 -0000	1.5.30.1
-@@ -32,6 +32,9 @@
- #include "precompiled_sc.hxx"
- 
- // ============================================================================
++    struct TableItem
++    {
++        String              maName;
++        TabProtectionPtr    mpProtect;
++    };
++    ::std::vector<TableItem> maTableItems;
 +
-+#if 0
++    DocProtectionPtr    mpDocItem;
++    size_t              mnCurScrollPos;
++    ScPasswordHash      meDesiredHash;
++};
 +
- #include "warnpassword.hxx"
- #include <com/sun/star/task/XInteractionHandler.hpp>
- #include <com/sun/star/task/XInteractionRequest.hpp>
-@@ -95,3 +98,5 @@
-     }
-     return bReturn;
- }
++// ============================================================================
 +
-+#endif
-Index: sc/source/ui/view/gridwin.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/gridwin.cxx,v
-retrieving revision 1.96
-retrieving revision 1.92.26.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.96 -r1.92.26.5
---- sc/source/ui/view/gridwin.cxx	1 Jul 2008 16:27:56 -0000	1.96
-+++ sc/source/ui/view/gridwin.cxx	17 Jul 2008 01:00:06 -0000	1.92.26.5
-@@ -139,6 +139,7 @@
- #include "drwlayer.hxx"
- #include "attrib.hxx"
- #include "cellsh.hxx"
-+#include "tabprotection.hxx"
- 
- // #114409#
- #include <vcl/salbtype.hxx>		// FRound
-@@ -2014,8 +2015,9 @@
- 		Point aPos = rMEvt.GetPosPixel();
-         SCsCOL nPosX;
-         SCsROW nPosY;
-+        SCTAB nTab = pViewData->GetTabNo();
-         pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
--		ScDPObject*	pDPObj	= pDoc->GetDPAtCursor( nPosX, nPosY, pViewData->GetTabNo() );
-+		ScDPObject*	pDPObj	= pDoc->GetDPAtCursor( nPosX, nPosY, nTab );
- 		if ( pDPObj && pDPObj->GetSaveData()->GetDrillDown() )
- 		{
- 			ScAddress aCellPos( nPosX, nPosY, pViewData->GetTabNo() );
-@@ -2057,19 +2059,37 @@
- 			return;
- 		}
- 
--		//	edit cell contents
--		pViewData->GetViewShell()->UpdateInputHandler();
--		pScMod->SetInputMode( SC_INPUT_TABLE );
--		if (pViewData->HasEditView(eWhich))
--		{
--			//	Text-Cursor gleich an die geklickte Stelle setzen
--			EditView* pEditView = pViewData->GetEditView( eWhich );
--			MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
--			pEditView->MouseButtonDown( aEditEvt );
--			pEditView->MouseButtonUp( aEditEvt );
--		}
-+        // Check for cell protection attribute.
-+        ScTableProtection* pProtect = pDoc->GetTabProtection( nTab );
-+        bool bEditAllowed = true;
-+        if ( pProtect && pProtect->isProtected() )
-+        {
-+            bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
-+            bool bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
-+            bool bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
++class ScRetypePassInputDlg : public ModalDialog
++{
++public:
++    explicit ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected);
++    virtual ~ScRetypePassInputDlg();
 +
-+            if ( bSkipProtected && bSkipUnprotected )
-+                bEditAllowed = false;
-+            else if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
-+                bEditAllowed = false;
-+        }
++    virtual short Execute();
 +
-+        if ( bEditAllowed )
-+        {
-+            //  edit cell contents
-+            pViewData->GetViewShell()->UpdateInputHandler();
-+            pScMod->SetInputMode( SC_INPUT_TABLE );
-+            if (pViewData->HasEditView(eWhich))
-+            {
-+                //  Text-Cursor gleich an die geklickte Stelle setzen
-+                EditView* pEditView = pViewData->GetEditView( eWhich );
-+                MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
-+                pEditView->MouseButtonDown( aEditEvt );
-+                pEditView->MouseButtonUp( aEditEvt );
-+            }
-+        }
-         return;
--	}
-+    }
- 
- 			//
- 			//		Links in edit cells
-Index: sc/source/ui/view/scextopt.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/scextopt.cxx,v
-retrieving revision 1.5
-retrieving revision 1.4.486.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.5 -r1.4.486.3
---- sc/source/ui/view/scextopt.cxx	11 Apr 2008 01:37:36 -0000	1.5
-+++ sc/source/ui/view/scextopt.cxx	22 May 2008 21:44:08 -0000	1.4.486.3
-@@ -42,9 +42,7 @@
-     maOleSize( ScAddress::INITIALIZE_INVALID ),
-     mfTabBarWidth( -1.0 ),
-     mnLinkCnt( 0 ),
--    mnDisplTab( 0 ),
--    mbWinProtected( false ),
--    mbEncrypted( false )
-+    mnDisplTab( 0 )
- {
- }
- 
-Index: sc/source/ui/view/select.cxx
++    bool IsRemovePassword() const;
++    String GetNewPassword() const;
++
++private:
++    ScRetypePassInputDlg(); // disabled
++
++    void Init();
++    void CheckPasswordInput();
++
++private:
++    OKButton        maBtnOk;
++    CancelButton    maBtnCancel;
++    HelpButton      maBtnHelp;
++
++    RadioButton     maBtnRetypePassword;
++
++    FixedText       maPassword1Text;
++    Edit            maPassword1Edit;
++    FixedText       maPassword2Text;
++    Edit            maPassword2Edit;
++
++    CheckBox        maBtnMatchOldPass;
++
++    RadioButton     maBtnRemovePassword;
++
++    DECL_LINK( OKHdl, OKButton* );
++    DECL_LINK( RadioBtnHdl, RadioButton* );
++    DECL_LINK( CheckBoxHdl, CheckBox* );
++    DECL_LINK( PasswordModifyHdl, Edit* );
++
++    ScPassHashProtectable* mpProtected;
++};
++
++#endif
+Index: source/ui/view/select.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/select.cxx,v
-retrieving revision 1.20
-retrieving revision 1.18.324.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.20 -r1.18.324.3
---- sc/source/ui/view/select.cxx	22 Jul 2008 14:44:44 -0000	1.20
-+++ sc/source/ui/view/select.cxx	9 Aug 2008 21:48:44 -0000	1.18.324.3
+--- sc/source/ui/view/select.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/select.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -47,6 +47,7 @@
  //#include "dataobj.hxx"
  #include "transobj.hxx"
@@ -7097,149 +6358,34 @@
 +            return FALSE;
 +
 +        bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
-+        if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
-+            // Don't select this cell!
-+            return FALSE;
-+    }
-+
- 	ScModule* pScMod = SC_MOD();
-     ScTabViewShell* pViewShell = pViewData->GetViewShell();
-     bool bRefMode = ( pViewShell ? pViewShell->IsRefInputMode() : false );
-@@ -375,7 +396,6 @@
- 
- 		ScRange aDelRange;
- 		BOOL bOldDelMark = pViewData->GetDelMark( aDelRange );
--		ScDocument* pDoc = pViewData->GetDocument();
- 
- 		if ( nPosX+1 >= (SCsCOL) nStartX && nPosX <= (SCsCOL) nEndX &&
- 			 nPosY+1 >= (SCsROW) nStartY && nPosY <= (SCsROW) nEndY &&
-@@ -511,7 +531,6 @@
- 		BYTE nMode = pViewData->GetFillMode();
- 		if ( nMode == SC_FILL_EMBED_LT || nMode == SC_FILL_EMBED_RB )
- 		{
--			ScDocument* pDoc = pViewData->GetDocument();
- 			DBG_ASSERT( pDoc->IsEmbedded(), "!pDoc->IsEmbedded()" );
-             ScRange aRange;
- 			pDoc->GetEmbedded( aRange);
-Index: sc/source/ui/view/tabview3.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/tabview3.cxx,v
-retrieving revision 1.69
-retrieving revision 1.65.56.4
-diff -u -I $Revision.*$ -I $Author.*$ -r1.69 -r1.65.56.4
---- sc/source/ui/view/tabview3.cxx	22 Jul 2008 14:44:57 -0000	1.69
-+++ sc/source/ui/view/tabview3.cxx	9 Aug 2008 21:48:41 -0000	1.65.56.4
-@@ -79,6 +79,7 @@
- #include "AccessibilityHints.hxx"
- #include "rangeutl.hxx"
- #include "client.hxx"
-+#include "tabprotection.hxx"
- 
- #include <com/sun/star/chart2/data/HighlightedRange.hpp>
- 
-@@ -1023,6 +1024,17 @@
- 	ScDocument* pDoc = aViewData.GetDocument();
- 	SCTAB nTab = aViewData.GetTabNo();
- 
-+    bool bSkipProtected = false, bSkipUnprotected = false;
-+    ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
-+    if ( pProtect && pProtect->isProtected() )
-+    {
-+        bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
-+        bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
-+    }
-+
-+    if ( bSkipProtected && bSkipUnprotected )
-+        return;
-+
- 	SCsCOL nOldX;
- 	SCsROW nOldY;
- 	SCsCOL nCurX;
-@@ -1042,7 +1054,7 @@
- 		nCurY = (nMovY != 0) ? nOldY+nMovY : (SCsROW) aViewData.GetOldCurY();
- 	}
- 
--	BOOL bHidden;
-+	BOOL bSkipCell = FALSE;
- 	aViewData.ResetOldCursor();
- 
- 	if (nMovX != 0 && VALIDCOLROW(nCurX,nCurY))
-@@ -1051,15 +1063,20 @@
- 		do
- 		{
- 			BYTE nColFlags = pDoc->GetColFlags( nCurX, nTab );
--			bHidden = (nColFlags & CR_HIDDEN) || pDoc->IsHorOverlapped( nCurX, nCurY, nTab );
--			if (bHidden)
-+            bSkipCell = (nColFlags & CR_HIDDEN) || pDoc->IsHorOverlapped( nCurX, nCurY, nTab );
-+            if (bSkipProtected && !bSkipCell)
-+                bSkipCell = pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
-+            if (bSkipUnprotected && !bSkipCell)
-+                bSkipCell = !pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
-+
-+			if (bSkipCell)
- 			{
- 				if ( nCurX<=0 || nCurX>=MAXCOL )
- 				{
- 					if (bHFlip)
- 					{
- 						nCurX = nOldX;
--						bHidden = FALSE;
-+						bSkipCell = FALSE;
- 					}
- 					else
- 					{
-@@ -1072,7 +1089,8 @@
- 					if (nMovX > 0) ++nCurX; else --nCurX;
- 			}
- 		}
--		while (bHidden);
-+		while (bSkipCell);
-+
- 		if (pDoc->IsVerOverlapped( nCurX, nCurY, nTab ))
- 		{
- 			aViewData.SetOldCursor( nCurX,nCurY );
-@@ -1087,15 +1105,20 @@
- 		do
- 		{
- 			BYTE nRowFlags = pDoc->GetRowFlags( nCurY, nTab );
--			bHidden = (nRowFlags & CR_HIDDEN) || pDoc->IsVerOverlapped( nCurX, nCurY, nTab );
--			if (bHidden)
-+            bSkipCell = (nRowFlags & CR_HIDDEN) || pDoc->IsVerOverlapped( nCurX, nCurY, nTab );
-+            if (bSkipProtected && !bSkipCell)
-+                bSkipCell = pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
-+            if (bSkipUnprotected && !bSkipCell)
-+                bSkipCell = !pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
-+
-+			if (bSkipCell)
- 			{
- 				if ( nCurY<=0 || nCurY>=MAXROW )
- 				{
- 					if (bVFlip)
- 					{
- 						nCurY = nOldY;
--						bHidden = FALSE;
-+						bSkipCell = FALSE;
- 					}
- 					else
- 					{
-@@ -1108,7 +1131,8 @@
- 					if (nMovY > 0) ++nCurY; else --nCurY;
- 			}
- 		}
--		while (bHidden);
-+		while (bSkipCell);
++        if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
++            // Don't select this cell!
++            return FALSE;
++    }
 +
- 		if (pDoc->IsHorOverlapped( nCurX, nCurY, nTab ))
+ 	ScModule* pScMod = SC_MOD();
+     ScTabViewShell* pViewShell = pViewData->GetViewShell();
+     bool bRefMode = ( pViewShell ? pViewShell->IsRefInputMode() : false );
+@@ -375,7 +396,6 @@
+ 
+ 		ScRange aDelRange;
+ 		BOOL bOldDelMark = pViewData->GetDelMark( aDelRange );
+-		ScDocument* pDoc = pViewData->GetDocument();
+ 
+ 		if ( nPosX+1 >= (SCsCOL) nStartX && nPosX <= (SCsCOL) nEndX &&
+ 			 nPosY+1 >= (SCsROW) nStartY && nPosY <= (SCsROW) nEndY &&
+@@ -511,7 +531,6 @@
+ 		BYTE nMode = pViewData->GetFillMode();
+ 		if ( nMode == SC_FILL_EMBED_LT || nMode == SC_FILL_EMBED_RB )
  		{
- 			aViewData.SetOldCursor( nCurX,nCurY );
-Index: sc/source/ui/view/tabvwsh3.cxx
+-			ScDocument* pDoc = pViewData->GetDocument();
+ 			DBG_ASSERT( pDoc->IsEmbedded(), "!pDoc->IsEmbedded()" );
+             ScRange aRange;
+ 			pDoc->GetEmbedded( aRange);
+Index: source/ui/view/tabvwsh3.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/tabvwsh3.cxx,v
-retrieving revision 1.40
-retrieving revision 1.38.80.5
-diff -u -I $Revision.*$ -I $Author.*$ -r1.40 -r1.38.80.5
---- sc/source/ui/view/tabvwsh3.cxx	14 May 2008 10:05:09 -0000	1.40
-+++ sc/source/ui/view/tabvwsh3.cxx	31 May 2008 01:31:54 -0000	1.38.80.5
+--- sc/source/ui/view/tabvwsh3.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/tabvwsh3.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -75,6 +75,8 @@
  #include "autofmt.hxx"
  #include "dwfunctr.hxx"
@@ -7276,7 +6422,7 @@
  					{
  						String	aText( ScResId(SCSTR_PASSWORD) );
  
-@@ -1027,89 +1034,84 @@
+@@ -1027,90 +1034,85 @@
  
  
  		case FID_PROTECT_TABLE:
@@ -7299,6 +6445,10 @@
 -					if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
 -						bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
 -                    if( bNewProtection == bOldProtection )
+-                    {
+-                        rReq.Ignore();
+-                        break;
+-                    }
 +            if( pReqArgs )
 +            {
 +                const SfxPoolItem* pItem;
@@ -7309,13 +6459,23 @@
 +                {
 +                    rReq.Ignore();
 +                    break;
-+                }
+                 }
 +            }
-+
+ 
+-                    if ( bOldProtection)
+-                    {
+-                        if (pDoc->GetTabPassword(nTab).getLength())
+-                        {
+-                            String  aText( ScResId(SCSTR_PASSWORD) );
 +            if (bOldProtection)
 +            {
 +                // Unprotect a protected sheet.
-+
+ 
+-                            pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
+-                            pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
+-                            pDlg->SetMinLen( 0 );
+-                            pDlg->SetHelpId( FID_PROTECT_TABLE );
+-                            pDlg->SetEditHelpId( HID_PASSWD_TABLE );
 +                ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
 +                if (pProtect && pProtect->isProtectedWithPass())
 +                {
@@ -7325,35 +6485,33 @@
 +                    pDlg->SetMinLen( 0 );
 +                    pDlg->SetHelpId( FID_PROTECT_TABLE );
 +                    pDlg->SetEditHelpId( HID_PASSWD_TABLE );
-+
+ 
+-                            if (pDlg->Execute() == RET_OK)
+-                                aPassword = pDlg->GetPassword();
+-                            else
+-                                bCancel = TRUE;
+-
+-                            delete pDlg;
+-                        }
 +                    if (pDlg->Execute() == RET_OK)
-                     {
--                        rReq.Ignore();
--                        break;
++                    {
 +                        String aPassword = pDlg->GetPassword();
 +                        Unprotect(nTab, aPassword);
                      }
-                 }
+-                    else
+-                    {
+-                        String aText( ScResId(SCSTR_PASSWORDOPT) );
++                }
 +                else
 +                    // this sheet is not password-protected.
 +                    Unprotect(nTab, String());
  
--                    if ( bOldProtection)
--                    {
--                        if (pDoc->GetTabPassword(nTab).getLength())
--                        {
--                            String  aText( ScResId(SCSTR_PASSWORD) );
--
--                            pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
--                            pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
--                            pDlg->SetMinLen( 0 );
--                            pDlg->SetHelpId( FID_PROTECT_TABLE );
--                            pDlg->SetEditHelpId( HID_PASSWD_TABLE );
--
--                            if (pDlg->Execute() == RET_OK)
--                                aPassword = pDlg->GetPassword();
--                            else
--                                bCancel = TRUE;
+-                        pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
+-                        pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
+-                        pDlg->SetMinLen( 0 );
+-                        pDlg->SetHelpId( FID_PROTECT_TABLE );
+-                        pDlg->SetEditHelpId( HID_PASSWD_TABLE );
+-                        pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
 +                if (!pReqArgs)
 +                {
 +                    rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
@@ -7364,40 +6522,27 @@
 +            {
 +                // Protect a current sheet.
  
--                            delete pDlg;
--                        }
--                    }
--                    else
--                    {
--                        String aText( ScResId(SCSTR_PASSWORDOPT) );
-+                auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
- 
--                        pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
--                        pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
--                        pDlg->SetMinLen( 0 );
--                        pDlg->SetHelpId( FID_PROTECT_TABLE );
--                        pDlg->SetEditHelpId( HID_PASSWD_TABLE );
--                        pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
--
 -                        if (pDlg->Execute() == RET_OK)
 -                            aPassword = pDlg->GetPassword();
 -                        else
 -                            bCancel = TRUE;
-+                ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
-+                if (pProtect)
-+                    pDlg->SetDialogData(*pProtect);
++                auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
  
 -                        delete pDlg;
 -                    }
-+                if (pDlg->Execute() == RET_OK)
-+                {
-+                    pScMod->InputEnterHandler();
++                ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
++                if (pProtect)
++                    pDlg->SetDialogData(*pProtect);
  
 -                if( !bCancel )
 -				{
 -                    if ( bOldProtection )
 -						Unprotect( nTab, aPassword );
 -					else
++                if (pDlg->Execute() == RET_OK)
++                {
++                    pScMod->InputEnterHandler();
++
 +                    ScTableProtection aNewProtect;
 +                    pDlg->WriteData(aNewProtect);
 +                    ProtectSheet(nTab, aNewProtect);
@@ -7418,28 +6563,210 @@
 -						rReq.Done();
 -					}
 -				}
--
--				TabChanged();
--				UpdateInputHandler(TRUE);	// damit sofort wieder eingegeben werden kann
--				SelectionChanged();
--			}
--			break;
 +            TabChanged();
 +            UpdateInputHandler(true);   // damit sofort wieder eingegeben werden kann
 +            SelectionChanged();
 +        }
 +        break;
  
-         case SID_OPT_LOCALE_CHANGED :
-             {   // locale changed, SYSTEM number formats changed => repaint cell contents
-Index: sc/source/ui/view/tabvwshh.cxx
+-				TabChanged();
+-				UpdateInputHandler(TRUE);	// damit sofort wieder eingegeben werden kann
+-				SelectionChanged();
+-			}
+-			break;
+-
+         case SID_OPT_LOCALE_CHANGED :
+             {   // locale changed, SYSTEM number formats changed => repaint cell contents
+                 PaintGrid();
+Index: source/ui/view/viewfun2.cxx
+===================================================================
+--- sc/source/ui/view/viewfun2.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/viewfun2.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -2150,7 +2150,7 @@
+ 			pUndoDoc->SetVisible( nTab, pDoc->IsVisible( nTab ) );
+ 
+ 			if ( pDoc->IsTabProtected( nTab ) )
+-				pUndoDoc->SetTabProtection( nTab, TRUE, pDoc->GetTabPassword( nTab ) );
++                pUndoDoc->SetTabProtection(nTab, pDoc->GetTabProtection(nTab));
+ 
+ 			//	Drawing-Layer muss sein Undo selbst in der Hand behalten !!!
+ 			//		pUndoDoc->TransferDrawPage(pDoc, nTab,nTab);
+@@ -2565,7 +2565,7 @@
+ 				}
+ 
+ 				if ( nErrVal > 0 && pDoc->IsTabProtected( TheTabs[i] ) )
+-					pDestDoc->SetTabProtection( nDestTab1, TRUE, pDoc->GetTabPassword( TheTabs[i] ) );
++                    pDestDoc->SetTabProtection(nDestTab1, pDoc->GetTabProtection(TheTabs[i]));
+ 
+ 				nDestTab1++;
+ 			}
+Index: source/ui/view/tabview3.cxx
+===================================================================
+--- sc/source/ui/view/tabview3.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/tabview3.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -79,6 +79,7 @@
+ #include "AccessibilityHints.hxx"
+ #include "rangeutl.hxx"
+ #include "client.hxx"
++#include "tabprotection.hxx"
+ 
+ #include <com/sun/star/chart2/data/HighlightedRange.hpp>
+ 
+@@ -942,6 +943,17 @@
+ 	ScDocument* pDoc = aViewData.GetDocument();
+ 	SCTAB nTab = aViewData.GetTabNo();
+ 
++    bool bSkipProtected = false, bSkipUnprotected = false;
++    ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
++    if ( pProtect && pProtect->isProtected() )
++    {
++        bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
++        bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
++    }
++
++    if ( bSkipProtected && bSkipUnprotected )
++        return;
++
+ 	SCsCOL nOldX;
+ 	SCsROW nOldY;
+ 	SCsCOL nCurX;
+@@ -961,7 +973,7 @@
+ 		nCurY = (nMovY != 0) ? nOldY+nMovY : (SCsROW) aViewData.GetOldCurY();
+ 	}
+ 
+-	BOOL bHidden;
++	BOOL bSkipCell = FALSE;
+ 	aViewData.ResetOldCursor();
+ 
+ 	if (nMovX != 0 && VALIDCOLROW(nCurX,nCurY))
+@@ -970,15 +982,20 @@
+ 		do
+ 		{
+ 			BYTE nColFlags = pDoc->GetColFlags( nCurX, nTab );
+-			bHidden = (nColFlags & CR_HIDDEN) || pDoc->IsHorOverlapped( nCurX, nCurY, nTab );
+-			if (bHidden)
++            bSkipCell = (nColFlags & CR_HIDDEN) || pDoc->IsHorOverlapped( nCurX, nCurY, nTab );
++            if (bSkipProtected && !bSkipCell)
++                bSkipCell = pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
++            if (bSkipUnprotected && !bSkipCell)
++                bSkipCell = !pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
++
++			if (bSkipCell)
+ 			{
+ 				if ( nCurX<=0 || nCurX>=MAXCOL )
+ 				{
+ 					if (bHFlip)
+ 					{
+ 						nCurX = nOldX;
+-						bHidden = FALSE;
++						bSkipCell = FALSE;
+ 					}
+ 					else
+ 					{
+@@ -991,7 +1008,8 @@
+ 					if (nMovX > 0) ++nCurX; else --nCurX;
+ 			}
+ 		}
+-		while (bHidden);
++		while (bSkipCell);
++
+ 		if (pDoc->IsVerOverlapped( nCurX, nCurY, nTab ))
+ 		{
+ 			aViewData.SetOldCursor( nCurX,nCurY );
+@@ -1006,15 +1024,20 @@
+ 		do
+ 		{
+ 			BYTE nRowFlags = pDoc->GetRowFlags( nCurY, nTab );
+-			bHidden = (nRowFlags & CR_HIDDEN) || pDoc->IsVerOverlapped( nCurX, nCurY, nTab );
+-			if (bHidden)
++            bSkipCell = (nRowFlags & CR_HIDDEN) || pDoc->IsVerOverlapped( nCurX, nCurY, nTab );
++            if (bSkipProtected && !bSkipCell)
++                bSkipCell = pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
++            if (bSkipUnprotected && !bSkipCell)
++                bSkipCell = !pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
++
++			if (bSkipCell)
+ 			{
+ 				if ( nCurY<=0 || nCurY>=MAXROW )
+ 				{
+ 					if (bVFlip)
+ 					{
+ 						nCurY = nOldY;
+-						bHidden = FALSE;
++						bSkipCell = FALSE;
+ 					}
+ 					else
+ 					{
+@@ -1027,7 +1050,8 @@
+ 					if (nMovY > 0) ++nCurY; else --nCurY;
+ 			}
+ 		}
+-		while (bHidden);
++		while (bSkipCell);
++
+ 		if (pDoc->IsHorOverlapped( nCurX, nCurY, nTab ))
+ 		{
+ 			aViewData.SetOldCursor( nCurX,nCurY );
+Index: source/ui/view/scextopt.cxx
+===================================================================
+--- sc/source/ui/view/scextopt.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/scextopt.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -42,9 +42,7 @@
+     maOleSize( ScAddress::INITIALIZE_INVALID ),
+     mfTabBarWidth( -1.0 ),
+     mnLinkCnt( 0 ),
+-    mnDisplTab( 0 ),
+-    mbWinProtected( false ),
+-    mbEncrypted( false )
++    mnDisplTab( 0 )
+ {
+ }
+ 
+Index: source/ui/view/viewfunc.cxx
+===================================================================
+--- sc/source/ui/view/viewfunc.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/viewfunc.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -2394,6 +2394,36 @@
+ 	ShowAllCursors();
+ }
+ 
++void ScViewFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
++{
++    if (nTab == TABLEID_DOC)
++        return;
++
++	ScMarkData& rMark = GetViewData()->GetMarkData();
++	ScDocShell* pDocSh = GetViewData()->GetDocShell();
++	ScDocument* pDoc = pDocSh->GetDocument();
++	ScDocFunc aFunc(*pDocSh);
++	bool bUndo(pDoc->IsUndoEnabled());
++
++    //	modifying several tables is handled here
++
++    if (bUndo)
++    {
++        String aUndo = ScGlobal::GetRscString( STR_UNDO_PROTECT_TAB );
++        pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
++    }
++
++    SCTAB nCount = pDocSh->GetDocument()->GetTableCount();
++    for ( SCTAB i=0; i<nCount; i++ )
++        if ( rMark.GetTableSelect(i) )
++            aFunc.ProtectSheet(i, rProtect);
++
++    if (bUndo)
++        pDocSh->GetUndoManager()->LeaveListAction();
++
++	UpdateLayerLocks();			//!	broadcast to all views
++}
++
+ void ScViewFunc::Protect( SCTAB nTab, const String& rPassword )
+ {
+ 	ScMarkData& rMark = GetViewData()->GetMarkData();
+Index: source/ui/view/tabvwshh.cxx
 ===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/tabvwshh.cxx,v
-retrieving revision 1.16
-retrieving revision 1.16.30.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.16 -r1.16.30.3
---- sc/source/ui/view/tabvwshh.cxx	11 Apr 2008 01:45:43 -0000	1.16
-+++ sc/source/ui/view/tabvwshh.cxx	21 May 2008 04:37:42 -0000	1.16.30.3
+--- sc/source/ui/view/tabvwshh.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/tabvwshh.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
 @@ -43,6 +43,7 @@
  #include <sfx2/request.hxx>
  #include <basic/sbxcore.hxx>
@@ -7448,108 +6775,462 @@
  
  #include "tabvwsh.hxx"
  #include "client.hxx"
-@@ -50,6 +51,10 @@
+@@ -50,7 +51,11 @@
  #include "docsh.hxx"
  #include "sc.hrc"
  #include "drwlayer.hxx"		// GetVisibleName
 +#include "retypepassdlg.hxx"
 +#include "tabprotection.hxx"
+ 
++#include <memory>
++
+ using namespace com::sun::star;
+ 
+ //------------------------------------------------------------------
+@@ -270,6 +275,22 @@
+ 	return pAccessibilityBroadcaster != NULL;
+ }
+ 
++bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
++{
++    using ::std::auto_ptr;
+ 
++    ScDocument* pDoc = GetViewData()->GetDocument();
+ 
++    auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
++    pDlg->SetData(*pDoc);
++    pDlg->SetDesiredHash(eDesiredHash);
++    if (pDlg->Execute() != RET_OK)
++        return false;
+ 
++    pDlg->WriteNewDataToDocument(*pDoc);
++    return true;
++}
++
++
++
++
+Index: source/ui/view/gridwin.cxx
+===================================================================
+--- sc/source/ui/view/gridwin.cxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/source/ui/view/gridwin.cxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -139,6 +139,7 @@
+ #include "drwlayer.hxx"
+ #include "attrib.hxx"
+ #include "cellsh.hxx"
++#include "tabprotection.hxx"
+ 
+ // #114409#
+ #include <vcl/salbtype.hxx>		// FRound
+@@ -2018,8 +2019,9 @@
+ 		Point aPos = rMEvt.GetPosPixel();
+         SCsCOL nPosX;
+         SCsROW nPosY;
++        SCTAB nTab = pViewData->GetTabNo();
+         pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
+-		ScDPObject*	pDPObj	= pDoc->GetDPAtCursor( nPosX, nPosY, pViewData->GetTabNo() );
++		ScDPObject*	pDPObj	= pDoc->GetDPAtCursor( nPosX, nPosY, nTab );
+ 		if ( pDPObj && pDPObj->GetSaveData()->GetDrillDown() )
+ 		{
+ 			ScAddress aCellPos( nPosX, nPosY, pViewData->GetTabNo() );
+@@ -2061,19 +2063,37 @@
+ 			return;
+ 		}
+ 
+-		//	edit cell contents
+-		pViewData->GetViewShell()->UpdateInputHandler();
+-		pScMod->SetInputMode( SC_INPUT_TABLE );
+-		if (pViewData->HasEditView(eWhich))
+-		{
+-			//	Text-Cursor gleich an die geklickte Stelle setzen
+-			EditView* pEditView = pViewData->GetEditView( eWhich );
+-			MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
+-			pEditView->MouseButtonDown( aEditEvt );
+-			pEditView->MouseButtonUp( aEditEvt );
+-		}
++        // Check for cell protection attribute.
++        ScTableProtection* pProtect = pDoc->GetTabProtection( nTab );
++        bool bEditAllowed = true;
++        if ( pProtect && pProtect->isProtected() )
++        {
++            bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
++            bool bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
++            bool bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
++
++            if ( bSkipProtected && bSkipUnprotected )
++                bEditAllowed = false;
++            else if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
++                bEditAllowed = false;
++        }
++
++        if ( bEditAllowed )
++        {
++            //  edit cell contents
++            pViewData->GetViewShell()->UpdateInputHandler();
++            pScMod->SetInputMode( SC_INPUT_TABLE );
++            if (pViewData->HasEditView(eWhich))
++            {
++                //  Text-Cursor gleich an die geklickte Stelle setzen
++                EditView* pEditView = pViewData->GetEditView( eWhich );
++                MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
++                pEditView->MouseButtonDown( aEditEvt );
++                pEditView->MouseButtonUp( aEditEvt );
++            }
++        }
+         return;
+-	}
++    }
+ 
+ 			//
+ 			//		Links in edit cells
+Index: inc/sc.hrc
+===================================================================
+--- sc/inc/sc.hrc	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/inc/sc.hrc	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -1626,8 +1626,13 @@
+ #define RID_SCDLG_CONFLICTS             (SC_DIALOGS_START + 145)
+ #define RID_SCDLG_SHAREDOCUMENT         (SC_DIALOGS_START + 146)
+ 
+-#define SC_DIALOGS_END          (SC_DIALOGS_START + 150)
++#define RID_SCDLG_TABPROTECTION         (SC_DIALOGS_START + 147)
++#define RID_SCDLG_DOCPROTECTION         (SC_DIALOGS_START + 148)
++#define RID_SCDLG_RETYPEPASS            (SC_DIALOGS_START + 149)
++#define RID_SCDLG_RETYPEPASS_INPUT      (SC_DIALOGS_START + 150)
+ 
++#define SC_DIALOGS_END          (SC_DIALOGS_START + 151)
++
+ #ifndef STD_MASKCOLOR
+ #define STD_MASKCOLOR Color { Red = 0xFF00; Green = 0x0000; Blue = 0xFF00; }
+ #endif
+Index: inc/table.hxx
+===================================================================
+--- sc/inc/table.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/inc/table.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -39,6 +39,8 @@
+ #include "sortparam.hxx"
+ #include "compressedarray.hxx"
+ 
++#include <memory>
++
+ namespace utl {
+ 	class SearchParam;
+ 	class TextSearch;
+@@ -65,6 +67,7 @@
+ class ScSortInfoArray;
+ class ScStyleSheet;
+ class ScTableLink;
++class ScTableProtection;
+ class ScUserListData;
+ class ScIndexMap;
+ struct RowInfo;
+@@ -102,8 +105,7 @@
+ 	SCROW			nRepeatStartY;
+ 	SCROW			nRepeatEndY;
+ 
+-	BOOL			bProtected;
+-	com::sun::star::uno::Sequence<sal_Int8>	aProtectPass;
++    ::std::auto_ptr<ScTableProtection> pTabProtection;
+ 
+ 	USHORT*			pColWidth;
+ 	ScSummableCompressedArray< SCROW, USHORT>*  pRowHeight;
+@@ -218,10 +220,11 @@
+ 	void			SetPageStyle( const String& rName );
+ 	void			PageStyleModified( const String& rNewName );
+ 
+-	BOOL			IsProtected() const						{ return bProtected; }
+-	const com::sun::star::uno::Sequence<sal_Int8>&	GetPassword() const						{ return aProtectPass; }
+-	void			SetProtection( BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd )
+-										{ bProtected = bProtect; aProtectPass = rPasswd; }
++    BOOL            IsProtected() const;
++    void            SetProtection(BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd);
++    void            SetProtection(bool bProtect, const String& aPassText);
++    void            SetProtection(const ScTableProtection* pProtect);
++    ScTableProtection* GetProtection();
+ 
+ 	Size			GetPageSize() const;
+ 	void			SetPageSize( const Size& rSize );
+Index: inc/warnpassword.hxx
+===================================================================
+--- sc/inc/warnpassword.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/inc/warnpassword.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -31,8 +31,8 @@
+ #ifndef SC_WARNPASSWORD_HXX
+ #define SC_WARNPASSWORD_HXX
+ 
++#if 0
+ 
+-
+ class SfxMedium; 
+ /** Static API helper functions. */
+ class ScWarnPassword 
+@@ -46,6 +46,7 @@
+     static bool        WarningOnPassword( SfxMedium& rMedium );
+ };
+ 
++#endif
+ 
+ #endif
+ 
+Index: inc/scextopt.hxx
+===================================================================
+--- sc/inc/scextopt.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/inc/scextopt.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -46,8 +46,6 @@
+     double              mfTabBarWidth;      /// Width of the tabbar, relative to frame window width (0.0 ... 1.0).
+     sal_uInt32          mnLinkCnt;          /// Recursive counter for loading external documents.
+     SCTAB               mnDisplTab;         /// Index of displayed sheet.
+-    bool                mbWinProtected;     /// true = Window properties are protected.
+-    bool                mbEncrypted;        /// true = Imported file was encrypted.
+ 
+     explicit            ScExtDocSettings();
+ };
+Index: inc/tabprotection.hxx
+===================================================================
+--- sc/inc/tabprotection.hxx	(.../tags/DEV300_m36/sc)	(revision 0)
++++ sc/inc/tabprotection.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -0,0 +1,178 @@
++/*************************************************************************
++ *
++ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
++ *
++ * Copyright 2008 by Sun Microsystems, Inc.
++ *
++ * OpenOffice.org - a multi-platform office productivity suite
++ *
++ * $RCSfile: tabprotection.hxx,v $
++ * $Revision: 1.1.4.6 $
++ *
++ * This file is part of OpenOffice.org.
++ *
++ * OpenOffice.org is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License version 3
++ * only, as published by the Free Software Foundation.
++ *
++ * OpenOffice.org is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU Lesser General Public License version 3 for more details
++ * (a copy is included in the LICENSE file that accompanied this code).
++ *
++ * You should have received a copy of the GNU Lesser General Public License
++ * version 3 along with OpenOffice.org.  If not, see
++ * <http://www.openoffice.org/license.html>
++ * for a copy of the LGPLv3 License.
++ *
++ ************************************************************************/
++
++#ifndef SC_TAB_PROTECTION_HXX
++#define SC_TAB_PROTECTION_HXX
 +
++#include "sal/types.h"
++#include <com/sun/star/uno/Sequence.hxx>
++
++#include "global.hxx"
++#include <vector>
 +#include <memory>
- 
- using namespace com::sun::star;
- 
-@@ -270,6 +275,22 @@
- 	return pAccessibilityBroadcaster != NULL;
- }
- 
-+bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
++
++class ScDocument;
++class ScTableProtectionImpl;
++
++enum ScPasswordHash
 +{
-+    using ::std::auto_ptr;
++    PASSHASH_OOO = 0,
++    PASSHASH_XL
++};
 +
-+    ScDocument* pDoc = GetViewData()->GetDocument();
++class ScPassHashHelper
++{
++public:
++    /** Check for the compatibility of all password hashes.  If there is at
++        least one hash that needs to be regenerated, it returns true.  If all
++        hash values are compatible with the specified hash type, then it
++        returns false. */
++    static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash);
 +
-+    auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
-+    pDlg->SetData(*pDoc);
-+    pDlg->SetDesiredHash(eDesiredHash);
-+    if (pDlg->Execute() != RET_OK)
-+        return false;
++private:
++    ScPassHashHelper();
++    ~ScPassHashHelper();
++};
 +
-+    pDlg->WriteNewDataToDocument(*pDoc);
-+    return true;
-+}
++// ============================================================================
 +
- 
- 
- 
-Index: sc/source/ui/view/viewfun2.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/viewfun2.cxx,v
-retrieving revision 1.41
-retrieving revision 1.38.28.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.41 -r1.38.28.3
---- sc/source/ui/view/viewfun2.cxx	14 May 2008 10:05:47 -0000	1.41
-+++ sc/source/ui/view/viewfun2.cxx	23 May 2008 01:50:28 -0000	1.38.28.3
-@@ -2150,7 +2150,7 @@
- 			pUndoDoc->SetVisible( nTab, pDoc->IsVisible( nTab ) );
- 
- 			if ( pDoc->IsTabProtected( nTab ) )
--				pUndoDoc->SetTabProtection( nTab, TRUE, pDoc->GetTabPassword( nTab ) );
-+                pUndoDoc->SetTabProtection(nTab, pDoc->GetTabProtection(nTab));
- 
- 			//	Drawing-Layer muss sein Undo selbst in der Hand behalten !!!
- 			//		pUndoDoc->TransferDrawPage(pDoc, nTab,nTab);
-@@ -2565,7 +2565,7 @@
- 				}
- 
- 				if ( nErrVal > 0 && pDoc->IsTabProtected( TheTabs[i] ) )
--					pDestDoc->SetTabProtection( nDestTab1, TRUE, pDoc->GetTabPassword( TheTabs[i] ) );
-+                    pDestDoc->SetTabProtection(nDestTab1, pDoc->GetTabProtection(TheTabs[i]));
- 
- 				nDestTab1++;
- 			}
-Index: sc/source/ui/view/viewfunc.cxx
-===================================================================
-RCS file: /cvs/sc/sc/source/ui/view/viewfunc.cxx,v
-retrieving revision 1.46
-retrieving revision 1.44.20.3
-diff -u -I $Revision.*$ -I $Author.*$ -r1.46 -r1.44.20.3
---- sc/source/ui/view/viewfunc.cxx	22 Jul 2008 14:45:24 -0000	1.46
-+++ sc/source/ui/view/viewfunc.cxx	9 Aug 2008 21:48:49 -0000	1.44.20.3
-@@ -2394,6 +2394,36 @@
- 	ShowAllCursors();
- }
- 
-+void ScViewFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
++class SAL_NO_VTABLE ScPassHashProtectable
 +{
-+    if (nTab == TABLEID_DOC)
-+        return;
++public:
++    virtual ~ScPassHashProtectable() = 0;
 +
-+	ScMarkData& rMark = GetViewData()->GetMarkData();
-+	ScDocShell* pDocSh = GetViewData()->GetDocShell();
-+	ScDocument* pDoc = pDocSh->GetDocument();
-+	ScDocFunc aFunc(*pDocSh);
-+	bool bUndo(pDoc->IsUndoEnabled());
++    virtual bool isProtected() const = 0;
++    virtual bool isProtectedWithPass() const = 0;
++    virtual void setProtected(bool bProtected) = 0;
 +
-+    //	modifying several tables is handled here
++    virtual bool isPasswordEmpty() const = 0;
++    virtual bool hasPasswordHash(ScPasswordHash eHash) const = 0;
++    virtual void setPassword(const String& aPassText) = 0;
++    virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const = 0;
++    virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 
++                                 ScPasswordHash eHash = PASSHASH_OOO) = 0;
++    virtual bool verifyPassword(const String& aPassText) const = 0;
++};
 +
-+    if (bUndo)
++// ============================================================================
++
++class ScDocProtection : public ScPassHashProtectable
++{
++public:
++    enum Option
 +    {
-+        String aUndo = ScGlobal::GetRscString( STR_UNDO_PROTECT_TAB );
-+        pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
-+    }
++        STRUCTURE = 0,
++        WINDOWS,
++        CONTENT,
++        NONE        // last item - used to resize the vector
++    };
 +
-+    SCTAB nCount = pDocSh->GetDocument()->GetTableCount();
-+    for ( SCTAB i=0; i<nCount; i++ )
-+        if ( rMark.GetTableSelect(i) )
-+            aFunc.ProtectSheet(i, rProtect);
++    explicit ScDocProtection();
++    explicit ScDocProtection(const ScDocProtection& r);
++    virtual ~ScDocProtection();
 +
-+    if (bUndo)
-+        pDocSh->GetUndoManager()->LeaveListAction();
++    virtual bool isProtected() const;
++    virtual bool isProtectedWithPass() const;
++    virtual void setProtected(bool bProtected);
++            
++    virtual bool isPasswordEmpty() const;
++    virtual bool hasPasswordHash(ScPasswordHash eHash) const;
++    virtual void setPassword(const String& aPassText);
++    virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
++    virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 
++                                 ScPasswordHash eHash = PASSHASH_OOO);
++    virtual bool verifyPassword(const String& aPassText) const;
++    
++    bool isOptionEnabled(Option eOption) const;
++    void setOption(Option eOption, bool bEnabled);
 +
-+	UpdateLayerLocks();			//!	broadcast to all views
-+}
++private:
++    ::std::auto_ptr<ScTableProtectionImpl> mpImpl;
++};
 +
- void ScViewFunc::Protect( SCTAB nTab, const String& rPassword )
- {
- 	ScMarkData& rMark = GetViewData()->GetMarkData();
++// ============================================================================
++
++/** sheet protection state container
++    
++    This class stores sheet's protection state: 1) whether the protection
++    is on, 2) password and/or password hash, and 3) any associated
++    protection options.  This class is also used as a protection state
++    container for the undo/redo stack, in which case the password, hash and
++    the options need to be preserved even when the protection flag is
++    off. */
++class ScTableProtection : public ScPassHashProtectable
++{
++public:
++    enum Option
++    {
++        AUTOFILTER = 0,
++        DELETE_COLUMNS,
++        DELETE_ROWS,
++        FORMAT_CELLS,
++        FORMAT_COLUMNS,
++        FORMAT_ROWS,
++        INSERT_COLUMNS,
++        INSERT_HYPERLINKS,
++        INSERT_ROWS,
++        OBJECTS,
++        PIVOT_TABLES,
++        SCENARIOS,
++        SELECT_LOCKED_CELLS,
++        SELECT_UNLOCKED_CELLS,
++        SHEET,
++        SORT,
++        NONE        // last item - used to resize the vector
++    };
++
++    explicit ScTableProtection();
++    explicit ScTableProtection(const ScTableProtection& r);
++    virtual ~ScTableProtection();
++
++    virtual bool isProtected() const;
++    virtual bool isProtectedWithPass() const;
++    virtual void setProtected(bool bProtected);
++            
++    virtual bool isPasswordEmpty() const;
++    virtual bool hasPasswordHash(ScPasswordHash eHash) const;
++    virtual void setPassword(const String& aPassText);
++    virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
++    virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 
++                                 ScPasswordHash eHash = PASSHASH_OOO);
++    virtual bool verifyPassword(const String& aPassText) const;
++    
++    SC_DLLPUBLIC bool isOptionEnabled(Option eOption) const;
++    SC_DLLPUBLIC void setOption(Option eOption, bool bEnabled);
++
++private:
++    ::std::auto_ptr<ScTableProtectionImpl> mpImpl;
++};
++
++
++#endif
+Index: inc/document.hxx
+===================================================================
+--- sc/inc/document.hxx	(.../tags/DEV300_m36/sc)	(revision 264730)
++++ sc/inc/document.hxx	(.../cws/scsheetprotection02/sc)	(revision 264730)
+@@ -89,6 +89,7 @@
+ class ScDetOpData;
+ class ScDetOpList;
+ class ScDocOptions;
++class ScDocProtection;
+ class ScDocumentPool;
+ class ScDrawLayer;
+ class ScExtDocOptions;
+@@ -106,6 +107,7 @@
+ class ScStyleSheet;
+ class ScStyleSheetPool;
+ class ScTable;
++class ScTableProtection;
+ class ScTokenArray;
+ class ScValidationData;
+ class ScValidationDataList;
+@@ -281,7 +283,7 @@
+ 
+ 	ScFieldEditEngine*	pCacheFieldEditEngine;
+ 
+-	com::sun::star::uno::Sequence<sal_Int8>	aProtectPass;
++    ::std::auto_ptr<ScDocProtection> pDocProtection;
+ 	String              aDocName;                       // opt: Dokumentname
+ 	ScRangePairListRef	xColNameRanges;
+ 	ScRangePairListRef	xRowNameRanges;
+@@ -343,7 +345,6 @@
+ 
+ 	ScLkUpdMode			eLinkMode;
+ 
+-	BOOL				bProtected;
+ 	BOOL				bAutoCalc;						// Automatisch Berechnen
+ 	BOOL				bAutoCalcShellDisabled;			// in/von/fuer ScDocShell disabled
+ 	// ob noch ForcedFormulas berechnet werden muessen,
+@@ -523,13 +524,16 @@
+ 	inline SCTAB	GetTableCount() const { return nMaxTableNumber; }
+ 	SvNumberFormatterIndexTable* GetFormatExchangeList() const { return pFormatExchangeList; }
+ 
+-	void			SetDocProtection( BOOL bProtect, const com::sun::star::uno::Sequence <sal_Int8>& aPass );
+-	void			SetTabProtection( SCTAB nTab, BOOL bProtect, const com::sun::star::uno::Sequence <sal_Int8>& aPass );
++    ScDocProtection* GetDocProtection() const;
++    void            SetDocProtection(bool bProtect, const String& aPassText);
++    void            SetDocProtection(const ScDocProtection* pProtect);
+ 	BOOL			IsDocProtected() const;
+ 	BOOL			IsDocEditable() const;
+ 	BOOL			IsTabProtected( SCTAB nTab ) const;
+-	const com::sun::star::uno::Sequence <sal_Int8>&	GetDocPassword() const;
+-	const com::sun::star::uno::Sequence <sal_Int8>&	GetTabPassword( SCTAB nTab ) const;
++    SC_DLLPUBLIC    ScTableProtection* GetTabProtection( SCTAB nTab ) const;
++    void            SetTabProtection(SCTAB nTab, bool bProtect, const String& aPassText);
++    void            SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect);
++    void            CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest);
+ 
+ 	void			LockTable(SCTAB nTab);
+ 	void			UnlockTable(SCTAB nTab);
+@@ -1455,6 +1459,8 @@
+ 
+ 
+ private:
++    ScDocument(const ScDocument& r); // disabled with no definition
++
+ //UNUSED2008-05  void				SetAutoFilterFlags();
+ 	void				FindMaxRotCol( SCTAB nTab, RowInfo* pRowInfo, SCSIZE nArrCount,
+ 										SCCOL nX1, SCCOL nX2 ) const;

Modified: trunk/patches/dev300/cws-scsheetprotection02-sfx2.diff
==============================================================================
--- trunk/patches/dev300/cws-scsheetprotection02-sfx2.diff	(original)
+++ trunk/patches/dev300/cws-scsheetprotection02-sfx2.diff	Tue Dec  2 22:39:33 2008
@@ -1,33 +1,15 @@
-? sfx2/sfx2.vpj
-Index: sfx2/inc/sfx2/passwd.hxx
+Index: source/dialog/filedlghelper.cxx
 ===================================================================
-RCS file: /cvs/framework/sfx2/inc/sfx2/passwd.hxx,v
-retrieving revision 1.3
-retrieving revision 1.2.272.2
-diff -u -b -I $Revision.*$ -I $Author.*$ -r1.3 -r1.2.272.2
---- sfx2/inc/sfx2/passwd.hxx	11 Apr 2008 11:37:34 -0000	1.3
-+++ sfx2/inc/sfx2/passwd.hxx	6 May 2008 23:39:22 -0000	1.2.272.2
-@@ -81,6 +81,7 @@
- 	String			GetConfirm() const { return maConfirmED.GetText(); }
- 
- 	void 			SetMinLen( USHORT Len );
-+    void            SetMaxLen( USHORT Len );
- 	void			SetEditHelpId( ULONG nId ) { maPasswordED.SetHelpId( nId ); }
- 	void			ShowExtras( USHORT nExtras ) { mnExtras = nExtras; }
- 
-Index: sfx2/source/dialog/filedlghelper.cxx
-===================================================================
-RCS file: /cvs/framework/sfx2/source/dialog/filedlghelper.cxx,v
-retrieving revision 1.142
-retrieving revision 1.140.2.3
-diff -u -b -I $Revision.*$ -I $Author.*$ -r1.142 -r1.140.2.3
---- sfx2/source/dialog/filedlghelper.cxx	15 Apr 2008 14:18:43 -0000	1.142
-+++ sfx2/source/dialog/filedlghelper.cxx	6 May 2008 23:39:30 -0000	1.140.2.3
-@@ -556,6 +556,11 @@
+--- sfx2/source/dialog/filedlghelper.cxx	(.../tags/DEV300_m36/sfx2)	(revision 264730)
++++ sfx2/source/dialog/filedlghelper.cxx	(.../cws/scsheetprotection02/sfx2)	(revision 264730)
+@@ -556,6 +556,14 @@
  {
  	sal_Bool operator() ( const SfxFilter* _pFilter )
  	{
-+        if (_pFilter && _pFilter->GetFilterName().EqualsAscii("MS Excel 97"))
++        if (!_pFilter)
++            return false;
++
++        if (_pFilter->GetFilterName().EqualsAscii("MS Excel 97"))
 +            // temporary hack to enable password protection for Excel 97.  Is
 +            // there a better way to enable password protection of a filter?
 +            return true;
@@ -35,7 +17,7 @@
          return  _pFilter && _pFilter->IsOwnFormat()
  			&&	_pFilter->UsesStorage()
  			&&	( SOFFICE_FILEFORMAT_60 <= _pFilter->GetVersion() );
-@@ -1538,6 +1543,9 @@
+@@ -1544,6 +1552,9 @@
  		if( !rpSet )
  			rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
  
@@ -45,7 +27,7 @@
  		// check, wether or not we have to display a password box
  		if ( mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
  		{
-@@ -1547,9 +1555,16 @@
+@@ -1553,9 +1564,16 @@
  				sal_Bool bPassWord = sal_False;
  				if ( ( aValue >>= bPassWord ) && bPassWord )
  				{
@@ -63,7 +45,7 @@
  					short nRet = aPasswordDlg.Execute();
  					if ( RET_OK == nRet )
  					{
-@@ -1616,9 +1631,6 @@
+@@ -1622,9 +1640,6 @@
  			catch( IllegalArgumentException ){}
  		}
  
@@ -73,14 +55,10 @@
  		// fill the rpURLList
  		implGetAndCacheFiles(mxFileDlg, rpURLList, getCurentSfxFilter());
  		if ( rpURLList == NULL )
-Index: sfx2/source/dialog/passwd.cxx
+Index: source/dialog/passwd.cxx
 ===================================================================
-RCS file: /cvs/framework/sfx2/source/dialog/passwd.cxx,v
-retrieving revision 1.9
-retrieving revision 1.8.72.2
-diff -u -b -I $Revision.*$ -I $Author.*$ -r1.9 -r1.8.72.2
---- sfx2/source/dialog/passwd.cxx	11 Apr 2008 12:45:35 -0000	1.9
-+++ sfx2/source/dialog/passwd.cxx	6 May 2008 23:39:25 -0000	1.8.72.2
+--- sfx2/source/dialog/passwd.cxx	(.../tags/DEV300_m36/sfx2)	(revision 264730)
++++ sfx2/source/dialog/passwd.cxx	(.../cws/scsheetprotection02/sfx2)	(revision 264730)
 @@ -112,6 +112,15 @@
  
  // -----------------------------------------------------------------------
@@ -97,9 +75,15 @@
  short SfxPasswordDialog::Execute()
  {
  	if ( mnExtras < SHOWEXTRAS_ALL )
-Index: sfx2/source/doc/objserv.cxx
+Index: inc/sfx2/passwd.hxx
 ===================================================================
-RCS file: /cvs/framework/sfx2/source/doc/objserv.cxx,v
-retrieving revision 1.105
-retrieving revision 1.104.20.3
-diff -u -b -I $Revision.*$ -I $Author.*$ -r1.105 -r1.104.20.3
+--- sfx2/inc/sfx2/passwd.hxx	(.../tags/DEV300_m36/sfx2)	(revision 264730)
++++ sfx2/inc/sfx2/passwd.hxx	(.../cws/scsheetprotection02/sfx2)	(revision 264730)
+@@ -81,6 +81,7 @@
+ 	String			GetConfirm() const { return maConfirmED.GetText(); }
+ 
+ 	void 			SetMinLen( USHORT Len );
++    void            SetMaxLen( USHORT Len );
+ 	void			SetEditHelpId( ULONG nId ) { maPasswordED.SetHelpId( nId ); }
+ 	void			ShowExtras( USHORT nExtras ) { mnExtras = nExtras; }
+ 

Modified: trunk/patches/dev300/cws-scsheetprotection02-svx.diff
==============================================================================
--- trunk/patches/dev300/cws-scsheetprotection02-svx.diff	(original)
+++ trunk/patches/dev300/cws-scsheetprotection02-svx.diff	Tue Dec  2 22:39:33 2008
@@ -1,46 +1,7 @@
-? svx/svx.vpj
-? svx/source/table/localize.sdf
-Index: svx/inc/mscodec.hxx
+Index: source/msfilter/mscodec.cxx
 ===================================================================
-RCS file: /cvs/graphics/svx/inc/mscodec.hxx,v
-retrieving revision 1.5
-retrieving revision 1.4.1248.5
-diff -u -b -I $Revision.*$ -I $Author.*$ -r1.5 -r1.4.1248.5
---- svx/inc/mscodec.hxx	10 Apr 2008 18:46:33 -0000	1.5
-+++ svx/inc/mscodec.hxx	22 May 2008 23:30:40 -0000	1.4.1248.5
-@@ -235,6 +235,14 @@
-      */
-     bool                InitCipher( sal_uInt32 nCounter );
- 
-+    /** Creates an MD5 digest of salt digest. */
-+    bool                CreateSaltDigest( 
-+                            const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] );
-+
-+    bool                Encode(
-+                            const void* pData, sal_Size nDatLen,
-+                            sal_uInt8* pBuffer, sal_Size nBufLen );
-+
-     /** Decodes a block of memory.
- 
-         @see rtl_cipher_decode()
-@@ -276,6 +284,9 @@
-     bool                Skip( sal_Size nDatLen );
- 
- private:
-+    void                GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] );
-+
-+private:
-                         SVX_DLLPRIVATE MSCodec_Std97( const MSCodec_Std97& );
-     SVX_DLLPRIVATE MSCodec_Std97&      operator=( const MSCodec_Std97& );
- 
-Index: svx/source/msfilter/mscodec.cxx
-===================================================================
-RCS file: /cvs/graphics/svx/source/msfilter/mscodec.cxx,v
-retrieving revision 1.7
-retrieving revision 1.6.104.5
-diff -u -b -I $Revision.*$ -I $Author.*$ -r1.7 -r1.6.104.5
---- svx/source/msfilter/mscodec.cxx	11 Apr 2008 02:05:35 -0000	1.7
-+++ svx/source/msfilter/mscodec.cxx	22 May 2008 23:01:29 -0000	1.6.104.5
+--- svx/source/msfilter/mscodec.cxx	(.../tags/DEV300_m36/svx)	(revision 264730)
++++ svx/source/msfilter/mscodec.cxx	(.../cws/scsheetprotection02/svx)	(revision 264730)
 @@ -37,6 +37,13 @@
  #include <string.h>
  #include <tools/solar.h>
@@ -158,7 +119,8 @@
      {
          sal_uInt8 pDigest[RTL_DIGEST_LENGTH_MD5];
 -        sal_uInt8 pBuffer[64];
--
++        GetDigestFromSalt(pSaltData, pDigest);
+ 
 -        // Decode SaltData into Buffer.
 -        rtl_cipher_decode (
 -            m_hCipher, pSaltData, 16, pBuffer, sizeof(pBuffer));
@@ -172,8 +134,7 @@
 -            m_hDigest, pBuffer, sizeof(pBuffer));
 -        rtl_digest_rawMD5 (
 -            m_hDigest, pDigest, sizeof(pDigest));
-+        GetDigestFromSalt(pSaltData, pDigest);
- 
+-
 +        sal_uInt8 pBuffer[16];
          // Decode original SaltDigest into Buffer.
          rtl_cipher_decode (
@@ -269,3 +230,32 @@
  // ============================================================================
  
  } // namespace svx
+Index: inc/mscodec.hxx
+===================================================================
+--- svx/inc/mscodec.hxx	(.../tags/DEV300_m36/svx)	(revision 264730)
++++ svx/inc/mscodec.hxx	(.../cws/scsheetprotection02/svx)	(revision 264730)
+@@ -235,6 +235,14 @@
+      */
+     bool                InitCipher( sal_uInt32 nCounter );
+ 
++    /** Creates an MD5 digest of salt digest. */
++    bool                CreateSaltDigest( 
++                            const sal_uInt8 nSaltData[16], sal_uInt8 nSaltDigest[16] );
++
++    bool                Encode(
++                            const void* pData, sal_Size nDatLen,
++                            sal_uInt8* pBuffer, sal_Size nBufLen );
++
+     /** Decodes a block of memory.
+ 
+         @see rtl_cipher_decode()
+@@ -276,6 +284,9 @@
+     bool                Skip( sal_Size nDatLen );
+ 
+ private:
++    void                GetDigestFromSalt( const sal_uInt8 pSaltData[16], sal_uInt8 pDigest[16] );
++
++private:
+                         SVX_DLLPRIVATE MSCodec_Std97( const MSCodec_Std97& );
+     SVX_DLLPRIVATE MSCodec_Std97&      operator=( const MSCodec_Std97& );
+ 

Modified: trunk/patches/vba/vba-workbook-worksheet-events.diff
==============================================================================
--- trunk/patches/vba/vba-workbook-worksheet-events.diff	(original)
+++ trunk/patches/vba/vba-workbook-worksheet-events.diff	Tue Dec  2 22:39:33 2008
@@ -1467,9 +1467,9 @@
 --- /home/feng/work/ooo-build/build/dev300-m14/sc/source/core/data/documen2.cxx	2008-06-16 21:30:17.000000000 +0800
 +++ sc/source/core/data/documen2.cxx	2008-06-16 14:35:26.000000000 +0800
 @@ -93,6 +93,7 @@
- #include "listenercalls.hxx"
  #include "recursionhelper.hxx"
  #include "lookupcache.hxx"
+ #include "tabprotection.hxx"
 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
  
  // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]