LOK: tilebench improvements
[LibreOffice.git] / sc / inc / tabprotection.hxx
blob61e0d605e6a8d472f46df5ef64ddfaff08760e66
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 <memory>
30 class ScDocument;
31 class ScTableProtectionImpl;
33 enum ScPasswordHash
35 PASSHASH_SHA1 = 0,
36 PASSHASH_XL,
37 PASSHASH_UNSPECIFIED
40 namespace ScPassHashHelper
42 /** Check for the compatibility of all password hashes. If there is at
43 * least one hash that needs to be regenerated, it returns true. If all
44 * hash values are compatible with the specified hash type, then it
45 * returns false. */
46 bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
48 OUString getHashURI(ScPasswordHash eHash);
50 ScPasswordHash getHashTypeFromURI(const OUString& rURI);
53 class SAL_NO_VTABLE ScPassHashProtectable
55 public:
56 virtual ~ScPassHashProtectable() = 0;
58 virtual bool isProtected() const = 0;
59 virtual bool isProtectedWithPass() const = 0;
60 virtual void setProtected(bool bProtected) = 0;
62 virtual bool isPasswordEmpty() const = 0;
63 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
64 virtual void setPassword(const OUString& aPassText) = 0;
65 virtual css::uno::Sequence<sal_Int8> getPasswordHash(
66 ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
67 virtual void setPasswordHash(
68 const css::uno::Sequence<sal_Int8>& aPassword,
69 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) = 0;
70 virtual bool verifyPassword(const OUString& aPassText) const = 0;
73 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
75 public:
76 enum Option
78 STRUCTURE = 0,
79 WINDOWS,
80 NONE ///< last item - used to resize the vector
83 explicit ScDocProtection();
84 explicit ScDocProtection(const ScDocProtection& r);
85 virtual ~ScDocProtection() override;
87 virtual bool isProtected() const override;
88 virtual bool isProtectedWithPass() const override;
89 virtual void setProtected(bool bProtected) override;
91 virtual bool isPasswordEmpty() const override;
92 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
93 virtual void setPassword(const OUString& aPassText) override;
94 virtual css::uno::Sequence<sal_Int8> getPasswordHash(
95 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
96 virtual void setPasswordHash(
97 const css::uno::Sequence<sal_Int8>& aPassword,
98 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) override;
99 virtual bool verifyPassword(const OUString& aPassText) const override;
101 bool isOptionEnabled(Option eOption) const;
102 void setOption(Option eOption, bool bEnabled);
104 private:
105 std::unique_ptr<ScTableProtectionImpl> mpImpl;
108 /** Container for the Excel EnhancedProtection feature.
110 struct ScEnhancedProtection
112 ScRangeListRef maRangeList;
113 sal_uInt32 mnAreserved;
114 sal_uInt32 mnPasswordVerifier;
115 OUString maTitle;
116 ::std::vector< sal_uInt8 > maSecurityDescriptor; // imported as raw BIFF data
117 OUString maSecurityDescriptorXML; // imported from OOXML
118 // OOXML password definitions
119 OUString maAlgorithmName;
120 OUString maHashValue;
121 OUString maSaltValue;
122 sal_uInt32 mnSpinCount;
124 ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0), mnSpinCount(0) {}
126 bool hasSecurityDescriptor() const
128 return !maSecurityDescriptor.empty() || !maSecurityDescriptorXML.isEmpty();
131 bool hasPassword() const
133 return mnPasswordVerifier != 0 || !maHashValue.isEmpty();
137 /** sheet protection state container
139 * This class stores sheet's protection state: 1) whether the protection
140 * is on, 2) password and/or password hash, and 3) any associated
141 * protection options. This class is also used as a protection state
142 * container for the undo/redo stack, in which case the password, hash and
143 * the options need to be preserved even when the protection flag is
144 * off. */
145 class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
147 public:
148 enum Option
150 AUTOFILTER = 0,
151 DELETE_COLUMNS,
152 DELETE_ROWS,
153 FORMAT_CELLS,
154 FORMAT_COLUMNS,
155 FORMAT_ROWS,
156 INSERT_COLUMNS,
157 INSERT_HYPERLINKS,
158 INSERT_ROWS,
159 OBJECTS,
160 PIVOT_TABLES,
161 SCENARIOS,
162 SELECT_LOCKED_CELLS,
163 SELECT_UNLOCKED_CELLS,
164 SORT,
165 NONE ///< last item - used to resize the vector
168 explicit ScTableProtection();
169 explicit ScTableProtection(const ScTableProtection& r);
170 virtual ~ScTableProtection() override;
172 virtual bool isProtected() const override;
173 virtual bool isProtectedWithPass() const override;
174 virtual void setProtected(bool bProtected) override;
176 virtual bool isPasswordEmpty() const override;
177 virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
178 virtual void setPassword(const OUString& aPassText) override;
179 virtual css::uno::Sequence<sal_Int8> getPasswordHash(
180 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const override;
181 virtual void setPasswordHash(
182 const css::uno::Sequence<sal_Int8>& aPassword,
183 ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) override;
184 virtual bool verifyPassword(const OUString& aPassText) const override;
186 bool isOptionEnabled(Option eOption) const;
187 void setOption(Option eOption, bool bEnabled);
189 void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt );
190 const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const;
191 bool updateReference( UpdateRefMode, const ScDocument*, const ScRange& rWhere, SCCOL nDx, SCROW nDy, SCTAB nDz );
192 bool isBlockEditable( const ScRange& rRange ) const;
193 bool isSelectionEditable( const ScRangeList& rRangeList ) const;
195 private:
196 std::unique_ptr<ScTableProtectionImpl> mpImpl;
199 #endif
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */