merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / inc / tabprotection.hxx
blobd8dbd45d27faf7a0d56147d93e81e29f42923f1a
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>
34 #include "global.hxx"
35 #include <vector>
36 #include <boost/shared_ptr.hpp>
38 #define ENABLE_SHEET_PROTECTION 0
40 class ScDocument;
41 class ScTableProtectionImpl;
43 enum ScPasswordHash
45 PASSHASH_OOO = 0,
46 PASSHASH_XL
49 class ScPassHashHelper
51 public:
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
55 returns false. */
56 static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash);
58 private:
59 ScPassHashHelper();
60 ~ScPassHashHelper();
63 // ============================================================================
65 class SAL_NO_VTABLE ScPassHashProtectable
67 public:
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
87 public:
88 enum Option
90 STRUCTURE = 0,
91 WINDOWS,
92 CONTENT,
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);
115 private:
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
128 off. */
129 class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
131 public:
132 enum Option
134 AUTOFILTER = 0,
135 DELETE_COLUMNS,
136 DELETE_ROWS,
137 FORMAT_CELLS,
138 FORMAT_COLUMNS,
139 FORMAT_ROWS,
140 INSERT_COLUMNS,
141 INSERT_HYPERLINKS,
142 INSERT_ROWS,
143 OBJECTS,
144 PIVOT_TABLES,
145 SCENARIOS,
146 SELECT_LOCKED_CELLS,
147 SELECT_UNLOCKED_CELLS,
148 SHEET,
149 SORT,
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);
172 private:
173 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
177 #endif