Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / inc / tabprotection.hxx
blobb8db018336eb4bdb1b14ed6dd852f279d9b4c7e3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef SC_TAB_PROTECTION_HXX
21 #define SC_TAB_PROTECTION_HXX
23 #include "sal/types.h"
24 #include <com/sun/star/uno/Sequence.hxx>
26 #include "global.hxx"
27 #include <boost/shared_ptr.hpp>
29 class ScDocument;
30 class ScTableProtectionImpl;
32 enum ScPasswordHash
34 PASSHASH_SHA1 = 0,
35 PASSHASH_XL,
36 PASSHASH_UNSPECIFIED
39 class ScPassHashHelper
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);
48 static ::rtl::OUString getHashURI(ScPasswordHash eHash);
50 static ScPasswordHash getHashTypeFromURI(const ::rtl::OUString& rURI);
52 private:
53 ScPassHashHelper();
54 ~ScPassHashHelper();
57 // ============================================================================
59 class SAL_NO_VTABLE ScPassHashProtectable
61 public:
62 virtual ~ScPassHashProtectable() = 0;
64 virtual bool isProtected() const = 0;
65 virtual bool isProtectedWithPass() const = 0;
66 virtual void setProtected(bool bProtected) = 0;
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;
79 // ============================================================================
81 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
83 public:
84 enum Option
86 STRUCTURE = 0,
87 WINDOWS,
88 CONTENT,
89 NONE // last item - used to resize the vector
92 explicit ScDocProtection();
93 explicit ScDocProtection(const ScDocProtection& r);
94 virtual ~ScDocProtection();
96 virtual bool isProtected() const;
97 virtual bool isProtectedWithPass() const;
98 virtual void setProtected(bool bProtected);
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;
110 bool isOptionEnabled(Option eOption) const;
111 void setOption(Option eOption, bool bEnabled);
113 private:
114 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
117 // ============================================================================
119 /** sheet protection state container
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
129 public:
130 enum Option
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
151 explicit ScTableProtection();
152 explicit ScTableProtection(const ScTableProtection& r);
153 virtual ~ScTableProtection();
155 virtual bool isProtected() const;
156 virtual bool isProtectedWithPass() const;
157 virtual void setProtected(bool bProtected);
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;
169 bool isOptionEnabled(Option eOption) const;
170 void setOption(Option eOption, bool bEnabled);
172 private:
173 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
177 #endif
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */