LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaworksheets.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 286 0.0 %
Date: 2014-04-14 Functions: 0 41 0.0 %
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             : #include "vbaworksheets.hxx"
      20             : 
      21             : #include <sfx2/dispatch.hxx>
      22             : #include <sfx2/app.hxx>
      23             : #include <sfx2/bindings.hxx>
      24             : #include <sfx2/request.hxx>
      25             : #include <sfx2/viewfrm.hxx>
      26             : #include <sfx2/itemwrapper.hxx>
      27             : #include <svl/itemset.hxx>
      28             : #include <svl/eitem.hxx>
      29             : 
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <cppuhelper/implbase3.hxx>
      32             : 
      33             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      34             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      35             : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
      36             : #include <com/sun/star/container/XNamed.hpp>
      37             : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
      38             : #include <com/sun/star/beans/XPropertySet.hpp>
      39             : 
      40             : #include <ooo/vba/excel/XApplication.hpp>
      41             : #include "tabvwsh.hxx"
      42             : 
      43             : #include "vbaglobals.hxx"
      44             : #include "vbaworksheet.hxx"
      45             : #include "vbaworkbook.hxx"
      46             : #include "unonames.hxx"
      47             : #include "markdata.hxx"
      48             : 
      49             : #include <vector>
      50             : #include "prevwsh.hxx"
      51             : #include "preview.hxx"
      52             : using namespace ::ooo::vba;
      53             : using namespace ::com::sun::star;
      54             : 
      55             : 
      56             : typedef ::cppu::WeakImplHelper1< container::XEnumeration > SheetEnumeration_BASE;
      57             : typedef ::cppu::WeakImplHelper3< container::XNameAccess, container::XIndexAccess, container::XEnumerationAccess > SheetCollectionHelper_BASE;
      58             : // a map ( or hashmap ) wont do as we need also to preserve the order
      59             : // (as added ) of the items
      60             : typedef std::vector< uno::Reference< sheet::XSpreadsheet > >  SheetMap;
      61             : 
      62             : 
      63             : // #FIXME #TODO the implementation of the Sheets collections sucks,
      64             : // e.g. there is no support for tracking sheets added/removed from the collection
      65             : 
      66           0 : class WorkSheetsEnumeration : public SheetEnumeration_BASE
      67             : {
      68             :     SheetMap mSheetMap;
      69             :     SheetMap::iterator mIt;
      70             : public:
      71           0 :     WorkSheetsEnumeration( const SheetMap& sMap ) : mSheetMap( sMap ), mIt( mSheetMap.begin() ) {}
      72           0 :     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
      73             :     {
      74           0 :         return ( mIt != mSheetMap.end() );
      75             :     }
      76           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      77             :     {
      78           0 :         if ( !hasMoreElements() )
      79           0 :             throw container::NoSuchElementException();
      80           0 :         uno::Reference< sheet::XSpreadsheet > xSheet( *mIt++ );
      81           0 :         return uno::makeAny( xSheet ) ;
      82             :     }
      83             : };
      84             : 
      85           0 : class SheetCollectionHelper : public SheetCollectionHelper_BASE
      86             : {
      87             :     SheetMap mSheetMap;
      88             :     SheetMap::iterator cachePos;
      89             : public:
      90           0 :     SheetCollectionHelper( const SheetMap& sMap ) : mSheetMap( sMap ), cachePos(mSheetMap.begin()) {}
      91             :     // XElementAccess
      92           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return  cppu::UnoType<sheet::XSpreadsheet>::get(); }
      93           0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return ( !mSheetMap.empty() ); }
      94             :     // XNameAcess
      95           0 :     virtual uno::Any SAL_CALL getByName( const OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      96             :     {
      97           0 :         if ( !hasByName(aName) )
      98           0 :             throw container::NoSuchElementException();
      99           0 :         return uno::makeAny( *cachePos );
     100             :     }
     101           0 :     virtual uno::Sequence< OUString > SAL_CALL getElementNames(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     102             :     {
     103           0 :         uno::Sequence< OUString > sNames( mSheetMap.size() );
     104           0 :         OUString* pString = sNames.getArray();
     105           0 :         SheetMap::iterator it = mSheetMap.begin();
     106           0 :         SheetMap::iterator it_end = mSheetMap.end();
     107             : 
     108           0 :         for ( ; it != it_end; ++it, ++pString )
     109             :         {
     110           0 :             uno::Reference< container::XNamed > xName( *it, uno::UNO_QUERY_THROW );
     111           0 :             *pString = xName->getName();
     112           0 :         }
     113           0 :         return sNames;
     114             :     }
     115           0 :     virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     116             :     {
     117           0 :         cachePos = mSheetMap.begin();
     118           0 :         SheetMap::iterator it_end = mSheetMap.end();
     119           0 :         for ( ; cachePos != it_end; ++cachePos )
     120             :         {
     121           0 :             uno::Reference< container::XNamed > xName( *cachePos, uno::UNO_QUERY_THROW );
     122           0 :             if ( aName.equals( xName->getName() ) )
     123           0 :                 break;
     124           0 :         }
     125           0 :         return ( cachePos != it_end );
     126             :     }
     127             : 
     128             :     // XElementAccess
     129           0 :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mSheetMap.size(); }
     130           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception ) SAL_OVERRIDE
     131             :     {
     132           0 :         if ( Index < 0 || Index >= getCount() )
     133           0 :             throw lang::IndexOutOfBoundsException();
     134             : 
     135           0 :         return uno::makeAny( mSheetMap[ Index ] );
     136             : 
     137             :     }
     138             :     // XEnumerationAccess
     139           0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     140             :     {
     141           0 :         return new WorkSheetsEnumeration( mSheetMap );
     142             :     }
     143             : };
     144             : 
     145           0 : class SheetsEnumeration : public EnumerationHelperImpl
     146             : {
     147             :     uno::Reference< frame::XModel > m_xModel;
     148             : public:
     149           0 :     SheetsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration,  const uno::Reference< frame::XModel >& xModel  ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_xModel( xModel ) {}
     150             : 
     151           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
     152             :     {
     153           0 :         uno::Reference< sheet::XSpreadsheet > xSheet( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
     154           0 :         uno::Reference< XHelperInterface > xIf = excel::getUnoSheetModuleObj( xSheet );
     155           0 :         uno::Any aRet;
     156           0 :         if ( !xIf.is() )
     157             :         {
     158             :             // if the Sheet is in a document created by the api unfortunately ( at the
     159             :             // moment, it actually wont have the special Document modules
     160           0 :             uno::Reference< excel::XWorksheet > xNewSheet( new ScVbaWorksheet( m_xParent, m_xContext, xSheet, m_xModel ) );
     161           0 :             aRet <<= xNewSheet;
     162             :         }
     163             :         else
     164           0 :             aRet <<= xIf;
     165           0 :         return aRet;
     166             :     }
     167             : 
     168             : };
     169             : 
     170           0 : ScVbaWorksheets::ScVbaWorksheets( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xSheets, const uno::Reference< frame::XModel >& xModel ): ScVbaWorksheets_BASE( xParent, xContext,  xSheets ), mxModel( xModel ), m_xSheets( uno::Reference< sheet::XSpreadsheets >( xSheets, uno::UNO_QUERY ) )
     171             : {
     172           0 : }
     173             : 
     174           0 : ScVbaWorksheets::ScVbaWorksheets( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XEnumerationAccess >& xEnumAccess, const uno::Reference< frame::XModel >& xModel  ):  ScVbaWorksheets_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xEnumAccess, uno::UNO_QUERY ) ), mxModel(xModel)
     175             : {
     176           0 : }
     177             : 
     178             : // XEnumerationAccess
     179             : uno::Type
     180           0 : ScVbaWorksheets::getElementType() throw (uno::RuntimeException)
     181             : {
     182           0 :     return cppu::UnoType<excel::XWorksheet>::get();
     183             : }
     184             : 
     185             : uno::Reference< container::XEnumeration >
     186           0 : ScVbaWorksheets::createEnumeration() throw (uno::RuntimeException)
     187             : {
     188           0 :     if ( !m_xSheets.is() )
     189             :     {
     190           0 :         uno::Reference< container::XEnumerationAccess > xAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     191           0 :         return xAccess->createEnumeration();
     192             :     }
     193           0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xSheets, uno::UNO_QUERY_THROW );
     194           0 :     return new SheetsEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel );
     195             : }
     196             : 
     197             : uno::Any
     198           0 : ScVbaWorksheets::createCollectionObject( const uno::Any& aSource )
     199             : {
     200           0 :     uno::Reference< sheet::XSpreadsheet > xSheet( aSource, uno::UNO_QUERY );
     201           0 :     uno::Reference< XHelperInterface > xIf = excel::getUnoSheetModuleObj( xSheet );
     202           0 :     uno::Any aRet;
     203           0 :     if ( !xIf.is() )
     204             :     {
     205             :         // if the Sheet is in a document created by the api unfortunately ( at the
     206             :         // moment, it actually wont have the special Document modules
     207           0 :         uno::Reference< excel::XWorksheet > xNewSheet( new ScVbaWorksheet( getParent(), mxContext, xSheet, mxModel ) );
     208           0 :         aRet <<= xNewSheet;
     209             :     }
     210             :     else
     211           0 :         aRet <<= xIf;
     212           0 :     return aRet;
     213             : }
     214             : 
     215             : // XWorksheets
     216             : uno::Any
     217           0 : ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After,
     218             :                      const uno::Any& Count, const uno::Any& Type ) throw (uno::RuntimeException, std::exception)
     219             : {
     220           0 :     if ( isSelectedSheets() )
     221           0 :         return uno::Any(); // or should we throw?
     222             : 
     223           0 :     OUString aStringSheet;
     224           0 :     sal_Bool bBefore(sal_True);
     225           0 :     SCTAB nSheetIndex = 0;
     226           0 :     SCTAB nNewSheets = 1, nType = 0;
     227           0 :     Count >>= nNewSheets;
     228           0 :     Type >>= nType;
     229           0 :     SCTAB nCount = 0;
     230             : 
     231           0 :     uno::Reference< excel::XWorksheet > xBeforeAfterSheet;
     232             : 
     233           0 :     if ( Before.hasValue() )
     234             :     {
     235           0 :             if ( Before >>= xBeforeAfterSheet )
     236           0 :             aStringSheet = xBeforeAfterSheet->getName();
     237             :         else
     238           0 :             Before >>= aStringSheet;
     239             :     }
     240             : 
     241           0 :     if (aStringSheet.isEmpty() && After.hasValue() )
     242             :     {
     243           0 :             if ( After >>= xBeforeAfterSheet )
     244           0 :             aStringSheet = xBeforeAfterSheet->getName();
     245             :         else
     246           0 :             After >>= aStringSheet;
     247           0 :         bBefore = false;
     248             :     }
     249           0 :     if (aStringSheet.isEmpty())
     250             :     {
     251           0 :         uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
     252           0 :         aStringSheet = xApplication->getActiveWorkbook()->getActiveSheet()->getName();
     253           0 :         bBefore = sal_True;
     254             :     }
     255           0 :         nCount = static_cast< SCTAB >( m_xIndexAccess->getCount() );
     256           0 :         for (SCTAB i=0; i < nCount; i++)
     257             :         {
     258           0 :             uno::Reference< sheet::XSpreadsheet > xSheet(m_xIndexAccess->getByIndex(i), uno::UNO_QUERY);
     259           0 :             uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
     260           0 :             if (xNamed->getName() == aStringSheet)
     261             :             {
     262           0 :                 nSheetIndex = i;
     263           0 :                 break;
     264             :             }
     265           0 :         }
     266             : 
     267           0 :     if(!bBefore)
     268           0 :         nSheetIndex++;
     269             : 
     270           0 :     SCTAB nSheetName = nCount + 1L;
     271           0 :     OUString aStringBase( "Sheet" );
     272           0 :     uno::Any result;
     273           0 :     for (SCTAB i=0; i < nNewSheets; i++, nSheetName++)
     274             :     {
     275           0 :         OUString aStringName = aStringBase + OUString::number(nSheetName);
     276           0 :         while (m_xNameAccess->hasByName(aStringName))
     277             :         {
     278           0 :             nSheetName++;
     279           0 :             aStringName = aStringBase + OUString::number(nSheetName);
     280             :         }
     281           0 :         m_xSheets->insertNewByName(aStringName, nSheetIndex + i);
     282           0 :         result = getItemByStringIndex( aStringName );
     283           0 :     }
     284           0 :     uno::Reference< excel::XWorksheet > xNewSheet( result, uno::UNO_QUERY );
     285           0 :     if ( xNewSheet.is() )
     286           0 :         xNewSheet->Activate();
     287           0 :     return  result;
     288             : }
     289             : 
     290             : void
     291           0 : ScVbaWorksheets::Delete() throw (uno::RuntimeException, std::exception)
     292             : {
     293             :     // #TODO #INVESTIGATE
     294             :     // mmm this method could be trouble if the underlying
     295             :     // uno objects ( the m_xIndexAccess etc ) aren't aware of the
     296             :     // contents that are deleted
     297           0 :     sal_Int32 nElems = getCount();
     298           0 :     for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem )
     299             :     {
     300           0 :         uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW );
     301           0 :         xSheet->Delete();
     302           0 :     }
     303           0 : }
     304             : 
     305             : bool
     306           0 : ScVbaWorksheets::isSelectedSheets()
     307             : {
     308           0 :     return !m_xSheets.is();
     309             : }
     310             : 
     311             : void SAL_CALL
     312           0 : ScVbaWorksheets::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) throw (uno::RuntimeException, std::exception)
     313             : {
     314           0 :     sal_Int32 nTo = 0;
     315           0 :     sal_Int32 nFrom = 0;
     316           0 :     sal_Int16 nCopies = 1;
     317           0 :     sal_Bool bCollate = false;
     318           0 :     sal_Bool bSelection = false;
     319           0 :     From >>= nFrom;
     320           0 :     To >>= nTo;
     321           0 :     Copies >>= nCopies;
     322           0 :     if ( nCopies > 1 ) // Collate only useful when more that 1 copy
     323           0 :         Collate >>= bCollate;
     324             : 
     325           0 :     if ( !( nFrom || nTo ) )
     326           0 :         if ( isSelectedSheets() )
     327           0 :             bSelection = sal_True;
     328             : 
     329           0 :     PrintOutHelper( excel::getBestViewShell( mxModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection );
     330           0 : }
     331             : 
     332             : uno::Any SAL_CALL
     333           0 : ScVbaWorksheets::getVisible() throw (uno::RuntimeException, std::exception)
     334             : {
     335           0 :     sal_Bool bVisible = sal_True;
     336           0 :     uno::Reference< container::XEnumeration > xEnum( createEnumeration(), uno::UNO_QUERY_THROW );
     337           0 :     while ( xEnum->hasMoreElements() )
     338             :     {
     339           0 :         uno::Reference< excel::XWorksheet > xSheet( xEnum->nextElement(), uno::UNO_QUERY_THROW );
     340           0 :         if ( xSheet->getVisible() == 0 )
     341             :         {
     342           0 :                 bVisible = false;
     343           0 :                 break;
     344             :         }
     345           0 :     }
     346           0 :     return uno::makeAny( bVisible );
     347             : }
     348             : 
     349             : void SAL_CALL
     350           0 : ScVbaWorksheets::setVisible( const uno::Any& _visible ) throw (uno::RuntimeException, std::exception)
     351             : {
     352           0 :     sal_Bool bState = false;
     353           0 :     if ( _visible >>= bState )
     354             :     {
     355           0 :         uno::Reference< container::XEnumeration > xEnum( createEnumeration(), uno::UNO_QUERY_THROW );
     356           0 :         while ( xEnum->hasMoreElements() )
     357             :         {
     358           0 :             uno::Reference< excel::XWorksheet > xSheet( xEnum->nextElement(), uno::UNO_QUERY_THROW );
     359           0 :             xSheet->setVisible( bState );
     360           0 :         }
     361             :     }
     362             :     else
     363           0 :         throw uno::RuntimeException("Visible property doesn't support non boolean #FIXME", uno::Reference< uno::XInterface >() );
     364           0 : }
     365             : 
     366             : void SAL_CALL
     367           0 : ScVbaWorksheets::Select( const uno::Any& Replace ) throw (uno::RuntimeException, std::exception)
     368             : {
     369           0 :     ScTabViewShell* pViewShell = excel::getBestViewShell( mxModel );
     370           0 :     if ( !pViewShell )
     371           0 :         throw uno::RuntimeException("Cannot obtain view shell", uno::Reference< uno::XInterface >() );
     372             : 
     373           0 :     ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData();
     374           0 :     sal_Bool bReplace = sal_True;
     375           0 :     Replace >>= bReplace;
     376             :     // Replace is defaulted to True, meanining this current collection
     377             :     // becomes the Selection, if it were false then the current selection would
     378             :     // be extended
     379           0 :     bool bSelectSingle = bReplace;
     380           0 :     sal_Int32 nElems = getCount();
     381           0 :     for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem )
     382             :     {
     383           0 :         uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW );
     384           0 :         ScVbaWorksheet* pSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
     385           0 :         if ( bSelectSingle )
     386             :         {
     387           0 :             rMarkData.SelectOneTable( static_cast< SCTAB >( pSheet->getSheetID() ) );
     388           0 :             bSelectSingle = false;
     389             :         }
     390             :         else
     391           0 :             rMarkData.SelectTable( static_cast< SCTAB >( pSheet->getSheetID() ), true );
     392           0 :     }
     393             : 
     394             : 
     395           0 : }
     396             : 
     397             : void SAL_CALL
     398           0 : ScVbaWorksheets::Copy ( const uno::Any& Before, const uno::Any& After) throw (css::uno::RuntimeException, std::exception)
     399             : {
     400           0 :     uno::Reference<excel::XWorksheet> xSheet;
     401           0 :     sal_Int32 nElems = getCount();
     402           0 :     bool bAfter = After.hasValue();
     403           0 :     std::vector< uno::Reference< excel::XWorksheet > > Sheets;
     404           0 :     sal_Int32 nItem = 0;
     405             : 
     406           0 :     for ( nItem = 1; nItem <= nElems; ++nItem)
     407             :     {
     408           0 :         uno::Reference<excel::XWorksheet> xWorksheet(Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW );
     409           0 :         Sheets.push_back(xWorksheet);
     410           0 :     }
     411           0 :     bool bNewDoc = (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()));
     412             : 
     413           0 :     uno::Reference< excel::XWorksheet > xSrcSheet;
     414           0 :     if ( bNewDoc )
     415             :     {
     416           0 :         bAfter = true;
     417           0 :         xSrcSheet = Sheets.at(0);
     418           0 :         ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
     419           0 :         xSheet = pSrcSheet->createSheetCopyInNewDoc(xSrcSheet->getName());
     420           0 :         nItem = 1;
     421             :     }
     422             :     else
     423             :     {
     424           0 :         nItem=0;
     425             :     }
     426             : 
     427           0 :     for (; nItem < nElems; ++nItem )
     428             :     {
     429           0 :         xSrcSheet = Sheets[nItem];
     430           0 :         ScVbaWorksheet* pSrcSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSrcSheet );
     431           0 :         if ( bAfter )
     432           0 :             xSheet = pSrcSheet->createSheetCopy(xSheet, bAfter);
     433             :         else
     434           0 :             pSrcSheet->createSheetCopy(xSheet, bAfter);
     435           0 :     }
     436           0 : }
     437             : 
     438             : //ScVbaCollectionBaseImpl
     439             : uno::Any SAL_CALL
     440           0 : ScVbaWorksheets::Item( const uno::Any& Index, const uno::Any& Index2  ) throw (uno::RuntimeException)
     441             : {
     442           0 :     if ( Index.getValueTypeClass() == uno::TypeClass_SEQUENCE )
     443             :     {
     444           0 :         uno::Reference< script::XTypeConverter > xConverter = getTypeConverter(mxContext);
     445           0 :         uno::Any aConverted;
     446           0 :         aConverted = xConverter->convertTo( Index, getCppuType((uno::Sequence< uno::Any >*)0) );
     447           0 :         SheetMap mSheets;
     448           0 :         uno::Sequence< uno::Any > sIndices;
     449           0 :         aConverted >>= sIndices;
     450           0 :         sal_Int32 nElems = sIndices.getLength();
     451           0 :         for( sal_Int32 index = 0; index < nElems; ++index )
     452             :         {
     453           0 :             uno::Reference< excel::XWorksheet > xWorkSheet( ScVbaWorksheets_BASE::Item( sIndices[ index ], Index2 ), uno::UNO_QUERY_THROW );
     454           0 :             ScVbaWorksheet* pWorkSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xWorkSheet );
     455           0 :             uno::Reference< sheet::XSpreadsheet > xSheet( pWorkSheet->getSheet() , uno::UNO_QUERY_THROW );
     456           0 :             uno::Reference< container::XNamed > xName( xSheet, uno::UNO_QUERY_THROW );
     457           0 :             mSheets.push_back( xSheet );
     458           0 :         }
     459           0 :         uno::Reference< container::XIndexAccess > xIndexAccess = new SheetCollectionHelper( mSheets );
     460           0 :         uno::Reference< XCollection > xSelectedSheets(  new ScVbaWorksheets( this->getParent(), mxContext, xIndexAccess, mxModel ) );
     461           0 :         return uno::makeAny( xSelectedSheets );
     462             :     }
     463           0 :     return  ScVbaWorksheets_BASE::Item( Index, Index2 );
     464             : }
     465             : 
     466             : uno::Any
     467           0 : ScVbaWorksheets::getItemByStringIndex( const OUString& sIndex ) throw (uno::RuntimeException)
     468             : {
     469           0 :     return ScVbaWorksheets_BASE::getItemByStringIndex( sIndex );
     470             : }
     471             : 
     472             : OUString
     473           0 : ScVbaWorksheets::getServiceImplName()
     474             : {
     475           0 :     return OUString("ScVbaWorksheets");
     476             : }
     477             : 
     478             : css::uno::Sequence<OUString>
     479           0 : ScVbaWorksheets::getServiceNames()
     480             : {
     481           0 :     static uno::Sequence< OUString > sNames;
     482           0 :     if ( sNames.getLength() == 0 )
     483             :     {
     484           0 :         sNames.realloc( 1 );
     485           0 :         sNames[0] = "ooo.vba.excel.Worksheets";
     486             :     }
     487           0 :     return sNames;
     488             : }
     489             : 
     490           0 : bool ScVbaWorksheets::nameExists( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, const OUString & name, SCTAB& nTab ) throw ( lang::IllegalArgumentException )
     491             : {
     492           0 :     if (!xSpreadDoc.is())
     493           0 :         throw lang::IllegalArgumentException( OUString( "nameExists() xSpreadDoc is null" ), uno::Reference< uno::XInterface  >(), 1 );
     494           0 :     uno::Reference <container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
     495           0 :     if ( xIndex.is() )
     496             :     {
     497           0 :         SCTAB  nCount = static_cast< SCTAB >( xIndex->getCount() );
     498           0 :         for (SCTAB i=0; i < nCount; i++)
     499             :         {
     500           0 :             uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), uno::UNO_QUERY_THROW );
     501           0 :             if (xNamed->getName() == name)
     502             :             {
     503           0 :                 nTab = i;
     504           0 :                 return true;
     505             :             }
     506           0 :         }
     507             :     }
     508           0 :     return false;
     509             : }
     510             : 
     511           0 : void ScVbaWorksheets::PrintPreview( const css::uno::Any& /*EnableChanges*/ ) throw (css::uno::RuntimeException, std::exception)
     512             : {
     513             :     // need test, print preview current active sheet
     514             :     // !! TODO !! get view shell from controller
     515           0 :     ScTabViewShell* pViewShell = excel::getBestViewShell( mxModel );
     516           0 :     SfxViewFrame* pViewFrame = NULL;
     517           0 :     if ( pViewShell )
     518           0 :         pViewFrame = pViewShell->GetViewFrame();
     519           0 :     if ( pViewFrame )
     520             :     {
     521           0 :         if ( !pViewFrame->GetFrame().IsInPlace() )
     522             :         {
     523           0 :             dispatchExecute( pViewShell, SID_VIEWSHELL1 );
     524           0 :             SfxViewShell*  pShell = SfxViewShell::Get( pViewFrame->GetFrame().GetFrameInterface()->getController() );
     525             : 
     526           0 :             if (  pShell->ISA( ScPreviewShell ) )
     527             :             {
     528           0 :                 ScPreviewShell* pPrvShell = static_cast<  ScPreviewShell* >( pShell );
     529           0 :                 ScPreview* pPrvView = pPrvShell->GetPreview();
     530           0 :                 ScMarkData aMarkData;
     531           0 :                 sal_Int32 nElems = getCount();
     532           0 :                 for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem )
     533             :                 {
     534           0 :                     uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW );
     535           0 :                     ScVbaWorksheet* pSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
     536           0 :                     if ( pSheet )
     537           0 :                         aMarkData.SelectTable(static_cast< SCTAB >( pSheet->getSheetID() ), true );
     538           0 :                 }
     539             :                 // save old selection, setting the selectedtabs in the preview
     540             :                 // can affect the current selection when preview has been
     541             :                 // closed
     542           0 :                 ScMarkData::MarkedTabsType aOldTabs = pPrvView->GetSelectedTabs();
     543           0 :                 pPrvView->SetSelectedTabs( aMarkData );
     544             :                 // force update
     545           0 :                 pPrvView->DataChanged();
     546             :                 // set sensible first page
     547           0 :                 long nPage = pPrvView->GetFirstPage( 1 );
     548           0 :                 pPrvView->SetPageNo( nPage );
     549           0 :                 WaitUntilPreviewIsClosed( pViewFrame );
     550             :                 // restore old tab selection
     551           0 :                 pViewShell = excel::getBestViewShell( mxModel );
     552           0 :                 pViewShell->GetViewData()->GetMarkData().SetSelectedTabs(aOldTabs);
     553             :             }
     554             :         }
     555             :     }
     556             : 
     557           0 : }
     558             : 
     559             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10