xref: /aoo42x/main/sc/inc/tabprotection.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_TAB_PROTECTION_HXX
25 #define SC_TAB_PROTECTION_HXX
26 
27 #include "sal/types.h"
28 #include <com/sun/star/uno/Sequence.hxx>
29 
30 #include "global.hxx"
31 #include <vector>
32 #include <boost/shared_ptr.hpp>
33 
34 #define ENABLE_SHEET_PROTECTION 0
35 
36 class ScDocument;
37 class ScTableProtectionImpl;
38 
39 enum ScPasswordHash
40 {
41     PASSHASH_OOO = 0,
42     PASSHASH_XL
43 };
44 
45 class ScPassHashHelper
46 {
47 public:
48     /** Check for the compatibility of all password hashes.  If there is at
49         least one hash that needs to be regenerated, it returns true.  If all
50         hash values are compatible with the specified hash type, then it
51         returns false. */
52     static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash);
53 
54 private:
55     ScPassHashHelper();
56     ~ScPassHashHelper();
57 };
58 
59 // ============================================================================
60 
61 class SAL_NO_VTABLE ScPassHashProtectable
62 {
63 public:
64     virtual ~ScPassHashProtectable() = 0;
65 
66     virtual bool isProtected() const = 0;
67     virtual bool isProtectedWithPass() const = 0;
68     virtual void setProtected(bool bProtected) = 0;
69 
70     virtual bool isPasswordEmpty() const = 0;
71     virtual bool hasPasswordHash(ScPasswordHash eHash) const = 0;
72     virtual void setPassword(const String& aPassText) = 0;
73     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const = 0;
74     virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
75                                  ScPasswordHash eHash = PASSHASH_OOO) = 0;
76     virtual bool verifyPassword(const String& aPassText) const = 0;
77 };
78 
79 // ============================================================================
80 
81 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
82 {
83 public:
84     enum Option
85     {
86         STRUCTURE = 0,
87         WINDOWS,
88         CONTENT,
89         NONE        // last item - used to resize the vector
90     };
91 
92     explicit ScDocProtection();
93     explicit ScDocProtection(const ScDocProtection& r);
94     virtual ~ScDocProtection();
95 
96     virtual bool isProtected() const;
97     virtual bool isProtectedWithPass() const;
98     virtual void setProtected(bool bProtected);
99 
100     virtual bool isPasswordEmpty() const;
101     virtual bool hasPasswordHash(ScPasswordHash eHash) const;
102     virtual void setPassword(const String& aPassText);
103     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
104     virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
105                                  ScPasswordHash eHash = PASSHASH_OOO);
106     virtual bool verifyPassword(const String& aPassText) const;
107 
108     bool isOptionEnabled(Option eOption) const;
109     void setOption(Option eOption, bool bEnabled);
110 
111 private:
112     ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
113 };
114 
115 // ============================================================================
116 
117 /** sheet protection state container
118 
119     This class stores sheet's protection state: 1) whether the protection
120     is on, 2) password and/or password hash, and 3) any associated
121     protection options.  This class is also used as a protection state
122     container for the undo/redo stack, in which case the password, hash and
123     the options need to be preserved even when the protection flag is
124     off. */
125 class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
126 {
127 public:
128     enum Option
129     {
130         AUTOFILTER = 0,
131         DELETE_COLUMNS,
132         DELETE_ROWS,
133         FORMAT_CELLS,
134         FORMAT_COLUMNS,
135         FORMAT_ROWS,
136         INSERT_COLUMNS,
137         INSERT_HYPERLINKS,
138         INSERT_ROWS,
139         OBJECTS,
140         PIVOT_TABLES,
141         SCENARIOS,
142         SELECT_LOCKED_CELLS,
143         SELECT_UNLOCKED_CELLS,
144         SHEET,
145         SORT,
146         NONE        // last item - used to resize the vector
147     };
148 
149     explicit ScTableProtection();
150     explicit ScTableProtection(const ScTableProtection& r);
151     virtual ~ScTableProtection();
152 
153     virtual bool isProtected() const;
154     virtual bool isProtectedWithPass() const;
155     virtual void setProtected(bool bProtected);
156 
157     virtual bool isPasswordEmpty() const;
158     virtual bool hasPasswordHash(ScPasswordHash eHash) const;
159     virtual void setPassword(const String& aPassText);
160     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const;
161     virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
162                                  ScPasswordHash eHash = PASSHASH_OOO);
163     virtual bool verifyPassword(const String& aPassText) const;
164 
165     bool isOptionEnabled(Option eOption) const;
166     void setOption(Option eOption, bool bEnabled);
167 
168 private:
169     ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
170 };
171 
172 
173 #endif
174