1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SC_TAB_PROTECTION_HXX
29 #define SC_TAB_PROTECTION_HXX
31 #include "sal/types.h"
32 #include <com/sun/star/uno/Sequence.hxx>
36 #include <boost/shared_ptr.hpp>
38 #define ENABLE_SHEET_PROTECTION 0
41 class ScTableProtectionImpl
;
49 class ScPassHashHelper
52 /** Check for the compatibility of all password hashes. If there is at
53 least one hash that needs to be regenerated, it returns true. If all
54 hash values are compatible with the specified hash type, then it
56 static bool needsPassHashRegen(const ScDocument
& rDoc
, ScPasswordHash eHash
);
63 // ============================================================================
65 class SAL_NO_VTABLE ScPassHashProtectable
68 virtual ~ScPassHashProtectable() = 0;
70 virtual bool isProtected() const = 0;
71 virtual bool isProtectedWithPass() const = 0;
72 virtual void setProtected(bool bProtected
) = 0;
74 virtual bool isPasswordEmpty() const = 0;
75 virtual bool hasPasswordHash(ScPasswordHash eHash
) const = 0;
76 virtual void setPassword(const String
& aPassText
) = 0;
77 virtual ::com::sun::star::uno::Sequence
<sal_Int8
> getPasswordHash(ScPasswordHash eHash
) const = 0;
78 virtual void setPasswordHash(const ::com::sun::star::uno::Sequence
<sal_Int8
>& aPassword
,
79 ScPasswordHash eHash
= PASSHASH_OOO
) = 0;
80 virtual bool verifyPassword(const String
& aPassText
) const = 0;
83 // ============================================================================
85 class SC_DLLPUBLIC ScDocProtection
: public ScPassHashProtectable
93 NONE
// last item - used to resize the vector
96 explicit ScDocProtection();
97 explicit ScDocProtection(const ScDocProtection
& r
);
98 virtual ~ScDocProtection();
100 virtual bool isProtected() const;
101 virtual bool isProtectedWithPass() const;
102 virtual void setProtected(bool bProtected
);
104 virtual bool isPasswordEmpty() const;
105 virtual bool hasPasswordHash(ScPasswordHash eHash
) const;
106 virtual void setPassword(const String
& aPassText
);
107 virtual ::com::sun::star::uno::Sequence
<sal_Int8
> getPasswordHash(ScPasswordHash eHash
) const;
108 virtual void setPasswordHash(const ::com::sun::star::uno::Sequence
<sal_Int8
>& aPassword
,
109 ScPasswordHash eHash
= PASSHASH_OOO
);
110 virtual bool verifyPassword(const String
& aPassText
) const;
112 bool isOptionEnabled(Option eOption
) const;
113 void setOption(Option eOption
, bool bEnabled
);
116 ::boost::shared_ptr
<ScTableProtectionImpl
> mpImpl
;
119 // ============================================================================
121 /** sheet protection state container
123 This class stores sheet's protection state: 1) whether the protection
124 is on, 2) password and/or password hash, and 3) any associated
125 protection options. This class is also used as a protection state
126 container for the undo/redo stack, in which case the password, hash and
127 the options need to be preserved even when the protection flag is
129 class SC_DLLPUBLIC ScTableProtection
: public ScPassHashProtectable
147 SELECT_UNLOCKED_CELLS
,
150 NONE
// last item - used to resize the vector
153 explicit ScTableProtection();
154 explicit ScTableProtection(const ScTableProtection
& r
);
155 virtual ~ScTableProtection();
157 virtual bool isProtected() const;
158 virtual bool isProtectedWithPass() const;
159 virtual void setProtected(bool bProtected
);
161 virtual bool isPasswordEmpty() const;
162 virtual bool hasPasswordHash(ScPasswordHash eHash
) const;
163 virtual void setPassword(const String
& aPassText
);
164 virtual ::com::sun::star::uno::Sequence
<sal_Int8
> getPasswordHash(ScPasswordHash eHash
) const;
165 virtual void setPasswordHash(const ::com::sun::star::uno::Sequence
<sal_Int8
>& aPassword
,
166 ScPasswordHash eHash
= PASSHASH_OOO
);
167 virtual bool verifyPassword(const String
& aPassText
) const;
169 bool isOptionEnabled(Option eOption
) const;
170 void setOption(Option eOption
, bool bEnabled
);
173 ::boost::shared_ptr
<ScTableProtectionImpl
> mpImpl
;