2010-10-12 15:59:00 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-11-30 12:23:25 +00:00
/*
* This file is part of the LibreOffice project .
2007-04-25 15:14:08 +00:00
*
2012-11-30 12:23:25 +00:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
2007-04-25 15:14:08 +00:00
*
2012-11-30 12:23:25 +00:00
* This file incorporates work covered by the following license notice :
2007-04-25 15:14:08 +00:00
*
2012-11-30 12:23:25 +00:00
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2010-06-15 20:02:53 +02:00
2009-09-18 15:24:22 +00:00
# include <vbahelper/helperdecl.hxx>
2007-04-25 15:14:08 +00:00
# include <cppuhelper/queryinterface.hxx>
2010-06-15 20:02:53 +02:00
# include "vbaworksheet.hxx"
2011-03-15 09:56:18 +00:00
# include "vbanames.hxx"
2010-06-15 20:02:53 +02:00
2007-04-25 15:14:08 +00:00
# include <com/sun/star/beans/XPropertySet.hpp>
# include <com/sun/star/beans/XIntrospectionAccess.hpp>
2009-09-18 15:24:22 +00:00
# include <com/sun/star/beans/XIntrospection.hpp>
2007-04-25 15:14:08 +00:00
# include <com/sun/star/container/XNamed.hpp>
# include <com/sun/star/util/XProtectable.hpp>
# include <com/sun/star/table/XCellRange.hpp>
# include <com/sun/star/sheet/XSpreadsheetView.hpp>
# include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
# include <com/sun/star/sheet/XCalculatable.hpp>
# include <com/sun/star/sheet/XCellRangeAddressable.hpp>
2010-08-04 18:13:02 +02:00
# include <com/sun/star/sheet/XCellRangeReferrer.hpp>
2007-04-25 15:14:08 +00:00
# include <com/sun/star/sheet/XSheetCellRange.hpp>
# include <com/sun/star/sheet/XSheetCellCursor.hpp>
# include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
# include <com/sun/star/sheet/XUsedAreaCursor.hpp>
# include <com/sun/star/sheet/XSpreadsheets.hpp>
# include <com/sun/star/sheet/XSheetPastable.hpp>
# include <com/sun/star/sheet/XCellAddressable.hpp>
# include <com/sun/star/sheet/XSheetOutline.hpp>
2009-02-13 13:03:24 +00:00
# include <com/sun/star/sheet/XSheetPageBreak.hpp>
2007-04-25 15:14:08 +00:00
# include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
2010-09-01 10:26:59 +02:00
# include <com/sun/star/sheet/XNamedRanges.hpp>
2007-04-25 15:14:08 +00:00
# include <com/sun/star/util/XURLTransformer.hpp>
# include <com/sun/star/frame/XDispatchProvider.hpp>
2012-12-14 12:58:00 +02:00
# include <com/sun/star/frame/Desktop.hpp>
2007-04-25 15:14:08 +00:00
# include <com/sun/star/table/XColumnRowRange.hpp>
# include <com/sun/star/table/XTableChartsSupplier.hpp>
# include <com/sun/star/drawing/XDrawPageSupplier.hpp>
# include <com/sun/star/drawing/XControlShape.hpp>
# include <com/sun/star/form/FormComponentType.hpp>
2009-02-13 13:03:24 +00:00
# include <com/sun/star/form/XFormsSupplier.hpp>
2009-09-18 15:24:22 +00:00
# include <ooo/vba/excel/XlEnableSelection.hpp>
2010-08-26 14:15:19 +02:00
# include <ooo/vba/excel/XlSheetVisibility.hpp>
2010-07-30 17:28:42 +02:00
# include <ooo/vba/excel/XWorkbook.hpp>
2009-09-18 15:24:22 +00:00
# include <ooo/vba/XControlProvider.hpp>
2007-12-07 10:06:55 +00:00
# include <comphelper/processfactory.hxx>
2011-06-02 22:57:57 +01:00
# include <comphelper/servicehelper.hxx>
2010-06-15 20:02:53 +02:00
# include <vbahelper/vbashapes.hxx>
2007-12-07 10:06:55 +00:00
2011-04-26 09:32:22 +01:00
# include <com/sun/star/script/vba/VBAEventId.hpp>
# include <com/sun/star/script/vba/XVBACompatibility.hpp>
# include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
# include <com/sun/star/script/vba/XVBAModuleInfo.hpp>
# include <com/sun/star/script/ModuleInfo.hpp>
# include <com/sun/star/script/ModuleType.hpp>
2007-04-25 15:14:08 +00:00
# include <tools/string.hxx>
2007-12-07 10:06:55 +00:00
//zhangyun showdataform
# include <sfx2/sfxdlg.hxx>
2010-06-15 20:02:53 +02:00
# include "scabstdlg.hxx"
# include "tabvwsh.hxx"
# include "scitems.hxx"
2007-12-07 10:06:55 +00:00
2007-04-25 15:14:08 +00:00
# include <svx/svdouno.hxx>
2008-01-29 14:47:58 +00:00
# include <svx/svdpage.hxx>
2007-04-25 15:14:08 +00:00
# include "cellsuno.hxx"
# include "drwlayer.hxx"
2010-10-06 10:15:43 +01:00
# include "tabprotection.hxx"
2007-12-07 10:06:55 +00:00
# include "scextopt.hxx"
2007-04-25 15:14:08 +00:00
# include "vbaoutline.hxx"
# include "vbarange.hxx"
# include "vbacomments.hxx"
# include "vbachartobjects.hxx"
# include "vbapivottables.hxx"
2007-12-07 10:06:55 +00:00
# include "vbaoleobject.hxx"
# include "vbaoleobjects.hxx"
2009-02-13 13:03:24 +00:00
# include "vbapagesetup.hxx"
# include "vbapagebreaks.hxx"
2010-06-15 20:02:53 +02:00
# include "vbaworksheets.hxx"
# include "vbahyperlinks.hxx"
# include "vbasheetobjects.hxx"
2011-11-23 21:32:01 -05:00
# include "markdata.hxx"
2011-11-23 23:34:18 -05:00
# include "dbdata.hxx"
2007-04-25 15:14:08 +00:00
2011-04-21 22:01:59 +02:00
# include "attrib.hxx"
2007-04-25 15:14:08 +00:00
# define STANDARDWIDTH 2267
# define STANDARDHEIGHT 427
2010-06-15 20:02:53 +02:00
2007-04-25 15:14:08 +00:00
using namespace com : : sun : : star ;
2009-02-13 13:03:24 +00:00
using namespace ooo : : vba ;
2007-04-25 15:14:08 +00:00
static void getNewSpreadsheetName ( rtl : : OUString & aNewName , rtl : : OUString aOldName , uno : : Reference < sheet : : XSpreadsheetDocument > & xSpreadDoc )
{
if ( ! xSpreadDoc . is ( ) )
throw lang : : IllegalArgumentException ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " getNewSpreadsheetName() xSpreadDoc is null " ) ) , uno : : Reference < uno : : XInterface > ( ) , 1 ) ;
2013-02-24 16:08:05 +01:00
static OUString aUnderScore ( " _ " ) ;
2007-04-25 15:14:08 +00:00
int currentNum = 2 ;
2013-02-24 16:08:05 +01:00
aNewName = aOldName + aUnderScore + OUString : : number ( currentNum ) ;
2007-04-25 15:14:08 +00:00
SCTAB nTab = 0 ;
2010-06-15 20:02:53 +02:00
while ( ScVbaWorksheets : : nameExists ( xSpreadDoc , aNewName , nTab ) )
2007-04-25 15:14:08 +00:00
{
2013-02-24 16:08:05 +01:00
aNewName = aOldName + aUnderScore + OUString : : number ( + + currentNum ) ;
2007-04-25 15:14:08 +00:00
}
}
static void removeAllSheets ( uno : : Reference < sheet : : XSpreadsheetDocument > & xSpreadDoc , rtl : : OUString aSheetName )
{
if ( ! xSpreadDoc . is ( ) )
throw lang : : IllegalArgumentException ( rtl : : OUString ( RTL_CONSTASCII_USTRINGPARAM ( " removeAllSheets() xSpreadDoc is null " ) ) , uno : : Reference < uno : : XInterface > ( ) , 1 ) ;
uno : : Reference < sheet : : XSpreadsheets > xSheets = xSpreadDoc - > getSheets ( ) ;
uno : : Reference < container : : XIndexAccess > xIndex ( xSheets , uno : : UNO_QUERY ) ;
if ( xIndex . is ( ) )
{
uno : : Reference < container : : XNameContainer > xNameContainer ( xSheets , uno : : UNO_QUERY_THROW ) ;
for ( sal_Int32 i = xIndex - > getCount ( ) - 1 ; i > = 1 ; i - - )
{
uno : : Reference < sheet : : XSpreadsheet > xSheet ( xIndex - > getByIndex ( i ) , uno : : UNO_QUERY ) ;
uno : : Reference < container : : XNamed > xNamed ( xSheet , uno : : UNO_QUERY_THROW ) ;
if ( xNamed . is ( ) )
{
xNameContainer - > removeByName ( xNamed - > getName ( ) ) ;
}
}
2010-06-15 20:02:53 +02:00
uno : : Reference < sheet : : XSpreadsheet > xSheet ( xIndex - > getByIndex ( 0 ) , uno : : UNO_QUERY ) ;
uno : : Reference < container : : XNamed > xNamed ( xSheet , uno : : UNO_QUERY_THROW ) ;
2007-04-25 15:14:08 +00:00
if ( xNamed . is ( ) )
{
xNamed - > setName ( aSheetName ) ;
}
}
}
static uno : : Reference < frame : : XModel >
openNewDoc ( rtl : : OUString aSheetName )
{
uno : : Reference < frame : : XModel > xModel ;
try
{
2012-09-29 17:20:22 +02:00
uno : : Reference < uno : : XComponentContext > xContext (
comphelper : : getProcessComponentContext ( ) ) ;
2007-04-25 15:14:08 +00:00
2012-12-14 12:58:00 +02:00
uno : : Reference < frame : : XDesktop2 > xComponentLoader = frame : : Desktop : : create ( xContext ) ;
2007-04-25 15:14:08 +00:00
uno : : Reference < lang : : XComponent > xComponent ( xComponentLoader - > loadComponentFromURL (
2013-03-19 09:22:44 +01:00
rtl : : OUString ( " private:factory/scalc " ) ,
rtl : : OUString ( " _blank " ) , 0 ,
2007-04-25 15:14:08 +00:00
uno : : Sequence < : : com : : sun : : star : : beans : : PropertyValue > ( ) ) ) ;
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( xComponent , uno : : UNO_QUERY_THROW ) ;
if ( xSpreadDoc . is ( ) )
{
removeAllSheets ( xSpreadDoc , aSheetName ) ;
}
xModel . set ( xSpreadDoc , uno : : UNO_QUERY_THROW ) ;
}
catch ( uno : : Exception & /*e*/ )
{
}
return xModel ;
}
2009-02-13 13:03:24 +00:00
ScVbaWorksheet : : ScVbaWorksheet ( const uno : : Reference < XHelperInterface > & xParent , const uno : : Reference < uno : : XComponentContext > & xContext ,
2007-04-25 15:14:08 +00:00
const uno : : Reference < sheet : : XSpreadsheet > & xSheet ,
2012-11-30 12:23:25 +00:00
const uno : : Reference < frame : : XModel > & xModel ) throw ( uno : : RuntimeException ) : WorksheetImpl_BASE ( xParent , xContext ) , mxSheet ( xSheet ) , mxModel ( xModel ) , mbVeryHidden ( false )
2007-04-25 15:14:08 +00:00
{
}
2007-12-07 10:06:55 +00:00
ScVbaWorksheet : : ScVbaWorksheet ( uno : : Sequence < uno : : Any > const & args ,
2010-08-26 14:15:19 +02:00
uno : : Reference < uno : : XComponentContext > const & xContext ) throw ( lang : : IllegalArgumentException ) : WorksheetImpl_BASE ( getXSomethingFromArgs < XHelperInterface > ( args , 0 ) , xContext ) , mxModel ( getXSomethingFromArgs < frame : : XModel > ( args , 1 ) ) , mbVeryHidden ( false )
2007-12-07 10:06:55 +00:00
{
2010-09-20 15:32:20 +02:00
if ( args . getLength ( ) < 3 )
2007-12-07 10:06:55 +00:00
throw lang : : IllegalArgumentException ( ) ;
rtl : : OUString sSheetName ;
args [ 2 ] > > = sSheetName ;
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( mxModel , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XNameAccess > xNameAccess ( xSpreadDoc - > getSheets ( ) , uno : : UNO_QUERY_THROW ) ;
mxSheet . set ( xNameAccess - > getByName ( sSheetName ) , uno : : UNO_QUERY_THROW ) ;
}
2010-06-15 20:02:53 +02:00
ScVbaWorksheet : : ~ ScVbaWorksheet ( )
{
}
2011-06-02 22:57:57 +01:00
namespace
2011-04-07 17:14:41 +01:00
{
2011-06-02 22:57:57 +01:00
class theScVbaWorksheetUnoTunnelId : public rtl : : Static < UnoTunnelIdInit , theScVbaWorksheetUnoTunnelId > { } ;
}
2011-04-07 17:14:41 +01:00
2011-06-02 22:57:57 +01:00
const uno : : Sequence < sal_Int8 > & ScVbaWorksheet : : getUnoTunnelId ( )
{
return theScVbaWorksheetUnoTunnelId : : get ( ) . getSeq ( ) ;
2011-04-07 17:14:41 +01:00
}
2011-04-15 13:52:40 +01:00
uno : : Reference < ov : : excel : : XWorksheet >
ScVbaWorksheet : : createSheetCopyInNewDoc ( rtl : : OUString aCurrSheetName )
{
uno : : Reference < sheet : : XSheetCellCursor > xSheetCellCursor = getSheet ( ) - > createCursor ( ) ;
uno : : Reference < sheet : : XUsedAreaCursor > xUsedCursor ( xSheetCellCursor , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < table : : XCellRange > xRange1 ( xSheetCellCursor , uno : : UNO_QUERY ) ;
uno : : Reference < excel : : XRange > xRange = new ScVbaRange ( this , mxContext , xRange1 ) ;
if ( xRange . is ( ) )
xRange - > Select ( ) ;
excel : : implnCopy ( mxModel ) ;
uno : : Reference < frame : : XModel > xModel = openNewDoc ( aCurrSheetName ) ;
if ( xModel . is ( ) )
{
excel : : implnPaste ( xModel ) ;
}
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( xModel , uno : : UNO_QUERY_THROW ) ;
2011-04-26 09:32:22 +01:00
excel : : setUpDocumentModules ( xSpreadDoc ) ;
2011-04-15 13:52:40 +01:00
uno : : Reference < sheet : : XSpreadsheets > xSheets ( xSpreadDoc - > getSheets ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndex ( xSheets , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < sheet : : XSpreadsheet > xSheet ( xIndex - > getByIndex ( 0 ) , uno : : UNO_QUERY_THROW ) ;
2011-04-26 09:32:22 +01:00
ScDocShell * pShell = excel : : getDocShell ( xModel ) ;
2011-08-26 19:33:59 -04:00
rtl : : OUString aCodeName ;
2011-04-26 09:32:22 +01:00
pShell - > GetDocument ( ) - > GetCodeName ( 0 , aCodeName ) ;
return uno : : Reference < excel : : XWorksheet > ( getUnoDocModule ( aCodeName , pShell ) , uno : : UNO_QUERY_THROW ) ;
2011-04-15 13:52:40 +01:00
}
css : : uno : : Reference < ov : : excel : : XWorksheet >
ScVbaWorksheet : : createSheetCopy ( uno : : Reference < excel : : XWorksheet > xSheet , bool bAfter )
{
rtl : : OUString aCurrSheetName = getName ( ) ;
ScVbaWorksheet * pDestSheet = excel : : getImplFromDocModuleWrapper < ScVbaWorksheet > ( xSheet ) ;
uno : : Reference < sheet : : XSpreadsheetDocument > xDestDoc ( pDestSheet - > getModel ( ) , uno : : UNO_QUERY ) ;
uno : : Reference < sheet : : XSpreadsheetDocument > xSrcDoc ( getModel ( ) , uno : : UNO_QUERY ) ;
SCTAB nDest = 0 ;
SCTAB nSrc = 0 ;
rtl : : OUString aSheetName = xSheet - > getName ( ) ;
bool bSameDoc = ( pDestSheet - > getModel ( ) = = getModel ( ) ) ;
bool bDestSheetExists = ScVbaWorksheets : : nameExists ( xDestDoc , aSheetName , nDest ) ;
bool bSheetExists = ScVbaWorksheets : : nameExists ( xSrcDoc , aCurrSheetName , nSrc ) ;
// set sheet name to be newSheet name
aSheetName = aCurrSheetName ;
if ( bSheetExists & & bDestSheetExists )
{
SCTAB nDummy = 0 ;
if ( bAfter )
nDest + + ;
uno : : Reference < sheet : : XSpreadsheets > xSheets = xDestDoc - > getSheets ( ) ;
if ( bSameDoc | | ScVbaWorksheets : : nameExists ( xDestDoc , aCurrSheetName , nDummy ) )
getNewSpreadsheetName ( aSheetName , aCurrSheetName , xDestDoc ) ;
if ( bSameDoc )
xSheets - > copyByName ( aCurrSheetName , aSheetName , nDest ) ;
else
{
ScDocShell * pDestDocShell = excel : : getDocShell ( pDestSheet - > getModel ( ) ) ;
ScDocShell * pSrcDocShell = excel : : getDocShell ( getModel ( ) ) ;
if ( pDestDocShell & & pSrcDocShell )
pDestDocShell - > TransferTab ( * pSrcDocShell , static_cast < SCTAB > ( nSrc ) , static_cast < SCTAB > ( nDest ) , true , true ) ;
}
}
// return new sheet
uno : : Reference < excel : : XApplication > xApplication ( Application ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < excel : : XWorksheet > xNewSheet ( xApplication - > Worksheets ( uno : : makeAny ( aSheetName ) ) , uno : : UNO_QUERY_THROW ) ;
return xNewSheet ;
}
2007-04-25 15:14:08 +00:00
: : rtl : : OUString
ScVbaWorksheet : : getName ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < container : : XNamed > xNamed ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
return xNamed - > getName ( ) ;
}
void
ScVbaWorksheet : : setName ( const : : rtl : : OUString & rName ) throw ( uno : : RuntimeException )
{
uno : : Reference < container : : XNamed > xNamed ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
xNamed - > setName ( rName ) ;
}
2012-09-11 08:48:02 +01:00
sal_Int32
2007-04-25 15:14:08 +00:00
ScVbaWorksheet : : getVisible ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < beans : : XPropertySet > xProps ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
2012-09-11 08:48:02 +01:00
bool bVisible = false ;
xProps - > getPropertyValue ( " IsVisible " ) > > = bVisible ;
using namespace : : ooo : : vba : : excel : : XlSheetVisibility ;
return bVisible ? xlSheetVisible : ( mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden ) ;
2007-04-25 15:14:08 +00:00
}
void
2012-09-11 08:48:02 +01:00
ScVbaWorksheet : : setVisible ( sal_Int32 nVisible ) throw ( uno : : RuntimeException )
2007-04-25 15:14:08 +00:00
{
2010-08-26 14:15:19 +02:00
using namespace : : ooo : : vba : : excel : : XlSheetVisibility ;
bool bVisible = true ;
switch ( nVisible )
{
case xlSheetVisible : case 1 : // Excel accepts -1 and 1 for visible sheets
bVisible = true ;
mbVeryHidden = false ;
break ;
case xlSheetHidden :
bVisible = false ;
mbVeryHidden = false ;
break ;
case xlSheetVeryHidden :
bVisible = false ;
mbVeryHidden = true ;
break ;
default :
throw uno : : RuntimeException ( ) ;
}
2007-04-25 15:14:08 +00:00
uno : : Reference < beans : : XPropertySet > xProps ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
2012-09-11 08:48:02 +01:00
xProps - > setPropertyValue ( " IsVisible " , uno : : Any ( bVisible ) ) ;
2007-04-25 15:14:08 +00:00
}
2009-02-13 13:03:24 +00:00
sal_Int16
ScVbaWorksheet : : getIndex ( ) throw ( uno : : RuntimeException )
{
return getSheetID ( ) + 1 ;
}
2009-09-18 15:24:22 +00:00
sal_Int32
ScVbaWorksheet : : getEnableSelection ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
SCTAB nTab = 0 ;
2010-06-15 20:02:53 +02:00
if ( ScVbaWorksheets : : nameExists ( xSpreadDoc , getName ( ) , nTab ) )
2009-09-18 15:24:22 +00:00
{
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
ScDocument * pDoc = excel : : getDocShell ( xModel ) - > GetDocument ( ) ;
ScTableProtection * pProtect = pDoc - > GetTabProtection ( nTab ) ;
2011-03-10 16:55:21 -05:00
sal_Bool bLockedCells = false ;
sal_Bool bUnlockedCells = false ;
2009-09-18 15:24:22 +00:00
if ( pProtect )
{
bLockedCells = pProtect - > isOptionEnabled ( ScTableProtection : : SELECT_LOCKED_CELLS ) ;
bUnlockedCells = pProtect - > isOptionEnabled ( ScTableProtection : : SELECT_UNLOCKED_CELLS ) ;
}
if ( bLockedCells )
return excel : : XlEnableSelection : : xlNoRestrictions ;
if ( bUnlockedCells )
return excel : : XlEnableSelection : : xlUnlockedCells ;
return excel : : XlEnableSelection : : xlNoSelection ;
}
else
2013-03-19 09:22:44 +01:00
throw uno : : RuntimeException ( : : rtl : : OUString ( " Sheet Name does not exist. " ) ,
2009-09-18 15:24:22 +00:00
uno : : Reference < XInterface > ( ) ) ;
}
void
ScVbaWorksheet : : setEnableSelection ( sal_Int32 nSelection ) throw ( uno : : RuntimeException )
{
if ( ( nSelection ! = excel : : XlEnableSelection : : xlNoRestrictions ) & &
( nSelection ! = excel : : XlEnableSelection : : xlUnlockedCells ) & &
( nSelection ! = excel : : XlEnableSelection : : xlNoSelection ) )
{
DebugHelper : : exception ( SbERR_BAD_PARAMETER , rtl : : OUString ( ) ) ;
}
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
SCTAB nTab = 0 ;
2010-06-15 20:02:53 +02:00
if ( ScVbaWorksheets : : nameExists ( xSpreadDoc , getName ( ) , nTab ) )
2009-09-18 15:24:22 +00:00
{
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
ScDocument * pDoc = excel : : getDocShell ( xModel ) - > GetDocument ( ) ;
ScTableProtection * pProtect = pDoc - > GetTabProtection ( nTab ) ;
// default is xlNoSelection
2011-03-10 16:55:21 -05:00
sal_Bool bLockedCells = false ;
sal_Bool bUnlockedCells = false ;
2009-09-18 15:24:22 +00:00
if ( nSelection = = excel : : XlEnableSelection : : xlNoRestrictions )
{
bLockedCells = sal_True ;
bUnlockedCells = sal_True ;
}
else if ( nSelection = = excel : : XlEnableSelection : : xlUnlockedCells )
{
bUnlockedCells = sal_True ;
}
if ( pProtect )
{
pProtect - > setOption ( ScTableProtection : : SELECT_LOCKED_CELLS , bLockedCells ) ;
pProtect - > setOption ( ScTableProtection : : SELECT_UNLOCKED_CELLS , bUnlockedCells ) ;
}
}
else
2013-03-19 09:22:44 +01:00
throw uno : : RuntimeException ( : : rtl : : OUString ( " Sheet Name does not exist. " ) ,
2009-09-18 15:24:22 +00:00
uno : : Reference < XInterface > ( ) ) ;
}
2010-08-04 18:13:02 +02:00
sal_Bool SAL_CALL ScVbaWorksheet : : getAutoFilterMode ( ) throw ( uno : : RuntimeException )
{
2011-04-21 22:01:59 +02:00
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
ScDocument * pDoc = excel : : getDocShell ( xModel ) - > GetDocument ( ) ;
ScDBData * pDBData = pDoc - > GetAnonymousDBData ( getSheetID ( ) ) ;
if ( pDBData )
return pDBData - > HasAutoFilter ( ) ;
return false ;
2010-08-04 18:13:02 +02:00
}
void SAL_CALL ScVbaWorksheet : : setAutoFilterMode ( sal_Bool bAutoFilterMode ) throw ( uno : : RuntimeException )
{
2011-04-21 22:01:59 +02:00
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
ScDocShell * pDocShell = excel : : getDocShell ( xModel ) ;
ScDocument * pDoc = pDocShell - > GetDocument ( ) ;
ScDBData * pDBData = pDoc - > GetAnonymousDBData ( getSheetID ( ) ) ;
if ( pDBData )
{
pDBData - > SetAutoFilter ( bAutoFilterMode ) ;
ScRange aRange ;
pDBData - > GetArea ( aRange ) ;
if ( bAutoFilterMode & & pDoc )
pDoc - > ApplyFlagsTab ( aRange . aStart . Col ( ) , aRange . aStart . Row ( ) ,
aRange . aEnd . Col ( ) , aRange . aStart . Row ( ) ,
aRange . aStart . Tab ( ) , SC_MF_AUTO ) ;
else if ( ! bAutoFilterMode & & pDoc )
pDoc - > RemoveFlagsTab ( aRange . aStart . Col ( ) , aRange . aStart . Row ( ) ,
aRange . aEnd . Col ( ) , aRange . aStart . Row ( ) ,
aRange . aStart . Tab ( ) , SC_MF_AUTO ) ;
ScRange aPaintRange ( aRange . aStart , aRange . aEnd ) ;
aPaintRange . aEnd . SetRow ( aPaintRange . aStart . Row ( ) ) ;
pDocShell - > PostPaint ( aPaintRange , PAINT_GRID ) ;
}
2010-08-04 18:13:02 +02:00
}
2007-04-25 15:14:08 +00:00
uno : : Reference < excel : : XRange >
ScVbaWorksheet : : getUsedRange ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSheetCellRange > xSheetCellRange ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < sheet : : XSheetCellCursor > xSheetCellCursor ( getSheet ( ) - > createCursorByRange ( xSheetCellRange ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < sheet : : XUsedAreaCursor > xUsedCursor ( xSheetCellCursor , uno : : UNO_QUERY_THROW ) ;
xUsedCursor - > gotoStartOfUsedArea ( false ) ;
xUsedCursor - > gotoEndOfUsedArea ( true ) ;
uno : : Reference < table : : XCellRange > xRange ( xSheetCellCursor , uno : : UNO_QUERY ) ;
2007-12-07 10:06:55 +00:00
return new ScVbaRange ( this , mxContext , xRange ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Reference < excel : : XOutline >
ScVbaWorksheet : : Outline ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSheetOutline > xOutline ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
return new ScVbaOutline ( this , mxContext , xOutline ) ;
2007-04-25 15:14:08 +00:00
}
2009-02-13 13:03:24 +00:00
uno : : Reference < excel : : XPageSetup >
ScVbaWorksheet : : PageSetup ( ) throw ( uno : : RuntimeException )
{
return new ScVbaPageSetup ( this , mxContext , getSheet ( ) , getModel ( ) ) ;
}
uno : : Any
ScVbaWorksheet : : HPageBreaks ( const uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSheetPageBreak > xSheetPageBreak ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < excel : : XHPageBreaks > xHPageBreaks ( new ScVbaHPageBreaks ( this , mxContext , xSheetPageBreak ) ) ;
if ( aIndex . hasValue ( ) )
return xHPageBreaks - > Item ( aIndex , uno : : Any ( ) ) ;
return uno : : makeAny ( xHPageBreaks ) ;
}
2009-09-18 15:24:22 +00:00
uno : : Any
ScVbaWorksheet : : VPageBreaks ( const uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSheetPageBreak > xSheetPageBreak ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < excel : : XVPageBreaks > xVPageBreaks ( new ScVbaVPageBreaks ( this , mxContext , xSheetPageBreak ) ) ;
if ( aIndex . hasValue ( ) )
return xVPageBreaks - > Item ( aIndex , uno : : Any ( ) ) ;
return uno : : makeAny ( xVPageBreaks ) ;
}
2007-04-25 15:14:08 +00:00
sal_Int32
ScVbaWorksheet : : getStandardWidth ( ) throw ( uno : : RuntimeException )
{
return STANDARDWIDTH ;
}
sal_Int32
ScVbaWorksheet : : getStandardHeight ( ) throw ( uno : : RuntimeException )
{
return STANDARDHEIGHT ;
}
sal_Bool
ScVbaWorksheet : : getProtectionMode ( ) throw ( uno : : RuntimeException )
{
2011-03-10 16:55:21 -05:00
return false ;
2007-04-25 15:14:08 +00:00
}
sal_Bool
ScVbaWorksheet : : getProtectContents ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < util : : XProtectable > xProtectable ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
return xProtectable - > isProtected ( ) ;
}
sal_Bool
ScVbaWorksheet : : getProtectDrawingObjects ( ) throw ( uno : : RuntimeException )
{
2010-10-06 10:15:43 +01:00
SCTAB nTab = 0 ;
rtl : : OUString aSheetName = getName ( ) ;
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
bool bSheetExists = ScVbaWorksheets : : nameExists ( xSpreadDoc , aSheetName , nTab ) ;
if ( bSheetExists )
{
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
ScDocument * pDoc = excel : : getDocShell ( xModel ) - > GetDocument ( ) ;
ScTableProtection * pProtect = pDoc - > GetTabProtection ( nTab ) ;
if ( pProtect )
return pProtect - > isOptionEnabled ( ScTableProtection : : OBJECTS ) ;
}
2011-03-10 16:55:21 -05:00
return false ;
2010-08-10 10:27:30 +02:00
}
sal_Bool
ScVbaWorksheet : : getProtectScenarios ( ) throw ( uno : : RuntimeException )
{
2011-03-10 16:55:21 -05:00
return false ;
2007-04-25 15:14:08 +00:00
}
void
ScVbaWorksheet : : Activate ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSpreadsheetView > xSpreadsheet (
getModel ( ) - > getCurrentController ( ) , uno : : UNO_QUERY_THROW ) ;
xSpreadsheet - > setActiveSheet ( getSheet ( ) ) ;
}
void
2012-09-11 08:48:02 +01:00
ScVbaWorksheet : : Select ( ) throw ( uno : : RuntimeException )
2007-04-25 15:14:08 +00:00
{
2012-09-11 08:48:02 +01:00
Activate ( ) ;
2007-04-25 15:14:08 +00:00
}
void
ScVbaWorksheet : : Move ( const uno : : Any & Before , const uno : : Any & After ) throw ( uno : : RuntimeException )
{
uno : : Reference < excel : : XWorksheet > xSheet ;
2010-06-15 20:02:53 +02:00
rtl : : OUString aCurrSheetName = getName ( ) ;
2007-04-25 15:14:08 +00:00
if ( ! ( Before > > = xSheet ) & & ! ( After > > = xSheet ) & & ! ( Before . hasValue ( ) ) & & ! ( After . hasValue ( ) ) )
{
uno : : Reference < sheet : : XSheetCellCursor > xSheetCellCursor = getSheet ( ) - > createCursor ( ) ;
uno : : Reference < sheet : : XUsedAreaCursor > xUsedCursor ( xSheetCellCursor , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < table : : XCellRange > xRange1 ( xSheetCellCursor , uno : : UNO_QUERY ) ;
2007-12-07 10:06:55 +00:00
// #FIXME needs worksheet as parent
uno : : Reference < excel : : XRange > xRange = new ScVbaRange ( this , mxContext , xRange1 ) ;
2007-04-25 15:14:08 +00:00
if ( xRange . is ( ) )
xRange - > Select ( ) ;
2009-09-18 15:24:22 +00:00
excel : : implnCopy ( mxModel ) ;
2007-04-25 15:14:08 +00:00
uno : : Reference < frame : : XModel > xModel = openNewDoc ( aCurrSheetName ) ;
if ( xModel . is ( ) )
{
2009-09-18 15:24:22 +00:00
excel : : implnPaste ( xModel ) ;
2007-04-25 15:14:08 +00:00
Delete ( ) ;
}
return ;
}
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
SCTAB nDest = 0 ;
2010-06-15 20:02:53 +02:00
if ( ScVbaWorksheets : : nameExists ( xSpreadDoc , xSheet - > getName ( ) , nDest ) )
2007-04-25 15:14:08 +00:00
{
sal_Bool bAfter = After . hasValue ( ) ;
if ( bAfter )
nDest + + ;
uno : : Reference < sheet : : XSpreadsheets > xSheets = xSpreadDoc - > getSheets ( ) ;
xSheets - > moveByName ( aCurrSheetName , nDest ) ;
}
}
void
ScVbaWorksheet : : Copy ( const uno : : Any & Before , const uno : : Any & After ) throw ( uno : : RuntimeException )
{
uno : : Reference < excel : : XWorksheet > xSheet ;
if ( ! ( Before > > = xSheet ) & & ! ( After > > = xSheet ) & & ! ( Before . hasValue ( ) ) & & ! ( After . hasValue ( ) ) )
{
2011-04-15 13:52:40 +01:00
createSheetCopyInNewDoc ( getName ( ) ) ;
2007-04-25 15:14:08 +00:00
return ;
}
2011-04-15 13:52:40 +01:00
uno : : Reference < excel : : XWorksheet > xNewSheet = createSheetCopy ( xSheet , After . hasValue ( ) ) ;
2010-10-06 10:15:43 +01:00
xNewSheet - > Activate ( ) ;
2007-04-25 15:14:08 +00:00
}
void
ScVbaWorksheet : : Paste ( const uno : : Any & Destination , const uno : : Any & /*Link*/ ) throw ( uno : : RuntimeException )
{
// #TODO# #FIXME# Link is not used
uno : : Reference < excel : : XRange > xRange ( Destination , uno : : UNO_QUERY ) ;
if ( xRange . is ( ) )
xRange - > Select ( ) ;
2009-09-18 15:24:22 +00:00
excel : : implnPaste ( mxModel ) ;
2007-04-25 15:14:08 +00:00
}
void
ScVbaWorksheet : : Delete ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
rtl : : OUString aSheetName = getName ( ) ;
if ( xSpreadDoc . is ( ) )
{
SCTAB nTab = 0 ;
2010-06-15 20:02:53 +02:00
if ( ! ScVbaWorksheets : : nameExists ( xSpreadDoc , aSheetName , nTab ) )
2007-04-25 15:14:08 +00:00
{
return ;
}
uno : : Reference < sheet : : XSpreadsheets > xSheets = xSpreadDoc - > getSheets ( ) ;
uno : : Reference < container : : XNameContainer > xNameContainer ( xSheets , uno : : UNO_QUERY_THROW ) ;
xNameContainer - > removeByName ( aSheetName ) ;
2009-02-13 13:03:24 +00:00
mxSheet . clear ( ) ;
2007-04-25 15:14:08 +00:00
}
}
uno : : Reference < excel : : XWorksheet >
ScVbaWorksheet : : getSheetAtOffset ( SCTAB offset ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSpreadsheetDocument > xSpreadDoc ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < sheet : : XSpreadsheets > xSheets ( xSpreadDoc - > getSheets ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndex ( xSheets , uno : : UNO_QUERY_THROW ) ;
SCTAB nIdx = 0 ;
2010-06-15 20:02:53 +02:00
if ( ! ScVbaWorksheets : : nameExists ( xSpreadDoc , getName ( ) , nIdx ) )
2007-04-25 15:14:08 +00:00
return uno : : Reference < excel : : XWorksheet > ( ) ;
nIdx = nIdx + offset ;
uno : : Reference < sheet : : XSpreadsheet > xSheet ( xIndex - > getByIndex ( nIdx ) , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
// parent will be the parent of 'this' worksheet
return new ScVbaWorksheet ( getParent ( ) , mxContext , xSheet , getModel ( ) ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Reference < excel : : XWorksheet >
ScVbaWorksheet : : getNext ( ) throw ( uno : : RuntimeException )
{
2012-09-11 08:48:02 +01:00
return getSheetAtOffset ( static_cast < SCTAB > ( 1 ) ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Reference < excel : : XWorksheet >
ScVbaWorksheet : : getPrevious ( ) throw ( uno : : RuntimeException )
{
2012-09-11 08:48:02 +01:00
return getSheetAtOffset ( - 1 ) ;
2007-04-25 15:14:08 +00:00
}
void
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 )
{
// #TODO# #FIXME# is there anything we can do witht the unused param
// can the implementation use anything else here
uno : : Reference < util : : XProtectable > xProtectable ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
: : rtl : : OUString aPasswd ;
Password > > = aPasswd ;
xProtectable - > protect ( aPasswd ) ;
}
void
ScVbaWorksheet : : Unprotect ( const uno : : Any & Password ) throw ( uno : : RuntimeException )
{
uno : : Reference < util : : XProtectable > xProtectable ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
: : rtl : : OUString aPasswd ;
Password > > = aPasswd ;
xProtectable - > unprotect ( aPasswd ) ;
}
void
ScVbaWorksheet : : Calculate ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XCalculatable > xReCalculate ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
xReCalculate - > calculate ( ) ;
}
uno : : Reference < excel : : XRange >
ScVbaWorksheet : : Range ( const : : uno : : Any & Cell1 , const : : uno : : Any & Cell2 ) throw ( uno : : RuntimeException )
{
2007-12-07 10:06:55 +00:00
uno : : Reference < excel : : XRange > xSheetRange ( new ScVbaRange ( this , mxContext
2007-04-25 15:14:08 +00:00
, uno : : Reference < table : : XCellRange > ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ) ) ;
return xSheetRange - > Range ( Cell1 , Cell2 ) ;
}
void
ScVbaWorksheet : : CheckSpelling ( const uno : : Any & /*CustomDictionary*/ , const uno : : Any & /*IgnoreUppercase*/ , const uno : : Any & /*AlwaysSuggest*/ , const uno : : Any & /*SpellingLang*/ ) throw ( uno : : RuntimeException )
{
// #TODO# #FIXME# unused params above, can we do anything with those
2013-03-19 09:22:44 +01:00
rtl : : OUString url = rtl : : OUString ( " .uno:SpellDialog " ) ;
2007-04-25 15:14:08 +00:00
uno : : Reference < frame : : XModel > xModel ( getModel ( ) ) ;
dispatchRequests ( xModel , url ) ;
}
uno : : Reference < excel : : XRange >
ScVbaWorksheet : : getSheetRange ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < table : : XCellRange > xRange ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
return uno : : Reference < excel : : XRange > ( new ScVbaRange ( this , mxContext , xRange ) ) ;
2007-04-25 15:14:08 +00:00
}
// These are hacks - we prolly (somehow) need to inherit
// the vbarange functionality here ...
uno : : Reference < excel : : XRange >
ScVbaWorksheet : : Cells ( const : : uno : : Any & nRow , const : : uno : : Any & nCol )
throw ( uno : : RuntimeException )
{
2010-09-14 23:23:30 +02:00
// Performance optimization for often-called Cells method:
// Use a common helper method instead of creating a new ScVbaRange object
uno : : Reference < table : : XCellRange > xRange ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
2010-09-20 13:52:55 +02:00
return ScVbaRange : : CellsHelper ( this , mxContext , xRange , nRow , nCol ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Reference < excel : : XRange >
ScVbaWorksheet : : Rows ( const uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
return getSheetRange ( ) - > Rows ( aIndex ) ;
}
uno : : Reference < excel : : XRange >
ScVbaWorksheet : : Columns ( const uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
return getSheetRange ( ) - > Columns ( aIndex ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : ChartObjects ( const uno : : Any & Index ) throw ( uno : : RuntimeException )
{
if ( ! mxCharts . is ( ) )
{
uno : : Reference < table : : XTableChartsSupplier > xChartSupplier ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < table : : XTableCharts > xTableCharts = xChartSupplier - > getCharts ( ) ;
2012-09-11 08:48:02 +01:00
uno : : Reference < drawing : : XDrawPageSupplier > xDrawPageSupplier ( mxSheet , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
mxCharts = new ScVbaChartObjects ( this , mxContext , xTableCharts , xDrawPageSupplier ) ;
2007-04-25 15:14:08 +00:00
}
if ( Index . hasValue ( ) )
{
2009-02-13 13:03:24 +00:00
uno : : Reference < XCollection > xColl ( mxCharts , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
return xColl - > Item ( Index , uno : : Any ( ) ) ;
2007-04-25 15:14:08 +00:00
}
else
2007-12-07 10:06:55 +00:00
return uno : : makeAny ( mxCharts ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Any SAL_CALL
ScVbaWorksheet : : PivotTables ( const uno : : Any & Index ) throw ( uno : : RuntimeException )
{
uno : : Reference < css : : sheet : : XSpreadsheet > xSheet = getSheet ( ) ;
uno : : Reference < sheet : : XDataPilotTablesSupplier > xTables ( xSheet , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndexAccess ( xTables - > getDataPilotTables ( ) , uno : : UNO_QUERY_THROW ) ;
2009-02-13 13:03:24 +00:00
uno : : Reference < XCollection > xColl ( new ScVbaPivotTables ( this , mxContext , xIndexAccess ) ) ;
2007-04-25 15:14:08 +00:00
if ( Index . hasValue ( ) )
2007-12-07 10:06:55 +00:00
return xColl - > Item ( Index , uno : : Any ( ) ) ;
return uno : : makeAny ( xColl ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Any SAL_CALL
ScVbaWorksheet : : Comments ( const uno : : Any & Index ) throw ( uno : : RuntimeException )
{
uno : : Reference < css : : sheet : : XSpreadsheet > xSheet = getSheet ( ) ;
uno : : Reference < sheet : : XSheetAnnotationsSupplier > xAnnosSupp ( xSheet , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < sheet : : XSheetAnnotations > xAnnos ( xAnnosSupp - > getAnnotations ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndexAccess ( xAnnos , uno : : UNO_QUERY_THROW ) ;
2010-06-15 20:02:53 +02:00
uno : : Reference < XCollection > xColl ( new ScVbaComments ( this , mxContext , mxModel , xIndexAccess ) ) ;
2007-04-25 15:14:08 +00:00
if ( Index . hasValue ( ) )
2007-12-07 10:06:55 +00:00
return xColl - > Item ( Index , uno : : Any ( ) ) ;
return uno : : makeAny ( xColl ) ;
}
2010-06-15 20:02:53 +02:00
uno : : Any SAL_CALL
ScVbaWorksheet : : Hyperlinks ( const uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
/* The worksheet always returns the same Hyperlinks object.
See vbahyperlinks . hxx for more details . */
if ( ! mxHlinks . is ( ) )
mxHlinks . set ( new ScVbaHyperlinks ( this , mxContext ) ) ;
if ( aIndex . hasValue ( ) )
return uno : : Reference < XCollection > ( mxHlinks , uno : : UNO_QUERY_THROW ) - > Item ( aIndex , uno : : Any ( ) ) ;
return uno : : Any ( mxHlinks ) ;
}
2010-07-30 17:28:42 +02:00
uno : : Any SAL_CALL
ScVbaWorksheet : : Names ( const css : : uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
2010-09-01 10:26:59 +02:00
// fake sheet-local names by returning all global names
// #163498# initialize Names object with correct parent (this worksheet)
// TODO: real sheet-local names...
uno : : Reference < beans : : XPropertySet > xProps ( mxModel , uno : : UNO_QUERY_THROW ) ;
2013-03-19 09:22:44 +01:00
uno : : Reference < sheet : : XNamedRanges > xNamedRanges ( xProps - > getPropertyValue ( rtl : : OUString ( " NamedRanges " ) ) , uno : : UNO_QUERY_THROW ) ;
2010-09-01 10:26:59 +02:00
uno : : Reference < XCollection > xNames ( new ScVbaNames ( this , mxContext , xNamedRanges , mxModel ) ) ;
if ( aIndex . hasValue ( ) )
return uno : : Any ( xNames - > Item ( aIndex , uno : : Any ( ) ) ) ;
return uno : : Any ( xNames ) ;
2010-07-30 17:28:42 +02:00
}
2007-12-07 10:06:55 +00:00
uno : : Any SAL_CALL
ScVbaWorksheet : : OLEObjects ( const uno : : Any & Index ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSpreadsheet > xSpreadsheet ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < drawing : : XDrawPageSupplier > xDrawPageSupplier ( xSpreadsheet , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < drawing : : XDrawPage > xDrawPage ( xDrawPageSupplier - > getDrawPage ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndexAccess ( xDrawPage , uno : : UNO_QUERY_THROW ) ;
2010-07-30 17:28:42 +02:00
uno : : Reference < excel : : XOLEObjects > xOleObjects ( new ScVbaOLEObjects ( this , mxContext , xIndexAccess ) ) ;
2007-12-07 10:06:55 +00:00
if ( Index . hasValue ( ) )
2010-07-30 17:28:42 +02:00
return xOleObjects - > Item ( Index , uno : : Any ( ) ) ;
return uno : : Any ( xOleObjects ) ;
2007-12-07 10:06:55 +00:00
}
2010-07-30 17:28:42 +02:00
2007-12-07 10:06:55 +00:00
uno : : Any SAL_CALL
ScVbaWorksheet : : Shapes ( const uno : : Any & aIndex ) throw ( uno : : RuntimeException )
{
uno : : Reference < sheet : : XSpreadsheet > xSpreadsheet ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < drawing : : XDrawPageSupplier > xDrawPageSupplier ( xSpreadsheet , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < drawing : : XShapes > xShapes ( xDrawPageSupplier - > getDrawPage ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndexAccess ( xShapes , uno : : UNO_QUERY_THROW ) ;
2009-09-18 15:24:22 +00:00
uno : : Reference < msforms : : XShapes > xVbaShapes ( new ScVbaShapes ( this , mxContext , xIndexAccess , getModel ( ) ) ) ;
2007-12-07 10:06:55 +00:00
if ( aIndex . hasValue ( ) )
return xVbaShapes - > Item ( aIndex , uno : : Any ( ) ) ;
return uno : : makeAny ( xVbaShapes ) ;
}
2010-06-15 20:02:53 +02:00
uno : : Any SAL_CALL
ScVbaWorksheet : : Buttons ( const uno : : Any & rIndex ) throw ( uno : : RuntimeException )
{
if ( ! mxButtons . is ( ) )
mxButtons . set ( new ScVbaButtons ( this , mxContext , mxModel , mxSheet ) ) ;
else
mxButtons - > collectShapes ( ) ;
if ( rIndex . hasValue ( ) )
return mxButtons - > Item ( rIndex , uno : : Any ( ) ) ;
return uno : : Any ( uno : : Reference < XCollection > ( mxButtons . get ( ) ) ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : CheckBoxes ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : DropDowns ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : GroupBoxes ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : Labels ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : ListBoxes ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : OptionButtons ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : ScrollBars ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : Spinners ( const uno : : Any & /*rIndex*/ ) throw ( uno : : RuntimeException )
{
throw uno : : RuntimeException ( ) ;
}
2007-12-07 10:06:55 +00:00
void SAL_CALL
ScVbaWorksheet : : ShowDataForm ( ) throw ( uno : : RuntimeException )
{
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
2009-09-18 15:24:22 +00:00
ScTabViewShell * pTabViewShell = excel : : getBestViewShell ( xModel ) ;
2007-12-07 10:06:55 +00:00
ScAbstractDialogFactory * pFact = ScAbstractDialogFactory : : Create ( ) ;
2011-05-21 15:04:26 +02:00
OSL_ENSURE ( pFact , " ScAbstractFactory create fail! " ) ;
2007-12-07 10:06:55 +00:00
AbstractScDataFormDlg * pDlg = pFact - > CreateScDataFormDlg ( pTabViewShell - > GetDialogParent ( ) , RID_SCDLG_DATAFORM , pTabViewShell ) ;
2011-05-21 15:04:26 +02:00
OSL_ENSURE ( pDlg , " Dialog create fail! " ) ;
2007-12-07 10:06:55 +00:00
pDlg - > Execute ( ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Any SAL_CALL
ScVbaWorksheet : : Evaluate ( const : : rtl : : OUString & Name ) throw ( uno : : RuntimeException )
{
// #TODO Evaluate allows other things to be evaluated, e.g. functions
// I think ( like SIN(3) etc. ) need to investigate that
// named Ranges also? e.g. [MyRange] if so need a list of named ranges
uno : : Any aVoid ;
return uno : : Any ( Range ( uno : : Any ( Name ) , aVoid ) ) ;
}
uno : : Reference < beans : : XIntrospectionAccess > SAL_CALL
ScVbaWorksheet : : getIntrospection ( ) throw ( uno : : RuntimeException )
{
return uno : : Reference < beans : : XIntrospectionAccess > ( ) ;
}
uno : : Any SAL_CALL
ScVbaWorksheet : : invoke ( const : : rtl : : OUString & aFunctionName , const uno : : Sequence < uno : : Any > & /*aParams*/ , uno : : Sequence < : : sal_Int16 > & /*aOutParamIndex*/ , uno : : Sequence < uno : : Any > & /*aOutParam*/ ) throw ( lang : : IllegalArgumentException , script : : CannotConvertException , reflection : : InvocationTargetException , uno : : RuntimeException )
{
OSL_TRACE ( " ** ScVbaWorksheet::invoke( %s ), will barf " ,
rtl : : OUStringToOString ( aFunctionName , RTL_TEXTENCODING_UTF8 ) . getStr ( ) ) ;
throw uno : : RuntimeException ( ) ; // unsupported operation
}
void SAL_CALL
2009-09-18 15:24:22 +00:00
ScVbaWorksheet : : setValue ( const : : rtl : : OUString & aPropertyName , const uno : : Any & aValue ) throw ( beans : : UnknownPropertyException , script : : CannotConvertException , reflection : : InvocationTargetException , uno : : RuntimeException )
2007-04-25 15:14:08 +00:00
{
2009-09-18 15:24:22 +00:00
setDefaultPropByIntrospection ( uno : : makeAny ( getValue ( aPropertyName ) ) , aValue ) ;
2007-04-25 15:14:08 +00:00
}
uno : : Any SAL_CALL
ScVbaWorksheet : : getValue ( const : : rtl : : OUString & aPropertyName ) throw ( beans : : UnknownPropertyException , uno : : RuntimeException )
{
2007-12-07 10:06:55 +00:00
uno : : Reference < drawing : : XControlShape > xControlShape ( getControlShape ( aPropertyName ) , uno : : UNO_QUERY_THROW ) ;
2009-09-18 15:24:22 +00:00
uno : : Reference < lang : : XMultiComponentFactory > xServiceManager ( mxContext - > getServiceManager ( ) , uno : : UNO_QUERY_THROW ) ;
2013-03-19 09:22:44 +01:00
uno : : Reference < XControlProvider > xControlProvider ( xServiceManager - > createInstanceWithContext ( rtl : : OUString ( " ooo.vba.ControlProvider " ) , mxContext ) , uno : : UNO_QUERY_THROW ) ;
2009-09-18 15:24:22 +00:00
uno : : Reference < msforms : : XControl > xControl ( xControlProvider - > createControl ( xControlShape , getModel ( ) ) ) ;
2007-12-07 10:06:55 +00:00
return uno : : makeAny ( xControl ) ;
2007-04-25 15:14:08 +00:00
}
: : sal_Bool SAL_CALL
ScVbaWorksheet : : hasMethod ( const : : rtl : : OUString & /*aName*/ ) throw ( uno : : RuntimeException )
{
2011-03-10 16:55:21 -05:00
return false ;
2007-04-25 15:14:08 +00:00
}
2009-02-13 13:03:24 +00:00
uno : : Reference < container : : XNameAccess >
ScVbaWorksheet : : getFormControls ( )
2007-04-25 15:14:08 +00:00
{
2009-02-13 13:03:24 +00:00
uno : : Reference < container : : XNameAccess > xFormControls ;
2007-12-07 10:06:55 +00:00
try
{
2009-02-13 13:03:24 +00:00
uno : : Reference < sheet : : XSpreadsheet > xSpreadsheet ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < drawing : : XDrawPageSupplier > xDrawPageSupplier ( xSpreadsheet , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < form : : XFormsSupplier > xFormSupplier ( xDrawPageSupplier - > getDrawPage ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndexAccess ( xFormSupplier - > getForms ( ) , uno : : UNO_QUERY_THROW ) ;
// get the www-standard container ( maybe we should access the
// 'www-standard' by name rather than index, this seems an
// implementation detail
2010-09-17 13:52:02 +02:00
if ( xIndexAccess - > hasElements ( ) )
xFormControls . set ( xIndexAccess - > getByIndex ( 0 ) , uno : : UNO_QUERY ) ;
2009-02-13 13:03:24 +00:00
2007-12-07 10:06:55 +00:00
}
catch ( uno : : Exception & )
{
}
2009-02-13 13:03:24 +00:00
return xFormControls ;
2007-04-25 15:14:08 +00:00
2009-02-13 13:03:24 +00:00
}
: : sal_Bool SAL_CALL
ScVbaWorksheet : : hasProperty ( const : : rtl : : OUString & aName ) throw ( uno : : RuntimeException )
{
uno : : Reference < container : : XNameAccess > xFormControls ( getFormControls ( ) ) ;
if ( xFormControls . is ( ) )
return xFormControls - > hasByName ( aName ) ;
2011-03-10 16:55:21 -05:00
return false ;
2007-04-25 15:14:08 +00:00
}
2007-12-07 10:06:55 +00:00
uno : : Any
ScVbaWorksheet : : getControlShape ( const : : rtl : : OUString & sName )
{
2009-02-13 13:03:24 +00:00
// ideally we would get an XControl object but it appears an XControl
// implementation only exists for a Control implementation optained from the
// view ( e.g. in basic you would get this from
// thiscomponent.currentcontroller.getControl( controlModel ) )
// and the thing to realise is that it is only possible to get an XControl
// for a currently displayed control :-( often we would want to modify
// a control not on the active sheet. But.. you can always access the
// XControlShape from the DrawPage whether that is the active drawpage or not
uno : : Reference < drawing : : XDrawPageSupplier > xDrawPageSupplier ( getSheet ( ) , uno : : UNO_QUERY_THROW ) ;
uno : : Reference < container : : XIndexAccess > xIndexAccess ( xDrawPageSupplier - > getDrawPage ( ) , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
sal_Int32 nCount = xIndexAccess - > getCount ( ) ;
for ( int index = 0 ; index < nCount ; index + + )
{
uno : : Any aUnoObj = xIndexAccess - > getByIndex ( index ) ;
2009-02-13 13:03:24 +00:00
// It seems there are some drawing objects that can not query into Control shapes?
uno : : Reference < drawing : : XControlShape > xControlShape ( aUnoObj , uno : : UNO_QUERY ) ;
if ( xControlShape . is ( ) )
{
uno : : Reference < container : : XNamed > xNamed ( xControlShape - > getControl ( ) , uno : : UNO_QUERY_THROW ) ;
2007-12-07 10:06:55 +00:00
if ( sName . equals ( xNamed - > getName ( ) ) )
{
return aUnoObj ;
}
2009-02-13 13:03:24 +00:00
}
2007-12-07 10:06:55 +00:00
}
return uno : : Any ( ) ;
}
2012-03-24 14:00:06 +00:00
rtl : : OUString
2007-12-07 10:06:55 +00:00
ScVbaWorksheet : : getServiceImplName ( )
{
2013-03-19 09:22:44 +01:00
return rtl : : OUString ( " ScVbaWorksheet " ) ;
2007-12-07 10:06:55 +00:00
}
2012-03-24 14:00:06 +00:00
2007-12-07 10:06:55 +00:00
void SAL_CALL
ScVbaWorksheet : : setEnableCalculation ( : : sal_Bool bEnableCalculation ) throw ( script : : BasicErrorException , uno : : RuntimeException )
{
uno : : Reference < sheet : : XCalculatable > xCalculatable ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
xCalculatable - > enableAutomaticCalculation ( bEnableCalculation ) ;
}
: : sal_Bool SAL_CALL
ScVbaWorksheet : : getEnableCalculation ( ) throw ( css : : script : : BasicErrorException , css : : uno : : RuntimeException )
{
uno : : Reference < sheet : : XCalculatable > xCalculatable ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
return xCalculatable - > isAutomaticCalculationEnabled ( ) ;
}
uno : : Sequence < rtl : : OUString >
ScVbaWorksheet : : getServiceNames ( )
{
static uno : : Sequence < rtl : : OUString > aServiceNames ;
if ( aServiceNames . getLength ( ) = = 0 )
{
aServiceNames . realloc ( 1 ) ;
2013-03-19 09:22:44 +01:00
aServiceNames [ 0 ] = rtl : : OUString ( " ooo.vba.excel.Worksheet " ) ;
2007-12-07 10:06:55 +00:00
}
return aServiceNames ;
}
rtl : : OUString SAL_CALL
ScVbaWorksheet : : getCodeName ( ) throw ( css : : uno : : RuntimeException )
{
2010-06-15 20:02:53 +02:00
uno : : Reference < beans : : XPropertySet > xSheetProp ( mxSheet , uno : : UNO_QUERY_THROW ) ;
2013-03-19 09:22:44 +01:00
return xSheetProp - > getPropertyValue ( : : rtl : : OUString ( " CodeName " ) ) . get < : : rtl : : OUString > ( ) ;
2007-12-07 10:06:55 +00:00
}
2007-04-25 15:14:08 +00:00
2007-12-07 10:06:55 +00:00
sal_Int16
ScVbaWorksheet : : getSheetID ( ) throw ( uno : : RuntimeException )
{
2012-09-11 08:48:02 +01:00
uno : : Reference < sheet : : XCellRangeAddressable > xAddressable ( mxSheet , uno : : UNO_QUERY_THROW ) ; // if ActiveSheet, mxSheet is null.
2007-12-07 10:06:55 +00:00
return xAddressable - > getRangeAddress ( ) . Sheet ;
}
2007-04-25 15:14:08 +00:00
2009-02-13 13:03:24 +00:00
void SAL_CALL
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 )
{
sal_Int32 nTo = 0 ;
sal_Int32 nFrom = 0 ;
sal_Int16 nCopies = 1 ;
2011-03-10 16:55:21 -05:00
sal_Bool bCollate = false ;
sal_Bool bSelection = false ;
sal_Bool bIgnorePrintAreas = false ;
2009-02-13 13:03:24 +00:00
From > > = nFrom ;
To > > = nTo ;
Copies > > = nCopies ;
IgnorePrintAreas > > = bIgnorePrintAreas ;
if ( nCopies > 1 ) // Collate only useful when more that 1 copy
Collate > > = bCollate ;
if ( ! ( nFrom | | nTo ) )
bSelection = sal_True ;
uno : : Reference < frame : : XModel > xModel ( getModel ( ) , uno : : UNO_QUERY_THROW ) ;
2009-09-18 15:24:22 +00:00
PrintOutHelper ( excel : : getBestViewShell ( xModel ) , From , To , Copies , Preview , ActivePrinter , PrintToFile , Collate , PrToFileName , bSelection ) ;
2009-02-13 13:03:24 +00:00
}
2011-04-07 17:14:41 +01:00
sal_Int64 SAL_CALL
ScVbaWorksheet : : getSomething ( const uno : : Sequence < sal_Int8 > & rId ) throw ( uno : : RuntimeException )
{
if ( rId . getLength ( ) = = 16 & &
2012-07-28 20:34:39 +02:00
0 = = memcmp ( ScVbaWorksheet : : getUnoTunnelId ( ) . getConstArray ( ) , rId . getConstArray ( ) , 16 ) )
2011-04-07 17:14:41 +01:00
{
return sal : : static_int_cast < sal_Int64 > ( reinterpret_cast < sal_IntPtr > ( this ) ) ;
}
return 0 ;
}
2007-12-07 10:06:55 +00:00
namespace worksheet
{
namespace sdecl = comphelper : : service_decl ;
sdecl : : vba_service_class_ < ScVbaWorksheet , sdecl : : with_args < true > > serviceImpl ;
extern sdecl : : ServiceDecl const serviceDecl (
serviceImpl ,
" ScVbaWorksheet " ,
2009-02-13 13:03:24 +00:00
" ooo.vba.excel.Worksheet " ) ;
2007-12-07 10:06:55 +00:00
}
2010-10-12 15:59:00 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */