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

Generated by: LCOV version 1.10