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

Generated by: LCOV version 1.10