LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbaworksheet.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 544 5.1 %
Date: 2012-12-17 Functions: 9 84 10.7 %
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             : 
      20             : #include <vbahelper/helperdecl.hxx>
      21             : #include <cppuhelper/queryinterface.hxx>
      22             : 
      23             : #include "vbaworksheet.hxx"
      24             : #include "vbanames.hxx"
      25             : 
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
      28             : #include <com/sun/star/beans/XIntrospection.hpp>
      29             : #include <com/sun/star/container/XNamed.hpp>
      30             : #include <com/sun/star/util/XProtectable.hpp>
      31             : #include <com/sun/star/table/XCellRange.hpp>
      32             : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
      33             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      34             : #include <com/sun/star/sheet/XCalculatable.hpp>
      35             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      36             : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      37             : #include <com/sun/star/sheet/XSheetCellRange.hpp>
      38             : #include <com/sun/star/sheet/XSheetCellCursor.hpp>
      39             : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
      40             : #include <com/sun/star/sheet/XUsedAreaCursor.hpp>
      41             : #include <com/sun/star/sheet/XSpreadsheets.hpp>
      42             : #include <com/sun/star/sheet/XSheetPastable.hpp>
      43             : #include <com/sun/star/sheet/XCellAddressable.hpp>
      44             : #include <com/sun/star/sheet/XSheetOutline.hpp>
      45             : #include <com/sun/star/sheet/XSheetPageBreak.hpp>
      46             : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
      47             : #include <com/sun/star/sheet/XNamedRanges.hpp>
      48             : #include <com/sun/star/util/XURLTransformer.hpp>
      49             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      50             : #include <com/sun/star/frame/XComponentLoader.hpp>
      51             : #include <com/sun/star/table/XColumnRowRange.hpp>
      52             : #include <com/sun/star/table/XTableChartsSupplier.hpp>
      53             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      54             : #include <com/sun/star/drawing/XControlShape.hpp>
      55             : #include <com/sun/star/form/FormComponentType.hpp>
      56             : #include <com/sun/star/form/XFormsSupplier.hpp>
      57             : #include <ooo/vba/excel/XlEnableSelection.hpp>
      58             : #include <ooo/vba/excel/XlSheetVisibility.hpp>
      59             : #include <ooo/vba/excel/XWorkbook.hpp>
      60             : #include <ooo/vba/XControlProvider.hpp>
      61             : 
      62             : #include <comphelper/processfactory.hxx>
      63             : #include <comphelper/servicehelper.hxx>
      64             : #include <vbahelper/vbashapes.hxx>
      65             : 
      66             : #include <com/sun/star/script/vba/VBAEventId.hpp>
      67             : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
      68             : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
      69             : #include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
      70             : #include <com/sun/star/script/ModuleInfo.hpp>
      71             : #include <com/sun/star/script/ModuleType.hpp>
      72             : 
      73             : #include <tools/string.hxx>
      74             : 
      75             : //zhangyun showdataform
      76             : #include <sfx2/sfxdlg.hxx>
      77             : #include "scabstdlg.hxx"
      78             : #include "tabvwsh.hxx"
      79             : #include "scitems.hxx"
      80             : 
      81             : #include <svx/svdouno.hxx>
      82             : #include <svx/svdpage.hxx>
      83             : 
      84             : #include "cellsuno.hxx"
      85             : #include "drwlayer.hxx"
      86             : #include "tabprotection.hxx"
      87             : #include "scextopt.hxx"
      88             : #include "vbaoutline.hxx"
      89             : #include "vbarange.hxx"
      90             : #include "vbacomments.hxx"
      91             : #include "vbachartobjects.hxx"
      92             : #include "vbapivottables.hxx"
      93             : #include "vbaoleobject.hxx"
      94             : #include "vbaoleobjects.hxx"
      95             : #include "vbapagesetup.hxx"
      96             : #include "vbapagebreaks.hxx"
      97             : #include "vbaworksheets.hxx"
      98             : #include "vbahyperlinks.hxx"
      99             : #include "vbasheetobjects.hxx"
     100             : #include "markdata.hxx"
     101             : #include "dbdata.hxx"
     102             : 
     103             : #include "attrib.hxx"
     104             : 
     105             : #define STANDARDWIDTH 2267
     106             : #define STANDARDHEIGHT 427
     107             : 
     108             : using namespace com::sun::star;
     109             : using namespace ooo::vba;
     110             : 
     111           0 : static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldName, uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc )
     112             : {
     113           0 :     if (!xSpreadDoc.is())
     114           0 :         throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getNewSpreadsheetName() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface  >(), 1 );
     115           0 :     static rtl::OUString aUnderScre( RTL_CONSTASCII_USTRINGPARAM( "_" ) );
     116           0 :     int currentNum =2;
     117           0 :     aNewName = aOldName + aUnderScre+ String::CreateFromInt32(currentNum) ;
     118           0 :     SCTAB nTab = 0;
     119           0 :     while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) )
     120             :     {
     121             :         aNewName = aOldName + aUnderScre +
     122           0 :         String::CreateFromInt32(++currentNum) ;
     123             :     }
     124           0 : }
     125             : 
     126           0 : static void removeAllSheets( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, rtl::OUString aSheetName)
     127             : {
     128           0 :     if (!xSpreadDoc.is())
     129           0 :         throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "removeAllSheets() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface  >(), 1 );
     130           0 :     uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     131           0 :     uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
     132             : 
     133           0 :     if ( xIndex.is() )
     134             :     {
     135           0 :         uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
     136           0 :         for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--)
     137             :         {
     138           0 :             uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY);
     139           0 :             uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
     140           0 :             if (xNamed.is())
     141             :             {
     142           0 :                 xNameContainer->removeByName(xNamed->getName());
     143             :             }
     144           0 :         }
     145             : 
     146           0 :         uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY);
     147           0 :         uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
     148           0 :         if (xNamed.is())
     149             :         {
     150           0 :             xNamed->setName(aSheetName);
     151           0 :         }
     152           0 :     }
     153           0 : }
     154             : 
     155             : static uno::Reference<frame::XModel>
     156           0 : openNewDoc(rtl::OUString aSheetName )
     157             : {
     158           0 :     uno::Reference<frame::XModel> xModel;
     159             :     try
     160             :     {
     161             :         uno::Reference< uno::XComponentContext > xContext(
     162           0 :             comphelper::getProcessComponentContext() );
     163             :         uno::Reference<lang::XMultiComponentFactory > xServiceManager(
     164           0 :             xContext->getServiceManager() );
     165             : 
     166             :         uno::Reference <frame::XComponentLoader > xComponentLoader(
     167           0 :                         xServiceManager->createInstanceWithContext(
     168             :                         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ),
     169           0 :                         xContext ), uno::UNO_QUERY_THROW );
     170             : 
     171           0 :         uno::Reference<lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL(
     172             :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ),
     173             :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0,
     174           0 :                 uno::Sequence < ::com::sun::star::beans::PropertyValue >() ) );
     175           0 :         uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xComponent, uno::UNO_QUERY_THROW );
     176           0 :         if ( xSpreadDoc.is() )
     177             :         {
     178           0 :             removeAllSheets(xSpreadDoc,aSheetName);
     179             :         }
     180           0 :         xModel.set(xSpreadDoc,uno::UNO_QUERY_THROW);
     181             :     }
     182           0 :     catch ( uno::Exception & /*e*/ )
     183             :     {
     184             :     }
     185           0 :     return xModel;
     186             : }
     187             : 
     188           0 : ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
     189             :         const uno::Reference< sheet::XSpreadsheet >& xSheet,
     190           0 :         const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false )
     191             : {
     192           0 : }
     193             : 
     194          12 : ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args,
     195          12 :     uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) :  WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false )
     196             : {
     197          12 :     if ( args.getLength() < 3 )
     198           0 :         throw lang::IllegalArgumentException();
     199             : 
     200          12 :     rtl::OUString sSheetName;
     201          12 :     args[2] >>= sSheetName;
     202             : 
     203          12 :     uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc( mxModel, uno::UNO_QUERY_THROW );
     204          12 :     uno::Reference< container::XNameAccess > xNameAccess( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
     205          12 :     mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW );
     206          12 : }
     207             : 
     208           0 : ScVbaWorksheet::~ScVbaWorksheet()
     209             : {
     210           0 : }
     211             : 
     212             : namespace
     213             : {
     214             :     class theScVbaWorksheetUnoTunnelId  : public rtl::Static< UnoTunnelIdInit, theScVbaWorksheetUnoTunnelId > {};
     215             : }
     216             : 
     217           0 : const uno::Sequence<sal_Int8>& ScVbaWorksheet::getUnoTunnelId()
     218             : {
     219           0 :     return theScVbaWorksheetUnoTunnelId::get().getSeq();
     220             : }
     221             : 
     222             : uno::Reference< ov::excel::XWorksheet >
     223           0 : ScVbaWorksheet::createSheetCopyInNewDoc(rtl::OUString aCurrSheetName)
     224             : {
     225           0 :     uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
     226           0 :     uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
     227           0 :     uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
     228           0 :     uno::Reference<excel::XRange> xRange =  new ScVbaRange( this, mxContext, xRange1);
     229           0 :     if (xRange.is())
     230           0 :         xRange->Select();
     231           0 :     excel::implnCopy(mxModel);
     232           0 :     uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
     233           0 :     if (xModel.is())
     234             :     {
     235           0 :         excel::implnPaste(xModel);
     236             :     }
     237           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
     238           0 :     excel::setUpDocumentModules(xSpreadDoc);
     239           0 :     uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
     240           0 :     uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
     241           0 :     uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
     242             : 
     243           0 :     ScDocShell* pShell = excel::getDocShell( xModel );
     244           0 :     rtl::OUString aCodeName;
     245           0 :     pShell->GetDocument()->GetCodeName( 0, aCodeName );
     246           0 :     return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW );
     247             : }
     248             : 
     249             : css::uno::Reference< ov::excel::XWorksheet >
     250           0 : ScVbaWorksheet::createSheetCopy(uno::Reference<excel::XWorksheet> xSheet, bool bAfter)
     251             : {
     252           0 :     rtl::OUString aCurrSheetName = getName();
     253           0 :     ScVbaWorksheet* pDestSheet = excel::getImplFromDocModuleWrapper<ScVbaWorksheet>( xSheet );
     254             : 
     255           0 :     uno::Reference <sheet::XSpreadsheetDocument> xDestDoc( pDestSheet->getModel(), uno::UNO_QUERY );
     256           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSrcDoc( getModel(), uno::UNO_QUERY );
     257             : 
     258           0 :     SCTAB nDest = 0;
     259           0 :     SCTAB nSrc = 0;
     260           0 :     rtl::OUString aSheetName = xSheet->getName();
     261           0 :     bool bSameDoc = ( pDestSheet->getModel() == getModel() );
     262           0 :     bool bDestSheetExists = ScVbaWorksheets::nameExists (xDestDoc, aSheetName, nDest );
     263           0 :     bool bSheetExists = ScVbaWorksheets::nameExists (xSrcDoc, aCurrSheetName, nSrc );
     264             : 
     265             :     // set sheet name to be newSheet name
     266           0 :     aSheetName = aCurrSheetName;
     267           0 :     if ( bSheetExists && bDestSheetExists )
     268             :     {
     269           0 :         SCTAB nDummy=0;
     270           0 :         if(bAfter)
     271           0 :               nDest++;
     272           0 :         uno::Reference<sheet::XSpreadsheets> xSheets = xDestDoc->getSheets();
     273           0 :         if ( bSameDoc || ScVbaWorksheets::nameExists( xDestDoc, aCurrSheetName, nDummy ) )
     274           0 :             getNewSpreadsheetName(aSheetName,aCurrSheetName,xDestDoc);
     275           0 :         if ( bSameDoc )
     276           0 :             xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
     277             :         else
     278             :         {
     279           0 :             ScDocShell* pDestDocShell = excel::getDocShell( pDestSheet->getModel() );
     280           0 :             ScDocShell* pSrcDocShell = excel::getDocShell( getModel() );
     281           0 :             if ( pDestDocShell && pSrcDocShell )
     282           0 :                 pDestDocShell->TransferTab( *pSrcDocShell, static_cast<SCTAB>(nSrc), static_cast<SCTAB>(nDest), true, true );
     283           0 :         }
     284             :     }
     285             :     // return new sheet
     286           0 :     uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
     287           0 :     uno::Reference< excel::XWorksheet > xNewSheet( xApplication->Worksheets( uno::makeAny( aSheetName ) ), uno::UNO_QUERY_THROW );
     288           0 :     return xNewSheet;
     289             : }
     290             : 
     291             : ::rtl::OUString
     292           0 : ScVbaWorksheet::getName() throw (uno::RuntimeException)
     293             : {
     294           0 :     uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
     295           0 :     return xNamed->getName();
     296             : }
     297             : 
     298             : void
     299           0 : ScVbaWorksheet::setName(const ::rtl::OUString &rName ) throw (uno::RuntimeException)
     300             : {
     301           0 :     uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
     302           0 :     xNamed->setName( rName );
     303           0 : }
     304             : 
     305             : sal_Int32
     306           0 : ScVbaWorksheet::getVisible() throw (uno::RuntimeException)
     307             : {
     308           0 :     uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
     309           0 :     bool bVisible = false;
     310           0 :     xProps->getPropertyValue( "IsVisible" ) >>= bVisible;
     311             :     using namespace ::ooo::vba::excel::XlSheetVisibility;
     312           0 :     return bVisible ? xlSheetVisible : (mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden);
     313             : }
     314             : 
     315             : void
     316           0 : ScVbaWorksheet::setVisible( sal_Int32 nVisible ) throw (uno::RuntimeException)
     317             : {
     318             :     using namespace ::ooo::vba::excel::XlSheetVisibility;
     319           0 :     bool bVisible = true;
     320           0 :     switch( nVisible )
     321             :     {
     322             :         case xlSheetVisible: case 1:  // Excel accepts -1 and 1 for visible sheets
     323           0 :             bVisible = true;
     324           0 :             mbVeryHidden = false;
     325           0 :         break;
     326             :         case xlSheetHidden:
     327           0 :             bVisible = false;
     328           0 :             mbVeryHidden = false;
     329           0 :         break;
     330             :         case xlSheetVeryHidden:
     331           0 :             bVisible = false;
     332           0 :             mbVeryHidden = true;
     333           0 :         break;
     334             :         default:
     335           0 :             throw uno::RuntimeException();
     336             :     }
     337           0 :     uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
     338           0 :     xProps->setPropertyValue( "IsVisible", uno::Any( bVisible ) );
     339           0 : }
     340             : 
     341             : sal_Int16
     342           6 : ScVbaWorksheet::getIndex() throw (uno::RuntimeException)
     343             : {
     344           6 :     return getSheetID() + 1;
     345             : }
     346             : 
     347             : sal_Int32
     348           0 : ScVbaWorksheet::getEnableSelection() throw (uno::RuntimeException)
     349             : {
     350           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
     351           0 :     SCTAB nTab = 0;
     352           0 :     if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
     353             :     {
     354           0 :         uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
     355           0 :         ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
     356           0 :         ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
     357           0 :         sal_Bool bLockedCells = false;
     358           0 :         sal_Bool bUnlockedCells = false;
     359           0 :         if( pProtect )
     360             :         {
     361           0 :             bLockedCells   = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
     362           0 :             bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
     363             :         }
     364           0 :         if( bLockedCells )
     365           0 :             return excel::XlEnableSelection::xlNoRestrictions;
     366           0 :         if( bUnlockedCells )
     367           0 :             return excel::XlEnableSelection::xlUnlockedCells;
     368           0 :         return excel::XlEnableSelection::xlNoSelection;
     369             :     }
     370             :     else
     371             :         throw uno::RuntimeException(::rtl::OUString(
     372             :                                 RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
     373           0 :                                 uno::Reference< XInterface >() );
     374             : }
     375             : 
     376             : 
     377             : void
     378           0 : ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection ) throw (uno::RuntimeException)
     379             : {
     380           0 :     if( (nSelection != excel::XlEnableSelection::xlNoRestrictions) &&
     381             :         (nSelection != excel::XlEnableSelection::xlUnlockedCells) &&
     382             :         (nSelection != excel::XlEnableSelection::xlNoSelection) )
     383             :     {
     384           0 :         DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
     385             :     }
     386             : 
     387           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
     388           0 :     SCTAB nTab = 0;
     389           0 :     if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
     390             :     {
     391           0 :         uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
     392           0 :         ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
     393           0 :         ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
     394             :         // default is xlNoSelection
     395           0 :         sal_Bool bLockedCells = false;
     396           0 :         sal_Bool bUnlockedCells = false;
     397           0 :         if( nSelection == excel::XlEnableSelection::xlNoRestrictions )
     398             :         {
     399           0 :             bLockedCells = sal_True;
     400           0 :             bUnlockedCells = sal_True;
     401             :         }
     402           0 :         else if( nSelection == excel::XlEnableSelection::xlUnlockedCells )
     403             :         {
     404           0 :             bUnlockedCells = sal_True;
     405             :         }
     406           0 :         if( pProtect )
     407             :         {
     408           0 :             pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells );
     409           0 :             pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells );
     410           0 :         }
     411             :     }
     412             :     else
     413             :         throw uno::RuntimeException(::rtl::OUString(
     414             :                                 RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
     415           0 :                                 uno::Reference< XInterface >() );
     416             : 
     417           0 : }
     418             : 
     419           0 : sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() throw (uno::RuntimeException)
     420             : {
     421           0 :     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
     422           0 :     ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
     423           0 :     ScDBData* pDBData = pDoc->GetAnonymousDBData(getSheetID());
     424           0 :     if (pDBData)
     425           0 :         return pDBData->HasAutoFilter();
     426           0 :     return false;
     427             : }
     428             : 
     429           0 : void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) throw (uno::RuntimeException)
     430             : {
     431           0 :     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
     432           0 :     ScDocShell* pDocShell = excel::getDocShell( xModel );
     433           0 :     ScDocument* pDoc = pDocShell->GetDocument();
     434           0 :     ScDBData* pDBData = pDoc->GetAnonymousDBData(getSheetID());
     435           0 :     if (pDBData)
     436             :     {
     437           0 :         pDBData->SetAutoFilter(bAutoFilterMode);
     438           0 :         ScRange aRange;
     439           0 :         pDBData->GetArea(aRange);
     440           0 :         if (bAutoFilterMode && pDoc)
     441           0 :             pDoc->ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(),
     442           0 :                                     aRange.aEnd.Col(), aRange.aStart.Row(),
     443           0 :                                     aRange.aStart.Tab(), SC_MF_AUTO );
     444           0 :         else  if (!bAutoFilterMode && pDoc)
     445           0 :             pDoc->RemoveFlagsTab(aRange.aStart.Col(), aRange.aStart.Row(),
     446           0 :                                     aRange.aEnd.Col(), aRange.aStart.Row(),
     447           0 :                                     aRange.aStart.Tab(), SC_MF_AUTO );
     448           0 :         ScRange aPaintRange(aRange.aStart, aRange.aEnd);
     449           0 :         aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row());
     450           0 :         pDocShell->PostPaint(aPaintRange, PAINT_GRID);
     451           0 :     }
     452           0 : }
     453             : 
     454             : uno::Reference< excel::XRange >
     455           0 : ScVbaWorksheet::getUsedRange() throw (uno::RuntimeException)
     456             : {
     457           0 :      uno::Reference< sheet::XSheetCellRange > xSheetCellRange(getSheet(), uno::UNO_QUERY_THROW );
     458           0 :     uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor( getSheet()->createCursorByRange( xSheetCellRange ), uno::UNO_QUERY_THROW );
     459           0 :     uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
     460           0 :     xUsedCursor->gotoStartOfUsedArea( false );
     461           0 :     xUsedCursor->gotoEndOfUsedArea( true );
     462           0 :     uno::Reference< table::XCellRange > xRange( xSheetCellCursor, uno::UNO_QUERY);
     463           0 :     return new ScVbaRange(this, mxContext, xRange);
     464             : }
     465             : 
     466             : uno::Reference< excel::XOutline >
     467           0 : ScVbaWorksheet::Outline( ) throw (uno::RuntimeException)
     468             : {
     469           0 :     uno::Reference<sheet::XSheetOutline> xOutline(getSheet(),uno::UNO_QUERY_THROW);
     470           0 :     return new ScVbaOutline( this, mxContext, xOutline);
     471             : }
     472             : 
     473             : uno::Reference< excel::XPageSetup >
     474           0 : ScVbaWorksheet::PageSetup( ) throw (uno::RuntimeException)
     475             : {
     476           0 :     return new ScVbaPageSetup( this, mxContext, getSheet(), getModel() );
     477             : }
     478             : 
     479             : uno::Any
     480           0 : ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex ) throw (uno::RuntimeException)
     481             : {
     482           0 :     uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(getSheet(),uno::UNO_QUERY_THROW);
     483           0 :     uno::Reference< excel::XHPageBreaks > xHPageBreaks( new ScVbaHPageBreaks( this, mxContext, xSheetPageBreak));
     484           0 :    if ( aIndex.hasValue() )
     485           0 :       return xHPageBreaks->Item( aIndex, uno::Any());
     486           0 :    return uno::makeAny( xHPageBreaks );
     487             : }
     488             : 
     489             : uno::Any
     490           0 : ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex ) throw ( uno::RuntimeException )
     491             : {
     492           0 :     uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak( getSheet(), uno::UNO_QUERY_THROW );
     493           0 :     uno::Reference< excel::XVPageBreaks > xVPageBreaks( new ScVbaVPageBreaks( this, mxContext, xSheetPageBreak ) );
     494           0 :     if( aIndex.hasValue() )
     495           0 :         return xVPageBreaks->Item( aIndex, uno::Any());
     496           0 :     return uno::makeAny( xVPageBreaks );
     497             : }
     498             : 
     499             : sal_Int32
     500           0 : ScVbaWorksheet::getStandardWidth() throw (uno::RuntimeException)
     501             : {
     502           0 :     return STANDARDWIDTH ;
     503             : }
     504             : 
     505             : sal_Int32
     506           0 : ScVbaWorksheet::getStandardHeight() throw (uno::RuntimeException)
     507             : {
     508           0 :     return STANDARDHEIGHT;
     509             : }
     510             : 
     511             : sal_Bool
     512           0 : ScVbaWorksheet::getProtectionMode() throw (uno::RuntimeException)
     513             : {
     514           0 :     return false;
     515             : }
     516             : 
     517             : sal_Bool
     518           0 : ScVbaWorksheet::getProtectContents()throw (uno::RuntimeException)
     519             : {
     520           0 :     uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
     521           0 :     return xProtectable->isProtected();
     522             : }
     523             : 
     524             : sal_Bool
     525           0 : ScVbaWorksheet::getProtectDrawingObjects() throw (uno::RuntimeException)
     526             : {
     527           0 :     SCTAB nTab = 0;
     528           0 :     rtl::OUString aSheetName = getName();
     529           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
     530           0 :     bool bSheetExists = ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nTab);
     531           0 :     if ( bSheetExists )
     532             :     {
     533           0 :         uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
     534           0 :         ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
     535           0 :         ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
     536           0 :         if ( pProtect )
     537           0 :             return pProtect->isOptionEnabled( ScTableProtection::OBJECTS );
     538             :     }
     539           0 :     return false;
     540             : }
     541             : 
     542             : sal_Bool
     543           0 : ScVbaWorksheet::getProtectScenarios() throw (uno::RuntimeException)
     544             : {
     545           0 :     return false;
     546             : }
     547             : 
     548             : void
     549           0 : ScVbaWorksheet::Activate() throw (uno::RuntimeException)
     550             : {
     551             :     uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
     552           0 :             getModel()->getCurrentController(), uno::UNO_QUERY_THROW );
     553           0 :     xSpreadsheet->setActiveSheet(getSheet());
     554           0 : }
     555             : 
     556             : void
     557           0 : ScVbaWorksheet::Select() throw (uno::RuntimeException)
     558             : {
     559           0 :     Activate();
     560           0 : }
     561             : 
     562             : void
     563           0 : ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException)
     564             : {
     565           0 :     uno::Reference<excel::XWorksheet> xSheet;
     566           0 :     rtl::OUString aCurrSheetName = getName();
     567             : 
     568           0 :     if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
     569             :     {
     570           0 :         uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
     571           0 :         uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
     572           0 :             uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
     573             :         // #FIXME needs worksheet as parent
     574           0 :         uno::Reference<excel::XRange> xRange =  new ScVbaRange( this, mxContext, xRange1);
     575           0 :         if (xRange.is())
     576           0 :             xRange->Select();
     577           0 :         excel::implnCopy(mxModel);
     578           0 :         uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
     579           0 :         if (xModel.is())
     580             :         {
     581           0 :             excel::implnPaste(xModel);
     582           0 :             Delete();
     583             :         }
     584           0 :         return ;
     585             :     }
     586             : 
     587           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
     588           0 :     SCTAB nDest = 0;
     589           0 :     if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) )
     590             :     {
     591           0 :         sal_Bool bAfter = After.hasValue();
     592           0 :         if (bAfter)
     593           0 :             nDest++;
     594           0 :         uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     595           0 :         xSheets->moveByName(aCurrSheetName,nDest);
     596           0 :     }
     597             : }
     598             : 
     599             : void
     600           0 : ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException)
     601             : {
     602           0 :     uno::Reference<excel::XWorksheet> xSheet;
     603           0 :     if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
     604             :     {
     605           0 :         createSheetCopyInNewDoc(getName());
     606           0 :         return;
     607             :     }
     608             : 
     609           0 :     uno::Reference<excel::XWorksheet> xNewSheet = createSheetCopy(xSheet, After.hasValue());
     610           0 :     xNewSheet->Activate();
     611             : }
     612             : 
     613             : 
     614             : void
     615           0 : ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ ) throw (uno::RuntimeException)
     616             : {
     617             :     // #TODO# #FIXME# Link is not used
     618           0 :     uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
     619           0 :     if ( xRange.is() )
     620           0 :         xRange->Select();
     621           0 :     excel::implnPaste( mxModel );
     622           0 : }
     623             : 
     624             : void
     625           0 : ScVbaWorksheet::Delete() throw (uno::RuntimeException)
     626             : {
     627           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
     628           0 :     rtl::OUString aSheetName = getName();
     629           0 :     if ( xSpreadDoc.is() )
     630             :     {
     631           0 :         SCTAB nTab = 0;
     632           0 :         if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab ))
     633             :         {
     634           0 :             return;
     635             :         }
     636           0 :         uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
     637           0 :         uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
     638           0 :         xNameContainer->removeByName(aSheetName);
     639           0 :         mxSheet.clear();
     640           0 :     }
     641             : }
     642             : 
     643             : uno::Reference< excel::XWorksheet >
     644           0 : ScVbaWorksheet::getSheetAtOffset(SCTAB offset) throw (uno::RuntimeException)
     645             : {
     646           0 :     uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
     647           0 :     uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
     648           0 :     uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
     649             : 
     650           0 :     SCTAB nIdx = 0;
     651           0 :     if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) )
     652           0 :         return uno::Reference< excel::XWorksheet >();
     653           0 :     nIdx = nIdx + offset;
     654           0 :     uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW);
     655             :     // parent will be the parent of 'this' worksheet
     656           0 :     return new ScVbaWorksheet (getParent(), mxContext, xSheet, getModel());
     657             : }
     658             : 
     659             : uno::Reference< excel::XWorksheet >
     660           0 : ScVbaWorksheet::getNext() throw (uno::RuntimeException)
     661             : {
     662           0 :     return getSheetAtOffset(static_cast<SCTAB>(1));
     663             : }
     664             : 
     665             : uno::Reference< excel::XWorksheet >
     666           0 : ScVbaWorksheet::getPrevious() throw (uno::RuntimeException)
     667             : {
     668           0 :     return getSheetAtOffset(-1);
     669             : }
     670             : 
     671             : 
     672             : void
     673           0 : ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObjects*/, const uno::Any& /*Contents*/, const uno::Any& /*Scenarios*/, const uno::Any& /*UserInterfaceOnly*/ ) throw (uno::RuntimeException)
     674             : {
     675             :     // #TODO# #FIXME# is there anything we can do witht the unused param
     676             :     // can the implementation use anything else here
     677           0 :     uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
     678           0 :     ::rtl::OUString aPasswd;
     679           0 :     Password >>= aPasswd;
     680           0 :     xProtectable->protect( aPasswd );
     681           0 : }
     682             : 
     683             : void
     684           0 : ScVbaWorksheet::Unprotect( const uno::Any& Password ) throw (uno::RuntimeException)
     685             : {
     686           0 :     uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
     687           0 :     ::rtl::OUString aPasswd;
     688           0 :     Password >>= aPasswd;
     689           0 :     xProtectable->unprotect( aPasswd );
     690           0 : }
     691             : 
     692             : void
     693           0 : ScVbaWorksheet::Calculate() throw (uno::RuntimeException)
     694             : {
     695           0 :     uno::Reference <sheet::XCalculatable> xReCalculate(getModel(), uno::UNO_QUERY_THROW);
     696           0 :     xReCalculate->calculate();
     697           0 : }
     698             : 
     699             : uno::Reference< excel::XRange >
     700          20 : ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 ) throw (uno::RuntimeException)
     701             : {
     702             :     uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext
     703          20 : , uno::Reference< table::XCellRange >( getSheet(), uno::UNO_QUERY_THROW ) ) );
     704          20 :     return xSheetRange->Range( Cell1, Cell2 );
     705             : }
     706             : 
     707             : void
     708           0 : ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::Any& /*IgnoreUppercase*/,const uno::Any& /*AlwaysSuggest*/, const uno::Any& /*SpellingLang*/ ) throw (uno::RuntimeException)
     709             : {
     710             :     // #TODO# #FIXME# unused params above, can we do anything with those
     711           0 :     rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SpellDialog"));
     712           0 :     uno::Reference< frame::XModel > xModel( getModel() );
     713           0 :     dispatchRequests(xModel,url);
     714           0 : }
     715             : 
     716             : uno::Reference< excel::XRange >
     717          12 : ScVbaWorksheet::getSheetRange() throw (uno::RuntimeException)
     718             : {
     719          12 :     uno::Reference< table::XCellRange > xRange( getSheet(),uno::UNO_QUERY_THROW );
     720          12 :     return uno::Reference< excel::XRange >( new ScVbaRange( this, mxContext, xRange ) );
     721             : }
     722             : 
     723             : // These are hacks - we prolly (somehow) need to inherit
     724             : // the vbarange functionality here ...
     725             : uno::Reference< excel::XRange >
     726           2 : ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol )
     727             :         throw (uno::RuntimeException)
     728             : {
     729             :     // Performance optimization for often-called Cells method:
     730             :     // Use a common helper method instead of creating a new ScVbaRange object
     731           2 :     uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW );
     732           2 :     return ScVbaRange::CellsHelper( this, mxContext, xRange, nRow, nCol );
     733             : }
     734             : 
     735             : uno::Reference< excel::XRange >
     736           0 : ScVbaWorksheet::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException)
     737             : {
     738           0 :     return getSheetRange()->Rows( aIndex );
     739             : }
     740             : 
     741             : uno::Reference< excel::XRange >
     742          12 : ScVbaWorksheet::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException)
     743             : {
     744          12 :     return getSheetRange()->Columns( aIndex );
     745             : }
     746             : 
     747             : uno::Any SAL_CALL
     748           0 : ScVbaWorksheet::ChartObjects( const uno::Any& Index ) throw (uno::RuntimeException)
     749             : {
     750           0 :     if ( !mxCharts.is() )
     751             :     {
     752           0 :         uno::Reference< table::XTableChartsSupplier > xChartSupplier( getSheet(), uno::UNO_QUERY_THROW );
     753           0 :         uno::Reference< table::XTableCharts > xTableCharts = xChartSupplier->getCharts();
     754             : 
     755           0 :         uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxSheet, uno::UNO_QUERY_THROW );
     756           0 :         mxCharts = new ScVbaChartObjects(  this, mxContext, xTableCharts, xDrawPageSupplier );
     757             :     }
     758           0 :     if ( Index.hasValue() )
     759             :     {
     760           0 :         uno::Reference< XCollection > xColl( mxCharts, uno::UNO_QUERY_THROW );
     761           0 :         return xColl->Item( Index, uno::Any() );
     762             :     }
     763             :     else
     764           0 :         return uno::makeAny( mxCharts );
     765             : 
     766             : }
     767             : 
     768             : uno::Any SAL_CALL
     769           0 : ScVbaWorksheet::PivotTables( const uno::Any& Index ) throw (uno::RuntimeException)
     770             : {
     771           0 :     uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
     772           0 :     uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
     773           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
     774             : 
     775           0 :     uno::Reference< XCollection > xColl(  new ScVbaPivotTables( this, mxContext, xIndexAccess ) );
     776           0 :     if ( Index.hasValue() )
     777           0 :         return xColl->Item( Index, uno::Any() );
     778           0 :     return uno::makeAny( xColl );
     779             : }
     780             : 
     781             : uno::Any SAL_CALL
     782           0 : ScVbaWorksheet::Comments( const uno::Any& Index ) throw (uno::RuntimeException)
     783             : {
     784           0 :     uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
     785           0 :     uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
     786           0 :     uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
     787           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xAnnos, uno::UNO_QUERY_THROW );
     788           0 :     uno::Reference< XCollection > xColl(  new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) );
     789           0 :     if ( Index.hasValue() )
     790           0 :         return xColl->Item( Index, uno::Any() );
     791           0 :     return uno::makeAny( xColl );
     792             : }
     793             : 
     794             : uno::Any SAL_CALL
     795           0 : ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException)
     796             : {
     797             :     /*  The worksheet always returns the same Hyperlinks object.
     798             :         See vbahyperlinks.hxx for more details. */
     799           0 :     if( !mxHlinks.is() )
     800           0 :         mxHlinks.set( new ScVbaHyperlinks( this, mxContext ) );
     801           0 :     if( aIndex.hasValue() )
     802           0 :         return uno::Reference< XCollection >( mxHlinks, uno::UNO_QUERY_THROW )->Item( aIndex, uno::Any() );
     803           0 :     return uno::Any( mxHlinks );
     804             : }
     805             : 
     806             : uno::Any SAL_CALL
     807           0 : ScVbaWorksheet::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException)
     808             : {
     809             :     // fake sheet-local names by returning all global names
     810             :     // #163498# initialize Names object with correct parent (this worksheet)
     811             :     // TODO: real sheet-local names...
     812           0 :     uno::Reference< beans::XPropertySet > xProps( mxModel, uno::UNO_QUERY_THROW );
     813           0 :     uno::Reference< sheet::XNamedRanges > xNamedRanges(  xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
     814           0 :     uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, mxModel ) );
     815           0 :     if ( aIndex.hasValue() )
     816           0 :         return uno::Any( xNames->Item( aIndex, uno::Any() ) );
     817           0 :     return uno::Any( xNames );
     818             : }
     819             : 
     820             : uno::Any SAL_CALL
     821           0 : ScVbaWorksheet::OLEObjects( const uno::Any& Index ) throw (uno::RuntimeException)
     822             : {
     823           0 :     uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
     824           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
     825           0 :     uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
     826           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPage, uno::UNO_QUERY_THROW );
     827             : 
     828           0 :     uno::Reference< excel::XOLEObjects >xOleObjects( new ScVbaOLEObjects( this, mxContext, xIndexAccess ) );
     829           0 :     if( Index.hasValue() )
     830           0 :         return xOleObjects->Item( Index, uno::Any() );
     831           0 :     return uno::Any( xOleObjects );
     832             : }
     833             : 
     834             : uno::Any SAL_CALL
     835           0 : ScVbaWorksheet::Shapes( const uno::Any& aIndex ) throw (uno::RuntimeException)
     836             : {
     837           0 :     uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
     838           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
     839           0 :     uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
     840           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
     841             : 
     842           0 :    uno::Reference< msforms::XShapes> xVbaShapes( new ScVbaShapes( this, mxContext, xIndexAccess, getModel() ) );
     843           0 :    if ( aIndex.hasValue() )
     844           0 :       return xVbaShapes->Item( aIndex, uno::Any() );
     845           0 :    return uno::makeAny( xVbaShapes );
     846             : }
     847             : 
     848             : uno::Any SAL_CALL
     849           0 : ScVbaWorksheet::Buttons( const uno::Any& rIndex ) throw (uno::RuntimeException)
     850             : {
     851           0 :     if( !mxButtons.is() )
     852           0 :         mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
     853             :     else
     854           0 :         mxButtons->collectShapes();
     855           0 :     if( rIndex.hasValue() )
     856           0 :         return mxButtons->Item( rIndex, uno::Any() );
     857           0 :     return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
     858             : }
     859             : 
     860             : uno::Any SAL_CALL
     861           0 : ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     862             : {
     863           0 :     throw uno::RuntimeException();
     864             : }
     865             : 
     866             : uno::Any SAL_CALL
     867           0 : ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     868             : {
     869           0 :     throw uno::RuntimeException();
     870             : }
     871             : 
     872             : uno::Any SAL_CALL
     873           0 : ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     874             : {
     875           0 :     throw uno::RuntimeException();
     876             : }
     877             : 
     878             : uno::Any SAL_CALL
     879           0 : ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     880             : {
     881           0 :     throw uno::RuntimeException();
     882             : }
     883             : 
     884             : uno::Any SAL_CALL
     885           0 : ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     886             : {
     887           0 :     throw uno::RuntimeException();
     888             : }
     889             : 
     890             : uno::Any SAL_CALL
     891           0 : ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     892             : {
     893           0 :     throw uno::RuntimeException();
     894             : }
     895             : 
     896             : uno::Any SAL_CALL
     897           0 : ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     898             : {
     899           0 :     throw uno::RuntimeException();
     900             : }
     901             : 
     902             : uno::Any SAL_CALL
     903           0 : ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException)
     904             : {
     905           0 :     throw uno::RuntimeException();
     906             : }
     907             : 
     908             : void SAL_CALL
     909           0 : ScVbaWorksheet::ShowDataForm( ) throw (uno::RuntimeException)
     910             : {
     911           0 :     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
     912           0 :     ScTabViewShell* pTabViewShell = excel::getBestViewShell( xModel );
     913             : 
     914           0 :     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     915             :     OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
     916             : 
     917           0 :     AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg( pTabViewShell->GetDialogParent(),RID_SCDLG_DATAFORM, pTabViewShell);
     918             :     OSL_ENSURE(pDlg, "Dialog create fail!");
     919             : 
     920           0 :     pDlg->Execute();
     921           0 : }
     922             : 
     923             : uno::Any SAL_CALL
     924           0 : ScVbaWorksheet::Evaluate( const ::rtl::OUString& Name ) throw (uno::RuntimeException)
     925             : {
     926             :     // #TODO Evaluate allows other things to be evaluated, e.g. functions
     927             :     // I think ( like SIN(3) etc. ) need to investigate that
     928             :     // named Ranges also? e.g. [MyRange] if so need a list of named ranges
     929           0 :     uno::Any aVoid;
     930           0 :     return uno::Any( Range( uno::Any( Name ), aVoid ) );
     931             : }
     932             : 
     933             : 
     934             : uno::Reference< beans::XIntrospectionAccess > SAL_CALL
     935           0 : ScVbaWorksheet::getIntrospection(  ) throw (uno::RuntimeException)
     936             : {
     937           0 :     return uno::Reference< beans::XIntrospectionAccess >();
     938             : }
     939             : 
     940             : uno::Any SAL_CALL
     941           0 : ScVbaWorksheet::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
     942             : {
     943             :     OSL_TRACE("** ScVbaWorksheet::invoke( %s ), will barf",
     944             :         rtl::OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
     945             : 
     946           0 :     throw uno::RuntimeException(); // unsupported operation
     947             : }
     948             : 
     949             : void SAL_CALL
     950           0 : ScVbaWorksheet::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
     951             : {
     952           0 :     setDefaultPropByIntrospection( uno::makeAny( getValue( aPropertyName ) ), aValue );
     953           0 : }
     954             : uno::Any SAL_CALL
     955           0 : ScVbaWorksheet::getValue( const ::rtl::OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException)
     956             : {
     957           0 :     uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
     958             : 
     959           0 :     uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
     960           0 :     uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW );
     961           0 :     uno::Reference< msforms::XControl > xControl( xControlProvider->createControl(  xControlShape, getModel() ) );
     962           0 :     return uno::makeAny( xControl );
     963             : }
     964             : 
     965             : ::sal_Bool SAL_CALL
     966           0 : ScVbaWorksheet::hasMethod( const ::rtl::OUString& /*aName*/ ) throw (uno::RuntimeException)
     967             : {
     968           0 :     return false;
     969             : }
     970             : 
     971             : uno::Reference< container::XNameAccess >
     972           0 : ScVbaWorksheet::getFormControls()
     973             : {
     974           0 :     uno::Reference< container::XNameAccess > xFormControls;
     975             :     try
     976             :     {
     977           0 :         uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
     978           0 :         uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
     979           0 :         uno::Reference< form::XFormsSupplier >  xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
     980           0 :             uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
     981             :         // get the www-standard container ( maybe we should access the
     982             :         // 'www-standard' by name rather than index, this seems an
     983             :         // implementation detail
     984           0 :         if( xIndexAccess->hasElements() )
     985           0 :             xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
     986             : 
     987             :     }
     988           0 :     catch( uno::Exception& )
     989             :     {
     990             :     }
     991           0 :     return xFormControls;
     992             : 
     993             :                 }
     994             : ::sal_Bool SAL_CALL
     995           0 : ScVbaWorksheet::hasProperty( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
     996             : {
     997           0 :     uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
     998           0 :     if ( xFormControls.is() )
     999           0 :         return xFormControls->hasByName( aName );
    1000           0 :     return false;
    1001             : }
    1002             : 
    1003             : uno::Any
    1004           0 : ScVbaWorksheet::getControlShape( const ::rtl::OUString& sName )
    1005             : {
    1006             :     // ideally we would get an XControl object but it appears an XControl
    1007             :     // implementation only exists for a Control implementation optained from the
    1008             :     // view ( e.g. in basic you would get this from
    1009             :     // thiscomponent.currentcontroller.getControl( controlModel ) )
    1010             :     // and the thing to realise is that it is only possible to get an XControl
    1011             :     // for a currently displayed control :-( often we would want to modify
    1012             :     // a control not on the active sheet. But.. you can always access the
    1013             :     // XControlShape from the DrawPage whether that is the active drawpage or not
    1014             : 
    1015           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getSheet(), uno::UNO_QUERY_THROW );
    1016           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
    1017             : 
    1018           0 :     sal_Int32 nCount = xIndexAccess->getCount();
    1019           0 :     for( int index = 0; index < nCount; index++ )
    1020             :     {
    1021           0 :         uno::Any aUnoObj =  xIndexAccess->getByIndex( index );
    1022             :          // It seems there are some drawing objects that can not query into Control shapes?
    1023           0 :         uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
    1024           0 :          if( xControlShape.is() )
    1025             :          {
    1026           0 :              uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
    1027           0 :         if( sName.equals( xNamed->getName() ))
    1028             :         {
    1029           0 :             return aUnoObj;
    1030           0 :         }
    1031             :          }
    1032           0 :     }
    1033           0 :     return uno::Any();
    1034             : }
    1035             : 
    1036             : 
    1037             : rtl::OUString
    1038           0 : ScVbaWorksheet::getServiceImplName()
    1039             : {
    1040           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaWorksheet"));
    1041             : }
    1042             : 
    1043             : void SAL_CALL
    1044           0 : ScVbaWorksheet::setEnableCalculation( ::sal_Bool bEnableCalculation ) throw ( script::BasicErrorException, uno::RuntimeException)
    1045             : {
    1046           0 :     uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
    1047           0 :         xCalculatable->enableAutomaticCalculation( bEnableCalculation);
    1048           0 : }
    1049             : ::sal_Bool SAL_CALL
    1050           0 : ScVbaWorksheet::getEnableCalculation(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
    1051             : {
    1052           0 :     uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
    1053           0 :     return xCalculatable->isAutomaticCalculationEnabled();
    1054             : }
    1055             : 
    1056             : uno::Sequence< rtl::OUString >
    1057           0 : ScVbaWorksheet::getServiceNames()
    1058             : {
    1059           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
    1060           0 :     if ( aServiceNames.getLength() == 0 )
    1061             :     {
    1062           0 :         aServiceNames.realloc( 1 );
    1063           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheet" ) );
    1064             :     }
    1065           0 :     return aServiceNames;
    1066             : }
    1067             : 
    1068             : rtl::OUString SAL_CALL
    1069           0 : ScVbaWorksheet::getCodeName() throw (css::uno::RuntimeException)
    1070             : {
    1071           0 :     uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW );
    1072           0 :     return xSheetProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >();
    1073             : }
    1074             : 
    1075             : sal_Int16
    1076           6 : ScVbaWorksheet::getSheetID() throw (uno::RuntimeException)
    1077             : {
    1078           6 :     uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxSheet, uno::UNO_QUERY_THROW ); // if ActiveSheet, mxSheet is null.
    1079           6 :     return xAddressable->getRangeAddress().Sheet;
    1080             : }
    1081             : 
    1082             : void SAL_CALL
    1083           0 : ScVbaWorksheet::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, const uno::Any& IgnorePrintAreas ) throw (uno::RuntimeException)
    1084             : {
    1085           0 :     sal_Int32 nTo = 0;
    1086           0 :     sal_Int32 nFrom = 0;
    1087           0 :     sal_Int16 nCopies = 1;
    1088           0 :     sal_Bool bCollate = false;
    1089           0 :     sal_Bool bSelection = false;
    1090           0 :     sal_Bool bIgnorePrintAreas = false;
    1091           0 :     From >>= nFrom;
    1092           0 :     To >>= nTo;
    1093           0 :     Copies >>= nCopies;
    1094           0 :     IgnorePrintAreas >>= bIgnorePrintAreas;
    1095           0 :     if ( nCopies > 1 ) // Collate only useful when more that 1 copy
    1096           0 :         Collate >>= bCollate;
    1097             : 
    1098           0 :     if ( !( nFrom || nTo ) )
    1099           0 :         bSelection = sal_True;
    1100             : 
    1101           0 :     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
    1102           0 :     PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection );
    1103           0 : }
    1104             : 
    1105             : sal_Int64 SAL_CALL
    1106           0 : ScVbaWorksheet::getSomething(const uno::Sequence<sal_Int8 > & rId) throw(uno::RuntimeException)
    1107             : {
    1108           0 :     if (rId.getLength() == 16 &&
    1109           0 :         0 == memcmp( ScVbaWorksheet::getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ))
    1110             :     {
    1111           0 :         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
    1112             :     }
    1113           0 :     return 0;
    1114             : }
    1115             : 
    1116             : namespace worksheet
    1117             : {
    1118             : namespace sdecl = comphelper::service_decl;
    1119           2 : sdecl::vba_service_class_<ScVbaWorksheet, sdecl::with_args<true> > serviceImpl;
    1120           2 : extern sdecl::ServiceDecl const serviceDecl(
    1121             :     serviceImpl,
    1122             :     "ScVbaWorksheet",
    1123             :     "ooo.vba.excel.Worksheet" );
    1124           6 : }
    1125             : 
    1126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10