LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/oox - worksheetsettings.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 105 21.9 %
Date: 2012-12-27 Functions: 7 18 38.9 %
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             : 
      30             : namespace oox {
      31             : namespace xls {
      32             : 
      33             : // ============================================================================
      34             : 
      35             : using namespace ::com::sun::star::beans;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::util;
      38             : 
      39             : using ::oox::core::CodecHelper;
      40             : using ::rtl::OUString;
      41             : 
      42             : // ============================================================================
      43             : 
      44             : namespace {
      45             : 
      46             : const sal_uInt8 BIFF12_SHEETPR_FILTERMODE       = 0x01;
      47             : const sal_uInt8 BIFF12_SHEETPR_EVAL_CF          = 0x02;
      48             : 
      49             : const sal_uInt32 BIFF_SHEETEXT_NOTABCOLOR       = 0x7F;
      50             : 
      51             : const sal_uInt16 BIFF_SHEETPR_DIALOGSHEET       = 0x0010;
      52             : const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES       = 0x0020;
      53             : const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW      = 0x0040;
      54             : const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT      = 0x0080;
      55             : const sal_uInt16 BIFF_SHEETPR_FITTOPAGES        = 0x0100;
      56             : const sal_uInt16 BIFF_SHEETPR_SKIPEXT           = 0x0200;       // BIFF3-BIFF4
      57             : 
      58             : const sal_uInt32 BIFF_SHEETPROT_OBJECTS         = 0x00000001;
      59             : const sal_uInt32 BIFF_SHEETPROT_SCENARIOS       = 0x00000002;
      60             : const sal_uInt32 BIFF_SHEETPROT_FORMAT_CELLS    = 0x00000004;
      61             : const sal_uInt32 BIFF_SHEETPROT_FORMAT_COLUMNS  = 0x00000008;
      62             : const sal_uInt32 BIFF_SHEETPROT_FORMAT_ROWS     = 0x00000010;
      63             : const sal_uInt32 BIFF_SHEETPROT_INSERT_COLUMNS  = 0x00000020;
      64             : const sal_uInt32 BIFF_SHEETPROT_INSERT_ROWS     = 0x00000040;
      65             : const sal_uInt32 BIFF_SHEETPROT_INSERT_HLINKS   = 0x00000080;
      66             : const sal_uInt32 BIFF_SHEETPROT_DELETE_COLUMNS  = 0x00000100;
      67             : const sal_uInt32 BIFF_SHEETPROT_DELETE_ROWS     = 0x00000200;
      68             : const sal_uInt32 BIFF_SHEETPROT_SELECT_LOCKED   = 0x00000400;
      69             : const sal_uInt32 BIFF_SHEETPROT_SORT            = 0x00000800;
      70             : const sal_uInt32 BIFF_SHEETPROT_AUTOFILTER      = 0x00001000;
      71             : const sal_uInt32 BIFF_SHEETPROT_PIVOTTABLES     = 0x00002000;
      72             : const sal_uInt32 BIFF_SHEETPROT_SELECT_UNLOCKED = 0x00004000;
      73             : 
      74             : } // namespace
      75             : 
      76             : // ============================================================================
      77             : 
      78          25 : SheetSettingsModel::SheetSettingsModel() :
      79             :     mbFilterMode( false ),
      80             :     mbApplyStyles( false ),
      81             :     mbSummaryBelow( true ),
      82          25 :     mbSummaryRight( true )
      83             : {
      84          25 : }
      85             : 
      86             : // ============================================================================
      87             : 
      88          25 : SheetProtectionModel::SheetProtectionModel() :
      89             :     mnPasswordHash( 0 ),
      90             :     mbSheet( false ),
      91             :     mbObjects( false ),
      92             :     mbScenarios( false ),
      93             :     mbFormatCells( true ),
      94             :     mbFormatColumns( true ),
      95             :     mbFormatRows( true ),
      96             :     mbInsertColumns( true ),
      97             :     mbInsertRows( true ),
      98             :     mbInsertHyperlinks( true ),
      99             :     mbDeleteColumns( true ),
     100             :     mbDeleteRows( true ),
     101             :     mbSelectLocked( false ),
     102             :     mbSort( true ),
     103             :     mbAutoFilter( true ),
     104             :     mbPivotTables( true ),
     105          25 :     mbSelectUnlocked( false )
     106             : {
     107          25 : }
     108             : 
     109             : // ============================================================================
     110             : 
     111          25 : WorksheetSettings::WorksheetSettings( const WorksheetHelper& rHelper ) :
     112             :     WorksheetHelper( rHelper ),
     113          25 :     maPhoneticSett( rHelper )
     114             : {
     115          25 : }
     116             : 
     117          20 : void WorksheetSettings::importSheetPr( const AttributeList& rAttribs )
     118             : {
     119          20 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
     120          20 :     maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
     121          20 : }
     122             : 
     123           0 : void WorksheetSettings::importChartSheetPr( const AttributeList& rAttribs )
     124             : {
     125           0 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
     126           0 : }
     127             : 
     128           0 : void WorksheetSettings::importTabColor( const AttributeList& rAttribs )
     129             : {
     130           0 :     maSheetSettings.maTabColor.importColor( rAttribs );
     131           0 : }
     132             : 
     133           0 : void WorksheetSettings::importOutlinePr( const AttributeList& rAttribs )
     134             : {
     135           0 :     maSheetSettings.mbApplyStyles  = rAttribs.getBool( XML_applyStyles, false );
     136           0 :     maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
     137           0 :     maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
     138           0 : }
     139             : 
     140           0 : void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
     141             : {
     142           0 :     maSheetProt.mnPasswordHash     = CodecHelper::getPasswordHash( rAttribs, XML_password );
     143           0 :     maSheetProt.mbSheet            = rAttribs.getBool( XML_sheet, false );
     144           0 :     maSheetProt.mbObjects          = rAttribs.getBool( XML_objects, false );
     145           0 :     maSheetProt.mbScenarios        = rAttribs.getBool( XML_scenarios, false );
     146           0 :     maSheetProt.mbFormatCells      = rAttribs.getBool( XML_formatCells, true );
     147           0 :     maSheetProt.mbFormatColumns    = rAttribs.getBool( XML_formatColumns, true );
     148           0 :     maSheetProt.mbFormatRows       = rAttribs.getBool( XML_formatRows, true );
     149           0 :     maSheetProt.mbInsertColumns    = rAttribs.getBool( XML_insertColumns, true );
     150           0 :     maSheetProt.mbInsertRows       = rAttribs.getBool( XML_insertRows, true );
     151           0 :     maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
     152           0 :     maSheetProt.mbDeleteColumns    = rAttribs.getBool( XML_deleteColumns, true );
     153           0 :     maSheetProt.mbDeleteRows       = rAttribs.getBool( XML_deleteRows, true );
     154           0 :     maSheetProt.mbSelectLocked     = rAttribs.getBool( XML_selectLockedCells, false );
     155           0 :     maSheetProt.mbSort             = rAttribs.getBool( XML_sort, true );
     156           0 :     maSheetProt.mbAutoFilter       = rAttribs.getBool( XML_autoFilter, true );
     157           0 :     maSheetProt.mbPivotTables      = rAttribs.getBool( XML_pivotTables, true );
     158           0 :     maSheetProt.mbSelectUnlocked   = rAttribs.getBool( XML_selectUnlockedCells, false );
     159           0 : }
     160             : 
     161           0 : void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
     162             : {
     163           0 :     maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
     164           0 :     maSheetProt.mbSheet        = rAttribs.getBool( XML_content, false );
     165           0 :     maSheetProt.mbObjects      = rAttribs.getBool( XML_objects, false );
     166           0 : }
     167             : 
     168           0 : void WorksheetSettings::importPhoneticPr( const AttributeList& rAttribs )
     169             : {
     170           0 :     maPhoneticSett.importPhoneticPr( rAttribs );
     171           0 : }
     172             : 
     173           0 : void WorksheetSettings::importSheetPr( SequenceInputStream& rStrm )
     174             : {
     175             :     sal_uInt16 nFlags1;
     176             :     sal_uInt8 nFlags2;
     177           0 :     rStrm >> nFlags1 >> nFlags2 >> maSheetSettings.maTabColor;
     178           0 :     rStrm.skip( 8 );    // sync anchor cell
     179           0 :     rStrm >> maSheetSettings.maCodeName;
     180             :     // sheet settings
     181           0 :     maSheetSettings.mbFilterMode = getFlag( nFlags2, BIFF12_SHEETPR_FILTERMODE );
     182             :     // outline settings, equal flags in all BIFFs
     183           0 :     maSheetSettings.mbApplyStyles  = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
     184           0 :     maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
     185           0 :     maSheetSettings.mbSummaryBelow = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSBELOW );
     186             :     /*  Fit printout to width/height - for whatever reason, this flag is still
     187             :         stored separated from the page settings */
     188           0 :     getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
     189           0 : }
     190             : 
     191           0 : void WorksheetSettings::importChartSheetPr( SequenceInputStream& rStrm )
     192             : {
     193           0 :     rStrm.skip( 2 );    // flags, contains only the 'published' flag
     194           0 :     rStrm >> maSheetSettings.maTabColor >> maSheetSettings.maCodeName;
     195           0 : }
     196             : 
     197           0 : void WorksheetSettings::importSheetProtection( SequenceInputStream& rStrm )
     198             : {
     199           0 :     rStrm >> maSheetProt.mnPasswordHash;
     200             :     // no flags field for all these boolean flags?!?
     201           0 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     202           0 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     203           0 :     maSheetProt.mbScenarios        = rStrm.readInt32() != 0;
     204           0 :     maSheetProt.mbFormatCells      = rStrm.readInt32() != 0;
     205           0 :     maSheetProt.mbFormatColumns    = rStrm.readInt32() != 0;
     206           0 :     maSheetProt.mbFormatRows       = rStrm.readInt32() != 0;
     207           0 :     maSheetProt.mbInsertColumns    = rStrm.readInt32() != 0;
     208           0 :     maSheetProt.mbInsertRows       = rStrm.readInt32() != 0;
     209           0 :     maSheetProt.mbInsertHyperlinks = rStrm.readInt32() != 0;
     210           0 :     maSheetProt.mbDeleteColumns    = rStrm.readInt32() != 0;
     211           0 :     maSheetProt.mbDeleteRows       = rStrm.readInt32() != 0;
     212           0 :     maSheetProt.mbSelectLocked     = rStrm.readInt32() != 0;
     213           0 :     maSheetProt.mbSort             = rStrm.readInt32() != 0;
     214           0 :     maSheetProt.mbAutoFilter       = rStrm.readInt32() != 0;
     215           0 :     maSheetProt.mbPivotTables      = rStrm.readInt32() != 0;
     216           0 :     maSheetProt.mbSelectUnlocked   = rStrm.readInt32() != 0;
     217           0 : }
     218             : 
     219           0 : void WorksheetSettings::importChartProtection( SequenceInputStream& rStrm )
     220             : {
     221           0 :     rStrm >> maSheetProt.mnPasswordHash;
     222             :     // no flags field for all these boolean flags?!?
     223           0 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     224           0 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     225           0 : }
     226             : 
     227           0 : void WorksheetSettings::importPhoneticPr( SequenceInputStream& rStrm )
     228             : {
     229           0 :     maPhoneticSett.importPhoneticPr( rStrm );
     230           0 : }
     231             : 
     232          25 : void WorksheetSettings::finalizeImport()
     233             : {
     234             :     // sheet protection
     235          25 :     if( maSheetProt.mbSheet ) try
     236             :     {
     237           0 :         Reference< XProtectable > xProtectable( getSheet(), UNO_QUERY_THROW );
     238           0 :         xProtectable->protect( OUString() );
     239             :     }
     240           0 :     catch( Exception& )
     241             :     {
     242             :     }
     243             : 
     244             :     // VBA code name
     245          25 :     PropertySet aPropSet( getSheet() );
     246          25 :     aPropSet.setProperty( PROP_CodeName, maSheetSettings.maCodeName );
     247             : 
     248             :     // sheet tab color
     249          25 :     if( !maSheetSettings.maTabColor.isAuto() )
     250             :     {
     251          25 :         sal_Int32 nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() );
     252          25 :         aPropSet.setProperty( PROP_TabColor, nColor );
     253          25 :     }
     254          25 : }
     255             : 
     256             : // ============================================================================
     257             : 
     258             : } // namespace xls
     259           9 : } // namespace oox
     260             : 
     261             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10