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

Generated by: LCOV version 1.10