LCOV - code coverage report
Current view: top level - sc/source/filter/oox - workbooksettings.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 72 114 63.2 %
Date: 2012-08-25 Functions: 12 17 70.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 48 163 29.4 %

           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 "workbooksettings.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/sheet/XCalculatable.hpp>
      32                 :            : #include <com/sun/star/util/Date.hpp>
      33                 :            : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      34                 :            : #include <comphelper/mediadescriptor.hxx>
      35                 :            : #include "oox/core/filterbase.hxx"
      36                 :            : #include "oox/helper/attributelist.hxx"
      37                 :            : #include "oox/helper/propertyset.hxx"
      38                 :            : #include "oox/core/xmlfilterbase.hxx"
      39                 :            : #include "oox/token/properties.hxx"
      40                 :            : #include "biffinputstream.hxx"
      41                 :            : #include "unitconverter.hxx"
      42                 :            : 
      43                 :            : namespace oox {
      44                 :            : namespace xls {
      45                 :            : 
      46                 :            : // ============================================================================
      47                 :            : 
      48                 :            : using namespace ::com::sun::star::beans;
      49                 :            : using namespace ::com::sun::star::sheet;
      50                 :            : using namespace ::com::sun::star::uno;
      51                 :            : using namespace ::com::sun::star::util;
      52                 :            : 
      53                 :            : using ::comphelper::MediaDescriptor;
      54                 :            : using ::oox::core::CodecHelper;
      55                 :            : using ::rtl::OUString;
      56                 :            : 
      57                 :            : // ============================================================================
      58                 :            : 
      59                 :            : namespace {
      60                 :            : 
      61                 :            : const sal_uInt32 BIFF12_WORKBOOKPR_DATE1904     = 0x00000001;
      62                 :            : const sal_uInt32 BIFF12_WORKBOOKPR_STRIPEXT     = 0x00000080;
      63                 :            : 
      64                 :            : const sal_uInt16 BIFF12_CALCPR_A1               = 0x0002;
      65                 :            : const sal_uInt16 BIFF12_CALCPR_ITERATE          = 0x0004;
      66                 :            : const sal_uInt16 BIFF12_CALCPR_FULLPRECISION    = 0x0008;
      67                 :            : const sal_uInt16 BIFF12_CALCPR_CALCCOMPLETED    = 0x0010;
      68                 :            : const sal_uInt16 BIFF12_CALCPR_CALCONSAVE       = 0x0020;
      69                 :            : const sal_uInt16 BIFF12_CALCPR_CONCURRENT       = 0x0040;
      70                 :            : const sal_uInt16 BIFF12_CALCPR_MANUALPROC       = 0x0080;
      71                 :            : 
      72                 :            : // no predefined constants for show objects mode
      73                 :            : const sal_Int16 API_SHOWMODE_SHOW               = 0;        /// Show drawing objects.
      74                 :            : const sal_Int16 API_SHOWMODE_HIDE               = 1;        /// Hide drawing objects.
      75                 :            : const sal_Int16 API_SHOWMODE_PLACEHOLDER        = 2;        /// Show placeholders for drawing objects.
      76                 :            : 
      77                 :            : } // namespace
      78                 :            : 
      79                 :            : // ============================================================================
      80                 :            : 
      81                 :         24 : FileSharingModel::FileSharingModel() :
      82                 :            :     mnPasswordHash( 0 ),
      83                 :         24 :     mbRecommendReadOnly( false )
      84                 :            : {
      85                 :         24 : }
      86                 :            : 
      87                 :            : // ============================================================================
      88                 :            : 
      89                 :         24 : WorkbookSettingsModel::WorkbookSettingsModel() :
      90                 :            :     mnShowObjectMode( XML_all ),
      91                 :            :     mnUpdateLinksMode( XML_userSet ),
      92                 :            :     mnDefaultThemeVer( -1 ),
      93                 :            :     mbDateMode1904( false ),
      94                 :         24 :     mbSaveExtLinkValues( true )
      95                 :            : {
      96                 :         24 : }
      97                 :            : 
      98                 :          0 : void WorkbookSettingsModel::setBiffObjectMode( sal_uInt16 nObjMode )
      99                 :            : {
     100                 :            :     static const sal_Int32 spnObjModes[] = { XML_all, XML_placeholders, XML_none };
     101         [ #  # ]:          0 :     mnShowObjectMode = STATIC_ARRAY_SELECT( spnObjModes, nObjMode, XML_all );
     102                 :          0 : }
     103                 :            : 
     104                 :            : // ============================================================================
     105                 :            : 
     106                 :         24 : CalcSettingsModel::CalcSettingsModel() :
     107                 :            :     mfIterateDelta( 0.001 ),
     108                 :            :     mnCalcId( -1 ),
     109                 :            :     mnRefMode( XML_A1 ),
     110                 :            :     mnCalcMode( XML_auto ),
     111                 :            :     mnIterateCount( 100 ),
     112                 :            :     mnProcCount( -1 ),
     113                 :            :     mbCalcOnSave( true ),
     114                 :            :     mbCalcCompleted( true ),
     115                 :            :     mbFullPrecision( true ),
     116                 :            :     mbIterate( false ),
     117                 :            :     mbConcurrent( true ),
     118                 :         24 :     mbUseNlr( false )
     119                 :            : {
     120                 :         24 : }
     121                 :            : 
     122                 :            : // ============================================================================
     123                 :            : 
     124                 :         24 : WorkbookSettings::WorkbookSettings( const WorkbookHelper& rHelper ) :
     125                 :         24 :     WorkbookHelper( rHelper )
     126                 :            : {
     127                 :         24 : }
     128                 :            : 
     129                 :          0 : void WorkbookSettings::importFileSharing( const AttributeList& rAttribs )
     130                 :            : {
     131         [ #  # ]:          0 :     maFileSharing.maUserName          = rAttribs.getXString( XML_userName, OUString() );
     132                 :          0 :     maFileSharing.mnPasswordHash      = CodecHelper::getPasswordHash( rAttribs, XML_reservationPassword );
     133                 :          0 :     maFileSharing.mbRecommendReadOnly = rAttribs.getBool( XML_readOnlyRecommended, false );
     134                 :          0 : }
     135                 :            : 
     136                 :         24 : void WorkbookSettings::importWorkbookPr( const AttributeList& rAttribs )
     137                 :            : {
     138         [ +  - ]:         24 :     maBookSettings.maCodeName          = rAttribs.getString( XML_codeName, OUString() );
     139                 :         24 :     maBookSettings.mnShowObjectMode    = rAttribs.getToken( XML_showObjects, XML_all );
     140                 :         24 :     maBookSettings.mnUpdateLinksMode   = rAttribs.getToken( XML_updateLinks, XML_userSet );
     141                 :         24 :     maBookSettings.mnDefaultThemeVer   = rAttribs.getInteger( XML_defaultThemeVersion, -1 );
     142                 :         24 :     maBookSettings.mbSaveExtLinkValues = rAttribs.getBool( XML_saveExternalLinkValues, true );
     143                 :         24 :     setDateMode( rAttribs.getBool( XML_date1904, false ), rAttribs.getBool( XML_dateCompatibility, true ) );
     144                 :         24 : }
     145                 :            : 
     146                 :         24 : void WorkbookSettings::importCalcPr( const AttributeList& rAttribs )
     147                 :            : {
     148                 :         24 :     maCalcSettings.mfIterateDelta  = rAttribs.getDouble( XML_iterateDelta, 0.0001 );
     149                 :         24 :     maCalcSettings.mnCalcId        = rAttribs.getInteger( XML_calcId, -1 );
     150                 :         24 :     maCalcSettings.mnRefMode       = rAttribs.getToken( XML_refMode, XML_A1 );
     151                 :         24 :     maCalcSettings.mnCalcMode      = rAttribs.getToken( XML_calcMode, XML_auto );
     152                 :         24 :     maCalcSettings.mnIterateCount  = rAttribs.getInteger( XML_iterateCount, 100 );
     153                 :         24 :     maCalcSettings.mnProcCount     = rAttribs.getInteger( XML_concurrentManualCount, -1 );
     154                 :         24 :     maCalcSettings.mbCalcOnSave    = rAttribs.getBool( XML_calcOnSave, true );
     155                 :         24 :     maCalcSettings.mbCalcCompleted = rAttribs.getBool( XML_calcCompleted, true );
     156                 :         24 :     maCalcSettings.mbFullPrecision = rAttribs.getBool( XML_fullPrecision, true );
     157                 :         24 :     maCalcSettings.mbIterate       = rAttribs.getBool( XML_iterate, false );
     158                 :         24 :     maCalcSettings.mbConcurrent    = rAttribs.getBool( XML_concurrentCalc, true );
     159                 :         24 : }
     160                 :            : 
     161                 :          0 : void WorkbookSettings::importFileSharing( SequenceInputStream& rStrm )
     162                 :            : {
     163                 :          0 :     maFileSharing.mbRecommendReadOnly = rStrm.readuInt16() != 0;
     164                 :          0 :     rStrm >> maFileSharing.mnPasswordHash >> maFileSharing.maUserName;
     165                 :          0 : }
     166                 :            : 
     167                 :          0 : void WorkbookSettings::importWorkbookPr( SequenceInputStream& rStrm )
     168                 :            : {
     169                 :            :     sal_uInt32 nFlags;
     170 [ #  # ][ #  # ]:          0 :     rStrm >> nFlags >> maBookSettings.mnDefaultThemeVer >> maBookSettings.maCodeName;
                 [ #  # ]
     171                 :          0 :     maBookSettings.setBiffObjectMode( extractValue< sal_uInt16 >( nFlags, 13, 2 ) );
     172                 :            :     // set flag means: strip external link values
     173                 :          0 :     maBookSettings.mbSaveExtLinkValues = !getFlag( nFlags, BIFF12_WORKBOOKPR_STRIPEXT );
     174         [ #  # ]:          0 :     setDateMode( getFlag( nFlags, BIFF12_WORKBOOKPR_DATE1904 ) );
     175                 :          0 : }
     176                 :            : 
     177                 :          0 : void WorkbookSettings::importCalcPr( SequenceInputStream& rStrm )
     178                 :            : {
     179                 :            :     sal_Int32 nCalcMode, nProcCount;
     180                 :            :     sal_uInt16 nFlags;
     181 [ #  # ][ #  # ]:          0 :     rStrm >> maCalcSettings.mnCalcId >> nCalcMode >> maCalcSettings.mnIterateCount >> maCalcSettings.mfIterateDelta >> nProcCount >> nFlags;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     182                 :            : 
     183                 :            :     static const sal_Int32 spnCalcModes[] = { XML_manual, XML_auto, XML_autoNoTable };
     184         [ #  # ]:          0 :     maCalcSettings.mnRefMode       = getFlagValue( nFlags, BIFF12_CALCPR_A1, XML_A1, XML_R1C1 );
     185         [ #  # ]:          0 :     maCalcSettings.mnCalcMode      = STATIC_ARRAY_SELECT( spnCalcModes, nCalcMode, XML_auto );
     186         [ #  # ]:          0 :     maCalcSettings.mnProcCount     = getFlagValue< sal_Int32 >( nFlags, BIFF12_CALCPR_MANUALPROC, nProcCount, -1 );
     187                 :          0 :     maCalcSettings.mbCalcOnSave    = getFlag( nFlags, BIFF12_CALCPR_CALCONSAVE );
     188                 :          0 :     maCalcSettings.mbCalcCompleted = getFlag( nFlags, BIFF12_CALCPR_CALCCOMPLETED );
     189                 :          0 :     maCalcSettings.mbFullPrecision = getFlag( nFlags, BIFF12_CALCPR_FULLPRECISION );
     190                 :          0 :     maCalcSettings.mbIterate       = getFlag( nFlags, BIFF12_CALCPR_ITERATE );
     191                 :          0 :     maCalcSettings.mbConcurrent    = getFlag( nFlags, BIFF12_CALCPR_CONCURRENT );
     192                 :          0 : }
     193                 :            : 
     194                 :         24 : void WorkbookSettings::finalizeImport()
     195                 :            : {
     196                 :            :     // default settings
     197 [ +  - ][ +  - ]:         24 :     PropertySet aPropSet( getDocument() );
     198      [ +  -  - ]:         24 :     switch( getFilterType() )
                 [ +  - ]
     199                 :            :     {
     200                 :            :         case FILTER_OOXML:
     201                 :            :         case FILTER_BIFF:
     202         [ +  - ]:         24 :             aPropSet.setProperty( PROP_IgnoreCase,          true );     // always in Excel
     203         [ +  - ]:         24 :             aPropSet.setProperty( PROP_RegularExpressions,  false );    // not supported in Excel
     204                 :         24 :         break;
     205                 :            :         case FILTER_UNKNOWN:
     206                 :          0 :         break;
     207                 :            :     }
     208                 :            : 
     209                 :            :     // write protection
     210 [ +  - ][ -  + ]:         24 :     if( maFileSharing.mbRecommendReadOnly || (maFileSharing.mnPasswordHash != 0) ) try
     211                 :            :     {
     212 [ #  # ][ #  # ]:          0 :         getBaseFilter().getMediaDescriptor()[ CREATE_OUSTRING( "ReadOnly" ) ] <<= true;
         [ #  # ][ #  # ]
                 [ #  # ]
     213                 :            : 
     214 [ #  # ][ #  # ]:          0 :         Reference< XPropertySet > xDocumentSettings( getBaseFilter().getModelFactory()->createInstance(
                 [ #  # ]
     215 [ #  # ][ #  # ]:          0 :             CREATE_OUSTRING( "com.sun.star.document.Settings" ) ), UNO_QUERY_THROW );
                 [ #  # ]
     216         [ #  # ]:          0 :         PropertySet aSettingsProp( xDocumentSettings );
     217         [ #  # ]:          0 :         if( maFileSharing.mbRecommendReadOnly )
     218 [ #  # ][ #  # ]:          0 :             aSettingsProp.setProperty( PROP_LoadReadonly, true );
                 [ #  # ]
     219                 :            : //        if( maFileSharing.mnPasswordHash != 0 )
     220                 :            : //            aSettingsProp.setProperty( PROP_ModifyPasswordHash, static_cast< sal_Int32 >( maFileSharing.mnPasswordHash ) );
     221                 :            :     }
     222         [ #  # ]:          0 :     catch( Exception& )
     223                 :            :     {
     224                 :            :     }
     225                 :            : 
     226                 :            :     // calculation settings
     227         [ +  - ]:         24 :     Date aNullDate = getNullDate();
     228                 :            : 
     229         [ +  - ]:         24 :     aPropSet.setProperty( PROP_NullDate,           aNullDate );
     230         [ +  - ]:         24 :     aPropSet.setProperty( PROP_IsIterationEnabled, maCalcSettings.mbIterate );
     231         [ +  - ]:         24 :     aPropSet.setProperty( PROP_IterationCount,     maCalcSettings.mnIterateCount );
     232         [ +  - ]:         24 :     aPropSet.setProperty( PROP_IterationEpsilon,   maCalcSettings.mfIterateDelta );
     233         [ +  - ]:         24 :     aPropSet.setProperty( PROP_CalcAsShown,        !maCalcSettings.mbFullPrecision );
     234         [ +  - ]:         24 :     aPropSet.setProperty( PROP_LookUpLabels,       maCalcSettings.mbUseNlr );
     235                 :            : 
     236 [ +  - ][ +  - ]:         24 :     Reference< XNumberFormatsSupplier > xNumFmtsSupp( getDocument(), UNO_QUERY );
     237         [ +  - ]:         24 :     if( xNumFmtsSupp.is() )
     238                 :            :     {
     239 [ +  - ][ +  - ]:         24 :         PropertySet aNumFmtProp( xNumFmtsSupp->getNumberFormatSettings() );
                 [ +  - ]
     240 [ +  - ][ +  - ]:         24 :         aNumFmtProp.setProperty( PROP_NullDate, aNullDate );
     241                 :            :     }
     242                 :            : 
     243 [ +  - ][ +  - ]:         24 :     Reference< XCalculatable > xCalculatable( getDocument(), UNO_QUERY );
     244         [ +  - ]:         24 :     if( xCalculatable.is() )
     245 [ +  - ][ -  + ]:         24 :         xCalculatable->enableAutomaticCalculation( (maCalcSettings.mnCalcMode == XML_auto) || (maCalcSettings.mnCalcMode == XML_autoNoTable) );
         [ #  # ][ +  - ]
     246                 :            : 
     247                 :            :     // VBA code name
     248 [ +  - ][ +  - ]:         24 :     aPropSet.setProperty( PROP_CodeName, maBookSettings.maCodeName );
     249                 :         24 : }
     250                 :            : 
     251                 :         24 : sal_Int16 WorkbookSettings::getApiShowObjectMode() const
     252                 :            : {
     253   [ +  -  -  - ]:         24 :     switch( maBookSettings.mnShowObjectMode )
     254                 :            :     {
     255                 :         24 :         case XML_all:           return API_SHOWMODE_SHOW;
     256                 :          0 :         case XML_none:          return API_SHOWMODE_HIDE;
     257                 :            :         // #i80528# placeholders not supported anymore, but this is handled internally in Calc
     258                 :          0 :         case XML_placeholders:  return API_SHOWMODE_PLACEHOLDER;
     259                 :            :     }
     260                 :         24 :     return API_SHOWMODE_SHOW;
     261                 :            : }
     262                 :            : 
     263                 :         48 : Date WorkbookSettings::getNullDate() const
     264                 :            : {
     265 [ +  + ][ +  - ]:         48 :     static const Date saDate1900                 ( 30, 12, 1899 );
     266 [ +  + ][ +  - ]:         48 :     static const Date saDate1904                 ( 1, 1, 1904 );
     267 [ +  + ][ +  - ]:         48 :     static const Date saDateBackCompatibility1900( 31, 12, 1899 );
     268                 :            : 
     269         [ -  + ]:         48 :     if( getOoxFilter().getVersion() == oox::core::ISOIEC_29500_2008 )
     270                 :            :     {
     271         [ #  # ]:          0 :         if( !maBookSettings.mbDateCompatibility )
     272                 :          0 :             return saDate1900;
     273                 :            : 
     274                 :            :         return maBookSettings.mbDateMode1904 ? saDate1904 :
     275         [ #  # ]:          0 :                                                saDateBackCompatibility1900;
     276                 :            :     }
     277                 :            : 
     278         [ -  + ]:         48 :     return maBookSettings.mbDateMode1904 ? saDate1904 : saDate1900;
     279                 :            : }
     280                 :            : 
     281                 :         24 : void WorkbookSettings::setDateMode( bool bDateMode1904, bool bDateCompatibility )
     282                 :            : {
     283                 :         24 :     maBookSettings.mbDateMode1904      = bDateMode1904;
     284                 :         24 :     maBookSettings.mbDateCompatibility = bDateCompatibility;
     285                 :            : 
     286 [ +  - ][ +  - ]:         24 :     getUnitConverter().finalizeNullDate( getNullDate() );
     287                 :         24 : }
     288                 :            : 
     289                 :            : // ============================================================================
     290                 :            : 
     291                 :            : } // namespace xls
     292 [ +  - ][ +  - ]:         24 : } // namespace oox
     293                 :            : 
     294                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10