Bump version to 4.3-4
[LibreOffice.git] / sc / inc / tabprotection.hxx
blobf1d2799ac2e6df6f5f99f72d6fd0c1e10c8efb88
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SC_INC_TABPROTECTION_HXX
21 #define INCLUDED_SC_INC_TABPROTECTION_HXX
23 #include <sal/types.h>
24 #include <com/sun/star/uno/Sequence.hxx>
26 #include "global.hxx"
27 #include "rangelst.hxx"
28 #include <boost/shared_ptr.hpp>
30 class ScDocument;
31 class ScTableProtectionImpl;
33 enum ScPasswordHash
35 PASSHASH_SHA1 = 0,
36 PASSHASH_XL,
37 PASSHASH_UNSPECIFIED
40 class ScPassHashHelper
42 public:
43 /** Check for the compatibility of all password hashes. If there is at
44 * least one hash that needs to be regenerated, it returns true. If all
45 * hash values are compatible with the specified hash type, then it
46 * returns false. */
47 static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
49 static OUString getHashURI(ScPasswordHash eHash);
51 static ScPasswordHash getHashTypeFromURI(const OUString& rURI);
53 private:
54 ScPassHashHelper();
55 ~ScPassHashHelper();
58 class SAL_NO_VTABLE ScPassHashProtectable
60 public:
61 virtual ~ScPassHashProtectable() = 0;
63 virtual bool isProtected() const = 0;
64 virtual bool isProtectedWithPass() const = 0;
65 virtual void setProtected(bool bProtected) = 0;
67 virtual bool isPasswordEmpty() const = 0;
68 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
69 virtual void setPassword(const OUString& aPassText) = 0;
70 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
71 ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
72 virtual void setPasswordHash(
73 const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
74 ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) = 0;
75 virtual bool verifyPassword(const OUString& aPassText) const = 0;
78 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
80 public:
81 enum Option
83 STRUCTURE = 0,
84 WINDOWS,
85 CONTENT,
86 NONE ///< last item - used to resize the vector
89 explicit ScDocProtection();
90 explicit ScDocProtection(const ScDocProtection& r);
91 virtual ~ScDocProtection();
93 virtual bool isProtected() const SAL_OVERRIDE;
94 virtual bool isProtectedWithPass() const SAL_OVERRIDE;
95 virtual void setProtected(bool bProtected) SAL_OVERRIDE;
97 virtual bool isPasswordEmpty() const SAL_OVERRIDE;
98 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
99 virtual void setPassword(const OUString& aPassText) SAL_OVERRIDE;
100 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
101 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
102 virtual void setPasswordHash(
103 const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
104 ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) SAL_OVERRIDE;
105 virtual bool verifyPassword(const OUString& aPassText) const SAL_OVERRIDE;
107 bool isOptionEnabled(Option eOption) const;
108 void setOption(Option eOption, bool bEnabled);
110 private:
111 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
114 /** Container for the Excel EnhancedProtection feature.
116 struct ScEnhancedProtection
118 ScRangeListRef maRangeList;
119 sal_uInt32 mnAreserved;
120 sal_uInt32 mnPasswordVerifier;
121 OUString maTitle;
122 ::std::vector< sal_uInt8 > maSecurityDescriptor; // imported as raw BIFF data
123 OUString maSecurityDescriptorXML; // imported from OOXML
124 // OOXML password definitions
125 OUString maAlgorithmName;
126 OUString maHashValue;
127 OUString maSaltValue;
128 sal_uInt32 mnSpinCount;
130 ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0), mnSpinCount(0) {}
132 bool hasSecurityDescriptor() const
134 return !maSecurityDescriptor.empty() || !maSecurityDescriptorXML.isEmpty();
137 bool hasPassword() const
139 return mnPasswordVerifier != 0 || !maHashValue.isEmpty();
143 /** sheet protection state container
145 * This class stores sheet's protection state: 1) whether the protection
146 * is on, 2) password and/or password hash, and 3) any associated
147 * protection options. This class is also used as a protection state
148 * container for the undo/redo stack, in which case the password, hash and
149 * the options need to be preserved even when the protection flag is
150 * off. */
151 class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
153 public:
154 enum Option
156 AUTOFILTER = 0,
157 DELETE_COLUMNS,
158 DELETE_ROWS,
159 FORMAT_CELLS,
160 FORMAT_COLUMNS,
161 FORMAT_ROWS,
162 INSERT_COLUMNS,
163 INSERT_HYPERLINKS,
164 INSERT_ROWS,
165 OBJECTS,
166 PIVOT_TABLES,
167 SCENARIOS,
168 SELECT_LOCKED_CELLS,
169 SELECT_UNLOCKED_CELLS,
170 SHEET,
171 SORT,
172 NONE ///< last item - used to resize the vector
175 explicit ScTableProtection();
176 explicit ScTableProtection(const ScTableProtection& r);
177 virtual ~ScTableProtection();
179 virtual bool isProtected() const SAL_OVERRIDE;
180 virtual bool isProtectedWithPass() const SAL_OVERRIDE;
181 virtual void setProtected(bool bProtected) SAL_OVERRIDE;
183 virtual bool isPasswordEmpty() const SAL_OVERRIDE;
184 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
185 virtual void setPassword(const OUString& aPassText) SAL_OVERRIDE;
186 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
187 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
188 virtual void setPasswordHash(
189 const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
190 ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) SAL_OVERRIDE;
191 virtual bool verifyPassword(const OUString& aPassText) const SAL_OVERRIDE;
193 bool isOptionEnabled(Option eOption) const;
194 void setOption(Option eOption, bool bEnabled);
196 void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt );
197 const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const;
198 bool updateReference( UpdateRefMode, ScDocument*, const ScRange& rWhere, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
199 bool isBlockEditable( const ScRange& rRange ) const;
200 bool isSelectionEditable( const ScRangeList& rRangeList ) const;
203 private:
204 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
207 #endif
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */