LCOV - code coverage report
Current view: top level - sc/source/filter/oox - worksheetsettings.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 96 150 64.0 %
Date: 2014-04-11 Functions: 12 20 60.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             : #include "worksheetsettings.hxx"
      21             : 
      22             : #include <com/sun/star/util/XProtectable.hpp>
      23             : #include "oox/core/filterbase.hxx"
      24             : #include "oox/helper/attributelist.hxx"
      25             : #include "oox/token/properties.hxx"
      26             : #include "biffinputstream.hxx"
      27             : #include "pagesettings.hxx"
      28             : #include "workbooksettings.hxx"
      29             : #include "tabprotection.hxx"
      30             : #include "document.hxx"
      31             : #include "convuno.hxx"
      32             : 
      33             : namespace oox {
      34             : namespace xls {
      35             : 
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::util;
      39             : 
      40             : using ::oox::core::CodecHelper;
      41             : 
      42             : namespace {
      43             : 
      44             : const sal_uInt8 BIFF12_SHEETPR_FILTERMODE       = 0x01;
      45             : 
      46             : const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES       = 0x0020;
      47             : const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW      = 0x0040;
      48             : const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT      = 0x0080;
      49             : const sal_uInt16 BIFF_SHEETPR_FITTOPAGES        = 0x0100;
      50             : 
      51             : } // namespace
      52             : 
      53          85 : SheetSettingsModel::SheetSettingsModel() :
      54             :     mbFilterMode( false ),
      55             :     mbApplyStyles( false ),
      56             :     mbSummaryBelow( true ),
      57          85 :     mbSummaryRight( true )
      58             : {
      59          85 : }
      60             : 
      61          85 : SheetProtectionModel::SheetProtectionModel() :
      62             :     mnPasswordHash( 0 ),
      63             :     mbSheet( false ),
      64             :     mbObjects( false ),
      65             :     mbScenarios( false ),
      66             :     mbFormatCells( true ),
      67             :     mbFormatColumns( true ),
      68             :     mbFormatRows( true ),
      69             :     mbInsertColumns( true ),
      70             :     mbInsertRows( true ),
      71             :     mbInsertHyperlinks( true ),
      72             :     mbDeleteColumns( true ),
      73             :     mbDeleteRows( true ),
      74             :     mbSelectLocked( false ),
      75             :     mbSort( true ),
      76             :     mbAutoFilter( true ),
      77             :     mbPivotTables( true ),
      78          85 :     mbSelectUnlocked( false )
      79             : {
      80          85 : }
      81             : 
      82          85 : WorksheetSettings::WorksheetSettings( const WorksheetHelper& rHelper ) :
      83             :     WorksheetHelper( rHelper ),
      84          85 :     maPhoneticSett( rHelper )
      85             : {
      86          85 : }
      87             : 
      88          53 : void WorksheetSettings::importSheetPr( const AttributeList& rAttribs )
      89             : {
      90          53 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
      91          53 :     maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
      92          53 : }
      93             : 
      94           0 : void WorksheetSettings::importChartSheetPr( const AttributeList& rAttribs )
      95             : {
      96           0 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
      97           0 : }
      98             : 
      99          32 : void WorksheetSettings::importTabColor( const AttributeList& rAttribs )
     100             : {
     101          32 :     maSheetSettings.maTabColor.importColor( rAttribs );
     102          32 : }
     103             : 
     104           0 : void WorksheetSettings::importOutlinePr( const AttributeList& rAttribs )
     105             : {
     106           0 :     maSheetSettings.mbApplyStyles  = rAttribs.getBool( XML_applyStyles, false );
     107           0 :     maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
     108           0 :     maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
     109           0 : }
     110             : 
     111           4 : void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
     112             : {
     113           4 :     maSheetProt.mnPasswordHash     = CodecHelper::getPasswordHash( rAttribs, XML_password );
     114           4 :     maSheetProt.mbSheet            = rAttribs.getBool( XML_sheet, false );
     115           4 :     maSheetProt.mbObjects          = rAttribs.getBool( XML_objects, false );
     116           4 :     maSheetProt.mbScenarios        = rAttribs.getBool( XML_scenarios, false );
     117           4 :     maSheetProt.mbFormatCells      = rAttribs.getBool( XML_formatCells, true );
     118           4 :     maSheetProt.mbFormatColumns    = rAttribs.getBool( XML_formatColumns, true );
     119           4 :     maSheetProt.mbFormatRows       = rAttribs.getBool( XML_formatRows, true );
     120           4 :     maSheetProt.mbInsertColumns    = rAttribs.getBool( XML_insertColumns, true );
     121           4 :     maSheetProt.mbInsertRows       = rAttribs.getBool( XML_insertRows, true );
     122           4 :     maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
     123           4 :     maSheetProt.mbDeleteColumns    = rAttribs.getBool( XML_deleteColumns, true );
     124           4 :     maSheetProt.mbDeleteRows       = rAttribs.getBool( XML_deleteRows, true );
     125           4 :     maSheetProt.mbSelectLocked     = rAttribs.getBool( XML_selectLockedCells, false );
     126           4 :     maSheetProt.mbSort             = rAttribs.getBool( XML_sort, true );
     127           4 :     maSheetProt.mbAutoFilter       = rAttribs.getBool( XML_autoFilter, true );
     128           4 :     maSheetProt.mbPivotTables      = rAttribs.getBool( XML_pivotTables, true );
     129           4 :     maSheetProt.mbSelectUnlocked   = rAttribs.getBool( XML_selectUnlockedCells, false );
     130           4 : }
     131             : 
     132           1 : void WorksheetSettings::importProtectedRanges( const AttributeList& rAttribs )
     133             : {
     134             :     (void)rAttribs; // no attribs known (yet?)
     135           1 : }
     136             : 
     137           5 : void WorksheetSettings::importProtectedRange( const AttributeList& rAttribs )
     138             : {
     139           5 :     ScEnhancedProtection aProt;
     140           5 :     aProt.maTitle = rAttribs.getString( XML_name, OUString());
     141             :     /* XXX ECMA-376/OOXML XMLSchema and ISO/IEC 29500 say 'securityDescriptor'
     142             :      * would be an element, but Excel2013 stores it as attribute. */
     143           5 :     aProt.maSecurityDescriptorXML = rAttribs.getString( XML_securityDescriptor, OUString());
     144             :     /* XXX ECMA-376/OOXML or ISO/IEC 29500 do not even mention a 'password'
     145             :      * attribute here (or anywhere else), but this is what Excel2013 writes,
     146             :      * similar to BIFF, if the original file was a BIFF file. OOXML XMLschema
     147             :      * and ISO/IEC 29500 instead define 'algorithmName', 'hashValue',
     148             :      * 'saltValue' and 'spinCount' that are written if the protection was newly
     149             :      * created. */
     150           5 :     aProt.mnPasswordVerifier = rAttribs.getIntegerHex( XML_password, 0);
     151           5 :     aProt.maAlgorithmName = rAttribs.getString( XML_algorithmName, OUString());
     152           5 :     aProt.maHashValue = rAttribs.getString( XML_hashValue, OUString());
     153           5 :     aProt.maSaltValue = rAttribs.getString( XML_saltValue, OUString());
     154           5 :     aProt.mnSpinCount = rAttribs.getUnsigned( XML_spinCount, 0);
     155          10 :     OUString aRefs( rAttribs.getString( XML_sqref, OUString()));
     156           5 :     if (!aRefs.isEmpty())
     157             :     {
     158           5 :         ApiCellRangeList aRangeList;
     159           5 :         getAddressConverter().convertToCellRangeList( aRangeList, aRefs, getSheetIndex(), true );
     160           5 :         if (!aRangeList.empty())
     161             :         {
     162           5 :             ScRangeList* pRangeList = aProt.maRangeList = new ScRangeList;
     163          10 :             for (ApiCellRangeList::const_iterator itr( aRangeList.begin()), end( aRangeList.end()); itr != end; ++itr)
     164             :             {
     165           5 :                 ScRange aRange;
     166           5 :                 ScUnoConversion::FillScRange( aRange, *itr);
     167           5 :                 pRangeList->Append( aRange);
     168             :             }
     169           5 :         }
     170             :     }
     171          10 :     maSheetProt.maEnhancedProtections.push_back( aProt);
     172           5 : }
     173             : 
     174           0 : void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
     175             : {
     176           0 :     maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
     177           0 :     maSheetProt.mbSheet        = rAttribs.getBool( XML_content, false );
     178           0 :     maSheetProt.mbObjects      = rAttribs.getBool( XML_objects, false );
     179           0 : }
     180             : 
     181           6 : void WorksheetSettings::importPhoneticPr( const AttributeList& rAttribs )
     182             : {
     183           6 :     maPhoneticSett.importPhoneticPr( rAttribs );
     184           6 : }
     185             : 
     186           0 : void WorksheetSettings::importSheetPr( SequenceInputStream& rStrm )
     187             : {
     188             :     sal_uInt16 nFlags1;
     189             :     sal_uInt8 nFlags2;
     190           0 :     rStrm >> nFlags1 >> nFlags2 >> maSheetSettings.maTabColor;
     191           0 :     rStrm.skip( 8 );    // sync anchor cell
     192           0 :     rStrm >> maSheetSettings.maCodeName;
     193             :     // sheet settings
     194           0 :     maSheetSettings.mbFilterMode = getFlag( nFlags2, BIFF12_SHEETPR_FILTERMODE );
     195             :     // outline settings, equal flags in all BIFFs
     196           0 :     maSheetSettings.mbApplyStyles  = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
     197           0 :     maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
     198           0 :     maSheetSettings.mbSummaryBelow = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSBELOW );
     199             :     /*  Fit printout to width/height - for whatever reason, this flag is still
     200             :         stored separated from the page settings */
     201           0 :     getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
     202           0 : }
     203             : 
     204           0 : void WorksheetSettings::importChartSheetPr( SequenceInputStream& rStrm )
     205             : {
     206           0 :     rStrm.skip( 2 );    // flags, contains only the 'published' flag
     207           0 :     rStrm >> maSheetSettings.maTabColor >> maSheetSettings.maCodeName;
     208           0 : }
     209             : 
     210           0 : void WorksheetSettings::importSheetProtection( SequenceInputStream& rStrm )
     211             : {
     212           0 :     rStrm >> maSheetProt.mnPasswordHash;
     213             :     // no flags field for all these boolean flags?!?
     214           0 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     215           0 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     216           0 :     maSheetProt.mbScenarios        = rStrm.readInt32() != 0;
     217           0 :     maSheetProt.mbFormatCells      = rStrm.readInt32() != 0;
     218           0 :     maSheetProt.mbFormatColumns    = rStrm.readInt32() != 0;
     219           0 :     maSheetProt.mbFormatRows       = rStrm.readInt32() != 0;
     220           0 :     maSheetProt.mbInsertColumns    = rStrm.readInt32() != 0;
     221           0 :     maSheetProt.mbInsertRows       = rStrm.readInt32() != 0;
     222           0 :     maSheetProt.mbInsertHyperlinks = rStrm.readInt32() != 0;
     223           0 :     maSheetProt.mbDeleteColumns    = rStrm.readInt32() != 0;
     224           0 :     maSheetProt.mbDeleteRows       = rStrm.readInt32() != 0;
     225           0 :     maSheetProt.mbSelectLocked     = rStrm.readInt32() != 0;
     226           0 :     maSheetProt.mbSort             = rStrm.readInt32() != 0;
     227           0 :     maSheetProt.mbAutoFilter       = rStrm.readInt32() != 0;
     228           0 :     maSheetProt.mbPivotTables      = rStrm.readInt32() != 0;
     229           0 :     maSheetProt.mbSelectUnlocked   = rStrm.readInt32() != 0;
     230           0 : }
     231             : 
     232           0 : void WorksheetSettings::importChartProtection( SequenceInputStream& rStrm )
     233             : {
     234           0 :     rStrm >> maSheetProt.mnPasswordHash;
     235             :     // no flags field for all these boolean flags?!?
     236           0 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     237           0 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     238           0 : }
     239             : 
     240           0 : void WorksheetSettings::importPhoneticPr( SequenceInputStream& rStrm )
     241             : {
     242           0 :     maPhoneticSett.importPhoneticPr( rStrm );
     243           0 : }
     244             : 
     245          85 : void WorksheetSettings::finalizeImport()
     246             : {
     247             :     // sheet protection
     248          85 :     if( maSheetProt.mbSheet )
     249             :     {
     250           4 :         ScTableProtection aProtect;
     251           4 :         aProtect.setProtected(true);
     252           4 :         if (maSheetProt.mnPasswordHash)
     253             :         {
     254           2 :             Sequence<sal_Int8> aPass(2);
     255           2 :             aPass[0] = ( maSheetProt.mnPasswordHash>> 8) & 0xFF;
     256           2 :             aPass[1] = maSheetProt.mnPasswordHash & 0xFF;
     257           2 :             aProtect.setPasswordHash(aPass, PASSHASH_XL);
     258             :         }
     259           4 :         aProtect.setOption( ScTableProtection::OBJECTS, !maSheetProt.mbObjects);
     260           4 :         aProtect.setOption( ScTableProtection::SCENARIOS, !maSheetProt.mbScenarios );
     261           4 :         aProtect.setOption( ScTableProtection::FORMAT_CELLS, !maSheetProt.mbFormatCells );
     262           4 :         aProtect.setOption( ScTableProtection::FORMAT_COLUMNS, !maSheetProt.mbFormatColumns );
     263           4 :         aProtect.setOption( ScTableProtection::FORMAT_ROWS, !maSheetProt.mbFormatRows );
     264           4 :         aProtect.setOption( ScTableProtection::INSERT_COLUMNS, !maSheetProt.mbInsertColumns );
     265           4 :         aProtect.setOption( ScTableProtection::INSERT_ROWS,  !maSheetProt.mbInsertRows );
     266           4 :         aProtect.setOption( ScTableProtection::INSERT_HYPERLINKS, !maSheetProt.mbInsertHyperlinks );
     267           4 :         aProtect.setOption( ScTableProtection::DELETE_COLUMNS, !maSheetProt.mbDeleteColumns );
     268           4 :         aProtect.setOption( ScTableProtection::DELETE_ROWS,!maSheetProt.mbDeleteRows );
     269           4 :         aProtect.setOption( ScTableProtection::SELECT_LOCKED_CELLS, !maSheetProt.mbSelectLocked );
     270           4 :         aProtect.setOption( ScTableProtection::SORT, !maSheetProt.mbSort );
     271           4 :         aProtect.setOption( ScTableProtection::AUTOFILTER, !maSheetProt.mbAutoFilter );
     272           4 :         aProtect.setOption( ScTableProtection::PIVOT_TABLES, !maSheetProt.mbPivotTables );
     273           4 :         aProtect.setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, !maSheetProt.mbSelectUnlocked );
     274             : 
     275           4 :         aProtect.setEnhancedProtection( maSheetProt.maEnhancedProtections);
     276             : 
     277           4 :         getScDocument().SetTabProtection( getSheetIndex(), &aProtect );
     278             :     }
     279             : 
     280             :     // VBA code name
     281          85 :     PropertySet aPropSet( getSheet() );
     282          85 :     aPropSet.setProperty( PROP_CodeName, maSheetSettings.maCodeName );
     283             : 
     284             :     // sheet tab color
     285          85 :     if( !maSheetSettings.maTabColor.isAuto() )
     286             :     {
     287          85 :         sal_Int32 nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() );
     288          85 :         aPropSet.setProperty( PROP_TabColor, nColor );
     289          85 :     }
     290          85 : }
     291             : 
     292             : } // namespace xls
     293          18 : } // namespace oox
     294             : 
     295             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10