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

Generated by: LCOV version 1.10