LCOV - code coverage report
Current view: top level - sc/source/filter/oox - excelvbaproject.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 34 2.9 %
Date: 2012-08-25 Functions: 2 7 28.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 78 2.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 "excelvbaproject.hxx"
      30                 :            : 
      31                 :            : #include <list>
      32                 :            : #include <set>
      33                 :            : #include <com/sun/star/container/XEnumeration.hpp>
      34                 :            : #include <com/sun/star/container/XEnumerationAccess.hpp>
      35                 :            : #include <com/sun/star/document/XEventsSupplier.hpp>
      36                 :            : #include <com/sun/star/frame/XModel.hpp>
      37                 :            : #include <com/sun/star/script/ModuleType.hpp>
      38                 :            : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      39                 :            : #include <rtl/ustrbuf.hxx>
      40                 :            : #include "oox/helper/helper.hxx"
      41                 :            : #include "oox/helper/propertyset.hxx"
      42                 :            : #include "oox/token/properties.hxx"
      43                 :            : 
      44                 :            : namespace oox {
      45                 :            : namespace xls {
      46                 :            : 
      47                 :            : // ============================================================================
      48                 :            : 
      49                 :            : using namespace ::com::sun::star::container;
      50                 :            : using namespace ::com::sun::star::document;
      51                 :            : using namespace ::com::sun::star::frame;
      52                 :            : using namespace ::com::sun::star::lang;
      53                 :            : using namespace ::com::sun::star::script;
      54                 :            : using namespace ::com::sun::star::sheet;
      55                 :            : using namespace ::com::sun::star::uno;
      56                 :            : 
      57                 :            : using ::rtl::OUString;
      58                 :            : using ::rtl::OUStringBuffer;
      59                 :            : 
      60                 :            : // ============================================================================
      61                 :            : 
      62                 :          0 : ExcelVbaProject::ExcelVbaProject( const Reference< XComponentContext >& rxContext, const Reference< XSpreadsheetDocument >& rxDocument ) :
      63                 :            :     ::oox::ole::VbaProject( rxContext, Reference< XModel >( rxDocument, UNO_QUERY ), CREATE_OUSTRING( "Calc" ) ),
      64 [ #  # ][ #  # ]:          0 :     mxDocument( rxDocument )
      65                 :            : {
      66                 :          0 : }
      67                 :            : 
      68                 :            : // protected ------------------------------------------------------------------
      69                 :            : 
      70                 :            : namespace {
      71                 :            : 
      72                 :          0 : struct SheetCodeNameInfo
      73                 :            : {
      74                 :            :     PropertySet         maSheetProps;       /// Property set of the sheet without codename.
      75                 :            :     OUString            maPrefix;           /// Prefix for the codename to be generated.
      76                 :            : 
      77                 :          0 :     inline explicit     SheetCodeNameInfo( PropertySet& rSheetProps, const OUString& rPrefix ) :
      78                 :          0 :                             maSheetProps( rSheetProps ), maPrefix( rPrefix ) {}
      79                 :            : };
      80                 :            : 
      81                 :            : typedef ::std::set< OUString >              CodeNameSet;
      82                 :            : typedef ::std::list< SheetCodeNameInfo >    SheetCodeNameInfoList;
      83                 :            : 
      84                 :            : } // namespace
      85                 :            : 
      86                 :          0 : void ExcelVbaProject::prepareImport()
      87                 :            : {
      88                 :            :     /*  Check if the sheets have imported codenames. Generate new unused
      89                 :            :         codenames if not. */
      90         [ #  # ]:          0 :     if( mxDocument.is() ) try
      91                 :            :     {
      92                 :            :         // collect existing codenames (do not use them when creating new codenames)
      93         [ #  # ]:          0 :         CodeNameSet aUsedCodeNames;
      94                 :            : 
      95                 :            :         // collect sheets without codenames
      96         [ #  # ]:          0 :         SheetCodeNameInfoList aCodeNameInfos;
      97                 :            : 
      98                 :            :         // iterate over all imported sheets
      99 [ #  # ][ #  # ]:          0 :         Reference< XEnumerationAccess > xSheetsEA( mxDocument->getSheets(), UNO_QUERY_THROW );
                 [ #  # ]
     100 [ #  # ][ #  # ]:          0 :         Reference< XEnumeration > xSheetsEnum( xSheetsEA->createEnumeration(), UNO_SET_THROW );
                 [ #  # ]
     101                 :            :         // own try/catch for every sheet
     102 [ #  # ][ #  # ]:          0 :         while( xSheetsEnum->hasMoreElements() ) try
                 [ #  # ]
     103                 :            :         {
     104 [ #  # ][ #  # ]:          0 :             PropertySet aSheetProp( xSheetsEnum->nextElement() );
                 [ #  # ]
     105                 :          0 :             OUString aCodeName;
     106         [ #  # ]:          0 :             aSheetProp.getProperty( aCodeName, PROP_CodeName );
     107         [ #  # ]:          0 :             if( !aCodeName.isEmpty() )
     108                 :            :             {
     109         [ #  # ]:          0 :                 aUsedCodeNames.insert( aCodeName );
     110                 :            :             }
     111                 :            :             else
     112                 :            :             {
     113                 :            :                 // TODO: once we have chart sheets we need a switch/case on sheet type ('SheetNNN' vs. 'ChartNNN')
     114 [ #  # ][ #  # ]:          0 :                 aCodeNameInfos.push_back( SheetCodeNameInfo( aSheetProp, CREATE_OUSTRING( "Sheet" ) ) );
         [ #  # ][ #  # ]
     115 [ #  # ][ #  # ]:          0 :             }
     116                 :            :         }
     117         [ #  # ]:          0 :         catch( Exception& )
     118                 :            :         {
     119                 :            :         }
     120                 :            : 
     121                 :            :         // create new codenames if sheets do not have one
     122         [ #  # ]:          0 :         for( SheetCodeNameInfoList::iterator aIt = aCodeNameInfos.begin(), aEnd = aCodeNameInfos.end(); aIt != aEnd; ++aIt )
     123                 :            :         {
     124                 :            :             // search for an unused codename
     125                 :          0 :             sal_Int32 nCounter = 1;
     126                 :          0 :             OUString aCodeName;
     127         [ #  # ]:          0 :             do
     128                 :            :             {
     129 [ #  # ][ #  # ]:          0 :                 aCodeName = OUStringBuffer( aIt->maPrefix ).append( nCounter++ ).makeStringAndClear();
                 [ #  # ]
     130                 :            :             }
     131         [ #  # ]:          0 :             while( aUsedCodeNames.count( aCodeName ) > 0 );
     132         [ #  # ]:          0 :             aUsedCodeNames.insert( aCodeName );
     133                 :            : 
     134                 :            :             // set codename at sheet
     135         [ #  # ]:          0 :             aIt->maSheetProps.setProperty( PROP_CodeName, aCodeName );
     136                 :            : 
     137                 :            :             // tell base class to create a dummy module
     138         [ #  # ]:          0 :             addDummyModule( aCodeName, ModuleType::DOCUMENT );
     139         [ #  # ]:          0 :         }
     140                 :            :     }
     141                 :          0 :     catch( Exception& )
     142                 :            :     {
     143                 :            :     }
     144                 :          0 : }
     145                 :            : 
     146                 :            : // ============================================================================
     147                 :            : 
     148                 :            : } // namespace xls
     149 [ +  - ][ +  - ]:         24 : } // namespace oox
     150                 :            : 
     151                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10