Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_TAB_PROTECTION_HXX
21 : #define SC_TAB_PROTECTION_HXX
22 :
23 : #include "sal/types.h"
24 : #include <com/sun/star/uno/Sequence.hxx>
25 :
26 : #include "global.hxx"
27 : #include <boost/shared_ptr.hpp>
28 :
29 : class ScDocument;
30 : class ScTableProtectionImpl;
31 :
32 : enum ScPasswordHash
33 : {
34 : PASSHASH_SHA1 = 0,
35 : PASSHASH_XL,
36 : PASSHASH_UNSPECIFIED
37 : };
38 :
39 : class ScPassHashHelper
40 : {
41 : public:
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 : static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
47 :
48 : static OUString getHashURI(ScPasswordHash eHash);
49 :
50 : static ScPasswordHash getHashTypeFromURI(const OUString& rURI);
51 :
52 : private:
53 : ScPassHashHelper();
54 : ~ScPassHashHelper();
55 : };
56 :
57 : // ============================================================================
58 :
59 29 : class SAL_NO_VTABLE ScPassHashProtectable
60 : {
61 : public:
62 : virtual ~ScPassHashProtectable() = 0;
63 :
64 : virtual bool isProtected() const = 0;
65 : virtual bool isProtectedWithPass() const = 0;
66 : virtual void setProtected(bool bProtected) = 0;
67 :
68 : virtual bool isPasswordEmpty() const = 0;
69 : virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
70 : virtual void setPassword(const String& aPassText) = 0;
71 : virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
72 : ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
73 : virtual void setPasswordHash(
74 : const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
75 : ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) = 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, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
102 : virtual void setPassword(const String& aPassText);
103 : virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
104 : ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
105 : virtual void setPasswordHash(
106 : const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
107 : ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
108 : virtual bool verifyPassword(const String& aPassText) const;
109 :
110 : bool isOptionEnabled(Option eOption) const;
111 : void setOption(Option eOption, bool bEnabled);
112 :
113 : private:
114 : ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
115 : };
116 :
117 : // ============================================================================
118 :
119 : /** sheet protection state container
120 : *
121 : * This class stores sheet's protection state: 1) whether the protection
122 : * is on, 2) password and/or password hash, and 3) any associated
123 : * protection options. This class is also used as a protection state
124 : * container for the undo/redo stack, in which case the password, hash and
125 : * the options need to be preserved even when the protection flag is
126 : * off. */
127 : class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
128 : {
129 : public:
130 : enum Option
131 : {
132 : AUTOFILTER = 0,
133 : DELETE_COLUMNS,
134 : DELETE_ROWS,
135 : FORMAT_CELLS,
136 : FORMAT_COLUMNS,
137 : FORMAT_ROWS,
138 : INSERT_COLUMNS,
139 : INSERT_HYPERLINKS,
140 : INSERT_ROWS,
141 : OBJECTS,
142 : PIVOT_TABLES,
143 : SCENARIOS,
144 : SELECT_LOCKED_CELLS,
145 : SELECT_UNLOCKED_CELLS,
146 : SHEET,
147 : SORT,
148 : NONE ///< last item - used to resize the vector
149 : };
150 :
151 : explicit ScTableProtection();
152 : explicit ScTableProtection(const ScTableProtection& r);
153 : virtual ~ScTableProtection();
154 :
155 : virtual bool isProtected() const;
156 : virtual bool isProtectedWithPass() const;
157 : virtual void setProtected(bool bProtected);
158 :
159 : virtual bool isPasswordEmpty() const;
160 : virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
161 : virtual void setPassword(const String& aPassText);
162 : virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
163 : ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const;
164 : virtual void setPasswordHash(
165 : const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
166 : ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
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 :
179 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|