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