LCOV - code coverage report
Current view: top level - sc/inc - tabprotection.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 7 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          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 "rangelst.hxx"
      28             : #include <boost/shared_ptr.hpp>
      29             : 
      30             : class ScDocument;
      31             : class ScTableProtectionImpl;
      32             : 
      33             : enum ScPasswordHash
      34             : {
      35             :     PASSHASH_SHA1 = 0,
      36             :     PASSHASH_XL,
      37             :     PASSHASH_UNSPECIFIED
      38             : };
      39             : 
      40             : class ScPassHashHelper
      41             : {
      42             : public:
      43             :     /** Check for the compatibility of all password hashes.  If there is at
      44             :      * least one hash that needs to be regenerated, it returns true.  If all
      45             :      * hash values are compatible with the specified hash type, then it
      46             :      * returns false. */
      47             :     static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED);
      48             : 
      49             :     static OUString getHashURI(ScPasswordHash eHash);
      50             : 
      51             :     static ScPasswordHash getHashTypeFromURI(const OUString& rURI);
      52             : 
      53             : private:
      54             :     ScPassHashHelper();
      55             :     ~ScPassHashHelper();
      56             : };
      57             : 
      58           0 : class SAL_NO_VTABLE ScPassHashProtectable
      59             : {
      60             : public:
      61             :     virtual ~ScPassHashProtectable() = 0;
      62             : 
      63             :     virtual bool isProtected() const = 0;
      64             :     virtual bool isProtectedWithPass() const = 0;
      65             :     virtual void setProtected(bool bProtected) = 0;
      66             : 
      67             :     virtual bool isPasswordEmpty() const = 0;
      68             :     virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const = 0;
      69             :     virtual void setPassword(const OUString& aPassText) = 0;
      70             :     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
      71             :         ScPasswordHash eHash, ScPasswordHash eHas2 = PASSHASH_UNSPECIFIED) const = 0;
      72             :     virtual void setPasswordHash(
      73             :         const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
      74             :         ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) = 0;
      75             :     virtual bool verifyPassword(const OUString& aPassText) const = 0;
      76             : };
      77             : 
      78             : class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable
      79             : {
      80             : public:
      81             :     enum Option
      82             :     {
      83             :         STRUCTURE = 0,
      84             :         WINDOWS,
      85             :         CONTENT,
      86             :         NONE        ///< last item - used to resize the vector
      87             :     };
      88             : 
      89             :     explicit ScDocProtection();
      90             :     explicit ScDocProtection(const ScDocProtection& r);
      91             :     virtual ~ScDocProtection();
      92             : 
      93             :     virtual bool isProtected() const SAL_OVERRIDE;
      94             :     virtual bool isProtectedWithPass() const SAL_OVERRIDE;
      95             :     virtual void setProtected(bool bProtected) SAL_OVERRIDE;
      96             : 
      97             :     virtual bool isPasswordEmpty() const SAL_OVERRIDE;
      98             :     virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
      99             :     virtual void setPassword(const OUString& aPassText) SAL_OVERRIDE;
     100             :     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
     101             :         ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
     102             :     virtual void setPasswordHash(
     103             :         const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
     104             :         ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) SAL_OVERRIDE;
     105             :     virtual bool verifyPassword(const OUString& aPassText) const SAL_OVERRIDE;
     106             : 
     107             :     bool isOptionEnabled(Option eOption) const;
     108             :     void setOption(Option eOption, bool bEnabled);
     109             : 
     110             : private:
     111             :     ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
     112             : };
     113             : 
     114             : /** Container for the Excel EnhancedProtection feature.
     115             :  */
     116           0 : struct ScEnhancedProtection
     117             : {
     118             :     ScRangeListRef              maRangeList;
     119             :     sal_uInt32                  mnAreserved;
     120             :     sal_uInt32                  mnPasswordVerifier;
     121             :     OUString                    maTitle;
     122             :     ::std::vector< sal_uInt8 >  maSecurityDescriptor;       // imported as raw BIFF data
     123             :     OUString                    maSecurityDescriptorXML;    // imported from OOXML
     124             :     // OOXML password definitions
     125             :     OUString                    maAlgorithmName;
     126             :     OUString                    maHashValue;
     127             :     OUString                    maSaltValue;
     128             :     sal_uInt32                  mnSpinCount;
     129             : 
     130           0 :     ScEnhancedProtection() : mnAreserved(0), mnPasswordVerifier(0), mnSpinCount(0) {}
     131             : 
     132           0 :     bool hasSecurityDescriptor() const
     133             :     {
     134           0 :         return !maSecurityDescriptor.empty() || !maSecurityDescriptorXML.isEmpty();
     135             :     }
     136             : 
     137           0 :     bool hasPassword() const
     138             :     {
     139           0 :         return mnPasswordVerifier != 0 || !maHashValue.isEmpty();
     140             :     }
     141             : };
     142             : 
     143             : /** sheet protection state container
     144             :  *
     145             :  * This class stores sheet's protection state: 1) whether the protection
     146             :  * is on, 2) password and/or password hash, and 3) any associated
     147             :  * protection options.  This class is also used as a protection state
     148             :  * container for the undo/redo stack, in which case the password, hash and
     149             :  * the options need to be preserved even when the protection flag is
     150             :  * off. */
     151             : class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable
     152             : {
     153             : public:
     154             :     enum Option
     155             :     {
     156             :         AUTOFILTER = 0,
     157             :         DELETE_COLUMNS,
     158             :         DELETE_ROWS,
     159             :         FORMAT_CELLS,
     160             :         FORMAT_COLUMNS,
     161             :         FORMAT_ROWS,
     162             :         INSERT_COLUMNS,
     163             :         INSERT_HYPERLINKS,
     164             :         INSERT_ROWS,
     165             :         OBJECTS,
     166             :         PIVOT_TABLES,
     167             :         SCENARIOS,
     168             :         SELECT_LOCKED_CELLS,
     169             :         SELECT_UNLOCKED_CELLS,
     170             :         SHEET,
     171             :         SORT,
     172             :         NONE        ///< last item - used to resize the vector
     173             :     };
     174             : 
     175             :     explicit ScTableProtection();
     176             :     explicit ScTableProtection(const ScTableProtection& r);
     177             :     virtual ~ScTableProtection();
     178             : 
     179             :     virtual bool isProtected() const SAL_OVERRIDE;
     180             :     virtual bool isProtectedWithPass() const SAL_OVERRIDE;
     181             :     virtual void setProtected(bool bProtected) SAL_OVERRIDE;
     182             : 
     183             :     virtual bool isPasswordEmpty() const SAL_OVERRIDE;
     184             :     virtual bool hasPasswordHash(ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
     185             :     virtual void setPassword(const OUString& aPassText) SAL_OVERRIDE;
     186             :     virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(
     187             :         ScPasswordHash eHash, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) const SAL_OVERRIDE;
     188             :     virtual void setPasswordHash(
     189             :         const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword,
     190             :         ScPasswordHash eHash = PASSHASH_SHA1, ScPasswordHash eHash2 = PASSHASH_UNSPECIFIED) SAL_OVERRIDE;
     191             :     virtual bool verifyPassword(const OUString& aPassText) const SAL_OVERRIDE;
     192             : 
     193             :     bool isOptionEnabled(Option eOption) const;
     194             :     void setOption(Option eOption, bool bEnabled);
     195             : 
     196             :     void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt );
     197             :     const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const;
     198             :     bool updateReference( UpdateRefMode, ScDocument*, const ScRange& rWhere, SCsCOL nDx, SCsROW nDy, SCsTAB nDz );
     199             :     bool isBlockEditable( const ScRange& rRange ) const;
     200             :     bool isSelectionEditable( const ScRangeList& rRangeList ) const;
     201             : 
     202             : 
     203             : private:
     204             :     ::boost::shared_ptr<ScTableProtectionImpl> mpImpl;
     205             : };
     206             : 
     207             : #endif
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10