update dev300-m57
[ooovba.git] / sc / inc / tabprotection.hxx
blobb9860700df86b2d0fae931d0f4acfa34eb3fd734
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabprotection.hxx,v $
10 * $Revision: 1.1.4.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_TAB_PROTECTION_HXX
32 #define SC_TAB_PROTECTION_HXX
34 #include "sal/types.h"
35 #include <com/sun/star/uno/Sequence.hxx>
37 #include "global.hxx"
38 #include <boost/shared_ptr.hpp>
40 #define ENABLE_SHEET_PROTECTION 1
42 class ScDocument;
43 class ScTableProtectionImpl;
45 enum ScPasswordHash
47 PASSHASH_SHA1 = 0,
48 PASSHASH_XL,
49 PASSHASH_UNSPECIFIED
52 class ScPassHashHelper
54 public:
55 /** Check for the compatibility of all password hashes. If there is at
56 least one hash that needs to be regenerated, it returns true. If all
57 hash values are compatible with the specified hash type, then it
58 returns false. */
59 static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
61 static ::rtl::OUString getHashURI(ScPasswordHash eHash);
63 static ScPasswordHash getHashTypeFromURI(const ::rtl::OUString& rURI);
65 private:
66 ScPassHashHelper();
67 ~ScPassHashHelper();
70 // ============================================================================
72 class SAL_NO_VTABLE ScPassHashProtectable
74 public:
75 virtual ~ScPassHashProtectable() = 0;
77 virtual bool isProtected() const = 0;
78 virtual bool isProtectedWithPass() const = 0;
79 virtual void setProtected(bool bProtected) = 0;
81 virtual bool isPasswordEmpty() const = 0;
82 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
83 virtual void setPassword(const String& aPassText) = 0;
84 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
85 ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
86 virtual void setPasswordHash(
87 const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
88 ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) = 0;
89 virtual bool verifyPassword(const String& aPassText) const = 0;
92 // ============================================================================
94 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
96 public:
97 enum Option
99 STRUCTURE = 0,
100 WINDOWS,
101 CONTENT,
102 NONE // last item - used to resize the vector
105 explicit ScDocProtection();
106 explicit ScDocProtection(const ScDocProtection& r);
107 virtual ~ScDocProtection();
109 virtual bool isProtected() const;
110 virtual bool isProtectedWithPass() const;
111 virtual void setProtected(bool bProtected);
113 virtual bool isPasswordEmpty() const;
114 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
115 virtual void setPassword(const String& aPassText);
116 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
117 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
118 virtual void setPasswordHash(
119 const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
120 ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
121 virtual bool verifyPassword(const String& aPassText) const;
123 bool isOptionEnabled(Option eOption) const;
124 void setOption(Option eOption, bool bEnabled);
126 private:
127 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
130 // ============================================================================
132 /** sheet protection state container
134 This class stores sheet's protection state: 1) whether the protection
135 is on, 2) password and/or password hash, and 3) any associated
136 protection options. This class is also used as a protection state
137 container for the undo/redo stack, in which case the password, hash and
138 the options need to be preserved even when the protection flag is
139 off. */
140 class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
142 public:
143 enum Option
145 AUTOFILTER = 0,
146 DELETE_COLUMNS,
147 DELETE_ROWS,
148 FORMAT_CELLS,
149 FORMAT_COLUMNS,
150 FORMAT_ROWS,
151 INSERT_COLUMNS,
152 INSERT_HYPERLINKS,
153 INSERT_ROWS,
154 OBJECTS,
155 PIVOT_TABLES,
156 SCENARIOS,
157 SELECT_LOCKED_CELLS,
158 SELECT_UNLOCKED_CELLS,
159 SHEET,
160 SORT,
161 NONE // last item - used to resize the vector
164 explicit ScTableProtection();
165 explicit ScTableProtection(const ScTableProtection& r);
166 virtual ~ScTableProtection();
168 virtual bool isProtected() const;
169 virtual bool isProtectedWithPass() const;
170 virtual void setProtected(bool bProtected);
172 virtual bool isPasswordEmpty() const;
173 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
174 virtual void setPassword(const String& aPassText);
175 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
176 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
177 virtual void setPasswordHash(
178 const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
179 ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
180 virtual bool verifyPassword(const String& aPassText) const;
182 bool isOptionEnabled(Option eOption) const;
183 void setOption(Option eOption, bool bEnabled);
185 private:
186 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
190 #endif