LCOV - code coverage report
Current view: top level - sc/source/filter/oox - worksheetsettings.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 105 21.9 %
Date: 2012-08-25 Functions: 7 18 38.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 60 26.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "worksheetsettings.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/util/XProtectable.hpp>
      32                 :            : #include "oox/core/filterbase.hxx"
      33                 :            : #include "oox/helper/attributelist.hxx"
      34                 :            : #include "oox/token/properties.hxx"
      35                 :            : #include "biffinputstream.hxx"
      36                 :            : #include "pagesettings.hxx"
      37                 :            : #include "workbooksettings.hxx"
      38                 :            : 
      39                 :            : namespace oox {
      40                 :            : namespace xls {
      41                 :            : 
      42                 :            : // ============================================================================
      43                 :            : 
      44                 :            : using namespace ::com::sun::star::beans;
      45                 :            : using namespace ::com::sun::star::uno;
      46                 :            : using namespace ::com::sun::star::util;
      47                 :            : 
      48                 :            : using ::oox::core::CodecHelper;
      49                 :            : using ::rtl::OUString;
      50                 :            : 
      51                 :            : // ============================================================================
      52                 :            : 
      53                 :            : namespace {
      54                 :            : 
      55                 :            : const sal_uInt8 BIFF12_SHEETPR_FILTERMODE       = 0x01;
      56                 :            : const sal_uInt8 BIFF12_SHEETPR_EVAL_CF          = 0x02;
      57                 :            : 
      58                 :            : const sal_uInt32 BIFF_SHEETEXT_NOTABCOLOR       = 0x7F;
      59                 :            : 
      60                 :            : const sal_uInt16 BIFF_SHEETPR_DIALOGSHEET       = 0x0010;
      61                 :            : const sal_uInt16 BIFF_SHEETPR_APPLYSTYLES       = 0x0020;
      62                 :            : const sal_uInt16 BIFF_SHEETPR_SYMBOLSBELOW      = 0x0040;
      63                 :            : const sal_uInt16 BIFF_SHEETPR_SYMBOLSRIGHT      = 0x0080;
      64                 :            : const sal_uInt16 BIFF_SHEETPR_FITTOPAGES        = 0x0100;
      65                 :            : const sal_uInt16 BIFF_SHEETPR_SKIPEXT           = 0x0200;       // BIFF3-BIFF4
      66                 :            : 
      67                 :            : const sal_uInt32 BIFF_SHEETPROT_OBJECTS         = 0x00000001;
      68                 :            : const sal_uInt32 BIFF_SHEETPROT_SCENARIOS       = 0x00000002;
      69                 :            : const sal_uInt32 BIFF_SHEETPROT_FORMAT_CELLS    = 0x00000004;
      70                 :            : const sal_uInt32 BIFF_SHEETPROT_FORMAT_COLUMNS  = 0x00000008;
      71                 :            : const sal_uInt32 BIFF_SHEETPROT_FORMAT_ROWS     = 0x00000010;
      72                 :            : const sal_uInt32 BIFF_SHEETPROT_INSERT_COLUMNS  = 0x00000020;
      73                 :            : const sal_uInt32 BIFF_SHEETPROT_INSERT_ROWS     = 0x00000040;
      74                 :            : const sal_uInt32 BIFF_SHEETPROT_INSERT_HLINKS   = 0x00000080;
      75                 :            : const sal_uInt32 BIFF_SHEETPROT_DELETE_COLUMNS  = 0x00000100;
      76                 :            : const sal_uInt32 BIFF_SHEETPROT_DELETE_ROWS     = 0x00000200;
      77                 :            : const sal_uInt32 BIFF_SHEETPROT_SELECT_LOCKED   = 0x00000400;
      78                 :            : const sal_uInt32 BIFF_SHEETPROT_SORT            = 0x00000800;
      79                 :            : const sal_uInt32 BIFF_SHEETPROT_AUTOFILTER      = 0x00001000;
      80                 :            : const sal_uInt32 BIFF_SHEETPROT_PIVOTTABLES     = 0x00002000;
      81                 :            : const sal_uInt32 BIFF_SHEETPROT_SELECT_UNLOCKED = 0x00004000;
      82                 :            : 
      83                 :            : } // namespace
      84                 :            : 
      85                 :            : // ============================================================================
      86                 :            : 
      87                 :         60 : SheetSettingsModel::SheetSettingsModel() :
      88                 :            :     mbFilterMode( false ),
      89                 :            :     mbApplyStyles( false ),
      90                 :            :     mbSummaryBelow( true ),
      91         [ +  - ]:         60 :     mbSummaryRight( true )
      92                 :            : {
      93                 :         60 : }
      94                 :            : 
      95                 :            : // ============================================================================
      96                 :            : 
      97                 :         60 : SheetProtectionModel::SheetProtectionModel() :
      98                 :            :     mnPasswordHash( 0 ),
      99                 :            :     mbSheet( false ),
     100                 :            :     mbObjects( false ),
     101                 :            :     mbScenarios( false ),
     102                 :            :     mbFormatCells( true ),
     103                 :            :     mbFormatColumns( true ),
     104                 :            :     mbFormatRows( true ),
     105                 :            :     mbInsertColumns( true ),
     106                 :            :     mbInsertRows( true ),
     107                 :            :     mbInsertHyperlinks( true ),
     108                 :            :     mbDeleteColumns( true ),
     109                 :            :     mbDeleteRows( true ),
     110                 :            :     mbSelectLocked( false ),
     111                 :            :     mbSort( true ),
     112                 :            :     mbAutoFilter( true ),
     113                 :            :     mbPivotTables( true ),
     114                 :         60 :     mbSelectUnlocked( false )
     115                 :            : {
     116                 :         60 : }
     117                 :            : 
     118                 :            : // ============================================================================
     119                 :            : 
     120                 :         60 : WorksheetSettings::WorksheetSettings( const WorksheetHelper& rHelper ) :
     121                 :            :     WorksheetHelper( rHelper ),
     122 [ +  - ][ +  - ]:         60 :     maPhoneticSett( rHelper )
     123                 :            : {
     124                 :         60 : }
     125                 :            : 
     126                 :         51 : void WorksheetSettings::importSheetPr( const AttributeList& rAttribs )
     127                 :            : {
     128         [ +  - ]:         51 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
     129                 :         51 :     maSheetSettings.mbFilterMode = rAttribs.getBool( XML_filterMode, false );
     130                 :         51 : }
     131                 :            : 
     132                 :          0 : void WorksheetSettings::importChartSheetPr( const AttributeList& rAttribs )
     133                 :            : {
     134         [ #  # ]:          0 :     maSheetSettings.maCodeName = rAttribs.getString( XML_codeName, OUString() );
     135                 :          0 : }
     136                 :            : 
     137                 :          0 : void WorksheetSettings::importTabColor( const AttributeList& rAttribs )
     138                 :            : {
     139                 :          0 :     maSheetSettings.maTabColor.importColor( rAttribs );
     140                 :          0 : }
     141                 :            : 
     142                 :          0 : void WorksheetSettings::importOutlinePr( const AttributeList& rAttribs )
     143                 :            : {
     144                 :          0 :     maSheetSettings.mbApplyStyles  = rAttribs.getBool( XML_applyStyles, false );
     145                 :          0 :     maSheetSettings.mbSummaryBelow = rAttribs.getBool( XML_summaryBelow, true );
     146                 :          0 :     maSheetSettings.mbSummaryRight = rAttribs.getBool( XML_summaryRight, true );
     147                 :          0 : }
     148                 :            : 
     149                 :          0 : void WorksheetSettings::importSheetProtection( const AttributeList& rAttribs )
     150                 :            : {
     151                 :          0 :     maSheetProt.mnPasswordHash     = CodecHelper::getPasswordHash( rAttribs, XML_password );
     152                 :          0 :     maSheetProt.mbSheet            = rAttribs.getBool( XML_sheet, false );
     153                 :          0 :     maSheetProt.mbObjects          = rAttribs.getBool( XML_objects, false );
     154                 :          0 :     maSheetProt.mbScenarios        = rAttribs.getBool( XML_scenarios, false );
     155                 :          0 :     maSheetProt.mbFormatCells      = rAttribs.getBool( XML_formatCells, true );
     156                 :          0 :     maSheetProt.mbFormatColumns    = rAttribs.getBool( XML_formatColumns, true );
     157                 :          0 :     maSheetProt.mbFormatRows       = rAttribs.getBool( XML_formatRows, true );
     158                 :          0 :     maSheetProt.mbInsertColumns    = rAttribs.getBool( XML_insertColumns, true );
     159                 :          0 :     maSheetProt.mbInsertRows       = rAttribs.getBool( XML_insertRows, true );
     160                 :          0 :     maSheetProt.mbInsertHyperlinks = rAttribs.getBool( XML_insertHyperlinks, true );
     161                 :          0 :     maSheetProt.mbDeleteColumns    = rAttribs.getBool( XML_deleteColumns, true );
     162                 :          0 :     maSheetProt.mbDeleteRows       = rAttribs.getBool( XML_deleteRows, true );
     163                 :          0 :     maSheetProt.mbSelectLocked     = rAttribs.getBool( XML_selectLockedCells, false );
     164                 :          0 :     maSheetProt.mbSort             = rAttribs.getBool( XML_sort, true );
     165                 :          0 :     maSheetProt.mbAutoFilter       = rAttribs.getBool( XML_autoFilter, true );
     166                 :          0 :     maSheetProt.mbPivotTables      = rAttribs.getBool( XML_pivotTables, true );
     167                 :          0 :     maSheetProt.mbSelectUnlocked   = rAttribs.getBool( XML_selectUnlockedCells, false );
     168                 :          0 : }
     169                 :            : 
     170                 :          0 : void WorksheetSettings::importChartProtection( const AttributeList& rAttribs )
     171                 :            : {
     172                 :          0 :     maSheetProt.mnPasswordHash = CodecHelper::getPasswordHash( rAttribs, XML_password );
     173                 :          0 :     maSheetProt.mbSheet        = rAttribs.getBool( XML_content, false );
     174                 :          0 :     maSheetProt.mbObjects      = rAttribs.getBool( XML_objects, false );
     175                 :          0 : }
     176                 :            : 
     177                 :          0 : void WorksheetSettings::importPhoneticPr( const AttributeList& rAttribs )
     178                 :            : {
     179                 :          0 :     maPhoneticSett.importPhoneticPr( rAttribs );
     180                 :          0 : }
     181                 :            : 
     182                 :          0 : void WorksheetSettings::importSheetPr( SequenceInputStream& rStrm )
     183                 :            : {
     184                 :            :     sal_uInt16 nFlags1;
     185                 :            :     sal_uInt8 nFlags2;
     186 [ #  # ][ #  # ]:          0 :     rStrm >> nFlags1 >> nFlags2 >> maSheetSettings.maTabColor;
                 [ #  # ]
     187         [ #  # ]:          0 :     rStrm.skip( 8 );    // sync anchor cell
     188         [ #  # ]:          0 :     rStrm >> maSheetSettings.maCodeName;
     189                 :            :     // sheet settings
     190                 :          0 :     maSheetSettings.mbFilterMode = getFlag( nFlags2, BIFF12_SHEETPR_FILTERMODE );
     191                 :            :     // outline settings, equal flags in all BIFFs
     192                 :          0 :     maSheetSettings.mbApplyStyles  = getFlag( nFlags1, BIFF_SHEETPR_APPLYSTYLES );
     193                 :          0 :     maSheetSettings.mbSummaryRight = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSRIGHT );
     194                 :          0 :     maSheetSettings.mbSummaryBelow = getFlag( nFlags1, BIFF_SHEETPR_SYMBOLSBELOW );
     195                 :            :     /*  Fit printout to width/height - for whatever reason, this flag is still
     196                 :            :         stored separated from the page settings */
     197 [ #  # ][ #  # ]:          0 :     getPageSettings().setFitToPagesMode( getFlag( nFlags1, BIFF_SHEETPR_FITTOPAGES ) );
     198                 :          0 : }
     199                 :            : 
     200                 :          0 : void WorksheetSettings::importChartSheetPr( SequenceInputStream& rStrm )
     201                 :            : {
     202                 :          0 :     rStrm.skip( 2 );    // flags, contains only the 'published' flag
     203                 :          0 :     rStrm >> maSheetSettings.maTabColor >> maSheetSettings.maCodeName;
     204                 :          0 : }
     205                 :            : 
     206                 :          0 : void WorksheetSettings::importSheetProtection( SequenceInputStream& rStrm )
     207                 :            : {
     208                 :          0 :     rStrm >> maSheetProt.mnPasswordHash;
     209                 :            :     // no flags field for all these boolean flags?!?
     210                 :          0 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     211                 :          0 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     212                 :          0 :     maSheetProt.mbScenarios        = rStrm.readInt32() != 0;
     213                 :          0 :     maSheetProt.mbFormatCells      = rStrm.readInt32() != 0;
     214                 :          0 :     maSheetProt.mbFormatColumns    = rStrm.readInt32() != 0;
     215                 :          0 :     maSheetProt.mbFormatRows       = rStrm.readInt32() != 0;
     216                 :          0 :     maSheetProt.mbInsertColumns    = rStrm.readInt32() != 0;
     217                 :          0 :     maSheetProt.mbInsertRows       = rStrm.readInt32() != 0;
     218                 :          0 :     maSheetProt.mbInsertHyperlinks = rStrm.readInt32() != 0;
     219                 :          0 :     maSheetProt.mbDeleteColumns    = rStrm.readInt32() != 0;
     220                 :          0 :     maSheetProt.mbDeleteRows       = rStrm.readInt32() != 0;
     221                 :          0 :     maSheetProt.mbSelectLocked     = rStrm.readInt32() != 0;
     222                 :          0 :     maSheetProt.mbSort             = rStrm.readInt32() != 0;
     223                 :          0 :     maSheetProt.mbAutoFilter       = rStrm.readInt32() != 0;
     224                 :          0 :     maSheetProt.mbPivotTables      = rStrm.readInt32() != 0;
     225                 :          0 :     maSheetProt.mbSelectUnlocked   = rStrm.readInt32() != 0;
     226                 :          0 : }
     227                 :            : 
     228                 :          0 : void WorksheetSettings::importChartProtection( SequenceInputStream& rStrm )
     229                 :            : {
     230                 :          0 :     rStrm >> maSheetProt.mnPasswordHash;
     231                 :            :     // no flags field for all these boolean flags?!?
     232                 :          0 :     maSheetProt.mbSheet            = rStrm.readInt32() != 0;
     233                 :          0 :     maSheetProt.mbObjects          = rStrm.readInt32() != 0;
     234                 :          0 : }
     235                 :            : 
     236                 :          0 : void WorksheetSettings::importPhoneticPr( SequenceInputStream& rStrm )
     237                 :            : {
     238                 :          0 :     maPhoneticSett.importPhoneticPr( rStrm );
     239                 :          0 : }
     240                 :            : 
     241                 :         60 : void WorksheetSettings::finalizeImport()
     242                 :            : {
     243                 :            :     // sheet protection
     244         [ -  + ]:         60 :     if( maSheetProt.mbSheet ) try
     245                 :            :     {
     246 [ #  # ][ #  # ]:          0 :         Reference< XProtectable > xProtectable( getSheet(), UNO_QUERY_THROW );
     247 [ #  # ][ #  # ]:          0 :         xProtectable->protect( OUString() );
                 [ #  # ]
     248                 :            :     }
     249         [ #  # ]:          0 :     catch( Exception& )
     250                 :            :     {
     251                 :            :     }
     252                 :            : 
     253                 :            :     // VBA code name
     254 [ +  - ][ +  - ]:         60 :     PropertySet aPropSet( getSheet() );
     255         [ +  - ]:         60 :     aPropSet.setProperty( PROP_CodeName, maSheetSettings.maCodeName );
     256                 :            : 
     257                 :            :     // sheet tab color
     258         [ +  - ]:         60 :     if( !maSheetSettings.maTabColor.isAuto() )
     259                 :            :     {
     260 [ +  - ][ +  - ]:         60 :         sal_Int32 nColor = maSheetSettings.maTabColor.getColor( getBaseFilter().getGraphicHelper() );
                 [ +  - ]
     261         [ +  - ]:         60 :         aPropSet.setProperty( PROP_TabColor, nColor );
     262         [ +  - ]:         60 :     }
     263                 :         60 : }
     264                 :            : 
     265                 :            : // ============================================================================
     266                 :            : 
     267                 :            : } // namespace xls
     268 [ +  - ][ +  - ]:         24 : } // namespace oox
     269                 :            : 
     270                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10