LCOV - code coverage report
Current view: top level - sc/source/filter/oox - worksheetsettings.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 127 152 83.6 %
Date: 2015-06-13 12:38:46 Functions: 14 20 70.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             : namespace {
      41             : 
      42             : const sal_uInt8 BIFF12_SHEETPR_FILTERMODE       = 0x01;
      43             : 
      44             : const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES       = 0x0020;
      45             : const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW      = 0x0040;
      46             : const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT      = 0x0080;
      47             : const sal_uInt16 BIFF_SHEETPR_FITTOPAGES        = 0x0100;
      48             : 
      49             : } // namespace
      50             : 
      51         269 : SheetSettingsModel::SheetSettingsModel() :
      52             :     mbFilterMode( false ),
      53             :     mbApplyStyles( false ),
      54             :     mbSummaryBelow( true ),
      55         269 :     mbSummaryRight( true )
      56             : {
      57         269 : }
      58             : 
      59         269 : SheetProtectionModel::SheetProtectionModel() :
      60             :     mnPasswordHash( 0 ),
      61             :     mbSheet( false ),
      62             :     mbObjects( false ),
      63             :     mbScenarios( false ),
      64             :     mbFormatCells( true ),
      65             :     mbFormatColumns( true ),
      66             :     mbFormatRows( true ),
      67             :     mbInsertColumns( true ),
      68             :     mbInsertRows( true ),
      69             :     mbInsertHyperlinks( true ),
      70             :     mbDeleteColumns( true ),
      71             :     mbDeleteRows( true ),
      72             :     mbSelectLocked( false ),
      73             :     mbSort( true ),
      74             :     mbAutoFilter( true ),
      75             :     mbPivotTables( true ),
      76         269 :     mbSelectUnlocked( false )
      77             : {
      78         269 : }
      79             : 
      80         269 : WorksheetSettings::WorksheetSettings( const WorksheetHelper& rHelper ) :
      81             :     WorksheetHelper( rHelper ),
      82         269 :     maPhoneticSett( rHelper )
      83             : {
      84         269 : }
      85             : 
      86         117 : void WorksheetSettings::importSheetPr( const AttributeList& rAttribs )
      87             : {
      88         117 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
      89         117 :     maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
      90         117 : }
      91             : 
      92           0 : void WorksheetSettings::importChartSheetPr( const AttributeList& rAttribs )
      93             : {
      94           0 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
      95           0 : }
      96             : 
      97          18 : void WorksheetSettings::importTabColor( const AttributeList& rAttribs )
      98             : {
      99          18 :     maSheetSettings.maTabColor.importColor( rAttribs );
     100          18 : }
     101             : 
     102           0 : void WorksheetSettings::importOutlinePr( const AttributeList& rAttribs )
     103             : {
     104           0 :     maSheetSettings.mbApplyStyles  = rAttribs.getBool( XML_applyStyles, false );
     105           0 :     maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
     106           0 :     maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
     107           0 : }
     108             : 
     109           4 : void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
     110             : {
     111           4 :     maSheetProt.mnPasswordHash     = oox::core::CodecHelper::getPasswordHash( rAttribs, XML_password );
     112           4 :     maSheetProt.mbSheet            = rAttribs.getBool( XML_sheet, false );
     113           4 :     maSheetProt.mbObjects          = rAttribs.getBool( XML_objects, false );
     114           4 :     maSheetProt.mbScenarios        = rAttribs.getBool( XML_scenarios, false );
     115           4 :     maSheetProt.mbFormatCells      = rAttribs.getBool( XML_formatCells, true );
     116           4 :     maSheetProt.mbFormatColumns    = rAttribs.getBool( XML_formatColumns, true );
     117           4 :     maSheetProt.mbFormatRows       = rAttribs.getBool( XML_formatRows, true );
     118           4 :     maSheetProt.mbInsertColumns    = rAttribs.getBool( XML_insertColumns, true );
     119           4 :     maSheetProt.mbInsertRows       = rAttribs.getBool( XML_insertRows, true );
     120           4 :     maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
     121           4 :     maSheetProt.mbDeleteColumns    = rAttribs.getBool( XML_deleteColumns, true );
     122           4 :     maSheetProt.mbDeleteRows       = rAttribs.getBool( XML_deleteRows, true );
     123           4 :     maSheetProt.mbSelectLocked     = rAttribs.getBool( XML_selectLockedCells, false );
     124           4 :     maSheetProt.mbSort             = rAttribs.getBool( XML_sort, true );
     125           4 :     maSheetProt.mbAutoFilter       = rAttribs.getBool( XML_autoFilter, true );
     126           4 :     maSheetProt.mbPivotTables      = rAttribs.getBool( XML_pivotTables, true );
     127           4 :     maSheetProt.mbSelectUnlocked   = rAttribs.getBool( XML_selectUnlockedCells, false );
     128           4 : }
     129             : 
     130           1 : void WorksheetSettings::importProtectedRanges( const AttributeList& rAttribs )
     131             : {
     132             :     (void)rAttribs; // no attribs known (yet?)
     133           1 : }
     134             : 
     135           5 : void WorksheetSettings::importProtectedRange( const AttributeList& rAttribs )
     136             : {
     137           5 :     ScEnhancedProtection aProt;
     138           5 :     aProt.maTitle = rAttribs.getString( XML_name, OUString());
     139             :     /* XXX ECMA-376/OOXML XMLSchema and ISO/IEC 29500 say 'securityDescriptor'
     140             :      * would be an element, but Excel2013 stores it as attribute. */
     141           5 :     aProt.maSecurityDescriptorXML = rAttribs.getString( XML_securityDescriptor, OUString());
     142             :     /* XXX ECMA-376/OOXML or ISO/IEC 29500 do not even mention a 'password'
     143             :      * attribute here (or anywhere else), but this is what Excel2013 writes,
     144             :      * similar to BIFF, if the original file was a BIFF file. OOXML XMLschema
     145             :      * and ISO/IEC 29500 instead define 'algorithmName', 'hashValue',
     146             :      * 'saltValue' and 'spinCount' that are written if the protection was newly
     147             :      * created. */
     148           5 :     aProt.mnPasswordVerifier = rAttribs.getIntegerHex( XML_password, 0);
     149           5 :     aProt.maAlgorithmName = rAttribs.getString( XML_algorithmName, OUString());
     150           5 :     aProt.maHashValue = rAttribs.getString( XML_hashValue, OUString());
     151           5 :     aProt.maSaltValue = rAttribs.getString( XML_saltValue, OUString());
     152           5 :     aProt.mnSpinCount = rAttribs.getUnsigned( XML_spinCount, 0);
     153          10 :     OUString aRefs( rAttribs.getString( XML_sqref, OUString()));
     154           5 :     if (!aRefs.isEmpty())
     155             :     {
     156           5 :         ApiCellRangeList aRangeList;
     157           5 :         getAddressConverter().convertToCellRangeList( aRangeList, aRefs, getSheetIndex(), true );
     158           5 :         if (!aRangeList.empty())
     159             :         {
     160           5 :             ScRangeList* pRangeList = aProt.maRangeList = new ScRangeList;
     161          10 :             for (::std::vector< ::com::sun::star::table::CellRangeAddress >::const_iterator itr( aRangeList.begin()), end( aRangeList.end()); itr != end; ++itr)
     162             :             {
     163           5 :                 ScRange aRange;
     164           5 :                 ScUnoConversion::FillScRange( aRange, *itr);
     165           5 :                 pRangeList->Append( aRange);
     166             :             }
     167           5 :         }
     168             :     }
     169          10 :     maSheetProt.maEnhancedProtections.push_back( aProt);
     170           5 : }
     171             : 
     172           0 : void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
     173             : {
     174           0 :     maSheetProt.mnPasswordHash = oox::core::CodecHelper::getPasswordHash( rAttribs, XML_password );
     175           0 :     maSheetProt.mbSheet        = rAttribs.getBool( XML_content, false );
     176           0 :     maSheetProt.mbObjects      = rAttribs.getBool( XML_objects, false );
     177           0 : }
     178             : 
     179          12 : void WorksheetSettings::importPhoneticPr( const AttributeList& rAttribs )
     180             : {
     181          12 :     maPhoneticSett.importPhoneticPr( rAttribs );
     182          12 : }
     183             : 
     184           3 : void WorksheetSettings::importSheetPr( SequenceInputStream& rStrm )
     185             : {
     186             :     sal_uInt16 nFlags1;
     187             :     sal_uInt8 nFlags2;
     188           3 :     nFlags1 = rStrm.readuInt16();
     189           3 :     nFlags2 = rStrm.readuChar();
     190           3 :     rStrm >> maSheetSettings.maTabColor;
     191           3 :     rStrm.skip( 8 );    // sync anchor cell
     192           3 :     rStrm >> maSheetSettings.maCodeName;
     193             :     // sheet settings
     194           3 :     maSheetSettings.mbFilterMode = getFlag( nFlags2, BIFF12_SHEETPR_FILTERMODE );
     195             :     // outline settings, equal flags in all BIFFs
     196           3 :     maSheetSettings.mbApplyStyles  = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
     197           3 :     maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
     198           3 :     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           3 :     getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
     202           3 : }
     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           3 : void WorksheetSettings::importSheetProtection( SequenceInputStream& rStrm )
     211             : {
     212           3 :     maSheetProt.mnPasswordHash = rStrm.readuInt16();
     213             :     // no flags field for all these boolean flags?!?
     214           3 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     215           3 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     216           3 :     maSheetProt.mbScenarios        = rStrm.readInt32() != 0;
     217           3 :     maSheetProt.mbFormatCells      = rStrm.readInt32() != 0;
     218           3 :     maSheetProt.mbFormatColumns    = rStrm.readInt32() != 0;
     219           3 :     maSheetProt.mbFormatRows       = rStrm.readInt32() != 0;
     220           3 :     maSheetProt.mbInsertColumns    = rStrm.readInt32() != 0;
     221           3 :     maSheetProt.mbInsertRows       = rStrm.readInt32() != 0;
     222           3 :     maSheetProt.mbInsertHyperlinks = rStrm.readInt32() != 0;
     223           3 :     maSheetProt.mbDeleteColumns    = rStrm.readInt32() != 0;
     224           3 :     maSheetProt.mbDeleteRows       = rStrm.readInt32() != 0;
     225           3 :     maSheetProt.mbSelectLocked     = rStrm.readInt32() != 0;
     226           3 :     maSheetProt.mbSort             = rStrm.readInt32() != 0;
     227           3 :     maSheetProt.mbAutoFilter       = rStrm.readInt32() != 0;
     228           3 :     maSheetProt.mbPivotTables      = rStrm.readInt32() != 0;
     229           3 :     maSheetProt.mbSelectUnlocked   = rStrm.readInt32() != 0;
     230           3 : }
     231             : 
     232           0 : void WorksheetSettings::importChartProtection( SequenceInputStream& rStrm )
     233             : {
     234           0 :     maSheetProt.mnPasswordHash = rStrm.readuInt16();
     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         269 : void WorksheetSettings::finalizeImport()
     246             : {
     247             :     // sheet protection
     248         269 :     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         269 :     PropertySet aPropSet( getSheet() );
     282         269 :     aPropSet.setProperty( PROP_CodeName, maSheetSettings.maCodeName );
     283             : 
     284             :     // sheet tab color
     285         269 :     if( !maSheetSettings.maTabColor.isAuto() )
     286             :     {
     287         266 :         sal_Int32 nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() );
     288         266 :         aPropSet.setProperty( PROP_TabColor, nColor );
     289         269 :     }
     290         269 : }
     291             : 
     292             : } // namespace xls
     293          30 : } // namespace oox
     294             : 
     295             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11