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

Generated by: LCOV version 1.10