1 --- sc/inc/document.hxx.old 2009-04-06 16:41:48.000000000 +0000
2 +++ sc/inc/document.hxx 2009-04-06 16:41:49.000000000 +0000
3 @@ -90,6 +90,7 @@ class ScDBData;
7 +class ScDocProtection;
10 class ScExtDocOptions;
11 @@ -108,6 +109,7 @@ class ScRangeName;
13 class ScStyleSheetPool;
15 +class ScTableProtection;
17 class ScValidationData;
18 class ScValidationDataList;
19 @@ -283,7 +285,7 @@ private:
21 ScFieldEditEngine* pCacheFieldEditEngine;
23 - com::sun::star::uno::Sequence<sal_Int8> aProtectPass;
24 + ::std::auto_ptr<ScDocProtection> pDocProtection;
26 ::std::auto_ptr<ScExternalRefManager> pExternalRefMgr;
27 String aDocName; // opt: Dokumentname
28 @@ -347,7 +349,6 @@ private:
30 ScLkUpdMode eLinkMode;
33 BOOL bAutoCalc; // Automatisch Berechnen
34 BOOL bAutoCalcShellDisabled; // in/von/fuer ScDocShell disabled
35 // ob noch ForcedFormulas berechnet werden muessen,
36 @@ -529,13 +530,14 @@ public:
37 SC_DLLPUBLIC inline SCTAB GetTableCount() const { return nMaxTableNumber; }
38 SvNumberFormatterIndexTable* GetFormatExchangeList() const { return pFormatExchangeList; }
40 - SC_DLLPUBLIC void SetDocProtection( BOOL bProtect, const com::sun::star::uno::Sequence <sal_Int8>& aPass );
41 - SC_DLLPUBLIC void SetTabProtection( SCTAB nTab, BOOL bProtect, const com::sun::star::uno::Sequence <sal_Int8>& aPass );
42 + SC_DLLPUBLIC ScDocProtection* GetDocProtection() const;
43 + SC_DLLPUBLIC void SetDocProtection(const ScDocProtection* pProtect);
44 SC_DLLPUBLIC BOOL IsDocProtected() const;
45 BOOL IsDocEditable() const;
46 SC_DLLPUBLIC BOOL IsTabProtected( SCTAB nTab ) const;
47 - const com::sun::star::uno::Sequence <sal_Int8>& GetDocPassword() const;
48 - const com::sun::star::uno::Sequence <sal_Int8>& GetTabPassword( SCTAB nTab ) const;
49 + SC_DLLPUBLIC ScTableProtection* GetTabProtection( SCTAB nTab ) const;
50 + SC_DLLPUBLIC void SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect);
51 + void CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest);
53 void LockTable(SCTAB nTab);
54 void UnlockTable(SCTAB nTab);
55 @@ -1471,7 +1473,8 @@ public:
59 -//UNUSED2008-05 void SetAutoFilterFlags();
60 + ScDocument(const ScDocument& r); // disabled with no definition
62 void FindMaxRotCol( SCTAB nTab, RowInfo* pRowInfo, SCSIZE nArrCount,
63 SCCOL nX1, SCCOL nX2 ) const;
65 --- sc/inc/sc.hrc.old 2009-04-06 16:41:49.000000000 +0000
66 +++ sc/inc/sc.hrc 2009-04-06 16:41:49.000000000 +0000
67 @@ -1627,7 +1627,12 @@
68 #define RID_SCDLG_CONFLICTS (SC_DIALOGS_START + 145)
69 #define RID_SCDLG_SHAREDOCUMENT (SC_DIALOGS_START + 146)
71 -#define SC_DIALOGS_END (SC_DIALOGS_START + 150)
72 +#define RID_SCDLG_TABPROTECTION (SC_DIALOGS_START + 147)
73 +#define RID_SCDLG_DOCPROTECTION (SC_DIALOGS_START + 148)
74 +#define RID_SCDLG_RETYPEPASS (SC_DIALOGS_START + 149)
75 +#define RID_SCDLG_RETYPEPASS_INPUT (SC_DIALOGS_START + 150)
77 +#define SC_DIALOGS_END (SC_DIALOGS_START + 151)
80 #define STD_MASKCOLOR Color { Red = 0xFF00; Green = 0x0000; Blue = 0xFF00; }
81 --- sc/inc/scextopt.hxx.old 2009-04-02 10:45:43.000000000 +0000
82 +++ sc/inc/scextopt.hxx 2009-04-06 16:41:49.000000000 +0000
83 @@ -46,8 +46,6 @@ struct ScExtDocSettings
84 double mfTabBarWidth; /// Width of the tabbar, relative to frame window width (0.0 ... 1.0).
85 sal_uInt32 mnLinkCnt; /// Recursive counter for loading external documents.
86 SCTAB mnDisplTab; /// Index of displayed sheet.
87 - bool mbWinProtected; /// true = Window properties are protected.
88 - bool mbEncrypted; /// true = Imported file was encrypted.
90 explicit ScExtDocSettings();
92 --- sc/inc/table.hxx.old 2009-04-02 10:45:43.000000000 +0000
93 +++ sc/inc/table.hxx 2009-04-06 16:41:49.000000000 +0000
95 #include "sortparam.hxx"
96 #include "compressedarray.hxx"
103 @@ -65,6 +67,7 @@ class ScRangeList;
104 class ScSortInfoArray;
107 +class ScTableProtection;
108 class ScUserListData;
111 @@ -102,8 +105,7 @@ private:
116 - com::sun::star::uno::Sequence<sal_Int8> aProtectPass;
117 + ::std::auto_ptr<ScTableProtection> pTabProtection;
120 ScSummableCompressedArray< SCROW, USHORT>* pRowHeight;
121 @@ -218,10 +220,9 @@ public:
122 void SetPageStyle( const String& rName );
123 void PageStyleModified( const String& rNewName );
125 - BOOL IsProtected() const { return bProtected; }
126 - const com::sun::star::uno::Sequence<sal_Int8>& GetPassword() const { return aProtectPass; }
127 - void SetProtection( BOOL bProtect, const com::sun::star::uno::Sequence<sal_Int8>& rPasswd )
128 - { bProtected = bProtect; aProtectPass = rPasswd; }
129 + BOOL IsProtected() const;
130 + void SetProtection(const ScTableProtection* pProtect);
131 + ScTableProtection* GetProtection();
133 Size GetPageSize() const;
134 void SetPageSize( const Size& rSize );
135 --- sc/inc/tabprotection.hxx.old 1970-01-01 00:00:00.000000000 +0000
136 +++ sc/inc/tabprotection.hxx 2009-04-06 16:41:49.000000000 +0000
138 +/*************************************************************************
140 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
142 + * Copyright 2008 by Sun Microsystems, Inc.
144 + * OpenOffice.org - a multi-platform office productivity suite
146 + * $RCSfile: tabprotection.hxx,v $
147 + * $Revision: 1.1.4.6 $
149 + * This file is part of OpenOffice.org.
151 + * OpenOffice.org is free software: you can redistribute it and/or modify
152 + * it under the terms of the GNU Lesser General Public License version 3
153 + * only, as published by the Free Software Foundation.
155 + * OpenOffice.org is distributed in the hope that it will be useful,
156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
158 + * GNU Lesser General Public License version 3 for more details
159 + * (a copy is included in the LICENSE file that accompanied this code).
161 + * You should have received a copy of the GNU Lesser General Public License
162 + * version 3 along with OpenOffice.org. If not, see
163 + * <http://www.openoffice.org/license.html>
164 + * for a copy of the LGPLv3 License.
166 + ************************************************************************/
168 +#ifndef SC_TAB_PROTECTION_HXX
169 +#define SC_TAB_PROTECTION_HXX
171 +#include "sal/types.h"
172 +#include <com/sun/star/uno/Sequence.hxx>
174 +#include "global.hxx"
176 +#include <boost/shared_ptr.hpp>
178 +#define ENABLE_SHEET_PROTECTION 0
181 +class ScTableProtectionImpl;
189 +class ScPassHashHelper
192 + /** Check for the compatibility of all password hashes. If there is at
193 + least one hash that needs to be regenerated, it returns true. If all
194 + hash values are compatible with the specified hash type, then it
196 + static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash);
199 + ScPassHashHelper();
200 + ~ScPassHashHelper();
203 +// ============================================================================
205 +class SAL_NO_VTABLE ScPassHashProtectable
208 + virtual ~ScPassHashProtectable() = 0;
210 + virtual bool isProtected() const = 0;
211 + virtual bool isProtectedWithPass() const = 0;
212 + virtual void setProtected(bool bProtected) = 0;
214 + virtual bool isPasswordEmpty() const = 0;
215 + virtual bool hasPasswordHash(ScPasswordHash eHash) const = 0;
216 + virtual void setPassword(const String& aPassText) = 0;
217 + virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const = 0;
218 + virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
219 + ScPasswordHash eHash = PASSHASH_OOO) = 0;
220 + virtual bool verifyPassword(const String& aPassText) const = 0;
223 +// ============================================================================
225 +class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
233 + NONE // last item - used to resize the vector
236 + explicit ScDocProtection();
237 + explicit ScDocProtection(const ScDocProtection& r);
238 + virtual ~ScDocProtection();
240 + virtual bool isProtected() const;
241 + virtual bool isProtectedWithPass() const;
242 + virtual void setProtected(bool bProtected);
244 + virtual bool isPasswordEmpty() const;
245 + virtual bool hasPasswordHash(ScPasswordHash eHash) const;
246 + virtual void setPassword(const String& aPassText);
247 + virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
248 + virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
249 + ScPasswordHash eHash = PASSHASH_OOO);
250 + virtual bool verifyPassword(const String& aPassText) const;
252 + bool isOptionEnabled(Option eOption) const;
253 + void setOption(Option eOption, bool bEnabled);
256 + ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
259 +// ============================================================================
261 +/** sheet protection state container
263 + This class stores sheet's protection state: 1) whether the protection
264 + is on, 2) password and/or password hash, and 3) any associated
265 + protection options. This class is also used as a protection state
266 + container for the undo/redo stack, in which case the password, hash and
267 + the options need to be preserved even when the protection flag is
269 +class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
286 + SELECT_LOCKED_CELLS,
287 + SELECT_UNLOCKED_CELLS,
290 + NONE // last item - used to resize the vector
293 + explicit ScTableProtection();
294 + explicit ScTableProtection(const ScTableProtection& r);
295 + virtual ~ScTableProtection();
297 + virtual bool isProtected() const;
298 + virtual bool isProtectedWithPass() const;
299 + virtual void setProtected(bool bProtected);
301 + virtual bool isPasswordEmpty() const;
302 + virtual bool hasPasswordHash(ScPasswordHash eHash) const;
303 + virtual void setPassword(const String& aPassText);
304 + virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
305 + virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
306 + ScPasswordHash eHash = PASSHASH_OOO);
307 + virtual bool verifyPassword(const String& aPassText) const;
309 + bool isOptionEnabled(Option eOption) const;
310 + void setOption(Option eOption, bool bEnabled);
313 + ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
318 --- sc/source/core/data/documen2.cxx.old 2009-04-02 10:45:01.000000000 +0000
319 +++ sc/source/core/data/documen2.cxx 2009-04-06 16:41:49.000000000 +0000
321 #include "recursionhelper.hxx"
322 #include "lookupcache.hxx"
323 #include "externalrefmgr.hxx"
324 +#include "tabprotection.hxx"
326 // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
327 // dtor plus helpers are convenient.
328 @@ -151,6 +152,7 @@ ScDocument::ScDocument( ScDocumentMode e
329 pChangeViewSettings( NULL ),
330 pScriptTypeData( NULL ),
331 pCacheFieldEditEngine( NULL ),
332 + pDocProtection( NULL ),
333 pExternalRefMgr( NULL ),
334 pViewOptions( NULL ),
336 @@ -174,7 +176,6 @@ ScDocument::ScDocument( ScDocumentMode e
339 eLinkMode(LM_UNKNOWN),
340 - bProtected( FALSE ),
341 bAutoCalc( eMode == SCDOCMODE_DOCUMENT ),
342 bAutoCalcShellDisabled( FALSE ),
343 bForcedFormulaPending( FALSE ),
344 --- sc/source/core/data/documen3.cxx.old 2009-04-02 10:45:01.000000000 +0000
345 +++ sc/source/core/data/documen3.cxx 2009-04-06 16:41:49.000000000 +0000
347 #include "drwlayer.hxx"
348 #include "unoreflist.hxx"
349 #include "listenercalls.hxx"
350 +#include "svtools/PasswordHelper.hxx"
351 +#include "tabprotection.hxx"
355 @@ -1701,28 +1703,28 @@ void ScDocument::SnapVisArea( Rectangle&
356 ScDrawLayer::MirrorRectRTL( rRect ); // back to real rectangle
359 -void ScDocument::SetDocProtection( BOOL bProtect, const uno::Sequence<sal_Int8>& rPasswd )
360 +ScDocProtection* ScDocument::GetDocProtection() const
362 - bProtected = bProtect;
363 - aProtectPass = rPasswd;
364 + return pDocProtection.get();
367 -void ScDocument::SetTabProtection( SCTAB nTab, BOOL bProtect, const uno::Sequence<sal_Int8>& rPasswd )
368 +void ScDocument::SetDocProtection(const ScDocProtection* pProtect)
370 - if (VALIDTAB(nTab))
372 - pTab[nTab]->SetProtection( bProtect, rPasswd );
374 + pDocProtection.reset(new ScDocProtection(*pProtect));
376 + pDocProtection.reset(NULL);
379 BOOL ScDocument::IsDocProtected() const
382 + return pDocProtection.get() && pDocProtection->isProtected();
385 BOOL ScDocument::IsDocEditable() const
387 // import into read-only document is possible
388 - return !bProtected && ( bImportingXML || mbChangeReadOnlyEnabled || !pShell || !pShell->IsReadOnly() );
389 + return !IsDocProtected() && ( bImportingXML || mbChangeReadOnlyEnabled || !pShell || !pShell->IsReadOnly() );
392 BOOL ScDocument::IsTabProtected( SCTAB nTab ) const
393 @@ -1734,18 +1736,28 @@ BOOL ScDocument::IsTabProtected( SCTAB n
397 -const uno::Sequence<sal_Int8>& ScDocument::GetDocPassword() const
398 +ScTableProtection* ScDocument::GetTabProtection( SCTAB nTab ) const
400 - return aProtectPass;
401 + if (VALIDTAB(nTab) && pTab[nTab])
402 + return pTab[nTab]->GetProtection();
407 -const uno::Sequence<sal_Int8>& ScDocument::GetTabPassword( SCTAB nTab ) const
408 +void ScDocument::SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect)
410 - if (VALIDTAB(nTab) && pTab[nTab])
411 - return pTab[nTab]->GetPassword();
412 + if (!ValidTab(nTab))
415 - DBG_ERROR("Falsche Tabellennummer");
416 - return aProtectPass;
417 + pTab[nTab]->SetProtection(pProtect);
420 +void ScDocument::CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest)
422 + if (!ValidTab(nTabSrc) || !ValidTab(nTabDest))
425 + pTab[nTabDest]->SetProtection( pTab[nTabSrc]->GetProtection() );
428 const ScDocOptions& ScDocument::GetDocOptions() const
429 --- sc/source/core/data/document.cxx.old 2009-04-02 10:45:01.000000000 +0000
430 +++ sc/source/core/data/document.cxx 2009-04-06 16:41:49.000000000 +0000
432 #include "bcaslot.hxx"
433 #include "postit.hxx"
434 #include "externalrefmgr.hxx"
435 +#include "tabprotection.hxx"
437 namespace WritingMode2 = ::com::sun::star::text::WritingMode2;
439 @@ -3972,24 +3973,6 @@ BOOL ScDocument::RefreshAutoFilter( SCCO
443 -//UNUSED2008-05 void ScDocument::SetAutoFilterFlags()
445 -//UNUSED2008-05 USHORT nCount = pDBCollection->GetCount();
446 -//UNUSED2008-05 for (USHORT i=0; i<nCount; i++)
448 -//UNUSED2008-05 ScDBData* pData = (*pDBCollection)[i];
449 -//UNUSED2008-05 SCTAB nDBTab;
450 -//UNUSED2008-05 SCCOL nDBStartCol;
451 -//UNUSED2008-05 SCROW nDBStartRow;
452 -//UNUSED2008-05 SCCOL nDBEndCol;
453 -//UNUSED2008-05 SCROW nDBEndRow;
454 -//UNUSED2008-05 pData->GetArea( nDBTab, nDBStartCol,nDBStartRow, nDBEndCol,nDBEndRow );
455 -//UNUSED2008-05 pData->SetAutoFilter( HasAttrib( nDBStartCol,nDBStartRow,nDBTab,
456 -//UNUSED2008-05 nDBEndCol,nDBStartRow,nDBTab, HASATTR_AUTOFILTER ) );
461 BOOL ScDocument::IsHorOverlapped( SCCOL nCol, SCROW nRow, SCTAB nTab ) const
463 const ScMergeFlagAttr* pAttr = (const ScMergeFlagAttr*)
464 --- sc/source/core/data/makefile.mk.old 2009-04-02 10:45:01.000000000 +0000
465 +++ sc/source/core/data/makefile.mk 2009-04-06 16:41:49.000000000 +0000
466 @@ -108,6 +108,7 @@ SLOFILES = \
470 + $(SLO)$/tabprotection.obj \
471 $(SLO)$/userdat.obj \
472 $(SLO)$/validat.obj \
474 @@ -128,6 +129,7 @@ EXCEPTIONSFILES= \
475 $(SLO)$/global2.obj \
478 + $(SLO)$/tabprotection.obj \
480 $(SLO)$/documen3.obj \
481 $(SLO)$/documen5.obj \
482 --- sc/source/core/data/table1.cxx.old 2009-04-02 10:45:01.000000000 +0000
483 +++ sc/source/core/data/table1.cxx 2009-04-06 16:41:49.000000000 +0000
485 #include "progress.hxx"
486 #include "hints.hxx" // fuer Paint-Broadcast
487 #include "prnsave.hxx"
488 +#include "tabprotection.hxx"
490 // STATIC DATA -----------------------------------------------------------
492 @@ -132,7 +133,7 @@ ScTable::ScTable( ScDocument* pDoc, SCTA
493 bPageSizeValid( FALSE ),
494 nRepeatStartX( SCCOL_REPEAT_NONE ),
495 nRepeatStartY( SCROW_REPEAT_NONE ),
496 - bProtected( FALSE ),
497 + pTabProtection( NULL ),
501 --- sc/source/core/data/table2.cxx.old 2009-04-02 10:45:01.000000000 +0000
502 +++ sc/source/core/data/table2.cxx 2009-04-06 16:41:49.000000000 +0000
503 @@ -292,7 +292,7 @@ void ScTable::DeleteArea(SCCOL nCol1, SC
504 // Zellschutz auf geschuetzter Tabelle nicht setzen
507 - if ( bProtected && (nDelFlag & IDF_ATTRIB) )
508 + if ( IsProtected() && (nDelFlag & IDF_ATTRIB) )
510 ScPatternAttr aPattern(pDocument->GetPool());
511 aPattern.GetItemSet().Put( ScProtectionAttr( FALSE ) );
512 @@ -318,7 +318,7 @@ void ScTable::DeleteSelection( USHORT nD
513 // Zellschutz auf geschuetzter Tabelle nicht setzen
516 - if ( bProtected && (nDelFlag & IDF_ATTRIB) )
517 + if ( IsProtected() && (nDelFlag & IDF_ATTRIB) )
519 ScDocumentPool* pPool = pDocument->GetPool();
520 SfxItemSet aSet( *pPool, ATTR_PATTERN_START, ATTR_PATTERN_END );
521 @@ -361,7 +361,7 @@ void ScTable::CopyToClip(SCCOL nCol1, SC
523 // ggf. Formeln durch Werte ersetzen
526 + if ( IsProtected() )
527 for (i = nCol1; i <= nCol2; i++)
528 pTable->aCol[i].RemoveProtected(nRow1, nRow2);
530 @@ -406,7 +406,7 @@ void ScTable::CopyFromClip(SCCOL nCol1,
531 // Zellschutz auf geschuetzter Tabelle nicht setzen
534 - if ( bProtected && (nInsFlag & IDF_ATTRIB) )
535 + if ( IsProtected() && (nInsFlag & IDF_ATTRIB) )
537 ScPatternAttr aPattern(pDocument->GetPool());
538 aPattern.GetItemSet().Put( ScProtectionAttr( FALSE ) );
539 @@ -1451,7 +1451,7 @@ BOOL ScTable::IsBlockEditable( SCCOL nCo
540 BOOL bIsEditable = TRUE;
543 - else if ( bProtected && !pDocument->IsScenario(nTab) )
544 + else if ( IsProtected() && !pDocument->IsScenario(nTab) )
546 if((bIsEditable = !HasAttrib( nCol1, nRow1, nCol2, nRow2, HASATTR_PROTECTED )) != FALSE)
548 @@ -1518,7 +1518,7 @@ BOOL ScTable::IsSelectionEditable( const
549 BOOL bIsEditable = TRUE;
552 - else if ( bProtected && !pDocument->IsScenario(nTab))
553 + else if ( IsProtected() && !pDocument->IsScenario(nTab) )
555 if((bIsEditable = !HasAttribSelection( rMark, HASATTR_PROTECTED )) != FALSE)
557 --- sc/source/core/data/table5.cxx.old 2009-04-02 10:45:01.000000000 +0000
558 +++ sc/source/core/data/table5.cxx 2009-04-06 16:41:49.000000000 +0000
560 #include "stlpool.hxx"
561 #include "stlsheet.hxx"
562 #include "brdcst.hxx"
563 +#include "tabprotection.hxx"
564 #include "globstr.hrc"
566 +using ::com::sun::star::uno::Sequence;
568 // STATIC DATA -----------------------------------------------------------
570 #define GET_SCALEVALUE(set,id) ((const SfxUInt16Item&)(set.Get( id ))).GetValue()
571 @@ -273,6 +276,24 @@ void ScTable::SetPageSize( const Size& r
572 bPageSizeValid = FALSE;
575 +BOOL ScTable::IsProtected() const
577 + return pTabProtection.get() && pTabProtection->isProtected();
580 +void ScTable::SetProtection(const ScTableProtection* pProtect)
583 + pTabProtection.reset(new ScTableProtection(*pProtect));
585 + pTabProtection.reset(NULL);
588 +ScTableProtection* ScTable::GetProtection()
590 + return pTabProtection.get();
593 Size ScTable::GetPageSize() const
595 if ( bPageSizeValid )
596 --- sc/source/core/data/tabprotection.cxx.old 1970-01-01 00:00:00.000000000 +0000
597 +++ sc/source/core/data/tabprotection.cxx 2009-04-06 16:41:49.000000000 +0000
599 +/*************************************************************************
601 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
603 + * Copyright 2008 by Sun Microsystems, Inc.
605 + * OpenOffice.org - a multi-platform office productivity suite
607 + * $RCSfile: tabprotection.cxx,v $
608 + * $Revision: 1.1.4.7 $
610 + * This file is part of OpenOffice.org.
612 + * OpenOffice.org is free software: you can redistribute it and/or modify
613 + * it under the terms of the GNU Lesser General Public License version 3
614 + * only, as published by the Free Software Foundation.
616 + * OpenOffice.org is distributed in the hope that it will be useful,
617 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
618 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
619 + * GNU Lesser General Public License version 3 for more details
620 + * (a copy is included in the LICENSE file that accompanied this code).
622 + * You should have received a copy of the GNU Lesser General Public License
623 + * version 3 along with OpenOffice.org. If not, see
624 + * <http://www.openoffice.org/license.html>
625 + * for a copy of the LGPLv3 License.
627 + ************************************************************************/
629 +// MARKER(update_precomp.py): autogen include statement, do not remove
630 +#include "precompiled_sc.hxx"
632 +// INCLUDE ---------------------------------------------------------------
634 +#include "tabprotection.hxx"
635 +#include "tools/debug.hxx"
636 +#include "svtools/PasswordHelper.hxx"
637 +#include "document.hxx"
639 +#define DEBUG_TAB_PROTECTION 0
641 +using namespace ::com::sun::star;
642 +using ::com::sun::star::uno::Sequence;
643 +using ::rtl::OUString;
645 +// ============================================================================
647 +bool ScPassHashHelper::needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash)
649 + if (rDoc.IsDocProtected())
651 + const ScDocProtection* p = rDoc.GetDocProtection();
652 + if (!p->isPasswordEmpty() && !p->hasPasswordHash(eHash))
656 + SCTAB nTabCount = rDoc.GetTableCount();
657 + for (SCTAB i = 0; i < nTabCount; ++i)
659 + const ScTableProtection* p = rDoc.GetTabProtection(i);
660 + if (!p || !p->isProtected())
661 + // Sheet not protected. Skip it.
664 + if (!p->isPasswordEmpty() && !p->hasPasswordHash(eHash))
671 +// ============================================================================
673 +ScPassHashProtectable::~ScPassHashProtectable()
677 +// ============================================================================
679 +static sal_uInt16 lcl_getXLHashFromChar(const sal_Char* szPassword)
681 + sal_uInt16 cchPassword = strlen(szPassword);
682 + sal_uInt16 wPasswordHash = 0;
684 + return wPasswordHash;
686 + const char* pch = &szPassword[cchPassword];
687 + while (pch-- != szPassword)
689 + wPasswordHash = ((wPasswordHash >> 14) & 0x01) |
690 + ((wPasswordHash << 1) & 0x7fff);
691 + wPasswordHash ^= *pch;
694 + wPasswordHash = ((wPasswordHash >> 14) & 0x01) |
695 + ((wPasswordHash << 1) & 0x7fff);
697 + wPasswordHash ^= (0x8000 | ('N' << 8) | 'K');
698 + wPasswordHash ^= cchPassword;
700 + return wPasswordHash;
703 +static Sequence<sal_Int8> lcl_getXLHash(const String& aPassText)
705 + const sal_Char* szBuf = OUStringToOString(OUString(aPassText), RTL_TEXTENCODING_UTF8).getStr();
706 + sal_uInt16 nHash = lcl_getXLHashFromChar(szBuf);
707 + Sequence<sal_Int8> aHash(2);
708 + aHash[0] = (nHash >> 8) & 0xFF;
709 + aHash[1] = nHash & 0xFF;
713 +class ScTableProtectionImpl
716 + static ::com::sun::star::uno::Sequence<sal_Int8> hashPassword(const String& aPassText, ScPasswordHash eHash = PASSHASH_OOO);
718 + explicit ScTableProtectionImpl(SCSIZE nOptSize);
719 + explicit ScTableProtectionImpl(const ScTableProtectionImpl& r);
721 + bool isProtected() const;
722 + bool isProtectedWithPass() const;
723 + void setProtected(bool bProtected);
725 + bool isPasswordEmpty() const;
726 + bool hasPasswordHash(ScPasswordHash eHash) const;
727 + void setPassword(const String& aPassText);
728 + ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
729 + void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash = PASSHASH_OOO);
730 + bool verifyPassword(const String& aPassText) const;
732 + bool isOptionEnabled(SCSIZE nOptId) const;
733 + void setOption(SCSIZE nOptId, bool bEnabled);
737 + ::com::sun::star::uno::Sequence<sal_Int8> maPassHash;
738 + ::std::vector<bool> maOptions;
741 + ScPasswordHash meHash;
744 +Sequence<sal_Int8> ScTableProtectionImpl::hashPassword(const String& aPassText, ScPasswordHash eHash)
746 + Sequence<sal_Int8> aHash;
750 + aHash = lcl_getXLHash(aPassText);
754 + SvPasswordHelper::GetHashPassword(aHash, aPassText);
760 +ScTableProtectionImpl::ScTableProtectionImpl(SCSIZE nOptSize) :
761 + maOptions(nOptSize),
763 + mbProtected(false),
764 + meHash(PASSHASH_OOO)
768 +ScTableProtectionImpl::ScTableProtectionImpl(const ScTableProtectionImpl& r) :
769 + maPassText(r.maPassText),
770 + maPassHash(r.maPassHash),
771 + maOptions(r.maOptions),
772 + mbEmptyPass(r.mbEmptyPass),
773 + mbProtected(r.mbProtected),
778 +bool ScTableProtectionImpl::isProtected() const
780 + return mbProtected;
783 +bool ScTableProtectionImpl::isProtectedWithPass() const
788 + return maPassText.Len() || maPassHash.getLength();
791 +void ScTableProtectionImpl::setProtected(bool bProtected)
793 + mbProtected = bProtected;
794 + // We need to keep the old password even when the protection is off. So,
795 + // don't erase the password data here.
798 +void ScTableProtectionImpl::setPassword(const String& aPassText)
800 + // We can't hash it here because we don't know whether this document will
801 + // get saved to Excel or ODF, depending on which we will need to use a
802 + // different hashing algorithm. One alternative is to hash it using all
803 + // hash algorithms that we support, and store them all.
805 + maPassText = aPassText;
806 + mbEmptyPass = aPassText.Len() == 0;
809 + maPassHash = Sequence<sal_Int8>();
813 +bool ScTableProtectionImpl::isPasswordEmpty() const
815 + return mbEmptyPass;
818 +bool ScTableProtectionImpl::hasPasswordHash(ScPasswordHash eHash) const
823 + if (maPassText.Len())
826 + if (meHash == eHash)
832 +Sequence<sal_Int8> ScTableProtectionImpl::getPasswordHash(ScPasswordHash eHash) const
835 + // Flaged as empty.
836 + return Sequence<sal_Int8>();
838 + if (maPassText.Len())
839 + // Cleartext password exists. Hash it.
840 + return hashPassword(maPassText, eHash);
842 + if (meHash == eHash)
843 + // Stored hash exists.
846 + // Failed to find a matching hash.
847 + return Sequence<sal_Int8>();
850 +void ScTableProtectionImpl::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
852 + sal_Int32 nLen = aPassword.getLength();
853 + mbEmptyPass = nLen <= 0 ? true : false;
855 + maPassHash = aPassword;
857 +#if DEBUG_TAB_PROTECTION
858 + for (sal_Int32 i = 0; i < nLen; ++i)
859 + printf("%2.2X ", static_cast<sal_uInt8>(aPassword[i]));
864 +bool ScTableProtectionImpl::verifyPassword(const String& aPassText) const
866 +#if DEBUG_TAB_PROTECTION
867 + fprintf(stdout, "ScTableProtectionImpl::verifyPassword: input = '%s'\n",
868 + OUStringToOString(rtl::OUString(aPassText), RTL_TEXTENCODING_UTF8).getStr());
872 + return aPassText.Len() == 0;
874 + if (maPassText.Len())
875 + // Clear text password exists, and this one takes precedence.
876 + return aPassText.Equals(maPassText);
878 + Sequence<sal_Int8> aHash = hashPassword(aPassText, meHash);
880 +#if DEBUG_TAB_PROTECTION
881 + fprintf(stdout, "ScTableProtectionImpl::verifyPassword: hash = ");
882 + for (sal_Int32 i = 0; i < aHash.getLength(); ++i)
883 + printf("%2.2X ", static_cast<sal_uInt8>(aHash[i]));
887 + return aHash == maPassHash;
890 +bool ScTableProtectionImpl::isOptionEnabled(SCSIZE nOptId) const
892 + if ( maOptions.size() <= static_cast<size_t>(nOptId) )
894 + DBG_ERROR("ScTableProtectionImpl::isOptionEnabled: wrong size");
898 + return maOptions[nOptId];
901 +void ScTableProtectionImpl::setOption(SCSIZE nOptId, bool bEnabled)
903 + if ( maOptions.size() <= static_cast<size_t>(nOptId) )
905 + DBG_ERROR("ScTableProtectionImpl::setOption: wrong size");
909 + maOptions[nOptId] = bEnabled;
912 +// ============================================================================
914 +ScDocProtection::ScDocProtection() :
915 + mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScDocProtection::NONE)))
919 +ScDocProtection::ScDocProtection(const ScDocProtection& r) :
920 + ScPassHashProtectable(),
921 + mpImpl(new ScTableProtectionImpl(*r.mpImpl))
925 +ScDocProtection::~ScDocProtection()
929 +bool ScDocProtection::isProtected() const
931 + return mpImpl->isProtected();
934 +bool ScDocProtection::isProtectedWithPass() const
936 + return mpImpl->isProtectedWithPass();
939 +void ScDocProtection::setProtected(bool bProtected)
941 + mpImpl->setProtected(bProtected);
943 + // Currently Calc doesn't support document protection options. So, let's
944 + // assume that when the document is protected, its structure is protected.
945 + // We need to do this for Excel export.
946 + mpImpl->setOption(ScDocProtection::STRUCTURE, bProtected);
949 +bool ScDocProtection::isPasswordEmpty() const
951 + return mpImpl->isPasswordEmpty();
954 +bool ScDocProtection::hasPasswordHash(ScPasswordHash eHash) const
956 + return mpImpl->hasPasswordHash(eHash);
959 +void ScDocProtection::setPassword(const String& aPassText)
961 + mpImpl->setPassword(aPassText);
964 +uno::Sequence<sal_Int8> ScDocProtection::getPasswordHash(ScPasswordHash eHash) const
966 + return mpImpl->getPasswordHash(eHash);
969 +void ScDocProtection::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
971 + mpImpl->setPasswordHash(aPassword, eHash);
974 +bool ScDocProtection::verifyPassword(const String& aPassText) const
976 + return mpImpl->verifyPassword(aPassText);
979 +bool ScDocProtection::isOptionEnabled(Option eOption) const
981 + return mpImpl->isOptionEnabled(eOption);
984 +void ScDocProtection::setOption(Option eOption, bool bEnabled)
986 + mpImpl->setOption(eOption, bEnabled);
989 +// ============================================================================
991 +ScTableProtection::ScTableProtection() :
992 + mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScTableProtection::NONE)))
994 + // Set default values for the options.
995 + mpImpl->setOption(SELECT_LOCKED_CELLS, true);
996 + mpImpl->setOption(SELECT_UNLOCKED_CELLS, true);
999 +ScTableProtection::ScTableProtection(const ScTableProtection& r) :
1000 + ScPassHashProtectable(),
1001 + mpImpl(new ScTableProtectionImpl(*r.mpImpl))
1005 +ScTableProtection::~ScTableProtection()
1009 +bool ScTableProtection::isProtected() const
1011 + return mpImpl->isProtected();
1014 +bool ScTableProtection::isProtectedWithPass() const
1016 + return mpImpl->isProtectedWithPass();
1019 +void ScTableProtection::setProtected(bool bProtected)
1021 + mpImpl->setProtected(bProtected);
1024 +bool ScTableProtection::isPasswordEmpty() const
1026 + return mpImpl->isPasswordEmpty();
1029 +bool ScTableProtection::hasPasswordHash(ScPasswordHash eHash) const
1031 + return mpImpl->hasPasswordHash(eHash);
1034 +void ScTableProtection::setPassword(const String& aPassText)
1036 + mpImpl->setPassword(aPassText);
1039 +Sequence<sal_Int8> ScTableProtection::getPasswordHash(ScPasswordHash eHash) const
1041 + return mpImpl->getPasswordHash(eHash);
1044 +void ScTableProtection::setPasswordHash(const uno::Sequence<sal_Int8>& aPassword, ScPasswordHash eHash)
1046 + mpImpl->setPasswordHash(aPassword, eHash);
1049 +bool ScTableProtection::verifyPassword(const String& aPassText) const
1051 + return mpImpl->verifyPassword(aPassText);
1054 +bool ScTableProtection::isOptionEnabled(Option eOption) const
1056 + return mpImpl->isOptionEnabled(eOption);
1059 +void ScTableProtection::setOption(Option eOption, bool bEnabled)
1061 + mpImpl->setOption(eOption, bEnabled);
1064 --- sc/source/filter/excel/excdoc.cxx.old 2009-04-02 10:44:55.000000000 +0000
1065 +++ sc/source/filter/excel/excdoc.cxx 2009-04-06 16:41:49.000000000 +0000
1067 #include "convuno.hxx"
1068 #include "patattr.hxx"
1069 #include "docoptio.hxx"
1070 +#include "tabprotection.hxx"
1072 #include "excdoc.hxx"
1073 #include "namebuff.hxx"
1075 -#include "xcl97dum.hxx"
1076 #include "xcl97rec.hxx"
1077 #include "xcl97esc.hxx"
1078 #include "xetable.hxx"
1079 @@ -118,7 +118,7 @@ static void lcl_AddCalcPr( XclExpRecordL
1080 aRecList.AppendNewRecord( new XclRefmode( rDoc ) );
1081 aRecList.AppendNewRecord( new XclIteration( rDoc ) );
1082 aRecList.AppendNewRecord( new XclDelta( rDoc ) );
1083 - aRecList.AppendNewRecord( new ExcDummy8_02 );
1084 + aRecList.AppendNewRecord( new XclExpBoolRecord(0x005F, true) ); // SAVERECALC
1085 aRecList.AppendNewRecord( new XclExpXmlEndSingleElementRecord() ); // XML_calcPr
1088 @@ -209,7 +209,16 @@ void ExcTable::FillAsHeader( ExcBoundshe
1089 Add( new ExcDummy_00 );
1092 - Add( new ExcDummy8_00a );
1093 + if ( IsDocumentEncrypted() )
1094 + Add( new XclExpFilePass(GetRoot()) );
1096 + Add( new XclExpInterfaceHdr );
1097 + Add( new XclExpMMS );
1098 + Add( new XclExpInterfaceEnd );
1099 + Add( new XclExpWriteAccess );
1100 + Add( new XclExpCodePage );
1101 + Add( new XclExpDSF );
1102 + Add( new XclExpExcel9File );
1103 rR.pTabId = new XclExpChTrTabId( Max( nExcTabCount, nCodenames ) );
1105 if( HasVbaStorage() )
1106 @@ -219,7 +228,8 @@ void ExcTable::FillAsHeader( ExcBoundshe
1107 if( rCodeName.Len() )
1108 Add( new XclCodename( rCodeName ) );
1110 - Add( new ExcDummy8_00b );
1112 + Add( new XclExpFnGroupCount );
1115 // erst Namen- und Tabellen-Eintraege aufbauen
1116 @@ -239,12 +249,22 @@ void ExcTable::FillAsHeader( ExcBoundshe
1117 aRecList.AppendRecord( CreateRecord( EXC_ID_NAME ) );
1120 - aRecList.AppendNewRecord( new XclExpWindowProtection( GetExtDocOptions().GetDocSettings().mbWinProtected ) );
1121 - aRecList.AppendNewRecord( new XclExpDocProtection( rDoc.IsDocProtected() ) );
1122 - aRecList.AppendNewRecord( new XclExpBoolRecord( EXC_ID_PASSWORD, false ) );
1123 + // document protection options
1124 + const ScDocProtection* pProtect = GetDoc().GetDocProtection();
1125 + if (pProtect && pProtect->isProtected())
1127 + Add( new XclExpWindowProtection(pProtect->isOptionEnabled(ScDocProtection::WINDOWS)) );
1128 + Add( new XclExpProtection(pProtect->isOptionEnabled(ScDocProtection::STRUCTURE)) );
1129 +#if ENABLE_SHEET_PROTECTION
1130 + Add( new XclExpPassHash(pProtect->getPasswordHash(PASSHASH_XL)) );
1134 if( GetBiff() == EXC_BIFF8 )
1135 - Add( new ExcDummy8_040 );
1137 + Add( new XclExpProt4Rev );
1138 + Add( new XclExpProt4RevPass );
1141 // document protection options
1142 if( GetOutput() == EXC_OUTPUT_BINARY )
1143 @@ -255,6 +275,12 @@ void ExcTable::FillAsHeader( ExcBoundshe
1145 Add( new XclExpXmlStartSingleElementRecord( XML_workbookPr ) );
1147 + if ( GetBiff() == EXC_BIFF8 )
1149 + Add( new XclExpBoolRecord(0x0040, false) ); // BACKUP
1150 + Add( new XclExpBoolRecord(0x008D, false) ); // HIDEOBJ
1153 if( GetBiff() <= EXC_BIFF5 )
1155 Add( new ExcDummy_040 );
1156 @@ -263,9 +289,12 @@ void ExcTable::FillAsHeader( ExcBoundshe
1161 Add( new Exc1904( rDoc ) );
1162 Add( new XclExpBoolRecord( 0x000E, !rDoc.GetDocOptions().IsCalcAsShown() ) );
1163 - Add( new ExcDummy8_041 );
1164 + Add( new XclExpBoolRecord(0x01B7, false) ); // REFRESHALL
1165 + Add( new XclExpBoolRecord(0x00DA, false) ); // BOOKBOOL
1167 // OOXTODO: The following /workbook/workbookPr attributes are mapped
1168 // to various BIFF records that are not currently supported:
1170 @@ -361,10 +390,14 @@ void ExcTable::FillAsHeader( ExcBoundshe
1171 if( GetOutput() != EXC_OUTPUT_BINARY )
1172 lcl_AddCalcPr( aRecList, *this );
1174 + Add( new XclExpRecalcId );
1176 // MSODRAWINGGROUP per-document data
1177 Add( new XclMsodrawinggroup( rR, ESCHER_DggContainer ) );
1178 // Shared string table: SST, EXTSST
1179 aRecList.AppendRecord( CreateRecord( EXC_ID_SST ) );
1181 + Add( new XclExpBookExt );
1185 @@ -425,8 +458,16 @@ void ExcTable::FillAsTable( size_t nCode
1186 // page settings (SETUP and various other records)
1187 aRecList.AppendRecord( xPageSett );
1189 - if( rDoc.IsTabProtected( mnScTab ) )
1190 - Add( new XclProtection() );
1191 + const ScTableProtection* pTabProtect = rDoc.GetTabProtection(mnScTab);
1192 + if (pTabProtect && pTabProtect->isProtected())
1194 + Add( new XclExpProtection(true) );
1195 + Add( new XclExpBoolRecord(0x00DD, pTabProtect->isOptionEnabled(ScTableProtection::SCENARIOS)) );
1196 + Add( new XclExpBoolRecord(0x0063, pTabProtect->isOptionEnabled(ScTableProtection::OBJECTS)) );
1197 +#if ENABLE_SHEET_PROTECTION
1198 + Add( new XclExpPassHash(pTabProtect->getPasswordHash(PASSHASH_XL)) );
1202 // local link table: EXTERNCOUNT, EXTERNSHEET
1203 if( eBiff <= EXC_BIFF5 )
1204 @@ -467,6 +508,9 @@ void ExcTable::FillAsTable( size_t nCode
1206 if( eBiff == EXC_BIFF8 )
1208 + // sheet protection options
1209 + Add( new XclExpSheetProtectOptions( GetRoot(), mnScTab ) );
1212 Add( new XclExpWebQueryBuffer( GetRoot() ) );
1214 --- sc/source/filter/excel/excimp8.cxx.old 2009-04-06 16:41:48.000000000 +0000
1215 +++ sc/source/filter/excel/excimp8.cxx 2009-04-06 16:41:49.000000000 +0000
1216 @@ -160,12 +160,6 @@ void ImportExcel8::Iteration( void )
1220 -void ImportExcel8:: WinProtection( void )
1222 - if( aIn.ReaduInt16() != 0 )
1223 - GetExtDocOptions().GetDocSettings().mbWinProtected = true;
1226 void ImportExcel8::Boundsheet( void )
1229 @@ -249,6 +243,11 @@ void ImportExcel8::Codename( BOOL bWorkb
1233 +void ImportExcel8::SheetProtection( void )
1235 + GetSheetProtectBuffer().ReadOptions( aIn, GetCurrScTab() );
1238 bool lcl_hasVBAEnabled()
1240 uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY);
1241 @@ -295,6 +294,8 @@ void ImportExcel8::PostDocLoad( void )
1242 pExcRoot->pAutoFilterBuffer->Apply();
1244 GetWebQueryBuffer().Apply(); //! test if extant
1245 + GetSheetProtectBuffer().Apply();
1246 + GetDocProtectBuffer().Apply();
1248 ImportExcel::PostDocLoad();
1250 --- sc/source/filter/excel/excrecds.cxx.old 2009-04-06 16:41:48.000000000 +0000
1251 +++ sc/source/filter/excel/excrecds.cxx 2009-04-06 16:41:49.000000000 +0000
1252 @@ -340,6 +340,7 @@ sal_Size ExcFngroupcount::GetLen( void )
1256 +using ::com::sun::star::uno::Sequence;
1258 //--------------------------------------------------------- class ExcDummy_00 -
1260 @@ -432,7 +433,9 @@ ExcBundlesheetBase::ExcBundlesheetBase()
1261 void ExcBundlesheetBase::UpdateStreamPos( XclExpStream& rStrm )
1263 rStrm.SetSvStreamPos( nOwnPos );
1264 + rStrm.DisableEncryption();
1265 rStrm << static_cast<sal_uInt32>(nStrPos);
1266 + rStrm.EnableEncryption();
1270 @@ -543,14 +546,36 @@ void XclExpWindowProtection::SaveXml( Xc
1274 -// XclExpDocProtection ===============================================================
1275 +// XclExpProtection ===========================================================
1277 -XclExpDocProtection::XclExpDocProtection(bool bValue) :
1278 +XclExpProtection::XclExpProtection(bool bValue) :
1279 XclExpBoolRecord(EXC_ID_PROTECT,bValue)
1283 // ============================================================================
1285 +XclExpPassHash::XclExpPassHash(const Sequence<sal_Int8>& aHash) :
1286 + XclExpRecord(EXC_ID_PASSWORD, 2),
1289 + if (aHash.getLength() >= 2)
1291 + mnHash = ((aHash[0] << 8) & 0xFFFF);
1292 + mnHash |= (aHash[1] & 0xFF);
1296 +XclExpPassHash::~XclExpPassHash()
1300 +void XclExpPassHash::WriteBody(XclExpStream& rStrm)
1305 +// ============================================================================
1307 XclExpFiltermode::XclExpFiltermode() :
1308 XclExpEmptyRecord( EXC_ID_FILTERMODE )
1309 --- sc/source/filter/excel/impop.cxx.old 2009-04-02 10:44:55.000000000 +0000
1310 +++ sc/source/filter/excel/impop.cxx 2009-04-06 16:41:49.000000000 +0000
1312 #include "xiview.hxx"
1313 #include "xilink.hxx"
1314 #include "xiescher.hxx"
1315 +#include "xicontent.hxx"
1317 #include "excimp8.hxx"
1318 #include "excform.hxx"
1319 @@ -418,14 +419,12 @@ void ImportExcel::Eof( void )
1323 -BOOL ImportExcel::Password( void )
1324 +void ImportExcel::SheetPassword( void )
1326 - // POST: return = TRUE, wenn Password <> 0
1328 + if (GetRoot().GetBiff() != EXC_BIFF8)
1333 - return nPasswd != 0x0000;
1334 + GetRoot().GetSheetProtectBuffer().ReadPasswordHash( aIn, GetCurrScTab() );
1338 @@ -439,6 +438,15 @@ void ImportExcel::Externsheet( void )
1342 +void ImportExcel:: WinProtection( void )
1344 + if (GetRoot().GetBiff() != EXC_BIFF8)
1347 + GetRoot().GetDocProtectBuffer().ReadWinProtect( aIn );
1351 void ImportExcel::Columndefault( void )
1352 {// Default Cell Attributes
1353 UINT16 nColMic, nColMac;
1354 @@ -570,27 +578,33 @@ void ImportExcel::Defrowheight2( void )
1358 -void ImportExcel::Protect( void )
1359 +void ImportExcel::SheetProtect( void )
1361 - if( aIn.ReaduInt16() )
1363 - uno::Sequence<sal_Int8> aEmptyPass;
1364 - GetDoc().SetTabProtection( GetCurrScTab(), TRUE, aEmptyPass );
1366 + if (GetRoot().GetBiff() != EXC_BIFF8)
1369 + GetRoot().GetSheetProtectBuffer().ReadProtect( aIn, GetCurrScTab() );
1372 void ImportExcel::DocProtect( void )
1374 - if( aIn.ReaduInt16() )
1376 - uno::Sequence<sal_Int8> aEmptyPass;
1377 - GetDoc().SetDocProtection( TRUE, aEmptyPass );
1379 + if (GetRoot().GetBiff() != EXC_BIFF8)
1382 + GetRoot().GetDocProtectBuffer().ReadDocProtect( aIn );
1385 +void ImportExcel::DocPasssword( void )
1387 + if (GetRoot().GetBiff() != EXC_BIFF8)
1390 + GetRoot().GetDocProtectBuffer().ReadPasswordHash( aIn );
1393 void ImportExcel::Codepage( void )
1395 + maStrm.EnableDecryption();
1396 SetCodePage( maStrm.ReaduInt16() );
1399 --- sc/source/filter/excel/read.cxx.old 2009-04-06 16:41:48.000000000 +0000
1400 +++ sc/source/filter/excel/read.cxx 2009-04-06 16:41:49.000000000 +0000
1401 @@ -363,7 +363,7 @@ FltError ImportExcel::Read( void )
1405 - case 0x12: Protect(); break; // SHEET PROTECTION
1406 + case 0x12: SheetProtect(); break; // SHEET PROTECTION
1408 case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
1409 case 0x17: Externsheet(); break; // EXTERNSHEET [ 2345]
1410 @@ -478,7 +478,7 @@ FltError ImportExcel::Read( void )
1414 - case 0x12: Protect(); break; // SHEET PROTECTION
1415 + case 0x12: SheetProtect(); break; // SHEET PROTECTION
1417 case 0x15: rPageSett.ReadHeaderFooter( maStrm ); break;
1419 @@ -605,7 +605,7 @@ FltError ImportExcel::Read( void )
1421 aIn.SeekGlobalPosition(); // und zurueck an alte Position
1423 - case 0x12: Protect(); break; // SHEET PROTECTION
1424 + case 0x12: SheetProtect(); break; // SHEET PROTECTION
1426 case 0x1B: rPageSett.ReadPageBreaks( maStrm ); break;
1427 case 0x1D: rTabViewSett.ReadSelection( maStrm ); break;
1428 @@ -904,6 +904,7 @@ FltError ImportExcel8::Read( void )
1431 case 0x12: DocProtect(); break; // PROTECT [ 5678]
1432 + case 0x13: DocPasssword(); break;
1433 case 0x19: WinProtection(); break;
1434 case 0x2F: // FILEPASS [ 2345 ]
1435 eLastErr = XclImpDecryptHelper::ReadFilepass( maStrm );
1436 @@ -1048,7 +1049,8 @@ FltError ImportExcel8::Read( void )
1437 eAkt = EXC_STATE_SHEET;
1438 aIn.SeekGlobalPosition(); // und zurueck an alte Position
1440 - case 0x12: Protect(); break;
1441 + case 0x12: SheetProtect(); break;
1442 + case 0x13: SheetPassword(); break;
1443 case 0x42: Codepage(); break; // CODEPAGE [ 2345 ]
1444 case 0x55: DefColWidth(); break;
1445 case 0x7D: Colinfo(); break; // COLINFO [ 345 ]
1446 @@ -1064,6 +1066,7 @@ FltError ImportExcel8::Read( void )
1447 case 0x0221: Array34(); break; // ARRAY [ 34 ]
1448 case 0x0225: Defrowheight345();break;//DEFAULTROWHEI[ 345 ]
1449 case 0x04BC: Shrfmla(); break; // SHRFMLA [ 5 ]
1450 + case 0x0867: SheetProtection(); break; // SHEETPROTECTION
1454 --- sc/source/filter/excel/xeroot.cxx.old 2009-04-02 10:44:55.000000000 +0000
1455 +++ sc/source/filter/excel/xeroot.cxx 2009-04-06 16:41:49.000000000 +0000
1457 // MARKER(update_precomp.py): autogen include statement, do not remove
1458 #include "precompiled_sc.hxx"
1459 #include <sfx2/docfile.hxx>
1460 +#include <sfx2/sfxsids.hrc>
1461 #include <svtools/saveopt.hxx>
1462 +#include <svtools/itemset.hxx>
1463 +#include <svtools/stritem.hxx>
1464 +#include <svtools/eitem.hxx>
1465 #include "xecontent.hxx"
1466 #include "xltracer.hxx"
1467 #include "xehelper.hxx"
1469 #include "xepivot.hxx"
1470 #include "xeroot.hxx"
1472 -// for filter manager
1473 -#include "excrecds.hxx"
1474 +#include "excrecds.hxx" // for filter manager
1475 +#include "tabprotection.hxx"
1476 +#include "document.hxx"
1477 +#include "scextopt.hxx"
1479 // Global data ================================================================
1481 @@ -221,6 +227,40 @@ XclExpRecordRef XclExpRoot::CreateRecord
1485 +bool XclExpRoot::IsDocumentEncrypted() const
1487 + // We need to encrypt the content when the document structure is protected.
1488 + const ScDocProtection* pDocProt = GetDoc().GetDocProtection();
1489 + if (pDocProt && pDocProt->isProtected() && pDocProt->isOptionEnabled(ScDocProtection::STRUCTURE))
1492 + if (GetPassword().Len() > 0)
1493 + // Password is entered directly into the save dialog.
1499 +const String XclExpRoot::GetPassword() const
1501 + SfxItemSet* pSet = GetMedium().GetItemSet();
1505 + const SfxPoolItem* pItem = NULL;
1506 + if (SFX_ITEM_SET == pSet->GetItemState(SID_PASSWORD, sal_True, &pItem))
1508 + const SfxStringItem* pStrItem = dynamic_cast<const SfxStringItem*>(pItem);
1511 + // Password from the save dialog.
1512 + return pStrItem->GetValue();
1519 XclExpRootData::XclExpLinkMgrRef XclExpRoot::GetLocalLinkMgrRef() const
1521 return IsInGlobals() ? mrExpData.mxGlobLinkMgr : mrExpData.mxLocLinkMgr;
1522 --- sc/source/filter/excel/xestream.cxx.old 2009-04-02 10:44:55.000000000 +0000
1523 +++ sc/source/filter/excel/xestream.cxx 2009-04-06 16:41:49.000000000 +0000
1525 #include <oox/core/tokens.hxx>
1526 #include <formula/grammar.hxx>
1528 +#define DEBUG_XL_ENCRYPTION 0
1530 +using ::std::vector;
1532 using ::com::sun::star::beans::PropertyValue;
1533 using ::com::sun::star::io::XOutputStream;
1534 using ::com::sun::star::io::XStream;
1535 @@ -92,16 +96,19 @@ XclExpStream::~XclExpStream()
1536 void XclExpStream::StartRecord( sal_uInt16 nRecId, sal_Size nRecSize )
1538 DBG_ASSERT( !mbInRec, "XclExpStream::StartRecord - another record still open" );
1539 + DisableEncryption();
1540 mnMaxContSize = mnCurrMaxSize = mnMaxRecSize;
1541 mnPredictSize = nRecSize;
1543 InitRecord( nRecId );
1545 + EnableEncryption();
1548 void XclExpStream::EndRecord()
1550 DBG_ASSERT( mbInRec, "XclExpStream::EndRecord - no record open" );
1551 + DisableEncryption();
1553 mrStrm.Seek( STREAM_SEEK_TO_END );
1555 @@ -113,6 +120,86 @@ void XclExpStream::SetSliceSize( sal_uIn
1559 +XclExpStream& XclExpStream::operator<<( sal_Int8 nValue )
1561 + PrepareWrite( 1 );
1562 + if (mbUseEncrypter && HasValidEncrypter())
1563 + mxEncrypter->Encrypt(mrStrm, nValue);
1569 +XclExpStream& XclExpStream::operator<<( sal_uInt8 nValue )
1571 + PrepareWrite( 1 );
1572 + if (mbUseEncrypter && HasValidEncrypter())
1573 + mxEncrypter->Encrypt(mrStrm, nValue);
1579 +XclExpStream& XclExpStream::operator<<( sal_Int16 nValue )
1581 + PrepareWrite( 2 );
1582 + if (mbUseEncrypter && HasValidEncrypter())
1583 + mxEncrypter->Encrypt(mrStrm, nValue);
1589 +XclExpStream& XclExpStream::operator<<( sal_uInt16 nValue )
1591 + PrepareWrite( 2 );
1592 + if (mbUseEncrypter && HasValidEncrypter())
1593 + mxEncrypter->Encrypt(mrStrm, nValue);
1599 +XclExpStream& XclExpStream::operator<<( sal_Int32 nValue )
1601 + PrepareWrite( 4 );
1602 + if (mbUseEncrypter && HasValidEncrypter())
1603 + mxEncrypter->Encrypt(mrStrm, nValue);
1609 +XclExpStream& XclExpStream::operator<<( sal_uInt32 nValue )
1611 + PrepareWrite( 4 );
1612 + if (mbUseEncrypter && HasValidEncrypter())
1613 + mxEncrypter->Encrypt(mrStrm, nValue);
1619 +XclExpStream& XclExpStream::operator<<( float fValue )
1621 + PrepareWrite( 4 );
1622 + if (mbUseEncrypter && HasValidEncrypter())
1623 + mxEncrypter->Encrypt(mrStrm, fValue);
1629 +XclExpStream& XclExpStream::operator<<( double fValue )
1631 + PrepareWrite( 8 );
1632 + if (mbUseEncrypter && HasValidEncrypter())
1633 + mxEncrypter->Encrypt(mrStrm, fValue);
1639 sal_Size XclExpStream::Write( const void* pData, sal_Size nBytes )
1642 @@ -127,9 +214,21 @@ sal_Size XclExpStream::Write( const void
1643 while( bValid && (nBytesLeft > 0) )
1645 sal_Size nWriteLen = ::std::min< sal_Size >( PrepareWrite(), nBytesLeft );
1646 - sal_Size nWriteRet = mrStrm.Write( pBuffer, nWriteLen );
1647 + sal_Size nWriteRet = nWriteLen;
1648 + if (mbUseEncrypter && HasValidEncrypter())
1650 + DBG_ASSERT(nWriteLen > 0, "XclExpStream::Write: write length is 0!");
1651 + vector<sal_uInt8> aBytes(nWriteLen);
1652 + memcpy(&aBytes[0], pBuffer, nWriteLen);
1653 + mxEncrypter->EncryptBytes(mrStrm, aBytes);
1654 + // TODO: How do I check if all the bytes have been successfully written ?
1658 + nWriteRet = mrStrm.Write( pBuffer, nWriteLen );
1659 bValid = (nWriteLen == nWriteRet);
1660 DBG_ASSERT( bValid, "XclExpStream::Write - stream write error" );
1662 pBuffer += nWriteRet;
1664 nBytesLeft -= nWriteRet;
1665 @@ -265,6 +364,26 @@ void XclExpStream::WriteCharBuffer( cons
1666 Write( &rBuffer[ 0 ], rBuffer.size() );
1669 +void XclExpStream::SetEncrypter( XclExpEncrypterRef xEncrypter )
1671 + mxEncrypter = xEncrypter;
1674 +bool XclExpStream::HasValidEncrypter() const
1676 + return mxEncrypter.is() && mxEncrypter->IsValid();
1679 +void XclExpStream::EnableEncryption( bool bEnable )
1681 + mbUseEncrypter = bEnable && HasValidEncrypter();
1684 +void XclExpStream::DisableEncryption()
1686 + EnableEncryption(false);
1689 sal_Size XclExpStream::SetSvStreamPos( sal_Size nPos )
1691 DBG_ASSERT( !mbInRec, "XclExpStream::SetSvStreamPos - not allowed inside of a record" );
1692 @@ -356,6 +475,190 @@ void XclExpStream::WriteRawZeroBytes( sa
1694 // ============================================================================
1696 +XclExpBiff8Encrypter::XclExpBiff8Encrypter( const XclExpRoot& rRoot, const sal_uInt8 nDocId[16],
1697 + const sal_uInt8 nSalt[16] ) :
1699 + mnOldPos(STREAM_SEEK_TO_END),
1702 + String aPass = rRoot.GetPassword();
1703 + if (aPass.Len() == 0)
1704 + // Empty password. Get the default biff8 password.
1705 + aPass = XclCryptoHelper::GetBiff8WbProtPassword();
1706 + Init(aPass, nDocId, nSalt);
1709 +XclExpBiff8Encrypter::~XclExpBiff8Encrypter()
1713 +bool XclExpBiff8Encrypter::IsValid() const
1718 +void XclExpBiff8Encrypter::GetSaltDigest( sal_uInt8 nSaltDigest[16] ) const
1720 + memcpy(nSaltDigest, mnSaltDigest, 16);
1723 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt8 nData )
1725 + vector<sal_uInt8> aByte(1);
1727 + EncryptBytes(rStrm, aByte);
1730 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt16 nData )
1732 + ::std::vector<sal_uInt8> pnBytes(2);
1733 + pnBytes[0] = nData & 0xFF;
1734 + pnBytes[1] = (nData >> 8) & 0xFF;
1735 + EncryptBytes(rStrm, pnBytes);
1738 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_uInt32 nData )
1740 + ::std::vector<sal_uInt8> pnBytes(4);
1741 + pnBytes[0] = nData & 0xFF;
1742 + pnBytes[1] = (nData >> 8) & 0xFF;
1743 + pnBytes[2] = (nData >> 16) & 0xFF;
1744 + pnBytes[3] = (nData >> 24) & 0xFF;
1745 + EncryptBytes(rStrm, pnBytes);
1748 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, float fValue )
1750 + ::std::vector<sal_uInt8> pnBytes(4);
1751 + memcpy(&pnBytes[0], &fValue, 4);
1752 + EncryptBytes(rStrm, pnBytes);
1755 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, double fValue )
1757 + ::std::vector<sal_uInt8> pnBytes(8);
1758 + memcpy(&pnBytes[0], &fValue, 8);
1759 + EncryptBytes(rStrm, pnBytes);
1762 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int8 nData )
1764 + Encrypt(rStrm, static_cast<sal_uInt8>(nData));
1767 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int16 nData )
1769 + Encrypt(rStrm, static_cast<sal_uInt16>(nData));
1772 +void XclExpBiff8Encrypter::Encrypt( SvStream& rStrm, sal_Int32 nData )
1774 + Encrypt(rStrm, static_cast<sal_uInt32>(nData));
1777 +void XclExpBiff8Encrypter::Init( const String& aPass, const sal_uInt8 nDocId[16],
1778 + const sal_uInt8 nSalt[16] )
1780 + memset(mnSaltDigest, 0, sizeof(mnSaltDigest));
1782 + xub_StrLen nLen = aPass.Len();
1783 + bool bValid = (0 < nLen) && (nLen < 16);
1786 + // transform String to sal_uInt16 array
1787 + memset(mnPassw, 0, sizeof(mnPassw));
1788 + for (xub_StrLen nChar = 0; nChar < nLen; ++nChar)
1789 + mnPassw[nChar] = static_cast<sal_uInt16>(aPass.GetChar(nChar));
1791 + // copy document ID
1792 + memcpy(mnDocId, nDocId, sizeof(mnDocId));
1795 + maCodec.InitKey(mnPassw, mnDocId);
1797 + // generate salt hash.
1798 + ::svx::MSCodec_Std97 aCodec;
1799 + aCodec.InitKey(mnPassw, mnDocId);
1800 + aCodec.CreateSaltDigest(nSalt, mnSaltDigest);
1802 + // verify to make sure it's in good shape.
1803 + bValid = maCodec.VerifyKey(nSalt, mnSaltDigest);
1809 +sal_uInt32 XclExpBiff8Encrypter::GetBlockPos( sal_Size nStrmPos ) const
1811 + return static_cast<sal_uInt32>(nStrmPos / EXC_ENCR_BLOCKSIZE);
1814 +sal_uInt16 XclExpBiff8Encrypter::GetOffsetInBlock( sal_Size nStrmPos ) const
1816 + return static_cast<sal_uInt16>(nStrmPos % EXC_ENCR_BLOCKSIZE);
1819 +void XclExpBiff8Encrypter::EncryptBytes( SvStream& rStrm, vector<sal_uInt8>& aBytes )
1821 + sal_Size nStrmPos = rStrm.Tell();
1822 + sal_uInt16 nBlockOffset = GetOffsetInBlock(nStrmPos);
1823 + sal_uInt16 nBlockPos = GetBlockPos(nStrmPos);
1825 +#if DEBUG_XL_ENCRYPTION
1826 + fprintf(stdout, "XclExpBiff8Encrypter::EncryptBytes: stream pos = %ld offset in block = %d block pos = %ld\n",
1827 + nStrmPos, nBlockOffset, nBlockPos);
1830 + sal_uInt16 nSize = aBytes.size();
1834 +#if DEBUG_XL_ENCRYPTION
1835 + fprintf(stdout, "RAW: ");
1836 + for (sal_uInt16 i = 0; i < nSize; ++i)
1837 + fprintf(stdout, "%2.2X ", aBytes[i]);
1838 + fprintf(stdout, "\n");
1841 + if (mnOldPos != nStrmPos)
1843 + sal_uInt16 nOldOffset = GetOffsetInBlock(mnOldPos);
1844 + sal_uInt16 nOldBlockPos = GetBlockPos(mnOldPos);
1846 + if ( (nBlockPos != nOldBlockPos) || (nBlockOffset < nOldOffset) )
1848 + maCodec.InitCipher(nBlockPos);
1852 + if (nBlockOffset > nOldOffset)
1853 + maCodec.Skip(nBlockOffset - nOldOffset);
1856 + sal_uInt16 nBytesLeft = nSize;
1857 + sal_uInt16 nPos = 0;
1858 + while (nBytesLeft > 0)
1860 + sal_uInt16 nBlockLeft = EXC_ENCR_BLOCKSIZE - nBlockOffset;
1861 + sal_uInt16 nEncBytes = ::std::min(nBlockLeft, nBytesLeft);
1863 + bool bRet = maCodec.Encode(&aBytes[nPos], nEncBytes, &aBytes[nPos], nEncBytes);
1864 + DBG_ASSERT(bRet, "XclExpBiff8Encrypter::EncryptBytes: encryption failed!!");
1866 + sal_Size nRet = rStrm.Write(&aBytes[nPos], nEncBytes);
1867 + DBG_ASSERT(nRet == nEncBytes, "XclExpBiff8Encrypter::EncryptBytes: fail to write to stream!!");
1869 + nStrmPos = rStrm.Tell();
1870 + nBlockOffset = GetOffsetInBlock(nStrmPos);
1871 + nBlockPos = GetBlockPos(nStrmPos);
1872 + if (nBlockOffset == 0)
1873 + maCodec.InitCipher(nBlockPos);
1875 + nBytesLeft -= nEncBytes;
1876 + nPos += nEncBytes;
1878 + mnOldPos = nStrmPos;
1880 rtl::OUString XclXmlUtils::GetStreamName( const char* sStreamDir, const char* sStream, sal_Int32 nId )
1882 rtl::OUStringBuffer sBuf;
1883 --- sc/source/filter/excel/xicontent.cxx.old 2009-04-02 10:44:55.000000000 +0000
1884 +++ sc/source/filter/excel/xicontent.cxx 2009-04-06 16:41:49.000000000 +0000
1886 #include "scitems.hxx"
1887 #include <svx/eeitem.hxx>
1888 #include <svtools/intitem.hxx>
1889 +#include <svtools/stritem.hxx>
1890 #include <svx/flditem.hxx>
1891 #include <svx/fhgtitem.hxx>
1892 #include <svx/wghtitem.hxx>
1894 #include "xiname.hxx"
1896 #include "excform.hxx"
1897 +#include "tabprotection.hxx"
1901 +using ::com::sun::star::uno::Sequence;
1902 +using ::std::auto_ptr;
1904 // Shared string table ========================================================
1906 @@ -1091,11 +1098,186 @@ ErrCode XclImpDecryptHelper::ReadFilepas
1908 // set decrypter at import stream
1909 rStrm.SetDecrypter( xDecr );
1910 - // remember encryption for export
1911 - rStrm.GetRoot().GetExtDocOptions().GetDocSettings().mbEncrypted = true;
1913 + // Store the document password for export.
1914 + SfxItemSet* pSet = rStrm.GetRoot().GetDocShell()->GetMedium()->GetItemSet();
1917 + String aPass = xDecr->GetPassword();
1918 + pSet->Put( SfxStringItem(SID_PASSWORD, aPass) );
1921 return xDecr.is() ? xDecr->GetError() : EXC_ENCR_ERROR_UNSUPP_CRYPT;
1924 +// Document protection ========================================================
1926 +XclImpDocProtectBuffer::XclImpDocProtectBuffer( const XclImpRoot& rRoot ) :
1927 + XclImpRoot( rRoot ),
1928 + mnPassHash(0x0000),
1929 + mbDocProtect(false),
1930 + mbWinProtect(false)
1934 +void XclImpDocProtectBuffer::ReadDocProtect( XclImpStream& rStrm )
1936 + mbDocProtect = rStrm.ReaduInt16() ? true : false;
1939 +void XclImpDocProtectBuffer::ReadWinProtect( XclImpStream& rStrm )
1941 + mbWinProtect = rStrm.ReaduInt16() ? true : false;
1944 +void XclImpDocProtectBuffer::ReadPasswordHash( XclImpStream& rStrm )
1946 + rStrm.EnableDecryption();
1947 + mnPassHash = rStrm.ReaduInt16();
1950 +void XclImpDocProtectBuffer::Apply() const
1952 + if (!mbDocProtect && !mbWinProtect)
1953 + // Excel requires either the structure or windows protection is set.
1954 + // If neither is set then the document is not protected at all.
1957 + auto_ptr<ScDocProtection> pProtect(new ScDocProtection);
1958 + pProtect->setProtected(true);
1960 +#if ENABLE_SHEET_PROTECTION
1963 + // 16-bit password pash.
1964 + Sequence<sal_Int8> aPass(2);
1965 + aPass[0] = (mnPassHash >> 8) & 0xFF;
1966 + aPass[1] = mnPassHash & 0xFF;
1967 + pProtect->setPasswordHash(aPass, PASSHASH_XL);
1971 + // document protection options
1972 + pProtect->setOption(ScDocProtection::STRUCTURE, mbDocProtect);
1973 + pProtect->setOption(ScDocProtection::WINDOWS, mbWinProtect);
1975 + GetDoc().SetDocProtection(pProtect.get());
1978 +// Sheet Protection ===========================================================
1980 +XclImpSheetProtectBuffer::Sheet::Sheet() :
1981 + mbProtected(false),
1982 + mnPasswordHash(0x0000),
1987 +// ----------------------------------------------------------------------------
1989 +XclImpSheetProtectBuffer::Sheet::Sheet(const Sheet& r) :
1990 + mbProtected(r.mbProtected),
1991 + mnPasswordHash(r.mnPasswordHash),
1992 + mnOptions(r.mnOptions)
1996 +XclImpSheetProtectBuffer::XclImpSheetProtectBuffer( const XclImpRoot& rRoot ) :
1997 + XclImpRoot( rRoot )
2001 +void XclImpSheetProtectBuffer::ReadProtect( XclImpStream& rStrm, SCTAB nTab )
2003 + if ( rStrm.ReaduInt16() )
2005 + Sheet* pSheet = GetSheetItem(nTab);
2007 + pSheet->mbProtected = true;
2011 +void XclImpSheetProtectBuffer::ReadOptions( XclImpStream& rStrm, SCTAB nTab )
2014 + sal_uInt16 nOptions;
2015 + rStrm >> nOptions;
2017 + Sheet* pSheet = GetSheetItem(nTab);
2019 + pSheet->mnOptions = nOptions;
2022 +void XclImpSheetProtectBuffer::ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab )
2026 + Sheet* pSheet = GetSheetItem(nTab);
2028 + pSheet->mnPasswordHash = nHash;
2031 +void XclImpSheetProtectBuffer::Apply() const
2033 + for (ProtectedSheetMap::const_iterator itr = maProtectedSheets.begin(), itrEnd = maProtectedSheets.end();
2034 + itr != itrEnd; ++itr)
2036 + if (!itr->second.mbProtected)
2037 + // This sheet is (for whatever reason) not protected.
2040 + auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
2041 + pProtect->setProtected(true);
2043 +#if ENABLE_SHEET_PROTECTION
2044 + // 16-bit hash password
2045 + const sal_uInt16 nHash = itr->second.mnPasswordHash;
2048 + Sequence<sal_Int8> aPass(2);
2049 + aPass[0] = (nHash >> 8) & 0xFF;
2050 + aPass[1] = nHash & 0xFF;
2051 + pProtect->setPasswordHash(aPass, PASSHASH_XL);
2055 + // sheet protection options
2056 + const sal_uInt16 nOptions = itr->second.mnOptions;
2057 + pProtect->setOption( ScTableProtection::OBJECTS, (nOptions & 0x0001) );
2058 + pProtect->setOption( ScTableProtection::SCENARIOS, (nOptions & 0x0002) );
2059 + pProtect->setOption( ScTableProtection::FORMAT_CELLS, (nOptions & 0x0004) );
2060 + pProtect->setOption( ScTableProtection::FORMAT_COLUMNS, (nOptions & 0x0008) );
2061 + pProtect->setOption( ScTableProtection::FORMAT_ROWS, (nOptions & 0x0010) );
2062 + pProtect->setOption( ScTableProtection::INSERT_COLUMNS, (nOptions & 0x0020) );
2063 + pProtect->setOption( ScTableProtection::INSERT_ROWS, (nOptions & 0x0040) );
2064 + pProtect->setOption( ScTableProtection::INSERT_HYPERLINKS, (nOptions & 0x0080) );
2065 + pProtect->setOption( ScTableProtection::DELETE_COLUMNS, (nOptions & 0x0100) );
2066 + pProtect->setOption( ScTableProtection::DELETE_ROWS, (nOptions & 0x0200) );
2067 + pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, (nOptions & 0x0400) );
2068 + pProtect->setOption( ScTableProtection::SORT, (nOptions & 0x0800) );
2069 + pProtect->setOption( ScTableProtection::AUTOFILTER, (nOptions & 0x1000) );
2070 + pProtect->setOption( ScTableProtection::PIVOT_TABLES, (nOptions & 0x2000) );
2071 + pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, (nOptions & 0x4000) );
2073 + // all done. now commit.
2074 + GetDoc().SetTabProtection(itr->first, pProtect.get());
2078 +XclImpSheetProtectBuffer::Sheet* XclImpSheetProtectBuffer::GetSheetItem( SCTAB nTab )
2080 + ProtectedSheetMap::iterator itr = maProtectedSheets.find(nTab);
2081 + if (itr == maProtectedSheets.end())
2084 + if ( !maProtectedSheets.insert( ProtectedSheetMap::value_type(nTab, Sheet()) ).second )
2087 + itr = maProtectedSheets.find(nTab);
2090 + return &itr->second;
2093 // ============================================================================
2095 --- sc/source/filter/excel/xilink.cxx.old 2009-04-02 10:44:55.000000000 +0000
2096 +++ sc/source/filter/excel/xilink.cxx 2009-04-06 16:41:49.000000000 +0000
2097 @@ -263,6 +263,7 @@ void XclImpTabInfo::ReadTabid( XclImpStr
2098 DBG_ASSERT_BIFF( rStrm.GetRoot().GetBiff() == EXC_BIFF8 );
2099 if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
2101 + rStrm.EnableDecryption();
2102 sal_Size nReadCount = rStrm.GetRecLeft() / 2;
2103 DBG_ASSERT( nReadCount <= 0xFFFF, "XclImpTabInfo::ReadTabid - record too long" );
2105 --- sc/source/filter/excel/xiroot.cxx.old 2009-04-02 10:44:55.000000000 +0000
2106 +++ sc/source/filter/excel/xiroot.cxx 2009-04-06 16:41:49.000000000 +0000
2108 XclImpRootData::XclImpRootData( XclBiff eBiff, SfxMedium& rMedium,
2109 SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) :
2110 XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ),
2111 + mbPassQueried( false ),
2112 mbHasCodePage( false )
2115 @@ -86,6 +87,8 @@ XclImpRoot::XclImpRoot( XclImpRootData&
2116 GetOldRoot().pAutoFilterBuffer = new XclImpAutoFilterBuffer;
2117 mrImpData.mxWebQueryBfr.reset( new XclImpWebQueryBuffer( GetRoot() ) );
2118 mrImpData.mxPTableMgr.reset( new XclImpPivotTableManager( GetRoot() ) );
2119 + mrImpData.mxTabProtect.reset( new XclImpSheetProtectBuffer( GetRoot() ) );
2120 + mrImpData.mxDocProtect.reset( new XclImpDocProtectBuffer( GetRoot() ) );
2123 mrImpData.mxPageSett.reset( new XclImpPageSettings( GetRoot() ) );
2124 @@ -232,6 +235,18 @@ XclImpPivotTableManager& XclImpRoot::Get
2125 return *mrImpData.mxPTableMgr;
2128 +XclImpSheetProtectBuffer& XclImpRoot::GetSheetProtectBuffer() const
2130 + DBG_ASSERT( mrImpData.mxTabProtect.is(), "XclImpRoot::GetSheetProtectBuffer - invalid call, wrong BIFF" );
2131 + return *mrImpData.mxTabProtect;
2134 +XclImpDocProtectBuffer& XclImpRoot::GetDocProtectBuffer() const
2136 + DBG_ASSERT( mrImpData.mxDocProtect.is(), "XclImpRoot::GetDocProtectBuffer - invalid call, wrong BIFF" );
2137 + return *mrImpData.mxDocProtect;
2140 XclImpPageSettings& XclImpRoot::GetPageSettings() const
2142 return *mrImpData.mxPageSett;
2143 @@ -255,5 +270,16 @@ String XclImpRoot::GetScAddInName( const
2147 +const String& XclImpRoot::QueryPassword() const
2149 + if( !mrImpData.mbPassQueried )
2151 + mrImpData.maPassw = ScfApiHelper::QueryPasswordForMedium( GetMedium() );
2152 + // set to true, even if dialog has been cancelled (never ask twice)
2153 + mrImpData.mbPassQueried = true;
2155 + return mrImpData.maPassw;
2158 // ============================================================================
2160 --- sc/source/filter/excel/xistream.cxx.old 2009-04-02 10:44:55.000000000 +0000
2161 +++ sc/source/filter/excel/xistream.cxx 2009-04-06 16:41:49.000000000 +0000
2163 #include "xlstring.hxx"
2164 #include "xiroot.hxx"
2168 // ============================================================================
2170 // ============================================================================
2171 @@ -97,11 +99,21 @@ sal_uInt16 XclImpDecrypter::Read( SvStre
2175 +const String XclImpDecrypter::GetPassword() const
2180 void XclImpDecrypter::SetHasValidPassword( bool bValid )
2182 mnError = bValid ? ERRCODE_NONE : EXC_ENCR_ERROR_WRONG_PASS;
2185 +void XclImpDecrypter::SetPassword( const String& rPass )
2190 // ----------------------------------------------------------------------------
2192 XclImpBiff5Decrypter::XclImpBiff5Decrypter( const XclImpRoot& rRoot, sal_uInt16 nKey, sal_uInt16 nHash )
2193 @@ -157,6 +169,9 @@ void XclImpBiff5Decrypter::Init( const B
2195 maCodec.InitKey( mpnPassw );
2196 bValid = maCodec.VerifyKey( nKey, nHash );
2198 + String aUniPass( rPass, RTL_TEXTENCODING_MS_1252 );
2199 + SetPassword( aUniPass );
2202 SetHasValidPassword( bValid );
2203 @@ -255,6 +270,8 @@ void XclImpBiff8Decrypter::Init(
2205 maCodec.InitKey( mpnPassw, mpnDocId );
2206 bValid = maCodec.VerifyKey( pnSaltData, pnSaltHash );
2208 + SetPassword(rPass);
2211 SetHasValidPassword( bValid );
2212 --- sc/source/filter/excel/xlroot.cxx.old 2009-04-02 10:44:55.000000000 +0000
2213 +++ sc/source/filter/excel/xlroot.cxx 2009-04-06 16:41:49.000000000 +0000
2214 @@ -92,8 +92,7 @@ XclRootData::XclRootData( XclBiff eBiff,
2215 mxRD( new RootData ),//!
2218 - mbExport( bExport ),
2219 - mbHasPassw( false )
2220 + mbExport( bExport )
2222 // default script type, e.g. for empty cells
2223 switch( ScGlobal::GetDefaultScriptType() )
2224 @@ -199,17 +198,6 @@ void XclRoot::SetCharWidth( const XclFon
2228 -const String& XclRoot::QueryPassword() const
2230 - if( !mrData.mbHasPassw )
2232 - mrData.maPassw = ScfApiHelper::QueryPasswordForMedium( GetMedium() );
2233 - // set to true, even if dialog has been cancelled (never ask twice)
2234 - mrData.mbHasPassw = true;
2236 - return mrData.maPassw;
2239 bool XclRoot::HasVbaStorage() const
2241 SotStorageRef xRootStrg = GetRootStorage();
2242 --- sc/source/filter/inc/excimp8.hxx.old 2009-04-02 10:44:58.000000000 +0000
2243 +++ sc/source/filter/inc/excimp8.hxx 2009-04-06 16:41:49.000000000 +0000
2244 @@ -61,7 +61,6 @@ class ImportExcel8 : public ImportExcel
2245 void Precision( void ); // 0x0E
2246 void Delta( void ); // 0x10
2247 void Iteration( void ); // 0x11
2248 - void WinProtection( void ); // 0x19
2249 void Boundsheet( void ); // 0x85
2250 void FilterMode( void ); // 0x9B
2251 void AutoFilterInfo( void ); // 0x9D
2252 @@ -73,6 +72,7 @@ class ImportExcel8 : public ImportExcel
2254 void Hlink( void ); // 0x01B8
2255 void Codename( BOOL bWBGlobals ); // 0x01BA
2256 + void SheetProtection( void ); // 0x0867
2258 virtual void EndSheet( void );
2259 virtual void PostDocLoad( void );
2260 --- sc/source/filter/inc/excrecds.hxx.old 2009-04-06 16:41:48.000000000 +0000
2261 +++ sc/source/filter/inc/excrecds.hxx 2009-04-06 16:41:49.000000000 +0000
2262 @@ -246,10 +246,23 @@ class XclExpWindowProtection : public Xc
2265 // EXC_ID_PROTECT Document Protection
2266 -class XclExpDocProtection : public XclExpBoolRecord
2267 +class XclExpProtection : public XclExpBoolRecord
2270 - XclExpDocProtection(bool bValue);
2271 + XclExpProtection(bool bValue);
2274 +class XclExpPassHash : public XclExpRecord
2277 + XclExpPassHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aHash);
2278 + virtual ~XclExpPassHash();
2281 + virtual void WriteBody(XclExpStream& rStrm);
2284 + sal_uInt16 mnHash;
2288 --- sc/source/filter/inc/imp_op.hxx.old 2009-04-02 10:44:58.000000000 +0000
2289 +++ sc/source/filter/inc/imp_op.hxx 2009-04-06 16:41:49.000000000 +0000
2290 @@ -135,9 +135,11 @@ protected:
2291 void Bof2( void ); // 0x09
2292 void Eof( void ); // 0x0A
2293 void DocProtect( void ); // 0x12
2294 - void Protect( void ); // 0x12 Sheet Protection
2295 - BOOL Password( void ); // 0x13
2296 + void SheetProtect( void ); // 0x12 Sheet Protection
2297 + void DocPasssword( void ); // 0x13 document password
2298 + void SheetPassword( void ); // 0x13 sheet password
2299 void Externsheet( void ); // 0x17
2300 + void WinProtection( void ); // 0x19
2301 void Columndefault( void ); // 0x20
2302 void Array25( void ); // 0x21
2303 void Rec1904( void ); // 0x22
2304 --- sc/source/filter/inc/xcl97rec.hxx.old 2009-04-02 10:44:58.000000000 +0000
2305 +++ sc/source/filter/inc/xcl97rec.hxx 2009-04-06 16:41:49.000000000 +0000
2307 #include "xcl97esc.hxx"
2308 #include "xlstyle.hxx"
2312 // --- class XclMsodrawing_Base --------------------------------------
2314 class XclMsodrawing_Base
2315 @@ -57,29 +59,26 @@ public:
2317 // --- class XclMsodrawinggroup --------------------------------------
2319 -class XclMsodrawinggroup : public XclMsodrawing_Base, public ExcRecord
2320 +class XclMsodrawinggroup : public XclMsodrawing_Base, public XclExpRecord
2324 - virtual void SaveCont( XclExpStream& rStrm );
2325 + virtual void WriteBody( XclExpStream& rStrm );
2328 XclMsodrawinggroup( RootData& rRoot,
2329 UINT16 nEscherType = 0 );
2330 virtual ~XclMsodrawinggroup();
2332 - virtual UINT16 GetNum() const;
2333 - virtual sal_Size GetLen() const;
2337 // --- class XclMsodrawing -------------------------------------------
2339 -class XclMsodrawing : public XclMsodrawing_Base, public ExcRecord
2340 +class XclMsodrawing : public XclMsodrawing_Base, public XclExpRecord
2344 - virtual void SaveCont( XclExpStream& rStrm );
2345 + virtual void WriteBody( XclExpStream& rStrm );
2349 @@ -87,9 +86,6 @@ public:
2350 UINT16 nEscherType = 0,
2351 sal_Size nInitialSize = 0 );
2352 virtual ~XclMsodrawing();
2354 - virtual UINT16 GetNum() const;
2355 - virtual sal_Size GetLen() const;
2359 @@ -464,23 +460,24 @@ public:
2360 virtual sal_Size GetLen() const;
2363 +// ============================================================================
2365 -// ---- class XclProtection ------------------------------------------
2367 -class XclProtection : public ExcDummyRec
2368 +/** Represents a SHEETPROTECTION record that stores sheet protection
2369 + options. Note that a sheet still needs to save its sheet protection
2370 + options even when it's not protected. */
2371 +class XclExpSheetProtectOptions : public XclExpRecord
2373 - // replacement for records PROTECT, SCENPROTECT, OBJPROTECT...
2375 - static const BYTE pMyData[];
2376 - static const sal_Size nMyLen;
2378 - virtual sal_Size GetLen( void ) const;
2379 - virtual const BYTE* GetData( void ) const;
2381 + explicit XclExpSheetProtectOptions( const XclExpRoot& rRoot, SCTAB nTab );
2384 + virtual void WriteBody( XclExpStream& rStrm );
2386 -// -------------------------------------------------------------------
2388 + sal_uInt16 mnOptions; /// Encoded sheet protection options.
2391 +// ============================================================================
2393 class XclCalccount : public ExcRecord
2395 @@ -533,6 +530,163 @@ public:
2396 virtual void SaveXml( XclExpXmlStream& rStrm );
2399 +// ============================================================================
2401 +class XclExpFilePass : public XclExpRecord
2404 + explicit XclExpFilePass( const XclExpRoot& rRoot );
2405 + virtual ~XclExpFilePass();
2408 + virtual void WriteBody( XclExpStream& rStrm );
2411 + const XclExpRoot& mrRoot;
2414 +// ============================================================================
2416 +class XclExpFnGroupCount : public XclExpRecord
2419 + explicit XclExpFnGroupCount();
2420 + virtual ~XclExpFnGroupCount();
2423 + virtual void WriteBody( XclExpStream& rStrm );
2426 +// ============================================================================
2428 +/** Beginning of User Interface Records */
2429 +class XclExpInterfaceHdr : public XclExpRecord
2432 + explicit XclExpInterfaceHdr();
2433 + virtual ~XclExpInterfaceHdr();
2436 + virtual void WriteBody( XclExpStream& rStrm );
2439 +// ============================================================================
2441 +/** Beginning of User Interface Records */
2442 +class XclExpInterfaceEnd : public XclExpRecord
2445 + explicit XclExpInterfaceEnd();
2446 + virtual ~XclExpInterfaceEnd();
2449 + virtual void WriteBody( XclExpStream& rStrm );
2452 +// ============================================================================
2454 +/** ADDMENU/DELMENU Record Group Count */
2455 +class XclExpMMS : public XclExpRecord
2458 + explicit XclExpMMS();
2459 + virtual ~XclExpMMS();
2462 + virtual void WriteBody( XclExpStream& rStrm );
2465 +// ============================================================================
2467 +/** Write Access User Name - This record contains the user name, which is
2468 + the name you type when you install Excel. */
2469 +class XclExpWriteAccess : public XclExpRecord
2472 + explicit XclExpWriteAccess();
2473 + virtual ~XclExpWriteAccess();
2476 + virtual void WriteBody( XclExpStream& rStrm );
2479 +// ============================================================================
2481 +class XclExpCodePage : public XclExpRecord
2484 + explicit XclExpCodePage();
2485 + virtual ~XclExpCodePage();
2488 + virtual void WriteBody( XclExpStream& rStrm );
2491 +// ============================================================================
2493 +class XclExpDSF : public XclExpRecord
2496 + explicit XclExpDSF();
2497 + virtual ~XclExpDSF();
2500 + virtual void WriteBody( XclExpStream& rStrm );
2503 +// ============================================================================
2505 +class XclExpProt4Rev : public XclExpRecord
2508 + explicit XclExpProt4Rev();
2509 + virtual ~XclExpProt4Rev();
2512 + virtual void WriteBody( XclExpStream& rStrm );
2515 +// ============================================================================
2517 +class XclExpProt4RevPass : public XclExpRecord
2520 + explicit XclExpProt4RevPass();
2521 + virtual ~XclExpProt4RevPass();
2524 + virtual void WriteBody( XclExpStream& rStrm );
2527 +// ============================================================================
2529 +/** What's this record for? It is a zero-byte record. */
2530 +class XclExpExcel9File : public XclExpRecord
2533 + explicit XclExpExcel9File();
2534 + virtual ~XclExpExcel9File();
2537 + virtual void WriteBody( XclExpStream& rStrm );
2540 +// ============================================================================
2542 +class XclExpRecalcId : public XclExpDummyRecord
2545 + explicit XclExpRecalcId();
2548 +// ============================================================================
2550 +class XclExpBookExt : public XclExpDummyRecord
2553 + explicit XclExpBookExt();
2559 --- sc/source/filter/inc/xeroot.hxx.old 2009-04-02 10:44:58.000000000 +0000
2560 +++ sc/source/filter/inc/xeroot.hxx 2009-04-06 16:41:49.000000000 +0000
2561 @@ -154,7 +154,12 @@ public:
2562 @param nRecId Identifier that specifies which record is returned. */
2563 XclExpRecordRef CreateRecord( sal_uInt16 nRecId ) const;
2565 + bool IsDocumentEncrypted() const;
2567 + const String GetPassword() const;
2571 /** Returns the local or global link manager, depending on current context. */
2572 XclExpRootData::XclExpLinkMgrRef GetLocalLinkMgrRef() const;
2574 --- sc/source/filter/inc/xestream.hxx.old 2009-04-02 10:44:58.000000000 +0000
2575 +++ sc/source/filter/inc/xestream.hxx 2009-04-06 16:41:49.000000000 +0000
2577 #include "xlstream.hxx"
2578 #include "xestring.hxx"
2580 +#include <svx/mscodec.hxx>
2583 /* ============================================================================
2584 Output stream class for Excel export
2585 - CONTINUE record handling
2586 @@ -50,6 +53,8 @@ Output stream class for Excel export
2587 ============================================================================ */
2590 +class XclExpBiff8Encrypter;
2591 +typedef ScfRef< XclExpBiff8Encrypter > XclExpEncrypterRef;
2593 /** This class is used to export Excel record streams.
2594 @descr An instance is constructed with an SvStream and the maximum size of Excel
2595 @@ -108,14 +113,14 @@ public:
2596 /** Sets data slice length. 0 = no slices. */
2597 void SetSliceSize( sal_uInt16 nSize );
2599 - inline XclExpStream& operator<<( sal_Int8 nValue );
2600 - inline XclExpStream& operator<<( sal_uInt8 nValue );
2601 - inline XclExpStream& operator<<( sal_Int16 nValue );
2602 - inline XclExpStream& operator<<( sal_uInt16 nValue );
2603 - inline XclExpStream& operator<<( sal_Int32 nValue );
2604 - inline XclExpStream& operator<<( sal_uInt32 nValue );
2605 - inline XclExpStream& operator<<( float fValue );
2606 - inline XclExpStream& operator<<( double fValue );
2607 + XclExpStream& operator<<( sal_Int8 nValue );
2608 + XclExpStream& operator<<( sal_uInt8 nValue );
2609 + XclExpStream& operator<<( sal_Int16 nValue );
2610 + XclExpStream& operator<<( sal_uInt16 nValue );
2611 + XclExpStream& operator<<( sal_Int32 nValue );
2612 + XclExpStream& operator<<( sal_uInt32 nValue );
2613 + XclExpStream& operator<<( float fValue );
2614 + XclExpStream& operator<<( double fValue );
2616 /** Writes nBytes bytes from memory. */
2617 sal_Size Write( const void* pData, sal_Size nBytes );
2618 @@ -158,6 +163,14 @@ public:
2619 /** Returns the absolute position of the system stream. */
2620 inline sal_Size GetSvStreamPos() const { return mrStrm.Tell(); }
2622 + void SetEncrypter( XclExpEncrypterRef xEncrypter );
2624 + bool HasValidEncrypter() const;
2626 + void EnableEncryption( bool bEnable = true );
2628 + void DisableEncryption();
2631 /** Writes header data, internal setup. */
2632 void InitRecord( sal_uInt16 nRecId );
2633 @@ -180,6 +193,9 @@ private:
2634 SvStream& mrStrm; /// Reference to the system output stream.
2635 const XclExpRoot& mrRoot; /// Filter root data.
2637 + bool mbUseEncrypter;
2638 + XclExpEncrypterRef mxEncrypter;
2641 sal_uInt16 mnMaxRecSize; /// Maximum size of record content.
2642 sal_uInt16 mnMaxContSize; /// Maximum size of CONTINUE content.
2643 @@ -197,64 +213,51 @@ private:
2645 // ----------------------------------------------------------------------------
2647 -inline XclExpStream& XclExpStream::operator<<( sal_Int8 nValue )
2649 - PrepareWrite( 1 );
2654 -inline XclExpStream& XclExpStream::operator<<( sal_uInt8 nValue )
2656 - PrepareWrite( 1 );
2660 +// ============================================================================
2662 -inline XclExpStream& XclExpStream::operator<<( sal_Int16 nValue )
2663 +class XclExpBiff8Encrypter
2665 - PrepareWrite( 2 );
2670 + explicit XclExpBiff8Encrypter( const XclExpRoot& rRoot, const sal_uInt8 nDocId[16],
2671 + const sal_uInt8 nSalt[16] );
2672 + ~XclExpBiff8Encrypter();
2674 -inline XclExpStream& XclExpStream::operator<<( sal_uInt16 nValue )
2676 - PrepareWrite( 2 );
2680 + bool IsValid() const;
2682 -inline XclExpStream& XclExpStream::operator<<( sal_Int32 nValue )
2684 - PrepareWrite( 4 );
2688 + void GetSaltDigest( sal_uInt8 nSaltDigest[16] ) const;
2690 -inline XclExpStream& XclExpStream::operator<<( sal_uInt32 nValue )
2692 - PrepareWrite( 4 );
2696 + void Encrypt( SvStream& rStrm, sal_uInt8 nData );
2697 + void Encrypt( SvStream& rStrm, sal_uInt16 nData );
2698 + void Encrypt( SvStream& rStrm, sal_uInt32 nData );
2700 -inline XclExpStream& XclExpStream::operator<<( float fValue )
2702 - PrepareWrite( 4 );
2706 + void Encrypt( SvStream& rStrm, sal_Int8 nData );
2707 + void Encrypt( SvStream& rStrm, sal_Int16 nData );
2708 + void Encrypt( SvStream& rStrm, sal_Int32 nData );
2710 -inline XclExpStream& XclExpStream::operator<<( double fValue )
2712 - PrepareWrite( 8 );
2716 + void Encrypt( SvStream& rStrm, float fValue );
2717 + void Encrypt( SvStream& rStrm, double fValue );
2719 + void EncryptBytes( SvStream& rStrm, ::std::vector<sal_uInt8>& aBytes );
2721 -// ============================================================================
2723 + void Init( const String& aPass, const sal_uInt8 nDocId[16],
2724 + const sal_uInt8 nSalt[16] );
2726 + sal_uInt32 GetBlockPos( sal_Size nStrmPos ) const;
2727 + sal_uInt16 GetOffsetInBlock( sal_Size nStrmPos ) const;
2731 + ::svx::MSCodec_Std97 maCodec; /// Crypto algorithm implementation.
2732 + sal_uInt16 mnPassw[16]; /// Cached password data for copy construction.
2733 + sal_uInt8 mnDocId[16]; /// Cached document ID for copy construction.
2734 + sal_uInt8 mnSaltDigest[16];
2736 + const XclExpRoot& mrRoot;
2737 + sal_Size mnOldPos; /// Last known stream position
2741 // ----------------------------------------------------------------------------
2743 --- sc/source/filter/inc/xetable.hxx.old 2009-04-02 10:44:58.000000000 +0000
2744 +++ sc/source/filter/inc/xetable.hxx 2009-04-06 16:41:49.000000000 +0000
2745 @@ -1088,7 +1088,5 @@ private:
2746 XclExpDvalRef mxDval; /// Data validation with DVAL and DV records.
2749 -// ============================================================================
2753 --- sc/source/filter/inc/xicontent.hxx.old 2009-04-02 10:44:58.000000000 +0000
2754 +++ sc/source/filter/inc/xicontent.hxx 2009-04-06 16:41:49.000000000 +0000
2756 #include "xistring.hxx"
2757 #include "xiroot.hxx"
2761 /* ============================================================================
2762 Classes to import the big Excel document contents (related to several cells or
2763 globals for the document).
2764 @@ -249,5 +251,64 @@ public:
2766 // ============================================================================
2768 +// Document protection ========================================================
2770 +class XclImpDocProtectBuffer : protected XclImpRoot
2773 + explicit XclImpDocProtectBuffer( const XclImpRoot& rRoot );
2775 + /** document structure protection flag */
2776 + void ReadDocProtect( XclImpStream& rStrm );
2778 + /** document windows properties protection flag */
2779 + void ReadWinProtect( XclImpStream& rStrm );
2781 + void ReadPasswordHash( XclImpStream& rStrm );
2783 + void Apply() const;
2786 + sal_uInt16 mnPassHash;
2787 + bool mbDocProtect:1;
2788 + bool mbWinProtect:1;
2791 +// Sheet protection ===========================================================
2793 +class XclImpSheetProtectBuffer : protected XclImpRoot
2796 + explicit XclImpSheetProtectBuffer( const XclImpRoot& rRoot );
2798 + void ReadProtect( XclImpStream& rStrm, SCTAB nTab );
2800 + void ReadOptions( XclImpStream& rStrm, SCTAB nTab );
2802 + void ReadPasswordHash( XclImpStream& rStrm, SCTAB nTab );
2804 + void Apply() const;
2810 + sal_uInt16 mnPasswordHash;
2811 + sal_uInt16 mnOptions;
2814 + Sheet(const Sheet& r);
2817 + Sheet* GetSheetItem( SCTAB nTab );
2820 + typedef ::std::map<SCTAB, Sheet> ProtectedSheetMap;
2821 + ProtectedSheetMap maProtectedSheets;
2825 +// ============================================================================
2829 --- sc/source/filter/inc/xiroot.hxx.old 2009-04-02 10:44:58.000000000 +0000
2830 +++ sc/source/filter/inc/xiroot.hxx 2009-04-06 16:41:49.000000000 +0000
2831 @@ -61,6 +61,8 @@ class XclImpPivotTableManager;
2832 class XclImpPageSettings;
2833 class XclImpDocViewSettings;
2834 class XclImpTabViewSettings;
2835 +class XclImpSheetProtectBuffer;
2836 +class XclImpDocProtectBuffer;
2838 class _ScRangeListTabs;
2840 @@ -87,6 +89,8 @@ struct XclImpRootData : public XclRootDa
2841 typedef ScfRef< XclImpPageSettings > XclImpPageSettRef;
2842 typedef ScfRef< XclImpDocViewSettings > XclImpDocViewSettRef;
2843 typedef ScfRef< XclImpTabViewSettings > XclImpTabViewSettRef;
2844 + typedef ScfRef< XclImpSheetProtectBuffer > XclImpTabProtectRef;
2845 + typedef ScfRef< XclImpDocProtectBuffer > XclImpDocProtectRef;
2847 XclImpAddrConvRef mxAddrConv; /// The address converter.
2848 XclImpFmlaCompRef mxFmlaComp; /// The formula compiler.
2849 @@ -110,6 +114,11 @@ struct XclImpRootData : public XclRootDa
2850 XclImpPageSettRef mxPageSett; /// Page settings for current sheet.
2851 XclImpDocViewSettRef mxDocViewSett; /// View settings for entire document.
2852 XclImpTabViewSettRef mxTabViewSett; /// View settings for current sheet.
2853 + XclImpTabProtectRef mxTabProtect; /// Sheet protection options for current sheet.
2854 + XclImpDocProtectRef mxDocProtect; /// Document protection options.
2856 + String maPassw; /// Entered password for stream decryption.
2857 + bool mbPassQueried; /// true = Password already querried.
2859 bool mbHasCodePage; /// true = CODEPAGE record exists.
2861 @@ -181,6 +190,10 @@ public:
2862 XclImpWebQueryBuffer& GetWebQueryBuffer() const;
2863 /** Returns the pivot table manager. */
2864 XclImpPivotTableManager& GetPivotTableManager() const;
2865 + /** Returns the sheet protection options of the current sheet. */
2866 + XclImpSheetProtectBuffer& GetSheetProtectBuffer() const;
2867 + /** Returns the document protection options. */
2868 + XclImpDocProtectBuffer& GetDocProtectBuffer() const;
2870 /** Returns the page settings of the current sheet. */
2871 XclImpPageSettings& GetPageSettings() const;
2872 @@ -192,6 +205,9 @@ public:
2873 /** Returns the Calc add-in function name for an Excel function name. */
2874 String GetScAddInName( const String& rXclName ) const;
2876 + /** Queries a password from the user and returns it (empty string -> input cancelled). */
2877 + const String& QueryPassword() const;
2880 mutable XclImpRootData& mrImpData; /// Reference to the global import data struct.
2882 --- sc/source/filter/inc/xistream.hxx.old 2009-04-02 10:44:58.000000000 +0000
2883 +++ sc/source/filter/inc/xistream.hxx 2009-04-06 16:41:49.000000000 +0000
2884 @@ -73,6 +73,8 @@ public:
2885 @return Count of bytes really read. */
2886 sal_uInt16 Read( SvStream& rStrm, void* pData, sal_uInt16 nBytes );
2888 + const String GetPassword() const;
2891 /** Protected copy c'tor for OnClone(). */
2892 explicit XclImpDecrypter( const XclImpDecrypter& rSrc );
2893 @@ -80,6 +82,8 @@ protected:
2894 /** Sets the decrypter to a state showing whether the password was correct. */
2895 void SetHasValidPassword( bool bValid );
2897 + void SetPassword( const String& rPass );
2900 /** Implementation of cloning this object. */
2901 virtual XclImpDecrypter* OnClone() const = 0;
2902 @@ -89,6 +93,7 @@ private:
2903 virtual sal_uInt16 OnRead( SvStream& rStrm, sal_uInt8* pnData, sal_uInt16 nBytes ) = 0;
2906 + String maPass; /// Stored password (needed for export)
2907 ErrCode mnError; /// Decrypter error code.
2908 sal_Size mnOldPos; /// Last known stream position.
2909 sal_uInt16 mnRecSize; /// Current record size.
2910 --- sc/source/filter/inc/xlroot.hxx.old 2009-04-02 10:44:58.000000000 +0000
2911 +++ sc/source/filter/inc/xlroot.hxx 2009-04-06 16:41:49.000000000 +0000
2912 @@ -92,7 +92,6 @@ struct XclRootData
2913 ScDocument& mrDoc; /// The source or destination document.
2914 String maDocUrl; /// Document URL of imported/exported file.
2915 String maBasePath; /// Base path of imported/exported file (path of maDocUrl).
2916 - String maPassw; /// Entered password for stream encryption/decryption.
2917 rtl_TextEncoding meTextEnc; /// Text encoding to import/export byte strings.
2918 LanguageType meSysLang; /// System language.
2919 LanguageType meDocLang; /// Document language (import: from file, export: from system).
2920 @@ -116,7 +115,6 @@ struct XclRootData
2921 long mnCharWidth; /// Width of '0' in default font (twips).
2922 SCTAB mnScTab; /// Current Calc sheet index.
2923 const bool mbExport; /// false = Import, true = Export.
2924 - bool mbHasPassw; /// true = Password already querried.
2926 explicit XclRootData( XclBiff eBiff, SfxMedium& rMedium,
2927 SotStorageRef xRootStrg, ScDocument& rDoc,
2928 @@ -184,8 +182,6 @@ public:
2929 inline const String& GetDocUrl() const { return mrData.maDocUrl; }
2930 /** Returns the base path of the imported/exported file. */
2931 inline const String& GetBasePath() const { return mrData.maBasePath; }
2932 - /** Queries a password from the user and returns it (empty string -> input cancelled). */
2933 - const String& QueryPassword() const;
2935 /** Returns the OLE2 root storage of the imported/exported file.
2936 @return Pointer to root storage or 0, if the file is a simple stream. */
2937 --- sc/source/filter/starcalc/scflt.cxx.old 2009-04-02 10:44:59.000000000 +0000
2938 +++ sc/source/filter/starcalc/scflt.cxx 2009-04-06 16:41:49.000000000 +0000
2940 #include "postit.hxx"
2941 #include "globstr.hrc"
2942 #include "ftools.hxx"
2943 +#include "tabprotection.hxx"
2945 #include "fprogressbar.hxx"
2947 @@ -1087,9 +1088,11 @@ void Sc10Import::LoadProtect()
2948 //rStream.Read(&SheetProtect, sizeof(SheetProtect));
2949 lcl_ReadSheetProtect(rStream, SheetProtect);
2950 nError = rStream.GetError();
2951 - uno::Sequence<sal_Int8> aPass;
2952 - SvPasswordHelper::GetHashPassword(aPass, SC10TOSTRING( SheetProtect.PassWord ));
2953 - pDoc->SetDocProtection( SheetProtect.Protect, aPass);
2955 + ScDocProtection aProtection;
2956 + aProtection.setProtected(static_cast<bool>(SheetProtect.Protect));
2957 + aProtection.setPassword(SC10TOSTRING(SheetProtect.PassWord));
2958 + pDoc->SetDocProtection(&aProtection);
2962 @@ -1441,10 +1444,11 @@ void Sc10Import::LoadTables()
2964 //rStream.Read(&TabProtect, sizeof(TabProtect));
2965 lcl_ReadTabProtect(rStream, TabProtect);
2966 - uno::Sequence<sal_Int8> aPass;
2967 - SvPasswordHelper::GetHashPassword(aPass, SC10TOSTRING( TabProtect.PassWord ));
2969 - pDoc->SetTabProtection( static_cast<SCTAB>(Tab), TabProtect.Protect, aPass);
2970 + ScTableProtection aProtection;
2971 + aProtection.setProtected(static_cast<bool>(TabProtect.Protect));
2972 + aProtection.setPassword(SC10TOSTRING(TabProtect.PassWord));
2973 + pDoc->SetTabProtection(static_cast<SCTAB>(Tab), &aProtection);
2977 --- sc/source/filter/xcl97/XclExpChangeTrack.cxx.old 2009-04-02 10:44:57.000000000 +0000
2978 +++ sc/source/filter/xcl97/XclExpChangeTrack.cxx 2009-04-06 16:41:49.000000000 +0000
2979 @@ -491,6 +491,7 @@ void XclExpChTrTabId::Copy( const XclExp
2981 void XclExpChTrTabId::SaveCont( XclExpStream& rStrm )
2983 + rStrm.EnableEncryption();
2985 for( sal_uInt16* pElem = pBuffer; pElem < (pBuffer + nTabCount); pElem++ )
2987 --- sc/source/filter/xcl97/makefile.mk.old 2009-04-02 10:44:57.000000000 +0000
2988 +++ sc/source/filter/xcl97/makefile.mk 2009-04-06 16:41:49.000000000 +0000
2989 @@ -49,7 +49,6 @@ PROJECTPCHSOURCE=..\pch\filt_pch
2990 # --- Files --------------------------------------------------------
2993 - $(SLO)$/xcl97dum.obj \
2994 $(SLO)$/xcl97esc.obj \
2995 $(SLO)$/xcl97rec.obj \
2996 $(SLO)$/XclImpChangeTrack.obj \
2997 --- sc/source/filter/xcl97/xcl97rec.cxx.old 2009-04-02 10:44:57.000000000 +0000
2998 +++ sc/source/filter/xcl97/xcl97rec.cxx 2009-04-06 16:41:49.000000000 +0000
3000 #include "scextopt.hxx"
3001 #include "docoptio.hxx"
3002 #include "patattr.hxx"
3003 +#include "tabprotection.hxx"
3005 #include <oox/core/tokens.hxx>
3007 @@ -135,9 +136,9 @@ sal_Size XclMsodrawing_Base::GetDataLen(
3009 // --- class XclMsodrawinggroup --------------------------------------
3011 -XclMsodrawinggroup::XclMsodrawinggroup( RootData& rRoot, UINT16 nEscherType )
3013 - XclMsodrawing_Base( *rRoot.pEscher )
3014 +XclMsodrawinggroup::XclMsodrawinggroup( RootData& rRoot, UINT16 nEscherType ) :
3015 + XclMsodrawing_Base( *rRoot.pEscher ),
3016 + XclExpRecord(0x00EB, 2) // bogus record size since we don't know the actual size yet.
3020 @@ -182,7 +183,7 @@ XclMsodrawinggroup::~XclMsodrawinggroup(
3024 -void XclMsodrawinggroup::SaveCont( XclExpStream& rStrm )
3025 +void XclMsodrawinggroup::WriteBody( XclExpStream& rStrm )
3027 DBG_ASSERT( GetEscherEx()->GetStreamPos() == GetEscherEx()->GetOffsetFromMap( nStartPos ),
3028 "XclMsodrawinggroup::SaveCont: Escher stream position mismatch" );
3029 @@ -190,23 +191,11 @@ void XclMsodrawinggroup::SaveCont( XclEx
3033 -UINT16 XclMsodrawinggroup::GetNum() const
3039 -sal_Size XclMsodrawinggroup::GetLen() const
3041 - return GetDataLen();
3046 // --- class XclMsodrawing --------------------------------------
3048 XclMsodrawing::XclMsodrawing( const XclExpRoot& rRoot, UINT16 nEscherType, sal_Size nInitialSize ) :
3049 - XclMsodrawing_Base( *rRoot.GetOldRoot().pEscher, nInitialSize )
3050 + XclMsodrawing_Base( *rRoot.GetOldRoot().pEscher, nInitialSize ),
3051 + XclExpRecord( 0x00EC, nInitialSize )
3055 @@ -232,7 +221,7 @@ XclMsodrawing::~XclMsodrawing()
3059 -void XclMsodrawing::SaveCont( XclExpStream& rStrm )
3060 +void XclMsodrawing::WriteBody( XclExpStream& rStrm )
3062 DBG_ASSERT( GetEscherEx()->GetStreamPos() == GetEscherEx()->GetOffsetFromMap( nStartPos ),
3063 "XclMsodrawing::SaveCont: Escher stream position mismatch" );
3064 @@ -240,16 +229,6 @@ void XclMsodrawing::SaveCont( XclExpStre
3068 -UINT16 XclMsodrawing::GetNum() const
3074 -sal_Size XclMsodrawing::GetLen() const
3076 - return GetDataLen();
3080 // --- class XclObjList ----------------------------------------------
3081 @@ -887,6 +866,7 @@ ExcBof8_Base::ExcBof8_Base()
3083 void ExcBof8_Base::SaveCont( XclExpStream& rStrm )
3085 + rStrm.DisableEncryption();
3086 rStrm << nVers << nDocType << nRupBuild << nRupYear
3087 << nFileHistory << nLowestBiffVer;
3089 @@ -946,7 +926,10 @@ void ExcBundlesheet8::SaveCont( XclExpSt
3091 nOwnPos = rStrm.GetSvStreamPos();
3092 // write dummy position, real position comes later
3093 - rStrm << sal_uInt32( 0 ) << nGrbit << GetName();
3094 + rStrm.DisableEncryption();
3095 + rStrm << sal_uInt32(0);
3096 + rStrm.EnableEncryption();
3097 + rStrm << nGrbit << GetName();
3101 @@ -1254,33 +1237,73 @@ sal_Size ExcEScenarioManager::GetLen() c
3105 +// ============================================================================
3108 -// ---- class XclProtection ------------------------------------------
3110 -const BYTE XclProtection::pMyData[] =
3111 +struct XclExpTabProtectOption
3113 - 0x12, 0x00, 0x02, 0x00, 0x01, 0x00, // PROTECT
3114 - 0xDD, 0x00, 0x02, 0x00, 0x01, 0x00, // SCENPROTECT
3115 - 0x63, 0x00, 0x02, 0x00, 0x01, 0x00 // OBJPROTECT
3116 + ScTableProtection::Option eOption;
3119 -const sal_Size XclProtection::nMyLen = sizeof( XclProtection::pMyData );
3121 -sal_Size XclProtection::GetLen( void ) const
3122 +XclExpSheetProtectOptions::XclExpSheetProtectOptions( const XclExpRoot& rRoot, SCTAB nTab ) :
3123 + XclExpRecord( 0x0867, 23 )
3128 + static const XclExpTabProtectOption aTable[] =
3130 + { ScTableProtection::OBJECTS, 0x0001 },
3131 + { ScTableProtection::SCENARIOS, 0x0002 },
3132 + { ScTableProtection::FORMAT_CELLS, 0x0004 },
3133 + { ScTableProtection::FORMAT_COLUMNS, 0x0008 },
3134 + { ScTableProtection::FORMAT_ROWS, 0x0010 },
3135 + { ScTableProtection::INSERT_COLUMNS, 0x0020 },
3136 + { ScTableProtection::INSERT_ROWS, 0x0040 },
3137 + { ScTableProtection::INSERT_HYPERLINKS, 0x0080 },
3139 + { ScTableProtection::DELETE_COLUMNS, 0x0100 },
3140 + { ScTableProtection::DELETE_ROWS, 0x0200 },
3141 + { ScTableProtection::SELECT_LOCKED_CELLS, 0x0400 },
3142 + { ScTableProtection::SORT, 0x0800 },
3143 + { ScTableProtection::AUTOFILTER, 0x1000 },
3144 + { ScTableProtection::PIVOT_TABLES, 0x2000 },
3145 + { ScTableProtection::SELECT_UNLOCKED_CELLS, 0x4000 },
3147 + { ScTableProtection::NONE, 0x0000 }
3150 + mnOptions = 0x0000;
3151 + ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab);
3155 -const BYTE* XclProtection::GetData( void ) const
3158 + for (int i = 0; aTable[i].nMask != 0x0000; ++i)
3160 + if ( pProtect->isOptionEnabled(aTable[i].eOption) )
3161 + mnOptions |= aTable[i].nMask;
3165 +void XclExpSheetProtectOptions::WriteBody( XclExpStream& rStrm )
3167 + sal_uInt16 nBytes = 0x0867;
3170 + sal_uChar nZero = 0x00;
3171 + for (int i = 0; i < 9; ++i)
3179 + rStrm << nBytes << nBytes;
3181 + rStrm << mnOptions;
3186 +// ============================================================================
3190 @@ -1393,6 +1416,253 @@ XclRefmode::XclRefmode( const ScDocument
3194 +// ============================================================================
3196 +XclExpFilePass::XclExpFilePass( const XclExpRoot& rRoot ) :
3197 + XclExpRecord(0x002F, 54),
3202 +XclExpFilePass::~XclExpFilePass()
3206 +void XclExpFilePass::WriteBody( XclExpStream& rStrm )
3208 + static const sal_uInt8 nDocId[] = {
3209 + 0x17, 0xf7, 0x01, 0x08, 0xea, 0xad, 0x30, 0x5c,
3210 + 0x1a, 0x95, 0xa5, 0x75, 0xd6, 0x79, 0xcd, 0x8d };
3213 + static const sal_uInt8 nSalt[] = {
3214 + 0xa4, 0x5b, 0xf7, 0xe9, 0x9f, 0x55, 0x21, 0xc5,
3215 + 0xc5, 0x56, 0xa8, 0x0d, 0x39, 0x05, 0x3a, 0xb4 };
3217 + // 0x0000 - neither standard nor strong encryption
3218 + // 0x0001 - standard or strong encryption
3219 + rStrm << static_cast<sal_uInt16>(0x0001);
3221 + // 0x0000 - non standard encryption
3222 + // 0x0001 - standard encryption
3223 + sal_uInt16 nStdEnc = 0x0001;
3224 + rStrm << nStdEnc << nStdEnc;
3226 + sal_uInt8 nSaltHash[16];
3227 + XclExpEncrypterRef xEnc( new XclExpBiff8Encrypter(mrRoot, nDocId, nSalt) );
3228 + xEnc->GetSaltDigest(nSaltHash);
3230 + rStrm.Write(nDocId, 16);
3231 + rStrm.Write(nSalt, 16);
3232 + rStrm.Write(nSaltHash, 16);
3234 + rStrm.SetEncrypter(xEnc);
3237 +// ============================================================================
3239 +XclExpFnGroupCount::XclExpFnGroupCount() :
3240 + XclExpRecord(0x009C, 2)
3244 +XclExpFnGroupCount::~XclExpFnGroupCount()
3248 +void XclExpFnGroupCount::WriteBody( XclExpStream& rStrm )
3250 + rStrm << static_cast<sal_uInt16>(14);
3253 +// ============================================================================
3255 +XclExpInterfaceHdr::XclExpInterfaceHdr() :
3256 + XclExpRecord(0x00E1, 2)
3260 +XclExpInterfaceHdr::~XclExpInterfaceHdr()
3264 +void XclExpInterfaceHdr::WriteBody( XclExpStream& rStrm )
3266 + // The value must be the same value as the CODEPAGE record.
3267 + rStrm.DisableEncryption();
3268 + rStrm << static_cast<sal_uInt16>(0x04B0);
3271 +// ============================================================================
3273 +XclExpInterfaceEnd::XclExpInterfaceEnd() :
3274 + XclExpRecord(0x00E2, 0)
3278 +XclExpInterfaceEnd::~XclExpInterfaceEnd()
3282 +void XclExpInterfaceEnd::WriteBody( XclExpStream& /*rStrm*/ )
3286 +// ============================================================================
3288 +XclExpMMS::XclExpMMS() :
3289 + XclExpRecord(0x00C1, 2)
3293 +XclExpMMS::~XclExpMMS()
3297 +void XclExpMMS::WriteBody( XclExpStream& rStrm )
3299 + rStrm << static_cast<sal_uInt16>(0x0000);
3302 +// ============================================================================
3304 +XclExpWriteAccess::XclExpWriteAccess() :
3305 + XclExpRecord(0x005C, 112)
3309 +XclExpWriteAccess::~XclExpWriteAccess()
3313 +void XclExpWriteAccess::WriteBody( XclExpStream& rStrm )
3315 + static const sal_uInt8 aData[] = {
3316 + 0x04, 0x00, 0x00, 'C', 'a', 'l', 'c', 0x20,
3317 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3318 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3319 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3320 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3321 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3322 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3323 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3324 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3325 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3326 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3327 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3328 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
3329 + 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
3331 + sal_Size nDataSize = sizeof(aData);
3332 + for (sal_Size i = 0; i < nDataSize; ++i)
3333 + rStrm << aData[i];
3336 +// ============================================================================
3338 +XclExpCodePage::XclExpCodePage() :
3339 + XclExpRecord(0x0042, 2)
3343 +XclExpCodePage::~XclExpCodePage()
3347 +void XclExpCodePage::WriteBody( XclExpStream& rStrm )
3349 + // 0x04B0 : UTF-16 (BIFF8)
3350 + rStrm << static_cast<sal_uInt16>(0x04B0);
3353 +// ============================================================================
3355 +XclExpDSF::XclExpDSF() :
3356 + XclExpRecord(0x0161, 2)
3360 +XclExpDSF::~XclExpDSF()
3364 +void XclExpDSF::WriteBody( XclExpStream& rStrm )
3366 + rStrm << static_cast<sal_uInt16>(0x0000);
3369 +// ============================================================================
3371 +XclExpProt4Rev::XclExpProt4Rev() :
3372 + XclExpRecord(0x01AF, 2)
3376 +XclExpProt4Rev::~XclExpProt4Rev()
3380 +void XclExpProt4Rev::WriteBody( XclExpStream& rStrm )
3382 + rStrm << static_cast<sal_uInt16>(0x0000);
3385 +// ============================================================================
3387 +XclExpProt4RevPass::XclExpProt4RevPass() :
3388 + XclExpRecord(0x01BC, 2)
3392 +XclExpProt4RevPass::~XclExpProt4RevPass()
3396 +void XclExpProt4RevPass::WriteBody( XclExpStream& rStrm )
3398 + rStrm << static_cast<sal_uInt16>(0x0000);
3401 +// ============================================================================
3403 +XclExpExcel9File::XclExpExcel9File() :
3404 + XclExpRecord(0x01C0, 0)
3408 +XclExpExcel9File::~XclExpExcel9File()
3412 +void XclExpExcel9File::WriteBody( XclExpStream& /*rStrm*/ )
3416 +// ============================================================================
3418 +static const sal_uInt8 nDataRecalcId[] = {
3419 + 0xC1, 0x01, 0x00, 0x00, 0x54, 0x8D, 0x01, 0x00
3422 +XclExpRecalcId::XclExpRecalcId() :
3423 + XclExpDummyRecord(0x01C1, nDataRecalcId, sizeof(nDataRecalcId))
3427 +// ============================================================================
3429 +static const sal_uInt8 nDataBookExt[] = {
3430 + 0x63, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3431 + 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3435 +XclExpBookExt::XclExpBookExt() :
3436 + XclExpDummyRecord(0x0863, nDataBookExt, sizeof(nDataBookExt))
3441 void XclRefmode::SaveXml( XclExpXmlStream& rStrm )
3443 rStrm.WriteAttributes(
3444 --- sc/source/filter/xml/xmlbodyi.cxx.old 2009-04-02 10:44:57.000000000 +0000
3445 +++ sc/source/filter/xml/xmlbodyi.cxx 2009-04-06 16:41:49.000000000 +0000
3447 #include "XMLTrackedChangesContext.hxx"
3448 #include "XMLEmptyContext.hxx"
3449 #include "scerrors.hxx"
3450 +#include "tabprotection.hxx"
3452 #include <xmloff/xmltkmap.hxx>
3453 #include <xmloff/xmltoken.hxx>
3455 #include <sal/types.h>
3456 #include <tools/debug.hxx>
3460 using rtl::OUString;
3461 using namespace com::sun::star;
3462 using namespace xmloff::token;
3463 @@ -281,10 +284,17 @@ void ScXMLBodyContext::EndElement()
3464 // #i37959# handle document protection after the sheet settings
3467 + ::std::auto_ptr<ScDocProtection> pProtection(new ScDocProtection);
3468 + pProtection->setProtected(true);
3470 uno::Sequence<sal_Int8> aPass;
3471 if (sPassword.getLength())
3473 SvXMLUnitConverter::decodeBase64(aPass, sPassword);
3474 - pDoc->SetDocProtection(bProtected, aPass);
3475 + pProtection->setPasswordHash(aPass, PASSHASH_OOO);
3478 + pDoc->SetDocProtection(pProtection.get());
3481 GetScImport().UnlockSolarMutex();
3482 --- sc/source/filter/xml/xmlexprt.cxx.old 2009-04-06 16:41:49.000000000 +0000
3483 +++ sc/source/filter/xml/xmlexprt.cxx 2009-04-06 16:41:49.000000000 +0000
3485 #include "convuno.hxx"
3486 #include "postit.hxx"
3487 #include "externalrefmgr.hxx"
3488 +#include "tabprotection.hxx"
3490 #include <xmloff/xmltoken.hxx>
3491 #include <xmloff/xmlnmspe.hxx>
3492 @@ -1439,7 +1440,11 @@ void ScXMLExport::SetBodyAttributes()
3494 AddAttribute(XML_NAMESPACE_TABLE, XML_STRUCTURE_PROTECTED, XML_TRUE);
3495 rtl::OUStringBuffer aBuffer;
3496 - SvXMLUnitConverter::encodeBase64(aBuffer, pDoc->GetDocPassword());
3497 + uno::Sequence<sal_Int8> aPassHash;
3498 + const ScDocProtection* p = pDoc->GetDocProtection();
3500 + aPassHash = p->getPasswordHash(PASSHASH_OOO);
3501 + SvXMLUnitConverter::encodeBase64(aBuffer, aPassHash);
3502 if (aBuffer.getLength())
3503 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
3505 @@ -1513,7 +1518,11 @@ void ScXMLExport::_ExportContent()
3506 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
3507 rtl::OUStringBuffer aBuffer;
3509 - SvXMLUnitConverter::encodeBase64(aBuffer, pDoc->GetTabPassword(static_cast<SCTAB>(nTable)));
3511 + ScTableProtection* pProtect = pDoc->GetTabProtection(static_cast<SCTAB>(nTable));
3513 + SvXMLUnitConverter::encodeBase64(aBuffer, pProtect->getPasswordHash(PASSHASH_OOO));
3515 if (aBuffer.getLength())
3516 AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTION_KEY, aBuffer.makeStringAndClear());
3518 --- sc/source/filter/xml/xmlsubti.cxx.old 2009-04-02 10:44:57.000000000 +0000
3519 +++ sc/source/filter/xml/xmlsubti.cxx 2009-04-06 16:41:49.000000000 +0000
3521 #include "docuno.hxx"
3522 #include "cellsuno.hxx"
3523 #include "XMLStylesImportHelper.hxx"
3524 +#include "tabprotection.hxx"
3526 #include <xmloff/xmltkmap.hxx>
3527 #include <xmloff/nmspmap.hxx>
3529 #include <com/sun/star/util/XProtectable.hpp>
3530 #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
3534 +using ::std::auto_ptr;
3536 //------------------------------------------------------------------
3538 using namespace com::sun::star;
3539 @@ -616,13 +621,10 @@ void ScMyTables::DeleteTable()
3541 uno::Sequence<sal_Int8> aPass;
3542 SvXMLUnitConverter::decodeBase64(aPass, sPassword);
3543 - rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), bProtection, aPass);
3544 - /*uno::Reference <util::XProtectable> xProtectable(xCurrentSheet, uno::UNO_QUERY);
3545 - if (xProtectable.is())
3547 - rtl::OUString sKey;
3548 - xProtectable->protect(sKey);
3550 + auto_ptr<ScTableProtection> pProtect(new ScTableProtection);
3551 + pProtect->setProtected(bProtection);
3552 + pProtect->setPasswordHash(aPass, PASSHASH_OOO);
3553 + rImport.GetDocument()->SetTabProtection(static_cast<SCTAB>(nCurrentSheet), pProtect.get());
3556 rImport.UnlockSolarMutex();
3557 --- sc/source/ui/docshell/docfunc.cxx.old 2009-04-02 10:45:27.000000000 +0000
3558 +++ sc/source/ui/docshell/docfunc.cxx 2009-04-06 16:41:49.000000000 +0000
3560 #include "editable.hxx"
3561 #include "compiler.hxx"
3562 #include "scui_def.hxx" //CHINA001
3563 +#include "tabprotection.hxx"
3567 using namespace com::sun::star;
3568 +using ::com::sun::star::uno::Sequence;
3570 // STATIC DATA -----------------------------------------------------------
3572 @@ -2861,103 +2866,156 @@ BOOL ScDocFunc::RemovePageBreak( BOOL bC
3574 //------------------------------------------------------------------------
3576 -BOOL lcl_ValidPassword( ScDocument* pDoc, SCTAB nTab,
3577 - const String& rPassword,
3578 - uno::Sequence<sal_Int8>* pReturnOld = NULL )
3579 +void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
3581 - uno::Sequence<sal_Int8> aOldPassword;
3582 - if ( nTab == TABLEID_DOC )
3584 - if (pDoc->IsDocProtected())
3585 - aOldPassword = pDoc->GetDocPassword();
3589 - if (pDoc->IsTabProtected(nTab))
3590 - aOldPassword = pDoc->GetTabPassword(nTab);
3592 + ScDocument* pDoc = rDocShell.GetDocument();
3595 - *pReturnOld = aOldPassword;
3596 + pDoc->SetTabProtection(nTab, &rProtect);
3597 + if (pDoc->IsUndoEnabled())
3599 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
3600 + DBG_ASSERT(pProtect, "ScDocFunc::Unprotect: ScTableProtection pointer is NULL!");
3603 + ::std::auto_ptr<ScTableProtection> p(new ScTableProtection(*pProtect));
3604 + p->setProtected(true); // just in case ...
3605 + rDocShell.GetUndoManager()->AddUndoAction(
3606 + new ScUndoTabProtect(&rDocShell, nTab, p) );
3608 - return ((aOldPassword.getLength() == 0) || SvPasswordHelper::CompareHashPassword(aOldPassword, rPassword));
3609 + // ownership of auto_ptr now transferred to ScUndoTabProtect.
3613 + rDocShell.PostPaintGridAll();
3614 + ScDocShellModificator aModificator(rDocShell);
3615 + aModificator.SetDocumentModified();
3618 -BOOL ScDocFunc::Protect( SCTAB nTab, const String& rPassword, BOOL bApi )
3619 +BOOL ScDocFunc::Protect( SCTAB nTab, const String& rPassword, BOOL /*bApi*/ )
3621 - ScDocShellModificator aModificator( rDocShell );
3622 + ScDocument* pDoc = rDocShell.GetDocument();
3623 + if (nTab == TABLEID_DOC)
3625 + // document protection
3626 + ScDocProtection aProtection;
3627 + aProtection.setProtected(true);
3628 + aProtection.setPassword(rPassword);
3629 + pDoc->SetDocProtection(&aProtection);
3630 + if (pDoc->IsUndoEnabled())
3632 + ScDocProtection* pProtect = pDoc->GetDocProtection();
3633 + DBG_ASSERT(pProtect, "ScDocFunc::Unprotect: ScDocProtection pointer is NULL!");
3636 + ::std::auto_ptr<ScDocProtection> p(new ScDocProtection(*pProtect));
3637 + p->setProtected(true); // just in case ...
3638 + rDocShell.GetUndoManager()->AddUndoAction(
3639 + new ScUndoDocProtect(&rDocShell, p) );
3640 + // ownership of auto_ptr is transferred to ScUndoDocProtect.
3646 + // sheet protection
3648 - ScDocument* pDoc = rDocShell.GetDocument();
3649 - BOOL bUndo(pDoc->IsUndoEnabled());
3650 - BOOL bOk = lcl_ValidPassword( pDoc, nTab, rPassword);
3653 - uno::Sequence<sal_Int8> aPass;
3654 - if (rPassword.Len())
3655 - SvPasswordHelper::GetHashPassword(aPass, rPassword);
3656 + ScTableProtection aProtection;
3657 + aProtection.setProtected(true);
3658 + aProtection.setPassword(rPassword);
3659 + pDoc->SetTabProtection(nTab, &aProtection);
3660 + if (pDoc->IsUndoEnabled())
3662 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
3663 + DBG_ASSERT(pProtect, "ScDocFunc::Unprotect: ScTableProtection pointer is NULL!");
3666 + ::std::auto_ptr<ScTableProtection> p(new ScTableProtection(*pProtect));
3667 + p->setProtected(true); // just in case ...
3668 + rDocShell.GetUndoManager()->AddUndoAction(
3669 + new ScUndoTabProtect(&rDocShell, nTab, p) );
3670 + // ownership of auto_ptr now transferred to ScUndoTabProtect.
3677 - rDocShell.GetUndoManager()->AddUndoAction(
3678 - new ScUndoProtect( &rDocShell, nTab, TRUE, aPass ) );
3680 + rDocShell.PostPaintGridAll();
3681 + ScDocShellModificator aModificator( rDocShell );
3682 + aModificator.SetDocumentModified();
3684 - if ( nTab == TABLEID_DOC )
3685 - pDoc->SetDocProtection( TRUE, aPass );
3687 - pDoc->SetTabProtection( nTab, TRUE, aPass );
3691 - rDocShell.PostPaintGridAll();
3692 - aModificator.SetDocumentModified();
3696 - // different password was set before
3697 +BOOL ScDocFunc::Unprotect( SCTAB nTab, const String& rPassword, BOOL bApi )
3699 + ScDocument* pDoc = rDocShell.GetDocument();
3701 -//! rDocShell.ErrorMessage(...);
3702 + if (nTab == TABLEID_DOC)
3704 + // document protection
3706 - InfoBox aBox( rDocShell.GetActiveDialogParent(), String( ScResId( SCSTR_WRONGPASSWORD ) ) );
3709 + ScDocProtection* pDocProtect = pDoc->GetDocProtection();
3710 + if (!pDocProtect || !pDocProtect->isProtected())
3711 + // already unprotected (should not happen)!
3716 + // save the protection state before unprotect (for undo).
3717 + ::std::auto_ptr<ScDocProtection> pProtectCopy(new ScDocProtection(*pDocProtect));
3719 -BOOL ScDocFunc::Unprotect( SCTAB nTab, const String& rPassword, BOOL bApi )
3721 - ScDocShellModificator aModificator( rDocShell );
3722 + if (!pDocProtect->verifyPassword(rPassword))
3726 + InfoBox aBox( rDocShell.GetActiveDialogParent(), String( ScResId( SCSTR_WRONGPASSWORD ) ) );
3732 - ScDocument* pDoc = rDocShell.GetDocument();
3733 - BOOL bUndo(pDoc->IsUndoEnabled());
3734 - uno::Sequence<sal_Int8> aOldPassword;
3735 - uno::Sequence<sal_Int8> aPass;
3736 - BOOL bOk = lcl_ValidPassword( pDoc, nTab, rPassword, &aOldPassword );
3739 - uno::Sequence<sal_Int8> aEmptyPass;
3740 - if ( nTab == TABLEID_DOC )
3741 - pDoc->SetDocProtection( FALSE, aEmptyPass );
3743 - pDoc->SetTabProtection( nTab, FALSE, aEmptyPass );
3744 + pDoc->SetDocProtection(NULL);
3745 + if (pDoc->IsUndoEnabled())
3747 + pProtectCopy->setProtected(false);
3748 + rDocShell.GetUndoManager()->AddUndoAction(
3749 + new ScUndoDocProtect(&rDocShell, pProtectCopy) );
3750 + // ownership of auto_ptr now transferred to ScUndoDocProtect.
3755 + // sheet protection
3759 - rDocShell.GetUndoManager()->AddUndoAction(
3760 - new ScUndoProtect( &rDocShell, nTab, FALSE, aOldPassword ) );
3762 + ScTableProtection* pTabProtect = pDoc->GetTabProtection(nTab);
3763 + if (!pTabProtect || !pTabProtect->isProtected())
3764 + // already unprotected (should not happen)!
3767 + // save the protection state before unprotect (for undo).
3768 + ::std::auto_ptr<ScTableProtection> pProtectCopy(new ScTableProtection(*pTabProtect));
3769 + if (!pTabProtect->verifyPassword(rPassword))
3773 + InfoBox aBox( rDocShell.GetActiveDialogParent(), String( ScResId( SCSTR_WRONGPASSWORD ) ) );
3779 - rDocShell.PostPaintGridAll();
3780 - aModificator.SetDocumentModified();
3784 -//! rDocShell.ErrorMessage(...);
3785 + pDoc->SetTabProtection(nTab, NULL);
3786 + if (pDoc->IsUndoEnabled())
3788 + pProtectCopy->setProtected(false);
3789 + rDocShell.GetUndoManager()->AddUndoAction(
3790 + new ScUndoTabProtect(&rDocShell, nTab, pProtectCopy) );
3791 + // ownership of auto_ptr now transferred to ScUndoTabProtect.
3795 - InfoBox aBox( rDocShell.GetActiveDialogParent(), String( ScResId( SCSTR_WRONGPASSWORD ) ) );
3798 + rDocShell.PostPaintGridAll();
3799 + ScDocShellModificator aModificator( rDocShell );
3800 + aModificator.SetDocumentModified();
3806 //------------------------------------------------------------------------
3807 --- sc/source/ui/docshell/docsh.cxx.old 2009-04-06 16:41:46.000000000 +0000
3808 +++ sc/source/ui/docshell/docsh.cxx 2009-04-06 16:41:49.000000000 +0000
3810 #include <sot/formats.hxx>
3811 #define SOT_FORMATSTR_ID_STARCALC_30 SOT_FORMATSTR_ID_STARCALC
3813 -//REMOVE #ifndef SO2_DECL_SVSTORAGESTREAM_DEFINED
3814 -//REMOVE #define SO2_DECL_SVSTORAGESTREAM_DEFINED
3815 -//REMOVE SO2_DECL_REF(SotStorageStream)
3818 // INCLUDE ---------------------------------------------------------------
3822 #include "scresid.hxx"
3824 #include "globstr.hrc"
3825 -//CHINA001 #include "tpstat.hxx"
3826 #include "scerrors.hxx"
3827 #include "brdcst.hxx"
3828 #include "stlpool.hxx"
3830 #include "cfgids.hxx"
3831 #include "warnpassword.hxx"
3832 #include "optsolver.hxx"
3833 +#include "tabprotection.hxx"
3835 #include "docsh.hxx"
3836 #include "docshimp.hxx"
3837 @@ -1323,6 +1318,16 @@ BOOL __EXPORT ScDocShell::SaveAs( SfxMed
3839 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::SaveAs" );
3841 +#if ENABLE_SHEET_PROTECTION
3842 + ScTabViewShell* pViewShell = GetBestViewShell();
3843 + if (pViewShell && ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_OOO))
3845 + if (!pViewShell->ExecuteRetypePassDlg(PASSHASH_OOO))
3846 + // password re-type cancelled. Don't save the document.
3851 ScRefreshTimerProtector( aDocument.GetRefreshTimerControlAddress() );
3853 PrepareSaveGuard aPrepareGuard( *this);
3854 @@ -1788,7 +1793,6 @@ void ScDocShell::AsciiSave( SvStream& rS
3855 rStream.SetNumberFormatInt( nOldNumberFormatInt );
3859 BOOL __EXPORT ScDocShell::ConvertTo( SfxMedium &rMed )
3861 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::ConvertTo" );
3862 @@ -1842,15 +1846,40 @@ BOOL __EXPORT ScDocShell::ConvertTo( Sfx
3863 aDocument.SetExtDocOptions( pExtDocOpt = new ScExtDocOptions );
3864 pViewShell->GetViewData()->WriteExtOptions( *pExtDocOpt );
3866 - /* #115980 #If the imported document contained an encrypted password -
3867 - determine if we should save without it. */
3868 - ScExtDocSettings& rDocSett = pExtDocOpt->GetDocSettings();
3869 - if( rDocSett.mbEncrypted )
3870 +#if ENABLE_SHEET_PROTECTION
3871 + bool bNeedRetypePassDlg = ScPassHashHelper::needsPassHashRegen(aDocument, PASSHASH_XL);
3872 + if (bNeedRetypePassDlg && !pViewShell->ExecuteRetypePassDlg(PASSHASH_XL))
3874 + SetError( ERRCODE_ABORT );
3878 + bool bEncrypted = false;
3882 + SfxItemSet* pSet = rMed.GetItemSet();
3886 + const SfxPoolItem* pItem = NULL;
3887 + if (SFX_ITEM_SET != pSet->GetItemState(SID_PASSWORD, sal_True, &pItem))
3888 + // password is not set.
3891 + /* #115980 #If the imported document contained an encrypted password -
3892 + determine if we should save without it. */
3893 bDoSave = ScWarnPassword::WarningOnPassword( rMed );
3894 - // #i42858# warn only on time
3895 - rDocSett.mbEncrypted = false;
3899 + // #i42858# warn only one time
3900 + pSet->ClearItem(SID_PASSWORD);
3909 --- sc/source/ui/docshell/docsh5.cxx.old 2009-04-02 10:45:27.000000000 +0000
3910 +++ sc/source/ui/docshell/docsh5.cxx 2009-04-06 16:41:49.000000000 +0000
3911 @@ -827,7 +827,7 @@ BOOL ScDocShell::MoveTable( SCTAB nSrcTa
3912 ++nAdjSource; // new position of source table after CopyTab
3914 if ( aDocument.IsTabProtected( nAdjSource ) )
3915 - aDocument.SetTabProtection( nDestTab, TRUE, aDocument.GetTabPassword( nAdjSource ) );
3916 + aDocument.CopyTabProtection(nAdjSource, nDestTab);
3920 --- sc/source/ui/inc/docfunc.hxx.old 2009-04-02 10:45:37.000000000 +0000
3921 +++ sc/source/ui/inc/docfunc.hxx 2009-04-06 16:41:49.000000000 +0000
3922 @@ -47,7 +47,7 @@ class ScRangeName;
3925 struct ScTabOpParam;
3927 +class ScTableProtection;
3929 // ---------------------------------------------------------------------------
3931 @@ -135,6 +135,8 @@ public:
3932 BOOL RemovePageBreak( BOOL bColumn, const ScAddress& rPos,
3933 BOOL bRecord, BOOL bSetModified, BOOL bApi );
3935 + void ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
3937 BOOL Protect( SCTAB nTab, const String& rPassword, BOOL bApi );
3938 BOOL Unprotect( SCTAB nTab, const String& rPassword, BOOL bApi );
3940 --- sc/source/ui/inc/protectiondlg.hrc.old 1970-01-01 00:00:00.000000000 +0000
3941 +++ sc/source/ui/inc/protectiondlg.hrc 2009-04-06 16:41:49.000000000 +0000
3943 +/*************************************************************************
3945 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3947 + * Copyright 2008 by Sun Microsystems, Inc.
3949 + * OpenOffice.org - a multi-platform office productivity suite
3951 + * $RCSfile: protectiondlg.hrc,v $
3952 + * $Revision: 1.1.2.1 $
3954 + * This file is part of OpenOffice.org.
3956 + * OpenOffice.org is free software: you can redistribute it and/or modify
3957 + * it under the terms of the GNU Lesser General Public License version 3
3958 + * only, as published by the Free Software Foundation.
3960 + * OpenOffice.org is distributed in the hope that it will be useful,
3961 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3962 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3963 + * GNU Lesser General Public License version 3 for more details
3964 + * (a copy is included in the LICENSE file that accompanied this code).
3966 + * You should have received a copy of the GNU Lesser General Public License
3967 + * version 3 along with OpenOffice.org. If not, see
3968 + * <http://www.openoffice.org/license.html>
3969 + * for a copy of the LGPLv3 License.
3971 + ************************************************************************/
3976 +#define BTN_CANCEL 2
3979 +#define BTN_PROTECT 4
3980 +#define FT_PASSWORD1 5
3981 +#define ED_PASSWORD1 6
3982 +#define FT_PASSWORD2 7
3983 +#define ED_PASSWORD2 8
3984 +#define FL_OPTIONS 9
3985 +#define FT_OPTIONS 10
3986 +#define CLB_OPTIONS 11
3988 +#define ST_SELECT_LOCKED_CELLS 50
3989 +#define ST_SELECT_UNLOCKED_CELLS 51
3990 --- sc/source/ui/inc/protectiondlg.hxx.old 1970-01-01 00:00:00.000000000 +0000
3991 +++ sc/source/ui/inc/protectiondlg.hxx 2009-04-06 16:41:49.000000000 +0000
3993 +/*************************************************************************
3995 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3997 + * Copyright 2008 by Sun Microsystems, Inc.
3999 + * OpenOffice.org - a multi-platform office productivity suite
4001 + * $RCSfile: protectiondlg.hxx,v $
4002 + * $Revision: 1.1.2.4 $
4004 + * This file is part of OpenOffice.org.
4006 + * OpenOffice.org is free software: you can redistribute it and/or modify
4007 + * it under the terms of the GNU Lesser General Public License version 3
4008 + * only, as published by the Free Software Foundation.
4010 + * OpenOffice.org is distributed in the hope that it will be useful,
4011 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4012 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4013 + * GNU Lesser General Public License version 3 for more details
4014 + * (a copy is included in the LICENSE file that accompanied this code).
4016 + * You should have received a copy of the GNU Lesser General Public License
4017 + * version 3 along with OpenOffice.org. If not, see
4018 + * <http://www.openoffice.org/license.html>
4019 + * for a copy of the LGPLv3 License.
4021 + ************************************************************************/
4023 +#ifndef SC_UI_PROTECTION_DLG_HXX
4024 +#define SC_UI_PROTECTION_DLG_HXX
4026 +#include <vcl/dialog.hxx>
4027 +#include <vcl/button.hxx>
4028 +#include <vcl/fixed.hxx>
4029 +#include <vcl/edit.hxx>
4030 +#include <svx/checklbx.hxx>
4033 +class ScTableProtection;
4035 +class ScTableProtectionDlg : public ModalDialog
4038 + explicit ScTableProtectionDlg(Window* pParent);
4039 + virtual ~ScTableProtectionDlg();
4041 + virtual short Execute();
4043 + void SetDialogData(const ScTableProtection& rData);
4045 + void WriteData(ScTableProtection& rData) const;
4048 + ScTableProtectionDlg(); // disabled
4052 + void EnableOptionalWidgets(bool bEnable = true);
4054 + CheckBox maBtnProtect;
4056 + FixedText maPassword1Text;
4057 + Edit maPassword1Edit;
4058 + FixedText maPassword2Text;
4059 + Edit maPassword2Edit;
4061 + FixedLine maOptionsLine;
4062 + FixedText maOptionsText;
4063 + SvxCheckListBox maOptionsListBox;
4066 + CancelButton maBtnCancel;
4067 + HelpButton maBtnHelp;
4069 + String maSelectLockedCells;
4070 + String maSelectUnlockedCells;
4072 + DECL_LINK( OKHdl, OKButton* );
4073 + DECL_LINK( CheckBoxHdl, CheckBox* );
4074 + DECL_LINK( PasswordModifyHdl, Edit* );
4078 --- sc/source/ui/inc/retypepassdlg.hrc.old 1970-01-01 00:00:00.000000000 +0000
4079 +++ sc/source/ui/inc/retypepassdlg.hrc 2009-04-06 16:41:49.000000000 +0000
4081 +/*************************************************************************
4083 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4085 + * Copyright 2008 by Sun Microsystems, Inc.
4087 + * OpenOffice.org - a multi-platform office productivity suite
4089 + * $RCSfile: retypepassdlg.hrc,v $
4090 + * $Revision: 1.1.2.2 $
4092 + * This file is part of OpenOffice.org.
4094 + * OpenOffice.org is free software: you can redistribute it and/or modify
4095 + * it under the terms of the GNU Lesser General Public License version 3
4096 + * only, as published by the Free Software Foundation.
4098 + * OpenOffice.org is distributed in the hope that it will be useful,
4099 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4101 + * GNU Lesser General Public License version 3 for more details
4102 + * (a copy is included in the LICENSE file that accompanied this code).
4104 + * You should have received a copy of the GNU Lesser General Public License
4105 + * version 3 along with OpenOffice.org. If not, see
4106 + * <http://www.openoffice.org/license.html>
4107 + * for a copy of the LGPLv3 License.
4109 + ************************************************************************/
4114 +#define BTN_CANCEL 2
4118 +#define FL_DOCUMENT 11
4119 +#define FT_DOCSTATUS 12
4120 +#define BTN_RETYPE_DOC 13
4122 +#define FL_SHEET 112
4124 +#define FT_SHEETNAME1 113
4125 +#define FT_SHEETSTATUS1 114
4126 +#define BTN_RETYPE_SHEET1 115
4128 +#define FT_SHEETNAME2 116
4129 +#define FT_SHEETSTATUS2 117
4130 +#define BTN_RETYPE_SHEET2 118
4132 +#define FT_SHEETNAME3 119
4133 +#define FT_SHEETSTATUS3 120
4134 +#define BTN_RETYPE_SHEET3 121
4136 +#define FT_SHEETNAME4 122
4137 +#define FT_SHEETSTATUS4 123
4138 +#define BTN_RETYPE_SHEET4 124
4140 +#define SB_SCROLL 190
4142 +#define STR_NOT_PROTECTED 200
4143 +#define STR_NOT_PASS_PROTECTED 201
4144 +#define STR_HASH_BAD 202
4145 +#define STR_HASH_GOOD 203
4146 +#define STR_HASH_REGENERATED 204
4148 +#define FT_PASSWORD1 301
4149 +#define ED_PASSWORD1 302
4150 +#define FT_PASSWORD2 303
4151 +#define ED_PASSWORD2 304
4152 +#define BTN_MATCH_OLD_PASSWORD 305
4153 +#define BTN_RETYPE_PASSWORD 306
4154 +#define BTN_REMOVE_PASSWORD 307
4155 --- sc/source/ui/inc/retypepassdlg.hxx.old 1970-01-01 00:00:00.000000000 +0000
4156 +++ sc/source/ui/inc/retypepassdlg.hxx 2009-04-06 16:41:49.000000000 +0000
4158 +/*************************************************************************
4160 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4162 + * Copyright 2008 by Sun Microsystems, Inc.
4164 + * OpenOffice.org - a multi-platform office productivity suite
4166 + * $RCSfile: retypepassdlg.hxx,v $
4167 + * $Revision: 1.1.2.7 $
4169 + * This file is part of OpenOffice.org.
4171 + * OpenOffice.org is free software: you can redistribute it and/or modify
4172 + * it under the terms of the GNU Lesser General Public License version 3
4173 + * only, as published by the Free Software Foundation.
4175 + * OpenOffice.org is distributed in the hope that it will be useful,
4176 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4177 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4178 + * GNU Lesser General Public License version 3 for more details
4179 + * (a copy is included in the LICENSE file that accompanied this code).
4181 + * You should have received a copy of the GNU Lesser General Public License
4182 + * version 3 along with OpenOffice.org. If not, see
4183 + * <http://www.openoffice.org/license.html>
4184 + * for a copy of the LGPLv3 License.
4186 + ************************************************************************/
4188 +#ifndef SC_UI_RETYPEPASS_DLG_HXX
4189 +#define SC_UI_RETYPEPASS_DLG_HXX
4191 +#include <vcl/dialog.hxx>
4192 +#include <vcl/button.hxx>
4193 +#include <vcl/fixed.hxx>
4194 +#include <vcl/edit.hxx>
4195 +#include <vcl/scrbar.hxx>
4196 +#include <svx/checklbx.hxx>
4197 +#include <svtools/stdctrl.hxx>
4199 +#include "tabprotection.hxx"
4201 +#include <boost/shared_ptr.hpp>
4204 +class ScDocProtection;
4205 +class ScTableProtection;
4208 +class ScRetypePassDlg : public ModalDialog
4211 + typedef ::boost::shared_ptr<ScDocProtection> DocProtectionPtr;
4212 + typedef ::boost::shared_ptr<ScTableProtection> TabProtectionPtr;
4214 + explicit ScRetypePassDlg(Window* pParent);
4215 + virtual ~ScRetypePassDlg();
4217 + virtual short Execute();
4219 + void SetData(const ScDocument& rDoc);
4220 + void SetDesiredHash(ScPasswordHash eHash);
4222 + /** Write the new set of password data to the document instance to
4223 + overwrite the current ones. */
4224 + void WriteNewDataToDocument(ScDocument& rDoc) const;
4227 + ScRetypePassDlg(); // disabled
4230 + void PopulateDialog();
4231 + void SetDocData();
4232 + void SetTableData(sal_uInt8 nRowPos, SCTAB nTab);
4233 + void ResetTableRows();
4235 + /** Check the status of all hash values to see if it's okay to enable
4237 + void CheckHashStatus();
4241 + CancelButton maBtnCancel;
4242 + HelpButton maBtnHelp;
4244 + FixedInfo maTextDescription;
4246 + FixedLine maLineDocument;
4247 + FixedText maTextDocStatus;
4248 + PushButton maBtnRetypeDoc;
4250 + FixedLine maLineSheet;
4251 + FixedText maTextSheetName1;
4252 + FixedText maTextSheetStatus1;
4253 + PushButton maBtnRetypeSheet1;
4255 + FixedText maTextSheetName2;
4256 + FixedText maTextSheetStatus2;
4257 + PushButton maBtnRetypeSheet2;
4259 + FixedText maTextSheetName3;
4260 + FixedText maTextSheetStatus3;
4261 + PushButton maBtnRetypeSheet3;
4263 + FixedText maTextSheetName4;
4264 + FixedText maTextSheetStatus4;
4265 + PushButton maBtnRetypeSheet4;
4267 + ScrollBar maScrollBar;
4269 + String maTextNotProtected;
4270 + String maTextNotPassProtected;
4271 + String maTextHashBad;
4272 + String maTextHashGood;
4273 + String maTextHashRegen;
4275 + DECL_LINK( OKHdl, OKButton* );
4276 + DECL_LINK( RetypeBtnHdl, PushButton* );
4277 + DECL_LINK( ScrollHdl, ScrollBar* );
4282 + TabProtectionPtr mpProtect;
4284 + ::std::vector<TableItem> maTableItems;
4286 + DocProtectionPtr mpDocItem;
4287 + size_t mnCurScrollPos;
4288 + ScPasswordHash meDesiredHash;
4291 +// ============================================================================
4293 +class ScRetypePassInputDlg : public ModalDialog
4296 + explicit ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected);
4297 + virtual ~ScRetypePassInputDlg();
4299 + virtual short Execute();
4301 + bool IsRemovePassword() const;
4302 + String GetNewPassword() const;
4305 + ScRetypePassInputDlg(); // disabled
4308 + void CheckPasswordInput();
4312 + CancelButton maBtnCancel;
4313 + HelpButton maBtnHelp;
4315 + RadioButton maBtnRetypePassword;
4317 + FixedText maPassword1Text;
4318 + Edit maPassword1Edit;
4319 + FixedText maPassword2Text;
4320 + Edit maPassword2Edit;
4322 + CheckBox maBtnMatchOldPass;
4324 + RadioButton maBtnRemovePassword;
4326 + DECL_LINK( OKHdl, OKButton* );
4327 + DECL_LINK( RadioBtnHdl, RadioButton* );
4328 + DECL_LINK( CheckBoxHdl, CheckBox* );
4329 + DECL_LINK( PasswordModifyHdl, Edit* );
4331 + ScPassHashProtectable* mpProtected;
4335 --- sc/source/ui/inc/tabvwsh.hxx.old 2009-04-06 16:41:41.000000000 +0000
4336 +++ sc/source/ui/inc/tabvwsh.hxx 2009-04-06 16:41:49.000000000 +0000
4338 #include "target.hxx"
4339 #include "rangelst.hxx" // ScRangeListRef
4340 #include "shellids.hxx"
4341 +#include "tabprotection.hxx" // for ScPasswordHash
4345 @@ -428,6 +429,8 @@ public:
4346 void BroadcastAccessibility( const SfxHint &rHint );
4347 BOOL HasAccessibilityObjects();
4349 + bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash);
4351 using ScTabView::ShowCursor;
4354 --- sc/source/ui/inc/undotab.hxx.old 2009-04-02 10:45:37.000000000 +0000
4355 +++ sc/source/ui/inc/undotab.hxx 2009-04-06 16:41:49.000000000 +0000
4358 #include <com/sun/star/uno/Sequence.hxx>
4364 class SdrUndoAction;
4365 class ScPrintRangeSaver;
4367 +class ScDocProtection;
4368 +class ScTableProtection;
4370 //----------------------------------------------------------------------------
4372 @@ -335,14 +339,15 @@ private:
4373 void DoChange( BOOL bShow ) const;
4376 +// ============================================================================
4378 -class ScUndoProtect : public ScSimpleUndo
4379 +/** This class implements undo & redo of document protect & unprotect
4381 +class ScUndoDocProtect : public ScSimpleUndo
4385 - ScUndoProtect( ScDocShell* pShell, SCTAB nNewTab,
4386 - BOOL bNewProtect, const com::sun::star::uno::Sequence<sal_Int8>& rNewPassword );
4387 - virtual ~ScUndoProtect();
4388 + ScUndoDocProtect(ScDocShell* pShell, ::std::auto_ptr<ScDocProtection> pProtectSettings);
4389 + virtual ~ScUndoDocProtect();
4391 virtual void Undo();
4392 virtual void Redo();
4393 @@ -352,11 +357,34 @@ public:
4394 virtual String GetComment() const;
4399 - com::sun::star::uno::Sequence<sal_Int8> aPassword;
4400 + ::std::auto_ptr<ScDocProtection> mpProtectSettings;
4402 + void DoProtect(bool bProtect);
4405 +// ============================================================================
4407 +/** This class implements undo & redo of both protect and unprotect of
4409 +class ScUndoTabProtect : public ScSimpleUndo
4412 + ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab,
4413 + ::std::auto_ptr<ScTableProtection> pProtectSettings);
4414 + virtual ~ScUndoTabProtect();
4416 + virtual void Undo();
4417 + virtual void Redo();
4418 + virtual void Repeat(SfxRepeatTarget& rTarget);
4419 + virtual BOOL CanRepeat(SfxRepeatTarget& rTarget) const;
4421 + virtual String GetComment() const;
4425 + ::std::auto_ptr<ScTableProtection> mpProtectSettings;
4427 - void DoProtect( BOOL bDo );
4428 + void DoProtect(bool bProtect);
4432 --- sc/source/ui/inc/viewfunc.hxx.old 2009-04-06 16:41:39.000000000 +0000
4433 +++ sc/source/ui/inc/viewfunc.hxx 2009-04-06 16:41:49.000000000 +0000
4434 @@ -69,6 +69,7 @@ class Exchange;
4436 class SvxHyperlinkItem;
4437 class ScTransferObj;
4438 +class ScTableProtection;
4440 namespace com { namespace sun { namespace star { namespace datatransfer { class XTransferable; } } } }
4442 @@ -199,6 +200,8 @@ public:
4444 void ChangeIndent( BOOL bIncrement );
4446 + void ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect );
4448 void Protect( SCTAB nTab, const String& rPassword );
4449 BOOL Unprotect( SCTAB nTab, const String& rPassword );
4451 --- sc/source/ui/miscdlgs/makefile.mk.old 2009-04-06 16:41:48.000000000 +0000
4452 +++ sc/source/ui/miscdlgs/makefile.mk 2009-04-06 16:41:49.000000000 +0000
4453 @@ -79,7 +79,9 @@ SLOFILES = \
4454 $(SLO)$/warnbox.obj \
4455 $(SLO)$/scuiautofmt.obj \
4456 $(SLO)$/conflictsdlg.obj \
4457 - $(SLO)$/sharedocdlg.obj
4458 + $(SLO)$/sharedocdlg.obj \
4459 + $(SLO)$/protectiondlg.obj \
4460 + $(SLO)$/retypepassdlg.obj
4463 $(SLO)$/acredlin.obj \
4464 @@ -88,7 +90,9 @@ EXCEPTIONSFILES = \
4465 $(SLO)$/optsolver.obj \
4466 $(SLO)$/solveroptions.obj \
4467 $(SLO)$/crnrdlg.obj \
4468 - $(SLO)$/solverutil.obj
4469 + $(SLO)$/solverutil.obj \
4470 + $(SLO)$/protectiondlg.obj \
4471 + $(SLO)$/retypepassdlg.obj
4475 @@ -97,7 +101,9 @@ SRC1FILES = \
4481 + protectiondlg.src \
4484 LIB1TARGET = $(SLB)$/$(TARGET).lib
4486 @@ -119,7 +125,9 @@ LIB1OBJFILES = \
4487 $(SLO)$/conflictsdlg.obj \
4488 $(SLO)$/sharedocdlg.obj \
4489 $(SLO)$/scuiautofmt.obj \
4490 - $(SLO)$/strindlg.obj
4491 + $(SLO)$/strindlg.obj \
4492 + $(SLO)$/protectiondlg.obj \
4493 + $(SLO)$/retypepassdlg.obj
4495 # --- Tagets -------------------------------------------------------
4497 --- sc/source/ui/miscdlgs/protectiondlg.cxx.old 1970-01-01 00:00:00.000000000 +0000
4498 +++ sc/source/ui/miscdlgs/protectiondlg.cxx 2009-04-06 16:41:49.000000000 +0000
4500 +/*************************************************************************
4502 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4504 + * Copyright 2008 by Sun Microsystems, Inc.
4506 + * OpenOffice.org - a multi-platform office productivity suite
4508 + * $RCSfile: protectiondlg.cxx,v $
4509 + * $Revision: 1.1.2.6 $
4511 + * This file is part of OpenOffice.org.
4513 + * OpenOffice.org is free software: you can redistribute it and/or modify
4514 + * it under the terms of the GNU Lesser General Public License version 3
4515 + * only, as published by the Free Software Foundation.
4517 + * OpenOffice.org is distributed in the hope that it will be useful,
4518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4520 + * GNU Lesser General Public License version 3 for more details
4521 + * (a copy is included in the LICENSE file that accompanied this code).
4523 + * You should have received a copy of the GNU Lesser General Public License
4524 + * version 3 along with OpenOffice.org. If not, see
4525 + * <http://www.openoffice.org/license.html>
4526 + * for a copy of the LGPLv3 License.
4528 + ************************************************************************/
4530 +#include "protectiondlg.hxx"
4531 +#include "protectiondlg.hrc"
4532 +#include "scresid.hxx"
4533 +#include "tabprotection.hxx"
4535 +#include <vcl/msgbox.hxx>
4538 +// The order must match that of the list box.
4539 +static const ScTableProtection::Option aOptions[] = {
4540 + ScTableProtection::SELECT_LOCKED_CELLS,
4541 + ScTableProtection::SELECT_UNLOCKED_CELLS,
4543 +static const USHORT nOptionCount = sizeof(aOptions)/sizeof(aOptions[0]);
4546 +ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) :
4547 + ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)),
4549 + maBtnProtect (this, ScResId(BTN_PROTECT)),
4550 + maPassword1Text (this, ScResId(FT_PASSWORD1)),
4551 + maPassword1Edit (this, ScResId(ED_PASSWORD1)),
4552 + maPassword2Text (this, ScResId(FT_PASSWORD2)),
4553 + maPassword2Edit (this, ScResId(ED_PASSWORD2)),
4554 + maOptionsLine (this, ScResId(FL_OPTIONS)),
4555 + maOptionsText (this, ScResId(FT_OPTIONS)),
4556 + maOptionsListBox(this, ScResId(CLB_OPTIONS)),
4558 + maBtnOk (this, ScResId(BTN_OK)),
4559 + maBtnCancel (this, ScResId(BTN_CANCEL)),
4560 + maBtnHelp (this, ScResId(BTN_HELP)),
4562 + maSelectLockedCells(ScResId(ST_SELECT_LOCKED_CELLS)),
4563 + maSelectUnlockedCells(ScResId(ST_SELECT_UNLOCKED_CELLS))
4569 +ScTableProtectionDlg::~ScTableProtectionDlg()
4573 +short ScTableProtectionDlg::Execute()
4575 + return ModalDialog::Execute();
4578 +void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
4580 + for (USHORT i = 0; i < nOptionCount; ++i)
4581 + maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
4584 +void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
4586 + rData.setProtected(maBtnProtect.IsChecked());
4588 + // We assume that the two password texts match.
4589 + rData.setPassword(maPassword1Edit.GetText());
4591 + for (USHORT i = 0; i < nOptionCount; ++i)
4592 + rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i));
4595 +void ScTableProtectionDlg::Init()
4597 + Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
4598 + maBtnProtect.SetClickHdl(aLink);
4600 + aLink = LINK( this, ScTableProtectionDlg, OKHdl );
4601 + maBtnOk.SetClickHdl(aLink);
4603 + aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
4604 + maPassword1Edit.SetModifyHdl(aLink);
4605 + maPassword2Edit.SetModifyHdl(aLink);
4607 + maOptionsListBox.SetUpdateMode(false);
4608 + maOptionsListBox.Clear();
4610 + maOptionsListBox.InsertEntry(maSelectLockedCells);
4611 + maOptionsListBox.InsertEntry(maSelectUnlockedCells);
4613 + maOptionsListBox.CheckEntryPos(0, true);
4614 + maOptionsListBox.CheckEntryPos(1, true);
4616 + maOptionsListBox.SetUpdateMode(true);
4618 + // Set the default state of the dialog.
4619 + maBtnProtect.Check(true);
4620 + maPassword1Edit.GrabFocus();
4623 +void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
4625 + maPassword1Text.Enable(bEnable);
4626 + maPassword1Edit.Enable(bEnable);
4627 + maPassword2Text.Enable(bEnable);
4628 + maPassword2Edit.Enable(bEnable);
4629 + maOptionsLine.Enable(bEnable);
4630 + maOptionsText.Enable(bEnable);
4632 + maOptionsListBox.Enable(bEnable);
4633 + maOptionsListBox.Invalidate();
4636 +IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
4638 + if (pBtn == &maBtnProtect)
4640 + bool bChecked = maBtnProtect.IsChecked();
4641 + EnableOptionalWidgets(bChecked);
4642 + maBtnOk.Enable(bChecked);
4648 +IMPL_LINK( ScTableProtectionDlg, OKHdl, OKButton*, EMPTYARG )
4650 + EndDialog(RET_OK);
4654 +IMPL_LINK( ScTableProtectionDlg, PasswordModifyHdl, Edit*, EMPTYARG )
4656 + String aPass1 = maPassword1Edit.GetText();
4657 + String aPass2 = maPassword2Edit.GetText();
4658 + maBtnOk.Enable(aPass1.Equals(aPass2));
4661 --- sc/source/ui/miscdlgs/protectiondlg.src.old 1970-01-01 00:00:00.000000000 +0000
4662 +++ sc/source/ui/miscdlgs/protectiondlg.src 2009-04-06 16:41:49.000000000 +0000
4664 +/*************************************************************************
4666 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4668 + * Copyright 2008 by Sun Microsystems, Inc.
4670 + * OpenOffice.org - a multi-platform office productivity suite
4672 + * $RCSfile: protectiondlg.src,v $
4673 + * $Revision: 1.1.2.6 $
4675 + * This file is part of OpenOffice.org.
4677 + * OpenOffice.org is free software: you can redistribute it and/or modify
4678 + * it under the terms of the GNU Lesser General Public License version 3
4679 + * only, as published by the Free Software Foundation.
4681 + * OpenOffice.org is distributed in the hope that it will be useful,
4682 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4683 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4684 + * GNU Lesser General Public License version 3 for more details
4685 + * (a copy is included in the LICENSE file that accompanied this code).
4687 + * You should have received a copy of the GNU Lesser General Public License
4688 + * version 3 along with OpenOffice.org. If not, see
4689 + * <http://www.openoffice.org/license.html>
4690 + * for a copy of the LGPLv3 License.
4692 + ************************************************************************/
4694 +#include "protectiondlg.hrc"
4696 +ModalDialog RID_SCDLG_TABPROTECTION
4698 + Text [ en-US ] = "Protect Sheet" ;
4699 + Size = MAP_APPFONT ( 220 , 135 ) ;
4701 + Closeable = TRUE ;
4705 + Pos = MAP_APPFONT ( 164 , 6 ) ;
4706 + Size = MAP_APPFONT ( 50 , 14 ) ;
4707 + DefButton = TRUE ;
4709 + CancelButton BTN_CANCEL
4711 + Pos = MAP_APPFONT ( 164 , 23 ) ;
4712 + Size = MAP_APPFONT ( 50 , 14 ) ;
4714 + HelpButton BTN_HELP
4716 + Pos = MAP_APPFONT ( 164 , 43 ) ;
4717 + Size = MAP_APPFONT ( 50 , 14 ) ;
4720 + CheckBox BTN_PROTECT
4722 + Pos = MAP_APPFONT ( 6 , 6 ) ;
4723 + Size = MAP_APPFONT ( 150 , 10 );
4725 + Text [ en-US ] = "P~rotect this sheet and the contents of locked cells" ;
4728 + FixedText FT_PASSWORD1
4730 + Pos = MAP_APPFONT ( 11, 23 );
4731 + Size = MAP_APPFONT ( 42, 10 );
4733 + Text [ en-US ] = "~Password" ;
4740 + Pos = MAP_APPFONT ( 56, 22 );
4741 + Size = MAP_APPFONT ( 75, 12 );
4744 + FixedText FT_PASSWORD2
4746 + Pos = MAP_APPFONT ( 11, 40 );
4747 + Size = MAP_APPFONT ( 42, 10 );
4749 + Text [ en-US ] = "~Confirm" ;
4756 + Pos = MAP_APPFONT ( 56, 39 );
4757 + Size = MAP_APPFONT ( 75, 12 );
4760 + FixedLine FL_OPTIONS
4762 + Pos = MAP_APPFONT ( 6, 60 );
4763 + Size = MAP_APPFONT ( 150, 8 );
4765 + Text [ en-US ] = "Options";
4768 + FixedText FT_OPTIONS
4770 + Pos = MAP_APPFONT ( 11, 74 );
4771 + Size = MAP_APPFONT ( 140, 8 );
4773 + Text [ en-US ] = "Allow all users of this sheet to:";
4776 + Control CLB_OPTIONS
4778 + Pos = MAP_APPFONT ( 11, 85 );
4779 + Size = MAP_APPFONT ( 140, 40 );
4784 + String ST_SELECT_LOCKED_CELLS
4786 + Text [ en-US ] = "Select locked cells";
4789 + String ST_SELECT_UNLOCKED_CELLS
4791 + Text [ en-US ] = "Select unlocked cells";
4794 --- sc/source/ui/miscdlgs/retypepassdlg.cxx.old 1970-01-01 00:00:00.000000000 +0000
4795 +++ sc/source/ui/miscdlgs/retypepassdlg.cxx 2009-04-06 16:41:49.000000000 +0000
4797 +/*************************************************************************
4799 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4801 + * Copyright 2008 by Sun Microsystems, Inc.
4803 + * OpenOffice.org - a multi-platform office productivity suite
4805 + * $RCSfile: retypepassdlg.cxx,v $
4806 + * $Revision: 1.1.2.7 $
4808 + * This file is part of OpenOffice.org.
4810 + * OpenOffice.org is free software: you can redistribute it and/or modify
4811 + * it under the terms of the GNU Lesser General Public License version 3
4812 + * only, as published by the Free Software Foundation.
4814 + * OpenOffice.org is distributed in the hope that it will be useful,
4815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4817 + * GNU Lesser General Public License version 3 for more details
4818 + * (a copy is included in the LICENSE file that accompanied this code).
4820 + * You should have received a copy of the GNU Lesser General Public License
4821 + * version 3 along with OpenOffice.org. If not, see
4822 + * <http://www.openoffice.org/license.html>
4823 + * for a copy of the LGPLv3 License.
4825 + ************************************************************************/
4827 +#include "retypepassdlg.hxx"
4828 +#include "retypepassdlg.hrc"
4829 +#include "scresid.hxx"
4830 +#include "document.hxx"
4831 +#include "tabprotection.hxx"
4835 +#include <vcl/msgbox.hxx>
4837 +ScRetypePassDlg::ScRetypePassDlg(Window* pParent) :
4838 + ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS)),
4840 + maBtnOk (this, ScResId(BTN_OK)),
4841 + maBtnCancel (this, ScResId(BTN_CANCEL)),
4842 + maBtnHelp (this, ScResId(BTN_HELP)),
4844 + maTextDescription(this, ScResId(FT_DESC)),
4845 + maLineDocument(this, ScResId(FL_DOCUMENT)),
4846 + maTextDocStatus(this, ScResId(FT_DOCSTATUS)),
4847 + maBtnRetypeDoc(this, ScResId(BTN_RETYPE_DOC)),
4849 + maLineSheet(this, ScResId(FL_SHEET)),
4850 + maTextSheetName1(this, ScResId(FT_SHEETNAME1)),
4851 + maTextSheetStatus1(this, ScResId(FT_SHEETSTATUS1)),
4852 + maBtnRetypeSheet1(this, ScResId(BTN_RETYPE_SHEET1)),
4854 + maTextSheetName2(this, ScResId(FT_SHEETNAME2)),
4855 + maTextSheetStatus2(this, ScResId(FT_SHEETSTATUS2)),
4856 + maBtnRetypeSheet2(this, ScResId(BTN_RETYPE_SHEET2)),
4858 + maTextSheetName3(this, ScResId(FT_SHEETNAME3)),
4859 + maTextSheetStatus3(this, ScResId(FT_SHEETSTATUS3)),
4860 + maBtnRetypeSheet3(this, ScResId(BTN_RETYPE_SHEET3)),
4862 + maTextSheetName4(this, ScResId(FT_SHEETNAME4)),
4863 + maTextSheetStatus4(this, ScResId(FT_SHEETSTATUS4)),
4864 + maBtnRetypeSheet4(this, ScResId(BTN_RETYPE_SHEET4)),
4866 + maScrollBar (this, ScResId(SB_SCROLL)),
4868 + maTextNotProtected(ScResId(STR_NOT_PROTECTED)),
4869 + maTextNotPassProtected(ScResId(STR_NOT_PASS_PROTECTED)),
4870 + maTextHashBad(ScResId(STR_HASH_BAD)),
4871 + maTextHashGood(ScResId(STR_HASH_GOOD)),
4872 + maTextHashRegen(ScResId(STR_HASH_REGENERATED)),
4874 + mpDocItem(static_cast<ScDocProtection*>(NULL)),
4875 + mnCurScrollPos(0),
4876 + meDesiredHash(PASSHASH_OOO)
4881 +ScRetypePassDlg::~ScRetypePassDlg()
4885 +short ScRetypePassDlg::Execute()
4888 + CheckHashStatus();
4889 + return ModalDialog::Execute();
4892 +void ScRetypePassDlg::SetData(const ScDocument& rDoc)
4894 + const ScDocProtection* pDocProtect = rDoc.GetDocProtection();
4895 + if (pDocProtect && pDocProtect->isProtected())
4896 + mpDocItem.reset(new ScDocProtection(*pDocProtect));
4898 + SCTAB nTabCount = rDoc.GetTableCount();
4899 + maTableItems.reserve(nTabCount);
4900 + for (SCTAB i = 0; i < nTabCount; ++i)
4902 + TableItem aTabItem;
4903 + rDoc.GetName(i, aTabItem.maName);
4905 + const ScTableProtection* pTabProtect = rDoc.GetTabProtection(i);
4906 + if (pTabProtect && pTabProtect->isProtected())
4907 + aTabItem.mpProtect.reset(new ScTableProtection(*pTabProtect));
4909 + maTableItems.push_back(aTabItem);
4913 +void ScRetypePassDlg::SetDesiredHash(ScPasswordHash eHash)
4915 + meDesiredHash = eHash;
4918 +void ScRetypePassDlg::WriteNewDataToDocument(ScDocument& rDoc) const
4920 + if (mpDocItem.get())
4921 + rDoc.SetDocProtection(mpDocItem.get());
4923 + size_t nTabCount = rDoc.GetTableCount();
4924 + size_t n = maTableItems.size();
4925 + for (size_t i = 0; i < n; ++i)
4927 + if (i >= nTabCount)
4930 + ScTableProtection* pTabProtect = maTableItems[i].mpProtect.get();
4932 + rDoc.SetTabProtection(static_cast<SCTAB>(i), pTabProtect);
4936 +void ScRetypePassDlg::Init()
4938 + Link aLink = LINK( this, ScRetypePassDlg, OKHdl );
4939 + maBtnOk.SetClickHdl(aLink);
4941 + aLink = LINK( this, ScRetypePassDlg, RetypeBtnHdl );
4942 + maBtnRetypeDoc.SetClickHdl(aLink);
4943 + maBtnRetypeSheet1.SetClickHdl(aLink);
4944 + maBtnRetypeSheet2.SetClickHdl(aLink);
4945 + maBtnRetypeSheet3.SetClickHdl(aLink);
4946 + maBtnRetypeSheet4.SetClickHdl(aLink);
4948 + maTextDocStatus.SetText(maTextNotProtected);
4949 + maTextSheetStatus1.SetText(maTextNotProtected);
4950 + maTextSheetStatus2.SetText(maTextNotProtected);
4951 + maTextSheetStatus3.SetText(maTextNotProtected);
4952 + maTextSheetStatus4.SetText(maTextNotProtected);
4953 + maBtnRetypeDoc.Disable();
4955 + // Make all sheet rows invisible.
4957 + maTextSheetName1.Show(false);
4958 + maTextSheetStatus1.Show(false);
4959 + maBtnRetypeSheet1.Show(false);
4960 + maBtnRetypeSheet1.Disable();
4962 + maTextSheetName2.Show(false);
4963 + maTextSheetStatus2.Show(false);
4964 + maBtnRetypeSheet2.Show(false);
4965 + maBtnRetypeSheet2.Disable();
4967 + maTextSheetName3.Show(false);
4968 + maTextSheetStatus3.Show(false);
4969 + maBtnRetypeSheet3.Show(false);
4970 + maBtnRetypeSheet3.Disable();
4972 + maTextSheetName4.Show(false);
4973 + maTextSheetStatus4.Show(false);
4974 + maBtnRetypeSheet4.Show(false);
4975 + maBtnRetypeSheet4.Disable();
4977 + maScrollBar.Show(false);
4979 + maScrollBar.SetEndScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
4980 + maScrollBar.SetScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
4982 + maScrollBar.SetPageSize(4);
4983 + maScrollBar.SetVisibleSize(4);
4984 + maScrollBar.SetLineSize(1);
4987 +void ScRetypePassDlg::PopulateDialog()
4989 + // Document protection first.
4992 + // Sheet protection next. We're only interested in the first 4 sheets
4994 + size_t n = maTableItems.size();
4995 + for (size_t i = 0; i < n && i < 4; ++i)
4996 + SetTableData(i, i);
5000 + maScrollBar.Show(true);
5001 + maScrollBar.SetRange(Range(0, n));
5005 +void ScRetypePassDlg::SetDocData()
5007 + bool bBtnEnabled = false;
5008 + if (mpDocItem.get() && mpDocItem->isProtected())
5010 + if (mpDocItem->isPasswordEmpty())
5011 + maTextDocStatus.SetText(maTextNotPassProtected);
5012 + else if (mpDocItem->hasPasswordHash(meDesiredHash))
5013 + maTextDocStatus.SetText(maTextHashGood);
5016 + // incompatible hash
5017 + maTextDocStatus.SetText(maTextHashBad);
5018 + bBtnEnabled = true;
5021 + maBtnRetypeDoc.Enable(bBtnEnabled);
5024 +void ScRetypePassDlg::SetTableData(sal_uInt8 nRowPos, SCTAB nTab)
5029 + FixedText* pName = NULL;
5030 + FixedText* pStatus = NULL;
5031 + PushButton* pBtn = NULL;
5035 + pName = &maTextSheetName1;
5036 + pStatus = &maTextSheetStatus1;
5037 + pBtn = &maBtnRetypeSheet1;
5040 + pName = &maTextSheetName2;
5041 + pStatus = &maTextSheetStatus2;
5042 + pBtn = &maBtnRetypeSheet2;
5045 + pName = &maTextSheetName3;
5046 + pStatus = &maTextSheetStatus3;
5047 + pBtn = &maBtnRetypeSheet3;
5050 + pName = &maTextSheetName4;
5051 + pStatus = &maTextSheetStatus4;
5052 + pBtn = &maBtnRetypeSheet4;
5058 + bool bBtnEnabled = false;
5059 + pName->SetText(maTableItems[nTab].maName);
5060 + pName->Show(true);
5061 + const ScTableProtection* pTabProtect = maTableItems[nTab].mpProtect.get();
5062 + if (pTabProtect && pTabProtect->isProtected())
5064 + if (pTabProtect->isPasswordEmpty())
5065 + pStatus->SetText(maTextNotPassProtected);
5066 + else if (pTabProtect->hasPasswordHash(meDesiredHash))
5067 + pStatus->SetText(maTextHashGood);
5070 + // incompatible hash
5071 + pStatus->SetText(maTextHashBad);
5072 + bBtnEnabled = true;
5076 + pStatus->SetText(maTextNotProtected);
5078 + pStatus->Show(true);
5080 + pBtn->Enable(bBtnEnabled);
5083 +void ScRetypePassDlg::ResetTableRows()
5085 + long nScrollPos = maScrollBar.GetThumbPos();
5086 + mnCurScrollPos = nScrollPos < 0 ? 0 : nScrollPos;
5087 + size_t nRowCount = maTableItems.size() - nScrollPos;
5088 + for (size_t i = 0; i < nRowCount; ++i)
5089 + SetTableData(i, i + nScrollPos);
5092 +bool lcl_IsInGoodStatus(ScPassHashProtectable* pProtected, ScPasswordHash eDesiredHash)
5094 + if (!pProtected || !pProtected->isProtected())
5098 + if (pProtected->isPasswordEmpty())
5101 + if (pProtected->hasPasswordHash(eDesiredHash))
5107 +void ScRetypePassDlg::CheckHashStatus()
5111 + if (!lcl_IsInGoodStatus(mpDocItem.get(), meDesiredHash))
5114 + bool bStatusGood = true;
5115 + size_t nTabCount = maTableItems.size();
5116 + for (size_t i = 0; i < nTabCount && bStatusGood; ++i)
5118 + if (!lcl_IsInGoodStatus(maTableItems[i].mpProtect.get(), meDesiredHash))
5119 + bStatusGood = false;
5129 + maBtnOk.Disable();
5132 +IMPL_LINK( ScRetypePassDlg, OKHdl, OKButton*, EMPTYARG )
5134 + EndDialog(RET_OK);
5138 +IMPL_LINK( ScRetypePassDlg, RetypeBtnHdl, PushButton*, pBtn )
5140 + ScPassHashProtectable* pProtected = NULL;
5141 + if (pBtn == &maBtnRetypeDoc)
5143 + // document protection.
5144 + pProtected = mpDocItem.get();
5148 + // sheet protection.
5149 + size_t nTabPos = mnCurScrollPos;
5150 + if (pBtn == &maBtnRetypeSheet2)
5152 + else if (pBtn == &maBtnRetypeSheet3)
5154 + else if (pBtn == &maBtnRetypeSheet4)
5156 + else if (pBtn != &maBtnRetypeSheet1)
5157 + // This should never happen !
5160 + if (nTabPos >= maTableItems.size())
5161 + // Likewise, this should never happen !
5164 + pProtected = maTableItems[nTabPos].mpProtect.get();
5168 + // What the ... !?
5171 + ScRetypePassInputDlg aDlg(this, pProtected);
5172 + if (aDlg.Execute() == RET_OK)
5174 + // OK is pressed. Update the protected item.
5175 + if (aDlg.IsRemovePassword())
5177 + // Remove password from this item.
5178 + pProtected->setPassword(String());
5182 + // Set a new password.
5183 + String aNewPass = aDlg.GetNewPassword();
5184 + pProtected->setPassword(aNewPass);
5189 + CheckHashStatus();
5194 +IMPL_LINK( ScRetypePassDlg, ScrollHdl, ScrollBar*, EMPTYARG )
5200 +// ============================================================================
5202 +ScRetypePassInputDlg::ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected) :
5203 + ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS_INPUT)),
5205 + maBtnOk (this, ScResId(BTN_OK)),
5206 + maBtnCancel (this, ScResId(BTN_CANCEL)),
5207 + maBtnHelp (this, ScResId(BTN_HELP)),
5209 + maBtnRetypePassword(this, ScResId(BTN_RETYPE_PASSWORD)),
5211 + maPassword1Text (this, ScResId(FT_PASSWORD1)),
5212 + maPassword1Edit (this, ScResId(ED_PASSWORD1)),
5213 + maPassword2Text (this, ScResId(FT_PASSWORD2)),
5214 + maPassword2Edit (this, ScResId(ED_PASSWORD2)),
5215 + maBtnMatchOldPass(this, ScResId(BTN_MATCH_OLD_PASSWORD)),
5217 + maBtnRemovePassword(this, ScResId(BTN_REMOVE_PASSWORD)),
5219 + mpProtected(pProtected)
5224 +ScRetypePassInputDlg::~ScRetypePassInputDlg()
5228 +short ScRetypePassInputDlg::Execute()
5230 + return ModalDialog::Execute();
5233 +bool ScRetypePassInputDlg::IsRemovePassword() const
5235 + return maBtnRemovePassword.IsChecked();
5238 +String ScRetypePassInputDlg::GetNewPassword() const
5240 + return maPassword1Edit.GetText();
5243 +void ScRetypePassInputDlg::Init()
5245 + Link aLink = LINK( this, ScRetypePassInputDlg, OKHdl );
5246 + maBtnOk.SetClickHdl(aLink);
5247 + aLink = LINK( this, ScRetypePassInputDlg, RadioBtnHdl );
5248 + maBtnRetypePassword.SetClickHdl(aLink);
5249 + maBtnRemovePassword.SetClickHdl(aLink);
5250 + aLink = LINK( this, ScRetypePassInputDlg, CheckBoxHdl );
5251 + maBtnMatchOldPass.SetClickHdl(aLink);
5252 + aLink = LINK( this, ScRetypePassInputDlg, PasswordModifyHdl );
5253 + maPassword1Edit.SetModifyHdl(aLink);
5254 + maPassword2Edit.SetModifyHdl(aLink);
5256 + maBtnOk.Disable();
5257 + maBtnRetypePassword.Check(true);
5258 + maBtnMatchOldPass.Check(true);
5259 + maPassword1Edit.GrabFocus();
5262 +void ScRetypePassInputDlg::CheckPasswordInput()
5264 + String aPass1 = maPassword1Edit.GetText();
5265 + String aPass2 = maPassword2Edit.GetText();
5267 + if (!aPass1.Len() || !aPass2.Len())
5269 + // Empty password is not allowed.
5270 + maBtnOk.Disable();
5274 + if (!aPass1.Equals(aPass2))
5276 + // The two passwords differ.
5277 + maBtnOk.Disable();
5281 + if (!maBtnMatchOldPass.IsChecked())
5289 + // This should never happen!
5290 + maBtnOk.Disable();
5294 + bool bPassGood = mpProtected->verifyPassword(aPass1);
5295 + maBtnOk.Enable(bPassGood);
5298 +IMPL_LINK( ScRetypePassInputDlg, OKHdl, OKButton*, EMPTYARG )
5300 + EndDialog(RET_OK);
5304 +IMPL_LINK( ScRetypePassInputDlg, RadioBtnHdl, RadioButton*, pBtn )
5306 + if (pBtn == &maBtnRetypePassword)
5308 + maBtnRemovePassword.Check(false);
5309 + maPassword1Text.Enable();
5310 + maPassword1Edit.Enable();
5311 + maPassword2Text.Enable();
5312 + maPassword2Edit.Enable();
5313 + maBtnMatchOldPass.Enable();
5314 + CheckPasswordInput();
5316 + else if (pBtn == &maBtnRemovePassword)
5318 + maBtnRetypePassword.Check(false);
5319 + maPassword1Text.Disable();
5320 + maPassword1Edit.Disable();
5321 + maPassword2Text.Disable();
5322 + maPassword2Edit.Disable();
5323 + maBtnMatchOldPass.Disable();
5330 +IMPL_LINK( ScRetypePassInputDlg, CheckBoxHdl, CheckBox*, EMPTYARG )
5332 + CheckPasswordInput();
5336 +IMPL_LINK( ScRetypePassInputDlg, PasswordModifyHdl, Edit*, EMPTYARG )
5338 + CheckPasswordInput();
5341 --- sc/source/ui/miscdlgs/retypepassdlg.src.old 1970-01-01 00:00:00.000000000 +0000
5342 +++ sc/source/ui/miscdlgs/retypepassdlg.src 2009-04-06 16:41:49.000000000 +0000
5344 +/*************************************************************************
5346 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5348 + * Copyright 2008 by Sun Microsystems, Inc.
5350 + * OpenOffice.org - a multi-platform office productivity suite
5352 + * $RCSfile: retypepassdlg.src,v $
5353 + * $Revision: 1.1.2.3 $
5355 + * This file is part of OpenOffice.org.
5357 + * OpenOffice.org is free software: you can redistribute it and/or modify
5358 + * it under the terms of the GNU Lesser General Public License version 3
5359 + * only, as published by the Free Software Foundation.
5361 + * OpenOffice.org is distributed in the hope that it will be useful,
5362 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5363 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5364 + * GNU Lesser General Public License version 3 for more details
5365 + * (a copy is included in the LICENSE file that accompanied this code).
5367 + * You should have received a copy of the GNU Lesser General Public License
5368 + * version 3 along with OpenOffice.org. If not, see
5369 + * <http://www.openoffice.org/license.html>
5370 + * for a copy of the LGPLv3 License.
5372 + ************************************************************************/
5374 +#include "retypepassdlg.hrc"
5377 +ModalDialog RID_SCDLG_RETYPEPASS
5379 + Text [ en-US ] = "Re-type Password" ;
5380 + Size = MAP_APPFONT ( 260 , 165 ) ;
5382 + Closeable = TRUE ;
5386 + Pos = MAP_APPFONT ( 204, 6 ) ;
5387 + Size = MAP_APPFONT ( 50, 14 ) ;
5388 + DefButton = TRUE ;
5391 + CancelButton BTN_CANCEL
5393 + Pos = MAP_APPFONT ( 204, 23 ) ;
5394 + Size = MAP_APPFONT ( 50, 14 ) ;
5397 + HelpButton BTN_HELP
5399 + Pos = MAP_APPFONT ( 204, 43 ) ;
5400 + Size = MAP_APPFONT ( 50, 14 ) ;
5405 + Pos = MAP_APPFONT ( 6, 6 ) ;
5406 + Size = MAP_APPFONT ( 190, 36 );
5408 + WordBreak = TRUE ;
5410 + 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." ;
5413 + FixedLine FL_DOCUMENT
5415 + Pos = MAP_APPFONT ( 6, 48 );
5416 + Size = MAP_APPFONT ( 190, 8 );
5418 + Text [ en-US ] = "Document protection" ;
5421 + FixedText FT_DOCSTATUS
5423 + Pos = MAP_APPFONT ( 10, 62 );
5424 + Size = MAP_APPFONT ( 140, 8 );
5426 + Text [ en-US ] = "Status unknown" ;
5429 + PushButton BTN_RETYPE_DOC
5431 + Pos = MAP_APPFONT ( 158, 59 );
5432 + Size = MAP_APPFONT ( 30, 14 );
5434 + Text [ en-US ] = "Re-type" ;
5437 + FixedLine FL_SHEET
5439 + Pos = MAP_APPFONT ( 6, 83 );
5440 + Size = MAP_APPFONT ( 190, 8 );
5442 + Text [ en-US ] = "Sheet protection" ;
5445 + FixedText FT_SHEETNAME1
5447 + Pos = MAP_APPFONT ( 10, 97 );
5448 + Size = MAP_APPFONT ( 68, 8 );
5450 + Text [ en-US ] = "Sheet1 has a really long name" ;
5453 + FixedText FT_SHEETSTATUS1
5455 + Pos = MAP_APPFONT ( 82, 97 );
5456 + Size = MAP_APPFONT ( 72, 8 );
5458 + Text [ en-US ] = "Status unknown" ;
5461 + PushButton BTN_RETYPE_SHEET1
5463 + Pos = MAP_APPFONT ( 158, 94 );
5464 + Size = MAP_APPFONT ( 30, 14 );
5466 + Text [ en-US ] = "Re-type" ;
5469 + FixedText FT_SHEETNAME2
5471 + Pos = MAP_APPFONT ( 10, 113 );
5472 + Size = MAP_APPFONT ( 68, 8 );
5474 + Text [ en-US ] = "Sheet2" ;
5477 + FixedText FT_SHEETSTATUS2
5479 + Pos = MAP_APPFONT ( 82, 113 );
5480 + Size = MAP_APPFONT ( 72, 8 );
5482 + Text [ en-US ] = "Status unknown" ;
5485 + PushButton BTN_RETYPE_SHEET2
5487 + Pos = MAP_APPFONT ( 158, 110 );
5488 + Size = MAP_APPFONT ( 30, 14 );
5490 + Text [ en-US ] = "Re-type" ;
5493 + FixedText FT_SHEETNAME3
5495 + Pos = MAP_APPFONT ( 10, 129 );
5496 + Size = MAP_APPFONT ( 68, 8 );
5498 + Text [ en-US ] = "Sheet3" ;
5501 + FixedText FT_SHEETSTATUS3
5503 + Pos = MAP_APPFONT ( 82, 129 );
5504 + Size = MAP_APPFONT ( 72, 8 );
5506 + Text [ en-US ] = "Status unknown" ;
5509 + PushButton BTN_RETYPE_SHEET3
5511 + Pos = MAP_APPFONT ( 158, 126 );
5512 + Size = MAP_APPFONT ( 30, 14 );
5514 + Text [ en-US ] = "Re-type" ;
5517 + FixedText FT_SHEETNAME4
5519 + Pos = MAP_APPFONT ( 10, 145 );
5520 + Size = MAP_APPFONT ( 68, 8 );
5522 + Text [ en-US ] = "Sheet4" ;
5525 + FixedText FT_SHEETSTATUS4
5527 + Pos = MAP_APPFONT ( 82, 145 );
5528 + Size = MAP_APPFONT ( 72, 8 );
5530 + Text [ en-US ] = "Status unknown" ;
5533 + PushButton BTN_RETYPE_SHEET4
5535 + Pos = MAP_APPFONT ( 158, 142 );
5536 + Size = MAP_APPFONT ( 30, 14 );
5538 + Text [ en-US ] = "Re-type" ;
5541 + ScrollBar SB_SCROLL
5543 + Pos = MAP_APPFONT ( 190, 94 ) ;
5544 + Size = MAP_APPFONT ( 8, 61 ) ;
5548 + String STR_NOT_PROTECTED
5550 + Text [ en-US ] = "Not protected" ;
5553 + String STR_NOT_PASS_PROTECTED
5555 + Text [ en-US ] = "Not password-protected" ;
5558 + String STR_HASH_BAD
5560 + Text [ en-US ] = "Hash incompatible" ;
5563 + String STR_HASH_GOOD
5565 + Text [ en-US ] = "Hash compatible" ;
5568 + String STR_HASH_REGENERATED
5570 + Text [ en-US ] = "Hash re-generated" ;
5574 +// ----------------------------------------------------------------------------
5576 +ModalDialog RID_SCDLG_RETYPEPASS_INPUT
5578 + Text [ en-US ] = "Re-type Password" ;
5579 + Size = MAP_APPFONT ( 230 , 110 ) ;
5581 + Closeable = TRUE ;
5585 + Pos = MAP_APPFONT ( 174, 6 ) ;
5586 + Size = MAP_APPFONT ( 50, 14 ) ;
5587 + DefButton = TRUE ;
5590 + CancelButton BTN_CANCEL
5592 + Pos = MAP_APPFONT ( 174, 23 ) ;
5593 + Size = MAP_APPFONT ( 50, 14 ) ;
5596 + HelpButton BTN_HELP
5598 + Pos = MAP_APPFONT ( 174, 43 ) ;
5599 + Size = MAP_APPFONT ( 50, 14 ) ;
5602 + RadioButton BTN_RETYPE_PASSWORD
5604 + Pos = MAP_APPFONT ( 11, 10 );
5605 + Size = MAP_APPFONT ( 150, 10 );
5607 + Text [ en-US ] = "Re-type password" ;
5610 + FixedText FT_PASSWORD1
5612 + Pos = MAP_APPFONT ( 20, 30 );
5613 + Size = MAP_APPFONT ( 42, 10 );
5615 + Text [ en-US ] = "~Password" ;
5622 + Pos = MAP_APPFONT ( 65, 29 );
5623 + Size = MAP_APPFONT ( 75, 12 );
5626 + FixedText FT_PASSWORD2
5628 + Pos = MAP_APPFONT ( 20, 45 );
5629 + Size = MAP_APPFONT ( 42, 10 );
5631 + Text [ en-US ] = "~Confirm" ;
5638 + Pos = MAP_APPFONT ( 65, 44 );
5639 + Size = MAP_APPFONT ( 75, 12 );
5642 + CheckBox BTN_MATCH_OLD_PASSWORD
5644 + Pos = MAP_APPFONT ( 20, 65 );
5645 + Size = MAP_APPFONT ( 150, 10 );
5647 + Text [ en-US ] = "New password must match the original password." ;
5650 + RadioButton BTN_REMOVE_PASSWORD
5652 + Pos = MAP_APPFONT ( 11, 90 );
5653 + Size = MAP_APPFONT ( 150, 10 );
5655 + Text [ en-US ] = "Remove password from this protected item." ;
5660 --- sc/source/ui/undo/undotab.cxx.old 2009-04-02 10:45:28.000000000 +0000
5661 +++ sc/source/ui/undo/undotab.cxx 2009-04-06 16:41:49.000000000 +0000
5663 #include "prnsave.hxx"
5664 #include "printfun.hxx"
5665 #include "chgtrack.hxx"
5666 +#include "tabprotection.hxx"
5668 // for ScUndoRenameObject - might me moved to another file later
5669 #include <svx/svditer.hxx>
5671 extern BOOL bDrawIsInUndo; //! irgendwo als Member !!!
5673 using namespace com::sun::star;
5674 +using ::com::sun::star::uno::Sequence;
5675 +using ::std::auto_ptr;
5677 // STATIC DATA -----------------------------------------------------------
5679 @@ -85,7 +88,6 @@ TYPEINIT1(ScUndoMakeScenario, SfxUndoAct
5680 TYPEINIT1(ScUndoImportTab, SfxUndoAction);
5681 TYPEINIT1(ScUndoRemoveLink, SfxUndoAction);
5682 TYPEINIT1(ScUndoShowHideTab, SfxUndoAction);
5683 -TYPEINIT1(ScUndoProtect, SfxUndoAction);
5684 TYPEINIT1(ScUndoPrintRange, SfxUndoAction);
5685 TYPEINIT1(ScUndoScenarioFlags, SfxUndoAction);
5686 TYPEINIT1(ScUndoRenameObject, SfxUndoAction);
5687 @@ -112,12 +114,12 @@ ScUndoInsertTab::ScUndoInsertTab( ScDocS
5691 -__EXPORT ScUndoInsertTab::~ScUndoInsertTab()
5692 +ScUndoInsertTab::~ScUndoInsertTab()
5694 DeleteSdrUndoAction( pDrawUndo );
5697 -String __EXPORT ScUndoInsertTab::GetComment() const
5698 +String ScUndoInsertTab::GetComment() const
5701 return ScGlobal::GetRscString( STR_UNDO_APPEND_TAB );
5702 @@ -138,7 +140,7 @@ void ScUndoInsertTab::SetChangeTrack()
5703 nEndChangeAction = 0;
5706 -void __EXPORT ScUndoInsertTab::Undo()
5707 +void ScUndoInsertTab::Undo()
5709 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
5710 pViewShell->SetTabNo(nTab);
5711 @@ -159,7 +161,7 @@ void __EXPORT ScUndoInsertTab::Undo()
5712 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
5715 -void __EXPORT ScUndoInsertTab::Redo()
5716 +void ScUndoInsertTab::Redo()
5718 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
5720 @@ -180,14 +182,14 @@ void __EXPORT ScUndoInsertTab::Redo()
5724 -void __EXPORT ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
5725 +void ScUndoInsertTab::Repeat(SfxRepeatTarget& rTarget)
5727 if (rTarget.ISA(ScTabViewTarget))
5728 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
5729 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
5732 -BOOL __EXPORT ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
5733 +BOOL ScUndoInsertTab::CanRepeat(SfxRepeatTarget& rTarget) const
5735 return (rTarget.ISA(ScTabViewTarget));
5737 @@ -211,7 +213,7 @@ ScUndoInsertTables::ScUndoInsertTables(
5741 -__EXPORT ScUndoInsertTables::~ScUndoInsertTables()
5742 +ScUndoInsertTables::~ScUndoInsertTables()
5746 @@ -227,7 +229,7 @@ __EXPORT ScUndoInsertTables::~ScUndoInse
5747 DeleteSdrUndoAction( pDrawUndo );
5750 -String __EXPORT ScUndoInsertTables::GetComment() const
5751 +String ScUndoInsertTables::GetComment() const
5753 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
5755 @@ -252,7 +254,7 @@ void ScUndoInsertTables::SetChangeTrack(
5756 nStartChangeAction = nEndChangeAction = 0;
5759 -void __EXPORT ScUndoInsertTables::Undo()
5760 +void ScUndoInsertTables::Undo()
5762 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
5763 pViewShell->SetTabNo(nTab);
5764 @@ -282,7 +284,7 @@ void __EXPORT ScUndoInsertTables::Undo()
5765 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
5768 -void __EXPORT ScUndoInsertTables::Redo()
5769 +void ScUndoInsertTables::Redo()
5771 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
5773 @@ -299,14 +301,14 @@ void __EXPORT ScUndoInsertTables::Redo()
5777 -void __EXPORT ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
5778 +void ScUndoInsertTables::Repeat(SfxRepeatTarget& rTarget)
5780 if (rTarget.ISA(ScTabViewTarget))
5781 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
5782 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
5785 -BOOL __EXPORT ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
5786 +BOOL ScUndoInsertTables::CanRepeat(SfxRepeatTarget& rTarget) const
5788 return (rTarget.ISA(ScTabViewTarget));
5790 @@ -327,12 +329,12 @@ ScUndoDeleteTab::ScUndoDeleteTab( ScDocS
5794 -__EXPORT ScUndoDeleteTab::~ScUndoDeleteTab()
5795 +ScUndoDeleteTab::~ScUndoDeleteTab()
5797 theTabs.Remove(0,theTabs.Count());
5800 -String __EXPORT ScUndoDeleteTab::GetComment() const
5801 +String ScUndoDeleteTab::GetComment() const
5803 return ScGlobal::GetRscString( STR_UNDO_DELETE_TAB );
5805 @@ -366,7 +368,7 @@ SCTAB lcl_GetVisibleTabBefore( ScDocumen
5809 -void __EXPORT ScUndoDeleteTab::Undo()
5810 +void ScUndoDeleteTab::Undo()
5814 @@ -414,7 +416,7 @@ void __EXPORT ScUndoDeleteTab::Undo()
5815 pDoc->SetVisible( nTab, pRefUndoDoc->IsVisible( nTab ) );
5817 if ( pRefUndoDoc->IsTabProtected( nTab ) )
5818 - pDoc->SetTabProtection( nTab, TRUE, pRefUndoDoc->GetTabPassword( nTab ) );
5819 + pDoc->SetTabProtection(nTab, pRefUndoDoc->GetTabProtection(nTab));
5821 // Drawing-Layer passiert beim MoveUndo::EndUndo
5822 // pDoc->TransferDrawPage(pRefUndoDoc, nTab,nTab);
5823 @@ -450,7 +452,7 @@ void __EXPORT ScUndoDeleteTab::Undo()
5827 -void __EXPORT ScUndoDeleteTab::Redo()
5828 +void ScUndoDeleteTab::Redo()
5830 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
5831 pViewShell->SetTabNo( lcl_GetVisibleTabBefore( *pDocShell->GetDocument(), theTabs[0] ) );
5832 @@ -469,7 +471,7 @@ void __EXPORT ScUndoDeleteTab::Redo()
5833 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
5836 -void __EXPORT ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
5837 +void ScUndoDeleteTab::Repeat(SfxRepeatTarget& rTarget)
5839 if (rTarget.ISA(ScTabViewTarget))
5841 @@ -478,7 +480,7 @@ void __EXPORT ScUndoDeleteTab::Repeat(Sf
5845 -BOOL __EXPORT ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
5846 +BOOL ScUndoDeleteTab::CanRepeat(SfxRepeatTarget& rTarget) const
5848 return (rTarget.ISA(ScTabViewTarget));
5850 @@ -500,11 +502,11 @@ ScUndoRenameTab::ScUndoRenameTab( ScDocS
5851 sNewName = rNewName;
5854 -__EXPORT ScUndoRenameTab::~ScUndoRenameTab()
5855 +ScUndoRenameTab::~ScUndoRenameTab()
5859 -String __EXPORT ScUndoRenameTab::GetComment() const
5860 +String ScUndoRenameTab::GetComment() const
5862 return ScGlobal::GetRscString( STR_UNDO_RENAME_TAB );
5864 @@ -526,22 +528,22 @@ void ScUndoRenameTab::DoChange( SCTAB nT
5865 pViewShell->UpdateInputHandler();
5868 -void __EXPORT ScUndoRenameTab::Undo()
5869 +void ScUndoRenameTab::Undo()
5871 DoChange(nTab, sOldName);
5874 -void __EXPORT ScUndoRenameTab::Redo()
5875 +void ScUndoRenameTab::Redo()
5877 DoChange(nTab, sNewName);
5880 -void __EXPORT ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
5881 +void ScUndoRenameTab::Repeat(SfxRepeatTarget& /* rTarget */)
5883 // Repeat macht keinen Sinn
5886 -BOOL __EXPORT ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
5887 +BOOL ScUndoRenameTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
5891 @@ -565,13 +567,13 @@ ScUndoMoveTab::ScUndoMoveTab( ScDocShell
5892 theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
5895 -__EXPORT ScUndoMoveTab::~ScUndoMoveTab()
5896 +ScUndoMoveTab::~ScUndoMoveTab()
5898 theNewTabs.Remove(0,theNewTabs.Count());
5899 theOldTabs.Remove(0,theOldTabs.Count());
5902 -String __EXPORT ScUndoMoveTab::GetComment() const
5903 +String ScUndoMoveTab::GetComment() const
5905 return ScGlobal::GetRscString( STR_UNDO_MOVE_TAB );
5907 @@ -618,22 +620,22 @@ void ScUndoMoveTab::DoChange( BOOL bUndo
5908 pDocShell->PostDataChanged();
5911 -void __EXPORT ScUndoMoveTab::Undo()
5912 +void ScUndoMoveTab::Undo()
5917 -void __EXPORT ScUndoMoveTab::Redo()
5918 +void ScUndoMoveTab::Redo()
5923 -void __EXPORT ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
5924 +void ScUndoMoveTab::Repeat(SfxRepeatTarget& /* rTarget */)
5926 // kein Repeat ! ? !
5929 -BOOL __EXPORT ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
5930 +BOOL ScUndoMoveTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
5934 @@ -660,12 +662,12 @@ ScUndoCopyTab::ScUndoCopyTab( ScDocShell
5935 theNewTabs.Insert(aNewTab[sal::static_int_cast<USHORT>(i)],theNewTabs.Count());
5938 -__EXPORT ScUndoCopyTab::~ScUndoCopyTab()
5939 +ScUndoCopyTab::~ScUndoCopyTab()
5941 DeleteSdrUndoAction( pDrawUndo );
5944 -String __EXPORT ScUndoCopyTab::GetComment() const
5945 +String ScUndoCopyTab::GetComment() const
5947 return ScGlobal::GetRscString( STR_UNDO_COPY_TAB );
5949 @@ -684,7 +686,7 @@ void ScUndoCopyTab::DoChange() const
5950 pDocShell->PostDataChanged();
5953 -void __EXPORT ScUndoCopyTab::Undo()
5954 +void ScUndoCopyTab::Undo()
5956 ScDocument* pDoc = pDocShell->GetDocument();
5958 @@ -717,7 +719,7 @@ void __EXPORT ScUndoCopyTab::Undo()
5962 -void __EXPORT ScUndoCopyTab::Redo()
5963 +void ScUndoCopyTab::Redo()
5965 ScDocument* pDoc = pDocShell->GetDocument();
5966 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
5967 @@ -756,7 +758,7 @@ void __EXPORT ScUndoCopyTab::Redo()
5970 if ( pDoc->IsTabProtected( nAdjSource ) )
5971 - pDoc->SetTabProtection( nNewTab, TRUE, pDoc->GetTabPassword( nAdjSource ) );
5972 + pDoc->CopyTabProtection(nAdjSource, nNewTab);
5975 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
5976 @@ -767,12 +769,12 @@ void __EXPORT ScUndoCopyTab::Redo()
5980 -void __EXPORT ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
5981 +void ScUndoCopyTab::Repeat(SfxRepeatTarget& /* rTarget */)
5983 // kein Repeat ! ? !
5986 -BOOL __EXPORT ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
5987 +BOOL ScUndoCopyTab::CanRepeat(SfxRepeatTarget& /* rTarget */) const
5991 @@ -801,17 +803,17 @@ ScUndoMakeScenario::ScUndoMakeScenario(
5992 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
5995 -__EXPORT ScUndoMakeScenario::~ScUndoMakeScenario()
5996 +ScUndoMakeScenario::~ScUndoMakeScenario()
5998 DeleteSdrUndoAction( pDrawUndo );
6001 -String __EXPORT ScUndoMakeScenario::GetComment() const
6002 +String ScUndoMakeScenario::GetComment() const
6004 return ScGlobal::GetRscString( STR_UNDO_MAKESCENARIO );
6007 -void __EXPORT ScUndoMakeScenario::Undo()
6008 +void ScUndoMakeScenario::Undo()
6010 ScDocument* pDoc = pDocShell->GetDocument();
6012 @@ -836,7 +838,7 @@ void __EXPORT ScUndoMakeScenario::Undo()
6013 pDocShell->Broadcast( SfxSimpleHint( SC_HINT_FORCESETTAB ) );
6016 -void __EXPORT ScUndoMakeScenario::Redo()
6017 +void ScUndoMakeScenario::Redo()
6019 ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
6021 @@ -858,7 +860,7 @@ void __EXPORT ScUndoMakeScenario::Redo()
6022 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
6025 -void __EXPORT ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
6026 +void ScUndoMakeScenario::Repeat(SfxRepeatTarget& rTarget)
6028 if (rTarget.ISA(ScTabViewTarget))
6030 @@ -866,7 +868,7 @@ void __EXPORT ScUndoMakeScenario::Repeat
6034 -BOOL __EXPORT ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
6035 +BOOL ScUndoMakeScenario::CanRepeat(SfxRepeatTarget& rTarget) const
6037 return (rTarget.ISA(ScTabViewTarget));
6039 @@ -889,13 +891,13 @@ ScUndoImportTab::ScUndoImportTab( ScDocS
6040 pDrawUndo = GetSdrUndoAction( pDocShell->GetDocument() );
6043 -__EXPORT ScUndoImportTab::~ScUndoImportTab()
6044 +ScUndoImportTab::~ScUndoImportTab()
6047 DeleteSdrUndoAction( pDrawUndo );
6050 -String __EXPORT ScUndoImportTab::GetComment() const
6051 +String ScUndoImportTab::GetComment() const
6053 return ScGlobal::GetRscString( STR_UNDO_INSERT_TAB );
6055 @@ -922,7 +924,7 @@ void ScUndoImportTab::DoChange() const
6056 PAINT_GRID | PAINT_TOP | PAINT_LEFT | PAINT_EXTRAS );
6059 -void __EXPORT ScUndoImportTab::Undo()
6060 +void ScUndoImportTab::Undo()
6062 //! eingefuegte Bereichsnamen etc.
6064 @@ -958,7 +960,7 @@ void __EXPORT ScUndoImportTab::Undo()
6067 if ( pDoc->IsTabProtected( nTabPos ) )
6068 - pRedoDoc->SetTabProtection( nTabPos, TRUE, pDoc->GetTabPassword( nTabPos ) );
6069 + pRedoDoc->SetTabProtection(nTabPos, pDoc->GetTabProtection(nTabPos));
6073 @@ -973,7 +975,7 @@ void __EXPORT ScUndoImportTab::Undo()
6077 -void __EXPORT ScUndoImportTab::Redo()
6078 +void ScUndoImportTab::Redo()
6082 @@ -1012,7 +1014,7 @@ void __EXPORT ScUndoImportTab::Redo()
6085 if ( pRedoDoc->IsTabProtected( nTabPos ) )
6086 - pDoc->SetTabProtection( nTabPos, TRUE, pRedoDoc->GetTabPassword( nTabPos ) );
6087 + pDoc->SetTabProtection(nTabPos, pRedoDoc->GetTabProtection(nTabPos));
6090 RedoSdrUndoAction( pDrawUndo ); // after the sheets are inserted
6091 @@ -1020,14 +1022,14 @@ void __EXPORT ScUndoImportTab::Redo()
6095 -void __EXPORT ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
6096 +void ScUndoImportTab::Repeat(SfxRepeatTarget& rTarget)
6098 if (rTarget.ISA(ScTabViewTarget))
6099 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
6100 Execute(FID_INS_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
6103 -BOOL __EXPORT ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
6104 +BOOL ScUndoImportTab::CanRepeat(SfxRepeatTarget& rTarget) const
6106 return (rTarget.ISA(ScTabViewTarget));
6108 @@ -1075,14 +1077,14 @@ ScUndoRemoveLink::ScUndoRemoveLink( ScDo
6112 -__EXPORT ScUndoRemoveLink::~ScUndoRemoveLink()
6113 +ScUndoRemoveLink::~ScUndoRemoveLink()
6120 -String __EXPORT ScUndoRemoveLink::GetComment() const
6121 +String ScUndoRemoveLink::GetComment() const
6123 return ScGlobal::GetRscString( STR_UNDO_REMOVELINK );
6125 @@ -1099,22 +1101,22 @@ void ScUndoRemoveLink::DoChange( BOOL bL
6126 pDocShell->UpdateLinks();
6129 -void __EXPORT ScUndoRemoveLink::Undo()
6130 +void ScUndoRemoveLink::Undo()
6135 -void __EXPORT ScUndoRemoveLink::Redo()
6136 +void ScUndoRemoveLink::Redo()
6141 -void __EXPORT ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
6142 +void ScUndoRemoveLink::Repeat(SfxRepeatTarget& /* rTarget */)
6147 -BOOL __EXPORT ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6148 +BOOL ScUndoRemoveLink::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6152 @@ -1132,7 +1134,7 @@ ScUndoShowHideTab::ScUndoShowHideTab( Sc
6156 -__EXPORT ScUndoShowHideTab::~ScUndoShowHideTab()
6157 +ScUndoShowHideTab::~ScUndoShowHideTab()
6161 @@ -1149,17 +1151,17 @@ void ScUndoShowHideTab::DoChange( BOOL b
6162 pDocShell->SetDocumentModified();
6165 -void __EXPORT ScUndoShowHideTab::Undo()
6166 +void ScUndoShowHideTab::Undo()
6171 -void __EXPORT ScUndoShowHideTab::Redo()
6172 +void ScUndoShowHideTab::Redo()
6177 -void __EXPORT ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
6178 +void ScUndoShowHideTab::Repeat(SfxRepeatTarget& rTarget)
6180 if (rTarget.ISA(ScTabViewTarget))
6181 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
6182 @@ -1167,97 +1169,154 @@ void __EXPORT ScUndoShowHideTab::Repeat(
6183 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
6186 -BOOL __EXPORT ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
6187 +BOOL ScUndoShowHideTab::CanRepeat(SfxRepeatTarget& rTarget) const
6189 return (rTarget.ISA(ScTabViewTarget));
6192 -String __EXPORT ScUndoShowHideTab::GetComment() const
6193 +String ScUndoShowHideTab::GetComment() const
6195 USHORT nId = bShow ? STR_UNDO_SHOWTAB : STR_UNDO_HIDETAB;
6196 return ScGlobal::GetRscString( nId );
6199 -// -----------------------------------------------------------------------
6201 -// Tabelle/Dokument schuetzen oder Schutz aufheben
6203 +// ============================================================================
6205 -ScUndoProtect::ScUndoProtect( ScDocShell* pShell, SCTAB nNewTab,
6206 - BOOL bNewProtect, const uno::Sequence<sal_Int8>& rNewPassword ) :
6207 - ScSimpleUndo( pShell ),
6209 - bProtect( bNewProtect ),
6210 - aPassword( rNewPassword )
6211 +ScUndoDocProtect::ScUndoDocProtect(ScDocShell* pShell, auto_ptr<ScDocProtection> pProtectSettings) :
6212 + ScSimpleUndo(pShell),
6213 + mpProtectSettings(pProtectSettings)
6217 -__EXPORT ScUndoProtect::~ScUndoProtect()
6218 +ScUndoDocProtect::~ScUndoDocProtect()
6222 -void ScUndoProtect::DoProtect( BOOL bDo )
6223 +void ScUndoDocProtect::DoProtect(bool bProtect)
6225 - ScDocument* pDoc = pDocShell->GetDocument();
6226 + ScDocument* pDoc = pDocShell->GetDocument();
6230 - if ( nTab == TABLEID_DOC )
6231 - pDoc->SetDocProtection( TRUE, aPassword );
6233 - pDoc->SetTabProtection( nTab, TRUE, aPassword );
6237 - uno::Sequence<sal_Int8> aEmptyPass;
6238 - if ( nTab == TABLEID_DOC )
6239 - pDoc->SetDocProtection( FALSE, aEmptyPass );
6241 - pDoc->SetTabProtection( nTab, FALSE, aEmptyPass );
6245 + // set protection.
6246 + auto_ptr<ScDocProtection> pCopy(new ScDocProtection(*mpProtectSettings));
6247 + pCopy->setProtected(true);
6248 + pDoc->SetDocProtection(pCopy.get());
6252 + // remove protection.
6253 + pDoc->SetDocProtection(NULL);
6256 - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
6259 - pViewShell->UpdateLayerLocks();
6260 - pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
6262 + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
6265 + pViewShell->UpdateLayerLocks();
6266 + pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
6269 - pDocShell->PostPaintGridAll();
6270 + pDocShell->PostPaintGridAll();
6273 -void __EXPORT ScUndoProtect::Undo()
6274 +void ScUndoDocProtect::Undo()
6277 - DoProtect( !bProtect );
6280 + DoProtect(!mpProtectSettings->isProtected());
6284 -void __EXPORT ScUndoProtect::Redo()
6285 +void ScUndoDocProtect::Redo()
6288 - DoProtect( bProtect );
6291 + DoProtect(mpProtectSettings->isProtected());
6295 -void __EXPORT ScUndoProtect::Repeat(SfxRepeatTarget& /* rTarget */)
6296 +void ScUndoDocProtect::Repeat(SfxRepeatTarget& /* rTarget */)
6302 -BOOL __EXPORT ScUndoProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6303 +BOOL ScUndoDocProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6305 - return FALSE; // gippsnich
6306 + return FALSE; // gippsnich
6309 -String __EXPORT ScUndoProtect::GetComment() const
6310 +String ScUndoDocProtect::GetComment() const
6313 - if ( nTab == TABLEID_DOC )
6314 - nId = bProtect ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
6316 - nId = bProtect ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
6317 - return ScGlobal::GetRscString( nId );
6318 + USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_DOC : STR_UNDO_UNPROTECT_DOC;
6319 + return ScGlobal::GetRscString( nId );
6322 +// ============================================================================
6324 +ScUndoTabProtect::ScUndoTabProtect(ScDocShell* pShell, SCTAB nTab, auto_ptr<ScTableProtection> pProtectSettings) :
6325 + ScSimpleUndo(pShell),
6327 + mpProtectSettings(pProtectSettings)
6331 +ScUndoTabProtect::~ScUndoTabProtect()
6335 +void ScUndoTabProtect::DoProtect(bool bProtect)
6337 + ScDocument* pDoc = pDocShell->GetDocument();
6341 + // set protection.
6342 + auto_ptr<ScTableProtection> pCopy(new ScTableProtection(*mpProtectSettings));
6343 + pCopy->setProtected(true);
6344 + pDoc->SetTabProtection(mnTab, pCopy.get());
6348 + // remove protection.
6349 + pDoc->SetTabProtection(mnTab, NULL);
6352 + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
6355 + pViewShell->UpdateLayerLocks();
6356 + pViewShell->UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
6359 + pDocShell->PostPaintGridAll();
6362 +void ScUndoTabProtect::Undo()
6365 + DoProtect(!mpProtectSettings->isProtected());
6369 +void ScUndoTabProtect::Redo()
6372 + DoProtect(mpProtectSettings->isProtected());
6376 +void ScUndoTabProtect::Repeat(SfxRepeatTarget& /* rTarget */)
6381 +BOOL ScUndoTabProtect::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6383 + return FALSE; // gippsnich
6386 +String ScUndoTabProtect::GetComment() const
6388 + USHORT nId = mpProtectSettings->isProtected() ? STR_UNDO_PROTECT_TAB : STR_UNDO_UNPROTECT_TAB;
6389 + return ScGlobal::GetRscString( nId );
6392 // -----------------------------------------------------------------------
6393 @@ -1274,7 +1333,7 @@ ScUndoPrintRange::ScUndoPrintRange( ScDo
6397 -__EXPORT ScUndoPrintRange::~ScUndoPrintRange()
6398 +ScUndoPrintRange::~ScUndoPrintRange()
6402 @@ -1297,31 +1356,31 @@ void ScUndoPrintRange::DoChange(BOOL bUn
6403 pDocShell->PostPaint( ScRange(0,0,nTab,MAXCOL,MAXROW,nTab), PAINT_GRID );
6406 -void __EXPORT ScUndoPrintRange::Undo()
6407 +void ScUndoPrintRange::Undo()
6414 -void __EXPORT ScUndoPrintRange::Redo()
6415 +void ScUndoPrintRange::Redo()
6422 -void __EXPORT ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
6423 +void ScUndoPrintRange::Repeat(SfxRepeatTarget& /* rTarget */)
6428 -BOOL __EXPORT ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6429 +BOOL ScUndoPrintRange::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6431 return FALSE; // gippsnich
6434 -String __EXPORT ScUndoPrintRange::GetComment() const
6435 +String ScUndoPrintRange::GetComment() const
6437 return ScGlobal::GetRscString( STR_UNDO_PRINTRANGES );
6439 @@ -1350,16 +1409,16 @@ ScUndoScenarioFlags::ScUndoScenarioFlags
6443 -__EXPORT ScUndoScenarioFlags::~ScUndoScenarioFlags()
6444 +ScUndoScenarioFlags::~ScUndoScenarioFlags()
6448 -String __EXPORT ScUndoScenarioFlags::GetComment() const
6449 +String ScUndoScenarioFlags::GetComment() const
6451 return ScGlobal::GetRscString( STR_UNDO_EDITSCENARIO );
6454 -void __EXPORT ScUndoScenarioFlags::Undo()
6455 +void ScUndoScenarioFlags::Undo()
6457 ScDocument* pDoc = pDocShell->GetDocument();
6459 @@ -1376,7 +1435,7 @@ void __EXPORT ScUndoScenarioFlags::Undo(
6460 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
6463 -void __EXPORT ScUndoScenarioFlags::Redo()
6464 +void ScUndoScenarioFlags::Redo()
6466 ScDocument* pDoc = pDocShell->GetDocument();
6468 @@ -1393,12 +1452,12 @@ void __EXPORT ScUndoScenarioFlags::Redo(
6469 SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
6472 -void __EXPORT ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
6473 +void ScUndoScenarioFlags::Repeat(SfxRepeatTarget& /* rTarget */)
6475 // Repeat macht keinen Sinn
6478 -BOOL __EXPORT ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6479 +BOOL ScUndoScenarioFlags::CanRepeat(SfxRepeatTarget& /* rTarget */) const
6483 @@ -1498,7 +1557,7 @@ ScUndoLayoutRTL::ScUndoLayoutRTL( ScDocS
6487 -__EXPORT ScUndoLayoutRTL::~ScUndoLayoutRTL()
6488 +ScUndoLayoutRTL::~ScUndoLayoutRTL()
6492 @@ -1518,29 +1577,29 @@ void ScUndoLayoutRTL::DoChange( BOOL bNe
6493 pDocShell->SetInUndo( FALSE );
6496 -void __EXPORT ScUndoLayoutRTL::Undo()
6497 +void ScUndoLayoutRTL::Undo()
6502 -void __EXPORT ScUndoLayoutRTL::Redo()
6503 +void ScUndoLayoutRTL::Redo()
6508 -void __EXPORT ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
6509 +void ScUndoLayoutRTL::Repeat(SfxRepeatTarget& rTarget)
6511 if (rTarget.ISA(ScTabViewTarget))
6512 ((ScTabViewTarget&)rTarget).GetViewShell()->GetViewData()->GetDispatcher().
6513 Execute( FID_TAB_RTL, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
6516 -BOOL __EXPORT ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
6517 +BOOL ScUndoLayoutRTL::CanRepeat(SfxRepeatTarget& rTarget) const
6519 return (rTarget.ISA(ScTabViewTarget));
6522 -String __EXPORT ScUndoLayoutRTL::GetComment() const
6523 +String ScUndoLayoutRTL::GetComment() const
6525 return ScGlobal::GetRscString( STR_UNDO_TAB_RTL );
6527 @@ -1560,7 +1619,7 @@ ScUndoSetGrammar::ScUndoSetGrammar( ScDo
6528 meOldGrammar = pDocShell->GetDocument()->GetGrammar();
6531 -__EXPORT ScUndoSetGrammar::~ScUndoSetGrammar()
6532 +ScUndoSetGrammar::~ScUndoSetGrammar()
6536 @@ -1573,17 +1632,17 @@ void ScUndoSetGrammar::DoChange( formula
6537 pDocShell->SetInUndo( FALSE );
6540 -void __EXPORT ScUndoSetGrammar::Undo()
6541 +void ScUndoSetGrammar::Undo()
6543 DoChange( meOldGrammar );
6546 -void __EXPORT ScUndoSetGrammar::Redo()
6547 +void ScUndoSetGrammar::Redo()
6549 DoChange( meNewGrammar );
6552 -void __EXPORT ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
6553 +void ScUndoSetGrammar::Repeat(SfxRepeatTarget& /* rTarget */)
6556 // erAck: 2006-09-07T23:00+0200 commented out in CWS scr1c1
6557 @@ -1593,12 +1652,12 @@ void __EXPORT ScUndoSetGrammar::Repeat(S
6561 -BOOL __EXPORT ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
6562 +BOOL ScUndoSetGrammar::CanRepeat(SfxRepeatTarget& rTarget) const
6564 return (rTarget.ISA(ScTabViewTarget));
6567 -String __EXPORT ScUndoSetGrammar::GetComment() const
6568 +String ScUndoSetGrammar::GetComment() const
6570 return ScGlobal::GetRscString( STR_UNDO_TAB_R1C1 );
6572 --- sc/source/ui/unoobj/warnpassword.cxx.old 2009-04-02 10:45:26.000000000 +0000
6573 +++ sc/source/ui/unoobj/warnpassword.cxx 2009-04-06 16:41:49.000000000 +0000
6574 @@ -95,3 +95,4 @@ bool ScWarnPassword::WarningOnPassword(
6579 --- sc/source/ui/view/gridwin.cxx.old 2009-04-06 16:41:48.000000000 +0000
6580 +++ sc/source/ui/view/gridwin.cxx 2009-04-06 16:41:49.000000000 +0000
6582 #include "userdat.hxx"
6583 #include "drwlayer.hxx"
6584 #include "attrib.hxx"
6585 +#include "tabprotection.hxx"
6588 #include <vcl/salbtype.hxx> // FRound
6589 @@ -1990,8 +1991,9 @@ void __EXPORT ScGridWindow::MouseButtonU
6590 Point aPos = rMEvt.GetPosPixel();
6593 + SCTAB nTab = pViewData->GetTabNo();
6594 pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
6595 - ScDPObject* pDPObj = pDoc->GetDPAtCursor( nPosX, nPosY, pViewData->GetTabNo() );
6596 + ScDPObject* pDPObj = pDoc->GetDPAtCursor( nPosX, nPosY, nTab );
6597 if ( pDPObj && pDPObj->GetSaveData()->GetDrillDown() )
6599 ScAddress aCellPos( nPosX, nPosY, pViewData->GetTabNo() );
6600 @@ -2033,19 +2035,37 @@ void __EXPORT ScGridWindow::MouseButtonU
6604 - // edit cell contents
6605 - pViewData->GetViewShell()->UpdateInputHandler();
6606 - pScMod->SetInputMode( SC_INPUT_TABLE );
6607 - if (pViewData->HasEditView(eWhich))
6609 - // Text-Cursor gleich an die geklickte Stelle setzen
6610 - EditView* pEditView = pViewData->GetEditView( eWhich );
6611 - MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
6612 - pEditView->MouseButtonDown( aEditEvt );
6613 - pEditView->MouseButtonUp( aEditEvt );
6615 + // Check for cell protection attribute.
6616 + ScTableProtection* pProtect = pDoc->GetTabProtection( nTab );
6617 + bool bEditAllowed = true;
6618 + if ( pProtect && pProtect->isProtected() )
6620 + bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
6621 + bool bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
6622 + bool bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
6624 + if ( bSkipProtected && bSkipUnprotected )
6625 + bEditAllowed = false;
6626 + else if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
6627 + bEditAllowed = false;
6630 + if ( bEditAllowed )
6632 + // edit cell contents
6633 + pViewData->GetViewShell()->UpdateInputHandler();
6634 + pScMod->SetInputMode( SC_INPUT_TABLE );
6635 + if (pViewData->HasEditView(eWhich))
6637 + // Text-Cursor gleich an die geklickte Stelle setzen
6638 + EditView* pEditView = pViewData->GetEditView( eWhich );
6639 + MouseEvent aEditEvt( rMEvt.GetPosPixel(), 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
6640 + pEditView->MouseButtonDown( aEditEvt );
6641 + pEditView->MouseButtonUp( aEditEvt );
6649 // Links in edit cells
6650 --- sc/source/ui/view/scextopt.cxx.old 2009-04-02 10:45:40.000000000 +0000
6651 +++ sc/source/ui/view/scextopt.cxx 2009-04-06 16:41:49.000000000 +0000
6652 @@ -42,9 +42,7 @@ ScExtDocSettings::ScExtDocSettings() :
6653 maOleSize( ScAddress::INITIALIZE_INVALID ),
6654 mfTabBarWidth( -1.0 ),
6657 - mbWinProtected( false ),
6658 - mbEncrypted( false )
6663 --- sc/source/ui/view/select.cxx.old 2009-04-02 10:45:40.000000000 +0000
6664 +++ sc/source/ui/view/select.cxx 2009-04-06 16:41:49.000000000 +0000
6666 //#include "dataobj.hxx"
6667 #include "transobj.hxx"
6668 #include "docsh.hxx"
6669 +#include "tabprotection.hxx"
6671 extern USHORT nScFillModeMouseModifier; // global.cxx
6673 @@ -322,6 +323,26 @@ BOOL ScViewFunctionSet::SetCursorAtCell(
6675 ScTabView* pView = pViewData->GetView();
6676 SCTAB nTab = pViewData->GetTabNo();
6677 + ScDocument* pDoc = pViewData->GetDocument();
6679 + if ( pDoc->IsTabProtected(nTab) )
6681 + if (nPosX < 0 || nPosY < 0)
6684 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
6685 + bool bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
6686 + bool bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
6688 + if ( bSkipProtected && bSkipUnprotected )
6691 + bool bCellProtected = pDoc->HasAttrib(nPosX, nPosY, nTab, nPosX, nPosY, nTab, HASATTR_PROTECTED);
6692 + if ( (bCellProtected && bSkipProtected) || (!bCellProtected && bSkipUnprotected) )
6693 + // Don't select this cell!
6697 ScModule* pScMod = SC_MOD();
6698 ScTabViewShell* pViewShell = pViewData->GetViewShell();
6699 bool bRefMode = ( pViewShell ? pViewShell->IsRefInputMode() : false );
6700 @@ -375,7 +396,6 @@ BOOL ScViewFunctionSet::SetCursorAtCell(
6703 BOOL bOldDelMark = pViewData->GetDelMark( aDelRange );
6704 - ScDocument* pDoc = pViewData->GetDocument();
6706 if ( nPosX+1 >= (SCsCOL) nStartX && nPosX <= (SCsCOL) nEndX &&
6707 nPosY+1 >= (SCsROW) nStartY && nPosY <= (SCsROW) nEndY &&
6708 @@ -511,7 +531,6 @@ BOOL ScViewFunctionSet::SetCursorAtCell(
6709 BYTE nMode = pViewData->GetFillMode();
6710 if ( nMode == SC_FILL_EMBED_LT || nMode == SC_FILL_EMBED_RB )
6712 - ScDocument* pDoc = pViewData->GetDocument();
6713 DBG_ASSERT( pDoc->IsEmbedded(), "!pDoc->IsEmbedded()" );
6715 pDoc->GetEmbedded( aRange);
6716 --- sc/source/ui/view/tabview3.cxx.old 2009-04-02 10:45:40.000000000 +0000
6717 +++ sc/source/ui/view/tabview3.cxx 2009-04-06 16:41:49.000000000 +0000
6719 #include "AccessibilityHints.hxx"
6720 #include "rangeutl.hxx"
6721 #include "client.hxx"
6722 +#include "tabprotection.hxx"
6724 #include <com/sun/star/chart2/data/HighlightedRange.hpp>
6726 @@ -946,6 +947,17 @@ void ScTabView::MoveCursorRel( SCsCOL nM
6727 ScDocument* pDoc = aViewData.GetDocument();
6728 SCTAB nTab = aViewData.GetTabNo();
6730 + bool bSkipProtected = false, bSkipUnprotected = false;
6731 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
6732 + if ( pProtect && pProtect->isProtected() )
6734 + bSkipProtected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
6735 + bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
6738 + if ( bSkipProtected && bSkipUnprotected )
6744 @@ -965,7 +977,7 @@ void ScTabView::MoveCursorRel( SCsCOL nM
6745 nCurY = (nMovY != 0) ? nOldY+nMovY : (SCsROW) aViewData.GetOldCurY();
6749 + BOOL bSkipCell = FALSE;
6750 aViewData.ResetOldCursor();
6752 if (nMovX != 0 && VALIDCOLROW(nCurX,nCurY))
6753 @@ -974,15 +986,20 @@ void ScTabView::MoveCursorRel( SCsCOL nM
6756 BYTE nColFlags = pDoc->GetColFlags( nCurX, nTab );
6757 - bHidden = (nColFlags & CR_HIDDEN) || pDoc->IsHorOverlapped( nCurX, nCurY, nTab );
6759 + bSkipCell = (nColFlags & CR_HIDDEN) || pDoc->IsHorOverlapped( nCurX, nCurY, nTab );
6760 + if (bSkipProtected && !bSkipCell)
6761 + bSkipCell = pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
6762 + if (bSkipUnprotected && !bSkipCell)
6763 + bSkipCell = !pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
6767 if ( nCurX<=0 || nCurX>=MAXCOL )
6773 + bSkipCell = FALSE;
6777 @@ -995,7 +1012,8 @@ void ScTabView::MoveCursorRel( SCsCOL nM
6778 if (nMovX > 0) ++nCurX; else --nCurX;
6782 + while (bSkipCell);
6784 if (pDoc->IsVerOverlapped( nCurX, nCurY, nTab ))
6786 aViewData.SetOldCursor( nCurX,nCurY );
6787 @@ -1010,15 +1028,20 @@ void ScTabView::MoveCursorRel( SCsCOL nM
6790 BYTE nRowFlags = pDoc->GetRowFlags( nCurY, nTab );
6791 - bHidden = (nRowFlags & CR_HIDDEN) || pDoc->IsVerOverlapped( nCurX, nCurY, nTab );
6793 + bSkipCell = (nRowFlags & CR_HIDDEN) || pDoc->IsVerOverlapped( nCurX, nCurY, nTab );
6794 + if (bSkipProtected && !bSkipCell)
6795 + bSkipCell = pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
6796 + if (bSkipUnprotected && !bSkipCell)
6797 + bSkipCell = !pDoc->HasAttrib(nCurX, nCurY, nTab, nCurX, nCurY, nTab, HASATTR_PROTECTED);
6801 if ( nCurY<=0 || nCurY>=MAXROW )
6807 + bSkipCell = FALSE;
6811 @@ -1031,7 +1054,8 @@ void ScTabView::MoveCursorRel( SCsCOL nM
6812 if (nMovY > 0) ++nCurY; else --nCurY;
6816 + while (bSkipCell);
6818 if (pDoc->IsHorOverlapped( nCurX, nCurY, nTab ))
6820 aViewData.SetOldCursor( nCurX,nCurY );
6821 --- sc/source/ui/view/tabvwsh3.cxx.old 2009-04-02 10:45:40.000000000 +0000
6822 +++ sc/source/ui/view/tabvwsh3.cxx 2009-04-06 16:41:49.000000000 +0000
6824 #include "autofmt.hxx"
6825 #include "dwfunctr.hxx"
6826 #include "shtabdlg.hxx"
6827 +#include "tabprotection.hxx"
6828 +#include "protectiondlg.hxx"
6830 #include <svtools/ilstitem.hxx>
6831 #define _SVSTDARR_ULONGS
6833 #include <svx/dialogs.hrc> //CHINA001
6834 #include "scabstdlg.hxx" //CHINA001
6838 +using ::std::auto_ptr;
6840 #define IS_EDITMODE() GetViewData()->HasEditView( GetViewData()->GetActivePart() )
6841 #define IS_AVAILABLE(WhichId,ppItem) \
6842 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
6843 @@ -1002,12 +1008,13 @@ void ScTabViewShell::Execute( SfxRequest
6847 - if (pDoc->IsDocProtected())
6848 + ScDocProtection* pProtect = pDoc->GetDocProtection();
6849 + if (pProtect && pProtect->isProtected())
6851 BOOL bCancel = FALSE;
6854 - if (pDoc->GetDocPassword().getLength())
6855 + if (pProtect->isProtectedWithPass())
6857 String aText( ScResId(SCSTR_PASSWORD) );
6859 @@ -1057,89 +1064,164 @@ void ScTabViewShell::Execute( SfxRequest
6862 case FID_PROTECT_TABLE:
6864 - ScDocument* pDoc = GetViewData()->GetDocument();
6865 - SCTAB nTab = GetViewData()->GetTabNo();
6866 - SfxPasswordDialog* pDlg;
6868 - BOOL bCancel = FALSE;
6869 - BOOL bOldProtection = pDoc->IsTabProtected(nTab);
6870 - BOOL bNewProtection = ! bOldProtection;
6872 + ScDocument* pDoc = GetViewData()->GetDocument();
6873 + SCTAB nTab = GetViewData()->GetTabNo();
6874 + bool bOldProtection = pDoc->IsTabProtected(nTab);
6878 - const SfxPoolItem* pItem;
6879 - if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
6880 - bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
6881 - if( bNewProtection == bOldProtection )
6882 +#if ENABLE_SHEET_PROTECTION
6886 + const SfxPoolItem* pItem;
6887 + bool bNewProtection = !bOldProtection;
6888 + if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
6889 + bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
6890 + if( bNewProtection == bOldProtection )
6897 + if (bOldProtection)
6899 + // Unprotect a protected sheet.
6901 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
6902 + if (pProtect && pProtect->isProtectedWithPass())
6904 + String aText( ScResId(SCSTR_PASSWORDOPT) );
6905 + auto_ptr<SfxPasswordDialog> pDlg(new SfxPasswordDialog(GetDialogParent(), &aText));
6906 + pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
6907 + pDlg->SetMinLen( 0 );
6908 + pDlg->SetHelpId( FID_PROTECT_TABLE );
6909 + pDlg->SetEditHelpId( HID_PASSWD_TABLE );
6911 + if (pDlg->Execute() == RET_OK)
6915 + String aPassword = pDlg->GetPassword();
6916 + Unprotect(nTab, aPassword);
6920 + // this sheet is not password-protected.
6921 + Unprotect(nTab, String());
6923 - if ( bOldProtection)
6925 - if (pDoc->GetTabPassword(nTab).getLength())
6927 - String aText( ScResId(SCSTR_PASSWORD) );
6930 + rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
6936 + // Protect a current sheet.
6938 - pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
6939 - pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
6940 - pDlg->SetMinLen( 0 );
6941 - pDlg->SetHelpId( FID_PROTECT_TABLE );
6942 - pDlg->SetEditHelpId( HID_PASSWD_TABLE );
6944 - if (pDlg->Execute() == RET_OK)
6945 - aPassword = pDlg->GetPassword();
6948 + auto_ptr<ScTableProtectionDlg> pDlg(new ScTableProtectionDlg(GetDialogParent()));
6952 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
6954 + pDlg->SetDialogData(*pProtect);
6956 + if (pDlg->Execute() == RET_OK)
6958 + pScMod->InputEnterHandler();
6960 + ScTableProtection aNewProtect;
6961 + pDlg->WriteData(aNewProtect);
6962 + ProtectSheet(nTab, aNewProtect);
6965 + rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
6971 + auto_ptr<SfxPasswordDialog> pDlg;
6973 + BOOL bCancel = FALSE;
6974 + BOOL bNewProtection = ! bOldProtection;
6978 + const SfxPoolItem* pItem;
6979 + if( IS_AVAILABLE( FID_PROTECT_TABLE, &pItem ) )
6980 + bNewProtection = ((const SfxBoolItem*)pItem)->GetValue();
6981 + if( bNewProtection == bOldProtection )
6988 + if ( bOldProtection)
6990 + // Unprotect a protected sheet.
6992 + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
6993 + if (pProtect && pProtect->isProtectedWithPass())
6995 + String aText( ScResId(SCSTR_PASSWORDOPT) );
6996 + pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
6997 + pDlg->SetText( ScResId(SCSTR_UNPROTECTTAB) );
6998 + pDlg->SetMinLen( 0 );
6999 + pDlg->SetHelpId( FID_PROTECT_TABLE );
7000 + pDlg->SetEditHelpId( HID_PASSWD_TABLE );
7002 + if (pDlg->Execute() == RET_OK)
7003 + aPassword = pDlg->GetPassword();
7006 - String aText( ScResId(SCSTR_PASSWORDOPT) );
7010 - pDlg = new SfxPasswordDialog( GetDialogParent(), &aText );
7011 - pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
7012 - pDlg->SetMinLen( 0 );
7013 - pDlg->SetHelpId( FID_PROTECT_TABLE );
7014 - pDlg->SetEditHelpId( HID_PASSWD_TABLE );
7015 - pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
7017 - if (pDlg->Execute() == RET_OK)
7018 - aPassword = pDlg->GetPassword();
7023 + rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
7029 + String aText( ScResId(SCSTR_PASSWORDOPT) );
7033 + pDlg.reset(new SfxPasswordDialog(GetDialogParent(), &aText));
7034 + pDlg->SetText( ScResId(SCSTR_PROTECTTAB) );
7035 + pDlg->SetMinLen( 0 );
7036 + pDlg->SetHelpId( FID_PROTECT_TABLE );
7037 + pDlg->SetEditHelpId( HID_PASSWD_TABLE );
7038 + pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
7042 - if ( bOldProtection )
7043 - Unprotect( nTab, aPassword );
7046 - pScMod->InputEnterHandler();
7047 + if (pDlg->Execute() == RET_OK)
7048 + aPassword = pDlg->GetPassword();
7053 - Protect( nTab, aPassword );
7057 + if ( bOldProtection )
7058 + Unprotect( nTab, aPassword );
7061 + pScMod->InputEnterHandler();
7065 - rReq.AppendItem( SfxBoolItem( FID_PROTECT_TABLE, bNewProtection ) );
7069 + Protect( nTab, aPassword );
7073 - UpdateInputHandler(TRUE); // damit sofort wieder eingegeben werden kann
7074 - SelectionChanged();
7079 + rReq.AppendItem( SfxBoolItem( FID_PROTECT_TABLE, bNewProtection ) );
7085 + UpdateInputHandler(true); // damit sofort wieder eingegeben werden kann
7086 + SelectionChanged();
7090 case SID_OPT_LOCALE_CHANGED :
7091 { // locale changed, SYSTEM number formats changed => repaint cell contents
7092 --- sc/source/ui/view/tabvwshh.cxx.old 2009-04-02 10:45:40.000000000 +0000
7093 +++ sc/source/ui/view/tabvwshh.cxx 2009-04-06 16:41:49.000000000 +0000
7095 #include <sfx2/request.hxx>
7096 #include <basic/sbxcore.hxx>
7097 #include <svtools/whiter.hxx>
7098 +#include <vcl/msgbox.hxx>
7100 #include "tabvwsh.hxx"
7101 #include "client.hxx"
7103 #include "docsh.hxx"
7105 #include "drwlayer.hxx" // GetVisibleName
7106 +#include "retypepassdlg.hxx"
7107 +#include "tabprotection.hxx"
7111 using namespace com::sun::star;
7113 @@ -270,6 +275,22 @@ BOOL ScTabViewShell::HasAccessibilityObj
7114 return pAccessibilityBroadcaster != NULL;
7117 +bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
7119 + using ::std::auto_ptr;
7121 + ScDocument* pDoc = GetViewData()->GetDocument();
7123 + auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
7124 + pDlg->SetData(*pDoc);
7125 + pDlg->SetDesiredHash(eDesiredHash);
7126 + if (pDlg->Execute() != RET_OK)
7129 + pDlg->WriteNewDataToDocument(*pDoc);
7136 --- sc/source/ui/view/viewfun2.cxx.old 2009-04-02 10:45:40.000000000 +0000
7137 +++ sc/source/ui/view/viewfun2.cxx 2009-04-06 16:41:49.000000000 +0000
7138 @@ -2197,7 +2197,7 @@ BOOL ScViewFunc::DeleteTables(const SvSh
7139 pUndoDoc->SetVisible( nTab, pDoc->IsVisible( nTab ) );
7141 if ( pDoc->IsTabProtected( nTab ) )
7142 - pUndoDoc->SetTabProtection( nTab, TRUE, pDoc->GetTabPassword( nTab ) );
7143 + pUndoDoc->SetTabProtection(nTab, pDoc->GetTabProtection(nTab));
7145 // Drawing-Layer muss sein Undo selbst in der Hand behalten !!!
7146 // pUndoDoc->TransferDrawPage(pDoc, nTab,nTab);
7147 @@ -2612,7 +2612,7 @@ void ScViewFunc::MoveTable( USHORT nDest
7150 if ( nErrVal > 0 && pDoc->IsTabProtected( TheTabs[i] ) )
7151 - pDestDoc->SetTabProtection( nDestTab1, TRUE, pDoc->GetTabPassword( TheTabs[i] ) );
7152 + pDestDoc->SetTabProtection(nDestTab1, pDoc->GetTabProtection(TheTabs[i]));
7156 --- sc/source/ui/view/viewfunc.cxx.old 2009-04-06 16:41:48.000000000 +0000
7157 +++ sc/source/ui/view/viewfunc.cxx 2009-04-06 16:41:49.000000000 +0000
7158 @@ -2582,6 +2582,36 @@ void ScViewFunc::ModifyCellSize( ScDirec
7162 +void ScViewFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
7164 + if (nTab == TABLEID_DOC)
7167 + ScMarkData& rMark = GetViewData()->GetMarkData();
7168 + ScDocShell* pDocSh = GetViewData()->GetDocShell();
7169 + ScDocument* pDoc = pDocSh->GetDocument();
7170 + ScDocFunc aFunc(*pDocSh);
7171 + bool bUndo(pDoc->IsUndoEnabled());
7173 + // modifying several tables is handled here
7177 + String aUndo = ScGlobal::GetRscString( STR_UNDO_PROTECT_TAB );
7178 + pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo );
7181 + SCTAB nCount = pDocSh->GetDocument()->GetTableCount();
7182 + for ( SCTAB i=0; i<nCount; i++ )
7183 + if ( rMark.GetTableSelect(i) )
7184 + aFunc.ProtectSheet(i, rProtect);
7187 + pDocSh->GetUndoManager()->LeaveListAction();
7189 + UpdateLayerLocks(); //! broadcast to all views
7192 void ScViewFunc::Protect( SCTAB nTab, const String& rPassword )
7194 ScMarkData& rMark = GetViewData()->GetMarkData();