LCOV - code coverage report
Current view: top level - sc/source/filter/oox - scenariobuffer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 107 6.5 %
Date: 2012-08-25 Functions: 4 19 21.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 182 1.6 %

           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 "scenariobuffer.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      32                 :            : #include <com/sun/star/sheet/XScenario.hpp>
      33                 :            : #include <com/sun/star/sheet/XScenarios.hpp>
      34                 :            : #include <com/sun/star/sheet/XScenariosSupplier.hpp>
      35                 :            : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      36                 :            : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      37                 :            : #include "oox/helper/attributelist.hxx"
      38                 :            : #include "oox/helper/containerhelper.hxx"
      39                 :            : #include "oox/helper/propertyset.hxx"
      40                 :            : #include "oox/token/properties.hxx"
      41                 :            : #include "addressconverter.hxx"
      42                 :            : #include "biffinputstream.hxx"
      43                 :            : 
      44                 :            : namespace oox {
      45                 :            : namespace xls {
      46                 :            : 
      47                 :            : // ============================================================================
      48                 :            : 
      49                 :            : using namespace ::com::sun::star::container;
      50                 :            : using namespace ::com::sun::star::sheet;
      51                 :            : using namespace ::com::sun::star::table;
      52                 :            : using namespace ::com::sun::star::uno;
      53                 :            : 
      54                 :            : using ::rtl::OUString;
      55                 :            : 
      56                 :            : // ============================================================================
      57                 :            : 
      58                 :            : namespace {
      59                 :            : 
      60                 :            : const sal_Int32 BIFF_SCENARIO_DELETED       = 0x4000;
      61                 :            : 
      62                 :            : } // namespace
      63                 :            : 
      64                 :            : // ============================================================================
      65                 :            : 
      66                 :          0 : ScenarioCellModel::ScenarioCellModel() :
      67                 :            :     mnNumFmtId( 0 ),
      68                 :          0 :     mbDeleted( false )
      69                 :            : {
      70                 :          0 : }
      71                 :            : 
      72                 :            : // ----------------------------------------------------------------------------
      73                 :            : 
      74                 :          0 : ScenarioModel::ScenarioModel() :
      75                 :            :     mbLocked( false ),
      76                 :          0 :     mbHidden( false )
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :            : // ----------------------------------------------------------------------------
      81                 :            : 
      82                 :          0 : Scenario::Scenario( const WorkbookHelper& rHelper, sal_Int16 nSheet ) :
      83                 :            :     WorkbookHelper( rHelper ),
      84         [ #  # ]:          0 :     mnSheet( nSheet )
      85                 :            : {
      86                 :          0 : }
      87                 :            : 
      88                 :          0 : void Scenario::importScenario( const AttributeList& rAttribs )
      89                 :            : {
      90         [ #  # ]:          0 :     maModel.maName    = rAttribs.getXString( XML_name, OUString() );
      91         [ #  # ]:          0 :     maModel.maComment = rAttribs.getXString( XML_comment, OUString() );
      92         [ #  # ]:          0 :     maModel.maUser    = rAttribs.getXString( XML_user, OUString() );
      93                 :          0 :     maModel.mbLocked  = rAttribs.getBool( XML_locked, false );
      94                 :          0 :     maModel.mbHidden  = rAttribs.getBool( XML_hidden, false );
      95                 :          0 : }
      96                 :            : 
      97                 :          0 : void Scenario::importInputCells( const AttributeList& rAttribs )
      98                 :            : {
      99                 :          0 :     ScenarioCellModel aModel;
     100 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellAddressUnchecked( aModel.maPos, rAttribs.getString( XML_r, OUString() ), mnSheet );
                 [ #  # ]
     101         [ #  # ]:          0 :     aModel.maValue    = rAttribs.getXString( XML_val, OUString() );
     102         [ #  # ]:          0 :     aModel.mnNumFmtId = rAttribs.getInteger( XML_numFmtId, 0 );
     103         [ #  # ]:          0 :     aModel.mbDeleted  = rAttribs.getBool( XML_deleted, false );
     104         [ #  # ]:          0 :     maCells.push_back( aModel );
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : void Scenario::importScenario( SequenceInputStream& rStrm )
     108                 :            : {
     109                 :          0 :     rStrm.skip( 2 );    // cell count
     110                 :            :     // two longs instead of flag field
     111                 :          0 :     maModel.mbLocked = rStrm.readInt32() != 0;
     112                 :          0 :     maModel.mbHidden = rStrm.readInt32() != 0;
     113                 :          0 :     rStrm >> maModel.maName >> maModel.maComment >> maModel.maUser;
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : void Scenario::importInputCells( SequenceInputStream& rStrm )
     117                 :            : {
     118                 :            :     // TODO: where is the deleted flag?
     119                 :          0 :     ScenarioCellModel aModel;
     120                 :          0 :     BinAddress aPos;
     121         [ #  # ]:          0 :     rStrm >> aPos;
     122         [ #  # ]:          0 :     rStrm.skip( 8 );
     123         [ #  # ]:          0 :     aModel.mnNumFmtId = rStrm.readuInt16();
     124         [ #  # ]:          0 :     rStrm >> aModel.maValue;
     125 [ #  # ][ #  # ]:          0 :     getAddressConverter().convertToCellAddressUnchecked( aModel.maPos, aPos, mnSheet );
     126         [ #  # ]:          0 :     maCells.push_back( aModel );
     127                 :          0 : }
     128                 :            : 
     129                 :          0 : void Scenario::finalizeImport()
     130                 :            : {
     131         [ #  # ]:          0 :     AddressConverter& rAddrConv = getAddressConverter();
     132         [ #  # ]:          0 :     ::std::vector< CellRangeAddress > aRanges;
     133 [ #  # ][ #  # ]:          0 :     for( ScenarioCellVector::iterator aIt = maCells.begin(), aEnd = maCells.end(); aIt != aEnd; ++aIt )
     134 [ #  # ][ #  # ]:          0 :         if( !aIt->mbDeleted && rAddrConv.checkCellAddress( aIt->maPos, true ) )
         [ #  # ][ #  # ]
     135         [ #  # ]:          0 :             aRanges.push_back( CellRangeAddress( aIt->maPos.Sheet, aIt->maPos.Column, aIt->maPos.Row, aIt->maPos.Column, aIt->maPos.Row ) );
     136                 :            : 
     137 [ #  # ][ #  # ]:          0 :     if( !aRanges.empty() && !maModel.maName.isEmpty() ) try
                 [ #  # ]
     138                 :            :     {
     139                 :            :         /*  Find an unused name for the scenario (Calc stores scenario data in
     140                 :            :             hidden sheets named after the scenario following the base sheet). */
     141 [ #  # ][ #  # ]:          0 :         Reference< XNameAccess > xSheetsNA( getDocument()->getSheets(), UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     142         [ #  # ]:          0 :         OUString aScenName = ContainerHelper::getUnusedName( xSheetsNA, maModel.maName, '_' );
     143                 :            : 
     144                 :            :         // create the new scenario sheet
     145 [ #  # ][ #  # ]:          0 :         Reference< XScenariosSupplier > xScenariosSupp( getSheetFromDoc( mnSheet ), UNO_QUERY_THROW );
     146 [ #  # ][ #  # ]:          0 :         Reference< XScenarios > xScenarios( xScenariosSupp->getScenarios(), UNO_SET_THROW );
                 [ #  # ]
     147 [ #  # ][ #  # ]:          0 :         xScenarios->addNewByName( aScenName, ContainerHelper::vectorToSequence( aRanges ), maModel.maComment );
         [ #  # ][ #  # ]
     148                 :            : 
     149                 :            :         // write scenario cell values
     150 [ #  # ][ #  # ]:          0 :         Reference< XSpreadsheet > xSheet( getSheetFromDoc( aScenName ), UNO_SET_THROW );
     151 [ #  # ][ #  # ]:          0 :         for( ScenarioCellVector::iterator aIt = maCells.begin(), aEnd = maCells.end(); aIt != aEnd; ++aIt )
     152                 :            :         {
     153         [ #  # ]:          0 :             if( !aIt->mbDeleted ) try
     154                 :            :             {
     155                 :            :                 // use XCell::setFormula to auto-detect values and strings
     156 [ #  # ][ #  # ]:          0 :                 Reference< XCell > xCell( xSheet->getCellByPosition( aIt->maPos.Column, aIt->maPos.Row ), UNO_SET_THROW );
                 [ #  # ]
     157 [ #  # ][ #  # ]:          0 :                 xCell->setFormula( aIt->maValue );
                 [ #  # ]
     158                 :            :             }
     159         [ #  # ]:          0 :             catch( Exception& )
     160                 :            :             {
     161                 :            :             }
     162                 :            :         }
     163                 :            : 
     164                 :            :         // scenario properties
     165 [ #  # ][ #  # ]:          0 :         PropertySet aPropSet( xScenarios->getByName( aScenName ) );
                 [ #  # ]
     166         [ #  # ]:          0 :         aPropSet.setProperty( PROP_IsActive, false );
     167         [ #  # ]:          0 :         aPropSet.setProperty( PROP_CopyBack, false );
     168         [ #  # ]:          0 :         aPropSet.setProperty( PROP_CopyStyles, false );
     169         [ #  # ]:          0 :         aPropSet.setProperty( PROP_CopyFormulas, false );
     170         [ #  # ]:          0 :         aPropSet.setProperty( PROP_Protected, maModel.mbLocked );
     171                 :            :         // #112621# do not show/print scenario border
     172         [ #  # ]:          0 :         aPropSet.setProperty( PROP_ShowBorder, false );
     173 [ #  # ][ #  # ]:          0 :         aPropSet.setProperty( PROP_PrintBorder, false );
                 [ #  # ]
     174                 :            :     }
     175         [ #  # ]:          0 :     catch( Exception& )
     176                 :            :     {
     177                 :          0 :     }
     178                 :          0 : }
     179                 :            : 
     180                 :            : // ============================================================================
     181                 :            : 
     182                 :          0 : SheetScenariosModel::SheetScenariosModel() :
     183                 :            :     mnCurrent( 0 ),
     184                 :          0 :     mnShown( 0 )
     185                 :            : {
     186                 :          0 : }
     187                 :            : 
     188                 :            : // ----------------------------------------------------------------------------
     189                 :            : 
     190                 :          0 : SheetScenarios::SheetScenarios( const WorkbookHelper& rHelper, sal_Int16 nSheet ) :
     191                 :            :     WorkbookHelper( rHelper ),
     192         [ #  # ]:          0 :     mnSheet( nSheet )
     193                 :            : {
     194                 :          0 : }
     195                 :            : 
     196                 :          0 : void SheetScenarios::importScenarios( const AttributeList& rAttribs )
     197                 :            : {
     198                 :          0 :     maModel.mnCurrent = rAttribs.getInteger( XML_current, 0 );
     199                 :          0 :     maModel.mnShown   = rAttribs.getInteger( XML_show, 0 );
     200                 :          0 : }
     201                 :            : 
     202                 :          0 : void SheetScenarios::importScenarios( SequenceInputStream& rStrm )
     203                 :            : {
     204                 :          0 :     maModel.mnCurrent = rStrm.readuInt16();
     205                 :          0 :     maModel.mnShown   = rStrm.readuInt16();
     206                 :          0 : }
     207                 :            : 
     208                 :          0 : Scenario& SheetScenarios::createScenario()
     209                 :            : {
     210 [ #  # ][ #  # ]:          0 :     ScenarioVector::value_type xScenario( new Scenario( *this, mnSheet ) );
                 [ #  # ]
     211         [ #  # ]:          0 :     maScenarios.push_back( xScenario );
     212         [ #  # ]:          0 :     return *xScenario;
     213                 :            : }
     214                 :            : 
     215                 :          0 : void SheetScenarios::finalizeImport()
     216                 :            : {
     217                 :          0 :     maScenarios.forEachMem( &Scenario::finalizeImport );
     218                 :            : 
     219                 :            :     // activate a scenario
     220                 :            :     try
     221                 :            :     {
     222 [ #  # ][ #  # ]:          0 :         Reference< XScenariosSupplier > xScenariosSupp( getSheetFromDoc( mnSheet ), UNO_QUERY_THROW );
     223 [ #  # ][ #  # ]:          0 :         Reference< XIndexAccess > xScenariosIA( xScenariosSupp->getScenarios(), UNO_QUERY_THROW );
                 [ #  # ]
     224 [ #  # ][ #  # ]:          0 :         Reference< XScenario > xScenario( xScenariosIA->getByIndex( maModel.mnShown ), UNO_QUERY_THROW );
                 [ #  # ]
     225 [ #  # ][ #  # ]:          0 :         xScenario->apply();
                 [ #  # ]
     226                 :            :     }
     227                 :          0 :     catch( Exception& )
     228                 :            :     {
     229                 :            :     }
     230                 :          0 : }
     231                 :            : 
     232                 :            : // ============================================================================
     233                 :            : 
     234                 :         24 : ScenarioBuffer::ScenarioBuffer( const WorkbookHelper& rHelper ) :
     235         [ +  - ]:         24 :     WorkbookHelper( rHelper )
     236                 :            : {
     237                 :         24 : }
     238                 :            : 
     239                 :          0 : SheetScenarios& ScenarioBuffer::createSheetScenarios( sal_Int16 nSheet )
     240                 :            : {
     241                 :          0 :     SheetScenariosMap::mapped_type& rxSheetScens = maSheetScenarios[ nSheet ];
     242         [ #  # ]:          0 :     if( !rxSheetScens )
     243         [ #  # ]:          0 :         rxSheetScens.reset( new SheetScenarios( *this, nSheet ) );
     244                 :          0 :     return *rxSheetScens;
     245                 :            : }
     246                 :            : 
     247                 :         24 : void ScenarioBuffer::finalizeImport()
     248                 :            : {
     249                 :         24 :     maSheetScenarios.forEachMem( &SheetScenarios::finalizeImport );
     250                 :         24 : }
     251                 :            : 
     252                 :            : // ============================================================================
     253                 :            : 
     254                 :            : } // namespace xls
     255 [ +  - ][ +  - ]:         24 : } // namespace oox
     256                 :            : 
     257                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10