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

Generated by: LCOV version 1.11