diff options
author | Eike Rathke <erack@redhat.com> | 2014-03-22 01:04:54 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2014-03-22 01:06:08 +0100 |
commit | 926435ef5ab26e647c09887d471bde25b24e1c16 (patch) | |
tree | 35e700777119d76eb7d5fad6efd118d33405f8f1 /sc | |
parent | fc58d7ae8e45dc45988ee247b5a1b8ad5adeb8ac (diff) |
added editable testers to enhanced table protection
Change-Id: If535d92dada1e8a539af9aa105aa2f16aed629e9
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/tabprotection.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/tabprotection.cxx | 66 |
2 files changed, 68 insertions, 0 deletions
diff --git a/sc/inc/tabprotection.hxx b/sc/inc/tabprotection.hxx index a32f50f4828f..0133286364f1 100644 --- a/sc/inc/tabprotection.hxx +++ b/sc/inc/tabprotection.hxx @@ -180,6 +180,8 @@ public: void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt ); const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const; bool updateReference( UpdateRefMode, ScDocument*, const ScRange& rWhere, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); + bool isBlockEditable( const ScRange& rRange ) const; + bool isSelectionEditable( const ScRangeList& rRangeList ) const; private: diff --git a/sc/source/core/data/tabprotection.cxx b/sc/source/core/data/tabprotection.cxx index 8b4aa7ccbe9a..9922151a53e6 100644 --- a/sc/source/core/data/tabprotection.cxx +++ b/sc/source/core/data/tabprotection.cxx @@ -120,6 +120,8 @@ public: void setEnhancedProtection( const ::std::vector< ScEnhancedProtection > & rProt ); const ::std::vector< ScEnhancedProtection > & getEnhancedProtection() const; bool updateReference( UpdateRefMode, ScDocument*, const ScRange& rWhere, SCsCOL nDx, SCsROW nDy, SCsTAB nDz ); + bool isBlockEditable( const ScRange& rRange ) const; + bool isSelectionEditable( const ScRangeList& rRangeList ) const; private: OUString maPassText; @@ -381,6 +383,60 @@ bool ScTableProtectionImpl::updateReference( UpdateRefMode eMode, ScDocument* pD return bChanged; } +bool ScTableProtectionImpl::isBlockEditable( const ScRange& rRange ) const +{ + // No protection exception or overriding permission to edit if empty. + if (maEnhancedProtection.empty()) + return false; + + // No security descriptor in an enhanced protection means the ranges of + // that protection are editable. If there is any security descriptor + // present we assume the permission to edit is not granted. Until we + // actually can evaluate the descriptors.. + + for (::std::vector<ScEnhancedProtection>::const_iterator it(maEnhancedProtection.begin()), + itEnd(maEnhancedProtection.end()); it != itEnd; ++it) + { + if ((*it).maSecurityDescriptor.empty() && (*it).maRangeList.Is()) + { + if ((*it).maRangeList->In( rRange)) + return true; + } + } + + // For a single address, a simple check with single ranges was sufficient. + if (rRange.aStart == rRange.aEnd) + return false; + + // Test also for cases where rRange is encompassed by a union of two or + // more ranges of the list. The original ranges are not necessarily joined. + for (::std::vector<ScEnhancedProtection>::const_iterator it(maEnhancedProtection.begin()), + itEnd(maEnhancedProtection.end()); it != itEnd; ++it) + { + if ((*it).maSecurityDescriptor.empty() && (*it).maRangeList.Is()) + { + ScRangeList aList( (*it).maRangeList->GetIntersectedRange( rRange)); + if (aList.size() == 1 && *aList[0] == rRange) + return true; + } + } + + return false; +} + +bool ScTableProtectionImpl::isSelectionEditable( const ScRangeList& rRangeList ) const +{ + if (rRangeList.empty()) + return false; + + for (size_t i=0, nRanges = rRangeList.size(); i < nRanges; ++i) + { + if (!isBlockEditable( *rRangeList[i])) + return false; + } + return true; +} + ScDocProtection::ScDocProtection() : mpImpl(new ScTableProtectionImpl(static_cast<SCSIZE>(ScDocProtection::NONE))) @@ -550,4 +606,14 @@ bool ScTableProtection::updateReference( UpdateRefMode eMode, ScDocument* pDoc, return mpImpl->updateReference( eMode, pDoc, rWhere, nDx, nDy, nDz); } +bool ScTableProtection::isBlockEditable( const ScRange& rRange ) const +{ + return mpImpl->isBlockEditable( rRange); +} + +bool ScTableProtection::isSelectionEditable( const ScRangeList& rRangeList ) const +{ + return mpImpl->isSelectionEditable( rRangeList); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |