xref: /trunk/main/sc/inc/tabprotection.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_TAB_PROTECTION_HXX
29 #define SC_TAB_PROTECTION_HXX
30 
31 #include "sal/types.h"
32 #include <com/sun/star/uno/Sequence.hxx>
33 
34 #include "global.hxx"
35 #include <vector>
36 #include <boost/shared_ptr.hpp>
37 
38 #define ENABLE_SHEET_PROTECTION 0
39 
40 class ScDocument;
41 class ScTableProtectionImpl;
42 
43 enum ScPasswordHash
44 {
45     PASSHASH_OOO = 0,
46     PASSHASH_XL
47 };
48 
49 class ScPassHashHelper
50 {
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);
57 
58 private:
59     ScPassHashHelper();
60     ~ScPassHashHelper();
61 };
62 
63 // ============================================================================
64 
65 class SAL_NO_VTABLE ScPassHashProtectable
66 {
67 public:
68     virtual ~ScPassHashProtectable() = 0;
69 
70     virtual bool isProtected() const = 0;
71     virtual bool isProtectedWithPass() const = 0;
72     virtual void setProtected(bool bProtected) = 0;
73 
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;
81 };
82 
83 // ============================================================================
84 
85 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
86 {
87 public:
88     enum Option
89     {
90         STRUCTURE = 0,
91         WINDOWS,
92         CONTENT,
93         NONE        // last item - used to resize the vector
94     };
95 
96     explicit ScDocProtection();
97     explicit ScDocProtection(const ScDocProtection& r);
98     virtual ~ScDocProtection();
99 
100     virtual bool isProtected() const;
101     virtual bool isProtectedWithPass() const;
102     virtual void setProtected(bool bProtected);
103 
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;
111 
112     bool isOptionEnabled(Option eOption) const;
113     void setOption(Option eOption, bool bEnabled);
114 
115 private:
116     ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
117 };
118 
119 // ============================================================================
120 
121 /** sheet protection state container
122 
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
130 {
131 public:
132     enum Option
133     {
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
151     };
152 
153     explicit ScTableProtection();
154     explicit ScTableProtection(const ScTableProtection& r);
155     virtual ~ScTableProtection();
156 
157     virtual bool isProtected() const;
158     virtual bool isProtectedWithPass() const;
159     virtual void setProtected(bool bProtected);
160 
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;
168 
169     bool isOptionEnabled(Option eOption) const;
170     void setOption(Option eOption, bool bEnabled);
171 
172 private:
173     ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
174 };
175 
176 
177 #endif
178