diff options
Diffstat (limited to 'sc/source/ui/vba')
328 files changed, 40513 insertions, 0 deletions
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx new file mode 100644 index 000000000000..3ca5ba861dc8 --- /dev/null +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -0,0 +1,437 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <docuno.hxx> +#include "excelvbahelper.hxx" +#include "tabvwsh.hxx" +#include "transobj.hxx" +#include "scmod.hxx" +#include "cellsuno.hxx" +#include "compiler.hxx" +#include "token.hxx" +#include "tokenarray.hxx" +#include <comphelper/processfactory.hxx> +#include <com/sun/star/sheet/XSheetCellRange.hpp> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +namespace ooo +{ +namespace vba +{ +namespace excel +{ + +uno::Reference< sheet::XDatabaseRanges > +GetDataBaseRanges( ScDocShell* pShell ) throw ( uno::RuntimeException ) +{ + uno::Reference< frame::XModel > xModel; + if ( pShell ) + xModel.set( pShell->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xModelProps( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XDatabaseRanges > xDBRanges( xModelProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DatabaseRanges") ) ), uno::UNO_QUERY_THROW ); + return xDBRanges; +} + +// returns the XDatabaseRange for the autofilter on sheet (nSheet) +// also populates sName with the name of range +uno::Reference< sheet::XDatabaseRange > +GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName ) throw ( uno::RuntimeException ) +{ + uno::Reference< container::XIndexAccess > xIndexAccess( GetDataBaseRanges( pShell ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XDatabaseRange > xDataBaseRange; + table::CellRangeAddress dbAddress; + for ( sal_Int32 index=0; index < xIndexAccess->getCount(); ++index ) + { + uno::Reference< sheet::XDatabaseRange > xDBRange( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNamed > xNamed( xDBRange, uno::UNO_QUERY_THROW ); + // autofilters work weirdly with openoffice, unnamed is the default + // named range which is used to create an autofilter, but + // its also possible that another name could be used + // this also causes problems when an autofilter is created on + // another sheet + // ( but.. you can use any named range ) + dbAddress = xDBRange->getDataArea(); + if ( dbAddress.Sheet == nSheet ) + { + sal_Bool bHasAuto = sal_False; + uno::Reference< beans::XPropertySet > xProps( xDBRange, uno::UNO_QUERY_THROW ); + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ) ) >>= bHasAuto; + if ( bHasAuto ) + { + sName = xNamed->getName(); + xDataBaseRange=xDBRange; + break; + } + } + } + return xDataBaseRange; +} + +ScDocShell* GetDocShellFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException ) +{ + ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xRange ); + if ( !pScCellRangesBase ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying doc shell uno range object" ) ), uno::Reference< uno::XInterface >() ); + } + return pScCellRangesBase->GetDocShell(); +} + +ScDocShell* GetDocShellFromRanges( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException ) +{ + // need the ScCellRangesBase to get docshell + uno::Reference< uno::XInterface > xIf( xRanges, uno::UNO_QUERY_THROW ); + return GetDocShellFromRange( xIf ); +} + +ScDocument* GetDocumentFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException ) +{ + ScDocShell* pDocShell = GetDocShellFromRange( xRange ); + if ( !pDocShell ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying document from uno range object" ) ), uno::Reference< uno::XInterface >() ); + } + return pDocShell->GetDocument(); +} + +uno::Reference< frame::XModel > GetModelFromRange( const uno::Reference< uno::XInterface >& xRange ) throw ( uno::RuntimeException ) +{ + ScDocShell* pDocShell = GetDocShellFromRange( xRange ); + if ( !pDocShell ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying model uno range object" ) ), uno::Reference< uno::XInterface >() ); + } + return pDocShell->GetModel(); +} + +void implSetZoom( const uno::Reference< frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs ) +{ + ScTabViewShell* pViewSh = excel::getBestViewShell( xModel ); + Fraction aFract( nZoom, 100 ); + pViewSh->GetViewData()->SetZoom( aFract, aFract, nTabs ); + pViewSh->RefreshZoom(); +} +bool isInPrintPreview( SfxViewFrame* pView ) +{ + sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0; + if ( pView->GetObjectShell()->GetFactory().GetViewFactoryCount() > +nViewNo && !pView->GetObjectShell()->IsInPlaceActive() ) + { + SfxViewFactory &rViewFactory = + pView->GetObjectShell()->GetFactory().GetViewFactory(nViewNo); + if ( pView->GetCurViewId() == rViewFactory.GetOrdinal() ) + return true; + } + return false; +} + +const ::rtl::OUString REPLACE_CELLS_WARNING( RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning")); + +class PasteCellsWarningReseter +{ +private: + bool bInitialWarningState; + static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException ) + { + static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + static uno::Reference<lang::XMultiComponentFactory > xServiceManager( + xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW ); + return xProps; + } + + bool getReplaceCellsWarning() throw ( uno::RuntimeException ) + { + sal_Bool res = sal_False; + getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING ) >>= res; + return ( res == sal_True ); + } + + void setReplaceCellsWarning( bool bState ) throw ( uno::RuntimeException ) + { + getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING, uno::makeAny( bState ) ); + } +public: + PasteCellsWarningReseter() throw ( uno::RuntimeException ) + { + bInitialWarningState = getReplaceCellsWarning(); + if ( bInitialWarningState ) + setReplaceCellsWarning( false ); + } + ~PasteCellsWarningReseter() + { + if ( bInitialWarningState ) + { + // don't allow dtor to throw + try + { + setReplaceCellsWarning( true ); + } + catch ( uno::Exception& /*e*/ ){} + } + } +}; + +void +implnPaste( const uno::Reference< frame::XModel>& xModel ) +{ + PasteCellsWarningReseter resetWarningBox; + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + if ( pViewShell ) + { + pViewShell->PasteFromSystem(); + pViewShell->CellContentChanged(); + } +} + + +void +implnCopy( const uno::Reference< frame::XModel>& xModel ) +{ + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + if ( pViewShell ) + pViewShell->CopyToClip(NULL,false,false,true); +} + +void +implnCut( const uno::Reference< frame::XModel>& xModel ) +{ + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + if ( pViewShell ) + pViewShell->CutToClip( NULL, TRUE ); +} + +void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose) +{ + PasteCellsWarningReseter resetWarningBox; + sal_Bool bAsLink(sal_False), bOtherDoc(sal_False); + InsCellCmd eMoveMode = INS_NONE; + + ScTabViewShell* pTabViewShell = getBestViewShell( xModel ); + if ( pTabViewShell ) + { + ScViewData* pView = pTabViewShell->GetViewData(); + Window* pWin = ( pView != NULL ) ? pView->GetActiveWin() : NULL; + if ( pView && pWin ) + { + if ( bAsLink && bOtherDoc ) + pTabViewShell->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK + else + { + ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin ); + ScDocument* pDoc = NULL; + if ( pOwnClip ) + pDoc = pOwnClip->GetDocument(); + pTabViewShell->PasteFromClip( nFlags, pDoc, + nFunction, bSkipEmpty, bTranspose, bAsLink, + eMoveMode, IDF_NONE, TRUE ); + pTabViewShell->CellContentChanged(); + } + } + } + +} + +void implnCopyRange( const uno::Reference< frame::XModel>& xModel, const ScRange& rRange ) +{ + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + if ( pViewShell ) + { + pViewShell->CopyToClip( NULL, rRange, FALSE, TRUE, TRUE ); + } +} + +ScDocShell* +getDocShell( const css::uno::Reference< css::frame::XModel>& xModel ) +{ + uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW ); + ScModelObj* pModel = dynamic_cast< ScModelObj* >( xIf.get() ); + ScDocShell* pDocShell = NULL; + if ( pModel ) + pDocShell = (ScDocShell*)pModel->GetEmbeddedObject(); + return pDocShell; + +} + +ScTabViewShell* +getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel ) +{ + ScDocShell* pDocShell = getDocShell( xModel ); + if ( pDocShell ) + return pDocShell->GetBestViewShell(); + return NULL; +} + +ScTabViewShell* +getCurrentBestViewShell( const uno::Reference< uno::XComponentContext >& xContext ) +{ + uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext ); + return getBestViewShell( xModel ); +} + +SfxViewFrame* +getViewFrame( const uno::Reference< frame::XModel >& xModel ) +{ + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + if ( pViewShell ) + return pViewShell->GetViewFrame(); + return NULL; +} + +sal_Bool IsR1C1ReferFormat( ScDocument* pDoc, const rtl::OUString& sRangeStr ) +{ + ScRangeList aCellRanges; + String sAddress( sRangeStr ); + USHORT nMask = SCA_VALID; + USHORT rResFlags = aCellRanges.Parse( sAddress, pDoc, nMask, formula::FormulaGrammar::CONV_XL_R1C1 ); + if ( rResFlags & SCA_VALID ) + { + return sal_True; + } + return sal_False; +} + +uno::Reference< XHelperInterface > +getUnoSheetModuleObj( const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) +{ + uno::Reference< sheet::XSheetCellRange > xSheetRange( xRange, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xSheetRange->getSpreadsheet(), uno::UNO_QUERY_THROW ); + rtl::OUString sCodeName; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CodeName") ) ) >>= sCodeName; + // #TODO #FIXME ideally we should 'throw' here if we don't get a valid parent, but... it is possible + // to create a module ( and use 'Option VBASupport 1' ) for a calc document, in this scenario there + // are *NO* special document module objects ( of course being able to switch between vba/non vba mode at + // the document in the future could fix this, especially IF the switching of the vba mode takes care to + // create the special document module objects if they don't exist. + uno::Reference< XHelperInterface > xParent( ov::getUnoDocModule( sCodeName, GetDocShellFromRange( xRange ) ), uno::UNO_QUERY ); + + return xParent; +} + +formula::FormulaGrammar::Grammar GetFormulaGrammar( ScDocument* pDoc, const ScAddress& sAddress, const css::uno::Any& aFormula ) +{ + formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_NATIVE_XL_A1; + if ( pDoc && aFormula.hasValue() && aFormula.getValueTypeClass() == uno::TypeClass_STRING ) + { + rtl::OUString sFormula; + aFormula >>= sFormula; + + ScCompiler aCompiler( pDoc, sAddress ); + aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); + ScTokenArray* pCode = aCompiler.CompileString( sFormula ); + if ( pCode ) + { + USHORT nLen = pCode->GetLen(); + formula::FormulaToken** pTokens = pCode->GetArray(); + for ( USHORT nPos = 0; nPos < nLen; nPos++ ) + { + const formula::FormulaToken& rToken = *pTokens[nPos]; + switch ( rToken.GetType() ) + { + case formula::svSingleRef: + case formula::svDoubleRef: + { + return formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1; + } + break; + default: break; + } + } + } + } + return eGrammar; +} + +void CompileExcelFormulaToODF( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula ) +{ + if ( !pDoc ) + { + return; + } + ScCompiler aCompiler( pDoc, ScAddress() ); + aCompiler.SetGrammar( excel::GetFormulaGrammar( pDoc, ScAddress(), uno::Any( rtl::OUString( rOldFormula ) ) ) ); + ScTokenArray* pCode = aCompiler.CompileString( rOldFormula ); + aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 ); + aCompiler.CreateStringFromTokenArray( rNewFormula ); +} + +void CompileODFFormulaToExcel( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula, const formula::FormulaGrammar::Grammar eGrammar ) +{ + // eGrammar can be formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 and formula::FormulaGrammar::GRAM_NATIVE_XL_A1 + if ( !pDoc ) + { + return; + } + ScCompiler aCompiler( pDoc, ScAddress() ); + aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 ); + ScTokenArray* pCode = aCompiler.CompileString( rOldFormula ); + aCompiler.SetGrammar( eGrammar ); + if ( !pCode ) + { + return; + } + USHORT nLen = pCode->GetLen(); + formula::FormulaToken** pTokens = pCode->GetArray(); + for ( USHORT nPos = 0; nPos < nLen && pTokens[nPos]; nPos++ ) + { + String rFormula; + formula::FormulaToken* pToken = pTokens[nPos]; + aCompiler.CreateStringFromToken( rFormula, pToken, TRUE ); + if ( pToken->GetOpCode() == ocSep ) + { + // Excel formula separator is ",". + rFormula = String::CreateFromAscii(","); + } + rNewFormula += rFormula; + } +} + +uno::Reference< XHelperInterface > +getUnoSheetModuleObj( const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges ) throw ( uno::RuntimeException ) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( xRanges, uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration(); + uno::Reference< table::XCellRange > xRange( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + + return getUnoSheetModuleObj( xRange ); +} + +SfxItemSet* +ScVbaCellRangeAccess::GetDataSet( ScCellRangesBase* pRangeObj ) +{ + return pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : 0; +} + + +} //excel +} //vba +} //ooo + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx new file mode 100644 index 000000000000..bdab4fd28ddb --- /dev/null +++ b/sc/source/ui/vba/excelvbahelper.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_EXCEL_VBA_HELPER_HXX +#define SC_EXCEL_VBA_HELPER_HXX + +#include<vbahelper/vbahelper.hxx> +#include <docsh.hxx> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> +#include <ooo/vba/XHelperInterface.hpp> +#include <formula/grammar.hxx> + +class ScCellRangesBase; + +namespace ooo +{ + namespace vba + { + namespace excel + { + // nTabs empty means apply zoom to all sheets + void implSetZoom( const css::uno::Reference< css::frame::XModel >& xModel, sal_Int16 nZoom, std::vector< SCTAB >& nTabs ); + void implnCopy( const css::uno::Reference< css::frame::XModel>& xModel ); + void implnPaste ( const css::uno::Reference< css::frame::XModel>& xModel ); + void implnCut( const css::uno::Reference< css::frame::XModel>& xModel ); + void implnPasteSpecial( const css::uno::Reference< css::frame::XModel>& xModel, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose); + void implnCopyRange( const css::uno::Reference< css::frame::XModel>& xModel, const ScRange& rRange ); + ScTabViewShell* getBestViewShell( const css::uno::Reference< css::frame::XModel>& xModel ) ; + ScDocShell* getDocShell( const css::uno::Reference< css::frame::XModel>& xModel ) ; + ScTabViewShell* getCurrentBestViewShell( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + SfxViewFrame* getViewFrame( const css::uno::Reference< css::frame::XModel >& xModel ); + sal_Bool IsR1C1ReferFormat( ScDocument* pDoc, const ::rtl::OUString& sRangeStr ); + formula::FormulaGrammar::Grammar GetFormulaGrammar( ScDocument* pDoc, const ScAddress& sAddress, const css::uno::Any& aFormula ); + void CompileExcelFormulaToODF( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula ); + void CompileODFFormulaToExcel( ScDocument* pDoc, const String& rOldFormula, String& rNewFormula, const formula::FormulaGrammar::Grammar eGrammar ); + css::uno::Reference< css::sheet::XDatabaseRanges > GetDataBaseRanges( ScDocShell* pShell ) throw ( css::uno::RuntimeException ); + + css::uno::Reference< css::sheet::XDatabaseRange > GetAutoFiltRange( ScDocShell* pShell, sal_Int16 nSheet, rtl::OUString& sName ) throw ( css::uno::RuntimeException ); + css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException ); + css::uno::Reference< ooo::vba::XHelperInterface > getUnoSheetModuleObj( const css::uno::Reference< css::table::XCellRange >& xRange ) throw ( css::uno::RuntimeException ); + ScDocShell* GetDocShellFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); + ScDocShell* GetDocShellFromRanges( const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges ) throw ( css::uno::RuntimeException ); + ScDocument* GetDocumentFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); + css::uno::Reference< css::frame::XModel > GetModelFromRange( const css::uno::Reference< css::uno::XInterface >& xRange ) throw ( css::uno::RuntimeException ); + + class ScVbaCellRangeAccess + { + public: + static SfxItemSet* GetDataSet( ScCellRangesBase* pRangeObj ); + }; + } + } +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/helperdecl.hxx b/sc/source/ui/vba/helperdecl.hxx new file mode 100644 index 000000000000..4a0d0d3c01c6 --- /dev/null +++ b/sc/source/ui/vba/helperdecl.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <comphelper/servicedecl.hxx> +#include <ooo/vba/XHelperInterface.hpp> + +namespace comphelper { +namespace service_decl { +template <typename ImplT_, typename WithArgsT = with_args<false> > +struct vba_service_class_ : public serviceimpl_base< detail::OwnServiceImpl<ImplT_>, WithArgsT > +{ + typedef serviceimpl_base< detail::OwnServiceImpl<ImplT_>, WithArgsT > baseT; + /** Default ctor. Implementation class without args, expecting + component context as single argument. + */ + vba_service_class_() : baseT() {} + template <typename PostProcessFuncT> + /** Ctor to pass a post processing function/functor. + + @tpl PostProcessDefaultT let your compiler deduce this + @param postProcessFunc function/functor that gets the yet unacquired + ImplT_ pointer returning a + uno::Reference<uno::XInterface> + */ + explicit vba_service_class_( PostProcessFuncT const& postProcessFunc ) : baseT( postProcessFunc ) {} +}; + +} // namespace service_decl +} // namespace comphelper + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/makefile.mk b/sc/source/ui/vba/makefile.mk new file mode 100644 index 000000000000..ba50cbad9abd --- /dev/null +++ b/sc/source/ui/vba/makefile.mk @@ -0,0 +1,136 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/.. + +PRJNAME=sc +TARGET=vbaobj +ENABLE_EXCEPTIONS=TRUE +VISIBILITY_HIDDEN=TRUE +CDEFS+=-DVBA_OOBUILD_HACK +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +.IF "$(ENABLE_VBA)"!="YES" +dummy: + @echo "not building vba..." +.ENDIF +.IF "$(L10N_framework)"=="" +INCPRE=$(INCCOM)$/$(TARGET) + +# ------------------------------------------------------------------ + +SLOFILES= \ + $(SLO)$/excelvbahelper.obj \ + $(SLO)$/service.obj \ + $(SLO)$/vbaapplication.obj \ + $(SLO)$/vbaassistant.obj \ + $(SLO)$/vbaaxes.obj \ + $(SLO)$/vbaaxis.obj \ + $(SLO)$/vbaaxistitle.obj \ + $(SLO)$/vbaborders.obj \ + $(SLO)$/vbacharacters.obj \ + $(SLO)$/vbachart.obj \ + $(SLO)$/vbachartobject.obj \ + $(SLO)$/vbachartobjects.obj \ + $(SLO)$/vbacharts.obj \ + $(SLO)$/vbacharttitle.obj \ + $(SLO)$/vbacomment.obj \ + $(SLO)$/vbacomments.obj \ + $(SLO)$/vbacommentshape.obj \ + $(SLO)$/vbacondition.obj \ + $(SLO)$/vbadialog.obj \ + $(SLO)$/vbadialogs.obj \ + $(SLO)$/vbaeventshelper.obj \ + $(SLO)$/vbafiledialog.obj \ + $(SLO)$/vbafiledialogselecteditems.obj \ + $(SLO)$/vbafilesearch.obj \ + $(SLO)$/vbafont.obj \ + $(SLO)$/vbaformat.obj \ + $(SLO)$/vbaformatcondition.obj \ + $(SLO)$/vbaformatconditions.obj \ + $(SLO)$/vbafoundfiles.obj \ + $(SLO)$/vbaglobals.obj \ + $(SLO)$/vbahyperlink.obj \ + $(SLO)$/vbahyperlinks.obj \ + $(SLO)$/vbainterior.obj \ + $(SLO)$/vbamenubar.obj \ + $(SLO)$/vbamenubars.obj \ + $(SLO)$/vbamenu.obj \ + $(SLO)$/vbamenus.obj \ + $(SLO)$/vbamenuitem.obj \ + $(SLO)$/vbamenuitems.obj \ + $(SLO)$/vbaname.obj \ + $(SLO)$/vbanames.obj \ + $(SLO)$/vbaoleobject.obj \ + $(SLO)$/vbaoleobjects.obj \ + $(SLO)$/vbaoutline.obj \ + $(SLO)$/vbapagebreak.obj \ + $(SLO)$/vbapagebreaks.obj \ + $(SLO)$/vbapagesetup.obj \ + $(SLO)$/vbapalette.obj \ + $(SLO)$/vbapane.obj \ + $(SLO)$/vbapivotcache.obj \ + $(SLO)$/vbapivottable.obj \ + $(SLO)$/vbapivottables.obj \ + $(SLO)$/vbaquerytable.obj \ + $(SLO)$/vbarange.obj \ + $(SLO)$/vbaseriescollection.obj \ + $(SLO)$/vbasheetobject.obj \ + $(SLO)$/vbasheetobjects.obj \ + $(SLO)$/vbastyle.obj \ + $(SLO)$/vbastyles.obj \ + $(SLO)$/vbatextboxshape.obj \ + $(SLO)$/vbatextframe.obj \ + $(SLO)$/vbavalidation.obj \ + $(SLO)$/vbawindow.obj \ + $(SLO)$/vbawindows.obj \ + $(SLO)$/vbaworkbook.obj \ + $(SLO)$/vbaworkbooks.obj \ + $(SLO)$/vbaworksheet.obj \ + $(SLO)$/vbaworksheets.obj \ + $(SLO)$/vbawsfunction.obj + +.ENDIF +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +.IF "$(L10N_framework)"=="" + +ALLTAR : \ + $(MISC)$/$(TARGET).don \ + +$(SLOFILES) : $(MISC)$/$(TARGET).don + +$(MISC)$/$(TARGET).don : $(SOLARBINDIR)$/oovbaapi.rdb + +$(CPPUMAKER) -O$(INCCOM)$/$(TARGET) -BUCR $(SOLARBINDIR)$/oovbaapi.rdb -X$(SOLARBINDIR)$/types.rdb && echo > $@ + echo $@ + +.ENDIF diff --git a/sc/source/ui/vba/service.cxx b/sc/source/ui/vba/service.cxx new file mode 100644 index 000000000000..875424fc54ea --- /dev/null +++ b/sc/source/ui/vba/service.cxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "cppuhelper/implementationentry.hxx" +#include "com/sun/star/lang/XMultiServiceFactory.hpp" +#include "com/sun/star/registry/XRegistryKey.hpp" +#include "comphelper/servicedecl.hxx" + +// ============================================================================= +// component exports +// ============================================================================= +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace sdecl = comphelper::service_decl; + +// reference service helper(s) +namespace range +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace workbook +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace worksheet +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace window +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace globals +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace hyperlink +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace application +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace vbaeventshelper +{ +extern sdecl::ServiceDecl const serviceDecl; +} +namespace textframe +{ +extern sdecl::ServiceDecl const serviceDecl; +} + +extern "C" +{ + SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) + { + OSL_TRACE("In component_getImplementationEnv"); + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo( + lang::XMultiServiceFactory * pServiceManager, registry::XRegistryKey * pRegistryKey ) + { + OSL_TRACE("In component_writeInfo"); +#if 0 + // Component registration + if ( component_writeInfoHelper( pServiceManager, pRegistryKey, + range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl ) && component_writeInfoHelper( pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl ) ) + { + // Singleton registration + try + { + registry::XRegistryKey * pKey = + reinterpret_cast< registry::XRegistryKey * >(pRegistryKey); + + Reference< registry::XRegistryKey >xKey = pKey->createKey( + rtl::OUString::createFromAscii( ("ooo.vba.Globals/UNO/SINGLETONS/ooo.vba.theGlobals") ) ); + xKey->setStringValue( ::rtl::OUString::createFromAscii( + ("ooo.vba.Globals") ) ); + return sal_True; + } + catch( uno::Exception& /*e*/ ) + { + //recomp & friends will detect false returned and fail + } + } + return sal_False; +#else + // Component registration + return component_writeInfoHelper( pServiceManager, pRegistryKey, + range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl ) && component_writeInfoHelper( pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl, textframe::serviceDecl ); +#endif + + } + + SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) + { + OSL_TRACE("In component_getFactory for %s", pImplName ); + void* pRet = component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl ); + if( !pRet ) + pRet = component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl, textframe::serviceDecl ); + OSL_TRACE("Ret is 0x%x", pRet); + return pRet; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/testvba/README b/sc/source/ui/vba/testvba/README new file mode 100644 index 000000000000..3a91946de8df --- /dev/null +++ b/sc/source/ui/vba/testvba/README @@ -0,0 +1,37 @@ +to run the tests + +build +===== + dmake + +windows +======= + a) you can download a cygwin bash shell environment and install perl ( http://cygwin.com/setup.exe ) + from the cmdline './runTests.pl $(OFFICE_PROGRAM_PATH)' should run the testclient and compare the logs + b) use ordinary windows perl [1], but additionally you will need the 'diff' program for window ( download from http://gnuwin32.sourceforge.net/packages/diffutils.htm ) + +[1] for the testclient the perl ( all inclusive ) bundle from ActivePerl is mor e than adeqate ( download from http://downloads.activestate.com/ActivePerl/Windows/5.8/ActivePerl-5.8.8.822-MSWin32-x86-280952.msi ) + + to run all test cases type + 'perl ./runTests.pl $(OFFICE_PROGRAM_PATH)' + to run a test case type + 'perl ./runTests.pl $(OFFICE_PROGRAM_PATH) testfilename' + +unix +==== + +assuming perl is installed + './runTests.pl $(OFFICE_PROGRAM_PATH)' + or './runTests.pl $(OFFICE_PROGRAM_PATH) testfilename' for one file test. + + +Note: For either windows or unix all of the tests should pass ( and you should get a result like ) +Note Also: If you meat a problem that stop running test after serveral test documents have been run. please clean your .ooo-2.0 or .oooxxx first, and then re-run. + +========> + +skipped 0 test-cases(s) +compared 9 test-case documents + 9 tests passedTests + +Note also: the testclient will attempt to connect to an existing instance of open-office, when the testClient exits the soffice process may still be running, if you wish to repeat tests you may want to kill the office instance before re-running. diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/ApplicationRunTest.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/ApplicationRunTest.xls Binary files differnew file mode 100644 index 000000000000..a5a591c1f849 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/ApplicationRunTest.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/AutoFilter.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/AutoFilter.xls Binary files differnew file mode 100644 index 000000000000..9b3a1043c5ee --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/AutoFilter.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/CalcFont.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/CalcFont.xls Binary files differnew file mode 100644 index 000000000000..9ddb69600643 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/CalcFont.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/CalcZoom.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/CalcZoom.xls Binary files differnew file mode 100644 index 000000000000..5db47c76dbe9 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/CalcZoom.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/FinancialFuncTests.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/FinancialFuncTests.xls Binary files differnew file mode 100644 index 000000000000..d4776b98fe1d --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/FinancialFuncTests.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/FinancialFuncs.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/FinancialFuncs.xls Binary files differnew file mode 100644 index 000000000000..bb8941809947 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/FinancialFuncs.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/MiscOperatorTests.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/MiscOperatorTests.xls Binary files differnew file mode 100644 index 000000000000..23227ae37e24 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/MiscOperatorTests.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/MiscRangeTests.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/MiscRangeTests.xls Binary files differnew file mode 100644 index 000000000000..ebd9e91b5b28 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/MiscRangeTests.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/PageBreaks.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/PageBreaks.xls Binary files differnew file mode 100644 index 000000000000..b6651fa5d617 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/PageBreaks.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges-2.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges-2.xls Binary files differnew file mode 100644 index 000000000000..f6e81cf933fd --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges-2.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges-3.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges-3.xls Binary files differnew file mode 100644 index 000000000000..8722f6d3057e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges-3.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges.xls Binary files differnew file mode 100644 index 000000000000..1c1d74d37486 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Ranges.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Shapes.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Shapes.xls Binary files differnew file mode 100644 index 000000000000..254f3c97756c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Shapes.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/StrConv-test.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/StrConv-test.xls Binary files differnew file mode 100644 index 000000000000..198abbec5871 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/StrConv-test.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Template.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Template.xls Binary files differnew file mode 100644 index 000000000000..4387231fe744 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Template.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestAddress.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestAddress.xls Binary files differnew file mode 100644 index 000000000000..48d30cbe2e9e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestAddress.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestCalc_Rangetest.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestCalc_Rangetest.xls Binary files differnew file mode 100644 index 000000000000..a497d4f10f3e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestCalc_Rangetest.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestCalc_Rangetest2.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestCalc_Rangetest2.xls Binary files differnew file mode 100644 index 000000000000..34c606fc28f5 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestCalc_Rangetest2.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestIntersection.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestIntersection.xls Binary files differnew file mode 100644 index 000000000000..24f88db87ccc --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestIntersection.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestUnion.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestUnion.xls Binary files differnew file mode 100644 index 000000000000..5b8f0968cf38 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/TestUnion.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/VariantTest.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/VariantTest.xls Binary files differnew file mode 100644 index 000000000000..f604cfbe3975 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/VariantTest.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Window.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Window.xls Binary files differnew file mode 100644 index 000000000000..6fb6963c2f31 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/Window.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/bytearraystring.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/bytearraystring.xls Binary files differnew file mode 100644 index 000000000000..471bbc349e5b --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/bytearraystring.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/dateserial.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/dateserial.xls Binary files differnew file mode 100644 index 000000000000..768fb513eba4 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/dateserial.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/datevalue.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/datevalue.xls Binary files differnew file mode 100644 index 000000000000..852a51d100b8 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/datevalue.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/format.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/format.xls Binary files differnew file mode 100644 index 000000000000..99ed64d38915 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/format.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/AutoFilter.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/AutoFilter.log new file mode 100644 index 000000000000..1fe0cbd01fe5 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/AutoFilter.log @@ -0,0 +1,20 @@ +Test run started : 17/07/2007 17:36:22
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 'starts with' string criteria
+ ITEM Assertion OK : test2 'not equal to' string criteria
+ ITEM Assertion OK : test3 'ends with' string criteria
+ ITEM Assertion OK : test4 field 'all'
+ ITEM Assertion OK : test5 numeric '<15'
+ ITEM Assertion OK : test6 numeric '>=15'
+ ITEM Assertion OK : test7 numeric '<=12'
+Test Results +============ + +Tests passed: 7 +Tests failed: 0 +
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 17/07/2007 17:36:23
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/MiscRangeTests.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/MiscRangeTests.log new file mode 100644 index 000000000000..260465386d07 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/MiscRangeTests.log @@ -0,0 +1,45 @@ +Test run started : 17/07/2007 15:01:37
+----------------------------------------------------------------
+MiscRangeTests
+ TEST START : MiscRangeTests
+ ITEM Assertion OK : test 1
+ ITEM Assertion OK : test 2
+ ITEM Assertion OK : test 3
+ ITEM Assertion OK : test 4
+ ITEM Assertion OK : test 5
+ ITEM Assertion OK : test 6
+ ITEM Assertion OK : test 7
+ ITEM Assertion OK : test 8
+ ITEM Assertion OK : test 9
+ ITEM Assertion OK : test 10
+ ITEM Assertion OK : test 11
+ ITEM Assertion OK : test 12
+ ITEM Assertion OK : test 13
+ ITEM Assertion OK : test 14
+ ITEM Assertion OK : test 15
+ ITEM Assertion OK : test 16
+ ITEM Assertion OK : test 17
+ ITEM Assertion OK : test 18
+ ITEM Assertion OK : test 19
+ ITEM Assertion OK : test 20
+ ITEM Assertion OK : test 21
+ ITEM Assertion OK : test 22
+ ITEM Assertion OK : test 23
+ ITEM Assertion OK : test 24
+ ITEM Assertion OK : test 25
+ ITEM Assertion OK : test 26
+ ITEM Assertion OK : test 27
+ ITEM Assertion OK : test 28
+ ITEM Assertion OK : test 29
+ ITEM Assertion OK : test 30
+ ITEM Assertion OK : test 31
+No. tests: 31 +Summary +======= +Run: 31 +Passed: 31 +Failed: 0 +
+END 'MiscRangeTests
+ TEST OK : MiscRangeTests
+Test run finished : 17/07/2007 15:01:39
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges-2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges-2.log new file mode 100644 index 000000000000..736d5bbc42d0 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges-2.log @@ -0,0 +1,68 @@ +Test run started : 18/06/2007 17:50:04
+----------------------------------------------------------------
+ClearFormtsIssue
+ TEST START : ClearFormtsIssue
+ ITEM Assertion OK : Range.Font.Bold is: True
+ ITEM Assertion OK : Range.Font.Bold is: False
+END 'ClearFormtsIssue' Symbol
+ TEST OK : ClearFormtsIssue
+----------------------------------------------------------------
+VerticalAlignment-Issue
+ TEST START : VerticalAlignment-Issue
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : Range.VeritcalAlignment is Null
+END 'VerticalAlignment-Issue' Symbol
+ TEST OK : VerticalAlignment-Issue
+----------------------------------------------------------------
+HorizontalAlignment-Issue
+ TEST START : HorizontalAlignment-Issue
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : Range.HorizontalAlignment is Null
+END 'HorizontalAlignment-Issue' Symbol
+ TEST OK : HorizontalAlignment-Issue
+----------------------------------------------------------------
+WrapText-Issue
+ TEST START : WrapText-Issue
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : Range.WrapText is Null
+END 'WrapText-Issue' Symbol
+ TEST OK : WrapText-Issue
+----------------------------------------------------------------
+FontBorderIssues
+ TEST START : FontBorderIssues
+ ITEM Assertion OK : - = Borders.Color (getColor)
+ ITEM Assertion OK : - = Font.Color (getColor)
+END 'FontBorderIssues' Symbol
+ TEST OK : FontBorderIssues
+----------------------------------------------------------------
+RangeSizeIssues
+ TEST START : RangeSizeIssues
+ ITEM Assertion OK : Range.Left is: 114
+ ITEM Assertion OK : Range.Top is: 95.25
+ ITEM Assertion OK : Range.Width is: 216
+ ITEM Assertion OK : Range.Height is: 271.5
+END 'RangeSizeIssues' Symbol
+ TEST OK : RangeSizeIssues
+----------------------------------------------------------------
+ApplicationIssues
+ TEST START : ApplicationIssues
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Application.ActiveSheet.Name: Sheet1
+END 'ApplicationIssues' Symbol
+ TEST OK : ApplicationIssues
+Test run finished : 18/06/2007 17:50:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges-3.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges-3.log new file mode 100644 index 000000000000..a7de979d5e13 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges-3.log @@ -0,0 +1,8 @@ +Test run started : 19/06/2007 11:21:42
+----------------------------------------------------------------
+MyGoalseek-Issue
+ TEST START : MyGoalseek-Issue
+ ITEM Assertion OK : Variable Range value: 15
+END 'MyGoalseek-Issue' Symbol
+ TEST OK : MyGoalseek-Issue
+Test run finished : 19/06/2007 11:21:42
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges.log new file mode 100644 index 000000000000..8c9644aac155 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/Ranges.log @@ -0,0 +1,280 @@ +Test run started : 01/06/2007 11:28:58
+----------------------------------------------------------------
+ApplicationMethods
+ TEST START : ApplicationMethods
+ ITEM Assertion OK : Name of Workbook is: Ranges.xls
+ ITEM Assertion OK : Address of Application.Columns is: $A:$A
+ ITEM Assertion OK : Address of Application.Rows is: $1:$1
+ ITEM Assertion OK : Address of Application.Range is: $1:$1,$5:$7
+ ITEM Assertion OK : Please check manually: DefaultFilePath is: C:\Documents and Settings\vituosity\My Documents
+ ITEM Assertion OK : Please check manually: Library Path is: C:\Program Files\Microsoft Office\OFFICE11\LIBRARY
+ ITEM Assertion OK : Please check manually: Template Path is: C:\Documents and Settings\vituosity\Application Data\Microsoft\Templates\
+ ITEM Assertion OK : FileSeparator is \
+ ITEM Assertion OK : Name of ActiveWorkbook is: Ranges.xls
+END 'ApplicationMethods' Symbol
+ TEST OK : ApplicationMethods
+----------------------------------------------------------------
+Insert-Issue
+ TEST START : Insert-Issue
+ ITEM Assertion OK : Insert with xlShiftToRight: 10
+END 'Insert-Issue' Symbol
+ TEST OK : Insert-Issue
+----------------------------------------------------------------
+MergeCells-Issue
+ TEST START : MergeCells-Issue
+ ITEM Assertion OK : Range.MergeCells is True
+ ITEM Assertion OK : MergeCells is null: True
+ ITEM Assertion OK : RowCount after Merge: 6
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion OK : MergeCells of Second Area is null : True
+ ITEM Assertion OK : MergeCells of Ranges is Null: True
+ ITEM Assertion OK : RowCount after Merge: 7
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion OK : RowCount after Merge: 7
+END 'MergeCells-Issue' Symbol
+ TEST OK : MergeCells-Issue
+----------------------------------------------------------------
+Areas-Issue
+ TEST START : Areas-Issue
+ ITEM Assertion OK : Range Areas Count is2
+ ITEM Assertion OK : First Range Address is: $E$8:$G$13
+ ITEM Assertion OK : First Row is: 8
+ ITEM Assertion OK : First Column is: 5
+ ITEM Assertion OK : EntireRow Address is: $8:$13,$13:$19
+ ITEM Assertion OK : EntireColumn Address is: $E:$G,$G:$K
+ ITEM Assertion OK : Range Count:53
+END 'Areas-Issue' Symbol
+ TEST OK : Areas-Issue
+----------------------------------------------------------------
+Fill-Methods-Issue
+ TEST START : Fill-Methods-Issue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyRightFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyBottomFillValue
+END 'Fill-Methods-Issue' Symbol
+ TEST OK : Fill-Methods-Issue
+----------------------------------------------------------------
+Range/Item-Method-Issue
+ TEST START : Range/Item-Method-Issue
+ ITEM Assertion OK : Range of multiple columns is: $A:$A,$C:$C
+ ITEM Assertion OK : Range of multiple rows is: $1:$1,$5:$7
+ ITEM Assertion OK : Range of several columns is: $C:$E,$D:$D
+ ITEM Assertion OK : Range of several rows is: $5:$8,$6:$10
+ ITEM Assertion OK : Range of several single cells is: $C$5,$E$8
+ ITEM Assertion OK : Range of several named ranges is: $L$1:$M$6,$E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range of a single Item Cell is: $E$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$10
+END 'Range/Item-Method-Issue' Symbol
+ TEST OK : Range/Item-Method-Issue
+----------------------------------------------------------------
+R1C1-Formulas-Issue
+ TEST START : R1C1-Formulas-Issue
+ ITEM Assertion OK : R1C1 Range.Formula is: =IF(OR(R[-2]C[1]=0,RC[2]="YES"),"")
+ ITEM Assertion OK : Range.Formula is: =IF(OR(J8=0,K10="YES"),"")
+END 'R1C1-Formulas-Issue' Symbol
+ TEST OK : R1C1-Formulas-Issue
+----------------------------------------------------------------
+Verify_Delete
+ TEST START : Verify_Delete
+ ITEM Assertion OK : Ranges are intersecting: $G$13
+ ITEM Assertion OK : Delete with Default: $AJ$4
+ ITEM Assertion OK : Delete with ShifttoLeft: $AJ$4
+ ITEM Assertion OK : Delete with ShiftUp: $M$22
+END 'Verify_Delete' Symbol
+ TEST OK : Verify_Delete
+----------------------------------------------------------------
+Value-Issue
+ TEST START : Value-Issue
+ ITEM Assertion OK : Value of Range is: 12.3
+ ITEM Assertion OK : Text of Range is: 12.3
+ ITEM Assertion OK : Range has Formula: False
+ ITEM Assertion OK : Cell has Formula: False
+ ITEM Assertion OK : Text of Range is null: True
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Cell has Formula: True
+ ITEM Assertion OK : Value of Cell is: 12
+ ITEM Assertion OK : Application.Calculation is : -4135
+ ITEM Assertion OK : Calculation is automated: True
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Value of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Range has Formula after 'ClearContents: False
+ ITEM Assertion OK : Text of Cell is:
+ ITEM Assertion OK : Text of Cell is:
+END 'Value-Issue' Symbol
+ TEST OK : Value-Issue
+----------------------------------------------------------------
+AutoFit issue
+ TEST START : AutoFit issue
+ ITEM Assertion OK : Columns.AutoFit: CurrentWidth is 673
+ ITEM Assertion OK : Rows.AutoFit: CurrentHeight is 612
+END 'AutoFit issue' Symbol
+ TEST OK : AutoFit issue
+----------------------------------------------------------------
+Selections
+ TEST START : Selections
+ ITEM Assertion OK : ActiveCell is : $E$8
+ ITEM Assertion OK : Active Cell is : $E$8
+ ITEM Assertion OK : Number of Cells in Range: 53
+ ITEM Assertion OK : Number of Cells in Range: 53
+ ITEM Assertion OK : Number of Cells in Range: 53
+END 'Selections' Symbol
+ TEST OK : Selections
+----------------------------------------------------------------
+Offset-Resize
+ TEST START : Offset-Resize
+ ITEM Assertion OK : Offset is : $G$10:$I$15,$I$15:$M$21
+ ITEM Assertion OK : Offset is : $G$7:$I$12,$I$12:$M$18
+ ITEM Assertion OK : Resized Range is : $A$20:$D$23
+END 'Offset-Resize' Symbol
+ TEST OK : Offset-Resize
+----------------------------------------------------------------
+Ranges-Address
+ TEST START : Ranges-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range Address is: $E8:$G13,$G13:$K19
+ ITEM Assertion OK : Range Address is: E$8:G$13,G$13:K$19
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5],R[11]C[5]:R[17]C[9]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13,$G$13:$K$19
+END 'Ranges-Address' Symbol
+ TEST OK : Ranges-Address
+----------------------------------------------------------------
+Range-Address
+ TEST START : Range-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13
+ ITEM Assertion OK : Range Address is: $E8:$G13
+ ITEM Assertion OK : Range Address is: E$8:G$13
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: $E$8:$G$13
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13
+END 'Range-Address' Symbol
+ TEST OK : Range-Address
+----------------------------------------------------------------
+Column-Address
+ TEST START : Column-Address
+ ITEM Assertion OK : Range Address is: $F$8:$F$13
+ ITEM Assertion OK : Range Address is: $F8:$F13
+ ITEM Assertion OK : Range Address is: F$8:F$13
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: $F$8:$F$13
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: R[6]C[4]:R[11]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$8:$F$13
+END 'Column-Address' Symbol
+ TEST OK : Column-Address
+----------------------------------------------------------------
+Row-Address
+ TEST START : Row-Address
+ ITEM Assertion OK : Range Address is: $E$9:$G$9
+ ITEM Assertion OK : Range Address is: $E9:$G9
+ ITEM Assertion OK : Range Address is: E$9:G$9
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: $E$9:$G$9
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: R[7]C[3]:R[7]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$9:$G$9
+END 'Row-Address' Symbol
+ TEST OK : Row-Address
+----------------------------------------------------------------
+SingleCell-Address
+ TEST START : SingleCell-Address
+ ITEM Assertion OK : Range Address is: $F$9
+ ITEM Assertion OK : Range Address is: $F9
+ ITEM Assertion OK : Range Address is: F$9
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: $F$9
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: R[7]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$9
+END 'SingleCell-Address' Symbol
+ TEST OK : SingleCell-Address
+----------------------------------------------------------------
+Heights and Widths
+ TEST START : Heights and Widths
+ ITEM Assertion OK : Range RowHeight is 40
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 238
+ ITEM Assertion OK : Range Width is 798.75
+ ITEM Assertion OK : Range RowHeight is 50
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 297
+ ITEM Assertion OK : Range Width is 798.75
+ ITEM Assertion OK : RowHeight is null: True
+ ITEM Assertion OK : ColumnWidth is null: True
+END 'Heights and Widths' Symbol
+ TEST OK : Heights and Widths
+----------------------------------------------------------------
+RangeRowColumn-Issue
+ TEST START : RangeRowColumn-Issue
+ ITEM Assertion OK : Row is: 8
+ ITEM Assertion OK : Column is: 5
+ ITEM Assertion OK : EntireRow.Columns.Count = 256
+ ITEM Assertion OK : EntireColumn.Rows.Count = 65536
+END 'RangeRowColumn-Issue' Symbol
+ TEST OK : RangeRowColumn-Issue
+----------------------------------------------------------------
+Replace-Issue
+ TEST START : Replace-Issue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New Replace
+ ITEM Assertion OK : Value after Replace:
+END 'Replace-Issue' Symbol
+ TEST OK : Replace-Issue
+----------------------------------------------------------------
+Hidden-Issue
+ TEST START : Hidden-Issue
+ ITEM Assertion OK : - Range.Rows.Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Hidden (get)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (get)
+END 'Hidden-Issue' Symbol
+ TEST OK : Hidden-Issue
+----------------------------------------------------------------
+End issue
+ TEST START : End issue
+ ITEM Assertion OK : - = $E$48
+ ITEM Assertion OK : - = $E$1
+ ITEM Assertion OK : - = $E$3
+ ITEM Assertion OK : - = $A$8
+ ITEM Assertion OK : - = $B$8
+ ITEM Assertion OK : - = $IV$8
+ ITEM Assertion OK : - = $Z$8
+END 'End issue' Symbol
+ TEST OK : End issue
+----------------------------------------------------------------
+Outline issue
+ TEST START : Outline issue
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+END 'Outline issue' Symbol
+ TEST OK : Outline issue
+----------------------------------------------------------------
+Validation
+ TEST START : Validation
+ ITEM Assertion OK : Validation Input Message is : Attention!
+ ITEM Assertion OK : Validation Input Message is : Enter an integer from five to ten
+ ITEM Assertion OK : Validation Error Title is : You must enter a number from five to ten
+ ITEM Assertion OK : Validation Error Message is : An Error occured
+ ITEM Assertion OK : Validation Error Title is : Microsoft Excel
+END 'Validation' Symbol
+ TEST OK : Validation
+Test run finished : 01/06/2007 11:29:00
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestAddress.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestAddress.log new file mode 100644 index 000000000000..01e5503a7e62 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestAddress.log @@ -0,0 +1,62 @@ +Test run started : 17/07/2007 15:25:17
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 Range('e3:f3') A1 style addressing
+ ITEM Assertion OK : test2 Range('e3:f3') R1C1 style addressing
+ ITEM Assertion OK : test3 Range ('e:f') A1 style addressing
+ ITEM Assertion OK : test4 Range ('e:f') R1C1 style addressing
+ ITEM Assertion OK : test5 Columns A1 style addressing
+ ITEM Assertion OK : test6 Columns R1C1 style addressing
+ ITEM Assertion OK : test7 Columns(3) A1 style addressing
+ ITEM Assertion OK : test8 Columns(3) R1C1 style addressing
+ ITEM Assertion OK : test9 Columns('e') A1 style addressing
+ ITEM Assertion OK : test10 Columns('e') R1C1 style addressing
+ ITEM Assertion OK : test11 Columns('b:d') A1 style addressing
+ ITEM Assertion OK : test12 Columns('b:d') R1C1 style addressing
+ ITEM Assertion OK : test13 Range('c1:g10').Columns A1 style addressing
+ ITEM Assertion OK : test14 Range('c1:g10').Columns R1C1 style addressing
+ ITEM Assertion OK : test15 Range('c1:g10').Columns(1) A1 style addressing
+ ITEM Assertion OK : test16 Range('c1:g10').Columns(1) R1C1 style addressing
+ ITEM Assertion OK : test17 Range('c1:g10').Columns('a') A1 style addressing
+ ITEM Assertion OK : test18 Range('c1:g10').Columns('a') R1C1 style addressing
+ ITEM Assertion OK : test19 Range('c1:g10').Columns('c') A1 style addressing
+ ITEM Assertion OK : test20 Range('c1:g10').Columns('c') R1C1 style addressing
+ ITEM Assertion OK : test21 Range('c1:g10').Columns('x:z') A1 style addressing
+ ITEM Assertion OK : test22 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test23 Range('c1:g10').Columns(30) A1 style addressing
+ ITEM Assertion OK : test24 Range('c1:g10').Columns(30) R1C1 style addressing
+ ITEM Assertion OK : test25 Worksheets('Sheet2').Cells(1, 1) A1 style addressing
+ ITEM Assertion OK : test26 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, RowAddressAbsolute is false
+ ITEM Assertion OK : test27 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, ColAddressAbsolute is false
+ ITEM Assertion OK : test28 Worksheets('Sheet2').Cells(1, 1) R1C1 style addressing
+ ITEM Assertion OK : test29 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test30 Worksheets('Sheet2').Range('A1').EntireColumn A1 style addressing
+ ITEM Assertion OK : test31 Worksheets('Sheet2').Range('A1:E5').EntireRow A1 style addressing
+ ITEM Assertion OK : test32 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test33 Worksheets('Sheet2').Range('IV65536').EntireRow A1 style addressing
+ ITEM Assertion OK : test34 Worksheets('Sheet2').Range('IU2:IV65536') A1 style addressing
+ ITEM Assertion OK : test35 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test36 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test37 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test38 Worksheets('Sheet2').Range('10:12') A1 style addressing
+ ITEM Assertion OK : test39 Worksheets('Sheet2').Range('10:12') R1C1 style addressing
+ ITEM Assertion OK : test40 Range('Sheet3!A1:B4') A1 style addressing
+ ITEM Assertion OK : test41 Range('Sheet3!A1,B1,D4:F20') A1 style addressing
+ ITEM Assertion OK : test42 Range('g20:h40').Columns('c:c')
+ ITEM Assertion OK : test43 Range('g20:h40').Columns('c:f')
+ ITEM Assertion OK : test44 Range('g20:h40').Columns(-1)
+ ITEM Assertion OK : test45 Range('c4:g10').Rows(-1)
+ ITEM Assertion OK : test46 Range('a2:b4').Rows('1:1')
+ ITEM Assertion OK : test47 Range('a2:b4').Rows('1:2')
+ ITEM Assertion OK : test48 Range('a2:b4').Rows('2:2')
+ ITEM Assertion OK : test49 Range('a2:b4').Rows('2:3')
+Test Results +============ + +Tests passed: 49 +Tests failed: 0 +
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 17/07/2007 15:25:19
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestCalc_Rangetest.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestCalc_Rangetest.log new file mode 100644 index 000000000000..f055279ec6f4 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestCalc_Rangetest.log @@ -0,0 +1,60 @@ +Test run started : 30/05/2007 11:33:13
+BEGIN TestCalc
+ TEST START : RangeTest2
+ ITEM Assertion OK : - Range("D15").Row
+ ITEM Assertion OK : - WorkSheet("D15").Range.Row
+ ITEM Assertion OK : - Range("D15").Column
+ ITEM Assertion OK : - Worksheet.Range("D15").Column
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Columns.Count
+ ITEM Assertion OK : - Range("D1").EntireColumn.Rows.Count
+ ITEM Assertion OK : - Range("D15").ClearContent
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (get)
+ ITEM Assertion OK : - Range("B38").Orientation (get)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlDownward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlUpward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B39").WrapText (get)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (get)
+ ITEM Assertion OK : - Range("F39").MergeCells (get)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion OK : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion OK : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("D41:D42").Replace MatchCase:=False
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM OK (RangeTest2)
+ TEST succesfully completed : RangeTest2
+END TestCalc
+Test run finished : 30/05/2007 11:33:14
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestCalc_Rangetest2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestCalc_Rangetest2.log new file mode 100644 index 000000000000..19a5ba96b54a --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/excel/TestCalc_Rangetest2.log @@ -0,0 +1,64 @@ +Test run started : 31/05/2007 11:02:10
+BEGIN TestCalc
+ TEST START : RangeTest3
+ ITEM Assertion OK : - setFormulaR1C1
+ ITEM Assertion OK : - getFormulaR1C1
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy(Range("I10"))
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteValues
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormulas
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormats
+ ITEM Assertion OK : PasteSpecial
+ ITEM Assertion OK : PasteSpecial SkipBlanks:=True
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationAdd
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationSubtract
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationMultiply
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationDivide
+ ITEM Assertion OK : PasteSpecial Transpose:=True
+ ITEM Assertion OK : ActiveWorkbook.Name
+ ITEM Assertion OK : ActiveWorkbook.FullName und ActiveWorkbook.Path
+ ITEM Assertion OK : - = Range("K22").End (xlDown)
+ ITEM Assertion OK : - = Range("K22").End (xlUo)
+ ITEM Assertion OK : - = Range("K22").End (xlToLeft)
+ ITEM Assertion OK : - = Range("K22").End (xlRight)
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="x"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="<>"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="="
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter
+ ITEM Assertion OK : - ActiveSheet.Resize.Select
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion OK : - Application.GoTo Reference:="R[8]C[2]"
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Ungroup- please check visually
+ ITEM Assertion OK : - Range.Ungroup - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - ActiveSheet.UsedRange.Select
+ ITEM Assertion FAIL : - Range("A13").AddIndent
+ ITEM Assertion OK : - Range("A13").IndentLevel set
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Calculate
+ ITEM Assertion OK : Worksheet.Calculate
+ ITEM Assertion OK : - Application.Calculate
+ ITEM Assertion OK : Global.Calculate
+ ITEM Assertion OK : Calculation set
+ ITEM Assertion OK : - = ActiveWorkbook.Colors(3) set
+ ITEM Assertion OK : - = ActiveWorkbook.ResetColors
+ ITEM Assertion OK : - = ActiveWorkbook.Colors(3) get
+ ITEM FAIL (RangeTest3)
+ TEST Not succesfully completed : RangeTest3
+END TestCalc
+Test run finished : 31/05/2007 11:02:12
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/format.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/format.log new file mode 100644 index 000000000000..5226a161c61a --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/format.log @@ -0,0 +1,36 @@ +Test run started : 08/10/2008 13:08:40
+BEGIN Format
+ TEST START : Test Predefined_Number_Format_Sample function
+ ITEM Assertion OK : General Number: 562486.2356
+ ITEM Assertion OK : Fixed: 0.20
+ ITEM Assertion OK : Standard: 562,486.24
+ ITEM Assertion OK : Percent: 75.21%
+ ITEM Assertion OK : Scientific: 5.62E+05
+ ITEM Assertion OK : Scientific: -3.46E+03
+ ITEM Assertion OK : Yes/No: No
+ ITEM Assertion OK : Yes/No: Yes
+ ITEM Assertion OK : True/False: False
+ ITEM Assertion OK : True/False: True
+ ITEM Assertion OK : On/Off: Off
+ ITEM Assertion OK : On/Off: On
+ TEST OK : Test Predefined_Number_Format_Sample function
+ TEST START : Test Custom_Number_Format_Sample function
+ ITEM Assertion OK : 00.0000: 23.6750
+ ITEM Assertion OK : 00.00: 23.68
+ ITEM Assertion OK : 00000: 02658
+ ITEM Assertion OK : 00.00: 2658.00
+ ITEM Assertion OK : ##.####: 23.675
+ ITEM Assertion OK : ##.##: 23.68
+ ITEM Assertion OK : #,###.##: 12,345.25
+ ITEM Assertion OK : ##.00%: 25.00%
+ ITEM Assertion OK : #,###: 1,000,000
+ ITEM Assertion OK : ######E-###: 109838E-5
+ ITEM Assertion OK : $#,###.##: $2,345.25
+ ITEM Assertion OK : ##.###\%: .25%
+ TEST OK : Test Custom_Number_Format_Sample function
+ TEST START : Test Custom_Text_Format_Sample function
+ ITEM Assertion OK : <: vba
+ ITEM Assertion OK : >: VBA
+ TEST OK : Test Custom_Text_Format_Sample function
+END Format
+Test run finished : 08/10/2008 13:08:40
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/AutoFilter.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/AutoFilter.log new file mode 100644 index 000000000000..55f5d9526618 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/AutoFilter.log @@ -0,0 +1,20 @@ +Test run started : 18/07/2007 10:56:38 +---------------------------------------------------------------- +TestAddress + TEST START : TestAddress + ITEM Assertion OK : test1 'starts with' string criteria + ITEM Assertion OK : test2 'not equal to' string criteria + ITEM Assertion OK : test3 'ends with' string criteria + ITEM Assertion OK : test4 field 'all' + ITEM Assertion OK : test5 numeric '<15' + ITEM Assertion OK : test6 numeric '>=15' + ITEM Assertion OK : test7 numeric '<=12' +Test Results +============ + +Tests passed: 7 +Tests failed: 0 + +END 'TestAddress + TEST OK : TestAddress +Test run finished : 18/07/2007 10:56:44 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/CalcFont.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/CalcFont.log new file mode 100644 index 000000000000..f3583e4cbb12 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/CalcFont.log @@ -0,0 +1,17 @@ +Test run started : 10/09/2008 02:40:17 PM +CalcFont_Format + TEST START : Font_Format + ITEM Assertion OK : correctly set font to Bold + ITEM Assertion OK : correctly set font to Italic + ITEM Assertion OK : correctly read FontStyle + ITEM Assertion OK : correctly set font to Shadow + ITEM Assertion OK : correctly set font color + ITEM Assertion OK : correctly set font color index + ITEM Assertion OK : correctly set font name + ITEM Assertion OK : correctly set font outline + ITEM Assertion OK : correctly set font size + ITEM Assertion OK : correctly set font strikethrough + ITEM Assertion OK : correctly set font underline + TEST Success. : Font_Format +CalcFont_Format +Test run finished : 10/09/2008 02:40:17 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/CalcZoom.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/CalcZoom.log new file mode 100644 index 000000000000..f8c83531a8a2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/CalcZoom.log @@ -0,0 +1,18 @@ +Test run started : 15/06/2009 12:49:35 +CalcZoom + TEST START : CalcZoom + ITEM Assertion OK : test1 read window.zoom activesheet = sheet1 + ITEM Assertion OK : test2 read window.zoom activesheet = sheet2 + ITEM Assertion OK : test3 read window.zoom activesheet = sheet3 + ITEM Assertion OK : test4 read window.zoom activesheet = sheet3 + ITEM Assertion OK : test4 read window.zoom activesheet = sheet2 + ITEM Assertion OK : test4 read window.zoom activesheet = sheet1 + TEST Success. : CalcZoom +CalcZoom +Test Results +============ + +Tests passed: 6 +Tests failed: 0 + +Test run finished : 15/06/2009 12:49:37 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/FinancialFuncTests.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/FinancialFuncTests.log new file mode 100644 index 000000000000..5633a8100e08 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/FinancialFuncTests.log @@ -0,0 +1,31 @@ +Test run started : 04/08/2009 12:42:26 +---------------------------------------------------------------- +FinancialFuncs + TEST START : FinancialFuncs + ITEM Assertion OK : DDB test + ITEM Assertion OK : FV test + ITEM Assertion OK : IPmt test + ITEM Assertion FAIL : IRR test + ITEM Assertion OK : MIRR test + ITEM Assertion FAIL : NPer test + ITEM Assertion FAIL : NPV test + ITEM Assertion FAIL : Pmt test + ITEM Assertion OK : PPmt test + ITEM Assertion OK : PV test + ITEM Assertion FAIL : Rate test + ITEM Assertion OK : SLN test + ITEM Assertion OK : SYD test +Test Results +============ + +IRR test Failed: expected 35.8625323270733 got 35.8625323273411 +NPer test Failed: expected 21.5365977313406 got 21.5365977313408 +NPV test Failed: expected 3874.42183648785 got 3874.42183648784 +Pmt test Failed: expected 20276.3942884139 got 20276.3942884138 +Rate test Failed: expected 4.67819164224935E-02 got 4.67819164225E-02 +Tests passed: 8 +Tests failed: 5 + +END 'FinancialFuncs + TEST OK : FinancialFuncs +Test run finished : 04/08/2009 12:42:36 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/MiscOperatorTests.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/MiscOperatorTests.log new file mode 100644 index 000000000000..116f9f98c7e8 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/MiscOperatorTests.log @@ -0,0 +1,30 @@ +Test run started : 12/05/2009 12:36:15 +---------------------------------------------------------------- +TestAddress + TEST START : TestAddress + ITEM Assertion OK : test1: res = Not ( A > B ) + ITEM Assertion OK : test2: res = Not ( B > A ) + ITEM Assertion OK : test3: res = Not ( D ) + ITEM Assertion OK : test4: res = Not A + ITEM Assertion OK : test5: res = ( A > D ) + ITEM Assertion OK : test6: res = ( D > A ) + ITEM Assertion OK : test7: res = ( A < D ) + ITEM Assertion OK : test8: res = ( D < A ) + ITEM Assertion OK : test9: res = ( A >= D ) + ITEM Assertion OK : test10: res = ( D >= A ) + ITEM Assertion OK : test11: res = ( A <= D ) + ITEM Assertion OK : test12: res = ( D <= A ) + ITEM Assertion OK : test13: res = ( D = A ) + ITEM Assertion OK : test14: res = ( A = D ) + ITEM Assertion OK : test15: res = ( D <> A ) + ITEM Assertion OK : test16: res = ( A <> D ) + ITEM Assertion OK : test17: ( A = D ) = True +Test Results +============ + +Tests passed: 17 +Tests failed: 0 + +END 'TestAddress + TEST OK : TestAddress +Test run finished : 12/05/2009 12:36:15 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/MiscRangeTests.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/MiscRangeTests.log new file mode 100644 index 000000000000..215842f9a7e6 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/MiscRangeTests.log @@ -0,0 +1,45 @@ +Test run started : 17/07/2007 20:54:56 +---------------------------------------------------------------- +MiscRangeTests + TEST START : MiscRangeTests + ITEM Assertion OK : test 1 + ITEM Assertion OK : test 2 + ITEM Assertion OK : test 3 + ITEM Assertion OK : test 4 + ITEM Assertion OK : test 5 + ITEM Assertion OK : test 6 + ITEM Assertion OK : test 7 + ITEM Assertion OK : test 8 + ITEM Assertion OK : test 9 + ITEM Assertion OK : test 10 + ITEM Assertion OK : test 11 + ITEM Assertion OK : test 12 + ITEM Assertion OK : test 13 + ITEM Assertion OK : test 14 + ITEM Assertion OK : test 15 + ITEM Assertion OK : test 16 + ITEM Assertion OK : test 17 + ITEM Assertion OK : test 18 + ITEM Assertion OK : test 19 + ITEM Assertion OK : test 20 + ITEM Assertion OK : test 21 + ITEM Assertion OK : test 22 + ITEM Assertion OK : test 23 + ITEM Assertion OK : test 24 + ITEM Assertion OK : test 25 + ITEM Assertion OK : test 26 + ITEM Assertion OK : test 27 + ITEM Assertion OK : test 28 + ITEM Assertion OK : test 29 + ITEM Assertion OK : test 30 + ITEM Assertion OK : test 31 +No. tests: 31 +Summary +======= +Run: 31 +Passed: 31 +Failed: 0 + +END 'MiscRangeTests + TEST OK : MiscRangeTests +Test run finished : 17/07/2007 20:55:03 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/PageBreaks.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/PageBreaks.log new file mode 100644 index 000000000000..0ff400d49e85 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/PageBreaks.log @@ -0,0 +1,10 @@ +Test run started : 07/24/2008 05:06:12 PM +---------------------------------------------------------------- + TEST START : PageBreaks-Issue + ITEM Assertion OK : HPageBreaks.Count is 3 + ITEM Assertion OK : HPageBreak.Type is -4135 + ITEM Assertion OK : HPageBreak.Location: Range.Row is 5 + ITEM Assertion OK : HPageBreak.Delete: HPageBreaks.Count is 2 +END 'PageBreaks-Issue' Symbol + TEST OK : PageBreaks-Issue +Test run finished : 07/24/2008 05:06:13 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges-2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges-2.log new file mode 100644 index 000000000000..8b7076efaea0 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges-2.log @@ -0,0 +1,68 @@ +Test run started : 19/06/2007 11:14:01 +---------------------------------------------------------------- +ClearFormtsIssue + TEST START : ClearFormtsIssue + ITEM Assertion OK : Range.Font.Bold is: True + ITEM Assertion OK : Range.Font.Bold is: False +END 'ClearFormtsIssue' Symbol + TEST OK : ClearFormtsIssue +---------------------------------------------------------------- +VerticalAlignment-Issue + TEST START : VerticalAlignment-Issue + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (set) + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (set) + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (set) + ITEM Assertion OK : Range.VeritcalAlignment is Null +END 'VerticalAlignment-Issue' Symbol + TEST OK : VerticalAlignment-Issue +---------------------------------------------------------------- +HorizontalAlignment-Issue + TEST START : HorizontalAlignment-Issue + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : Range.HorizontalAlignment is Null +END 'HorizontalAlignment-Issue' Symbol + TEST OK : HorizontalAlignment-Issue +---------------------------------------------------------------- +WrapText-Issue + TEST START : WrapText-Issue + ITEM Assertion OK : - Range.WrapText (get) + ITEM Assertion OK : - Range.WrapText (get) + ITEM Assertion OK : Range.WrapText is Null +END 'WrapText-Issue' Symbol + TEST OK : WrapText-Issue +---------------------------------------------------------------- +FontBorderIssues + TEST START : FontBorderIssues + ITEM Assertion OK : - = Borders.Color (getColor) + ITEM Assertion OK : - = Font.Color (getColor) +END 'FontBorderIssues' Symbol + TEST OK : FontBorderIssues +---------------------------------------------------------------- +RangeSizeIssues + TEST START : RangeSizeIssues + ITEM Assertion OK : Range.Left is: 118.8432 + ITEM Assertion OK : Range.Top is: 92.16585 + ITEM Assertion OK : Range.Width is: 226.2 + ITEM Assertion OK : Range.Height is: 271.5 +END 'RangeSizeIssues' Symbol + TEST OK : RangeSizeIssues +---------------------------------------------------------------- +ApplicationIssues + TEST START : ApplicationIssues + ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Application.ActiveSheet.Name: Sheet1 +END 'ApplicationIssues' Symbol + TEST OK : ApplicationIssues +Test run finished : 19/06/2007 11:14:02 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges-3.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges-3.log new file mode 100644 index 000000000000..a130737ceb65 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges-3.log @@ -0,0 +1,8 @@ +Test run started : 19/06/2007 11:26:09 +---------------------------------------------------------------- +MyGoalseek-Issue + TEST START : MyGoalseek-Issue + ITEM Assertion OK : Variable Range value: 15 +END 'MyGoalseek-Issue' Symbol + TEST OK : MyGoalseek-Issue +Test run finished : 19/06/2007 11:26:10 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges.log new file mode 100644 index 000000000000..cdd18685e977 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Ranges.log @@ -0,0 +1,280 @@ +Test run started : 10/03/2008 15:15:11 +---------------------------------------------------------------- +ApplicationMethods + TEST START : ApplicationMethods + ITEM Assertion OK : Name of Workbook is: Ranges.xls + ITEM Assertion OK : Address of Application.Columns is: $A:$A + ITEM Assertion OK : Address of Application.Rows is: $1:$1 + ITEM Assertion OK : Address of Application.Range is: $1:$1,$5:$7 + ITEM Assertion OK : Please check manually: DefaultFilePath is: /data4/home/npower/Documents + ITEM Assertion OK : Please check manually: Library Path is: /data4/home/npower/.ooo-2.0/user/basic + ITEM Assertion OK : Please check manually: Template Path is: /data4/home/npower/.ooo-2.0/user/template + ITEM Assertion OK : FileSeparator is / + ITEM Assertion OK : Name of ActiveWorkbook is: Ranges.xls +END 'ApplicationMethods' Symbol + TEST OK : ApplicationMethods +---------------------------------------------------------------- +Insert-Issue + TEST START : Insert-Issue + ITEM Assertion OK : Insert with xlShiftToRight: 10 +END 'Insert-Issue' Symbol + TEST OK : Insert-Issue +---------------------------------------------------------------- +MergeCells-Issue + TEST START : MergeCells-Issue + ITEM Assertion OK : Range.MergeCells is True + ITEM Assertion FAIL : MergeCells is null: False + ITEM Assertion OK : RowCount after Merge: 13 + ITEM Assertion OK : Range.MergeCells is False + ITEM Assertion OK : MergeCells is null: False + ITEM Assertion FAIL : MergeCells of Second Area is null : False + ITEM Assertion FAIL : MergeCells of Ranges is Null: False + ITEM Assertion OK : RowCount after Merge: 7 + ITEM Assertion OK : Range.MergeCells is False + ITEM Assertion OK : MergeCells is null: False + ITEM Assertion OK : RowCount after Merge: 7 +END 'MergeCells-Issue' Symbol + TEST OK : MergeCells-Issue +---------------------------------------------------------------- +Areas-Issue + TEST START : Areas-Issue + ITEM Assertion OK : Range Areas Count is2 + ITEM Assertion OK : First Range Address is: $E$8:$G$13 + ITEM Assertion OK : First Row is: 8 + ITEM Assertion OK : First Column is: 5 + ITEM Assertion OK : EntireRow Address is: $8:$13,$13:$19 + ITEM Assertion OK : EntireColumn Address is: $E:$G,$G:$K + ITEM Assertion OK : Range Count:53 +END 'Areas-Issue' Symbol + TEST OK : Areas-Issue +---------------------------------------------------------------- +Fill-Methods-Issue + TEST START : Fill-Methods-Issue + ITEM Assertion OK : Range Value after FillDown: MyFillValue + ITEM Assertion OK : Range Value after FillDown: MyFillValue + ITEM Assertion OK : Range Value after FillDown: MyRightFillValue + ITEM Assertion OK : Range Value after FillDown: MyBottomFillValue +END 'Fill-Methods-Issue' Symbol + TEST OK : Fill-Methods-Issue +---------------------------------------------------------------- +Range/Item-Method-Issue + TEST START : Range/Item-Method-Issue + ITEM Assertion OK : Range of multiple columns is: $A:$A,$C:$C + ITEM Assertion OK : Range of multiple rows is: $1:$1,$5:$7 + ITEM Assertion OK : Range of several columns is: $C:$E,$D:$D + ITEM Assertion OK : Range of several rows is: $5:$8,$6:$10 + ITEM Assertion OK : Range of several single cells is: $C$5,$E$8 + ITEM Assertion OK : Range of several named ranges is: $L$1:$M$6,$E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Range of a single Item Cell is: $E$21 + ITEM Assertion OK : Range of a single Item Cell is: $F$21 + ITEM Assertion OK : Range of a single Item Cell is: $F$10 +END 'Range/Item-Method-Issue' Symbol + TEST OK : Range/Item-Method-Issue +---------------------------------------------------------------- +R1C1-Formulas-Issue + TEST START : R1C1-Formulas-Issue + ITEM Assertion OK : R1C1 Range.Formula is: =IF(OR(R[-2]C[1]=0,RC[2]="YES"),"") + ITEM Assertion OK : Range.Formula is: =IF(OR(J8=0,K10="YES"),"") +END 'R1C1-Formulas-Issue' Symbol + TEST OK : R1C1-Formulas-Issue +---------------------------------------------------------------- +Verify_Delete + TEST START : Verify_Delete + ITEM Assertion OK : Ranges are intersecting: $G$13 + ITEM Assertion OK : Delete with Default: $AJ$4 + ITEM Assertion OK : Delete with ShifttoLeft: $AJ$4 + ITEM Assertion OK : Delete with ShiftUp: $M$22 +END 'Verify_Delete' Symbol + TEST OK : Verify_Delete +---------------------------------------------------------------- +Value-Issue + TEST START : Value-Issue + ITEM Assertion OK : Value of Range is: 12.3 + ITEM Assertion OK : Text of Range is: 12.3 + ITEM Assertion OK : Range has Formula: False + ITEM Assertion OK : Cell has Formula: False + ITEM Assertion FAIL : Text of Range is null: False + ITEM Assertion OK : Range has Formula: True + ITEM Assertion OK : Cell has Formula: True + ITEM Assertion OK : Value of Cell is: 12 + ITEM Assertion OK : Application.Calculation is : -4135 + ITEM Assertion OK : Calculation is automated: True + ITEM Assertion OK : Range has Formula: True + ITEM Assertion OK : Value of Cell is: 16 + ITEM Assertion OK : Text of Cell is: 16 + ITEM Assertion OK : Text of Cell is: 16 + ITEM Assertion OK : Range has Formula after 'ClearContents: False + ITEM Assertion OK : Text of Cell is: + ITEM Assertion OK : Text of Cell is: +END 'Value-Issue' Symbol + TEST OK : Value-Issue +---------------------------------------------------------------- +AutoFit issue + TEST START : AutoFit issue + ITEM Assertion OK : Columns.AutoFit: CurrentWidth is 680 + ITEM Assertion OK : Rows.AutoFit: CurrentHeight is 554 +END 'AutoFit issue' Symbol + TEST OK : AutoFit issue +---------------------------------------------------------------- +Selections + TEST START : Selections + ITEM Assertion OK : ActiveCell is : $E$8 + ITEM Assertion OK : Active Cell is : $E$8 + ITEM Assertion OK : Number of Cells in Range: 52 + ITEM Assertion OK : Number of Cells in Range: 52 + ITEM Assertion OK : Number of Cells in Range: 52 +END 'Selections' Symbol + TEST OK : Selections +---------------------------------------------------------------- +Offset-Resize + TEST START : Offset-Resize + ITEM Assertion OK : Offset is : $G$10:$I$15,$I$15:$M$21 + ITEM Assertion OK : Offset is : $G$7:$I$12,$I$12:$M$18 + ITEM Assertion OK : Resized Range is : $A$20:$D$23 +END 'Offset-Resize' Symbol + TEST OK : Offset-Resize +---------------------------------------------------------------- +Ranges-Address + TEST START : Ranges-Address + ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Range Address is: $E8:$G13,$G13:$K19 + ITEM Assertion OK : Range Address is: E$8:G$13,G$13:K$19 + ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11 + ITEM Assertion FAIL : Range Address is: R8C5:R13C7,R13C7:R19C11 + ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11 + ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5],R[11]C[5]:R[17]C[9] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13,$G$13:$K$19 +END 'Ranges-Address' Symbol + TEST OK : Ranges-Address +---------------------------------------------------------------- +Range-Address + TEST START : Range-Address + ITEM Assertion OK : Range Address is: $E$8:$G$13 + ITEM Assertion OK : Range Address is: $E8:$G13 + ITEM Assertion OK : Range Address is: E$8:G$13 + ITEM Assertion OK : Range Address is: R8C5:R13C7 + ITEM Assertion FAIL : Range Address is: R8C5:R13C7 + ITEM Assertion OK : Range Address is: R8C5:R13C7 + ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13 +END 'Range-Address' Symbol + TEST OK : Range-Address +---------------------------------------------------------------- +Column-Address + TEST START : Column-Address + ITEM Assertion OK : Range Address is: $F$8:$F$13 + ITEM Assertion OK : Range Address is: $F8:$F13 + ITEM Assertion OK : Range Address is: F$8:F$13 + ITEM Assertion OK : Range Address is: R8C6:R13C6 + ITEM Assertion FAIL : Range Address is: R8C6:R13C6 + ITEM Assertion OK : Range Address is: R8C6:R13C6 + ITEM Assertion OK : Range Address is: R[6]C[4]:R[11]C[4] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$8:$F$13 +END 'Column-Address' Symbol + TEST OK : Column-Address +---------------------------------------------------------------- +Row-Address + TEST START : Row-Address + ITEM Assertion OK : Range Address is: $E$9:$G$9 + ITEM Assertion OK : Range Address is: $E9:$G9 + ITEM Assertion OK : Range Address is: E$9:G$9 + ITEM Assertion OK : Range Address is: R9C5:R9C7 + ITEM Assertion FAIL : Range Address is: R9C5:R9C7 + ITEM Assertion OK : Range Address is: R9C5:R9C7 + ITEM Assertion OK : Range Address is: R[7]C[3]:R[7]C[5] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$9:$G$9 +END 'Row-Address' Symbol + TEST OK : Row-Address +---------------------------------------------------------------- +SingleCell-Address + TEST START : SingleCell-Address + ITEM Assertion OK : Range Address is: $F$9 + ITEM Assertion OK : Range Address is: $F9 + ITEM Assertion OK : Range Address is: F$9 + ITEM Assertion OK : Range Address is: R9C6 + ITEM Assertion FAIL : Range Address is: R9C6 + ITEM Assertion OK : Range Address is: R9C6 + ITEM Assertion OK : Range Address is: R[7]C[4] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$9 +END 'SingleCell-Address' Symbol + TEST OK : SingleCell-Address +---------------------------------------------------------------- +Heights and Widths + TEST START : Heights and Widths + ITEM Assertion OK : Range RowHeight is 40 + ITEM Assertion OK : Range ColumnWidth is 50 + ITEM Assertion OK : Range Height is 240 + ITEM Assertion OK : Range Width is 795 + ITEM Assertion OK : Range RowHeight is 50 + ITEM Assertion OK : Range ColumnWidth is 50 + ITEM Assertion OK : Range Height is 300 + ITEM Assertion OK : Range Width is 795 + ITEM Assertion OK : RowHeight is null: True + ITEM Assertion OK : ColumnWidth is null: True +END 'Heights and Widths' Symbol + TEST OK : Heights and Widths +---------------------------------------------------------------- +RangeRowColumn-Issue + TEST START : RangeRowColumn-Issue + ITEM Assertion OK : Row is: 8 + ITEM Assertion OK : Column is: 5 + ITEM Assertion OK : EntireRow.Columns.Count = 256 + ITEM Assertion OK : EntireColumn.Rows.Count = 131072 +END 'RangeRowColumn-Issue' Symbol + TEST OK : RangeRowColumn-Issue +---------------------------------------------------------------- +Replace-Issue + TEST START : Replace-Issue + ITEM Assertion OK : Value after Replace: YourValue + ITEM Assertion OK : Value after Replace: YourValue + ITEM Assertion OK : Value after Replace: ReplaceValue + ITEM Assertion OK : Value after Replace: New ReplaceValue + ITEM Assertion OK : Value after Replace: New ReplaceValue + ITEM Assertion OK : Value after Replace: New Replace + ITEM Assertion OK : Value after Replace: +END 'Replace-Issue' Symbol + TEST OK : Replace-Issue +---------------------------------------------------------------- +Hidden-Issue + TEST START : Hidden-Issue + ITEM Assertion OK : - Range.Rows.Hidden (set) + ITEM Assertion OK : - Range.Rows.Hidden (get) + ITEM Assertion OK : - Range.Rows.Item(1).Hidden (set) + ITEM Assertion OK : - Range.Rows.Item(1).Hidden (get) + ITEM Assertion OK : - Range.Columns.Hidden (set) + ITEM Assertion OK : - Range.Columns.Hidden (get) + ITEM Assertion OK : - Range.Columns.Item(1).Hidden (set) + ITEM Assertion OK : - Range.Columns.Item(1).Hidden (get) +END 'Hidden-Issue' Symbol + TEST OK : Hidden-Issue +---------------------------------------------------------------- +End issue + TEST START : End issue + ITEM Assertion OK : - = $E$48 + ITEM Assertion OK : - = $E$1 + ITEM Assertion OK : - = $E$3 + ITEM Assertion OK : - = $A$8 + ITEM Assertion OK : - = $B$8 + ITEM Assertion OK : - = $IV$8 + ITEM Assertion OK : - = $Z$8 +END 'End issue' Symbol + TEST OK : End issue +---------------------------------------------------------------- +Outline issue + TEST START : Outline issue + ITEM Assertion OK : - Range.clearOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually +END 'Outline issue' Symbol + TEST OK : Outline issue +---------------------------------------------------------------- +Validation + TEST START : Validation + ITEM Assertion OK : Validation Input Message is : Attention! + ITEM Assertion OK : Validation Input Message is : Enter an integer from five to ten + ITEM Assertion OK : Validation Error Title is : You must enter a number from five to ten + ITEM Assertion OK : Validation Error Message is : An Error occured + ITEM Assertion OK : Validation Error Title is : Microsoft Excel +END 'Validation' Symbol + TEST OK : Validation +Test run finished : 10/03/2008 15:15:13 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Shapes.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Shapes.log new file mode 100644 index 000000000000..3193a0b1094d --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Shapes.log @@ -0,0 +1,77 @@ +Test run started : 10/16/2007 05:25:21 PM +BEGIN Shapes_Collection_Behaviour + TEST START : Shapes_Collection_Behaviour + ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape1' + ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape2' + TEST Success. : Shapes_Collection_Behaviour +END Shapes_Collection_Behaviour +BEGIN Shapes_Select_Item + TEST START : Shapes_Select_Item + ITEM Assertion OK : Correctly selected shape through Range + ITEM Assertion OK : Correctly selected shape through Item + ITEM Assertion OK : Needs to be visually checked. Is there a line on the document? + ITEM Assertion OK : Needs to be visually checked. Are All Shapes Selected? + TEST Success. : Shapes_Select_Item +END Shapes_Select_Item +BEGIN Shapes_Fill + TEST START : Shapes_Fill + ITEM Assertion OK : correctly set visibility of shape fill + ITEM Assertion OK : correctly set transparency of shape line + ITEM Assertion OK : correctly set forecolor of shape fill + ITEM Assertion FAIL : correctly set backcolor of shape fill + ITEM Assertion OK : the success of the TwoColorGradient method needs to be verified visually! + ITEM Assertion OK : correctly set forecolor of shape fill + ITEM Assertion FAIL : correctly set forecolor of shape fill + TEST Success. : Shapes_Fill +END Shapes_Fill +BEGIN Shapes_Line + TEST START : Shapes_Line + ITEM Assertion FAIL : correctly set weight of shape line + ITEM Assertion OK : correctly set visibility of shape line + ITEM Assertion OK : correctly set transparency of shape line + ITEM Assertion OK : correctly set dash style of shape line + ITEM Assertion OK : correctly set dash style of shape line + ITEM Assertion OK : correctly set forecolor of shape line + ITEM Assertion FAIL : correctly set backcolor of shape line + TEST Success. : Shapes_Line +END Shapes_Line +BEGIN Shapes_TextFrame + TEST START : Shapes_TextFrame + ITEM Assertion OK : correctly set Autosize of Shape TextFrame + TEST Success. : Shapes_TextFrame +END Shapes_TextFrame +BEGIN Shapes_SimpleGeometry + TEST START : Shapes_SimpleGeometery + ITEM Assertion OK : shape height should be 47.0425168477155 and got 46.9984222363199 + ITEM Assertion OK : shape width should be 101.467710269751 and got 101.423615658355 + ITEM Assertion OK : shape left should be 68.5574761223637 and got 68.5417279658754 + ITEM Assertion OK : shape top should be 42.0251943291216 and got 42.0094461726333 + ITEM Assertion OK : shape rotation should be 0 and got 0 + ITEM Assertion OK : shape rotation should be 25 and got 25 + ITEM Assertion OK : shape incrementrotation should be 50 and got 50 + ITEM Assertion OK : shape incrementleft should be 70.6834602404119 and got 70.6677120839236 + ITEM Assertion OK : shape incrementtop should be 91.262986503119 and got 91.2472383466307 + TEST Success. : Shapes_SimpleGeometery +END Shapes_SimpleGeometry +BEGIN Shapes_Range + TEST START : Shapes_Range + ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to contain 1 element, it contains 1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to return Sheet2Shape1 got Sheet2Shape1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to contain 1 element, it contains 1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to return Sheet2Shape3 got Sheet2Shape3 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to contain 2 elements, it contains 2 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to return concated element/shape names Sheet2Shape3Sheet2Shape1 and got Sheet2Shape3Sheet2Shape1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to contain 3 elements, it contains 3 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to return concated element/shape names Sheet2Shape3Sheet2Shape1Sheet2Shape2 and got Sheet2Shape3Sheet2Shape1Sheet2Shape2 + TEST Success. : Shapes_Range +END Shapes_Range +BEGIN Shapes_ShapeRange + TEST START : Shapes_ShapeRange + ITEM Assertion OK : ShapeRange.IncrementLeft shp1.left should be 90.6677120839236 and got 90.6519627935771 + ITEM Assertion OK : ShapeRange.IncrementLeft shp2.left should be 240.02518299054 and got 240.009433700193 + ITEM Assertion OK : ShapeRange.IncrementTop shp1.Top should be 111.247238346631 and got 111.231489056284 + ITEM Assertion OK : ShapeRange.IncrementTop shp2.Top should be 65.0708633026228 and got 65.0551140122763 + ITEM Assertion OK : ShapeRange.IncrementRotation shp1.Rotation should be 70 and got 70 + ITEM Assertion OK : ShapeRange.IncrementRotation shp2.Rotation should be 20 and got 20 +END Shapes_ShapeRange +Test run finished : 10/16/2007 05:25:22 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/StrConv-test.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/StrConv-test.log new file mode 100644 index 000000000000..c7a7d8750583 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/StrConv-test.log @@ -0,0 +1,9 @@ +Test run started : 05/29/2008 02:51:03 PM +BEGIN StrConv + TEST START : Test StrConv function + ITEM Assertion OK : Converts the string to uppercase characters:ABC EFG HIJ + ITEM Assertion OK : Converts the string to lowercase characters:abc efg hij + ITEM Assertion OK : Converts the first letter of every word in string to uppercase:Abc Efg Hij + TEST OK : Test StrConv function +END StrConv +Test run finished : 05/29/2008 02:51:03 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Template.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Template.log new file mode 100644 index 000000000000..c6376c5b3732 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Template.log @@ -0,0 +1,14 @@ +Test run started : 2008/07/10 11:57:05 +---------------------------------------------------------------- +TestCaseName + TEST START : TestCaseName + ITEM Assertion OK : Something has been done. +Test Results +============ + +Tests passed: 1 +Tests failed: 0 + +END 'TestCaseName + TEST OK : TestCaseName +Test run finished : 2008/07/10 11:57:05 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestAddress.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestAddress.log new file mode 100644 index 000000000000..4fa4bc820f59 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestAddress.log @@ -0,0 +1,67 @@ +Test run started : 12/05/2009 11:23:35 +---------------------------------------------------------------- +TestAddress + TEST START : TestAddress + ITEM Assertion OK : test1 Range('e3:f3') A1 style addressing + ITEM Assertion OK : test2 Range('e3:f3') R1C1 style addressing + ITEM Assertion OK : test3 Range ('e:f') A1 style addressing + ITEM Assertion OK : test4 Range ('e:f') R1C1 style addressing + ITEM Assertion OK : test5 Columns A1 style addressing + ITEM Assertion OK : test6 Columns R1C1 style addressing + ITEM Assertion OK : test7 Columns(3) A1 style addressing + ITEM Assertion OK : test8 Columns(3) R1C1 style addressing + ITEM Assertion OK : test9 Columns('e') A1 style addressing + ITEM Assertion OK : test10 Columns('e') R1C1 style addressing + ITEM Assertion OK : test11 Columns('b:d') A1 style addressing + ITEM Assertion OK : test12 Columns('b:d') R1C1 style addressing + ITEM Assertion OK : test13 Range('c1:g10').Columns A1 style addressing + ITEM Assertion OK : test14 Range('c1:g10').Columns R1C1 style addressing + ITEM Assertion OK : test15 Range('c1:g10').Columns(1) A1 style addressing + ITEM Assertion OK : test16 Range('c1:g10').Columns(1) R1C1 style addressing + ITEM Assertion OK : test17 Range('c1:g10').Columns('a') A1 style addressing + ITEM Assertion OK : test18 Range('c1:g10').Columns('a') R1C1 style addressing + ITEM Assertion OK : test19 Range('c1:g10').Columns('c') A1 style addressing + ITEM Assertion OK : test20 Range('c1:g10').Columns('c') R1C1 style addressing + ITEM Assertion OK : test21 Range('c1:g10').Columns('x:z') A1 style addressing + ITEM Assertion OK : test22 Range('c1:g10').Columns('x:z') R1C1 style addressing + ITEM Assertion OK : test23 Range('c1:g10').Columns(30) A1 style addressing + ITEM Assertion OK : test24 Range('c1:g10').Columns(30) R1C1 style addressing + ITEM Assertion OK : test25 Worksheets('Sheet2').Cells(1, 1) A1 style addressing + ITEM Assertion OK : test26 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, RowAddressAbsolute is false + ITEM Assertion OK : test27 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, ColAddressAbsolute is false + ITEM Assertion OK : test28 Worksheets('Sheet2').Cells(1, 1) R1C1 style addressing + ITEM Assertion OK : test29 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing + ITEM Assertion OK : test30 Worksheets('Sheet2').Range('A1').EntireColumn A1 style addressing + ITEM Assertion OK : test31 Worksheets('Sheet2').Range('A1:E5').EntireRow A1 style addressing + ITEM Assertion OK : test32 Worksheets('Sheet2').Range('A1') A1 style addressing + ITEM Assertion OK : test33 Worksheets('Sheet2').Range('IV65536').EntireRow A1 style addressing + ITEM Assertion OK : test34 Worksheets('Sheet2').Range('IU2:IV65536') A1 style addressing + ITEM Assertion OK : test35 Range('c1:g10').Columns('x:z') R1C1 style addressing + ITEM Assertion OK : test36 Worksheets('Sheet2').Range('A1') A1 style addressing + ITEM Assertion OK : test37 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing + ITEM Assertion OK : test38 Worksheets('Sheet2').Range('10:12') A1 style addressing + ITEM Assertion OK : test39 Worksheets('Sheet2').Range('10:12') R1C1 style addressing + ITEM Assertion OK : test40 Range('Sheet3!A1:B4') A1 style addressing + ITEM Assertion OK : test41 Range('Sheet3!A1,B1,D4:F20') A1 style addressing + ITEM Assertion OK : test42 Range('g20:h40').Columns('c:c') + ITEM Assertion OK : test43 Range('g20:h40').Columns('c:f') + ITEM Assertion OK : test44 Range('g20:h40').Columns(-1) + ITEM Assertion OK : test45 Range('c4:g10').Rows(-1) + ITEM Assertion OK : test46 Range('a2:b4').Rows('1:1') + ITEM Assertion OK : test47 Range('a2:b4').Rows('1:2') + ITEM Assertion OK : test48 Range('a2:b4').Rows('2:2') + ITEM Assertion OK : test49 Range('a2:b4').Rows('2:3') + ITEM Assertion OK : test50 Range(' A2:B4 ') + ITEM Assertion OK : test51 Range('A 2:B 4') + ITEM Assertion OK : test52 Range('A2 : B4 ') + ITEM Assertion OK : test53 Range('Sheet1 !A2 : B4 ') + ITEM Assertion OK : test54 Range('Sheet1! A2 : B4 ') +Test Results +============ + +Tests passed: 54 +Tests failed: 0 + +END 'TestAddress + TEST OK : TestAddress +Test run finished : 12/05/2009 11:23:35 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestCalc_Rangetest.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestCalc_Rangetest.log new file mode 100644 index 000000000000..083819d4b64e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestCalc_Rangetest.log @@ -0,0 +1,60 @@ +Test run started : 30/05/2007 15:59:40 +BEGIN TestCalc + TEST START : RangeTest2 + ITEM Assertion OK : - Range("D15").Row + ITEM Assertion OK : - WorkSheet("D15").Range.Row + ITEM Assertion OK : - Range("D15").Column + ITEM Assertion OK : - Worksheet.Range("D15").Column + ITEM Assertion OK : - Range("D1").EntireRow.Valuer + ITEM Assertion OK : - Range("D1").EntireRow.Valuer + ITEM Assertion OK : - Range("D1").EntireRow.Columns.Count + ITEM Assertion OK : - Range("D1").EntireColumn.Rows.Count + ITEM Assertion OK : - Range("D15").ClearContent + ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (get) + ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (get) + ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (get) + ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (get) + ITEM Assertion OK : - Range("B38").Orientation (get) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlDownward) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlUpward) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical) + ITEM Assertion OK : - Range("B39").WrapText (get) + ITEM Assertion OK : - Range("B39").WrapText (set) + ITEM Assertion OK : - Range("B39").WrapText (set) + ITEM Assertion OK : - Range("E39").MergeCells (get) + ITEM Assertion OK : - Range("F39").MergeCells (get) + ITEM Assertion OK : - Range("E39").MergeCells (set) + ITEM Assertion FAIL : - Range("F39").MergeCells (set) + ITEM Assertion OK : - Range("E39").MergeCells (set) + ITEM Assertion OK : - Range("F39").MergeCells (set) + ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True + ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True + ITEM Assertion OK : - Range("D41:D42").Replace MatchCase:=False + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (set) + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (set) + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM FAIL (RangeTest2) + TEST Not succesfully completed : RangeTest2 +END TestCalc +Test run finished : 30/05/2007 15:59:42 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestCalc_Rangetest2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestCalc_Rangetest2.log new file mode 100644 index 000000000000..b1573c06d90e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestCalc_Rangetest2.log @@ -0,0 +1,65 @@ +Test run started : 10/03/2008 15:15:19 +BEGIN TestCalc + TEST START : RangeTest3 + ITEM Assertion OK : - setFormulaR1C1 + ITEM Assertion OK : - getFormulaR1C1 + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Copy(Range("I10")) + ITEM Assertion OK : PasteSpecial Paste:=xlPasteValues + ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormulas + ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormats + ITEM Assertion OK : PasteSpecial + ITEM Assertion OK : PasteSpecial SkipBlanks:=True + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationAdd + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationSubtract + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationMultiply + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationDivide + ITEM Assertion OK : PasteSpecial Transpose:=True + ITEM Assertion FAIL : ActiveWorkbook.FileFormat + ITEM Assertion OK : ActiveWorkbook.Name + ITEM Assertion OK : ActiveWorkbook.FullName und ActiveWorkbook.Path + ITEM Assertion FAIL : - = ActiveWorkbook.Colors(3) set + ITEM Assertion OK : - = ActiveWorkbook.ResetColors + ITEM Assertion OK : - = ActiveWorkbook.Colors(3) get + ITEM Assertion OK : - = Range("K22").End (xlDown) + ITEM Assertion OK : - = Range("K22").End (xlUo) + ITEM Assertion OK : - = Range("K22").End (xlToLeft) + ITEM Assertion OK : - = Range("K22").End (xlRight) + ITEM Assertion OK : - ActiveSpreadsheet.Next + ITEM Assertion OK : - ActiveSpreadsheet.Next + ITEM Assertion OK : - ActiveSpreadsheet.Previous + ITEM Assertion OK : - ActiveSpreadsheet.Previous + ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="x" + ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="<>" + ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="=" + ITEM Assertion OK : - Range("J4:J11").AutoFilter + ITEM Assertion OK : - ActiveSheet.Resize.Select + ITEM Assertion OK : - Application.GoTo Reference:="R8C2" + ITEM Assertion FAIL : - Application.GoTo Reference:="R[8]C[2]" + ITEM Assertion OK : - Application.GoTo Reference:="R8C2" + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.Ungroup- please check visually + ITEM Assertion OK : - Range.Ungroup - please check visually + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.clearOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually + ITEM Assertion OK : - ActiveSheet.UsedRange.Select + ITEM Assertion OK : - Range("A13").AddIndent + ITEM Assertion OK : - Range("A13").IndentLevel set + ITEM Assertion OK : - Range("A13").IndentLevel get + ITEM Assertion OK : - Range("A13").IndentLevel get + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Calculate + ITEM Assertion OK : Worksheet.Calculate + ITEM Assertion OK : - Application.Calculate + ITEM Assertion OK : Global.Calculate + ITEM Assertion OK : Calculation set + ITEM FAIL (RangeTest3) + TEST Not succesfully completed : RangeTest3 +END TestCalc +Test run finished : 10/03/2008 15:15:21 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestIntersection.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestIntersection.log new file mode 100644 index 000000000000..ea686a830cde --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestIntersection.log @@ -0,0 +1,26 @@ +Test run started : 13/01/2009 14:31:43 +---------------------------------------------------------------- +TestIntersection + TEST START : TestIntersection + ITEM Assertion OK : test1 Application.Intersect( Range('A2:D10'), Range('C4:E6')) + ITEM Assertion OK : test2 Application.Intersect( Range('A2:D10'), Range('A4:G10')) + ITEM Assertion OK : test3 Application.Intersect( Range('A2:c8,d2:f8,g2:i8'), Range('A4:G10')) + ITEM Assertion OK : test4 Application.Intersect( Range('A4:G10'), Range('A2:c8,d2:f8,g2:i8')) + ITEM Assertion OK : test5 Application.Intersect( Range('A2:c8,d2:f8,g2:i8'), Range('g4:i10,A4:G10')) + ITEM Assertion OK : test6 Application.Intersect( Range('g4:i10,A4:G10'), Range('A2:c8,d2:f8,g2:i8')) + ITEM Assertion OK : test7 Application.Intersect( Range('a2:d10,b5:e10'), Range('a5:i10')) + ITEM Assertion OK : test8 Application.Intersect( Range('a2:c8,d2:f8'), Range('b6:e9,a6:f9')) + ITEM Assertion OK : test9 Application.Intersect( Range('a2:c8,e2:f8'), Range('b6:e9,a6:f9')) + ITEM Assertion OK : test10 Application.Intersect( Range('a1:a3,c1:c3'), Range('a2:c3')) + ITEM Assertion OK : test11 Application.Intersect( Range('a1:a3,b1:b3'), Range('a2:c3')) + ITEM Assertion OK : test12 Application.Intersect( Range('a2:d5,b3:f7,c1:g4'), Range('b2:e6')) + ITEM Assertion OK : test13 Range(" a2:d10,b5:e10,g13:j32 "), Range(" a5:i10,b6:e9 "), Range("b2:r5,f10:h19") +Test Results +============ + +Tests passed: 13 +Tests failed: 0 + +END 'TestIntersection + TEST OK : TestIntersection +Test run finished : 13/01/2009 14:31:43 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestUnion.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestUnion.log new file mode 100644 index 000000000000..da3cb35dedb3 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/TestUnion.log @@ -0,0 +1,17 @@ +Test run started : 13/01/2009 14:32:16 +---------------------------------------------------------------- +TestUnion + TEST START : TestUnion + ITEM Assertion OK : test1Application.Range('A2:D10'), Range('C4:E6') + ITEM Assertion OK : test2Application.Range('A2:D5,a3:d4'), Range('A4:G10') + ITEM Assertion OK : test3Application.Range('A4:G10,A1:B6'), Range('A2:D5,A3:D4') + ITEM Assertion OK : test4Application.Range('A5:D10'), Range('B5:E10') +Test Results +============ + +Tests passed: 4 +Tests failed: 0 + +END 'TestUnion + TEST OK : TestUnion +Test run finished : 13/01/2009 14:32:16 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/VariantTest.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/VariantTest.log new file mode 100644 index 000000000000..a916ac4a37fd --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/VariantTest.log @@ -0,0 +1,47 @@ +Test run started : 24/09/2008 10:58:18 +---------------------------------------------------------------- +TestAddress + TEST START : TestAddress + ITEM Assertion OK : test1: res = (aboo = '') + ITEM Assertion OK : test 2: res = (aboo = 'fiddlesticks') + ITEM Assertion OK : test 3: res = ('' = aboo) + ITEM Assertion OK : test 4: res = ('fiddlesticks' = aboo ) + ITEM Assertion OK : test 5: res = (testString = '') + ITEM Assertion OK : test 6: res = (testString = 'fiddlesticks') + ITEM Assertion OK : test 7: res = ('' = testString) + ITEM Assertion OK : test 8: res = ('fiddlesticks' = testString ) + ITEM Assertion OK : test 9: res = ( aboo < " ) + ITEM Assertion OK : test 10: res = ( testString < " ) + ITEM Assertion OK : test 11: res = ( aboo > " ) + ITEM Assertion OK : test 12: res = ( testString > " ) + ITEM Assertion OK : test 13: res = ( aboo <> '' ) + ITEM Assertion OK : test 14: res = ( testString <> '' ) + ITEM Assertion OK : test 15: res = (aboo = something/14) + ITEM Assertion OK : test 16: res = something + 'string' + ITEM Assertion OK : test 17: res = something & 'string' + ITEM Assertion OK : test 18: res = something MOD 10 ) + ITEM Assertion OK : test 19: res = something AND 1 ) + ITEM Assertion OK : test 20: res = something AND 0 ) + ITEM Assertion OK : test 21: res = something OR 12) + ITEM Assertion OK : test 22: res = something OR 0 ) + ITEM Assertion OK : test 23: res = something XOR 0 ) + ITEM Assertion OK : test 24: res = something XOR 1 ) + ITEM Assertion OK : test 25: res = something EQV 0 ) + ITEM Assertion OK : test 26: res = something EQV 1 ) + ITEM Assertion OK : test 27: res = something IMP 0 ) + ITEM Assertion OK : test 28: res = something IMP 1 ) + ITEM Assertion OK : test 29: res = something IMP 14 ) + ITEM Assertion OK : test 30: res = NOT something ) + ITEM Assertion OK : test 31: res = something + 12 ) + ITEM Assertion OK : test 32: res = something - 12 ) + ITEM Assertion OK : test 33: res = -something ) + ITEM Assertion OK : test 34: res = something * 12 ) +Test Results +============ + +Tests passed: 34 +Tests failed: 0 + +END 'TestAddress + TEST OK : TestAddress +Test run finished : 24/09/2008 10:58:20 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Window.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Window.log new file mode 100644 index 000000000000..ec9a6656113e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/Window.log @@ -0,0 +1,46 @@ +Test run started : 05/29/2008 02:55:00 PM +---------------------------------------------------------------- + TEST START : Window-Issue + ITEM Assertion OK : Window.Left is: 0 (Test only applies to maximized Window) + ITEM Assertion OK : Window.Top is: 21 (Test only applies to maximized Window) + ITEM Assertion OK : Window.Width is: 1280 (Test only applies to maximized Window) + ITEM Assertion OK : Window.Height is: 752 (Test only applies to maximized Window) + ITEM Assertion OK : Window.ScrollColumn is: 100 + ITEM Assertion OK : Window.ScrollColumn is: 1 + ITEM Assertion OK : Window.ScrollRow is: 100 + ITEM Assertion OK : Window.ScrollRow is: 1 + ITEM Assertion OK : Window.LargeScroll(Down): ScrollRow is: 94 (Test may only apply to maximized Window) + ITEM Assertion OK : Window.LargeScroll(Up): ScrollRow is: 1 + ITEM Assertion OK : Window.LargeScroll(ToRight): ScrollColumn is: 58 (Test may only apply to maximized Window) + ITEM Assertion OK : Window.LargeScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Window.SmallScroll(ToRight): ScrollColumn is: 4 (Test may only apply to maximized Window) + ITEM Assertion OK : Window.SmallScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Window.DisplayWorkBookTabs is: False + ITEM Assertion OK : Window.DisplayWorkBookTabs is: True + ITEM Assertion OK : Window.DisplayVerticalScrollBar is: True + ITEM Assertion OK : Window.DisplayVerticalScrollBar is: False + ITEM Assertion OK : Window.DisplayHorizontalScrollBar is: False + ITEM Assertion OK : Window.DisplayHorizontalScrollBar is: True + ITEM Assertion OK : Window.DisplayHeadings is: False + ITEM Assertion OK : Window.DisplayHeadings is: True + ITEM Assertion OK : Window.DisplayOutline is: False + ITEM Assertion OK : Window.DisplayOutline is: True + ITEM Assertion OK : Window.Visible is: False + ITEM Assertion OK : Window.Visible is: True + ITEM Assertion OK : Window.Caption is: MyCaption + ITEM Assertion OK : Pane.ScrollColumn is: 100 + ITEM Assertion OK : Pane.ScrollColumn is: 1 + ITEM Assertion OK : Pane.ScrollRow is: 100 + ITEM Assertion OK : Pane.ScrollRow is: 1 + ITEM Assertion OK : Pane.LargeScroll(Down): ScrollRow is: 94 (Test may only apply to maximized Window) + ITEM Assertion OK : Pane.LargeScroll(Up): ScrollRow is: 1 + ITEM Assertion OK : Pane.LargeScroll(ToRight): ScrollColumn is: 58 (Test may only apply to maximized Window) + ITEM Assertion OK : Pane.LargeScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Pane.SmallScroll(ToRight): ScrollColumn is: 4 (Test may only apply to maximized Window) + ITEM Assertion OK : Pane.SmallScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Window Selection: $A$2:$D$5 + ITEM Assertion OK : ActiveSheet name of Window: Sheet1 + ITEM Assertion OK : Window ActiveCell: $A$1 +END 'Window-Issue' Symbol + TEST OK : Window-Issue +Test run finished : 05/29/2008 02:55:01 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/bytearraystring.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/bytearraystring.log new file mode 100644 index 000000000000..bd243283d8f1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/bytearraystring.log @@ -0,0 +1,8 @@ +Test run started : 05/29/2008 02:25:58 PM +BEGIN Bytearray To String + TEST START : Test the conversion between bytearray and string + ITEM Assertion OK : The number of byte is:6 + ITEM Assertion OK : the return string is: abc + TEST OK : Test the conversion between bytearray and string +END Bytearray To String +Test run finished : 05/29/2008 02:25:58 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/dateserial.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/dateserial.log new file mode 100644 index 000000000000..4dd5f53160f2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/dateserial.log @@ -0,0 +1,9 @@ +Test run started : 01/24/2008 01:24:50 PM +BEGIN DateSerial + TEST START : Test DateSerial function + ITEM Assertion OK : the return date is: 06/15/1999 + ITEM Assertion OK : the return date is: 06/15/1999 + ITEM Assertion OK : the return date is: 06/15/1999 + TEST OK : Test DateSerial function +END DateSerial +Test run finished : 01/24/2008 01:24:50 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/datevalue.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/datevalue.log new file mode 100644 index 000000000000..830d5e7b6c3e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/datevalue.log @@ -0,0 +1,8 @@ +Test run started : 01/24/2008 01:24:41 PM +BEGIN DateValue + TEST START : Test DateValue function + ITEM Assertion OK : the return date is: 02/12/1969 + ITEM Assertion OK : the return date is: 01/21/2008 + TEST OK : Test DateValue function +END DateValue +Test run finished : 01/24/2008 01:24:41 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/format.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/format.log new file mode 100644 index 000000000000..96725bf7daa8 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/format.log @@ -0,0 +1,36 @@ +Test run started : 2008/09/18 11:35:34 +BEGIN Format + TEST START : Test Predefined_Number_Format_Sample function + ITEM Assertion OK : General Number: 562486.2356 + ITEM Assertion OK : Fixed: 0.20 + ITEM Assertion OK : Standard: 562,486.24 + ITEM Assertion OK : Percent: 75.21% + ITEM Assertion OK : Scientific: 5.62E+05 + ITEM Assertion OK : Scientific: -3.46E+03 + ITEM Assertion OK : Yes/No: No + ITEM Assertion OK : Yes/No: Yes + ITEM Assertion OK : True/False: False + ITEM Assertion OK : True/False: True + ITEM Assertion OK : On/Off: Off + ITEM Assertion OK : On/Off: On + TEST OK : Test Predefined_Number_Format_Sample function + TEST START : Test Custom_Number_Format_Sample function + ITEM Assertion OK : 00.0000: 23.6750 + ITEM Assertion OK : 00.00: 23.68 + ITEM Assertion OK : 00000: 02658 + ITEM Assertion OK : 00.00: 2658.00 + ITEM Assertion OK : ##.####: 23.675 + ITEM Assertion OK : ##.##: 23.68 + ITEM Assertion OK : #,###.##: 12,345.25 + ITEM Assertion OK : ##.00%: 25.00% + ITEM Assertion OK : #,###: 1,000,000 + ITEM Assertion OK : ######E-###: 109838E-5 + ITEM Assertion OK : $#,###.##: $2,345.25 + ITEM Assertion OK : ##.###\%: .25% + TEST OK : Test Custom_Number_Format_Sample function + TEST START : Test Custom_Text_Format_Sample function + ITEM Assertion OK : <: vba + ITEM Assertion OK : >: VBA + TEST OK : Test Custom_Text_Format_Sample function +END Format +Test run finished : 2008/09/18 11:35:34 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/pagesetup.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/pagesetup.log new file mode 100644 index 000000000000..f04585c3f9e1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/pagesetup.log @@ -0,0 +1,77 @@ +Test run started : 07/21/2008 02:00:06 PM +BEGIN PageSetup + TEST START : Sheet_PrintArea + ITEM Assertion OK : PrintArea has changed as expected + TEST OK : Sheet_PrintArea + TEST START : Test margins (no headers) + ITEM Assertion OK : PageSetup.LeftMargin set/get + ITEM Assertion OK : PageSetup.RightMargin set/get + ITEM Assertion OK : PageSetup.TopMargin set/get + ITEM Assertion OK : PageSetup.BottomMargin set/get +Verify that page margins on sheet 1 are all 0.5inch + TEST OK : Test margins (no headers) + TEST START : Test margins (headers) + ITEM Assertion OK : PageSetup.HeaderMargin set/get + ITEM Assertion OK : PageSetup.FooterMargin set/get + ITEM Assertion OK : PageSetup.LeftMargin set/get + ITEM Assertion OK : PageSetup.LeftMargin set/get +Verify that top/bottom/header/footer page margins on sheet 2 are all 0.5inch + TEST OK : Test margins (headers) + TEST START : Test header/footer text + ITEM Assertion OK : PageSetup.LeftHeader set + ITEM Assertion OK : PageSetup.LeftHeader set/get + ITEM Assertion OK : PageSetup.CenterHeader set + ITEM Assertion OK : PageSetup.CenterHeader set/get + ITEM Assertion OK : PageSetup.RightHeader set + ITEM Assertion OK : PageSetup.RightHeader set/get + ITEM Assertion OK : PageSetup.LeftFooter set + ITEM Assertion OK : PageSetup.LeftFooter set/get + ITEM Assertion OK : PageSetup.CenterFooter set + ITEM Assertion OK : PageSetup.CenterFooter set/get + ITEM Assertion OK : PageSetup.RightFooter set + ITEM Assertion OK : PageSetup.RightFooter set/get +Verify that headers on sheet 2 are Ready,to,go +Verify that footers on sheet 2 are This,now,Works + TEST OK : Test header/footer text + TEST START : Test zoom + ITEM Assertion OK : PageSetup.Zoom set + ITEM Assertion OK : PageSetup.Zoom set/get +Verify that sheet 1 zoom is 10% + TEST OK : Test zoom + TEST START : Test orientation + ITEM Assertion OK : PageSetup.Zoom set + ITEM Assertion OK : PageSetup.Orientation set/get +Verify that sheet 1 orientation is now landscape + TEST OK : Test orientation + TEST START : Test order + ITEM Assertion OK : PageSetup.Order get + ITEM Assertion OK : PageSetup.Order set/get +Verify that order on sheet 1 is now over, then down. + TEST OK : Test order + TEST START : Test first page number + ITEM Assertion OK : PageSetup.FirstPageNumber get + ITEM Assertion OK : PageSetup.FirstPageNumber set/get +Verify that first page number on sheet 1 is now 2. + TEST OK : Test first page number + TEST START : Test center vertically + ITEM Assertion OK : PageSetup.CenterVertically get + ITEM Assertion OK : PageSetup.CenterVertically set/get +Verify that CenterVertically on sheet 1 is now true. + TEST OK : Test center vertically + TEST START : Test center horizontally + ITEM Assertion OK : PageSetup.CenterHorizontally get + ITEM Assertion OK : PageSetup.CenterHorizontally set/get +Verify that CenterHorizontally on sheet 1 is now true. + TEST OK : Test center horizontally + TEST START : Test FitToPagesTall + ITEM Assertion OK : PageSetup.FitToPagesTall set/get + TEST OK : Test FitToPagesTall + TEST START : Test FitToPagesWide + ITEM Assertion OK : PageSetup.FitToPagesWide set/get + TEST OK : Test FitToPagesWide + TEST START : Test PrintHeadings + ITEM Assertion OK : PageSetup.PrintHeadings set/get + ITEM Assertion OK : PageSetup.PrintHeadings set/get + TEST OK : Test PrintHeadings +END PageSetup +Test run finished : 07/21/2008 02:00:07 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/partition.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/partition.log new file mode 100644 index 000000000000..7b4f2a01bead --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/partition.log @@ -0,0 +1,11 @@ +Test run started : 12/10/2007 11:26:43 AM +BEGIN Partition + TEST START : Test Partition function + ITEM Assertion OK : the number 20 occurs in the range:20:24 + ITEM Assertion OK : the number 20 occurs in the range: 20: 20 + ITEM Assertion OK : the number 120 occurs in the range:100: + ITEM Assertion OK : the number -5 occurs in the range: : -1 + ITEM Assertion OK : the number 2 occurs in the range: 2: 3 + TEST OK : Test Partition function +END Partition +Test run finished : 12/10/2007 11:26:43 AM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/range-4.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/range-4.log new file mode 100644 index 000000000000..fb37b6ff201b --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/range-4.log @@ -0,0 +1,16 @@ +Test run started : 2008/06/19 17:14:57 +---------------------------------------------------------------- +ShowDetail-Issue + TEST START : ShowDetail-Issue + ITEM Assertion OK : Range.ShowDetail is True + ITEM Assertion OK : Range.ShowDetail is False +END 'ShowDetail-Issue' Symbol + TEST OK : ShowDetail-Issue +---------------------------------------------------------------- +RangeMerged-Issue + TEST START : RangeMerged-Issue + ITEM Assertion OK : Range.RangeMerged is $F$2:$H$5 + ITEM Assertion OK : The first address of Range.RangeMerged is $F$2 +END 'RangeMerged-Issue' Symbol + TEST OK : RangeMerged-Issue +Test run finished : 2008/06/19 17:14:57 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/replace.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/replace.log new file mode 100644 index 000000000000..8f600faaa6b1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/replace.log @@ -0,0 +1,14 @@ +Test run started : 09/05/2008 10:21:46 AM +BEGIN Replace + TEST START : Test Replace function + ITEM Assertion OK : common string:aefefdBc + ITEM Assertion OK : expression string:aefefdef + ITEM Assertion OK : binanary compare:aefefdBc + ITEM Assertion OK : text compare:aefefdef + ITEM Assertion OK : text compare:aefefdef + ITEM Assertion OK : start = 3:cefdBc + ITEM Assertion OK : count = 2: aefefdBc + ITEM Assertion OK : start = 1, count = 0, not support in Unix: abcbcdBc + TEST OK : Test Replace function +END Replace +Test run finished : 09/05/2008 10:21:47 AM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/stringplusdouble.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/stringplusdouble.log new file mode 100644 index 000000000000..6e8b8d994bd1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/stringplusdouble.log @@ -0,0 +1,62 @@ +Test run started : 05/29/2008 02:51:22 PM +BEGIN String Plus Double + TEST START : double = string + double +The next compute raises error: s = null, d = null, r = s + d + ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = null, r = s & d .The result is: 0 +The next compute raises error: s = null, d = 20, r = s + d + ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20 + ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10 + ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 100 + ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 30 + ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020 +The next compute raises error: s = 'abc', d = null, r = s + d + ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = null, r = s & d + ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s + d + ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s & d + ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: -1 + TEST OK : double = string + double + TEST START : string = string + double +The next compute raises error: s = null, d = null, r = s + d + ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = null, r = s & d .The result is: 0 +The next compute raises error: s = null, d = 20, r = s + d + ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20 + ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10 + ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 100 + ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 30 + ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020 +The next compute raises error: s = 'abc', d = null, r = s + d + ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1 + ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: abc0 +The next compute raises error: s = 'abc', d = 20, r = s + d + ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1 + ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: abc20 + TEST OK : string = string + double + TEST START : double = string + string +The next compute raises error: s = null, d = null, r = s + d + ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1 +The next compute raises error: s = null, d = null, r = s & d + ITEM Assertion OK : s = null, d = null, r = s & d .The result is: -1 + ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: 20 + ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20 + ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10 + ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 10 + ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 1020 + ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020 +The next compute raises error: s = 'abc', d = null, r = s + d + ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = null, r = s & d + ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s + d + ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s & d + ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: -1 + TEST OK : double = string + string +END String Plus Double +Test run finished : 05/29/2008 02:51:22 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/window2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/window2.log new file mode 100644 index 000000000000..8e26d0580621 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/unix/window2.log @@ -0,0 +1,41 @@ +Test run started : 2008/09/22 11:18:57 +BEGIN Window2 + TEST START : Test Window.SplitRow + ITEM Assertion OK : Test SplitColumn: 2 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitRow: 2 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitVertical: 242.465788476212 + ITEM Assertion OK : Test SplitHorizontal: 242.465788476212 + ITEM Assertion OK : Test SplitRow: 4 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitColumn: 3 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitColumn: 0 + ITEM Assertion OK : Test SplitRow: 0 + TEST OK : Test Window.SplitRow + TEST START : Test Window.DisplayGridlines + ITEM Assertion OK : Test gridlines are on + ITEM Assertion OK : Test gridlines are off + TEST OK : Test Window.DisplayGridlines + TEST START : Test Window.DisplayHeadings + ITEM Assertion OK : Test Headings are on + ITEM Assertion OK : Test Headings are off + TEST OK : Test Window.DisplayHeadings + TEST START : Test Window.Visibility + ITEM Assertion OK : Window is visible + ITEM Assertion OK : Window is not visible + TEST OK : Test Window.Visibility + TEST START : Test Window.FreezePanes + ITEM Assertion OK : Test no panes frozen + ITEM Assertion OK : Test panes frozen at center + ITEM Assertion OK : Test panes frozen at split + TEST OK : Test Window.FreezePanes + TEST START : Test Window.View + TEST OK : Test Window.View + TEST START : Test Window.Zoom + ITEM Assertion OK : Test zoom=100% + ITEM Assertion OK : Test zoom=150% + TEST OK : Test Window.Zoom + TEST START : Test Windows.Count + ITEM Assertion OK : Windows Count: 1 + ITEM Assertion OK : Application.Windows Count: 1 + TEST OK : Test Windows.Count +END Window2 +Test run finished : 2008/09/22 11:18:58 diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/AutoFilter.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/AutoFilter.log new file mode 100644 index 000000000000..b8d0b85a8ff9 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/AutoFilter.log @@ -0,0 +1,20 @@ +Test run started : 16/10/2007 17:42:01
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 'starts with' string criteria
+ ITEM Assertion OK : test2 'not equal to' string criteria
+ ITEM Assertion OK : test3 'ends with' string criteria
+ ITEM Assertion OK : test4 field 'all'
+ ITEM Assertion OK : test5 numeric '<15'
+ ITEM Assertion OK : test6 numeric '>=15'
+ ITEM Assertion OK : test7 numeric '<=12'
+Test Results
+============
+
+Tests passed: 7
+Tests failed: 0
+
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 16/10/2007 17:42:02
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/CalcFont.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/CalcFont.log new file mode 100644 index 000000000000..e8695523a0a1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/CalcFont.log @@ -0,0 +1,17 @@ +Test run started : 15/01/2009 17:00:35
+CalcFont_Format
+ TEST START : Font_Format
+ ITEM Assertion OK : correctly set font to Bold
+ ITEM Assertion OK : correctly set font to Italic
+ ITEM Assertion OK : correctly read FontStyle
+ ITEM Assertion OK : correctly set font to Shadow
+ ITEM Assertion OK : correctly set font color
+ ITEM Assertion OK : correctly set font color index
+ ITEM Assertion OK : correctly set font name
+ ITEM Assertion OK : correctly set font outline
+ ITEM Assertion OK : correctly set font size
+ ITEM Assertion OK : correctly set font strikethrough
+ ITEM Assertion OK : correctly set font underline
+ TEST Success. : Font_Format
+CalcFont_Format
+Test run finished : 15/01/2009 17:00:36
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/MiscOperatorTests.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/MiscOperatorTests.log new file mode 100644 index 000000000000..3ccec0a1577d --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/MiscOperatorTests.log @@ -0,0 +1,29 @@ +Test run started : 15/01/2009 17:03:13
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1: res = Not ( A > B )
+ ITEM Assertion OK : test2: res = Not ( B > A )
+ ITEM Assertion OK : test3: res = Not ( D )
+ ITEM Assertion OK : test4: res = Not A
+ ITEM Assertion OK : test5: res = ( A > D )
+ ITEM Assertion OK : test6: res = ( D > A )
+ ITEM Assertion OK : test7: res = ( A < D )
+ ITEM Assertion OK : test8: res = ( D < A )
+ ITEM Assertion OK : test9: res = ( A >= D )
+ ITEM Assertion OK : test10: res = ( D >= A )
+ ITEM Assertion OK : test11: res = ( A <= D )
+ ITEM Assertion OK : test12: res = ( D <= A )
+ ITEM Assertion OK : test13: res = ( D = A )
+ ITEM Assertion OK : test14: res = ( A = D )
+ ITEM Assertion OK : test15: res = ( D <> A )
+ ITEM Assertion OK : test16: res = ( A <> D )
+Test Results
+============
+
+Tests passed: 16
+Tests failed: 0
+
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 15/01/2009 17:03:15
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/MiscRangeTests.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/MiscRangeTests.log new file mode 100644 index 000000000000..d190abb5f645 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/MiscRangeTests.log @@ -0,0 +1,45 @@ +Test run started : 17/07/2007 15:08:56
+----------------------------------------------------------------
+MiscRangeTests
+ TEST START : MiscRangeTests
+ ITEM Assertion OK : test 1
+ ITEM Assertion OK : test 2
+ ITEM Assertion OK : test 3
+ ITEM Assertion OK : test 4
+ ITEM Assertion OK : test 5
+ ITEM Assertion OK : test 6
+ ITEM Assertion OK : test 7
+ ITEM Assertion OK : test 8
+ ITEM Assertion OK : test 9
+ ITEM Assertion OK : test 10
+ ITEM Assertion OK : test 11
+ ITEM Assertion OK : test 12
+ ITEM Assertion OK : test 13
+ ITEM Assertion OK : test 14
+ ITEM Assertion OK : test 15
+ ITEM Assertion OK : test 16
+ ITEM Assertion OK : test 17
+ ITEM Assertion OK : test 18
+ ITEM Assertion OK : test 19
+ ITEM Assertion OK : test 20
+ ITEM Assertion OK : test 21
+ ITEM Assertion OK : test 22
+ ITEM Assertion OK : test 23
+ ITEM Assertion OK : test 24
+ ITEM Assertion OK : test 25
+ ITEM Assertion OK : test 26
+ ITEM Assertion OK : test 27
+ ITEM Assertion OK : test 28
+ ITEM Assertion OK : test 29
+ ITEM Assertion OK : test 30
+ ITEM Assertion OK : test 31
+No. tests: 31
+Summary
+=======
+Run: 31
+Passed: 31
+Failed: 0
+
+END 'MiscRangeTests
+ TEST OK : MiscRangeTests
+Test run finished : 17/07/2007 15:08:59
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/PageBreaks.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/PageBreaks.log new file mode 100644 index 000000000000..30b6e45d1681 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/PageBreaks.log @@ -0,0 +1,10 @@ +Test run started : 08/10/2008 12:02:12
+----------------------------------------------------------------
+ TEST START : PageBreaks-Issue
+ ITEM Assertion OK : HPageBreaks.Count is 3
+ ITEM Assertion OK : HPageBreak.Type is -4135
+ ITEM Assertion OK : HPageBreak.Location: Range.Row is 5
+ ITEM Assertion OK : HPageBreak.Delete: HPageBreaks.Count is 2
+END 'PageBreaks-Issue' Symbol
+ TEST OK : PageBreaks-Issue
+Test run finished : 08/10/2008 12:02:12
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges-2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges-2.log new file mode 100644 index 000000000000..b80d996e3d3f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges-2.log @@ -0,0 +1,68 @@ +Test run started : 10/07/2007 01:55:47
+----------------------------------------------------------------
+ClearFormtsIssue
+ TEST START : ClearFormtsIssue
+ ITEM Assertion OK : Range.Font.Bold is: True
+ ITEM Assertion OK : Range.Font.Bold is: False
+END 'ClearFormtsIssue' Symbol
+ TEST OK : ClearFormtsIssue
+----------------------------------------------------------------
+VerticalAlignment-Issue
+ TEST START : VerticalAlignment-Issue
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : Range.VeritcalAlignment is Null
+END 'VerticalAlignment-Issue' Symbol
+ TEST OK : VerticalAlignment-Issue
+----------------------------------------------------------------
+HorizontalAlignment-Issue
+ TEST START : HorizontalAlignment-Issue
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : Range.HorizontalAlignment is Null
+END 'HorizontalAlignment-Issue' Symbol
+ TEST OK : HorizontalAlignment-Issue
+----------------------------------------------------------------
+WrapText-Issue
+ TEST START : WrapText-Issue
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : Range.WrapText is Null
+END 'WrapText-Issue' Symbol
+ TEST OK : WrapText-Issue
+----------------------------------------------------------------
+FontBorderIssues
+ TEST START : FontBorderIssues
+ ITEM Assertion OK : - = Borders.Color (getColor)
+ ITEM Assertion OK : - = Font.Color (getColor)
+END 'FontBorderIssues' Symbol
+ TEST OK : FontBorderIssues
+----------------------------------------------------------------
+RangeSizeIssues
+ TEST START : RangeSizeIssues
+ ITEM Assertion OK : Range.Left is: 100.5291
+ ITEM Assertion OK : Range.Top is: 95.39775
+ ITEM Assertion OK : Range.Width is: 191.25
+ ITEM Assertion OK : Range.Height is: 271.5
+END 'RangeSizeIssues' Symbol
+ TEST OK : RangeSizeIssues
+----------------------------------------------------------------
+ApplicationIssues
+ TEST START : ApplicationIssues
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Application.ActiveSheet.Name: Sheet1
+END 'ApplicationIssues' Symbol
+ TEST OK : ApplicationIssues
+Test run finished : 10/07/2007 01:55:48
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges-3.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges-3.log new file mode 100644 index 000000000000..365d126a7e2d --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges-3.log @@ -0,0 +1,8 @@ +Test run started : 10/07/2007 01:55:51
+----------------------------------------------------------------
+MyGoalseek-Issue
+ TEST START : MyGoalseek-Issue
+ ITEM Assertion OK : Variable Range value: 15
+END 'MyGoalseek-Issue' Symbol
+ TEST OK : MyGoalseek-Issue
+Test run finished : 10/07/2007 01:55:51
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges.log new file mode 100644 index 000000000000..6491fe4173ec --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Ranges.log @@ -0,0 +1,280 @@ +Test run started : 08/10/2008 11:30:21
+----------------------------------------------------------------
+ApplicationMethods
+ TEST START : ApplicationMethods
+ ITEM Assertion OK : Name of Workbook is: Ranges.xls
+ ITEM Assertion OK : Address of Application.Columns is: $A:$A
+ ITEM Assertion OK : Address of Application.Rows is: $1:$1
+ ITEM Assertion OK : Address of Application.Range is: $1:$1,$5:$7
+ ITEM Assertion OK : Please check manually: DefaultFilePath is: C:\Documents and Settings\vituosity\My Documents
+ ITEM Assertion OK : Please check manually: Library Path is: C:\Documents and Settings\vituosity\Application Data\OpenOffice.org\3\user\basic
+ ITEM Assertion OK : Please check manually: Template Path is: C:\Documents and Settings\vituosity\Application Data\OpenOffice.org\3\user\template
+ ITEM Assertion OK : FileSeparator is \
+ ITEM Assertion OK : Name of ActiveWorkbook is: Ranges.xls
+END 'ApplicationMethods' Symbol
+ TEST OK : ApplicationMethods
+----------------------------------------------------------------
+Insert-Issue
+ TEST START : Insert-Issue
+ ITEM Assertion OK : Insert with xlShiftToRight: 10
+END 'Insert-Issue' Symbol
+ TEST OK : Insert-Issue
+----------------------------------------------------------------
+MergeCells-Issue
+ TEST START : MergeCells-Issue
+ ITEM Assertion OK : Range.MergeCells is True
+ ITEM Assertion FAIL : MergeCells is null: False
+ ITEM Assertion OK : RowCount after Merge: 13
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion FAIL : MergeCells of Second Area is null : False
+ ITEM Assertion FAIL : MergeCells of Ranges is Null: False
+ ITEM Assertion OK : RowCount after Merge: 7
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion OK : RowCount after Merge: 7
+END 'MergeCells-Issue' Symbol
+ TEST OK : MergeCells-Issue
+----------------------------------------------------------------
+Areas-Issue
+ TEST START : Areas-Issue
+ ITEM Assertion OK : Range Areas Count is2
+ ITEM Assertion OK : First Range Address is: $E$8:$G$13
+ ITEM Assertion OK : First Row is: 8
+ ITEM Assertion OK : First Column is: 5
+ ITEM Assertion OK : EntireRow Address is: $8:$13,$13:$19
+ ITEM Assertion OK : EntireColumn Address is: $E:$G,$G:$K
+ ITEM Assertion OK : Range Count:53
+END 'Areas-Issue' Symbol
+ TEST OK : Areas-Issue
+----------------------------------------------------------------
+Fill-Methods-Issue
+ TEST START : Fill-Methods-Issue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyRightFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyBottomFillValue
+END 'Fill-Methods-Issue' Symbol
+ TEST OK : Fill-Methods-Issue
+----------------------------------------------------------------
+Range/Item-Method-Issue
+ TEST START : Range/Item-Method-Issue
+ ITEM Assertion OK : Range of multiple columns is: $A:$A,$C:$C
+ ITEM Assertion OK : Range of multiple rows is: $1:$1,$5:$7
+ ITEM Assertion OK : Range of several columns is: $C:$E,$D:$D
+ ITEM Assertion OK : Range of several rows is: $5:$8,$6:$10
+ ITEM Assertion OK : Range of several single cells is: $C$5,$E$8
+ ITEM Assertion OK : Range of several named ranges is: $L$1:$M$6,$E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range of a single Item Cell is: $E$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$10
+END 'Range/Item-Method-Issue' Symbol
+ TEST OK : Range/Item-Method-Issue
+----------------------------------------------------------------
+R1C1-Formulas-Issue
+ TEST START : R1C1-Formulas-Issue
+ ITEM Assertion OK : R1C1 Range.Formula is: =IF(OR(R[-2]C[1]=0,RC[2]="YES"),"")
+ ITEM Assertion OK : Range.Formula is: =IF(OR(J8=0,K10="YES"),"")
+END 'R1C1-Formulas-Issue' Symbol
+ TEST OK : R1C1-Formulas-Issue
+----------------------------------------------------------------
+Verify_Delete
+ TEST START : Verify_Delete
+ ITEM Assertion OK : Ranges are intersecting: $G$13
+ ITEM Assertion OK : Delete with Default: $AJ$4
+ ITEM Assertion OK : Delete with ShifttoLeft: $AJ$4
+ ITEM Assertion OK : Delete with ShiftUp: $M$22
+END 'Verify_Delete' Symbol
+ TEST OK : Verify_Delete
+----------------------------------------------------------------
+Value-Issue
+ TEST START : Value-Issue
+ ITEM Assertion OK : Value of Range is: 12.3
+ ITEM Assertion OK : Text of Range is: 12.3
+ ITEM Assertion OK : Range has Formula: False
+ ITEM Assertion OK : Cell has Formula: False
+ ITEM Assertion FAIL : Text of Range is null: False
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Cell has Formula: True
+ ITEM Assertion OK : Value of Cell is: 12
+ ITEM Assertion OK : Application.Calculation is : -4135
+ ITEM Assertion OK : Calculation is automated: True
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Value of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Range has Formula after 'ClearContents: False
+ ITEM Assertion OK : Text of Cell is:
+ ITEM Assertion OK : Text of Cell is:
+END 'Value-Issue' Symbol
+ TEST OK : Value-Issue
+----------------------------------------------------------------
+AutoFit issue
+ TEST START : AutoFit issue
+ ITEM Assertion OK : Columns.AutoFit: CurrentWidth is 680
+ ITEM Assertion OK : Rows.AutoFit: CurrentHeight is 582
+END 'AutoFit issue' Symbol
+ TEST OK : AutoFit issue
+----------------------------------------------------------------
+Selections
+ TEST START : Selections
+ ITEM Assertion OK : ActiveCell is : $E$8
+ ITEM Assertion OK : Active Cell is : $E$8
+ ITEM Assertion OK : Number of Cells in Range: 52
+ ITEM Assertion OK : Number of Cells in Range: 52
+ ITEM Assertion OK : Number of Cells in Range: 52
+END 'Selections' Symbol
+ TEST OK : Selections
+----------------------------------------------------------------
+Offset-Resize
+ TEST START : Offset-Resize
+ ITEM Assertion OK : Offset is : $G$10:$I$15,$I$15:$M$21
+ ITEM Assertion OK : Offset is : $G$7:$I$12,$I$12:$M$18
+ ITEM Assertion OK : Resized Range is : $A$20:$D$23
+END 'Offset-Resize' Symbol
+ TEST OK : Offset-Resize
+----------------------------------------------------------------
+Ranges-Address
+ TEST START : Ranges-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range Address is: $E8:$G13,$G13:$K19
+ ITEM Assertion OK : Range Address is: E$8:G$13,G$13:K$19
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion FAIL : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5],R[11]C[5]:R[17]C[9]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13,$G$13:$K$19
+END 'Ranges-Address' Symbol
+ TEST OK : Ranges-Address
+----------------------------------------------------------------
+Range-Address
+ TEST START : Range-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13
+ ITEM Assertion OK : Range Address is: $E8:$G13
+ ITEM Assertion OK : Range Address is: E$8:G$13
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion FAIL : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13
+END 'Range-Address' Symbol
+ TEST OK : Range-Address
+----------------------------------------------------------------
+Column-Address
+ TEST START : Column-Address
+ ITEM Assertion OK : Range Address is: $F$8:$F$13
+ ITEM Assertion OK : Range Address is: $F8:$F13
+ ITEM Assertion OK : Range Address is: F$8:F$13
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion FAIL : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: R[6]C[4]:R[11]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$8:$F$13
+END 'Column-Address' Symbol
+ TEST OK : Column-Address
+----------------------------------------------------------------
+Row-Address
+ TEST START : Row-Address
+ ITEM Assertion OK : Range Address is: $E$9:$G$9
+ ITEM Assertion OK : Range Address is: $E9:$G9
+ ITEM Assertion OK : Range Address is: E$9:G$9
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion FAIL : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: R[7]C[3]:R[7]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$9:$G$9
+END 'Row-Address' Symbol
+ TEST OK : Row-Address
+----------------------------------------------------------------
+SingleCell-Address
+ TEST START : SingleCell-Address
+ ITEM Assertion OK : Range Address is: $F$9
+ ITEM Assertion OK : Range Address is: $F9
+ ITEM Assertion OK : Range Address is: F$9
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion FAIL : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: R[7]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$9
+END 'SingleCell-Address' Symbol
+ TEST OK : SingleCell-Address
+----------------------------------------------------------------
+Heights and Widths
+ TEST START : Heights and Widths
+ ITEM Assertion OK : Range RowHeight is 40
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 240
+ ITEM Assertion FAIL : Range Width is 675
+ ITEM Assertion OK : Range RowHeight is 50
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 300
+ ITEM Assertion FAIL : Range Width is 675
+ ITEM Assertion OK : RowHeight is null: True
+ ITEM Assertion OK : ColumnWidth is null: True
+END 'Heights and Widths' Symbol
+ TEST OK : Heights and Widths
+----------------------------------------------------------------
+RangeRowColumn-Issue
+ TEST START : RangeRowColumn-Issue
+ ITEM Assertion OK : Row is: 8
+ ITEM Assertion OK : Column is: 5
+ ITEM Assertion OK : EntireRow.Columns.Count = 1024
+ ITEM Assertion OK : EntireColumn.Rows.Count = 131072
+END 'RangeRowColumn-Issue' Symbol
+ TEST OK : RangeRowColumn-Issue
+----------------------------------------------------------------
+Replace-Issue
+ TEST START : Replace-Issue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New Replace
+ ITEM Assertion OK : Value after Replace:
+END 'Replace-Issue' Symbol
+ TEST OK : Replace-Issue
+----------------------------------------------------------------
+Hidden-Issue
+ TEST START : Hidden-Issue
+ ITEM Assertion OK : - Range.Rows.Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Hidden (get)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (get)
+END 'Hidden-Issue' Symbol
+ TEST OK : Hidden-Issue
+----------------------------------------------------------------
+End issue
+ TEST START : End issue
+ ITEM Assertion OK : - = $E$48
+ ITEM Assertion OK : - = $E$1
+ ITEM Assertion OK : - = $E$3
+ ITEM Assertion OK : - = $A$8
+ ITEM Assertion OK : - = $B$8
+ ITEM Assertion OK : - = $AMJ$8
+ ITEM Assertion OK : - = $Z$8
+END 'End issue' Symbol
+ TEST OK : End issue
+----------------------------------------------------------------
+Outline issue
+ TEST START : Outline issue
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+END 'Outline issue' Symbol
+ TEST OK : Outline issue
+----------------------------------------------------------------
+Validation
+ TEST START : Validation
+ ITEM Assertion OK : Validation Input Message is : Attention!
+ ITEM Assertion OK : Validation Input Message is : Enter an integer from five to ten
+ ITEM Assertion OK : Validation Error Title is : You must enter a number from five to ten
+ ITEM Assertion OK : Validation Error Message is : An Error occured
+ ITEM Assertion OK : Validation Error Title is : Microsoft Excel
+END 'Validation' Symbol
+ TEST OK : Validation
+Test run finished : 08/10/2008 11:30:24
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Shapes.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Shapes.log new file mode 100644 index 000000000000..fe62ab03d3f2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Shapes.log @@ -0,0 +1,77 @@ +Test run started : 16/10/2007 17:46:03
+BEGIN Shapes_Collection_Behaviour
+ TEST START : Shapes_Collection_Behaviour
+ ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape1'
+ ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape2'
+ TEST Success. : Shapes_Collection_Behaviour
+END Shapes_Collection_Behaviour
+BEGIN Shapes_Select_Item
+ TEST START : Shapes_Select_Item
+ ITEM Assertion OK : Correctly selected shape through Range
+ ITEM Assertion OK : Correctly selected shape through Item
+ ITEM Assertion OK : Needs to be visually checked. Is there a line on the document?
+ ITEM Assertion OK : Needs to be visually checked. Are All Shapes Selected?
+ TEST Success. : Shapes_Select_Item
+END Shapes_Select_Item
+BEGIN Shapes_Fill
+ TEST START : Shapes_Fill
+ ITEM Assertion OK : correctly set visibility of shape fill
+ ITEM Assertion OK : correctly set transparency of shape line
+ ITEM Assertion OK : correctly set forecolor of shape fill
+ ITEM Assertion FAIL : correctly set backcolor of shape fill
+ ITEM Assertion OK : the success of the TwoColorGradient method needs to be verified visually!
+ ITEM Assertion OK : correctly set forecolor of shape fill
+ ITEM Assertion FAIL : correctly set forecolor of shape fill
+ TEST Success. : Shapes_Fill
+END Shapes_Fill
+BEGIN Shapes_Line
+ TEST START : Shapes_Line
+ ITEM Assertion FAIL : correctly set weight of shape line
+ ITEM Assertion OK : correctly set visibility of shape line
+ ITEM Assertion OK : correctly set transparency of shape line
+ ITEM Assertion OK : correctly set dash style of shape line
+ ITEM Assertion OK : correctly set dash style of shape line
+ ITEM Assertion OK : correctly set forecolor of shape line
+ ITEM Assertion FAIL : correctly set backcolor of shape line
+ TEST Success. : Shapes_Line
+END Shapes_Line
+BEGIN Shapes_TextFrame
+ TEST START : Shapes_TextFrame
+ ITEM Assertion OK : correctly set Autosize of Shape TextFrame
+ TEST Success. : Shapes_TextFrame
+END Shapes_TextFrame
+BEGIN Shapes_SimpleGeometry
+ TEST START : Shapes_SimpleGeometery
+ ITEM Assertion OK : shape height should be 49.4519655148368 and got 49.4078709034412
+ ITEM Assertion OK : shape width should be 101.467710269751 and got 101.423615658355
+ ITEM Assertion OK : shape left should be 68.5574761223637 and got 68.5417279658754
+ ITEM Assertion OK : shape top should be 44.1511784471699 and got 44.1354302906816
+ ITEM Assertion OK : shape rotation should be 0 and got 0
+ ITEM Assertion OK : shape rotation should be 25 and got 25
+ ITEM Assertion OK : shape incrementrotation should be 50 and got 50
+ ITEM Assertion OK : shape incrementleft should be 69.7480272284707 and got 69.7322790719824
+ ITEM Assertion OK : shape incrementtop should be 93.8141674447769 and got 93.7984192882885
+ TEST Success. : Shapes_SimpleGeometery
+END Shapes_SimpleGeometry
+BEGIN Shapes_Range
+ TEST START : Shapes_Range
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to contain 1 element, it contains 1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to return Sheet2Shape1 got Sheet2Shape1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to contain 1 element, it contains 1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to return Sheet2Shape3 got Sheet2Shape3
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to contain 2 elements, it contains 2
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to return concated element/shape names Sheet2Shape3Sheet2Shape1 and got Sheet2Shape3Sheet2Shape1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to contain 3 elements, it contains 3
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to return concated element/shape names Sheet2Shape3Sheet2Shape1Sheet2Shape2 and got Sheet2Shape3Sheet2Shape1Sheet2Shape2
+ TEST Success. : Shapes_Range
+END Shapes_Range
+BEGIN Shapes_ShapeRange
+ TEST START : Shapes_ShapeRange
+ ITEM Assertion OK : ShapeRange.IncrementLeft shp1.left should be 89.7322790719824 and got 89.7165297816359
+ ITEM Assertion OK : ShapeRange.IncrementLeft shp2.left should be 240.02518299054 and got 240.009433700193
+ ITEM Assertion OK : ShapeRange.IncrementTop shp1.Top should be 113.798419288289 and got 113.782669997942
+ ITEM Assertion OK : ShapeRange.IncrementTop shp2.Top should be 67.4519655148368 and got 67.4362162244903
+ ITEM Assertion OK : ShapeRange.IncrementRotation shp1.Rotation should be 70 and got 70
+ ITEM Assertion OK : ShapeRange.IncrementRotation shp2.Rotation should be 20 and got 20
+END Shapes_ShapeRange
+Test run finished : 16/10/2007 17:46:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/StrConv-test.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/StrConv-test.log new file mode 100644 index 000000000000..b1f7794234f9 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/StrConv-test.log @@ -0,0 +1,9 @@ +Test run started : 08/10/2008 12:04:16
+BEGIN StrConv
+ TEST START : Test StrConv function
+ ITEM Assertion OK : Converts the string to uppercase characters:ABC EFG HIJ
+ ITEM Assertion OK : Converts the string to lowercase characters:abc efg hij
+ ITEM Assertion OK : Converts the first letter of every word in string to uppercase:Abc Efg Hij
+ TEST OK : Test StrConv function
+END StrConv
+Test run finished : 08/10/2008 12:04:16
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Template.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Template.log new file mode 100644 index 000000000000..774994adb02c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Template.log @@ -0,0 +1,14 @@ +Test run started : 08/10/2008 12:05:52
+----------------------------------------------------------------
+TestCaseName
+ TEST START : TestCaseName
+ ITEM Assertion OK : Something has been done.
+Test Results
+============
+
+Tests passed: 1
+Tests failed: 0
+
+END 'TestCaseName
+ TEST OK : TestCaseName
+Test run finished : 08/10/2008 12:05:52
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestAddress.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestAddress.log new file mode 100644 index 000000000000..0007e6f9c958 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestAddress.log @@ -0,0 +1,67 @@ +Test run started : 08/10/2008 11:30:32
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 Range('e3:f3') A1 style addressing
+ ITEM Assertion OK : test2 Range('e3:f3') R1C1 style addressing
+ ITEM Assertion OK : test3 Range ('e:f') A1 style addressing
+ ITEM Assertion OK : test4 Range ('e:f') R1C1 style addressing
+ ITEM Assertion OK : test5 Columns A1 style addressing
+ ITEM Assertion OK : test6 Columns R1C1 style addressing
+ ITEM Assertion OK : test7 Columns(3) A1 style addressing
+ ITEM Assertion OK : test8 Columns(3) R1C1 style addressing
+ ITEM Assertion OK : test9 Columns('e') A1 style addressing
+ ITEM Assertion OK : test10 Columns('e') R1C1 style addressing
+ ITEM Assertion OK : test11 Columns('b:d') A1 style addressing
+ ITEM Assertion OK : test12 Columns('b:d') R1C1 style addressing
+ ITEM Assertion OK : test13 Range('c1:g10').Columns A1 style addressing
+ ITEM Assertion OK : test14 Range('c1:g10').Columns R1C1 style addressing
+ ITEM Assertion OK : test15 Range('c1:g10').Columns(1) A1 style addressing
+ ITEM Assertion OK : test16 Range('c1:g10').Columns(1) R1C1 style addressing
+ ITEM Assertion OK : test17 Range('c1:g10').Columns('a') A1 style addressing
+ ITEM Assertion OK : test18 Range('c1:g10').Columns('a') R1C1 style addressing
+ ITEM Assertion OK : test19 Range('c1:g10').Columns('c') A1 style addressing
+ ITEM Assertion OK : test20 Range('c1:g10').Columns('c') R1C1 style addressing
+ ITEM Assertion OK : test21 Range('c1:g10').Columns('x:z') A1 style addressing
+ ITEM Assertion OK : test22 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test23 Range('c1:g10').Columns(30) A1 style addressing
+ ITEM Assertion OK : test24 Range('c1:g10').Columns(30) R1C1 style addressing
+ ITEM Assertion OK : test25 Worksheets('Sheet2').Cells(1, 1) A1 style addressing
+ ITEM Assertion OK : test26 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, RowAddressAbsolute is false
+ ITEM Assertion OK : test27 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, ColAddressAbsolute is false
+ ITEM Assertion OK : test28 Worksheets('Sheet2').Cells(1, 1) R1C1 style addressing
+ ITEM Assertion OK : test29 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test30 Worksheets('Sheet2').Range('A1').EntireColumn A1 style addressing
+ ITEM Assertion OK : test31 Worksheets('Sheet2').Range('A1:E5').EntireRow A1 style addressing
+ ITEM Assertion OK : test32 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test33 Worksheets('Sheet2').Range('IV65536').EntireRow A1 style addressing
+ ITEM Assertion OK : test34 Worksheets('Sheet2').Range('IU2:IV65536') A1 style addressing
+ ITEM Assertion OK : test35 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test36 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test37 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test38 Worksheets('Sheet2').Range('10:12') A1 style addressing
+ ITEM Assertion OK : test39 Worksheets('Sheet2').Range('10:12') R1C1 style addressing
+ ITEM Assertion OK : test40 Range('Sheet3!A1:B4') A1 style addressing
+ ITEM Assertion OK : test41 Range('Sheet3!A1,B1,D4:F20') A1 style addressing
+ ITEM Assertion OK : test42 Range('g20:h40').Columns('c:c')
+ ITEM Assertion OK : test43 Range('g20:h40').Columns('c:f')
+ ITEM Assertion OK : test44 Range('g20:h40').Columns(-1)
+ ITEM Assertion OK : test45 Range('c4:g10').Rows(-1)
+ ITEM Assertion OK : test46 Range('a2:b4').Rows('1:1')
+ ITEM Assertion OK : test47 Range('a2:b4').Rows('1:2')
+ ITEM Assertion OK : test48 Range('a2:b4').Rows('2:2')
+ ITEM Assertion OK : test49 Range('a2:b4').Rows('2:3')
+ ITEM Assertion OK : test50 Range(' A2:B4 ')
+ ITEM Assertion OK : test51 Range('A 2:B 4')
+ ITEM Assertion OK : test52 Range('A2 : B4 ')
+ ITEM Assertion OK : test53 Range('Sheet1 !A2 : B4 ')
+ ITEM Assertion OK : test54 Range('Sheet1! A2 : B4 ')
+Test Results
+============
+
+Tests passed: 54
+Tests failed: 0
+
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 08/10/2008 11:30:32
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestCalc_Rangetest.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestCalc_Rangetest.log new file mode 100644 index 000000000000..492c24bc023c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestCalc_Rangetest.log @@ -0,0 +1,60 @@ +Test run started : 10/07/2007 01:56:07
+BEGIN TestCalc
+ TEST START : RangeTest2
+ ITEM Assertion OK : - Range("D15").Row
+ ITEM Assertion OK : - WorkSheet("D15").Range.Row
+ ITEM Assertion OK : - Range("D15").Column
+ ITEM Assertion OK : - Worksheet.Range("D15").Column
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Columns.Count
+ ITEM Assertion OK : - Range("D1").EntireColumn.Rows.Count
+ ITEM Assertion OK : - Range("D15").ClearContent
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (get)
+ ITEM Assertion OK : - Range("B38").Orientation (get)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlDownward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlUpward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B39").WrapText (get)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (get)
+ ITEM Assertion OK : - Range("F39").MergeCells (get)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion FAIL : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion OK : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("D41:D42").Replace MatchCase:=False
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM FAIL (RangeTest2)
+ TEST Not succesfully completed : RangeTest2
+END TestCalc
+Test run finished : 10/07/2007 01:56:12
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestCalc_Rangetest2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestCalc_Rangetest2.log new file mode 100644 index 000000000000..9159217cb442 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestCalc_Rangetest2.log @@ -0,0 +1,65 @@ +Test run started : 08/10/2008 11:30:38
+BEGIN TestCalc
+ TEST START : RangeTest3
+ ITEM Assertion OK : - setFormulaR1C1
+ ITEM Assertion OK : - getFormulaR1C1
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy(Range("I10"))
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteValues
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormulas
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormats
+ ITEM Assertion OK : PasteSpecial
+ ITEM Assertion OK : PasteSpecial SkipBlanks:=True
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationAdd
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationSubtract
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationMultiply
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationDivide
+ ITEM Assertion OK : PasteSpecial Transpose:=True
+ ITEM Assertion FAIL : ActiveWorkbook.FileFormat
+ ITEM Assertion OK : ActiveWorkbook.Name
+ ITEM Assertion OK : ActiveWorkbook.FullName und ActiveWorkbook.Path
+ ITEM Assertion FAIL : - = ActiveWorkbook.Colors(3) set
+ ITEM Assertion OK : - = ActiveWorkbook.ResetColors
+ ITEM Assertion OK : - = ActiveWorkbook.Colors(3) get
+ ITEM Assertion OK : - = Range("K22").End (xlDown)
+ ITEM Assertion OK : - = Range("K22").End (xlUo)
+ ITEM Assertion OK : - = Range("K22").End (xlToLeft)
+ ITEM Assertion OK : - = Range("K22").End (xlRight)
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="x"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="<>"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="="
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter
+ ITEM Assertion OK : - ActiveSheet.Resize.Select
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion FAIL : - Application.GoTo Reference:="R[8]C[2]"
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Ungroup- please check visually
+ ITEM Assertion OK : - Range.Ungroup - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - ActiveSheet.UsedRange.Select
+ ITEM Assertion OK : - Range("A13").AddIndent
+ ITEM Assertion OK : - Range("A13").IndentLevel set
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Calculate
+ ITEM Assertion OK : Worksheet.Calculate
+ ITEM Assertion OK : - Application.Calculate
+ ITEM Assertion OK : Global.Calculate
+ ITEM Assertion OK : Calculation set
+ ITEM FAIL (RangeTest3)
+ TEST Not succesfully completed : RangeTest3
+END TestCalc
+Test run finished : 08/10/2008 11:30:41
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestIntersection.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestIntersection.log new file mode 100644 index 000000000000..2cf4fe36ea6f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestIntersection.log @@ -0,0 +1,26 @@ +Test run started : 15/01/2009 17:05:08
+----------------------------------------------------------------
+TestIntersection
+ TEST START : TestIntersection
+ ITEM Assertion OK : test1 Application.Intersect( Range('A2:D10'), Range('C4:E6'))
+ ITEM Assertion OK : test2 Application.Intersect( Range('A2:D10'), Range('A4:G10'))
+ ITEM Assertion OK : test3 Application.Intersect( Range('A2:c8,d2:f8,g2:i8'), Range('A4:G10'))
+ ITEM Assertion OK : test4 Application.Intersect( Range('A4:G10'), Range('A2:c8,d2:f8,g2:i8'))
+ ITEM Assertion OK : test5 Application.Intersect( Range('A2:c8,d2:f8,g2:i8'), Range('g4:i10,A4:G10'))
+ ITEM Assertion OK : test6 Application.Intersect( Range('g4:i10,A4:G10'), Range('A2:c8,d2:f8,g2:i8'))
+ ITEM Assertion OK : test7 Application.Intersect( Range('a2:d10,b5:e10'), Range('a5:i10'))
+ ITEM Assertion OK : test8 Application.Intersect( Range('a2:c8,d2:f8'), Range('b6:e9,a6:f9'))
+ ITEM Assertion OK : test9 Application.Intersect( Range('a2:c8,e2:f8'), Range('b6:e9,a6:f9'))
+ ITEM Assertion OK : test10 Application.Intersect( Range('a1:a3,c1:c3'), Range('a2:c3'))
+ ITEM Assertion OK : test11 Application.Intersect( Range('a1:a3,b1:b3'), Range('a2:c3'))
+ ITEM Assertion OK : test12 Application.Intersect( Range('a2:d5,b3:f7,c1:g4'), Range('b2:e6'))
+ ITEM Assertion OK : test13 Range(" a2:d10,b5:e10,g13:j32 "), Range(" a5:i10,b6:e9 "), Range("b2:r5,f10:h19")
+Test Results
+============
+
+Tests passed: 13
+Tests failed: 0
+
+END 'TestIntersection
+ TEST OK : TestIntersection
+Test run finished : 15/01/2009 17:05:09
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestUnion.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestUnion.log new file mode 100644 index 000000000000..2382db549554 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/TestUnion.log @@ -0,0 +1,17 @@ +Test run started : 15/01/2009 17:06:07
+----------------------------------------------------------------
+TestUnion
+ TEST START : TestUnion
+ ITEM Assertion OK : test1Application.Range('A2:D10'), Range('C4:E6')
+ ITEM Assertion OK : test2Application.Range('A2:D5,a3:d4'), Range('A4:G10')
+ ITEM Assertion OK : test3Application.Range('A4:G10,A1:B6'), Range('A2:D5,A3:D4')
+ ITEM Assertion OK : test4Application.Range('A5:D10'), Range('B5:E10')
+Test Results
+============
+
+Tests passed: 4
+Tests failed: 0
+
+END 'TestUnion
+ TEST OK : TestUnion
+Test run finished : 15/01/2009 17:06:08
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/VariantTest.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/VariantTest.log new file mode 100644 index 000000000000..d2bfeb8e14a1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/VariantTest.log @@ -0,0 +1,47 @@ +Test run started : 08/10/2008 12:07:24
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1: res = (aboo = '')
+ ITEM Assertion OK : test 2: res = (aboo = 'fiddlesticks')
+ ITEM Assertion OK : test 3: res = ('' = aboo)
+ ITEM Assertion OK : test 4: res = ('fiddlesticks' = aboo )
+ ITEM Assertion OK : test 5: res = (testString = '')
+ ITEM Assertion OK : test 6: res = (testString = 'fiddlesticks')
+ ITEM Assertion OK : test 7: res = ('' = testString)
+ ITEM Assertion OK : test 8: res = ('fiddlesticks' = testString )
+ ITEM Assertion OK : test 9: res = ( aboo < " )
+ ITEM Assertion OK : test 10: res = ( testString < " )
+ ITEM Assertion OK : test 11: res = ( aboo > " )
+ ITEM Assertion OK : test 12: res = ( testString > " )
+ ITEM Assertion OK : test 13: res = ( aboo <> '' )
+ ITEM Assertion OK : test 14: res = ( testString <> '' )
+ ITEM Assertion OK : test 15: res = (aboo = something/14)
+ ITEM Assertion OK : test 16: res = something + 'string'
+ ITEM Assertion OK : test 17: res = something & 'string'
+ ITEM Assertion OK : test 18: res = something MOD 10 )
+ ITEM Assertion OK : test 19: res = something AND 1 )
+ ITEM Assertion OK : test 20: res = something AND 0 )
+ ITEM Assertion OK : test 21: res = something OR 12)
+ ITEM Assertion OK : test 22: res = something OR 0 )
+ ITEM Assertion OK : test 23: res = something XOR 0 )
+ ITEM Assertion OK : test 24: res = something XOR 1 )
+ ITEM Assertion OK : test 25: res = something EQV 0 )
+ ITEM Assertion OK : test 26: res = something EQV 1 )
+ ITEM Assertion OK : test 27: res = something IMP 0 )
+ ITEM Assertion OK : test 28: res = something IMP 1 )
+ ITEM Assertion OK : test 29: res = something IMP 14 )
+ ITEM Assertion OK : test 30: res = NOT something )
+ ITEM Assertion OK : test 31: res = something + 12 )
+ ITEM Assertion OK : test 32: res = something - 12 )
+ ITEM Assertion OK : test 33: res = -something )
+ ITEM Assertion OK : test 34: res = something * 12 )
+Test Results
+============
+
+Tests passed: 34
+Tests failed: 0
+
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 08/10/2008 12:07:26
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Window.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Window.log new file mode 100644 index 000000000000..178582e753c7 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/Window.log @@ -0,0 +1,46 @@ +Test run started : 08/10/2008 12:09:50
+----------------------------------------------------------------
+ TEST START : Window-Issue
+ ITEM Assertion OK : Window.Left is: 0 (Test only applies to maximized Window)
+ ITEM Assertion OK : Window.Top is: 26 (Test only applies to maximized Window)
+ ITEM Assertion OK : Window.Width is: 1280 (Test only applies to maximized Window)
+ ITEM Assertion OK : Window.Height is: 968 (Test only applies to maximized Window)
+ ITEM Assertion OK : Window.ScrollColumn is: 100
+ ITEM Assertion OK : Window.ScrollColumn is: 1
+ ITEM Assertion OK : Window.ScrollRow is: 100
+ ITEM Assertion OK : Window.ScrollRow is: 1
+ ITEM Assertion OK : Window.LargeScroll(Down): ScrollRow is: 127 (Test may only apply to maximized Window)
+ ITEM Assertion OK : Window.LargeScroll(Up): ScrollRow is: 1
+ ITEM Assertion OK : Window.LargeScroll(ToRight): ScrollColumn is: 58 (Test may only apply to maximized Window)
+ ITEM Assertion OK : Window.LargeScroll(ToLeft): ScrollColumn is: 1
+ ITEM Assertion OK : Window.SmallScroll(ToRight): ScrollColumn is: 4 (Test may only apply to maximized Window)
+ ITEM Assertion OK : Window.SmallScroll(ToLeft): ScrollColumn is: 1
+ ITEM Assertion OK : Window.DisplayWorkBookTabs is: False
+ ITEM Assertion OK : Window.DisplayWorkBookTabs is: True
+ ITEM Assertion OK : Window.DisplayVerticalScrollBar is: True
+ ITEM Assertion OK : Window.DisplayVerticalScrollBar is: False
+ ITEM Assertion OK : Window.DisplayHorizontalScrollBar is: False
+ ITEM Assertion OK : Window.DisplayHorizontalScrollBar is: True
+ ITEM Assertion OK : Window.DisplayHeadings is: False
+ ITEM Assertion OK : Window.DisplayHeadings is: True
+ ITEM Assertion OK : Window.DisplayOutline is: False
+ ITEM Assertion OK : Window.DisplayOutline is: True
+ ITEM Assertion OK : Window.Visible is: False
+ ITEM Assertion OK : Window.Visible is: True
+ ITEM Assertion OK : Window.Caption is: MyCaption
+ ITEM Assertion OK : Pane.ScrollColumn is: 100
+ ITEM Assertion OK : Pane.ScrollColumn is: 1
+ ITEM Assertion OK : Pane.ScrollRow is: 100
+ ITEM Assertion OK : Pane.ScrollRow is: 1
+ ITEM Assertion OK : Pane.LargeScroll(Down): ScrollRow is: 127 (Test may only apply to maximized Window)
+ ITEM Assertion OK : Pane.LargeScroll(Up): ScrollRow is: 1
+ ITEM Assertion OK : Pane.LargeScroll(ToRight): ScrollColumn is: 58 (Test may only apply to maximized Window)
+ ITEM Assertion OK : Pane.LargeScroll(ToLeft): ScrollColumn is: 1
+ ITEM Assertion OK : Pane.SmallScroll(ToRight): ScrollColumn is: 4 (Test may only apply to maximized Window)
+ ITEM Assertion OK : Pane.SmallScroll(ToLeft): ScrollColumn is: 1
+ ITEM Assertion OK : Window Selection: $A$2:$D$5
+ ITEM Assertion OK : ActiveSheet name of Window: Sheet1
+ ITEM Assertion OK : Window ActiveCell: $A$1
+END 'Window-Issue' Symbol
+ TEST OK : Window-Issue
+Test run finished : 08/10/2008 12:09:50
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/bytearraystring.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/bytearraystring.log new file mode 100644 index 000000000000..8913fc096dc2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/bytearraystring.log @@ -0,0 +1,8 @@ +Test run started : 08/10/2008 12:54:46
+BEGIN Bytearray To String
+ TEST START : Test the conversion between bytearray and string
+ ITEM Assertion OK : The number of byte is:6
+ ITEM Assertion OK : the return string is: abc
+ TEST OK : Test the conversion between bytearray and string
+END Bytearray To String
+Test run finished : 08/10/2008 12:54:46
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/dateserial.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/dateserial.log new file mode 100644 index 000000000000..0b02f7b91a2c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/dateserial.log @@ -0,0 +1,9 @@ +Test run started : 08/10/2008 12:56:07
+BEGIN DateSerial
+ TEST START : Test DateSerial function
+ ITEM Assertion OK : the return date is: 15/06/1999
+ ITEM Assertion OK : the return date is: 15/06/1999
+ ITEM Assertion OK : the return date is: 15/06/1999
+ TEST OK : Test DateSerial function
+END DateSerial
+Test run finished : 08/10/2008 12:56:07
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/datevalue.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/datevalue.log new file mode 100644 index 000000000000..4698463362d2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/datevalue.log @@ -0,0 +1,8 @@ +Test run started : 08/10/2008 13:07:49
+BEGIN DateValue
+ TEST START : Test DateValue function
+ ITEM Assertion OK : the return date is: 12/02/1969
+ ITEM Assertion OK : the return date is: 21/01/2008
+ TEST OK : Test DateValue function
+END DateValue
+Test run finished : 08/10/2008 13:07:49
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/format.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/format.log new file mode 100644 index 000000000000..ef84cbbdb925 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/format.log @@ -0,0 +1,36 @@ +Test run started : 15/01/2009 17:07:59
+BEGIN Format
+ TEST START : Test Predefined_Number_Format_Sample function
+ ITEM Assertion OK : General Number: 562486.2356
+ ITEM Assertion OK : Fixed: 0.20
+ ITEM Assertion OK : Standard: 562,486.24
+ ITEM Assertion OK : Percent: 75.21%
+ ITEM Assertion OK : Scientific: 5.62E+05
+ ITEM Assertion OK : Scientific: -3.46E+03
+ ITEM Assertion OK : Yes/No: No
+ ITEM Assertion OK : Yes/No: Yes
+ ITEM Assertion OK : True/False: False
+ ITEM Assertion OK : True/False: True
+ ITEM Assertion OK : On/Off: Off
+ ITEM Assertion OK : On/Off: On
+ TEST OK : Test Predefined_Number_Format_Sample function
+ TEST START : Test Custom_Number_Format_Sample function
+ ITEM Assertion OK : 00.0000: 23.6750
+ ITEM Assertion OK : 00.00: 23.68
+ ITEM Assertion OK : 00000: 02658
+ ITEM Assertion OK : 00.00: 2658.00
+ ITEM Assertion OK : ##.####: 23.675
+ ITEM Assertion OK : ##.##: 23.68
+ ITEM Assertion OK : #,###.##: 12,345.25
+ ITEM Assertion OK : ##.00%: 25.00%
+ ITEM Assertion OK : #,###: 1,000,000
+ ITEM Assertion OK : ######E-###: 109838E-5
+ ITEM Assertion OK : $#,###.##: $2,345.25
+ ITEM Assertion OK : ##.###\%: .25%
+ TEST OK : Test Custom_Number_Format_Sample function
+ TEST START : Test Custom_Text_Format_Sample function
+ ITEM Assertion OK : <: vba
+ ITEM Assertion OK : >: VBA
+ TEST OK : Test Custom_Text_Format_Sample function
+END Format
+Test run finished : 15/01/2009 17:07:59
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/pagesetup.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/pagesetup.log new file mode 100644 index 000000000000..a1c90473ce07 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/pagesetup.log @@ -0,0 +1,87 @@ +Test run started : 7/21/2008 10:37:24 AM
+BEGIN PageSetup
+ TEST START : Sheet_PrintArea
+ ITEM Assertion OK : PrintArea has changed as expected
+ TEST OK : Sheet_PrintArea
+ TEST START : Test margins (no headers)
+ ITEM Assertion OK : PageSetup.LeftMargin set/get
+ ITEM Assertion OK : PageSetup.RightMargin set/get
+ ITEM Assertion OK : PageSetup.TopMargin set/get
+ ITEM Assertion OK : PageSetup.BottomMargin set/get
+Verify that page margins on sheet 1 are all 0.5inch
+ TEST OK : Test margins (no headers)
+ TEST START : Test margins (headers)
+ ITEM Assertion OK : PageSetup.HeaderMargin set/get
+ ITEM Assertion OK : PageSetup.FooterMargin set/get
+ ITEM Assertion OK : PageSetup.LeftMargin set/get
+ ITEM Assertion OK : PageSetup.LeftMargin set/get
+Verify that top/bottom/header/footer page margins on sheet 2 are all 0.5inch
+ TEST OK : Test margins (headers)
+ TEST START : Test header/footer text
+ ITEM Assertion OK : PageSetup.LeftHeader set
+ ITEM Assertion OK : PageSetup.LeftHeader set/get
+ ITEM Assertion OK : PageSetup.CenterHeader set
+ ITEM Assertion OK : PageSetup.CenterHeader set/get
+ ITEM Assertion OK : PageSetup.RightHeader set
+ ITEM Assertion OK : PageSetup.RightHeader set/get
+ ITEM Assertion OK : PageSetup.LeftFooter set
+ ITEM Assertion OK : PageSetup.LeftFooter set/get
+ ITEM Assertion OK : PageSetup.CenterFooter set
+ ITEM Assertion OK : PageSetup.CenterFooter set/get
+ ITEM Assertion OK : PageSetup.RightFooter set
+ ITEM Assertion OK : PageSetup.RightFooter set/get
+Verify that headers on sheet 2 are Ready,to,go
+Verify that footers on sheet 2 are This,now,Works
+ TEST OK : Test header/footer text
+ TEST START : Test zoom
+ ITEM Assertion OK : PageSetup.Zoom set
+ ITEM Assertion OK : PageSetup.Zoom set/get
+Verify that sheet 1 zoom is 10%
+ TEST OK : Test zoom
+ TEST START : Test orientation
+ ITEM Assertion OK : PageSetup.Zoom set
+ ITEM Assertion OK : PageSetup.Orientation set/get
+Verify that sheet 1 orientation is now landscape
+ TEST OK : Test orientation
+ TEST START : Test paper size
+ ITEM Assertion OK : PageSetup.PaperSize get
+ ITEM Assertion OK : PageSetup.PaperSize set/get
+Verify that paper size on sheet 1 is now Letter
+ TEST OK : Test paper size
+ TEST START : Test order
+ ITEM Assertion OK : PageSetup.Order get
+ ITEM Assertion OK : PageSetup.Order set/get
+Verify that order on sheet 1 is now over, then down.
+ TEST OK : Test order
+ TEST START : Test first page number
+ ITEM Assertion OK : PageSetup.FirstPageNumber get
+ ITEM Assertion OK : PageSetup.FirstPageNumber set/get
+Verify that first page number on sheet 1 is now 2.
+ TEST OK : Test first page number
+ TEST START : Test center vertically
+ ITEM Assertion OK : PageSetup.CenterVertically get
+ ITEM Assertion OK : PageSetup.CenterVertically set/get
+Verify that CenterVertically on sheet 1 is now true.
+ TEST OK : Test center vertically
+ TEST START : Test center horizontally
+ ITEM Assertion OK : PageSetup.CenterHorizontally get
+ ITEM Assertion OK : PageSetup.CenterHorizontally set/get
+Verify that CenterHorizontally on sheet 1 is now true.
+ TEST OK : Test center horizontally
+ TEST START : Test FitToPagesTall
+ ITEM Assertion OK : PageSetup.FitToPagesTall set/get
+ TEST OK : Test FitToPagesTall
+ TEST START : Test FitToPagesWide
+ ITEM Assertion OK : PageSetup.FitToPagesWide set/get
+ TEST OK : Test FitToPagesWide
+ TEST START : Test PrintHeadings
+ ITEM Assertion OK : PageSetup.PrintHeadings set/get
+ ITEM Assertion OK : PageSetup.PrintHeadings set/get
+ TEST OK : Test PrintHeadings
+ TEST START : Test PrintTitleRows
+ ITEM Assertion OK : PageSetup.PrintTitleRows get
+ ITEM Assertion OK : PageSetup.PrintTitleRows set range/get
+ ITEM Assertion OK : PageSetup.PrintTitleRows set false/get
+ TEST OK : Test PrintTitleRows
+END PageSetup
+Test run finished : 7/21/2008 10:37:32 AM
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/partition.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/partition.log new file mode 100644 index 000000000000..1ea267d641e8 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/partition.log @@ -0,0 +1,11 @@ +Test run started : 08/10/2008 13:09:51
+BEGIN Partition
+ TEST START : Test Partition function
+ ITEM Assertion OK : the number 20 occurs in the range:20:24
+ ITEM Assertion OK : the number 20 occurs in the range: 20: 20
+ ITEM Assertion OK : the number 120 occurs in the range:100:
+ ITEM Assertion OK : the number -5 occurs in the range: : -1
+ ITEM Assertion OK : the number 2 occurs in the range: 2: 3
+ TEST OK : Test Partition function
+END Partition
+Test run finished : 08/10/2008 13:09:51
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/range-4.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/range-4.log new file mode 100644 index 000000000000..11de80133dfa --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/range-4.log @@ -0,0 +1,16 @@ +Test run started : 08/10/2008 11:30:16
+----------------------------------------------------------------
+ShowDetail-Issue
+ TEST START : ShowDetail-Issue
+ ITEM Assertion OK : Range.ShowDetail is True
+ ITEM Assertion OK : Range.ShowDetail is False
+END 'ShowDetail-Issue' Symbol
+ TEST OK : ShowDetail-Issue
+----------------------------------------------------------------
+RangeMerged-Issue
+ TEST START : RangeMerged-Issue
+ ITEM Assertion OK : Range.RangeMerged is $F$2:$H$5
+ ITEM Assertion OK : The first address of Range.RangeMerged is $F$2
+END 'RangeMerged-Issue' Symbol
+ TEST OK : RangeMerged-Issue
+Test run finished : 08/10/2008 11:30:16
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/replace.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/replace.log new file mode 100644 index 000000000000..e96004e4d2a6 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/replace.log @@ -0,0 +1,14 @@ +Test run started : 2007-11-21 11:24:04
+BEGIN Replace
+ TEST START : Test Replace function
+ ITEM Assertion OK : common string:aefefdBc
+ ITEM Assertion OK : expression string:aefefdef
+ ITEM Assertion OK : binanary compare:aefefdBc
+ ITEM Assertion OK : text compare:aefefdef
+ ITEM Assertion OK : text compare:aefefdef
+ ITEM Assertion OK : start = 3:cefdBc
+ ITEM Assertion OK : count = 2: aefefdBc
+ ITEM Assertion OK : start = 1, count = 0, not support in Unix: abcbcdBc
+ TEST OK : Test Replace function
+END Replace
+Test run finished : 2007-11-21 11:24:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/stringplusdouble.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/stringplusdouble.log new file mode 100644 index 000000000000..51a958a412cf --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/stringplusdouble.log @@ -0,0 +1,62 @@ +Test run started : 15/01/2009 17:09:03
+BEGIN String Plus Double
+ TEST START : double = string + double
+The next compute raises error: s = null, d = null, r = s + d
+ ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1
+ ITEM Assertion OK : s = null, d = null, r = s & d .The result is: 0
+The next compute raises error: s = null, d = 20, r = s + d
+ ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: -1
+ ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20
+ ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10
+ ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 100
+ ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 30
+ ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020
+The next compute raises error: s = 'abc', d = null, r = s + d
+ ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1
+The next compute raises error: s = 'abc', d = null, r = s & d
+ ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: -1
+The next compute raises error: s = 'abc', d = 20, r = s + d
+ ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1
+The next compute raises error: s = 'abc', d = 20, r = s & d
+ ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: -1
+ TEST OK : double = string + double
+ TEST START : string = string + double
+The next compute raises error: s = null, d = null, r = s + d
+ ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1
+ ITEM Assertion OK : s = null, d = null, r = s & d .The result is: 0
+The next compute raises error: s = null, d = 20, r = s + d
+ ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: -1
+ ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20
+ ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10
+ ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 100
+ ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 30
+ ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020
+The next compute raises error: s = 'abc', d = null, r = s + d
+ ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1
+ ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: abc0
+The next compute raises error: s = 'abc', d = 20, r = s + d
+ ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1
+ ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: abc20
+ TEST OK : string = string + double
+ TEST START : double = string + string
+The next compute raises error: s = null, d = null, r = s + d
+ ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1
+The next compute raises error: s = null, d = null, r = s & d
+ ITEM Assertion OK : s = null, d = null, r = s & d .The result is: -1
+ ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: 20
+ ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20
+ ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10
+ ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 10
+ ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 1020
+ ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020
+The next compute raises error: s = 'abc', d = null, r = s + d
+ ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1
+The next compute raises error: s = 'abc', d = null, r = s & d
+ ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: -1
+The next compute raises error: s = 'abc', d = 20, r = s + d
+ ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1
+The next compute raises error: s = 'abc', d = 20, r = s & d
+ ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: -1
+ TEST OK : double = string + string
+END String Plus Double
+Test run finished : 15/01/2009 17:09:03
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/window2.log b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/window2.log new file mode 100644 index 000000000000..01fba9c6dfa6 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/logs/win/window2.log @@ -0,0 +1,41 @@ +Test run started : 15/01/2009 17:10:02
+BEGIN Window2
+ TEST START : Test Window.SplitRow
+ ITEM Assertion OK : Test SplitColumn: 2 (Test only applies to maximized Window and at least has 800*600 solotion)
+ ITEM Assertion FAIL : Test SplitRow: 1 (Test only applies to maximized Window and at least has 800*600 solotion)
+ ITEM Assertion OK : Test SplitVertical: 242.283803521067
+ ITEM Assertion OK : Test SplitHorizontal: 242.283803521067
+ ITEM Assertion FAIL : Test SplitRow: 3 (Test only applies to maximized Window and at least has 800*600 solotion)
+ ITEM Assertion OK : Test SplitColumn: 3 (Test only applies to maximized Window and at least has 800*600 solotion)
+ ITEM Assertion OK : Test SplitColumn: 0
+ ITEM Assertion OK : Test SplitRow: 0
+ TEST OK : Test Window.SplitRow
+ TEST START : Test Window.DisplayGridlines
+ ITEM Assertion OK : Test gridlines are on
+ ITEM Assertion OK : Test gridlines are off
+ TEST OK : Test Window.DisplayGridlines
+ TEST START : Test Window.DisplayHeadings
+ ITEM Assertion OK : Test Headings are on
+ ITEM Assertion OK : Test Headings are off
+ TEST OK : Test Window.DisplayHeadings
+ TEST START : Test Window.Visibility
+ ITEM Assertion OK : Window is visible
+ ITEM Assertion OK : Window is not visible
+ TEST OK : Test Window.Visibility
+ TEST START : Test Window.FreezePanes
+ ITEM Assertion OK : Test no panes frozen
+ ITEM Assertion OK : Test panes frozen at center
+ ITEM Assertion OK : Test panes frozen at split
+ TEST OK : Test Window.FreezePanes
+ TEST START : Test Window.View
+ TEST OK : Test Window.View
+ TEST START : Test Window.Zoom
+ ITEM Assertion OK : Test zoom=100%
+ ITEM Assertion OK : Test zoom=150%
+ TEST OK : Test Window.Zoom
+ TEST START : Test Windows.Count
+ ITEM Assertion OK : Windows Count: 1
+ ITEM Assertion OK : Application.Windows Count: 1
+ TEST OK : Test Windows.Count
+END Window2
+Test run finished : 15/01/2009 17:10:03
diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/error.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/error.xls Binary files differnew file mode 100644 index 000000000000..ea2095d5e3d7 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/error.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/imagecontrols.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/imagecontrols.xls Binary files differnew file mode 100644 index 000000000000..0de17b403f23 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/imagecontrols.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/keyword.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/keyword.xls Binary files differnew file mode 100644 index 000000000000..3bf711ed4f42 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/keyword.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/objectmodule.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/objectmodule.xls Binary files differnew file mode 100644 index 000000000000..d3aff35b938c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/objectmodule.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/stringtodouble.ods b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/stringtodouble.ods Binary files differnew file mode 100644 index 000000000000..5a732a765886 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/notwork/stringtodouble.ods diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/partition.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/partition.xls Binary files differnew file mode 100644 index 000000000000..5c8d12b1d54f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/partition.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/range-4.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/range-4.xls Binary files differnew file mode 100644 index 000000000000..52452369462f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/range-4.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/replace.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/replace.xls Binary files differnew file mode 100644 index 000000000000..dcf3c6e8ec06 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/replace.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/stringplusdouble.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/stringplusdouble.xls Binary files differnew file mode 100644 index 000000000000..596be7f6b9bc --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/stringplusdouble.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments-ooo-build/window2.xls b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/window2.xls Binary files differnew file mode 100644 index 000000000000..4d5e1cbfe944 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments-ooo-build/window2.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/ApplicationRunTest.xls b/sc/source/ui/vba/testvba/TestDocuments/ApplicationRunTest.xls Binary files differnew file mode 100644 index 000000000000..a5a591c1f849 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/ApplicationRunTest.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/AutoFilter.xls b/sc/source/ui/vba/testvba/TestDocuments/AutoFilter.xls Binary files differnew file mode 100644 index 000000000000..9b3a1043c5ee --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/AutoFilter.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/CalcFont.xls b/sc/source/ui/vba/testvba/TestDocuments/CalcFont.xls Binary files differnew file mode 100644 index 000000000000..9ddb69600643 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/CalcFont.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/FinancialFuncs.xls b/sc/source/ui/vba/testvba/TestDocuments/FinancialFuncs.xls Binary files differnew file mode 100644 index 000000000000..bb8941809947 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/FinancialFuncs.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/MiscRangeTests.xls b/sc/source/ui/vba/testvba/TestDocuments/MiscRangeTests.xls Binary files differnew file mode 100644 index 000000000000..ebd9e91b5b28 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/MiscRangeTests.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/PageBreaks.xls b/sc/source/ui/vba/testvba/TestDocuments/PageBreaks.xls Binary files differnew file mode 100644 index 000000000000..b6651fa5d617 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/PageBreaks.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/Ranges-2.xls b/sc/source/ui/vba/testvba/TestDocuments/Ranges-2.xls Binary files differnew file mode 100644 index 000000000000..f6e81cf933fd --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/Ranges-2.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/Ranges-3.xls b/sc/source/ui/vba/testvba/TestDocuments/Ranges-3.xls Binary files differnew file mode 100644 index 000000000000..8722f6d3057e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/Ranges-3.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/Ranges.xls b/sc/source/ui/vba/testvba/TestDocuments/Ranges.xls Binary files differnew file mode 100644 index 000000000000..1c1d74d37486 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/Ranges.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/Shapes.xls b/sc/source/ui/vba/testvba/TestDocuments/Shapes.xls Binary files differnew file mode 100644 index 000000000000..254f3c97756c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/Shapes.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/StrConv-test.xls b/sc/source/ui/vba/testvba/TestDocuments/StrConv-test.xls Binary files differnew file mode 100755 index 000000000000..198abbec5871 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/StrConv-test.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/Template.xls b/sc/source/ui/vba/testvba/TestDocuments/Template.xls Binary files differnew file mode 100755 index 000000000000..4387231fe744 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/Template.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/TestAddress.xls b/sc/source/ui/vba/testvba/TestDocuments/TestAddress.xls Binary files differnew file mode 100644 index 000000000000..48d30cbe2e9e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/TestAddress.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/TestCalc_Rangetest.xls b/sc/source/ui/vba/testvba/TestDocuments/TestCalc_Rangetest.xls Binary files differnew file mode 100644 index 000000000000..a497d4f10f3e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/TestCalc_Rangetest.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/TestCalc_Rangetest2.xls b/sc/source/ui/vba/testvba/TestDocuments/TestCalc_Rangetest2.xls Binary files differnew file mode 100644 index 000000000000..34c606fc28f5 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/TestCalc_Rangetest2.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/TestIntersection.xls b/sc/source/ui/vba/testvba/TestDocuments/TestIntersection.xls Binary files differnew file mode 100644 index 000000000000..24f88db87ccc --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/TestIntersection.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/TestUnion.xls b/sc/source/ui/vba/testvba/TestDocuments/TestUnion.xls Binary files differnew file mode 100644 index 000000000000..5b8f0968cf38 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/TestUnion.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/Window.xls b/sc/source/ui/vba/testvba/TestDocuments/Window.xls Binary files differnew file mode 100644 index 000000000000..6fb6963c2f31 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/Window.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/bytearraystring.xls b/sc/source/ui/vba/testvba/TestDocuments/bytearraystring.xls Binary files differnew file mode 100755 index 000000000000..471bbc349e5b --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/bytearraystring.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/dateserial.xls b/sc/source/ui/vba/testvba/TestDocuments/dateserial.xls Binary files differnew file mode 100755 index 000000000000..768fb513eba4 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/dateserial.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/datevalue.xls b/sc/source/ui/vba/testvba/TestDocuments/datevalue.xls Binary files differnew file mode 100755 index 000000000000..852a51d100b8 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/datevalue.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/format.xls b/sc/source/ui/vba/testvba/TestDocuments/format.xls Binary files differnew file mode 100644 index 000000000000..99ed64d38915 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/format.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/AutoFilter.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/AutoFilter.log new file mode 100644 index 000000000000..1fe0cbd01fe5 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/AutoFilter.log @@ -0,0 +1,20 @@ +Test run started : 17/07/2007 17:36:22
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 'starts with' string criteria
+ ITEM Assertion OK : test2 'not equal to' string criteria
+ ITEM Assertion OK : test3 'ends with' string criteria
+ ITEM Assertion OK : test4 field 'all'
+ ITEM Assertion OK : test5 numeric '<15'
+ ITEM Assertion OK : test6 numeric '>=15'
+ ITEM Assertion OK : test7 numeric '<=12'
+Test Results +============ + +Tests passed: 7 +Tests failed: 0 +
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 17/07/2007 17:36:23
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/MiscRangeTests.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/MiscRangeTests.log new file mode 100644 index 000000000000..260465386d07 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/MiscRangeTests.log @@ -0,0 +1,45 @@ +Test run started : 17/07/2007 15:01:37
+----------------------------------------------------------------
+MiscRangeTests
+ TEST START : MiscRangeTests
+ ITEM Assertion OK : test 1
+ ITEM Assertion OK : test 2
+ ITEM Assertion OK : test 3
+ ITEM Assertion OK : test 4
+ ITEM Assertion OK : test 5
+ ITEM Assertion OK : test 6
+ ITEM Assertion OK : test 7
+ ITEM Assertion OK : test 8
+ ITEM Assertion OK : test 9
+ ITEM Assertion OK : test 10
+ ITEM Assertion OK : test 11
+ ITEM Assertion OK : test 12
+ ITEM Assertion OK : test 13
+ ITEM Assertion OK : test 14
+ ITEM Assertion OK : test 15
+ ITEM Assertion OK : test 16
+ ITEM Assertion OK : test 17
+ ITEM Assertion OK : test 18
+ ITEM Assertion OK : test 19
+ ITEM Assertion OK : test 20
+ ITEM Assertion OK : test 21
+ ITEM Assertion OK : test 22
+ ITEM Assertion OK : test 23
+ ITEM Assertion OK : test 24
+ ITEM Assertion OK : test 25
+ ITEM Assertion OK : test 26
+ ITEM Assertion OK : test 27
+ ITEM Assertion OK : test 28
+ ITEM Assertion OK : test 29
+ ITEM Assertion OK : test 30
+ ITEM Assertion OK : test 31
+No. tests: 31 +Summary +======= +Run: 31 +Passed: 31 +Failed: 0 +
+END 'MiscRangeTests
+ TEST OK : MiscRangeTests
+Test run finished : 17/07/2007 15:01:39
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges-2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges-2.log new file mode 100644 index 000000000000..736d5bbc42d0 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges-2.log @@ -0,0 +1,68 @@ +Test run started : 18/06/2007 17:50:04
+----------------------------------------------------------------
+ClearFormtsIssue
+ TEST START : ClearFormtsIssue
+ ITEM Assertion OK : Range.Font.Bold is: True
+ ITEM Assertion OK : Range.Font.Bold is: False
+END 'ClearFormtsIssue' Symbol
+ TEST OK : ClearFormtsIssue
+----------------------------------------------------------------
+VerticalAlignment-Issue
+ TEST START : VerticalAlignment-Issue
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : Range.VeritcalAlignment is Null
+END 'VerticalAlignment-Issue' Symbol
+ TEST OK : VerticalAlignment-Issue
+----------------------------------------------------------------
+HorizontalAlignment-Issue
+ TEST START : HorizontalAlignment-Issue
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : Range.HorizontalAlignment is Null
+END 'HorizontalAlignment-Issue' Symbol
+ TEST OK : HorizontalAlignment-Issue
+----------------------------------------------------------------
+WrapText-Issue
+ TEST START : WrapText-Issue
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : Range.WrapText is Null
+END 'WrapText-Issue' Symbol
+ TEST OK : WrapText-Issue
+----------------------------------------------------------------
+FontBorderIssues
+ TEST START : FontBorderIssues
+ ITEM Assertion OK : - = Borders.Color (getColor)
+ ITEM Assertion OK : - = Font.Color (getColor)
+END 'FontBorderIssues' Symbol
+ TEST OK : FontBorderIssues
+----------------------------------------------------------------
+RangeSizeIssues
+ TEST START : RangeSizeIssues
+ ITEM Assertion OK : Range.Left is: 114
+ ITEM Assertion OK : Range.Top is: 95.25
+ ITEM Assertion OK : Range.Width is: 216
+ ITEM Assertion OK : Range.Height is: 271.5
+END 'RangeSizeIssues' Symbol
+ TEST OK : RangeSizeIssues
+----------------------------------------------------------------
+ApplicationIssues
+ TEST START : ApplicationIssues
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Application.ActiveSheet.Name: Sheet1
+END 'ApplicationIssues' Symbol
+ TEST OK : ApplicationIssues
+Test run finished : 18/06/2007 17:50:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges-3.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges-3.log new file mode 100644 index 000000000000..a7de979d5e13 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges-3.log @@ -0,0 +1,8 @@ +Test run started : 19/06/2007 11:21:42
+----------------------------------------------------------------
+MyGoalseek-Issue
+ TEST START : MyGoalseek-Issue
+ ITEM Assertion OK : Variable Range value: 15
+END 'MyGoalseek-Issue' Symbol
+ TEST OK : MyGoalseek-Issue
+Test run finished : 19/06/2007 11:21:42
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges.log new file mode 100644 index 000000000000..8c9644aac155 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/Ranges.log @@ -0,0 +1,280 @@ +Test run started : 01/06/2007 11:28:58
+----------------------------------------------------------------
+ApplicationMethods
+ TEST START : ApplicationMethods
+ ITEM Assertion OK : Name of Workbook is: Ranges.xls
+ ITEM Assertion OK : Address of Application.Columns is: $A:$A
+ ITEM Assertion OK : Address of Application.Rows is: $1:$1
+ ITEM Assertion OK : Address of Application.Range is: $1:$1,$5:$7
+ ITEM Assertion OK : Please check manually: DefaultFilePath is: C:\Documents and Settings\vituosity\My Documents
+ ITEM Assertion OK : Please check manually: Library Path is: C:\Program Files\Microsoft Office\OFFICE11\LIBRARY
+ ITEM Assertion OK : Please check manually: Template Path is: C:\Documents and Settings\vituosity\Application Data\Microsoft\Templates\
+ ITEM Assertion OK : FileSeparator is \
+ ITEM Assertion OK : Name of ActiveWorkbook is: Ranges.xls
+END 'ApplicationMethods' Symbol
+ TEST OK : ApplicationMethods
+----------------------------------------------------------------
+Insert-Issue
+ TEST START : Insert-Issue
+ ITEM Assertion OK : Insert with xlShiftToRight: 10
+END 'Insert-Issue' Symbol
+ TEST OK : Insert-Issue
+----------------------------------------------------------------
+MergeCells-Issue
+ TEST START : MergeCells-Issue
+ ITEM Assertion OK : Range.MergeCells is True
+ ITEM Assertion OK : MergeCells is null: True
+ ITEM Assertion OK : RowCount after Merge: 6
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion OK : MergeCells of Second Area is null : True
+ ITEM Assertion OK : MergeCells of Ranges is Null: True
+ ITEM Assertion OK : RowCount after Merge: 7
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion OK : RowCount after Merge: 7
+END 'MergeCells-Issue' Symbol
+ TEST OK : MergeCells-Issue
+----------------------------------------------------------------
+Areas-Issue
+ TEST START : Areas-Issue
+ ITEM Assertion OK : Range Areas Count is2
+ ITEM Assertion OK : First Range Address is: $E$8:$G$13
+ ITEM Assertion OK : First Row is: 8
+ ITEM Assertion OK : First Column is: 5
+ ITEM Assertion OK : EntireRow Address is: $8:$13,$13:$19
+ ITEM Assertion OK : EntireColumn Address is: $E:$G,$G:$K
+ ITEM Assertion OK : Range Count:53
+END 'Areas-Issue' Symbol
+ TEST OK : Areas-Issue
+----------------------------------------------------------------
+Fill-Methods-Issue
+ TEST START : Fill-Methods-Issue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyRightFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyBottomFillValue
+END 'Fill-Methods-Issue' Symbol
+ TEST OK : Fill-Methods-Issue
+----------------------------------------------------------------
+Range/Item-Method-Issue
+ TEST START : Range/Item-Method-Issue
+ ITEM Assertion OK : Range of multiple columns is: $A:$A,$C:$C
+ ITEM Assertion OK : Range of multiple rows is: $1:$1,$5:$7
+ ITEM Assertion OK : Range of several columns is: $C:$E,$D:$D
+ ITEM Assertion OK : Range of several rows is: $5:$8,$6:$10
+ ITEM Assertion OK : Range of several single cells is: $C$5,$E$8
+ ITEM Assertion OK : Range of several named ranges is: $L$1:$M$6,$E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range of a single Item Cell is: $E$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$10
+END 'Range/Item-Method-Issue' Symbol
+ TEST OK : Range/Item-Method-Issue
+----------------------------------------------------------------
+R1C1-Formulas-Issue
+ TEST START : R1C1-Formulas-Issue
+ ITEM Assertion OK : R1C1 Range.Formula is: =IF(OR(R[-2]C[1]=0,RC[2]="YES"),"")
+ ITEM Assertion OK : Range.Formula is: =IF(OR(J8=0,K10="YES"),"")
+END 'R1C1-Formulas-Issue' Symbol
+ TEST OK : R1C1-Formulas-Issue
+----------------------------------------------------------------
+Verify_Delete
+ TEST START : Verify_Delete
+ ITEM Assertion OK : Ranges are intersecting: $G$13
+ ITEM Assertion OK : Delete with Default: $AJ$4
+ ITEM Assertion OK : Delete with ShifttoLeft: $AJ$4
+ ITEM Assertion OK : Delete with ShiftUp: $M$22
+END 'Verify_Delete' Symbol
+ TEST OK : Verify_Delete
+----------------------------------------------------------------
+Value-Issue
+ TEST START : Value-Issue
+ ITEM Assertion OK : Value of Range is: 12.3
+ ITEM Assertion OK : Text of Range is: 12.3
+ ITEM Assertion OK : Range has Formula: False
+ ITEM Assertion OK : Cell has Formula: False
+ ITEM Assertion OK : Text of Range is null: True
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Cell has Formula: True
+ ITEM Assertion OK : Value of Cell is: 12
+ ITEM Assertion OK : Application.Calculation is : -4135
+ ITEM Assertion OK : Calculation is automated: True
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Value of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Range has Formula after 'ClearContents: False
+ ITEM Assertion OK : Text of Cell is:
+ ITEM Assertion OK : Text of Cell is:
+END 'Value-Issue' Symbol
+ TEST OK : Value-Issue
+----------------------------------------------------------------
+AutoFit issue
+ TEST START : AutoFit issue
+ ITEM Assertion OK : Columns.AutoFit: CurrentWidth is 673
+ ITEM Assertion OK : Rows.AutoFit: CurrentHeight is 612
+END 'AutoFit issue' Symbol
+ TEST OK : AutoFit issue
+----------------------------------------------------------------
+Selections
+ TEST START : Selections
+ ITEM Assertion OK : ActiveCell is : $E$8
+ ITEM Assertion OK : Active Cell is : $E$8
+ ITEM Assertion OK : Number of Cells in Range: 53
+ ITEM Assertion OK : Number of Cells in Range: 53
+ ITEM Assertion OK : Number of Cells in Range: 53
+END 'Selections' Symbol
+ TEST OK : Selections
+----------------------------------------------------------------
+Offset-Resize
+ TEST START : Offset-Resize
+ ITEM Assertion OK : Offset is : $G$10:$I$15,$I$15:$M$21
+ ITEM Assertion OK : Offset is : $G$7:$I$12,$I$12:$M$18
+ ITEM Assertion OK : Resized Range is : $A$20:$D$23
+END 'Offset-Resize' Symbol
+ TEST OK : Offset-Resize
+----------------------------------------------------------------
+Ranges-Address
+ TEST START : Ranges-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range Address is: $E8:$G13,$G13:$K19
+ ITEM Assertion OK : Range Address is: E$8:G$13,G$13:K$19
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5],R[11]C[5]:R[17]C[9]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13,$G$13:$K$19
+END 'Ranges-Address' Symbol
+ TEST OK : Ranges-Address
+----------------------------------------------------------------
+Range-Address
+ TEST START : Range-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13
+ ITEM Assertion OK : Range Address is: $E8:$G13
+ ITEM Assertion OK : Range Address is: E$8:G$13
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: $E$8:$G$13
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13
+END 'Range-Address' Symbol
+ TEST OK : Range-Address
+----------------------------------------------------------------
+Column-Address
+ TEST START : Column-Address
+ ITEM Assertion OK : Range Address is: $F$8:$F$13
+ ITEM Assertion OK : Range Address is: $F8:$F13
+ ITEM Assertion OK : Range Address is: F$8:F$13
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: $F$8:$F$13
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: R[6]C[4]:R[11]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$8:$F$13
+END 'Column-Address' Symbol
+ TEST OK : Column-Address
+----------------------------------------------------------------
+Row-Address
+ TEST START : Row-Address
+ ITEM Assertion OK : Range Address is: $E$9:$G$9
+ ITEM Assertion OK : Range Address is: $E9:$G9
+ ITEM Assertion OK : Range Address is: E$9:G$9
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: $E$9:$G$9
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: R[7]C[3]:R[7]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$9:$G$9
+END 'Row-Address' Symbol
+ TEST OK : Row-Address
+----------------------------------------------------------------
+SingleCell-Address
+ TEST START : SingleCell-Address
+ ITEM Assertion OK : Range Address is: $F$9
+ ITEM Assertion OK : Range Address is: $F9
+ ITEM Assertion OK : Range Address is: F$9
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: $F$9
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: R[7]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$9
+END 'SingleCell-Address' Symbol
+ TEST OK : SingleCell-Address
+----------------------------------------------------------------
+Heights and Widths
+ TEST START : Heights and Widths
+ ITEM Assertion OK : Range RowHeight is 40
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 238
+ ITEM Assertion OK : Range Width is 798.75
+ ITEM Assertion OK : Range RowHeight is 50
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 297
+ ITEM Assertion OK : Range Width is 798.75
+ ITEM Assertion OK : RowHeight is null: True
+ ITEM Assertion OK : ColumnWidth is null: True
+END 'Heights and Widths' Symbol
+ TEST OK : Heights and Widths
+----------------------------------------------------------------
+RangeRowColumn-Issue
+ TEST START : RangeRowColumn-Issue
+ ITEM Assertion OK : Row is: 8
+ ITEM Assertion OK : Column is: 5
+ ITEM Assertion OK : EntireRow.Columns.Count = 256
+ ITEM Assertion OK : EntireColumn.Rows.Count = 65536
+END 'RangeRowColumn-Issue' Symbol
+ TEST OK : RangeRowColumn-Issue
+----------------------------------------------------------------
+Replace-Issue
+ TEST START : Replace-Issue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New Replace
+ ITEM Assertion OK : Value after Replace:
+END 'Replace-Issue' Symbol
+ TEST OK : Replace-Issue
+----------------------------------------------------------------
+Hidden-Issue
+ TEST START : Hidden-Issue
+ ITEM Assertion OK : - Range.Rows.Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Hidden (get)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (get)
+END 'Hidden-Issue' Symbol
+ TEST OK : Hidden-Issue
+----------------------------------------------------------------
+End issue
+ TEST START : End issue
+ ITEM Assertion OK : - = $E$48
+ ITEM Assertion OK : - = $E$1
+ ITEM Assertion OK : - = $E$3
+ ITEM Assertion OK : - = $A$8
+ ITEM Assertion OK : - = $B$8
+ ITEM Assertion OK : - = $IV$8
+ ITEM Assertion OK : - = $Z$8
+END 'End issue' Symbol
+ TEST OK : End issue
+----------------------------------------------------------------
+Outline issue
+ TEST START : Outline issue
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+END 'Outline issue' Symbol
+ TEST OK : Outline issue
+----------------------------------------------------------------
+Validation
+ TEST START : Validation
+ ITEM Assertion OK : Validation Input Message is : Attention!
+ ITEM Assertion OK : Validation Input Message is : Enter an integer from five to ten
+ ITEM Assertion OK : Validation Error Title is : You must enter a number from five to ten
+ ITEM Assertion OK : Validation Error Message is : An Error occured
+ ITEM Assertion OK : Validation Error Title is : Microsoft Excel
+END 'Validation' Symbol
+ TEST OK : Validation
+Test run finished : 01/06/2007 11:29:00
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestAddress.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestAddress.log new file mode 100644 index 000000000000..01e5503a7e62 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestAddress.log @@ -0,0 +1,62 @@ +Test run started : 17/07/2007 15:25:17
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 Range('e3:f3') A1 style addressing
+ ITEM Assertion OK : test2 Range('e3:f3') R1C1 style addressing
+ ITEM Assertion OK : test3 Range ('e:f') A1 style addressing
+ ITEM Assertion OK : test4 Range ('e:f') R1C1 style addressing
+ ITEM Assertion OK : test5 Columns A1 style addressing
+ ITEM Assertion OK : test6 Columns R1C1 style addressing
+ ITEM Assertion OK : test7 Columns(3) A1 style addressing
+ ITEM Assertion OK : test8 Columns(3) R1C1 style addressing
+ ITEM Assertion OK : test9 Columns('e') A1 style addressing
+ ITEM Assertion OK : test10 Columns('e') R1C1 style addressing
+ ITEM Assertion OK : test11 Columns('b:d') A1 style addressing
+ ITEM Assertion OK : test12 Columns('b:d') R1C1 style addressing
+ ITEM Assertion OK : test13 Range('c1:g10').Columns A1 style addressing
+ ITEM Assertion OK : test14 Range('c1:g10').Columns R1C1 style addressing
+ ITEM Assertion OK : test15 Range('c1:g10').Columns(1) A1 style addressing
+ ITEM Assertion OK : test16 Range('c1:g10').Columns(1) R1C1 style addressing
+ ITEM Assertion OK : test17 Range('c1:g10').Columns('a') A1 style addressing
+ ITEM Assertion OK : test18 Range('c1:g10').Columns('a') R1C1 style addressing
+ ITEM Assertion OK : test19 Range('c1:g10').Columns('c') A1 style addressing
+ ITEM Assertion OK : test20 Range('c1:g10').Columns('c') R1C1 style addressing
+ ITEM Assertion OK : test21 Range('c1:g10').Columns('x:z') A1 style addressing
+ ITEM Assertion OK : test22 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test23 Range('c1:g10').Columns(30) A1 style addressing
+ ITEM Assertion OK : test24 Range('c1:g10').Columns(30) R1C1 style addressing
+ ITEM Assertion OK : test25 Worksheets('Sheet2').Cells(1, 1) A1 style addressing
+ ITEM Assertion OK : test26 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, RowAddressAbsolute is false
+ ITEM Assertion OK : test27 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, ColAddressAbsolute is false
+ ITEM Assertion OK : test28 Worksheets('Sheet2').Cells(1, 1) R1C1 style addressing
+ ITEM Assertion OK : test29 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test30 Worksheets('Sheet2').Range('A1').EntireColumn A1 style addressing
+ ITEM Assertion OK : test31 Worksheets('Sheet2').Range('A1:E5').EntireRow A1 style addressing
+ ITEM Assertion OK : test32 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test33 Worksheets('Sheet2').Range('IV65536').EntireRow A1 style addressing
+ ITEM Assertion OK : test34 Worksheets('Sheet2').Range('IU2:IV65536') A1 style addressing
+ ITEM Assertion OK : test35 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test36 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test37 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test38 Worksheets('Sheet2').Range('10:12') A1 style addressing
+ ITEM Assertion OK : test39 Worksheets('Sheet2').Range('10:12') R1C1 style addressing
+ ITEM Assertion OK : test40 Range('Sheet3!A1:B4') A1 style addressing
+ ITEM Assertion OK : test41 Range('Sheet3!A1,B1,D4:F20') A1 style addressing
+ ITEM Assertion OK : test42 Range('g20:h40').Columns('c:c')
+ ITEM Assertion OK : test43 Range('g20:h40').Columns('c:f')
+ ITEM Assertion OK : test44 Range('g20:h40').Columns(-1)
+ ITEM Assertion OK : test45 Range('c4:g10').Rows(-1)
+ ITEM Assertion OK : test46 Range('a2:b4').Rows('1:1')
+ ITEM Assertion OK : test47 Range('a2:b4').Rows('1:2')
+ ITEM Assertion OK : test48 Range('a2:b4').Rows('2:2')
+ ITEM Assertion OK : test49 Range('a2:b4').Rows('2:3')
+Test Results +============ + +Tests passed: 49 +Tests failed: 0 +
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 17/07/2007 15:25:19
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestCalc_Rangetest.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestCalc_Rangetest.log new file mode 100644 index 000000000000..f055279ec6f4 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestCalc_Rangetest.log @@ -0,0 +1,60 @@ +Test run started : 30/05/2007 11:33:13
+BEGIN TestCalc
+ TEST START : RangeTest2
+ ITEM Assertion OK : - Range("D15").Row
+ ITEM Assertion OK : - WorkSheet("D15").Range.Row
+ ITEM Assertion OK : - Range("D15").Column
+ ITEM Assertion OK : - Worksheet.Range("D15").Column
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Columns.Count
+ ITEM Assertion OK : - Range("D1").EntireColumn.Rows.Count
+ ITEM Assertion OK : - Range("D15").ClearContent
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (get)
+ ITEM Assertion OK : - Range("B38").Orientation (get)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlDownward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlUpward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B39").WrapText (get)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (get)
+ ITEM Assertion OK : - Range("F39").MergeCells (get)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion OK : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion OK : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("D41:D42").Replace MatchCase:=False
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM OK (RangeTest2)
+ TEST succesfully completed : RangeTest2
+END TestCalc
+Test run finished : 30/05/2007 11:33:14
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestCalc_Rangetest2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestCalc_Rangetest2.log new file mode 100644 index 000000000000..19a5ba96b54a --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/excel/TestCalc_Rangetest2.log @@ -0,0 +1,64 @@ +Test run started : 31/05/2007 11:02:10
+BEGIN TestCalc
+ TEST START : RangeTest3
+ ITEM Assertion OK : - setFormulaR1C1
+ ITEM Assertion OK : - getFormulaR1C1
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy(Range("I10"))
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteValues
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormulas
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormats
+ ITEM Assertion OK : PasteSpecial
+ ITEM Assertion OK : PasteSpecial SkipBlanks:=True
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationAdd
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationSubtract
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationMultiply
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationDivide
+ ITEM Assertion OK : PasteSpecial Transpose:=True
+ ITEM Assertion OK : ActiveWorkbook.Name
+ ITEM Assertion OK : ActiveWorkbook.FullName und ActiveWorkbook.Path
+ ITEM Assertion OK : - = Range("K22").End (xlDown)
+ ITEM Assertion OK : - = Range("K22").End (xlUo)
+ ITEM Assertion OK : - = Range("K22").End (xlToLeft)
+ ITEM Assertion OK : - = Range("K22").End (xlRight)
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="x"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="<>"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="="
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter
+ ITEM Assertion OK : - ActiveSheet.Resize.Select
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion OK : - Application.GoTo Reference:="R[8]C[2]"
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Ungroup- please check visually
+ ITEM Assertion OK : - Range.Ungroup - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - ActiveSheet.UsedRange.Select
+ ITEM Assertion FAIL : - Range("A13").AddIndent
+ ITEM Assertion OK : - Range("A13").IndentLevel set
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Calculate
+ ITEM Assertion OK : Worksheet.Calculate
+ ITEM Assertion OK : - Application.Calculate
+ ITEM Assertion OK : Global.Calculate
+ ITEM Assertion OK : Calculation set
+ ITEM Assertion OK : - = ActiveWorkbook.Colors(3) set
+ ITEM Assertion OK : - = ActiveWorkbook.ResetColors
+ ITEM Assertion OK : - = ActiveWorkbook.Colors(3) get
+ ITEM FAIL (RangeTest3)
+ TEST Not succesfully completed : RangeTest3
+END TestCalc
+Test run finished : 31/05/2007 11:02:12
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/AutoFilter.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/AutoFilter.log new file mode 100644 index 000000000000..55f5d9526618 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/AutoFilter.log @@ -0,0 +1,20 @@ +Test run started : 18/07/2007 10:56:38 +---------------------------------------------------------------- +TestAddress + TEST START : TestAddress + ITEM Assertion OK : test1 'starts with' string criteria + ITEM Assertion OK : test2 'not equal to' string criteria + ITEM Assertion OK : test3 'ends with' string criteria + ITEM Assertion OK : test4 field 'all' + ITEM Assertion OK : test5 numeric '<15' + ITEM Assertion OK : test6 numeric '>=15' + ITEM Assertion OK : test7 numeric '<=12' +Test Results +============ + +Tests passed: 7 +Tests failed: 0 + +END 'TestAddress + TEST OK : TestAddress +Test run finished : 18/07/2007 10:56:44 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/CalcFont.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/CalcFont.log new file mode 100644 index 000000000000..f3583e4cbb12 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/CalcFont.log @@ -0,0 +1,17 @@ +Test run started : 10/09/2008 02:40:17 PM +CalcFont_Format + TEST START : Font_Format + ITEM Assertion OK : correctly set font to Bold + ITEM Assertion OK : correctly set font to Italic + ITEM Assertion OK : correctly read FontStyle + ITEM Assertion OK : correctly set font to Shadow + ITEM Assertion OK : correctly set font color + ITEM Assertion OK : correctly set font color index + ITEM Assertion OK : correctly set font name + ITEM Assertion OK : correctly set font outline + ITEM Assertion OK : correctly set font size + ITEM Assertion OK : correctly set font strikethrough + ITEM Assertion OK : correctly set font underline + TEST Success. : Font_Format +CalcFont_Format +Test run finished : 10/09/2008 02:40:17 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/MiscRangeTests.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/MiscRangeTests.log new file mode 100644 index 000000000000..215842f9a7e6 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/MiscRangeTests.log @@ -0,0 +1,45 @@ +Test run started : 17/07/2007 20:54:56 +---------------------------------------------------------------- +MiscRangeTests + TEST START : MiscRangeTests + ITEM Assertion OK : test 1 + ITEM Assertion OK : test 2 + ITEM Assertion OK : test 3 + ITEM Assertion OK : test 4 + ITEM Assertion OK : test 5 + ITEM Assertion OK : test 6 + ITEM Assertion OK : test 7 + ITEM Assertion OK : test 8 + ITEM Assertion OK : test 9 + ITEM Assertion OK : test 10 + ITEM Assertion OK : test 11 + ITEM Assertion OK : test 12 + ITEM Assertion OK : test 13 + ITEM Assertion OK : test 14 + ITEM Assertion OK : test 15 + ITEM Assertion OK : test 16 + ITEM Assertion OK : test 17 + ITEM Assertion OK : test 18 + ITEM Assertion OK : test 19 + ITEM Assertion OK : test 20 + ITEM Assertion OK : test 21 + ITEM Assertion OK : test 22 + ITEM Assertion OK : test 23 + ITEM Assertion OK : test 24 + ITEM Assertion OK : test 25 + ITEM Assertion OK : test 26 + ITEM Assertion OK : test 27 + ITEM Assertion OK : test 28 + ITEM Assertion OK : test 29 + ITEM Assertion OK : test 30 + ITEM Assertion OK : test 31 +No. tests: 31 +Summary +======= +Run: 31 +Passed: 31 +Failed: 0 + +END 'MiscRangeTests + TEST OK : MiscRangeTests +Test run finished : 17/07/2007 20:55:03 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/PageBreaks.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/PageBreaks.log new file mode 100644 index 000000000000..0ff400d49e85 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/PageBreaks.log @@ -0,0 +1,10 @@ +Test run started : 07/24/2008 05:06:12 PM +---------------------------------------------------------------- + TEST START : PageBreaks-Issue + ITEM Assertion OK : HPageBreaks.Count is 3 + ITEM Assertion OK : HPageBreak.Type is -4135 + ITEM Assertion OK : HPageBreak.Location: Range.Row is 5 + ITEM Assertion OK : HPageBreak.Delete: HPageBreaks.Count is 2 +END 'PageBreaks-Issue' Symbol + TEST OK : PageBreaks-Issue +Test run finished : 07/24/2008 05:06:13 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges-2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges-2.log new file mode 100644 index 000000000000..8b7076efaea0 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges-2.log @@ -0,0 +1,68 @@ +Test run started : 19/06/2007 11:14:01 +---------------------------------------------------------------- +ClearFormtsIssue + TEST START : ClearFormtsIssue + ITEM Assertion OK : Range.Font.Bold is: True + ITEM Assertion OK : Range.Font.Bold is: False +END 'ClearFormtsIssue' Symbol + TEST OK : ClearFormtsIssue +---------------------------------------------------------------- +VerticalAlignment-Issue + TEST START : VerticalAlignment-Issue + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (set) + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (set) + ITEM Assertion OK : - Range.VerticalAlignment (get) + ITEM Assertion OK : - Range.VerticalAlignment (set) + ITEM Assertion OK : Range.VeritcalAlignment is Null +END 'VerticalAlignment-Issue' Symbol + TEST OK : VerticalAlignment-Issue +---------------------------------------------------------------- +HorizontalAlignment-Issue + TEST START : HorizontalAlignment-Issue + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : - Range.HorizontalAlignment (get) + ITEM Assertion OK : - Range.HorizontalAlignment (set) + ITEM Assertion OK : Range.HorizontalAlignment is Null +END 'HorizontalAlignment-Issue' Symbol + TEST OK : HorizontalAlignment-Issue +---------------------------------------------------------------- +WrapText-Issue + TEST START : WrapText-Issue + ITEM Assertion OK : - Range.WrapText (get) + ITEM Assertion OK : - Range.WrapText (get) + ITEM Assertion OK : Range.WrapText is Null +END 'WrapText-Issue' Symbol + TEST OK : WrapText-Issue +---------------------------------------------------------------- +FontBorderIssues + TEST START : FontBorderIssues + ITEM Assertion OK : - = Borders.Color (getColor) + ITEM Assertion OK : - = Font.Color (getColor) +END 'FontBorderIssues' Symbol + TEST OK : FontBorderIssues +---------------------------------------------------------------- +RangeSizeIssues + TEST START : RangeSizeIssues + ITEM Assertion OK : Range.Left is: 118.8432 + ITEM Assertion OK : Range.Top is: 92.16585 + ITEM Assertion OK : Range.Width is: 226.2 + ITEM Assertion OK : Range.Height is: 271.5 +END 'RangeSizeIssues' Symbol + TEST OK : RangeSizeIssues +---------------------------------------------------------------- +ApplicationIssues + TEST START : ApplicationIssues + ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Application.ActiveSheet.Name: Sheet1 +END 'ApplicationIssues' Symbol + TEST OK : ApplicationIssues +Test run finished : 19/06/2007 11:14:02 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges-3.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges-3.log new file mode 100644 index 000000000000..a130737ceb65 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges-3.log @@ -0,0 +1,8 @@ +Test run started : 19/06/2007 11:26:09 +---------------------------------------------------------------- +MyGoalseek-Issue + TEST START : MyGoalseek-Issue + ITEM Assertion OK : Variable Range value: 15 +END 'MyGoalseek-Issue' Symbol + TEST OK : MyGoalseek-Issue +Test run finished : 19/06/2007 11:26:10 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges.log new file mode 100644 index 000000000000..cdd18685e977 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Ranges.log @@ -0,0 +1,280 @@ +Test run started : 10/03/2008 15:15:11 +---------------------------------------------------------------- +ApplicationMethods + TEST START : ApplicationMethods + ITEM Assertion OK : Name of Workbook is: Ranges.xls + ITEM Assertion OK : Address of Application.Columns is: $A:$A + ITEM Assertion OK : Address of Application.Rows is: $1:$1 + ITEM Assertion OK : Address of Application.Range is: $1:$1,$5:$7 + ITEM Assertion OK : Please check manually: DefaultFilePath is: /data4/home/npower/Documents + ITEM Assertion OK : Please check manually: Library Path is: /data4/home/npower/.ooo-2.0/user/basic + ITEM Assertion OK : Please check manually: Template Path is: /data4/home/npower/.ooo-2.0/user/template + ITEM Assertion OK : FileSeparator is / + ITEM Assertion OK : Name of ActiveWorkbook is: Ranges.xls +END 'ApplicationMethods' Symbol + TEST OK : ApplicationMethods +---------------------------------------------------------------- +Insert-Issue + TEST START : Insert-Issue + ITEM Assertion OK : Insert with xlShiftToRight: 10 +END 'Insert-Issue' Symbol + TEST OK : Insert-Issue +---------------------------------------------------------------- +MergeCells-Issue + TEST START : MergeCells-Issue + ITEM Assertion OK : Range.MergeCells is True + ITEM Assertion FAIL : MergeCells is null: False + ITEM Assertion OK : RowCount after Merge: 13 + ITEM Assertion OK : Range.MergeCells is False + ITEM Assertion OK : MergeCells is null: False + ITEM Assertion FAIL : MergeCells of Second Area is null : False + ITEM Assertion FAIL : MergeCells of Ranges is Null: False + ITEM Assertion OK : RowCount after Merge: 7 + ITEM Assertion OK : Range.MergeCells is False + ITEM Assertion OK : MergeCells is null: False + ITEM Assertion OK : RowCount after Merge: 7 +END 'MergeCells-Issue' Symbol + TEST OK : MergeCells-Issue +---------------------------------------------------------------- +Areas-Issue + TEST START : Areas-Issue + ITEM Assertion OK : Range Areas Count is2 + ITEM Assertion OK : First Range Address is: $E$8:$G$13 + ITEM Assertion OK : First Row is: 8 + ITEM Assertion OK : First Column is: 5 + ITEM Assertion OK : EntireRow Address is: $8:$13,$13:$19 + ITEM Assertion OK : EntireColumn Address is: $E:$G,$G:$K + ITEM Assertion OK : Range Count:53 +END 'Areas-Issue' Symbol + TEST OK : Areas-Issue +---------------------------------------------------------------- +Fill-Methods-Issue + TEST START : Fill-Methods-Issue + ITEM Assertion OK : Range Value after FillDown: MyFillValue + ITEM Assertion OK : Range Value after FillDown: MyFillValue + ITEM Assertion OK : Range Value after FillDown: MyRightFillValue + ITEM Assertion OK : Range Value after FillDown: MyBottomFillValue +END 'Fill-Methods-Issue' Symbol + TEST OK : Fill-Methods-Issue +---------------------------------------------------------------- +Range/Item-Method-Issue + TEST START : Range/Item-Method-Issue + ITEM Assertion OK : Range of multiple columns is: $A:$A,$C:$C + ITEM Assertion OK : Range of multiple rows is: $1:$1,$5:$7 + ITEM Assertion OK : Range of several columns is: $C:$E,$D:$D + ITEM Assertion OK : Range of several rows is: $5:$8,$6:$10 + ITEM Assertion OK : Range of several single cells is: $C$5,$E$8 + ITEM Assertion OK : Range of several named ranges is: $L$1:$M$6,$E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Range of a single Item Cell is: $E$21 + ITEM Assertion OK : Range of a single Item Cell is: $F$21 + ITEM Assertion OK : Range of a single Item Cell is: $F$10 +END 'Range/Item-Method-Issue' Symbol + TEST OK : Range/Item-Method-Issue +---------------------------------------------------------------- +R1C1-Formulas-Issue + TEST START : R1C1-Formulas-Issue + ITEM Assertion OK : R1C1 Range.Formula is: =IF(OR(R[-2]C[1]=0,RC[2]="YES"),"") + ITEM Assertion OK : Range.Formula is: =IF(OR(J8=0,K10="YES"),"") +END 'R1C1-Formulas-Issue' Symbol + TEST OK : R1C1-Formulas-Issue +---------------------------------------------------------------- +Verify_Delete + TEST START : Verify_Delete + ITEM Assertion OK : Ranges are intersecting: $G$13 + ITEM Assertion OK : Delete with Default: $AJ$4 + ITEM Assertion OK : Delete with ShifttoLeft: $AJ$4 + ITEM Assertion OK : Delete with ShiftUp: $M$22 +END 'Verify_Delete' Symbol + TEST OK : Verify_Delete +---------------------------------------------------------------- +Value-Issue + TEST START : Value-Issue + ITEM Assertion OK : Value of Range is: 12.3 + ITEM Assertion OK : Text of Range is: 12.3 + ITEM Assertion OK : Range has Formula: False + ITEM Assertion OK : Cell has Formula: False + ITEM Assertion FAIL : Text of Range is null: False + ITEM Assertion OK : Range has Formula: True + ITEM Assertion OK : Cell has Formula: True + ITEM Assertion OK : Value of Cell is: 12 + ITEM Assertion OK : Application.Calculation is : -4135 + ITEM Assertion OK : Calculation is automated: True + ITEM Assertion OK : Range has Formula: True + ITEM Assertion OK : Value of Cell is: 16 + ITEM Assertion OK : Text of Cell is: 16 + ITEM Assertion OK : Text of Cell is: 16 + ITEM Assertion OK : Range has Formula after 'ClearContents: False + ITEM Assertion OK : Text of Cell is: + ITEM Assertion OK : Text of Cell is: +END 'Value-Issue' Symbol + TEST OK : Value-Issue +---------------------------------------------------------------- +AutoFit issue + TEST START : AutoFit issue + ITEM Assertion OK : Columns.AutoFit: CurrentWidth is 680 + ITEM Assertion OK : Rows.AutoFit: CurrentHeight is 554 +END 'AutoFit issue' Symbol + TEST OK : AutoFit issue +---------------------------------------------------------------- +Selections + TEST START : Selections + ITEM Assertion OK : ActiveCell is : $E$8 + ITEM Assertion OK : Active Cell is : $E$8 + ITEM Assertion OK : Number of Cells in Range: 52 + ITEM Assertion OK : Number of Cells in Range: 52 + ITEM Assertion OK : Number of Cells in Range: 52 +END 'Selections' Symbol + TEST OK : Selections +---------------------------------------------------------------- +Offset-Resize + TEST START : Offset-Resize + ITEM Assertion OK : Offset is : $G$10:$I$15,$I$15:$M$21 + ITEM Assertion OK : Offset is : $G$7:$I$12,$I$12:$M$18 + ITEM Assertion OK : Resized Range is : $A$20:$D$23 +END 'Offset-Resize' Symbol + TEST OK : Offset-Resize +---------------------------------------------------------------- +Ranges-Address + TEST START : Ranges-Address + ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19 + ITEM Assertion OK : Range Address is: $E8:$G13,$G13:$K19 + ITEM Assertion OK : Range Address is: E$8:G$13,G$13:K$19 + ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11 + ITEM Assertion FAIL : Range Address is: R8C5:R13C7,R13C7:R19C11 + ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11 + ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5],R[11]C[5]:R[17]C[9] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13,$G$13:$K$19 +END 'Ranges-Address' Symbol + TEST OK : Ranges-Address +---------------------------------------------------------------- +Range-Address + TEST START : Range-Address + ITEM Assertion OK : Range Address is: $E$8:$G$13 + ITEM Assertion OK : Range Address is: $E8:$G13 + ITEM Assertion OK : Range Address is: E$8:G$13 + ITEM Assertion OK : Range Address is: R8C5:R13C7 + ITEM Assertion FAIL : Range Address is: R8C5:R13C7 + ITEM Assertion OK : Range Address is: R8C5:R13C7 + ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13 +END 'Range-Address' Symbol + TEST OK : Range-Address +---------------------------------------------------------------- +Column-Address + TEST START : Column-Address + ITEM Assertion OK : Range Address is: $F$8:$F$13 + ITEM Assertion OK : Range Address is: $F8:$F13 + ITEM Assertion OK : Range Address is: F$8:F$13 + ITEM Assertion OK : Range Address is: R8C6:R13C6 + ITEM Assertion FAIL : Range Address is: R8C6:R13C6 + ITEM Assertion OK : Range Address is: R8C6:R13C6 + ITEM Assertion OK : Range Address is: R[6]C[4]:R[11]C[4] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$8:$F$13 +END 'Column-Address' Symbol + TEST OK : Column-Address +---------------------------------------------------------------- +Row-Address + TEST START : Row-Address + ITEM Assertion OK : Range Address is: $E$9:$G$9 + ITEM Assertion OK : Range Address is: $E9:$G9 + ITEM Assertion OK : Range Address is: E$9:G$9 + ITEM Assertion OK : Range Address is: R9C5:R9C7 + ITEM Assertion FAIL : Range Address is: R9C5:R9C7 + ITEM Assertion OK : Range Address is: R9C5:R9C7 + ITEM Assertion OK : Range Address is: R[7]C[3]:R[7]C[5] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$9:$G$9 +END 'Row-Address' Symbol + TEST OK : Row-Address +---------------------------------------------------------------- +SingleCell-Address + TEST START : SingleCell-Address + ITEM Assertion OK : Range Address is: $F$9 + ITEM Assertion OK : Range Address is: $F9 + ITEM Assertion OK : Range Address is: F$9 + ITEM Assertion OK : Range Address is: R9C6 + ITEM Assertion FAIL : Range Address is: R9C6 + ITEM Assertion OK : Range Address is: R9C6 + ITEM Assertion OK : Range Address is: R[7]C[4] + ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$9 +END 'SingleCell-Address' Symbol + TEST OK : SingleCell-Address +---------------------------------------------------------------- +Heights and Widths + TEST START : Heights and Widths + ITEM Assertion OK : Range RowHeight is 40 + ITEM Assertion OK : Range ColumnWidth is 50 + ITEM Assertion OK : Range Height is 240 + ITEM Assertion OK : Range Width is 795 + ITEM Assertion OK : Range RowHeight is 50 + ITEM Assertion OK : Range ColumnWidth is 50 + ITEM Assertion OK : Range Height is 300 + ITEM Assertion OK : Range Width is 795 + ITEM Assertion OK : RowHeight is null: True + ITEM Assertion OK : ColumnWidth is null: True +END 'Heights and Widths' Symbol + TEST OK : Heights and Widths +---------------------------------------------------------------- +RangeRowColumn-Issue + TEST START : RangeRowColumn-Issue + ITEM Assertion OK : Row is: 8 + ITEM Assertion OK : Column is: 5 + ITEM Assertion OK : EntireRow.Columns.Count = 256 + ITEM Assertion OK : EntireColumn.Rows.Count = 131072 +END 'RangeRowColumn-Issue' Symbol + TEST OK : RangeRowColumn-Issue +---------------------------------------------------------------- +Replace-Issue + TEST START : Replace-Issue + ITEM Assertion OK : Value after Replace: YourValue + ITEM Assertion OK : Value after Replace: YourValue + ITEM Assertion OK : Value after Replace: ReplaceValue + ITEM Assertion OK : Value after Replace: New ReplaceValue + ITEM Assertion OK : Value after Replace: New ReplaceValue + ITEM Assertion OK : Value after Replace: New Replace + ITEM Assertion OK : Value after Replace: +END 'Replace-Issue' Symbol + TEST OK : Replace-Issue +---------------------------------------------------------------- +Hidden-Issue + TEST START : Hidden-Issue + ITEM Assertion OK : - Range.Rows.Hidden (set) + ITEM Assertion OK : - Range.Rows.Hidden (get) + ITEM Assertion OK : - Range.Rows.Item(1).Hidden (set) + ITEM Assertion OK : - Range.Rows.Item(1).Hidden (get) + ITEM Assertion OK : - Range.Columns.Hidden (set) + ITEM Assertion OK : - Range.Columns.Hidden (get) + ITEM Assertion OK : - Range.Columns.Item(1).Hidden (set) + ITEM Assertion OK : - Range.Columns.Item(1).Hidden (get) +END 'Hidden-Issue' Symbol + TEST OK : Hidden-Issue +---------------------------------------------------------------- +End issue + TEST START : End issue + ITEM Assertion OK : - = $E$48 + ITEM Assertion OK : - = $E$1 + ITEM Assertion OK : - = $E$3 + ITEM Assertion OK : - = $A$8 + ITEM Assertion OK : - = $B$8 + ITEM Assertion OK : - = $IV$8 + ITEM Assertion OK : - = $Z$8 +END 'End issue' Symbol + TEST OK : End issue +---------------------------------------------------------------- +Outline issue + TEST START : Outline issue + ITEM Assertion OK : - Range.clearOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually +END 'Outline issue' Symbol + TEST OK : Outline issue +---------------------------------------------------------------- +Validation + TEST START : Validation + ITEM Assertion OK : Validation Input Message is : Attention! + ITEM Assertion OK : Validation Input Message is : Enter an integer from five to ten + ITEM Assertion OK : Validation Error Title is : You must enter a number from five to ten + ITEM Assertion OK : Validation Error Message is : An Error occured + ITEM Assertion OK : Validation Error Title is : Microsoft Excel +END 'Validation' Symbol + TEST OK : Validation +Test run finished : 10/03/2008 15:15:13 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Shapes.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Shapes.log new file mode 100644 index 000000000000..3193a0b1094d --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Shapes.log @@ -0,0 +1,77 @@ +Test run started : 10/16/2007 05:25:21 PM +BEGIN Shapes_Collection_Behaviour + TEST START : Shapes_Collection_Behaviour + ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape1' + ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape2' + TEST Success. : Shapes_Collection_Behaviour +END Shapes_Collection_Behaviour +BEGIN Shapes_Select_Item + TEST START : Shapes_Select_Item + ITEM Assertion OK : Correctly selected shape through Range + ITEM Assertion OK : Correctly selected shape through Item + ITEM Assertion OK : Needs to be visually checked. Is there a line on the document? + ITEM Assertion OK : Needs to be visually checked. Are All Shapes Selected? + TEST Success. : Shapes_Select_Item +END Shapes_Select_Item +BEGIN Shapes_Fill + TEST START : Shapes_Fill + ITEM Assertion OK : correctly set visibility of shape fill + ITEM Assertion OK : correctly set transparency of shape line + ITEM Assertion OK : correctly set forecolor of shape fill + ITEM Assertion FAIL : correctly set backcolor of shape fill + ITEM Assertion OK : the success of the TwoColorGradient method needs to be verified visually! + ITEM Assertion OK : correctly set forecolor of shape fill + ITEM Assertion FAIL : correctly set forecolor of shape fill + TEST Success. : Shapes_Fill +END Shapes_Fill +BEGIN Shapes_Line + TEST START : Shapes_Line + ITEM Assertion FAIL : correctly set weight of shape line + ITEM Assertion OK : correctly set visibility of shape line + ITEM Assertion OK : correctly set transparency of shape line + ITEM Assertion OK : correctly set dash style of shape line + ITEM Assertion OK : correctly set dash style of shape line + ITEM Assertion OK : correctly set forecolor of shape line + ITEM Assertion FAIL : correctly set backcolor of shape line + TEST Success. : Shapes_Line +END Shapes_Line +BEGIN Shapes_TextFrame + TEST START : Shapes_TextFrame + ITEM Assertion OK : correctly set Autosize of Shape TextFrame + TEST Success. : Shapes_TextFrame +END Shapes_TextFrame +BEGIN Shapes_SimpleGeometry + TEST START : Shapes_SimpleGeometery + ITEM Assertion OK : shape height should be 47.0425168477155 and got 46.9984222363199 + ITEM Assertion OK : shape width should be 101.467710269751 and got 101.423615658355 + ITEM Assertion OK : shape left should be 68.5574761223637 and got 68.5417279658754 + ITEM Assertion OK : shape top should be 42.0251943291216 and got 42.0094461726333 + ITEM Assertion OK : shape rotation should be 0 and got 0 + ITEM Assertion OK : shape rotation should be 25 and got 25 + ITEM Assertion OK : shape incrementrotation should be 50 and got 50 + ITEM Assertion OK : shape incrementleft should be 70.6834602404119 and got 70.6677120839236 + ITEM Assertion OK : shape incrementtop should be 91.262986503119 and got 91.2472383466307 + TEST Success. : Shapes_SimpleGeometery +END Shapes_SimpleGeometry +BEGIN Shapes_Range + TEST START : Shapes_Range + ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to contain 1 element, it contains 1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to return Sheet2Shape1 got Sheet2Shape1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to contain 1 element, it contains 1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to return Sheet2Shape3 got Sheet2Shape3 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to contain 2 elements, it contains 2 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to return concated element/shape names Sheet2Shape3Sheet2Shape1 and got Sheet2Shape3Sheet2Shape1 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to contain 3 elements, it contains 3 + ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to return concated element/shape names Sheet2Shape3Sheet2Shape1Sheet2Shape2 and got Sheet2Shape3Sheet2Shape1Sheet2Shape2 + TEST Success. : Shapes_Range +END Shapes_Range +BEGIN Shapes_ShapeRange + TEST START : Shapes_ShapeRange + ITEM Assertion OK : ShapeRange.IncrementLeft shp1.left should be 90.6677120839236 and got 90.6519627935771 + ITEM Assertion OK : ShapeRange.IncrementLeft shp2.left should be 240.02518299054 and got 240.009433700193 + ITEM Assertion OK : ShapeRange.IncrementTop shp1.Top should be 111.247238346631 and got 111.231489056284 + ITEM Assertion OK : ShapeRange.IncrementTop shp2.Top should be 65.0708633026228 and got 65.0551140122763 + ITEM Assertion OK : ShapeRange.IncrementRotation shp1.Rotation should be 70 and got 70 + ITEM Assertion OK : ShapeRange.IncrementRotation shp2.Rotation should be 20 and got 20 +END Shapes_ShapeRange +Test run finished : 10/16/2007 05:25:22 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/StrConv-test.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/StrConv-test.log new file mode 100644 index 000000000000..c7a7d8750583 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/StrConv-test.log @@ -0,0 +1,9 @@ +Test run started : 05/29/2008 02:51:03 PM +BEGIN StrConv + TEST START : Test StrConv function + ITEM Assertion OK : Converts the string to uppercase characters:ABC EFG HIJ + ITEM Assertion OK : Converts the string to lowercase characters:abc efg hij + ITEM Assertion OK : Converts the first letter of every word in string to uppercase:Abc Efg Hij + TEST OK : Test StrConv function +END StrConv +Test run finished : 05/29/2008 02:51:03 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Template.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Template.log new file mode 100644 index 000000000000..c6376c5b3732 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Template.log @@ -0,0 +1,14 @@ +Test run started : 2008/07/10 11:57:05 +---------------------------------------------------------------- +TestCaseName + TEST START : TestCaseName + ITEM Assertion OK : Something has been done. +Test Results +============ + +Tests passed: 1 +Tests failed: 0 + +END 'TestCaseName + TEST OK : TestCaseName +Test run finished : 2008/07/10 11:57:05 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestAddress.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestAddress.log new file mode 100644 index 000000000000..4fa4bc820f59 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestAddress.log @@ -0,0 +1,67 @@ +Test run started : 12/05/2009 11:23:35 +---------------------------------------------------------------- +TestAddress + TEST START : TestAddress + ITEM Assertion OK : test1 Range('e3:f3') A1 style addressing + ITEM Assertion OK : test2 Range('e3:f3') R1C1 style addressing + ITEM Assertion OK : test3 Range ('e:f') A1 style addressing + ITEM Assertion OK : test4 Range ('e:f') R1C1 style addressing + ITEM Assertion OK : test5 Columns A1 style addressing + ITEM Assertion OK : test6 Columns R1C1 style addressing + ITEM Assertion OK : test7 Columns(3) A1 style addressing + ITEM Assertion OK : test8 Columns(3) R1C1 style addressing + ITEM Assertion OK : test9 Columns('e') A1 style addressing + ITEM Assertion OK : test10 Columns('e') R1C1 style addressing + ITEM Assertion OK : test11 Columns('b:d') A1 style addressing + ITEM Assertion OK : test12 Columns('b:d') R1C1 style addressing + ITEM Assertion OK : test13 Range('c1:g10').Columns A1 style addressing + ITEM Assertion OK : test14 Range('c1:g10').Columns R1C1 style addressing + ITEM Assertion OK : test15 Range('c1:g10').Columns(1) A1 style addressing + ITEM Assertion OK : test16 Range('c1:g10').Columns(1) R1C1 style addressing + ITEM Assertion OK : test17 Range('c1:g10').Columns('a') A1 style addressing + ITEM Assertion OK : test18 Range('c1:g10').Columns('a') R1C1 style addressing + ITEM Assertion OK : test19 Range('c1:g10').Columns('c') A1 style addressing + ITEM Assertion OK : test20 Range('c1:g10').Columns('c') R1C1 style addressing + ITEM Assertion OK : test21 Range('c1:g10').Columns('x:z') A1 style addressing + ITEM Assertion OK : test22 Range('c1:g10').Columns('x:z') R1C1 style addressing + ITEM Assertion OK : test23 Range('c1:g10').Columns(30) A1 style addressing + ITEM Assertion OK : test24 Range('c1:g10').Columns(30) R1C1 style addressing + ITEM Assertion OK : test25 Worksheets('Sheet2').Cells(1, 1) A1 style addressing + ITEM Assertion OK : test26 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, RowAddressAbsolute is false + ITEM Assertion OK : test27 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, ColAddressAbsolute is false + ITEM Assertion OK : test28 Worksheets('Sheet2').Cells(1, 1) R1C1 style addressing + ITEM Assertion OK : test29 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing + ITEM Assertion OK : test30 Worksheets('Sheet2').Range('A1').EntireColumn A1 style addressing + ITEM Assertion OK : test31 Worksheets('Sheet2').Range('A1:E5').EntireRow A1 style addressing + ITEM Assertion OK : test32 Worksheets('Sheet2').Range('A1') A1 style addressing + ITEM Assertion OK : test33 Worksheets('Sheet2').Range('IV65536').EntireRow A1 style addressing + ITEM Assertion OK : test34 Worksheets('Sheet2').Range('IU2:IV65536') A1 style addressing + ITEM Assertion OK : test35 Range('c1:g10').Columns('x:z') R1C1 style addressing + ITEM Assertion OK : test36 Worksheets('Sheet2').Range('A1') A1 style addressing + ITEM Assertion OK : test37 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing + ITEM Assertion OK : test38 Worksheets('Sheet2').Range('10:12') A1 style addressing + ITEM Assertion OK : test39 Worksheets('Sheet2').Range('10:12') R1C1 style addressing + ITEM Assertion OK : test40 Range('Sheet3!A1:B4') A1 style addressing + ITEM Assertion OK : test41 Range('Sheet3!A1,B1,D4:F20') A1 style addressing + ITEM Assertion OK : test42 Range('g20:h40').Columns('c:c') + ITEM Assertion OK : test43 Range('g20:h40').Columns('c:f') + ITEM Assertion OK : test44 Range('g20:h40').Columns(-1) + ITEM Assertion OK : test45 Range('c4:g10').Rows(-1) + ITEM Assertion OK : test46 Range('a2:b4').Rows('1:1') + ITEM Assertion OK : test47 Range('a2:b4').Rows('1:2') + ITEM Assertion OK : test48 Range('a2:b4').Rows('2:2') + ITEM Assertion OK : test49 Range('a2:b4').Rows('2:3') + ITEM Assertion OK : test50 Range(' A2:B4 ') + ITEM Assertion OK : test51 Range('A 2:B 4') + ITEM Assertion OK : test52 Range('A2 : B4 ') + ITEM Assertion OK : test53 Range('Sheet1 !A2 : B4 ') + ITEM Assertion OK : test54 Range('Sheet1! A2 : B4 ') +Test Results +============ + +Tests passed: 54 +Tests failed: 0 + +END 'TestAddress + TEST OK : TestAddress +Test run finished : 12/05/2009 11:23:35 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestCalc_Rangetest.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestCalc_Rangetest.log new file mode 100644 index 000000000000..083819d4b64e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestCalc_Rangetest.log @@ -0,0 +1,60 @@ +Test run started : 30/05/2007 15:59:40 +BEGIN TestCalc + TEST START : RangeTest2 + ITEM Assertion OK : - Range("D15").Row + ITEM Assertion OK : - WorkSheet("D15").Range.Row + ITEM Assertion OK : - Range("D15").Column + ITEM Assertion OK : - Worksheet.Range("D15").Column + ITEM Assertion OK : - Range("D1").EntireRow.Valuer + ITEM Assertion OK : - Range("D1").EntireRow.Valuer + ITEM Assertion OK : - Range("D1").EntireRow.Columns.Count + ITEM Assertion OK : - Range("D1").EntireColumn.Rows.Count + ITEM Assertion OK : - Range("D15").ClearContent + ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (get) + ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (get) + ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (get) + ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (set) + ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (get) + ITEM Assertion OK : - Range("B38").Orientation (get) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlDownward) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlUpward) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical) + ITEM Assertion OK : - Range("B38").Orientation (set) + ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical) + ITEM Assertion OK : - Range("B39").WrapText (get) + ITEM Assertion OK : - Range("B39").WrapText (set) + ITEM Assertion OK : - Range("B39").WrapText (set) + ITEM Assertion OK : - Range("E39").MergeCells (get) + ITEM Assertion OK : - Range("F39").MergeCells (get) + ITEM Assertion OK : - Range("E39").MergeCells (set) + ITEM Assertion FAIL : - Range("F39").MergeCells (set) + ITEM Assertion OK : - Range("E39").MergeCells (set) + ITEM Assertion OK : - Range("F39").MergeCells (set) + ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True + ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True + ITEM Assertion OK : - Range("D41:D42").Replace MatchCase:=False + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (set) + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (set) + ITEM Assertion OK : - Range("B39").VerticalAlignment (get) + ITEM Assertion OK : - Range("B39").VerticalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (get) + ITEM Assertion OK : - Range("B39").HorizontalAlignment (set) + ITEM FAIL (RangeTest2) + TEST Not succesfully completed : RangeTest2 +END TestCalc +Test run finished : 30/05/2007 15:59:42 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestCalc_Rangetest2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestCalc_Rangetest2.log new file mode 100644 index 000000000000..b1573c06d90e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestCalc_Rangetest2.log @@ -0,0 +1,65 @@ +Test run started : 10/03/2008 15:15:19 +BEGIN TestCalc + TEST START : RangeTest3 + ITEM Assertion OK : - setFormulaR1C1 + ITEM Assertion OK : - getFormulaR1C1 + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Copy(Range("I10")) + ITEM Assertion OK : PasteSpecial Paste:=xlPasteValues + ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormulas + ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormats + ITEM Assertion OK : PasteSpecial + ITEM Assertion OK : PasteSpecial SkipBlanks:=True + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationAdd + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationSubtract + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationMultiply + ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationDivide + ITEM Assertion OK : PasteSpecial Transpose:=True + ITEM Assertion FAIL : ActiveWorkbook.FileFormat + ITEM Assertion OK : ActiveWorkbook.Name + ITEM Assertion OK : ActiveWorkbook.FullName und ActiveWorkbook.Path + ITEM Assertion FAIL : - = ActiveWorkbook.Colors(3) set + ITEM Assertion OK : - = ActiveWorkbook.ResetColors + ITEM Assertion OK : - = ActiveWorkbook.Colors(3) get + ITEM Assertion OK : - = Range("K22").End (xlDown) + ITEM Assertion OK : - = Range("K22").End (xlUo) + ITEM Assertion OK : - = Range("K22").End (xlToLeft) + ITEM Assertion OK : - = Range("K22").End (xlRight) + ITEM Assertion OK : - ActiveSpreadsheet.Next + ITEM Assertion OK : - ActiveSpreadsheet.Next + ITEM Assertion OK : - ActiveSpreadsheet.Previous + ITEM Assertion OK : - ActiveSpreadsheet.Previous + ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="x" + ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="<>" + ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="=" + ITEM Assertion OK : - Range("J4:J11").AutoFilter + ITEM Assertion OK : - ActiveSheet.Resize.Select + ITEM Assertion OK : - Application.GoTo Reference:="R8C2" + ITEM Assertion FAIL : - Application.GoTo Reference:="R[8]C[2]" + ITEM Assertion OK : - Application.GoTo Reference:="R8C2" + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.Ungroup- please check visually + ITEM Assertion OK : - Range.Ungroup - please check visually + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.Group - please check visually + ITEM Assertion OK : - Range.clearOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually + ITEM Assertion OK : - Range.AutoOutline - please check visually + ITEM Assertion OK : - ActiveSheet.UsedRange.Select + ITEM Assertion OK : - Range("A13").AddIndent + ITEM Assertion OK : - Range("A13").IndentLevel set + ITEM Assertion OK : - Range("A13").IndentLevel get + ITEM Assertion OK : - Range("A13").IndentLevel get + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial() + ITEM Assertion OK : - Range.Calculate + ITEM Assertion OK : Worksheet.Calculate + ITEM Assertion OK : - Application.Calculate + ITEM Assertion OK : Global.Calculate + ITEM Assertion OK : Calculation set + ITEM FAIL (RangeTest3) + TEST Not succesfully completed : RangeTest3 +END TestCalc +Test run finished : 10/03/2008 15:15:21 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestIntersection.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestIntersection.log new file mode 100644 index 000000000000..ea686a830cde --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestIntersection.log @@ -0,0 +1,26 @@ +Test run started : 13/01/2009 14:31:43 +---------------------------------------------------------------- +TestIntersection + TEST START : TestIntersection + ITEM Assertion OK : test1 Application.Intersect( Range('A2:D10'), Range('C4:E6')) + ITEM Assertion OK : test2 Application.Intersect( Range('A2:D10'), Range('A4:G10')) + ITEM Assertion OK : test3 Application.Intersect( Range('A2:c8,d2:f8,g2:i8'), Range('A4:G10')) + ITEM Assertion OK : test4 Application.Intersect( Range('A4:G10'), Range('A2:c8,d2:f8,g2:i8')) + ITEM Assertion OK : test5 Application.Intersect( Range('A2:c8,d2:f8,g2:i8'), Range('g4:i10,A4:G10')) + ITEM Assertion OK : test6 Application.Intersect( Range('g4:i10,A4:G10'), Range('A2:c8,d2:f8,g2:i8')) + ITEM Assertion OK : test7 Application.Intersect( Range('a2:d10,b5:e10'), Range('a5:i10')) + ITEM Assertion OK : test8 Application.Intersect( Range('a2:c8,d2:f8'), Range('b6:e9,a6:f9')) + ITEM Assertion OK : test9 Application.Intersect( Range('a2:c8,e2:f8'), Range('b6:e9,a6:f9')) + ITEM Assertion OK : test10 Application.Intersect( Range('a1:a3,c1:c3'), Range('a2:c3')) + ITEM Assertion OK : test11 Application.Intersect( Range('a1:a3,b1:b3'), Range('a2:c3')) + ITEM Assertion OK : test12 Application.Intersect( Range('a2:d5,b3:f7,c1:g4'), Range('b2:e6')) + ITEM Assertion OK : test13 Range(" a2:d10,b5:e10,g13:j32 "), Range(" a5:i10,b6:e9 "), Range("b2:r5,f10:h19") +Test Results +============ + +Tests passed: 13 +Tests failed: 0 + +END 'TestIntersection + TEST OK : TestIntersection +Test run finished : 13/01/2009 14:31:43 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestUnion.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestUnion.log new file mode 100644 index 000000000000..da3cb35dedb3 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/TestUnion.log @@ -0,0 +1,17 @@ +Test run started : 13/01/2009 14:32:16 +---------------------------------------------------------------- +TestUnion + TEST START : TestUnion + ITEM Assertion OK : test1Application.Range('A2:D10'), Range('C4:E6') + ITEM Assertion OK : test2Application.Range('A2:D5,a3:d4'), Range('A4:G10') + ITEM Assertion OK : test3Application.Range('A4:G10,A1:B6'), Range('A2:D5,A3:D4') + ITEM Assertion OK : test4Application.Range('A5:D10'), Range('B5:E10') +Test Results +============ + +Tests passed: 4 +Tests failed: 0 + +END 'TestUnion + TEST OK : TestUnion +Test run finished : 13/01/2009 14:32:16 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Window.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Window.log new file mode 100644 index 000000000000..ec9a6656113e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/Window.log @@ -0,0 +1,46 @@ +Test run started : 05/29/2008 02:55:00 PM +---------------------------------------------------------------- + TEST START : Window-Issue + ITEM Assertion OK : Window.Left is: 0 (Test only applies to maximized Window) + ITEM Assertion OK : Window.Top is: 21 (Test only applies to maximized Window) + ITEM Assertion OK : Window.Width is: 1280 (Test only applies to maximized Window) + ITEM Assertion OK : Window.Height is: 752 (Test only applies to maximized Window) + ITEM Assertion OK : Window.ScrollColumn is: 100 + ITEM Assertion OK : Window.ScrollColumn is: 1 + ITEM Assertion OK : Window.ScrollRow is: 100 + ITEM Assertion OK : Window.ScrollRow is: 1 + ITEM Assertion OK : Window.LargeScroll(Down): ScrollRow is: 94 (Test may only apply to maximized Window) + ITEM Assertion OK : Window.LargeScroll(Up): ScrollRow is: 1 + ITEM Assertion OK : Window.LargeScroll(ToRight): ScrollColumn is: 58 (Test may only apply to maximized Window) + ITEM Assertion OK : Window.LargeScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Window.SmallScroll(ToRight): ScrollColumn is: 4 (Test may only apply to maximized Window) + ITEM Assertion OK : Window.SmallScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Window.DisplayWorkBookTabs is: False + ITEM Assertion OK : Window.DisplayWorkBookTabs is: True + ITEM Assertion OK : Window.DisplayVerticalScrollBar is: True + ITEM Assertion OK : Window.DisplayVerticalScrollBar is: False + ITEM Assertion OK : Window.DisplayHorizontalScrollBar is: False + ITEM Assertion OK : Window.DisplayHorizontalScrollBar is: True + ITEM Assertion OK : Window.DisplayHeadings is: False + ITEM Assertion OK : Window.DisplayHeadings is: True + ITEM Assertion OK : Window.DisplayOutline is: False + ITEM Assertion OK : Window.DisplayOutline is: True + ITEM Assertion OK : Window.Visible is: False + ITEM Assertion OK : Window.Visible is: True + ITEM Assertion OK : Window.Caption is: MyCaption + ITEM Assertion OK : Pane.ScrollColumn is: 100 + ITEM Assertion OK : Pane.ScrollColumn is: 1 + ITEM Assertion OK : Pane.ScrollRow is: 100 + ITEM Assertion OK : Pane.ScrollRow is: 1 + ITEM Assertion OK : Pane.LargeScroll(Down): ScrollRow is: 94 (Test may only apply to maximized Window) + ITEM Assertion OK : Pane.LargeScroll(Up): ScrollRow is: 1 + ITEM Assertion OK : Pane.LargeScroll(ToRight): ScrollColumn is: 58 (Test may only apply to maximized Window) + ITEM Assertion OK : Pane.LargeScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Pane.SmallScroll(ToRight): ScrollColumn is: 4 (Test may only apply to maximized Window) + ITEM Assertion OK : Pane.SmallScroll(ToLeft): ScrollColumn is: 1 + ITEM Assertion OK : Window Selection: $A$2:$D$5 + ITEM Assertion OK : ActiveSheet name of Window: Sheet1 + ITEM Assertion OK : Window ActiveCell: $A$1 +END 'Window-Issue' Symbol + TEST OK : Window-Issue +Test run finished : 05/29/2008 02:55:01 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/bytearraystring.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/bytearraystring.log new file mode 100644 index 000000000000..bd243283d8f1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/bytearraystring.log @@ -0,0 +1,8 @@ +Test run started : 05/29/2008 02:25:58 PM +BEGIN Bytearray To String + TEST START : Test the conversion between bytearray and string + ITEM Assertion OK : The number of byte is:6 + ITEM Assertion OK : the return string is: abc + TEST OK : Test the conversion between bytearray and string +END Bytearray To String +Test run finished : 05/29/2008 02:25:58 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/dateserial.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/dateserial.log new file mode 100644 index 000000000000..4dd5f53160f2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/dateserial.log @@ -0,0 +1,9 @@ +Test run started : 01/24/2008 01:24:50 PM +BEGIN DateSerial + TEST START : Test DateSerial function + ITEM Assertion OK : the return date is: 06/15/1999 + ITEM Assertion OK : the return date is: 06/15/1999 + ITEM Assertion OK : the return date is: 06/15/1999 + TEST OK : Test DateSerial function +END DateSerial +Test run finished : 01/24/2008 01:24:50 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/datevalue.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/datevalue.log new file mode 100644 index 000000000000..830d5e7b6c3e --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/datevalue.log @@ -0,0 +1,8 @@ +Test run started : 01/24/2008 01:24:41 PM +BEGIN DateValue + TEST START : Test DateValue function + ITEM Assertion OK : the return date is: 02/12/1969 + ITEM Assertion OK : the return date is: 01/21/2008 + TEST OK : Test DateValue function +END DateValue +Test run finished : 01/24/2008 01:24:41 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/format.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/format.log new file mode 100644 index 000000000000..96725bf7daa8 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/format.log @@ -0,0 +1,36 @@ +Test run started : 2008/09/18 11:35:34 +BEGIN Format + TEST START : Test Predefined_Number_Format_Sample function + ITEM Assertion OK : General Number: 562486.2356 + ITEM Assertion OK : Fixed: 0.20 + ITEM Assertion OK : Standard: 562,486.24 + ITEM Assertion OK : Percent: 75.21% + ITEM Assertion OK : Scientific: 5.62E+05 + ITEM Assertion OK : Scientific: -3.46E+03 + ITEM Assertion OK : Yes/No: No + ITEM Assertion OK : Yes/No: Yes + ITEM Assertion OK : True/False: False + ITEM Assertion OK : True/False: True + ITEM Assertion OK : On/Off: Off + ITEM Assertion OK : On/Off: On + TEST OK : Test Predefined_Number_Format_Sample function + TEST START : Test Custom_Number_Format_Sample function + ITEM Assertion OK : 00.0000: 23.6750 + ITEM Assertion OK : 00.00: 23.68 + ITEM Assertion OK : 00000: 02658 + ITEM Assertion OK : 00.00: 2658.00 + ITEM Assertion OK : ##.####: 23.675 + ITEM Assertion OK : ##.##: 23.68 + ITEM Assertion OK : #,###.##: 12,345.25 + ITEM Assertion OK : ##.00%: 25.00% + ITEM Assertion OK : #,###: 1,000,000 + ITEM Assertion OK : ######E-###: 109838E-5 + ITEM Assertion OK : $#,###.##: $2,345.25 + ITEM Assertion OK : ##.###\%: .25% + TEST OK : Test Custom_Number_Format_Sample function + TEST START : Test Custom_Text_Format_Sample function + ITEM Assertion OK : <: vba + ITEM Assertion OK : >: VBA + TEST OK : Test Custom_Text_Format_Sample function +END Format +Test run finished : 2008/09/18 11:35:34 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/pagesetup.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/pagesetup.log new file mode 100644 index 000000000000..f04585c3f9e1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/pagesetup.log @@ -0,0 +1,77 @@ +Test run started : 07/21/2008 02:00:06 PM +BEGIN PageSetup + TEST START : Sheet_PrintArea + ITEM Assertion OK : PrintArea has changed as expected + TEST OK : Sheet_PrintArea + TEST START : Test margins (no headers) + ITEM Assertion OK : PageSetup.LeftMargin set/get + ITEM Assertion OK : PageSetup.RightMargin set/get + ITEM Assertion OK : PageSetup.TopMargin set/get + ITEM Assertion OK : PageSetup.BottomMargin set/get +Verify that page margins on sheet 1 are all 0.5inch + TEST OK : Test margins (no headers) + TEST START : Test margins (headers) + ITEM Assertion OK : PageSetup.HeaderMargin set/get + ITEM Assertion OK : PageSetup.FooterMargin set/get + ITEM Assertion OK : PageSetup.LeftMargin set/get + ITEM Assertion OK : PageSetup.LeftMargin set/get +Verify that top/bottom/header/footer page margins on sheet 2 are all 0.5inch + TEST OK : Test margins (headers) + TEST START : Test header/footer text + ITEM Assertion OK : PageSetup.LeftHeader set + ITEM Assertion OK : PageSetup.LeftHeader set/get + ITEM Assertion OK : PageSetup.CenterHeader set + ITEM Assertion OK : PageSetup.CenterHeader set/get + ITEM Assertion OK : PageSetup.RightHeader set + ITEM Assertion OK : PageSetup.RightHeader set/get + ITEM Assertion OK : PageSetup.LeftFooter set + ITEM Assertion OK : PageSetup.LeftFooter set/get + ITEM Assertion OK : PageSetup.CenterFooter set + ITEM Assertion OK : PageSetup.CenterFooter set/get + ITEM Assertion OK : PageSetup.RightFooter set + ITEM Assertion OK : PageSetup.RightFooter set/get +Verify that headers on sheet 2 are Ready,to,go +Verify that footers on sheet 2 are This,now,Works + TEST OK : Test header/footer text + TEST START : Test zoom + ITEM Assertion OK : PageSetup.Zoom set + ITEM Assertion OK : PageSetup.Zoom set/get +Verify that sheet 1 zoom is 10% + TEST OK : Test zoom + TEST START : Test orientation + ITEM Assertion OK : PageSetup.Zoom set + ITEM Assertion OK : PageSetup.Orientation set/get +Verify that sheet 1 orientation is now landscape + TEST OK : Test orientation + TEST START : Test order + ITEM Assertion OK : PageSetup.Order get + ITEM Assertion OK : PageSetup.Order set/get +Verify that order on sheet 1 is now over, then down. + TEST OK : Test order + TEST START : Test first page number + ITEM Assertion OK : PageSetup.FirstPageNumber get + ITEM Assertion OK : PageSetup.FirstPageNumber set/get +Verify that first page number on sheet 1 is now 2. + TEST OK : Test first page number + TEST START : Test center vertically + ITEM Assertion OK : PageSetup.CenterVertically get + ITEM Assertion OK : PageSetup.CenterVertically set/get +Verify that CenterVertically on sheet 1 is now true. + TEST OK : Test center vertically + TEST START : Test center horizontally + ITEM Assertion OK : PageSetup.CenterHorizontally get + ITEM Assertion OK : PageSetup.CenterHorizontally set/get +Verify that CenterHorizontally on sheet 1 is now true. + TEST OK : Test center horizontally + TEST START : Test FitToPagesTall + ITEM Assertion OK : PageSetup.FitToPagesTall set/get + TEST OK : Test FitToPagesTall + TEST START : Test FitToPagesWide + ITEM Assertion OK : PageSetup.FitToPagesWide set/get + TEST OK : Test FitToPagesWide + TEST START : Test PrintHeadings + ITEM Assertion OK : PageSetup.PrintHeadings set/get + ITEM Assertion OK : PageSetup.PrintHeadings set/get + TEST OK : Test PrintHeadings +END PageSetup +Test run finished : 07/21/2008 02:00:07 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/partition.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/partition.log new file mode 100644 index 000000000000..7b4f2a01bead --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/partition.log @@ -0,0 +1,11 @@ +Test run started : 12/10/2007 11:26:43 AM +BEGIN Partition + TEST START : Test Partition function + ITEM Assertion OK : the number 20 occurs in the range:20:24 + ITEM Assertion OK : the number 20 occurs in the range: 20: 20 + ITEM Assertion OK : the number 120 occurs in the range:100: + ITEM Assertion OK : the number -5 occurs in the range: : -1 + ITEM Assertion OK : the number 2 occurs in the range: 2: 3 + TEST OK : Test Partition function +END Partition +Test run finished : 12/10/2007 11:26:43 AM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/range-4.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/range-4.log new file mode 100644 index 000000000000..fb37b6ff201b --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/range-4.log @@ -0,0 +1,16 @@ +Test run started : 2008/06/19 17:14:57 +---------------------------------------------------------------- +ShowDetail-Issue + TEST START : ShowDetail-Issue + ITEM Assertion OK : Range.ShowDetail is True + ITEM Assertion OK : Range.ShowDetail is False +END 'ShowDetail-Issue' Symbol + TEST OK : ShowDetail-Issue +---------------------------------------------------------------- +RangeMerged-Issue + TEST START : RangeMerged-Issue + ITEM Assertion OK : Range.RangeMerged is $F$2:$H$5 + ITEM Assertion OK : The first address of Range.RangeMerged is $F$2 +END 'RangeMerged-Issue' Symbol + TEST OK : RangeMerged-Issue +Test run finished : 2008/06/19 17:14:57 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/replace.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/replace.log new file mode 100644 index 000000000000..8f600faaa6b1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/replace.log @@ -0,0 +1,14 @@ +Test run started : 09/05/2008 10:21:46 AM +BEGIN Replace + TEST START : Test Replace function + ITEM Assertion OK : common string:aefefdBc + ITEM Assertion OK : expression string:aefefdef + ITEM Assertion OK : binanary compare:aefefdBc + ITEM Assertion OK : text compare:aefefdef + ITEM Assertion OK : text compare:aefefdef + ITEM Assertion OK : start = 3:cefdBc + ITEM Assertion OK : count = 2: aefefdBc + ITEM Assertion OK : start = 1, count = 0, not support in Unix: abcbcdBc + TEST OK : Test Replace function +END Replace +Test run finished : 09/05/2008 10:21:47 AM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/stringplusdouble.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/stringplusdouble.log new file mode 100644 index 000000000000..6e8b8d994bd1 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/stringplusdouble.log @@ -0,0 +1,62 @@ +Test run started : 05/29/2008 02:51:22 PM +BEGIN String Plus Double + TEST START : double = string + double +The next compute raises error: s = null, d = null, r = s + d + ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = null, r = s & d .The result is: 0 +The next compute raises error: s = null, d = 20, r = s + d + ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20 + ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10 + ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 100 + ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 30 + ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020 +The next compute raises error: s = 'abc', d = null, r = s + d + ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = null, r = s & d + ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s + d + ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s & d + ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: -1 + TEST OK : double = string + double + TEST START : string = string + double +The next compute raises error: s = null, d = null, r = s + d + ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = null, r = s & d .The result is: 0 +The next compute raises error: s = null, d = 20, r = s + d + ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: -1 + ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20 + ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10 + ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 100 + ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 30 + ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020 +The next compute raises error: s = 'abc', d = null, r = s + d + ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1 + ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: abc0 +The next compute raises error: s = 'abc', d = 20, r = s + d + ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1 + ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: abc20 + TEST OK : string = string + double + TEST START : double = string + string +The next compute raises error: s = null, d = null, r = s + d + ITEM Assertion OK : s = null, d = null, r = s + d .The result is: -1 +The next compute raises error: s = null, d = null, r = s & d + ITEM Assertion OK : s = null, d = null, r = s & d .The result is: -1 + ITEM Assertion OK : s = null, d = 20, r = s + d .The result is: 20 + ITEM Assertion OK : s = null, d = 20, r = s & d .The result is: 20 + ITEM Assertion OK : s = '10', d = null, r = s + d .The result is: 10 + ITEM Assertion OK : s = '10', d = null, r = s & d .The result is: 10 + ITEM Assertion OK : s = '10', d = 20, r = s + d .The result is: 1020 + ITEM Assertion OK : s = '10', d = 20, r = s & d .The result is: 1020 +The next compute raises error: s = 'abc', d = null, r = s + d + ITEM Assertion OK : s = 'abc', d = null, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = null, r = s & d + ITEM Assertion OK : s = 'abc', d = null, r = s & d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s + d + ITEM Assertion OK : s = 'abc', d = 20, r = s + d .The result is: -1 +The next compute raises error: s = 'abc', d = 20, r = s & d + ITEM Assertion OK : s = 'abc', d = 20, r = s & d .The result is: -1 + TEST OK : double = string + string +END String Plus Double +Test run finished : 05/29/2008 02:51:22 PM diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/unix/window2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/window2.log new file mode 100644 index 000000000000..8e26d0580621 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/unix/window2.log @@ -0,0 +1,41 @@ +Test run started : 2008/09/22 11:18:57 +BEGIN Window2 + TEST START : Test Window.SplitRow + ITEM Assertion OK : Test SplitColumn: 2 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitRow: 2 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitVertical: 242.465788476212 + ITEM Assertion OK : Test SplitHorizontal: 242.465788476212 + ITEM Assertion OK : Test SplitRow: 4 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitColumn: 3 (Test only applies to maximized Window and at least has 800*600 solotion) + ITEM Assertion OK : Test SplitColumn: 0 + ITEM Assertion OK : Test SplitRow: 0 + TEST OK : Test Window.SplitRow + TEST START : Test Window.DisplayGridlines + ITEM Assertion OK : Test gridlines are on + ITEM Assertion OK : Test gridlines are off + TEST OK : Test Window.DisplayGridlines + TEST START : Test Window.DisplayHeadings + ITEM Assertion OK : Test Headings are on + ITEM Assertion OK : Test Headings are off + TEST OK : Test Window.DisplayHeadings + TEST START : Test Window.Visibility + ITEM Assertion OK : Window is visible + ITEM Assertion OK : Window is not visible + TEST OK : Test Window.Visibility + TEST START : Test Window.FreezePanes + ITEM Assertion OK : Test no panes frozen + ITEM Assertion OK : Test panes frozen at center + ITEM Assertion OK : Test panes frozen at split + TEST OK : Test Window.FreezePanes + TEST START : Test Window.View + TEST OK : Test Window.View + TEST START : Test Window.Zoom + ITEM Assertion OK : Test zoom=100% + ITEM Assertion OK : Test zoom=150% + TEST OK : Test Window.Zoom + TEST START : Test Windows.Count + ITEM Assertion OK : Windows Count: 1 + ITEM Assertion OK : Application.Windows Count: 1 + TEST OK : Test Windows.Count +END Window2 +Test run finished : 2008/09/22 11:18:58 diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/AutoFilter.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/AutoFilter.log new file mode 100644 index 000000000000..b8d0b85a8ff9 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/AutoFilter.log @@ -0,0 +1,20 @@ +Test run started : 16/10/2007 17:42:01
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 'starts with' string criteria
+ ITEM Assertion OK : test2 'not equal to' string criteria
+ ITEM Assertion OK : test3 'ends with' string criteria
+ ITEM Assertion OK : test4 field 'all'
+ ITEM Assertion OK : test5 numeric '<15'
+ ITEM Assertion OK : test6 numeric '>=15'
+ ITEM Assertion OK : test7 numeric '<=12'
+Test Results
+============
+
+Tests passed: 7
+Tests failed: 0
+
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 16/10/2007 17:42:02
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/MiscRangeTests.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/MiscRangeTests.log new file mode 100644 index 000000000000..d190abb5f645 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/MiscRangeTests.log @@ -0,0 +1,45 @@ +Test run started : 17/07/2007 15:08:56
+----------------------------------------------------------------
+MiscRangeTests
+ TEST START : MiscRangeTests
+ ITEM Assertion OK : test 1
+ ITEM Assertion OK : test 2
+ ITEM Assertion OK : test 3
+ ITEM Assertion OK : test 4
+ ITEM Assertion OK : test 5
+ ITEM Assertion OK : test 6
+ ITEM Assertion OK : test 7
+ ITEM Assertion OK : test 8
+ ITEM Assertion OK : test 9
+ ITEM Assertion OK : test 10
+ ITEM Assertion OK : test 11
+ ITEM Assertion OK : test 12
+ ITEM Assertion OK : test 13
+ ITEM Assertion OK : test 14
+ ITEM Assertion OK : test 15
+ ITEM Assertion OK : test 16
+ ITEM Assertion OK : test 17
+ ITEM Assertion OK : test 18
+ ITEM Assertion OK : test 19
+ ITEM Assertion OK : test 20
+ ITEM Assertion OK : test 21
+ ITEM Assertion OK : test 22
+ ITEM Assertion OK : test 23
+ ITEM Assertion OK : test 24
+ ITEM Assertion OK : test 25
+ ITEM Assertion OK : test 26
+ ITEM Assertion OK : test 27
+ ITEM Assertion OK : test 28
+ ITEM Assertion OK : test 29
+ ITEM Assertion OK : test 30
+ ITEM Assertion OK : test 31
+No. tests: 31
+Summary
+=======
+Run: 31
+Passed: 31
+Failed: 0
+
+END 'MiscRangeTests
+ TEST OK : MiscRangeTests
+Test run finished : 17/07/2007 15:08:59
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges-2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges-2.log new file mode 100644 index 000000000000..b80d996e3d3f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges-2.log @@ -0,0 +1,68 @@ +Test run started : 10/07/2007 01:55:47
+----------------------------------------------------------------
+ClearFormtsIssue
+ TEST START : ClearFormtsIssue
+ ITEM Assertion OK : Range.Font.Bold is: True
+ ITEM Assertion OK : Range.Font.Bold is: False
+END 'ClearFormtsIssue' Symbol
+ TEST OK : ClearFormtsIssue
+----------------------------------------------------------------
+VerticalAlignment-Issue
+ TEST START : VerticalAlignment-Issue
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : - Range.VerticalAlignment (get)
+ ITEM Assertion OK : - Range.VerticalAlignment (set)
+ ITEM Assertion OK : Range.VeritcalAlignment is Null
+END 'VerticalAlignment-Issue' Symbol
+ TEST OK : VerticalAlignment-Issue
+----------------------------------------------------------------
+HorizontalAlignment-Issue
+ TEST START : HorizontalAlignment-Issue
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : - Range.HorizontalAlignment (get)
+ ITEM Assertion OK : - Range.HorizontalAlignment (set)
+ ITEM Assertion OK : Range.HorizontalAlignment is Null
+END 'HorizontalAlignment-Issue' Symbol
+ TEST OK : HorizontalAlignment-Issue
+----------------------------------------------------------------
+WrapText-Issue
+ TEST START : WrapText-Issue
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : - Range.WrapText (get)
+ ITEM Assertion OK : Range.WrapText is Null
+END 'WrapText-Issue' Symbol
+ TEST OK : WrapText-Issue
+----------------------------------------------------------------
+FontBorderIssues
+ TEST START : FontBorderIssues
+ ITEM Assertion OK : - = Borders.Color (getColor)
+ ITEM Assertion OK : - = Font.Color (getColor)
+END 'FontBorderIssues' Symbol
+ TEST OK : FontBorderIssues
+----------------------------------------------------------------
+RangeSizeIssues
+ TEST START : RangeSizeIssues
+ ITEM Assertion OK : Range.Left is: 100.5291
+ ITEM Assertion OK : Range.Top is: 95.39775
+ ITEM Assertion OK : Range.Width is: 191.25
+ ITEM Assertion OK : Range.Height is: 271.5
+END 'RangeSizeIssues' Symbol
+ TEST OK : RangeSizeIssues
+----------------------------------------------------------------
+ApplicationIssues
+ TEST START : ApplicationIssues
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range.Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Application.ActiveSheet.Name: Sheet1
+END 'ApplicationIssues' Symbol
+ TEST OK : ApplicationIssues
+Test run finished : 10/07/2007 01:55:48
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges-3.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges-3.log new file mode 100644 index 000000000000..365d126a7e2d --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges-3.log @@ -0,0 +1,8 @@ +Test run started : 10/07/2007 01:55:51
+----------------------------------------------------------------
+MyGoalseek-Issue
+ TEST START : MyGoalseek-Issue
+ ITEM Assertion OK : Variable Range value: 15
+END 'MyGoalseek-Issue' Symbol
+ TEST OK : MyGoalseek-Issue
+Test run finished : 10/07/2007 01:55:51
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges.log new file mode 100644 index 000000000000..fe77d7a9d467 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Ranges.log @@ -0,0 +1,280 @@ +Test run started : 10/07/2007 01:55:56
+----------------------------------------------------------------
+ApplicationMethods
+ TEST START : ApplicationMethods
+ ITEM Assertion OK : Name of Workbook is: Ranges.xls
+ ITEM Assertion OK : Address of Application.Columns is: $A:$A
+ ITEM Assertion OK : Address of Application.Rows is: $1:$1
+ ITEM Assertion OK : Address of Application.Range is: $1:$1,$5:$7
+ ITEM Assertion OK : Please check manually: DefaultFilePath is: C:\Documents and Settings\vituosity\My Documents
+ ITEM Assertion OK : Please check manually: Library Path is: C:\Documents and Settings\vituosity\Application Data\OpenOffice.org2\user\basic
+ ITEM Assertion OK : Please check manually: Template Path is: C:\Documents and Settings\vituosity\Application Data\OpenOffice.org2\user\template
+ ITEM Assertion OK : FileSeparator is \
+ ITEM Assertion OK : Name of ActiveWorkbook is: Ranges.xls
+END 'ApplicationMethods' Symbol
+ TEST OK : ApplicationMethods
+----------------------------------------------------------------
+Insert-Issue
+ TEST START : Insert-Issue
+ ITEM Assertion OK : Insert with xlShiftToRight: 10
+END 'Insert-Issue' Symbol
+ TEST OK : Insert-Issue
+----------------------------------------------------------------
+MergeCells-Issue
+ TEST START : MergeCells-Issue
+ ITEM Assertion OK : Range.MergeCells is True
+ ITEM Assertion FAIL : MergeCells is null: False
+ ITEM Assertion OK : RowCount after Merge: 13
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion FAIL : MergeCells of Second Area is null : False
+ ITEM Assertion FAIL : MergeCells of Ranges is Null: False
+ ITEM Assertion OK : RowCount after Merge: 7
+ ITEM Assertion OK : Range.MergeCells is False
+ ITEM Assertion OK : MergeCells is null: False
+ ITEM Assertion OK : RowCount after Merge: 7
+END 'MergeCells-Issue' Symbol
+ TEST OK : MergeCells-Issue
+----------------------------------------------------------------
+Areas-Issue
+ TEST START : Areas-Issue
+ ITEM Assertion OK : Range Areas Count is2
+ ITEM Assertion OK : First Range Address is: $E$8:$G$13
+ ITEM Assertion OK : First Row is: 8
+ ITEM Assertion OK : First Column is: 5
+ ITEM Assertion OK : EntireRow Address is: $8:$13,$13:$19
+ ITEM Assertion OK : EntireColumn Address is: $E:$G,$G:$K
+ ITEM Assertion OK : Range Count:53
+END 'Areas-Issue' Symbol
+ TEST OK : Areas-Issue
+----------------------------------------------------------------
+Fill-Methods-Issue
+ TEST START : Fill-Methods-Issue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyRightFillValue
+ ITEM Assertion OK : Range Value after FillDown: MyBottomFillValue
+END 'Fill-Methods-Issue' Symbol
+ TEST OK : Fill-Methods-Issue
+----------------------------------------------------------------
+Range/Item-Method-Issue
+ TEST START : Range/Item-Method-Issue
+ ITEM Assertion OK : Range of multiple columns is: $A:$A,$C:$C
+ ITEM Assertion OK : Range of multiple rows is: $1:$1,$5:$7
+ ITEM Assertion OK : Range of several columns is: $C:$E,$D:$D
+ ITEM Assertion OK : Range of several rows is: $5:$8,$6:$10
+ ITEM Assertion OK : Range of several single cells is: $C$5,$E$8
+ ITEM Assertion OK : Range of several named ranges is: $L$1:$M$6,$E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range of a single Item Cell is: $E$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$21
+ ITEM Assertion OK : Range of a single Item Cell is: $F$10
+END 'Range/Item-Method-Issue' Symbol
+ TEST OK : Range/Item-Method-Issue
+----------------------------------------------------------------
+R1C1-Formulas-Issue
+ TEST START : R1C1-Formulas-Issue
+ ITEM Assertion OK : R1C1 Range.Formula is: =IF(OR(R[-2]C[1]=0,RC[2]="YES"),"")
+ ITEM Assertion FAIL : Range.Formula is: =IF(OR(J8=0,RC[2]="YES"),"")
+END 'R1C1-Formulas-Issue' Symbol
+ TEST OK : R1C1-Formulas-Issue
+----------------------------------------------------------------
+Verify_Delete
+ TEST START : Verify_Delete
+ ITEM Assertion OK : Ranges are intersecting: $G$13
+ ITEM Assertion OK : Delete with Default: $AJ$4
+ ITEM Assertion OK : Delete with ShifttoLeft: $AJ$4
+ ITEM Assertion OK : Delete with ShiftUp: $M$22
+END 'Verify_Delete' Symbol
+ TEST OK : Verify_Delete
+----------------------------------------------------------------
+Value-Issue
+ TEST START : Value-Issue
+ ITEM Assertion OK : Value of Range is: 12.3
+ ITEM Assertion OK : Text of Range is: 12.3
+ ITEM Assertion OK : Range has Formula: False
+ ITEM Assertion OK : Cell has Formula: False
+ ITEM Assertion FAIL : Text of Range is null: False
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Cell has Formula: True
+ ITEM Assertion OK : Value of Cell is: 12
+ ITEM Assertion OK : Application.Calculation is : -4135
+ ITEM Assertion OK : Calculation is automated: True
+ ITEM Assertion OK : Range has Formula: True
+ ITEM Assertion OK : Value of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Text of Cell is: 16
+ ITEM Assertion OK : Range has Formula after 'ClearContents: False
+ ITEM Assertion OK : Text of Cell is:
+ ITEM Assertion OK : Text of Cell is:
+END 'Value-Issue' Symbol
+ TEST OK : Value-Issue
+----------------------------------------------------------------
+AutoFit issue
+ TEST START : AutoFit issue
+ ITEM Assertion OK : Columns.AutoFit: CurrentWidth is 467
+ ITEM Assertion FAIL : Rows.AutoFit: CurrentHeight is 78
+END 'AutoFit issue' Symbol
+ TEST OK : AutoFit issue
+----------------------------------------------------------------
+Selections
+ TEST START : Selections
+ ITEM Assertion OK : ActiveCell is : $E$8
+ ITEM Assertion OK : Active Cell is : $E$8
+ ITEM Assertion OK : Number of Cells in Range: 52
+ ITEM Assertion OK : Number of Cells in Range: 52
+ ITEM Assertion OK : Number of Cells in Range: 52
+END 'Selections' Symbol
+ TEST OK : Selections
+----------------------------------------------------------------
+Offset-Resize
+ TEST START : Offset-Resize
+ ITEM Assertion OK : Offset is : $G$10:$I$15,$I$15:$M$21
+ ITEM Assertion OK : Offset is : $G$7:$I$12,$I$12:$M$18
+ ITEM Assertion OK : Resized Range is : $A$20:$D$23
+END 'Offset-Resize' Symbol
+ TEST OK : Offset-Resize
+----------------------------------------------------------------
+Ranges-Address
+ TEST START : Ranges-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13,$G$13:$K$19
+ ITEM Assertion OK : Range Address is: $E8:$G13,$G13:$K19
+ ITEM Assertion OK : Range Address is: E$8:G$13,G$13:K$19
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion FAIL : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: R8C5:R13C7,R13C7:R19C11
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5],R[11]C[5]:R[17]C[9]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13,$G$13:$K$19
+END 'Ranges-Address' Symbol
+ TEST OK : Ranges-Address
+----------------------------------------------------------------
+Range-Address
+ TEST START : Range-Address
+ ITEM Assertion OK : Range Address is: $E$8:$G$13
+ ITEM Assertion OK : Range Address is: $E8:$G13
+ ITEM Assertion OK : Range Address is: E$8:G$13
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion FAIL : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: R8C5:R13C7
+ ITEM Assertion OK : Range Address is: R[6]C[3]:R[11]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$8:$G$13
+END 'Range-Address' Symbol
+ TEST OK : Range-Address
+----------------------------------------------------------------
+Column-Address
+ TEST START : Column-Address
+ ITEM Assertion OK : Range Address is: $F$8:$F$13
+ ITEM Assertion OK : Range Address is: $F8:$F13
+ ITEM Assertion OK : Range Address is: F$8:F$13
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion FAIL : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: R8C6:R13C6
+ ITEM Assertion OK : Range Address is: R[6]C[4]:R[11]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$8:$F$13
+END 'Column-Address' Symbol
+ TEST OK : Column-Address
+----------------------------------------------------------------
+Row-Address
+ TEST START : Row-Address
+ ITEM Assertion OK : Range Address is: $E$9:$G$9
+ ITEM Assertion OK : Range Address is: $E9:$G9
+ ITEM Assertion OK : Range Address is: E$9:G$9
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion FAIL : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: R9C5:R9C7
+ ITEM Assertion OK : Range Address is: R[7]C[3]:R[7]C[5]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$E$9:$G$9
+END 'Row-Address' Symbol
+ TEST OK : Row-Address
+----------------------------------------------------------------
+SingleCell-Address
+ TEST START : SingleCell-Address
+ ITEM Assertion OK : Range Address is: $F$9
+ ITEM Assertion OK : Range Address is: $F9
+ ITEM Assertion OK : Range Address is: F$9
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion FAIL : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: R9C6
+ ITEM Assertion OK : Range Address is: R[7]C[4]
+ ITEM Assertion OK : RangeAddress is [Ranges.xls]Sheet1!$F$9
+END 'SingleCell-Address' Symbol
+ TEST OK : SingleCell-Address
+----------------------------------------------------------------
+Heights and Widths
+ TEST START : Heights and Widths
+ ITEM Assertion OK : Range RowHeight is 40
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 240
+ ITEM Assertion FAIL : Range Width is 675
+ ITEM Assertion OK : Range RowHeight is 50
+ ITEM Assertion OK : Range ColumnWidth is 50
+ ITEM Assertion OK : Range Height is 300
+ ITEM Assertion FAIL : Range Width is 675
+ ITEM Assertion FAIL : RowHeight is null: False
+ ITEM Assertion OK : ColumnWidth is null: True
+END 'Heights and Widths' Symbol
+ TEST OK : Heights and Widths
+----------------------------------------------------------------
+RangeRowColumn-Issue
+ TEST START : RangeRowColumn-Issue
+ ITEM Assertion OK : Row is: 8
+ ITEM Assertion OK : Column is: 5
+ ITEM Assertion OK : EntireRow.Columns.Count = 256
+ ITEM Assertion OK : EntireColumn.Rows.Count = 131072
+END 'RangeRowColumn-Issue' Symbol
+ TEST OK : RangeRowColumn-Issue
+----------------------------------------------------------------
+Replace-Issue
+ TEST START : Replace-Issue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: YourValue
+ ITEM Assertion OK : Value after Replace: ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New ReplaceValue
+ ITEM Assertion OK : Value after Replace: New Replace
+ ITEM Assertion OK : Value after Replace:
+END 'Replace-Issue' Symbol
+ TEST OK : Replace-Issue
+----------------------------------------------------------------
+Hidden-Issue
+ TEST START : Hidden-Issue
+ ITEM Assertion OK : - Range.Rows.Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Hidden (get)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Rows.Item(1).Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Hidden (get)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (set)
+ ITEM Assertion OK : - Range.Columns.Item(1).Hidden (get)
+END 'Hidden-Issue' Symbol
+ TEST OK : Hidden-Issue
+----------------------------------------------------------------
+End issue
+ TEST START : End issue
+ ITEM Assertion OK : - = $E$48
+ ITEM Assertion OK : - = $E$1
+ ITEM Assertion OK : - = $E$3
+ ITEM Assertion OK : - = $A$8
+ ITEM Assertion OK : - = $B$8
+ ITEM Assertion OK : - = $IV$8
+ ITEM Assertion OK : - = $Z$8
+END 'End issue' Symbol
+ TEST OK : End issue
+----------------------------------------------------------------
+Outline issue
+ TEST START : Outline issue
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+END 'Outline issue' Symbol
+ TEST OK : Outline issue
+----------------------------------------------------------------
+Validation
+ TEST START : Validation
+ ITEM Assertion OK : Validation Input Message is : Attention!
+ ITEM Assertion OK : Validation Input Message is : Enter an integer from five to ten
+ ITEM Assertion OK : Validation Error Title is : You must enter a number from five to ten
+ ITEM Assertion OK : Validation Error Message is : An Error occured
+ ITEM Assertion OK : Validation Error Title is : Microsoft Excel
+END 'Validation' Symbol
+ TEST OK : Validation
+Test run finished : 10/07/2007 01:56:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/Shapes.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Shapes.log new file mode 100644 index 000000000000..fe62ab03d3f2 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/Shapes.log @@ -0,0 +1,77 @@ +Test run started : 16/10/2007 17:46:03
+BEGIN Shapes_Collection_Behaviour
+ TEST START : Shapes_Collection_Behaviour
+ ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape1'
+ ITEM Assertion OK : Name of indexed shape should be 'Sheet2Shape2'
+ TEST Success. : Shapes_Collection_Behaviour
+END Shapes_Collection_Behaviour
+BEGIN Shapes_Select_Item
+ TEST START : Shapes_Select_Item
+ ITEM Assertion OK : Correctly selected shape through Range
+ ITEM Assertion OK : Correctly selected shape through Item
+ ITEM Assertion OK : Needs to be visually checked. Is there a line on the document?
+ ITEM Assertion OK : Needs to be visually checked. Are All Shapes Selected?
+ TEST Success. : Shapes_Select_Item
+END Shapes_Select_Item
+BEGIN Shapes_Fill
+ TEST START : Shapes_Fill
+ ITEM Assertion OK : correctly set visibility of shape fill
+ ITEM Assertion OK : correctly set transparency of shape line
+ ITEM Assertion OK : correctly set forecolor of shape fill
+ ITEM Assertion FAIL : correctly set backcolor of shape fill
+ ITEM Assertion OK : the success of the TwoColorGradient method needs to be verified visually!
+ ITEM Assertion OK : correctly set forecolor of shape fill
+ ITEM Assertion FAIL : correctly set forecolor of shape fill
+ TEST Success. : Shapes_Fill
+END Shapes_Fill
+BEGIN Shapes_Line
+ TEST START : Shapes_Line
+ ITEM Assertion FAIL : correctly set weight of shape line
+ ITEM Assertion OK : correctly set visibility of shape line
+ ITEM Assertion OK : correctly set transparency of shape line
+ ITEM Assertion OK : correctly set dash style of shape line
+ ITEM Assertion OK : correctly set dash style of shape line
+ ITEM Assertion OK : correctly set forecolor of shape line
+ ITEM Assertion FAIL : correctly set backcolor of shape line
+ TEST Success. : Shapes_Line
+END Shapes_Line
+BEGIN Shapes_TextFrame
+ TEST START : Shapes_TextFrame
+ ITEM Assertion OK : correctly set Autosize of Shape TextFrame
+ TEST Success. : Shapes_TextFrame
+END Shapes_TextFrame
+BEGIN Shapes_SimpleGeometry
+ TEST START : Shapes_SimpleGeometery
+ ITEM Assertion OK : shape height should be 49.4519655148368 and got 49.4078709034412
+ ITEM Assertion OK : shape width should be 101.467710269751 and got 101.423615658355
+ ITEM Assertion OK : shape left should be 68.5574761223637 and got 68.5417279658754
+ ITEM Assertion OK : shape top should be 44.1511784471699 and got 44.1354302906816
+ ITEM Assertion OK : shape rotation should be 0 and got 0
+ ITEM Assertion OK : shape rotation should be 25 and got 25
+ ITEM Assertion OK : shape incrementrotation should be 50 and got 50
+ ITEM Assertion OK : shape incrementleft should be 69.7480272284707 and got 69.7322790719824
+ ITEM Assertion OK : shape incrementtop should be 93.8141674447769 and got 93.7984192882885
+ TEST Success. : Shapes_SimpleGeometery
+END Shapes_SimpleGeometry
+BEGIN Shapes_Range
+ TEST START : Shapes_Range
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to contain 1 element, it contains 1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(1) to return Sheet2Shape1 got Sheet2Shape1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to contain 1 element, it contains 1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Sheet2Shape3) to return Sheet2Shape3 got Sheet2Shape3
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to contain 2 elements, it contains 2
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array(3, 1) to return concated element/shape names Sheet2Shape3Sheet2Shape1 and got Sheet2Shape3Sheet2Shape1
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to contain 3 elements, it contains 3
+ ITEM Assertion OK : expected Sheets(2).Shapes.Range(Array('Sheet2Shape3', 1, 'Sheet2Shape2')) to return concated element/shape names Sheet2Shape3Sheet2Shape1Sheet2Shape2 and got Sheet2Shape3Sheet2Shape1Sheet2Shape2
+ TEST Success. : Shapes_Range
+END Shapes_Range
+BEGIN Shapes_ShapeRange
+ TEST START : Shapes_ShapeRange
+ ITEM Assertion OK : ShapeRange.IncrementLeft shp1.left should be 89.7322790719824 and got 89.7165297816359
+ ITEM Assertion OK : ShapeRange.IncrementLeft shp2.left should be 240.02518299054 and got 240.009433700193
+ ITEM Assertion OK : ShapeRange.IncrementTop shp1.Top should be 113.798419288289 and got 113.782669997942
+ ITEM Assertion OK : ShapeRange.IncrementTop shp2.Top should be 67.4519655148368 and got 67.4362162244903
+ ITEM Assertion OK : ShapeRange.IncrementRotation shp1.Rotation should be 70 and got 70
+ ITEM Assertion OK : ShapeRange.IncrementRotation shp2.Rotation should be 20 and got 20
+END Shapes_ShapeRange
+Test run finished : 16/10/2007 17:46:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestAddress.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestAddress.log new file mode 100644 index 000000000000..cc51e378f06a --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestAddress.log @@ -0,0 +1,62 @@ +Test run started : 17/07/2007 15:26:54
+----------------------------------------------------------------
+TestAddress
+ TEST START : TestAddress
+ ITEM Assertion OK : test1 Range('e3:f3') A1 style addressing
+ ITEM Assertion OK : test2 Range('e3:f3') R1C1 style addressing
+ ITEM Assertion OK : test3 Range ('e:f') A1 style addressing
+ ITEM Assertion OK : test4 Range ('e:f') R1C1 style addressing
+ ITEM Assertion OK : test5 Columns A1 style addressing
+ ITEM Assertion OK : test6 Columns R1C1 style addressing
+ ITEM Assertion OK : test7 Columns(3) A1 style addressing
+ ITEM Assertion OK : test8 Columns(3) R1C1 style addressing
+ ITEM Assertion OK : test9 Columns('e') A1 style addressing
+ ITEM Assertion OK : test10 Columns('e') R1C1 style addressing
+ ITEM Assertion OK : test11 Columns('b:d') A1 style addressing
+ ITEM Assertion OK : test12 Columns('b:d') R1C1 style addressing
+ ITEM Assertion OK : test13 Range('c1:g10').Columns A1 style addressing
+ ITEM Assertion OK : test14 Range('c1:g10').Columns R1C1 style addressing
+ ITEM Assertion OK : test15 Range('c1:g10').Columns(1) A1 style addressing
+ ITEM Assertion OK : test16 Range('c1:g10').Columns(1) R1C1 style addressing
+ ITEM Assertion OK : test17 Range('c1:g10').Columns('a') A1 style addressing
+ ITEM Assertion OK : test18 Range('c1:g10').Columns('a') R1C1 style addressing
+ ITEM Assertion OK : test19 Range('c1:g10').Columns('c') A1 style addressing
+ ITEM Assertion OK : test20 Range('c1:g10').Columns('c') R1C1 style addressing
+ ITEM Assertion OK : test21 Range('c1:g10').Columns('x:z') A1 style addressing
+ ITEM Assertion OK : test22 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test23 Range('c1:g10').Columns(30) A1 style addressing
+ ITEM Assertion OK : test24 Range('c1:g10').Columns(30) R1C1 style addressing
+ ITEM Assertion OK : test25 Worksheets('Sheet2').Cells(1, 1) A1 style addressing
+ ITEM Assertion OK : test26 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, RowAddressAbsolute is false
+ ITEM Assertion OK : test27 Worksheets('Sheet2').Cells(1, 1) A1 style addressing, ColAddressAbsolute is false
+ ITEM Assertion OK : test28 Worksheets('Sheet2').Cells(1, 1) R1C1 style addressing
+ ITEM Assertion OK : test29 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test30 Worksheets('Sheet2').Range('A1').EntireColumn A1 style addressing
+ ITEM Assertion OK : test31 Worksheets('Sheet2').Range('A1:E5').EntireRow A1 style addressing
+ ITEM Assertion OK : test32 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test33 Worksheets('Sheet2').Range('IV65536').EntireRow A1 style addressing
+ ITEM Assertion OK : test34 Worksheets('Sheet2').Range('IU2:IV65536') A1 style addressing
+ ITEM Assertion OK : test35 Range('c1:g10').Columns('x:z') R1C1 style addressing
+ ITEM Assertion OK : test36 Worksheets('Sheet2').Range('A1') A1 style addressing
+ ITEM Assertion OK : test37 Worksheets('Sheet2').Range('A1:E5').EntireColumn A1 style addressing
+ ITEM Assertion OK : test38 Worksheets('Sheet2').Range('10:12') A1 style addressing
+ ITEM Assertion OK : test39 Worksheets('Sheet2').Range('10:12') R1C1 style addressing
+ ITEM Assertion OK : test40 Range('Sheet3!A1:B4') A1 style addressing
+ ITEM Assertion OK : test41 Range('Sheet3!A1,B1,D4:F20') A1 style addressing
+ ITEM Assertion OK : test42 Range('g20:h40').Columns('c:c')
+ ITEM Assertion OK : test43 Range('g20:h40').Columns('c:f')
+ ITEM Assertion OK : test44 Range('g20:h40').Columns(-1)
+ ITEM Assertion OK : test45 Range('c4:g10').Rows(-1)
+ ITEM Assertion OK : test46 Range('a2:b4').Rows('1:1')
+ ITEM Assertion OK : test47 Range('a2:b4').Rows('1:2')
+ ITEM Assertion OK : test48 Range('a2:b4').Rows('2:2')
+ ITEM Assertion OK : test49 Range('a2:b4').Rows('2:3')
+Test Results
+============
+
+Tests passed: 49
+Tests failed: 0
+
+END 'TestAddress
+ TEST OK : TestAddress
+Test run finished : 17/07/2007 15:26:56
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestCalc_Rangetest.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestCalc_Rangetest.log new file mode 100644 index 000000000000..492c24bc023c --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestCalc_Rangetest.log @@ -0,0 +1,60 @@ +Test run started : 10/07/2007 01:56:07
+BEGIN TestCalc
+ TEST START : RangeTest2
+ ITEM Assertion OK : - Range("D15").Row
+ ITEM Assertion OK : - WorkSheet("D15").Range.Row
+ ITEM Assertion OK : - Range("D15").Column
+ ITEM Assertion OK : - Worksheet.Range("D15").Column
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Valuer
+ ITEM Assertion OK : - Range("D1").EntireRow.Columns.Count
+ ITEM Assertion OK : - Range("D1").EntireColumn.Rows.Count
+ ITEM Assertion OK : - Range("D15").ClearContent
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Rows(1).Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns.Hidden (get)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (set)
+ ITEM Assertion OK : - Range("M1:N2").Columns(1).Hidden (get)
+ ITEM Assertion OK : - Range("B38").Orientation (get)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlDownward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlUpward)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B38").Orientation (set)
+ ITEM Assertion OK : - Range("B38").Orientation (set = xlVertical)
+ ITEM Assertion OK : - Range("B39").WrapText (get)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("B39").WrapText (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (get)
+ ITEM Assertion OK : - Range("F39").MergeCells (get)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion FAIL : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("E39").MergeCells (set)
+ ITEM Assertion OK : - Range("F39").MergeCells (set)
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("C41:C42").Replace MatchCase:=True
+ ITEM Assertion OK : - Range("D41:D42").Replace MatchCase:=False
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (get)
+ ITEM Assertion OK : - Range("B39").VerticalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (get)
+ ITEM Assertion OK : - Range("B39").HorizontalAlignment (set)
+ ITEM FAIL (RangeTest2)
+ TEST Not succesfully completed : RangeTest2
+END TestCalc
+Test run finished : 10/07/2007 01:56:12
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestCalc_Rangetest2.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestCalc_Rangetest2.log new file mode 100644 index 000000000000..2532289bbe41 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/TestCalc_Rangetest2.log @@ -0,0 +1,65 @@ +Test run started : 10/07/2007 01:56:15
+BEGIN TestCalc
+ TEST START : RangeTest3
+ ITEM Assertion FAIL : - setFormulaR1C1
+ ITEM Assertion OK : - getFormulaR1C1
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy(Range("I10"))
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteValues
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormulas
+ ITEM Assertion OK : PasteSpecial Paste:=xlPasteFormats
+ ITEM Assertion OK : PasteSpecial
+ ITEM Assertion OK : PasteSpecial SkipBlanks:=True
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationAdd
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationSubtract
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationMultiply
+ ITEM Assertion OK : PasteSpecial Operation:=xlPasteSpecialOperationDivide
+ ITEM Assertion OK : PasteSpecial Transpose:=True
+ ITEM Assertion FAIL : ActiveWorkbook.FileFormat
+ ITEM Assertion OK : ActiveWorkbook.Name
+ ITEM Assertion OK : ActiveWorkbook.FullName und ActiveWorkbook.Path
+ ITEM Assertion FAIL : - = ActiveWorkbook.Colors(3) set
+ ITEM Assertion OK : - = ActiveWorkbook.ResetColors
+ ITEM Assertion OK : - = ActiveWorkbook.Colors(3) get
+ ITEM Assertion OK : - = Range("K22").End (xlDown)
+ ITEM Assertion OK : - = Range("K22").End (xlUo)
+ ITEM Assertion OK : - = Range("K22").End (xlToLeft)
+ ITEM Assertion OK : - = Range("K22").End (xlRight)
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Next
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - ActiveSpreadsheet.Previous
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="x"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="<>"
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter field:=1, Criteria1:="="
+ ITEM Assertion OK : - Range("J4:J11").AutoFilter
+ ITEM Assertion OK : - ActiveSheet.Resize.Select
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion FAIL : - Application.GoTo Reference:="R[8]C[2]"
+ ITEM Assertion OK : - Application.GoTo Reference:="R8C2"
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Ungroup- please check visually
+ ITEM Assertion OK : - Range.Ungroup - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.Group - please check visually
+ ITEM Assertion OK : - Range.clearOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - Range.AutoOutline - please check visually
+ ITEM Assertion OK : - ActiveSheet.UsedRange.Select
+ ITEM Assertion OK : - Range("A13").AddIndent
+ ITEM Assertion OK : - Range("A13").IndentLevel set
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range("A13").IndentLevel get
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Copy() and Range.PasteSpecial()
+ ITEM Assertion OK : - Range.Calculate
+ ITEM Assertion OK : Worksheet.Calculate
+ ITEM Assertion OK : - Application.Calculate
+ ITEM Assertion OK : Global.Calculate
+ ITEM Assertion OK : Calculation set
+ ITEM FAIL (RangeTest3)
+ TEST Not succesfully completed : RangeTest3
+END TestCalc
+Test run finished : 10/07/2007 01:56:23
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/pagesetup.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/pagesetup.log new file mode 100644 index 000000000000..a1c90473ce07 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/pagesetup.log @@ -0,0 +1,87 @@ +Test run started : 7/21/2008 10:37:24 AM
+BEGIN PageSetup
+ TEST START : Sheet_PrintArea
+ ITEM Assertion OK : PrintArea has changed as expected
+ TEST OK : Sheet_PrintArea
+ TEST START : Test margins (no headers)
+ ITEM Assertion OK : PageSetup.LeftMargin set/get
+ ITEM Assertion OK : PageSetup.RightMargin set/get
+ ITEM Assertion OK : PageSetup.TopMargin set/get
+ ITEM Assertion OK : PageSetup.BottomMargin set/get
+Verify that page margins on sheet 1 are all 0.5inch
+ TEST OK : Test margins (no headers)
+ TEST START : Test margins (headers)
+ ITEM Assertion OK : PageSetup.HeaderMargin set/get
+ ITEM Assertion OK : PageSetup.FooterMargin set/get
+ ITEM Assertion OK : PageSetup.LeftMargin set/get
+ ITEM Assertion OK : PageSetup.LeftMargin set/get
+Verify that top/bottom/header/footer page margins on sheet 2 are all 0.5inch
+ TEST OK : Test margins (headers)
+ TEST START : Test header/footer text
+ ITEM Assertion OK : PageSetup.LeftHeader set
+ ITEM Assertion OK : PageSetup.LeftHeader set/get
+ ITEM Assertion OK : PageSetup.CenterHeader set
+ ITEM Assertion OK : PageSetup.CenterHeader set/get
+ ITEM Assertion OK : PageSetup.RightHeader set
+ ITEM Assertion OK : PageSetup.RightHeader set/get
+ ITEM Assertion OK : PageSetup.LeftFooter set
+ ITEM Assertion OK : PageSetup.LeftFooter set/get
+ ITEM Assertion OK : PageSetup.CenterFooter set
+ ITEM Assertion OK : PageSetup.CenterFooter set/get
+ ITEM Assertion OK : PageSetup.RightFooter set
+ ITEM Assertion OK : PageSetup.RightFooter set/get
+Verify that headers on sheet 2 are Ready,to,go
+Verify that footers on sheet 2 are This,now,Works
+ TEST OK : Test header/footer text
+ TEST START : Test zoom
+ ITEM Assertion OK : PageSetup.Zoom set
+ ITEM Assertion OK : PageSetup.Zoom set/get
+Verify that sheet 1 zoom is 10%
+ TEST OK : Test zoom
+ TEST START : Test orientation
+ ITEM Assertion OK : PageSetup.Zoom set
+ ITEM Assertion OK : PageSetup.Orientation set/get
+Verify that sheet 1 orientation is now landscape
+ TEST OK : Test orientation
+ TEST START : Test paper size
+ ITEM Assertion OK : PageSetup.PaperSize get
+ ITEM Assertion OK : PageSetup.PaperSize set/get
+Verify that paper size on sheet 1 is now Letter
+ TEST OK : Test paper size
+ TEST START : Test order
+ ITEM Assertion OK : PageSetup.Order get
+ ITEM Assertion OK : PageSetup.Order set/get
+Verify that order on sheet 1 is now over, then down.
+ TEST OK : Test order
+ TEST START : Test first page number
+ ITEM Assertion OK : PageSetup.FirstPageNumber get
+ ITEM Assertion OK : PageSetup.FirstPageNumber set/get
+Verify that first page number on sheet 1 is now 2.
+ TEST OK : Test first page number
+ TEST START : Test center vertically
+ ITEM Assertion OK : PageSetup.CenterVertically get
+ ITEM Assertion OK : PageSetup.CenterVertically set/get
+Verify that CenterVertically on sheet 1 is now true.
+ TEST OK : Test center vertically
+ TEST START : Test center horizontally
+ ITEM Assertion OK : PageSetup.CenterHorizontally get
+ ITEM Assertion OK : PageSetup.CenterHorizontally set/get
+Verify that CenterHorizontally on sheet 1 is now true.
+ TEST OK : Test center horizontally
+ TEST START : Test FitToPagesTall
+ ITEM Assertion OK : PageSetup.FitToPagesTall set/get
+ TEST OK : Test FitToPagesTall
+ TEST START : Test FitToPagesWide
+ ITEM Assertion OK : PageSetup.FitToPagesWide set/get
+ TEST OK : Test FitToPagesWide
+ TEST START : Test PrintHeadings
+ ITEM Assertion OK : PageSetup.PrintHeadings set/get
+ ITEM Assertion OK : PageSetup.PrintHeadings set/get
+ TEST OK : Test PrintHeadings
+ TEST START : Test PrintTitleRows
+ ITEM Assertion OK : PageSetup.PrintTitleRows get
+ ITEM Assertion OK : PageSetup.PrintTitleRows set range/get
+ ITEM Assertion OK : PageSetup.PrintTitleRows set false/get
+ TEST OK : Test PrintTitleRows
+END PageSetup
+Test run finished : 7/21/2008 10:37:32 AM
diff --git a/sc/source/ui/vba/testvba/TestDocuments/logs/win/replace.log b/sc/source/ui/vba/testvba/TestDocuments/logs/win/replace.log new file mode 100644 index 000000000000..e96004e4d2a6 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/logs/win/replace.log @@ -0,0 +1,14 @@ +Test run started : 2007-11-21 11:24:04
+BEGIN Replace
+ TEST START : Test Replace function
+ ITEM Assertion OK : common string:aefefdBc
+ ITEM Assertion OK : expression string:aefefdef
+ ITEM Assertion OK : binanary compare:aefefdBc
+ ITEM Assertion OK : text compare:aefefdef
+ ITEM Assertion OK : text compare:aefefdef
+ ITEM Assertion OK : start = 3:cefdBc
+ ITEM Assertion OK : count = 2: aefefdBc
+ ITEM Assertion OK : start = 1, count = 0, not support in Unix: abcbcdBc
+ TEST OK : Test Replace function
+END Replace
+Test run finished : 2007-11-21 11:24:04
diff --git a/sc/source/ui/vba/testvba/TestDocuments/pagesetup.xls b/sc/source/ui/vba/testvba/TestDocuments/pagesetup.xls Binary files differnew file mode 100755 index 000000000000..dfa1b2a8be58 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/pagesetup.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/partition.xls b/sc/source/ui/vba/testvba/TestDocuments/partition.xls Binary files differnew file mode 100644 index 000000000000..5c8d12b1d54f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/partition.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/range-4.xls b/sc/source/ui/vba/testvba/TestDocuments/range-4.xls Binary files differnew file mode 100755 index 000000000000..52452369462f --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/range-4.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/replace.xls b/sc/source/ui/vba/testvba/TestDocuments/replace.xls Binary files differnew file mode 100644 index 000000000000..dcf3c6e8ec06 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/replace.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/stringplusdouble.xls b/sc/source/ui/vba/testvba/TestDocuments/stringplusdouble.xls Binary files differnew file mode 100644 index 000000000000..596be7f6b9bc --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/stringplusdouble.xls diff --git a/sc/source/ui/vba/testvba/TestDocuments/window2.xls b/sc/source/ui/vba/testvba/TestDocuments/window2.xls Binary files differnew file mode 100755 index 000000000000..4d5e1cbfe944 --- /dev/null +++ b/sc/source/ui/vba/testvba/TestDocuments/window2.xls diff --git a/sc/source/ui/vba/testvba/launchTest.pl b/sc/source/ui/vba/testvba/launchTest.pl new file mode 100644 index 000000000000..5b64f7522c09 --- /dev/null +++ b/sc/source/ui/vba/testvba/launchTest.pl @@ -0,0 +1,45 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +use File::Basename; + +my $test_class = shift || die 'must provide a ext name'; +my $TESTDOCUMENT = shift || die 'must provide a path to testdocument dirs'; +my $OUTPUTDIR = shift || die 'must provide an output path to deposit logs in'; + +die "can't access TestClass $test_class/TestVBA.class" unless -f "$test_class/TestVBA.class"; +die "can't access officepath env variable \$OFFICEPATH" unless -d $ENV{OFFICEPATH}; +die "can't access testdocuments" unless -d $TESTDOCUMENT; +die "testdocument not of the correct structure $TESTDOCUMENT/logs/excel" unless -d "$TESTDOCUMENT/logs/excel"; +die "can't access output dir" unless -d $OUTPUTDIR; + + +my $officeclasspath = "$ENV{OFFICEPATH}/program/classes/"; +my $classpath = "$officeclasspath/jurt.jar:$officeclasspath/unoil.jar:$officeclasspath/juh.jar:$officeclasspath/java_uno.jar:$officeclasspath/ridl.jar:$test_class:$ENV{CLASSPATH}"; +$ENV{CLASSPATH}=$classpath; +print "classpath $ENV{CLASSPATH}\n"; +my $status = system("java -classpath $ENV{CLASSPATH} TestVBA $TESTDOCUMENT $OUTPUTDIR" ); diff --git a/sc/source/ui/vba/testvba/makefile.mk b/sc/source/ui/vba/testvba/makefile.mk new file mode 100644 index 000000000000..fb131f314ed3 --- /dev/null +++ b/sc/source/ui/vba/testvba/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/..$/..$/..$/ + +PRJNAME=sc +TARGET=testvba +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +DLLPRE = + +.IF "$(ENABLE_VBA)"!="YES" +dummy: + @echo "not building vba..." +.ENDIF + +INCPRE=$(INCCOM)$/$(TARGET) +CDEFS+=-DVBA_OOBUILD_HACK +# ------------------------------------------------------------------ + +SLOFILES= \ + $(SLO)$/testvba.obj \ + + +# --- Targets ------------------------------------------------------ + +APP1TARGET=testclient +APP1OBJS= $(SLOFILES) + +APP1STDLIBS=\ + $(SALLIB) \ + $(STDLIBCPP) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(COMPHELPERLIB) \ + $(TOOLSLIB) \ + $(UNOTOOLSLIB) \ + +#APP1OBJS= $(OBJ)$/testclient.obj +.INCLUDE : target.mk + + diff --git a/sc/source/ui/vba/testvba/runTests.pl b/sc/source/ui/vba/testvba/runTests.pl new file mode 100755 index 000000000000..70f80329cfeb --- /dev/null +++ b/sc/source/ui/vba/testvba/runTests.pl @@ -0,0 +1,121 @@ +#!/usr/bin/perl -w +use URI::Escape; +use File::Basename; +use Cwd; +use Cwd 'abs_path'; + +$numArgs = $#ARGV + 1; +print "thanks, you gave me $numArgs command-line arguments.\n"; + +foreach $argnum (0 .. $#ARGV) { + print "$ARGV[$argnum]\n"; +} + + +my $binDir = abs_path( dirname($0) ); + +my $sysDir = "unix"; +my $fileSep = "/"; +my $theResult; +my $officepath = shift || die "please specify path to office installation program dir"; +my $DocName = shift || ""; +my $programpath = "$officepath"."3/program:$officepath/program:"; +my $basiclibrarypath = "$officepath/basis3.3/program"; +my $urelibpath = "$officepath/ure/lib"; +my $binext = ""; +my $testDocDir = "$binDir/TestDocuments"; +my $testLogDir = "$binDir/Logs"; +my $testclientname = "testclient"; +my $buildtestclient = "../../../../unxlngi6.pro/bin/$testclientname"; + +# test testclient +if ( -e "$buildtestclient" ) +{ + print "use the latest build\n"; + system( "cp $buildtestclient ." ); +} +elsif ( !( -e "$testclientname" ) ) +{ + print "$testclientname do not exist\n"; + exit; +} + +# test for uname +system("uname"); +$exit_value = $? >> 8; +$signal_num = $? & 127; +$dumped_core = $? & 128; + +$failed = ( $exit_value || $signal_num || $dumped_core ); + +print "$failed = ( $exit_value || $signal_num || $dumped_core )\n"; + +if ( !$failed && open(UNAME, "uname -a|") ) { + $theResult = <UNAME>; + close(UNAME); + if ( $theResult =~ /^CYGWIN/ ) { + # windows under cygwin + $sysDir = "win" ; + $tmpPath=$ENV{"PATH"}; + $ENV{"PATH"} = "$officepath:$tmpPath"; + $testDocDir=`cygpath -m $testDocDir`; + uri_escape($testDocDir); + # hacky windows url construction + $testDocDir="file:///$testDocDir"; + + chomp($testDocDir); + #print "*** doc dir is $testDocDir\n"; + $testLogDir = `cygpath -m "$testLogDir"`; + uri_escape($testLogDir); + $testLogDir="file:///$testLogDir"; + chomp($testLogDir); + #print "*** log dir is $testLogDir\n"; + $binext = ".exe"; + } + else{ + # unix we need to find sal etc. ( from the office path ) + my $tmpPath=$ENV{"PATH"}; + $ENV{"PATH"} = "$programpath:$basiclibrarypath:$urelibpath/../bin:$tmpPath"; + $tmpPATH = $ENV{"LD_LIBRARY_PATH"}; + $ENV{"LD_LIBRARY_PATH"} = "$officepath:$programpath:$basiclibrarypath:$urelibpath:$urelibpath../bin/javaldx:$urelibpath/../bin:$tmpPATH"; + $ENV{"LD_LIBRARY_PATH"} = "$officepath:$programpath:$basiclibrarypath:$urelibpath:$tmpPATH"; + my $testPath = $ENV{"LD_LIBRARY_PATH"}; + print "$testPath\n"; + $testPath = $ENV{"PATH"}; + print "$testPath\n"; + $ENV{"STAR_RESOURCEPATH"} = "$officepath/basis3.0/program/resource"; + $ENV{"SAL_ALLOW_LINKOO_SYMLINKS"} = "1"; + $testPath = $ENV{"LANG"}; + print "$testPath\n"; + } +} +else +{ + # ordinary windows, not sure if this will actually work + $sysDir = "win" ; + $tmpPath=$ENV{"PATH"}; + $ENV{"PATH"} = "$tmpPath;$officepath"; + $binext = ".exe"; +} + +# the exe needs system paths or urls ( urls are by far the least troublesome ) + +my $runCmd = ""; +my $analyseCmd = ""; + +if ( "$DocName" eq "" ) +{ + $runCmd = "$binDir/testclient$binext $testDocDir $testLogDir"; + $analyseCmd = "perl $binDir/testResults.pl $binDir/Logs $binDir/TestDocuments/logs/$sysDir"; +} +else +{ + $runCmd = "$binDir/testclient$binext $testDocDir $testLogDir $testDocDir/$DocName"; + $analyseCmd = "perl $binDir/testResult.pl $binDir/Logs $binDir/TestDocuments/logs/$sysDir $DocName"; +} +print "runCmd = $runCmd\n"; + +system ("rm -rf $testLogDir/*"); +my $status = system( $runCmd ); +print "analyseCmd = $analyseCmd\n"; +$status = system( $analyseCmd ); diff --git a/sc/source/ui/vba/testvba/testResult.pl b/sc/source/ui/vba/testvba/testResult.pl new file mode 100644 index 000000000000..171be2597ddb --- /dev/null +++ b/sc/source/ui/vba/testvba/testResult.pl @@ -0,0 +1,171 @@ +#!/usr/bin/perl -w +use File::Temp qw/ tempfile tempdir /; +use File::Basename; +use File::stat; +use File::Copy; + +my $binDir = dirname($0); +my $timestampclean= "perl $binDir/timestampsClean.pl"; +#sub gen_diff($) + +sub testLog +{ + # 2 No Log to compare against + # 1 Log passed + # 0 Log failed + my $result = 0; + my $testfile = shift; + my $dirtocheck = shift; + my $filename = basename($testfile); + $filename = "$logdir/$filename"; + print "processing $testfile $filename\n"; + if ( -f $filename ) { + my $tmpFile; + $dir = tempdir( CLEANUP => 1 ); + ($fh, $tmpFile) = tempfile( DIR => $dir ); + close($fh); + # + my $status = system("diff -U 0 -p $testfile $filename | $timestampclean > $tmpFile"); + my $info = stat($tmpFile) or die "no $tmpFile: $!"; + if ( ($status >>=8) == 0 && ( $info->size == 0) ) { + #print "diff worked size is 0\n"; + $result = 1; + } + elsif ( ($status >>=8) == 0 && ( $info->size > 0) ) + { + #print "diff worked size > 0\n"; + $result = 0; + } + else + { + #print "diff failed size > 0\n"; + $result = 0; + } + } + else + { + #print "not file > 0\n"; + $result = 2; + } + #print "diff result = $result\n"; + return $result; +} + +if ( ! ( $logdir = shift @ARGV ) ) { + print STDERR "No logdir specified!\n"; + usage(); + exit 1; +} + +if ( ! ( $testlogdir = shift @ARGV ) ) { + print STDERR "No testdocuments dir to compare against specified!\n"; + usage(); + exit 1; +} + +if ( !(-d $logdir ) ) { + print STDERR "No output directory $logdir exists, please create it!!!!\n"; + exit 1; +} +if ( !(-d $testlogdir ) ) { + print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n"; + usage(); + exit 1; +} +print "logdir $logdir\n"; +print "testlogdir $testlogdir\n"; +sub filter_crud($) +{ + my $a = shift; + + $a =~ /~$/ && return; + $a =~ /\#$/ && return; + $a =~ /\.orig$/ && return; + $a =~ /unxlng.*\.pro$/ && return; + $a =~ /wntmsc.*\.pro$/ && return; + $a =~ /.swp$/ && return; + $a =~ /POSITION/ && return; + $a =~ /ReadMe/ && return; + $a =~ /.tmp$/ && return; + $a =~ /\.svn/ && return; + $a eq 'CVS' && return; + $a eq '.' && return; + $a eq '..' && return; + + return $a; +} +sub slurp_dir($); + +sub slurp_dir($) +{ + my $dir = shift; + my ($dirhandle, $fname); + my @files = (); + + opendir ($dirhandle, $dir) || die "Can't open $dir"; + while ($fname = readdir ($dirhandle)) { + $fname = filter_crud($fname); + defined $fname || next; +# if (-d "$dir/$fname") { +# push @files, slurp_dir("$dir/$fname"); +# } else + { + push @files, "$dir/$fname"; + } + } + closedir ($dirhandle); + + return @files; +} + +if (-d $testlogdir) { + push @files, slurp_dir($testlogdir); +} + +my $processed = 0; +my $passed = 0; +my @passedTests=(); +my @skippedTests=(); +my @failedTests=(); + +my $failureCmd=""; +my $testfile = shift @ARGV; +my $testfilepath = "$testlogdir/$testfile"; +$testfilepath =~ s/\.xls/\.log/; +print "$testfilepath\n"; +for $a (@files) { + $filename = $a; + if ( "$testfilepath" eq "$filename" ) + { + $processed++; + my $testcase = $a; + $testcase =~ s/\.log/\.xls/; + my $result = testLog( $a, $logdir ); + if ( $result == 0 ) { + push @failedTests, basename($testcase); + if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; } + } + elsif ( $result == 2 ) { + #print "skipped $a\n"; + push @skippedTests, $testcase; + } + else { + $passed++; + push @passedTests, $testcase; + #print "Test document for $a \t \t passed. \n"; + } + } +} +my $compared=@passedTests+@failedTests; +my $skip = @skippedTests; +print "skipped $skip test-cases(s)\n"; +print "compared $compared test-case documents\n"; +print "\t \t $passed tests $@passedTests\n"; +if ( @failedTests > 0 ) { + print "the following test-case documents failed, please examine the logs manually\n"; + + for $a (@failedTests) { + print "\t$a\n"; + } + print "e.g. $failureCmd\n" +} diff --git a/sc/source/ui/vba/testvba/testResults.pl b/sc/source/ui/vba/testvba/testResults.pl new file mode 100755 index 000000000000..6f731327e76b --- /dev/null +++ b/sc/source/ui/vba/testvba/testResults.pl @@ -0,0 +1,163 @@ +#!/usr/bin/perl -w +use File::Temp qw/ tempfile tempdir /; +use File::Basename; +use File::stat; +use File::Copy; + +my $binDir = dirname($0); +my $timestampclean= "perl $binDir/timestampsClean.pl"; +#sub gen_diff($) + +sub testLog +{ + # 2 No Log to compare against + # 1 Log passed + # 0 Log failed + my $result = 0; + my $testfile = shift; + my $dirtocheck = shift; + my $filename = basename($testfile); + $filename = "$logdir/$filename"; + print "processing $testfile $filename\n"; + if ( -f $filename ) { + my $tmpFile; + $dir = tempdir( CLEANUP => 1 ); + ($fh, $tmpFile) = tempfile( DIR => $dir ); + close($fh); + # + my $status = system("diff -U 0 -p $testfile $filename | $timestampclean > $tmpFile"); + my $info = stat($tmpFile) or die "no $tmpFile: $!"; + if ( ($status >>=8) == 0 && ( $info->size == 0) ) { + #print "diff worked size is 0\n"; + $result = 1; + } + elsif ( ($status >>=8) == 0 && ( $info->size > 0) ) + { + #print "diff worked size > 0\n"; + $result = 0; + } + else + { + #print "diff failed size > 0\n"; + $result = 0; + } + } + else + { + #print "not file > 0\n"; + $result = 2; + } + #print "diff result = $result\n"; + return $result; +} + +if ( ! ( $logdir = shift @ARGV ) ) { + print STDERR "No logdir specified!\n"; + usage(); + exit 1; +} + +if ( ! ( $testlogdir = shift @ARGV ) ) { + print STDERR "No testdocuments dir to compare against specified!\n"; + usage(); + exit 1; +} + +if ( !(-d $logdir ) ) { + print STDERR "No output directory $logdir exists, please create it!!!!\n"; + exit 1; +} +if ( !(-d $testlogdir ) ) { + print STDERR "the directory containing the logfiles to compare against \"$logdir\" does not exist\n"; + usage(); + exit 1; +} +print "logdir $logdir\n"; +print "testlogdir $testlogdir\n"; +sub filter_crud($) +{ + my $a = shift; + + $a =~ /~$/ && return; + $a =~ /\#$/ && return; + $a =~ /\.orig$/ && return; + $a =~ /unxlng.*\.pro$/ && return; + $a =~ /wntmsc.*\.pro$/ && return; + $a =~ /.swp$/ && return; + $a =~ /POSITION/ && return; + $a =~ /ReadMe/ && return; + $a =~ /.tmp$/ && return; + $a =~ /\.svn/ && return; + $a eq 'CVS' && return; + $a eq '.' && return; + $a eq '..' && return; + + return $a; +} +sub slurp_dir($); + +sub slurp_dir($) +{ + my $dir = shift; + my ($dirhandle, $fname); + my @files = (); + + opendir ($dirhandle, $dir) || die "Can't open $dir"; + while ($fname = readdir ($dirhandle)) { + $fname = filter_crud($fname); + defined $fname || next; +# if (-d "$dir/$fname") { +# push @files, slurp_dir("$dir/$fname"); +# } else + { + push @files, "$dir/$fname"; + } + } + closedir ($dirhandle); + + return @files; +} + +if (-d $testlogdir) { + push @files, slurp_dir($testlogdir); +} + +my $processed = 0; +my $passed = 0; +my @passedTests=(); +my @skippedTests=(); +my @failedTests=(); + +my $failureCmd=""; +for $a (@files) { + $processed++; + my $testcase = $a; + $testcase =~ s/\.log/\.xls/; + my $result = testLog( $a, $logdir ); + if ( $result == 0 ) { + push @failedTests, basename($testcase); + if ( $failureCmd eq "" ) { $failureCmd = " diff -up $a $logdir "; } + } + elsif ( $result == 2 ) { + #print "skipped $a\n"; + push @skippedTests, $testcase; + } + else { + $passed++; + push @passedTests, $testcase; + #print "Test document for $a \t \t passed. \n"; + } +} +my $compared=@passedTests+@failedTests; +my $skip = @skippedTests; +print "skipped $skip test-cases(s)\n"; +print "compared $compared test-case documents\n"; +print "\t \t $passed tests $@passedTests\n"; +if ( @failedTests > 0 ) { + print "the following test-case documents failed, please examine the logs manually\n"; + + for $a (@failedTests) { + print "\t$a\n"; + } + print "e.g. $failureCmd\n" +} diff --git a/sc/source/ui/vba/testvba/testclient b/sc/source/ui/vba/testvba/testclient Binary files differnew file mode 100755 index 000000000000..c9cde8c5b052 --- /dev/null +++ b/sc/source/ui/vba/testvba/testclient diff --git a/sc/source/ui/vba/testvba/testvba.cxx b/sc/source/ui/vba/testvba/testvba.cxx new file mode 100644 index 000000000000..f240c523edc6 --- /dev/null +++ b/sc/source/ui/vba/testvba/testvba.cxx @@ -0,0 +1,312 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include "cppuhelper/bootstrap.hxx" + +#include <com/sun/star/beans/Property.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/script/provider/XScriptProviderSupplier.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> + +#include <tools/urlobj.hxx> +#include <osl/file.hxx> + +#include <memory> +#include <iostream> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::sheet; + +using ::com::sun::star::beans::Property; +using ::com::sun::star::beans::PropertyValue; +using ::com::sun::star::beans::XPropertySet; +using ::com::sun::star::beans::XPropertySetInfo; +using ::com::sun::star::container::XNameContainer; +using ::com::sun::star::lang::XComponent; +using ::com::sun::star::lang::XMultiComponentFactory; +using ::com::sun::star::frame::XComponentLoader; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::uno::XComponentContext; +using ::com::sun::star::uno::XInterface; +using ::com::sun::star::ucb::XSimpleFileAccess; +using ::com::sun::star::document::XTypeDetection; +using ::rtl::OUString; + +using ::std::auto_ptr; + +const OUString EXTN = rtl::OUString::createFromAscii(".xls"); + +OUString convertToURL( const OUString& rPath ) +{ + rtl::OUString aURL; + INetURLObject aObj; + aObj.SetURL( rPath ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + if ( bIsURL ) + aURL = rPath; + else + { + osl::FileBase::getFileURLFromSystemPath( rPath, aURL ); + if ( aURL.equals( rPath ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "could'nt convert " ).concat( rPath ).concat( rtl::OUString::createFromAscii( " to a URL, is it a fully qualified path name? " ) ), Reference< uno::XInterface >() ); + } + return aURL; +} + +OUString ascii(const sal_Char* cstr) +{ + return OUString::createFromAscii(cstr); +} + +const sal_Char* getStr(const OUString& ou) +{ + return OUStringToOString(ou, RTL_TEXTENCODING_UTF8).getStr(); +} + + +int usage( const char* pName ) +{ + std::cerr << "usage: " << pName << "<path to testdocument dir> <output_directory>" << std::endl; + return 1; + +} + +class TestVBA +{ +private: + Reference< XComponentContext > mxContext; + Reference< XMultiComponentFactory > mxMCF; + Reference< XComponentLoader > mxCompLoader; + Reference< XSimpleFileAccess > mxSFA; + rtl::OUString msOutDirPath; +protected: +public: + TestVBA( const Reference< XComponentContext >& _xContext, + const Reference< XMultiComponentFactory >& _xMCF, + const Reference< XComponentLoader >& _xCompLoader, + const rtl::OUString& _outDirPath ) : mxContext( _xContext ), mxMCF( _xMCF ), +mxCompLoader( _xCompLoader ), msOutDirPath( convertToURL( _outDirPath ) ) + { + mxSFA.set( mxMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ), mxContext), uno::UNO_QUERY_THROW ); + } + + rtl::OUString getLogLocation() throw ( beans::UnknownPropertyException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::Exception ) + { + rtl::OUString sLogLocation; + Reference< XPropertySet > pathSettings( mxMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.comp.framework.PathSettings" ), mxContext), uno::UNO_QUERY_THROW ); + pathSettings->getPropertyValue( rtl::OUString::createFromAscii( "Work" ) ) >>= sLogLocation; + sLogLocation = sLogLocation.concat( rtl::OUString::createFromAscii( "/" ) ).concat( rtl::OUString::createFromAscii( "HelperAPI-test.log" ) ); + return sLogLocation; + } + rtl::OUString getLogLocationWithName( OUString fileName ) throw ( beans::UnknownPropertyException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::Exception ) + { + printf("%s\n", getenv("HOME") ); + printf("file name %s\n", rtl::OUStringToOString( fileName, RTL_TEXTENCODING_UTF8 ).getStr() ); + //rtl::OUString sLogLocation( rtl::OUString::createFromAscii( getenv("HOME") ) ); + rtl::OUString sLogLocation; + Reference< XPropertySet > pathSettings( mxMCF->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.comp.framework.PathSettings" ), mxContext), uno::UNO_QUERY_THROW ); + pathSettings->getPropertyValue( rtl::OUString::createFromAscii( "Work" ) ) >>= sLogLocation; + sLogLocation = sLogLocation.concat( rtl::OUString::createFromAscii( "/" ) ).concat( fileName.copy ( 0, fileName.lastIndexOf( EXTN ) ) + rtl::OUString::createFromAscii( ".log" ) ); + return sLogLocation; + } + + void init() + { + // blow away previous logs? + } + + void proccessDocument( const rtl::OUString& sUrl ) + { + if ( !mxSFA->isFolder( sUrl ) && sUrl.endsWithIgnoreAsciiCaseAsciiL( ".xls", 4 ) ) + + { + try + { + OSL_TRACE( "processing %s", rtl::OUStringToOString( sUrl, RTL_TEXTENCODING_UTF8 ).getStr() ); + printf( "processing %s\n", rtl::OUStringToOString( sUrl, RTL_TEXTENCODING_UTF8 ).getStr() ); + // Loading the wanted document + Sequence< PropertyValue > propertyValues(1); + propertyValues[0].Name = rtl::OUString::createFromAscii( "Hidden" ); + propertyValues[0].Value <<= sal_False; + + rtl::OUString sfileUrl = convertToURL( sUrl ); + printf( "try to get xDoc %s\n", rtl::OUStringToOString( sfileUrl, RTL_TEXTENCODING_UTF8 ).getStr() ); + Reference< uno::XInterface > xDoc = + mxCompLoader->loadComponentFromURL( sfileUrl, rtl::OUString::createFromAscii( "_blank" ), 0, propertyValues); + printf( "got xDoc\n" ); + + OUString logFileURL = convertToURL( getLogLocation() ); + try + { + Reference< script::provider::XScriptProviderSupplier > xSupplier( xDoc, uno::UNO_QUERY_THROW ) ; + if ( mxSFA->exists( logFileURL ) ) + mxSFA->kill( logFileURL ); + + printf("try to get the ScriptProvider\n"); + Reference< script::provider::XScriptProvider > xProv = xSupplier->getScriptProvider(); + printf("get the ScriptProvider\n"); + printf("try to get the Script\n"); + Reference< script::provider::XScript > xScript; + try + { + xScript = xProv->getScript( rtl::OUString::createFromAscii( "vnd.sun.star.script:VBAProject.TestMacros.Main?language=Basic&location=document" )); + } catch ( uno::Exception& e ) + { + try + { + xScript = xProv->getScript( rtl::OUString::createFromAscii( "vnd.sun.star.script:VBAProject.testMacro.Main?language=Basic&location=document" )); + } catch ( uno::Exception& e2 ) + { + xScript = xProv->getScript( rtl::OUString::createFromAscii( "vnd.sun.star.script:VBAProject.testMain.Main?language=Basic&location=document" )); + } + } + OSL_TRACE("Got script for doc %s", rtl::OUStringToOString( sUrl, RTL_TEXTENCODING_UTF8 ).getStr() ); + printf("get the Script\n"); + Sequence< uno::Any > aArgs; + Sequence< sal_Int16 > aOutArgsIndex; + Sequence< uno::Any > aOutArgs; + + xScript->invoke(aArgs, aOutArgsIndex, aOutArgs); + + OUString fileName = sUrl.copy ( sUrl.lastIndexOf( '/' ) ); + OUString newLocation = msOutDirPath + fileName.copy ( 0, fileName.lastIndexOf( EXTN ) ) + rtl::OUString::createFromAscii( ".log" ); + try + { + printf("move log file\n"); + mxSFA->move( logFileURL, newLocation ); + OSL_TRACE("new logfile location is %s ", rtl::OUStringToOString( newLocation, RTL_TEXTENCODING_UTF8 ).getStr() ); + printf("moved to new location\n"); + } + catch ( uno::Exception& e ) + { + logFileURL = convertToURL( getLogLocationWithName( fileName ) ); + printf("move log file from %s\n", rtl::OUStringToOString( logFileURL, RTL_TEXTENCODING_UTF8 ).getStr() ); + mxSFA->move( logFileURL, newLocation ); + OSL_TRACE("new logfile location is %s ", rtl::OUStringToOString( newLocation, RTL_TEXTENCODING_UTF8 ).getStr() ); + printf("moved to new location\n"); + } + + } + catch ( uno::Exception& e ) + { + std::cerr << "Caught exception " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl; + } + + // interface is supported, otherwise use XComponent.dispose + Reference< util::XCloseable > xCloseable ( xDoc, uno::UNO_QUERY ); + + if ( xCloseable.is() ) + { + printf("try to close\n"); + // will close application. and only run a test case for 3.0 + // maybe it is a bug. yes, it is a bug + // if only one frame and model, click a button which related will colse. + // will make a crash. It related with window listener. + // so, for run all test cases, it should not close the document at this moment. + xCloseable->close(sal_False); + printf("closed\n"); + } + else + { + printf("try to dispose\n"); + Reference< XComponent > xComp( xDoc, uno::UNO_QUERY_THROW ); + // same as close. + xComp->dispose(); + printf("disposed\n"); + } + } + catch( uno::Exception& e ) + { + std::cerr << "Caught exception " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl; + } + + } + printf("complete processing %s\n", rtl::OUStringToOString( sUrl, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + + void traverse( const rtl::OUString& sFileDirectory ) + { + rtl::OUString sFileDirectoryURL = convertToURL( sFileDirectory ); + if ( !mxSFA->isFolder( sFileDirectoryURL) ) + { + throw lang::IllegalArgumentException( rtl::OUString::createFromAscii( "not a directory: ").concat( sFileDirectoryURL ), Reference<uno::XInterface>(), 1 ); + } + // Getting all files and directories in the current directory + Sequence<OUString> entries = mxSFA->getFolderContents( sFileDirectoryURL, sal_False ); + + // Iterating for each file and directory + printf( "Entries %d\n", (int)entries.getLength() ); + for ( sal_Int32 i = 0; i < entries.getLength(); ++i ) + { + proccessDocument( entries[ i ] ); + } + } +}; + +void tryDispose( Reference< uno::XInterface > xIF, const char* sComp ) +{ + Reference< lang::XComponent > xComponent( xIF, uno::UNO_QUERY ); + if ( xComponent.is() ) + { + try + { + xComponent->dispose(); + } + catch( uno::Exception& e ) + { + std::cerr << "tryDispose caught exception " <<rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << " while disposing " << sComp << std::endl; + } + } +} +int main( int argv, char** argc ) +{ + if ( !( argv > 2 ) ) + return usage( argc[0] ); + try + { + + OSL_TRACE("Attempting to bootstrap normal"); + Reference<XComponentContext> xCC = ::cppu::bootstrap(); + Reference<XMultiComponentFactory> xFactory = xCC->getServiceManager(); + OSL_TRACE("got servicemanager"); + std::cout << "got servicemanager" << std::endl; + Reference<XInterface> desktop = xFactory->createInstanceWithContext( + ascii("com.sun.star.frame.Desktop"), xCC); + OSL_TRACE("got desktop"); + std::cout << "got desktop" << std::endl; + Reference<frame::XComponentLoader> xLoader(desktop, UNO_QUERY_THROW); + TestVBA* dTest = new TestVBA( xCC, xFactory, xLoader, ascii( argc[ 2 ] ) ); + if ( argv == 4 ) + { + std::cout << "before process" << std::endl; + dTest->proccessDocument( ascii( argc[ 3 ] ) ); + std::cout << "after process" << std::endl; + } + else + { + dTest->traverse( ascii( argc[ 1 ] ) ); + } + delete dTest; +// tryDispose( xLoader, "desktop" ); +// tryDispose( xCC, "remote context" ); + + } + catch( uno::Exception& e ) + { + std::cerr << "Caught Exception " << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() << std::endl; + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/testvba/timestampsClean.pl b/sc/source/ui/vba/testvba/timestampsClean.pl new file mode 100755 index 000000000000..2c947d0cc6d5 --- /dev/null +++ b/sc/source/ui/vba/testvba/timestampsClean.pl @@ -0,0 +1,73 @@ +#!/usr/bin/perl -w + +my @output_buffer = (); +my $fname; +my $detectedSomeGuff = 0; +sub pure_guff($) +{ + my $array = shift; + my @lines = @{$array}; + my $contains_sense = ''; + my $contains_guff = ''; + while (scalar @lines) + { + my $line = pop @lines; + if ($line =~ m/Test run started :/ || + $line =~ m/ITEM Assertion OK/ || + $line =~ m/Test run finished :/) { + $contains_guff = '1'; + } elsif ($line =~ m/^[\+\-][^\-\+]/) { + $contains_sense = '1'; + } + } + if ($contains_guff && $contains_sense) { + print STDERR "Patch fragment with mixed good/bad changes in '$ARGV' near $line_index\n"; + $contains_guff = ''; + } + elsif ( $contains_guff ) { + $detectedSomeGuff++; + } +# print "contains guff: $contains_guff\n"; + return $contains_guff; +} + +sub output_lines($) +{ + my $array = shift; + my @lines = @{$array}; + + if (pure_guff (\@lines)) { + return; + } + + while (scalar @lines) + { + my $line = pop @lines; + push @output_buffer, $line; + } +} + +my $header; +my @lines; +my $frag_count = 0; +$line_index = 0; + +while (<>) { + if (/^\@\@/ || /^[^ \-\+]/) { + output_lines (\@lines); + @lines = (); + $frag_count++; + } + unshift @lines, $_; + $line_index++; + close ARGV if eof; +} +output_lines(\@lines); + +# $detectedSomeGuff contains the skipped hunks that contain acceptable diff +# e.g. a timestamp or an OK assertion that contains different content +# like perhaps a path +#print "frag_count = $frag_count fragstocount = $fragstocount detectedSomeGuff = $detectedSomeGuff \n"; +if ($frag_count > $detectedSomeGuff) { + print @output_buffer; +} diff --git a/sc/source/ui/vba/vbaapplication.cxx b/sc/source/ui/vba/vbaapplication.cxx new file mode 100644 index 000000000000..8c9581a66d23 --- /dev/null +++ b/sc/source/ui/vba/vbaapplication.cxx @@ -0,0 +1,1813 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <stdio.h> + +#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> +#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <ooo/vba/excel/XlCalculation.hpp> +#include <ooo/vba/excel/XlCutCopyMode.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#include <com/sun/star/sheet/XCalculatable.hpp> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <com/sun/star/task/XStatusIndicatorSupplier.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <ooo/vba/excel/XlMousePointer.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> +#include <com/sun/star/ui/dialogs/XFilePicker.hpp> +#include <com/sun/star/ui/dialogs/XFilePicker2.hpp> +#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> +#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> +//2009-11-06 add by limingl +#include <com/sun/star/ui/dialogs/XFilterManager.hpp> +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +//end +#include<ooo/vba/XCommandBars.hpp> +#include <ooo/vba/excel/XlEnableCancelKey.hpp> //liuchen 2009-11-26 +#include <ooo/vba/excel/XlApplicationInternational.hpp> //liuchen 2009-11-26 +#include <unotools/localedatawrapper.hxx> //liuchen 2009-11-26 + +#include "vbaapplication.hxx" +#include "vbaworkbooks.hxx" +#include "vbaworkbook.hxx" +#include "vbaworksheets.hxx" +#include "vbarange.hxx" +#include "vbawsfunction.hxx" +#include "vbadialogs.hxx" +#include "vbawindow.hxx" +#include "vbawindows.hxx" +#include "vbaglobals.hxx" +#include "vbamenubars.hxx" +#include "tabvwsh.hxx" +#include "gridwin.hxx" +#include "vbanames.hxx" +#include <vbahelper/vbashape.hxx> +#include "vbatextboxshape.hxx" +#include "vbaassistant.hxx" +#include "vbafilesearch.hxx" //liuchen 2009-8-18, add the support of VBA Application.FileSearch +#include "sc.hrc" +#include "macromgr.hxx" +#include "global.hxx" //liuchen 2009-11-26 +#include "scmod.hxx" //liuchen 2009-11-26 +#include "docoptio.hxx" //liuchen 2009-11-26 +#include "appoptio.hxx" + +#include <osl/file.hxx> + +#include <map> + +#include <sfx2/request.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/app.hxx> + +#include <comphelper/processfactory.hxx> + +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/helper/vclunohelper.hxx> + +#include <tools/diagnose_ex.h> +#include <tools/urlobj.hxx> + +#include <docuno.hxx> + +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbuno.hxx> +#include <basic/sbmeth.hxx> + +#include "transobj.hxx" +#include "convuno.hxx" +#include "cellsuno.hxx" +#include "miscuno.hxx" +#include "unonames.hxx" +#include "docsh.hxx" +#include <vbahelper/helperdecl.hxx> +#include "excelvbahelper.hxx" + +#include <basic/sbmeth.hxx> +#include <basic/sbmod.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbx.hxx> +#include <basic/sbxobj.hxx> +#include <basic/sbuno.hxx> +//limingl 2009-07-20 +#include "vbafiledialog.hxx" +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::uno::UNO_QUERY; +using ::rtl::OUString; + +// #TODO is this defined somewhere else? +#if ( defined UNX ) || ( defined OS2 ) //unix +#define FILE_PATH_SEPERATOR "/" +#else // windows +#define FILE_PATH_SEPERATOR "\\" +#endif + +uno::Any sbxToUnoValue( SbxVariable* pVar ); + +class ActiveWorkbook : public ScVbaWorkbook +{ +protected: + virtual uno::Reference< frame::XModel > getModel() + { + return getCurrentExcelDoc(mxContext); + } +public: + ActiveWorkbook( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) : ScVbaWorkbook( xParent, xContext ){} +}; + +ScVbaApplication::ScVbaApplication( const uno::Reference<uno::XComponentContext >& xContext ) : + ScVbaApplication_BASE( xContext ), + m_xCalculation( excel::XlCalculation::xlCalculationAutomatic ), + m_bDisplayAlerts( sal_True ), + m_bEnableEvents( sal_True ) +{ +} + +ScVbaApplication::~ScVbaApplication() +{ +} + +SfxObjectShell* ScVbaApplication::GetDocShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + return static_cast< SfxObjectShell* >( excel::getDocShell( xModel ) ); +} + +::rtl::OUString SAL_CALL +ScVbaApplication::getExactName( const ::rtl::OUString& aApproximateName ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XExactName > xWSF( new ScVbaWSFunction( this, mxContext ) ); + return xWSF->getExactName( aApproximateName ); +} + +uno::Reference< beans::XIntrospectionAccess > SAL_CALL +ScVbaApplication::getIntrospection() throw(css::uno::RuntimeException) +{ + uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); + return xWSF->getIntrospection(); +} + +uno::Any SAL_CALL +ScVbaApplication::invoke( const ::rtl::OUString& FunctionName, const uno::Sequence< uno::Any >& Params, uno::Sequence< sal_Int16 >& OutParamIndex, uno::Sequence< uno::Any >& OutParam) throw(lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + /* When calling the functions directly at the Application object, no runtime + errors are thrown, but the error is inserted into the return value. */ + uno::Any aAny; + try + { + uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); + aAny = xWSF->invoke( FunctionName, Params, OutParamIndex, OutParam ); + } + catch( uno::Exception& ) + { + aAny <<= script::BasicErrorException( ::rtl::OUString(), uno::Reference< uno::XInterface >(), 1000, ::rtl::OUString() ); + } + return aAny; +} + +void SAL_CALL +ScVbaApplication::setValue( const ::rtl::OUString& PropertyName, const uno::Any& Value ) throw(beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); + xWSF->setValue( PropertyName, Value ); +} + +uno::Any SAL_CALL +ScVbaApplication::getValue( const ::rtl::OUString& PropertyName ) throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); + return xWSF->getValue( PropertyName ); +} + +sal_Bool SAL_CALL +ScVbaApplication::hasMethod( const ::rtl::OUString& Name ) throw(uno::RuntimeException) +{ + uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); + return xWSF->hasMethod( Name ); +} + +sal_Bool SAL_CALL +ScVbaApplication::hasProperty( const ::rtl::OUString& Name ) throw(uno::RuntimeException) +{ + uno::Reference< script::XInvocation > xWSF( new ScVbaWSFunction( this, mxContext ) ); + return xWSF->hasProperty( Name ); +} + +uno::Reference< excel::XWorkbook > +ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException) +{ + uno::Reference< excel::XWorkbook > xWrkbk; + ScDocShell* pShell = excel::getDocShell( getCurrentExcelDoc( mxContext ) ); + if ( pShell ) + { + String aName; + if ( pShell->GetDocument() ) + { + aName = pShell->GetDocument()->GetCodeName(); + xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY ); + // fallback ( e.g. it's possible a new document was created via the api ) + // in that case the document will not have the appropriate Document Modules + // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document + // vba mode etc. ) + if ( !xWrkbk.is() ) + return new ActiveWorkbook( this, mxContext ); + } + } + return xWrkbk; +} + +uno::Reference< excel::XWorkbook > SAL_CALL +ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException) +{ + uno::Reference< excel::XWorkbook > xWrkbk; + ScDocShell* pShell = excel::getDocShell( getThisExcelDoc( mxContext ) ); + if ( pShell ) + { + String aName; + if ( pShell->GetDocument() ) + { + aName = pShell->GetDocument()->GetCodeName(); + xWrkbk.set( getUnoDocModule( aName, pShell ), uno::UNO_QUERY ); + // fallback ( e.g. it's possible a new document was created via the api ) + // in that case the document will not have the appropriate Document Modules + // #TODO #FIXME ( needs to be fixes as part of providing support for an overall document + // vba mode etc. ) + if ( !xWrkbk.is() ) + return new ActiveWorkbook( this, mxContext ); + } + } + return xWrkbk; +} + +uno::Reference< XAssistant > SAL_CALL +ScVbaApplication::getAssistant() throw (uno::RuntimeException) +{ + return uno::Reference< XAssistant >( new ScVbaAssistant( this, mxContext ) ); +} + +//liuchen 2009-8-18, add support of VBA Application.FileSearch +uno::Reference< XFileSearch > SAL_CALL +ScVbaApplication::getFileSearch() throw (uno::RuntimeException) +{ + if (! m_xFileSearch.get() ) + { + m_xFileSearch = uno::Reference< XFileSearch >( new ScVbaFileSearch( this, uno::Reference< XHelperInterface >( this ), mxContext ) ); + } + + return m_xFileSearch; +} +//liuchen + +uno::Any SAL_CALL +ScVbaApplication::getSelection() throw (uno::RuntimeException) +{ + OSL_TRACE("** ScVbaApplication::getSelection() ** "); + uno::Reference< frame::XModel > xModel( getCurrentDocument() ); + + Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), UNO_QUERY_THROW ); + Reference< beans::XPropertySet > xPropSet( xSelSupp, UNO_QUERY_THROW ); + OUString aPropName = OUString::createFromAscii( SC_UNO_FILTERED_RANGE_SELECTION ); + uno::Any aOldVal = xPropSet->getPropertyValue( aPropName ); + uno::Any any; + any <<= sal_False; + xPropSet->setPropertyValue( aPropName, any ); + uno::Reference< uno::XInterface > aSelection = ScUnoHelpFunctions::AnyToInterface( + xSelSupp->getSelection() ); + xPropSet->setPropertyValue( aPropName, aOldVal ); + + if (!aSelection.is()) + { + throw uno::RuntimeException( + rtl::OUString::createFromAscii("failed to obtain current selection"), + uno::Reference< uno::XInterface >() ); + } + + uno::Reference< lang::XServiceInfo > xServiceInfo( aSelection, uno::UNO_QUERY_THROW ); + rtl::OUString sImplementationName = xServiceInfo->getImplementationName(); + + if( sImplementationName.equalsIgnoreAsciiCaseAscii("com.sun.star.drawing.SvxShapeCollection") ) + { + uno::Reference< drawing::XShapes > xShapes( aSelection, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XShape > xShape( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW ); + // if ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape + // and the uno object implements the com.sun.star.drawing.Text service + // return a textboxshape object + if ( ScVbaShape::getType( xShape ) == office::MsoShapeType::msoAutoShape ) + { + uno::Reference< lang::XServiceInfo > xShapeServiceInfo( xShape, uno::UNO_QUERY_THROW ); + if ( xShapeServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.Text" ) ) ) ) + { + return uno::makeAny( uno::Reference< msforms::XTextBoxShape >(new ScVbaTextBoxShape( mxContext, xShape, xShapes, xModel ) ) ); + } + } + return uno::makeAny( uno::Reference< msforms::XShape >(new ScVbaShape( this, mxContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) ) ); + } + else if( xServiceInfo->supportsService( rtl::OUString::createFromAscii("com.sun.star.sheet.SheetCellRange")) || + xServiceInfo->supportsService( rtl::OUString::createFromAscii("com.sun.star.sheet.SheetCellRanges"))) + { + uno::Reference< table::XCellRange > xRange( aSelection, ::uno::UNO_QUERY); + if ( !xRange.is() ) + { + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( aSelection, ::uno::UNO_QUERY); + if ( xRanges.is() ) + return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), mxContext, xRanges ) ) ); + + } + return uno::makeAny( uno::Reference< excel::XRange >(new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange ) ) ); + } + else + { + throw uno::RuntimeException( sImplementationName + rtl::OUString::createFromAscii(" not supported"), uno::Reference< uno::XInterface >() ); + } +} + +uno::Reference< excel::XRange > +ScVbaApplication::getActiveCell() throw (uno::RuntimeException ) +{ + uno::Reference< sheet::XSpreadsheetView > xView( getCurrentDocument()->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xRange( xView->getActiveSheet(), ::uno::UNO_QUERY_THROW); + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell(mxContext); + if ( !pViewShell ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewShell available"), uno::Reference< uno::XInterface >() ); + ScViewData* pTabView = pViewShell->GetViewData(); + if ( !pTabView ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewData available"), uno::Reference< uno::XInterface >() ); + + sal_Int32 nCursorX = pTabView->GetCurX(); + sal_Int32 nCursorY = pTabView->GetCurY(); + + uno::Reference< XHelperInterface > xParent( excel::getUnoSheetModuleObj( xRange ), uno::UNO_QUERY_THROW ); + return new ScVbaRange( xParent, mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) ); +} + +uno::Any SAL_CALL +ScVbaApplication::Workbooks( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< XCollection > xWorkBooks( new ScVbaWorkbooks( this, mxContext ) ); + if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) + { + // void then somebody did Workbooks.something in vba + return uno::Any( xWorkBooks ); + } + + return uno::Any ( xWorkBooks->Item( aIndex, uno::Any() ) ); +} + +uno::Any SAL_CALL +ScVbaApplication::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY ); + uno::Any result; + if ( xWorkbook.is() ) + result = xWorkbook->Worksheets( aIndex ); + + else + // Fixme - check if this is reasonable/desired behavior + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "No ActiveWorkBook available" ), uno::Reference< uno::XInterface >() ); + + return result; +} + +uno::Any SAL_CALL +ScVbaApplication::WorksheetFunction( ) throw (::com::sun::star::uno::RuntimeException) +{ + return uno::makeAny( uno::Reference< script::XInvocation >( new ScVbaWSFunction( this, mxContext ) ) ); +} + +uno::Any SAL_CALL +ScVbaApplication::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( getActiveWorkbook()->getActiveSheet()->Range( uno::Any( Name ), aVoid ) ); +} + +uno::Any +ScVbaApplication::Dialogs( const uno::Any &aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< excel::XDialogs > xDialogs( new ScVbaDialogs( uno::Reference< XHelperInterface >( this ), mxContext, getCurrentDocument() ) ); + if( !aIndex.hasValue() ) + return uno::Any( xDialogs ); + return uno::Any( xDialogs->Item( aIndex ) ); +} + +uno::Reference< excel::XWindow > SAL_CALL +ScVbaApplication::getActiveWindow() throw (uno::RuntimeException) +{ + // #FIXME sofar can't determine Parent + uno::Reference< frame::XModel > xModel = getCurrentDocument(); + ScVbaWindow* pWin = new ScVbaWindow( uno::Reference< XHelperInterface >(), mxContext, xModel ); + uno::Reference< excel::XWindow > xWin( pWin ); + return xWin; +} + +uno::Any SAL_CALL +ScVbaApplication::getCutCopyMode() throw (uno::RuntimeException) +{ + uno::Any result; + ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( NULL ); + ScDocument* pDoc = pOwnClip ? pOwnClip->GetDocument() : NULL; + if ( pDoc ) + { + if ( pDoc->IsCutMode() ) + { + result <<= excel::XlCutCopyMode::xlCut; + } + else + { + result <<= excel::XlCutCopyMode::xlCopy; + } + } + else + { + result <<= sal_False; + } + return result; +} + +void SAL_CALL +ScVbaApplication::setCutCopyMode( const uno::Any& _cutcopymode ) throw (uno::RuntimeException) +{ + // According to Excel's behavior, no matter what is the value of _cutcopymode, always releases the clip object. + sal_Bool bCutCopyMode = sal_False; + if ( ( _cutcopymode >>= bCutCopyMode ) ) + { + ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( NULL ); + if ( pOwnClip ) + { + pOwnClip->ObjectReleased(); + ScTabViewShell* pTabViewShell = excel::getBestViewShell( getCurrentDocument() ); + if ( pTabViewShell ) + { + ScViewData* pView = pTabViewShell->GetViewData(); + Window* pWindow = pView ? pView->GetActiveWin() : NULL; + if ( pWindow ) + { + Reference< datatransfer::clipboard::XClipboard > xClipboard = pWindow->GetClipboard(); + Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY ); + if ( xClipboard.is() ) + { + xClipboard->setContents( NULL, NULL ); + if ( xFlushableClipboard.is() ) + { + const sal_uInt32 nRef = Application::ReleaseSolarMutex(); + try + { + xFlushableClipboard->flushClipboard(); + } + catch( const uno::Exception& ) + { + } + Application::AcquireSolarMutex( nRef ); + } + } + } + } + } + } +} + +uno::Any SAL_CALL +ScVbaApplication::getStatusBar() throw (uno::RuntimeException) +{ + return uno::makeAny( !getDisplayStatusBar() ); +} + +void SAL_CALL +ScVbaApplication::setStatusBar( const uno::Any& _statusbar ) throw (uno::RuntimeException) +{ + rtl::OUString sText; + sal_Bool bDefault = sal_False; + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< task::XStatusIndicatorSupplier > xStatusIndicatorSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< task::XStatusIndicator > xStatusIndicator( xStatusIndicatorSupplier->getStatusIndicator(), uno::UNO_QUERY_THROW ); + if( _statusbar >>= sText ) + { + setDisplayStatusBar( sal_True ); + xStatusIndicator->start( sText, 100 ); + //xStatusIndicator->setText( sText ); + } + else if( _statusbar >>= bDefault ) + { + if( bDefault == sal_False ) + { + xStatusIndicator->end(); + setDisplayStatusBar( sal_True ); + } + } + else + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid prarameter. It should be a string or False" ), + uno::Reference< uno::XInterface >() ); +} + +::sal_Int32 SAL_CALL +ScVbaApplication::getCalculation() throw (uno::RuntimeException) +{ + uno::Reference<sheet::XCalculatable> xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); + if(xCalc->isAutomaticCalculationEnabled()) + return excel::XlCalculation::xlCalculationAutomatic; + else + return excel::XlCalculation::xlCalculationManual; +} + +void SAL_CALL +ScVbaApplication::setCalculation( ::sal_Int32 _calculation ) throw (uno::RuntimeException) +{ + uno::Reference< sheet::XCalculatable > xCalc(getCurrentDocument(), uno::UNO_QUERY_THROW); + switch(_calculation) + { + case excel::XlCalculation::xlCalculationManual: + xCalc->enableAutomaticCalculation(sal_False); + break; + case excel::XlCalculation::xlCalculationAutomatic: + case excel::XlCalculation::xlCalculationSemiautomatic: + xCalc->enableAutomaticCalculation(sal_True); + break; + } +} + +uno::Any SAL_CALL +ScVbaApplication::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< excel::XWindows > xWindows( new ScVbaWindows( this, mxContext ) ); + if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) + return uno::Any( xWindows ); + return uno::Any( xWindows->Item( aIndex, uno::Any() ) ); +} +void SAL_CALL +ScVbaApplication::wait( double time ) throw (uno::RuntimeException) +{ + StarBASIC* pBasic = SFX_APP()->GetBasic(); + SFX_APP()->EnterBasicCall(); + SbxArrayRef aArgs = new SbxArray; + SbxVariableRef aRef = new SbxVariable; + aRef->PutDouble( time ); + aArgs->Put( aRef, 1 ); + SbMethod* pMeth = (SbMethod*)pBasic->GetRtl()->Find( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WaitUntil") ), SbxCLASS_METHOD ); + + if ( pMeth ) + { + pMeth->SetParameters( aArgs ); + SbxVariableRef refTemp = pMeth; + // forces a broadcast + SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth)); + } + SFX_APP()->LeaveBasicCall(); + +} + +uno::Any SAL_CALL +ScVbaApplication::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException) +{ + uno::Reference< excel::XRange > xVbRange = ScVbaRange::ApplicationRange( mxContext, Cell1, Cell2 ); + return uno::makeAny( xVbRange ); +} + +uno::Any SAL_CALL +ScVbaApplication::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException ) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("NamedRanges")) , uno::UNO_QUERY_THROW ); + css::uno::Reference< excel::XNames > xNames ( new ScVbaNames( this , mxContext , xNamedRanges , xModel ) ); + if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) + { + return uno::Any( xNames ); +} + return uno::Any( xNames->Item( aIndex, uno::Any() ) ); +} + + +uno::Reference< excel::XWorksheet > SAL_CALL +ScVbaApplication::getActiveSheet() throw (uno::RuntimeException) +{ + uno::Reference< excel::XWorksheet > result; + uno::Reference< excel::XWorkbook > xWorkbook( getActiveWorkbook(), uno::UNO_QUERY ); + if ( xWorkbook.is() ) + { + uno::Reference< excel::XWorksheet > xWorksheet( + xWorkbook->getActiveSheet(), uno::UNO_QUERY ); + if ( xWorksheet.is() ) + { + result = xWorksheet; + } + } + + if ( !result.is() ) + { + // Fixme - check if this is reasonable/desired behavior + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "No activeSheet available" ), uno::Reference< uno::XInterface >() ); + } + return result; + +} + +/******************************************************************************* + * In msdn: + * Reference Optional Variant. The destination. Can be a Range + * object, a string that contains a cell reference in R1C1-style notation, + * or a string that contains a Visual Basic procedure name. + * Scroll Optional Variant. True to scrol, False to not scroll through + * the window. The default is False. + * Parser is split to three parts, Range, R1C1 string and procedure name. + * by test excel, it seems Scroll no effect. ??? +*******************************************************************************/ +void SAL_CALL +ScVbaApplication::GoTo( const uno::Any& Reference, const uno::Any& Scroll ) throw (uno::RuntimeException) +{ + //test Scroll is a boolean + sal_Bool bScroll = sal_False; + //R1C1-style string or a string of procedure name. + + if( Scroll.hasValue() ) + { + sal_Bool aScroll = sal_False; + if( Scroll >>= aScroll ) + { + bScroll = aScroll; + } + else + throw uno::RuntimeException( rtl::OUString::createFromAscii( "sencond parameter should be boolean" ), + uno::Reference< uno::XInterface >() ); + } + + rtl::OUString sRangeName; + if( Reference >>= sRangeName ) + { + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheetView > xSpreadsheet( + xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xDoc = xSpreadsheet->getActiveSheet(); + + ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext ); + ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow(); + try + { + uno::Reference< excel::XRange > xVbaSheetRange = ScVbaRange::getRangeObjectForName( + mxContext, sRangeName, excel::getDocShell( xModel ), formula::FormulaGrammar::CONV_XL_R1C1 ); + + if( bScroll ) + { + xVbaSheetRange->Select(); + uno::Reference< excel::XWindow > xWindow = getActiveWindow(); + ScSplitPos eWhich = pShell->GetViewData()->GetActivePart(); + sal_Int32 nValueX = pShell->GetViewData()->GetPosX(WhichH(eWhich)); + sal_Int32 nValueY = pShell->GetViewData()->GetPosY(WhichV(eWhich)); + xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaSheetRange->getRow() - 1) ), + uno::makeAny( (sal_Int16)nValueY ), + uno::makeAny( (sal_Int16)(xVbaSheetRange->getColumn() - 1) ), + uno::makeAny( (sal_Int16)nValueX ) ); + gridWindow->GrabFocus(); + } + else + { + xVbaSheetRange->Select(); + gridWindow->GrabFocus(); + } + } + catch( uno::RuntimeException ) + { + //maybe this should be a procedure name + //TODO for procedure name + //browse::XBrowseNodeFactory is a singlton. OUString::createFromAscii( "/singletons/com.sun.star.script.browse.theBrowseNodeFactory") + //and the createView( browse::BrowseNodeFactoryViewTypes::MACROSELECTOR ) to get a root browse::XBrowseNode. + //for query XInvocation interface. + //but how to directly get the XInvocation? + throw uno::RuntimeException( rtl::OUString::createFromAscii( "invalid reference for range name, it should be procedure name" ), + uno::Reference< uno::XInterface >() ); + } + return; + } + uno::Reference< excel::XRange > xRange; + if( Reference >>= xRange ) + { + uno::Reference< excel::XRange > xVbaRange( Reference, uno::UNO_QUERY ); + ScTabViewShell* pShell = excel::getCurrentBestViewShell( mxContext ); + ScGridWindow* gridWindow = (ScGridWindow*)pShell->GetWindow(); + if ( xVbaRange.is() ) + { + //TODO bScroll should be using, In this time, it doesenot have effection + if( bScroll ) + { + xVbaRange->Select(); + uno::Reference< excel::XWindow > xWindow = getActiveWindow(); + ScSplitPos eWhich = pShell->GetViewData()->GetActivePart(); + sal_Int32 nValueX = pShell->GetViewData()->GetPosX(WhichH(eWhich)); + sal_Int32 nValueY = pShell->GetViewData()->GetPosY(WhichV(eWhich)); + xWindow->SmallScroll( uno::makeAny( (sal_Int16)(xVbaRange->getRow() - 1) ), + uno::makeAny( (sal_Int16)nValueY ), + uno::makeAny( (sal_Int16)(xVbaRange->getColumn() - 1) ), + uno::makeAny( (sal_Int16)nValueX ) ); + gridWindow->GrabFocus(); + } + else + { + xVbaRange->Select(); + gridWindow->GrabFocus(); + } + } + return; + } + throw uno::RuntimeException( rtl::OUString::createFromAscii( "invalid reference or name" ), + uno::Reference< uno::XInterface >() ); +} + +sal_Int32 SAL_CALL +ScVbaApplication::getCursor() throw (uno::RuntimeException) +{ + sal_Int32 nPointerStyle = getPointerStyle(getCurrentDocument()); + + switch( nPointerStyle ) + { + case POINTER_ARROW: + return excel::XlMousePointer::xlNorthwestArrow; + case POINTER_NULL: + return excel::XlMousePointer::xlDefault; + case POINTER_WAIT: + return excel::XlMousePointer::xlWait; + case POINTER_TEXT: + return excel::XlMousePointer::xlIBeam; + default: + return excel::XlMousePointer::xlDefault; + } +} + +void SAL_CALL +ScVbaApplication::setCursor( sal_Int32 _cursor ) throw (uno::RuntimeException) +{ + try + { + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + switch( _cursor ) + { + case excel::XlMousePointer::xlNorthwestArrow: + { + const Pointer& rPointer( POINTER_ARROW ); + setCursorHelper( xModel, rPointer, sal_False ); + break; + } + case excel::XlMousePointer::xlWait: + case excel::XlMousePointer::xlIBeam: + { + const Pointer& rPointer( static_cast< PointerStyle >( _cursor ) ); + //It will set the edit window, toobar and statusbar's mouse pointer. + setCursorHelper( xModel, rPointer, sal_True ); + break; + } + case excel::XlMousePointer::xlDefault: + { + const Pointer& rPointer( POINTER_NULL ); + setCursorHelper( xModel, rPointer, sal_False ); + break; + } + default: + throw uno::RuntimeException( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("Unknown value for Cursor pointer")), uno::Reference< uno::XInterface >() ); + // TODO: isn't this a flaw in the API? It should be allowed to throw an + // IllegalArgumentException, or so + } + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + +// #TODO perhaps we should switch the return type depending of the filter +// type, e.g. return Calc for Calc and Excel if its an imported doc +rtl::OUString SAL_CALL +ScVbaApplication::getName() throw (uno::RuntimeException) +{ + static rtl::OUString appName( RTL_CONSTASCII_USTRINGPARAM("Microsoft Excel" ) ); + return appName; +} + +// #TODO #FIXME get/setDisplayAlerts are just stub impl +// here just the status of the switch is set +// the function that throws an error message needs to +// evaluate this switch in order to know whether it has to disable the +// error message thrown by OpenOffice + +void SAL_CALL +ScVbaApplication::setDisplayAlerts(sal_Bool displayAlerts) throw (uno::RuntimeException) +{ + m_bDisplayAlerts = displayAlerts; +} + +sal_Bool SAL_CALL +ScVbaApplication::getDisplayAlerts() throw (uno::RuntimeException) +{ + return m_bDisplayAlerts; +} + +void SAL_CALL +ScVbaApplication::setEnableEvents(sal_Bool bEnable) throw (uno::RuntimeException) +{ + m_bEnableEvents = bEnable; +} + +sal_Bool SAL_CALL +ScVbaApplication::getEnableEvents() throw (uno::RuntimeException) +{ + return m_bEnableEvents; +} + +sal_Bool SAL_CALL +ScVbaApplication::getVisible() throw (uno::RuntimeException) +{ + sal_Bool bVisible = sal_True; + return bVisible; +} + +void SAL_CALL +ScVbaApplication::setVisible(sal_Bool /*bVisible*/) throw (uno::RuntimeException) +{ +} + +//liuchen 2009-11-25 add the support of Excel VBA Application.Iteration +//The Excel Iteration option is global and unique, but in Symphony there is an Iteration property in ScModule and one in every ScDocument, +//so the set method will set all the Iteration properties +sal_Bool SAL_CALL +ScVbaApplication::getIteration() throw (uno::RuntimeException) +{ + ScModule* pScMod = SC_MOD(); + ScDocOptions aDocOpt = pScMod->GetDocOptions(); + + return aDocOpt.IsIter(); +} + +void SAL_CALL +ScVbaApplication::setIteration(sal_Bool bIteration) throw (uno::RuntimeException) +{ + ScModule* pScMod = SC_MOD(); + ScDocOptions& aDocOpt = const_cast< ScDocOptions& > (pScMod->GetDocOptions()); + aDocOpt.SetIter( bIteration ); + + uno::Any aIteration; + aIteration <<= bIteration; + + OUString aPropName = OUString::createFromAscii( "IsIterationEnabled" ); + + uno::Reference< XCollection > xWorkbooks( new ScVbaWorkbooks( this, mxContext ) ); + sal_Int32 nCount = xWorkbooks->getCount(); + + for (sal_Int32 i = 1; i <= nCount; i++) + { + uno::Reference< ooo::vba::excel::XWorkbook > xWorkbook; + uno::Any aWorkbook = xWorkbooks->Item(uno::makeAny(i), uno::Any()); + aWorkbook >>= xWorkbook; + ScVbaWorkbook* pWorkbook = static_cast< ScVbaWorkbook* > ( xWorkbook.get() ); + + uno::Reference< frame::XModel > xModel( pWorkbook->getDocModel(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW ); + xPropertySet->setPropertyValue( aPropName, aIteration ); + } +} +//liuchen 2009-11-25 end + +//liuchen 2009-11-26 add the support of Excel VBA Application.EnableCancelKey +sal_Int32 SAL_CALL +ScVbaApplication::getEnableCancelKey() throw (uno::RuntimeException) +{ + return ooo::vba::excel::XlEnableCancelKey::xlDisabled; +} + +void SAL_CALL +ScVbaApplication::setEnableCancelKey(sal_Int32 /*lEnableCancelKey*/) throw (uno::RuntimeException) +{ +} +//liuchen 2009-11-26 end + +sal_Int32 SAL_CALL ScVbaApplication::getSheetsInNewWorkbook() throw (uno::RuntimeException) +{ + const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions(); + return rAppOpt.GetTabCountInNewSpreadsheet(); +} + +void SAL_CALL ScVbaApplication::setSheetsInNewWorkbook( sal_Int32 SheetsInNewWorkbook ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( SheetsInNewWorkbook < 1 || SheetsInNewWorkbook > MAXTAB ) + { + DebugHelper::exception( OUString::createFromAscii("The number must be between 1 and 255"), uno::Exception(), SbERR_METHOD_FAILED, OUString() ); + } + else + { + ScAppOptions& rAppOpt = const_cast< ScAppOptions& >(SC_MOD()->GetAppOptions()); + rAppOpt.SetTabCountInNewSpreadsheet( SheetsInNewWorkbook ); + } +} + +void SAL_CALL +ScVbaApplication::Calculate() throw( script::BasicErrorException , uno::RuntimeException ) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCalculatable > xCalculatable( getCurrentDocument(), uno::UNO_QUERY_THROW ); + xCalculatable->calculateAll(); +} + +uno::Reference< beans::XPropertySet > lcl_getPathSettingsService( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException ) +{ + static uno::Reference< beans::XPropertySet > xPathSettings; + if ( !xPathSettings.is() ) + { + uno::Reference< lang::XMultiComponentFactory > xSMgr( xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + xPathSettings.set( xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.util.PathSettings"), xContext), uno::UNO_QUERY_THROW ); + } + return xPathSettings; +} +rtl::OUString ScVbaApplication::getOfficePath( const rtl::OUString& _sPathType ) throw ( uno::RuntimeException ) +{ + rtl::OUString sRetPath; + uno::Reference< beans::XPropertySet > xProps = lcl_getPathSettingsService( mxContext ); + try + { + rtl::OUString sUrl; + xProps->getPropertyValue( _sPathType ) >>= sUrl; + + // if its a list of paths then use the last one + sal_Int32 nIndex = sUrl.lastIndexOf( ';' ) ; + if ( nIndex > 0 ) + sUrl = sUrl.copy( nIndex + 1 ); + ::osl::File::getSystemPathFromFileURL( sUrl, sRetPath ); + } + catch (uno::Exception&) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return sRetPath; +} +void SAL_CALL +ScVbaApplication::setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getPathSettingsService( mxContext ); + rtl::OUString aURL; + osl::FileBase::getFileURLFromSystemPath( DefaultFilePath, aURL ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work")), uno::makeAny( aURL ) ); + + +} + +::rtl::OUString SAL_CALL +ScVbaApplication::getDefaultFilePath( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Work"))); +} + +::rtl::OUString SAL_CALL +ScVbaApplication::LibraryPath( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Basic"))); +} + +::rtl::OUString SAL_CALL +ScVbaApplication::TemplatesPath( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return getOfficePath( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Template"))); +} + +::rtl::OUString SAL_CALL +ScVbaApplication::PathSeparator( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + static rtl::OUString sPathSep( RTL_CONSTASCII_USTRINGPARAM( FILE_PATH_SEPERATOR ) ); + return sPathSep; +} + +// ---------------------------------------------------------------------------- +// Helpers for Intersect and Union + +namespace { + +typedef ::std::list< ScRange > ListOfScRange; + +/** Appends all ranges of a VBA Range object in the passed Any to the list of ranges. */ +void lclAddToListOfScRange( ListOfScRange& rList, const uno::Any& rArg ) + throw (script::BasicErrorException, uno::RuntimeException) +{ + if( rArg.hasValue() ) + { + uno::Reference< excel::XRange > xRange( rArg, uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xCol( xRange->Areas( uno::Any() ), uno::UNO_QUERY_THROW ); + for( sal_Int32 nIdx = 1, nCount = xCol->getCount(); nIdx <= nCount; ++nIdx ) + { + uno::Reference< excel::XRange > xAreaRange( xCol->Item( uno::Any( nIdx ), uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeAddressable > xAddressable( xAreaRange->getCellRange(), uno::UNO_QUERY_THROW ); + ScRange aScRange; + ScUnoConversion::FillScRange( aScRange, xAddressable->getRangeAddress() ); + rList.push_back( aScRange ); + } + } +} + +/** Returns true, if the passed ranges can be expressed by a single range. The + new range will be contained in r1 then, the range r2 can be removed. */ +bool lclTryJoin( ScRange& r1, const ScRange& r2 ) +{ + // 1) r2 is completely inside r1 + if( r1.In( r2 ) ) + return true; + + // 2) r1 is completely inside r2 + if( r2.In( r1 ) ) + { + r1 = r2; + return true; + } + + SCCOL n1L = r1.aStart.Col(); + SCCOL n1R = r1.aEnd.Col(); + SCROW n1T = r1.aStart.Row(); + SCROW n1B = r1.aEnd.Row(); + SCCOL n2L = r2.aStart.Col(); + SCCOL n2R = r2.aEnd.Col(); + SCROW n2T = r2.aStart.Row(); + SCROW n2B = r2.aEnd.Row(); + + // 3) r1 and r2 have equal upper and lower border + if( (n1T == n2T) && (n1B == n2B) ) + { + // check that r1 overlaps or touches r2 + if( ((n1L < n2L) && (n2L - 1 <= n1R)) || ((n2L < n1L) && (n1L - 1 <= n2R)) ) + { + r1.aStart.SetCol( ::std::min( n1L, n2L ) ); + r1.aEnd.SetCol( ::std::max( n1R, n2R ) ); + return true; + } + return false; + } + + // 4) r1 and r2 have equal left and right border + if( (n1L == n2L) && (n1R == n2R) ) + { + // check that r1 overlaps or touches r2 + if( ((n1T < n2T) && (n2T + 1 <= n1B)) || ((n2T < n1T) && (n1T + 1 <= n2B)) ) + { + r1.aStart.SetRow( ::std::min( n1T, n2T ) ); + r1.aEnd.SetRow( ::std::max( n1B, n2B ) ); + return true; + } + return false; + } + + // 5) cannot join these ranges + return false; +} + +/** Strips out ranges that are contained by other ranges, joins ranges that can be joined + together (aligned borders, e.g. A4:D10 and B4:E10 would be combined to A4:E10. */ +void lclJoinRanges( ListOfScRange& rList ) +{ + ListOfScRange::iterator aOuterIt = rList.begin(); + while( aOuterIt != rList.end() ) + { + bool bAnyErased = false; // true = any range erased from rList + ListOfScRange::iterator aInnerIt = rList.begin(); + while( aInnerIt != rList.end() ) + { + bool bInnerErased = false; // true = aInnerIt erased from rList + // do not compare a range with itself + if( (aOuterIt != aInnerIt) && lclTryJoin( *aOuterIt, *aInnerIt ) ) + { + // aOuterIt points to joined range, aInnerIt will be removed + aInnerIt = rList.erase( aInnerIt ); + bInnerErased = bAnyErased = true; + } + /* If aInnerIt has been erased from rList, it already points to + the next element (return value of list::erase()). */ + if( !bInnerErased ) + ++aInnerIt; + } + // if any range has been erased, repeat outer loop with the same range + if( !bAnyErased ) + ++aOuterIt; + } +} + +/** Intersects the passed list with all ranges of a VBA Range object in the passed Any. */ +void lclIntersectRanges( ListOfScRange& rList, const uno::Any& rArg ) + throw (script::BasicErrorException, uno::RuntimeException) +{ + // extract the ranges from the passed argument, will throw on invalid data + ListOfScRange aList2; + lclAddToListOfScRange( aList2, rArg ); + // do nothing, if the passed list is already empty + if( !rList.empty() && !aList2.empty() ) + { + // save original list in a local + ListOfScRange aList1; + aList1.swap( rList ); + // join ranges from passed argument + lclJoinRanges( aList2 ); + // calculate intersection of the ranges in both lists + for( ListOfScRange::const_iterator aOuterIt = aList1.begin(), aOuterEnd = aList1.end(); aOuterIt != aOuterEnd; ++aOuterIt ) + { + for( ListOfScRange::const_iterator aInnerIt = aList2.begin(), aInnerEnd = aList2.end(); aInnerIt != aInnerEnd; ++aInnerIt ) + { + if( aOuterIt->Intersects( *aInnerIt ) ) + { + ScRange aIsectRange( + Max( aOuterIt->aStart.Col(), aInnerIt->aStart.Col() ), + Max( aOuterIt->aStart.Row(), aInnerIt->aStart.Row() ), + Max( aOuterIt->aStart.Tab(), aInnerIt->aStart.Tab() ), + Min( aOuterIt->aEnd.Col(), aInnerIt->aEnd.Col() ), + Min( aOuterIt->aEnd.Row(), aInnerIt->aEnd.Row() ), + Min( aOuterIt->aEnd.Tab(), aInnerIt->aEnd.Tab() ) ); + rList.push_back( aIsectRange ); + } + } + } + // again, join the result ranges + lclJoinRanges( rList ); + } +} + +/** Creates a VBA Range object from the passed list of ranges. */ +uno::Reference< excel::XRange > lclCreateVbaRange( + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const ListOfScRange& rList ) throw (uno::RuntimeException) +{ + ScDocShell* pDocShell = excel::getDocShell( rxModel ); + if( !pDocShell ) throw uno::RuntimeException(); + + ScRangeList aCellRanges; + for( ListOfScRange::const_iterator aIt = rList.begin(), aEnd = rList.end(); aIt != aEnd; ++aIt ) + aCellRanges.Append( *aIt ); + + if( aCellRanges.Count() == 1 ) + { + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocShell, *aCellRanges.First() ) ); + return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), rxContext, xRange ); + } + if( aCellRanges.Count() > 1 ) + { + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocShell, aCellRanges ) ); + return new ScVbaRange( excel::getUnoSheetModuleObj( xRanges ), rxContext, xRanges ); + } + return 0; +} + +} // namespace + +// ---------------------------------------------------------------------------- + +uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Intersect( + const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2, + const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6, + const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10, + const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14, + const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18, + const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22, + const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26, + const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 ) + throw (script::BasicErrorException, uno::RuntimeException) +{ + if( !rArg1.is() || !rArg2.is() ) + DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() ); + + // initialize the result list with 1st parameter, join its ranges together + ListOfScRange aList; + lclAddToListOfScRange( aList, uno::Any( rArg1 ) ); + lclJoinRanges( aList ); + + // process all other parameters, this updates the list with intersection + lclIntersectRanges( aList, uno::Any( rArg2 ) ); + lclIntersectRanges( aList, rArg3 ); + lclIntersectRanges( aList, rArg4 ); + lclIntersectRanges( aList, rArg5 ); + lclIntersectRanges( aList, rArg6 ); + lclIntersectRanges( aList, rArg7 ); + lclIntersectRanges( aList, rArg8 ); + lclIntersectRanges( aList, rArg9 ); + lclIntersectRanges( aList, rArg10 ); + lclIntersectRanges( aList, rArg11 ); + lclIntersectRanges( aList, rArg12 ); + lclIntersectRanges( aList, rArg13 ); + lclIntersectRanges( aList, rArg14 ); + lclIntersectRanges( aList, rArg15 ); + lclIntersectRanges( aList, rArg16 ); + lclIntersectRanges( aList, rArg17 ); + lclIntersectRanges( aList, rArg18 ); + lclIntersectRanges( aList, rArg19 ); + lclIntersectRanges( aList, rArg20 ); + lclIntersectRanges( aList, rArg21 ); + lclIntersectRanges( aList, rArg22 ); + lclIntersectRanges( aList, rArg23 ); + lclIntersectRanges( aList, rArg24 ); + lclIntersectRanges( aList, rArg25 ); + lclIntersectRanges( aList, rArg26 ); + lclIntersectRanges( aList, rArg27 ); + lclIntersectRanges( aList, rArg28 ); + lclIntersectRanges( aList, rArg29 ); + lclIntersectRanges( aList, rArg30 ); + + // create the VBA Range object + return lclCreateVbaRange( mxContext, getCurrentDocument(), aList ); +} + +uno::Reference< excel::XRange > SAL_CALL ScVbaApplication::Union( + const uno::Reference< excel::XRange >& rArg1, const uno::Reference< excel::XRange >& rArg2, + const uno::Any& rArg3, const uno::Any& rArg4, const uno::Any& rArg5, const uno::Any& rArg6, + const uno::Any& rArg7, const uno::Any& rArg8, const uno::Any& rArg9, const uno::Any& rArg10, + const uno::Any& rArg11, const uno::Any& rArg12, const uno::Any& rArg13, const uno::Any& rArg14, + const uno::Any& rArg15, const uno::Any& rArg16, const uno::Any& rArg17, const uno::Any& rArg18, + const uno::Any& rArg19, const uno::Any& rArg20, const uno::Any& rArg21, const uno::Any& rArg22, + const uno::Any& rArg23, const uno::Any& rArg24, const uno::Any& rArg25, const uno::Any& rArg26, + const uno::Any& rArg27, const uno::Any& rArg28, const uno::Any& rArg29, const uno::Any& rArg30 ) + throw (script::BasicErrorException, uno::RuntimeException) +{ + if( !rArg1.is() || !rArg2.is() ) + DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() ); + + ListOfScRange aList; + lclAddToListOfScRange( aList, uno::Any( rArg1 ) ); + lclAddToListOfScRange( aList, uno::Any( rArg2 ) ); + lclAddToListOfScRange( aList, rArg3 ); + lclAddToListOfScRange( aList, rArg4 ); + lclAddToListOfScRange( aList, rArg5 ); + lclAddToListOfScRange( aList, rArg6 ); + lclAddToListOfScRange( aList, rArg7 ); + lclAddToListOfScRange( aList, rArg8 ); + lclAddToListOfScRange( aList, rArg9 ); + lclAddToListOfScRange( aList, rArg10 ); + lclAddToListOfScRange( aList, rArg11 ); + lclAddToListOfScRange( aList, rArg12 ); + lclAddToListOfScRange( aList, rArg13 ); + lclAddToListOfScRange( aList, rArg14 ); + lclAddToListOfScRange( aList, rArg15 ); + lclAddToListOfScRange( aList, rArg16 ); + lclAddToListOfScRange( aList, rArg17 ); + lclAddToListOfScRange( aList, rArg18 ); + lclAddToListOfScRange( aList, rArg19 ); + lclAddToListOfScRange( aList, rArg20 ); + lclAddToListOfScRange( aList, rArg21 ); + lclAddToListOfScRange( aList, rArg22 ); + lclAddToListOfScRange( aList, rArg23 ); + lclAddToListOfScRange( aList, rArg24 ); + lclAddToListOfScRange( aList, rArg25 ); + lclAddToListOfScRange( aList, rArg26 ); + lclAddToListOfScRange( aList, rArg27 ); + lclAddToListOfScRange( aList, rArg28 ); + lclAddToListOfScRange( aList, rArg29 ); + lclAddToListOfScRange( aList, rArg30 ); + + // simply join together all ranges as much as possible, strip out covered ranges etc. + lclJoinRanges( aList ); + + // create the VBA Range object + return lclCreateVbaRange( mxContext, getCurrentDocument(), aList ); +} + +void +ScVbaApplication::Volatile( const uno::Any& aVolatile ) throw ( uno::RuntimeException ) +{ + sal_Bool bVolatile = sal_True; + aVolatile >>= bVolatile; + SbMethod* pMeth = StarBASIC::GetActiveMethod(); + if ( pMeth ) + { + OSL_TRACE("ScVbaApplication::Volatile() In method ->%s<-", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() ); + uno::Reference< frame::XModel > xModel( getCurrentDocument() ); + ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument(); + pDoc->GetMacroManager()->SetUserFuncVolatile( pMeth->GetName(), bVolatile); + } + +// this is bound to break when loading the document + return; +} + +::sal_Bool SAL_CALL +ScVbaApplication::getDisplayFormulaBar() throw ( css::uno::RuntimeException ) +{ + sal_Bool bRes = sal_False; + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext ); + if ( pViewShell ) + { + SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE); + SfxAllItemSet reqList( SFX_APP()->GetPool() ); + reqList.Put( sfxFormBar ); + + pViewShell->GetState( reqList ); + const SfxPoolItem *pItem=0; + if ( reqList.GetItemState( FID_TOGGLEINPUTLINE, sal_False, &pItem ) == SFX_ITEM_SET ) + bRes = ((SfxBoolItem*)pItem)->GetValue(); + } + return bRes; +} + +void SAL_CALL +ScVbaApplication::setDisplayFormulaBar( ::sal_Bool _displayformulabar ) throw ( css::uno::RuntimeException ) +{ + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext ); + if ( pViewShell && ( _displayformulabar != getDisplayFormulaBar() ) ) + { + SfxBoolItem sfxFormBar( FID_TOGGLEINPUTLINE, _displayformulabar); + SfxAllItemSet reqList( SFX_APP()->GetPool() ); + SfxRequest aReq( FID_TOGGLEINPUTLINE, 0, reqList ); + pViewShell->Execute( aReq ); + } +} + +uno::Any SAL_CALL +ScVbaApplication::Caller( const uno::Any& /*aIndex*/ ) throw ( uno::RuntimeException ) +{ + StarBASIC* pBasic = SFX_APP()->GetBasic(); + SFX_APP()->EnterBasicCall(); + SbMethod* pMeth = (SbMethod*)pBasic->GetRtl()->Find( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FuncCaller") ), SbxCLASS_METHOD ); + uno::Any aRet; + if ( pMeth ) + { + SbxVariableRef refTemp = pMeth; + // forces a broadcast + SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth)); + OSL_TRACE("pNew has type %d and string value %s", pNew->GetType(), rtl::OUStringToOString( pNew->GetString(), RTL_TEXTENCODING_UTF8 ).getStr() ); + aRet = sbxToUnoValue( pNew ); + } + SFX_APP()->LeaveBasicCall(); + return aRet; +} + +//Add by minz@cn.ibm.com. 2009-07-08. +uno::Any SAL_CALL +ScVbaApplication::GetOpenFilename(const uno::Any& FileFilter, const uno::Any& FilterIndex, const uno::Any& Title, const uno::Any& ButtonText, const uno::Any& MultiSelect) throw (uno::RuntimeException) +{ + uno::Any aRet = uno::makeAny( sal_False ); + try + { + const ::rtl::OUString sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" ); + uno::Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY ); + // Set the type of File Picker Dialog: TemplateDescription::FILEOPEN_SIMPLE. + uno::Sequence< uno::Any > aDialogType( 1 ); + aDialogType[0] <<= ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; + uno::Reference< ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY ); + uno::Reference< ui::dialogs::XFilePicker2 > xFilePicker2( xFilePicker, UNO_QUERY ); + uno::Reference< ui::dialogs::XFilterManager > xFilterManager( xFilePicker, UNO_QUERY ); + uno::Reference< ui::dialogs::XExecutableDialog > xExecutableDialog( xFilePicker, UNO_QUERY ); + uno::Reference< ui::dialogs::XFilePickerControlAccess > xPickerControlAccess( xFilePicker, UNO_QUERY ); + + if ( xFilterManager.is() && FileFilter.hasValue() ) + { + sal_Int32 nFilterIndex = 1; + if ( FilterIndex.hasValue() ) + { + FilterIndex >>= nFilterIndex; + } + ::rtl::OUString strFilter; + FileFilter >>= strFilter; + sal_Int32 nCommaID = 0; + sal_Int32 nIndex = 1; + do + { + ::rtl::OUString aFilterTitleToken = strFilter.getToken( 0, ',' , nCommaID ); + ::rtl::OUString aFilterToken; + if ( nCommaID >= 0 ) + { + aFilterToken = strFilter.getToken( 0, ',' , nCommaID ); + } + else if ( nCommaID < 0 && nIndex == 1 ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid FileFilter format!" ), uno::Reference< uno::XInterface >() ); + } + xFilterManager->appendFilter( aFilterTitleToken, aFilterToken ); + if ( nFilterIndex == nIndex ) + { + xFilterManager->setCurrentFilter( aFilterTitleToken ); + } + nIndex++; + } while ( nCommaID >= 0 ); + } + if ( xExecutableDialog.is() && Title.hasValue() ) + { + ::rtl::OUString sTitle; + Title >>= sTitle; + xExecutableDialog->setTitle( sTitle ); + } + if ( xPickerControlAccess.is() && ButtonText.hasValue() ) + { + ::rtl::OUString sButtonText; + ButtonText >>= sButtonText; + xPickerControlAccess->setLabel( ui::dialogs::CommonFilePickerElementIds::PUSHBUTTON_OK, sButtonText ); + } + sal_Bool bMultiSelect = sal_False; + if ( xFilePicker.is() && MultiSelect.hasValue() ) + { + MultiSelect >>= bMultiSelect; + xFilePicker->setMultiSelectionMode( bMultiSelect ); + } + + if ( xFilePicker.is() && xFilePicker->execute() ) + { + sal_Bool bUseXFilePicker2 = sal_False; + uno::Reference< lang::XServiceInfo > xServiceInfo( xFilePicker, UNO_QUERY ); + if ( xServiceInfo.is() ) + { + rtl::OUString sImplName = xServiceInfo->getImplementationName(); + if ( sImplName.equalsAscii("com.sun.star.comp.fpicker.VistaFileDialog") || sImplName.equalsAscii("com.sun.star.ui.dialogs.SalGtkFilePicker") ) + { + bUseXFilePicker2 = sal_True; + } + } + uno::Sequence< rtl::OUString > aSelectedFiles; + if ( bUseXFilePicker2 && xFilePicker2.is() ) + { + // On Linux, XFilePicker->getFiles() always return one selected file although we select more than one file, also on Vista + // XFilePicker->getFiles() does not work well too, so we call XFilePicker2->getSelectedFiles() to get selected files. + aSelectedFiles = xFilePicker2->getSelectedFiles(); + } + else + { + // If only one file is selected, the first entry of the sequence contains the complete path/filename in URL format. If multiple files are selected, + // the first entry of the sequence contains the path in URL format, and the other entries contains the names of the selected files without path information. + uno::Sequence< rtl::OUString > aTmpFiles = xFilePicker->getFiles(); + aSelectedFiles = aTmpFiles; + sal_Int32 iFileCount = aTmpFiles.getLength(); + if ( iFileCount > 1 ) + { + aSelectedFiles.realloc( iFileCount - 1 ); + INetURLObject aPath( aTmpFiles[0] ); + aPath.setFinalSlash(); + for ( sal_Int32 i = 1; i < iFileCount; i++ ) + { + if ( aTmpFiles[i].indexOf ('/') > 0 || aTmpFiles[i].indexOf ('\\') > 0 ) + { + aSelectedFiles[i - 1] = aTmpFiles[i]; + } + else + { + if ( i == 1 ) + aPath.Append( aTmpFiles[i] ); + else + aPath.setName( aTmpFiles[i] ); + aSelectedFiles[i - 1] = aPath.GetMainURL( INetURLObject::NO_DECODE ); + } + } + } + } + + sal_Int32 iFileCount = aSelectedFiles.getLength(); + for ( sal_Int32 i = 0; i < iFileCount; i++ ) + { + INetURLObject aObj( aSelectedFiles[i] ); + if ( aObj.GetProtocol() == INET_PROT_FILE ) + { + rtl::OUString aTemp = aObj.PathToFileName(); + aSelectedFiles[i] = aTemp.getLength() > 0 ? aTemp : aSelectedFiles[i]; + } + } + if ( bMultiSelect ) + { + aRet = uno::makeAny( aSelectedFiles ); + } + else if ( aSelectedFiles.getLength() > 0 && !bMultiSelect ) + { + aRet = uno::makeAny( aSelectedFiles[0] ); + } + } + } + catch( const uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + + return aRet; +} + +//liming 2009-7-17 +::com::sun::star::uno::Reference< ::ooo::vba::XFileDialog > SAL_CALL +ScVbaApplication::getFileDialog() throw (::com::sun::star::uno::RuntimeException) +{ + uno::Reference< XFileDialog > xFileDialogs( new ScVbaFileDialog( uno::Reference< XHelperInterface >( this ), mxContext, getCurrentDocument() ) ); + return xFileDialogs; +} + +typedef std::map< ::rtl::OUString, ::rtl::OUString > FileFilterMap; + +//2009-11-06 add by limingl +uno::Any SAL_CALL +ScVbaApplication::GetSaveAsFilename( const ::com::sun::star::uno::Any& InitialFilename, const ::com::sun::star::uno::Any& FileFilter, const ::com::sun::star::uno::Any& FilterIndex, const ::com::sun::star::uno::Any& Title, const ::com::sun::star::uno::Any& ButtonText ) throw (::com::sun::star::uno::RuntimeException) +{ + uno::Any strRet; + try + { + const ::rtl::OUString sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" ); + uno::Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY ); + + uno::Sequence< uno::Any > aDialogType( 1 ); + aDialogType[0] <<= ui::dialogs::TemplateDescription::FILESAVE_SIMPLE; + uno::Reference< ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY ); + + if (InitialFilename.hasValue()) + { + ::rtl::OUString strInitFileName; + InitialFilename >>= strInitFileName; + xFilePicker->setDefaultName(strInitFileName); + } + + // Begin from 1. + sal_Int32 nFilterIndex = 1; + if (FilterIndex.hasValue()) + { + FilterIndex >>= nFilterIndex; + } + + uno::Reference< ui::dialogs::XFilterManager > xFilter( xFilePicker, UNO_QUERY ); + FileFilterMap mFilterNameMap; + if (FileFilter.hasValue()) + { + ::rtl::OUString strFilter; + sal_Int32 nCommaID = 0; + FileFilter >>= strFilter; + + sal_Int32 nIndex = 1; + do + { + ::rtl::OUString aFilterTitleToken = strFilter.getToken( 0, ',' , nCommaID ); + ::rtl::OUString aFilterToken; + if ( nCommaID >= 0 ) + { + aFilterToken = strFilter.getToken( 0, ',' , nCommaID ); + } + else if ( nCommaID < 0 && nIndex == 1 ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid FileFilter format!" ), uno::Reference< uno::XInterface >() ); + } + + FileFilterMap::const_iterator aIt = mFilterNameMap.find( aFilterTitleToken ); + if ( aIt == mFilterNameMap.end() ) + { + xFilter->appendFilter( aFilterTitleToken, aFilterToken ); + if ( nFilterIndex == nIndex ) + { + xFilter->setCurrentFilter( aFilterTitleToken ); + } + nIndex++; + mFilterNameMap[aFilterTitleToken] = aFilterToken; + } + } while ( nCommaID >= 0 ); + } + + if (Title.hasValue()) + { + ::rtl::OUString strTitle; + Title >>= strTitle; + uno::Reference< ::com::sun::star::ui::dialogs::XExecutableDialog> xExcTblDlg(xFilePicker, UNO_QUERY ); + xExcTblDlg->setTitle(strTitle); + } + + if (ButtonText.hasValue()) + { + ::rtl::OUString strBttTxt; + ButtonText >>= strBttTxt; + } + + + if ( xFilePicker.is() ) + { + sal_Int16 nRet = xFilePicker->execute(); + if (nRet == 0) + { + strRet <<= sal_False; + } + else + { + uno::Sequence < rtl::OUString > aPathSeq = xFilePicker->getFiles(); + + if ( aPathSeq.getLength() ) + { + ::rtl::OUString sSelectedFilters; + if ( xFilter.is() ) + { + ::rtl::OUString sSelectedFilterName = xFilter->getCurrentFilter(); + FileFilterMap::const_iterator aIt = mFilterNameMap.find( sSelectedFilterName ); + if ( aIt != mFilterNameMap.end() ) + { + sSelectedFilters = aIt->second; + } + } + INetURLObject aURLObj( aPathSeq[0] ); + ::rtl::OUString aPathStr = aURLObj.PathToFileName(); + if ( aURLObj.GetProtocol() == INET_PROT_FILE ) + { + sal_Int32 nSemicolonID = 0; + ::rtl::OUString sFirstFilter = sSelectedFilters.getToken( 0, ';' , nSemicolonID ); + ::rtl::OUString sFileExtension = aURLObj.GetExtension(); + if ( sFileExtension.equalsAscii("") ) + { + sFileExtension = sFirstFilter.equalsAscii("*.*") ? sFileExtension : sFirstFilter.copy( sFirstFilter.indexOfAsciiL("*.", 2) + 2 ); + aPathStr = sFileExtension.equalsAscii("") ? aPathStr : aPathStr + ::rtl::OUString::createFromAscii(".") + sFileExtension; + } + else + { + sal_Bool bValidFilter = sal_False; + FileFilterMap::const_iterator aIt = mFilterNameMap.begin(); + while ( aIt != mFilterNameMap.end() ) + { + sSelectedFilters = aIt->second; + nSemicolonID = 0; + do + { + ::rtl::OUString aFilterToken = sSelectedFilters.getToken( 0, ';' , nSemicolonID ); + if ( aFilterToken.trim().equalsIgnoreAsciiCase(::rtl::OUString::createFromAscii("*.") + sFileExtension) ) + { + bValidFilter = sal_True; + break; + } + } while ( nSemicolonID >= 0 ); + if ( bValidFilter ) + { + break; + } + aIt++; + } + if ( !bValidFilter ) + { + sFileExtension = sFirstFilter.equalsAscii("*.*") ? ::rtl::OUString::createFromAscii("") : sFirstFilter.copy( sFirstFilter.indexOfAsciiL("*.", 2) + 2 ); + aPathStr = sFileExtension.equalsAscii("") ? aPathStr : aPathStr + ::rtl::OUString::createFromAscii(".") + sFileExtension; + } + } + } + strRet <<= aPathStr; + } + } + } + } + catch( const uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return strRet; +} + +//end add + +uno::Reference< frame::XModel > +ScVbaApplication::getCurrentDocument() throw (css::uno::RuntimeException) +{ + return getCurrentExcelDoc(mxContext); +} + +uno::Any SAL_CALL +ScVbaApplication::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< XCommandBars > xCommandBars( CommandBars( uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xMenuBars( new ScVbaMenuBars( this, mxContext, xCommandBars ) ); + if ( aIndex.hasValue() ) + { + return uno::Any ( xMenuBars->Item( aIndex, uno::Any() ) ); + } + + return uno::Any( xMenuBars ); +} + +//liuchen 2009-11-26 add the support of Application.International +sal_Int32 SAL_CALL +ConvertCountryCode(const OUString& language) +{ + sal_Int32 nCode = 0; + + if( language == OUString::createFromAscii("ar") ) nCode = 966; // Arabic + else if ( language == OUString::createFromAscii("cs") ) nCode = 42; // Czech + else if ( language == OUString::createFromAscii("da") ) nCode = 45; // Danish + else if ( language == OUString::createFromAscii("de") ) nCode = 49; // German + else if ( language == OUString::createFromAscii("en") ) nCode = 1; // English + else if ( language == OUString::createFromAscii("es") ) nCode = 34; // Spanish + else if ( language == OUString::createFromAscii("el") ) nCode = 30; // Greek + else if ( language == OUString::createFromAscii("fa") ) nCode = 98; // Persian = Farsi + else if ( language == OUString::createFromAscii("fi") ) nCode = 358; // Finnish + else if ( language == OUString::createFromAscii("fr") ) nCode = 33; // French + else if ( language == OUString::createFromAscii("he") ) nCode = 972; // Hebrew + else if ( language == OUString::createFromAscii("hi") ) nCode = 91; // Indian = Hindi + else if ( language == OUString::createFromAscii("hu") ) nCode = 36; // Hungarian + else if ( language == OUString::createFromAscii("it") ) nCode = 39; // Italian + else if ( language == OUString::createFromAscii("ja") ) nCode = 81; // Japanese + else if ( language == OUString::createFromAscii("ko") ) nCode = 82; // Korean + else if ( language == OUString::createFromAscii("nl") ) nCode = 31; // Dutch + else if ( language == OUString::createFromAscii("no") ) nCode = 47; // Norwegian + else if ( language == OUString::createFromAscii("pl") ) nCode = 48; // Polish + else if ( language == OUString::createFromAscii("pt") ) nCode = 351; // Portuguese + else if ( language == OUString::createFromAscii("ru") ) nCode = 7; // Russian + else if ( language == OUString::createFromAscii("sv") ) nCode = 46; // Swedish + else if ( language == OUString::createFromAscii("th") ) nCode = 66; // Thai + else if ( language == OUString::createFromAscii("tk") ) nCode = 90; // Turkish + else if ( language == OUString::createFromAscii("ur") ) nCode = 92; // Urdu + else if ( language == OUString::createFromAscii("vi") ) nCode = 84; // Vietnamese + else if ( language == OUString::createFromAscii("zh") ) nCode = 86; // Simplified Chinese + + return nCode; +} + +uno::Any SAL_CALL +ScVbaApplication::International( sal_Int32 Index ) throw (uno::RuntimeException) +{ + uno::Any aRet; + OUString str; + const LocaleDataWrapper* pLocaleData = ScGlobal::GetpLocaleData(); + switch ( Index ) + { + case excel::XlApplicationInternational::xlCountryCode: + aRet <<= ConvertCountryCode( pLocaleData->getLanguageCountryInfo().Language ); + break; + case excel::XlApplicationInternational::xlDecimalSeparator: + str = pLocaleData->getNumDecimalSep(); + aRet <<= str; + break; + case excel::XlApplicationInternational::xlDateSeparator: + str = pLocaleData->getDateSep(); + aRet <<= str; + break; + default: + break; + } + return aRet; +} +//liuchen 2009-11-26 end + +//2009-12-11 add by limingl +void SAL_CALL ScVbaApplication::Undo( ) throw (::com::sun::star::uno::RuntimeException) +{ + SfxAllItemSet reqList( SFX_APP()->GetPool() ); + SfxRequest rReq(SID_UNDO, 0, reqList); + ScTabViewShell* pViewShell = excel::getCurrentBestViewShell( mxContext ); + + if (pViewShell != NULL) + { + pViewShell->ExecuteUndo(rReq); + } +} +//end + +double SAL_CALL ScVbaApplication::InchesToPoints( double Inches ) throw (uno::RuntimeException) +{ + // Convert a measurement from Inch to Point (1 inch = 72 points). + return MetricField::ConvertDoubleValue( Inches, 0, 0, FUNIT_INCH, FUNIT_POINT ); +} + +rtl::OUString& +ScVbaApplication::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaApplication") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaApplication::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Application" ) ); + } + return aServiceNames; +} + +namespace application +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaApplication, sdecl::with_args<false> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaApplication", + "ooo.vba.excel.Application" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaapplication.hxx b/sc/source/ui/vba/vbaapplication.hxx new file mode 100644 index 000000000000..6a5f655f0dbe --- /dev/null +++ b/sc/source/ui/vba/vbaapplication.hxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_APPLICATION_HXX +#define SC_VBA_APPLICATION_HXX + + +#include <ooo/vba/excel/XWorksheetFunction.hpp> +#include <ooo/vba/excel/XApplication.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbaapplicationbase.hxx> +#include <cppuhelper/implbase1.hxx> + +//typedef InheritedHelperInterfaceImpl1< ov::excel::XApplication > ScVbaApplication_BASE; +typedef cppu::ImplInheritanceHelper1< VbaApplicationBase, ov::excel::XApplication > ScVbaApplication_BASE; + +class ScVbaApplication : public ScVbaApplication_BASE +{ +private: + sal_Int32 m_xCalculation; + sal_Bool m_bDisplayAlerts; + sal_Bool m_bEnableEvents; + + rtl::OUString getOfficePath( const rtl::OUString& sPath ) throw ( css::uno::RuntimeException ); + css::uno::Reference< ov::XFileSearch > m_xFileSearch; // + +protected: + virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() throw (css::uno::RuntimeException); + +public: + ScVbaApplication( const css::uno::Reference< css::uno::XComponentContext >& m_xContext ); + virtual ~ScVbaApplication(); + + virtual SfxObjectShell* GetDocShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + + // XExactName + virtual ::rtl::OUString SAL_CALL getExactName( const ::rtl::OUString& aApproximateName ) throw (css::uno::RuntimeException); + + // XInvocation + virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection(void) throw(css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL invoke(const rtl::OUString& FunctionName, const css::uno::Sequence< css::uno::Any >& Params, css::uno::Sequence< sal_Int16 >& OutParamIndex, css::uno::Sequence< css::uno::Any >& OutParam) throw(css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual void SAL_CALL setValue(const rtl::OUString& PropertyName, const css::uno::Any& Value) throw(css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue(const rtl::OUString& PropertyName) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasMethod(const rtl::OUString& Name) throw(css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasProperty(const rtl::OUString& Name) throw(css::uno::RuntimeException); + + // XApplication + virtual ::rtl::OUString SAL_CALL PathSeparator( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setDefaultFilePath( const ::rtl::OUString& DefaultFilePath ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getDefaultFilePath( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL LibraryPath( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL TemplatesPath( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getDisplayAlerts() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayAlerts( sal_Bool displayAlerts ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getCalculation() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCalculation( ::sal_Int32 _calculation ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getSelection() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getActiveWorkbook() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getActiveCell() throw ( css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWindow > SAL_CALL getActiveWindow() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayFormulaBar() throw ( css::uno::RuntimeException ); + virtual void SAL_CALL setDisplayFormulaBar( ::sal_Bool _displayformulabar ) throw ( css::uno::RuntimeException ); + + virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::XFileSearch > SAL_CALL getFileSearch() throw (css::uno::RuntimeException); //liuchen 2009-8-18 add the support of Application.FileSearch + virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Workbooks( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Worksheets( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL WorksheetFunction( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Evaluate( const ::rtl::OUString& Name ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Dialogs( const css::uno::Any& DialogIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getCutCopyMode() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCutCopyMode( const css::uno::Any& _cutcopymode ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStatusBar() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStatusBar( const css::uno::Any& _statusbar ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getCursor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCursor( ::sal_Int32 _cursor ) throw (css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool bVisible ) throw (css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL getIteration() throw (css::uno::RuntimeException); //liuchen 2009-11-25 add the support of Iteration + virtual void SAL_CALL setIteration( sal_Bool bIteration ) throw (css::uno::RuntimeException); //liuchen 2009-11-25 add the support of Iteration + virtual sal_Int32 SAL_CALL getEnableCancelKey() throw (css::uno::RuntimeException); //liuchen 2009-11-26 add the support of EnableCancelKey + virtual void SAL_CALL setEnableCancelKey( sal_Int32 lEnableCancelKey ) throw (css::uno::RuntimeException); //liuchen 2009-11-26 add the support of EnableCancelKey + + virtual sal_Int32 SAL_CALL getSheetsInNewWorkbook() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSheetsInNewWorkbook( sal_Int32 SheetsInNewWorkbook ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL getEnableEvents() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnableEvents( sal_Bool bEnable ) throw (css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL wait( double time ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Range( const css::uno::Any& Cell1, const css::uno::Any& Cell2 ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ) throw ( css::uno::RuntimeException ); + virtual void SAL_CALL GoTo( const css::uno::Any& Reference, const css::uno::Any& Scroll ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Calculate() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Intersect( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Union( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Volatile( const css::uno::Any& Volatile ) throw (css::uno::RuntimeException ); + virtual css::uno::Any SAL_CALL Caller( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL MenuBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL GetOpenFilename( const css::uno::Any& FileFilter, const css::uno::Any& FilterIndex, const css::uno::Any& Title, const css::uno::Any& ButtonText, const css::uno::Any& MultiSelect ) throw (css::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::ooo::vba::XFileDialog > SAL_CALL getFileDialog() throw (::com::sun::star::uno::RuntimeException); //liminl 2009-08-12 add + virtual css::uno::Any SAL_CALL International( sal_Int32 Index ) throw (css::uno::RuntimeException); //liuchen 2009-11-26 + //2009-12-04 add by limingl + virtual css::uno::Any SAL_CALL GetSaveAsFilename( const ::com::sun::star::uno::Any& InitialFilename, const ::com::sun::star::uno::Any& FileFilter, const ::com::sun::star::uno::Any& FilterIndex, const ::com::sun::star::uno::Any& Title, const ::com::sun::star::uno::Any& ButtonText ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL Undo( ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL InchesToPoints( double Inches ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SC_VBA_APPLICATION_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaassistant.cxx b/sc/source/ui/vba/vbaassistant.cxx new file mode 100644 index 000000000000..43ab4589809c --- /dev/null +++ b/sc/source/ui/vba/vbaassistant.cxx @@ -0,0 +1,135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <sfx2/app.hxx> +#include <svtools/helpopt.hxx> + +#include <ooo/vba/office/MsoAnimationType.hpp> + +#include"vbaassistant.hxx" + + +using namespace com::sun::star; +using namespace ooo::vba; + +using namespace ooo::vba::office::MsoAnimationType; + +ScVbaAssistant::ScVbaAssistant( const uno::Reference< XHelperInterface > xParent, const uno::Reference< uno::XComponentContext > xContext ): ScVbaAssistantImpl_BASE( xParent, xContext ) +{ + m_bIsVisible = sal_False; + m_nPointsLeft = 795; + m_nPointsTop = 248; + m_sName = rtl::OUString::createFromAscii( "Clippit" ); + m_nAnimation = msoAnimationIdle; +} + +ScVbaAssistant::~ScVbaAssistant() +{ +} + +sal_Bool SAL_CALL ScVbaAssistant::getVisible() throw (uno::RuntimeException) +{ + return m_bIsVisible; +} + +void SAL_CALL ScVbaAssistant::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException) +{ + m_bIsVisible = bVisible; +} + +sal_Bool SAL_CALL ScVbaAssistant::getOn() throw (uno::RuntimeException) +{ + if( SvtHelpOptions().IsHelpAgentAutoStartMode() ) + return sal_True; + else + return sal_False; +} + +void SAL_CALL ScVbaAssistant::setOn( sal_Bool bOn ) throw (uno::RuntimeException) +{ + SvtHelpOptions().SetHelpAgentAutoStartMode( bOn ); + setVisible( bOn ); +} + + +::sal_Int32 SAL_CALL +ScVbaAssistant::getTop() throw (css::uno::RuntimeException) +{ + return m_nPointsTop; +} +void SAL_CALL +ScVbaAssistant::setTop( ::sal_Int32 _top ) throw (css::uno::RuntimeException) +{ + m_nPointsTop = _top; +} +::sal_Int32 SAL_CALL +ScVbaAssistant::getLeft() throw (css::uno::RuntimeException) +{ + return m_nPointsLeft; +} +void SAL_CALL +ScVbaAssistant::setLeft( ::sal_Int32 _left ) throw (css::uno::RuntimeException) +{ + m_nPointsLeft = _left; +} +::sal_Int32 SAL_CALL +ScVbaAssistant::getAnimation() throw (css::uno::RuntimeException) +{ + return m_nAnimation; +} +void SAL_CALL +ScVbaAssistant::setAnimation( ::sal_Int32 _animation ) throw (css::uno::RuntimeException) +{ + m_nAnimation = _animation; +} + +::rtl::OUString SAL_CALL +ScVbaAssistant::Name( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return m_sName; +} + +rtl::OUString& +ScVbaAssistant::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaAssistant") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaAssistant::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.Assistant" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaassistant.hxx b/sc/source/ui/vba/vbaassistant.hxx new file mode 100644 index 000000000000..7c8f93186e8c --- /dev/null +++ b/sc/source/ui/vba/vbaassistant.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_ASSISTANT_HXX +#define SC_VBA_ASSISTANT_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/XAssistant.hpp> + +#include <sfx2/sfxhelp.hxx> + +#include "excelvbahelper.hxx" +#include <vbahelper/vbahelperinterface.hxx> + +typedef ::cppu::WeakImplHelper1< ov::XAssistant > Assistant; +typedef InheritedHelperInterfaceImpl< Assistant > ScVbaAssistantImpl_BASE; + +class ScVbaAssistant : public ScVbaAssistantImpl_BASE +{ +private: + sal_Bool m_bIsVisible; + sal_Int32 m_nPointsLeft; + sal_Int32 m_nPointsTop; + rtl::OUString m_sName; + sal_Int32 m_nAnimation; +public: + ScVbaAssistant( const css::uno::Reference< ov::XHelperInterface > xParent, const css::uno::Reference< css::uno::XComponentContext > xContext ); + virtual ~ScVbaAssistant(); + // XAssistant + virtual sal_Bool SAL_CALL getOn() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOn( sal_Bool _on ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTop( ::sal_Int32 _top ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeft( ::sal_Int32 _left ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getAnimation() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAnimation( ::sal_Int32 _animation ) throw (css::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL Name( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_ASSISTANT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaaxes.cxx b/sc/source/ui/vba/vbaaxes.cxx new file mode 100644 index 000000000000..e528b949ff2c --- /dev/null +++ b/sc/source/ui/vba/vbaaxes.cxx @@ -0,0 +1,205 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbaaxes.hxx" +#include "vbaaxis.hxx" +#include "vbachart.hxx" +#include <ooo/vba/excel/XlAxisType.hpp> +#include <ooo/vba/excel/XlAxisGroup.hpp> +#include <ooo/vba/excel/XAxis.hpp> +#include <map> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; +using namespace ::ooo::vba::excel::XlAxisType; +using namespace ::ooo::vba::excel::XlAxisGroup; + +// each 'Item' in the Axes collection is indexed via 2 indexes, group and type. +// We need to 'flatten' this into a single index in order to be able to wrap +// iteration over the set of Axis(s) in a XIndexAccess implementation +// +typedef ::std::pair<sal_Int32, sal_Int32 > AxesCoordinate; // type and group combination +typedef ::std::vector< AxesCoordinate > vecAxesIndices; + +typedef ::cppu::WeakImplHelper1< container::XIndexAccess > AxisIndexWrapper_BASE; + +class EnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference<container::XIndexAccess > m_xIndexAccess; + sal_Int32 nIndex; +public: + EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + return m_xIndexAccess->getByIndex( nIndex++ ); + throw container::NoSuchElementException(); + } +}; + + +uno::Reference< excel::XAxis > +ScVbaAxes::createAxis( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 nType, sal_Int32 nAxisGroup ) throw ( uno::RuntimeException ) +{ + ScVbaChart* pChart = static_cast< ScVbaChart* >( xChart.get() ); + if ( !pChart ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Object failure, can't access chart implementation" ), uno::Reference< uno::XInterface >() ); + + uno::Reference< beans::XPropertySet > xAxisPropertySet; + if (((nType == xlCategory) || (nType == xlSeriesAxis) || (nType == xlValue))) + { + if ((nAxisGroup != xlPrimary) && (nAxisGroup != xlSecondary)) + throw script::BasicErrorException( rtl::OUString(), NULL, SbERR_METHOD_FAILED, rtl::OUString()); + xAxisPropertySet.set( pChart->getAxisPropertySet(nType, nAxisGroup), uno::UNO_QUERY_THROW ); + } + else + throw script::BasicErrorException( rtl::OUString(), NULL, SbERR_METHOD_FAILED, rtl::OUString()); + uno::Reference< XHelperInterface > xParent( xChart, uno::UNO_QUERY_THROW ); + return new ScVbaAxis( xParent, xContext, xAxisPropertySet, nType, nAxisGroup); +} + +class AxisIndexWrapper : public AxisIndexWrapper_BASE +{ + // if necessary for better performance we could change this into a map and cache the + // indices -> Axis, currently we create a new Axis object + // on each getByIndex + uno::Reference< uno::XComponentContext > mxContext; + vecAxesIndices mCoordinates; + uno::Reference< excel::XChart > mxChart; +public: + AxisIndexWrapper( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XChart >& xChart ) : mxContext( xContext ), mxChart( xChart ) + { + if ( mxChart.is() ) + { + ScVbaChart* pChart = static_cast< ScVbaChart* >( mxChart.get() ); + // primary + sal_Bool bBool = false; + uno::Reference< beans::XPropertySet > xDiagramPropertySet( pChart->xDiagramPropertySet() ); + if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasXAxis" ) ) ) >>= bBool ) && bBool ) + mCoordinates.push_back( AxesCoordinate( xlPrimary, xlCategory ) ); + if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasYAxis" ) ) ) >>= bBool ) && bBool ) + mCoordinates.push_back( AxesCoordinate( xlPrimary, xlSeriesAxis ) ); + + if ( pChart->is3D() ) + mCoordinates.push_back( AxesCoordinate( xlPrimary, xlValue ) ); + + // secondary + if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryXAxis" ) ) ) >>= bBool ) && bBool ) + mCoordinates.push_back( AxesCoordinate( xlSecondary, xlCategory ) ); + if ( ( xDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HasSecondaryYAxis" ) ) ) >>= bBool ) && bBool ) + mCoordinates.push_back( AxesCoordinate( xlSecondary, xlSeriesAxis ) ); + } + + } + virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mCoordinates.size(); } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException) + { + AxesCoordinate dIndexes = mCoordinates[ Index ]; + return uno::makeAny( ScVbaAxes::createAxis( mxChart, mxContext, dIndexes.second, dIndexes.first ) ); + } + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) + { + return excel::XAxis::static_type(0); + } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return ( mCoordinates.size() > 0 ); + } +}; + +uno::Reference< container::XIndexAccess > createIndexWrapper( const uno::Reference< excel::XChart >& xChart, const uno::Reference< uno::XComponentContext >& xContext ) +{ + return new AxisIndexWrapper( xContext, xChart ); +} + +// #FIXME The collection semantics will never work as this object is not yet initialised correctly +ScVbaAxes::ScVbaAxes( const uno::Reference< XHelperInterface >& xParent,const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< excel::XChart >& xChart ) : ScVbaAxes_BASE( xParent, xContext, createIndexWrapper( xChart, xContext )), moChartParent( xChart ) +{ +} + +uno::Type SAL_CALL +ScVbaAxes::getElementType() throw (css::uno::RuntimeException) +{ + return excel::XAxes::static_type(0); +} + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaAxes::createEnumeration() throw (css::uno::RuntimeException) +{ + return new EnumWrapper( m_xIndexAccess ); +} + +uno::Any SAL_CALL +ScVbaAxes::Item( const css::uno::Any& _nType, const css::uno::Any& _oAxisGroup) throw (css::uno::RuntimeException) +{ + // #TODO map the possible index combinations to a container::XIndexAccess wrapper impl + // using a vector of valid std::pair maybe? + // bodgy helperapi port bits + sal_Int32 nAxisGroup = xlPrimary; + sal_Int32 nType = -1; + if ( !_nType.hasValue() || ( ( _nType >>= nType ) == sal_False ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Axes::Item Failed to extract type" ), uno::Reference< uno::XInterface >() ); + + if ( _oAxisGroup.hasValue() ) + _oAxisGroup >>= nAxisGroup ; + + return uno::makeAny( createAxis( moChartParent, mxContext, nType, nAxisGroup ) ); +} + +uno::Any +ScVbaAxes::createCollectionObject(const css::uno::Any& aSource) +{ + return aSource; // pass through ( it's already an XAxis object +} + +rtl::OUString& +ScVbaAxes::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaAxes") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaAxes::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Axes" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaaxes.hxx b/sc/source/ui/vba/vbaaxes.hxx new file mode 100644 index 000000000000..a9ebf1a76138 --- /dev/null +++ b/sc/source/ui/vba/vbaaxes.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_AXES_HXX +#define SC_VBA_AXES_HXX +#include <ooo/vba/excel/XAxes.hpp> +#include <ooo/vba/excel/XAxis.hpp> +#include <ooo/vba/excel/XChart.hpp> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XAxes > ScVbaAxes_BASE; +class ScVbaAxes : public ScVbaAxes_BASE +{ + css::uno::Reference< ov::excel::XChart > moChartParent; // not the true parent I guess +public: + ScVbaAxes( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< ov::excel::XChart >& xChart ); + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + css::uno::Any SAL_CALL Item( const css::uno::Any& aIndex, const css::uno::Any& aIndex2 ) throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject(const css::uno::Any&); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + static css::uno::Reference< ov::excel::XAxis > createAxis( const css::uno::Reference< ov::excel::XChart >& xChart, const css::uno::Reference< css::uno::XComponentContext >& xContext, sal_Int32 nType, sal_Int32 nAxisGroup ) throw ( css::uno::RuntimeException ); +}; + +#endif //SC_VBA_AXES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaaxis.cxx b/sc/source/ui/vba/vbaaxis.cxx new file mode 100644 index 000000000000..9e17b30135a4 --- /dev/null +++ b/sc/source/ui/vba/vbaaxis.cxx @@ -0,0 +1,672 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbaaxis.hxx" +#include <ooo/vba/excel/XlAxisCrosses.hpp> +#include <ooo/vba/excel/XlAxisType.hpp> +#include <ooo/vba/excel/XlScaleType.hpp> +#include "vbaaxistitle.hxx" +#include "vbachart.hxx" +using namespace ::com::sun::star; +using namespace ::ooo::vba; +using namespace ::ooo::vba::excel::XlAxisCrosses; +using namespace ::ooo::vba::excel::XlAxisType; +using namespace ::ooo::vba::excel::XlScaleType; + +const rtl::OUString ORIGIN( RTL_CONSTASCII_USTRINGPARAM("Origin") ); +const rtl::OUString AUTOORIGIN( RTL_CONSTASCII_USTRINGPARAM("AutoOrigin") ); +const rtl::OUString VBA_MIN( RTL_CONSTASCII_USTRINGPARAM("Max") ); +const rtl::OUString VBA_MAX( RTL_CONSTASCII_USTRINGPARAM("Min") ); +ScVbaChart* +ScVbaAxis::getChartPtr() throw( uno::RuntimeException ) +{ + ScVbaChart* pChart = static_cast< ScVbaChart* >( moChartParent.get() ); + if ( !pChart ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("Can't access parent chart impl"), uno::Reference< uno::XInterface >() ); + return pChart; +} + +sal_Bool +ScVbaAxis::isValueAxis() throw( script::BasicErrorException ) +{ + if ( getType() == xlCategory ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return sal_True; +} + +ScVbaAxis::ScVbaAxis( const uno::Reference< XHelperInterface >& xParent,const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, sal_Int32 _nType, sal_Int32 _nGroup ) : ScVbaAxis_BASE( xParent, xContext ), mxPropertySet( _xPropertySet ), mnType( _nType ), mnGroup( _nGroup ), bCrossesAreCustomized( sal_False ) +{ + oShapeHelper.reset( new ShapeHelper( uno::Reference< drawing::XShape >( mxPropertySet, uno::UNO_QUERY ) ) ); + moChartParent.set( xParent, uno::UNO_QUERY_THROW ); + setType(_nType); + setCrosses(xlAxisCrossesAutomatic); +} + +void SAL_CALL +ScVbaAxis::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< lang::XComponent > xComponent( mxPropertySet, uno::UNO_QUERY_THROW ); + xComponent->dispose(); +} + + uno::Reference< ::ooo::vba::excel::XAxisTitle > SAL_CALL +ScVbaAxis::getAxisTitle( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< excel::XAxisTitle > xAxisTitle; + try + { + ScVbaChart* pChart = getChartPtr(); + + if (getHasTitle() ) + { + int nType = getType(); + switch(nType) + { + case xlCategory: + xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisXSupplier->getXAxisTitle()); + break; + case xlSeriesAxis: + xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisZSupplier->getZAxisTitle()); + break; + default: // xlValue: + xAxisTitle = new ScVbaAxisTitle(this, mxContext, pChart->xAxisYSupplier->getYAxisTitle()); + break; + } + } + } + catch (uno::Exception& e) + { + DebugHelper::exception(e); + } + return xAxisTitle; + +} + +void SAL_CALL +ScVbaAxis::setDisplayUnit( ::sal_Int32 /*DisplayUnit*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); +} + +::sal_Int32 SAL_CALL +ScVbaAxis::getDisplayUnit( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + return -1; +} + +void SAL_CALL +ScVbaAxis::setCrosses( ::sal_Int32 _nCrosses ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + double fNum = 0.0; + switch (_nCrosses) + { + case xlAxisCrossesAutomatic: //Microsoft Excel sets the axis crossing point. + mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny( sal_True ) ); + bCrossesAreCustomized = sal_False; + return; + case xlAxisCrossesMinimum: // The axis crosses at the minimum value. + mxPropertySet->getPropertyValue(VBA_MIN) >>= fNum; + setCrossesAt( fNum ); + bCrossesAreCustomized = sal_False; + break; + case xlAxisCrossesMaximum: // The axis crosses at the maximum value. + mxPropertySet->getPropertyValue(VBA_MAX) >>= fNum; + setCrossesAt(fNum); + bCrossesAreCustomized = sal_False; + break; + default: //xlAxisCrossesCustom + bCrossesAreCustomized = sal_True; + break; + } + mxPropertySet->setPropertyValue(AUTOORIGIN, uno::makeAny(sal_False) ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} +::sal_Int32 SAL_CALL +ScVbaAxis::getCrosses( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Int32 nCrosses = xlAxisCrossesCustom; + try + { + sal_Bool bisAutoOrigin = sal_False; + mxPropertySet->getPropertyValue(AUTOORIGIN) >>= bisAutoOrigin; + if (bisAutoOrigin) + nCrosses = xlAxisCrossesAutomatic; + else + { + if (bCrossesAreCustomized) + nCrosses = xlAxisCrossesCustom; + else + { + double forigin = 0.0; + mxPropertySet->getPropertyValue(ORIGIN) >>= forigin; +//obsolete double fmax = AnyConverter.toDouble(mxPropertySet.getPropertyValue("Max")); + double fmin = 0.0; + mxPropertySet->getPropertyValue(VBA_MIN) >>= fmin; + if (forigin == fmin) + nCrosses = xlAxisCrossesMinimum; + else + nCrosses = xlAxisCrossesMaximum; + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + return nCrosses; +} + + void SAL_CALL +ScVbaAxis::setCrossesAt( double _fCrossesAt ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { +// if (getCrosses() == xlAxisCrossesCustom){ + setMaximumScaleIsAuto( sal_False ); + setMinimumScaleIsAuto( sal_False ); + mxPropertySet->setPropertyValue(ORIGIN, uno::makeAny(_fCrossesAt)); +// } + } + catch (uno::Exception& e) + { + DebugHelper::exception(e); + } +} + + double SAL_CALL +ScVbaAxis::getCrossesAt( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + double fCrosses = 0.0; + try + { + mxPropertySet->getPropertyValue(ORIGIN) >>= fCrosses; + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return fCrosses; +} + +void SAL_CALL +ScVbaAxis::setType( ::sal_Int32 _nType ) throw (script::BasicErrorException, uno::RuntimeException) +{ + mnType = _nType; +} + +::sal_Int32 SAL_CALL +ScVbaAxis::getType( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return mnType; +} + +void SAL_CALL +ScVbaAxis::setHasTitle( ::sal_Bool _bHasTitle ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + ScVbaChart* pChart = getChartPtr(); + sal_Int32 nType = getType(); + switch(nType) + { + case xlCategory: + pChart->mxDiagramPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasXAxisTitle")), uno::makeAny(_bHasTitle)); + break; + case xlSeriesAxis: + pChart->mxDiagramPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasZAxisTitle")), uno::makeAny(_bHasTitle)); + break; + default: // xlValue: + pChart->mxDiagramPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasYAxisTitle")), uno::makeAny(_bHasTitle)); + } + + } + catch (uno::Exception& e) + { + DebugHelper::exception(e); + } +} + + ::sal_Bool SAL_CALL +ScVbaAxis::getHasTitle( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bHasTitle = sal_False; + try + { + ScVbaChart* pChart = getChartPtr(); + int nType = getType(); + switch(nType) + { + case xlCategory: + pChart->mxDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasXAxisTitle")) ) >>= bHasTitle; + break; + case xlSeriesAxis: + pChart->mxDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasZAxisTitle")) ) >>= bHasTitle; + break; + default: // xlValue: + pChart->mxDiagramPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HasYAxisTitle")) ) >>= bHasTitle; + } + } + catch (uno::Exception& e) + { + DebugHelper::exception(e); + } + return bHasTitle; +} + +void SAL_CALL +ScVbaAxis::setMinorUnit( double _fMinorUnit ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepHelp") ), uno::makeAny(_fMinorUnit)); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +double SAL_CALL +ScVbaAxis::getMinorUnit( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + double fMinor = 1.0; + try + { + if (isValueAxis()) + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepHelp"))) >>= fMinor; + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return fMinor; +} + +void SAL_CALL +ScVbaAxis::setMinorUnitIsAuto( ::sal_Bool _bMinorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepHelp" ) ), uno::makeAny(_bMinorUnitIsAuto)); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + + ::sal_Bool SAL_CALL +ScVbaAxis::getMinorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bIsAuto = sal_False; + try + { + if (isValueAxis()) + { + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepHelp")) ) >>= bIsAuto; + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return bIsAuto; +} + +void SAL_CALL +ScVbaAxis::setReversePlotOrder( ::sal_Bool /*ReversePlotOrder*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); +} + +::sal_Bool SAL_CALL +ScVbaAxis::getReversePlotOrder( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + return sal_False; +} + +void SAL_CALL +ScVbaAxis::setMajorUnit( double _fMajorUnit ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + { + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepMain")), uno::makeAny(_fMajorUnit)); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +double SAL_CALL +ScVbaAxis::getMajorUnit( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + double fMax = 1.0; + try + { + if (isValueAxis()) + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("StepMain"))) >>= fMax; + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + return fMax; +} + +void SAL_CALL +ScVbaAxis::setMajorUnitIsAuto( ::sal_Bool _bMajorUnitIsAuto ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + { + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepMain" ) ), uno::makeAny( _bMajorUnitIsAuto )); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +::sal_Bool SAL_CALL +ScVbaAxis::getMajorUnitIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bIsAuto = sal_False; + try + { + if (isValueAxis()) + { + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoStepMain"))) >>= bIsAuto; + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return bIsAuto; +} + +void SAL_CALL +ScVbaAxis::setMaximumScale( double _fMaximumScale ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if ( isValueAxis() ) + { + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Max" ) ), uno::makeAny(_fMaximumScale)); + } + } + catch ( uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +double SAL_CALL +ScVbaAxis::getMaximumScale( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + double fMax = 1.0; + try + { + if (isValueAxis()) + { + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Max" ))) >>= fMax; + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return fMax; + +} + +void SAL_CALL +ScVbaAxis::setMaximumScaleIsAuto( ::sal_Bool _bMaximumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if ( isValueAxis() ) + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoMax" ) ), uno::makeAny( _bMaximumScaleIsAuto )); + + } + catch ( uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + + +::sal_Bool SAL_CALL +ScVbaAxis::getMaximumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bIsAuto = sal_False; + try + { + if (isValueAxis()) + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoMax" )) ) >>= bIsAuto; + } + catch ( uno::Exception& ) + { + DebugHelper::exception( SbERR_METHOD_FAILED, rtl::OUString() ); + } + return bIsAuto; +} + +void SAL_CALL +ScVbaAxis::setMinimumScale( double _fMinimumScale ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Min") ), uno::makeAny( _fMinimumScale ) ); + } + catch ( uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +double SAL_CALL +ScVbaAxis::getMinimumScale( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + double fMin = 0.0; + try + { + if (isValueAxis()) + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Min") )) >>= fMin; + } + catch (uno::Exception& e) + { + DebugHelper::exception(e); + } + return fMin; +} + +void SAL_CALL +ScVbaAxis::setMinimumScaleIsAuto( ::sal_Bool _bMinimumScaleIsAuto ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + { + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoMin") ), uno::makeAny(_bMinimumScaleIsAuto)); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +::sal_Bool SAL_CALL +ScVbaAxis::getMinimumScaleIsAuto( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bIsAuto = sal_False; + try + { + if (isValueAxis()) + { + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoMin")) ) >>= bIsAuto; + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return bIsAuto; +} + +::sal_Int32 SAL_CALL +ScVbaAxis::getAxisGroup( ) throw (uno::RuntimeException) +{ + return mnGroup; +} + +void SAL_CALL +ScVbaAxis::setScaleType( ::sal_Int32 _nScaleType ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + if (isValueAxis()) + { + switch (_nScaleType) + { + case xlScaleLinear: + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Logarithmic" ) ), uno::makeAny( sal_False ) ); + break; + case xlScaleLogarithmic: + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Logarithmic" ) ), uno::makeAny( sal_True ) ); + break; + default: + // According to MS the paramenter is ignored and no Error is thrown + break; + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +::sal_Int32 SAL_CALL +ScVbaAxis::getScaleType( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Int32 nScaleType = xlScaleLinear; + try + { + if (isValueAxis()) + { + sal_Bool bisLogarithmic = sal_False; + mxPropertySet->getPropertyValue( rtl::OUString( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Logarithmic"))) ) >>= bisLogarithmic; + if (bisLogarithmic) + nScaleType = xlScaleLogarithmic; + else + nScaleType = xlScaleLinear; + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return nScaleType; +} + +double SAL_CALL +ScVbaAxis::getHeight( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return oShapeHelper->getHeight(); +} + +void SAL_CALL ScVbaAxis::setHeight( double height ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + oShapeHelper->setHeight( height ); +} +double SAL_CALL ScVbaAxis::getWidth( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return oShapeHelper->getWidth( ); +} +void SAL_CALL ScVbaAxis::setWidth( double width ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + oShapeHelper->setWidth( width ); +} +double SAL_CALL ScVbaAxis::getTop( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return oShapeHelper->getTop( ); +} +void SAL_CALL ScVbaAxis::setTop( double top ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + oShapeHelper->setTop( top ); +} +double SAL_CALL ScVbaAxis::getLeft( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return oShapeHelper->getLeft( ); +} +void SAL_CALL ScVbaAxis::setLeft( double left ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + oShapeHelper->setLeft( left ); +} + +rtl::OUString& +ScVbaAxis::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaAxis") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaAxis::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Axis" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaaxis.hxx b/sc/source/ui/vba/vbaaxis.hxx new file mode 100644 index 000000000000..aa42ded186e3 --- /dev/null +++ b/sc/source/ui/vba/vbaaxis.hxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_AXIS_HXX +#define SC_VBA_AXOS_HXX +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/excel/XAxis.hpp> +#include <ooo/vba/excel/XChart.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <memory> +typedef InheritedHelperInterfaceImpl1< ov::excel::XAxis > ScVbaAxis_BASE; +class ScVbaChart; +class ScVbaAxis : public ScVbaAxis_BASE +{ + css::uno::Reference< ov::excel::XChart > moChartParent; + css::uno::Reference< css::beans::XPropertySet > mxPropertySet; + sal_Int32 mnType; + sal_Int32 mnGroup; + sal_Int32 mnCrosses; + sal_Bool bCrossesAreCustomized; + ScVbaChart* getChartPtr() throw( css::uno::RuntimeException ); + sal_Bool isValueAxis() throw( css::script::BasicErrorException ); + std::auto_ptr<ov::ShapeHelper> oShapeHelper; + +public: + ScVbaAxis( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, sal_Int32 _nType, sal_Int32 _nGroup ); + // Methods + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::excel::XAxisTitle > SAL_CALL getAxisTitle( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setDisplayUnit( ::sal_Int32 DisplayUnit ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getDisplayUnit( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setCrosses( ::sal_Int32 Crosses ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getCrosses( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setCrossesAt( double CrossesAt ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getCrossesAt( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setType( ::sal_Int32 Type ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getType( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setHasTitle( ::sal_Bool HasTitle ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getHasTitle( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMinorUnit( double MinorUnit ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getMinorUnit( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMinorUnitIsAuto( ::sal_Bool MinorUnitIsAuto ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getMinorUnitIsAuto( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setReversePlotOrder( ::sal_Bool ReversePlotOrder ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getReversePlotOrder( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMajorUnit( double MajorUnit ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getMajorUnit( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMajorUnitIsAuto( ::sal_Bool MajorUnitIsAuto ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getMajorUnitIsAuto( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMaximumScale( double MaximumScale ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getMaximumScale( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMaximumScaleIsAuto( ::sal_Bool MaximumScaleIsAuto ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getMaximumScaleIsAuto( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMinimumScale( double MinimumScale ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getMinimumScale( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMinimumScaleIsAuto( ::sal_Bool MinimumScaleIsAuto ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getMinimumScaleIsAuto( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getAxisGroup( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL setScaleType( ::sal_Int32 ScaleType ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getScaleType( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getHeight( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setHeight( double height ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getWidth( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setWidth( double width ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getTop( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setTop( double top ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual double SAL_CALL getLeft( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setLeft( double left ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_AXIS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaaxistitle.cxx b/sc/source/ui/vba/vbaaxistitle.cxx new file mode 100644 index 000000000000..2499fa756891 --- /dev/null +++ b/sc/source/ui/vba/vbaaxistitle.cxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaaxistitle.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +ScVbaAxisTitle::ScVbaAxisTitle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& _xTitleShape ) : AxisTitleBase( xParent, xContext, _xTitleShape ) +{ +} + +rtl::OUString& +ScVbaAxisTitle::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaAxisTitle") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaAxisTitle::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + uno::Sequence< rtl::OUString > BaseServiceNames = AxisTitleBase::getServiceNames(); + aServiceNames.realloc( BaseServiceNames.getLength() + 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.AxisTitle" ) ); + for ( sal_Int32 index = 1; index < (BaseServiceNames.getLength() + 1); ++index ) + aServiceNames[ index ] = BaseServiceNames[ index ]; + } + return aServiceNames; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaaxistitle.hxx b/sc/source/ui/vba/vbaaxistitle.hxx new file mode 100644 index 000000000000..4ab2c5e06c90 --- /dev/null +++ b/sc/source/ui/vba/vbaaxistitle.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_AXISTITLE_HXX +#define SC_VBA_AXISTITLE_HXX + +#include "vbatitle.hxx" +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XAxisTitle.hpp> + +typedef TitleImpl< cppu::WeakImplHelper1< ov::excel::XAxisTitle > > AxisTitleBase; + +class ScVbaAxisTitle : public AxisTitleBase +{ +public: + ScVbaAxisTitle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& _xTitleShape ); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaborders.cxx b/sc/source/ui/vba/vbaborders.cxx new file mode 100644 index 000000000000..0cb28dbc6556 --- /dev/null +++ b/sc/source/ui/vba/vbaborders.cxx @@ -0,0 +1,577 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaborders.hxx" + +#include <sal/macros.h> +#include <cppuhelper/implbase3.hxx> +#include <ooo/vba/excel/XlBordersIndex.hpp> +#include <ooo/vba/excel/XlBorderWeight.hpp> +#include <ooo/vba/excel/XlLineStyle.hpp> +#include <ooo/vba/excel/XlColorIndex.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/table/TableBorder.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include "vbapalette.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; +using namespace ::ooo::vba::excel; + + +typedef ::cppu::WeakImplHelper1<container::XIndexAccess > RangeBorders_Base; +typedef InheritedHelperInterfaceImpl1<excel::XBorder > ScVbaBorder_Base; + +// #TODO sort these indexes to match the order in which Excel iterates over the +// borders, the enumeration will match the order in this list +static const sal_Int16 supportedIndexTable[] = { XlBordersIndex::xlEdgeLeft, XlBordersIndex::xlEdgeTop, XlBordersIndex::xlEdgeBottom, XlBordersIndex::xlEdgeRight, XlBordersIndex::xlDiagonalDown, XlBordersIndex::xlDiagonalUp, XlBordersIndex::xlInsideVertical, XlBordersIndex::xlInsideHorizontal }; + +const static rtl::OUString sTableBorder( RTL_CONSTASCII_USTRINGPARAM("TableBorder") ); + +// Equiv widths in in 1/100 mm +const static sal_Int32 OOLineThin = 35; +const static sal_Int32 OOLineMedium = 88; +const static sal_Int32 OOLineThick = 141; +const static sal_Int32 OOLineHairline = 2; + +class ScVbaBorder : public ScVbaBorder_Base +{ +private: + uno::Reference< beans::XPropertySet > m_xProps; + sal_Int32 m_LineType; + ScVbaPalette m_Palette; + bool setBorderLine( table::BorderLine& rBorderLine ) + { + table::TableBorder aTableBorder; + m_xProps->getPropertyValue( sTableBorder ) >>= aTableBorder; + + switch ( m_LineType ) + { + case XlBordersIndex::xlEdgeLeft: + aTableBorder.IsLeftLineValid = sal_True; + aTableBorder.LeftLine= rBorderLine; + break; + case XlBordersIndex::xlEdgeTop: + aTableBorder.IsTopLineValid = sal_True; + aTableBorder.TopLine = rBorderLine; + break; + + case XlBordersIndex::xlEdgeBottom: + aTableBorder.IsBottomLineValid = sal_True; + aTableBorder.BottomLine = rBorderLine; + break; + case XlBordersIndex::xlEdgeRight: + aTableBorder.IsRightLineValid = sal_True; + aTableBorder.RightLine = rBorderLine; + break; + case XlBordersIndex::xlInsideVertical: + aTableBorder.IsVerticalLineValid = sal_True; + aTableBorder.VerticalLine = rBorderLine; + break; + case XlBordersIndex::xlInsideHorizontal: + aTableBorder.IsHorizontalLineValid = sal_True; + aTableBorder.HorizontalLine = rBorderLine; + break; + case XlBordersIndex::xlDiagonalDown: + case XlBordersIndex::xlDiagonalUp: + // #TODO have to ignore at the momement, would be + // nice to investigate what we can do here + break; + default: + return false; + } + m_xProps->setPropertyValue( sTableBorder, uno::makeAny(aTableBorder) ); + return true; + } + + bool getBorderLine( table::BorderLine& rBorderLine ) + { + table::TableBorder aTableBorder; + m_xProps->getPropertyValue( sTableBorder ) >>= aTableBorder; + switch ( m_LineType ) + { + case XlBordersIndex::xlEdgeLeft: + if ( aTableBorder.IsLeftLineValid ) + rBorderLine = aTableBorder.LeftLine; + break; + case XlBordersIndex::xlEdgeTop: + if ( aTableBorder.IsTopLineValid ) + rBorderLine = aTableBorder.TopLine; + break; + + case XlBordersIndex::xlEdgeBottom: + if ( aTableBorder.IsBottomLineValid ) + rBorderLine = aTableBorder.BottomLine; + break; + case XlBordersIndex::xlEdgeRight: + if ( aTableBorder.IsRightLineValid ) + rBorderLine = aTableBorder.RightLine; + break; + case XlBordersIndex::xlInsideVertical: + if ( aTableBorder.IsVerticalLineValid ) + rBorderLine = aTableBorder.VerticalLine; + break; + case XlBordersIndex::xlInsideHorizontal: + if ( aTableBorder.IsHorizontalLineValid ) + rBorderLine = aTableBorder.HorizontalLine; + break; + + case XlBordersIndex::xlDiagonalDown: + case XlBordersIndex::xlDiagonalUp: + // #TODO have to ignore at the momement, would be + // nice to investigate what we can do here + break; + default: + return false; + } + return true; + } + ScVbaBorder(); // no impl +protected: + virtual rtl::OUString& getServiceImplName() + { + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaBorder") ); + return sImplName; + } + virtual css::uno::Sequence<rtl::OUString> getServiceNames() + { + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Border" ) ); + } + return aServiceNames; + } +public: + ScVbaBorder( const uno::Reference< beans::XPropertySet > & xProps, const uno::Reference< uno::XComponentContext >& xContext, sal_Int32 lineType, ScVbaPalette& rPalette) : ScVbaBorder_Base( uno::Reference< XHelperInterface >( xProps, uno::UNO_QUERY ), xContext ), m_xProps( xProps ), m_LineType( lineType ), m_Palette( rPalette ) {} + + // XBorder + uno::Any SAL_CALL getColor() throw (uno::RuntimeException) + { + table::BorderLine aBorderLine; + if ( getBorderLine( aBorderLine ) ) + return uno::makeAny( OORGBToXLRGB( aBorderLine.Color ) ); + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No Implementation available" ) ), uno::Reference< uno::XInterface >() ); + } + void SAL_CALL setColor( const uno::Any& _color ) throw (uno::RuntimeException) + { + sal_Int32 nColor = 0; + _color >>= nColor; + table::BorderLine aBorderLine; + if ( getBorderLine( aBorderLine ) ) + { + aBorderLine.Color = XLRGBToOORGB( nColor ); + setBorderLine( aBorderLine ); + } + else + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "No Implementation available" ) ), uno::Reference< uno::XInterface >() ); + } + + uno::Any SAL_CALL getColorIndex() throw (uno::RuntimeException) + { + sal_Int32 nColor = 0; + XLRGBToOORGB( getColor() ) >>= nColor; + uno::Reference< container::XIndexAccess > xIndex = m_Palette.getPalette(); + sal_Int32 nElems = xIndex->getCount(); + sal_Int32 nIndex = -1; + for ( sal_Int32 count=0; count<nElems; ++count ) + { + sal_Int32 nPaletteColor = 0; + xIndex->getByIndex( count ) >>= nPaletteColor; + if ( nPaletteColor == nColor ) + { + nIndex = count + 1; + break; + } + } + return uno::makeAny(nIndex); + } + + void SAL_CALL setColorIndex( const uno::Any& _colorindex ) throw (uno::RuntimeException) + { + sal_Int32 nColor = 0; + _colorindex >>= nColor; + if ( !nColor || nColor == XlColorIndex::xlColorIndexAutomatic ) + nColor = 1; + setColor( OORGBToXLRGB( m_Palette.getPalette()->getByIndex( --nColor ) ) ); + } + uno::Any SAL_CALL getWeight() throw (uno::RuntimeException) + { + table::BorderLine aBorderLine; + if ( getBorderLine( aBorderLine ) ) + { + switch ( aBorderLine.OuterLineWidth ) + { + case 0: // Thin = default OO thickness + case OOLineThin: + return uno::makeAny( XlBorderWeight::xlThin ); + case OOLineMedium: + return uno::makeAny( XlBorderWeight::xlMedium ); + case OOLineThick: + return uno::makeAny( XlBorderWeight::xlThick ); + case OOLineHairline: + return uno::makeAny( XlBorderWeight::xlHairline ); + default: + break; + } + } + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() ); + } + void SAL_CALL setWeight( const uno::Any& _weight ) throw (uno::RuntimeException) + { + sal_Int32 nWeight = 0; + _weight >>= nWeight; + table::BorderLine aBorderLine; + if ( getBorderLine( aBorderLine ) ) + { + switch ( nWeight ) + { + case XlBorderWeight::xlThin: + aBorderLine.OuterLineWidth = OOLineThin; + break; + case XlBorderWeight::xlMedium: + aBorderLine.OuterLineWidth = OOLineMedium; + break; + case XlBorderWeight::xlThick: + aBorderLine.OuterLineWidth = OOLineThick; + break; + case XlBorderWeight::xlHairline: + aBorderLine.OuterLineWidth = OOLineHairline; + break; + default: + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Bad param" ) ), uno::Reference< uno::XInterface >() ); + } + setBorderLine( aBorderLine ); + } + else + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() ); + } + + uno::Any SAL_CALL getLineStyle() throw (uno::RuntimeException) + { + // always return xlContinuous; + return uno::makeAny( XlLineStyle::xlContinuous ); + } + void SAL_CALL setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException) + { + // Urk no choice but to silently ignore we don't support this attribute + // #TODO would be nice to support the excel line styles + sal_Int32 nLineStyle = 0; + _linestyle >>= nLineStyle; + table::BorderLine aBorderLine; + if ( getBorderLine( aBorderLine ) ) + { + switch ( nLineStyle ) + { + case XlLineStyle::xlContinuous: + case XlLineStyle::xlDash: + case XlLineStyle::xlDashDot: + case XlLineStyle::xlDashDotDot: + case XlLineStyle::xlDot: + case XlLineStyle::xlDouble: + case XlLineStyle::xlLineStyleNone: + case XlLineStyle::xlSlantDashDot: + break; + default: + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Bad param" ) ), uno::Reference< uno::XInterface >() ); + } + setBorderLine( aBorderLine ); + } + else + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Method failed" ) ), uno::Reference< uno::XInterface >() ); + } +}; + +class RangeBorders : public RangeBorders_Base +{ +private: + uno::Reference< table::XCellRange > m_xRange; + uno::Reference< uno::XComponentContext > m_xContext; + ScVbaPalette m_Palette; + sal_Int32 getTableIndex( sal_Int32 nConst ) + { + // hokay return position of the index in the table + sal_Int32 nIndexes = getCount(); + sal_Int32 realIndex = 0; + const sal_Int16* pTableEntry = supportedIndexTable; + for ( ; realIndex < nIndexes; ++realIndex, ++pTableEntry ) + { + if ( *pTableEntry == nConst ) + return realIndex; + } + return getCount(); // error condition + } +public: + RangeBorders( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< uno::XComponentContext > & xContext, ScVbaPalette& rPalette ) : m_xRange( xRange ), m_xContext( xContext ), m_Palette( rPalette ) + { + } + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return SAL_N_ELEMENTS( supportedIndexTable ); + } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + + sal_Int32 nIndex = getTableIndex( Index ); + if ( nIndex >= 0 && nIndex < getCount() ) + { + uno::Reference< beans::XPropertySet > xProps( m_xRange, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< excel::XBorder >( new ScVbaBorder( xProps, m_xContext, supportedIndexTable[ nIndex ], m_Palette )) ); + } + throw lang::IndexOutOfBoundsException(); + } + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return excel::XBorder::static_type(0); + } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return sal_True; + } +}; + +uno::Reference< container::XIndexAccess > +rangeToBorderIndexAccess( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< uno::XComponentContext > & xContext, ScVbaPalette& rPalette ) +{ + return new RangeBorders( xRange, xContext, rPalette ); +} + +class RangeBorderEnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference<container::XIndexAccess > m_xIndexAccess; + sal_Int32 nIndex; +public: + RangeBorderEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + return m_xIndexAccess->getByIndex( nIndex++ ); + throw container::NoSuchElementException(); + } +}; + +ScVbaBorders::ScVbaBorders( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< table::XCellRange >& xRange, ScVbaPalette& rPalette ): ScVbaBorders_BASE( xParent, xContext, rangeToBorderIndexAccess( xRange ,xContext, rPalette ) ), bRangeIsSingleCell( false ) +{ + uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW ); + if ( xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 ) + bRangeIsSingleCell = true; + m_xProps.set( xRange, uno::UNO_QUERY_THROW ); +} + +uno::Reference< container::XEnumeration > +ScVbaBorders::createEnumeration() throw (uno::RuntimeException) +{ + return new RangeBorderEnumWrapper( m_xIndexAccess ); +} + +uno::Any +ScVbaBorders::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; // its already a Border object +} + +uno::Type +ScVbaBorders::getElementType() throw (uno::RuntimeException) +{ + return excel::XBorders::static_type(0); +} + +uno::Any +ScVbaBorders::getItemByIntIndex( const sal_Int32 nIndex ) throw (uno::RuntimeException) +{ + return createCollectionObject( m_xIndexAccess->getByIndex( nIndex ) ); +} + + +uno::Any SAL_CALL ScVbaBorders::getColor() throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + uno::Any color; + for( sal_Int32 i = 0; i < count ; i++ ) + { + if( XlBordersIndex::xlDiagonalDown != supportedIndexTable[i] && XlBordersIndex::xlDiagonalUp != supportedIndexTable[i] ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + if( color.hasValue() ) + { + if( color != xBorder->getColor() ) + return uno::makeAny( uno::Reference< uno::XInterface >() ); + } + else + color = xBorder->getColor(); + } + } + return color; +} +void SAL_CALL ScVbaBorders::setColor( const uno::Any& _color ) throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + for( sal_Int32 i = 0; i < count ; i++ ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + xBorder->setColor( _color ); + } +} +uno::Any SAL_CALL ScVbaBorders::getColorIndex() throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + uno::Any nColorIndex; + for( sal_Int32 i = 0; i < count ; i++ ) + { + if( XlBordersIndex::xlDiagonalDown != supportedIndexTable[i] && XlBordersIndex::xlDiagonalUp != supportedIndexTable[i] ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + if( nColorIndex.hasValue() ) + { + if( nColorIndex != xBorder->getColorIndex() ) + return uno::makeAny( uno::Reference< uno::XInterface >() ); + } + else + nColorIndex = xBorder->getColorIndex(); + } + } + return nColorIndex; +} +void SAL_CALL ScVbaBorders::setColorIndex( const uno::Any& _colorindex ) throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + for( sal_Int32 i = 0; i < count ; i++ ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + xBorder->setColorIndex( _colorindex ); + } +} + +bool +lcl_areAllLineWidthsSame( const table::TableBorder& maTableBorder, bool bIsCell ) +{ + + bool bRes = false; + if (bIsCell) + { + bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) && +(maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) && +(maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth)); + } + else + { + bRes = ((maTableBorder.TopLine.OuterLineWidth == maTableBorder.BottomLine.OuterLineWidth) && +(maTableBorder.TopLine.OuterLineWidth == maTableBorder.LeftLine.OuterLineWidth) && +(maTableBorder.TopLine.OuterLineWidth == maTableBorder.HorizontalLine.OuterLineWidth) && +(maTableBorder.TopLine.OuterLineWidth == maTableBorder.VerticalLine.OuterLineWidth) && +(maTableBorder.TopLine.OuterLineWidth == maTableBorder.RightLine.OuterLineWidth)); + } + return bRes; +} + +uno::Any SAL_CALL ScVbaBorders::getLineStyle() throw (uno::RuntimeException) +{ + table::TableBorder maTableBorder; + m_xProps->getPropertyValue( sTableBorder ) >>= maTableBorder; + + sal_Int32 aLinestyle = XlLineStyle::xlLineStyleNone; + + if ( lcl_areAllLineWidthsSame( maTableBorder, bRangeIsSingleCell )) + { + if (maTableBorder.TopLine.LineDistance != 0) + { + aLinestyle = XlLineStyle::xlDouble; + } + else if ( maTableBorder.TopLine.OuterLineWidth != 0 ) + { + aLinestyle = XlLineStyle::xlContinuous; + } + } + return uno::makeAny( aLinestyle ); +} +void SAL_CALL ScVbaBorders::setLineStyle( const uno::Any& _linestyle ) throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + for( sal_Int32 i = 0; i < count ; i++ ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + xBorder->setLineStyle( _linestyle ); + } +} +uno::Any SAL_CALL ScVbaBorders::getWeight() throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + uno::Any weight; + for( sal_Int32 i = 0; i < count ; i++ ) + { + if( XlBordersIndex::xlDiagonalDown != supportedIndexTable[i] && XlBordersIndex::xlDiagonalUp != supportedIndexTable[i] ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + if( weight.hasValue() ) + { + if( weight != xBorder->getWeight() ) + return uno::makeAny( uno::Reference< uno::XInterface >() ); + } + else + weight = xBorder->getWeight(); + } + } + return weight; +} +void SAL_CALL ScVbaBorders::setWeight( const uno::Any& _weight ) throw (uno::RuntimeException) +{ + sal_Int32 count = getCount(); + for( sal_Int32 i = 0; i < count ; i++ ) + { + uno::Reference< XBorder > xBorder( getItemByIntIndex( supportedIndexTable[i] ), uno::UNO_QUERY_THROW ); + xBorder->setWeight( _weight ); + } +} + + +rtl::OUString& +ScVbaBorders::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaBorders") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaBorders::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Borders" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaborders.hxx b/sc/source/ui/vba/vbaborders.hxx new file mode 100644 index 000000000000..d6784691c488 --- /dev/null +++ b/sc/source/ui/vba/vbaborders.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_BORDERS_HXX +#define SC_VBA_BORDERS_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XBorders.hpp> + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + + +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XBorders > ScVbaBorders_BASE; +class ScVbaPalette; +class ScVbaBorders : public ScVbaBorders_BASE +{ + // XEnumerationAccess + virtual css::uno::Any getItemByIntIndex( const sal_Int32 nIndex ) throw (css::uno::RuntimeException); + bool bRangeIsSingleCell; + css::uno::Reference< css::beans::XPropertySet > m_xProps; +public: + ScVbaBorders( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::table::XCellRange >& xRange, ScVbaPalette& rPalette ); + virtual ~ScVbaBorders() {} + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + + // XBorders + + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + virtual css::uno::Any SAL_CALL getColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setColor( const css::uno::Any& _color ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getColorIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setColorIndex( const css::uno::Any& _colorindex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getLineStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLineStyle( const css::uno::Any& _linestyle ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getWeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWeight( const css::uno::Any& ) throw (css::uno::RuntimeException); + // xxxxBASE + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_BORDERS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacharacters.cxx b/sc/source/ui/vba/vbacharacters.cxx new file mode 100644 index 000000000000..5d12facad12b --- /dev/null +++ b/sc/source/ui/vba/vbacharacters.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacharacters.hxx" + +#include "vbaglobals.hxx" +#include "vbafont.hxx" + + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaCharacters::ScVbaCharacters( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const ScVbaPalette& dPalette, const uno::Reference< text::XSimpleText>& xRange,const css::uno::Any& Start, const css::uno::Any& Length, sal_Bool Replace ) throw ( css::lang::IllegalArgumentException ) : ScVbaCharacters_BASE( xParent, xContext ), m_xSimpleText(xRange), m_aPalette( dPalette), nLength(-1), nStart(1), bReplace( Replace ) +{ + Start >>= nStart; + if ( nStart < 1 ) + nStart = 1; // silently correct user error ( as ms ) + nStart--; // OOo is 0 based + Length >>=nLength; + uno::Reference< text::XTextCursor > xTextCursor( m_xSimpleText->createTextCursor(), uno::UNO_QUERY_THROW ); + xTextCursor->collapseToStart(); + if ( nStart ) + { + if ( ( nStart + 1 ) > m_xSimpleText->getString().getLength() ) + //nStart = m_xSimpleText->getString().getLength(); + xTextCursor->gotoEnd( sal_False ); + xTextCursor->goRight( nStart, sal_False ); + } + if ( nLength < 0 ) // expand to end + xTextCursor->gotoEnd( sal_True ); + else + xTextCursor->goRight( nLength, sal_True ); + m_xTextRange.set( xTextCursor, uno::UNO_QUERY_THROW ); + +} + +::rtl::OUString SAL_CALL +ScVbaCharacters::getCaption() throw (css::uno::RuntimeException) +{ + return m_xTextRange->getString(); +} +void SAL_CALL +ScVbaCharacters::setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException) +{ + m_xTextRange->setString( _caption ); + +} + +::sal_Int32 SAL_CALL +ScVbaCharacters::getCount() throw (css::uno::RuntimeException) +{ + return getCaption().getLength(); +} + +::rtl::OUString SAL_CALL +ScVbaCharacters::getText() throw (css::uno::RuntimeException) +{ + return getCaption(); +} +void SAL_CALL +ScVbaCharacters::setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException) +{ + setCaption( _text ); +} +uno::Reference< excel::XFont > SAL_CALL +ScVbaCharacters::getFont() throw (css::uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xTextRange, uno::UNO_QUERY_THROW ); + return uno::Reference< excel::XFont >( new ScVbaFont( this, mxContext, m_aPalette, xProps ) ); +} +void SAL_CALL +ScVbaCharacters::setFont( const uno::Reference< excel::XFont >& /*_font*/ ) throw (css::uno::RuntimeException) +{ + // #TODO #FIXME needs implementation, or can't be done? + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Not Implemented") ), uno::Reference< XInterface >() ); +} + + +// Methods +void SAL_CALL +ScVbaCharacters::Insert( const ::rtl::OUString& String ) throw (css::uno::RuntimeException) +{ + m_xSimpleText->insertString( m_xTextRange, String, bReplace ); +} + +void SAL_CALL +ScVbaCharacters::Delete( ) throw (css::uno::RuntimeException) +{ + // #FIXME #TODO is this a bit suspect?, I wonder should the contents + // of the cell be deleted from the parent ( range ) + m_xSimpleText->setString(rtl::OUString()); +} + + +rtl::OUString& +ScVbaCharacters::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharacters") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaCharacters::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Characters" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacharacters.hxx b/sc/source/ui/vba/vbacharacters.hxx new file mode 100644 index 000000000000..a0a6c350282c --- /dev/null +++ b/sc/source/ui/vba/vbacharacters.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHARACTERS_HXX +#define SC_VBA_CHARACTERS_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <ooo/vba/excel/XCharacters.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/text/XSimpleText.hpp> + +#include <vbahelper/vbahelperinterface.hxx> +#include "vbapalette.hxx" +typedef InheritedHelperInterfaceImpl1< ov::excel::XCharacters > ScVbaCharacters_BASE; + +class ScVbaCharacters : public ScVbaCharacters_BASE +{ +private: + css::uno::Reference< css::text::XTextRange > m_xTextRange; + css::uno::Reference< css::text::XSimpleText > m_xSimpleText; + ScVbaPalette m_aPalette; + sal_Int16 nLength; + sal_Int16 nStart; + // Add becuase of MSO has diferent behavior. + sal_Bool bReplace; +public: + ScVbaCharacters( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const ScVbaPalette& dPalette, const css::uno::Reference< css::text::XSimpleText >& xRange, const css::uno::Any& Start, const css::uno::Any& Length, sal_Bool bReplace = sal_False ) throw ( css::lang::IllegalArgumentException ); + + virtual ~ScVbaCharacters() {} + // Attributes + virtual ::rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFont( const css::uno::Reference< ov::excel::XFont >& _font ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Insert( const ::rtl::OUString& String ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete( ) throw (css::uno::RuntimeException); + + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; + +#endif /* SC_VBA_CHARACTER_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbachart.cxx b/sc/source/ui/vba/vbachart.cxx new file mode 100644 index 000000000000..fb02586e62f5 --- /dev/null +++ b/sc/source/ui/vba/vbachart.cxx @@ -0,0 +1,1255 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbachart.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/chart/XAxisXSupplier.hpp> +#include <com/sun/star/chart/XAxisYSupplier.hpp> +#include <com/sun/star/chart/XAxisZSupplier.hpp> +#include <com/sun/star/chart/XTwoAxisXSupplier.hpp> +#include <com/sun/star/chart/XTwoAxisYSupplier.hpp> +#include <com/sun/star/chart/XChartDataArray.hpp> +#include <com/sun/star/chart/ChartSymbolType.hpp> +#include <com/sun/star/chart/ChartSolidType.hpp> +#include <com/sun/star/chart/ChartDataRowSource.hpp> +#include <com/sun/star/chart/ChartDataCaption.hpp> +#include <ooo/vba/excel/XlChartType.hpp> +#include <ooo/vba/excel/XlRowCol.hpp> +#include <ooo/vba/excel/XlAxisType.hpp> +#include <ooo/vba/excel/XlAxisGroup.hpp> + +#include <basic/sberrors.hxx> +#include "vbachartobject.hxx" +#include "vbarange.hxx" +#include "vbacharttitle.hxx" +#include "vbaaxes.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; +using namespace ::ooo::vba::excel::XlChartType; +using namespace ::ooo::vba::excel::XlRowCol; +using namespace ::ooo::vba::excel::XlAxisType; +using namespace ::ooo::vba::excel::XlAxisGroup; + +const rtl::OUString CHART_NAME( RTL_CONSTASCII_USTRINGPARAM("Name") ); +// #TODO move this constant to vbaseries.[ch]xx ( when it exists ) +const rtl::OUString DEFAULTSERIESPREFIX( RTL_CONSTASCII_USTRINGPARAM("Series") ); +const rtl::OUString DATAROWSOURCE( RTL_CONSTASCII_USTRINGPARAM("DataRowSource") ); +const rtl::OUString UPDOWN( RTL_CONSTASCII_USTRINGPARAM("UpDown") ); +const rtl::OUString VOLUME( RTL_CONSTASCII_USTRINGPARAM("Volume") ); +const rtl::OUString LINES( RTL_CONSTASCII_USTRINGPARAM("Lines") ); +const rtl::OUString SPLINETYPE( RTL_CONSTASCII_USTRINGPARAM("SplineType") ); +const rtl::OUString SYMBOLTYPE( RTL_CONSTASCII_USTRINGPARAM("SymbolType") ); +const rtl::OUString DEEP( RTL_CONSTASCII_USTRINGPARAM("Deep") ); +const rtl::OUString SOLIDTYPE( RTL_CONSTASCII_USTRINGPARAM("SolidType") ); +const rtl::OUString VERTICAL( RTL_CONSTASCII_USTRINGPARAM("Vertical") ); +const rtl::OUString PERCENT( RTL_CONSTASCII_USTRINGPARAM("Percent") ); +const rtl::OUString STACKED( RTL_CONSTASCII_USTRINGPARAM("Stacked") ); +const rtl::OUString DIM3D( RTL_CONSTASCII_USTRINGPARAM("Dim3D") ); +const rtl::OUString HASMAINTITLE( RTL_CONSTASCII_USTRINGPARAM("HasMainTitle") ); +const rtl::OUString HASLEGEND( RTL_CONSTASCII_USTRINGPARAM("HasLegend") ); +const rtl::OUString DATACAPTION( RTL_CONSTASCII_USTRINGPARAM("DataCaption") ); + +ScVbaChart::ScVbaChart( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::lang::XComponent >& _xChartComponent, const css::uno::Reference< css::table::XTableChart >& _xTableChart ) : ChartImpl_BASE( _xParent, _xContext ), mxTableChart( _xTableChart ) +{ + mxChartDocument.set( _xChartComponent, uno::UNO_QUERY_THROW ) ; + // #TODO is is possible that the XPropertySet interface is not set + // code in setPlotBy seems to indicate that this is possible? but + // additionally there is no check in most of the places where it is used + // ( and therefore could possibly be NULL ) + // I'm going to let it throw for the moment ( npower ) + mxDiagramPropertySet.set( mxChartDocument->getDiagram(), uno::UNO_QUERY_THROW ); + mxChartPropertySet.set( _xChartComponent, uno::UNO_QUERY_THROW ) ; +} + +::rtl::OUString SAL_CALL +ScVbaChart::getName() throw (css::uno::RuntimeException) +{ + rtl::OUString sName; + uno::Reference< beans::XPropertySet > xProps( mxChartDocument, uno::UNO_QUERY_THROW ); + try + { + xProps->getPropertyValue( CHART_NAME ) >>= sName; + } + catch( uno::Exception e ) // swallow exceptions + { + } + return sName; +} + +uno::Any SAL_CALL +ScVbaChart::SeriesCollection(const uno::Any&) throw (uno::RuntimeException) +{ + return uno::Any(); +} + +::sal_Int32 SAL_CALL +ScVbaChart::getChartType() throw ( uno::RuntimeException, script::BasicErrorException) +{ + sal_Int32 nChartType = -1; + try + { + rtl::OUString sDiagramType = mxChartDocument->getDiagram()->getDiagramType(); + if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart.AreaDiagram" )))) + { + if (is3D()) + { + nChartType = getStackedType(xl3DAreaStacked, xl3DAreaStacked100, xl3DArea); + } + else + { + nChartType = getStackedType(xlAreaStacked, xlAreaStacked100, xlArea); + } + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.PieDiagram")))) + { + if (is3D()) + nChartType = xl3DPie; + else + nChartType = xlPie; /*TODO XlChartType xlPieExploded, XlChartType xlPieOfPie */ + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.BarDiagram")))) + { + sal_Int32 nSolidType = chart::ChartSolidType::RECTANGULAR_SOLID; + if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE)) + { //in 2D diagrams 'SolidType' may not be set + if (is3D()) + mxDiagramPropertySet->getPropertyValue(SOLIDTYPE) >>= nSolidType; + } + switch (nSolidType) + { + case chart::ChartSolidType::CONE: + nChartType = getSolidType(xlConeCol, xlConeColStacked, xlConeColStacked100, xlConeColClustered, xlConeBarStacked, xlConeBarStacked100, xlConeBarClustered); + break; + case chart::ChartSolidType::CYLINDER: + nChartType = getSolidType(xlCylinderCol, xlCylinderColStacked, xlCylinderColStacked100, xlCylinderColClustered, xlCylinderBarStacked, xlCylinderBarStacked100, xlCylinderBarClustered); + break; + case chart::ChartSolidType::PYRAMID: + nChartType = getSolidType(xlPyramidCol, xlPyramidColStacked, xlPyramidColStacked100, xlPyramidColClustered, xlPyramidBarStacked, xlPyramidBarStacked100, xlPyramidBarClustered); + break; + default: // RECTANGULAR_SOLID + if (is3D()) + { + nChartType = getSolidType(xl3DColumn, xl3DColumnStacked, xl3DColumnStacked100, xl3DColumnClustered, xl3DBarStacked, xl3DBarStacked100, xl3DBarClustered); + } + else + { + nChartType = getSolidType(xlColumnClustered, xlColumnStacked, xlColumnStacked100, xlColumnClustered, xlBarStacked, xlBarStacked100, xlBarClustered); + } + break; + } + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.StockDiagram")))) + { + sal_Bool bVolume = sal_False; + mxDiagramPropertySet->getPropertyValue(VOLUME) >>= bVolume; + if (bVolume) + { + nChartType = getStockUpDownValue(xlStockVOHLC, xlStockVHLC); + } + else + { + nChartType = getStockUpDownValue(xlStockOHLC, xlStockHLC); + } + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.XYDiagram")))) + { + sal_Bool bHasLines = sal_False; + mxDiagramPropertySet->getPropertyValue(LINES) >>= bHasLines; + sal_Int32 nSplineType = 0; + mxDiagramPropertySet->getPropertyValue(SPLINETYPE) >>= nSplineType; + if (nSplineType == 1) + { + nChartType = getMarkerType(xlXYScatterSmooth, xlXYScatterSmoothNoMarkers); + } + else if (bHasLines) + { + nChartType = getMarkerType(xlXYScatterLines, xlXYScatterLinesNoMarkers); + } + else + { + nChartType = xlXYScatter; + } + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.LineDiagram")))) + { + if (is3D()) + { + nChartType = xl3DLine; + } + else if (hasMarkers()) + { + nChartType = getStackedType(xlLineMarkersStacked, xlLineMarkersStacked100, xlLineMarkers); + } + else + { + nChartType = getStackedType(xlLineStacked, xlLineStacked100, xlLine); + } + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.DonutDiagram")))) + { + nChartType = xlDoughnut; // TODO DoughnutExploded ?? + } + else if (sDiagramType.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.NetDiagram")))) + { + nChartType = getMarkerType(xlRadarMarkers, xlRadar); + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return nChartType; +} + +void SAL_CALL +ScVbaChart::setChartType( ::sal_Int32 _nChartType ) throw ( uno::RuntimeException, script::BasicErrorException) +{ +try +{ + switch (_nChartType) + { + case xlColumnClustered: + case xlColumnStacked: + case xlColumnStacked100: + case xl3DColumnClustered: + case xl3DColumnStacked: + case xl3DColumnStacked100: + case xl3DColumn: + case xlBarClustered: + case xlBarStacked: + case xlBarStacked100: + case xl3DBarClustered: + case xl3DBarStacked: + case xl3DBarStacked100: + case xlConeColClustered: + case xlConeColStacked: + case xlConeColStacked100: + case xlConeBarClustered: + case xlConeBarStacked: + case xlConeBarStacked100: + case xlConeCol: + case xlPyramidColClustered: + case xlPyramidColStacked: + case xlPyramidColStacked100: + case xlPyramidBarClustered: + case xlPyramidBarStacked: + case xlPyramidBarStacked100: + case xlPyramidCol: + case xlCylinderColClustered: + case xlCylinderColStacked: + case xlCylinderColStacked100: + case xlCylinderBarClustered: + case xlCylinderBarStacked: + case xlCylinderBarStacked100: + case xlCylinderCol: + case xlSurface: // not possible + case xlSurfaceWireframe: + case xlSurfaceTopView: + case xlSurfaceTopViewWireframe: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.BarDiagram"))); + break; + case xlLine: + case xl3DLine: + case xlLineStacked: + case xlLineStacked100: + case xlLineMarkers: + case xlLineMarkersStacked: + case xlLineMarkersStacked100: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.LineDiagram"))); + break; + case xl3DArea: + case xlArea: + case xlAreaStacked: + case xlAreaStacked100: + case xl3DAreaStacked: + case xl3DAreaStacked100: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.AreaDiagram")) ); + break; + case xlDoughnut: + case xlDoughnutExploded: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.DonutDiagram") ) ); + break; + case xlStockHLC: + case xlStockOHLC: + case xlStockVHLC: + case xlStockVOHLC: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.StockDiagram"))); + mxDiagramPropertySet->setPropertyValue( UPDOWN, uno::makeAny(sal_Bool((_nChartType == xlStockOHLC) || (_nChartType == xlStockVOHLC)))); + mxDiagramPropertySet->setPropertyValue(VOLUME, uno::makeAny(sal_Bool((_nChartType == xlStockVHLC) || (_nChartType == xlStockVOHLC)))); + break; + + case xlPieOfPie: // not possible + case xlPieExploded: // SegmentOffset an ChartDataPointProperties ->am XDiagram abholen //wie macht Excel das? + case xl3DPieExploded: + case xl3DPie: + case xlPie: + case xlBarOfPie: // not possible (Zoom pie) + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.PieDiagram"))); + break; + + case xlRadar: + case xlRadarMarkers: + case xlRadarFilled: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.NetDiagram"))); + break; + case xlXYScatter: + case xlBubble: // not possible + case xlBubble3DEffect: // not possible + case xlXYScatterLines: + case xlXYScatterLinesNoMarkers: + case xlXYScatterSmooth: + case xlXYScatterSmoothNoMarkers: + setDiagram( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart.XYDiagram"))); + switch(_nChartType) + { + case xlXYScatter: + case xlBubble: // not possible + case xlBubble3DEffect: // not possible + mxDiagramPropertySet->setPropertyValue(LINES, uno::makeAny( sal_False )); + break; + case xlXYScatterLines: + case xlXYScatterLinesNoMarkers: + mxDiagramPropertySet->setPropertyValue(LINES, uno::makeAny( sal_True )); + break; + case xlXYScatterSmooth: + case xlXYScatterSmoothNoMarkers: + mxDiagramPropertySet->setPropertyValue(SPLINETYPE, uno::makeAny( sal_Int32(1))); + break; + default: + break; + } + break; + default: + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_CONVERSION, rtl::OUString() ); + } + + switch (_nChartType) + { + case xlLineMarkers: + case xlLineMarkersStacked: + case xlLineMarkersStacked100: + case xlRadarMarkers: + case xlXYScatterLines: + case xlXYScatterSmooth: + case xlXYScatter: + case xlBubble: // not possible + case xlBubble3DEffect: // not possible + mxDiagramPropertySet->setPropertyValue(SYMBOLTYPE, uno::makeAny( chart::ChartSymbolType::AUTO)); + break; + default: + if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SYMBOLTYPE)) + { + mxDiagramPropertySet->setPropertyValue(SYMBOLTYPE, uno::makeAny(chart::ChartSymbolType::NONE)); + } + break; + } + + switch (_nChartType) + { + case xlConeCol: + case xlPyramidCol: + case xlCylinderCol: + case xl3DColumn: + case xlSurface: // not possible + case xlSurfaceWireframe: + case xlSurfaceTopView: + case xlSurfaceTopViewWireframe: + mxDiagramPropertySet->setPropertyValue(DEEP,uno::makeAny( sal_True )); + break; + default: + if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(DEEP)) + { + mxDiagramPropertySet->setPropertyValue(DEEP, uno::makeAny( sal_False)); + } + break; + } + + + switch (_nChartType) + { + case xlConeColClustered: + case xlConeColStacked: + case xlConeColStacked100: + case xlConeBarClustered: + case xlConeBarStacked: + case xlConeBarStacked100: + case xlConeCol: + mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::CONE)); + break; + case xlPyramidColClustered: + case xlPyramidColStacked: + case xlPyramidColStacked100: + case xlPyramidBarClustered: + case xlPyramidBarStacked: + case xlPyramidBarStacked100: + case xlPyramidCol: + mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::PYRAMID)); + break; + case xlCylinderColClustered: + case xlCylinderColStacked: + case xlCylinderColStacked100: + case xlCylinderBarClustered: + case xlCylinderBarStacked: + case xlCylinderBarStacked100: + case xlCylinderCol: + mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::CYLINDER)); + break; + default: + if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(SOLIDTYPE)) + { + mxDiagramPropertySet->setPropertyValue(SOLIDTYPE, uno::makeAny(chart::ChartSolidType::RECTANGULAR_SOLID)); + } + break; + } + + switch ( _nChartType) + { + case xlConeCol: + case xlConeColClustered: + case xlConeColStacked: + case xlConeColStacked100: + case xlPyramidColClustered: + case xlPyramidColStacked: + case xlPyramidColStacked100: + case xlCylinderColClustered: + case xlCylinderColStacked: + case xlCylinderColStacked100: + case xlColumnClustered: + case xlColumnStacked: + case xlColumnStacked100: + case xl3DColumnClustered: + case xl3DColumnStacked: + case xl3DColumnStacked100: + case xlSurface: // not possible + case xlSurfaceWireframe: + case xlSurfaceTopView: + case xlSurfaceTopViewWireframe: + mxDiagramPropertySet->setPropertyValue(VERTICAL, uno::makeAny( sal_True)); + break; + default: + if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(VERTICAL)) + { + mxDiagramPropertySet->setPropertyValue(VERTICAL, uno::makeAny(sal_False)); + } + break; + } + + switch (_nChartType) + { + case xlColumnStacked: + case xl3DColumnStacked: + case xlBarStacked: + case xl3DBarStacked: + case xlLineStacked: + case xlLineMarkersStacked: + case xlAreaStacked: + case xl3DAreaStacked: + case xlCylinderColStacked: + case xlCylinderBarStacked: + case xlConeColStacked: + case xlConeBarStacked: + case xlPyramidColStacked: + case xlPyramidBarStacked: + mxDiagramPropertySet->setPropertyValue(PERCENT, uno::makeAny( sal_False )); + mxDiagramPropertySet->setPropertyValue(STACKED, uno::makeAny( sal_True )); + break; + case xlPyramidColStacked100: + case xlPyramidBarStacked100: + case xlConeColStacked100: + case xlConeBarStacked100: + case xlCylinderBarStacked100: + case xlCylinderColStacked100: + case xl3DAreaStacked100: + case xlLineMarkersStacked100: + case xlAreaStacked100: + case xlLineStacked100: + case xl3DBarStacked100: + case xlBarStacked100: + case xl3DColumnStacked100: + case xlColumnStacked100: + mxDiagramPropertySet->setPropertyValue(STACKED, uno::makeAny( sal_True)); + mxDiagramPropertySet->setPropertyValue(PERCENT, uno::makeAny( sal_True )); + break; + default: + mxDiagramPropertySet->setPropertyValue(PERCENT, uno::makeAny( sal_False)); + mxDiagramPropertySet->setPropertyValue(STACKED, uno::makeAny( sal_False)); + break; + } + switch (_nChartType) + { + case xl3DArea: + case xl3DAreaStacked: + case xl3DAreaStacked100: + case xl3DBarClustered: + case xl3DBarStacked: + case xl3DBarStacked100: + case xl3DColumn: + case xl3DColumnClustered: + case xl3DColumnStacked: + case xl3DColumnStacked100: + case xl3DLine: + case xl3DPie: + case xl3DPieExploded: + case xlConeColClustered: + case xlConeColStacked: + case xlConeColStacked100: + case xlConeBarClustered: + case xlConeBarStacked: + case xlConeBarStacked100: + case xlConeCol: + case xlPyramidColClustered: + case xlPyramidColStacked: + case xlPyramidColStacked100: + case xlPyramidBarClustered: + case xlPyramidBarStacked: + case xlPyramidBarStacked100: + case xlPyramidCol: + case xlCylinderColClustered: + case xlCylinderColStacked: + case xlCylinderColStacked100: + case xlCylinderBarClustered: + case xlCylinderBarStacked: + case xlCylinderBarStacked100: + case xlCylinderCol: + mxDiagramPropertySet->setPropertyValue(DIM3D, uno::makeAny( sal_True)); + break; + default: + if (mxDiagramPropertySet->getPropertySetInfo()->hasPropertyByName(DIM3D)) + { + mxDiagramPropertySet->setPropertyValue(DIM3D, uno::makeAny( sal_False)); + } + break; + } + } + catch ( uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +void SAL_CALL +ScVbaChart::Activate() throw (script::BasicErrorException, uno::RuntimeException) +{ + // #TODO how are Chart sheets handled ( I know we don't even consider + // them in the worksheets/sheets collections ), but.....??? + // note: in vba for excel the parent of a Chart sheet is a workbook, + // e.g. 'ThisWorkbook' + uno::Reference< XHelperInterface > xParent( getParent() ); + ScVbaChartObject* pChartObj = static_cast< ScVbaChartObject* >( xParent.get() ); + if ( pChartObj ) + pChartObj->Activate(); + else + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "no ChartObject as parent" ) ) ); +} + +void SAL_CALL +ScVbaChart::setSourceData( const css::uno::Reference< ::ooo::vba::excel::XRange >& _xCalcRange, const css::uno::Any& _aPlotBy ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + try + { + uno::Sequence< table::CellRangeAddress > mRangeAddresses(1); + table::CellRangeAddress mSingleRangeAddress; + + uno::Reference< sheet::XCellRangeAddressable > xAddressable( _xCalcRange->getCellRange(), uno::UNO_QUERY_THROW ); + mSingleRangeAddress = xAddressable->getRangeAddress(); + + mRangeAddresses[0] = mSingleRangeAddress; + + mxTableChart->setRanges(mRangeAddresses); + + sal_Bool bsetRowHeaders = sal_False; + sal_Bool bsetColumnHeaders = sal_False; + + ScVbaRange* pRange = static_cast< ScVbaRange* >( _xCalcRange.get() ); + if ( pRange ) + { + ScDocument* pDoc = pRange->getScDocument(); + if ( pDoc ) + { + bsetRowHeaders = pDoc->HasRowHeader( static_cast< SCCOL >( mSingleRangeAddress.StartColumn ), static_cast< SCROW >( mSingleRangeAddress.StartRow ), static_cast< SCCOL >( mSingleRangeAddress.EndColumn ), static_cast< SCROW >( mSingleRangeAddress.EndRow ), static_cast< SCTAB >( mSingleRangeAddress.Sheet ) );; + bsetColumnHeaders = pDoc->HasColHeader( static_cast< SCCOL >( mSingleRangeAddress.StartColumn ), static_cast< SCROW >( mSingleRangeAddress.StartRow ), static_cast< SCCOL >( mSingleRangeAddress.EndColumn ), static_cast< SCROW >( mSingleRangeAddress.EndRow ), static_cast< SCTAB >( mSingleRangeAddress.Sheet )); +; + } + } + mxTableChart->setHasRowHeaders(bsetRowHeaders); + mxTableChart->setHasColumnHeaders(bsetColumnHeaders); + + if ((!bsetColumnHeaders) || (!bsetRowHeaders)) + { + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + if (!bsetColumnHeaders) + { + xChartDataArray->setColumnDescriptions( getDefaultSeriesDescriptions(xChartDataArray->getColumnDescriptions().getLength() )); + } + if (!bsetRowHeaders) + { + xChartDataArray->setRowDescriptions(getDefaultSeriesDescriptions(xChartDataArray->getRowDescriptions().getLength() )); + } + } + + if ( _aPlotBy.hasValue() ) + { + sal_Int32 nVal = 0; + _aPlotBy >>= nVal; + setPlotBy( nVal ); + } + else + { + sal_Int32 nRows = mSingleRangeAddress.EndRow - mSingleRangeAddress.StartRow; + sal_Int32 nCols = mSingleRangeAddress.EndColumn - mSingleRangeAddress.StartColumn; + // AutoDetect emulation + if ( nRows > nCols ) + setPlotBy( xlColumns ); + else if ( nRows <= nCols ) + setPlotBy( xlRows ); + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +uno::Sequence< rtl::OUString > +ScVbaChart::getDefaultSeriesDescriptions( sal_Int32 _nCount ) +{ + uno::Sequence< rtl::OUString > sDescriptions ( _nCount ); + sal_Int32 nLen = sDescriptions.getLength(); + for (sal_Int32 i = 0; i < nLen; i++) + { + sDescriptions[i] = DEFAULTSERIESPREFIX + rtl::OUString::valueOf(i+1); + } + return sDescriptions; +} + +void +ScVbaChart::setDefaultChartType() throw ( script::BasicErrorException ) +{ + setChartType( xlColumnClustered ); +} + +void +ScVbaChart::setPlotBy( ::sal_Int32 _nPlotBy ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + try + { + if ( !mxDiagramPropertySet.is() ) + setDefaultChartType(); + switch (_nPlotBy) + { + case xlRows: + mxDiagramPropertySet->setPropertyValue( DATAROWSOURCE, uno::makeAny( chart::ChartDataRowSource_ROWS ) ); + break; + case xlColumns: + mxDiagramPropertySet->setPropertyValue( DATAROWSOURCE, uno::makeAny( chart::ChartDataRowSource_COLUMNS) ); + break; + default: + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +::sal_Int32 SAL_CALL +ScVbaChart::getPlotBy( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + chart::ChartDataRowSource aChartDataRowSource; + mxDiagramPropertySet->getPropertyValue(DATAROWSOURCE) >>= aChartDataRowSource; + if (aChartDataRowSource == chart::ChartDataRowSource_COLUMNS) + { + return xlColumns; + } + else + { + return xlRows; + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +void +ScVbaChart::setDiagram( const rtl::OUString& _sDiagramType ) throw( script::BasicErrorException ) +{ + try + { + uno::Reference< lang::XMultiServiceFactory > xMSF( mxChartDocument, uno::UNO_QUERY_THROW ); + uno::Reference< chart::XDiagram > xDiagram( xMSF->createInstance( _sDiagramType ), uno::UNO_QUERY_THROW ); + mxChartDocument->setDiagram( xDiagram ); + mxDiagramPropertySet.set( xDiagram, uno::UNO_QUERY_THROW ); + } + catch ( uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +// #TODO find out why we have Location/getLocation ? there is afaiks no +// Location property, just a Location function for the Chart object +sal_Int32 SAL_CALL +ScVbaChart::Location() throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return getLocation(); +} + +sal_Int32 SAL_CALL +ScVbaChart::getLocation() throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return -1; +} + +void SAL_CALL +ScVbaChart::setLocation( ::sal_Int32 /*where*/, const css::uno::Any& /*Name*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // Helper api just stubs out the code <shrug> + // #TODO come back and make sense out of this +// String sheetName = null; +// +// if ((name != null) && name instanceof String) { +// sheetName = (String) name; +// } +// XSpreadsheetDocument xShDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( XSpreadsheetDocument.class,getXModel() ); +// com.sun.star.sheet.XSpreadsheets xSheets = xShDoc.Sheets(); +// +// switch (where) { +// case ClLocationType.clLocationAsObject_value: //{ +// +// if (sheetName == null) { +// DebugHelper.writeInfo("Can't embed in Chart without knowing SheetName"); +// return; +// } +// +// try { +// Any any = (Any) xSheets.getByName(sheetName); +// chartSheet = (XSpreadsheet) any.getObject(); +// +// // chartSheet = (XSpreadsheet) xSheets.getByName( sheetName ); +// } catch (NoSuchElementException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// +// return; +// } catch (WrappedTargetException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// +// return; +// } catch (java.lang.Exception e) { +// e.printStackTrace(); +// } +// +// XTableChartsSupplier xTCS = (XTableChartsSupplier) UnoRuntime.queryInterface( XTableChartsSupplier.class, chartSheet); +// XTableCharts xTableCharts = xTCS.getCharts(); +// XIndexAccess xIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xTableCharts); +// int numCharts = xIA.getCount(); +// chartName = "Chart " + (numCharts + 1); +// +// //} +// break; +// +// case ClLocationType.clLocationAsNewSheet_value: +// case ClLocationType.clLocationAutomatic_value:default: //{ +// chartName = "Chart 1"; // Since it's a new sheet, it's the first on it... +// +// XIndexAccess xSheetIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, xSheets); +// +// short newSheetNum = (short) (xSheetIA.getCount() + 1); +// +// if (sheetName == null){ +// sheetName = "ChartSheet " + newSheetNum; // Why not? +// } +// // DPK TODO : Probably should use Sheets to create this! +// xSheets.insertNewByName(sheetName, newSheetNum); +// +// try { +// chartSheet = +// (XSpreadsheet) xSheets.getByName(sheetName); +// } catch (NoSuchElementException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// +// return; +// } catch (WrappedTargetException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// +// return; +// } +// +// //} +// break; +// } +// +// // Last thing should be a call to createChartForReal(), one of them +// // should succeed. +// createChartForReal(); + +} + +sal_Bool SAL_CALL +ScVbaChart::getHasTitle( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bHasTitle = sal_False; + try + { + mxChartPropertySet->getPropertyValue(HASMAINTITLE) >>= bHasTitle; + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return bHasTitle; +} + +void SAL_CALL +ScVbaChart::setHasTitle( ::sal_Bool bTitle ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + mxChartPropertySet->setPropertyValue(HASMAINTITLE, uno::makeAny( bTitle )); + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + +} + +::sal_Bool SAL_CALL +ScVbaChart::getHasLegend( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + sal_Bool bHasLegend = sal_False; + try + { + mxChartPropertySet->getPropertyValue(HASLEGEND) >>= bHasLegend; + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return bHasLegend; +} + +void SAL_CALL +ScVbaChart::setHasLegend( ::sal_Bool bLegend ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + mxChartPropertySet->setPropertyValue(HASLEGEND, uno::makeAny(bLegend)); + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +uno::Reference< excel::XChartTitle > SAL_CALL +ScVbaChart::getChartTitle( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< drawing::XShape > xTitleShape = mxChartDocument->getTitle(); + // #TODO check parent + return new ScVbaChartTitle(this, mxContext, xTitleShape); +} + +uno::Any SAL_CALL +ScVbaChart::Axes( const uno::Any& Type, const uno::Any& AxisGroup ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // mmm chart probably is the parent, #TODO check parent + uno::Reference< excel::XAxes > xAxes = new ScVbaAxes( this, mxContext, this ); + if ( !Type.hasValue() ) + return uno::makeAny( xAxes ); + return xAxes->Item( Type, AxisGroup ); +} +bool +ScVbaChart::is3D() throw ( uno::RuntimeException ) +{ + // #TODO perhaps provide limited Debughelper functionality + sal_Bool is3d = sal_False; + mxDiagramPropertySet->getPropertyValue(DIM3D) >>= is3d; + return is3d; +} + +sal_Int32 +ScVbaChart::getStackedType( sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked ) throw ( uno::RuntimeException ) +{ + // #TODO perhaps provide limited Debughelper functionality + if (isStacked()) + { + if (is100PercentStacked()) + return _n100PercentStacked; + else + return _nStacked; + } + else + return _nUnStacked; +} + +bool +ScVbaChart::isStacked() throw ( uno::RuntimeException ) +{ + // #TODO perhaps provide limited Debughelper functionality + sal_Bool bStacked = sal_False; + mxDiagramPropertySet->getPropertyValue(STACKED) >>= bStacked; + return bStacked; +} + +bool +ScVbaChart::is100PercentStacked() throw ( uno::RuntimeException ) +{ + // #TODO perhaps provide limited Debughelper functionality + sal_Bool b100Percent = sal_False; + mxDiagramPropertySet->getPropertyValue(PERCENT) >>= b100Percent; + return b100Percent; +} + +sal_Int32 +ScVbaChart::getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked) throw ( script::BasicErrorException ) +{ + sal_Bool bIsVertical = true; + try + { + mxDiagramPropertySet->getPropertyValue(VERTICAL) >>= bIsVertical; + sal_Bool bIsDeep = false; + mxDiagramPropertySet->getPropertyValue(DEEP) >>= bIsDeep; + + if (bIsDeep) + { + return _nDeep; + } + else + { + if (bIsVertical) + { + return getStackedType(_nVertiStacked, _nVerti100PercentStacked, _nVertiUnStacked); + } + else + { + return getStackedType(_nHoriStacked, _nHori100PercentStacked, _nHoriUnStacked); + } + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + + +sal_Int32 +ScVbaChart::getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown) throw (script::BasicErrorException) +{ + sal_Bool bUpDown = sal_False; + try + { + mxDiagramPropertySet->getPropertyValue(UPDOWN) >>= bUpDown; + if (bUpDown) + { + return _nUpDown; + } + else + { + return _nNotUpDown; + } + } + catch (uno::Exception& ) + { + rtl::OUString aTemp; // temporary needed for g++ 3.3.5 + script::BasicErrorException( aTemp, uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return _nNotUpDown; +} + +bool +ScVbaChart::hasMarkers() throw ( script::BasicErrorException ) +{ + bool bHasMarkers = false; + try + { + sal_Int32 nSymbol=0; + mxDiagramPropertySet->getPropertyValue(SYMBOLTYPE) >>= nSymbol; + bHasMarkers = nSymbol != chart::ChartSymbolType::NONE; + } + catch ( uno::Exception& ) + { + rtl::OUString aTemp; // temporary needed for g++ 3.3.5 + script::BasicErrorException( aTemp, uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return bHasMarkers; +} + +sal_Int32 +ScVbaChart::getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers) throw ( script::BasicErrorException ) +{ + if (hasMarkers()) + return _nWithMarkers; + return _nWithoutMarkers; +} + +void +ScVbaChart::assignDiagramAttributes() +{ + xAxisXSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW ); + xAxisYSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW ); + xAxisZSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW ); + xTwoAxisXSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW ); + xTwoAxisYSupplier.set( mxDiagramPropertySet, uno::UNO_QUERY_THROW ); +} + +bool +ScVbaChart::isSeriesIndexValid(sal_Int32 _seriesindex) throw( script::BasicErrorException ) +{ + bool bret = false; + try + { + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + // dblValues = xChartDataArray.getData(); + //TODO I guess we have to differentiate between XlRowCol + if ( !xChartDataArray.is() ) + { + if (getPlotBy() == xlRows) + { + if ((_seriesindex < xChartDataArray->getRowDescriptions().getLength() ) && (_seriesindex >= 0)) + bret = true; + } + else + { + if ((_seriesindex < xChartDataArray->getColumnDescriptions().getLength() ) && (_seriesindex >= 0)) + bret = true; + } + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + if (!bret) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_OUT_OF_RANGE, rtl::OUString() ); + } + return bret; +} + +bool +ScVbaChart::areIndicesValid( sal_Int32 _seriesindex, sal_Int32 _valindex) throw ( css::script::BasicErrorException ) +{ + if (isSeriesIndexValid(_seriesindex)) + { + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + dblValues = xChartDataArray->getData(); + return (_valindex < dblValues[_seriesindex].getLength() ); + } + return false; +} + +sal_Int32 +ScVbaChart::getSeriesIndex(rtl::OUString _sseriesname) throw ( script::BasicErrorException ) +{ + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + if (getPlotBy() == xlRows) + return ContainerUtilities::FieldInList(xChartDataArray->getRowDescriptions(), _sseriesname); + return ContainerUtilities::FieldInList(xChartDataArray->getColumnDescriptions(), _sseriesname); +} +void +ScVbaChart::setSeriesName(sal_Int32 _index, rtl::OUString _sname) throw ( script::BasicErrorException ) +{ + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + if (isSeriesIndexValid(_index)) + { + uno::Sequence< rtl::OUString > sDescriptions = xChartDataArray->getColumnDescriptions(); + sDescriptions[_index] = _sname; + xChartDataArray->setColumnDescriptions(sDescriptions); + } +} + +sal_Int32 +ScVbaChart::getSeriesCount() throw ( script::BasicErrorException ) +{ + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + + if (getPlotBy() == xlRows) + return xChartDataArray->getRowDescriptions().getLength(); + return xChartDataArray->getColumnDescriptions().getLength(); + +} + +rtl::OUString +ScVbaChart::getSeriesName(sal_Int32 _index) throw ( script::BasicErrorException ) +{ + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + uno::Sequence< rtl::OUString > sDescriptions; + rtl::OUString sName; + if (isSeriesIndexValid(_index)) + { + if (getPlotBy() == xlRows) + sDescriptions = xChartDataArray->getRowDescriptions(); + else + sDescriptions = xChartDataArray->getColumnDescriptions(); + sName = sDescriptions[_index]; + } + return sName; +} + +double +ScVbaChart::getValue(sal_Int32 _seriesindex, sal_Int32 _valindex) throw ( script::BasicErrorException ) +{ + double result = -1.0; + if (areIndicesValid(_seriesindex, _valindex)) + { + if (getPlotBy() == xlRows) + result = dblValues[_seriesindex][_valindex]; + else + result = dblValues[_valindex][_seriesindex]; + } + return result; +} + +sal_Int32 +ScVbaChart::getValuesCount(sal_Int32 _seriesIndex) throw ( script::BasicErrorException ) +{ + sal_Int32 nCount = 0; + uno::Reference< chart::XChartDataArray > xChartDataArray( mxChartDocument->getData(), uno::UNO_QUERY_THROW ); + if (isSeriesIndexValid(_seriesIndex)) + { + dblValues = xChartDataArray->getData(); + if (getPlotBy() == xlRows) + nCount = dblValues[_seriesIndex].getLength(); + else + nCount = dblValues.getLength(); + } + return nCount; +} + + +uno::Reference< excel::XDataLabels > +ScVbaChart::DataLabels( const uno::Reference< ov::excel::XSeries > /*_oSeries*/ ) throw ( css::script::BasicErrorException ) +{ + if ( true ) + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + // #TODO #FIXE provide implementation + return uno::Reference< excel::XDataLabels > (); +} + +bool +ScVbaChart::getHasDataCaption( const uno::Reference< css::beans::XPropertySet >& _xPropertySet )throw ( script::BasicErrorException ) +{ + bool bResult = false; + try + { + sal_Int32 nChartDataCaption = 0; + _xPropertySet->getPropertyValue(DATACAPTION) >>= nChartDataCaption; + bResult = (nChartDataCaption != chart::ChartDataCaption::NONE); + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return bResult; +} + +void +ScVbaChart::setHasDataCaption( const uno::Reference< beans::XPropertySet >& _xPropertySet, bool _bHasDataLabels )throw ( script::BasicErrorException ) +{ + try + { + if ( _bHasDataLabels ) + _xPropertySet->setPropertyValue(DATACAPTION, uno::makeAny ( chart::ChartDataCaption::VALUE) ); + else + _xPropertySet->setPropertyValue(DATACAPTION, uno::makeAny ( chart::ChartDataCaption::NONE) ); + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +uno::Reference< beans::XPropertySet > +ScVbaChart::getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup) throw ( script::BasicErrorException ) +{ + assignDiagramAttributes(); + uno::Reference< beans::XPropertySet > xAxisProps; + switch(_nAxisType) + { + case xlCategory: + if (_nAxisGroup == xlPrimary) + { + xAxisProps = xAxisXSupplier->getXAxis(); + } + else if (_nAxisGroup == xlSecondary) + { + xAxisProps = xTwoAxisXSupplier->getSecondaryXAxis(); + } + break; + case xlSeriesAxis: +// if (_nAxisGroup == xlPrimary){ + xAxisProps = xAxisZSupplier->getZAxis(); + break; +// } +// else if (_nAxisGroup == xlSecondary){ + // return xTwoAxisXSupplier.getSecondaryZAxis(); + // } + case xlValue: + if (_nAxisGroup == xlPrimary) + xAxisProps = xAxisYSupplier->getYAxis(); + else if (_nAxisGroup == xlSecondary) + xAxisProps = xTwoAxisYSupplier->getSecondaryYAxis(); + break; + default: + return xAxisProps; + } + return xAxisProps; +} + + +rtl::OUString& +ScVbaChart::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChart") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaChart::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Chart" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbachart.hxx b/sc/source/ui/vba/vbachart.hxx new file mode 100644 index 000000000000..3602baafaa64 --- /dev/null +++ b/sc/source/ui/vba/vbachart.hxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHART_HXX +#define SC_VBA_CHART_HXX +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/chart/XAxisXSupplier.hpp> +#include <com/sun/star/chart/XAxisYSupplier.hpp> +#include <com/sun/star/chart/XAxisZSupplier.hpp> +#include <com/sun/star/chart/XTwoAxisXSupplier.hpp> +#include <com/sun/star/chart/XTwoAxisYSupplier.hpp> +#include <ooo/vba/excel/XChart.hpp> +#include <ooo/vba/excel/XDataLabels.hpp> +#include <ooo/vba/excel/XSeries.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1<ov::excel::XChart > ChartImpl_BASE; + +class ScVbaChart : public ChartImpl_BASE +{ +friend class ScVbaAxis; + + css::uno::Reference< css::chart::XChartDocument > mxChartDocument; + css::uno::Reference< css::table::XTableChart > mxTableChart; + css::uno::Reference< css::beans::XPropertySet > mxDiagramPropertySet; + css::uno::Reference< css::beans::XPropertySet > mxChartPropertySet; + css::uno::Reference< css::chart::XAxisXSupplier > xAxisXSupplier; + css::uno::Reference< css::chart::XAxisYSupplier> xAxisYSupplier; + css::uno::Reference< css::chart::XAxisZSupplier > xAxisZSupplier; + css::uno::Reference< css::chart::XTwoAxisXSupplier > xTwoAxisXSupplier; + css::uno::Reference< css::chart::XTwoAxisYSupplier > xTwoAxisYSupplier; + + css::uno::Sequence< rtl::OUString > getDefaultSeriesDescriptions( sal_Int32 nCount ); + css::uno::Sequence< css::uno::Sequence< double > > dblValues; + void setDefaultChartType()throw ( css::script::BasicErrorException ) ; + void setDiagram( const rtl::OUString& _sDiagramType) throw( css::script::BasicErrorException ); + bool isStacked() throw ( css::uno::RuntimeException ); + bool is100PercentStacked() throw ( css::uno::RuntimeException ); + sal_Int32 getStackedType( sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked ) throw ( css::uno::RuntimeException ); + sal_Int32 getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked) throw ( css::script::BasicErrorException ); + sal_Int32 getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown) throw (css::script::BasicErrorException); + bool hasMarkers() throw ( css::script::BasicErrorException ); + sal_Int32 getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers) throw ( css::script::BasicErrorException ); + void assignDiagramAttributes(); + void setDefaultSeriesDescriptionLabels(){} +public: + ScVbaChart( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::lang::XComponent >& _xChartComponent, const css::uno::Reference< css::table::XTableChart >& _xTableChart ); + + // Non-interface + css::uno::Reference< css::beans::XPropertySet > xDiagramPropertySet() { return mxDiagramPropertySet; } + bool isSeriesIndexValid(sal_Int32 _seriesindex) throw( css::script::BasicErrorException ); + bool areIndicesValid(sal_Int32 _seriesindex, sal_Int32 _valindex) throw ( css::script::BasicErrorException ); + void setSeriesName(sal_Int32 _index, rtl::OUString _sname) throw ( css::script::BasicErrorException ); + sal_Int32 getSeriesIndex(rtl::OUString _sseriesname) throw ( css::script::BasicErrorException ); + sal_Int32 getSeriesCount() throw ( css::script::BasicErrorException ); + rtl::OUString getSeriesName(sal_Int32 _index) throw ( css::script::BasicErrorException ); + double getValue(sal_Int32 _seriesIndex, sal_Int32 _valindex) throw ( css::script::BasicErrorException ); + sal_Int32 getValuesCount(sal_Int32 _seriesIndex) throw ( css::script::BasicErrorException ); + css::uno::Reference< ov::excel::XDataLabels > DataLabels( const css::uno::Reference< ov::excel::XSeries > _oSeries ) throw ( css::script::BasicErrorException ); + bool getHasDataCaption( const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet )throw ( css::script::BasicErrorException ); + void setHasDataCaption( const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, bool _bHasDataLabels )throw ( css::script::BasicErrorException ); + bool is3D() throw ( css::uno::RuntimeException ); + css::uno::Reference< css::beans::XPropertySet > getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup) throw ( css::script::BasicErrorException ); + // Methods + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL SeriesCollection(const css::uno::Any&) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getChartType() throw ( css::uno::RuntimeException, css::script::BasicErrorException); + virtual void SAL_CALL setChartType( ::sal_Int32 _charttype ) throw ( css::uno::RuntimeException, css::script::BasicErrorException); + virtual void SAL_CALL Activate( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setSourceData( const css::uno::Reference< ::ooo::vba::excel::XRange >& range, const css::uno::Any& PlotBy ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL Location( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getLocation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setLocation( ::sal_Int32 where, const css::uno::Any& Name ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getHasTitle( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setHasTitle( ::sal_Bool bTitle ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getHasLegend( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setHasLegend( ::sal_Bool bLegend ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setPlotBy( ::sal_Int32 xlRowCol ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getPlotBy( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XChartTitle > SAL_CALL getChartTitle( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Axes( const css::uno::Any& Type, const css::uno::Any& AxisGroup ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; + +#endif //SC_VBA_WINDOW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbachartobject.cxx b/sc/source/ui/vba/vbachartobject.cxx new file mode 100644 index 000000000000..839b7cf27cc0 --- /dev/null +++ b/sc/source/ui/vba/vbachartobject.cxx @@ -0,0 +1,213 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbachart.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/script/BasicErrorException.hpp> +#include <basic/sberrors.hxx> +#include "vbachartobject.hxx" +#include "vbachartobjects.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +const rtl::OUString CHART_NAME( RTL_CONSTASCII_USTRINGPARAM("Name") ); +const rtl::OUString PERSIST_NAME( RTL_CONSTASCII_USTRINGPARAM("PersistName") ); + +ScVbaChartObject::ScVbaChartObject( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableChart >& _xTableChart, const css::uno::Reference< css::drawing::XDrawPageSupplier >& _xDrawPageSupplier ) : ChartObjectImpl_BASE( _xParent, _xContext ), xTableChart( _xTableChart ), xDrawPageSupplier( _xDrawPageSupplier ) +{ + xDrawPage = xDrawPageSupplier->getDrawPage(); + xEmbeddedObjectSupplier.set( xTableChart, uno::UNO_QUERY_THROW ); + xNamed.set( xTableChart, uno::UNO_QUERY_THROW ); + sPersistName = getPersistName(); + xShape = setShape(); + setName(sPersistName); + oShapeHelper.reset(new ShapeHelper(xShape)); +} + +rtl::OUString ScVbaChartObject::getPersistName() +{ + if ( !sPersistName.getLength() ) + sPersistName = xNamed->getName(); + return sPersistName; +} + +uno::Reference< drawing::XShape > +ScVbaChartObject::setShape() throw ( script::BasicErrorException ) +{ + try + { + sal_Int32 nItems = xDrawPage->getCount(); + for (int i = 0; i < nItems; i++) + { + xShape.set( xDrawPage->getByIndex(i), uno::UNO_QUERY_THROW ); + if (xShape->getShapeType().compareToAscii("com.sun.star.drawing.OLE2Shape") == 0 ) + { + uno::Reference< beans::XPropertySet > xShapePropertySet(xShape, uno::UNO_QUERY_THROW ); + rtl::OUString sName; + xShapePropertySet->getPropertyValue(PERSIST_NAME ) >>=sName; + if ( sName.equals(sPersistName)) + { + xNamedShape.set( xShape, uno::UNO_QUERY_THROW ); + return xShape; + } + } + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return NULL; +} + +void SAL_CALL +ScVbaChartObject::setName( const rtl::OUString& sName ) throw (css::uno::RuntimeException) +{ + xNamedShape->setName(sName); +} + + +::rtl::OUString SAL_CALL +ScVbaChartObject::getName() throw (css::uno::RuntimeException) +{ + return xNamedShape->getName(); +} + +void SAL_CALL +ScVbaChartObject::Delete() throw ( css::script::BasicErrorException ) +{ + // parent of this object is sheet + uno::Reference< excel::XWorksheet > xParent( getParent(), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XChartObjects > xColl( xParent->ChartObjects( uno::Any() ), uno::UNO_QUERY_THROW ); + ScVbaChartObjects* pChartObjectsImpl = static_cast< ScVbaChartObjects* >( xColl.get() ); + if (pChartObjectsImpl) + pChartObjectsImpl->removeByName( getPersistName() ); + else + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Parent is not ChartObjects" ) ) ); +} + +void +ScVbaChartObject::Activate() throw ( script::BasicErrorException ) +{ + try + { + // #TODO #FIXME should be ThisWorkbook or equivelant, or in + // fact probably the chart object should be created with + // the XModel owner + //uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getXModel().getCurrentController()); + uno::Reference< view::XSelectionSupplier > xSelectionSupplier( getCurrentExcelDoc(mxContext)->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelectionSupplier->select(uno::makeAny(xShape)); + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChartObject Activate internal error" ) ) ); + } +} + +uno::Reference< excel::XChart > SAL_CALL +ScVbaChartObject::getChart() throw (css::uno::RuntimeException) +{ + return new ScVbaChart( this, mxContext, xEmbeddedObjectSupplier->getEmbeddedObject(), xTableChart ); +} + +rtl::OUString& +ScVbaChartObject::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObject") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaChartObject::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObject" ) ); + } + return aServiceNames; +} + +double +ScVbaChartObject::getHeight() +{ + return oShapeHelper->getHeight(); +} + +void +ScVbaChartObject::setHeight(double _fheight) throw ( script::BasicErrorException ) +{ + oShapeHelper->setHeight(_fheight); +} + +double +ScVbaChartObject::getWidth() +{ + return oShapeHelper->getWidth(); +} + +void +ScVbaChartObject::setWidth(double _fWidth) throw ( script::BasicErrorException ) +{ + oShapeHelper->setWidth(_fWidth); +} + +double +ScVbaChartObject::getLeft() +{ + return oShapeHelper->getLeft(); +} + +void +ScVbaChartObject::setLeft(double _fLeft) +{ + oShapeHelper->setLeft(_fLeft); +} + +double +ScVbaChartObject::getTop() +{ + return oShapeHelper->getTop(); +} + +void +ScVbaChartObject::setTop(double _fTop) +{ + oShapeHelper->setTop(_fTop); +} + +uno::Reference< uno::XInterface > +ScVbaChartObject::getUnoObject() throw (script::BasicErrorException) +{ + return uno::Reference< uno::XInterface >( xShape, uno::UNO_QUERY ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbachartobject.hxx b/sc/source/ui/vba/vbachartobject.hxx new file mode 100644 index 000000000000..4e995d98a9fa --- /dev/null +++ b/sc/source/ui/vba/vbachartobject.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHARTOBJECT_HXX +#define SC_VBA_CHARTOBJECT_HXX +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> +#include <ooo/vba/excel/XChartObject.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <memory> + +typedef InheritedHelperInterfaceImpl1<ov::excel::XChartObject > ChartObjectImpl_BASE; + +class ScVbaChartObject : public ChartObjectImpl_BASE +{ + + css::uno::Reference< css::table::XTableChart > xTableChart; + css::uno::Reference< css::document::XEmbeddedObjectSupplier > xEmbeddedObjectSupplier; + css::uno::Reference< css::beans::XPropertySet > xPropertySet; + css::uno::Reference< css::drawing::XDrawPageSupplier > xDrawPageSupplier; + css::uno::Reference< css::drawing::XDrawPage > xDrawPage; + css::uno::Reference< css::drawing::XShape > xShape; + css::uno::Reference< css::container::XNamed > xNamed; + rtl::OUString sPersistName; + std::auto_ptr<ov::ShapeHelper> oShapeHelper; + css::uno::Reference< css::container::XNamed > xNamedShape; + rtl::OUString getPersistName(); + css::uno::Reference< css::drawing::XShape > setShape() throw ( css::script::BasicErrorException ); +public: + ScVbaChartObject( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableChart >& _xTableChart, const css::uno::Reference< css::drawing::XDrawPageSupplier >& _xDrawPageSupplier ); + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& sName ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XChart > SAL_CALL getChart() throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete() throw ( css::script::BasicErrorException ); + virtual void Activate() throw ( css::script::BasicErrorException ); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + // non interface methods + double getHeight(); + void setHeight( double _fheight ) throw ( css::script::BasicErrorException ); + double getWidth(); + void setWidth( double _fwidth ) throw ( css::script::BasicErrorException ); + double getLeft(); + void setLeft( double _fleft ); + double getTop(); + void setTop( double _ftop ); + // should make this part of the XHelperInterface with a default + // implementation returning NULL + css::uno::Reference< css::uno::XInterface > getUnoObject() throw ( css::script::BasicErrorException ); +}; + +#endif //SC_VBA_WINDOW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbachartobjects.cxx b/sc/source/ui/vba/vbachartobjects.cxx new file mode 100644 index 000000000000..ff97462b1b56 --- /dev/null +++ b/sc/source/ui/vba/vbachartobjects.cxx @@ -0,0 +1,196 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbachart.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> +#include <com/sun/star/table/XTableChartsSupplier.hpp> +#include <com/sun/star/table/XTableChart.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <ooo/vba/excel/XlChartType.hpp> + + +#include "vbachartobjects.hxx" +#include "vbachartobject.hxx" +#include "vbaglobals.hxx" +#include "cellsuno.hxx" +#include <vector> +#include <basic/sberrors.hxx> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + + +class ChartObjectEnumerationImpl : public EnumerationHelperImpl +{ + uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier; + +public: + + ChartObjectEnumerationImpl( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier, const uno::Reference< XHelperInterface >& _xParent ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( _xParent, xContext, xEnumeration ), xDrawPageSupplier( _xDrawPageSupplier ) {} + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + // parent Object is sheet + return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) ) ); + } +}; + + +ScVbaChartObjects::ScVbaChartObjects( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableCharts >& _xTableCharts, const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier ) : ChartObjects_BASE(_xParent, _xContext, css::uno::Reference< css::container::XIndexAccess >( _xTableCharts, css::uno::UNO_QUERY ) ), xTableCharts( _xTableCharts ) , xDrawPageSupplier( _xDrawPageSupplier ) +{ + +} + +void +ScVbaChartObjects::removeByName(const rtl::OUString& _sChartName) +{ + xTableCharts->removeByName( _sChartName ); +} + +uno::Sequence< rtl::OUString > +ScVbaChartObjects::getChartObjectNames() throw( css::script::BasicErrorException ) +{ + uno::Sequence< rtl::OUString > sChartNames; + try + { + // c++ hackery + uno::Reference< uno::XInterface > xIf( xDrawPageSupplier, uno::UNO_QUERY_THROW ); + ScCellRangesBase* pUno= dynamic_cast< ScCellRangesBase* >( xIf.get() ); + ScDocShell* pDocShell = NULL; + if ( !pUno ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("Failed to obtain the impl class from the drawpage"), uno::Reference< uno::XInterface >() ); + pDocShell = pUno->GetDocShell(); + if ( !pDocShell ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("Failed to obtain the docshell implclass"), uno::Reference< uno::XInterface >() ); + + uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( pDocShell->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSpreadsheetDocument->getSheets(); + std::vector< rtl::OUString > aChartNamesVector; + + uno::Sequence< rtl::OUString > sSheetNames = xSpreadsheets->getElementNames(); + sal_Int32 nItems = sSheetNames.getLength(); + for (sal_Int32 i = 0; i < nItems; i++) + { + uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(sSheetNames[i]), uno::UNO_QUERY_THROW ); + uno::Sequence< rtl::OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames(); + sal_Int32 nChartNames = scurchartnames.getLength(); + for (sal_Int32 n = 0; n < nChartNames; n++ ) + aChartNamesVector.push_back(scurchartnames[n]); + } + sChartNames.realloc( aChartNamesVector.size() ); + std::vector< rtl::OUString > ::const_iterator it = aChartNamesVector.begin(); + std::vector< rtl::OUString > ::const_iterator it_end = aChartNamesVector.end(); + for ( sal_Int32 index = 0 ; it != it_end; ++it, ++index ) + sChartNames[index] = *it; + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return sChartNames; +} + +// XChartObjects +uno::Any SAL_CALL +ScVbaChartObjects::Add( double _nX, double _nY, double _nWidth, double _nHeight ) throw (script::BasicErrorException) +{ + try + { + uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 ); + awt::Rectangle aRectangle; + aRectangle.X = Millimeter::getInHundredthsOfOneMillimeter(_nX); + aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY); + aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth); + aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight); + // Note the space at the end of the stem ("Chart "). In ChartSheets only "Chart" is the stem + rtl::OUString sPersistChartName = ContainerUtilities::getUniqueName( getChartObjectNames(), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Chart " ) ) , rtl::OUString(), 1); + xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress, true, false ); + uno::Reference< excel::XChartObject > xChartObject( getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW ); + xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered); + return uno::makeAny( xChartObject ); + } + catch ( uno::Exception& ex) + { + OSL_TRACE("AddItem caught exception ->%s", rtl::OUStringToOString( ex.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + return aNULL(); +} +void SAL_CALL ScVbaChartObjects::Delete( ) throw (script::BasicErrorException) +{ + uno::Sequence< rtl::OUString > sChartNames = xTableCharts->getElementNames(); + sal_Int32 ncount = sChartNames.getLength(); + for (sal_Int32 i = 0; i < ncount ; i++) + removeByName(sChartNames[i]); +} + +// XEnumerationAccess + +uno::Reference< container::XEnumeration > +ScVbaChartObjects::createEnumeration() throw (uno::RuntimeException) +{ + css::uno::Reference< container::XEnumerationAccess > xEnumAccess( xTableCharts, uno::UNO_QUERY_THROW ); + return new ChartObjectEnumerationImpl( mxContext, xEnumAccess->createEnumeration(), xDrawPageSupplier, getParent() /* sheet */); +} + +// XElementAccess + +uno::Type +ScVbaChartObjects::getElementType() throw (uno::RuntimeException) +{ + return excel::XChartObject::static_type(0); +} + +// ScVbaCollectionBaseImpl +uno::Any +ScVbaChartObjects::createCollectionObject( const css::uno::Any& aSource ) +{ + uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW ); + // correct parent object is sheet + return uno::makeAny( uno::Reference< excel::XChartObject > ( new ScVbaChartObject( getParent(), mxContext, xTableChart, xDrawPageSupplier ) ) ); +} + +rtl::OUString& +ScVbaChartObjects::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChartObjects") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaChartObjects::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ChartObjects") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbachartobjects.hxx b/sc/source/ui/vba/vbachartobjects.hxx new file mode 100644 index 000000000000..232b07401b90 --- /dev/null +++ b/sc/source/ui/vba/vbachartobjects.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHARTOBJECTS_HXX +#define SC_VBA_CHARTOBJECTS_HXX +#include <ooo/vba/excel/XChartObjects.hpp> +#include <ooo/vba/excel/XChartObject.hpp> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/table/XTableCharts.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <vbahelper/vbacollectionimpl.hxx> +#include "excelvbahelper.hxx" +#include <hash_map> + +typedef CollTestImplHelper< ov::excel::XChartObjects > ChartObjects_BASE; +/* #TODO see if this hash table is 'really' necessary +typedef ::std::hash_map< ::rtl::OUString, +css::uno::Reference< ov::excel::XChartObject >, + ::rtl::OUStringHash, + ::std::equal_to< ::rtl::OUString > > aHashTable; +*/ + +class ScVbaChartObjects : public ChartObjects_BASE +{ + + css::uno::Reference< css::table::XTableCharts > xTableCharts; + css::uno::Reference< css::drawing::XDrawPageSupplier > xDrawPageSupplier; + // method associated with populating the hashmap ( I'm not convinced this is necessary ) + //css::uno::Reference< ov::excel::XChartObject > putByPersistName( const rtl:::OUString& _sPersistChartName ); +public: + ScVbaChartObjects( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::table::XTableCharts >& _xTableCharts, const css::uno::Reference< css::drawing::XDrawPageSupplier >& _xDrawPageSupplier ); + + css::uno::Sequence< rtl::OUString > getChartObjectNames() throw( css::script::BasicErrorException ); + void removeByName(const rtl::OUString& _sChartName); + + // XChartObjects + virtual ::com::sun::star::uno::Any SAL_CALL Add( double Left, double Top, double Width, double Height ) throw (::com::sun::star::script::BasicErrorException); + virtual void SAL_CALL Delete( ) throw (::com::sun::star::script::BasicErrorException); + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + // ChartObjects_BASE + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_WINDOW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacharts.cxx b/sc/source/ui/vba/vbacharts.cxx new file mode 100644 index 000000000000..d9a720dc3dd1 --- /dev/null +++ b/sc/source/ui/vba/vbacharts.cxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacharts.hxx" +#include <basic/sberrors.hxx> +#include <com/sun/star/table/XTableChartsSupplier.hpp> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + + +ScVbaCharts::ScVbaCharts( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const uno::Reference< frame::XModel >& xModel ) : Charts_BASE(_xParent, _xContext, uno::Reference< container::XIndexAccess >()) +{ + xComponent.set( xModel, uno::UNO_QUERY_THROW ); + xSpreadsheetDocument.set( xComponent, uno::UNO_QUERY_THROW ); +} + +uno::Any SAL_CALL +ScVbaCharts::Add() throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + // Not implemented in the helperapi ( see ChartsImpl.java ) + if ( true ) + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() ); + return aNULL(); +} + +uno::Reference< excel::XChart > SAL_CALL +ScVbaCharts::getActiveChart() throw (script::BasicErrorException, uno::RuntimeException) +{ + return xActiveChart; +} + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaCharts::createEnumeration() throw (uno::RuntimeException) +{ + // #FIXME not implemented + if ( true ) + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() ); + return uno::Reference< container::XEnumeration >(); +} + +// #FIXME #TODO this method shouldn't appear in this class directly +// a XIndexAccess/XNameAccess wrapper should be passed to the base class instead +::sal_Int32 SAL_CALL +ScVbaCharts::getCount() throw (uno::RuntimeException) +{ + sal_Int32 ncount = 0; + try + { + uno::Reference< sheet::XSpreadsheets > xSpreadsheets( xSpreadsheetDocument->getSheets() ); + uno::Sequence< rtl::OUString > SheetNames = xSpreadsheets->getElementNames(); + sal_Int32 nLen = SheetNames.getLength(); + for (sal_Int32 i = 0; i < nLen; i++) + { + uno::Reference< table::XTableChartsSupplier > xTableChartsSupplier( xSpreadsheets->getByName(SheetNames[i]), uno::UNO_QUERY); + if ( xTableChartsSupplier.is() ) + { + uno::Reference< table::XTableCharts > xTableCharts = xTableChartsSupplier->getCharts(); + ncount =+ xTableCharts->getElementNames().getLength(); + } + } + } + catch (uno::Exception& ) + { + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return ncount; +} + +uno::Any +ScVbaCharts::createCollectionObject( const uno::Any& aSource ) +{ + if ( true ) + throw script::BasicErrorException( rtl::OUString(), uno::Reference< uno::XInterface >(), SbERR_BAD_METHOD, rtl::OUString() ); + // #TODO implementation please + return aSource; +} + +rtl::OUString& +ScVbaCharts::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCharts") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaCharts::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Charts") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacharts.hxx b/sc/source/ui/vba/vbacharts.hxx new file mode 100644 index 000000000000..399910a6c2f6 --- /dev/null +++ b/sc/source/ui/vba/vbacharts.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHARTS_HXX +#define SC_VBA_CHARTS_HXX +#include <ooo/vba/excel/XCharts.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <vbahelper/vbacollectionimpl.hxx> +#include "excelvbahelper.hxx" +#include <hash_map> + +typedef CollTestImplHelper< ov::excel::XCharts > Charts_BASE; + +class ScVbaCharts : public Charts_BASE +{ + css::uno::Reference< ov::excel::XChart > xActiveChart; + css::uno::Reference< css::sheet::XSpreadsheetDocument > xSpreadsheetDocument; + css::uno::Reference< css::lang::XComponent > xComponent; +public: + ScVbaCharts( const css::uno::Reference< ov::XHelperInterface >& _xParent, const css::uno::Reference< css::uno::XComponentContext >& _xContext, const css::uno::Reference< css::frame::XModel >& xModel ); + // XCharts + virtual css::uno::Any SAL_CALL Add() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XChart > SAL_CALL getActiveChart( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XCollection + ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException) { return ov::excel::XChart::static_type(0); } + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + // Charts_BASE or HelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacharttitle.cxx b/sc/source/ui/vba/vbacharttitle.cxx new file mode 100644 index 000000000000..ca81743b179f --- /dev/null +++ b/sc/source/ui/vba/vbacharttitle.cxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacharttitle.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaChartTitle::ScVbaChartTitle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& _xTitleShape ) : ChartTitleBase( xParent, xContext, _xTitleShape ) +{ +} + +rtl::OUString& +ScVbaChartTitle::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaChartTitle") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaChartTitle::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + uno::Sequence< rtl::OUString > BaseServiceNames = ChartTitleBase::getServiceNames(); + aServiceNames.realloc( BaseServiceNames.getLength() + 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Chart" ) ); + for ( sal_Int32 index = 1; index < (BaseServiceNames.getLength() + 1); ++index ) + aServiceNames[ index ] = BaseServiceNames[ index ]; + } + return aServiceNames; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacharttitle.hxx b/sc/source/ui/vba/vbacharttitle.hxx new file mode 100644 index 000000000000..2fe2d9e618d9 --- /dev/null +++ b/sc/source/ui/vba/vbacharttitle.hxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHARTTITLE_HXX +#define SC_VBA_CHARTTITLE_HXX +#include "vbatitle.hxx" +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XChartTitle.hpp> + + +typedef TitleImpl< cppu::WeakImplHelper1< ov::excel::XChartTitle > > ChartTitleBase; + +class ScVbaChartTitle : public ChartTitleBase +{ +public: + ScVbaChartTitle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& _xTitleShape ); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacomment.cxx b/sc/source/ui/vba/vbacomment.cxx new file mode 100644 index 000000000000..f707fad1eb13 --- /dev/null +++ b/sc/source/ui/vba/vbacomment.cxx @@ -0,0 +1,252 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacomment.hxx" + +#include <ooo/vba/excel/XlCreator.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp> +#include <com/sun/star/sheet/XSheetCellRange.hpp> +#include <com/sun/star/sheet/XCellAddressable.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XText.hpp> + +#include <cellsuno.hxx> +#include <postit.hxx> +#include <svx/svdobj.hxx> +#include <svx/svdocapt.hxx> +#include <ooo/vba/msforms/XShape.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/frame/XModel.hpp> + +#include <vbahelper/vbashape.hxx> +#include "vbaglobals.hxx" +#include "vbacomments.hxx" +#include "vbacommentshape.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaComment::ScVbaComment( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< frame::XModel >& xModel, + const uno::Reference< table::XCellRange >& xRange ) throw( lang::IllegalArgumentException ) : + ScVbaComment_BASE( xParent, xContext ), + mxModel( xModel, uno::UNO_SET_THROW ), + mxRange( xRange ) +{ + if ( !xRange.is() ) + throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "range is not set " ) ), uno::Reference< uno::XInterface >() , 1 ); + uno::Reference< text::XSimpleText > xAnnoText( getAnnotation(), uno::UNO_QUERY ); +} + +// private helper functions + +uno::Reference< sheet::XSheetAnnotation > SAL_CALL +ScVbaComment::getAnnotation() throw (uno::RuntimeException) +{ + uno::Reference< table::XCell > xCell( mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSheetAnnotationAnchor > xAnnoAnchor( xCell, uno::UNO_QUERY_THROW ); + return uno::Reference< sheet::XSheetAnnotation > ( xAnnoAnchor->getAnnotation(), uno::UNO_QUERY_THROW ); +} + +uno::Reference< sheet::XSheetAnnotations > SAL_CALL +ScVbaComment::getAnnotations() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSheetCellRange > xSheetCellRange(mxRange, ::uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet(); + uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW ); + + return uno::Reference< sheet::XSheetAnnotations > ( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW ); +} + +sal_Int32 SAL_CALL +ScVbaComment::getAnnotationIndex() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSheetAnnotations > xAnnos = getAnnotations(); + table::CellAddress aAddress = getAnnotation()->getPosition(); + + sal_Int32 aIndex = 0; + sal_Int32 aCount = xAnnos->getCount(); + + for ( ; aIndex < aCount ; aIndex++ ) + { + uno::Reference< sheet::XSheetAnnotation > xAnno( xAnnos->getByIndex( aIndex ), uno::UNO_QUERY_THROW ); + table::CellAddress xAddress = xAnno->getPosition(); + + if ( xAddress.Column == aAddress.Column && xAddress.Row == aAddress.Row && xAddress.Sheet == aAddress.Sheet ) + { + OSL_TRACE("** terminating search, index is %d", aIndex ); + break; + } + } + OSL_TRACE("** returning index is %d", aIndex ); + + return aIndex; +} + +uno::Reference< excel::XComment > SAL_CALL +ScVbaComment::getCommentByIndex( sal_Int32 Index ) throw (uno::RuntimeException) +{ + uno::Reference< container::XIndexAccess > xIndexAccess( getAnnotations(), uno::UNO_QUERY_THROW ); + // parent is sheet ( parent of the range which is the parent of the comment ) + uno::Reference< XCollection > xColl( new ScVbaComments( getParent()->getParent(), mxContext, mxModel, xIndexAccess ) ); + + return uno::Reference< excel::XComment > ( xColl->Item( uno::makeAny( Index ), uno::Any() ), uno::UNO_QUERY_THROW ); + } + +// public vba functions + +rtl::OUString SAL_CALL +ScVbaComment::getAuthor() throw (uno::RuntimeException) +{ + return getAnnotation()->getAuthor(); +} + +void SAL_CALL +ScVbaComment::setAuthor( const rtl::OUString& /*_author*/ ) throw (uno::RuntimeException) +{ + // #TODO #FIXME implementation needed +} + +uno::Reference< msforms::XShape > SAL_CALL +ScVbaComment::getShape() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSheetAnnotationShapeSupplier > xAnnoShapeSupp( getAnnotation(), uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XShape > xAnnoShape( xAnnoShapeSupp->getAnnotationShape(), uno::UNO_SET_THROW ); + uno::Reference< sheet::XSheetCellRange > xCellRange( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XShapes > xShapes( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW ); + return new ScVbaShape( this, mxContext, xAnnoShape, xShapes, mxModel, office::MsoShapeType::msoComment ); +} + +sal_Bool SAL_CALL +ScVbaComment::getVisible() throw (uno::RuntimeException) +{ + return getAnnotation()->getIsVisible(); +} + +void SAL_CALL +ScVbaComment::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) +{ + getAnnotation()->setIsVisible( _visible ); +} + +void SAL_CALL +ScVbaComment::Delete() throw (uno::RuntimeException) +{ + getAnnotations()->removeByIndex( getAnnotationIndex() ); +} + +uno::Reference< excel::XComment > SAL_CALL +ScVbaComment::Next() throw (uno::RuntimeException) +{ + // index: uno = 0, vba = 1 + return getCommentByIndex( getAnnotationIndex() + 2 ); +} + +uno::Reference< excel::XComment > SAL_CALL +ScVbaComment::Previous() throw (uno::RuntimeException) +{ + // index: uno = 0, vba = 1 + return getCommentByIndex( getAnnotationIndex() ); +} + +rtl::OUString SAL_CALL +ScVbaComment::Text( const uno::Any& aText, const uno::Any& aStart, const uno::Any& Overwrite ) throw (uno::RuntimeException) +{ + rtl::OUString sText; + aText >>= sText; + + uno::Reference< text::XSimpleText > xAnnoText( getAnnotation(), uno::UNO_QUERY_THROW ); + + if ( aStart.hasValue() ) + { + sal_Int16 nStart = 0; + sal_Bool bOverwrite = sal_True; + Overwrite >>= bOverwrite; + + if ( aStart >>= nStart ) + { + uno::Reference< text::XTextCursor > xTextCursor( xAnnoText->createTextCursor(), uno::UNO_QUERY_THROW ); + + if ( bOverwrite ) + { + xTextCursor->collapseToStart(); + xTextCursor->gotoStart( sal_False ); + xTextCursor->goRight( nStart - 1, sal_False ); + xTextCursor->gotoEnd( sal_True ); + } + else + { + xTextCursor->collapseToStart(); + xTextCursor->gotoStart( sal_False ); + xTextCursor->goRight( nStart - 1 , sal_True ); + } + + uno::Reference< text::XTextRange > xRange( xTextCursor, uno::UNO_QUERY_THROW ); + xAnnoText->insertString( xRange, sText, bOverwrite ); + return xAnnoText->getString(); + } + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScVbaComment::Text - bad Start value " ) ), uno::Reference< uno::XInterface >() ); + } + else if ( aText.hasValue() ) + { + uno::Reference< sheet::XCellAddressable > xCellAddr(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); + table::CellAddress aAddress = xCellAddr->getCellAddress(); + getAnnotations()->insertNew( aAddress, sText ); + } + + rtl::OUString sAnnoText = xAnnoText->getString(); + return sAnnoText; +} + +rtl::OUString& +ScVbaComment::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComment") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaComment::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.ScVbaComment" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacomment.hxx b/sc/source/ui/vba/vbacomment.hxx new file mode 100644 index 000000000000..7f6a5a3d5a77 --- /dev/null +++ b/sc/source/ui/vba/vbacomment.hxx @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMMENT_HXX +#define SC_VBA_COMMENT_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <ooo/vba/excel/XComment.hpp> +#include <ooo/vba/excel/XApplication.hpp> +#include <ooo/vba/msforms/XShape.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XComment > ScVbaComment_BASE; + +class ScVbaComment : public ScVbaComment_BASE +{ + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::table::XCellRange > mxRange; + +private: + css::uno::Reference< css::sheet::XSheetAnnotation > SAL_CALL getAnnotation() throw (css::uno::RuntimeException); + css::uno::Reference< css::sheet::XSheetAnnotations > SAL_CALL getAnnotations() throw (css::uno::RuntimeException); + sal_Int32 SAL_CALL getAnnotationIndex() throw (css::uno::RuntimeException); + css::uno::Reference< ov::excel::XComment > SAL_CALL getCommentByIndex( sal_Int32 Index ) throw (css::uno::RuntimeException); +public: + ScVbaComment( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::table::XCellRange >& xRange ) throw ( css::lang::IllegalArgumentException ); + + virtual ~ScVbaComment() {} + + // Attributes + virtual rtl::OUString SAL_CALL getAuthor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAuthor( const rtl::OUString& _author ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XShape > SAL_CALL getShape() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XComment > SAL_CALL Next() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XComment > SAL_CALL Previous() throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL Text( const css::uno::Any& Text, const css::uno::Any& Start, const css::uno::Any& Overwrite ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SC_VBA_COMMENT_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacomments.cxx b/sc/source/ui/vba/vbacomments.cxx new file mode 100644 index 000000000000..4d8d79a2106b --- /dev/null +++ b/sc/source/ui/vba/vbacomments.cxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacomments.hxx" + +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> + +#include "vbaglobals.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +uno::Any AnnotationToComment( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) +{ + uno::Reference< sheet::XSheetAnnotation > xAnno( aSource, uno::UNO_QUERY_THROW ); + uno::Reference< container::XChild > xChild( xAnno, uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xCellRange( xChild->getParent(), uno::UNO_QUERY_THROW ); + + // #FIXME needs to find the correct Parent + return uno::makeAny( uno::Reference< excel::XComment > ( + new ScVbaComment( uno::Reference< XHelperInterface >(), xContext, xModel, xCellRange ) ) ); +} + +class CommentEnumeration : public EnumerationHelperImpl +{ + css::uno::Reference< css::frame::XModel > mxModel; +public: + CommentEnumeration( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< container::XEnumeration >& xEnumeration, + const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : + EnumerationHelperImpl( xParent, xContext, xEnumeration ), + mxModel( xModel, uno::UNO_SET_THROW ) + {} + + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + return AnnotationToComment( m_xEnumeration->nextElement(), m_xContext, mxModel ); + } + +}; + +ScVbaComments::ScVbaComments( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext > & xContext, + const uno::Reference< frame::XModel >& xModel, + const uno::Reference< container::XIndexAccess >& xIndexAccess ) : + ScVbaComments_BASE( xParent, xContext, xIndexAccess ), + mxModel( xModel, uno::UNO_SET_THROW ) +{ +} + +// public helper functions + +uno::Reference< container::XEnumeration > +ScVbaComments::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return new CommentEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration(), mxModel ); +} + +uno::Any +ScVbaComments::createCollectionObject( const css::uno::Any& aSource ) +{ + return AnnotationToComment( aSource, mxContext, mxModel ); +} + +uno::Type +ScVbaComments::getElementType() throw (uno::RuntimeException) +{ + return excel::XComment::static_type(0); +} + +rtl::OUString& +ScVbaComments::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComments") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaComments::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Comments") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacomments.hxx b/sc/source/ui/vba/vbacomments.hxx new file mode 100644 index 000000000000..babefb4e6739 --- /dev/null +++ b/sc/source/ui/vba/vbacomments.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMMENTS_HXX +#define SC_VBA_COMMENTS_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <ooo/vba/excel/XComments.hpp> + +#include "excelvbahelper.hxx" +#include <vbahelper/vbacollectionimpl.hxx> +#include "vbacomment.hxx" + +typedef CollTestImplHelper< ov::excel::XComments > ScVbaComments_BASE; + +class ScVbaComments : public ScVbaComments_BASE +{ +public: + ScVbaComments( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext > & xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + + virtual ~ScVbaComments() {} + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // ScVbaComments_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +private: + css::uno::Reference< css::frame::XModel > mxModel; +}; + +#endif /* SC_VBA_COMMENTS_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacommentshape.cxx b/sc/source/ui/vba/vbacommentshape.cxx new file mode 100644 index 000000000000..768b63636ad2 --- /dev/null +++ b/sc/source/ui/vba/vbacommentshape.cxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbacommentshape.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaCommentShape::ScVbaCommentShape( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< excel::XComment >& xComment, + const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel, sal_Int32 nType ) : ScVbaShape( xParent, xContext, xShape, xShapes, xModel, nType ) +{ + m_xComment.set( xComment, uno::UNO_QUERY ); +} + +void SAL_CALL ScVbaCommentShape::Delete() throw (uno::RuntimeException) +{ + if ( m_xComment.is() ) + { + m_xComment->Delete(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacommentshape.hxx b/sc/source/ui/vba/vbacommentshape.hxx new file mode 100644 index 000000000000..6943321cbaef --- /dev/null +++ b/sc/source/ui/vba/vbacommentshape.hxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_COMMENTSHAPE_HXX +#define SC_VBA_COMMENTSHAPE_HXX + +#include <ooo/vba/excel/XComment.hpp> +#include <vbahelper/vbashape.hxx> + +class ScVbaCommentShape : public ScVbaShape +{ + css::uno::Reference< ooo::vba::excel::XComment > m_xComment; + +public: + ScVbaCommentShape( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, + const css::uno::Reference< ooo::vba::excel::XComment >& xComment, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nType ); + + // Methods + virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); +}; +#endif //SC_VBA_COMMENTSHAPE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacondition.cxx b/sc/source/ui/vba/vbacondition.cxx new file mode 100644 index 000000000000..6065f123ef39 --- /dev/null +++ b/sc/source/ui/vba/vbacondition.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbacondition.hxx" +#include <ooo/vba/excel/XlFormatConditionOperator.hpp> +#include <ooo/vba/excel/XFormatCondition.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +const sal_Int32 ISFORMULA = 98765432; + +template< typename Ifc1 > +ScVbaCondition< Ifc1 >::ScVbaCondition( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) : ScVbaCondition_BASE( xParent, xContext ), mxSheetCondition( _xSheetCondition ) +{ + mxAddressable.set( xParent, uno::UNO_QUERY_THROW ); +} + +template< typename Ifc1 > +sheet::ConditionOperator +ScVbaCondition< Ifc1 >::retrieveAPIOperator( const uno::Any& _aOperator) throw ( script::BasicErrorException ) +{ + sheet::ConditionOperator aRetAPIOperator = sheet::ConditionOperator_NONE; + sal_Int32 nOperator = 0; + if ( (_aOperator >>= nOperator ) ) + { + switch(nOperator) + { + case excel::XlFormatConditionOperator::xlBetween: + aRetAPIOperator = sheet::ConditionOperator_BETWEEN; + break; + case excel::XlFormatConditionOperator::xlNotBetween: + aRetAPIOperator = sheet::ConditionOperator_NOT_BETWEEN; + break; + case excel::XlFormatConditionOperator::xlEqual: + aRetAPIOperator = sheet::ConditionOperator_EQUAL; + break; + case excel::XlFormatConditionOperator::xlNotEqual: + aRetAPIOperator = sheet::ConditionOperator_NOT_EQUAL; + break; + case excel::XlFormatConditionOperator::xlGreater: + aRetAPIOperator = sheet::ConditionOperator_GREATER; + break; + case excel::XlFormatConditionOperator::xlLess: + aRetAPIOperator = sheet::ConditionOperator_LESS; + break; + case excel::XlFormatConditionOperator::xlGreaterEqual: + aRetAPIOperator = sheet::ConditionOperator_GREATER_EQUAL; + break; + case excel::XlFormatConditionOperator::xlLessEqual: + aRetAPIOperator = sheet::ConditionOperator_LESS_EQUAL; + break; + default: + aRetAPIOperator = sheet::ConditionOperator_NONE; + break; + } + } + return aRetAPIOperator; +} + +template< typename Ifc1 > +rtl::OUString +ScVbaCondition< Ifc1 >::Formula1( ) throw ( script::BasicErrorException, uno::RuntimeException ) +{ + return mxSheetCondition->getFormula1(); +} + +template< typename Ifc1 > +rtl::OUString +ScVbaCondition< Ifc1 >::Formula2( ) throw ( script::BasicErrorException, uno::RuntimeException ) +{ + return mxSheetCondition->getFormula2(); +} + +template< typename Ifc1 > +void +ScVbaCondition< Ifc1 >::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException ) +{ + rtl::OUString sFormula; + if ( (_aFormula1 >>= sFormula )) + { + mxSheetCondition->setFormula1( sFormula ); + table::CellRangeAddress aCellRangeAddress = mxAddressable->getRangeAddress(); + table::CellAddress aCellAddress( aCellRangeAddress.Sheet, aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow ); + mxSheetCondition->setSourcePosition(aCellAddress); + } +} + +template< typename Ifc1 > +void +ScVbaCondition< Ifc1 >::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException ) +{ + rtl::OUString sFormula2; + // #TODO surely this can't be right? + // ( from helperapi/impl/.../calc/ConditionImpl.java + if ( (_aFormula2 >>= sFormula2 )) + mxSheetCondition->setFormula1(sFormula2); +} + +template< typename Ifc1 > +sal_Int32 +ScVbaCondition< Ifc1 >::Operator(sal_Bool _bIncludeFormulaValue) throw ( script::BasicErrorException ) +{ + sal_Int32 retvalue = -1; + sheet::ConditionOperator aConditionalOperator = mxSheetCondition->getOperator(); + switch (aConditionalOperator) + { + case sheet::ConditionOperator_EQUAL: + retvalue = excel::XlFormatConditionOperator::xlEqual; + break; + case sheet::ConditionOperator_NOT_EQUAL: + retvalue = excel::XlFormatConditionOperator::xlNotEqual; + break; + case sheet::ConditionOperator_GREATER: + retvalue = excel::XlFormatConditionOperator::xlGreater; + break; + case sheet::ConditionOperator_GREATER_EQUAL: + retvalue = excel::XlFormatConditionOperator::xlGreaterEqual; + break; + case sheet::ConditionOperator_LESS: + retvalue = excel::XlFormatConditionOperator::xlLess; + break; + case sheet::ConditionOperator_LESS_EQUAL: + retvalue = excel::XlFormatConditionOperator::xlLessEqual; + break; + case sheet::ConditionOperator_BETWEEN: + retvalue = excel::XlFormatConditionOperator::xlBetween; + break; + case sheet::ConditionOperator_NOT_BETWEEN: + retvalue = excel::XlFormatConditionOperator::xlNotBetween; + break; + case sheet::ConditionOperator_FORMULA: + if (_bIncludeFormulaValue) + { + //#FIXME huh what's this all about + // from helperapi/impl/.../calc/ConditionImpl + retvalue = ISFORMULA; + break; + } + case sheet::ConditionOperator_NONE: + default: + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Operator not supported"))); + break; + } + return retvalue; +} + +template class ScVbaCondition< excel::XFormatCondition >; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbacondition.hxx b/sc/source/ui/vba/vbacondition.hxx new file mode 100644 index 000000000000..80e1b5bccd88 --- /dev/null +++ b/sc/source/ui/vba/vbacondition.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CONDITION_HXX +#define SC_VBA_CONDITION_HXX +#include <com/sun/star/sheet/XSheetCondition.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/sheet/ConditionOperator.hpp> + +template< typename Ifc1 > +class ScVbaCondition : public InheritedHelperInterfaceImpl1< Ifc1 > +{ +typedef InheritedHelperInterfaceImpl1< Ifc1 > ScVbaCondition_BASE; +protected: + css::uno::Reference< css::sheet::XCellRangeAddressable > mxAddressable; + css::uno::Reference< css::sheet::XSheetCondition > mxSheetCondition; +public: + ScVbaCondition( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetCondition >& _xSheetCondition ); + + static css::sheet::ConditionOperator retrieveAPIOperator( const css::uno::Any& _aOperator) throw ( css::script::BasicErrorException ); + + virtual rtl::OUString SAL_CALL Formula1( ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + virtual rtl::OUString SAL_CALL Formula2( ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + virtual void setFormula1( const css::uno::Any& _aFormula1) throw ( css::script::BasicErrorException ); + virtual void setFormula2( const css::uno::Any& _aFormula2) throw ( css::script::BasicErrorException ); + virtual sal_Int32 Operator(sal_Bool _bIncludeFormulaValue) throw ( css::script::BasicErrorException ); + virtual sal_Int32 SAL_CALL Operator() throw ( css::script::BasicErrorException, css::uno::RuntimeException ) = 0; + +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbadialog.cxx b/sc/source/ui/vba/vbadialog.cxx new file mode 100644 index 000000000000..452fa9aeb84a --- /dev/null +++ b/sc/source/ui/vba/vbadialog.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbadialog.hxx" + +#include <sal/macros.h> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +//liuchen 2009-7-27 +//solve the problem that "Application.Dialogs.Item(***).Show" and "Application.Dialogs.Count" cannot get the correct result +struct DialogMatch +{ + sal_Int32 nVbaDlgIndex; + rtl::OUString aOODlgName; +}; + +static const DialogMatch aDialogMatchList[] = +{ + { 1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Open" ) ) }, // xlDialogOpen -> .uno:Open + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FormatCellDialog" ) ) }, // ??? -> .uno:FormatCellDialog + { 55, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertCell" ) ) }, // xlDialogInsert -> .uno:InsertCell + { 8, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Print" ) ) }, // xlDialogPrint -> .uno:Print + { 9, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrinterSetup" ) ) }, // xlDialogPrinterSetup -> .uno:PrinterSetup + { 53, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PasteSpecial" ) ) }, // xlDialogPasteSpecial -> .uno:PasteSpecial + { 28, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ToolProtectionDocument" ) ) }, // xlDialogProtectDocument -> uno:ToolProtectionDocument + { 47, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ColumnWidth" ) ) }, // xlDialogColumnWidth -> .uno:ColumnWidth + { 61, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DefineName" ) ) }, // xlDialogDefineName -> .uno:DefineName + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConfigureDialog" ) ) }, // ??? -> .uno:ConfigureDialog + { 596, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:HyperlinkDialog" ) ) }, // xlDialogInsertHyperlink -> .uno:HyperlinkDialog + { 342, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertGraphic" ) ) }, // xlDialogInsertPicture -> .uno:InsertGraphic + { 259, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:InsertObject" ) ) }, // xlDialogInsertObject -> .uno:InsertObject + { 7, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PageFormatDialog" ) ) }, // xlDialogPageSetup -> .uno:PageFormatDialog + { 39, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DataSort" ) ) }, // xlDialogSort -> .uno:DataSort + { 127, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:RowHeight" ) ) }, // xlDialogRowHeight -> .uno:RowHeight + { 485, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AutoCorrectDlg" ) ) }, // xlDialogAutoCorrect -> .uno:AutoCorrectDlg + { 583, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ConditionalFormatDialog" ) ) }, // xlDialogCondiationalFormatting -> .uno:ConditionalFormatDialog + { 191, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DataConsolidate" ) ) }, // xlDialogConsolidate -> .uno:DataConsolidate + { 62, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CreateNames" ) ) }, // xlDialogCreateNames -> .uno:CreateNames + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillSeries" ) ) }, // ??? -> .uno:FillSeries + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Validation" ) ) }, // ??? -> .uno:Validation" + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DefineLabelRange" ) ) }, // ??? -> .uno:DefineLabelRange + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DataFilterAutoFilter" ) ) }, // ??? -> .uno:DataFilterAutoFilter + { -1, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:DataFilterSpecialFilter" ) ) }, // ??? -> .uno:DataFilterSpecialFilter + { 269, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AutoFormat" ) ) } // xlDialogFormatAuto -> .uno:AutoFormat +}; + +const sal_Int32 nDialogSize = SAL_N_ELEMENTS( aDialogMatchList ) ; + +//liuchen modified 2009-2-27 +rtl::OUString +ScVbaDialog::mapIndexToName( sal_Int32 nIndex ) +{ + for (int i = 0; i < nDialogSize; i++) + { + if ( aDialogMatchList[i].nVbaDlgIndex == nIndex ) + { + return aDialogMatchList[i].aOODlgName; + } + } + + return rtl::OUString(); +} + +rtl::OUString& +ScVbaDialog::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaDialog") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaDialog::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Dialog" ) ); + } + return aServiceNames; +} + +//liuchen add 2009-7-27 +sal_Int32 ScVbaDialog::GetSupportedDialogCount() +{ + return nDialogSize; +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbadialog.hxx b/sc/source/ui/vba/vbadialog.hxx new file mode 100644 index 000000000000..9c73aca10fbf --- /dev/null +++ b/sc/source/ui/vba/vbadialog.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_DIALOG_HXX +#define SC_VBA_DIALOG_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XDialog.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbadialogbase.hxx> + +typedef cppu::ImplInheritanceHelper1< VbaDialogBase, ov::excel::XDialog > ScVbaDialog_BASE; + +class ScVbaDialog : public ScVbaDialog_BASE +{ +public: + ScVbaDialog( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > xContext, const css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nIndex ):ScVbaDialog_BASE( xParent, xContext, xModel, nIndex ) {} + virtual ~ScVbaDialog() {} + + // Methods + virtual rtl::OUString mapIndexToName( sal_Int32 nIndex ); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + + //liuchen 2009-7-27 + static sal_Int32 GetSupportedDialogCount(); +}; + +#endif /* SC_VBA_DIALOG_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbadialogs.cxx b/sc/source/ui/vba/vbadialogs.cxx new file mode 100644 index 000000000000..361d1a45329c --- /dev/null +++ b/sc/source/ui/vba/vbadialogs.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <ooo/vba/excel/XDialog.hpp> +#include "vbadialogs.hxx" +#include "vbadialog.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +void +ScVbaDialogs::Dummy() throw (uno::RuntimeException) +{ +} + +uno::Any +ScVbaDialogs::Item( const uno::Any &aItem ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + aItem >>= nIndex; + uno::Reference< excel::XDialog > aDialog( new ScVbaDialog( uno::Reference< XHelperInterface >( Application(),uno::UNO_QUERY_THROW ), mxContext, m_xModel, nIndex ) ); + return uno::Any( aDialog ); +} + +rtl::OUString& +ScVbaDialogs::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaDialogs") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaDialogs::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Dialogs" ) ); + } + return aServiceNames; +} + +//liuchen 2009-7-27 +::sal_Int32 +ScVbaDialogs::getCount() throw (uno::RuntimeException) +{ + return ScVbaDialog::GetSupportedDialogCount(); +} + + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbadialogs.hxx b/sc/source/ui/vba/vbadialogs.hxx new file mode 100644 index 000000000000..785757b0a4e5 --- /dev/null +++ b/sc/source/ui/vba/vbadialogs.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_DIALOGS_HXX +#define SC_VBA_DIALOGS_HXX + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <ooo/vba/excel/XDialogs.hpp> +#include <ooo/vba/XCollection.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbadialogsbase.hxx> +#include <cppuhelper/implbase1.hxx> + +typedef cppu::ImplInheritanceHelper1< VbaDialogsBase, ov::excel::XDialogs > ScVbaDialogs_BASE; + +class ScVbaDialogs : public ScVbaDialogs_BASE +{ +public: + ScVbaDialogs( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel ): ScVbaDialogs_BASE( xParent, xContext, xModel ) {} + virtual ~ScVbaDialogs() {} + + // XCollection + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); //liuchen 2009-7-27 + + // XDialogs + virtual void SAL_CALL Dummy() throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SC_VBA_DIALOGS_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaeventshelper.cxx b/sc/source/ui/vba/vbaeventshelper.cxx new file mode 100644 index 000000000000..abca80602ef5 --- /dev/null +++ b/sc/source/ui/vba/vbaeventshelper.cxx @@ -0,0 +1,764 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbaeventshelper.hxx" + +#include <com/sun/star/awt/XWindowListener.hpp> +#include <com/sun/star/frame/XBorderResizeListener.hpp> +#include <com/sun/star/frame/XControllerBorder.hpp> +#include <com/sun/star/script/vba/VBAEventId.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/util/XChangesListener.hpp> +#include <com/sun/star/util/XChangesNotifier.hpp> +#include <com/sun/star/util/XCloseListener.hpp> + +#include <ooo/vba/excel/XApplication.hpp> + +#include <cppuhelper/implbase4.hxx> +#include <toolkit/unohlp.hxx> +#include <vbahelper/helperdecl.hxx> +#include <vcl/svapp.hxx> +#include <vcl/window.hxx> + +#include "cellsuno.hxx" +#include "convuno.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::script::vba::VBAEventId; +using namespace ::ooo::vba; + +// ============================================================================ + +typedef ::cppu::WeakImplHelper4< + awt::XWindowListener, util::XCloseListener, frame::XBorderResizeListener, util::XChangesListener > ScVbaEventsListener_BASE; + +// This class is to process Workbook window related event +class ScVbaEventsListener : public ScVbaEventsListener_BASE +{ +public : + ScVbaEventsListener( ScVbaEventsHelper& rVbaEvents, const uno::Reference< frame::XModel >& rxModel, ScDocShell* pDocShell ); + virtual ~ScVbaEventsListener(); + + void startListening(); + void stopListening(); + + // XWindowListener + virtual void SAL_CALL windowResized( const awt::WindowEvent& aEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowMoved( const awt::WindowEvent& aEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowShown( const lang::EventObject& aEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL windowHidden( const lang::EventObject& aEvent ) throw (uno::RuntimeException); + virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw (uno::RuntimeException); + + // XCloseListener + virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException); + virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException); + + // XBorderResizeListener + virtual void SAL_CALL borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject, const frame::BorderWidths& aNewSize ) throw (uno::RuntimeException); + + // XChangesListener + virtual void SAL_CALL changesOccurred( const util::ChangesEvent& aEvent ) throw (uno::RuntimeException); + +private: + uno::Reference< frame::XFrame > getFrame(); + uno::Reference< awt::XWindow > getContainerWindow(); + bool isMouseReleased(); + DECL_LINK( fireResizeMacro, void* ); + void processWindowResizeMacro(); + +private: + ::osl::Mutex maMutex; + ScVbaEventsHelper& mrVbaEvents; + uno::Reference< frame::XModel > mxModel; + ScDocShell* mpDocShell; + bool mbWindowResized; + bool mbBorderChanged; + bool mbDisposed; +}; + +// ---------------------------------------------------------------------------- + +ScVbaEventsListener::ScVbaEventsListener( ScVbaEventsHelper& rVbaEvents, const uno::Reference< frame::XModel >& rxModel, ScDocShell* pDocShell ) : + mrVbaEvents( rVbaEvents ), + mxModel( rxModel ), + mpDocShell( pDocShell ), + mbWindowResized( false ), + mbBorderChanged( false ), + mbDisposed( !rxModel.is() ) +{ + OSL_TRACE( "ScVbaEventsListener::ScVbaEventsListener( 0x%x ) - ctor ", this ); +} + +ScVbaEventsListener::~ScVbaEventsListener() +{ + OSL_TRACE( "ScVbaEventsListener::~ScVbaEventsListener( 0x%x ) - dtor ", this ); + stopListening(); +} + +void ScVbaEventsListener::startListening() +{ + if( !mbDisposed ) + { + // add window listener + try + { + uno::Reference< awt::XWindow > xWindow( getContainerWindow(), uno::UNO_QUERY_THROW ); + xWindow->addWindowListener( this ); + } + catch( uno::Exception& ) + { + } + // add close listener + try + { + uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( mxModel, uno::UNO_QUERY_THROW ); + xCloseBroadcaster->addCloseListener( this ); + } + catch( uno::Exception& ) + { + } + // add Border resize listener + try + { + uno::Reference< frame::XControllerBorder > xControllerBorder( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xControllerBorder->addBorderResizeListener( this ); + } + catch( uno::Exception& ) + { + } + // add content change listener + try + { + uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); + xChangesNotifier->addChangesListener( this ); + } + catch( uno::Exception& ) + { + } + } +} + +void ScVbaEventsListener::stopListening() +{ + if( !mbDisposed ) + { + try + { + uno::Reference< awt::XWindow > xWindow( getContainerWindow(), uno::UNO_QUERY_THROW ); + xWindow->removeWindowListener( this ); + } + catch( uno::Exception& ) + { + } + try + { + uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( mxModel, uno::UNO_QUERY_THROW ); + xCloseBroadcaster->removeCloseListener( this ); + } + catch( uno::Exception& ) + { + } + try + { + uno::Reference< frame::XControllerBorder > xControllerBorder( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xControllerBorder->removeBorderResizeListener( this ); + } + catch( uno::Exception& ) + { + } + try + { + uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModel, uno::UNO_QUERY_THROW ); + xChangesNotifier->removeChangesListener( this ); + } + catch( uno::Exception& ) + { + } + } + mbDisposed = true; +} + +void SAL_CALL ScVbaEventsListener::windowResized( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + // Workbook_window_resize event + mbWindowResized = true; + if( !mbDisposed && mbBorderChanged ) + { + if( /*Window* pWindow =*/ VCLUnoHelper::GetWindow( getContainerWindow() ) ) + { + mbBorderChanged = mbWindowResized = false; + acquire(); // ensure we don't get deleted before the event is handled + Application::PostUserEvent( LINK( this, ScVbaEventsListener, fireResizeMacro ), 0 ); + } + } +} + +void SAL_CALL ScVbaEventsListener::windowMoved( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException ) +{ + // not interest this time +} + +void SAL_CALL ScVbaEventsListener::windowShown( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException ) +{ + // not interest this time +} + +void SAL_CALL ScVbaEventsListener::windowHidden( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException ) +{ + // not interest this time +} + +void SAL_CALL ScVbaEventsListener::disposing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( maMutex ); + OSL_TRACE( "ScVbaEventsListener::disposing( 0x%x )", this ); + mbDisposed = true; +} + +void SAL_CALL ScVbaEventsListener::queryClosing( const lang::EventObject& /*Source*/, sal_Bool /*GetsOwnership*/ ) throw (util::CloseVetoException, uno::RuntimeException) +{ + // it can cancel the close, but need to throw a CloseVetoException, and it will be transmit to caller. +} + +void SAL_CALL ScVbaEventsListener::notifyClosing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( maMutex ); + stopListening(); +} + +void SAL_CALL ScVbaEventsListener::borderWidthsChanged( const uno::Reference< uno::XInterface >& /*aObject*/, const frame::BorderWidths& /*aNewSize*/ ) throw (uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( maMutex ); + // work with WindowResized event to guard Window Resize event. + mbBorderChanged = true; + if( !mbDisposed && mbWindowResized ) + { + if( /*Window* pWindow =*/ VCLUnoHelper::GetWindow( getContainerWindow() ) ) + { + mbWindowResized = mbBorderChanged = false; + acquire(); // ensure we don't get deleted before the timer fires. + Application::PostUserEvent( LINK( this, ScVbaEventsListener, fireResizeMacro ), 0 ); + } + } +} + +void SAL_CALL ScVbaEventsListener::changesOccurred( const util::ChangesEvent& aEvent ) throw (uno::RuntimeException) +{ + sal_Int32 nCount = aEvent.Changes.getLength(); + if( nCount == 0 ) + return; + + util::ElementChange aChange = aEvent.Changes[ 0 ]; + rtl::OUString sOperation; + aChange.Accessor >>= sOperation; + if( !sOperation.equalsIgnoreAsciiCaseAscii("cell-change") ) + return; + + if( nCount == 1 ) + { + uno::Reference< table::XCellRange > xRangeObj; + aChange.ReplacedElement >>= xRangeObj; + if( xRangeObj.is() ) + { + uno::Sequence< uno::Any > aArgs(1); + aArgs[0] <<= xRangeObj; + mrVbaEvents.processVbaEvent( WORKSHEET_CHANGE, aArgs ); + } + return; + } + + ScRangeList aRangeList; + for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) + { + aChange = aEvent.Changes[ nIndex ]; + aChange.Accessor >>= sOperation; + uno::Reference< table::XCellRange > xRangeObj; + aChange.ReplacedElement >>= xRangeObj; + if( xRangeObj.is() && sOperation.equalsIgnoreAsciiCaseAscii("cell-change") ) + { + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable( xRangeObj, uno::UNO_QUERY ); + if( xCellRangeAddressable.is() ) + { + ScRange aRange; + ScUnoConversion::FillScRange( aRange, xCellRangeAddressable->getRangeAddress() ); + aRangeList.Append( aRange ); + } + } + } + + if( (aRangeList.Count() > 0) && mpDocShell ) + { + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( mpDocShell, aRangeList ) ); + uno::Sequence< uno::Any > aArgs(1); + aArgs[0] <<= xRanges; + mrVbaEvents.processVbaEvent( WORKSHEET_CHANGE, aArgs ); + } +} + +// ---------------------------------------------------------------------------- + +uno::Reference< frame::XFrame > ScVbaEventsListener::getFrame() +{ + if( !mbDisposed && mxModel.is() ) try + { + uno::Reference< frame::XController > xController( mxModel->getCurrentController(), uno::UNO_QUERY_THROW ); + return xController->getFrame(); + } + catch( uno::Exception& ) + { + } + return uno::Reference< frame::XFrame >(); +} + +uno::Reference< awt::XWindow > ScVbaEventsListener::getContainerWindow() +{ + try + { + uno::Reference< frame::XFrame > xFrame( getFrame(), uno::UNO_SET_THROW ); + return xFrame->getContainerWindow(); + } + catch( uno::Exception& ) + { + } + return uno::Reference< awt::XWindow >(); +} + +bool ScVbaEventsListener::isMouseReleased() +{ + if( Window* pWindow = VCLUnoHelper::GetWindow( getContainerWindow() ) ) + { + Window::PointerState aPointerState = pWindow->GetPointerState(); + return (aPointerState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT )) == 0; + } + return false; +} + +IMPL_LINK( ScVbaEventsListener, fireResizeMacro, void*, EMPTYARG ) +{ + if( !mbDisposed && isMouseReleased() ) + processWindowResizeMacro(); + release(); + return 0; +} + +void ScVbaEventsListener::processWindowResizeMacro() +{ + OSL_TRACE( "**** Attempt to FIRE MACRO **** " ); + if( !mbDisposed ) + { + try + { + mrVbaEvents.processVbaEvent( WORKBOOK_WINDOWRESIZE, uno::Sequence< uno::Any >() ); + } + catch( uno::Exception& ) + { + } + } +} + +// ============================================================================ + +ScVbaEventsHelper::ScVbaEventsHelper( const uno::Sequence< uno::Any >& rArgs, const uno::Reference< uno::XComponentContext >& xContext ) : + VbaEventsHelperBase( rArgs, xContext ), + mbOpened( false ) +{ + mpDocShell = dynamic_cast< ScDocShell* >( mpShell ); // mpShell from base class + mpDoc = mpDocShell ? mpDocShell->GetDocument() : 0; + + if( !mxModel.is() || !mpDocShell || !mpDoc ) + return; + +#define REGISTER_EVENT( eventid, eventname, type, cancelindex, worksheet ) \ + registerEventHandler( eventid, eventname, type, cancelindex, uno::Any( worksheet ) ) + +#define REGISTER_WORKBOOK_EVENT( eventid, eventname, cancelindex ) \ + REGISTER_EVENT( WORKBOOK_##eventid, "Workbook_" eventname, EVENTHANDLER_DOCUMENT, cancelindex, false ) + +#define REGISTER_WORKSHEET_EVENT( eventid, eventname, cancelindex ) \ + REGISTER_EVENT( WORKSHEET_##eventid, "Worksheet_" eventname, EVENTHANDLER_DOCUMENT, cancelindex, true ); \ + REGISTER_EVENT( (USERDEFINED_START + WORKSHEET_##eventid), "Workbook_Sheet" eventname, EVENTHANDLER_DOCUMENT, (((cancelindex) >= 0) ? ((cancelindex) + 1) : -1), false ) + + // global + REGISTER_EVENT( AUTO_OPEN, "Auto_Open", EVENTHANDLER_GLOBAL, -1, false ); + REGISTER_EVENT( AUTO_CLOSE, "Auto_Close", EVENTHANDLER_GLOBAL, -1, false ); + + // Workbook + REGISTER_WORKBOOK_EVENT( ACTIVATE, "Activate", -1 ); + REGISTER_WORKBOOK_EVENT( DEACTIVATE, "Deactivate", -1 ); + REGISTER_WORKBOOK_EVENT( OPEN, "Open", -1 ); + REGISTER_WORKBOOK_EVENT( BEFORECLOSE, "BeforeClose", 0 ); + REGISTER_WORKBOOK_EVENT( BEFOREPRINT, "BeforePrint", 0 ); + REGISTER_WORKBOOK_EVENT( BEFORESAVE, "BeforeSave", 1 ); + REGISTER_WORKBOOK_EVENT( AFTERSAVE, "AfterSave", -1 ); + REGISTER_WORKBOOK_EVENT( NEWSHEET, "NewSheet", -1 ); + REGISTER_WORKBOOK_EVENT( WINDOWACTIVATE, "WindowActivate", -1 ); + REGISTER_WORKBOOK_EVENT( WINDOWDEACTIVATE, "WindowDeactivate", -1 ); + REGISTER_WORKBOOK_EVENT( WINDOWRESIZE, "WindowResize", -1 ); + + // Worksheet events. All events have a corresponding workbook event. + REGISTER_WORKSHEET_EVENT( ACTIVATE, "Activate", -1 ); + REGISTER_WORKSHEET_EVENT( DEACTIVATE, "Deactivate", -1 ); + REGISTER_WORKSHEET_EVENT( BEFOREDOUBLECLICK, "BeforeDoubleClick", 1 ); + REGISTER_WORKSHEET_EVENT( BEFORERIGHTCLICK, "BeforeRightClick", 1 ); + REGISTER_WORKSHEET_EVENT( CALCULATE, "Calculate", -1 ); + REGISTER_WORKSHEET_EVENT( CHANGE, "Change", -1 ); + REGISTER_WORKSHEET_EVENT( SELECTIONCHANGE, "SelectionChange", -1 ); + REGISTER_WORKSHEET_EVENT( FOLLOWHYPERLINK, "FollowHyperlink", -1 ); + +#undef REGISTER_EVENT +#undef REGISTER_WORKBOOK_EVENT +#undef REGISTER_WORKSHEET_EVENT +} + +ScVbaEventsHelper::~ScVbaEventsHelper() +{ +} + +void SAL_CALL ScVbaEventsHelper::disposing( const lang::EventObject& rSource ) throw (uno::RuntimeException) +{ + mxListener.clear(); + VbaEventsHelperBase::disposing( rSource ); +} + +// protected ------------------------------------------------------------------ + +bool ScVbaEventsHelper::implEventsEnabled() throw (uno::RuntimeException) +{ + // document and document shell are needed during event processing + if( !mpDocShell || !mpDoc ) + throw uno::RuntimeException(); + + // get Application object and check if events are enabled (this is an Excel-only attribute) + uno::Reference< excel::XApplication > xApplication( mxApplication.get(), uno::UNO_QUERY ); + if( !xApplication.is() && mpShell ) + { + uno::Any aVBAGlobals; + mpShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aVBAGlobals ); + uno::Reference< XHelperInterface > xHelperInterface( aVBAGlobals, uno::UNO_QUERY ); + if( xHelperInterface.is() ) + { + xApplication.set( xHelperInterface->Application(), uno::UNO_QUERY ); + mxApplication = xApplication; + } + } + if( !xApplication.is() ) + throw uno::RuntimeException(); + + // return whether event processing is enabled + return xApplication->getEnableEvents(); +} + +bool ScVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& rArgs ) throw (uno::RuntimeException) +{ + // check preconditions for some events, add more events if needed + bool bExecuteEvent = true; + switch( rInfo.mnEventId ) + { + case WORKBOOK_ACTIVATE: + // while loading, framework fires this before 'opened' event, delay it + bExecuteEvent = mbOpened; + break; + case WORKBOOK_OPEN: + bExecuteEvent = !mbOpened; + if( bExecuteEvent ) + { + // execute delayed Activate event too (see above) + rEventQueue.push_back( WORKBOOK_ACTIVATE ); + rEventQueue.push_back( WORKBOOK_WINDOWACTIVATE ); + rEventQueue.push_back( AUTO_OPEN ); + } + break; + case WORKSHEET_SELECTIONCHANGE: + // if selection is not changed, then do not fire the event + bExecuteEvent = mbOpened && isSelectionChanged( rArgs, 0 ); + break; + } + + // add workbook event associated to a sheet event + bool bSheetEvent = false; + rInfo.maUserData >>= bSheetEvent; + if( bSheetEvent && bExecuteEvent ) + rEventQueue.push_back( EventQueueEntry( rInfo.mnEventId + USERDEFINED_START, rArgs ) ); + + return bExecuteEvent; +} + +uno::Sequence< uno::Any > ScVbaEventsHelper::implBuildArgumentList( const EventHandlerInfo& rInfo, + const uno::Sequence< uno::Any >& rArgs ) throw (lang::IllegalArgumentException) +{ + // fill arguments for workbook events associated to sheet events according to sheet events, sheet will be added below + bool bSheetEventAsBookEvent = rInfo.mnEventId > USERDEFINED_START; + sal_Int32 nEventId = bSheetEventAsBookEvent ? (rInfo.mnEventId - USERDEFINED_START) : rInfo.mnEventId; + + uno::Sequence< uno::Any > aVbaArgs; + switch( nEventId ) + { + // *** Workbook *** + + // no arguments + case WORKBOOK_ACTIVATE: + case WORKBOOK_DEACTIVATE: + case WORKBOOK_OPEN: + break; + // 1 arg: cancel + case WORKBOOK_BEFORECLOSE: + case WORKBOOK_BEFOREPRINT: + aVbaArgs.realloc( 1 ); + // current cancel state will be inserted by caller + break; + // 2 args: saveAs, cancel + case WORKBOOK_BEFORESAVE: + aVbaArgs.realloc( 2 ); + checkArgumentType< bool >( rArgs, 0 ); + aVbaArgs[ 0 ] = rArgs[ 0 ]; + // current cancel state will be inserted by caller + break; + // 1 arg: success + case WORKBOOK_AFTERSAVE: + aVbaArgs.realloc( 1 ); + checkArgumentType< bool >( rArgs, 0 ); + aVbaArgs[ 0 ] = rArgs[ 0 ]; + break; + // 1 arg: window + case WORKBOOK_WINDOWACTIVATE: + case WORKBOOK_WINDOWDEACTIVATE: + case WORKBOOK_WINDOWRESIZE: + aVbaArgs.realloc( 1 ); + aVbaArgs[ 0 ] = createWindow(); + break; + // 1 arg: worksheet + case WORKBOOK_NEWSHEET: + aVbaArgs.realloc( 1 ); + aVbaArgs[ 0 ] = createWorksheet( rArgs, 0 ); + break; + + // *** Worksheet *** + + // no arguments + case WORKSHEET_ACTIVATE: + case WORKSHEET_CALCULATE: + case WORKSHEET_DEACTIVATE: + break; + // 1 arg: range + case WORKSHEET_CHANGE: + case WORKSHEET_SELECTIONCHANGE: + aVbaArgs.realloc( 1 ); + aVbaArgs[ 0 ] = createRange( rArgs, 0 ); + break; + // 2 args: range, cancel + case WORKSHEET_BEFOREDOUBLECLICK: + case WORKSHEET_BEFORERIGHTCLICK: + aVbaArgs.realloc( 2 ); + aVbaArgs[ 0 ] = createRange( rArgs, 0 ); + // current cancel state will be inserted by caller + break; + // 1 arg: hyperlink + case WORKSHEET_FOLLOWHYPERLINK: + aVbaArgs.realloc( 1 ); + aVbaArgs[ 0 ] = createHyperlink( rArgs, 0 ); + break; + } + + /* For workbook events associated to sheet events, the workbook event gets + the same arguments but with a Worksheet object in front of them. */ + if( bSheetEventAsBookEvent ) + { + sal_Int32 nLength = aVbaArgs.getLength(); + uno::Sequence< uno::Any > aVbaArgs2( nLength + 1 ); + aVbaArgs2[ 0 ] = createWorksheet( rArgs, 0 ); + for( sal_Int32 nIndex = 0; nIndex < nLength; ++nIndex ) + aVbaArgs2[ nIndex + 1 ] = aVbaArgs[ nIndex ]; + aVbaArgs = aVbaArgs2; + } + + return aVbaArgs; +} + +void ScVbaEventsHelper::implPostProcessEvent( EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, bool /*bSuccess*/, bool bCancel ) throw (uno::RuntimeException) +{ + switch( rInfo.mnEventId ) + { + case WORKBOOK_OPEN: + mbOpened = true; + // register the listeners + if( !mxListener.is() ) + { + mxListener = new ScVbaEventsListener( *this, mxModel, mpDocShell ); + mxListener->startListening(); + } + break; + case WORKBOOK_BEFORECLOSE: + /* Execute Auto_Close only if not cancelled by event handler, but + before UI asks user whether to cancel closing the document. */ + if( !bCancel ) + rEventQueue.push_back( AUTO_CLOSE ); + break; + } +} + +::rtl::OUString ScVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& rInfo, + const uno::Sequence< uno::Any >& rArgs ) const throw (lang::IllegalArgumentException) +{ + bool bSheetEvent = false; + rInfo.maUserData >>= bSheetEvent; + SCTAB nTab = bSheetEvent ? getTabFromArgs( rArgs, 0 ) : -1; + if( bSheetEvent && (nTab < 0) ) + throw lang::IllegalArgumentException(); + + String aCodeName; + if( bSheetEvent ) + mpDoc->GetCodeName( nTab, aCodeName ); + else + aCodeName = mpDoc->GetCodeName(); + return aCodeName; +} + +// private -------------------------------------------------------------------- + +SCTAB ScVbaEventsHelper::getTabFromArgs( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) throw (lang::IllegalArgumentException) +{ + checkArgument( rArgs, nIndex ); + + // first try to extract a sheet index + SCTAB nTab = -1; + if( rArgs[ nIndex ] >>= nTab ) + return nTab; + + // next, try single range object + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable = getXSomethingFromArgs< sheet::XCellRangeAddressable >( rArgs, nIndex ); + if( xCellRangeAddressable.is() ) + return xCellRangeAddressable->getRangeAddress().Sheet; + + // at last, try range list + uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); + if( xRanges.is() ) + { + uno::Sequence< table::CellRangeAddress > aRangeAddresses = xRanges->getRangeAddresses(); + if( aRangeAddresses.getLength() > 0 ) + return aRangeAddresses[ 0 ].Sheet; + } + + throw lang::IllegalArgumentException(); +} + +bool ScVbaEventsHelper::isSelectionChanged( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + uno::Reference< uno::XInterface > xNewSelection = getXSomethingFromArgs< uno::XInterface >( rArgs, nIndex, false ); + if( ScCellRangesBase* pNewCellRanges = ScCellRangesBase::getImplementation( xNewSelection ) ) + { + bool bChanged = maOldSelection != pNewCellRanges->GetRangeList(); + maOldSelection = pNewCellRanges->GetRangeList(); + return bChanged; + } + maOldSelection.Clear(); + return true; +} + +uno::Any ScVbaEventsHelper::createWorksheet( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + // Eventually we will be able to pull the Workbook/Worksheet objects + // directly from basic and register them as listeners + + // extract sheet index, will throw, if parameter is invalid + SCTAB nTab = getTabFromArgs( rArgs, nIndex ); + + // create Workbook + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= uno::Reference< uno::XInterface >(); + aArgs[ 1 ] <<= mxModel; + uno::Reference< uno::XInterface > xWorkbook( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Workbook", aArgs ), uno::UNO_SET_THROW ); + + // create WorkSheet + String aSheetName; + mpDoc->GetName( nTab, aSheetName ); + aArgs = uno::Sequence< uno::Any >( 3 ); + aArgs[ 0 ] <<= xWorkbook; + aArgs[ 1 ] <<= mxModel; + aArgs[ 2 ] <<= ::rtl::OUString( aSheetName ); + uno::Reference< uno::XInterface > xWorksheet( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Worksheet", aArgs ), uno::UNO_SET_THROW ); + return uno::Any( xWorksheet ); +} + +uno::Any ScVbaEventsHelper::createRange( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + uno::Reference< sheet::XSheetCellRangeContainer > xRanges = getXSomethingFromArgs< sheet::XSheetCellRangeContainer >( rArgs, nIndex ); + uno::Reference< table::XCellRange > xRange = getXSomethingFromArgs< table::XCellRange >( rArgs, nIndex ); + if ( !xRanges.is() && !xRange.is() ) + throw lang::IllegalArgumentException(); + + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= uno::Reference< uno::XInterface >(); // dummy parent + if ( xRanges.is() ) + aArgs[ 1 ] <<= xRanges; + else + aArgs[ 1 ] <<= xRange; + uno::Reference< uno::XInterface > xVbaRange( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Range", aArgs ), uno::UNO_SET_THROW ); + return uno::Any( xVbaRange ); +} + +uno::Any ScVbaEventsHelper::createHyperlink( const uno::Sequence< uno::Any >& rArgs, sal_Int32 nIndex ) const + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= uno::Reference< uno::XInterface >(); // dummy parent + aArgs[ 1 ] <<= getXSomethingFromArgs< table::XCell >( rArgs, nIndex, false ); + uno::Reference< uno::XInterface > xHyperlink( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Hyperlink", aArgs ), uno::UNO_SET_THROW ); + return uno::Any( xHyperlink ); +} + +uno::Any ScVbaEventsHelper::createWindow() const throw (uno::RuntimeException) +{ + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= createVBAUnoAPIService( mpShell, "ooo.vba.Application" ); + aArgs[ 1 ] <<= mxModel; + uno::Reference< uno::XInterface > xWindow( createVBAUnoAPIServiceWithArgs( mpShell, "ooo.vba.excel.Window", aArgs ), uno::UNO_SET_THROW ); + return uno::Any( xWindow ); +} + +// ============================================================================ + +namespace vbaeventshelper +{ +namespace sdecl = comphelper::service_decl; +sdecl::class_<ScVbaEventsHelper, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaEventsHelper", + "com.sun.star.script.vba.VBASpreadsheetEventProcessor" ); +} + +// ============================================================================ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaeventshelper.hxx b/sc/source/ui/vba/vbaeventshelper.hxx new file mode 100644 index 000000000000..3bd9655139b5 --- /dev/null +++ b/sc/source/ui/vba/vbaeventshelper.hxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBAEVENTS_HXX +#define SC_VBAEVENTS_HXX + +#include <rtl/ref.hxx> +#include <vbahelper/vbaeventshelperbase.hxx> +#include "excelvbahelper.hxx" +#include "rangelst.hxx" + +namespace ooo { namespace vba { namespace excel { class XApplication; } } } + +class ScVbaEventsListener; + +// ============================================================================ + +class ScVbaEventsHelper : public VbaEventsHelperBase +{ +public: + ScVbaEventsHelper( + const css::uno::Sequence< css::uno::Any >& rArgs, + const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + virtual ~ScVbaEventsHelper(); + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rSource ) throw (css::uno::RuntimeException); + +protected: + virtual bool implEventsEnabled() throw (css::uno::RuntimeException); + virtual bool implPrepareEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException); + virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException); + virtual void implPostProcessEvent( EventQueue& rEventQueue, const EventHandlerInfo& rInfo, bool bSuccess, bool bCancel ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString implGetDocumentModuleName( const EventHandlerInfo& rInfo, const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException); + +private: + /** Extracts a sheet index from the first element of the passed sequence. The + element may be an integer, or a Calc range or ranges object. */ + static SCTAB getTabFromArgs( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException); + /** Checks if selection has been changed compared to selection of last call. + @return true, if the selection has been changed. */ + bool isSelectionChanged( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + + /** Creates a VBA Worksheet object (the argument must contain a sheet index). */ + css::uno::Any createWorksheet( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) const throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + /** Creates a VBA Range object (the argument must contain a UNO range or UNO range list). */ + css::uno::Any createRange( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) const throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + /** Creates a VBA Hyperlink object (the argument must contain a UNO cell). */ + css::uno::Any createHyperlink( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) const throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + /** Creates a VBA Window object. */ + css::uno::Any createWindow() const throw (css::uno::RuntimeException); + +private: + mutable css::uno::WeakReference< ov::excel::XApplication > mxApplication; + ::rtl::Reference< ScVbaEventsListener > mxListener; + ScDocShell* mpDocShell; + ScDocument* mpDoc; + ScRangeList maOldSelection; + bool mbOpened; +}; + +// ============================================================================ + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafiledialog.cxx b/sc/source/ui/vba/vbafiledialog.cxx new file mode 100644 index 000000000000..9cb308529b88 --- /dev/null +++ b/sc/source/ui/vba/vbafiledialog.cxx @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbafiledialog.hxx" +#include "comphelper/processfactory.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ui/dialogs/XFilePicker.hpp> +#include <com/sun/star/ui/dialogs/XFilePicker2.hpp> +#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> +#include "tools/urlobj.hxx" + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + + +ScVbaFileDialog::ScVbaFileDialog( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel ) +: ScVbaFileDialog_BASE( xParent, xContext, xModel ) +{ + m_pFileDialogSelectedItems = new VbaFileDialogSelectedItems(xParent, xContext, (com::sun::star::container::XIndexAccess *)&m_FileDialogSelectedObj); +} + +ScVbaFileDialog::~ScVbaFileDialog() +{ + if (m_pFileDialogSelectedItems != NULL) + { + delete m_pFileDialogSelectedItems; + } +} + +rtl::OUString& +ScVbaFileDialog::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFileDialog") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaFileDialog::getServiceNames() +{ + static Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FileDialog" ) ); + } + return aServiceNames; + +} + +css::uno::Reference< ov::XFileDialogSelectedItems > SAL_CALL +ScVbaFileDialog::getSelectedItems() throw (css::uno::RuntimeException) +{ + css::uno::Reference< ov::XFileDialogSelectedItems > xFileDlgSlc = (ov::XFileDialogSelectedItems *)m_pFileDialogSelectedItems; + return xFileDlgSlc; +} + +::sal_Int32 SAL_CALL +ScVbaFileDialog::Show( ) throw (::com::sun::star::uno::RuntimeException) +{ + // Returns an Integer indicating if user pressed "Open" button(-1) or "Cancel" button(0). + sal_Int32 nResult = -1; + try + { + m_sSelectedItems.realloc(0); + + const ::rtl::OUString sServiceName = ::rtl::OUString::createFromAscii( "com.sun.star.ui.dialogs.FilePicker" ); + + Reference< lang::XMultiServiceFactory > xMSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY ); + // Set the type of File Picker Dialog: TemplateDescription::FILEOPEN_SIMPLE. + Sequence< uno::Any > aDialogType( 1 ); + aDialogType[0] <<= ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE; + Reference < ui::dialogs::XFilePicker > xFilePicker( xMSF->createInstanceWithArguments( sServiceName, aDialogType ), UNO_QUERY ); + Reference < ui::dialogs::XFilePicker2 > xFilePicker2( xFilePicker, UNO_QUERY ); + if ( xFilePicker.is() ) + { + xFilePicker->setMultiSelectionMode(sal_True); + if ( xFilePicker->execute() ) + { + sal_Bool bUseXFilePicker2 = sal_False; + Reference< lang::XServiceInfo > xServiceInfo( xFilePicker, UNO_QUERY ); + if (xServiceInfo.is()) + { + rtl::OUString sImplName = xServiceInfo->getImplementationName(); + if (sImplName.equalsAscii("com.sun.star.comp.fpicker.VistaFileDialog") || + sImplName.equalsAscii("com.sun.star.ui.dialogs.SalGtkFilePicker")) + { + bUseXFilePicker2 = sal_True; + } + } + if ( bUseXFilePicker2 && xFilePicker2.is() ) + { + // On Linux, XFilePicker->getFiles() always return one selected file although we select + // more than one file, also on Vista XFilePicker->getFiles() does not work well too, + // so we call XFilePicker2->getSelectedFiles() to get selected files. + m_sSelectedItems = xFilePicker2->getSelectedFiles(); + } + else + { + // If only one file is selected, the first entry of the sequence contains the complete path/filename in + // URL format. If multiple files are selected, the first entry of the sequence contains the path in URL + // format, and the other entries contains the names of the selected files without path information. + Sequence< rtl::OUString > aSelectedFiles = xFilePicker->getFiles(); + sal_Int32 iFileCount = aSelectedFiles.getLength(); + if ( iFileCount > 1 ) + { + m_sSelectedItems.realloc( iFileCount - 1 ); + INetURLObject aPath( aSelectedFiles[0] ); + aPath.setFinalSlash(); + for ( sal_Int32 i = 1; i < iFileCount; i++ ) + { + if ( aSelectedFiles[i].indexOf ('/') > 0 || aSelectedFiles[i].indexOf ('\\') > 0 ) + { + m_sSelectedItems[i - 1] = aSelectedFiles[i]; + } + else + { + if ( i == 1 ) + aPath.Append( aSelectedFiles[i] ); + else + aPath.setName( aSelectedFiles[i] ); + m_sSelectedItems[i - 1] = aPath.GetMainURL(INetURLObject::NO_DECODE); + } + } + } + else if ( iFileCount == 1 ) + { + m_sSelectedItems = aSelectedFiles; + } + } + + sal_Int32 iFileCount = m_sSelectedItems.getLength(); + rtl::OUString aTemp; + for ( sal_Int32 i = 0; i < iFileCount; i++ ) + { + INetURLObject aObj( m_sSelectedItems[i] ); + if ( aObj.GetProtocol() == INET_PROT_FILE ) + { + aTemp = aObj.PathToFileName(); + m_sSelectedItems[i] = aTemp.getLength() > 0 ? aTemp : m_sSelectedItems[i]; + } + } + } + else + { + nResult = 0; + } + } + + m_FileDialogSelectedObj.SetSelectedFile(m_sSelectedItems); + } + catch( const uno::Exception& ) + { + return 0; + } + + return nResult; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafiledialog.hxx b/sc/source/ui/vba/vbafiledialog.hxx new file mode 100644 index 000000000000..ac905f541185 --- /dev/null +++ b/sc/source/ui/vba/vbafiledialog.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _vbafiledialog_hxx_ +#define _vbafiledialog_hxx_ + +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbadialogsbase.hxx> +#include <ooo/vba/XFileDialog.hpp> +#include "vbafiledialogselecteditems.hxx" + + +typedef cppu::ImplInheritanceHelper1< VbaDialogsBase, ov::XFileDialog > ScVbaFileDialog_BASE; + +class ScVbaFileDialog : public ScVbaFileDialog_BASE +{ +public: + + ScVbaFileDialog( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel ) ; + virtual ~ScVbaFileDialog() ; + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + //XFileDialog + virtual css::uno::Reference< ov::XFileDialogSelectedItems > SAL_CALL getSelectedItems() throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL Show( ) throw (::com::sun::star::uno::RuntimeException) ; + +private: + css::uno::Sequence < rtl::OUString > m_sSelectedItems; + VbaFileDialogSelectedItems *m_pFileDialogSelectedItems; + VbaFileDialogSelectedObj m_FileDialogSelectedObj; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafiledialogselecteditems.cxx b/sc/source/ui/vba/vbafiledialogselecteditems.cxx new file mode 100644 index 000000000000..d8ebc937b489 --- /dev/null +++ b/sc/source/ui/vba/vbafiledialogselecteditems.cxx @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbafiledialogselecteditems.hxx" + +using namespace ::com::sun::star; + +VbaFileDialogSelectedItems::VbaFileDialogSelectedItems( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess + ) + : FileDialogSelectedItems_BASE( xParent, xContext, xIndexAccess ) +{ +} + + +rtl::OUString& VbaFileDialogSelectedItems::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFileDialogSelectedItems") ); + return sImplName; + +} +css::uno::Sequence<rtl::OUString> VbaFileDialogSelectedItems::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FileDialogSelectedItems" ) ); + } + return aServiceNames; + +} + +css::uno::Any VbaFileDialogSelectedItems::createCollectionObject( const css::uno::Any& aSource ) +{ + css::uno::Any aRet; + aRet = aSource; + return aRet; +} + + +css::uno::Type SAL_CALL +VbaFileDialogSelectedItems::getElementType() throw (css::uno::RuntimeException) +{ + return ooo::vba::XFileDialogSelectedItems::static_type(0); +} + +css::uno::Reference< css::container::XEnumeration > SAL_CALL +VbaFileDialogSelectedItems::createEnumeration() throw (css::uno::RuntimeException) +{ + css::uno::Reference< css::container::XEnumeration > xEnumRet(m_xIndexAccess, css::uno::UNO_QUERY); + return xEnumRet; +} + + +//VbaFileDialogSelectedObj +////////////////////////////////////////////////////////////////////////// + +VbaFileDialogSelectedObj::VbaFileDialogSelectedObj() +{ + m_nIndex = 0; +} + + +sal_Bool +VbaFileDialogSelectedObj::SetSelectedFile(css::uno::Sequence<rtl::OUString> &sFList) +{ + m_sFileList = sFList; + return sal_True; +} + +sal_Int32 SAL_CALL +VbaFileDialogSelectedObj::getCount() throw(::com::sun::star::uno::RuntimeException) +{ + sal_Int32 nListCnt = m_sFileList.getLength(); + return nListCnt; +} + +::com::sun::star::uno::Any SAL_CALL VbaFileDialogSelectedObj::getByIndex( sal_Int32 nIndex ) +throw(::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException) +{ + css::uno::Any aRet; + + if ( nIndex >= getCount() ) + { + throw css::lang::IndexOutOfBoundsException(); + } + + return uno::makeAny(m_sFileList[nIndex]); +} + +::com::sun::star::uno::Type SAL_CALL +VbaFileDialogSelectedObj::getElementType() +throw(::com::sun::star::uno::RuntimeException) +{ + return getCppuType((uno::Reference<com::sun::star::container::XIndexAccess>*)0); +} + +sal_Bool SAL_CALL VbaFileDialogSelectedObj::hasElements() +throw(::com::sun::star::uno::RuntimeException) +{ + return ( getCount() != 0 ); +} + +::sal_Bool SAL_CALL +VbaFileDialogSelectedObj::hasMoreElements( ) +throw (uno::RuntimeException) +{ + if (getCount() > m_nIndex) + { + return sal_True; + } + return sal_False; +} + +uno::Any SAL_CALL +VbaFileDialogSelectedObj::nextElement( ) +throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + if (!hasMoreElements()) + { + throw container::NoSuchElementException(); + } + + return uno::makeAny(m_sFileList[m_nIndex++]); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafiledialogselecteditems.hxx b/sc/source/ui/vba/vbafiledialogselecteditems.hxx new file mode 100644 index 000000000000..063bc502667a --- /dev/null +++ b/sc/source/ui/vba/vbafiledialogselecteditems.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _vbafiledialogselecteditems_hxx_ +#define _vbafiledialogselecteditems_hxx_ + +#include <ooo/vba/XFileDialogSelectedItems.hpp> +#include <vbahelper/vbacollectionimpl.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/container/XIndexAccess.hpp> + +typedef CollTestImplHelper< ov::XFileDialogSelectedItems > FileDialogSelectedItems_BASE; + + +class VbaFileDialogSelectedItems : public FileDialogSelectedItems_BASE +{ +public: + VbaFileDialogSelectedItems( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +private: +}; + + +class VbaFileDialogSelectedObj : public cppu::WeakImplHelper2<css::container::XIndexAccess, css::container::XEnumeration> +{ +public: + VbaFileDialogSelectedObj(); + sal_Bool SetSelectedFile(css::uno::Sequence<rtl::OUString> &sFList); + //XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) + throw(::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException); + + // XElementAccess + virtual ::com::sun::star::uno::Type SAL_CALL getElementType() + throw(::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException); + + //XEnumeration + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL nextElement( ) throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException); + +protected: +private: + css::uno::Sequence<rtl::OUString> m_sFileList; + sal_Int32 m_nIndex; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafilesearch.cxx b/sc/source/ui/vba/vbafilesearch.cxx new file mode 100644 index 000000000000..6df035c21c2b --- /dev/null +++ b/sc/source/ui/vba/vbafilesearch.cxx @@ -0,0 +1,245 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbafilesearch.hxx" +#include "vbaapplication.hxx" +#include "vbafoundfiles.hxx" +#include <comphelper/processfactory.hxx> +#include <tools/urlobj.hxx> +#include <tools/wldcrd.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess3.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <vector> +#include "unotools/viewoptions.hxx" +#include <osl/file.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::ucb; +using namespace ::com::sun::star::lang; +using namespace comphelper; + +static Reference< XSimpleFileAccess3 > getFileAccess( void ) +{ + static Reference< XSimpleFileAccess3 > xSFI; + if( !xSFI.is() ) + { + Reference< XMultiServiceFactory > xSMgr = getProcessServiceFactory(); + if( xSMgr.is() ) + { + xSFI = Reference< XSimpleFileAccess3 >( xSMgr->createInstance + ( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY ); + } + } + return xSFI; +} + +ScVbaFileSearch::ScVbaFileSearch( ScVbaApplication* pApp, const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) + : ScVbaFileSearchImpl_BASE( xParent, xContext ), m_pApplication( pApp ) +{ + NewSearch(); +} + +ScVbaFileSearch::~ScVbaFileSearch() +{ +} + +::rtl::OUString SAL_CALL ScVbaFileSearch::getFileName() throw (css::uno::RuntimeException) +{ + return m_sFileName; +} + +void SAL_CALL ScVbaFileSearch::setFileName(const ::rtl::OUString& _fileName ) throw (css::uno::RuntimeException) +{ + m_sFileName = _fileName; +} + +::rtl::OUString SAL_CALL ScVbaFileSearch::getLookIn() throw (css::uno::RuntimeException) +{ + return m_sLookIn; +} + +void SAL_CALL ScVbaFileSearch::setLookIn( const ::rtl::OUString& _lookIn ) throw (css::uno::RuntimeException) +{ + m_sLookIn = _lookIn; +} + +sal_Bool SAL_CALL ScVbaFileSearch::getSearchSubFolders() throw (css::uno::RuntimeException) +{ + return m_bSearchSubFolders; +} + +void SAL_CALL ScVbaFileSearch::setSearchSubFolders( sal_Bool _searchSubFolders ) throw (css::uno::RuntimeException) +{ + m_bSearchSubFolders = _searchSubFolders; +} + +sal_Bool SAL_CALL ScVbaFileSearch::getMatchTextExactly() throw (css::uno::RuntimeException) +{ + return m_bMatchTextExactly; +} + +void SAL_CALL ScVbaFileSearch::setMatchTextExactly( sal_Bool _matchTextExactly ) throw (css::uno::RuntimeException) +{ + m_bMatchTextExactly = _matchTextExactly; +} + +static bool IsWildCard( const ::rtl::OUString& fileName ) +{ + static sal_Char cWild1 = '*'; + static sal_Char cWild2 = '?'; + + return ( ( fileName.indexOf( cWild1 ) >= 0 ) + || ( fileName.indexOf( cWild2 ) >= 0 ) ); +} + +static void SearchWildCard(const WildCard& wildCard, const ::rtl::OUString& aDir, bool bSearchSubFolders, css::uno::Sequence< rtl::OUString >& aSearchedFiles) +{ + Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); + Sequence< rtl::OUString > aDirSeq; + try + { + if ( xSFI.is() ) + { + aDirSeq = xSFI->getFolderContents( aDir, bSearchSubFolders ); + } + } + catch( css::uno::Exception& ) + { + } + sal_Int32 nLength = aDirSeq.getLength(); + for ( sal_Int32 i = 0; i < nLength; i++ ) + { + rtl::OUString aURLStr = aDirSeq[i]; + if ( xSFI->isFolder( aURLStr ) ) + { + if ( bSearchSubFolders ) + { + SearchWildCard( wildCard, aURLStr, true, aSearchedFiles ); + } + } + else + { + INetURLObject aFileURL( aURLStr ); + rtl::OUString aFileName = aFileURL.GetLastName( INetURLObject::DECODE_UNAMBIGUOUS ); + if ( wildCard.Matches( aFileName.toAsciiLowerCase() ) ) + { + sal_Int32 nFilesLength = aSearchedFiles.getLength(); + aSearchedFiles.realloc( nFilesLength + 1 ); + rtl::OUString sSystemPath; + ::osl::File::getSystemPathFromFileURL( aURLStr, sSystemPath ); + aSearchedFiles[nFilesLength] = sSystemPath; + } + } + } +} + +sal_Int32 SAL_CALL ScVbaFileSearch::Execute( ) throw (css::uno::RuntimeException) +{ + m_aSearchedFiles.realloc(0); + Reference< XSimpleFileAccess3 > xSFI = getFileAccess(); + if ( !xSFI.is() || !xSFI->isFolder( m_sLookIn ) ) + { + return 0; + } + + if ( m_sFileName == ::rtl::OUString::createFromAscii( "" ) ) + { + return 1; + } + + ::rtl::OUString aTempFileName = m_sFileName.toAsciiLowerCase(); + if ( IsWildCard( aTempFileName ) ) + { + bool bEndWithAsterisk = aTempFileName.endsWithAsciiL("*", 1); + bool bStartWithAsterisk = (aTempFileName.indexOf(::rtl::OUString::createFromAscii("*")) == 0); + if ( !bEndWithAsterisk && !bStartWithAsterisk ) + { + aTempFileName = ::rtl::OUString::createFromAscii("*") + aTempFileName + ::rtl::OUString::createFromAscii("*"); + } + } + else + { + aTempFileName = ::rtl::OUString::createFromAscii("*") + aTempFileName + ::rtl::OUString::createFromAscii("*"); + } + WildCard wildCard( aTempFileName ); + SearchWildCard( wildCard, m_sLookIn, m_bSearchSubFolders, m_aSearchedFiles ); + + return m_aSearchedFiles.getLength(); +} + +//liuchen 2009-11-5 set ScVbaApplication::getDefaultFilePath( ) as the InitPath for FileSearch + ::rtl::OUString ScVbaFileSearch::getInitPath() throw (css::uno::RuntimeException) +{ + String aPath; + + if (m_pApplication != NULL) + { + aPath = m_pApplication->getDefaultFilePath(); + } + + return aPath; +} + +void SAL_CALL ScVbaFileSearch::NewSearch( ) throw (css::uno::RuntimeException) +{ + m_sFileName = ::rtl::OUString::createFromAscii( "" ); + m_sLookIn = getInitPath(); + m_bSearchSubFolders = false; + m_bMatchTextExactly = false; + m_aSearchedFiles.realloc(0); +} + +Reference< XFoundFiles > SAL_CALL ScVbaFileSearch::getFoundFiles() throw (css::uno::RuntimeException) +{ + css::uno::Reference< ov::XFoundFiles > xFoundFiles = new VbaFoundFiles( + mxParent, mxContext, (css::container::XIndexAccess *) new VbaFoundFilesEnum(m_aSearchedFiles) ); + return xFoundFiles; +} + +rtl::OUString& ScVbaFileSearch::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFileSearch") ); + return sImplName; +} + +css::uno::Sequence< rtl::OUString > ScVbaFileSearch::getServiceNames() +{ + static css::uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FileSearch") ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafilesearch.hxx b/sc/source/ui/vba/vbafilesearch.hxx new file mode 100644 index 000000000000..33e9caa53ca6 --- /dev/null +++ b/sc/source/ui/vba/vbafilesearch.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_FILESEARCH_HXX +#define SC_VBA_FILESEARCH_HXX + +#include <ooo/vba/XFileSearch.hpp> +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbahelperinterface.hxx> + +namespace css = ::com::sun::star; + +typedef InheritedHelperInterfaceImpl1< ooo::vba::XFileSearch > ScVbaFileSearchImpl_BASE; + +class ScVbaApplication; + +class ScVbaFileSearch : public ScVbaFileSearchImpl_BASE +{ +private: + rtl::OUString m_sFileName; + rtl::OUString m_sLookIn; + sal_Bool m_bSearchSubFolders; + sal_Bool m_bMatchTextExactly; + ScVbaApplication* m_pApplication; + css::uno::Sequence< rtl::OUString > m_aSearchedFiles; + + ::rtl::OUString getInitPath() throw (css::uno::RuntimeException); + +public: + ScVbaFileSearch( ScVbaApplication* pApp, const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + virtual ~ScVbaFileSearch(); + + // Attributes + virtual ::rtl::OUString SAL_CALL getFileName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFileName(const ::rtl::OUString& _fileName ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getLookIn() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLookIn(const ::rtl::OUString& _lookIn ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getSearchSubFolders() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSearchSubFolders( sal_Bool _searchSubFolders ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getMatchTextExactly() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMatchTextExactly( sal_Bool _matchTextExactly ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::XFoundFiles > SAL_CALL getFoundFiles() throw (css::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL Execute( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL NewSearch( ) throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence< rtl::OUString > getServiceNames(); +}; + +#endif /* SC_VBA_FILESEARCH_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafont.cxx b/sc/source/ui/vba/vbafont.cxx new file mode 100644 index 000000000000..1d37851785fe --- /dev/null +++ b/sc/source/ui/vba/vbafont.cxx @@ -0,0 +1,504 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/beans/XProperty.hpp> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <ooo/vba/excel/XlColorIndex.hpp> +#include <ooo/vba/excel/XlUnderlineStyle.hpp> +#include <svl/itemset.hxx> +#include "excelvbahelper.hxx" +#include "vbafont.hxx" +#include "scitems.hxx" +#include "cellsuno.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaFont::ScVbaFont( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const ScVbaPalette& dPalette, + const uno::Reference< beans::XPropertySet >& xPropertySet, + ScCellRangeObj* pRangeObj, bool bFormControl ) throw ( uno::RuntimeException ) : + ScVbaFont_BASE( xParent, xContext, dPalette.getPalette(), xPropertySet, bFormControl ), + mPalette( dPalette ), + mpRangeObj( pRangeObj ) +{ +} + +SfxItemSet* +ScVbaFont::GetDataSet() +{ + return mpRangeObj ? excel::ScVbaCellRangeAccess::GetDataSet( mpRangeObj ) : 0; +} + +ScVbaFont::~ScVbaFont() +{ +} + + +uno::Reference< beans::XPropertySet > lcl_TextProperties( uno::Reference< table::XCell >& xIf ) throw ( uno::RuntimeException ) +{ + uno::Reference< text::XTextRange > xTxtRange( xIf, uno::UNO_QUERY_THROW ); + uno::Reference< text::XSimpleText > xTxt( xTxtRange->getText(), uno::UNO_QUERY_THROW ) ; + uno::Reference< beans::XPropertySet > xProps( xTxt->createTextCursor(), uno::UNO_QUERY_THROW ); + return xProps; +} +void SAL_CALL +ScVbaFont::setSuperscript( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + // #FIXEME create some sort of generic get/set code where + // you can pass a functor + // get/set - Super/sub script code is exactly the same + // except for the call applied at each cell position + uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY ); + uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY ); + if ( !xCell.is() ) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW ); + sal_Int32 nCols = xColumnRowRange->getColumns()->getCount(); + sal_Int32 nRows = xColumnRowRange->getRows()->getCount(); + for ( sal_Int32 col = 0; col < nCols; ++col ) + { + for ( sal_Int32 row = 0; row < nRows; ++row ) + { + uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ) , uno::UNO_QUERY_THROW ); + ScVbaFont aFont( getParent(), mxContext, mPalette, xProps ); + aFont.setSuperscript( aValue ); + } + } + return; + + } + xCell.set( xCellRange->getCellByPosition( 0,0 ) ); + + uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell ); + sal_Bool bValue = sal_False; + aValue >>= bValue; + sal_Int16 nValue = NORMAL; + sal_Int8 nValue2 = NORMALHEIGHT; + + if( bValue ) + { + nValue = SUPERSCRIPT; + nValue2 = SUPERSCRIPTHEIGHT; + } + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ), ( uno::Any )nValue ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapementHeight" ) ), ( uno::Any )nValue2 ); +} + +uno::Any SAL_CALL +ScVbaFont::getSuperscript() throw ( uno::RuntimeException ) +{ + uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY ); + uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY ); + if ( !xCell.is() ) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW ); + sal_Int32 nCols = xColumnRowRange->getColumns()->getCount(); + sal_Int32 nRows = xColumnRowRange->getRows()->getCount(); + uno::Any aRes; + for ( sal_Int32 col = 0; col < nCols; ++col ) + { + for ( sal_Int32 row = 0; row < nRows; ++row ) + { + uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ), uno::UNO_QUERY_THROW ); + ScVbaFont aFont( getParent(), mxContext, mPalette, xProps ); + if ( !col && !row ) + aRes = aFont.getSuperscript(); + else if ( aRes != aFont.getSuperscript() ) + return aNULL(); + } + } + return aRes; + + } + xCell.set( xCellRange->getCellByPosition( 0,0 ) ); + uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell ); + short nValue = 0; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ) ) >>= nValue; + return uno::makeAny( ( nValue == SUPERSCRIPT ) ); +} + +void SAL_CALL +ScVbaFont::setSubscript( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY ); + uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY ); + if ( !xCell.is() ) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW ); + sal_Int32 nCols = xColumnRowRange->getColumns()->getCount(); + sal_Int32 nRows = xColumnRowRange->getRows()->getCount(); + for ( sal_Int32 col = 0; col < nCols; ++col ) + { + for ( sal_Int32 row = 0; row < nRows; ++row ) + { + uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ) , uno::UNO_QUERY_THROW ); + ScVbaFont aFont( getParent(), mxContext, mPalette, xProps ); + aFont.setSubscript( aValue ); + } + } + return; + + } + xCell.set( xCellRange->getCellByPosition( 0,0 ) ); + uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell ); + + sal_Bool bValue = sal_False; + aValue >>= bValue; + sal_Int16 nValue = NORMAL; + sal_Int8 nValue2 = NORMALHEIGHT; + + if( bValue ) + { + nValue= SUBSCRIPT; + nValue2 = SUBSCRIPTHEIGHT; + } + + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapementHeight" ) ), ( uno::Any )nValue2 ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ), ( uno::Any )nValue ); + +} + +uno::Any SAL_CALL +ScVbaFont::getSubscript() throw ( uno::RuntimeException ) +{ + uno::Reference< table::XCell> xCell( mxFont, uno::UNO_QUERY ); + uno::Reference< table::XCellRange > xCellRange( mxFont, uno::UNO_QUERY ); + if ( !xCell.is() ) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange(xCellRange, uno::UNO_QUERY_THROW ); + sal_Int32 nCols = xColumnRowRange->getColumns()->getCount(); + sal_Int32 nRows = xColumnRowRange->getRows()->getCount(); + uno::Any aRes; + for ( sal_Int32 col = 0; col < nCols; ++col ) + { + for ( sal_Int32 row = 0; row < nRows; ++row ) + { + uno::Reference< beans::XPropertySet > xProps( xCellRange->getCellByPosition( col, row ), uno::UNO_QUERY_THROW ); + ScVbaFont aFont( getParent(), mxContext, mPalette, xProps ); + if ( !col && !row ) + aRes = aFont.getSubscript(); + else if ( aRes != aFont.getSubscript() ) + return aNULL(); + } + } + return aRes; + + } + xCell.set( xCellRange->getCellByPosition( 0,0 ) ); + uno::Reference< beans::XPropertySet > xProps = lcl_TextProperties( xCell ); + + short nValue = NORMAL; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ) ) >>= nValue; + return uno::makeAny( ( nValue == SUBSCRIPT ) ); +} + +uno::Any SAL_CALL +ScVbaFont::getSize() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_HEIGHT, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return ScVbaFont_BASE::getSize(); +} + +void SAL_CALL +ScVbaFont::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException ) +{ + sal_Int32 nIndex = 0; + _colorindex >>= nIndex; + // #FIXME xlColorIndexAutomatic & xlColorIndexNone are not really + // handled properly here + + if ( !nIndex || ( nIndex == excel::XlColorIndex::xlColorIndexAutomatic ) ) + { + nIndex = 1; // check defualt ( assume black ) + ScVbaFont_BASE::setColorIndex( uno::makeAny( nIndex ) ); + } + else + ScVbaFont_BASE::setColorIndex( _colorindex ); +} + + +uno::Any SAL_CALL +ScVbaFont::getColorIndex() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_COLOR, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return ScVbaFont_BASE::getColorIndex(); +} + +////////////////////////////////////////////////////////////////////////////////////////// +void SAL_CALL +ScVbaFont::setStandardFontSize( const uno::Any& /*aValue*/ ) throw( uno::RuntimeException ) +{ +//XXX #TODO# #FIXME# + //mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharSize" ) ), ( uno::Any )fValue ); + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setStandardFontSize not supported") ), uno::Reference< uno::XInterface >() ); +} + + +uno::Any SAL_CALL +ScVbaFont::getStandardFontSize() throw ( uno::RuntimeException ) +{ +//XXX #TODO# #FIXME# + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getStandardFontSize not supported") ), uno::Reference< uno::XInterface >() ); + // return uno::Any(); +} + + +void SAL_CALL +ScVbaFont::setStandardFont( const uno::Any& /*aValue*/ ) throw( uno::RuntimeException ) +{ +//XXX #TODO# #FIXME# + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setStandardFont not supported") ), uno::Reference< uno::XInterface >() ); +} + + +uno::Any SAL_CALL +ScVbaFont::getStandardFont() throw ( uno::RuntimeException ) +{ +//XXX #TODO# #FIXME# + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getStandardFont not supported") ), uno::Reference< uno::XInterface >() ); + // return uno::Any(); +} + +void SAL_CALL +ScVbaFont::setFontStyle( const uno::Any& aValue ) throw( uno::RuntimeException ) +{ + sal_Bool bBold = sal_False; + sal_Bool bItalic = sal_False; + + rtl::OUString aStyles; + aValue >>= aStyles; + + std::vector< rtl::OUString > aTokens; + sal_Int32 nIndex = 0; + do + { + rtl::OUString aToken = aStyles.getToken( 0, ' ', nIndex ); + aTokens.push_back( aToken ); + }while( nIndex >= 0 ); + + std::vector< rtl::OUString >::iterator it; + for( it = aTokens.begin(); it != aTokens.end(); ++it ) + { + if( (*it).equalsIgnoreAsciiCaseAscii( "Bold" ) ) + bBold = sal_True; + + if( (*it).equalsIgnoreAsciiCaseAscii( "Italic" ) ) + bItalic = sal_True; + } + + setBold( uno::makeAny( bBold ) ); + setItalic( uno::makeAny( bItalic ) ); +} + + +uno::Any SAL_CALL +ScVbaFont::getFontStyle() throw ( uno::RuntimeException ) +{ + rtl::OUStringBuffer aStyles; + sal_Bool bValue = sal_False; + getBold() >>= bValue; + if( bValue ) + aStyles.appendAscii("Bold"); + + getItalic() >>= bValue; + if( bValue ) + { + if( aStyles.getLength() ) + aStyles.appendAscii(" "); + aStyles.appendAscii("Italic"); + } + return uno::makeAny( aStyles.makeStringAndClear() ); +} + +uno::Any SAL_CALL +ScVbaFont::getBold() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_WEIGHT, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return ScVbaFont_BASE::getBold(); +} + +void SAL_CALL +ScVbaFont::setUnderline( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + // default + sal_Int32 nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone; + aValue >>= nValue; + switch ( nValue ) + { +// NOTE:: #TODO #FIMXE +// xlUnderlineStyleDoubleAccounting & xlUnderlineStyleSingleAccounting +// don't seem to be supported in Openoffice. +// The import filter converts them to single or double underlines as appropriate +// So, here at the moment we are similarly silently converting +// xlUnderlineStyleSingleAccounting to xlUnderlineStyleSingle. + + case excel::XlUnderlineStyle::xlUnderlineStyleNone: + nValue = awt::FontUnderline::NONE; + break; + case excel::XlUnderlineStyle::xlUnderlineStyleSingle: + case excel::XlUnderlineStyle::xlUnderlineStyleSingleAccounting: + nValue = awt::FontUnderline::SINGLE; + break; + case excel::XlUnderlineStyle::xlUnderlineStyleDouble: + case excel::XlUnderlineStyle::xlUnderlineStyleDoubleAccounting: + nValue = awt::FontUnderline::DOUBLE; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value for Underline")), uno::Reference< uno::XInterface >() ); + } + + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharUnderline" ) ), ( uno::Any )nValue ); + +} + +uno::Any SAL_CALL +ScVbaFont::getUnderline() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_UNDERLINE, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + + sal_Int32 nValue = awt::FontUnderline::NONE; + mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharUnderline" ) ) ) >>= nValue; + switch ( nValue ) + { + case awt::FontUnderline::DOUBLE: + nValue = excel::XlUnderlineStyle::xlUnderlineStyleDouble; + break; + case awt::FontUnderline::SINGLE: + nValue = excel::XlUnderlineStyle::xlUnderlineStyleSingle; + break; + case awt::FontUnderline::NONE: + nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value retrieved for Underline") ), uno::Reference< uno::XInterface >() ); + + } + return uno::makeAny( nValue ); +} + +uno::Any SAL_CALL +ScVbaFont::getStrikethrough() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_CROSSEDOUT, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return ScVbaFont_BASE::getStrikethrough(); +} + +uno::Any SAL_CALL +ScVbaFont::getShadow() throw (uno::RuntimeException) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_SHADOWED, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return ScVbaFont_BASE::getShadow(); +} + +uno::Any SAL_CALL +ScVbaFont::getItalic() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_POSTURE, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + + return ScVbaFont_BASE::getItalic(); +} + +uno::Any SAL_CALL +ScVbaFont::getName() throw ( uno::RuntimeException ) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return ScVbaFont_BASE::getName(); +} +uno::Any +ScVbaFont::getColor() throw (uno::RuntimeException) +{ + // #TODO #FIXME - behave like getXXX above ( wrt. GetDataSet ) + uno::Any aAny; + aAny = OORGBToXLRGB( mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharColor" ) ) ) ); + return aAny; +} + +void SAL_CALL +ScVbaFont::setOutlineFont( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharContoured" ) ), aValue ); +} + +uno::Any SAL_CALL +ScVbaFont::getOutlineFont() throw (uno::RuntimeException) +{ + if ( GetDataSet() ) + if ( GetDataSet()->GetItemState( ATTR_FONT_CONTOUR, TRUE, NULL) == SFX_ITEM_DONTCARE ) + return aNULL(); + return mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharContoured" ) ) ); +} + +rtl::OUString& +ScVbaFont::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFont") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaFont::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Font" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafont.hxx b/sc/source/ui/vba/vbafont.hxx new file mode 100644 index 000000000000..d7f9010c3cfd --- /dev/null +++ b/sc/source/ui/vba/vbafont.hxx @@ -0,0 +1,92 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_FONT_HXX +#define SC_VBA_FONT_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/excel/XFont.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbafontbase.hxx> +#include "vbapalette.hxx" + +class ScTableSheetsObj; +class ScCellRangeObj; + +typedef cppu::ImplInheritanceHelper1< VbaFontBase, ov::excel::XFont > ScVbaFont_BASE; + +class ScVbaFont : public ScVbaFont_BASE +{ + ScVbaPalette mPalette; + ScCellRangeObj* mpRangeObj; + SfxItemSet* GetDataSet(); +public: + ScVbaFont( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const ScVbaPalette& dPalette, + const css::uno::Reference< css::beans::XPropertySet >& xPropertySet, + ScCellRangeObj* pRangeObj = 0, bool bFormControl = false ) throw ( css::uno::RuntimeException ); + virtual ~ScVbaFont();// {} + + // Attributes + virtual css::uno::Any SAL_CALL getSize() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStandardFontSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStandardFontSize( const css::uno::Any& _standardfontsize ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStandardFont() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStandardFont( const css::uno::Any& _standardfont ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFontStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFontStyle( const css::uno::Any& _fontstyle ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getColorIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setColorIndex( const css::uno::Any& _colorindex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getBold() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getUnderline() throw (css::uno::RuntimeException); + virtual void SAL_CALL setUnderline( const css::uno::Any& _underline ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStrikethrough() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getShadow() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getItalic() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getSubscript() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSubscript( const css::uno::Any& _subscript ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getSuperscript() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSuperscript( const css::uno::Any& _superscript ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getName() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getColor() throw (css::uno::RuntimeException) ; + virtual css::uno::Any SAL_CALL getOutlineFont() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setOutlineFont( const css::uno::Any& _outlinefont ) throw (css::uno::RuntimeException) ; + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; + + + +#endif /* SC_VBA_FONT_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaformat.cxx b/sc/source/ui/vba/vbaformat.cxx new file mode 100644 index 000000000000..a38c7f3c8876 --- /dev/null +++ b/sc/source/ui/vba/vbaformat.cxx @@ -0,0 +1,845 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaformat.hxx" +#include <ooo/vba/excel/XStyle.hpp> +#include <ooo/vba/excel/XlVAlign.hpp> +#include <ooo/vba/excel/XlHAlign.hpp> +#include <ooo/vba/excel/XlOrientation.hpp> +#include <ooo/vba/excel/Constants.hpp> +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/table/CellVertJustify2.hpp> +#include <com/sun/star/table/CellHoriJustify.hpp> +#include <com/sun/star/table/CellOrientation.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/text/WritingMode.hpp> +#include <com/sun/star/util/CellProtection.hpp> + +#include <rtl/math.hxx> + +#include "excelvbahelper.hxx" +#include "vbaborders.hxx" +#include "vbapalette.hxx" +#include "vbafont.hxx" +#include "vbainterior.hxx" + +#include <unonames.hxx> +#include <cellsuno.hxx> +#include <scitems.hxx> +#include <attrib.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +#define FORMATSTRING "FormatString" +#define LOCALE "Locale" + +template< typename Ifc1 > +ScVbaFormat< Ifc1 >::ScVbaFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, const uno::Reference< frame::XModel >& xModel, bool bCheckAmbiguoity ) throw ( script::BasicErrorException ) : ScVbaFormat_BASE( xParent, xContext ), m_aDefaultLocale( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("en") ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "US") ), rtl::OUString() ), mxPropertySet( _xPropertySet ), mxModel( xModel ), mbCheckAmbiguoity( bCheckAmbiguoity ), mbAddIndent( sal_False ) +{ + try + { + mxServiceInfo.set( mxPropertySet, uno::UNO_QUERY_THROW ); + if ( !mxModel.is() ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved") ) ); + mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setVerticalAlignment( const uno::Any& _oAlignment) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + uno::Any aVal; + sal_Int32 nAlignment = 0; + if ( !(_oAlignment >>= nAlignment )) + throw uno::RuntimeException(); + switch (nAlignment) + { + case excel::XlVAlign::xlVAlignBottom : + aVal = uno::makeAny( table::CellVertJustify2::BOTTOM ); + break; + case excel::XlVAlign::xlVAlignCenter : + aVal = uno::makeAny( table::CellVertJustify2::CENTER ); + break; + case excel::XlVAlign::xlVAlignDistributed: + case excel::XlVAlign::xlVAlignJustify: + aVal = uno::makeAny( table::CellVertJustify2::STANDARD ); + break; + + case excel::XlVAlign::xlVAlignTop: + aVal = uno::makeAny( table::CellVertJustify2::TOP); + break; + default: + aVal = uno::makeAny( table::CellVertJustify2::STANDARD ); + break; + } + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS ) ), aVal ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getVerticalAlignment( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aResult = aNULL(); + try + { + if (!isAmbiguous( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS ) ) ) ) + { + sal_Int32 aAPIAlignment = table::CellVertJustify2::STANDARD; + mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS ) ) ) >>= aAPIAlignment; + switch( aAPIAlignment ) + { + case table::CellVertJustify2::BOTTOM: + aResult = uno::makeAny( excel::XlVAlign::xlVAlignBottom ); + break; + case table::CellVertJustify2::CENTER: + aResult = uno::makeAny( excel::XlVAlign::xlVAlignCenter ); + break; + case table::CellVertJustify2::STANDARD: + aResult = uno::makeAny( excel::XlVAlign::xlVAlignBottom ); + break; + case table::CellVertJustify2::TOP: + aResult = uno::makeAny( excel::XlVAlign::xlVAlignTop ); + break; + default: + break; + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return aResult; +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setHorizontalAlignment( const uno::Any& HorizontalAlignment ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + uno::Any aVal; + sal_Int32 nAlignment = 0; + if ( !( HorizontalAlignment >>= nAlignment ) ) + throw uno::RuntimeException(); + switch ( nAlignment ) + { + case excel::XlHAlign::xlHAlignJustify: + aVal = uno::makeAny( table::CellHoriJustify_BLOCK); + break; + case excel::XlHAlign::xlHAlignCenter: + aVal = uno::makeAny( table::CellHoriJustify_CENTER ); + break; + case excel::XlHAlign::xlHAlignDistributed: + aVal = uno::makeAny( table::CellHoriJustify_BLOCK); + break; + case excel::XlHAlign::xlHAlignLeft: + aVal = uno::makeAny( table::CellHoriJustify_LEFT); + break; + case excel::XlHAlign::xlHAlignRight: + aVal = uno::makeAny( table::CellHoriJustify_RIGHT); + break; + } + // #FIXME what about the default case above? + // shouldn't need the test below + if ( aVal.hasValue() ) + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS ) ), aVal ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getHorizontalAlignment( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any NRetAlignment = aNULL(); + try + { + rtl::OUString sHoriJust( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS ) ); + if (!isAmbiguous(sHoriJust)) + { + table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_BLOCK; + + if ( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) + { + switch( aAPIAlignment ) + { + case table::CellHoriJustify_BLOCK: + NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignJustify ); + break; + case table::CellHoriJustify_CENTER: + NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignCenter ); + break; + case table::CellHoriJustify_LEFT: + NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignLeft ); + break; + case table::CellHoriJustify_RIGHT: + NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignRight ); + break; + default: // handle those other cases with a NULL return + break; + } + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + return NRetAlignment; +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setOrientation( const uno::Any& _aOrientation ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + sal_Int32 nOrientation = 0; + if ( !( _aOrientation >>= nOrientation ) ) + throw uno::RuntimeException(); + uno::Any aVal; + switch( nOrientation ) + { + case excel::XlOrientation::xlDownward: + aVal = uno::makeAny( table::CellOrientation_TOPBOTTOM); + break; + case excel::XlOrientation::xlHorizontal: + aVal = uno::makeAny( table::CellOrientation_STANDARD ); + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ROTANG ) ), uno::makeAny( sal_Int32(0) ) ); + break; + case excel::XlOrientation::xlUpward: + aVal = uno::makeAny( table::CellOrientation_BOTTOMTOP); + break; + case excel::XlOrientation::xlVertical: + aVal = uno::makeAny( table::CellOrientation_STACKED); + break; + } + // #FIXME what about the default case above? + // shouldn't need the test below + if ( aVal.hasValue() ) + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI ) ), aVal ); + + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getOrientation( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any NRetOrientation = aNULL(); + try + { + if (!isAmbiguous(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI ) ))) + { + table::CellOrientation aOrientation = table::CellOrientation_STANDARD; + if ( !( mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI ) ) ) >>= aOrientation ) ) + throw uno::RuntimeException(); + + switch(aOrientation) + { + case table::CellOrientation_STANDARD: + NRetOrientation = uno::makeAny( excel::XlOrientation::xlHorizontal ); + break; + case table::CellOrientation_BOTTOMTOP: + NRetOrientation = uno::makeAny( excel::XlOrientation::xlUpward ); + break; + case table::CellOrientation_TOPBOTTOM: + NRetOrientation = uno::makeAny( excel::XlOrientation::xlDownward ); + break; + case table::CellOrientation_STACKED: + NRetOrientation = uno::makeAny( excel::XlOrientation::xlVertical ); + break; + default: + NRetOrientation = uno::makeAny( excel::XlOrientation::xlHorizontal ); + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return NRetOrientation; +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setWrapText( const uno::Any& _aWrapText ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRAP ) ), _aWrapText); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getWrapText( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aWrap = aNULL(); + try + { + rtl::OUString aPropName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRAP ) ) ); + if (!isAmbiguous( aPropName )) + { + aWrap = mxPropertySet->getPropertyValue(aPropName); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + return aWrap; +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException ) +{ + ScVbaPalette aPalette( excel::getDocShell( mxModel ) ); + uno::Reference< XCollection > xColl = new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext, uno::Reference< table::XCellRange >( mxPropertySet, uno::UNO_QUERY_THROW ), aPalette ); + + if ( Index.hasValue() ) + { + return xColl->Item( Index, uno::Any() ); + } + return uno::makeAny( xColl ); +} + +template< typename Ifc1 > +uno::Reference< excel::XFont > SAL_CALL +ScVbaFormat<Ifc1>::Font( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + ScVbaPalette aPalette( excel::getDocShell( mxModel ) ); + return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext, aPalette, mxPropertySet ); +} + +template< typename Ifc1 > +uno::Reference< excel::XInterior > SAL_CALL +ScVbaFormat<Ifc1>::Interior( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext, mxPropertySet ); +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getNumberFormatLocal( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aRet = uno::makeAny( rtl::OUString() ); + try + { + rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ); + if (!isAmbiguous( sPropName )) + { + + initializeNumberFormats(); + + sal_Int32 nFormat = 0; + if ( ! (mxPropertySet->getPropertyValue( sPropName ) >>= nFormat ) ) + throw uno::RuntimeException(); + + rtl::OUString sFormat; + xNumberFormats->getByKey(nFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( FORMATSTRING ))) >>= sFormat; + aRet = uno::makeAny( sFormat.toAsciiLowerCase() ); + + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return aRet; + +} + +template< typename Ifc1 > +void +ScVbaFormat<Ifc1>::setNumberFormat( lang::Locale _aLocale, const rtl::OUString& _sFormatString) throw( script::BasicErrorException ) +{ + try + { + initializeNumberFormats(); + sal_Int32 nFormat = xNumberFormats->queryKey(_sFormatString, _aLocale , sal_True); + if (nFormat == -1) + { + xNumberFormats->addNew(_sFormatString, _aLocale); + } + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ), uno::makeAny( nFormat ) ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setNumberFormatLocal( const uno::Any& _oLocalFormatString ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + rtl::OUString sLocalFormatString; + sal_Int32 nFormat = -1; + rtl::OUString sNumFormat( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ); + if ( !(_oLocalFormatString >>= sLocalFormatString ) + || !( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat ) ) + throw uno::RuntimeException(); + + sLocalFormatString = sLocalFormatString.toAsciiUpperCase(); + initializeNumberFormats(); + lang::Locale aRangeLocale; + xNumberFormats->getByKey(nFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALE ) ) ) >>= aRangeLocale; + sal_Int32 nNewFormat = xNumberFormats->queryKey(sLocalFormatString, aRangeLocale, sal_True); + + if (nNewFormat == -1) + nNewFormat = xNumberFormats->addNew(sLocalFormatString, aRangeLocale); + mxPropertySet->setPropertyValue(sNumFormat, uno::makeAny( nNewFormat )); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setNumberFormat( const uno::Any& _oFormatString ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + rtl::OUString sFormatString; + if ( !( _oFormatString >>= sFormatString ) ) + throw uno::RuntimeException(); + + sFormatString = sFormatString.toAsciiUpperCase(); + + lang::Locale aDefaultLocale = m_aDefaultLocale; + initializeNumberFormats(); + sal_Int32 nFormat = xNumberFormats->queryKey(sFormatString, aDefaultLocale, sal_True); + + if (nFormat == -1) + nFormat = xNumberFormats->addNew(sFormatString, aDefaultLocale); + + lang::Locale aRangeLocale; + xNumberFormats->getByKey(nFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALE ) ) ) >>= aRangeLocale; + sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, aRangeLocale); + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ), uno::makeAny( nNewFormat)); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setIndentLevel( const uno::Any& _aLevel ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + sal_Int32 nLevel = 0; + if ( !(_aLevel >>= nLevel ) ) + throw uno::RuntimeException(); + table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_STANDARD; + + rtl::OUString sHoriJust( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS ) ); + if ( !( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) ) + throw uno::RuntimeException(); + if (aAPIAlignment == table::CellHoriJustify_STANDARD) + mxPropertySet->setPropertyValue( sHoriJust, uno::makeAny( table::CellHoriJustify_LEFT) ) ; + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_PINDENT ) ), uno::makeAny( sal_Int16(nLevel * 352.8) ) ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getIndentLevel( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any NRetIndentLevel = aNULL(); + try + { + rtl::OUString sParaIndent( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_PINDENT ) ); + if (!isAmbiguous(sParaIndent)) + { + sal_Int16 IndentLevel = 0; + if ( ( mxPropertySet->getPropertyValue(sParaIndent) >>= IndentLevel ) ) + NRetIndentLevel = uno::makeAny( sal_Int32( rtl::math::round(static_cast<double>( IndentLevel ) / 352.8)) ); + else + NRetIndentLevel = uno::makeAny( sal_Int32(0) ); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return NRetIndentLevel; +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setLocked( const uno::Any& _aLocked ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + sal_Bool bIsLocked = sal_False; + if ( !( _aLocked >>= bIsLocked ) ) + throw uno::RuntimeException(); + util::CellProtection aCellProtection; + rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) ); + mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; + aCellProtection.IsLocked = bIsLocked; + mxPropertySet->setPropertyValue(sCellProt, uno::makeAny( aCellProtection ) ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setFormulaHidden( const uno::Any& FormulaHidden ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + sal_Bool bIsFormulaHidden = sal_False; + FormulaHidden >>= bIsFormulaHidden; + util::CellProtection aCellProtection; + rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) ); + mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; + aCellProtection.IsFormulaHidden = bIsFormulaHidden; + mxPropertySet->setPropertyValue(sCellProt,uno::makeAny(aCellProtection)); + } + catch (uno::Exception& ) + { + DebugHelper::exception( SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getLocked( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aCellProtection = aNULL(); + try + { + rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) ); + + if (!isAmbiguous(sCellProt)) + { + SfxItemSet* pDataSet = getCurrentDataSet(); + if ( pDataSet ) + { + const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, TRUE); + SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL); + if(eState != SFX_ITEM_DONTCARE) + aCellProtection = uno::makeAny(rProtAttr.GetProtection()); + } + else // fallback to propertyset + { + util::CellProtection cellProtection; + mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; + aCellProtection = uno::makeAny( cellProtection.IsLocked ); + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return aCellProtection; +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getFormulaHidden( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aBoolRet = aNULL(); + try + { + rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) ); + if (!isAmbiguous(sCellProt)) + { + SfxItemSet* pDataSet = getCurrentDataSet(); + if ( pDataSet ) + { + const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, TRUE); + SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, TRUE, NULL); + if(eState != SFX_ITEM_DONTCARE) + aBoolRet = uno::makeAny(rProtAttr.GetHideFormula()); + } + else + { + util::CellProtection aCellProtection; + mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection; + aBoolRet = uno::makeAny( aCellProtection.IsFormulaHidden ); + } + } + } + catch (uno::Exception e) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return aBoolRet; +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setShrinkToFit( const uno::Any& ShrinkToFit ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + mxPropertySet->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHRINK_TO_FIT ) ), ShrinkToFit); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString() ); + } + +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getShrinkToFit( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aRet = aNULL(); + try + { + rtl::OUString sShrinkToFit( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHRINK_TO_FIT ) ); + if (!isAmbiguous(sShrinkToFit)) + aRet = mxPropertySet->getPropertyValue(sShrinkToFit); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + } + return aRet; +} + +template< typename Ifc1 > +void SAL_CALL +ScVbaFormat<Ifc1>::setReadingOrder( const uno::Any& ReadingOrder ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + sal_Int32 nReadingOrder = 0; + if ( !(ReadingOrder >>= nReadingOrder )) + throw uno::RuntimeException(); + uno::Any aVal; + switch(nReadingOrder) + { + case excel::Constants::xlLTR: + aVal = uno::makeAny( text::WritingMode_LR_TB ); + break; + case excel::Constants::xlRTL: + aVal = uno::makeAny( text::WritingMode_RL_TB ); + break; + case excel::Constants::xlContext: + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + break; + default: + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRITING ) ), aVal ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat<Ifc1>::getReadingOrder( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any NRetReadingOrder = aNULL(); + try + { + rtl::OUString sWritingMode( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRITING ) ); + if (!isAmbiguous(sWritingMode)) + { + text::WritingMode aWritingMode = text::WritingMode_LR_TB; + if ( ( mxPropertySet->getPropertyValue(sWritingMode) ) >>= aWritingMode ) + switch (aWritingMode){ + case text::WritingMode_LR_TB: + NRetReadingOrder = uno::makeAny(excel::Constants::xlLTR); + break; + case text::WritingMode_RL_TB: + NRetReadingOrder = uno::makeAny(excel::Constants::xlRTL); + break; + default: + NRetReadingOrder = uno::makeAny(excel::Constants::xlRTL); + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + } + return NRetReadingOrder; + +} + +template< typename Ifc1 > +uno::Any SAL_CALL +ScVbaFormat< Ifc1 >::getNumberFormat( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aFormat = aNULL(); + try + { + sal_Int32 nFormat = -1; + rtl::OUString sNumFormat( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ); + if (!isAmbiguous(sNumFormat) && + ( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat) ) + { + initializeNumberFormats(); + + sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, getDefaultLocale() ); + rtl::OUString sFormat; + xNumberFormats->getByKey(nNewFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( FORMATSTRING ))) >>= sFormat; + aFormat = uno::makeAny( sFormat ); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return aFormat; +} + +template< typename Ifc1 > +bool +ScVbaFormat<Ifc1>::isAmbiguous(const rtl::OUString& _sPropertyName) throw ( script::BasicErrorException ) +{ + bool bResult = false; + try + { + if (mbCheckAmbiguoity) + bResult = ( getXPropertyState()->getPropertyState(_sPropertyName) == beans::PropertyState_AMBIGUOUS_VALUE ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return bResult; +} + +template< typename Ifc1 > +void +ScVbaFormat<Ifc1>::initializeNumberFormats() throw ( script::BasicErrorException ) +{ + if ( !xNumberFormats.is() ) + { + mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW ); + xNumberFormats = mxNumberFormatsSupplier->getNumberFormats(); + xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY ); // _THROW? + } +} + +template< typename Ifc1 > +uno::Reference< beans::XPropertyState > +ScVbaFormat<Ifc1>::getXPropertyState() throw ( uno::RuntimeException ) +{ + if ( !xPropertyState.is() ) + xPropertyState.set( mxPropertySet, uno::UNO_QUERY_THROW ); + return xPropertyState; +} + +template< typename Ifc1 > +rtl::OUString& +ScVbaFormat<Ifc1>::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormat") ); + return sImplName; +} + +template< typename Ifc1 > +uno::Sequence< rtl::OUString > +ScVbaFormat<Ifc1>::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Format" ) ); + } + return aServiceNames; +} + +template< typename Ifc1 > +ScCellRangesBase* +ScVbaFormat<Ifc1>::getCellRangesBase() throw ( ::uno::RuntimeException ) +{ + return ScCellRangesBase::getImplementation( mxPropertySet ); +} + +template< typename Ifc1 > +SfxItemSet* +ScVbaFormat<Ifc1>::getCurrentDataSet( ) throw ( uno::RuntimeException ) +{ + SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() ); + if ( !pDataSet ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for XPropertySet" ) ), uno::Reference< uno::XInterface >() ); + return pDataSet; +} + + +template class ScVbaFormat< excel::XStyle >; +template class ScVbaFormat< excel::XRange >; + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaformat.hxx b/sc/source/ui/vba/vbaformat.hxx new file mode 100644 index 000000000000..60d1a4460ae1 --- /dev/null +++ b/sc/source/ui/vba/vbaformat.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_FORMAT_HXX +#define SC_VBA_FORMAT_HXX +#include <ooo/vba/excel/XFormat.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/util/XNumberFormats.hpp> +#include <com/sun/star/util/XNumberFormatTypes.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/beans/XPropertyState.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +class ScCellRangesBase; + +template< typename Ifc1 > +class ScVbaFormat : public InheritedHelperInterfaceImpl1< Ifc1 > +{ +typedef InheritedHelperInterfaceImpl1< Ifc1 > ScVbaFormat_BASE; + css::lang::Locale m_aDefaultLocale; +protected: + css::lang::Locale getDefaultLocale() { return m_aDefaultLocale; } + css::uno::Reference< css::beans::XPropertySet > mxPropertySet; + css::uno::Reference< css::util::XNumberFormatsSupplier > mxNumberFormatsSupplier; + css::uno::Reference< css::util::XNumberFormats > xNumberFormats; + css::uno::Reference< css::util::XNumberFormatTypes > xNumberFormatTypes; + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::lang::XServiceInfo > mxServiceInfo; + css::uno::Reference< css::beans::XPropertyState > xPropertyState; + sal_Bool mbCheckAmbiguoity; + sal_Bool mbAddIndent; + //NumberFormatter oNumberFormatter = null; + css::uno::Reference< css::lang::XMultiServiceFactory > xMultiServiceFactory; + bool isAmbiguous(const rtl::OUString& _sPropertyName) throw ( css::script::BasicErrorException ); + css::uno::Reference< css::beans::XPropertyState > getXPropertyState() throw ( css::uno::RuntimeException ); + void initializeNumberFormats() throw ( css::script::BasicErrorException ); + void setNumberFormat( css::lang::Locale _aLocale, const rtl::OUString& _sFormatString) throw( css::script::BasicErrorException ); + SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException ); +protected: + virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException ); +public: + ScVbaFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const css::uno::Reference< css::frame::XModel >& xModel, bool bCheckAmbiguoity ) throw ( css::script::BasicErrorException ); + virtual ~ScVbaFormat() {} + virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() = 0; + css::uno::Reference< css::lang::XServiceInfo > getXServiceInfo() { return mxServiceInfo; } + void SAL_CALL setAddIndent( const css::uno::Any& _BAddIndent) throw( css::uno::RuntimeException ) { _BAddIndent >>= mbAddIndent; } + css::uno::Any SAL_CALL getAddIndent() throw( css::uno::RuntimeException ) { return css::uno::makeAny( mbAddIndent ); } + // Interface Methods + virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& Index ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setNumberFormat( const css::uno::Any& NumberFormat ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getNumberFormat( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setNumberFormatLocal( const css::uno::Any& NumberFormatLocal ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getNumberFormatLocal( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setIndentLevel( const css::uno::Any& IndentLevel ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getIndentLevel( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setHorizontalAlignment( const css::uno::Any& HorizontalAlignment ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getHorizontalAlignment( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setVerticalAlignment( const css::uno::Any& VerticalAlignment ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getVerticalAlignment( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setOrientation( const css::uno::Any& Orientation ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getOrientation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setShrinkToFit( const css::uno::Any& ShrinkToFit ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getShrinkToFit( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setWrapText( const css::uno::Any& WrapText ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getWrapText( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setLocked( const css::uno::Any& Locked ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getLocked( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setFormulaHidden( const css::uno::Any& FormulaHidden ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFormulaHidden( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMergeCells( const css::uno::Any& MergeCells ) throw (css::script::BasicErrorException, css::uno::RuntimeException) = 0; + virtual css::uno::Any SAL_CALL getMergeCells( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) = 0; + virtual void SAL_CALL setReadingOrder( const css::uno::Any& ReadingOrder ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getReadingOrder( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaformatcondition.cxx b/sc/source/ui/vba/vbaformatcondition.cxx new file mode 100644 index 000000000000..ce7ecfd52a1c --- /dev/null +++ b/sc/source/ui/vba/vbaformatcondition.cxx @@ -0,0 +1,179 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaformatcondition.hxx" +#include "vbaformatconditions.hxx" +#include <ooo/vba/excel/XlFormatConditionType.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaFormatConditions* +lcl_getScVbaFormatConditionsPtr( const uno::Reference< excel::XFormatConditions >& xFormatConditions ) throw ( script::BasicErrorException ) +{ + ScVbaFormatConditions* pFormatConditions = static_cast< ScVbaFormatConditions* >( xFormatConditions.get() ); + if ( !pFormatConditions ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + return pFormatConditions; +} +ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const uno::Reference< excel::XStyle >& _xStyle, const uno::Reference< excel::XFormatConditions >& _xFormatConditions, const uno::Reference< css::beans::XPropertySet >& _xPropertySet ) throw ( css::uno::RuntimeException ) : ScVbaFormatCondition_BASE( xParent, xContext, uno::Reference< sheet::XSheetCondition >( _xSheetConditionalEntry, css::uno::UNO_QUERY_THROW ) ), moFormatConditions( _xFormatConditions ), mxStyle( _xStyle ), mxParentRangePropertySet( _xPropertySet ) +{ + mxSheetConditionalEntries = lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getSheetConditionalEntries(); + + mxSheetConditionalEntry = _xSheetConditionalEntry; + msStyleName = mxStyle->getName(); +} + + +void SAL_CALL +ScVbaFormatCondition::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions ); + pFormatConditions->removeFormatCondition(msStyleName, sal_True); + notifyRange(); +} + +void SAL_CALL +ScVbaFormatCondition::Modify( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions ); + pFormatConditions->removeFormatCondition(msStyleName, sal_False); + pFormatConditions->Add(_nType, _aOperator, _aFormula1, _aFormula2, mxStyle); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +uno::Reference< excel::XInterior > SAL_CALL +ScVbaFormatCondition::Interior( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return mxStyle->Interior(); +} + +uno::Reference< excel::XFont > SAL_CALL +ScVbaFormatCondition::Font( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return mxStyle->Font(); +} +uno::Any SAL_CALL +ScVbaFormatCondition::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException) +{ return mxStyle->Borders( Index ); +} + +sheet::ConditionOperator +ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) throw ( script::BasicErrorException ) +{ + sheet::ConditionOperator aAPIType = sheet::ConditionOperator_NONE; + switch (_nVBAType) + { + case excel::XlFormatConditionType::xlExpression: + aAPIType = sheet::ConditionOperator_FORMULA; + break; + case excel::XlFormatConditionType::xlCellValue: + if ( _xSheetCondition.is() && (_xSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA ) ) + aAPIType = sheet::ConditionOperator_NONE; + break; + default: + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + return aAPIType; +} + +void +ScVbaFormatCondition::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException ) +{ + // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax + // and if R1C1 convert to A1 + ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula1) ) ); +} + +void +ScVbaFormatCondition::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException ) +{ + ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) ); +} + +::sal_Int32 SAL_CALL +ScVbaFormatCondition::Type( ) throw ( script::BasicErrorException, uno::RuntimeException ) +{ + sal_Int32 nReturnType = 0; + if ( mxSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA) + nReturnType = excel::XlFormatConditionType::xlExpression; + else + nReturnType = excel::XlFormatConditionType::xlCellValue; + return nReturnType; +} + + +::sal_Int32 +ScVbaFormatCondition::Operator( sal_Bool bVal ) throw (script::BasicErrorException ) +{ + return ScVbaFormatCondition_BASE::Operator( bVal ); +} +::sal_Int32 SAL_CALL +ScVbaFormatCondition::Operator( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return ScVbaFormatCondition_BASE::Operator( sal_True ); +} + +void +ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException ) +{ + try + { + mxParentRangePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConditionalFormat") ), uno::makeAny( mxSheetConditionalEntries) ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } +} + +rtl::OUString& +ScVbaFormatCondition::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormatCondition") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaFormatCondition::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatCondition" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaformatcondition.hxx b/sc/source/ui/vba/vbaformatcondition.hxx new file mode 100644 index 000000000000..75706878d1c3 --- /dev/null +++ b/sc/source/ui/vba/vbaformatcondition.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_FORMATCONDITION_HXX +#define SC_VBA_FORMATCONDITION_HXX +#include <ooo/vba/excel/XFormatCondition.hpp> +#include <ooo/vba/excel/XFormatConditions.hpp> +#include <ooo/vba/excel/XStyle.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetCondition.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include "vbacondition.hxx" + +typedef ScVbaCondition< ov::excel::XFormatCondition > ScVbaFormatCondition_BASE; +class ScVbaFormatCondition : public ScVbaFormatCondition_BASE +{ +protected: + rtl::OUString msStyleName; + css::uno::Reference< css::sheet::XSheetConditionalEntry > mxSheetConditionalEntry; + css::uno::Reference< css::sheet::XSheetConditionalEntries > mxSheetConditionalEntries; + css::uno::Reference< ov::excel::XFormatConditions> moFormatConditions; + css::uno::Reference< ov::excel::XStyle > mxStyle; + css::uno::Reference< css::beans::XPropertySet > mxParentRangePropertySet; +public: + ScVbaFormatCondition( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const css::uno::Reference< ov::excel::XStyle >&, const css::uno::Reference< ov::excel::XFormatConditions >& _xFormatConditions, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet ) throw ( css::uno::RuntimeException ); + + void notifyRange() throw ( css::script::BasicErrorException ); + static css::sheet::ConditionOperator retrieveAPIType(sal_Int32 _nVBAType, const css::uno::Reference< css::sheet::XSheetCondition >& _xSheetCondition ) throw( css::script::BasicErrorException ); + + //Methods + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Modify( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL Type( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 Operator( sal_Bool ) throw (css::script::BasicErrorException); + virtual ::sal_Int32 SAL_CALL Operator( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void setFormula1( const css::uno::Any& _aFormula1) throw ( css::script::BasicErrorException ); + virtual void setFormula2( const css::uno::Any& _aFormula2) throw ( css::script::BasicErrorException ); + virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& Index ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaformatconditions.cxx b/sc/source/ui/vba/vbaformatconditions.cxx new file mode 100644 index 000000000000..26dcaac89040 --- /dev/null +++ b/sc/source/ui/vba/vbaformatconditions.cxx @@ -0,0 +1,303 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <vector> +#include "vbaformatconditions.hxx" +#include "vbaformatcondition.hxx" +#include "vbaworkbook.hxx" +#include "vbastyles.hxx" +#include "vbaglobals.hxx" +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +typedef std::vector< beans::PropertyValue > VecPropValues; + +static rtl::OUString OPERATOR( RTL_CONSTASCII_USTRINGPARAM("Operator") ); +static rtl::OUString FORMULA1( RTL_CONSTASCII_USTRINGPARAM("Formula1") ); +static rtl::OUString FORMULA2( RTL_CONSTASCII_USTRINGPARAM("Formula2") ); +static rtl::OUString STYLENAME( RTL_CONSTASCII_USTRINGPARAM("StyleName") ); +static rtl::OUString sStyleNamePrefix( RTL_CONSTASCII_USTRINGPARAM("Excel_CondFormat") ); + +ScVbaFormatConditions::ScVbaFormatConditions( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetConditionalEntries >& _xSheetConditionalEntries, const uno::Reference< frame::XModel >& /*xModel*/ ) : ScVbaFormatConditions_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( _xSheetConditionalEntries, uno::UNO_QUERY_THROW ) ), mxSheetConditionalEntries( _xSheetConditionalEntries ) +{ + mxRangeParent.set( xParent, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XApplication> xApp( Application(), uno::UNO_QUERY_THROW ); + mxStyles.set( xApp->getThisWorkbook()->Styles( uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeAddressable > xCellRange( mxRangeParent->getCellRange(), uno::UNO_QUERY_THROW ); + mxParentRangePropertySet.set( xCellRange, uno::UNO_QUERY_THROW ); + + table::CellRangeAddress rangeAddress = xCellRange->getRangeAddress(); + maCellAddress = table::CellAddress( rangeAddress.Sheet, rangeAddress.StartColumn, rangeAddress.StartRow ); +} + +void SAL_CALL +ScVbaFormatConditions::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + ScVbaStyles* pStyles = static_cast< ScVbaStyles* >( mxStyles.get() ); + if ( !pStyles ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + sal_Int32 nCount = mxSheetConditionalEntries->getCount(); + for (sal_Int32 i = nCount - 1; i >= 0; i--) + { + uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry( mxSheetConditionalEntries->getByIndex(i), uno::UNO_QUERY_THROW ); + pStyles->Delete(xSheetConditionalEntry->getStyleName()); + mxSheetConditionalEntries->removeByIndex(i); + } + notifyRange(); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +uno::Type SAL_CALL +ScVbaFormatConditions::getElementType() throw (css::uno::RuntimeException) +{ + return excel::XFormatCondition::static_type(0); +} + + +uno::Any xSheetConditionToFormatCondition( const uno::Reference< XHelperInterface >& xRangeParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XStyles >& xStyles, const uno::Reference< excel::XFormatConditions >& xFormatConditions, const uno::Reference< beans::XPropertySet >& xRangeProps, const uno::Any& aObject ) +{ + uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry; + aObject >>= xSheetConditionalEntry; + + uno::Reference< excel::XStyle > xStyle( xStyles->Item( uno::makeAny( xSheetConditionalEntry->getStyleName() ), uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XFormatCondition > xCondition = new ScVbaFormatCondition( xRangeParent, xContext, xSheetConditionalEntry, xStyle, xFormatConditions, xRangeProps ); + return uno::makeAny( xCondition ); +} + +uno::Any +ScVbaFormatConditions::createCollectionObject(const uno::Any& aObject ) +{ + return xSheetConditionToFormatCondition( uno::Reference< XHelperInterface >( mxRangeParent, uno::UNO_QUERY_THROW ), mxContext, mxStyles, this, mxParentRangePropertySet, aObject ); +} + +class EnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference<container::XIndexAccess > m_xIndexAccess; + uno::Reference<excel::XRange > m_xParentRange; + uno::Reference<uno::XComponentContext > m_xContext; + uno::Reference<excel::XStyles > m_xStyles; + uno::Reference<excel::XFormatConditions > m_xParentCollection; + uno::Reference<beans::XPropertySet > m_xProps; + + sal_Int32 nIndex; +public: + EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference<excel::XRange >& xRange, const uno::Reference<uno::XComponentContext >& xContext, const uno::Reference<excel::XStyles >& xStyles, const uno::Reference< excel::XFormatConditions >& xCollection, const uno::Reference<beans::XPropertySet >& xProps ) : m_xIndexAccess( xIndexAccess ), m_xParentRange( xRange ), m_xContext( xContext ), m_xStyles( xStyles ), m_xParentCollection( xCollection ), m_xProps( xProps ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + return xSheetConditionToFormatCondition( uno::Reference< XHelperInterface >( m_xParentRange, uno::UNO_QUERY_THROW ), m_xContext, m_xStyles, m_xParentCollection, m_xProps, m_xIndexAccess->getByIndex( nIndex++ ) ); + throw container::NoSuchElementException(); + } +}; + +uno::Reference< excel::XFormatCondition > SAL_CALL +ScVbaFormatConditions::Add( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return Add( _nType, _aOperator, _aFormula1, _aFormula2, uno::Reference< excel::XStyle >() ); +} + +uno::Reference< excel::XFormatCondition > +ScVbaFormatConditions::Add( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2, const css::uno::Reference< excel::XStyle >& _xStyle ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // #TODO + // #FIXME + // This method will NOT handle r1c1 formulas [*]and only assumes that + // the formulas are _xlA1 based ( need to hook into calc work ths should + // address this ) + // [*] reason: getA1Formula method below is just a hook and just + // returns whats it gets ( e.g. doesn't convert anything ) + uno::Reference< excel::XStyle > xStyle( _xStyle ); + uno::Reference< excel::XFormatCondition > xFormatCondition; + try + { + rtl::OUString sStyleName; + if ( !xStyle.is() ) + { + sStyleName = getStyleName(); + xStyle = mxStyles->Add(sStyleName, uno::Any() ); + } + else + { + sStyleName = xStyle->getName(); + } + + VecPropValues aPropertyValueVector; + sheet::ConditionOperator aType = ScVbaFormatCondition::retrieveAPIType(_nType, uno::Reference< sheet::XSheetCondition >() ); + uno::Any aValue; + + if ( aType == sheet::ConditionOperator_FORMULA) + aValue = uno::makeAny( sheet::ConditionOperator_FORMULA ); + else + aValue = uno::makeAny( ScVbaFormatCondition::retrieveAPIOperator(_aOperator) ); + + beans::PropertyValue aProperty( OPERATOR, 0, aValue, beans::PropertyState_DIRECT_VALUE ); + aPropertyValueVector.push_back( aProperty ); + + if ( _aFormula1.hasValue() ) + { + beans::PropertyValue aProp( FORMULA1, 0, uno::makeAny( getA1Formula( _aFormula1 ) ), beans::PropertyState_DIRECT_VALUE ); + aPropertyValueVector.push_back( aProp ); + } + if ( _aFormula2.hasValue() ) + { + beans::PropertyValue aProp( FORMULA2, 0, uno::makeAny( getA1Formula( _aFormula2 ) ), beans::PropertyState_DIRECT_VALUE ); + aPropertyValueVector.push_back( aProp ); + } + aProperty.Name = STYLENAME; + aProperty.Value = uno::makeAny( sStyleName ); + + // convert vector to sequence + uno::Sequence< beans::PropertyValue > aPropertyValueList(aPropertyValueVector.size()); + VecPropValues::iterator it = aPropertyValueVector.begin(); + VecPropValues::iterator it_end = aPropertyValueVector.end(); + for ( sal_Int32 index=0; it != it_end; ++it ) + aPropertyValueList[ index++ ] = *it; + + mxSheetConditionalEntries->addNew(aPropertyValueList); + for (sal_Int32 i = mxSheetConditionalEntries->getCount()-1; i >= 0; i--) + { + uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry( mxSheetConditionalEntries->getByIndex(i), uno::UNO_QUERY_THROW ); + if (xSheetConditionalEntry->getStyleName().equals(sStyleName)) + { + xFormatCondition = new ScVbaFormatCondition(uno::Reference< XHelperInterface >( mxRangeParent, uno::UNO_QUERY_THROW ), mxContext, xSheetConditionalEntry, xStyle, this, mxParentRangePropertySet); + notifyRange(); + return xFormatCondition; + } + } + } + catch (uno::Exception& ) + { + } + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + return xFormatCondition; +} + + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaFormatConditions::createEnumeration() throw (uno::RuntimeException) +{ + return new EnumWrapper( m_xIndexAccess, mxRangeParent, mxContext, mxStyles, this, mxParentRangePropertySet ); +} + + +void +ScVbaFormatConditions::notifyRange() throw ( script::BasicErrorException ) +{ + try + { + mxParentRangePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConditionalFormat")), uno::makeAny( mxSheetConditionalEntries )); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +rtl::OUString +ScVbaFormatConditions::getA1Formula(const css::uno::Any& _aFormula) throw ( script::BasicErrorException ) +{ + // #TODO, #FIXME hook-in proper formula conversion detection & logic + rtl::OUString sFormula; + if ( !( _aFormula >>= sFormula ) ) + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + return sFormula; +} + +rtl::OUString +ScVbaFormatConditions::getStyleName() +{ + ScVbaStyles* pStyles = static_cast< ScVbaStyles* >( mxStyles.get() ); + if ( !pStyles ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + uno::Sequence< rtl::OUString > sCellStyleNames = pStyles->getStyleNames(); + return ContainerUtilities::getUniqueName(sCellStyleNames, sStyleNamePrefix, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_") )); +} + +void +ScVbaFormatConditions::removeFormatCondition( const rtl::OUString& _sStyleName, sal_Bool _bRemoveStyle) throw ( script::BasicErrorException ) +{ + try + { + sal_Int32 nElems = mxSheetConditionalEntries->getCount(); + for (sal_Int32 i = 0; i < nElems; i++) + { + uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry( mxSheetConditionalEntries->getByIndex(i), uno::UNO_QUERY_THROW ); + if (_sStyleName.equals(xSheetConditionalEntry->getStyleName())) + { + mxSheetConditionalEntries->removeByIndex(i); + if (_bRemoveStyle) + { + ScVbaStyles* pStyles = static_cast< ScVbaStyles* >( mxStyles.get() ); + if ( !pStyles ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + pStyles->Delete( _sStyleName ); + } + return; + } + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +rtl::OUString& +ScVbaFormatConditions::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormatConditions") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaFormatConditions::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatConditions" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaformatconditions.hxx b/sc/source/ui/vba/vbaformatconditions.hxx new file mode 100644 index 000000000000..e51ca233164d --- /dev/null +++ b/sc/source/ui/vba/vbaformatconditions.hxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_FORMATCONDITIONS_HXX +#define SC_VBA_FORMATCONDITIONS_HXX +#include <ooo/vba/excel/XFormatConditions.hpp> +#include <ooo/vba/excel/XStyles.hpp> +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XFormatConditions > ScVbaFormatConditions_BASE; +class ScVbaFormatConditions: public ScVbaFormatConditions_BASE +{ + css::table::CellAddress maCellAddress; + css::uno::Reference< css::sheet::XSheetConditionalEntries > mxSheetConditionalEntries; + css::uno::Reference< ov::excel::XStyles > mxStyles; + css::uno::Reference< ov::excel::XRange > mxRangeParent; + css::uno::Reference< css::beans::XPropertySet > mxParentRangePropertySet; +public: + ScVbaFormatConditions( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::sheet::XSheetConditionalEntries >&, const css::uno::Reference< css::frame::XModel >& ); + void notifyRange() throw ( css::script::BasicErrorException ); + virtual css::uno::Reference< ov::excel::XFormatCondition > Add( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2, const css::uno::Reference< ov::excel::XStyle >& _xCalcStyle ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + rtl::OUString getA1Formula(const css::uno::Any& _aFormula) throw ( css::script::BasicErrorException ); + rtl::OUString getStyleName(); + void removeFormatCondition( const rtl::OUString& _sStyleName, sal_Bool _bRemoveStyle) throw ( css::script::BasicErrorException ); + css::uno::Reference< css::sheet::XSheetConditionalEntries > getSheetConditionalEntries() { return mxSheetConditionalEntries; } + // XFormatConditions + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XFormatCondition > SAL_CALL Add( ::sal_Int32 Type, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject(const css::uno::Any&); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_AXES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafoundfiles.cxx b/sc/source/ui/vba/vbafoundfiles.cxx new file mode 100644 index 000000000000..9d3af947e1dd --- /dev/null +++ b/sc/source/ui/vba/vbafoundfiles.cxx @@ -0,0 +1,146 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbafoundfiles.hxx" + +////////////////////////////////VbaFoundFilesEnum////////////////////////////////////////// +VbaFoundFilesEnum::VbaFoundFilesEnum() : m_nIndex(0) +{ + +} + +VbaFoundFilesEnum::VbaFoundFilesEnum( css::uno::Sequence<rtl::OUString>& sFileList ) : m_nIndex(0), m_sFileList(sFileList) +{ + +} + +VbaFoundFilesEnum::~VbaFoundFilesEnum() +{ + +} + +void VbaFoundFilesEnum::SetFileList( css::uno::Sequence<rtl::OUString>& sFileList ) +{ + m_nIndex = 0; + m_sFileList = sFileList; +} + +sal_Int32 SAL_CALL VbaFoundFilesEnum::getCount() throw (css::uno::RuntimeException) +{ + return m_sFileList.getLength(); +} + +css::uno::Any SAL_CALL VbaFoundFilesEnum::getByIndex( sal_Int32 nIndex ) + throw (css::lang::IndexOutOfBoundsException, css::lang::WrappedTargetException, css::uno::RuntimeException) +{ + if ( nIndex >= getCount() ) + { + throw css::lang::IndexOutOfBoundsException(); + } + + return css::uno::makeAny( m_sFileList[nIndex] ); +} + +css::uno::Type SAL_CALL VbaFoundFilesEnum::getElementType() throw (css::uno::RuntimeException) +{ + return getCppuType((css::uno::Reference< css::container::XIndexAccess >*)0); +} + +sal_Bool SAL_CALL VbaFoundFilesEnum::hasElements() throw (css::uno::RuntimeException) +{ + return ( getCount() != 0 ); +} + +sal_Bool SAL_CALL VbaFoundFilesEnum::hasMoreElements() throw (css::uno::RuntimeException) +{ + if ( getCount() > m_nIndex ) + { + return sal_True; + } + return sal_False; +} + +css::uno::Any SAL_CALL VbaFoundFilesEnum::nextElement() throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException) +{ + if ( !hasMoreElements() ) + { + throw css::container::NoSuchElementException(); + } + + return css::uno::makeAny( m_sFileList[m_nIndex++] ); +} + +////////////////////////////////VbaFoundFiles////////////////////////////////////////// +VbaFoundFiles::VbaFoundFiles( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess + ) : VbaFoundFilesImpl_BASE( xParent, xContext, xIndexAccess ) +{ + +} + +VbaFoundFiles::~VbaFoundFiles() +{ + +} + +css::uno::Reference< css::container::XEnumeration > VbaFoundFiles::createEnumeration() throw (css::uno::RuntimeException) +{ + css::uno::Reference< css::container::XEnumeration > xEnumRet( m_xIndexAccess, css::uno::UNO_QUERY ); + return xEnumRet; +} + +css::uno::Any VbaFoundFiles::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +css::uno::Type VbaFoundFiles::getElementType() throw (css::uno::RuntimeException) +{ + return ov::XFoundFiles::static_type(0); +} + +rtl::OUString& VbaFoundFiles::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaFoundFiles") ); + return sImplName; +} + +css::uno::Sequence< rtl::OUString > VbaFoundFiles::getServiceNames() +{ + static css::uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FoundFiles") ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbafoundfiles.hxx b/sc/source/ui/vba/vbafoundfiles.hxx new file mode 100644 index 000000000000..7a0a1e7b2a19 --- /dev/null +++ b/sc/source/ui/vba/vbafoundfiles.hxx @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_FOUNDFILES_HXX +#define SC_VBA_FOUNDFILES_HXX + +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <ooo/vba/XFoundFiles.hpp> +#include <vbahelper/vbacollectionimpl.hxx> + +namespace css = ::com::sun::star; + +typedef CollTestImplHelper< ooo::vba::XFoundFiles > VbaFoundFilesImpl_BASE; + +class VbaFoundFilesEnum : public cppu::WeakImplHelper2< css::container::XIndexAccess, css::container::XEnumeration > +{ +private: + sal_Int32 m_nIndex; + css::uno::Sequence< rtl::OUString > m_sFileList; + +public: + VbaFoundFilesEnum(); + VbaFoundFilesEnum( css::uno::Sequence< rtl::OUString >& sFileList ); + ~VbaFoundFilesEnum(); + + void SetFileList( css::uno::Sequence< rtl::OUString >& sFileList ); + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (css::lang::IndexOutOfBoundsException, css::lang::WrappedTargetException, css::uno::RuntimeException); + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); + + // XEnumeration + virtual sal_Bool SAL_CALL hasMoreElements() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL nextElement() throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException); +}; + +class VbaFoundFiles : public VbaFoundFilesImpl_BASE +{ +private: + +public: + VbaFoundFiles( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + virtual ~VbaFoundFiles(); + + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence< rtl::OUString > getServiceNames(); +}; + +#endif /* SC_VBA_FOUNDFILES_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaglobals.cxx b/sc/source/ui/vba/vbaglobals.cxx new file mode 100644 index 000000000000..b3e56cddb958 --- /dev/null +++ b/sc/source/ui/vba/vbaglobals.cxx @@ -0,0 +1,313 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> +#include "vbaglobals.hxx" + +#include <sal/macros.h> + +#include <comphelper/unwrapargs.hxx> + +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <cppuhelper/component_context.hxx> +#include "vbaapplication.hxx" +#include "vbaworksheet.hxx" +#include "vbarange.hxx" +#include <cppuhelper/bootstrap.hxx> +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::ooo::vba; + + + +// ============================================================================= +// ScVbaGlobals +// ============================================================================= + +//ScVbaGlobals::ScVbaGlobals( css::uno::Reference< css::uno::XComponentContext >const& rxContext, ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext ) +rtl::OUString sDocCtxName( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext") ); + +ScVbaGlobals::ScVbaGlobals( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& rxContext ) : ScVbaGlobals_BASE( uno::Reference< XHelperInterface >(), rxContext, sDocCtxName ) +{ + OSL_TRACE("ScVbaGlobals::ScVbaGlobals()"); + + uno::Sequence< beans::PropertyValue > aInitArgs( 2 ); + aInitArgs[ 0 ].Name = rtl::OUString::createFromAscii("Application"); + aInitArgs[ 0 ].Value = uno::makeAny( getApplication() ); + aInitArgs[ 1 ].Name = sDocCtxName; + aInitArgs[ 1 ].Value = uno::makeAny( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ) ); + + init( aInitArgs ); +} + +ScVbaGlobals::~ScVbaGlobals() +{ + OSL_TRACE("ScVbaGlobals::~ScVbaGlobals"); +} + +// ============================================================================= +// XGlobals +// ============================================================================= +uno::Reference<excel::XApplication > +ScVbaGlobals::getApplication() throw (uno::RuntimeException) +{ +// OSL_TRACE("In ScVbaGlobals::getApplication"); + if ( !mxApplication.is() ) + mxApplication.set( new ScVbaApplication( mxContext) ); + return mxApplication; +} + + +uno::Reference<excel::XApplication > SAL_CALL +ScVbaGlobals::getExcel() throw (uno::RuntimeException) +{ + return getApplication(); +} + + + +uno::Reference< excel::XWorkbook > SAL_CALL +ScVbaGlobals::getActiveWorkbook() throw (uno::RuntimeException) +{ +// OSL_TRACE("In ScVbaGlobals::getActiveWorkbook"); + uno::Reference< excel::XWorkbook > xWorkbook( getApplication()->getActiveWorkbook(), uno::UNO_QUERY); + if ( xWorkbook.is() ) + { + return xWorkbook; + } +// FIXME check if this is correct/desired behavior + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "No activeWorkbook available" ), Reference< uno::XInterface >() ); +} + + +uno::Reference< excel::XWindow > SAL_CALL +ScVbaGlobals::getActiveWindow() throw (uno::RuntimeException) +{ + return getApplication()->getActiveWindow(); +} + +uno::Reference< excel::XWorksheet > SAL_CALL +ScVbaGlobals::getActiveSheet() throw (uno::RuntimeException) +{ + return getApplication()->getActiveSheet(); +} + +uno::Any SAL_CALL +ScVbaGlobals::WorkBooks( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return uno::Any( getApplication()->Workbooks(aIndex) ); +} + +uno::Any SAL_CALL +ScVbaGlobals::WorkSheets(const uno::Any& aIndex) throw (uno::RuntimeException) +{ + return getApplication()->Worksheets( aIndex ); +} +uno::Any SAL_CALL +ScVbaGlobals::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return WorkSheets( aIndex ); +} + +uno::Any SAL_CALL +ScVbaGlobals::Range( const uno::Any& Cell1, const uno::Any& Cell2 ) throw (uno::RuntimeException) +{ + return getApplication()->Range( Cell1, Cell2 ); +} + +uno::Any SAL_CALL +ScVbaGlobals::Names( const css::uno::Any& aIndex ) throw ( uno::RuntimeException ) +{ + return getApplication()->Names( aIndex ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaGlobals::getActiveCell() throw (uno::RuntimeException) +{ + return getApplication()->getActiveCell(); +} + +uno::Reference< XAssistant > SAL_CALL +ScVbaGlobals::getAssistant() throw (uno::RuntimeException) +{ + return getApplication()->getAssistant(); +} + +uno::Any SAL_CALL +ScVbaGlobals::getSelection() throw (uno::RuntimeException) +{ + return getApplication()->getSelection(); +} + +uno::Reference< excel::XWorkbook > SAL_CALL +ScVbaGlobals::getThisWorkbook() throw (uno::RuntimeException) +{ + return getApplication()->getThisWorkbook(); +} +void SAL_CALL +ScVbaGlobals::Calculate() throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException) +{ + return getApplication()->Calculate(); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaGlobals::Cells( const uno::Any& RowIndex, const uno::Any& ColumnIndex ) throw (uno::RuntimeException) +{ + return getApplication()->getActiveSheet()->Cells( RowIndex, ColumnIndex ); +} +uno::Reference< excel::XRange > SAL_CALL +ScVbaGlobals::Columns( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return getApplication()->getActiveSheet()->Columns( aIndex ); +} + +uno::Any SAL_CALL +ScVbaGlobals::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< XApplicationBase > xBase( getApplication(), uno::UNO_QUERY_THROW ); + return xBase->CommandBars( aIndex ); +} + +css::uno::Reference< ov::excel::XRange > SAL_CALL +ScVbaGlobals::Union( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return getApplication()->Union( Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, Arg22, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30 ); +} +css::uno::Reference< ov::excel::XRange > SAL_CALL +ScVbaGlobals::Intersect( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + return getApplication()->Intersect( Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9, Arg10, Arg11, Arg12, Arg13, Arg14, Arg15, Arg16, Arg17, Arg18, Arg19, Arg20, Arg21, Arg22, Arg23, Arg24, Arg25, Arg26, Arg27, Arg28, Arg29, Arg30 ); +} + +uno::Any SAL_CALL +ScVbaGlobals::Evaluate( const ::rtl::OUString& Name ) throw (uno::RuntimeException) +{ + return getApplication()->Evaluate( Name ); +} + +css::uno::Any SAL_CALL +ScVbaGlobals::WorksheetFunction( ) throw (css::uno::RuntimeException) +{ + return getApplication()->WorksheetFunction(); +} + +uno::Any SAL_CALL +ScVbaGlobals::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return getApplication()->Windows( aIndex ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaGlobals::Rows( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return getApplication()->getActiveSheet()->Rows( aIndex ); + +} + + +uno::Any SAL_CALL +ScVbaGlobals::getDebug() throw (uno::RuntimeException) +{ + try // return empty object on error + { + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= uno::Reference< XHelperInterface >( this ); + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< uno::XInterface > xVBADebug = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.Debug" ) ), aArgs, mxContext ); + return uno::Any( xVBADebug ); + } + catch( uno::Exception& ) + { + } + return uno::Any(); +} + +uno::Any SAL_CALL +ScVbaGlobals::MenuBars( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return uno::Any( getApplication()->MenuBars(aIndex) ); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL +ScVbaGlobals::getAvailableServiceNames( ) throw (uno::RuntimeException) +{ + static bool bInit = false; + static uno::Sequence< rtl::OUString > serviceNames( ScVbaGlobals_BASE::getAvailableServiceNames() ); + if ( !bInit ) + { + rtl::OUString names[] = { + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Range" ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Workbook" ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Window" ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Worksheet" ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Application" ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.excel.Hyperlink" ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.script.vba.VBASpreadsheetEventProcessor" ) ) + }; + sal_Int32 nExcelServices = ( SAL_N_ELEMENTS(names) ); + sal_Int32 startIndex = serviceNames.getLength(); + serviceNames.realloc( serviceNames.getLength() + nExcelServices ); + for ( sal_Int32 index = 0; index < nExcelServices; ++index ) + serviceNames[ startIndex + index ] = names[ index ]; + bInit = true; + } + return serviceNames; +} + +rtl::OUString& +ScVbaGlobals::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaGlobals") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaGlobals::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Globals" ) ); + } + return aServiceNames; +} + +namespace globals +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaGlobals, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaGlobals", + "ooo.vba.excel.Globals" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaglobals.hxx b/sc/source/ui/vba/vbaglobals.hxx new file mode 100644 index 000000000000..dc7518ad64c2 --- /dev/null +++ b/sc/source/ui/vba/vbaglobals.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_GLOBALS +#define SC_VBA_GLOBALS + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <ooo/vba/excel/XGlobals.hpp> +#include <ooo/vba/excel/XApplication.hpp> + +#include <cppuhelper/implbase1.hxx> +#include "excelvbahelper.hxx" + +#include <vbahelper/vbaglobalbase.hxx> + // ============================================================================= + // class ScVbaGlobals + // ============================================================================= + +typedef ::cppu::ImplInheritanceHelper1< VbaGlobalsBase, ov::excel::XGlobals > ScVbaGlobals_BASE; + + class ScVbaGlobals : public ScVbaGlobals_BASE + { + css::uno::Reference< ov::excel::XApplication > mxApplication; + virtual css::uno::Reference< + ov::excel::XApplication > SAL_CALL getApplication() + throw (css::uno::RuntimeException); + public: + + ScVbaGlobals( css::uno::Sequence< css::uno::Any > const& aArgs, + css::uno::Reference< css::uno::XComponentContext >const& rxContext ); + //ScVbaGlobals( + // css::uno::Reference< css::uno::XComponentContext >const& rxContext, ); + virtual ~ScVbaGlobals(); + + // XGlobals + virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getActiveWorkbook() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWindow > SAL_CALL getActiveWindow() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::XAssistant > SAL_CALL getAssistant() throw (css::uno::RuntimeException); + virtual void SAL_CALL Calculate( ) throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL getSelection() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getActiveCell() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL getThisWorkbook() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells( const css::uno::Any& RowIndex, const css::uno::Any& ColumnIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Evaluate( const ::rtl::OUString& Name ) throw (css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL WorkSheets(const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL WorkBooks(const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL WorksheetFunction( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Sheets( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Range( const css::uno::Any& Cell1, const css::uno::Any& Cell2 ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::excel::XRange > SAL_CALL Rows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ) throw ( css::uno::RuntimeException ); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Intersect( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Union( const css::uno::Reference< ov::excel::XRange >& Arg1, const css::uno::Reference< ov::excel::XRange >& Arg2, const css::uno::Any& Arg3, const css::uno::Any& Arg4, const css::uno::Any& Arg5, const css::uno::Any& Arg6, const css::uno::Any& Arg7, const css::uno::Any& Arg8, const css::uno::Any& Arg9, const css::uno::Any& Arg10, const css::uno::Any& Arg11, const css::uno::Any& Arg12, const css::uno::Any& Arg13, const css::uno::Any& Arg14, const css::uno::Any& Arg15, const css::uno::Any& Arg16, const css::uno::Any& Arg17, const css::uno::Any& Arg18, const css::uno::Any& Arg19, const css::uno::Any& Arg20, const css::uno::Any& Arg21, const css::uno::Any& Arg22, const css::uno::Any& Arg23, const css::uno::Any& Arg24, const css::uno::Any& Arg25, const css::uno::Any& Arg26, const css::uno::Any& Arg27, const css::uno::Any& Arg28, const css::uno::Any& Arg29, const css::uno::Any& Arg30 ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XApplication > SAL_CALL getExcel() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getDebug() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL MenuBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + + + // XMultiServiceFactory + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + }; +#endif // + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbahelper.cxx b/sc/source/ui/vba/vbahelper.cxx new file mode 100644 index 000000000000..bc1b07d738ab --- /dev/null +++ b/sc/source/ui/vba/vbahelper.cxx @@ -0,0 +1,761 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <cppuhelper/bootstrap.hxx> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XIntrospection.hpp> + +#include <comphelper/processfactory.hxx> + +#include <sfx2/objsh.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/app.hxx> +#include <svl/stritem.hxx> + +#include <docuno.hxx> + +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <rtl/math.hxx> + +#include <math.h> +#include "vbahelper.hxx" +#include "tabvwsh.hxx" +#include "transobj.hxx" +#include "scmod.hxx" +#include "vbashape.hxx" +#include "unonames.hxx" +#include "cellsuno.hxx" +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +#define POINTTO100THMILLIMETERFACTOR 35.27778 +void unoToSbxValue( SbxVariable* pVar, const uno::Any& aValue ); + +uno::Any sbxToUnoValue( SbxVariable* pVar ); + + +namespace ooo +{ +namespace vba +{ + +const double Millimeter::factor = 35.27778; + +uno::Reference< beans::XIntrospectionAccess > +getIntrospectionAccess( const uno::Any& aObject ) throw (uno::RuntimeException) +{ + static uno::Reference< beans::XIntrospection > xIntrospection; + if( !xIntrospection.is() ) + { + uno::Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + xIntrospection.set( xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection") ), uno::UNO_QUERY_THROW ); + } + return xIntrospection->inspect( aObject ); +} + +uno::Reference< script::XTypeConverter > +getTypeConverter( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + static uno::Reference< script::XTypeConverter > xTypeConv( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter") ), xContext ), uno::UNO_QUERY_THROW ); + return xTypeConv; +} +// helper method to determine if the view ( calc ) is in print-preview mode +bool isInPrintPreview( SfxViewFrame* pView ) +{ + sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0; + if ( pView->GetObjectShell()->GetFactory().GetViewFactoryCount() > +nViewNo && !pView->GetObjectShell()->IsInPlaceActive() ) + { + SfxViewFactory &rViewFactory = + pView->GetObjectShell()->GetFactory().GetViewFactory(nViewNo); + if ( pView->GetCurViewId() == rViewFactory.GetOrdinal() ) + return true; + } + return false; +} +const ::rtl::OUString REPLACE_CELLS_WARNING( RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning")); +const uno::Any& +aNULL() +{ + static uno::Any aNULLL = uno::makeAny( uno::Reference< uno::XInterface >() ); + return aNULLL; +} + +class PasteCellsWarningReseter +{ +private: + bool bInitialWarningState; + static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException ) + { + static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + static uno::Reference<lang::XMultiComponentFactory > xServiceManager( + xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW ); + return xProps; + } + + bool getReplaceCellsWarning() throw ( uno::RuntimeException ) + { + sal_Bool res = sal_False; + getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING ) >>= res; + return ( res == sal_True ); + } + + void setReplaceCellsWarning( bool bState ) throw ( uno::RuntimeException ) + { + getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING, uno::makeAny( bState ) ); + } +public: + PasteCellsWarningReseter() throw ( uno::RuntimeException ) + { + bInitialWarningState = getReplaceCellsWarning(); + if ( bInitialWarningState ) + setReplaceCellsWarning( false ); + } + ~PasteCellsWarningReseter() + { + if ( bInitialWarningState ) + { + // don't allow dtor to throw + try + { + setReplaceCellsWarning( true ); + } + catch ( uno::Exception& /*e*/ ){} + } + } +}; + +void dispatchExecute(css::uno::Reference< css::frame::XModel>& xModel, USHORT nSlot, SfxCallMode nCall) +{ + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + SfxViewFrame* pViewFrame = NULL; + if ( pViewShell ) + pViewFrame = pViewShell->GetViewFrame(); + if ( pViewFrame ) + { + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + if( pDispatcher ) + { + pDispatcher->Execute( nSlot , nCall ); + } + } +} + +void +implnPaste() +{ + PasteCellsWarningReseter resetWarningBox; + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + { + pViewShell->PasteFromSystem(); + pViewShell->CellContentChanged(); + } +} + + +void +implnCopy() +{ + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + pViewShell->CopyToClip(NULL,false,false,true); +} + +void +implnCut() +{ + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + pViewShell->CutToClip( NULL, TRUE ); +} + +void implnPasteSpecial(USHORT nFlags,USHORT nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose) +{ + PasteCellsWarningReseter resetWarningBox; + sal_Bool bAsLink(sal_False), bOtherDoc(sal_False); + InsCellCmd eMoveMode = INS_NONE; + + ScTabViewShell* pTabViewShell = ScTabViewShell::GetActiveViewShell(); + if ( !pTabViewShell ) + // none active, try next best + pTabViewShell = getCurrentBestViewShell(); + if ( pTabViewShell ) + { + ScViewData* pView = pTabViewShell->GetViewData(); + Window* pWin = ( pView != NULL ) ? pView->GetActiveWin() : NULL; + if ( pView && pWin ) + { + if ( bAsLink && bOtherDoc ) + pTabViewShell->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK + else + { + ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin ); + ScDocument* pDoc = NULL; + if ( pOwnClip ) + pDoc = pOwnClip->GetDocument(); + pTabViewShell->PasteFromClip( nFlags, pDoc, + nFunction, bSkipEmpty, bTranspose, bAsLink, + eMoveMode, IDF_NONE, TRUE ); + pTabViewShell->CellContentChanged(); + } + } + } + +} + + uno::Reference< frame::XModel > +getCurrentDocument() throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel; + SbxObject* pBasic = dynamic_cast< SbxObject* > ( SFX_APP()->GetBasic() ); + SbxObject* basicChosen = pBasic ; + if ( basicChosen == NULL) + { + OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" ); + return xModel; + } + SbxObject* p = pBasic; + SbxObject* pParent = p->GetParent(); + SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL; + + if( pParentParent ) + { + basicChosen = pParentParent; + } + else if( pParent ) + { + basicChosen = pParent; + } + + + uno::Any aModel; + SbxVariable *pCompVar = basicChosen->Find( UniString(RTL_CONSTASCII_USTRINGPARAM("ThisComponent")), SbxCLASS_OBJECT ); + + if ( pCompVar ) + { + aModel = sbxToUnoValue( pCompVar ); + if ( sal_False == ( aModel >>= xModel ) || + !xModel.is() ) + { + // trying last gasp try the current component + uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + // test if vba service is present + uno::Reference< uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + uno::Reference<lang::XMultiComponentFactory > xSMgr( xCtx->getServiceManager(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XDesktop > xDesktop (xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), xCtx), uno::UNO_QUERY_THROW ); + xModel.set( xDesktop->getCurrentComponent(), uno::UNO_QUERY ); + if ( !xModel.is() ) + { + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract model from basic ( its obviously not set yet ) therefore don't know the currently selected document") ), uno::Reference< uno::XInterface >() ); + } + return xModel; + } + else + { + OSL_TRACE("Have model ThisComponent points to url %s", + ::rtl::OUStringToOString( xModel->getURL(), + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + } + } + else + { + OSL_TRACE("Failed to get ThisComponent"); + throw uno::RuntimeException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Can't determine the currently selected document") ), + uno::Reference< uno::XInterface >() ); + } + return xModel; +} + +ScDocShell* +getDocShell( css::uno::Reference< css::frame::XModel>& xModel ) +{ + uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW ); + ScModelObj* pModel = dynamic_cast< ScModelObj* >( xIf.get() ); + ScDocShell* pDocShell = NULL; + if ( pModel ) + pDocShell = (ScDocShell*)pModel->GetEmbeddedObject(); + return pDocShell; + +} + +ScTabViewShell* +getBestViewShell( css::uno::Reference< css::frame::XModel>& xModel ) +{ + ScDocShell* pDocShell = getDocShell( xModel ); + if ( pDocShell ) + return pDocShell->GetBestViewShell(); + return NULL; +} + +ScTabViewShell* +getCurrentBestViewShell() +{ + uno::Reference< frame::XModel > xModel = getCurrentDocument(); + return getBestViewShell( xModel ); +} + +SfxViewFrame* +getCurrentViewFrame() +{ + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + return pViewShell->GetViewFrame(); + return NULL; +} + +sal_Int32 +OORGBToXLRGB( sal_Int32 nCol ) +{ + sal_Int32 nRed = nCol; + nRed &= 0x00FF0000; + nRed >>= 16; + sal_Int32 nGreen = nCol; + nGreen &= 0x0000FF00; + nGreen >>= 8; + sal_Int32 nBlue = nCol; + nBlue &= 0x000000FF; + sal_Int32 nRGB = ( (nBlue << 16) | (nGreen << 8) | nRed ); + return nRGB; +} +sal_Int32 +XLRGBToOORGB( sal_Int32 nCol ) +{ + sal_Int32 nBlue = nCol; + nBlue &= 0x00FF0000; + nBlue >>= 16; + sal_Int32 nGreen = nCol; + nGreen &= 0x0000FF00; + nGreen >>= 8; + sal_Int32 nRed = nCol; + nRed &= 0x000000FF; + sal_Int32 nRGB = ( (nRed << 16) | (nGreen << 8) | nBlue ); + return nRGB; +} +uno::Any +OORGBToXLRGB( const uno::Any& aCol ) +{ + sal_Int32 nCol=0; + aCol >>= nCol; + nCol = OORGBToXLRGB( nCol ); + return uno::makeAny( nCol ); +} +uno::Any +XLRGBToOORGB( const uno::Any& aCol ) +{ + sal_Int32 nCol=0; + aCol >>= nCol; + nCol = XLRGBToOORGB( nCol ); + return uno::makeAny( nCol ); +} + +void PrintOutHelper( 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, css::uno::Reference< frame::XModel >& xModel, sal_Bool bUseSelection ) +{ + sal_Int32 nTo = 0; + sal_Int32 nFrom = 0; + sal_Int16 nCopies = 1; + sal_Bool bPreview = sal_False; + sal_Bool bCollate = sal_False; + sal_Bool bSelection = bUseSelection; + From >>= nFrom; + To >>= nTo; + Copies >>= nCopies; + Preview >>= bPreview; + if ( nCopies > 1 ) // Collate only useful when more that 1 copy + Collate >>= bCollate; + + rtl::OUString sRange( RTL_CONSTASCII_USTRINGPARAM( "-" ) ); + rtl::OUString sFileName; + + if (( nFrom || nTo ) ) + { + if ( nFrom ) + sRange = ( ::rtl::OUString::valueOf( nFrom ) + sRange ); + if ( nTo ) + sRange += ::rtl::OUString::valueOf( nTo ); + } + + if ( PrToFileName.getValue() ) + { + PrToFileName >>= sFileName; + } + ScTabViewShell* pViewShell = getBestViewShell( xModel ); + SfxViewFrame* pViewFrame = NULL; + if ( pViewShell ) + pViewFrame = pViewShell->GetViewFrame(); + if ( pViewFrame ) + { + SfxAllItemSet aArgs( SFX_APP()->GetPool() ); + + SfxBoolItem sfxCollate( SID_PRINT_COLLATE, bCollate ); + aArgs.Put( sfxCollate, sfxCollate.Which() ); + SfxInt16Item sfxCopies( SID_PRINT_COPIES, nCopies ); + aArgs.Put( sfxCopies, sfxCopies.Which() ); + if ( sFileName.getLength() ) + { + SfxStringItem sfxFileName( SID_FILE_NAME, sFileName); + aArgs.Put( sfxFileName, sfxFileName.Which() ); + + } + if ( sRange.getLength() ) + { + SfxStringItem sfxRange( SID_PRINT_PAGES, sRange ); + aArgs.Put( sfxRange, sfxRange.Which() ); + } + SfxBoolItem sfxSelection( SID_SELECTION, bSelection ); + aArgs.Put( sfxSelection, sfxSelection.Which() ); + SfxBoolItem sfxAsync( SID_ASYNCHRON, sal_False ); + aArgs.Put( sfxAsync, sfxAsync.Which() ); + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + + if ( pDispatcher ) + { + if ( bPreview ) + { + if ( !pViewFrame->GetFrame().IsInPlace() ) + { + SC_MOD()->InputEnterHandler(); + pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_SYNCHRON ); + while ( isInPrintPreview( pViewFrame ) ) + Application::Yield(); + } + } + else + pDispatcher->Execute( (USHORT)SID_PRINTDOC, (SfxCallMode)SFX_CALLMODE_SYNCHRON, aArgs ); + } + + } + + // #FIXME #TODO + // 1 ActivePrinter ( how/can we switch a printer via API? ) + // 2 PrintToFile ( ms behaviour if this option is specified but no + // filename supplied 'PrToFileName' then the user will be prompted ) + // 3 Need to check behaviour of Selected sheets with range ( e.g. From & To + // values ) in oOO these options are mutually exclusive + // 4 There is a pop up to do with transparent objects in the print source + // should be able to disable that via configuration for the duration + // of this method +} + + void PrintPreviewHelper( const css::uno::Any& /*EnableChanges*/, css::uno::Reference< css::frame::XModel >& xModel ) +{ + dispatchExecute( xModel, SID_VIEWSHELL1 ); +} + +rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) +{ + uno::Type aType = pvargItem.getValueType(); + uno::TypeClass eTypeClass = aType.getTypeClass(); + rtl::OUString sString; + switch ( eTypeClass ) + { + case uno::TypeClass_BOOLEAN: + { + sal_Bool bBool = sal_False; + pvargItem >>= bBool; + sString = rtl::OUString::valueOf( bBool ); + break; + } + case uno::TypeClass_STRING: + pvargItem >>= sString; + break; + case uno::TypeClass_FLOAT: + { + float aFloat = 0; + pvargItem >>= aFloat; + sString = rtl::OUString::valueOf( aFloat ); + break; + } + case uno::TypeClass_DOUBLE: + { + double aDouble = 0; + pvargItem >>= aDouble; + sString = rtl::OUString::valueOf( aDouble ); + break; + } + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + case uno::TypeClass_BYTE: + { + sal_Int32 aNum = 0; + pvargItem >>= aNum; + sString = rtl::OUString::valueOf( aNum ); + break; + } + + case uno::TypeClass_HYPER: + { + sal_Int64 aHyper = 0; + pvargItem >>= aHyper; + sString = rtl::OUString::valueOf( aHyper ); + break; + } + default: + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid type, can't convert" ), uno::Reference< uno::XInterface >() ); + } + return sString; +} + + +rtl::OUString +ContainerUtilities::getUniqueName( const uno::Sequence< ::rtl::OUString >& _slist, const rtl::OUString& _sElementName, const ::rtl::OUString& _sSuffixSeparator) +{ + return getUniqueName(_slist, _sElementName, _sSuffixSeparator, sal_Int32(2)); +} + +rtl::OUString +ContainerUtilities::getUniqueName( const uno::Sequence< rtl::OUString >& _slist, const rtl::OUString _sElementName, const rtl::OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix) +{ + sal_Int32 a = _nStartSuffix; + rtl::OUString scompname = _sElementName; + bool bElementexists = true; + sal_Int32 nLen = _slist.getLength(); + if ( nLen == 0 ) + return _sElementName; + + while (bElementexists == true) + { + for (sal_Int32 i = 0; i < nLen; i++) + { + if (FieldInList(_slist, scompname) == -1) + { + return scompname; + } + } + scompname = _sElementName + _sSuffixSeparator + rtl::OUString::valueOf( a++ ); + } + return rtl::OUString(); +} + +sal_Int32 +ContainerUtilities::FieldInList( const uno::Sequence< rtl::OUString >& SearchList, const rtl::OUString& SearchString ) +{ + sal_Int32 FieldLen = SearchList.getLength(); + sal_Int32 retvalue = -1; + for (sal_Int32 i = 0; i < FieldLen; i++) + { + // I wonder why comparing lexicographically is done + // when its a match is whats interesting? + //if (SearchList[i].compareTo(SearchString) == 0) + if ( SearchList[i].equals( SearchString ) ) + { + retvalue = i; + break; + } + } + return retvalue; + +} +bool NeedEsc(sal_Unicode cCode) +{ + String sEsc(RTL_CONSTASCII_USTRINGPARAM(".^$+\\|{}()")); + return (STRING_NOTFOUND != sEsc.Search(cCode)); +} + +rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike ) +{ + rtl::OUStringBuffer sResult; + const sal_Unicode *start = rIn.getStr(); + const sal_Unicode *end = start + rIn.getLength(); + + int seenright = 0; + if ( bForLike ) + sResult.append(static_cast<sal_Unicode>('^')); + + while (start < end) + { + switch (*start) + { + case '?': + sResult.append(static_cast<sal_Unicode>('.')); + start++; + break; + case '*': + sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*"))); + start++; + break; + case '#': + sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[0-9]"))); + start++; + break; + case '~': + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*(++start)); + start++; + break; + // dump the ~ and escape the next characture + case ']': + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start++); + break; + case '[': + sResult.append(*start++); + seenright = 0; + while (start < end && !seenright) + { + switch (*start) + { + case '[': + case '?': + case '*': + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start); + break; + case ']': + sResult.append(*start); + seenright = 1; + break; + case '!': + sResult.append(static_cast<sal_Unicode>('^')); + break; + default: + if (NeedEsc(*start)) + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start); + break; + } + start++; + } + break; + default: + if (NeedEsc(*start)) + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start++); + } + } + + if ( bForLike ) + sResult.append(static_cast<sal_Unicode>('$')); + + return sResult.makeStringAndClear( ); +} + +double getPixelTo100thMillimeterConversionFactor( css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) +{ + double fConvertFactor = 1.0; + if( bVertical ) + { + fConvertFactor = xDevice->getInfo().PixelPerMeterY/100000; + } + else + { + fConvertFactor = xDevice->getInfo().PixelPerMeterX/100000; + } + return fConvertFactor; +} + +double PointsToPixels( css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) +{ + double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); + return fPoints * POINTTO100THMILLIMETERFACTOR * fConvertFactor; +} +double PixelsToPoints( css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) +{ + double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); + return (fPixels/fConvertFactor)/POINTTO100THMILLIMETERFACTOR; +} + +ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape ) +{ + m_xShape = new ScVbaShape( xContext, xShape ); +} + +#define VBA_LEFT "PositionX" +#define VBA_TOP "PositionY" +UserFormGeometryHelper::UserFormGeometryHelper( const uno::Reference< uno::XComponentContext >& /*xContext*/, const uno::Reference< awt::XControl >& xControl ) +{ + mxModel.set( xControl->getModel(), uno::UNO_QUERY_THROW ); +} + double UserFormGeometryHelper::getLeft() + { + sal_Int32 nLeft = 0; + mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_LEFT ) ) ) >>= nLeft; + return Millimeter::getInPoints( nLeft ); + } + void UserFormGeometryHelper::setLeft( double nLeft ) + { + mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_LEFT ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nLeft ) ) ); + } + double UserFormGeometryHelper::getTop() + { + sal_Int32 nTop = 0; + mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_TOP ) ) ) >>= nTop; + return Millimeter::getInPoints( nTop ); + } + void UserFormGeometryHelper::setTop( double nTop ) + { + mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( VBA_TOP ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nTop ) ) ); + } + double UserFormGeometryHelper::getHeight() + { + sal_Int32 nHeight = 0; + mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHGT ) ) ) >>= nHeight; + return Millimeter::getInPoints( nHeight ); + } + void UserFormGeometryHelper::setHeight( double nHeight ) + { + mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHGT ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nHeight ) ) ); + } + double UserFormGeometryHelper::getWidth() + { + sal_Int32 nWidth = 0; + mxModel->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLWID ) ) ) >>= nWidth; + return Millimeter::getInPoints( nWidth ); + } + void UserFormGeometryHelper::setWidth( double nWidth) + { + mxModel->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLWID ) ), uno::makeAny( Millimeter::getInHundredthsOfOneMillimeter( nWidth ) ) ); + } + +SfxItemSet* +ScVbaCellRangeAccess::GetDataSet( ScCellRangeObj* pRangeObj ) +{ + SfxItemSet* pDataSet = pRangeObj ? pRangeObj->GetCurrentDataSet( true ) : NULL ; + return pDataSet; + +} + +} // vba +} // ooo + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbahyperlink.cxx b/sc/source/ui/vba/vbahyperlink.cxx new file mode 100644 index 000000000000..4499a1183400 --- /dev/null +++ b/sc/source/ui/vba/vbahyperlink.cxx @@ -0,0 +1,249 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahyperlink.hxx" +#include <vbahelper/helperdecl.hxx> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <ooo/vba/office/MsoHyperlinkType.hpp> +#include <ooo/vba/msforms/XShape.hpp> +#include "vbarange.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +// ============================================================================ + +ScVbaHyperlink::ScVbaHyperlink( const uno::Sequence< uno::Any >& rArgs, + const uno::Reference< uno::XComponentContext >& rxContext ) throw (lang::IllegalArgumentException) : + HyperlinkImpl_BASE( getXSomethingFromArgs< XHelperInterface >( rArgs, 0 ), rxContext ), + mxCell( getXSomethingFromArgs< table::XCell >( rArgs, 1, false ) ), + mnType( office::MsoHyperlinkType::msoHyperlinkRange ) +{ + uno::Reference< text::XTextFieldsSupplier > xTextFields( mxCell, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndex( xTextFields->getTextFields(), uno::UNO_QUERY_THROW ); + mxTextField.set( xIndex->getByIndex(0), uno::UNO_QUERY_THROW ); +} + +ScVbaHyperlink::ScVbaHyperlink( const uno::Reference< XHelperInterface >& rxAnchor, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Any& rAddress, const uno::Any& rSubAddress, + const uno::Any& rScreenTip, const uno::Any& rTextToDisplay ) throw (uno::RuntimeException) : + HyperlinkImpl_BASE( rxAnchor, rxContext ) // parent of Hyperlink is the anchor object +{ + // extract parameters, Address must not be empty + UrlComponents aUrlComp; + OUString aTextToDisplay; + if( !(rAddress >>= aUrlComp.first) || (aUrlComp.first.getLength() == 0) ) + throw uno::RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot get address" ) ), uno::Reference< uno::XInterface >() ); + rSubAddress >>= aUrlComp.second; + rScreenTip >>= maScreenTip; + rTextToDisplay >>= aTextToDisplay; + + // get anchor range or anchor shape + uno::Reference< excel::XRange > xAnchorRange( rxAnchor, uno::UNO_QUERY ); + if( xAnchorRange.is() ) + { + mnType = office::MsoHyperlinkType::msoHyperlinkRange; + // only single ranges are allowed + uno::Reference< table::XCellRange > xUnoRange( ScVbaRange::getCellRange( xAnchorRange ), uno::UNO_QUERY_THROW ); + // insert the hyperlink into the top-left cell only + mxCell.set( xUnoRange->getCellByPosition( 0, 0 ), uno::UNO_SET_THROW ); + uno::Reference< text::XText > xText( mxCell, uno::UNO_QUERY_THROW ); + // use cell text or URL if no TextToDisplay has been passed + if( aTextToDisplay.getLength() == 0 ) + { + aTextToDisplay = xText->getString(); + if( aTextToDisplay.getLength() == 0 ) + { + OUStringBuffer aBuffer( aUrlComp.first ); + if( aUrlComp.second.getLength() > 0 ) + aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( " - " ) ).append( aUrlComp.second ); + aTextToDisplay = aBuffer.makeStringAndClear(); + } + } + // create and initialize a new URL text field + uno::Reference< lang::XMultiServiceFactory > xFactory( ScVbaRange::getUnoModel( xAnchorRange ), uno::UNO_QUERY_THROW ); + uno::Reference< text::XTextContent > xUrlField( xFactory->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextField.URL" ) ) ), uno::UNO_QUERY_THROW ); + mxTextField.set( xUrlField, uno::UNO_QUERY_THROW ); + setUrlComponents( aUrlComp ); + setTextToDisplay( aTextToDisplay ); + // insert the text field into the document + xText->setString( OUString() ); + uno::Reference< text::XTextRange > xRange( xText->createTextCursor(), uno::UNO_QUERY_THROW ); + xText->insertTextContent( xRange, xUrlField, sal_False ); + } + else + { + uno::Reference< msforms::XShape > xAnchorShape( rxAnchor, uno::UNO_QUERY_THROW ); + mnType = office::MsoHyperlinkType::msoHyperlinkShape; + // FIXME: insert hyperlink into shape + throw uno::RuntimeException(); + } +} + +ScVbaHyperlink::~ScVbaHyperlink() +{ +} + +OUString ScVbaHyperlink::getName() throw (uno::RuntimeException) +{ + // it seems this attribute is same as TextToDisplay + return getTextToDisplay(); +} + +void ScVbaHyperlink::setName( const OUString& rName ) throw (uno::RuntimeException) +{ + setTextToDisplay( rName ); +} + +OUString ScVbaHyperlink::getAddress() throw (uno::RuntimeException) +{ + return getUrlComponents().first; +} + +void ScVbaHyperlink::setAddress( const OUString& rAddress ) throw (uno::RuntimeException) +{ + UrlComponents aUrlComp = getUrlComponents(); + aUrlComp.first = rAddress; + setUrlComponents( aUrlComp ); +} + +OUString ScVbaHyperlink::getSubAddress() throw (uno::RuntimeException) +{ + return getUrlComponents().second; +} + +void ScVbaHyperlink::setSubAddress( const OUString& rSubAddress ) throw (uno::RuntimeException) +{ + UrlComponents aUrlComp = getUrlComponents(); + aUrlComp.second = rSubAddress; + setUrlComponents( aUrlComp ); +} + +OUString SAL_CALL ScVbaHyperlink::getScreenTip() throw (uno::RuntimeException) +{ + return maScreenTip; +} + +void SAL_CALL ScVbaHyperlink::setScreenTip( const OUString& rScreenTip ) throw (uno::RuntimeException) +{ + maScreenTip = rScreenTip; +} + +OUString ScVbaHyperlink::getTextToDisplay() throw (uno::RuntimeException) +{ + ensureTextField(); + OUString aTextToDisplay; + mxTextField->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Representation" ) ) ) >>= aTextToDisplay; + return aTextToDisplay; +} + +void ScVbaHyperlink::setTextToDisplay( const OUString& rTextToDisplay ) throw (uno::RuntimeException) +{ + ensureTextField(); + mxTextField->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Representation" ) ), uno::Any( rTextToDisplay ) ); +} + +sal_Int32 SAL_CALL ScVbaHyperlink::getType() throw (uno::RuntimeException) +{ + return mnType; +} + +uno::Reference< excel::XRange > SAL_CALL ScVbaHyperlink::getRange() throw (uno::RuntimeException) +{ + if( mnType == office::MsoHyperlinkType::msoHyperlinkRange ) + { + // if constructed from Hyperlinks object, range has been passed as parent + uno::Reference< excel::XRange > xAnchorRange( getParent(), uno::UNO_QUERY ); + if( !xAnchorRange.is() ) + { + // if constructed via service c'tor, create new range based on cell + uno::Reference< table::XCellRange > xRange( mxCell, uno::UNO_QUERY_THROW ); + // FIXME: need to pass current worksheet as the parent of XRange. + xAnchorRange.set( new ScVbaRange( uno::Reference< XHelperInterface >(), mxContext, xRange ) ); + } + return xAnchorRange; + } + // error if called at a shape Hyperlink object + throw uno::RuntimeException(); +} + +uno::Reference< msforms::XShape > SAL_CALL ScVbaHyperlink::getShape() throw (uno::RuntimeException) +{ + // error if called at a range Hyperlink object + return uno::Reference< msforms::XShape >( getParent(), uno::UNO_QUERY_THROW ); +} + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaHyperlink, "ooo.vba.excel.Hyperlink" ) + +// private -------------------------------------------------------------------- + +void ScVbaHyperlink::ensureTextField() throw (uno::RuntimeException) +{ + if( !mxTextField.is() ) + throw uno::RuntimeException(); +} + +ScVbaHyperlink::UrlComponents ScVbaHyperlink::getUrlComponents() throw (uno::RuntimeException) +{ + ensureTextField(); + OUString aUrl; + mxTextField->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ) >>= aUrl; + sal_Int32 nHashPos = aUrl.indexOf( '#' ); + if( nHashPos < 0 ) + return UrlComponents( aUrl, OUString() ); + return UrlComponents( aUrl.copy( 0, nHashPos ), aUrl.copy( nHashPos + 1 ) ); +} + +void ScVbaHyperlink::setUrlComponents( const UrlComponents& rUrlComp ) throw (uno::RuntimeException) +{ + ensureTextField(); + OUStringBuffer aUrl( rUrlComp.first ); + if( rUrlComp.second.getLength() > 0 ) + aUrl.append( sal_Unicode( '#' ) ).append( rUrlComp.second ); + mxTextField->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ), uno::Any( aUrl.makeStringAndClear() ) ); +} + +namespace hyperlink +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaHyperlink, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaHyperlink", + "ooo.vba.excel.Hyperlink" ); +} + +// ============================================================================ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbahyperlink.hxx b/sc/source/ui/vba/vbahyperlink.hxx new file mode 100644 index 000000000000..1e74707c2397 --- /dev/null +++ b/sc/source/ui/vba/vbahyperlink.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_HYPERLINK_HXX +#define SC_VBA_HYPERLINK_HXX + +#include <ooo/vba/excel/XHyperlink.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/excel/XRange.hpp> + +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XHyperlink > HyperlinkImpl_BASE; + +class ScVbaHyperlink : public HyperlinkImpl_BASE +{ +public: + ScVbaHyperlink( + const css::uno::Sequence< css::uno::Any >& rArgs, + const css::uno::Reference< css::uno::XComponentContext >& rxContext ) throw (css::lang::IllegalArgumentException); + + ScVbaHyperlink( + const css::uno::Reference< ov::XHelperInterface >& rxAnchor, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Any& rAddress, const css::uno::Any& rSubAddress, + const css::uno::Any& rScreenTip, const css::uno::Any& rTextToDisplay ) throw (css::uno::RuntimeException); + + virtual ~ScVbaHyperlink(); + + // Attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getAddress() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAddress( const ::rtl::OUString& rAddress ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getSubAddress() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSubAddress( const ::rtl::OUString& rSubAddress ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getScreenTip() throw (css::uno::RuntimeException); + virtual void SAL_CALL setScreenTip( const ::rtl::OUString& rScreenTip ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getTextToDisplay() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTextToDisplay( const ::rtl::OUString& rTextToDisplay ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getRange() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XShape > SAL_CALL getShape() throw (css::uno::RuntimeException); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > UrlComponents; + + void ensureTextField() throw (css::uno::RuntimeException); + UrlComponents getUrlComponents() throw (css::uno::RuntimeException); + void setUrlComponents( const UrlComponents& rUrlComp ) throw (css::uno::RuntimeException); + +private: + css::uno::Reference< css::table::XCell > mxCell; + css::uno::Reference< css::beans::XPropertySet > mxTextField; + ::rtl::OUString maScreenTip; + long mnType; +}; + +#endif /* SC_VBA_HYPERLINK_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbahyperlinks.cxx b/sc/source/ui/vba/vbahyperlinks.cxx new file mode 100644 index 000000000000..686f636669c8 --- /dev/null +++ b/sc/source/ui/vba/vbahyperlinks.cxx @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahyperlinks.hxx" +#include <algorithm> +#include <vector> +#include <ooo/vba/office/MsoHyperlinkType.hpp> +#include "rangelst.hxx" +#include "vbahyperlink.hxx" +#include "vbarange.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using ::rtl::OUString; + +// ============================================================================ + +namespace { + +/** Returns true, if every range of rxInner is contained in any range of rScOuter. */ +bool lclContains( const ScRangeList& rScOuter, const uno::Reference< excel::XRange >& rxInner ) throw (uno::RuntimeException) +{ + const ScRangeList& rScInner = ScVbaRange::getScRangeList( rxInner ); + if( (rScInner.Count() == 0) || (rScOuter.Count() == 0) ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Empty range objects" ) ), uno::Reference< uno::XInterface >() ); + + for( ULONG nIndex = 0, nCount = rScInner.Count(); nIndex < nCount; ++nIndex ) + if( !rScOuter.In( *rScInner.GetObject( nIndex ) ) ) + return false; + return true; +} + +// ---------------------------------------------------------------------------- + +/** Functor to decide whether the anchors of two Hyperlink objects are equal. */ +struct EqualAnchorFunctor +{ + uno::Reference< excel::XRange > mxAnchorRange; + uno::Reference< msforms::XShape > mxAnchorShape; + sal_Int32 mnType; + EqualAnchorFunctor( const uno::Reference< excel::XHyperlink >& rxHlink ) throw (uno::RuntimeException); + bool operator()( const uno::Reference< excel::XHyperlink >& rxHlink ) const throw (uno::RuntimeException); +}; + +EqualAnchorFunctor::EqualAnchorFunctor( const uno::Reference< excel::XHyperlink >& rxHlink ) throw (uno::RuntimeException) : + mnType( rxHlink->getType() ) +{ + switch( mnType ) + { + case office::MsoHyperlinkType::msoHyperlinkRange: + mxAnchorRange.set( rxHlink->getRange(), uno::UNO_QUERY_THROW ); + break; + case office::MsoHyperlinkType::msoHyperlinkShape: + case office::MsoHyperlinkType::msoHyperlinkInlineShape: + mxAnchorShape.set( rxHlink->getShape(), uno::UNO_QUERY_THROW ); + break; + default: + throw uno::RuntimeException(); + } +} + +bool EqualAnchorFunctor::operator()( const uno::Reference< excel::XHyperlink >& rxHlink ) const throw (uno::RuntimeException) +{ + sal_Int32 nType = rxHlink->getType(); + if( nType != mnType ) + return false; + + switch( nType ) + { + case office::MsoHyperlinkType::msoHyperlinkRange: + { + uno::Reference< excel::XRange > xAnchorRange( rxHlink->getRange(), uno::UNO_QUERY_THROW ); + const ScRangeList& rScRanges1 = ScVbaRange::getScRangeList( xAnchorRange ); + const ScRangeList& rScRanges2 = ScVbaRange::getScRangeList( mxAnchorRange ); + return (rScRanges1.Count() == 1) && (rScRanges2.Count() == 1) && (*rScRanges1.GetObject( 0 ) == *rScRanges2.GetObject( 0 )); + } + case office::MsoHyperlinkType::msoHyperlinkShape: + case office::MsoHyperlinkType::msoHyperlinkInlineShape: + { + uno::Reference< msforms::XShape > xAnchorShape( rxHlink->getShape(), uno::UNO_QUERY_THROW ); + return xAnchorShape.get() == mxAnchorShape.get(); + } + default: + throw uno::RuntimeException(); + } +} + +} // namespace + +// ============================================================================ + +namespace detail { + +class ScVbaHlinkContainer : public ::cppu::WeakImplHelper1< container::XIndexAccess > +{ +public: + explicit ScVbaHlinkContainer() throw (uno::RuntimeException); + explicit ScVbaHlinkContainer( const ScVbaHlinkContainerRef& rxSheetContainer, const ScRangeList& rScRanges ) throw (uno::RuntimeException); + virtual ~ScVbaHlinkContainer(); + + /** Inserts the passed hyperlink into the collection. Will remove a + Hyperlink object with the same anchor as the passed Hyperlink object. */ + void insertHyperlink( const uno::Reference< excel::XHyperlink >& rxHlink ) throw (uno::RuntimeException); + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException); + + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); + +private: + typedef ::std::vector< uno::Reference< excel::XHyperlink > > HyperlinkVector; + HyperlinkVector maHlinks; +}; + +// ---------------------------------------------------------------------------- + +ScVbaHlinkContainer::ScVbaHlinkContainer() throw (uno::RuntimeException) +{ + // TODO FIXME: fill with existing hyperlinks +} + +ScVbaHlinkContainer::ScVbaHlinkContainer( const ScVbaHlinkContainerRef& rxSheetContainer, + const ScRangeList& rScRanges ) throw (uno::RuntimeException) +{ + for( sal_Int32 nIndex = 0, nCount = rxSheetContainer->getCount(); nIndex < nCount; ++nIndex ) + { + uno::Reference< excel::XHyperlink > xHlink( rxSheetContainer->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XRange > xHlinkRange( xHlink->getRange(), uno::UNO_QUERY_THROW ); + if( lclContains( rScRanges, xHlinkRange ) ) + maHlinks.push_back( xHlink ); + } +} + +ScVbaHlinkContainer::~ScVbaHlinkContainer() +{ +} + +void ScVbaHlinkContainer::insertHyperlink( const uno::Reference< excel::XHyperlink >& rxHlink ) throw (uno::RuntimeException) +{ + HyperlinkVector::iterator aIt = ::std::find_if( maHlinks.begin(), maHlinks.end(), EqualAnchorFunctor( rxHlink ) ); + if( aIt == maHlinks.end() ) + maHlinks.push_back( rxHlink ); + else + *aIt = rxHlink; +} + +sal_Int32 SAL_CALL ScVbaHlinkContainer::getCount() throw (uno::RuntimeException) +{ + return static_cast< sal_Int32 >( maHlinks.size() ); +} + +uno::Any SAL_CALL ScVbaHlinkContainer::getByIndex( sal_Int32 nIndex ) + throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( (0 <= nIndex) && (nIndex < getCount()) ) + return uno::Any( maHlinks[ static_cast< size_t >( nIndex ) ] ); + throw lang::IndexOutOfBoundsException(); +} + +uno::Type SAL_CALL ScVbaHlinkContainer::getElementType() throw (uno::RuntimeException) +{ + return excel::XHyperlink::static_type( 0 ); +} + +sal_Bool SAL_CALL ScVbaHlinkContainer::hasElements() throw (uno::RuntimeException) +{ + return !maHlinks.empty(); +} + +// ============================================================================ + +ScVbaHlinkContainerMember::ScVbaHlinkContainerMember( ScVbaHlinkContainer* pContainer ) : + mxContainer( pContainer ) +{ +} + +ScVbaHlinkContainerMember::~ScVbaHlinkContainerMember() +{ +} + +} // namespace detail + +// ============================================================================ + +ScVbaHyperlinks::ScVbaHyperlinks( const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext ) throw (uno::RuntimeException) : + detail::ScVbaHlinkContainerMember( new detail::ScVbaHlinkContainer ), + ScVbaHyperlinks_BASE( rxParent, rxContext, uno::Reference< container::XIndexAccess >( mxContainer.get() ) ) +{ +} + +ScVbaHyperlinks::ScVbaHyperlinks( const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const ScVbaHyperlinksRef& rxSheetHlinks, const ScRangeList& rScRanges ) throw (uno::RuntimeException) : + detail::ScVbaHlinkContainerMember( new detail::ScVbaHlinkContainer( rxSheetHlinks->mxContainer, rScRanges ) ), + ScVbaHyperlinks_BASE( rxParent, rxContext, uno::Reference< container::XIndexAccess >( mxContainer.get() ) ), + mxSheetHlinks( rxSheetHlinks ) +{ +} + +ScVbaHyperlinks::~ScVbaHyperlinks() +{ +} + +// XHyperlinks ---------------------------------------------------------------- + +uno::Reference< excel::XHyperlink > SAL_CALL ScVbaHyperlinks::Add( + const uno::Any& rAnchor, const uno::Any& rAddress, const uno::Any& rSubAddress, + const uno::Any& rScreenTip, const uno::Any& rTextToDisplay ) throw (uno::RuntimeException) +{ + /* If this Hyperlinks object has been craeted from a Range object, the + call to Add() is passed to the Hyperlinks object of the parent + worksheet. This container will not be modified (it will not contain the + inserted hyperlink). + For details, see documentation in hyperlinks.hxx. + */ + if( mxSheetHlinks.is() ) + return mxSheetHlinks->Add( rAnchor, rAddress, rSubAddress, rScreenTip, rTextToDisplay ); + + // get anchor object (can be a Range or a Shape object) + uno::Reference< XHelperInterface > xAnchor( rAnchor, uno::UNO_QUERY_THROW ); + + /* Create the Hyperlink object, this tries to insert the hyperlink into + the spreadsheet document. Parent of the Hyperlink is the anchor object. */ + uno::Reference< excel::XHyperlink > xHlink( new ScVbaHyperlink( + xAnchor, mxContext, rAddress, rSubAddress, rScreenTip, rTextToDisplay ) ); + + /* If creation of the hyperlink did not throw, insert it into the + collection. */ + mxContainer->insertHyperlink( xHlink ); + return xHlink; +} + +void SAL_CALL ScVbaHyperlinks::Delete() throw (uno::RuntimeException) +{ + // FIXME not implemented + throw uno::RuntimeException(); +} + +// XEnumerationAccess --------------------------------------------------------- + +uno::Reference< container::XEnumeration > SAL_CALL ScVbaHyperlinks::createEnumeration() throw (uno::RuntimeException) +{ + return new SimpleIndexAccessToEnumeration( m_xIndexAccess ); +} + +// XElementAccess ------------------------------------------------------------- + +uno::Type SAL_CALL ScVbaHyperlinks::getElementType() throw (uno::RuntimeException) +{ + return excel::XHyperlink::static_type( 0 ); +} + +// ScVbaCollectionBase -------------------------------------------------------- + +uno::Any ScVbaHyperlinks::createCollectionObject( const uno::Any& rSource ) +{ + // container stores XHyperlink objects, just return the passed object + return rSource; +} + +// XHelperInterface ----------------------------------------------------------- + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaHyperlinks, "ooo.vba.excel.Hyperlinks" ) + +// ============================================================================ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbahyperlinks.hxx b/sc/source/ui/vba/vbahyperlinks.hxx new file mode 100644 index 000000000000..37dab9dd886a --- /dev/null +++ b/sc/source/ui/vba/vbahyperlinks.hxx @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_HYPERLINKS_HXX +#define SC_VBA_HYPERLINKS_HXX + +#include <ooo/vba/excel/XHyperlinks.hpp> +#include <rtl/ref.hxx> +#include <vbahelper/vbacollectionimpl.hxx> + +class ScRangeList; + +// ============================================================================ + +namespace detail { + +class ScVbaHlinkContainer; +typedef ::rtl::Reference< ScVbaHlinkContainer > ScVbaHlinkContainerRef; + +/** Base class for ScVbaHyperlinks to get an initialized ScVbaHlinkContainer + class member before the ScVbaHyperlinks_BASE base class will be constructed. + */ +struct ScVbaHlinkContainerMember +{ + ScVbaHlinkContainerRef mxContainer; + + explicit ScVbaHlinkContainerMember( ScVbaHlinkContainer* pContainer ); + ~ScVbaHlinkContainerMember(); +}; + +} // namespace detail + +// ============================================================================ + +class ScVbaHyperlinks; +typedef ::rtl::Reference< ScVbaHyperlinks > ScVbaHyperlinksRef; + +typedef CollTestImplHelper< ov::excel::XHyperlinks > ScVbaHyperlinks_BASE; + +/** Represents a collection of hyperlinks of a worksheet or of a range. + + When a Hyperlinks collection object has been constructed from a VBA + Worksheet object, it will always represent the current set of all + hyperlinks existing in the sheet. Insertion and deletion of hyperlinks will + be reflected by the instance. + + When a Hyperlinks collection object has been constructed from a VBA Range + object, it will represent the set of hyperlinks that have existed at its + construction time, and that are located completely inside the range(s) + represented by the Range object. Insertion and deletion of hyperlinks will + *not* be reflected by that instance. The instance will always offer all + hyperlinks it has been constructed with, even if they no longer exist. + Furthermore, the instance will not offer hyperlinks inserted later, even if + the instance itself has been used to insert the new hyperlinks. + + VBA code example: + + With ThisWorkbook.Worksheets(1) + + Set hlinks = .Hyperlinks ' global Hyperlinks object + Set myrange = .Range("A1:C3") + Set rangelinks1 = myrange.Hyperlinks ' hyperlinks of range A1:C3 + + MsgBox hlinks.Count ' 0 + MsgBox rangelinks1.Count ' 0 + + hlinks.Add .Range("A1"), "http://example.com" + ' a new hyperlink has been added in cell A1 + + MsgBox hlinks.Count ' 1 + MsgBox rangelinks1.Count ' still 0! + Set rangelinks2 = myrange.Hyperlinks ' hyperlinks of range A1:C3 + MsgBox rangelinks2.Count ' 1 (constructed after Add) + + rangelinks1.Add .Range("A2"), "http://example.com" + ' a new hyperlink has been constructed via the rangelinks1 object + ' but this addition has been done by the worksheet Hyperlinks object + + MsgBox hlinks.Count ' 2 + MsgBox rangelinks1.Count ' still 0!!! + MsgBox rangelinks2.Count ' still 1!!! + MsgBox myrange.Hyperlinks.Count ' 2 (constructed after Add) + + End With + */ +class ScVbaHyperlinks : private detail::ScVbaHlinkContainerMember, public ScVbaHyperlinks_BASE +{ +public: + explicit ScVbaHyperlinks( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext ) throw (css::uno::RuntimeException); + + explicit ScVbaHyperlinks( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const ScVbaHyperlinksRef& rxSheetHlinks, const ScRangeList& rScRanges ) throw (css::uno::RuntimeException); + + virtual ~ScVbaHyperlinks(); + + // XHyperlinks + virtual css::uno::Reference< ov::excel::XHyperlink > SAL_CALL Add( + const css::uno::Any& rAnchor, const css::uno::Any& rAddress, const css::uno::Any& rSubAddress, + const css::uno::Any& rScreenTip, const css::uno::Any& rTextToDisplay ) + throw (css::uno::RuntimeException); + + virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); + + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + + // ScVbaCollectionBase + virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource ); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + ScVbaHyperlinksRef mxSheetHlinks; +}; + +// ============================================================================ + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbainterior.cxx b/sc/source/ui/vba/vbainterior.cxx new file mode 100644 index 000000000000..f3ea1b0f53dd --- /dev/null +++ b/sc/source/ui/vba/vbainterior.cxx @@ -0,0 +1,419 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/beans/XIntrospection.hpp> +#include <com/sun/star/beans/XIntrospectionAccess.hpp> +#include <com/sun/star/reflection/XIdlMethod.hpp> +#include <com/sun/star/beans/MethodConcept.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/xml/AttributeData.hpp> + +#include <ooo/vba/excel/XlColorIndex.hpp> +#include <ooo/vba/excel/XlPattern.hpp> + +#include <comphelper/processfactory.hxx> +#include <cppuhelper/queryinterface.hxx> + +#include <map> + +#include <svx/xtable.hxx> + +#include "vbainterior.hxx" +#include "vbapalette.hxx" +#include "document.hxx" + +#define STATIC_TABLE_SIZE( array ) (sizeof(array)/sizeof(*(array))) +#define COLORMAST 0xFFFFFF +const sal_uInt16 EXC_COLOR_WINDOWBACK = 65; +typedef std::map< sal_Int32, sal_Int32 > PatternMap; +typedef std::pair< sal_Int32, sal_Int32 > PatternPair; +using namespace ::com::sun::star; +using namespace ::ooo::vba; +using namespace ::ooo::vba::excel::XlPattern; +static const rtl::OUString BACKCOLOR( RTL_CONSTASCII_USTRINGPARAM( "CellBackColor" ) ); +static const rtl::OUString PATTERN( RTL_CONSTASCII_USTRINGPARAM( "Pattern" ) ); +static const rtl::OUString PATTERNCOLOR( RTL_CONSTASCII_USTRINGPARAM( "PatternColor" ) ); + +PatternMap lcl_getPatternMap() +{ + PatternMap aPatternMap; + aPatternMap.insert( PatternPair( xlPatternAutomatic, 0 ) ); + aPatternMap.insert( PatternPair( xlPatternChecker, 9 ) ); + aPatternMap.insert( PatternPair( xlPatternCrissCross, 16 ) ); + aPatternMap.insert( PatternPair( xlPatternDown, 7 ) ); + aPatternMap.insert( PatternPair( xlPatternGray16, 17 ) ); + aPatternMap.insert( PatternPair( xlPatternGray25, 4 ) ); + aPatternMap.insert( PatternPair( xlPatternGray50, 2 ) ); + aPatternMap.insert( PatternPair( xlPatternGray75, 3 ) ); + aPatternMap.insert( PatternPair( xlPatternGray8, 18 ) ); + aPatternMap.insert( PatternPair( xlPatternGrid, 15 ) ); + aPatternMap.insert( PatternPair( xlPatternHorizontal, 5 ) ); + aPatternMap.insert( PatternPair( xlPatternLightDown, 13 ) ); + aPatternMap.insert( PatternPair( xlPatternLightHorizontal, 11 ) ); + aPatternMap.insert( PatternPair( xlPatternLightUp, 14 ) ); + aPatternMap.insert( PatternPair( xlPatternLightVertical, 12 ) ); + aPatternMap.insert( PatternPair( xlPatternNone, 0 ) ); + aPatternMap.insert( PatternPair( xlPatternSemiGray75, 10 ) ); + aPatternMap.insert( PatternPair( xlPatternSolid, 0 ) ); + aPatternMap.insert( PatternPair( xlPatternUp, 8 ) ); + aPatternMap.insert( PatternPair( xlPatternVertical, 6 ) ); + return aPatternMap; +} + +static PatternMap aPatternMap( lcl_getPatternMap() ); + +ScVbaInterior::ScVbaInterior( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< beans::XPropertySet >& xProps, ScDocument* pScDoc ) throw ( lang::IllegalArgumentException) : ScVbaInterior_BASE( xParent, xContext ), m_xProps(xProps), m_pScDoc( pScDoc ) +{ + // auto color + //m_aPattColor.SetColor( (sal_uInt32)0xFFFFFFFF ); + m_aPattColor.SetColor( (sal_uInt32)0x0 ); + m_nPattern = 0L; + if ( !m_xProps.is() ) + throw lang::IllegalArgumentException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "properties") ), uno::Reference< uno::XInterface >(), 2 ); +} + +uno::Any +ScVbaInterior::getColor() throw (uno::RuntimeException) +{ + Color aBackColor( GetBackColor() ); + return uno::makeAny( OORGBToXLRGB( aBackColor.GetColor() ) ); +} + +void +ScVbaInterior::setColor( const uno::Any& _color ) throw (uno::RuntimeException) +{ + sal_Int32 nColor = 0; + if( _color >>= nColor ) + { + SetUserDefinedAttributes( BACKCOLOR, SetAttributeData( XLRGBToOORGB( nColor ) ) ); + //m_xProps->setPropertyValue( BACKCOLOR , XLRGBToOORGB(_color)); + SetMixedColor(); + } +} + +void +ScVbaInterior::SetMixedColor() +{ + // pattern + uno::Any aPattern = GetUserDefinedAttributes( PATTERN ); + if( aPattern.hasValue() ) + { + m_nPattern = GetAttributeData( aPattern ); + } + sal_Int32 nPattern = aPatternMap[ m_nPattern ]; + // pattern color + uno::Any aPatternColor = GetUserDefinedAttributes( PATTERNCOLOR ); + if( aPatternColor.hasValue() ) + { + sal_uInt32 nPatternColor = GetAttributeData( aPatternColor ); + m_aPattColor.SetColor( nPatternColor ); + } + sal_Int32 nPatternColor = m_aPattColor.GetColor(); + // back color + Color aBackColor( GetBackColor() ); + // set mixed color + Color aMixedColor; + if( nPattern > 0 ) + aMixedColor = GetPatternColor( Color(nPatternColor), aBackColor, (sal_uInt32)nPattern ); + else + aMixedColor = GetPatternColor( aBackColor, aBackColor, (sal_uInt32)nPattern ); + sal_Int32 nMixedColor = aMixedColor.GetColor() & COLORMAST; + m_xProps->setPropertyValue( BACKCOLOR , uno::makeAny( nMixedColor ) ); +} + +uno::Reference< container::XIndexAccess > +ScVbaInterior::getPalette() +{ + if ( !m_pScDoc ) + throw uno::RuntimeException(); + SfxObjectShell* pShell = m_pScDoc->GetDocumentShell(); + ScVbaPalette aPalette( pShell ); + return aPalette.getPalette(); +} + +void SAL_CALL +ScVbaInterior::setColorIndex( const css::uno::Any& _colorindex ) throw (css::uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + _colorindex >>= nIndex; + + // hackly for excel::XlColorIndex::xlColorIndexNone + if( nIndex == excel::XlColorIndex::xlColorIndexNone ) + { + m_xProps->setPropertyValue( BACKCOLOR, uno::makeAny( sal_Int32( -1 ) ) ); + } + else + { + // setColor expects colors in XL RGB values + // #FIXME this is daft we convert OO RGB val to XL RGB val and + // then back again to OO RGB value + setColor( OORGBToXLRGB( GetIndexColor( nIndex ) ) ); + } +} +uno::Any +ScVbaInterior::GetIndexColor( const sal_Int32& nColorIndex ) +{ + sal_Int32 nIndex = nColorIndex; + // #FIXME xlColorIndexAutomatic & xlColorIndexNone are not really + // handled properly here + if ( !nIndex || ( nIndex == excel::XlColorIndex::xlColorIndexAutomatic ) || ( nIndex == excel::XlColorIndex::xlColorIndexNone ) ) + nIndex = 2; // default is white ( this maybe will probably break, e.g. we may at some stage need to know what this interior is, a cell or something else and then pick a default colour based on that ) + --nIndex; // OOo indices are zero bases + uno::Reference< container::XIndexAccess > xIndex = getPalette(); + return xIndex->getByIndex( nIndex ); +} + +sal_Int32 +ScVbaInterior::GetColorIndex( const sal_Int32 nColor ) +{ + uno::Reference< container::XIndexAccess > xIndex = getPalette(); + sal_Int32 nElems = xIndex->getCount(); + sal_Int32 nIndex = -1; + for ( sal_Int32 count=0; count<nElems; ++count ) + { + sal_Int32 nPaletteColor = 0; + xIndex->getByIndex( count ) >>= nPaletteColor; + if ( nPaletteColor == nColor ) + { + nIndex = count + 1; // 1 based + break; + } + } + return nIndex; +} + +uno::Any SAL_CALL +ScVbaInterior::getColorIndex() throw ( css::uno::RuntimeException ) +{ + sal_Int32 nColor = 0; + // hackly for excel::XlColorIndex::xlColorIndexNone + uno::Any aColor = m_xProps->getPropertyValue( BACKCOLOR ); + if( ( aColor >>= nColor ) && ( nColor == -1 ) ) + { + nColor = excel::XlColorIndex::xlColorIndexNone; + return uno::makeAny( nColor ); + } + + // getColor returns Xl ColorValue, need to convert it to OO val + // as the palette deals with OO RGB values + // #FIXME this is daft in getColor we convert OO RGB val to XL RGB val + // and then back again to OO RGB value + XLRGBToOORGB( getColor() ) >>= nColor; + + return uno::makeAny( GetColorIndex( nColor ) ); +} +Color +ScVbaInterior::GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt32 nXclPattern ) +{ + // 0x00 == 0% transparence (full rPattColor) + // 0x80 == 100% transparence (full rBackColor) + static const sal_uInt8 pnRatioTable[] = + { + 0x80, 0x00, 0x40, 0x20, 0x60, 0x40, 0x40, 0x40, // 00 - 07 + 0x40, 0x40, 0x20, 0x60, 0x60, 0x60, 0x60, 0x48, // 08 - 15 + 0x50, 0x70, 0x78 // 16 - 18 + }; + return ( nXclPattern < STATIC_TABLE_SIZE( pnRatioTable ) ) ? + GetMixedColor( rPattColor, rBackColor, pnRatioTable[ nXclPattern ] ) : rPattColor; +} +Color +ScVbaInterior::GetMixedColor( const Color& rFore, const Color& rBack, sal_uInt8 nTrans ) +{ + return Color( + nTrans, + GetMixedColorComp( rFore.GetRed(), rBack.GetRed(), nTrans ), + GetMixedColorComp( rFore.GetGreen(), rBack.GetGreen(), nTrans ), + GetMixedColorComp( rFore.GetBlue(), rBack.GetBlue(), nTrans )); +} +sal_uInt8 +ScVbaInterior::GetMixedColorComp( sal_uInt8 nFore, sal_uInt8 nBack, sal_uInt8 nTrans ) +{ + sal_uInt32 nTemp = ((static_cast< sal_Int32 >( nBack ) - nFore) * nTrans) / 0x80 + nFore; + return static_cast< sal_uInt8 >( nTemp ); +} +uno::Reference< container::XNameContainer > +ScVbaInterior::GetAttributeContainer() +{ + return uno::Reference < container::XNameContainer > ( m_xProps->getPropertyValue( rtl::OUString::createFromAscii( "UserDefinedAttributes" ) ), uno::UNO_QUERY_THROW ); +} +sal_Int32 +ScVbaInterior::GetAttributeData( uno::Any aValue ) +{ + xml::AttributeData aDataValue; + if( aValue >>= aDataValue ) + { + return aDataValue.Value.toInt32(); + } + return sal_Int32( 0 ); +} +uno::Any +ScVbaInterior::SetAttributeData( sal_Int32 nValue ) +{ + xml::AttributeData aAttributeData; + //aAttributeData.Namespace = rtl::OUString::createFromAscii( "ooo.vba.excel.CellPatten"); + aAttributeData.Type = rtl::OUString::createFromAscii( "sal_Int32" ); + aAttributeData.Value = rtl::OUString::valueOf( nValue ); + return uno::makeAny( aAttributeData ); +} +uno::Any +ScVbaInterior::GetUserDefinedAttributes( const rtl::OUString& sName ) +{ + uno::Reference< container::XNameContainer > xNameContainer( GetAttributeContainer(), uno::UNO_QUERY_THROW ); + if( xNameContainer->hasByName( sName ) ) + { + return xNameContainer->getByName( sName ); + } + return uno::Any(); +} +void +ScVbaInterior::SetUserDefinedAttributes( const rtl::OUString& sName, const uno::Any& aValue ) +{ + if( aValue.hasValue() ) + { + uno::Reference< container::XNameContainer > xNameContainer( GetAttributeContainer(), uno::UNO_QUERY_THROW ); + if( xNameContainer->hasByName( sName ) ) + xNameContainer->removeByName( sName ); + xNameContainer->insertByName( sName, aValue ); + m_xProps->setPropertyValue( rtl::OUString::createFromAscii( "UserDefinedAttributes" ), uno::makeAny( xNameContainer ) ); + } +} +// OOo do not support below API +uno::Any SAL_CALL +ScVbaInterior::getPattern() throw (uno::RuntimeException) +{ + // XlPattern + uno::Any aPattern = GetUserDefinedAttributes( PATTERN ); + if( aPattern.hasValue() ) + return uno::makeAny( GetAttributeData( aPattern ) ); + return uno::makeAny( excel::XlPattern::xlPatternNone ); +} +void SAL_CALL +ScVbaInterior::setPattern( const uno::Any& _pattern ) throw (uno::RuntimeException) +{ + if( _pattern >>= m_nPattern ) + { + SetUserDefinedAttributes( PATTERN, SetAttributeData( m_nPattern ) ); + SetMixedColor(); + } + else + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Pattern index" ), uno::Reference< uno::XInterface >() ); +} +Color +ScVbaInterior::GetBackColor() +{ + sal_Int32 nColor = 0; + Color aBackColor; + uno::Any aColor = GetUserDefinedAttributes( BACKCOLOR ); + if( aColor.hasValue() ) + { + nColor = GetAttributeData( aColor ); + aBackColor.SetColor( nColor ); + } + else + { + uno::Any aAny; + aAny = OORGBToXLRGB( m_xProps->getPropertyValue( BACKCOLOR ) ); + if( aAny >>= nColor ) + { + nColor = XLRGBToOORGB( nColor ); + aBackColor.SetColor( nColor ); + SetUserDefinedAttributes( BACKCOLOR, SetAttributeData( nColor ) ); + } + } + return aBackColor; +} +uno::Any SAL_CALL +ScVbaInterior::getPatternColor() throw (uno::RuntimeException) +{ + // 0 is the default color. no filled. + uno::Any aPatternColor = GetUserDefinedAttributes( PATTERNCOLOR ); + if( aPatternColor.hasValue() ) + { + sal_uInt32 nPatternColor = GetAttributeData( aPatternColor ); + return uno::makeAny( OORGBToXLRGB( nPatternColor ) ); + } + return uno::makeAny( sal_Int32( 0 ) ); +} +void SAL_CALL +ScVbaInterior::setPatternColor( const uno::Any& _patterncolor ) throw (uno::RuntimeException) +{ + sal_Int32 nPattColor = 0; + if( _patterncolor >>= nPattColor ) + { + SetUserDefinedAttributes( PATTERNCOLOR, SetAttributeData( XLRGBToOORGB( nPattColor ) ) ); + SetMixedColor(); + } + else + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Pattern Color" ), uno::Reference< uno::XInterface >() ); +} +uno::Any SAL_CALL +ScVbaInterior::getPatternColorIndex() throw (uno::RuntimeException) +{ + sal_Int32 nColor = 0; + XLRGBToOORGB( getPatternColor() ) >>= nColor; + + return uno::makeAny( GetIndexColor( nColor ) ); +} +void SAL_CALL +ScVbaInterior::setPatternColorIndex( const uno::Any& _patterncolorindex ) throw (uno::RuntimeException) +{ + sal_Int32 nColorIndex = 0; + if( _patterncolorindex >>= nColorIndex ) + { + if( nColorIndex == 0 ) + return; + sal_Int32 nPattColor = 0; + GetIndexColor( nColorIndex ) >>= nPattColor; + setPatternColor( uno::makeAny( OORGBToXLRGB( nPattColor ) ) ); + } + else + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Pattern Color" ), uno::Reference< uno::XInterface >() ); +} + +rtl::OUString& +ScVbaInterior::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaInterior") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaInterior::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Interior" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbainterior.hxx b/sc/source/ui/vba/vbainterior.hxx new file mode 100644 index 000000000000..51b06e7d97c4 --- /dev/null +++ b/sc/source/ui/vba/vbainterior.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_INTERIOR_HXX +#define SC_VBA_INTERIOR_HXX + +#include <ooo/vba/excel/XInterior.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> + +#include <com/sun/star/script/XInvocation.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +#include <tools/color.hxx> + +class ScDocument; + +typedef InheritedHelperInterfaceImpl1< ov::excel::XInterior > ScVbaInterior_BASE; + +class ScVbaInterior : public ScVbaInterior_BASE +{ + css::uno::Reference< css::beans::XPropertySet > m_xProps; + ScDocument* m_pScDoc; + Color m_aPattColor; + sal_Int32 m_nPattern; + + css::uno::Reference< css::container::XIndexAccess > getPalette(); + css::uno::Reference< css::container::XNameContainer > GetAttributeContainer(); + css::uno::Any SetAttributeData( sal_Int32 nValue ); + sal_Int32 GetAttributeData( css::uno::Any aValue ); + Color GetBackColor(); +protected: + Color GetPatternColor( const Color& rPattColor, const Color& rBackColor, sal_uInt32 nXclPattern ); + Color GetMixedColor( const Color& rFore, const Color& rBack, sal_uInt8 nTrans ); + sal_uInt8 GetMixedColorComp( sal_uInt8 nFore, sal_uInt8 nBack, sal_uInt8 nTrans ); + css::uno::Any GetIndexColor( const sal_Int32& nColorIndex ); + sal_Int32 GetColorIndex( const sal_Int32 nColor ); + css::uno::Any GetUserDefinedAttributes( const rtl::OUString& sName ); + void SetUserDefinedAttributes( const rtl::OUString& sName, const css::uno::Any& aValue ); + void SetMixedColor(); +public: + ScVbaInterior( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::beans::XPropertySet >& xProps, ScDocument* pScDoc = NULL) throw ( css::lang::IllegalArgumentException); + + virtual ~ScVbaInterior(){} + + virtual css::uno::Any SAL_CALL getColor() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setColor( const css::uno::Any& _color ) throw (css::uno::RuntimeException) ; + + virtual css::uno::Any SAL_CALL getColorIndex() throw ( css::uno::RuntimeException); + virtual void SAL_CALL setColorIndex( const css::uno::Any& _colorindex ) throw ( css::uno::RuntimeException ); + virtual css::uno::Any SAL_CALL getPattern() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPattern( const css::uno::Any& _pattern ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getPatternColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPatternColor( const css::uno::Any& _patterncolor ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getPatternColorIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPatternColorIndex( const css::uno::Any& _patterncolorindex ) throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenu.cxx b/sc/source/ui/vba/vbamenu.cxx new file mode 100644 index 000000000000..ae6d4e4b1223 --- /dev/null +++ b/sc/source/ui/vba/vbamenu.cxx @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "vbamenu.hxx" +#include "vbamenuitems.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaMenu::ScVbaMenu( const uno::Reference< ov::XHelperInterface > xParent, const uno::Reference< uno::XComponentContext > xContext, const uno::Reference< XCommandBarControl >& xCommandBarControl ) throw( uno::RuntimeException ) : Menu_BASE( xParent, xContext ), m_xCommandBarControl( xCommandBarControl ) +{ +} + +::rtl::OUString SAL_CALL +ScVbaMenu::getCaption() throw ( uno::RuntimeException ) +{ + return m_xCommandBarControl->getCaption(); +} + +void SAL_CALL +ScVbaMenu::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) +{ + m_xCommandBarControl->setCaption( _caption ); +} + +void SAL_CALL +ScVbaMenu::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + m_xCommandBarControl->Delete(); +} + +uno::Any SAL_CALL +ScVbaMenu::MenuItems( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< XCommandBarControls > xCommandBarControls( m_xCommandBarControl->Controls( uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XMenuItems > xMenuItems( new ScVbaMenuItems( this, mxContext, xCommandBarControls ) ); + if( aIndex.hasValue() ) + { + return xMenuItems->Item( aIndex, uno::Any() ); + } + return uno::makeAny( xMenuItems ); +} + +rtl::OUString& +ScVbaMenu::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenu") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaMenu::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Menu" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenu.hxx b/sc/source/ui/vba/vbamenu.hxx new file mode 100644 index 000000000000..3141b5718447 --- /dev/null +++ b/sc/source/ui/vba/vbamenu.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SC_VBA_MENU_HXX +#define SC_VBA_MENU_HXX + +#include <ooo/vba/excel/XMenu.hpp> +#include <ooo/vba/XCommandBarControl.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XMenu > Menu_BASE; + +class ScVbaMenu : public Menu_BASE +{ +private: + css::uno::Reference< ov::XCommandBarControl > m_xCommandBarControl; + +public: + ScVbaMenu( const css::uno::Reference< ov::XHelperInterface > xParent, const css::uno::Reference< css::uno::XComponentContext > xContext, const css::uno::Reference< ov::XCommandBarControl >& xCommandBarControl ) throw( css::uno::RuntimeException ); + + virtual ::rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException); + + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL MenuItems( const css::uno::Any& aIndex ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif//SC_VBA_MENU_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenubar.cxx b/sc/source/ui/vba/vbamenubar.cxx new file mode 100644 index 000000000000..1ad19a6a3b51 --- /dev/null +++ b/sc/source/ui/vba/vbamenubar.cxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#include "vbamenubar.hxx" +#include "vbamenus.hxx" +#include <ooo/vba/XCommandBarControls.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaMenuBar::ScVbaMenuBar( const uno::Reference< ov::XHelperInterface > xParent, const uno::Reference< uno::XComponentContext > xContext, const uno::Reference< XCommandBar >& xCommandBar ) throw( uno::RuntimeException ) : MenuBar_BASE( xParent, xContext ), m_xCommandBar( xCommandBar ) +{ +} + +uno::Any SAL_CALL +ScVbaMenuBar::Menus( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< XCommandBarControls > xCommandBarControls( m_xCommandBar->Controls( uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XMenus > xMenus( new ScVbaMenus( this, mxContext, xCommandBarControls ) ); + if( aIndex.hasValue() ) + { + return xMenus->Item( aIndex, uno::Any() ); + } + return uno::makeAny( xMenus ); +} + +rtl::OUString& +ScVbaMenuBar::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuBar") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaMenuBar::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.MenuBar" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenubar.hxx b/sc/source/ui/vba/vbamenubar.hxx new file mode 100644 index 000000000000..15253d4e73cb --- /dev/null +++ b/sc/source/ui/vba/vbamenubar.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SC_VBA_MENUBAR_HXX +#define SC_VBA_MENUBAR_HXX + +#include <ooo/vba/excel/XMenuBar.hpp> +#include <ooo/vba/XCommandBar.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XMenuBar > MenuBar_BASE; + +class ScVbaMenuBar : public MenuBar_BASE +{ +private: + css::uno::Reference< ov::XCommandBar > m_xCommandBar; + +public: + ScVbaMenuBar( const css::uno::Reference< ov::XHelperInterface > xParent, const css::uno::Reference< css::uno::XComponentContext > xContext, const css::uno::Reference< ov::XCommandBar >& xCommandBar ) throw( css::uno::RuntimeException ); + + virtual css::uno::Any SAL_CALL Menus( const css::uno::Any& aIndex ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif//SC_VBA_MENUBAR_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenubars.cxx b/sc/source/ui/vba/vbamenubars.cxx new file mode 100644 index 000000000000..4dfaefcddda4 --- /dev/null +++ b/sc/source/ui/vba/vbamenubars.cxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#include "vbamenubars.hxx" +#include "vbamenubar.hxx" +#include <ooo/vba/excel/XlSheetType.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuBarEnumeration_BASE; + +class MenuBarEnumeration : public MenuBarEnumeration_BASE +{ + uno::Reference< XHelperInterface > m_xParent; + uno::Reference< uno::XComponentContext > m_xContext; + uno::Reference< container::XEnumeration > m_xEnumeration; +public: + MenuBarEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration ) + { + } + virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException ) + { + return m_xEnumeration->hasMoreElements(); + } + virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) + { + // FIXME: should be add menubar + if( hasMoreElements() ) + { + uno::Reference< XCommandBar > xCommandBar( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( m_xParent, m_xContext, xCommandBar ) ); + return uno::makeAny( xMenuBar ); + } + else + throw container::NoSuchElementException(); + return uno::Any(); + } +}; + +ScVbaMenuBars::ScVbaMenuBars( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCommandBars >& xCommandBars ) throw ( uno::RuntimeException ) : MenuBars_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBars( xCommandBars ) +{ +} + +ScVbaMenuBars::~ScVbaMenuBars() +{ +} + +// XEnumerationAccess +uno::Type SAL_CALL +ScVbaMenuBars::getElementType() throw ( uno::RuntimeException ) +{ + return excel::XMenuBar::static_type( 0 ); +} + +uno::Reference< container::XEnumeration > +ScVbaMenuBars::createEnumeration() throw ( uno::RuntimeException ) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBars, uno::UNO_QUERY_THROW ); + return uno::Reference< container::XEnumeration >( new MenuBarEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) ); +} + +uno::Any +ScVbaMenuBars::createCollectionObject( const uno::Any& aSource ) +{ + // make no sense + return aSource; +} + +sal_Int32 SAL_CALL +ScVbaMenuBars::getCount() throw(css::uno::RuntimeException) +{ + return m_xCommandBars->getCount(); +} + +// ScVbaCollectionBaseImpl +uno::Any SAL_CALL +ScVbaMenuBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException ) +{ + sal_Int16 nIndex = 0; + aIndex >>= nIndex; + if( nIndex == excel::XlSheetType::xlWorksheet ) + { + uno::Any aSource; + aSource <<= rtl::OUString::createFromAscii( "Worksheet Menu Bar" ); + uno::Reference< XCommandBar > xCommandBar( m_xCommandBars->Item( aSource, uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XMenuBar > xMenuBar( new ScVbaMenuBar( this, mxContext, xCommandBar ) ); + return uno::makeAny( xMenuBar ); + } + + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + + return uno::Any(); +} + +// XHelperInterface +rtl::OUString& +ScVbaMenuBars::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuBars") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaMenuBars::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.MenuBars" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenubars.hxx b/sc/source/ui/vba/vbamenubars.hxx new file mode 100644 index 000000000000..2579eb74f8aa --- /dev/null +++ b/sc/source/ui/vba/vbamenubars.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SC_VBA_MENUBARS_HXX +#define SC_VBA_MENUBARS_HXX + +#include <ooo/vba/excel/XMenuBars.hpp> +#include <ooo/vba/excel/XMenuBar.hpp> +#include <ooo/vba/XCommandBars.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XMenuBars > MenuBars_BASE; + +class ScVbaMenuBars : public MenuBars_BASE +{ +private: + css::uno::Reference< ov::XCommandBars > m_xCommandBars; + +public: + ScVbaMenuBars( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< ov::XCommandBars >& xCommandBars ) throw (css::uno::RuntimeException); + virtual ~ScVbaMenuBars(); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + virtual sal_Int32 SAL_CALL getCount() throw(css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& aIndex, const css::uno::Any& /*aIndex2*/ ) throw( css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_MENUBARS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenuitem.cxx b/sc/source/ui/vba/vbamenuitem.cxx new file mode 100644 index 000000000000..8843544f31f0 --- /dev/null +++ b/sc/source/ui/vba/vbamenuitem.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#include "vbamenuitem.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaMenuItem::ScVbaMenuItem( const uno::Reference< ov::XHelperInterface > xParent, const uno::Reference< uno::XComponentContext > xContext, const uno::Reference< XCommandBarControl >& xCommandBarControl ) throw( uno::RuntimeException ) : MenuItem_BASE( xParent, xContext ), m_xCommandBarControl( xCommandBarControl ) +{ +} + +::rtl::OUString SAL_CALL +ScVbaMenuItem::getCaption() throw ( uno::RuntimeException ) +{ + return m_xCommandBarControl->getCaption(); +} + +void SAL_CALL +ScVbaMenuItem::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) +{ + m_xCommandBarControl->setCaption( _caption ); +} + +::rtl::OUString SAL_CALL +ScVbaMenuItem::getOnAction() throw ( uno::RuntimeException ) +{ + return m_xCommandBarControl->getOnAction(); +} + +void SAL_CALL +ScVbaMenuItem::setOnAction( const ::rtl::OUString& _onaction ) throw (uno::RuntimeException) +{ + m_xCommandBarControl->setOnAction( _onaction ); +} + +void SAL_CALL +ScVbaMenuItem::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + m_xCommandBarControl->Delete(); +} + +rtl::OUString& +ScVbaMenuItem::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuItem") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaMenuItem::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.MenuItem" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenuitem.hxx b/sc/source/ui/vba/vbamenuitem.hxx new file mode 100644 index 000000000000..5c22b3409a28 --- /dev/null +++ b/sc/source/ui/vba/vbamenuitem.hxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SC_VBA_MENUITEM_HXX +#define SC_VBA_MENUITEM_HXX + +#include <ooo/vba/excel/XMenuItem.hpp> +#include <ooo/vba/XCommandBarControl.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XMenuItem > MenuItem_BASE; + +class ScVbaMenuItem : public MenuItem_BASE +{ +private: + css::uno::Reference< ov::XCommandBarControl > m_xCommandBarControl; + +public: + ScVbaMenuItem( const css::uno::Reference< ov::XHelperInterface > xParent, const css::uno::Reference< css::uno::XComponentContext > xContext, const css::uno::Reference< ov::XCommandBarControl >& xCommandBarControl ) throw( css::uno::RuntimeException ); + + virtual ::rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getOnAction() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOnAction( const ::rtl::OUString& _onaction ) throw (css::uno::RuntimeException); + + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif//SC_VBA_MENUITEM_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenuitems.cxx b/sc/source/ui/vba/vbamenuitems.cxx new file mode 100644 index 000000000000..5722830fce0a --- /dev/null +++ b/sc/source/ui/vba/vbamenuitems.cxx @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#include "vbamenuitems.hxx" +#include "vbamenuitem.hxx" +#include "vbamenu.hxx" +#include <ooo/vba/office/MsoControlType.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuEnumeration_BASE; + +class MenuEnumeration : public MenuEnumeration_BASE +{ + uno::Reference< XHelperInterface > m_xParent; + uno::Reference< uno::XComponentContext > m_xContext; + uno::Reference< container::XEnumeration > m_xEnumeration; +public: + MenuEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration ) + { + } + virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException ) + { + return m_xEnumeration->hasMoreElements(); + } + virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) + { + // FIXME: should be add menu + if( hasMoreElements() ) + { + uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup ) + { + uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) ); + return uno::makeAny( xMenu ); + } + else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton ) + { + uno::Reference< excel::XMenuItem > xMenuItem( new ScVbaMenuItem( m_xParent, m_xContext, xCommandBarControl ) ); + return uno::makeAny( xMenuItem ); + } + nextElement(); + } + else + throw container::NoSuchElementException(); + return uno::Any(); + } +}; + +ScVbaMenuItems::ScVbaMenuItems( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCommandBarControls >& xCommandBarControls ) throw ( uno::RuntimeException ) : MenuItems_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBarControls( xCommandBarControls ) +{ +} + +// XEnumerationAccess +uno::Type SAL_CALL +ScVbaMenuItems::getElementType() throw ( uno::RuntimeException ) +{ + return excel::XMenuItem::static_type( 0 ); +} + +uno::Reference< container::XEnumeration > +ScVbaMenuItems::createEnumeration() throw ( uno::RuntimeException ) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW ); + return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) ); +} + +uno::Any +ScVbaMenuItems::createCollectionObject( const uno::Any& aSource ) +{ + // make no sense + return aSource; +} + +sal_Int32 SAL_CALL +ScVbaMenuItems::getCount() throw(css::uno::RuntimeException) +{ + // FIXME: should check if it is a popup menu + return m_xCommandBarControls->getCount(); +} + +// ScVbaCollectionBaseImpl +uno::Any SAL_CALL +ScVbaMenuItems::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException ) +{ + uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW ); + if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup ) + return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) ); + else if( xCommandBarControl->getType() == office::MsoControlType::msoControlButton ) + return uno::makeAny( uno::Reference< excel::XMenuItem > ( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) ) ); + throw uno::RuntimeException(); +} + +uno::Reference< excel::XMenuItem > SAL_CALL ScVbaMenuItems::Add( const rtl::OUString& Caption, const css::uno::Any& OnAction, const css::uno::Any& /*ShortcutKey*/, const css::uno::Any& Before, const css::uno::Any& Restore, const css::uno::Any& /*StatusBar*/, const css::uno::Any& /*HelpFile*/, const css::uno::Any& /*HelpContextID*/ ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + sal_Int32 nType = office::MsoControlType::msoControlButton; + uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add( uno::makeAny( nType ), uno::Any(), uno::Any(), Before, Restore ); + xCommandBarControl->setCaption( Caption ); + if( OnAction.hasValue() ) + { + rtl::OUString sAction; + OnAction >>= sAction; + xCommandBarControl->setOnAction( sAction ); + } + return uno::Reference< excel::XMenuItem >( new ScVbaMenuItem( this, mxContext, xCommandBarControl ) ); +} + +// XHelperInterface +rtl::OUString& +ScVbaMenuItems::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenuItems") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaMenuItems::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.MenuItems" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenuitems.hxx b/sc/source/ui/vba/vbamenuitems.hxx new file mode 100644 index 000000000000..8a8dd6021b2d --- /dev/null +++ b/sc/source/ui/vba/vbamenuitems.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SC_VBA_MENUITEMS_HXX +#define SC_VBA_MENUITEMS_HXX + +#include <ooo/vba/excel/XMenuItems.hpp> +#include <ooo/vba/excel/XMenuItem.hpp> +#include <ooo/vba/XCommandBarControls.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XMenuItems > MenuItems_BASE; + +class ScVbaMenuItems : public MenuItems_BASE +{ +private: + css::uno::Reference< ov::XCommandBarControls > m_xCommandBarControls; + +public: + ScVbaMenuItems( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< ov::XCommandBarControls >& xCommandBarControls ) throw( css::uno::RuntimeException ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // Methods + virtual sal_Int32 SAL_CALL getCount() throw(css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index, const css::uno::Any& /*Index2*/ ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XMenuItem > SAL_CALL Add( const rtl::OUString& Caption, const css::uno::Any& OnAction, const css::uno::Any& ShortcutKey, const css::uno::Any& Before, const css::uno::Any& Restore, const css::uno::Any& StatusBar, const css::uno::Any& HelpFile, const css::uno::Any& HelpContextID ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_MENUITEMS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenus.cxx b/sc/source/ui/vba/vbamenus.cxx new file mode 100644 index 000000000000..e604d7b59242 --- /dev/null +++ b/sc/source/ui/vba/vbamenus.cxx @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#include "vbamenus.hxx" +#include "vbamenu.hxx" +#include <ooo/vba/office/MsoControlType.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > MenuEnumeration_BASE; + +class MenuEnumeration : public MenuEnumeration_BASE +{ + uno::Reference< XHelperInterface > m_xParent; + uno::Reference< uno::XComponentContext > m_xContext; + uno::Reference< container::XEnumeration > m_xEnumeration; +public: + MenuEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration ) + { + } + virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException ) + { + return m_xEnumeration->hasMoreElements(); + } + virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) + { + // FIXME: should be add menu + if( hasMoreElements() ) + { + uno::Reference< XCommandBarControl > xCommandBarControl( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + if( xCommandBarControl->getType() == office::MsoControlType::msoControlPopup ) + { + uno::Reference< excel::XMenu > xMenu( new ScVbaMenu( m_xParent, m_xContext, xCommandBarControl ) ); + return uno::makeAny( xMenu ); + } + nextElement(); + } + else + throw container::NoSuchElementException(); + return uno::Any(); + } +}; + +ScVbaMenus::ScVbaMenus( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCommandBarControls >& xCommandBarControls ) throw ( uno::RuntimeException ) : Menus_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ), m_xCommandBarControls( xCommandBarControls ) +{ +} + +// XEnumerationAccess +uno::Type SAL_CALL +ScVbaMenus::getElementType() throw ( uno::RuntimeException ) +{ + return excel::XMenu::static_type( 0 ); +} + +uno::Reference< container::XEnumeration > +ScVbaMenus::createEnumeration() throw ( uno::RuntimeException ) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xCommandBarControls, uno::UNO_QUERY_THROW ); + return uno::Reference< container::XEnumeration >( new MenuEnumeration( this, mxContext, xEnumAccess->createEnumeration() ) ); +} + +uno::Any +ScVbaMenus::createCollectionObject( const uno::Any& aSource ) +{ + // make no sense + return aSource; +} + +sal_Int32 SAL_CALL +ScVbaMenus::getCount() throw(css::uno::RuntimeException) +{ + // FIXME: should check if it is a popup menu + return m_xCommandBarControls->getCount(); +} + +// ScVbaCollectionBaseImpl +uno::Any SAL_CALL +ScVbaMenus::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException ) +{ + uno::Reference< XCommandBarControl > xCommandBarControl( m_xCommandBarControls->Item( aIndex, uno::Any() ), uno::UNO_QUERY_THROW ); + if( xCommandBarControl->getType() != office::MsoControlType::msoControlPopup ) + throw uno::RuntimeException(); + return uno::makeAny( uno::Reference< excel::XMenu > ( new ScVbaMenu( this, mxContext, xCommandBarControl ) ) ); +} + +uno::Reference< excel::XMenu > SAL_CALL ScVbaMenus::Add( const rtl::OUString& Caption, const css::uno::Any& Before, const css::uno::Any& Restore ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + sal_Int32 nType = office::MsoControlType::msoControlPopup; + uno::Reference< XCommandBarControl > xCommandBarControl = m_xCommandBarControls->Add( uno::makeAny( nType ), uno::Any(), uno::Any(), Before, Restore ); + xCommandBarControl->setCaption( Caption ); + return uno::Reference< excel::XMenu >( new ScVbaMenu( this, mxContext, xCommandBarControl ) ); +} + +// XHelperInterface +rtl::OUString& +ScVbaMenus::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMenus") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaMenus::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Menus" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbamenus.hxx b/sc/source/ui/vba/vbamenus.hxx new file mode 100644 index 000000000000..a85e73bdb394 --- /dev/null +++ b/sc/source/ui/vba/vbamenus.hxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Initial Developer of the Original Code is + * Novell Inc. + * Portions created by the Initial Developer are Copyright (C) 2010 the + * Initial Developer. All Rights Reserved. + * + * Contributor(s): Pei Feng Lin <pflin@novell.com> + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ +#ifndef SC_VBA_MENUS_HXX +#define SC_VBA_MENUS_HXX + +#include <ooo/vba/excel/XMenus.hpp> +#include <ooo/vba/excel/XMenu.hpp> +#include <ooo/vba/XCommandBarControls.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XMenus > Menus_BASE; + +class ScVbaMenus : public Menus_BASE +{ +private: + css::uno::Reference< ov::XCommandBarControls > m_xCommandBarControls; + +public: + ScVbaMenus( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< ov::XCommandBarControls >& xCommandBarControls ) throw( css::uno::RuntimeException ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // Methods + virtual sal_Int32 SAL_CALL getCount() throw(css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index, const css::uno::Any& /*Index2*/ ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XMenu > SAL_CALL Add( const rtl::OUString& Caption, const css::uno::Any& Before, const css::uno::Any& Restore ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_MENUS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaname.cxx b/sc/source/ui/vba/vbaname.cxx new file mode 100644 index 000000000000..37170f60bb39 --- /dev/null +++ b/sc/source/ui/vba/vbaname.cxx @@ -0,0 +1,234 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> + +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> + +#include "vbaname.hxx" +#include "vbarange.hxx" +#include "vbaglobals.hxx" +#include <vector> +#include <rangenam.hxx> +#include <vcl/msgbox.hxx> +#include "tabvwsh.hxx" +#include "viewdata.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaName::ScVbaName(const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::sheet::XNamedRange >& xName, + const css::uno::Reference< css::sheet::XNamedRanges >& xNames, + const css::uno::Reference< css::frame::XModel >& xModel ): + NameImpl_BASE( xParent , xContext ), + mxModel( xModel ), + mxNamedRange( xName ), + mxNames( xNames ) +{ +} + +ScVbaName::~ScVbaName() +{ +} + +css::uno::Reference< ov::excel::XWorksheet > +ScVbaName::getWorkSheet() throw (css::uno::RuntimeException) +{ + uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + return xApplication->getActiveSheet(); +} + +::rtl::OUString +ScVbaName::getName() throw (css::uno::RuntimeException) +{ + String sName; + //sName += UniString( getWorkSheet()->getName()); //liuchen 2009-9-9 resolve the defect that the name get by macro code are not the same with that in UI (for example, if a name of "AA" is found in the UI "Define Names" dialog box, the result of get that name through macro code will be "Sheet1!AA") + //sName += String::CreateFromAscii("!"); + sName += UniString ( mxNamedRange->getName() ); + return ::rtl::OUString( sName ); +} + +void +ScVbaName::setName( const ::rtl::OUString & rName ) throw (css::uno::RuntimeException) +{ + mxNamedRange->setName( rName ); +} + +::rtl::OUString +ScVbaName::getNameLocal() throw (css::uno::RuntimeException) +{ + return getName(); +} + +void +ScVbaName::setNameLocal( const ::rtl::OUString & rName ) throw (css::uno::RuntimeException) +{ + setName( rName ); +} + +sal_Bool +ScVbaName::getVisible() throw (css::uno::RuntimeException) +{ + return true; +} + +void +ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException) +{ +} + +::rtl::OUString +ScVbaName::getValue() throw (css::uno::RuntimeException) +{ + return getValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); +} + +::rtl::OUString +ScVbaName::getValue(const formula::FormulaGrammar::Grammar eGrammar) throw (css::uno::RuntimeException) +{ + rtl::OUString sValue = mxNamedRange->getContent(); + ScDocShell* pDocShell = excel::getDocShell( mxModel ); + ScDocument* pDoc = pDocShell ? pDocShell->GetDocument() : NULL; + String aContent; + excel::CompileODFFormulaToExcel( pDoc, sValue, aContent, eGrammar ); + if ( aContent.Len() > 0 ) + { + sValue = aContent; + } + if ( sValue.indexOf('=') != 0 ) + { + sValue = rtl::OUString::createFromAscii("=") + sValue; + } + return sValue; +} + +void +ScVbaName::setValue( const ::rtl::OUString & rValue ) throw (css::uno::RuntimeException) +{ + ::rtl::OUString sValue = rValue; + ScDocShell* pDocShell = excel::getDocShell( mxModel ); + ScDocument* pDoc = pDocShell ? pDocShell->GetDocument() : NULL; + String aContent; + excel::CompileExcelFormulaToODF( pDoc, sValue, aContent ); + if ( aContent.Len() > 0 ) + { + sValue = aContent; + } + mxNamedRange->setContent( sValue ); +} + +::rtl::OUString +ScVbaName::getRefersTo() throw (css::uno::RuntimeException) +{ + return getValue(); +} + +void +ScVbaName::setRefersTo( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException) +{ + setValue( rRefersTo ); +} + +::rtl::OUString +ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException) +{ + return getRefersTo(); +} + +void +ScVbaName::setRefersToLocal( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException) +{ + setRefersTo( rRefersTo ); +} + +::rtl::OUString +ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException) +{ + return getValue( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); +} + +void +ScVbaName::setRefersToR1C1( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException) +{ + setRefersTo( rRefersTo ); +} + +::rtl::OUString +ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException) +{ + return getValue( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); +} + +void +ScVbaName::setRefersToR1C1Local( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException) +{ + setRefersTo( rRefersTo ); +} + +css::uno::Reference< ov::excel::XRange > +ScVbaName::getRefersToRange() throw (css::uno::RuntimeException) +{ + uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName( + mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 ); + return xRange; +} + +void +ScVbaName::setRefersToRange( const css::uno::Reference< ov::excel::XRange > /*rRange*/ ) throw (css::uno::RuntimeException) +{ +} + +void +ScVbaName::Delete() throw (css::uno::RuntimeException) +{ + mxNames->removeByName( mxNamedRange->getName() ); +} + +rtl::OUString& +ScVbaName::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaName") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaName::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Name" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaname.hxx b/sc/source/ui/vba/vbaname.hxx new file mode 100644 index 000000000000..4ef4b3a13a39 --- /dev/null +++ b/sc/source/ui/vba/vbaname.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_NAME_HXX +#define SC_VBA_NAME_HXX + +#include <ooo/vba/excel/XName.hpp> +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> + +#include <vbahelper/vbahelperinterface.hxx> + +#include <formula/grammar.hxx> + +class ScDocument; + +typedef InheritedHelperInterfaceImpl1< ov::excel::XName > NameImpl_BASE; + +class ScVbaName : public NameImpl_BASE +{ + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::sheet::XNamedRange > mxNamedRange; + css::uno::Reference< css::sheet::XNamedRanges > mxNames; + + ScDocument * m_pDoc; + +protected: + virtual css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } + virtual css::uno::Reference< ov::excel::XWorksheet > getWorkSheet() throw (css::uno::RuntimeException); + // Get value by FormulaGrammar, such as FormulaGrammar::GRAM_NATIVE_XL_R1C1 + virtual ::rtl::OUString SAL_CALL getValue(const formula::FormulaGrammar::Grammar eGrammar) throw (css::uno::RuntimeException); + +public: + ScVbaName( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XNamedRange >& xName , const css::uno::Reference< css::sheet::XNamedRanges >& xNames , const css::uno::Reference< css::frame::XModel >& xModel ); + virtual ~ScVbaName(); + + // Attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString &rName ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getNameLocal() throw (css::uno::RuntimeException); + virtual void SAL_CALL setNameLocal( const ::rtl::OUString &rName ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool bVisible ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const ::rtl::OUString &rValue ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRefersTo() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRefersTo( const ::rtl::OUString &rRefersTo ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRefersToLocal() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRefersToLocal( const ::rtl::OUString &rRefersTo ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRefersToR1C1() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRefersToR1C1( const ::rtl::OUString &rRefersTo ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRefersToR1C1Local() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRefersToR1C1Local( const ::rtl::OUString &rRefersTo ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getRefersToRange() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRefersToRange( const css::uno::Reference< ov::excel::XRange > xRange ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SC_VBA_NAME_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbanames.cxx b/sc/source/ui/vba/vbanames.cxx new file mode 100644 index 000000000000..bee4fbb58856 --- /dev/null +++ b/sc/source/ui/vba/vbanames.cxx @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> + +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> + +#include "vbanames.hxx" +#include "vbaname.hxx" +#include "vbarange.hxx" +#include "vbaglobals.hxx" +#include <vector> +#include <rangenam.hxx> +#include <vcl/msgbox.hxx> +#include "tabvwsh.hxx" +#include "viewdata.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class NamesEnumeration : public EnumerationHelperImpl +{ + uno::Reference< frame::XModel > m_xModel; + uno::WeakReference< XHelperInterface > m_xParent; + uno::Reference< sheet::XNamedRanges > m_xNames; +public: + NamesEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< frame::XModel >& xModel , const uno::Reference< sheet::XNamedRanges >& xNames ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_xModel( xModel ), m_xParent( xParent ), m_xNames( xNames ) {} + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + uno::Reference< sheet::XNamedRange > xNamed( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< excel::XName > ( new ScVbaName( m_xParent, m_xContext, xNamed ,m_xNames , m_xModel ) ) ); + } + +}; + + +ScVbaNames::ScVbaNames(const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::sheet::XNamedRanges >& xNames, + const css::uno::Reference< css::frame::XModel >& xModel ): + ScVbaNames_BASE( xParent , xContext , uno::Reference< container::XIndexAccess >( xNames, uno::UNO_QUERY ) ), + mxModel( xModel ), + mxNames( xNames ) +{ + m_xNameAccess.set( xNames, uno::UNO_QUERY_THROW ); +} + +ScVbaNames::~ScVbaNames() +{ +} + +ScDocument * +ScVbaNames::getScDocument() +{ + uno::Reference< frame::XModel > xModel( getModel() , uno::UNO_QUERY_THROW ); + ScTabViewShell * pTabViewShell = excel::getBestViewShell( xModel ); + if ( !pTabViewShell ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewShell available"), uno::Reference< uno::XInterface >() ); + ScViewData* pViewData = pTabViewShell->GetViewData(); + if ( !pViewData ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("No ViewData available"), uno::Reference< uno::XInterface >() ); + return pViewData->GetDocument(); +} + +void GetRangeOrRefersTo( const css::uno::Any& RefersTo, const uno::Reference< uno::XComponentContext >& xContext, css::uno::Reference< excel::XRange >& xRange, rtl::OUString& sRefersTo ) +{ + if ( RefersTo.getValueTypeClass() == uno::TypeClass_STRING ) + { + RefersTo >>= sRefersTo; + } + else if ( RefersTo.getValueTypeClass() == uno::TypeClass_INTERFACE ) + { + RefersTo >>= xRange; + } + else if ( RefersTo.hasValue() ) + { + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext ); + try + { + if ( xConverter.is() ) + { + uno::Any aConverted = xConverter->convertTo( RefersTo, getCppuType((rtl::OUString*)0) ); + aConverted >>= sRefersTo; + } + } + catch( uno::Exception& ) + { + } + } +} + +css::uno::Any +ScVbaNames::Add( const css::uno::Any& Name , + const css::uno::Any& RefersTo, + const css::uno::Any& /*Visible*/, + const css::uno::Any& /*MacroType*/, + const css::uno::Any& /*ShoutcutKey*/, + const css::uno::Any& /*Category*/, + const css::uno::Any& NameLocal, + const css::uno::Any& /*RefersToLocal*/, + const css::uno::Any& /*CategoryLocal*/, + const css::uno::Any& RefersToR1C1, + const css::uno::Any& RefersToR1C1Local ) throw (css::uno::RuntimeException) +{ + rtl::OUString sSheetName; + rtl::OUString sName; + rtl::OUString sRefersTo; + uno::Reference< excel::XRange > xRange; + if ( Name.hasValue() ) + Name >>= sName; + else if ( NameLocal.hasValue() ) + NameLocal >>= sName; + if ( sName.getLength() != 0 ) + { + sal_Int32 nTokenIndex = sName.indexOf('!'); + if ( nTokenIndex >= 0 ) + { + sSheetName = sName.copy( 0, nTokenIndex ); + sName = sName.copy( nTokenIndex + 1 ); + } + if ( !ScRangeData::IsNameValid( sName , getScDocument() ) ) + { + ::rtl::OUString sResult ; + sal_Int32 nToken = 0; + sal_Int32 nIndex = 0; + sResult = sName.getToken( nToken , '!' , nIndex ); + if ( -1 == nIndex ) + sResult = sName; + else + sResult = sName.copy( nIndex ); + sName = sResult ; + if ( !ScRangeData::IsNameValid( sName , getScDocument() ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("This Name is a invalid ."), uno::Reference< uno::XInterface >() ); + } + } + if ( RefersTo.hasValue() || RefersToR1C1.hasValue() || RefersToR1C1Local.hasValue() ) + { + if ( RefersTo.hasValue() ) + GetRangeOrRefersTo( RefersTo, mxContext, xRange, sRefersTo ); + if ( RefersToR1C1.hasValue() ) + GetRangeOrRefersTo( RefersToR1C1, mxContext, xRange, sRefersTo ); + if ( RefersToR1C1Local.hasValue() ) + GetRangeOrRefersTo( RefersToR1C1Local, mxContext, xRange, sRefersTo ); + } + + String aContent; + table::CellAddress aPosition; + RangeType nType = RT_NAME; + if ( xRange.is() ) + { + ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() ); + uno::Reference< table::XCellRange > thisRange ; + uno::Any xAny = pRange->getCellRange() ; + if ( xAny.hasValue() ) + xAny >>= thisRange; + uno::Reference< sheet::XCellRangeAddressable > thisRangeAdd( thisRange, ::uno::UNO_QUERY_THROW); + table::CellRangeAddress aAddr = thisRangeAdd->getRangeAddress(); + ScAddress aPos( static_cast< SCCOL >( aAddr.StartColumn ) , static_cast< SCROW >( aAddr.StartRow ) , static_cast< SCTAB >(aAddr.Sheet ) ); + uno::Any xAny2 ; + String sRangeAdd = xRange->Address( xAny2, xAny2 , xAny2 , xAny2, xAny2 ); + aContent += String::CreateFromAscii("$"); + aContent += UniString(xRange->getWorksheet()->getName()); + aContent += String::CreateFromAscii("."); + aContent += sRangeAdd; + aPosition = table::CellAddress( aAddr.Sheet , aAddr.StartColumn , aAddr.StartRow ); + } + else + { + ScDocShell* pDocShell = excel::getDocShell( mxModel ); + ScDocument* pDoc = pDocShell ? pDocShell->GetDocument() : NULL; + excel::CompileExcelFormulaToODF( pDoc, sRefersTo, aContent ); + if ( aContent.Len() == 0 ) + { + aContent = sRefersTo; + } + } + + uno::Reference< sheet::XNamedRange > xNewNamedRange; + if ( mxNames.is() ) + { + if ( mxNames->hasByName( sName ) ) + { + mxNames->removeByName( sName ); + } + mxNames->addNewByName( sName, rtl::OUString( aContent ), aPosition, (sal_Int32) nType ); + xNewNamedRange = uno::Reference< sheet::XNamedRange >( mxNames->getByName( sName ), uno::UNO_QUERY ); + } + if ( xNewNamedRange.is() ) + { + return uno::makeAny( uno::Reference< excel::XName >( new ScVbaName( mxParent, mxContext, xNewNamedRange ,mxNames , mxModel ) ) ); + } + return css::uno::Any(); +} + +// XEnumerationAccess +css::uno::Type +ScVbaNames::getElementType() throw( css::uno::RuntimeException ) +{ + return ov::excel::XName::static_type(0); +} + +uno::Reference< container::XEnumeration > +ScVbaNames::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( mxNames, uno::UNO_QUERY_THROW ); + return new NamesEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel , mxNames ); +} + +uno::Any +ScVbaNames::createCollectionObject( const uno::Any& aSource ) +{ + uno::Reference< sheet::XNamedRange > xName( aSource, uno::UNO_QUERY ); + return uno::makeAny( uno::Reference< excel::XName > ( new ScVbaName( getParent(), mxContext, xName, mxNames , mxModel ) ) ); +} + +rtl::OUString& +ScVbaNames::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaNames") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaNames::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.NamedRanges" ) ); + } + return aServiceNames; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbanames.hxx b/sc/source/ui/vba/vbanames.hxx new file mode 100644 index 000000000000..de9b2d862e56 --- /dev/null +++ b/sc/source/ui/vba/vbanames.hxx @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_NAMES_HXX +#define SC_VBA_NAMES_HXX + +#include <ooo/vba/excel/XNames.hpp> +#include <ooo/vba/XCollection.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <vbahelper/vbacollectionimpl.hxx> + +class ScDocument; +class ScDocShell; + +typedef CollTestImplHelper< ov::excel::XNames > ScVbaNames_BASE; + +class ScVbaNames : public ScVbaNames_BASE +{ + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::sheet::XNamedRanges > mxNames; + +protected: + virtual css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } + +public: + ScVbaNames( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XNamedRanges >& xNames , const css::uno::Reference< css::frame::XModel >& xModel ); + + ScDocument* getScDocument(); + ScDocShell* getScDocShell(); + + virtual ~ScVbaNames(); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // Methods + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& aName , + const css::uno::Any& aRefersTo, + const css::uno::Any& aVisible, + const css::uno::Any& aMacroType, + const css::uno::Any& aShoutcutKey, + const css::uno::Any& aCategory, + const css::uno::Any& aNameLocal, + const css::uno::Any& aRefersToLocal, + const css::uno::Any& aCategoryLocal, + const css::uno::Any& aRefersToR1C1, + const css::uno::Any& aRefersToR1C1Local ) throw (css::uno::RuntimeException); + + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // ScVbaNames_BASE + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; +#endif /* SC_VBA_NAMES_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaoleobject.cxx b/sc/source/ui/vba/vbaoleobject.cxx new file mode 100644 index 000000000000..2d8347bdbd8b --- /dev/null +++ b/sc/source/ui/vba/vbaoleobject.cxx @@ -0,0 +1,167 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/awt/XWindow2.hpp> +#include <com/sun/star/view/XControlAccess.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <ooo/vba/XControlProvider.hpp> + +#include "vbaoleobject.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + + +sal_Int32 pt2mm( double pt ) //1/100mm +{ + return static_cast<sal_Int32>(pt * 0.352778); +} + +double mm2pt( sal_Int32 mm ) +{ + return mm * 2.8345; +} + + +ScVbaOLEObject::ScVbaOLEObject( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, + css::uno::Reference< css::drawing::XControlShape > xControlShape ) +: OLEObjectImpl_BASE( xParent, xContext ), m_xControlShape( xControlShape ) +{ + //init m_xWindowPeer + uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl(), css::uno::UNO_QUERY_THROW ); + uno::Reference< container::XChild > xChild( xControlModel, uno::UNO_QUERY_THROW ); + xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW ); + xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW ); + css::uno::Reference< css::frame::XModel > xModel( xChild->getParent(), uno::UNO_QUERY_THROW ); + uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW ); + m_xControl.set( xControlProvider->createControl( xControlShape, xModel ) ); +} + +uno::Reference< uno::XInterface > SAL_CALL +ScVbaOLEObject::getObject() throw (uno::RuntimeException) +{ + return uno::Reference< uno::XInterface >( m_xControl, uno::UNO_QUERY_THROW ); +} + +sal_Bool SAL_CALL +ScVbaOLEObject::getEnabled() throw (uno::RuntimeException) +{ + return m_xControl->getEnabled(); +} + +void SAL_CALL +ScVbaOLEObject::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) +{ + m_xControl->setEnabled( _enabled ); +} + +sal_Bool SAL_CALL +ScVbaOLEObject::getVisible() throw (uno::RuntimeException) +{ + OSL_TRACE("OleObject %s returning visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), m_xControl->getVisible() ? "true" : "false" ); + return m_xControl->getVisible(); +} + +void SAL_CALL +ScVbaOLEObject::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) +{ + OSL_TRACE("OleObject %s set visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), _visible ? "true" : "false" ); + m_xControl->setVisible( _visible ); +} + +double SAL_CALL +ScVbaOLEObject::getLeft() throw (uno::RuntimeException) +{ + return m_xControl->getLeft(); +} + +void SAL_CALL +ScVbaOLEObject::setLeft( double _left ) throw (uno::RuntimeException) +{ + m_xControl->setLeft( _left ); + +} + +double SAL_CALL +ScVbaOLEObject::getTop() throw (uno::RuntimeException) +{ + return m_xControl->getTop(); +} + +void SAL_CALL +ScVbaOLEObject::setTop( double _top ) throw (uno::RuntimeException) +{ + m_xControl->setTop( _top ); +} + +double SAL_CALL +ScVbaOLEObject::getHeight() throw (uno::RuntimeException) +{ + return m_xControl->getHeight(); +} + +void SAL_CALL +ScVbaOLEObject::setHeight( double _height ) throw (uno::RuntimeException) +{ + m_xControl->setHeight( _height ); +} + +double SAL_CALL +ScVbaOLEObject::getWidth() throw (uno::RuntimeException) +{ + return m_xControl->getWidth(); +} + +void SAL_CALL +ScVbaOLEObject::setWidth( double _width ) throw (uno::RuntimeException) +{ + m_xControl->setWidth( _width ); +} +rtl::OUString& +ScVbaOLEObject::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaOLEObject") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaOLEObject::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.OLEObject" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaoleobject.hxx b/sc/source/ui/vba/vbaoleobject.hxx new file mode 100644 index 000000000000..da0630282506 --- /dev/null +++ b/sc/source/ui/vba/vbaoleobject.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_OLEOBJECT_HXX +#define SC_VBA_OLEOBJECT_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <ooo/vba/excel/XOLEObject.hpp> +#include <ooo/vba/msforms/XControl.hpp> + +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XOLEObject > OLEObjectImpl_BASE; + +class ScVbaOLEObject : public OLEObjectImpl_BASE +{ +protected: + css::uno::Reference< css::drawing::XControlShape > m_xControlShape; + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + css::uno::Reference< ov::msforms::XControl> m_xControl; +public: + ScVbaOLEObject( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::drawing::XControlShape > xControlShape ); + + // XOLEObject Attributes + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getObject() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeft( double _left ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTop( double _top ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( double _height ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( double _width ) throw (css::uno::RuntimeException); + +}; +#endif //SC_VBA_OLEOBJECT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaoleobjects.cxx b/sc/source/ui/vba/vbaoleobjects.cxx new file mode 100644 index 000000000000..bbb88d9b7680 --- /dev/null +++ b/sc/source/ui/vba/vbaoleobjects.cxx @@ -0,0 +1,188 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <ooo/vba/excel/XOLEObject.hpp> + +#include "vbaoleobject.hxx" +#include "vbaoleobjects.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE; + +class IndexAccessWrapper : public XIndexAccess_BASE +{ +typedef std::vector< uno::Reference< drawing::XControlShape > > OLEObjects; + OLEObjects vObjects; +public: + IndexAccessWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) + { + sal_Int32 nLen = xIndexAccess->getCount(); + for ( sal_Int32 index = 0; index < nLen; ++index ) + { + uno::Reference< drawing::XControlShape > xControlShape( xIndexAccess->getByIndex( index), uno::UNO_QUERY); + if ( xControlShape.is() ) + vObjects.push_back( xControlShape ); + } + } + + virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) + { + return vObjects.size(); + } + + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 || Index >= getCount() ) + throw lang::IndexOutOfBoundsException(); + return uno::makeAny( vObjects[ Index ] ); + } + + // Methods XElementAcess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) + { + return drawing::XControlShape::static_type(0); + } + + virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) + { + return ( getCount() > 0 ); + } + +}; + +class EnumWrapper : public EnumerationHelper_BASE +{ + + uno::Reference<XHelperInterface > m_xParent; + uno::Reference<uno::XComponentContext > m_xContext; + uno::Reference<container::XIndexAccess > m_xIndexAccess; + sal_Int32 nIndex; +public: + EnumWrapper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xContext( xContext), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {} + + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + { + uno::Reference< drawing::XControlShape > xControlShape ( m_xIndexAccess->getByIndex( nIndex++ ), uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< ov::excel::XOLEObject >( new ScVbaOLEObject( m_xParent, m_xContext, xControlShape ) ) ); + } + throw container::NoSuchElementException(); + } +}; + +uno::Reference< container::XIndexAccess > oleObjectIndexWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) +{ + return new IndexAccessWrapper( xIndexAccess ); +} + +ScVbaOLEObjects::ScVbaOLEObjects( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) + : OLEObjectsImpl_BASE( xParent, xContext, oleObjectIndexWrapper( xIndexAccess ) ) +{ +} +uno::Reference< container::XEnumeration > +ScVbaOLEObjects::createEnumeration() throw (uno::RuntimeException) +{ + return new EnumWrapper( getParent(), mxContext, m_xIndexAccess ); +} + +uno::Any +ScVbaOLEObjects::createCollectionObject( const css::uno::Any& aSource ) +{ + if( aSource.hasValue() ) + { + uno::Reference< drawing::XControlShape > xControlShape( aSource, uno::UNO_QUERY_THROW ); + // parent of OLEObject is the same parent as the collection ( e.g. the sheet ) + return uno::makeAny( uno::Reference< ov::excel::XOLEObject >( new ScVbaOLEObject( getParent(), mxContext, xControlShape ) ) ); + } + return uno::Any(); +} + +uno::Any +ScVbaOLEObjects::getItemByStringIndex( const rtl::OUString& sIndex ) throw (uno::RuntimeException) +{ + try + { + return OLEObjectsImpl_BASE::getItemByStringIndex( sIndex ); + } + catch( uno::RuntimeException ) + { + uno::Reference< container::XIndexAccess > xIndexAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + sal_Int32 nCount = xIndexAccess->getCount(); + for( int index = 0; index < nCount; index++ ) + { + uno::Any aUnoObj = xIndexAccess->getByIndex( index ); + uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY_THROW ); + uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl() ); + uno::Reference< container::XNamed > xNamed( xControlModel, uno::UNO_QUERY_THROW ); + if( sIndex.equals( xNamed->getName() )) + { + return createCollectionObject( aUnoObj ); + } + + } + return uno::Any(); + } +} + +uno::Type +ScVbaOLEObjects::getElementType() throw (uno::RuntimeException) +{ + return ooo::vba::excel::XOLEObject::static_type(0); +} +rtl::OUString& +ScVbaOLEObjects::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaOLEObjects") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaOLEObjects::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.OLEObjects" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaoleobjects.hxx b/sc/source/ui/vba/vbaoleobjects.hxx new file mode 100644 index 000000000000..7ebbf4956734 --- /dev/null +++ b/sc/source/ui/vba/vbaoleobjects.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_OLEOBJECTS_HXX +#define SC_VBA_OLEOBJECTS_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XOLEObjects.hpp> + +#include <vbahelper/vbacollectionimpl.hxx> +#include "excelvbahelper.hxx" + +typedef CollTestImplHelper< ov::excel::XOLEObjects > OLEObjectsImpl_BASE; + +class ScVbaOLEObjects : public OLEObjectsImpl_BASE +{ +protected: + virtual css::uno::Any getItemByStringIndex( const rtl::OUString& sIndex ) throw (css::uno::RuntimeException); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +public: + ScVbaOLEObjects( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + +}; +#endif //SC_VBA_OLEOBJECTS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaoutline.cxx b/sc/source/ui/vba/vbaoutline.cxx new file mode 100644 index 000000000000..3d00b80ca0a5 --- /dev/null +++ b/sc/source/ui/vba/vbaoutline.cxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaoutline.hxx" +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +void +ScVbaOutline::ShowLevels( const uno::Any& RowLevels, const uno::Any& ColumnLevels ) throw (uno::RuntimeException) +{ + sal_Int16 nLevel = 0; + if (mxOutline.is()) + { + if (RowLevels >>= nLevel) + { + mxOutline->showLevel(nLevel, table::TableOrientation_ROWS); + } + if (ColumnLevels >>= nLevel) + { + mxOutline->showLevel(nLevel,table::TableOrientation_COLUMNS); + } + } +} + +rtl::OUString& +ScVbaOutline::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaOutline") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaOutline::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Outline" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaoutline.hxx b/sc/source/ui/vba/vbaoutline.hxx new file mode 100644 index 000000000000..4cc1c7386779 --- /dev/null +++ b/sc/source/ui/vba/vbaoutline.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_OUTLINE_HXX +#define SC_VBA_OUTLINE_HXX + +#include <com/sun/star/sheet/XSheetOutline.hpp> +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XOutline.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XOutline > ScVbaOutline_BASE; + +class ScVbaOutline : public ScVbaOutline_BASE +{ + css::uno::Reference< css::sheet::XSheetOutline > mxOutline; +public: + ScVbaOutline( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference<css::sheet::XSheetOutline> outline): ScVbaOutline_BASE( xParent, xContext) , mxOutline(outline) + {} + virtual ~ScVbaOutline(){} + + virtual void SAL_CALL ShowLevels( const css::uno::Any& RowLevels, const css::uno::Any& ColumnLevels ) throw (css::uno::RuntimeException) ; + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapagebreak.cxx b/sc/source/ui/vba/vbapagebreak.cxx new file mode 100644 index 000000000000..813a5954d6e1 --- /dev/null +++ b/sc/source/ui/vba/vbapagebreak.cxx @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapagebreak.hxx" +#include "vbarange.hxx" +#include <ooo/vba/excel/XlPageBreak.hpp> +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +template< typename Ifc1 > +ScVbaPageBreak<Ifc1>::ScVbaPageBreak( const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + uno::Reference< beans::XPropertySet >& xProps, + sheet::TablePageBreakData aTablePageBreakData) throw (uno::RuntimeException): + ScVbaPageBreak_BASE( xParent, xContext ), + mxRowColPropertySet( xProps ), + maTablePageBreakData( aTablePageBreakData ) +{ +} + +template< typename Ifc1 > +sal_Int32 ScVbaPageBreak<Ifc1>::getType() throw (uno::RuntimeException) +{ + uno::Any aValue = mxRowColPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" ))); + sal_Bool hasPageBreak = sal_False; + aValue >>= hasPageBreak; + + if( !hasPageBreak ) + return excel::XlPageBreak::xlPageBreakNone; + + if( maTablePageBreakData.ManualBreak ) + return excel::XlPageBreak::xlPageBreakManual; + + return excel::XlPageBreak::xlPageBreakAutomatic; +} + +template< typename Ifc1 > +void ScVbaPageBreak<Ifc1>::setType(sal_Int32 type) throw (uno::RuntimeException) +{ + if( (type != excel::XlPageBreak::xlPageBreakNone) && + (type != excel::XlPageBreak::xlPageBreakManual) && + (type != excel::XlPageBreak::xlPageBreakAutomatic) ) + { + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + + if( type == excel::XlPageBreak::xlPageBreakNone ) + { + mxRowColPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" )), uno::makeAny(sal_False)); + return; + } + + mxRowColPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" )), uno::makeAny(sal_True)); + if( type == excel::XlPageBreak::xlPageBreakManual ) + maTablePageBreakData.ManualBreak = sal_True; + else + maTablePageBreakData.ManualBreak = sal_False; +} + +template< typename Ifc1 > +void ScVbaPageBreak<Ifc1>::Delete() throw ( script::BasicErrorException, uno::RuntimeException) +{ + mxRowColPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" )), uno::makeAny(sal_False)); +} + +template< typename Ifc1 > +uno::Reference< excel::XRange> ScVbaPageBreak<Ifc1>::Location() throw ( script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< table::XCellRange > xRange( mxRowColPropertySet, uno::UNO_QUERY_THROW ); + return new ScVbaRange( ScVbaPageBreak_BASE::getParent(), ScVbaPageBreak_BASE::mxContext, xRange); +} + +template< typename Ifc1 > +rtl::OUString& +ScVbaPageBreak<Ifc1>::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPageBreak") ); + return sImplName; +} + +template< typename Ifc1 > +uno::Sequence< rtl::OUString > +ScVbaPageBreak<Ifc1>::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PageBreak" ) ); + } + return aServiceNames; +} + +template class ScVbaPageBreak< excel::XHPageBreak >; + +/* class ScVbaHPageBreak */ +rtl::OUString& +ScVbaHPageBreak::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaHPageBreak") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaHPageBreak::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.HPageBreak" ) ); + } + return aServiceNames; +} + +template class ScVbaPageBreak< excel::XVPageBreak >; + +/* class ScVbaVPageBreak */ +ScVbaVPageBreak::ScVbaVPageBreak( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::beans::XPropertySet >& xProps, + css::sheet::TablePageBreakData aTablePageBreakData ) throw ( css::uno::RuntimeException ) +: ScVbaVPageBreak_BASE( xParent, xContext, xProps, aTablePageBreakData ) +{ +} + +ScVbaVPageBreak::~ScVbaVPageBreak() +{ +} + +rtl::OUString& +ScVbaVPageBreak::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaVPageBreak") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaVPageBreak::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.VPageBreak" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapagebreak.hxx b/sc/source/ui/vba/vbapagebreak.hxx new file mode 100644 index 000000000000..c0579787a4c6 --- /dev/null +++ b/sc/source/ui/vba/vbapagebreak.hxx @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PAGEBREAK_HXX +#define SC_VBA_PAGEBREAK_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XPageBreak.hpp> +#include <ooo/vba/excel/XHPageBreak.hpp> +#include <ooo/vba/excel/XVPageBreak.hpp> +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/script/BasicErrorException.hpp> +#include <com/sun/star/sheet/TablePageBreakData.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +template< typename Ifc1 > +class ScVbaPageBreak : public InheritedHelperInterfaceImpl1< Ifc1 > +{ +typedef InheritedHelperInterfaceImpl1< Ifc1 > ScVbaPageBreak_BASE; +protected: + css::uno::Reference< css::beans::XPropertySet > mxRowColPropertySet; + css::sheet::TablePageBreakData maTablePageBreakData; +public: + ScVbaPageBreak( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::beans::XPropertySet >& xProps, + css::sheet::TablePageBreakData aTablePageBreakData) throw (css::uno::RuntimeException); + virtual ~ScVbaPageBreak(){} + + virtual sal_Int32 SAL_CALL getType( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL setType(sal_Int32 type) throw (css::uno::RuntimeException); + + virtual void SAL_CALL Delete() throw ( css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange> SAL_CALL Location() throw ( css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + + +typedef ScVbaPageBreak < ov::excel::XHPageBreak > ScVbaHPageBreak_BASE; + +class ScVbaHPageBreak : public ScVbaHPageBreak_BASE +{ +public: + ScVbaHPageBreak( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::beans::XPropertySet >& xProps, + css::sheet::TablePageBreakData aTablePageBreakData) throw (css::uno::RuntimeException): + ScVbaHPageBreak_BASE( xParent,xContext,xProps,aTablePageBreakData ){} + + virtual ~ScVbaHPageBreak(){} + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +//VPageBreak +typedef ScVbaPageBreak < ov::excel::XVPageBreak > ScVbaVPageBreak_BASE; + +class ScVbaVPageBreak : public ScVbaVPageBreak_BASE +{ +public: + ScVbaVPageBreak( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::beans::XPropertySet >& xProps, + css::sheet::TablePageBreakData aTablePageBreakData) throw (css::uno::RuntimeException); + + virtual ~ScVbaVPageBreak(); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapagebreaks.cxx b/sc/source/ui/vba/vbapagebreaks.cxx new file mode 100644 index 000000000000..e6c83ed618c7 --- /dev/null +++ b/sc/source/ui/vba/vbapagebreaks.cxx @@ -0,0 +1,321 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapagebreaks.hxx" +#include "vbapagebreak.hxx" +#include <ooo/vba/excel/XWorksheet.hpp> +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +typedef ::cppu::WeakImplHelper1<container::XIndexAccess > RangePageBreaks_Base; +class RangePageBreaks : public RangePageBreaks_Base +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< sheet::XSheetPageBreak > mxSheetPageBreak; + sal_Bool m_bColumn; + +public: + RangePageBreaks( const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + uno::Reference< sheet::XSheetPageBreak >& xSheetPageBreak, + sal_Bool bColumn ) : mxParent( xParent ), mxContext( xContext ), mxSheetPageBreak( xSheetPageBreak ), m_bColumn( bColumn ) + { + } + + sal_Int32 getAPIStartofRange( const uno::Reference< excel::XRange >& xRange ) throw (css::uno::RuntimeException) + { + if( m_bColumn ) + return xRange->getColumn() - 1; + return xRange->getRow() - 1; + } + + sal_Int32 getAPIEndIndexofRange( const uno::Reference< excel::XRange >& xRange, sal_Int32 nUsedStart ) throw (uno::RuntimeException) + { + if( m_bColumn ) + return nUsedStart + xRange->Columns( uno::Any() )->getCount(); + return nUsedStart + xRange->Rows( uno::Any() )->getCount(); + } + + uno::Sequence<sheet::TablePageBreakData> getAllPageBreaks() throw (uno::RuntimeException) + { + if( m_bColumn ) + return mxSheetPageBreak->getColumnPageBreaks(); + return mxSheetPageBreak->getRowPageBreaks(); + } + + uno::Reference<container::XIndexAccess> getRowColContainer() throw (uno::RuntimeException) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange( mxSheetPageBreak, uno::UNO_QUERY_THROW ); + uno::Reference<container::XIndexAccess> xIndexAccess; + if( m_bColumn ) + xIndexAccess.set( xColumnRowRange->getColumns(), uno::UNO_QUERY_THROW ); + else + xIndexAccess.set( xColumnRowRange->getRows(), uno::UNO_QUERY_THROW ); + return xIndexAccess; + } + + sheet::TablePageBreakData getTablePageBreakData( sal_Int32 nAPIItemIndex ) throw ( script::BasicErrorException, uno::RuntimeException); + uno::Any Add( const css::uno::Any& Before ) throw ( css::script::BasicErrorException, css::uno::RuntimeException); + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException); + virtual uno::Any SAL_CALL getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException); + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + if( m_bColumn ) + return excel::XVPageBreak::static_type(0); + return excel::XHPageBreak::static_type(0); + } + virtual sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return sal_True; + } +}; + +/** @TODO Unlike MS Excel this method only considers the pagebreaks that intersect the used range +* To become completely compatible the print area has to be considered. As far as I found out this printarea +* also considers the position and sizes of shapes and manually inserted page breaks +* Note: In MS there is a limit of 1026 horizontal page breaks per sheet. +*/ +sal_Int32 SAL_CALL RangePageBreaks::getCount( ) throw (uno::RuntimeException) +{ + sal_Int32 nCount = 0; + uno::Reference< excel::XWorksheet > xWorksheet( mxParent, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XRange > xRange = xWorksheet->getUsedRange(); + sal_Int32 nUsedStart = getAPIStartofRange( xRange ); + sal_Int32 nUsedEnd = getAPIEndIndexofRange( xRange, nUsedStart ); + uno::Sequence<sheet::TablePageBreakData> aTablePageBreakData = getAllPageBreaks(); + + sal_Int32 nLength = aTablePageBreakData.getLength(); + for( sal_Int32 i=0; i<nLength; i++ ) + { + sal_Int32 nPos = aTablePageBreakData[i].Position; + + // VBA. minz@cn.ibm.com. All page breaks before the used range should be counted. + // And the page break at the end of the used range also should be counted. + if( nPos <= nUsedEnd + 1 ) + nCount++; + else + return nCount; + } + + return nCount; +} + +uno::Any SAL_CALL RangePageBreaks::getByIndex( sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( (Index < getCount()) && ( Index >= 0 )) + { + sheet::TablePageBreakData aTablePageBreakData = getTablePageBreakData( Index ); + uno::Reference< container::XIndexAccess > xIndexAccess = getRowColContainer(); + sal_Int32 nPos = aTablePageBreakData.Position; + if( (nPos < xIndexAccess->getCount()) && (nPos > -1) ) + { + uno::Reference< beans::XPropertySet > xRowColPropertySet( xIndexAccess->getByIndex(nPos), uno::UNO_QUERY_THROW ); + if( m_bColumn ) + return uno::makeAny( uno::Reference< excel::XVPageBreak >( new ScVbaVPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) )); + return uno::makeAny( uno::Reference< excel::XHPageBreak >( new ScVbaHPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) )); + } + } + throw lang::IndexOutOfBoundsException(); +} + +sheet::TablePageBreakData RangePageBreaks::getTablePageBreakData( sal_Int32 nAPIItemIndex ) throw ( script::BasicErrorException, uno::RuntimeException) +{ + sheet::TablePageBreakData aTablePageBreakData; + uno::Reference< excel::XWorksheet > xWorksheet( mxParent, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XRange > xRange = xWorksheet->getUsedRange(); + uno::Sequence<sheet::TablePageBreakData> aTablePageBreakDataList = getAllPageBreaks(); + + sal_Int32 nLength = aTablePageBreakDataList.getLength(); + //VBA. minz@cn.ibm.com. No need to filter the page break. All page breaks before the used range are counted. + if ( nAPIItemIndex < nLength && nAPIItemIndex>=0 ) + aTablePageBreakData = aTablePageBreakDataList[nAPIItemIndex]; + + return aTablePageBreakData; +} + +uno::Any RangePageBreaks::Add( const css::uno::Any& Before ) throw ( css::script::BasicErrorException, css::uno::RuntimeException) +{ + uno::Reference< excel::XRange > xRange; + Before >>= xRange; + if( !xRange.is() ) + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); + } + + sal_Int32 nAPIRowColIndex = getAPIStartofRange( xRange ); + uno::Reference< container::XIndexAccess > xIndexAccess = getRowColContainer(); + uno::Reference< beans::XPropertySet > xRowColPropertySet( xIndexAccess->getByIndex(nAPIRowColIndex), uno::UNO_QUERY_THROW ); + xRowColPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsStartOfNewPage" )), uno::makeAny(sal_True)); + sheet::TablePageBreakData aTablePageBreakData; + aTablePageBreakData.ManualBreak = sal_True; + aTablePageBreakData.Position = nAPIRowColIndex; + if( m_bColumn ) + return uno::makeAny( uno::Reference< excel::XVPageBreak >( new ScVbaVPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) )); + return uno::makeAny( uno::Reference< excel::XHPageBreak >( new ScVbaHPageBreak( mxParent, mxContext, xRowColPropertySet, aTablePageBreakData) )); +} + + +class RangePageBreaksEnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference<container::XIndexAccess > m_xIndexAccess; + sal_Int32 nIndex; +public: + RangePageBreaksEnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + return m_xIndexAccess->getByIndex( nIndex++ ); + throw container::NoSuchElementException(); + } +}; + +ScVbaHPageBreaks::ScVbaHPageBreaks( const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + uno::Reference< sheet::XSheetPageBreak >& xSheetPageBreak) throw (uno::RuntimeException): + ScVbaHPageBreaks_BASE( xParent,xContext, new RangePageBreaks( xParent, xContext, xSheetPageBreak, sal_False )), + mxSheetPageBreak( xSheetPageBreak ) +{ +} + +uno::Any SAL_CALL ScVbaHPageBreaks::Add( const uno::Any& Before) throw ( script::BasicErrorException, uno::RuntimeException) +{ + RangePageBreaks* pPageBreaks = dynamic_cast< RangePageBreaks* >( m_xIndexAccess.get() ); + if( pPageBreaks ) + { + return pPageBreaks->Add( Before ); + } + return uno::Any(); +} + +uno::Reference< container::XEnumeration > +ScVbaHPageBreaks::createEnumeration() throw (uno::RuntimeException) +{ + return new RangePageBreaksEnumWrapper( m_xIndexAccess ); +} + +uno::Any +ScVbaHPageBreaks::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; // its already a pagebreak object +} + +uno::Type +ScVbaHPageBreaks::getElementType() throw (uno::RuntimeException) +{ + return excel::XHPageBreak::static_type(0); +} + +rtl::OUString& +ScVbaHPageBreaks::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaHPageBreaks") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaHPageBreaks::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.HPageBreaks" ) ); + } + return aServiceNames; +} + +//VPageBreak +ScVbaVPageBreaks::ScVbaVPageBreaks( const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + uno::Reference< sheet::XSheetPageBreak >& xSheetPageBreak ) throw ( uno::RuntimeException ) +: ScVbaVPageBreaks_BASE( xParent, xContext, new RangePageBreaks( xParent, xContext, xSheetPageBreak, sal_True ) ), + mxSheetPageBreak( xSheetPageBreak ) +{ +} + +ScVbaVPageBreaks::~ScVbaVPageBreaks() +{ +} + +uno::Any SAL_CALL +ScVbaVPageBreaks::Add( const uno::Any& Before ) throw ( script::BasicErrorException, uno::RuntimeException ) +{ + RangePageBreaks* pPageBreaks = dynamic_cast< RangePageBreaks* >( m_xIndexAccess.get() ); + if( pPageBreaks ) + { + return pPageBreaks->Add( Before ); + } + return uno::Any(); +} + +uno::Reference< container::XEnumeration > +ScVbaVPageBreaks::createEnumeration() throw ( uno::RuntimeException ) +{ + return new RangePageBreaksEnumWrapper( m_xIndexAccess ); +} + +uno::Any +ScVbaVPageBreaks::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; // its already a pagebreak object +} + +uno::Type +ScVbaVPageBreaks::getElementType() throw ( uno::RuntimeException ) +{ + return excel::XVPageBreak::static_type( 0 ); +} + +rtl::OUString& +ScVbaVPageBreaks::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM( "ScVbaVPageBreaks" ) ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaVPageBreaks::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.VPageBreaks" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapagebreaks.hxx b/sc/source/ui/vba/vbapagebreaks.hxx new file mode 100644 index 000000000000..0230b2be0b58 --- /dev/null +++ b/sc/source/ui/vba/vbapagebreaks.hxx @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PAGEBREAKS_HXX +#define SC_VBA_PAGEBREAKS_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XHPageBreaks.hpp> +#include <ooo/vba/excel/XHPageBreak.hpp> +#include <ooo/vba/excel/XVPageBreaks.hpp> +#include <ooo/vba/excel/XVPageBreak.hpp> +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/script/BasicErrorException.hpp> +#include <com/sun/star/sheet/XSheetPageBreak.hpp> +#include <com/sun/star/sheet/TablePageBreakData.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XHPageBreaks > ScVbaHPageBreaks_BASE; + +class ScVbaHPageBreaks : public ScVbaHPageBreaks_BASE +{ + css::uno::Reference< css::sheet::XSheetPageBreak > mxSheetPageBreak; +public: + ScVbaHPageBreaks( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::sheet::XSheetPageBreak >& xSheetPageBreak) throw (css::uno::RuntimeException); + virtual ~ScVbaHPageBreaks(){} + + // XHPageBreaks + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Before) throw ( css::script::BasicErrorException, css::uno::RuntimeException); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject(const css::uno::Any&); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +//VPageBreaks +typedef CollTestImplHelper< ov::excel::XVPageBreaks > ScVbaVPageBreaks_BASE; + +class ScVbaVPageBreaks : public ScVbaVPageBreaks_BASE +{ + css::uno::Reference< css::sheet::XSheetPageBreak > mxSheetPageBreak; + +public: + ScVbaVPageBreaks( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::sheet::XSheetPageBreak >& xSheetPageBreak ) throw ( css::uno::RuntimeException ); + + virtual ~ScVbaVPageBreaks(); + + // XVPageBreaks + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Before ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw ( css::uno::RuntimeException ); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw ( css::uno::RuntimeException ); + virtual css::uno::Any createCollectionObject( const css::uno::Any& ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapagesetup.cxx b/sc/source/ui/vba/vbapagesetup.cxx new file mode 100644 index 000000000000..c80e407fb532 --- /dev/null +++ b/sc/source/ui/vba/vbapagesetup.cxx @@ -0,0 +1,734 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapagesetup.hxx" +#include "cellsuno.hxx" +#include "convuno.hxx" +#include "rangelst.hxx" +#include "excelvbahelper.hxx" +#include <com/sun/star/sheet/XPrintAreas.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <ooo/vba/excel/XlPageOrientation.hpp> +#include <ooo/vba/excel/XlOrder.hpp> +#include <ooo/vba/excel/Constants.hpp> +#include <i18npool/paper.hxx> +#include <editeng/paperinf.hxx> +#include <ooo/vba/excel/XlPaperSize.hpp> +#include <sal/macros.h> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +#define ZOOM_IN 10 +#define ZOOM_MAX 400 + +bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException ); + +ScVbaPageSetup::ScVbaPageSetup(const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< sheet::XSpreadsheet >& xSheet, + const uno::Reference< frame::XModel >& xModel) throw (uno::RuntimeException): + ScVbaPageSetup_BASE( xParent, xContext ), mxSheet( xSheet ) +{ + // query for current page style + mxModel.set( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xSheetProps( mxSheet, uno::UNO_QUERY_THROW ); + uno::Any aValue = xSheetProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageStyle" ))); + rtl::OUString aStyleName; + aValue >>= aStyleName; + + uno::Reference< style::XStyleFamiliesSupplier > xStyleFamiliesSup( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xStyleFamilies = xStyleFamiliesSup->getStyleFamilies(); + uno::Reference< container::XNameAccess > xPageStyle( xStyleFamilies->getByName(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageStyles"))), uno::UNO_QUERY_THROW ); + mxPageProps.set( xPageStyle->getByName(aStyleName), uno::UNO_QUERY_THROW ); + mnOrientLandscape = excel::XlPageOrientation::xlLandscape; + mnOrientPortrait = excel::XlPageOrientation::xlPortrait; +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getPrintArea() throw (css::uno::RuntimeException) +{ + String aPrintArea; + uno::Reference< sheet::XPrintAreas > xPrintAreas( mxSheet, uno::UNO_QUERY_THROW ); + uno::Sequence< table::CellRangeAddress > aSeq = xPrintAreas->getPrintAreas(); + sal_Int32 nCount = aSeq.getLength(); + if( nCount ) + { + ScAddress::Details aDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 ); + USHORT nFlags = SCA_VALID; + nFlags |= ( SCA_TAB_ABSOLUTE | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE ); + ScRangeList aRangeList; + for( sal_Int32 i=0; i<nCount; i++ ) + { + ScRange aRange; + ScUnoConversion::FillScRange( aRange, aSeq[i] ); + aRangeList.Append( aRange ); + } + ScDocument* pDoc = excel::getDocShell( mxModel )->GetDocument(); + aRangeList.Format( aPrintArea, nFlags, pDoc, formula::FormulaGrammar::CONV_XL_A1, ',' ); + } + + return aPrintArea; +} + +void SAL_CALL ScVbaPageSetup::setPrintArea( const rtl::OUString& rAreas ) throw (css::uno::RuntimeException) +{ + uno::Reference< sheet::XPrintAreas > xPrintAreas( mxSheet, uno::UNO_QUERY_THROW ); + if( rAreas.getLength() == 0 || + rAreas.equalsIgnoreAsciiCase ( rtl::OUString::createFromAscii("FALSE") ) ) + { + // print the whole sheet + uno::Sequence< table::CellRangeAddress > aSeq; + xPrintAreas->setPrintAreas( aSeq ); + } + else + { + ScRangeList aCellRanges; + ScRange aRange; + if( getScRangeListForAddress( rAreas, excel::getDocShell( mxModel ) , aRange, aCellRanges ) ) + { + uno::Sequence< table::CellRangeAddress > aSeq( aCellRanges.Count() ); + USHORT i=0; + for( ScRange* pRange = aCellRanges.First(); pRange; pRange = aCellRanges.Next() ) + { + table::CellRangeAddress aRangeAddress; + ScUnoConversion::FillApiRange( aRangeAddress, *pRange ); + aSeq[ i++ ] = aRangeAddress; + } + xPrintAreas->setPrintAreas( aSeq ); + } + } +} + +double SAL_CALL ScVbaPageSetup::getHeaderMargin() throw (css::uno::RuntimeException) +{ + return VbaPageSetupBase::getHeaderMargin(); +} + +void SAL_CALL ScVbaPageSetup::setHeaderMargin( double margin ) throw (css::uno::RuntimeException) +{ + VbaPageSetupBase::setHeaderMargin( margin ); +} + +double SAL_CALL ScVbaPageSetup::getFooterMargin() throw (css::uno::RuntimeException) +{ + return VbaPageSetupBase::getFooterMargin(); +} + +void SAL_CALL ScVbaPageSetup::setFooterMargin( double margin ) throw (css::uno::RuntimeException) +{ + VbaPageSetupBase::setFooterMargin( margin ); +} + +uno::Any SAL_CALL ScVbaPageSetup::getFitToPagesTall() throw (css::uno::RuntimeException) +{ + return mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesY"))); +} + +void SAL_CALL ScVbaPageSetup::setFitToPagesTall( const uno::Any& fitToPagesTall) throw (css::uno::RuntimeException) +{ + USHORT scaleToPageY = 0; + try + { + sal_Bool aValue; + if( fitToPagesTall.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesTall >>= aValue)) + { + fitToPagesTall >>= scaleToPageY; + } + + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesY")), uno::makeAny( scaleToPageY )); + } + catch( uno::Exception& ) + { + } +} + +uno::Any SAL_CALL ScVbaPageSetup::getFitToPagesWide() throw (css::uno::RuntimeException) +{ + return mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesX"))); +} + +void SAL_CALL ScVbaPageSetup::setFitToPagesWide( const uno::Any& fitToPagesWide) throw (css::uno::RuntimeException) +{ + USHORT scaleToPageX = 0; + try + { + sal_Bool aValue = sal_False; + if( fitToPagesWide.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesWide >>= aValue)) + { + fitToPagesWide >>= scaleToPageX; + } + + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesX")), uno::makeAny( scaleToPageX )); + } + catch( uno::Exception& ) + { + } +} + +uno::Any SAL_CALL ScVbaPageSetup::getZoom() throw (css::uno::RuntimeException) +{ + return mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageScale"))); +} + +void SAL_CALL ScVbaPageSetup::setZoom( const uno::Any& zoom) throw (css::uno::RuntimeException) +{ + USHORT pageScale = 0; + try + { + if( zoom.getValueTypeClass() == uno::TypeClass_BOOLEAN ) + { + sal_Bool aValue = sal_False; + zoom >>= aValue; + if( aValue ) + { + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + } + else + { + zoom >>= pageScale; + if(( pageScale < ZOOM_IN )||( pageScale > ZOOM_MAX )) + { + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + } + + // these only exist in S08 + USHORT nScale = 0; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPages")), uno::makeAny( nScale )); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesX")), uno::makeAny( nScale )); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScaleToPagesY")), uno::makeAny( nScale )); + } + catch( beans::UnknownPropertyException& ) + { + if( pageScale == 0 ) + { + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + } + catch( uno::Exception& ) + { + } + + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageScale")), uno::makeAny( pageScale )); +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getLeftHeader() throw (css::uno::RuntimeException) +{ + rtl::OUString leftHeader; + try + { + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW); + if( xHeaderContent.is() ) + { + uno::Reference< text::XText > xText = xHeaderContent->getLeftText(); + leftHeader = xText->getString(); + } + } + catch( uno::Exception& ) + { + } + + return leftHeader; +} + +void SAL_CALL ScVbaPageSetup::setLeftHeader( const rtl::OUString& leftHeader) throw (css::uno::RuntimeException) +{ + try + { + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW); + if( xHeaderContent.is() ) + { + uno::Reference< text::XText > xText = xHeaderContent->getLeftText(); + xText->setString( leftHeader ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent")), uno::makeAny(xHeaderContent) ); + } + } + catch( uno::Exception& ) + { + } +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getCenterHeader() throw (css::uno::RuntimeException) +{ + rtl::OUString centerHeader; + try + { + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW); + if( xHeaderContent.is() ) + { + uno::Reference< text::XText > xText = xHeaderContent->getCenterText(); + centerHeader = xText->getString(); + } + } + catch( uno::Exception& ) + { + } + + return centerHeader; +} + +void SAL_CALL ScVbaPageSetup::setCenterHeader( const rtl::OUString& centerHeader) throw (css::uno::RuntimeException) +{ + try + { + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW); + if( xHeaderContent.is() ) + { + uno::Reference< text::XText > xText = xHeaderContent->getCenterText(); + xText->setString( centerHeader ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent")), uno::makeAny(xHeaderContent) ); + } + } + catch( uno::Exception& ) + { + } +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getRightHeader() throw (css::uno::RuntimeException) +{ + rtl::OUString rightHeader; + try + { + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW); + if( xHeaderContent.is() ) + { + uno::Reference< text::XText > xText = xHeaderContent->getRightText(); + rightHeader = xText->getString(); + } + } + catch( uno::Exception& ) + { + } + + return rightHeader; +} + +void SAL_CALL ScVbaPageSetup::setRightHeader( const rtl::OUString& rightHeader) throw (css::uno::RuntimeException) +{ + try + { + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent"))), uno::UNO_QUERY_THROW); + if( xHeaderContent.is() ) + { + uno::Reference< text::XText > xText = xHeaderContent->getRightText(); + xText->setString( rightHeader ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageHeaderContent")), uno::makeAny(xHeaderContent) ); + } + } + catch( uno::Exception& ) + { + } +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getLeftFooter() throw (css::uno::RuntimeException) +{ + rtl::OUString leftFooter; + try + { + uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW); + if( xFooterContent.is() ) + { + uno::Reference< text::XText > xText = xFooterContent->getLeftText(); + leftFooter = xText->getString(); + } + } + catch( uno::Exception& ) + { + } + + return leftFooter; +} + +void SAL_CALL ScVbaPageSetup::setLeftFooter( const rtl::OUString& leftFooter) throw (css::uno::RuntimeException) +{ + try + { + uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW); + if( xFooterContent.is() ) + { + uno::Reference< text::XText > xText = xFooterContent->getLeftText(); + xText->setString( leftFooter ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent")), uno::makeAny(xFooterContent) ); + } + } + catch( uno::Exception& ) + { + } +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getCenterFooter() throw (css::uno::RuntimeException) +{ + rtl::OUString centerFooter; + try + { + uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW); + if( xFooterContent.is() ) + { + uno::Reference< text::XText > xText = xFooterContent->getCenterText(); + centerFooter = xText->getString(); + } + } + catch( uno::Exception& ) + { + } + + return centerFooter; +} + +void SAL_CALL ScVbaPageSetup::setCenterFooter( const rtl::OUString& centerFooter) throw (css::uno::RuntimeException) +{ + try + { + uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW); + if( xFooterContent.is() ) + { + uno::Reference< text::XText > xText = xFooterContent->getCenterText(); + xText->setString( centerFooter ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent")), uno::makeAny(xFooterContent) ); + } + } + catch( uno::Exception& ) + { + } + +} + +rtl::OUString SAL_CALL ScVbaPageSetup::getRightFooter() throw (css::uno::RuntimeException) +{ + rtl::OUString rightFooter; + try + { + uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW); + if( xFooterContent.is() ) + { + uno::Reference< text::XText > xText = xFooterContent->getRightText(); + rightFooter = xText->getString(); + } + } + catch( uno::Exception& ) + { + } + + return rightFooter; +} + +void SAL_CALL ScVbaPageSetup::setRightFooter( const rtl::OUString& rightFooter) throw (css::uno::RuntimeException) +{ + try + { + uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent"))), uno::UNO_QUERY_THROW); + if( xFooterContent.is() ) + { + uno::Reference< text::XText > xText = xFooterContent->getRightText(); + xText->setString( rightFooter ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightPageFooterContent")), uno::makeAny(xFooterContent) ); + } + } + catch( uno::Exception& ) + { + } +} + +sal_Int32 SAL_CALL ScVbaPageSetup::getOrder() throw (css::uno::RuntimeException) +{ + sal_Int32 order = excel::XlOrder::xlDownThenOver; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintDownFirst"))); + sal_Bool bPrintDownFirst = sal_False; + aValue >>= bPrintDownFirst; + if( !bPrintDownFirst ) + order = excel::XlOrder::xlOverThenDown; + } + catch( uno::Exception& ) + { + } + + return order; +} + +void SAL_CALL ScVbaPageSetup::setOrder( sal_Int32 order) throw (css::uno::RuntimeException) +{ + sal_Bool bOrder = sal_True; + switch( order ) + { + case excel::XlOrder::xlDownThenOver: + break; + case excel::XlOrder::xlOverThenDown: + bOrder = sal_False; + break; + default: + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + + try + { + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintDownFirst")), uno::makeAny( bOrder )); + } + catch( uno::Exception& ) + { + } +} + +sal_Int32 SAL_CALL ScVbaPageSetup::getFirstPageNumber() throw (css::uno::RuntimeException) +{ + sal_Int16 number = 0; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstPageNumber"))); + aValue >>= number; + } + catch( uno::Exception& ) + { + } + + if( number ==0 ) + { + number = excel::Constants::xlAutomatic; + } + + return number; +} + +void SAL_CALL ScVbaPageSetup::setFirstPageNumber( sal_Int32 firstPageNumber) throw (css::uno::RuntimeException) +{ + if( firstPageNumber < 0 ) + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + if( firstPageNumber == excel::Constants::xlAutomatic ) + firstPageNumber = 0; + + try + { + uno::Any aValue; + aValue <<= (sal_Int16)firstPageNumber; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FirstPageNumber")), aValue ); + } + catch( uno::Exception& ) + { + } +} + +sal_Bool SAL_CALL ScVbaPageSetup::getCenterVertically() throw (css::uno::RuntimeException) +{ + sal_Bool centerVertically = sal_False; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterVertically"))); + aValue >>= centerVertically; + } + catch( uno::Exception& ) + { + } + return centerVertically; +} + +void SAL_CALL ScVbaPageSetup::setCenterVertically( sal_Bool centerVertically) throw (css::uno::RuntimeException) +{ + try + { + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterVertically")), uno::makeAny( centerVertically )); + } + catch( uno::Exception& ) + { + } +} + +sal_Bool SAL_CALL ScVbaPageSetup::getCenterHorizontally() throw (css::uno::RuntimeException) +{ + sal_Bool centerHorizontally = sal_False; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterHorizontally"))); + aValue >>= centerHorizontally; + } + catch( uno::Exception& ) + { + } + return centerHorizontally; +} + +void SAL_CALL ScVbaPageSetup::setCenterHorizontally( sal_Bool centerHorizontally) throw (css::uno::RuntimeException) +{ + try + { + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CenterHorizontally")), uno::makeAny( centerHorizontally )); + } + catch( uno::Exception& ) + { + } +} + +sal_Bool SAL_CALL ScVbaPageSetup::getPrintHeadings() throw (css::uno::RuntimeException) +{ + sal_Bool printHeadings = sal_False; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintHeaders"))); + aValue >>= printHeadings; + } + catch( uno::Exception& ) + { + } + return printHeadings; +} + +void SAL_CALL ScVbaPageSetup::setPrintHeadings( sal_Bool printHeadings) throw (css::uno::RuntimeException) +{ + try + { + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PrintHeaders")), uno::makeAny( printHeadings )); + } + catch( uno::Exception& ) + { + } +} + +rtl::OUString& +ScVbaPageSetup::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPageSetup") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaPageSetup::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PageSetup" ) ); + } + return aServiceNames; +} + +//liuchen 2009-12-11 + +struct PaperSizeMap +{ + Paper ePaper; + sal_Int32 xlPaper; +}; + +static PaperSizeMap paperSizeMappings[] = +{ + { PAPER_A3, ooo::vba::excel::XlPaperSize::xlPaperA3 }, + { PAPER_A4, ooo::vba::excel::XlPaperSize::xlPaperA4 }, + { PAPER_A5, ooo::vba::excel::XlPaperSize::xlPaperA5 }, + { PAPER_B4_ISO, ooo::vba::excel::XlPaperSize::xlPaperB4 }, + { PAPER_B5_ISO, ooo::vba::excel::XlPaperSize::xlPaperB5 }, + { PAPER_LETTER, ooo::vba::excel::XlPaperSize::xlPaperLetter }, + { PAPER_LEGAL, ooo::vba::excel::XlPaperSize::xlPaperLegal }, + { PAPER_TABLOID, ooo::vba::excel::XlPaperSize::xlPaperTabloid }, + { PAPER_USER, ooo::vba::excel::XlPaperSize::xlPaperUser }, + { PAPER_B6_ISO, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeB6 }, + { PAPER_ENV_C4, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeC4 }, + { PAPER_ENV_C5, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeC5 }, + { PAPER_ENV_C6, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeC6 }, + { PAPER_ENV_C65, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeC65 }, + { PAPER_ENV_DL, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeDL }, + { PAPER_C, ooo::vba::excel::XlPaperSize::xlPaperCsheet }, + { PAPER_D, ooo::vba::excel::XlPaperSize::xlPaperDsheet }, + { PAPER_E, ooo::vba::excel::XlPaperSize::xlPaperEsheet }, + { PAPER_ENV_MONARCH, ooo::vba::excel::XlPaperSize::xlPaperEnvelopeMonarch }, + { PAPER_ENV_PERSONAL, ooo::vba::excel::XlPaperSize::xlPaperEnvelopePersonal }, + { PAPER_ENV_9, ooo::vba::excel::XlPaperSize::xlPaperEnvelope9 }, + { PAPER_ENV_10, ooo::vba::excel::XlPaperSize::xlPaperEnvelope10 }, + { PAPER_ENV_11, ooo::vba::excel::XlPaperSize::xlPaperEnvelope11 }, + { PAPER_ENV_12, ooo::vba::excel::XlPaperSize::xlPaperEnvelope12 } +}; + +static const int nMapSize = SAL_N_ELEMENTS(paperSizeMappings); + +sal_Int32 PaperSizeOOoToExcel(Paper ePaper) +{ + sal_Int32 nPaperSize = ooo::vba::excel::XlPaperSize::xlPaperUser; + + for (int i = 0; i < nMapSize; i++) + { + if (ePaper == paperSizeMappings[i].ePaper) + { + nPaperSize = paperSizeMappings[i].xlPaper; + break; + } + } + + return nPaperSize; +} + +sal_Int32 SAL_CALL ScVbaPageSetup::getPaperSize() throw (css::uno::RuntimeException) +{ + com::sun::star::awt::Size size; + Paper ePaper = PAPER_USER; + + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Size"))); + aValue >>= size; + ePaper = SvxPaperInfo::GetSvxPaper( Size(size.Width, size.Height), MAP_100TH_MM, TRUE); + } + catch( uno::Exception& ) + { + } + + return PaperSizeOOoToExcel(ePaper); +} + +Paper PaperSizeExcelToOOo( sal_Int32 xlPaper) +{ + Paper ePaper = PAPER_USER; + + for (int i = 0; i < nMapSize; i++) + { + if (xlPaper == paperSizeMappings[i].xlPaper) + { + ePaper = paperSizeMappings[i].ePaper; + break; + } + } + + return ePaper; +} +void SAL_CALL ScVbaPageSetup::setPaperSize( sal_Int32 paperSize) throw (css::uno::RuntimeException) +{ + Paper ePaper = PaperSizeExcelToOOo( paperSize ); + + try + { + Size size1 = SvxPaperInfo::GetPaperSize( ePaper, MAP_100TH_MM ); + com::sun::star::awt::Size size(size1.Width(), size1.Height()); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Size")), uno::makeAny( size )); + } + catch( uno::Exception& ) + { + } +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapagesetup.hxx b/sc/source/ui/vba/vbapagesetup.hxx new file mode 100644 index 000000000000..9fc3a5b295d6 --- /dev/null +++ b/sc/source/ui/vba/vbapagesetup.hxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PAGESETUP_HXX +#define SC_VBA_PAGESETUP_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XPageSetup.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbapagesetupbase.hxx> + +typedef cppu::ImplInheritanceHelper1< VbaPageSetupBase, ov::excel::XPageSetup > ScVbaPageSetup_BASE; + +class ScVbaPageSetup : public ScVbaPageSetup_BASE +{ + css::uno::Reference< css::sheet::XSpreadsheet > mxSheet; +public: + ScVbaPageSetup( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::sheet::XSpreadsheet>& xSheet, + const css::uno::Reference< css::frame::XModel >& xModel) throw (css::uno::RuntimeException); + virtual ~ScVbaPageSetup(){} + + // Attribute + virtual rtl::OUString SAL_CALL getPrintArea() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPrintArea( const rtl::OUString& rAreas ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeaderMargin() throw (css::uno::RuntimeException); + void SAL_CALL setHeaderMargin( double margin ) throw (css::uno::RuntimeException); + double SAL_CALL getFooterMargin() throw (css::uno::RuntimeException); + void SAL_CALL setFooterMargin( double margin ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFitToPagesTall() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFitToPagesTall( const css::uno::Any& fitToPagesTall ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFitToPagesWide() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFitToPagesWide( const css::uno::Any& fitToPagesWide ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getZoom() throw (css::uno::RuntimeException); + virtual void SAL_CALL setZoom( const css::uno::Any& zoom ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getLeftHeader() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeftHeader( const rtl::OUString& leftHeader ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getCenterHeader() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCenterHeader( const rtl::OUString& centerHeader ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getRightHeader() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRightHeader( const rtl::OUString& rightHeader ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getLeftFooter() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeftFooter( const rtl::OUString& leftFooter ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getCenterFooter() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCenterFooter( const rtl::OUString& centerFooter ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getRightFooter() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRightFooter( const rtl::OUString& rightFooter ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getOrder() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOrder( sal_Int32 order ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getFirstPageNumber() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFirstPageNumber( sal_Int32 firstPageNumber ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getCenterVertically() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCenterVertically( sal_Bool centerVertically ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getCenterHorizontally() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCenterHorizontally( sal_Bool centerHorizontally ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getPrintHeadings() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPrintHeadings( sal_Bool printHeadings ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getPaperSize() throw (css::uno::RuntimeException); //liuchen 2009-12-11 + virtual void SAL_CALL setPaperSize( sal_Int32 paperSize ) throw (css::uno::RuntimeException); //liuchen 2009-12-11 + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapalette.cxx b/sc/source/ui/vba/vbapalette.cxx new file mode 100644 index 000000000000..209dd2d8e564 --- /dev/null +++ b/sc/source/ui/vba/vbapalette.cxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbapalette.hxx" + +#include <sal/macros.h> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include "excelvbahelper.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +/** Standard EGA colors, bright. */ +#define EXC_PALETTE_EGA_COLORS_LIGHT \ + 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF +/** Standard EGA colors, dark. */ +#define EXC_PALETTE_EGA_COLORS_DARK \ + 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080 + +static const ColorData spnDefColorTable8[] = +{ +/* 8 */ EXC_PALETTE_EGA_COLORS_LIGHT, +/* 16 */ EXC_PALETTE_EGA_COLORS_DARK, +/* 24 */ 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF, 0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF, +/* 32 */ 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF, +/* 40 */ 0x00CCFF, 0xCCFFFF, 0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99, +/* 48 */ 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696, +/* 56 */ 0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333 +}; + +typedef ::cppu::WeakImplHelper1< container::XIndexAccess > XIndexAccess_BASE; + +class DefaultPalette : public XIndexAccess_BASE +{ +public: + DefaultPalette(){} + + // Methods XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) + { + return SAL_N_ELEMENTS(spnDefColorTable8); + } + + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 || Index >= getCount() ) + throw lang::IndexOutOfBoundsException(); + return uno::makeAny( sal_Int32( spnDefColorTable8[ Index ] ) ); + } + + // Methods XElementAcess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) + { + return ::getCppuType( (sal_Int32*)0 ); + } + virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) + { + return sal_True; + } + +}; + +ScVbaPalette::ScVbaPalette( const uno::Reference< frame::XModel >& rxModel ) : + m_pShell( excel::getDocShell( rxModel ) ) +{ +} + +uno::Reference< container::XIndexAccess > +ScVbaPalette::getDefaultPalette() +{ + return new DefaultPalette(); +} + +uno::Reference< container::XIndexAccess > +ScVbaPalette::getPalette() const +{ + uno::Reference< container::XIndexAccess > xIndex; + uno::Reference< beans::XPropertySet > xProps; + if ( m_pShell ) + xProps.set( m_pShell->GetModel(), uno::UNO_QUERY_THROW ); + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract palette, no doc shell" ) ), uno::Reference< uno::XInterface >() ); + xIndex.set( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ColorPalette") ) ), uno::UNO_QUERY ); + if ( !xIndex.is() ) + return new DefaultPalette(); + return xIndex; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapalette.hxx b/sc/source/ui/vba/vbapalette.hxx new file mode 100644 index 000000000000..a1ec16979c96 --- /dev/null +++ b/sc/source/ui/vba/vbapalette.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBAPALETTE_HXX +#define SC_VBAPALETTE_HXX + +#include <vbahelper/vbahelper.hxx> + +namespace com { namespace sun { namespace star { + namespace container { class XIndexAccess; } + namespace frame { class XModel; } +} } } + +class SfxObjectShell; + +class ScVbaPalette +{ +private: + SfxObjectShell* m_pShell; +public: + ScVbaPalette( SfxObjectShell* pShell = 0 ) : m_pShell( pShell ) {} + ScVbaPalette( const css::uno::Reference< css::frame::XModel >& rxModel ); + // if no palette available e.g. because the document doesn't have a + // palette defined then a default palette will be returned. + css::uno::Reference< css::container::XIndexAccess > getPalette() const; + static css::uno::Reference< css::container::XIndexAccess > getDefaultPalette(); +}; + +#endif //SC_VBAPALETTE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapane.cxx b/sc/source/ui/vba/vbapane.cxx new file mode 100644 index 000000000000..ee32fc3e5286 --- /dev/null +++ b/sc/source/ui/vba/vbapane.cxx @@ -0,0 +1,209 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbapane.hxx" +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include "vbarange.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaPane::ScVbaPane( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< frame::XModel >& xModel, + const uno::Reference< sheet::XViewPane > xViewPane ) throw (uno::RuntimeException) : + ScVbaPane_BASE( xParent, xContext ), + m_xModel( xModel, uno::UNO_SET_THROW ), + m_xViewPane( xViewPane, uno::UNO_SET_THROW ) +{ +} + +sal_Int32 SAL_CALL +ScVbaPane::getScrollColumn() throw (uno::RuntimeException) +{ + return ( m_xViewPane->getFirstVisibleColumn() + 1 ); +} + +void SAL_CALL +ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException) +{ + if( _scrollcolumn < 1 ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Column number should not less than 1" ), + uno::Reference< uno::XInterface >() ); + } + m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 ); +} + +sal_Int32 SAL_CALL +ScVbaPane::getScrollRow() throw (uno::RuntimeException) +{ + return ( m_xViewPane->getFirstVisibleRow() + 1 ); +} + +void SAL_CALL +ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException) +{ + if( _scrollrow < 1 ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Row number should not less than 1" ), + uno::Reference< uno::XInterface >() ); + } + m_xViewPane->setFirstVisibleRow( _scrollrow - 1 ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaPane::getVisibleRange() throw (uno::RuntimeException) +{ + // TODO: Excel includes partly visible rows/columns, Calc does not + table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange(); + uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xRange( xSheet->getCellRangeByPosition( aRangeAddr.StartColumn, aRangeAddr.StartRow, aRangeAddr.EndColumn, aRangeAddr.EndRow ), uno::UNO_SET_THROW ); + // TODO: getParent() returns the window, Range needs the worksheet + return new ScVbaRange( getParent(), mxContext, xRange ); +} + +//Method +void SAL_CALL +ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) +{ + rtl::OUString messageBuffer; + sal_Int32 downRows = 0; + sal_Int32 rightCols = 0; + table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange(); + + if( Down.hasValue() ) + { + sal_Int32 down = 0; + if( Down >>= down ) + downRows += down; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" ); + } + if( Up.hasValue() ) + { + sal_Int32 up = 0; + if( Up >>= up ) + downRows -= up; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" ); + } + if( ToRight.hasValue() ) + { + sal_Int32 right = 0; + if( ToRight >>= right ) + rightCols += right; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" ); + } + if( ToLeft.hasValue() ) + { + sal_Int32 left = 0; + if( ToLeft >>= left ) + rightCols -= left; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" ); + } + if( messageBuffer.getLength() > 0 ) + throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) ); + + sal_Int32 newStartRow = visibleRange.StartRow + downRows; + if( newStartRow < 0 ) + newStartRow = 0; + sal_Int32 newStartCol = visibleRange.StartColumn + rightCols; + if( newStartCol < 0 ) + newStartCol = 0; + m_xViewPane->setFirstVisibleRow( newStartRow ); + m_xViewPane->setFirstVisibleColumn( newStartCol ); +} + +void SAL_CALL +ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) +{ + rtl::OUString messageBuffer; + table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange(); + + sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow; + sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn; + sal_Int32 downPages = 0; + sal_Int32 acrossPages = 0; + if( Down.hasValue() ) + { + sal_Int32 down = 0; + if( Down >>= down ) + downPages += down; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" ); + } + if( Up.hasValue() ) + { + sal_Int32 up = 0; + if( Up >>= up ) + downPages -= up; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" ); + } + if( ToRight.hasValue() ) + { + sal_Int32 right = 0; + if( ToRight >>= right ) + acrossPages += right; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" ); + } + if( ToLeft.hasValue() ) + { + sal_Int32 left = 0; + if( ToLeft >>= left ) + acrossPages -= left; + else + messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" ); + } + if( messageBuffer.getLength() > 0 ) + throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) ); + + sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize ); + if( newStartRow < 0 ) + newStartRow = 0; + sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize ); + if( newStartCol < 0 ) + newStartCol = 0; + m_xViewPane->setFirstVisibleRow( newStartRow ); + m_xViewPane->setFirstVisibleColumn( newStartCol ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaPane, "ooo.vba.excel.Pane" ) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapane.hxx b/sc/source/ui/vba/vbapane.hxx new file mode 100644 index 000000000000..841776a7d918 --- /dev/null +++ b/sc/source/ui/vba/vbapane.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PANE_HXX +#define SC_VBA_PANE_HXX + +#include <com/sun/star/sheet/XViewPane.hpp> +#include <ooo/vba/excel/XPane.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include "excelvbahelper.hxx" + +typedef InheritedHelperInterfaceImpl1< ov::excel::XPane > ScVbaPane_BASE; + +class ScVbaPane : public ScVbaPane_BASE +{ +public: + ScVbaPane( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::sheet::XViewPane > xViewPane ) throw (css::uno::RuntimeException); + + css::uno::Reference< css::sheet::XViewPane > getViewPane() { return m_xViewPane; } + + // XPane attributes + virtual sal_Int32 SAL_CALL getScrollColumn() throw (css::uno::RuntimeException); + virtual void SAL_CALL setScrollColumn( sal_Int32 _scrollcolumn ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getScrollRow() throw (css::uno::RuntimeException); + virtual void SAL_CALL setScrollRow( sal_Int32 _scrollrow ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getVisibleRange() throw (css::uno::RuntimeException); + + // XPane methods + virtual void SAL_CALL SmallScroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft ) throw (css::uno::RuntimeException); + virtual void SAL_CALL LargeScroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft ) throw (css::uno::RuntimeException); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +protected: + css::uno::Reference< css::frame::XModel > m_xModel; + css::uno::Reference< css::sheet::XViewPane > m_xViewPane; +}; + +#endif //SC_VBA_PANE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapivotcache.cxx b/sc/source/ui/vba/vbapivotcache.cxx new file mode 100644 index 000000000000..7b2b4c6ddf61 --- /dev/null +++ b/sc/source/ui/vba/vbapivotcache.cxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapivotcache.hxx" + + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +ScVbaPivotCache::ScVbaPivotCache( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XDataPilotTable >& xTable ) : PivotCacheImpl_BASE( xParent, xContext ), m_xTable( xTable ) +{ +} + +sal_Int32 +ScVbaPivotCache::getMissingItemsLimit() throw (css::uno::RuntimeException) +{ + return -1; +} + +void +ScVbaPivotCache::setMissingItemsLimit( sal_Int32 /*aValue*/ ) throw ( css::uno::RuntimeException) +{ +} + +void SAL_CALL +ScVbaPivotCache::Refresh() throw (css::uno::RuntimeException) +{ + m_xTable->refresh(); +} +rtl::OUString& +ScVbaPivotCache::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPivotCache") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaPivotCache::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PivotCache" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapivotcache.hxx b/sc/source/ui/vba/vbapivotcache.hxx new file mode 100644 index 000000000000..da8c7752bd46 --- /dev/null +++ b/sc/source/ui/vba/vbapivotcache.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PIVOTCACHE_HXX +#define SC_VBA_PIVOTCACHE_HXX +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/sheet/XDataPilotTable.hpp> + +#include <ooo/vba/excel/XPivotCache.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1<ov::excel::XPivotCache > PivotCacheImpl_BASE; + +class ScVbaPivotCache : public PivotCacheImpl_BASE +{ + css::uno::Reference< css::sheet::XDataPilotTable > m_xTable; +public: + ScVbaPivotCache( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XDataPilotTable >& xTable ); + + virtual ::sal_Int32 SAL_CALL getMissingItemsLimit() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMissingItemsLimit( ::sal_Int32 aValue ) throw ( css::uno::RuntimeException); + + virtual void SAL_CALL Refresh() throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_PIVOTCACHE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapivottable.cxx b/sc/source/ui/vba/vbapivottable.cxx new file mode 100644 index 000000000000..7d788b1ed321 --- /dev/null +++ b/sc/source/ui/vba/vbapivottable.cxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapivottable.hxx" +#include "vbapivotcache.hxx" + + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +ScVbaPivotTable::ScVbaPivotTable( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XDataPilotTable >& xTable ) : PivotTableImpl_BASE( uno::Reference< XHelperInterface >(), xContext), m_xTable( xTable ) +{ +} + +uno::Reference< excel::XPivotCache > +ScVbaPivotTable::PivotCache() throw (uno::RuntimeException) +{ + // #FIXME with a quick example failed to determine what the parent + // should be, leaving as null at the moment + return new ScVbaPivotCache( uno::Reference< XHelperInterface >(), mxContext, m_xTable ); +} + +rtl::OUString& +ScVbaPivotTable::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPivotTable") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaPivotTable::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PivotTable" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapivottable.hxx b/sc/source/ui/vba/vbapivottable.hxx new file mode 100644 index 000000000000..dd7201be6170 --- /dev/null +++ b/sc/source/ui/vba/vbapivottable.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PIVOTTABLE_HXX +#define SC_VBA_PIVOTTABLE_HXX +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/sheet/XDataPilotTable.hpp> +#include <ooo/vba/excel/XPivotTable.hpp> +#include "excelvbahelper.hxx" +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XPivotTable > PivotTableImpl_BASE; + +class ScVbaPivotTable : public PivotTableImpl_BASE +{ + css::uno::Reference< css::sheet::XDataPilotTable > m_xTable; +public: + ScVbaPivotTable( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XDataPilotTable >& xTable ); + virtual css::uno::Reference< ov::excel::XPivotCache > SAL_CALL PivotCache( ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_PIVOTTABLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapivottables.cxx b/sc/source/ui/vba/vbapivottables.cxx new file mode 100644 index 000000000000..3212ac27a1af --- /dev/null +++ b/sc/source/ui/vba/vbapivottables.cxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapivottables.hxx" +#include "vbapivottable.hxx" +#include <com/sun/star/sheet/XDataPilotTable.hpp> +#include <ooo/vba/excel/XPivotTable.hpp> + + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +uno::Any DataPilotToPivotTable( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext ) +{ + uno::Reference< sheet::XDataPilotTable > xTable( aSource, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< excel::XPivotTable > ( new ScVbaPivotTable( xContext, xTable ) ) ); +} + +class PivotTableEnumeration : public EnumerationHelperImpl +{ +public: + PivotTableEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ) {} + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + return DataPilotToPivotTable( m_xEnumeration->nextElement(), m_xContext ); + } + +}; + +ScVbaPivotTables::ScVbaPivotTables( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess ): ScVbaPivotTables_BASE( xParent, xContext, xIndexAccess ) +{ +} + +uno::Reference< container::XEnumeration > +ScVbaPivotTables::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return new PivotTableEnumeration( mxParent, mxContext, xEnumAccess->createEnumeration() ); +} + +uno::Any +ScVbaPivotTables::createCollectionObject( const css::uno::Any& aSource ) +{ + return DataPilotToPivotTable( aSource, mxContext ); +} + +uno::Type +ScVbaPivotTables::getElementType() throw (uno::RuntimeException) +{ + return excel::XPivotTable::static_type(0); +} + +rtl::OUString& +ScVbaPivotTables::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPivotTables") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaPivotTables::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.PivotTables") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapivottables.hxx b/sc/source/ui/vba/vbapivottables.hxx new file mode 100644 index 000000000000..c511f064b229 --- /dev/null +++ b/sc/source/ui/vba/vbapivottables.hxx @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PIVOTTABLES_HXX +#define SC_VBA_PIVOTTABLES_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <ooo/vba/excel/XPivotTables.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include "excelvbahelper.hxx" +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> + + +typedef CollTestImplHelper< ov::excel::XPivotTables > ScVbaPivotTables_BASE; + +class ScVbaPivotTables : public ScVbaPivotTables_BASE +{ + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +public: + ScVbaPivotTables( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + virtual ~ScVbaPivotTables() {} + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + + // XPivotTables + + // ScVbaPivotTables_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + virtual rtl::OUString& getServiceImplName(); + +}; + +#endif //SC_VBA_PIVOTTABLES + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapropvalue.cxx b/sc/source/ui/vba/vbapropvalue.cxx new file mode 100644 index 000000000000..a850ef44269b --- /dev/null +++ b/sc/source/ui/vba/vbapropvalue.cxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapropvalue.hxx" + +using namespace com::sun::star; + +ScVbaPropValue::ScVbaPropValue( PropListener* pListener ) : m_pListener( pListener ) +{ +} + +css::uno::Any SAL_CALL +ScVbaPropValue::getValue() throw (css::uno::RuntimeException) +{ + return m_pListener->getValueEvent(); +} + +void SAL_CALL +ScVbaPropValue::setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException) +{ + m_pListener->setValueEvent( _value ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbapropvalue.hxx b/sc/source/ui/vba/vbapropvalue.hxx new file mode 100644 index 000000000000..51608e8642ed --- /dev/null +++ b/sc/source/ui/vba/vbapropvalue.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PROPVALULE_HXX +#define SC_VBA_PROPVALULE_HXX +#include <ooo/vba/XPropValue.hpp> +#include <cppuhelper/implbase1.hxx> + +#include "excelvbahelper.hxx" + +typedef ::cppu::WeakImplHelper1< ov::XPropValue > PropValueImpl_BASE; + +class PropListener +{ +public: + virtual void setValueEvent( const css::uno::Any& value ) = 0; + virtual css::uno::Any getValueEvent() = 0; +}; + + +class ScVbaPropValue : public PropValueImpl_BASE +{ + PropListener* m_pListener; +public: + ScVbaPropValue( PropListener* pListener ); + + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + + rtl::OUString SAL_CALL getDefaultPropertyName() throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + +}; +#endif //SC_VBA_PROPVALULE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaquerytable.cxx b/sc/source/ui/vba/vbaquerytable.cxx new file mode 100644 index 000000000000..305c14262d3a --- /dev/null +++ b/sc/source/ui/vba/vbaquerytable.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbaquerytable.hxx" +#include "document.hxx" +#include "docsh.hxx" +#include "sfx2/lnkbase.hxx" +#include "sfx2/linkmgr.hxx" +#include "arealink.hxx" +#include "vbarange.hxx" + +using namespace com::sun::star; + + +ScVbaQueryTable::ScVbaQueryTable(const css::uno::Reference< ov::XHelperInterface >& /*xParent*/, + const css::uno::Reference< css::uno::XComponentContext > & /*xContext*/, + ScDocument *pDocument , + ScVbaRange *pParent + ) +//:QueryTable_Base(xParent, xContext) +{ + m_pDocument = pDocument; + m_pParent = pParent; +} + +ScVbaQueryTable::~ScVbaQueryTable() +{ + +} + +::sal_Bool SAL_CALL +ScVbaQueryTable::Refresh( const ::com::sun::star::uno::Any& /*aBackgroundQuery*/ ) throw (::com::sun::star::uno::RuntimeException) +{ + + //Get parent Info + sal_Int32 nRow = m_pParent->getRow(); + sal_Int32 nClm = m_pParent->getColumn(); + sal_Int16 nTab = m_pParent->getWorksheet()->getIndex() - 1; //The vba index begin from 1. + ScAddress crrRngAddr(nClm, nRow, nTab); + + //Get link info + sfx2::LinkManager *pLinkMng = m_pDocument->GetLinkManager(); + const ::sfx2::SvBaseLinks &rLinks = pLinkMng->GetLinks(); + USHORT nCount = rLinks.Count(); + + for (USHORT i=0; i<nCount; i++) + { + ::sfx2::SvBaseLink* pBase = *rLinks[i]; + if (pBase->ISA(ScAreaLink)) + { + + ScAreaLink *pAreaLink = (ScAreaLink *)pBase; + const ScRange &destRange = pAreaLink->GetDestArea(); + if (destRange.In(crrRngAddr)) + { + pBase->Update(); + } + } + } + + return sal_True; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaquerytable.hxx b/sc/source/ui/vba/vbaquerytable.hxx new file mode 100644 index 000000000000..f7deea7014cb --- /dev/null +++ b/sc/source/ui/vba/vbaquerytable.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright IBM Corporation 2009, 2010. + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_QUERYTABLE_HXX +#define SC_VBA_QUERYTABLE_HXX + + +#include <ooo/vba/excel/XQueryTable.hpp> +#include "vbahelper/vbahelperinterface.hxx" + +using namespace ::ooo::vba; +typedef ::cppu::WeakImplHelper1<excel::XQueryTable> QueryTable_Base; + +class ScDocument; +class ScVbaRange; + +class ScVbaQueryTable : public QueryTable_Base +{ +private: + ScDocument *m_pDocument; + ScVbaRange *m_pParent; +public: + ScVbaQueryTable(const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext > & xContext, + ScDocument *pDocument = NULL, + ScVbaRange *pParent = NULL + ); + ~ScVbaQueryTable(); + virtual ::sal_Bool SAL_CALL Refresh( const ::com::sun::star::uno::Any& aBackgroundQuery ) + throw (::com::sun::star::uno::RuntimeException); + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx new file mode 100644 index 000000000000..c9dce622bf36 --- /dev/null +++ b/sc/source/ui/vba/vbarange.cxx @@ -0,0 +1,6239 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> + +#include <comphelper/unwrapargs.hxx> +#include <comphelper/processfactory.hxx> +#include <sfx2/objsh.hxx> + +#include <com/sun/star/script/ArrayWrapper.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/sheet/XGoalSeek.hpp> +#include <com/sun/star/sheet/XSheetOperation.hpp> +#include <com/sun/star/sheet/CellFlags.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/sheet/XCellAddressable.hpp> +#include <com/sun/star/table/CellContentType.hpp> +#include <com/sun/star/sheet/XCellSeries.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#include <com/sun/star/sheet/XSheetCellRange.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSheetCellCursor.hpp> +#include <com/sun/star/sheet/XArrayFormulaRange.hpp> +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XPrintAreas.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XFunctionAccess.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/table/XCellCursor.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/table/TableSortField.hpp> +#include <com/sun/star/util/XMergeable.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/util/XNumberFormats.hpp> +#include <com/sun/star/util/NumberFormat.hpp> +#include <com/sun/star/util/XNumberFormatTypes.hpp> +#include <com/sun/star/util/XReplaceable.hpp> +#include <com/sun/star/util/XSortable.hpp> +#include <com/sun/star/sheet/XCellRangeMovement.hpp> +#include <com/sun/star/sheet/XCellRangeData.hpp> +#include <com/sun/star/sheet/FormulaResult.hpp> +#include <com/sun/star/sheet/FilterOperator2.hpp> +#include <com/sun/star/sheet/TableFilterField.hpp> +#include <com/sun/star/sheet/TableFilterField2.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp> +#include <com/sun/star/sheet/XSheetFilterable.hpp> +#include <com/sun/star/sheet/FilterConnection.hpp> +#include <com/sun/star/util/CellProtection.hpp> +#include <com/sun/star/util/TriState.hpp> + +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/awt/XDevice.hpp> + +#include <com/sun/star/sheet/XCellRangeMovement.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/sheet/GeneralFunction.hdl> + +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/sheet/XSheetAnnotations.hpp> + +#include <com/sun/star/sheet/XDataPilotTable.hpp> +#include <com/sun/star/sheet/XDataPilotTable2.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/sheet/DataPilotTablePositionData.hpp> +#include <com/sun/star/sheet/DataPilotTablePositionType.hpp> + +#include <ooo/vba/excel/XlPasteSpecialOperation.hpp> +#include <ooo/vba/excel/XlPasteType.hpp> +#include <ooo/vba/excel/Constants.hpp> +#include <ooo/vba/excel/XlFindLookIn.hpp> +#include <ooo/vba/excel/XlLookAt.hpp> +#include <ooo/vba/excel/XlSearchOrder.hpp> +#include <ooo/vba/excel/XlSortOrder.hpp> +#include <ooo/vba/excel/XlYesNoGuess.hpp> +#include <ooo/vba/excel/XlSortOrientation.hpp> +#include <ooo/vba/excel/XlSortMethod.hpp> +#include <ooo/vba/excel/XlDirection.hpp> +#include <ooo/vba/excel/XlSortDataOption.hpp> +#include <ooo/vba/excel/XlDeleteShiftDirection.hpp> +#include <ooo/vba/excel/XlInsertShiftDirection.hpp> +#include <ooo/vba/excel/XlReferenceStyle.hpp> +#include <ooo/vba/excel/XlBordersIndex.hpp> +#include <ooo/vba/excel/XlPageBreak.hpp> +#include <ooo/vba/excel/XlAutoFilterOperator.hpp> +#include <ooo/vba/excel/XlAutoFillType.hpp> +#include <ooo/vba/excel/XlTextParsingType.hpp> +#include <ooo/vba/excel/XlTextQualifier.hpp> +#include <ooo/vba/excel/XlCellType.hpp> +#include <ooo/vba/excel/XlSpecialCellsValue.hpp> +#include <ooo/vba/excel/XlConsolidationFunction.hpp> +#include <ooo/vba/excel/XlSearchDirection.hpp> +#include <ooo/vba/excel/XlColumnDataType.hpp> +#include <ooo/vba/excel/XlFilterAction.hpp> + +#include <scitems.hxx> +#include <svl/srchitem.hxx> +#include <cellsuno.hxx> +#include <dbcolect.hxx> +#include "docfunc.hxx" +#include <docuno.hxx> + +#include <sfx2/dispatch.hxx> +#include <sfx2/app.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/request.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/itemwrapper.hxx> +#include <sc.hrc> +#include <globstr.hrc> +#include <unonames.hxx> +#include <tools/stream.hxx> + +#include "vbarange.hxx" +#include "vbafont.hxx" +#include "vbacomment.hxx" +#include "vbainterior.hxx" +#include "vbacharacters.hxx" +#include "vbaborders.hxx" +#include "vbaworksheet.hxx" +#include "vbavalidation.hxx" +#include "vbahyperlinks.hxx" + +#include "vbapivottable.hxx" + +#include "asciiopt.hxx" +#include "impex.hxx" +#include "tabvwsh.hxx" +#include "rangelst.hxx" +#include "rangenam.hxx" +#include "convuno.hxx" +#include "compiler.hxx" +#include "attrib.hxx" +#include "undodat.hxx" +#include "dbdocfun.hxx" +#include "patattr.hxx" +#include "olinetab.hxx" +#include <comphelper/anytostring.hxx> + +#include <global.hxx> + +#include "vbaglobals.hxx" +#include "vbastyle.hxx" +#include "vbaname.hxx" +#include "vbanames.hxx" +#include <vector> +#include <vbahelper/vbacollectionimpl.hxx> +// begin test includes +#include <com/sun/star/sheet/FunctionArgument.hpp> +// end test includes + +#include <ooo/vba/excel/Range.hpp> +#include <com/sun/star/bridge/oleautomation/Date.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using ::std::vector; + +// * 1 point = 1/72 inch = 20 twips +// * 1 inch = 72 points = 1440 twips +// * 1 cm = 567 twips +double lcl_hmmToPoints( double nVal ) { return ( (double)((nVal /1000 ) * 567 ) / 20 ); } + +static const sal_Int16 supportedIndexTable[] = { excel::XlBordersIndex::xlEdgeLeft, excel::XlBordersIndex::xlEdgeTop, excel::XlBordersIndex::xlEdgeBottom, excel::XlBordersIndex::xlEdgeRight, excel::XlBordersIndex::xlDiagonalDown, excel::XlBordersIndex::xlDiagonalUp, excel::XlBordersIndex::xlInsideVertical, excel::XlBordersIndex::xlInsideHorizontal }; + +USHORT lcl_pointsToTwips( double nVal ) +{ + nVal = nVal * static_cast<double>(20); + short nTwips = static_cast<short>(nVal); + return nTwips; +} +double lcl_TwipsToPoints( USHORT nVal ) +{ + double nPoints = nVal; + return nPoints / 20; +} + +double lcl_Round2DecPlaces( double nVal ) +{ + nVal = (nVal * (double)100); + long tmp = static_cast<long>(nVal); + if ( ( ( nVal - tmp ) >= 0.5 ) ) + ++tmp; + nVal = tmp; + nVal = nVal/100; + return nVal; +} + +uno::Any lcl_makeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any aAny, bool bIsRows, bool bIsColumns ) +{ + uno::Reference< table::XCellRange > xCellRange( aAny, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, xCellRange, bIsRows, bIsColumns ) ) ); +} + +uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRanges >& xLocSheetCellRanges, ScDocShell* pDoc ) +{ + uno::Reference< excel::XRange > xRange; + uno::Sequence< table::CellRangeAddress > sAddresses = xLocSheetCellRanges->getRangeAddresses(); + ScRangeList aCellRanges; + sal_Int32 nLen = sAddresses.getLength(); + if ( nLen ) + { + for ( sal_Int32 index = 0; index < nLen; ++index ) + { + ScRange refRange; + ScUnoConversion::FillScRange( refRange, sAddresses[ index ] ); + aCellRanges.Append( refRange ); + } + // Single range + if ( aCellRanges.First() == aCellRanges.Last() ) + { + uno::Reference< table::XCellRange > xTmpRange( new ScCellRangeObj( pDoc, *aCellRanges.First() ) ); + xRange = new ScVbaRange( xParent, xContext, xTmpRange ); + } + else + { + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDoc, aCellRanges ) ); + xRange = new ScVbaRange( xParent, xContext, xRanges ); + } + } + return xRange; +} + +ScCellRangesBase* ScVbaRange::getCellRangesBase() throw ( uno::RuntimeException ) +{ + if( mxRanges.is() ) + return ScCellRangesBase::getImplementation( mxRanges ); + if( mxRange.is() ) + return ScCellRangesBase::getImplementation( mxRange ); + throw uno::RuntimeException( rtl::OUString::createFromAscii("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() ); +} + +ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException ) +{ + return dynamic_cast< ScCellRangeObj* >( getCellRangesBase() ); +} + +ScCellRangesObj* ScVbaRange::getCellRangesObj() throw ( uno::RuntimeException ) +{ + return dynamic_cast< ScCellRangesObj* >( getCellRangesBase() ); +} + +SfxItemSet* ScVbaRange::getCurrentDataSet( ) throw ( uno::RuntimeException ) +{ + SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() ); + if ( !pDataSet ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for range" ) ), uno::Reference< uno::XInterface >() ); + return pDataSet; +} + +class SingleRangeEnumeration : public EnumerationHelper_BASE +{ + uno::Reference< XHelperInterface > m_xParent; + uno::Reference< table::XCellRange > m_xRange; + uno::Reference< uno::XComponentContext > mxContext; + bool bHasMore; +public: + + SingleRangeEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xRange( xRange ), mxContext( xContext ), bHasMore( true ) { } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) { return bHasMore; } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !bHasMore ) + throw container::NoSuchElementException(); + bHasMore = false; + return uno::makeAny( m_xRange ); + } +}; + +// very simple class to pass to ScVbaCollectionBaseImpl containing +// just one item +typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > SingleRange_BASE; + +class SingleRangeIndexAccess : public SingleRange_BASE +{ +private: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< table::XCellRange > m_xRange; + uno::Reference< uno::XComponentContext > mxContext; + SingleRangeIndexAccess(); // not defined +public: + SingleRangeIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ):mxParent( xParent ), m_xRange( xRange ), mxContext( xContext ) {} + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount() throw (::uno::RuntimeException) { return 1; } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index != 0 ) + throw lang::IndexOutOfBoundsException(); + return uno::makeAny( m_xRange ); + } + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return table::XCellRange::static_type(0); } + + virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) { return sal_True; } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException) { return new SingleRangeEnumeration( mxParent, mxContext, m_xRange ); } + +}; + + + +class RangesEnumerationImpl : public EnumerationHelperImpl +{ + bool mbIsRows; + bool mbIsColumns; +public: + + RangesEnumerationImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, bool bIsRows, bool bIsColumns ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {} + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns ); + } +}; + + +class ScVbaRangeAreas : public ScVbaCollectionBaseImpl +{ + bool mbIsRows; + bool mbIsColumns; +public: + ScVbaRangeAreas( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, bool bIsRows, bool bIsColumns ) : ScVbaCollectionBaseImpl( xParent, xContext, xIndexAccess ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {} + + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException); + + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return excel::XRange::static_type(0); } + + virtual uno::Any createCollectionObject( const uno::Any& aSource ); + + virtual rtl::OUString& getServiceImplName() { static rtl::OUString sDummy; return sDummy; } + + virtual uno::Sequence< rtl::OUString > getServiceNames() { return uno::Sequence< rtl::OUString >(); } + +}; + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaRangeAreas::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return new RangesEnumerationImpl( mxParent, mxContext, xEnumAccess->createEnumeration(), mbIsRows, mbIsColumns ); +} + +uno::Any +ScVbaRangeAreas::createCollectionObject( const uno::Any& aSource ) +{ + return lcl_makeRange( mxParent, mxContext, aSource, mbIsRows, mbIsColumns ); +} + +ScDocument* +ScVbaRange::getScDocument() throw (uno::RuntimeException) +{ + if ( mxRanges.is() ) + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + return excel::GetDocumentFromRange( xRange ); + } + return excel::GetDocumentFromRange( mxRange ); +} + +ScDocShell* +ScVbaRange::getScDocShell() throw (uno::RuntimeException) +{ + if ( mxRanges.is() ) + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + return excel::GetDocShellFromRange( xRange ); + } + return excel::GetDocShellFromRange( mxRange ); +} + +/*static*/ ScVbaRange* ScVbaRange::getImplementation( const uno::Reference< excel::XRange >& rxRange ) +{ + // FIXME: always save to use dynamic_cast? Or better to (implement and) use XTunnel? + return dynamic_cast< ScVbaRange* >( rxRange.get() ); +} + +uno::Reference< frame::XModel > ScVbaRange::getUnoModel() throw (uno::RuntimeException) +{ + if( ScDocShell* pDocShell = getScDocShell() ) + return pDocShell->GetModel(); + throw uno::RuntimeException(); +} + +/*static*/ uno::Reference< frame::XModel > ScVbaRange::getUnoModel( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException) +{ + if( ScVbaRange* pScVbaRange = getImplementation( rxRange ) ) + return pScVbaRange->getUnoModel(); + throw uno::RuntimeException(); +} + +const ScRangeList& ScVbaRange::getScRangeList() throw (uno::RuntimeException) +{ + if( ScCellRangesBase* pScRangesBase = getCellRangesBase() ) + return pScRangesBase->GetRangeList(); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain UNO range implementation object" ) ), uno::Reference< uno::XInterface >() ); +} + +/*static*/ const ScRangeList& ScVbaRange::getScRangeList( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException) +{ + if( ScVbaRange* pScVbaRange = getImplementation( rxRange ) ) + return pScVbaRange->getScRangeList(); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain VBA range implementation object" ) ), uno::Reference< uno::XInterface >() ); +} + + +class NumFormatHelper +{ + uno::Reference< util::XNumberFormatsSupplier > mxSupplier; + uno::Reference< beans::XPropertySet > mxRangeProps; + uno::Reference< util::XNumberFormats > mxFormats; +public: + NumFormatHelper( const uno::Reference< table::XCellRange >& xRange ) + { + mxSupplier.set( excel::GetModelFromRange( xRange ), uno::UNO_QUERY_THROW ); + mxRangeProps.set( xRange, uno::UNO_QUERY_THROW); + mxFormats = mxSupplier->getNumberFormats(); + } + uno::Reference< beans::XPropertySet > getNumberProps() + { + long nIndexKey = 0; + uno::Any aValue = mxRangeProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat"))); + aValue >>= nIndexKey; + + if ( mxFormats.is() ) + return mxFormats->getByKey( nIndexKey ); + return uno::Reference< beans::XPropertySet > (); + } + + bool isBooleanType() + { + + if ( getNumberFormat() & util::NumberFormat::LOGICAL ) + return true; + return false; + } + + bool isDateType() + { + sal_Int16 nType = getNumberFormat(); + if(( nType & util::NumberFormat::DATETIME )) + { + return true; + } + return false; + } + + rtl::OUString getNumberFormatString() + { + uno::Reference< uno::XInterface > xIf( mxRangeProps, uno::UNO_QUERY_THROW ); + ScCellRangesBase* pUnoCellRange = ScCellRangesBase::getImplementation( xIf ); + if ( pUnoCellRange ) + { + + SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange ); + SfxItemState eState = pDataSet->GetItemState( ATTR_VALUE_FORMAT, TRUE, NULL); + // one of the cells in the range is not like the other ;-) + // so return a zero length format to indicate that + if ( eState == SFX_ITEM_DONTCARE ) + return rtl::OUString(); + } + + + uno::Reference< beans::XPropertySet > xNumberProps( getNumberProps(), uno::UNO_QUERY_THROW ); + ::rtl::OUString aFormatString; + uno::Any aString = xNumberProps->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FormatString"))); + aString >>= aFormatString; + return aFormatString; + } + + sal_Int16 getNumberFormat() + { + uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps(); + sal_Int16 nType = ::comphelper::getINT16( + xNumberProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Type" ) ) ); + return nType; + } + + bool setNumberFormat( const rtl::OUString& rFormat ) + { + lang::Locale aLocale; + uno::Reference< beans::XPropertySet > xNumProps = getNumberProps(); + xNumProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Locale" ) ) >>= aLocale; + sal_Int32 nNewIndex = mxFormats->queryKey(rFormat, aLocale, false ); + if ( nNewIndex == -1 ) // format not defined + { + nNewIndex = mxFormats->addNew( rFormat, aLocale ); + } + mxRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat") ), uno::makeAny( nNewIndex ) ); + return true; + } + + bool setNumberFormat( sal_Int16 nType ) + { + uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps(); + lang::Locale aLocale; + xNumberProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Locale" ) ) >>= aLocale; + uno::Reference<util::XNumberFormatTypes> xTypes( mxFormats, uno::UNO_QUERY ); + if ( xTypes.is() ) + { + sal_Int32 nNewIndex = xTypes->getStandardFormat( nType, aLocale ); + mxRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NumberFormat") ), uno::makeAny( nNewIndex ) ); + return true; + } + return false; + } + +}; + +struct CellPos +{ + CellPos():m_nRow(-1), m_nCol(-1), m_nArea(0) {}; + CellPos( sal_Int32 nRow, sal_Int32 nCol, sal_Int32 nArea ):m_nRow(nRow), m_nCol(nCol), m_nArea( nArea ) {}; +sal_Int32 m_nRow; +sal_Int32 m_nCol; +sal_Int32 m_nArea; +}; + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > CellsEnumeration_BASE; +typedef ::std::vector< CellPos > vCellPos; + +// #FIXME - QUICK +// we could probably could and should modify CellsEnumeration below +// to handle rows and columns ( but I do this seperately for now +// and.. this class only handles singe areas ( does it have to handle +// multi area ranges?? ) +class ColumnsRowEnumeration: public CellsEnumeration_BASE +{ + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< excel::XRange > mxRange; + sal_Int32 mMaxElems; + sal_Int32 mCurElem; + +public: + ColumnsRowEnumeration( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XRange >& xRange, sal_Int32 nElems ) : mxContext( xContext ), mxRange( xRange ), mMaxElems( nElems ), mCurElem( 0 ) + { + } + + virtual ::sal_Bool SAL_CALL hasMoreElements() throw (::uno::RuntimeException){ return mCurElem < mMaxElems; } + + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + throw container::NoSuchElementException(); + sal_Int32 vbaIndex = 1 + mCurElem++; + return uno::makeAny( mxRange->Item( uno::makeAny( vbaIndex ), uno::Any() ) ); + } +}; + +class CellsEnumeration : public CellsEnumeration_BASE +{ + uno::WeakReference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< XCollection > m_xAreas; + vCellPos m_CellPositions; + vCellPos::const_iterator m_it; + + uno::Reference< table::XCellRange > getArea( sal_Int32 nVBAIndex ) throw ( uno::RuntimeException ) + { + if ( nVBAIndex < 1 || nVBAIndex > m_xAreas->getCount() ) + throw uno::RuntimeException(); + uno::Reference< excel::XRange > xRange( m_xAreas->Item( uno::makeAny(nVBAIndex), uno::Any() ), uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xCellRange( ScVbaRange::getCellRange( xRange ), uno::UNO_QUERY_THROW ); + return xCellRange; + } + + void populateArea( sal_Int32 nVBAIndex ) + { + uno::Reference< table::XCellRange > xRange = getArea( nVBAIndex ); + uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW ); + sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount(); + sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount(); + for ( sal_Int32 i=0; i<nRowCount; ++i ) + { + for ( sal_Int32 j=0; j<nColCount; ++j ) + m_CellPositions.push_back( CellPos( i,j,nVBAIndex ) ); + } + } +public: + CellsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCollection >& xAreas ): mxParent( xParent ), mxContext( xContext ), m_xAreas( xAreas ) + { + sal_Int32 nItems = m_xAreas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + populateArea( index ); + } + m_it = m_CellPositions.begin(); + } + virtual ::sal_Bool SAL_CALL hasMoreElements() throw (::uno::RuntimeException){ return m_it != m_CellPositions.end(); } + + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + throw container::NoSuchElementException(); + CellPos aPos = *(m_it)++; + + uno::Reference< table::XCellRange > xRangeArea = getArea( aPos.m_nArea ); + uno::Reference< table::XCellRange > xCellRange( xRangeArea->getCellByPosition( aPos.m_nCol, aPos.m_nRow ), uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( mxParent, mxContext, xCellRange ) ) ); + + } +}; + + +const static ::rtl::OUString ISVISIBLE( RTL_CONSTASCII_USTRINGPARAM( "IsVisible")); +const static ::rtl::OUString WIDTH( RTL_CONSTASCII_USTRINGPARAM( "Width")); +const static ::rtl::OUString HEIGHT( RTL_CONSTASCII_USTRINGPARAM( "Height")); +const static ::rtl::OUString POSITION( RTL_CONSTASCII_USTRINGPARAM( "Position")); +const static rtl::OUString EQUALS( RTL_CONSTASCII_USTRINGPARAM("=") ); +const static rtl::OUString NOTEQUALS( RTL_CONSTASCII_USTRINGPARAM("<>") ); +const static rtl::OUString GREATERTHAN( RTL_CONSTASCII_USTRINGPARAM(">") ); +const static rtl::OUString GREATERTHANEQUALS( RTL_CONSTASCII_USTRINGPARAM(">=") ); +const static rtl::OUString LESSTHAN( RTL_CONSTASCII_USTRINGPARAM("<") ); +const static rtl::OUString LESSTHANEQUALS( RTL_CONSTASCII_USTRINGPARAM("<=") ); +const static rtl::OUString CONTS_HEADER( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader" )); +const static rtl::OUString INSERTPAGEBREAKS( RTL_CONSTASCII_USTRINGPARAM("InsertPageBreaks" )); +const static rtl::OUString STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY( RTL_CONSTASCII_USTRINGPARAM("The command you chose cannot be performed with multiple selections.\nSelect a single range and click the command again") ); +const static rtl::OUString STR_ERRORMESSAGE_NOCELLSWEREFOUND( RTL_CONSTASCII_USTRINGPARAM("No cells were found") ); +const static rtl::OUString STR_ERRORMESSAGE_APPLIESTOROWCOLUMNSONLY( RTL_CONSTASCII_USTRINGPARAM("Property only applicable for Columns and Rows") ); +const static rtl::OUString CELLSTYLE( RTL_CONSTASCII_USTRINGPARAM("CellStyle") ); + +class CellValueSetter : public ValueSetter +{ +protected: + uno::Any maValue; + uno::TypeClass mTypeClass; +public: + CellValueSetter( const uno::Any& aValue ); + virtual bool processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell ); + virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ); + +}; + +CellValueSetter::CellValueSetter( const uno::Any& aValue ): maValue( aValue ), mTypeClass( aValue.getValueTypeClass() ) {} + +void +CellValueSetter::visitNode( sal_Int32 /*i*/, sal_Int32 /*j*/, const uno::Reference< table::XCell >& xCell ) +{ + processValue( maValue, xCell ); +} + +bool +CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell ) +{ + + bool isExtracted = false; + switch ( aValue.getValueTypeClass() ) + { + case uno::TypeClass_BOOLEAN: + { + sal_Bool bState = sal_False; + if ( aValue >>= bState ) + { + uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW ); + if ( bState ) + xCell->setValue( (double) 1 ); + else + xCell->setValue( (double) 0 ); + NumFormatHelper cellNumFormat( xRange ); + cellNumFormat.setNumberFormat( util::NumberFormat::LOGICAL ); + } + break; + } + case uno::TypeClass_STRING: + { + rtl::OUString aString; + if ( aValue >>= aString ) + { + uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW ); + xTextRange->setString( aString ); + } + else + isExtracted = false; + break; + } + default: + { + double nDouble = 0.0; + if ( aValue >>= nDouble ) + { + xCell->setValue( nDouble ); + uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW ); + NumFormatHelper cellNumFormat( xRange ); + if ( cellNumFormat.isBooleanType() ) + { + cellNumFormat.setNumberFormat( util::NumberFormat::NUMBER ); + } + } + else + isExtracted = false; + break; + } + } + return isExtracted; + +} + + +class CellValueGetter : public ValueGetter +{ +protected: + uno::Any maValue; + uno::TypeClass mTypeClass; +public: + CellValueGetter() {} + virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ); + virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue ); + const uno::Any& getValue() const { return maValue; } + +}; + +void +CellValueGetter::processValue( sal_Int32 /*x*/, sal_Int32 /*y*/, const uno::Any& aValue ) +{ + maValue = aValue; +} +void CellValueGetter::visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) +{ + uno::Any aValue; + table::CellContentType eType = xCell->getType(); + if( eType == table::CellContentType_VALUE || eType == table::CellContentType_FORMULA ) + { + if ( eType == table::CellContentType_FORMULA ) + { + + rtl::OUString sFormula = xCell->getFormula(); + if ( sFormula.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("=TRUE()") ) ) ) + aValue <<= sal_True; + else if ( sFormula.equals( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("=FALSE()") ) ) ) + aValue <<= sal_False; + else + { + uno::Reference< beans::XPropertySet > xProp( xCell, uno::UNO_QUERY_THROW ); + + table::CellContentType eFormulaType = table::CellContentType_VALUE; + // some formulas give textual results + xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FormulaResultType" ) ) ) >>= eFormulaType; + + if ( eFormulaType == table::CellContentType_TEXT ) + { + uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW); + aValue <<= xTextRange->getString(); + } + else + aValue <<= xCell->getValue(); + } + } + else + { + uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW ); + NumFormatHelper cellFormat( xRange ); + if ( cellFormat.isBooleanType() ) + aValue = uno::makeAny( ( xCell->getValue() != 0.0 ) ); + else if ( cellFormat.isDateType() ) + aValue = uno::makeAny( bridge::oleautomation::Date( xCell->getValue() ) ); + else + aValue <<= xCell->getValue(); + } + } + if( eType == table::CellContentType_TEXT ) + { + uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW); + aValue <<= xTextRange->getString(); + } + processValue( x,y,aValue ); +} + +class CellFormulaValueSetter : public CellValueSetter +{ +private: + ScDocument* m_pDoc; + formula::FormulaGrammar::Grammar m_eGrammar; +public: + CellFormulaValueSetter( const uno::Any& aValue, ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ):CellValueSetter( aValue ), m_pDoc( pDoc ), m_eGrammar( eGram ){} +protected: + bool processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell ) + { + rtl::OUString sFormula; + double aDblValue = 0.0; + if ( aValue >>= sFormula ) + { + // convert to GRAM_PODF_A1 style grammar because XCell::setFormula + // always compile it in that grammar. Perhaps + // css.sheet.FormulaParser should be used in future to directly + // pass formula tokens when that API stabilizes. + if ( m_eGrammar != formula::FormulaGrammar::GRAM_PODF_A1 && ( sFormula.trim().indexOf('=') == 0 ) ) + { + uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW ); + ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); + if ( pUnoRangesBase ) + { + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + ScCompiler aCompiler( m_pDoc, aCellRanges.First()->aStart ); + aCompiler.SetGrammar(m_eGrammar); + // compile the string in the format passed in + aCompiler.CompileString( sFormula ); + // set desired convention to that of the document + aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 ); + String sConverted; + aCompiler.CreateStringFromTokenArray(sConverted); + sFormula = EQUALS + sConverted; + } + } + + xCell->setFormula( sFormula ); + return true; + } + else if ( aValue >>= aDblValue ) + { + xCell->setValue( aDblValue ); + return true; + } + return false; + } + +}; + +class CellFormulaValueGetter : public CellValueGetter +{ +private: + ScDocument* m_pDoc; + formula::FormulaGrammar::Grammar m_eGrammar; +public: + CellFormulaValueGetter(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) : CellValueGetter( ), m_pDoc( pDoc ), m_eGrammar( eGram ) {} + virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) + { + uno::Any aValue; + aValue <<= xCell->getFormula(); + rtl::OUString sVal; + aValue >>= sVal; + uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW ); + ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() ); + if ( ( xCell->getType() == table::CellContentType_FORMULA ) && + pUnoRangesBase ) + { + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + ScCompiler aCompiler( m_pDoc, aCellRanges.First()->aStart ); + aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_DEFAULT); + aCompiler.CompileString( sVal ); + // set desired convention + aCompiler.SetGrammar( m_eGrammar ); + String sConverted; + aCompiler.CreateStringFromTokenArray(sConverted); + sVal = EQUALS + sConverted; + aValue <<= sVal; + } + + processValue( x,y,aValue ); + } + +}; + + +class Dim2ArrayValueGetter : public ArrayVisitor +{ +protected: + uno::Any maValue; + ValueGetter& mValueGetter; + virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue ) + { + uno::Sequence< uno::Sequence< uno::Any > >& aMatrix = *( uno::Sequence< uno::Sequence< uno::Any > >* )( maValue.getValue() ); + aMatrix[x][y] = aValue; + } + +public: + Dim2ArrayValueGetter(sal_Int32 nRowCount, sal_Int32 nColCount, ValueGetter& rValueGetter ): mValueGetter(rValueGetter) + { + uno::Sequence< uno::Sequence< uno::Any > > aMatrix; + aMatrix.realloc( nRowCount ); + for ( sal_Int32 index = 0; index < nRowCount; ++index ) + aMatrix[index].realloc( nColCount ); + maValue <<= aMatrix; + } + void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) + + { + mValueGetter.visitNode( x, y, xCell ); + processValue( x, y, mValueGetter.getValue() ); + } + const uno::Any& getValue() const { return maValue; } + +}; + +const static rtl::OUString sNA = rtl::OUString::createFromAscii("#N/A"); + +class Dim1ArrayValueSetter : public ArrayVisitor +{ + uno::Sequence< uno::Any > aMatrix; + sal_Int32 nColCount; + ValueSetter& mCellValueSetter; +public: + Dim1ArrayValueSetter( const uno::Any& aValue, ValueSetter& rCellValueSetter ):mCellValueSetter( rCellValueSetter ) + { + aValue >>= aMatrix; + nColCount = aMatrix.getLength(); + } + virtual void visitNode( sal_Int32 /*x*/, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) + { + if ( y < nColCount ) + mCellValueSetter.processValue( aMatrix[ y ], xCell ); + else + mCellValueSetter.processValue( uno::makeAny( sNA ), xCell ); + } +}; + + + +class Dim2ArrayValueSetter : public ArrayVisitor +{ + uno::Sequence< uno::Sequence< uno::Any > > aMatrix; + ValueSetter& mCellValueSetter; + sal_Int32 nRowCount; + sal_Int32 nColCount; +public: + Dim2ArrayValueSetter( const uno::Any& aValue, ValueSetter& rCellValueSetter ) : mCellValueSetter( rCellValueSetter ) + { + aValue >>= aMatrix; + nRowCount = aMatrix.getLength(); + nColCount = aMatrix[0].getLength(); + } + + virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell ) + { + if ( x < nRowCount && y < nColCount ) + mCellValueSetter.processValue( aMatrix[ x ][ y ], xCell ); + else + mCellValueSetter.processValue( uno::makeAny( sNA ), xCell ); + + } +}; + +class RangeProcessor +{ +public: + virtual void process( const uno::Reference< excel::XRange >& xRange ) = 0; +}; + +class RangeValueProcessor : public RangeProcessor +{ + const uno::Any& m_aVal; +public: + RangeValueProcessor( const uno::Any& rVal ):m_aVal( rVal ) {} + virtual void process( const uno::Reference< excel::XRange >& xRange ) + { + xRange->setValue( m_aVal ); + } +}; + +class RangeFormulaProcessor : public RangeProcessor +{ + const uno::Any& m_aVal; +public: + RangeFormulaProcessor( const uno::Any& rVal ):m_aVal( rVal ) {} + virtual void process( const uno::Reference< excel::XRange >& xRange ) + { + xRange->setFormula( m_aVal ); + } +}; + +class RangeCountProcessor : public RangeProcessor +{ + sal_Int32 nCount; +public: + RangeCountProcessor():nCount(0){} + virtual void process( const uno::Reference< excel::XRange >& xRange ) + { + nCount = nCount + xRange->getCount(); + } + sal_Int32 value() { return nCount; } +}; +class AreasVisitor +{ +private: + uno::Reference< XCollection > m_Areas; +public: + AreasVisitor( const uno::Reference< XCollection >& rAreas ):m_Areas( rAreas ){} + + void visit( RangeProcessor& processor ) + { + if ( m_Areas.is() ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + processor.process( xRange ); + } + } + } +}; + +class RangeHelper +{ + uno::Reference< table::XCellRange > m_xCellRange; + +public: + RangeHelper( const uno::Reference< table::XCellRange >& xCellRange ) throw (uno::RuntimeException) : m_xCellRange( xCellRange ) + { + if ( !m_xCellRange.is() ) + throw uno::RuntimeException(); + } + RangeHelper( const uno::Any aCellRange ) throw (uno::RuntimeException) + { + m_xCellRange.set( aCellRange, uno::UNO_QUERY_THROW ); + } + uno::Reference< sheet::XSheetCellRange > getSheetCellRange() throw (uno::RuntimeException) + { + return uno::Reference< sheet::XSheetCellRange >(m_xCellRange, uno::UNO_QUERY_THROW); + } + uno::Reference< sheet::XSpreadsheet > getSpreadSheet() throw (uno::RuntimeException) + { + return getSheetCellRange()->getSpreadsheet(); + } + + uno::Reference< table::XCellRange > getCellRangeFromSheet() throw (uno::RuntimeException) + { + return uno::Reference< table::XCellRange >(getSpreadSheet(), uno::UNO_QUERY_THROW ); + } + + uno::Reference< sheet::XCellRangeAddressable > getCellRangeAddressable() throw (uno::RuntimeException) + { + return uno::Reference< sheet::XCellRangeAddressable >(m_xCellRange, ::uno::UNO_QUERY_THROW); + + } + + uno::Reference< sheet::XSheetCellCursor > getSheetCellCursor() throw ( uno::RuntimeException ) + { + return uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_QUERY_THROW ); + } + + static uno::Reference< excel::XRange > createRangeFromRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference<uno::XComponentContext >& xContext, + const uno::Reference< table::XCellRange >& xRange, const uno::Reference< sheet::XCellRangeAddressable >& xCellRangeAddressable, + sal_Int32 nStartColOffset = 0, sal_Int32 nStartRowOffset = 0, sal_Int32 nEndColOffset = 0, sal_Int32 nEndRowOffset = 0 ) + { + return uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, + xRange->getCellRangeByPosition( + xCellRangeAddressable->getRangeAddress().StartColumn + nStartColOffset, + xCellRangeAddressable->getRangeAddress().StartRow + nStartRowOffset, + xCellRangeAddressable->getRangeAddress().EndColumn + nEndColOffset, + xCellRangeAddressable->getRangeAddress().EndRow + nEndRowOffset ) ) ); + } + +}; + +bool +getCellRangesForAddress( USHORT& rResFlags, const rtl::OUString& sAddress, ScDocShell* pDocSh, ScRangeList& rCellRanges, formula::FormulaGrammar::AddressConvention& eConv, char cDelimiter = 0 ) +{ + + ScDocument* pDoc = NULL; + if ( pDocSh ) + { + pDoc = pDocSh->GetDocument(); + String aString(sAddress); + USHORT nMask = SCA_VALID; + rResFlags = rCellRanges.Parse( sAddress, pDoc, nMask, eConv, cDelimiter ); + if ( rResFlags & SCA_VALID ) + { + return true; + } + } + return false; +} + +bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException ) +{ + // see if there is a match with a named range + uno::Reference< beans::XPropertySet > xProps( pDocSh->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW ); + // Strangly enough you can have Range( "namedRange1, namedRange2, etc," ) + // loop around each ',' seperated name + std::vector< rtl::OUString > vNames; + sal_Int32 nIndex = 0; + do + { + rtl::OUString aToken = sName.getToken( 0, ',', nIndex ); + vNames.push_back( aToken ); + } while ( nIndex >= 0 ); + + if ( !vNames.size() ) + vNames.push_back( sName ); + + std::vector< rtl::OUString >::iterator it = vNames.begin(); + std::vector< rtl::OUString >::iterator it_end = vNames.end(); + for ( ; it != it_end; ++it ) + { + + formula::FormulaGrammar::AddressConvention eConv = aConv; + // spaces are illegal ( but the user of course can enter them ) + rtl::OUString sAddress = (*it).trim(); + // if a local name ( on the active sheet ) exists this will + // take precedence over a global with the same name + if ( !xNameAccess->hasByName( sAddress ) && pDocSh ) + { + // try a local name + ScDocument* pDoc = pDocSh->GetDocument(); + SCTAB nCurTab = pDocSh->GetCurTab(); + if ( pDoc ) + { + NameToNameMap* pMap = pDoc->GetLocalNameMap( nCurTab ); + if ( pMap ) + { + NameToNameMap::iterator itTmp = pMap->find( sAddress ); + if ( itTmp != pMap->end() ) // found a mapping + sAddress = itTmp->second; + } + } + } + char aChar = 0; + if ( xNameAccess->hasByName( sAddress ) ) + { + uno::Reference< sheet::XNamedRange > xNamed( xNameAccess->getByName( sAddress ), uno::UNO_QUERY_THROW ); + sAddress = xNamed->getContent(); + // As the address comes from OOO, the addressing + // style is may not be XL_A1 + eConv = pDocSh->GetDocument()->GetAddressConvention(); + aChar = ';'; + } + + USHORT nFlags = 0; + if ( !getCellRangesForAddress( nFlags, sAddress, pDocSh, aCellRanges, eConv, aChar ) ) + return false; + + bool bTabFromReferrer = !( nFlags & SCA_TAB_3D ); + + for ( ScRange* pRange = aCellRanges.First() ; pRange; pRange = aCellRanges.Next() ) + { + pRange->aStart.SetCol( refRange.aStart.Col() + pRange->aStart.Col() ); + pRange->aStart.SetRow( refRange.aStart.Row() + pRange->aStart.Row() ); + pRange->aStart.SetTab( bTabFromReferrer ? refRange.aStart.Tab() : pRange->aStart.Tab() ); + pRange->aEnd.SetCol( refRange.aStart.Col() + pRange->aEnd.Col() ); + pRange->aEnd.SetRow( refRange.aStart.Row() + pRange->aEnd.Row() ); + pRange->aEnd.SetTab( bTabFromReferrer ? refRange.aEnd.Tab() : pRange->aEnd.Tab() ); + } + } + return true; +} + + +ScVbaRange* +getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sName, ScDocShell* pDocSh, table::CellRangeAddress& pAddr, formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException ) +{ + ScRangeList aCellRanges; + ScRange refRange; + ScUnoConversion::FillScRange( refRange, pAddr ); + if ( !getScRangeListForAddress ( sName, pDocSh, refRange, aCellRanges, eConv ) ) + throw uno::RuntimeException(); + // Single range + if ( aCellRanges.First() == aCellRanges.Last() ) + { + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocSh, *aCellRanges.First() ) ); + uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRange ); + return new ScVbaRange( xFixThisParent, xContext, xRange ); + } + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocSh, aCellRanges ) ); + + uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRanges ); + return new ScVbaRange( xFixThisParent, xContext, xRanges ); +} + +// ---------------------------------------------------------------------------- + +namespace { + +template< typename RangeType > +inline table::CellRangeAddress lclGetRangeAddress( const uno::Reference< RangeType >& rxCellRange ) throw (uno::RuntimeException) +{ + return uno::Reference< sheet::XCellRangeAddressable >( rxCellRange, uno::UNO_QUERY_THROW )->getRangeAddress(); +} + +void lclClearRange( const uno::Reference< table::XCellRange >& rxCellRange ) throw (uno::RuntimeException) +{ + using namespace ::com::sun::star::sheet::CellFlags; + sal_Int32 nFlags = VALUE | DATETIME | STRING | ANNOTATION | FORMULA | HARDATTR | STYLES | EDITATTR | FORMATTED; + uno::Reference< sheet::XSheetOperation > xSheetOperation( rxCellRange, uno::UNO_QUERY_THROW ); + xSheetOperation->clearContents( nFlags ); +} + +uno::Reference< sheet::XSheetCellRange > lclExpandToMerged( const uno::Reference< table::XCellRange >& rxCellRange, bool bRecursive ) throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSheetCellRange > xNewCellRange( rxCellRange, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet( xNewCellRange->getSpreadsheet(), uno::UNO_SET_THROW ); + table::CellRangeAddress aNewAddress = lclGetRangeAddress( xNewCellRange ); + table::CellRangeAddress aOldAddress; + // expand as long as there are new merged ranges included + do + { + aOldAddress = aNewAddress; + uno::Reference< sheet::XSheetCellCursor > xCursor( xSheet->createCursorByRange( xNewCellRange ), uno::UNO_SET_THROW ); + xCursor->collapseToMergedArea(); + xNewCellRange.set( xCursor, uno::UNO_QUERY_THROW ); + aNewAddress = lclGetRangeAddress( xNewCellRange ); + } + while( bRecursive && (aOldAddress != aNewAddress) ); + return xNewCellRange; +} + +uno::Reference< sheet::XSheetCellRangeContainer > lclExpandToMerged( const uno::Reference< sheet::XSheetCellRangeContainer >& rxCellRanges, bool bRecursive ) throw (uno::RuntimeException) +{ + if( !rxCellRanges.is() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Missing cell ranges object" ) ), uno::Reference< uno::XInterface >() ); + sal_Int32 nCount = rxCellRanges->getCount(); + if( nCount < 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Missing cell ranges object" ) ), uno::Reference< uno::XInterface >() ); + + ScRangeList aScRanges; + for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) + { + uno::Reference< table::XCellRange > xRange( rxCellRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + table::CellRangeAddress aRangeAddr = lclGetRangeAddress( lclExpandToMerged( xRange, bRecursive ) ); + ScRange aScRange; + ScUnoConversion::FillScRange( aScRange, aRangeAddr ); + aScRanges.Append( aScRange ); + } + return new ScCellRangesObj( excel::GetDocShellFromRanges( rxCellRanges ), aScRanges ); +} + +void lclExpandAndMerge( const uno::Reference< table::XCellRange >& rxCellRange, bool bMerge ) throw (uno::RuntimeException) +{ + uno::Reference< util::XMergeable > xMerge( lclExpandToMerged( rxCellRange, true ), uno::UNO_QUERY_THROW ); + // Calc cannot merge over merged ranges, always unmerge first + xMerge->merge( sal_False ); + if( bMerge ) + { + // clear all contents of the covered cells (not the top-left cell) + table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange ); + sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn; + sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow; + // clear cells of top row, right of top-left cell + if( nLastColIdx > 0 ) + lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) ); + // clear all rows below top row + if( nLastRowIdx > 0 ) + lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) ); + // merge the range + xMerge->merge( sal_True ); + } +} + +util::TriState lclGetMergedState( const uno::Reference< table::XCellRange >& rxCellRange ) throw (uno::RuntimeException) +{ + /* 1) Check if range is completely inside one single merged range. To do + this, try to extend from top-left cell only (not from entire range). + This will exclude cases where this range consists of several merged + ranges (or parts of them). */ + table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange ); + uno::Reference< table::XCellRange > xTopLeft( rxCellRange->getCellRangeByPosition( 0, 0, 0, 0 ), uno::UNO_SET_THROW ); + uno::Reference< sheet::XSheetCellRange > xExpanded( lclExpandToMerged( xTopLeft, false ), uno::UNO_SET_THROW ); + table::CellRangeAddress aExpAddr = lclGetRangeAddress( xExpanded ); + // check that expanded range has more than one cell (really merged) + if( ((aExpAddr.StartColumn < aExpAddr.EndColumn) || (aExpAddr.StartRow < aExpAddr.EndRow)) && ScUnoConversion::Contains( aExpAddr, aRangeAddr ) ) + return util::TriState_YES; + + /* 2) Check if this range contains any merged cells (completely or + partly). This seems to be hardly possible via API, as + XMergeable::getIsMerged() returns only true, if the top-left cell of a + merged range is part of this range, so cases where just the lower part + of a merged range is part of this range are not covered. */ + ScRange aScRange; + ScUnoConversion::FillScRange( aScRange, aRangeAddr ); + bool bHasMerged = excel::GetDocumentFromRange( rxCellRange )->HasAttrib( aScRange, HASATTR_MERGED | HASATTR_OVERLAPPED ); + return bHasMerged ? util::TriState_INDETERMINATE : util::TriState_NO; +} + +} // namespace + +// ---------------------------------------------------------------------------- + +css::uno::Reference< excel::XRange > +ScVbaRange::getRangeObjectForName( + const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sRangeName, + ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention eConv ) throw ( uno::RuntimeException ) +{ + table::CellRangeAddress refAddr; + return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv ); +} + +table::CellAddress ScVbaRange::getLeftUpperCellAddress() +{ + table::CellAddress aCellAddress; + uno::Reference< table::XCellRange > xCellRange = mxRange; + if ( mxRanges.is() && m_Areas.is() && m_Areas->getCount() > 1 ) + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY ); + if ( xIndex.is() && xIndex->getCount() > 0 ) + { + xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY ); + } + } + if ( xCellRange.is() ) + { + uno::Reference< sheet::XCellAddressable > xCellAddr( xCellRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY ); + if ( xCellAddr.is() ) + { + aCellAddress = xCellAddr->getCellAddress(); + } + } + return aCellAddress; +} + +table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam, ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1) throw ( uno::RuntimeException ) +{ + uno::Reference< table::XCellRange > xRangeParam; + switch ( aParam.getValueTypeClass() ) + { + case uno::TypeClass_STRING: + { + rtl::OUString rString; + aParam >>= rString; + ScRangeList aCellRanges; + ScRange refRange; + if ( getScRangeListForAddress ( rString, pDocSh, refRange, aCellRanges, aConv ) ) + { + if ( aCellRanges.First() == aCellRanges.Last() ) + { + table::CellRangeAddress aRangeAddress; + ScUnoConversion::FillApiRange( aRangeAddress, *aCellRanges.First() ); + return aRangeAddress; + } + } + } + case uno::TypeClass_INTERFACE: + { + uno::Reference< excel::XRange > xRange; + aParam >>= xRange; + if ( xRange.is() ) + { + ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() ); + if ( pRange && pDocSh && pRange->getScDocument() != pDocSh->GetDocument() ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid range" ) ), uno::Reference< uno::XInterface >() ); + } + xRange->getCellRange() >>= xRangeParam; + } + break; + } + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't extact CellRangeAddress from type" ) ), uno::Reference< uno::XInterface >() ); + } + return lclGetRangeAddress( xRangeParam ); +} + +uno::Reference< XCollection > +lcl_setupBorders( const uno::Reference< excel::XRange >& xParentRange, const uno::Reference<uno::XComponentContext>& xContext, const uno::Reference< table::XCellRange >& xRange ) throw( uno::RuntimeException ) +{ + uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW ); + ScDocument* pDoc = excel::GetDocumentFromRange(xRange); + if ( !pDoc ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); + ScVbaPalette aPalette( pDoc->GetDocumentShell() ); + uno::Reference< XCollection > borders( new ScVbaBorders( xParent, xContext, xRange, aPalette ) ); + return borders; +} + +void lcl_NotifyRangeChanges( const uno::Reference< frame::XModel >& xModel, ScCellRangesBase* pUnoRangesBase ) +{ + if ( xModel.is() && pUnoRangesBase ) + { + ScModelObj* pModelObj = ScModelObj::getImplementation( xModel ); + const ScRangeList& aCellRanges = pUnoRangesBase->GetRangeList(); + if ( pModelObj && pModelObj->HasChangesListeners() ) + { + pModelObj->NotifyChanges( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "cell-change" ) ), aCellRanges ); + } + } +} + +ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args, + uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), excel::GetModelFromRange( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( sal_False ), mbIsColumns( sal_False ) +{ + mxRange.set( mxPropertySet, uno::UNO_QUERY ); + mxRanges.set( mxPropertySet, uno::UNO_QUERY ); + uno::Reference< container::XIndexAccess > xIndex; + if ( mxRange.is() ) + { + xIndex = new SingleRangeIndexAccess( mxParent, mxContext, mxRange ); + } + else if ( mxRanges.is() ) + { + xIndex.set( mxRanges, uno::UNO_QUERY_THROW ); + } + m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns ); +} + +ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange, sal_Bool bIsRows, sal_Bool bIsColumns ) throw( lang::IllegalArgumentException ) +: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRange, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( xRange), true ), mxRange( xRange ), + mbIsRows( bIsRows ), + mbIsColumns( bIsColumns ) +{ + if ( !xContext.is() ) + throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "context is not set " ) ), uno::Reference< uno::XInterface >() , 1 ); + if ( !xRange.is() ) + throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "range is not set " ) ), uno::Reference< uno::XInterface >() , 1 ); + + uno::Reference< container::XIndexAccess > xIndex( new SingleRangeIndexAccess( mxParent, mxContext, xRange ) ); + m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns ); + +} + +ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows, sal_Bool bIsColumns ) throw ( lang::IllegalArgumentException ) +: ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRanges, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( uno::Reference< uno::XInterface >( xRanges, uno::UNO_QUERY_THROW ) ), true ), mxRanges( xRanges ),mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) + +{ + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + m_Areas = new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns ); + +} + +ScVbaRange::~ScVbaRange() +{ +} + +uno::Reference< XCollection >& ScVbaRange::getBorders() +{ + if ( !m_Borders.is() ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); + m_Borders = lcl_setupBorders( this, mxContext, uno::Reference< table::XCellRange >( xRange->getCellRange(), uno::UNO_QUERY_THROW ) ); + } + return m_Borders; +} + +void +ScVbaRange::visitArray( ArrayVisitor& visitor ) +{ + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); + sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount(); + sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount(); + for ( sal_Int32 i=0; i<nRowCount; ++i ) + { + for ( sal_Int32 j=0; j<nColCount; ++j ) + { + uno::Reference< table::XCell > xCell( mxRange->getCellByPosition( j, i ), uno::UNO_QUERY_THROW ); + + visitor.visitNode( i, j, xCell ); + } + } +} + +uno::Any SAL_CALL ScVbaRange::getName() throw (uno::RuntimeException) +{ + uno::Reference< excel::XName > xName; + + ScDocShell* pDocShell = getScDocShell(); + uno::Reference< frame::XModel > xModel = pDocShell ? pDocShell->GetModel() : NULL; + if ( !xModel.is() ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid document" ), uno::Reference< uno::XInterface >() ); + } + uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("NamedRanges")) , uno::UNO_QUERY_THROW ); + + uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), mxContext , xNamedRanges , xModel ) ); + sal_Int32 nCount = xNames->getCount(); + ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); + if ( pUnoRangesBase && nCount > 0 ) + { + ScRangeList aRangeList = pUnoRangesBase->GetRangeList(); + for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) + { + uno::Reference< excel::XName > xTmpName( xNames->Item( uno::makeAny( nIndex + 1 ), uno::Any() ), uno::UNO_QUERY ); + if ( xTmpName.is() ) + { + try + { + uno::Reference< excel::XRange > xRange = xTmpName->getRefersToRange(); + if ( xRange.is() ) + { + ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() ); + ScCellRangesBase* pCurRangesBase = pRange ? pRange->getCellRangesBase() : NULL; + if ( pCurRangesBase && aRangeList == pCurRangesBase->GetRangeList() ) + { + xName = xTmpName; + break; + } + } + } + catch (const uno::Exception&) + { + } + } + } + } + + return uno::makeAny( xName ); +} + +uno::Any +ScVbaRange::getValue( ValueGetter& valueGetter) throw (uno::RuntimeException) +{ + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); + // single cell range + if ( isSingleCellRange() ) + { + visitArray( valueGetter ); + return valueGetter.getValue(); + } + sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount(); + sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount(); + // multi cell range ( return array ) + Dim2ArrayValueGetter arrayGetter( nRowCount, nColCount, valueGetter ); + visitArray( arrayGetter ); + return uno::makeAny( script::ArrayWrapper( sal_False, arrayGetter.getValue() ) ); +} + +uno::Any SAL_CALL +ScVbaRange::getValue() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getValue(); + } + + CellValueGetter valueGetter; + return getValue( valueGetter ); + +} + + +void +ScVbaRange::setValue( const uno::Any &aValue, ValueSetter& valueSetter ) throw (uno::RuntimeException) +{ + uno::TypeClass aClass = aValue.getValueTypeClass(); + if ( aClass == uno::TypeClass_SEQUENCE ) + { + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + uno::Any aConverted; + try + { + // test for single dimension, could do + // with a better test than this + if ( aValue.getValueTypeName().indexOf('[') == aValue.getValueTypeName().lastIndexOf('[') ) + { + aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Any >*)0) ); + Dim1ArrayValueSetter setter( aConverted, valueSetter ); + visitArray( setter ); + } + else + { + aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) ); + Dim2ArrayValueSetter setter( aConverted, valueSetter ); + visitArray( setter ); + } + } + catch ( uno::Exception& e ) + { + OSL_TRACE("Bahhh, caught exception %s", + rtl::OUStringToOString( e.Message, + RTL_TEXTENCODING_UTF8 ).getStr() ); + } + } + else + { + visitArray( valueSetter ); + } +} + +void SAL_CALL +ScVbaRange::setValue( const uno::Any &aValue ) throw (uno::RuntimeException) +{ + // If this is a multiple selection apply setValue over all areas + if ( m_Areas->getCount() > 1 ) + { + AreasVisitor aVisitor( m_Areas ); + RangeValueProcessor valueProcessor( aValue ); + aVisitor.visit( valueProcessor ); + return; + } + CellValueSetter valueSetter( aValue ); + setValue( aValue, valueSetter ); + + // Fires the range change event. + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +void +ScVbaRange::Clear() throw (uno::RuntimeException) +{ + using namespace ::com::sun::star::sheet::CellFlags; + sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | EDITATTR | FORMATTED; + ClearContents( nFlags ); + + // Fires the range change event. + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +//helper ClearContent +void +ScVbaRange::ClearContents( sal_Int32 nFlags ) throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + ScVbaRange* pRange = getImplementation( xRange ); + if ( pRange ) + pRange->ClearContents( nFlags ); + } + return; + } + + + uno::Reference< sheet::XSheetOperation > xSheetOperation(mxRange, uno::UNO_QUERY_THROW); + xSheetOperation->clearContents( nFlags ); +} +void +ScVbaRange::ClearComments() throw (uno::RuntimeException) +{ + ClearContents( sheet::CellFlags::ANNOTATION ); +} + +void +ScVbaRange::ClearContents() throw (uno::RuntimeException) +{ + sal_Int32 nClearFlags = ( sheet::CellFlags::VALUE | + sheet::CellFlags::STRING | sheet::CellFlags::DATETIME | + sheet::CellFlags::FORMULA ); + ClearContents( nClearFlags ); + + // Fires the range change event. + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +void +ScVbaRange::ClearFormats() throw (uno::RuntimeException) +{ + //FIXME: need to check if we need to combine sheet::CellFlags::FORMATTED + sal_Int32 nClearFlags = sheet::CellFlags::HARDATTR | sheet::CellFlags::FORMATTED | sheet::CellFlags::EDITATTR; + ClearContents( nClearFlags ); + + // Fires the range change event. + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +void +ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::Grammar eGram ) throw (uno::RuntimeException) +{ + // If this is a multiple selection apply setFormula over all areas + if ( m_Areas->getCount() > 1 ) + { + AreasVisitor aVisitor( m_Areas ); + RangeFormulaProcessor valueProcessor( rFormula ); + aVisitor.visit( valueProcessor ); + return; + } + CellFormulaValueSetter formulaValueSetter( rFormula, getScDocument(), eGram ); + setValue( rFormula, formulaValueSetter ); + + // Fires the range change event. + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +uno::Any +ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getFormula(); + } + CellFormulaValueGetter valueGetter( getScDocument(), eGram ); + return getValue( valueGetter ); + +} + +void +ScVbaRange::setFormula(const uno::Any &rFormula ) throw (uno::RuntimeException) +{ + // #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO // results in "=$a$1:a1", temporalily disable conversion + setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );; +} + +uno::Any +ScVbaRange::getFormulaR1C1() throw (::com::sun::star::uno::RuntimeException) +{ + return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); +} + +void +ScVbaRange::setFormulaR1C1(const uno::Any& rFormula ) throw (uno::RuntimeException) +{ + setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 ); +} + +uno::Any +ScVbaRange::getFormula() throw (::com::sun::star::uno::RuntimeException) +{ + return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); +} + +sal_Int32 +ScVbaRange::getCount() throw (uno::RuntimeException) +{ + // If this is a multiple selection apply setValue over all areas + if ( m_Areas->getCount() > 1 ) + { + AreasVisitor aVisitor( m_Areas ); + RangeCountProcessor valueProcessor; + aVisitor.visit( valueProcessor ); + return valueProcessor.value(); + } + sal_Int32 rowCount = 0; + sal_Int32 colCount = 0; + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); + rowCount = xColumnRowRange->getRows()->getCount(); + colCount = xColumnRowRange->getColumns()->getCount(); + + if( IsRows() ) + return rowCount; + if( IsColumns() ) + return colCount; + return rowCount * colCount; +} + +sal_Int32 +ScVbaRange::getRow() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getRow(); + } + uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); + return xCellAddressable->getCellAddress().Row + 1; // Zero value indexing +} + +sal_Int32 +ScVbaRange::getColumn() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getColumn(); + } + uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW ); + return xCellAddressable->getCellAddress().Column + 1; // Zero value indexing +} + +uno::Any +ScVbaRange::HasFormula() throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + uno::Any aResult = aNULL(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + // if the HasFormula for any area is different to another + // return null + if ( index > 1 ) + if ( aResult != xRange->HasFormula() ) + return aNULL(); + aResult = xRange->HasFormula(); + if ( aNULL() == aResult ) + return aNULL(); + } + return aResult; + } + uno::Reference< uno::XInterface > xIf( mxRange, uno::UNO_QUERY_THROW ); + ScCellRangesBase* pThisRanges = dynamic_cast< ScCellRangesBase * > ( xIf.get() ); + if ( pThisRanges ) + { + uno::Reference<uno::XInterface> xRanges( pThisRanges->queryFormulaCells( ( sheet::FormulaResult::ERROR | sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING ) ), uno::UNO_QUERY_THROW ); + ScCellRangesBase* pFormulaRanges = dynamic_cast< ScCellRangesBase * > ( xRanges.get() ); + // check if there are no formula cell, return false + if ( pFormulaRanges->GetRangeList().Count() == 0 ) + return uno::makeAny(sal_False); + + // chech if there are holes (where some cells are not formulas) + // or returned range is not equal to this range + if ( ( pFormulaRanges->GetRangeList().Count() > 1 ) + || ( pFormulaRanges->GetRangeList().GetObject(0)->aStart != pThisRanges->GetRangeList().GetObject(0)->aStart ) + || ( pFormulaRanges->GetRangeList().GetObject(0)->aEnd != pThisRanges->GetRangeList().GetObject(0)->aEnd ) ) + return aNULL(); // should return aNULL; + } + return uno::makeAny( sal_True ); +} +void +ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ) throw( uno::RuntimeException ) +{ + if ( m_Areas->getCount() > 1 ) + { + // Multi-Area Range + uno::Reference< XCollection > xCollection( m_Areas, uno::UNO_QUERY_THROW ); + for ( sal_Int32 index = 1; index <= xCollection->getCount(); ++index ) + { + uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + ScVbaRange* pThisRange = getImplementation( xRange ); + pThisRange->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue ); + + } + return; + } + + uno::Reference< sheet::XCellSeries > xCellSeries(mxRange, uno::UNO_QUERY_THROW ); + xCellSeries->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue ); + + // Fires the range change event. + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() ); +} + +void +ScVbaRange::FillLeft() throw (uno::RuntimeException) +{ + fillSeries(sheet::FillDirection_TO_LEFT, + sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF); +} + +void +ScVbaRange::FillRight() throw (uno::RuntimeException) +{ + fillSeries(sheet::FillDirection_TO_RIGHT, + sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF); +} + +void +ScVbaRange::FillUp() throw (uno::RuntimeException) +{ + fillSeries(sheet::FillDirection_TO_TOP, + sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF); +} + +void +ScVbaRange::FillDown() throw (uno::RuntimeException) +{ + fillSeries(sheet::FillDirection_TO_BOTTOM, + sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF); +} + +::rtl::OUString +ScVbaRange::getText() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getText(); + } + uno::Reference< text::XTextRange > xTextRange(mxRange->getCellByPosition(0,0), uno::UNO_QUERY_THROW ); + return xTextRange->getString(); +} + +uno::Reference< excel::XRange > +ScVbaRange::Offset( const ::uno::Any &nRowOff, const uno::Any &nColOff ) throw (uno::RuntimeException) +{ + SCROW nRowOffset = 0; + SCCOL nColOffset = 0; + sal_Bool bIsRowOffset = ( nRowOff >>= nRowOffset ); + sal_Bool bIsColumnOffset = ( nColOff >>= nColOffset ); + ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); + + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + + + for ( ScRange* pRange = aCellRanges.First() ; pRange; pRange = aCellRanges.Next() ) + { + if ( bIsColumnOffset ) + { + pRange->aStart.SetCol( pRange->aStart.Col() + nColOffset ); + pRange->aEnd.SetCol( pRange->aEnd.Col() + nColOffset ); + } + if ( bIsRowOffset ) + { + pRange->aStart.SetRow( pRange->aStart.Row() + nRowOffset ); + pRange->aEnd.SetRow( pRange->aEnd.Row() + nRowOffset ); + } + } + + if ( aCellRanges.Count() > 1 ) // Multi-Area + { + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) ); + return new ScVbaRange( mxParent, mxContext, xRanges ); + } + // normal range + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.First() ) ); + return new ScVbaRange( mxParent, mxContext, xRange ); +} + +uno::Reference< excel::XRange > +ScVbaRange::CurrentRegion() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->CurrentRegion(); + } + + RangeHelper helper( mxRange ); + uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = + helper.getSheetCellCursor(); + xSheetCellCursor->collapseToCurrentRegion(); + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW); + return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable ); +} + +uno::Reference< excel::XRange > +ScVbaRange::CurrentArray() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->CurrentArray(); + } + RangeHelper helper( mxRange ); + uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = + helper.getSheetCellCursor(); + xSheetCellCursor->collapseToCurrentArray(); + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW); + return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable ); +} + +uno::Any +ScVbaRange::getFormulaArray() throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->getFormulaArray(); + } + + uno::Reference< sheet::XCellRangeFormula> xCellRangeFormula( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + uno::Any aMatrix; + + //VBA, minz@cn.ibm.com + uno::Sequence< uno::Sequence<rtl::OUString> > aFmArray = xCellRangeFormula->getFormulaArray(); + if( aFmArray.getLength() ) + { + if( aFmArray.getLength() == 1 && aFmArray[0].getLength() == 1 ) + aMatrix <<= aFmArray[0][0]; + else + aMatrix = xConverter->convertTo( uno::makeAny( xCellRangeFormula->getFormulaArray() ) , getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) ) ; + } + return aMatrix; +} + +void +ScVbaRange::setFormulaArray(const uno::Any& rFormula) throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->setFormulaArray( rFormula ); + } + // #TODO need to distinguish between getFormula and getFormulaArray e.g. (R1C1) + // but for the moment its just easier to treat them the same for setting + + setFormula( rFormula ); +} + +::rtl::OUString +ScVbaRange::Characters(const uno::Any& Start, const uno::Any& Length) throw (uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->Characters( Start, Length ); + } + + long nIndex = 0, nCount = 0; + ::rtl::OUString rString; + uno::Reference< text::XTextRange > xTextRange(mxRange, ::uno::UNO_QUERY_THROW ); + rString = xTextRange->getString(); + if( !( Start >>= nIndex ) && !( Length >>= nCount ) ) + return rString; + if(!( Start >>= nIndex ) ) + nIndex = 1; + if(!( Length >>= nCount ) ) + nIndex = rString.getLength(); + return rString.copy( --nIndex, nCount ); // Zero value indexing +} + +::rtl::OUString +ScVbaRange::Address( const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolute, const uno::Any& ReferenceStyle, const uno::Any& External, const uno::Any& RelativeTo ) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + // Multi-Area Range + rtl::OUString sAddress; + uno::Reference< XCollection > xCollection( m_Areas, uno::UNO_QUERY_THROW ); + uno::Any aExternalCopy = External; + for ( sal_Int32 index = 1; index <= xCollection->getCount(); ++index ) + { + uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + if ( index > 1 ) + { + sAddress += rtl::OUString( ',' ); + // force external to be false + // only first address should have the + // document and sheet specifications + aExternalCopy = uno::makeAny(sal_False); + } + sAddress += xRange->Address( RowAbsolute, ColumnAbsolute, ReferenceStyle, aExternalCopy, RelativeTo ); + } + return sAddress; + + } + ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 ); + if ( ReferenceStyle.hasValue() ) + { + sal_Int32 refStyle = excel::XlReferenceStyle::xlA1; + ReferenceStyle >>= refStyle; + if ( refStyle == excel::XlReferenceStyle::xlR1C1 ) + dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, 0, 0 ); + } + USHORT nFlags = SCA_VALID; + ScDocShell* pDocShell = getScDocShell(); + ScDocument* pDoc = pDocShell->GetDocument(); + + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) ); + String sRange; + USHORT ROW_ABSOLUTE = ( SCA_ROW_ABSOLUTE | SCA_ROW2_ABSOLUTE ); + USHORT COL_ABSOLUTE = ( SCA_COL_ABSOLUTE | SCA_COL2_ABSOLUTE ); + // default + nFlags |= ( SCA_TAB_ABSOLUTE | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE ); + if ( RowAbsolute.hasValue() ) + { + sal_Bool bVal = sal_True; + RowAbsolute >>= bVal; + if ( !bVal ) + nFlags &= ~ROW_ABSOLUTE; + } + if ( ColumnAbsolute.hasValue() ) + { + sal_Bool bVal = sal_True; + ColumnAbsolute >>= bVal; + if ( !bVal ) + nFlags &= ~COL_ABSOLUTE; + } + sal_Bool bLocal = sal_False; + if ( External.hasValue() ) + { + External >>= bLocal; + if ( bLocal ) + nFlags |= SCA_TAB_3D | SCA_FORCE_DOC; + } + if ( RelativeTo.hasValue() ) + { + // #TODO should I throw an error if R1C1 is not set? + + table::CellRangeAddress refAddress = getCellRangeAddressForVBARange( RelativeTo, pDocShell ); + dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, static_cast< SCROW >( refAddress.StartRow ), static_cast< SCCOL >( refAddress.StartColumn ) ); + } + aRange.Format( sRange, nFlags, pDoc, dDetails ); + return sRange; +} + +uno::Reference < excel::XFont > +ScVbaRange::Font() throw ( script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY ); + ScDocument* pDoc = getScDocument(); + if ( mxRange.is() ) + xProps.set(mxRange, ::uno::UNO_QUERY ); + else if ( mxRanges.is() ) + xProps.set(mxRanges, ::uno::UNO_QUERY ); + if ( !pDoc ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); + + ScVbaPalette aPalette( pDoc->GetDocumentShell() ); + ScCellRangeObj* pRangeObj = NULL; + try + { + pRangeObj = getCellRangeObj(); + } + catch( uno::Exception& ) + { + } + return new ScVbaFont( this, mxContext, aPalette, xProps, pRangeObj ); +} + +uno::Reference< excel::XRange > +ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException) +{ + // #TODO code within the test below "if ( m_Areas.... " can be removed + // Test is performed only because m_xRange is NOT set to be + // the first range in m_Areas ( to force failure while + // the implementations for each method are being updated ) + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->Cells( nRowIndex, nColumnIndex ); + } + + sal_Int32 nRow = 0, nColumn = 0; + + sal_Bool bIsIndex = nRowIndex.hasValue(); + sal_Bool bIsColumnIndex = nColumnIndex.hasValue(); + + // Sometimes we might get a float or a double or whatever + // set in the Any, we should convert as appropriate + // #FIXME - perhaps worth turning this into some sort of + // convertion routine e.g. bSuccess = getValueFromAny( nRow, nRowIndex, getCppuType((sal_Int32*)0) ) + uno::Any aRowIndexAny = nRowIndex; + if ( aRowIndexAny.getValueTypeClass() == uno::TypeClass_INTERFACE ) + { + try + { + aRowIndexAny = getDefaultPropByIntrospection( aRowIndexAny ); + } + catch( uno::Exception& ) {} + } + else if ( aRowIndexAny.hasValue() && !( aRowIndexAny >>= nRow ) ) + { + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + uno::Any aConverted; + try + { + aConverted = xConverter->convertTo( aRowIndexAny, getCppuType((sal_Int32*)0) ); + bIsIndex = ( aConverted >>= nRow ); + } + catch( uno::Exception& ) {} // silence any errors + } + + uno::Any aColumnAny = nColumnIndex; + + if ( bIsColumnIndex ) + { + // Column index can be a col address e.g Cells( 1, "B" ) etc. + rtl::OUString sCol; + if ( nColumnIndex >>= sCol ) + { + ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 ); + ScRange tmpRange; + USHORT flags = tmpRange.ParseCols( sCol, excel::GetDocumentFromRange( mxRange ), dDetails ); + if ( ( flags & 0x200 ) != 0x200 ) + throw uno::RuntimeException(); + nColumn = tmpRange.aStart.Col() + 1; + } + else + { + if ( aColumnAny.getValueTypeClass() == uno::TypeClass_INTERFACE ) + { + try + { + aColumnAny = getDefaultPropByIntrospection( aColumnAny ); + } + catch( uno::Exception& ) {} + } + if ( !( aColumnAny >>= nColumn ) ) + { + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + uno::Any aConverted; + try + { + aConverted = xConverter->convertTo( aColumnAny, getCppuType((sal_Int32*)0) ); + bIsColumnIndex = ( aConverted >>= nColumn ); + } + catch( uno::Exception& ) {} // silence any errors + } + } + } + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet(); + if( !bIsIndex && !bIsColumnIndex ) // .Cells + // #FIXE needs proper parent ( Worksheet ) + return uno::Reference< excel::XRange >( new ScVbaRange( mxParent, mxContext, mxRange ) ); + + sal_Int32 nIndex = --nRow; + if( bIsIndex && !bIsColumnIndex ) // .Cells(n) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, ::uno::UNO_QUERY_THROW); + sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount(); + + if ( !nIndex || nIndex < 0 ) + nRow = 0; + else + nRow = nIndex / nColCount; + nColumn = nIndex % nColCount; + } + else + --nColumn; + nRow = nRow + thisRangeAddress.StartRow; + nColumn = nColumn + thisRangeAddress.StartColumn; + return new ScVbaRange( mxParent, mxContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) ); +} + +void +ScVbaRange::Select() throw (uno::RuntimeException) +{ + ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); + if ( !pUnoRangesBase ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access underlying uno range object" ) ), uno::Reference< uno::XInterface >() ); + ScDocShell* pShell = pUnoRangesBase->GetDocShell(); + if ( pShell ) + { + uno::Reference< frame::XModel > xModel( pShell->GetModel(), uno::UNO_QUERY_THROW ); + uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + if ( mxRanges.is() ) + xSelection->select( uno::Any( lclExpandToMerged( mxRanges, true ) ) ); + else + xSelection->select( uno::Any( lclExpandToMerged( mxRange, true ) ) ); + // set focus on document e.g. + // ThisComponent.CurrentController.Frame.getContainerWindow.SetFocus + try + { + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< awt::XWindow > xWin( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW ); + xWin->setFocus(); + } + catch( uno::Exception& ) + { + } + } +} + +bool cellInRange( const table::CellRangeAddress& rAddr, const sal_Int32& nCol, const sal_Int32& nRow ) +{ + if ( nCol >= rAddr.StartColumn && nCol <= rAddr.EndColumn && + nRow >= rAddr.StartRow && nRow <= rAddr.EndRow ) + return true; + return false; +} + +void setCursor( const SCCOL& nCol, const SCROW& nRow, const uno::Reference< frame::XModel >& xModel, bool bInSel = true ) +{ + ScTabViewShell* pShell = excel::getBestViewShell( xModel ); + if ( pShell ) + { + if ( bInSel ) + pShell->SetCursor( nCol, nRow ); + else + pShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_NONE, FALSE, FALSE, TRUE, FALSE ); + } +} + +void +ScVbaRange::Activate() throw (uno::RuntimeException) +{ + // get first cell of current range + uno::Reference< table::XCellRange > xCellRange; + if ( mxRanges.is() ) + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + } + else + xCellRange.set( mxRange, uno::UNO_QUERY_THROW ); + + RangeHelper thisRange( xCellRange ); + uno::Reference< sheet::XCellRangeAddressable > xThisRangeAddress = thisRange.getCellRangeAddressable(); + table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress(); + uno::Reference< frame::XModel > xModel; + ScDocShell* pShell = getScDocShell(); + + if ( pShell ) + xModel = pShell->GetModel(); + + if ( !xModel.is() ) + throw uno::RuntimeException(); + + // get current selection + uno::Reference< sheet::XCellRangeAddressable > xRange( xModel->getCurrentSelection(), ::uno::UNO_QUERY); + + uno::Reference< sheet::XSheetCellRanges > xRanges( xModel->getCurrentSelection(), ::uno::UNO_QUERY); + + if ( xRanges.is() ) + { + uno::Sequence< table::CellRangeAddress > nAddrs = xRanges->getRangeAddresses(); + for ( sal_Int32 index = 0; index < nAddrs.getLength(); ++index ) + { + if ( cellInRange( nAddrs[index], thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) ) + { + setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel ); + return; + } + + } + } + + if ( xRange.is() && cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) ) + setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel ); + else + { + // if this range is multi cell select the range other + // wise just position the cell at this single range position + if ( isSingleCellRange() ) + // This top-leftmost cell of this Range is not in the current + // selection so just select this range + setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel, false ); + else + Select(); + } + +} + +uno::Reference< excel::XRange > +ScVbaRange::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + SCROW nStartRow = 0; + SCROW nEndRow = 0; + + sal_Int32 nValue = 0; + rtl::OUString sAddress; + + if ( aIndex.hasValue() ) + { + ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + + ScRange aRange = *aCellRanges.First(); + if( aIndex >>= nValue ) + { + aRange.aStart.SetRow( aRange.aStart.Row() + --nValue ); + aRange.aEnd.SetRow( aRange.aStart.Row() ); + } + + else if ( aIndex >>= sAddress ) + { + ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 ); + ScRange tmpRange; + tmpRange.ParseRows( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails ); + nStartRow = tmpRange.aStart.Row(); + nEndRow = tmpRange.aEnd.Row(); + + aRange.aStart.SetRow( aRange.aStart.Row() + nStartRow ); + aRange.aEnd.SetRow( aRange.aStart.Row() + ( nEndRow - nStartRow )); + } + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Illegal param" ) ), uno::Reference< uno::XInterface >() ); + + if ( aRange.aStart.Row() < 0 || aRange.aEnd.Row() < 0 ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("Internal failure, illegal param"), uno::Reference< uno::XInterface >() ); + // return a normal range ( even for multi-selection + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) ); + return new ScVbaRange( mxParent, mxContext, xRange, true ); + } + // Rows() - no params + if ( m_Areas->getCount() > 1 ) + return new ScVbaRange( mxParent, mxContext, mxRanges, true ); + return new ScVbaRange( mxParent, mxContext, mxRange, true ); +} + +uno::Reference< excel::XRange > +ScVbaRange::Columns(const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + SCCOL nStartCol = 0; + SCCOL nEndCol = 0; + + sal_Int32 nValue = 0; + rtl::OUString sAddress; + + ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + + ScRange aRange = *aCellRanges.First(); + if ( aIndex.hasValue() ) + { + if ( aIndex >>= nValue ) + { + aRange.aStart.SetCol( aRange.aStart.Col() + static_cast< SCCOL > ( --nValue ) ); + aRange.aEnd.SetCol( aRange.aStart.Col() ); + } + + else if ( aIndex >>= sAddress ) + { + ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 ); + ScRange tmpRange; + tmpRange.ParseCols( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails ); + nStartCol = tmpRange.aStart.Col(); + nEndCol = tmpRange.aEnd.Col(); + + aRange.aStart.SetCol( aRange.aStart.Col() + nStartCol ); + aRange.aEnd.SetCol( aRange.aStart.Col() + ( nEndCol - nStartCol )); + } + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Illegal param" ) ), uno::Reference< uno::XInterface >() ); + + if ( aRange.aStart.Col() < 0 || aRange.aEnd.Col() < 0 ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("Internal failure, illegal param"), uno::Reference< uno::XInterface >() ); + } + // Columns() - no params + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) ); + return new ScVbaRange( mxParent, mxContext, xRange, false, true ); +} + +void +ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) throw (script::BasicErrorException, uno::RuntimeException) +{ + bool bMerge = extractBoolFromAny( aIsMerged ); + + if( mxRanges.is() ) + { + sal_Int32 nCount = mxRanges->getCount(); + + // VBA does nothing (no error) if the own ranges overlap somehow + ::std::vector< table::CellRangeAddress > aList; + for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) + { + uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + table::CellRangeAddress aAddress = xRangeAddr->getRangeAddress(); + for( ::std::vector< table::CellRangeAddress >::const_iterator aIt = aList.begin(), aEnd = aList.end(); aIt != aEnd; ++aIt ) + if( ScUnoConversion::Intersects( *aIt, aAddress ) ) + return; + aList.push_back( aAddress ); + } + + // (un)merge every range after it has been extended to intersecting merged ranges from sheet + for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) + { + uno::Reference< table::XCellRange > xRange( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + lclExpandAndMerge( xRange, bMerge ); + } + return; + } + + // otherwise, merge single range + lclExpandAndMerge( mxRange, bMerge ); +} + +uno::Any +ScVbaRange::getMergeCells() throw (script::BasicErrorException, uno::RuntimeException) +{ + if( mxRanges.is() ) + { + sal_Int32 nCount = mxRanges->getCount(); + for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) + { + uno::Reference< table::XCellRange > xRange( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + util::TriState eMerged = lclGetMergedState( xRange ); + /* Excel always returns NULL, if one range of the range list is + partly or completely merged. Even if all ranges are completely + merged, the return value is still NULL. */ + if( eMerged != util::TriState_NO ) + return aNULL(); + } + // no range is merged anyhow, return false + return uno::Any( false ); + } + + // otherwise, check single range + switch( lclGetMergedState( mxRange ) ) + { + case util::TriState_YES: return uno::Any( true ); + case util::TriState_NO: return uno::Any( false ); + default: return aNULL(); + } +} + +void +ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() ); + if ( Destination.hasValue() ) + { + uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW ); + uno::Any aRange = xRange->getCellRange(); + uno::Reference< table::XCellRange > xCellRange; + aRange >>= xCellRange; + uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet(); + uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW); + uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition( + xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY); + xMover->copyRange( xDestination->getCellAddress(), xSource->getRangeAddress() ); + } + else + { + ScRange aRange; + RangeHelper thisRange( mxRange ); + ScUnoConversion::FillScRange( aRange, thisRange.getCellRangeAddressable()->getRangeAddress() ); + uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange ); + excel::implnCopyRange( xModel, aRange ); + } +} + +void +ScVbaRange::Cut(const ::uno::Any& Destination) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() ); + if (Destination.hasValue()) + { + uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xCellRange( xRange->getCellRange(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet(); + uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW); + uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition( + xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY); + uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY); + xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() ); + } + //VBA, minz@cn.ibm.com. + else { + uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange ); + Select(); + excel::implnCut( xModel ); + } +} + +void +ScVbaRange::setNumberFormat( const uno::Any& aFormat ) throw ( script::BasicErrorException, uno::RuntimeException) +{ + rtl::OUString sFormat; + aFormat >>= sFormat; + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->setNumberFormat( aFormat ); + } + return; + } + NumFormatHelper numFormat( mxRange ); + numFormat.setNumberFormat( sFormat ); +} + +uno::Any +ScVbaRange::getNumberFormat() throw ( script::BasicErrorException, uno::RuntimeException) +{ + + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + uno::Any aResult = aNULL(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + // if the numberformat of one area is different to another + // return null + if ( index > 1 ) + if ( aResult != xRange->getNumberFormat() ) + return aNULL(); + aResult = xRange->getNumberFormat(); + if ( aNULL() == aResult ) + return aNULL(); + } + return aResult; + } + NumFormatHelper numFormat( mxRange ); + rtl::OUString sFormat = numFormat.getNumberFormatString(); + if ( sFormat.getLength() > 0 ) + return uno::makeAny( sFormat ); + return aNULL(); +} + +uno::Reference< excel::XRange > +ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize ) throw (uno::RuntimeException) +{ + long nRowSize = 0, nColumnSize = 0; + sal_Bool bIsRowChanged = ( RowSize >>= nRowSize ), bIsColumnChanged = ( ColumnSize >>= nColumnSize ); + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, ::uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellRange > xSheetRange(mxRange, ::uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellCursor > xCursor( xSheetRange->getSpreadsheet()->createCursorByRange(xSheetRange), ::uno::UNO_QUERY_THROW ); + + if( !bIsRowChanged ) + nRowSize = xColumnRowRange->getRows()->getCount(); + if( !bIsColumnChanged ) + nColumnSize = xColumnRowRange->getColumns()->getCount(); + + xCursor->collapseToSize( nColumnSize, nRowSize ); + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xCursor, ::uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xRange( xSheetRange->getSpreadsheet(), ::uno::UNO_QUERY_THROW ); + return new ScVbaRange( mxParent, mxContext,xRange->getCellRangeByPosition( + xCellRangeAddressable->getRangeAddress().StartColumn, + xCellRangeAddressable->getRangeAddress().StartRow, + xCellRangeAddressable->getRangeAddress().EndColumn, + xCellRangeAddressable->getRangeAddress().EndRow ) ); +} + +void +ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + uno::Any aResult; + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->setWrapText( aIsWrapped ); + } + return; + } + + uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW ); + bool bIsWrapped = extractBoolFromAny( aIsWrapped ); + xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTextWrapped" ) ), uno::Any( bIsWrapped ) ); +} + +uno::Any +ScVbaRange::getWrapText() throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + uno::Any aResult; + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + if ( index > 1 ) + if ( aResult != xRange->getWrapText() ) + return aNULL(); + aResult = xRange->getWrapText(); + } + return aResult; + } + + SfxItemSet* pDataSet = getCurrentDataSet(); + + SfxItemState eState = pDataSet->GetItemState( ATTR_LINEBREAK, TRUE, NULL); + if ( eState == SFX_ITEM_DONTCARE ) + return aNULL(); + + uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW ); + uno::Any aValue = xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsTextWrapped" ) ) ); + return aValue; +} + +uno::Reference< excel::XInterior > ScVbaRange::Interior( ) throw ( script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW ); + return new ScVbaInterior ( this, mxContext, xProps, getScDocument() ); +} +uno::Reference< excel::XRange > +ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2 ) throw (uno::RuntimeException) +{ + return Range( Cell1, Cell2, false ); +} +uno::Reference< excel::XRange > +ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseInpuRangeTab ) throw (uno::RuntimeException) + +{ + uno::Reference< table::XCellRange > xCellRange = mxRange; + + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + } + else + xCellRange.set( mxRange ); + + RangeHelper thisRange( xCellRange ); + uno::Reference< table::XCellRange > xRanges = thisRange.getCellRangeFromSheet(); + uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRanges, uno::UNO_QUERY_THROW ); + + uno::Reference< table::XCellRange > xReferrer = + xRanges->getCellRangeByPosition( getColumn()-1, getRow()-1, + xAddressable->getRangeAddress().EndColumn, + xAddressable->getRangeAddress().EndRow ); + // xAddressable now for this range + xAddressable.set( xReferrer, uno::UNO_QUERY_THROW ); + + if( !Cell1.hasValue() ) + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " Invalid Argument " ) ), + uno::Reference< XInterface >() ); + + table::CellRangeAddress resultAddress; + table::CellRangeAddress parentRangeAddress = xAddressable->getRangeAddress(); + + ScRange aRange; + // Cell1 defined only + if ( !Cell2.hasValue() ) + { + rtl::OUString sName; + Cell1 >>= sName; + RangeHelper referRange( xReferrer ); + table::CellRangeAddress referAddress = referRange.getCellRangeAddressable()->getRangeAddress(); + return getRangeForName( mxContext, sName, getScDocShell(), referAddress ); + + } + else + { + table::CellRangeAddress cell1, cell2; + cell1 = getCellRangeAddressForVBARange( Cell1, getScDocShell() ); + // Cell1 & Cell2 defined + // Excel seems to combine the range as the range defined by + // the combination of Cell1 & Cell2 + + cell2 = getCellRangeAddressForVBARange( Cell2, getScDocShell() ); + + resultAddress.StartColumn = ( cell1.StartColumn < cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn; + resultAddress.StartRow = ( cell1.StartRow < cell2.StartRow ) ? cell1.StartRow : cell2.StartRow; + resultAddress.EndColumn = ( cell1.EndColumn > cell2.EndColumn ) ? cell1.EndColumn : cell2.EndColumn; + resultAddress.EndRow = ( cell1.EndRow > cell2.EndRow ) ? cell1.EndRow : cell2.EndRow; + if ( bForceUseInpuRangeTab ) + { + // this is a call from Application.Range( x,y ) + // its possiblefor x or y to specify a different sheet from + // the current or active on ( but they must be the same ) + if ( cell1.Sheet != cell2.Sheet ) + throw uno::RuntimeException(); + parentRangeAddress.Sheet = cell1.Sheet; + } + else + { + // this is not a call from Application.Range( x,y ) + // if a different sheet from this range is specified it's + // an error + if ( parentRangeAddress.Sheet != cell1.Sheet + || parentRangeAddress.Sheet != cell2.Sheet + ) + throw uno::RuntimeException(); + + } + ScUnoConversion::FillScRange( aRange, resultAddress ); + } + ScRange parentAddress; + ScUnoConversion::FillScRange( parentAddress, parentRangeAddress); + if ( aRange.aStart.Col() >= 0 && aRange.aStart.Row() >= 0 && aRange.aEnd.Col() >= 0 && aRange.aEnd.Row() >= 0 ) + { + sal_Int32 nStartX = parentAddress.aStart.Col() + aRange.aStart.Col(); + sal_Int32 nStartY = parentAddress.aStart.Row() + aRange.aStart.Row(); + sal_Int32 nEndX = parentAddress.aStart.Col() + aRange.aEnd.Col(); + sal_Int32 nEndY = parentAddress.aStart.Row() + aRange.aEnd.Row(); + + if ( nStartX <= nEndX && nEndX <= parentAddress.aEnd.Col() && + nStartY <= nEndY && nEndY <= parentAddress.aEnd.Row() ) + { + ScRange aNew( (SCCOL)nStartX, (SCROW)nStartY, parentAddress.aStart.Tab(), + (SCCOL)nEndX, (SCROW)nEndY, parentAddress.aEnd.Tab() ); + xCellRange = new ScCellRangeObj( getScDocShell(), aNew ); + } + } + + return new ScVbaRange( mxParent, mxContext, xCellRange ); + +} + +// Allow access to underlying openoffice uno api ( useful for debugging +// with openoffice basic ) +uno::Any SAL_CALL ScVbaRange::getCellRange( ) throw (uno::RuntimeException) +{ + uno::Any aAny; + if ( mxRanges.is() ) + aAny <<= mxRanges; + else if ( mxRange.is() ) + aAny <<= mxRange; + return aAny; +} + +/*static*/ uno::Any ScVbaRange::getCellRange( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException) +{ + if( ScVbaRange* pVbaRange = getImplementation( rxRange ) ) + return pVbaRange->getCellRange(); + throw uno::RuntimeException(); +} + +static USHORT +getPasteFlags (sal_Int32 Paste) +{ + USHORT nFlags = IDF_NONE; + switch (Paste) { + case excel::XlPasteType::xlPasteComments: + nFlags = IDF_NOTE;break; + case excel::XlPasteType::xlPasteFormats: + nFlags = IDF_ATTRIB;break; + case excel::XlPasteType::xlPasteFormulas: + nFlags = IDF_FORMULA;break; + case excel::XlPasteType::xlPasteFormulasAndNumberFormats : + case excel::XlPasteType::xlPasteValues: +#ifdef VBA_OOBUILD_HACK + nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING | IDF_SPECIAL_BOOLEAN ); break; +#else + nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING ); break; +#endif + case excel::XlPasteType::xlPasteValuesAndNumberFormats: + nFlags = IDF_VALUE | IDF_ATTRIB; break; + case excel::XlPasteType::xlPasteColumnWidths: + case excel::XlPasteType::xlPasteValidation: + nFlags = IDF_NONE;break; + case excel::XlPasteType::xlPasteAll: + case excel::XlPasteType::xlPasteAllExceptBorders: + default: + nFlags = IDF_ALL;break; + }; +return nFlags; +} + +static USHORT +getPasteFormulaBits( sal_Int32 Operation) +{ + USHORT nFormulaBits = PASTE_NOFUNC ; + switch (Operation) + { + case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd: + nFormulaBits = PASTE_ADD;break; + case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract: + nFormulaBits = PASTE_SUB;break; + case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply: + nFormulaBits = PASTE_MUL;break; + case excel::XlPasteSpecialOperation::xlPasteSpecialOperationDivide: + nFormulaBits = PASTE_DIV;break; + + case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone: + default: + nFormulaBits = PASTE_NOFUNC; break; + }; + +return nFormulaBits; +} +void SAL_CALL +ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, const uno::Any& SkipBlanks, const uno::Any& Transpose ) throw (::com::sun::star::uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() ); + ScDocShell* pShell = getScDocShell(); + + uno::Reference< frame::XModel > xModel( ( pShell ? pShell->GetModel() : NULL ), uno::UNO_QUERY_THROW ); + uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + // select this range + xSelection->select( uno::makeAny( mxRange ) ); + // set up defaults + sal_Int32 nPaste = excel::XlPasteType::xlPasteAll; + sal_Int32 nOperation = excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone; + sal_Bool bTranspose = sal_False; + sal_Bool bSkipBlanks = sal_False; + + if ( Paste.hasValue() ) + Paste >>= nPaste; + if ( Operation.hasValue() ) + Operation >>= nOperation; + if ( SkipBlanks.hasValue() ) + SkipBlanks >>= bSkipBlanks; + if ( Transpose.hasValue() ) + Transpose >>= bTranspose; + + USHORT nFlags = getPasteFlags(nPaste); + USHORT nFormulaBits = getPasteFormulaBits(nOperation); + excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose); +} + +uno::Reference< excel::XRange > +ScVbaRange::getEntireColumnOrRow( bool bColumn ) throw (uno::RuntimeException) +{ + ScCellRangesBase* pUnoRangesBase = getCellRangesBase(); + // copy the range list + ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); + + for ( ScRange* pRange = aCellRanges.First() ; pRange; pRange = aCellRanges.Next() ) + { + if ( bColumn ) + { + pRange->aStart.SetRow( 0 ); + pRange->aEnd.SetRow( MAXROW ); + } + else + { + pRange->aStart.SetCol( 0 ); + pRange->aEnd.SetCol( MAXCOL ); + } + } + if ( aCellRanges.Count() > 1 ) // Multi-Area + { + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) ); + + return new ScVbaRange( mxParent, mxContext, xRanges, !bColumn, bColumn ); + } + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.First() ) ); + return new ScVbaRange( mxParent, mxContext, xRange, !bColumn, bColumn ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::getEntireRow() throw (uno::RuntimeException) +{ + return getEntireColumnOrRow(false); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::getEntireColumn() throw (uno::RuntimeException) +{ + return getEntireColumnOrRow(); +} + +uno::Reference< excel::XComment > SAL_CALL +ScVbaRange::AddComment( const uno::Any& Text ) throw (uno::RuntimeException) +{ + // if there is already a comment in the top-left cell then throw + if( getComment().is() ) + throw uno::RuntimeException(); + + // workaround: Excel allows to create empty comment, Calc does not + ::rtl::OUString aNoteText; + if( Text.hasValue() && !(Text >>= aNoteText) ) + throw uno::RuntimeException(); + if( aNoteText.getLength() == 0 ) + aNoteText = ::rtl::OUString( sal_Unicode( ' ' ) ); + + // try to create a new annotation + table::CellRangeAddress aRangePos = lclGetRangeAddress( mxRange ); + table::CellAddress aNotePos( aRangePos.Sheet, aRangePos.StartColumn, aRangePos.StartRow ); + uno::Reference< sheet::XSheetCellRange > xCellRange( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_SET_THROW ); + xAnnos->insertNew( aNotePos, aNoteText ); + return new ScVbaComment( this, mxContext, getUnoModel(), mxRange ); +} + +uno::Reference< excel::XComment > SAL_CALL +ScVbaRange::getComment() throw (uno::RuntimeException) +{ + // intentional behavior to return a null object if no + // comment defined + uno::Reference< excel::XComment > xComment( new ScVbaComment( this, mxContext, getUnoModel(), mxRange ) ); + if ( !xComment->Text( uno::Any(), uno::Any(), uno::Any() ).getLength() ) + return NULL; + return xComment; + +} + +uno::Reference< beans::XPropertySet > +getRowOrColumnProps( const uno::Reference< table::XCellRange >& xCellRange, bool bRows ) throw ( uno::RuntimeException ) +{ + uno::Reference< table::XColumnRowRange > xColRow( xCellRange, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps; + if ( bRows ) + xProps.set( xColRow->getRows(), uno::UNO_QUERY_THROW ); + else + xProps.set( xColRow->getColumns(), uno::UNO_QUERY_THROW ); + return xProps; +} + +uno::Any SAL_CALL +ScVbaRange::getHidden() throw (uno::RuntimeException) +{ + // if multi-area result is the result of the + // first area + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(sal_Int32(1)), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->getHidden(); + } + bool bIsVisible = false; + try + { + uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows ); + if ( !( xProps->getPropertyValue( ISVISIBLE ) >>= bIsVisible ) ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to get IsVisible property")), uno::Reference< uno::XInterface >() ); + } + catch( uno::Exception& e ) + { + throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() ); + } + return uno::makeAny( !bIsVisible ); +} + +void SAL_CALL +ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->setHidden( _hidden ); + } + return; + } + + bool bHidden = extractBoolFromAny( _hidden ); + try + { + uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows ); + xProps->setPropertyValue( ISVISIBLE, uno::Any( !bHidden ) ); + } + catch( uno::Exception& e ) + { + throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() ); + } +} + +::sal_Bool SAL_CALL +ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& MatchCase, const uno::Any& MatchByte, const uno::Any& SearchFormat, const uno::Any& ReplaceFormat ) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + for ( sal_Int32 index = 1; index <= m_Areas->getCount(); ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->Replace( What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat ); + } + return sal_True; // seems to return true always ( or at least I haven't found the trick of + } + + // sanity check required params + if ( !What.getLength() /*|| !Replacement.getLength()*/ ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, missing params" )) , uno::Reference< uno::XInterface >() ); + rtl::OUString sWhat = VBAToRegexp( What); + // #TODO #FIXME SearchFormat & ReplacesFormat are not processed + // What do we do about MatchByte.. we don't seem to support that + const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem(); + SvxSearchItem newOptions( globalSearchOptions ); + + sal_Int16 nLook = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole; + sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns; + + sal_Bool bMatchCase = sal_False; + uno::Reference< util::XReplaceable > xReplace( mxRange, uno::UNO_QUERY ); + if ( xReplace.is() ) + { + uno::Reference< util::XReplaceDescriptor > xDescriptor = + xReplace->createReplaceDescriptor(); + + xDescriptor->setSearchString( sWhat); + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHREGEXP ) ), uno::makeAny( sal_True ) ); + xDescriptor->setReplaceString( Replacement); + if ( LookAt.hasValue() ) + { + // sets SearchWords ( true is Cell match ) + nLook = ::comphelper::getINT16( LookAt ); + sal_Bool bSearchWords = sal_False; + if ( nLook == excel::XlLookAt::xlPart ) + bSearchWords = sal_False; + else if ( nLook == excel::XlLookAt::xlWhole ) + bSearchWords = sal_True; + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookAt" )) , uno::Reference< uno::XInterface >() ); + // set global search props ( affects the find dialog + // and of course the defaults for this method + newOptions.SetWordOnly( bSearchWords ); + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) ); + } + // sets SearchByRow ( true for Rows ) + if ( SearchOrder.hasValue() ) + { + nSearchOrder = ::comphelper::getINT16( SearchOrder ); + sal_Bool bSearchByRow = sal_False; + if ( nSearchOrder == excel::XlSearchOrder::xlByColumns ) + bSearchByRow = sal_False; + else if ( nSearchOrder == excel::XlSearchOrder::xlByRows ) + bSearchByRow = sal_True; + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchOrder" )) , uno::Reference< uno::XInterface >() ); + + newOptions.SetRowDirection( bSearchByRow ); + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) ); + } + if ( MatchCase.hasValue() ) + { + // SearchCaseSensitive + MatchCase >>= bMatchCase; + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) ); + } + + ScGlobal::SetSearchItem( newOptions ); + // ignore MatchByte for the moment, its not supported in + // OOo.org afaik + + uno::Reference< util::XSearchDescriptor > xSearch( xDescriptor, uno::UNO_QUERY ); + // Find all cells that being replaced, used to fire the range changed event. + uno::Reference< container::XIndexAccess > xIndexAccess = xReplace->findAll( xSearch ); + xReplace->replaceAll( xSearch ); + + if ( xIndexAccess.is() && xIndexAccess->getCount() > 0 ) + { + // Fires the range change event. + ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xIndexAccess ); //liuchen 2010-01-05 + lcl_NotifyRangeChanges( getScDocShell()->GetModel(), pScCellRangesBase ); //liuchen 2010-01-05 the original convert method will fail in SUSE + } + } + return sal_True; // always +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& LookIn, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& SearchDirection, const uno::Any& MatchCase, const uno::Any& /*MatchByte*/, const uno::Any& /*SearchFormat*/ ) throw (uno::RuntimeException) +{ + // return a Range object that represents the first cell where that information is found. + rtl::OUString sWhat; + sal_Int32 nWhat = 0; + double fWhat = 0.0; + + // string. + if( What >>= sWhat ) + { + if( !sWhat.getLength() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Find, missing params" )) , uno::Reference< uno::XInterface >() ); + } + else if( What >>= nWhat ) + { + sWhat = rtl::OUString::valueOf( nWhat ); + } + else if( What >>= fWhat ) + { + sWhat = rtl::OUString::valueOf( fWhat ); + } + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Find, missing params" )) , uno::Reference< uno::XInterface >() ); + + rtl::OUString sSearch = VBAToRegexp( sWhat ); + + const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem(); + SvxSearchItem newOptions( globalSearchOptions ); + + sal_Int16 nLookAt = globalSearchOptions.GetWordOnly() ? excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole; + sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns; + + uno::Reference< util::XSearchable > xSearch( mxRange, uno::UNO_QUERY ); + if( xSearch.is() ) + { + uno::Reference< util::XSearchDescriptor > xDescriptor = xSearch->createSearchDescriptor(); + xDescriptor->setSearchString( sSearch ); + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHREGEXP ) ), uno::Any( true ) ); + + uno::Reference< excel::XRange > xAfterRange; + uno::Reference< table::XCellRange > xStartCell; + if( After >>= xAfterRange ) + { + // After must be a single cell in the range + if( xAfterRange->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("After must be a single cell." )) , uno::Reference< uno::XInterface >() ); + uno::Reference< excel::XRange > xCell( Cells( uno::makeAny( xAfterRange->getRow() ), uno::makeAny( xAfterRange->getColumn() ) ), uno::UNO_QUERY ); + if( !xCell.is() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("After must be in range." )) , uno::Reference< uno::XInterface >() ); + xStartCell.set( xAfterRange->getCellRange(), uno::UNO_QUERY_THROW ); + } + + // LookIn + if( LookIn.hasValue() ) + { + sal_Int32 nLookIn = 0; + if( LookIn >>= nLookIn ) + { + sal_Int16 nSearchType = 0; + switch( nLookIn ) + { + case excel::XlFindLookIn::xlComments : + nSearchType = SVX_SEARCHIN_NOTE; // Notes + break; + case excel::XlFindLookIn::xlFormulas : + nSearchType = SVX_SEARCHIN_FORMULA; + break; + case excel::XlFindLookIn::xlValues : + nSearchType = SVX_SEARCHIN_VALUE; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookIn." )) , uno::Reference< uno::XInterface >() ); + } + newOptions.SetCellType( nSearchType ); + xDescriptor->setPropertyValue( rtl::OUString::createFromAscii( "SearchType" ), uno::makeAny( nSearchType ) ); + } + } + + // LookAt + if ( LookAt.hasValue() ) + { + nLookAt = ::comphelper::getINT16( LookAt ); + sal_Bool bSearchWords = sal_False; + if ( nLookAt == excel::XlLookAt::xlPart ) + bSearchWords = sal_False; + else if ( nLookAt == excel::XlLookAt::xlWhole ) + bSearchWords = sal_True; + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for LookAt" )) , uno::Reference< uno::XInterface >() ); + newOptions.SetWordOnly( bSearchWords ); + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHWORDS ) ), uno::makeAny( bSearchWords ) ); + } + + // SearchOrder + if ( SearchOrder.hasValue() ) + { + nSearchOrder = ::comphelper::getINT16( SearchOrder ); + sal_Bool bSearchByRow = sal_False; + if ( nSearchOrder == excel::XlSearchOrder::xlByColumns ) + bSearchByRow = sal_False; + else if ( nSearchOrder == excel::XlSearchOrder::xlByRows ) + bSearchByRow = sal_True; + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchOrder" )) , uno::Reference< uno::XInterface >() ); + + newOptions.SetRowDirection( bSearchByRow ); + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHBYROW ) ), uno::makeAny( bSearchByRow ) ); + } + + // SearchDirection + if ( SearchDirection.hasValue() ) + { + sal_Int32 nSearchDirection = 0; + if( SearchDirection >>= nSearchDirection ) + { + sal_Bool bSearchBackwards = sal_False; + if ( nSearchDirection == excel::XlSearchDirection::xlNext ) + bSearchBackwards = sal_False; + else if( nSearchDirection == excel::XlSearchDirection::xlPrevious ) + bSearchBackwards = sal_True; + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for SearchDirection" )) , uno::Reference< uno::XInterface >() ); + newOptions.SetBackward( bSearchBackwards ); + xDescriptor->setPropertyValue( rtl::OUString::createFromAscii( "SearchBackwards" ), uno::makeAny( bSearchBackwards ) ); + } + } + + // MatchCase + sal_Bool bMatchCase = sal_False; + if ( MatchCase.hasValue() ) + { + // SearchCaseSensitive + if( !( MatchCase >>= bMatchCase ) ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Range::Replace, illegal value for MatchCase" )) , uno::Reference< uno::XInterface >() ); + } + xDescriptor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SRCHCASE ) ), uno::makeAny( bMatchCase ) ); + + // MatchByte + // SearchFormat + // ignore + + ScGlobal::SetSearchItem( newOptions ); + + uno::Reference< uno::XInterface > xInterface = xStartCell.is() ? xSearch->findNext( xStartCell, xDescriptor) : xSearch->findFirst( xDescriptor ); + uno::Reference< table::XCellRange > xCellRange( xInterface, uno::UNO_QUERY ); + // if we are searching from a starting cell and failed to find a match + // then try from the begining + if ( !xCellRange.is() && xStartCell.is() ) + { + xInterface = xSearch->findFirst( xDescriptor ); + xCellRange.set( xInterface, uno::UNO_QUERY ); + } + if ( xCellRange.is() ) + { + uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange ); + if( xResultRange.is() ) + { + xResultRange->Select(); + return xResultRange; + } + } + + } + + return uno::Reference< excel::XRange >(); +} + +uno::Reference< table::XCellRange > processKey( const uno::Any& Key, uno::Reference< uno::XComponentContext >& xContext, ScDocShell* pDocSh ) +{ + uno::Reference< excel::XRange > xKeyRange; + if ( Key.getValueType() == excel::XRange::static_type() ) + { + xKeyRange.set( Key, uno::UNO_QUERY_THROW ); + } + else if ( Key.getValueType() == ::getCppuType( static_cast< const rtl::OUString* >(0) ) ) + + { + rtl::OUString sRangeName = ::comphelper::getString( Key ); + table::CellRangeAddress aRefAddr; + if ( !pDocSh ) + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort no docshell to calculate key param")), uno::Reference< uno::XInterface >() ); + xKeyRange = getRangeForName( xContext, sRangeName, pDocSh, aRefAddr ); + } + else + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort illegal type value for key param")), uno::Reference< uno::XInterface >() ); + uno::Reference< table::XCellRange > xKey; + xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW ); + return xKey; +} + +// helper method for Sort +sal_Int32 findSortPropertyIndex( const uno::Sequence< beans::PropertyValue >& props, +const rtl::OUString& sPropName ) throw( uno::RuntimeException ) +{ + const beans::PropertyValue* pProp = props.getConstArray(); + sal_Int32 nItems = props.getLength(); + + sal_Int32 count=0; + for ( ; count < nItems; ++count, ++pProp ) + if ( pProp->Name.equals( sPropName ) ) + return count; + if ( count == nItems ) + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort unknown sort property")), uno::Reference< uno::XInterface >() ); + return -1; //should never reach here ( satisfy compiler ) +} + +// helper method for Sort +void updateTableSortField( const uno::Reference< table::XCellRange >& xParentRange, + const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder, + table::TableSortField& aTableField, sal_Bool bIsSortColumn, sal_Bool bMatchCase ) throw ( uno::RuntimeException ) +{ + RangeHelper parentRange( xParentRange ); + RangeHelper colRowRange( xColRowKey ); + + table::CellRangeAddress parentRangeAddress = parentRange.getCellRangeAddressable()->getRangeAddress(); + + table::CellRangeAddress colRowKeyAddress = colRowRange.getCellRangeAddressable()->getRangeAddress(); + + // make sure that upper left poing of key range is within the + // parent range + if ( ( !bIsSortColumn && colRowKeyAddress.StartColumn >= parentRangeAddress.StartColumn && + colRowKeyAddress.StartColumn <= parentRangeAddress.EndColumn ) || ( bIsSortColumn && + colRowKeyAddress.StartRow >= parentRangeAddress.StartRow && + colRowKeyAddress.StartRow <= parentRangeAddress.EndRow ) ) + { + //determine col/row index + if ( bIsSortColumn ) + aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow; + else + aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn; + aTableField.IsCaseSensitive = bMatchCase; + + if ( nOrder == excel::XlSortOrder::xlAscending ) + aTableField.IsAscending = sal_True; + else + aTableField.IsAscending = sal_False; + } + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal Key param" ) ), uno::Reference< uno::XInterface >() ); + + +} + +void SAL_CALL +ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& Key2, const uno::Any& /*Type*/, const uno::Any& Order2, const uno::Any& Key3, const uno::Any& Order3, const uno::Any& Header, const uno::Any& OrderCustom, const uno::Any& MatchCase, const uno::Any& Orientation, const uno::Any& SortMethod, const uno::Any& DataOption1, const uno::Any& DataOption2, const uno::Any& DataOption3 ) throw (uno::RuntimeException) +{ + // #TODO# #FIXME# can we do something with Type + if ( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("That command cannot be used on multiple selections" ) ), uno::Reference< uno::XInterface >() ); + + sal_Int16 nDataOption1 = excel::XlSortDataOption::xlSortNormal; + sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal;; + sal_Int16 nDataOption3 = excel::XlSortDataOption::xlSortNormal; + + ScDocument* pDoc = getScDocument(); + if ( !pDoc ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); + + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + ScSortParam aSortParam; + SCTAB nTab = thisRangeAddress.Sheet; + pDoc->GetSortParam( aSortParam, nTab ); + + if ( DataOption1.hasValue() ) + DataOption1 >>= nDataOption1; + if ( DataOption2.hasValue() ) + DataOption2 >>= nDataOption2; + if ( DataOption3.hasValue() ) + DataOption3 >>= nDataOption3; + + // 1) #TODO #FIXME need to process DataOption[1..3] not used currently + // 2) #TODO #FIXME need to refactor this ( below ) into a IsSingleCell() method + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW ); + + // 'Fraid I don't remember what I was trying to achieve here ??? +/* + if ( isSingleCellRange() ) + { + uno::Reference< XRange > xCurrent = CurrentRegion(); + xCurrent->Sort( Key1, Order1, Key2, Type, Order2, Key3, Order3, Header, OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2, DataOption3 ); + return; + } +*/ + // set up defaults + + sal_Int16 nOrder1 = aSortParam.bAscending[0] ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending; + sal_Int16 nOrder2 = aSortParam.bAscending[1] ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending; + sal_Int16 nOrder3 = aSortParam.bAscending[2] ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending; + + sal_Int16 nCustom = aSortParam.nUserIndex; + sal_Int16 nSortMethod = excel::XlSortMethod::xlPinYin; + sal_Bool bMatchCase = aSortParam.bCaseSens; + + // seems to work opposite to expected, see below + sal_Int16 nOrientation = aSortParam.bByRow ? excel::XlSortOrientation::xlSortColumns : excel::XlSortOrientation::xlSortRows; + + if ( Orientation.hasValue() ) + { + // Documentation says xlSortRows is default but that doesn't appear to be + // the case. Also it appears that xlSortColumns is the default which + // strangely enought sorts by Row + nOrientation = ::comphelper::getINT16( Orientation ); + // persist new option to be next calls default + if ( nOrientation == excel::XlSortOrientation::xlSortRows ) + aSortParam.bByRow = FALSE; + else + aSortParam.bByRow = TRUE; + + } + + sal_Bool bIsSortColumns=sal_False; // sort by row + + if ( nOrientation == excel::XlSortOrientation::xlSortRows ) + bIsSortColumns = sal_True; + sal_Int16 nHeader = 0; +#ifdef VBA_OOBUILD_HACK + nHeader = aSortParam.nCompatHeader; +#endif + sal_Bool bContainsHeader = sal_False; + + if ( Header.hasValue() ) + { + nHeader = ::comphelper::getINT16( Header ); +#ifdef VBA_OOBUILD_HACK + aSortParam.nCompatHeader = nHeader; +#endif + } + + if ( nHeader == excel::XlYesNoGuess::xlGuess ) + { + bool bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet )); + bool bHasRowHeader = pDoc->HasRowHeader( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ) ); + if ( bHasColHeader || bHasRowHeader ) + nHeader = excel::XlYesNoGuess::xlYes; + else + nHeader = excel::XlYesNoGuess::xlNo; +#ifdef VBA_OOBUILD_HACK + aSortParam.nCompatHeader = nHeader; +#endif + } + + if ( nHeader == excel::XlYesNoGuess::xlYes ) + bContainsHeader = sal_True; + + if ( SortMethod.hasValue() ) + { + nSortMethod = ::comphelper::getINT16( SortMethod ); + } + + if ( OrderCustom.hasValue() ) + { + OrderCustom >>= nCustom; + --nCustom; // 0-based in OOo + aSortParam.nUserIndex = nCustom; + } + + if ( MatchCase.hasValue() ) + { + MatchCase >>= bMatchCase; + aSortParam.bCaseSens = bMatchCase; + } + + if ( Order1.hasValue() ) + { + nOrder1 = ::comphelper::getINT16(Order1); + if ( nOrder1 == excel::XlSortOrder::xlAscending ) + aSortParam.bAscending[0] = TRUE; + else + aSortParam.bAscending[0] = FALSE; + + } + if ( Order2.hasValue() ) + { + nOrder2 = ::comphelper::getINT16(Order2); + if ( nOrder2 == excel::XlSortOrder::xlAscending ) + aSortParam.bAscending[1] = TRUE; + else + aSortParam.bAscending[1] = FALSE; + } + if ( Order3.hasValue() ) + { + nOrder3 = ::comphelper::getINT16(Order3); + if ( nOrder3 == excel::XlSortOrder::xlAscending ) + aSortParam.bAscending[2] = TRUE; + else + aSortParam.bAscending[2] = FALSE; + } + + uno::Reference< table::XCellRange > xKey1; + uno::Reference< table::XCellRange > xKey2; + uno::Reference< table::XCellRange > xKey3; + ScDocShell* pDocShell = getScDocShell(); + xKey1 = processKey( Key1, mxContext, pDocShell ); + if ( !xKey1.is() ) + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Range::Sort needs a key1 param")), uno::Reference< uno::XInterface >() ); + + if ( Key2.hasValue() ) + xKey2 = processKey( Key2, mxContext, pDocShell ); + if ( Key3.hasValue() ) + xKey3 = processKey( Key3, mxContext, pDocShell ); + + uno::Reference< util::XSortable > xSort( mxRange, uno::UNO_QUERY_THROW ); + uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor(); + sal_Int32 nTableSortFieldIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SortFields") ) ); + + uno::Sequence< table::TableSortField > sTableFields(1); + sal_Int32 nTableIndex = 0; + updateTableSortField( mxRange, xKey1, nOrder1, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase ); + + if ( xKey2.is() ) + { + sTableFields.realloc( sTableFields.getLength() + 1 ); + updateTableSortField( mxRange, xKey2, nOrder2, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase ); + } + if ( xKey3.is() ) + { + sTableFields.realloc( sTableFields.getLength() + 1 ); + updateTableSortField( mxRange, xKey3, nOrder3, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase ); + } + sortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields; + + sal_Int32 nIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSortColumns")) ); + sortDescriptor[ nIndex ].Value <<= bIsSortColumns; + + nIndex = findSortPropertyIndex( sortDescriptor, CONTS_HEADER ); + sortDescriptor[ nIndex ].Value <<= bContainsHeader; + + pDoc->SetSortParam( aSortParam, nTab ); + xSort->sort( sortDescriptor ); + + // #FIXME #TODO + // The SortMethod param is not processed ( not sure what its all about, need to + +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW ); + return xRange->End( Direction ); + } + + table::CellAddress aAddress = getLeftUpperCellAddress(); + SCTAB nTab = aAddress.Sheet; + SCCOL nCurX = aAddress.Column; + SCROW nCurY = aAddress.Row; + SCCOL nNewX = nCurX; + SCROW nNewY = nCurY; + + ScDocShell* pDocShell = getScDocShell(); + ScDocument* pDoc = pDocShell->GetDocument(); + + SCsCOL nMoveX = 0; + SCsROW nMoveY = 0; + switch ( Direction ) + { + case excel::XlDirection::xlDown: + nMoveY = 1; + break; + case excel::XlDirection::xlUp: + nMoveY = -1; + break; + case excel::XlDirection::xlToLeft: + nMoveX = -1; + break; + case excel::XlDirection::xlToRight: + nMoveX = 1; + break; + default: + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid Direction" ) ), uno::Reference< uno::XInterface >() ); + } + + if ( pDoc ) + { + pDoc->FindAreaPos( nNewX, nNewY, nTab, nMoveX, nMoveY ); + } + + ScRange aNewRange( (SCCOL)nNewX, (SCROW)nNewY, nTab, (SCCOL)nNewX, (SCROW)nNewY, nTab ); + uno::Reference< table::XCellRange > xCellRange( new ScCellRangeObj( getScDocShell(), aNewRange ) ); + uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange ); + return xResultRange; +} + +bool +ScVbaRange::isSingleCellRange() +{ + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY); + if ( xColumnRowRange.is() && xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 ) + return true; + return false; +} + +uno::Reference< excel::XCharacters > SAL_CALL +ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) throw (uno::RuntimeException) +{ + if ( !isSingleCellRange() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't create Characters property for multicell range ") ), uno::Reference< uno::XInterface >() ); + uno::Reference< text::XSimpleText > xSimple(mxRange->getCellByPosition(0,0) , uno::UNO_QUERY_THROW ); + ScDocument* pDoc = excel::GetDocumentFromRange(mxRange); + if ( !pDoc ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); + + ScVbaPalette aPalette( pDoc->GetDocumentShell() ); + return new ScVbaCharacters( this, mxContext, aPalette, xSimple, Start, Length ); +} + + void SAL_CALL +ScVbaRange::Delete( const uno::Any& Shift ) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->Delete( Shift ); + } + return; + } + sheet::CellDeleteMode mode = sheet::CellDeleteMode_NONE ; + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + if ( Shift.hasValue() ) + { + sal_Int32 nShift = 0; + Shift >>= nShift; + switch ( nShift ) + { + case excel::XlDeleteShiftDirection::xlShiftUp: + mode = sheet::CellDeleteMode_UP; + break; + case excel::XlDeleteShiftDirection::xlShiftToLeft: + mode = sheet::CellDeleteMode_LEFT; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("Illegal paramater ") ), uno::Reference< uno::XInterface >() ); + } + } + else + { + bool bFullRow = ( thisAddress.StartColumn == 0 && thisAddress.EndColumn == MAXCOL ); + sal_Int32 nCols = thisAddress.EndColumn - thisAddress.StartColumn; + sal_Int32 nRows = thisAddress.EndRow - thisAddress.StartRow; + if ( mbIsRows || bFullRow || ( nCols >= nRows ) ) + mode = sheet::CellDeleteMode_UP; + else + mode = sheet::CellDeleteMode_LEFT; + } + uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); + xCellRangeMove->removeRange( thisAddress, mode ); + +} + +//XElementAccess +sal_Bool SAL_CALL +ScVbaRange::hasElements() throw (uno::RuntimeException) +{ + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY ); + if ( xColumnRowRange.is() ) + if ( xColumnRowRange->getRows()->getCount() || + xColumnRowRange->getColumns()->getCount() ) + return sal_True; + return sal_False; +} + +// XEnumerationAccess +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaRange::createEnumeration() throw (uno::RuntimeException) +{ + if ( mbIsColumns || mbIsRows ) + { + uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY ); + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); + sal_Int32 nElems = 0; + if ( mbIsColumns ) + nElems = xColumnRowRange->getColumns()->getCount(); + else + nElems = xColumnRowRange->getRows()->getCount(); + return new ColumnsRowEnumeration( mxContext, xRange, nElems ); + + } + return new CellsEnumeration( mxParent, mxContext, m_Areas ); +} + +::rtl::OUString SAL_CALL +ScVbaRange::getDefaultMethodName( ) throw (uno::RuntimeException) +{ + const static rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM("Item") ); + return sName; +} + + +uno::Reference< awt::XDevice > +getDeviceFromDoc( const uno::Reference< frame::XModel >& xModel ) throw( uno::RuntimeException ) +{ + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame> xFrame( xController->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< awt::XDevice > xDevice( xFrame->getComponentWindow(), uno::UNO_QUERY_THROW ); + return xDevice; +} + +// returns calc internal col. width ( in points ) +double +ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) throw (uno::RuntimeException) +{ + ScDocument* pDoc = getScDocument(); + USHORT nWidth = pDoc->GetOriginalWidth( static_cast< SCCOL >( rAddress.StartColumn ), static_cast< SCTAB >( rAddress.Sheet ) ); + double nPoints = lcl_TwipsToPoints( nWidth ); + nPoints = lcl_Round2DecPlaces( nPoints ); + return nPoints; +} + +double +ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) throw (uno::RuntimeException) +{ + ScDocument* pDoc = excel::GetDocumentFromRange( mxRange ); + USHORT nWidth = pDoc->GetOriginalHeight( rAddress.StartRow, rAddress.Sheet ); + double nPoints = lcl_TwipsToPoints( nWidth ); + nPoints = lcl_Round2DecPlaces( nPoints ); + return nPoints; +} + +// return Char Width in points +double getDefaultCharWidth( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) +{ + const static rtl::OUString sDflt( RTL_CONSTASCII_USTRINGPARAM("Default")); + const static rtl::OUString sCharFontName( RTL_CONSTASCII_USTRINGPARAM("CharFontName")); + const static rtl::OUString sPageStyles( RTL_CONSTASCII_USTRINGPARAM("PageStyles")); + // get the font from the default style + uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xNameAccess( xStyleSupplier->getStyleFamilies(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xNameAccess2( xNameAccess->getByName( sPageStyles ), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xNameAccess2->getByName( sDflt ), uno::UNO_QUERY_THROW ); + rtl::OUString sFontName; + xProps->getPropertyValue( sCharFontName ) >>= sFontName; + + uno::Reference< awt::XDevice > xDevice = getDeviceFromDoc( xModel ); + awt::FontDescriptor aDesc; + aDesc.Name = sFontName; + uno::Reference< awt::XFont > xFont( xDevice->getFont( aDesc ), uno::UNO_QUERY_THROW ); + double nCharPixelWidth = xFont->getCharWidth( (sal_Int8)'0' ); + + double nPixelsPerMeter = xDevice->getInfo().PixelPerMeterX; + double nCharWidth = nCharPixelWidth / nPixelsPerMeter; + nCharWidth = nCharWidth * (double)56700;// in twips + return lcl_TwipsToPoints( (USHORT)nCharWidth ); +} + +uno::Any SAL_CALL +ScVbaRange::getColumnWidth() throw (uno::RuntimeException) +{ + sal_Int32 nLen = m_Areas->getCount(); + if ( nLen > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->getColumnWidth(); + } + + double nColWidth = 0; + ScDocShell* pShell = getScDocShell(); + if ( pShell ) + { + uno::Reference< frame::XModel > xModel = pShell->GetModel(); + double defaultCharWidth = getDefaultCharWidth( xModel ); + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + sal_Int32 nStartCol = thisAddress.StartColumn; + sal_Int32 nEndCol = thisAddress.EndColumn; + USHORT nColTwips = 0; + for( sal_Int32 nCol = nStartCol ; nCol <= nEndCol; ++nCol ) + { + thisAddress.StartColumn = nCol; + USHORT nCurTwips = pShell->GetDocument()->GetOriginalWidth( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCTAB >( thisAddress.Sheet ) ); + if ( nCol == nStartCol ) + nColTwips = nCurTwips; + if ( nColTwips != nCurTwips ) + return aNULL(); + } + nColWidth = lcl_Round2DecPlaces( lcl_TwipsToPoints( nColTwips ) ); + if ( xModel.is() ) + nColWidth = nColWidth / defaultCharWidth; + } + nColWidth = lcl_Round2DecPlaces( nColWidth ); + return uno::makeAny( nColWidth ); +} + +void SAL_CALL +ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = m_Areas->getCount(); + if ( nLen > 1 ) + { + for ( sal_Int32 index = 1; index != nLen; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->setColumnWidth( _columnwidth ); + } + return; + } + double nColWidth = 0; + _columnwidth >>= nColWidth; + nColWidth = lcl_Round2DecPlaces( nColWidth ); + ScDocShell* pDocShell = getScDocShell(); + if ( pDocShell ) + { + uno::Reference< frame::XModel > xModel = pDocShell->GetModel(); + if ( xModel.is() ) + { + + nColWidth = ( nColWidth * getDefaultCharWidth( xModel ) ); + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + USHORT nTwips = lcl_pointsToTwips( nColWidth ); + + ScDocFunc aFunc(*pDocShell); + SCCOLROW nColArr[2]; + nColArr[0] = thisAddress.StartColumn; + nColArr[1] = thisAddress.EndColumn; + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, thisAddress.Sheet, SC_SIZE_ORIGINAL, + nTwips, TRUE, TRUE ); + + } + } +} + +uno::Any SAL_CALL +ScVbaRange::getWidth() throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->getWidth(); + } + uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW ); + sal_Int32 nElems = xIndexAccess->getCount(); + double nWidth = 0; + for ( sal_Int32 index=0; index<nElems; ++index ) + { + uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + double nTmpWidth = getCalcColWidth( xAddressable->getRangeAddress() ); + nWidth += nTmpWidth; + } + return uno::makeAny( nWidth ); +} + +uno::Any SAL_CALL +ScVbaRange::Areas( const uno::Any& item) throw (uno::RuntimeException) +{ + if ( !item.hasValue() ) + return uno::makeAny( m_Areas ); + return m_Areas->Item( item, uno::Any() ); +} + +uno::Reference< excel::XRange > +ScVbaRange::getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException ) +{ + if ( !m_Areas.is() ) + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No areas available")), uno::Reference< uno::XInterface >() ); + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( ++nIndex ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange; +} + +uno::Any +ScVbaRange::Borders( const uno::Any& item ) throw( script::BasicErrorException, uno::RuntimeException ) +{ + if ( !item.hasValue() ) + return uno::makeAny( getBorders() ); + return getBorders()->Item( item, uno::Any() ); +} + +uno::Any SAL_CALL +ScVbaRange::BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& Weight, + const css::uno::Any& ColorIndex, const css::uno::Any& Color ) throw (css::uno::RuntimeException) +{ + sal_Int32 nCount = getBorders()->getCount(); + + for( sal_Int32 i = 0; i < nCount; i++ ) + { + const sal_Int32 nLineType = supportedIndexTable[i]; + switch( nLineType ) + { + case excel::XlBordersIndex::xlEdgeLeft: + case excel::XlBordersIndex::xlEdgeTop: + case excel::XlBordersIndex::xlEdgeBottom: + case excel::XlBordersIndex::xlEdgeRight: + { + uno::Reference< excel::XBorder > xBorder( m_Borders->Item( uno::makeAny( nLineType ), uno::Any() ), uno::UNO_QUERY_THROW ); + if( LineStyle.hasValue() ) + { + xBorder->setLineStyle( LineStyle ); + } + if( Weight.hasValue() ) + { + xBorder->setWeight( Weight ); + } + if( ColorIndex.hasValue() ) + { + xBorder->setColorIndex( ColorIndex ); + } + if( Color.hasValue() ) + { + xBorder->setColor( Color ); + } + break; + } + case excel::XlBordersIndex::xlInsideVertical: + case excel::XlBordersIndex::xlInsideHorizontal: + case excel::XlBordersIndex::xlDiagonalDown: + case excel::XlBordersIndex::xlDiagonalUp: + break; + default: + return uno::makeAny( sal_False ); + } + } + return uno::makeAny( sal_True ); +} + +uno::Any SAL_CALL +ScVbaRange::getRowHeight() throw (uno::RuntimeException) +{ + sal_Int32 nLen = m_Areas->getCount(); + if ( nLen > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->getRowHeight(); + } + + // if any row's RowHeight in the + // range is different from any other then return NULL + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + + sal_Int32 nStartRow = thisAddress.StartRow; + sal_Int32 nEndRow = thisAddress.EndRow; + USHORT nRowTwips = 0; + // #TODO probably possible to use the SfxItemSet ( and see if + // SFX_ITEM_DONTCARE is set ) to improve performance +// #CHECKME looks like this is general behaviour not just row Range specific +// if ( mbIsRows ) + ScDocShell* pShell = getScDocShell(); + if ( pShell ) + { + for ( sal_Int32 nRow = nStartRow ; nRow <= nEndRow; ++nRow ) + { + thisAddress.StartRow = nRow; + USHORT nCurTwips = pShell->GetDocument()->GetOriginalHeight( thisAddress.StartRow, thisAddress.Sheet ); + if ( nRow == nStartRow ) + nRowTwips = nCurTwips; + if ( nRowTwips != nCurTwips ) + return aNULL(); + } + } + double nHeight = lcl_Round2DecPlaces( lcl_TwipsToPoints( nRowTwips ) ); + return uno::makeAny( nHeight ); +} + +void SAL_CALL +ScVbaRange::setRowHeight( const uno::Any& _rowheight) throw (uno::RuntimeException) +{ + sal_Int32 nLen = m_Areas->getCount(); + if ( nLen > 1 ) + { + for ( sal_Int32 index = 1; index != nLen; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->setRowHeight( _rowheight ); + } + return; + } + double nHeight = 0; // Incomming height is in points + _rowheight >>= nHeight; + nHeight = lcl_Round2DecPlaces( nHeight ); + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + USHORT nTwips = lcl_pointsToTwips( nHeight ); + + ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange ); + ScDocFunc aFunc(*pDocShell); + SCCOLROW nRowArr[2]; + nRowArr[0] = thisAddress.StartRow; + nRowArr[1] = thisAddress.EndRow; + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, thisAddress.Sheet, SC_SIZE_ORIGINAL, + nTwips, TRUE, TRUE ); +} + +uno::Any SAL_CALL +ScVbaRange::getPageBreak() throw (uno::RuntimeException) +{ + sal_Int32 nPageBreak = excel::XlPageBreak::xlPageBreakNone; + ScDocShell* pShell = excel::GetDocShellFromRange( mxRange ); + if ( pShell ) + { + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + BOOL bColumn = FALSE; + + if (thisAddress.StartRow==0) + bColumn = TRUE; + + uno::Reference< frame::XModel > xModel = pShell->GetModel(); + if ( xModel.is() ) + { + ScDocument* pDoc = excel::GetDocumentFromRange( mxRange ); + + ScBreakType nBreak = BREAK_NONE; + if ( !bColumn ) + nBreak = pDoc->HasRowBreak(thisAddress.StartRow, thisAddress.Sheet); + else + nBreak = pDoc->HasColBreak(thisAddress.StartColumn, thisAddress.Sheet); + + if (nBreak & BREAK_PAGE) + nPageBreak = excel::XlPageBreak::xlPageBreakAutomatic; + + if (nBreak & BREAK_MANUAL) + nPageBreak = excel::XlPageBreak::xlPageBreakManual; + } + } + + return uno::makeAny( nPageBreak ); +} + +void SAL_CALL +ScVbaRange::setPageBreak( const uno::Any& _pagebreak) throw (uno::RuntimeException) +{ + sal_Int32 nPageBreak = 0; + _pagebreak >>= nPageBreak; + + ScDocShell* pShell = excel::GetDocShellFromRange( mxRange ); + if ( pShell ) + { + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0)) + return; + BOOL bColumn = FALSE; + + if (thisAddress.StartRow==0) + bColumn = TRUE; + + ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet ); + uno::Reference< frame::XModel > xModel = pShell->GetModel(); + if ( xModel.is() ) + { + ScTabViewShell* pViewShell = excel::getBestViewShell( xModel ); + if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual ) + pViewShell->InsertPageBreak( bColumn, TRUE, &aAddr); + else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone ) + pViewShell->DeletePageBreak( bColumn, TRUE, &aAddr); + } + } +} + +uno::Any SAL_CALL +ScVbaRange::getHeight() throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->getHeight(); + } + + uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW ); + sal_Int32 nElems = xIndexAccess->getCount(); + double nHeight = 0; + for ( sal_Int32 index=0; index<nElems; ++index ) + { + uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ); + nHeight += getCalcRowHeight(xAddressable->getRangeAddress() ); + } + return uno::makeAny( nHeight ); +} + +awt::Point +ScVbaRange::getPosition() throw ( uno::RuntimeException ) +{ + awt::Point aPoint; + uno::Reference< beans::XPropertySet > xProps; + if ( mxRange.is() ) + xProps.set( mxRange, uno::UNO_QUERY_THROW ); + else + xProps.set( mxRanges, uno::UNO_QUERY_THROW ); + xProps->getPropertyValue(POSITION) >>= aPoint; + return aPoint; +} +uno::Any SAL_CALL +ScVbaRange::getLeft() throw (uno::RuntimeException) +{ + // helperapi returns the first ranges left ( and top below ) + if ( m_Areas->getCount() > 1 ) + return getArea( 0 )->getLeft(); + awt::Point aPoint = getPosition(); + return uno::makeAny( lcl_hmmToPoints( aPoint.X ) ); +} + + +uno::Any SAL_CALL +ScVbaRange::getTop() throw (uno::RuntimeException) +{ + // helperapi returns the first ranges top + if ( m_Areas->getCount() > 1 ) + return getArea( 0 )->getTop(); + awt::Point aPoint= getPosition(); + return uno::makeAny( lcl_hmmToPoints( aPoint.Y ) ); +} + +uno::Reference< excel::XWorksheet > +ScVbaRange::getWorksheet() throw (uno::RuntimeException) +{ + // #TODO #FIXME parent should always be set up ( currently thats not + // the case ) + uno::Reference< excel::XWorksheet > xSheet( getParent(), uno::UNO_QUERY ); + if ( !xSheet.is() ) + { + uno::Reference< table::XCellRange > xRange = mxRange; + + if ( mxRanges.is() ) // assign xRange to first range + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + xRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + } + ScDocShell* pDocShell = excel::GetDocShellFromRange(xRange); + RangeHelper rHelper(xRange); + // parent should be Thisworkbook + xSheet.set( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), mxContext,rHelper.getSpreadSheet(),pDocShell->GetModel()) ); + } + return xSheet; +} + +// #TODO remove this ugly application processing +// Process an application Range request e.g. 'Range("a1,b2,a4:b6") +uno::Reference< excel::XRange > +ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) throw (css::uno::RuntimeException) +{ + // Althought the documentation seems clear that Range without a + // qualifier then its a shortcut for ActiveSheet.Range + // however, similarly Application.Range is apparently also a + // shortcut for ActiveSheet.Range + // The is however a subtle behavioural difference I've come across + // wrt to named ranges. + // If a named range "test" exists { Sheet1!$A1 } and the active sheet + // is Sheet2 then the following will fail + // msgbox ActiveSheet.Range("test").Address ' failes + // msgbox WorkSheets("Sheet2").Range("test").Address + // but !!! + // msgbox Range("test").Address ' works + // msgbox Application.Range("test").Address ' works + + // Single param Range + rtl::OUString sRangeName; + Cell1 >>= sRangeName; + if ( Cell1.hasValue() && !Cell2.hasValue() && sRangeName.getLength() ) + { + const static rtl::OUString sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges")); + uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW ); + + uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XCellRangeReferrer > xReferrer; + try + { + xReferrer.set ( xNamed->getByName( sRangeName ), uno::UNO_QUERY ); + } + catch( uno::Exception& /*e*/ ) + { + // do nothing + } + if ( xReferrer.is() ) + { + uno::Reference< table::XCellRange > xRange = xReferrer->getReferredCells(); + if ( xRange.is() ) + { + uno::Reference< excel::XRange > xVbRange = new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), xContext, xRange ); + return xVbRange; + } + } + } + + // Add these codes for supporting shortcut: Application.Range(Range1, Range2), Range1 or Range2 is not the range of current active sheet. + // If Range1 and Range2 are not in current active sheet, we should not use the active sheet, but use the sheet of Range1 and Range2. + // If Range1 and Range2 are not in the same sheet, we throw an exception. + uno::Reference< sheet::XSpreadsheet > xSpreadsheet; + uno::Reference< excel::XRange > xRange1( Cell1, uno::UNO_QUERY ), xRange2( Cell2, uno::UNO_QUERY ); + if ( xRange1.is() ) + { + RangeHelper thisRange( xRange1->getCellRange() ); + xSpreadsheet = thisRange.getSpreadSheet(); + } + else if ( xRange2.is() ) + { + RangeHelper thisRange( xRange2->getCellRange() ); + xSpreadsheet = thisRange.getSpreadSheet(); + } + if ( !xSpreadsheet.is() ) + { + uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext ); + if ( xModel.is() ) + { + uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSpreadsheet = xView->getActiveSheet(); + } + } + + uno::Reference< table::XCellRange > xSheetRange( xSpreadsheet, uno::UNO_QUERY_THROW ); + ScVbaRange* pRange = new ScVbaRange( excel::getUnoSheetModuleObj( xSheetRange ), xContext, xSheetRange ); + + uno::Reference< excel::XRange > xVbSheetRange( pRange ); + return pRange->Range( Cell1, Cell2, true ); +} + +// Helper functions for AutoFilter +ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet ) +{ + rtl::OUString sName; + excel::GetAutoFiltRange( pDocShell, nSheet, sName ); + OSL_TRACE("lcl_GetDBData_Impl got autofilter range %s for sheet %d", + rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet ); + ScDBData* pRet = NULL; + if (pDocShell) + { + ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); + if (pNames) + { + USHORT nPos = 0; + if (pNames->SearchName( sName , nPos )) + pRet = (*pNames)[nPos]; + } + } + return pRet; +} + +void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam ) +{ + if ( pDocShell ) + { + ScViewData* pViewData = pDocShell->GetViewData(); + if ( pViewData ) + { + OSL_TRACE("Pushing out SelectAll query"); + pViewData->GetView()->Query( aParam, NULL, TRUE ); + } + } +} + +ScQueryParam lcl_GetQueryParam( ScDocShell* pDocShell, sal_Int16 nSheet ) +{ + ScDBData* pDBData = lcl_GetDBData_Impl( pDocShell, nSheet ); + ScQueryParam aParam; + if (pDBData) + { + pDBData->GetQueryParam( aParam ); + } + return aParam; +} + +void lcl_SetAllQueryForField( ScQueryParam& aParam, SCCOLROW nField ) +{ + bool bFound = false; + SCSIZE i = 0; + for (; i<MAXQUERY && !bFound; i++) + { + ScQueryEntry& rEntry = aParam.GetEntry(i); + if ( rEntry.nField == nField) + { + OSL_TRACE("found at pos %d", i ); + bFound = true; + } + } + if ( bFound ) + { + OSL_TRACE("field %d to delete at pos %d", nField, ( i - 1 ) ); + aParam.DeleteQuery(--i); + } +} + + +void lcl_SetAllQueryForField( ScDocShell* pDocShell, SCCOLROW nField, sal_Int16 nSheet ) +{ + ScQueryParam aParam = lcl_GetQueryParam( pDocShell, nSheet ); + lcl_SetAllQueryForField( aParam, nField ); + lcl_SelectAll( pDocShell, aParam ); +} + +// Modifies sCriteria, and nOp depending on the value of sCriteria +void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference< beans::XPropertySet >& xDescProps, sheet::TableFilterField2& rFilterField ) +{ + // #TODO make this more efficient and cycle through + // sCriteria1 character by character to pick up <,<>,=, * etc. + // right now I am more concerned with just getting it to work right + + sCriteria1 = sCriteria1.trim(); + // table of translation of criteria text to FilterOperators + // <>searchtext - NOT_EQUAL + // =searchtext - EQUAL + // *searchtext - startwith + // <>*searchtext - doesn't startwith + // *searchtext* - contains + // <>*searchtext* - doesn't contain + // [>|>=|<=|...]searchtext for GREATER_value, GREATER_EQUAL_value etc. + sal_Int32 nPos = 0; + bool bIsNumeric = false; + if ( ( nPos = sCriteria1.indexOf( EQUALS ) ) == 0 ) + { + if ( sCriteria1.getLength() == EQUALS.getLength() ) + rFilterField.Operator = sheet::FilterOperator2::EMPTY; + else + { + rFilterField.Operator = sheet::FilterOperator2::EQUAL; + sCriteria1 = sCriteria1.copy( EQUALS.getLength() ); + sCriteria1 = VBAToRegexp( sCriteria1 ); + // UseRegularExpressions + if ( xDescProps.is() ) + xDescProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseRegularExpressions" ) ), uno::Any( sal_True ) ); + } + + } + else if ( ( nPos = sCriteria1.indexOf( NOTEQUALS ) ) == 0 ) + { + if ( sCriteria1.getLength() == NOTEQUALS.getLength() ) + rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY; + else + { + rFilterField.Operator = sheet::FilterOperator2::NOT_EQUAL; + sCriteria1 = sCriteria1.copy( NOTEQUALS.getLength() ); + sCriteria1 = VBAToRegexp( sCriteria1 ); + // UseRegularExpressions + if ( xDescProps.is() ) + xDescProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseRegularExpressions" ) ), uno::Any( sal_True ) ); + } + } + else if ( ( nPos = sCriteria1.indexOf( GREATERTHAN ) ) == 0 ) + { + bIsNumeric = true; + if ( ( nPos = sCriteria1.indexOf( GREATERTHANEQUALS ) ) == 0 ) + { + sCriteria1 = sCriteria1.copy( GREATERTHANEQUALS.getLength() ); + rFilterField.Operator = sheet::FilterOperator2::GREATER_EQUAL; + } + else + { + sCriteria1 = sCriteria1.copy( GREATERTHAN.getLength() ); + rFilterField.Operator = sheet::FilterOperator2::GREATER; + } + + } + else if ( ( nPos = sCriteria1.indexOf( LESSTHAN ) ) == 0 ) + { + bIsNumeric = true; + if ( ( nPos = sCriteria1.indexOf( LESSTHANEQUALS ) ) == 0 ) + { + sCriteria1 = sCriteria1.copy( LESSTHANEQUALS.getLength() ); + rFilterField.Operator = sheet::FilterOperator2::LESS_EQUAL; + } + else + { + sCriteria1 = sCriteria1.copy( LESSTHAN.getLength() ); + rFilterField.Operator = sheet::FilterOperator2::LESS; + } + + } + else + rFilterField.Operator = sheet::FilterOperator2::EQUAL; + + if ( bIsNumeric ) + { + rFilterField.IsNumeric= sal_True; + rFilterField.NumericValue = sCriteria1.toDouble(); + } + rFilterField.StringValue = sCriteria1; +} + +void SAL_CALL +ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const uno::Any& Operator, const uno::Any& Criteria2, const uno::Any& VisibleDropDown ) throw (uno::RuntimeException) +{ + // Is there an existing autofilter + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + sal_Int16 nSheet = thisAddress.Sheet; + ScDocShell* pShell = getScDocShell(); + sal_Bool bHasAuto = sal_False; + rtl::OUString sAutofiltRangeName; + uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet, sAutofiltRangeName ); + if ( xDataBaseRange.is() ) + bHasAuto = true; + + uno::Reference< table::XCellRange > xFilterRange; + if ( !bHasAuto ) + { + if ( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY, uno::Reference< uno::XInterface >() ); + + table::CellRangeAddress autoFiltAddress; + //CurrentRegion() + if ( isSingleCellRange() ) + { + uno::Reference< excel::XRange > xCurrent( CurrentRegion() ); + if ( xCurrent.is() ) + { + ScVbaRange* pRange = getImplementation( xCurrent ); + if ( pRange->isSingleCellRange() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't create AutoFilter") ), uno::Reference< uno::XInterface >() ); + if ( pRange ) + { + RangeHelper currentRegion( pRange->mxRange ); + autoFiltAddress = currentRegion.getCellRangeAddressable()->getRangeAddress(); + } + } + } + else // multi-cell range + { + RangeHelper multiCellRange( mxRange ); + autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress(); + } + + uno::Reference< sheet::XDatabaseRanges > xDBRanges = excel::GetDataBaseRanges( pShell ); + if ( xDBRanges.is() ) + { + rtl::OUString sGenName( RTL_CONSTASCII_USTRINGPARAM("VBA_Autofilter_") ); + sGenName += rtl::OUString::valueOf( static_cast< sal_Int32 >( nSheet ) ); + OSL_TRACE("Going to add new autofilter range.. name %s", + rtl::OUStringToOString( sGenName, RTL_TEXTENCODING_UTF8 ).getStr() , nSheet ); + if ( !xDBRanges->hasByName( sGenName ) ) + xDBRanges->addNewByName( sGenName, autoFiltAddress ); + xDataBaseRange.set( xDBRanges->getByName( sGenName ), uno::UNO_QUERY_THROW ); + } + if ( !xDataBaseRange.is() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Failed to find the autofilter placeholder range" ) ), uno::Reference< uno::XInterface >() ); + + uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW ); + // set autofilt + xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(sal_True) ); + // set header + uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW ); + sal_Bool bHasColHeader = sal_False; + ScDocument* pDoc = pShell ? pShell->GetDocument() : NULL; + + bHasColHeader = pDoc->HasColHeader( static_cast< SCCOL >( autoFiltAddress.StartColumn ), static_cast< SCROW >( autoFiltAddress.StartRow ), static_cast< SCCOL >( autoFiltAddress.EndColumn ), static_cast< SCROW >( autoFiltAddress.EndRow ), static_cast< SCTAB >( autoFiltAddress.Sheet ) ) ? sal_True : sal_False; + xFiltProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ContainsHeader") ), uno::Any( bHasColHeader ) ); + } + + + sal_Int32 nField = 0; // *IS* 1 based + rtl::OUString sCriteria1; + sal_Int32 nOperator = excel::XlAutoFilterOperator::xlAnd; + + sal_Bool bVisible = sal_True; + bool bChangeDropDown = false; + VisibleDropDown >>= bVisible; + + if ( bVisible == bHasAuto ) // dropdown is displayed/notdisplayed as + // required + bVisible = sal_False; + else + bChangeDropDown = true; + sheet::FilterConnection nConn = sheet::FilterConnection_AND; + double nCriteria1 = 0; + + bool bHasCritValue = Criteria1.hasValue(); + bool bCritHasNumericValue = sal_False; // not sure if a numeric criteria is possible + if ( bHasCritValue ) + bCritHasNumericValue = ( Criteria1 >>= nCriteria1 ); + + if ( !Field.hasValue() && ( Criteria1.hasValue() || Operator.hasValue() || Criteria2.hasValue() ) ) + throw uno::RuntimeException(); + // Use the normal uno api, sometimes e.g. when you want to use ALL as the filter + // we can't use refresh as the uno interface doesn't have a concept of ALL + // in this case we just call the core calc functionality - + bool bAll = false; + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + bool bIsValidFieldValue = ( Field >>= nField ); + if ( !bIsValidFieldValue && xConverter.is() ) + { + try + { + uno::Any aConverted = xConverter->convertTo( Field, getCppuType( (sal_Int32*)0 ) ); + bIsValidFieldValue = ( aConverted >>= nField ); + } + catch( const uno::Exception& ex ) + { + } + } + if ( bIsValidFieldValue ) + { + uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc( + xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY ); + if ( xDesc.is() ) + { + uno::Sequence< sheet::TableFilterField2 > sTabFilts; + uno::Reference< beans::XPropertySet > xDescProps( xDesc, uno::UNO_QUERY_THROW ); + if ( Criteria1.hasValue() ) + { + sTabFilts.realloc( 1 ); + sTabFilts[0].Operator = sheet::FilterOperator2::EQUAL;// sensible default + if ( !bCritHasNumericValue ) + { + Criteria1 >>= sCriteria1; + sTabFilts[0].IsNumeric = bCritHasNumericValue; + if ( bHasCritValue && sCriteria1.getLength() ) + lcl_setTableFieldsFromCriteria( sCriteria1, xDescProps, sTabFilts[0] ); + else + bAll = true; + } + else // numeric + { + sTabFilts[0].IsNumeric = sal_True; + sTabFilts[0].NumericValue = nCriteria1; + } + } + else // no value specified + bAll = true; + // not sure what the relationship between Criteria1 and Operator is, + // e.g. can you have a Operator without a Criteria ? in openoffice it + bool bIsValidOpValue = ( Operator.hasValue() && ( Operator >>= nOperator ) ); + if ( Operator.hasValue() && !bIsValidOpValue && xConverter.is() ) + { + try + { + uno::Any aConverted = xConverter->convertTo( Operator, getCppuType( (sal_Int32*)0 ) ); + bIsValidOpValue = ( aConverted >>= nOperator ); + } + catch( const uno::Exception& ex ) + { + } + } + if ( bIsValidOpValue ) + { + // if its a bottom/top Ten(Percent/Value) and there + // is no value specified for critera1 set it to 10 + if ( !bCritHasNumericValue && !sCriteria1.getLength() && ( nOperator != excel::XlAutoFilterOperator::xlOr ) && ( nOperator != excel::XlAutoFilterOperator::xlAnd ) ) + { + sTabFilts[0].IsNumeric = sal_True; + sTabFilts[0].NumericValue = 10; + bAll = false; + } + switch ( nOperator ) + { + case excel::XlAutoFilterOperator::xlBottom10Items: + sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_VALUES; + break; + case excel::XlAutoFilterOperator::xlBottom10Percent: + sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_PERCENT; + break; + case excel::XlAutoFilterOperator::xlTop10Items: + sTabFilts[0].Operator = sheet::FilterOperator2::TOP_VALUES; + break; + case excel::XlAutoFilterOperator::xlTop10Percent: + sTabFilts[0].Operator = sheet::FilterOperator2::TOP_PERCENT; + break; + case excel::XlAutoFilterOperator::xlOr: + nConn = sheet::FilterConnection_OR; + break; + case excel::XlAutoFilterOperator::xlAnd: + nConn = sheet::FilterConnection_AND; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UnknownOption") ), uno::Reference< uno::XInterface >() ); + + } + + } + if ( !bAll ) + { + sTabFilts[0].Connection = sheet::FilterConnection_AND; + sTabFilts[0].Field = (nField - 1); + + rtl::OUString sCriteria2; + if ( Criteria2.hasValue() ) // there is a Criteria2 + { + sTabFilts.realloc(2); + sTabFilts[1].Field = sTabFilts[0].Field; + sTabFilts[1].Connection = nConn; + + if ( Criteria2 >>= sCriteria2 ) + { + if ( sCriteria2.getLength() > 0 ) + { + uno::Reference< beans::XPropertySet > xProps; + lcl_setTableFieldsFromCriteria( sCriteria2, xProps, sTabFilts[1] ); + sTabFilts[1].IsNumeric = sal_False; + } + } + else // numeric + { + Criteria2 >>= sTabFilts[1].NumericValue; + sTabFilts[1].IsNumeric = sal_True; + sTabFilts[1].Operator = sheet::FilterOperator2::EQUAL; + } + } + } + + xDesc->setFilterFields2( sTabFilts ); + if ( !bAll ) + { + xDataBaseRange->refresh(); + } + else + // was 0 based now seems to be 1 + lcl_SetAllQueryForField( pShell, nField, nSheet ); + } + } + else + { + // this is just to toggle autofilter on and off ( not to be confused with + // a VisibleDropDown option combined with a field, in that case just the + // button should be disabled ) - currently we don't support that + bChangeDropDown = true; + uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW ); + if ( bHasAuto ) + { + // find the any field with the query and select all + ScQueryParam aParam = lcl_GetQueryParam( pShell, nSheet ); + SCSIZE i = 0; + for (; i<MAXQUERY; i++) + { + ScQueryEntry& rEntry = aParam.GetEntry(i); + if ( rEntry.bDoQuery ) + lcl_SetAllQueryForField( pShell, rEntry.nField, nSheet ); + } + // remove exising filters + uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor( + xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY ); + if( xSheetFilterDescriptor.is() ) + xSheetFilterDescriptor->setFilterFields2( uno::Sequence< sheet::TableFilterField2 >() ); + } + xDBRangeProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AutoFilter") ), uno::Any(!bHasAuto) ); + + } +} + +void SAL_CALL +ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& CopyOrigin ) throw (uno::RuntimeException) +{ + sal_Bool bCopyOrigin = sal_True; + CopyOrigin >>= bCopyOrigin; + // It appears ( from the web ) that the undocumented CopyOrigin + // param should contain member of enum XlInsertFormatOrigin + // which can have values xlFormatFromLeftOrAbove or xlFormatFromRightOrBelow + // #TODO investigate resultant behaviour using these constants + // currently just processing Shift + + sheet::CellInsertMode mode = sheet::CellInsertMode_NONE; + if ( Shift.hasValue() ) + { + sal_Int32 nShift = 0; + Shift >>= nShift; + switch ( nShift ) + { + case excel::XlInsertShiftDirection::xlShiftToRight: + mode = sheet::CellInsertMode_RIGHT; + break; + case excel::XlInsertShiftDirection::xlShiftDown: + mode = sheet::CellInsertMode_DOWN; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("Illegal paramater ") ), uno::Reference< uno::XInterface >() ); + } + } + else + { + if ( getRow() >= getColumn() ) + mode = sheet::CellInsertMode_DOWN; + else + mode = sheet::CellInsertMode_RIGHT; + } + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); + xCellRangeMove->insertCells( thisAddress, mode ); + if ( bCopyOrigin ) + { + // After the insert ( this range ) actually has moved + ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) ); + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( excel::GetDocShellFromRange( mxRange ) , aRange ) ); + uno::Reference< excel::XRange > xVbaRange( new ScVbaRange( mxParent, mxContext, xRange, mbIsRows, mbIsColumns ) ); + xVbaRange->PasteSpecial( uno::Any(), uno::Any(), uno::Any(), uno::Any() ); + } +} + +void SAL_CALL +ScVbaRange::Autofit() throw (uno::RuntimeException) +{ + sal_Int32 nLen = m_Areas->getCount(); + if ( nLen > 1 ) + { + for ( sal_Int32 index = 1; index != nLen; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->Autofit(); + } + return; + } + // if the range is a not a row or column range autofit will + // throw an error + + if ( !( mbIsColumns || mbIsRows ) ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange ); + if ( pDocShell ) + { + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + + ScDocFunc aFunc(*pDocShell); + SCCOLROW nColArr[2]; + nColArr[0] = thisAddress.StartColumn; + nColArr[1] = thisAddress.EndColumn; + BOOL bDirection = TRUE; + if ( mbIsRows ) + { + bDirection = FALSE; + nColArr[0] = thisAddress.StartRow; + nColArr[1] = thisAddress.EndRow; + } + aFunc.SetWidthOrHeight( bDirection, 1, nColArr, thisAddress.Sheet, SC_SIZE_OPTIMAL, + 0, TRUE, TRUE ); + + } +} + +/*************************************************************************************** + * interface for text: + * com.sun.star.text.XText, com.sun.star.table.XCell, com.sun.star.container.XEnumerationAccess + * com.sun.star.text.XTextRange, + * the main problem is to recognize the numeric and date, which assosiate with DecimalSeparator, ThousandsSeparator, + * TrailingMinusNumbers and FieldInfo. +***************************************************************************************/ +void SAL_CALL +ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier, + const css::uno::Any& ConsecutiveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma, + const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo, + const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& /*TrailingMinusNumbers*/ ) throw (css::uno::RuntimeException) +{ + uno::Reference< excel::XRange > xRange; + if( Destination.hasValue() ) + { + if( !( Destination >>= xRange ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Destination parameter should be a range" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set range\n"); + } + else + { + //set as current + xRange = this; + OSL_TRACE("set range as himself\n"); + } + + sal_Int16 xlTextParsingType = excel::XlTextParsingType::xlDelimited; + if ( DataType.hasValue() ) + { + if( !( DataType >>= xlTextParsingType ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "DataType parameter should be a short" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set Datatype\n" ); + } + sal_Bool bDilimited = ( xlTextParsingType == excel::XlTextParsingType::xlDelimited ); + + sal_Int16 xlTextQualifier = excel::XlTextQualifier::xlTextQualifierDoubleQuote; + if( TextQualifier.hasValue() ) + { + if( !( TextQualifier >>= xlTextQualifier )) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "TextQualifier parameter should be a short" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set TextQualifier\n"); + } + + sal_Bool bConsecutiveDelimiter = sal_False; + if( ConsecutiveDelimiter.hasValue() ) + { + if( !( ConsecutiveDelimiter >>= bConsecutiveDelimiter ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "ConsecutiveDelimiter parameter should be a boolean" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set ConsecutiveDelimiter\n"); + } + + sal_Bool bTab = sal_False; + if( Tab.hasValue() && bDilimited ) + { + if( !( Tab >>= bTab ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Tab parameter should be a boolean" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set Tab\n"); + } + + sal_Bool bSemicolon = sal_False; + if( Semicolon.hasValue() && bDilimited ) + { + if( !( Semicolon >>= bSemicolon ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Semicolon parameter should be a boolean" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set Semicolon\n"); + } + sal_Bool bComma = sal_False; + if( Comma.hasValue() && bDilimited ) + { + if( !( Comma >>= bComma ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Comma parameter should be a boolean" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set Comma\n"); + } + sal_Bool bSpace = sal_False; + if( Space.hasValue() && bDilimited ) + { + if( !( Space >>= bSpace ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Space parameter should be a boolean" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set Space\n"); + } + sal_Bool bOther = sal_False; + rtl::OUString sOtherChar; + if( Other.hasValue() && bDilimited ) + { + if( Other >>= bOther ) + { + if( OtherChar.hasValue() ) + if( !( OtherChar >>= sOtherChar ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "OtherChar parameter should be a String" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set OtherChar\n" ); + } + else if( bOther ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Other parameter should be a True" ), + uno::Reference< uno::XInterface >() ); + } + // FieldInfo, Optional Variant. An array containing parse information for the individual columns of data. + // The interpretation depends on the value of DataType. When the data is delimited, this argument is an array + // of two-element arrays, with each two-element array specifying the conversion options for a particular column. + // The first element is the column number (1-based), and the second element is one of the xlColumnDataType + // constants specifying how the column is parsed. + uno::Sequence< uno::Sequence< uno::Any > > sFieldInfo; + FieldInfo >>= sFieldInfo; + + rtl::OUString sDecimalSeparator; + if( DecimalSeparator.hasValue() ) + { + if( !( DecimalSeparator >>= sDecimalSeparator ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "DecimalSeparator parameter should be a String" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set DecimalSeparator\n" ); + } + rtl::OUString sThousandsSeparator; + if( ThousandsSeparator.hasValue() ) + { + if( !( ThousandsSeparator >>= sThousandsSeparator ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "ThousandsSeparator parameter should be a String" ), + uno::Reference< uno::XInterface >() ); + OSL_TRACE("set ThousandsSpeparator\n" ); + } + //TODO* TrailingMinusNumbers Optional Variant. Numbers that begin with a minus character. + + // Get the destination range's left-upper cell address. + ScVbaRange* pDestVbaRange = dynamic_cast< ScVbaRange* >( xRange.get() ); + ScAddress aScDestAddress; + if ( pDestVbaRange ) + { + ScUnoConversion::FillScAddress( aScDestAddress, pDestVbaRange->getLeftUpperCellAddress() ); + } + + // Parse the value of parameter FieldInfo. + USHORT nCount = 0, nRealCount = 0; + xub_StrLen* pColumns = NULL; + BYTE* pFormats = NULL; + if ( sFieldInfo.getLength() > 0 ) + { + nCount = sFieldInfo.getLength(); + pColumns = new xub_StrLen[nCount]; + pFormats = new BYTE[nCount]; + USHORT nFormat = 1; + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) + { + if ( sFieldInfo[nIndex].getLength() >= 2 ) + { + nFormat = 1; + try + { + uno::Any aConverted = xConverter->convertTo( sFieldInfo[nIndex][0], getCppuType((xub_StrLen*)0) ); + aConverted >>= pColumns[nRealCount]; + aConverted = xConverter->convertTo( sFieldInfo[nIndex][1], getCppuType((USHORT*)0) ); + aConverted >>= nFormat; + } + catch( const uno::Exception& ) + { + } + pFormats[nRealCount++] = nFormat; + } + } + } + + sal_Unicode cTextQualifier = '"'; + cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierNone ? '\0' : cTextQualifier; + cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierSingleQuote ? '\'' : cTextQualifier; + + // Get field delimiters. + String rFieldDelimiters; + if ( bTab ) rFieldDelimiters += '\t'; + if ( bSemicolon ) rFieldDelimiters += ';'; + if ( bComma ) rFieldDelimiters += ','; + if ( bSpace ) rFieldDelimiters += ' '; + if ( bOther ) rFieldDelimiters += *sOtherChar.getStr(); + + // Get the text in current range to SvMemoryStream. + ScRange aSrcScRange; + ScCellRangesBase* pSrcCellRangesBase = getCellRangesBase(); + if ( pSrcCellRangesBase ) + { + ScRangeList aRangeList = pSrcCellRangesBase->GetRangeList(); + if ( aRangeList.First() ) + { + aSrcScRange = *aRangeList.First(); + } + } + ScImportExport aExport( getScDocument(), aSrcScRange ); + aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) ); + SvMemoryStream aStream; + aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); + ScImportExport::SetNoEndianSwap( aStream ); + aExport.ExportStream( aStream, String(), FORMAT_STRING ); + aStream.Seek( 0 ); + + // Set ScAsciiOptions according to the input parameters. + ScAsciiOptions aOptions; + aOptions.SetFixedLen( !bDilimited ); + aOptions.SetStartRow( 0 ); + aOptions.SetColInfo( nRealCount, pColumns, pFormats ); + if ( bDilimited ) + { + aOptions.SetFieldSeps( rFieldDelimiters ); + aOptions.SetMergeSeps( bConsecutiveDelimiter ); + aOptions.SetTextSep( cTextQualifier ); + } + + // Split the String in to columns. + if ( pDestVbaRange && pDestVbaRange->getScDocument() ) + { + ScImportExport aImport( pDestVbaRange->getScDocument(), aScDestAddress ); + aImport.SetExtOptions( aOptions ); + aImport.SetApi( false ); + aImport.ImportStream( aStream, String(), FORMAT_STRING ); + } + if ( pColumns ) + { + DELETEZ( pColumns ); + } + if ( pFormats ) + { + DELETEZ( pFormats ); + } +} + +uno::Any SAL_CALL +ScVbaRange::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + /* The range object always returns a new Hyperlinks object containing a + fixed list of existing hyperlinks in the range. + See vbahyperlinks.hxx for more details. */ + + // get the global hyperlink object of the sheet (sheet should always be the parent of a Range object) + uno::Reference< excel::XWorksheet > xWorksheet( getParent(), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XHyperlinks > xSheetHlinks( xWorksheet->Hyperlinks( uno::Any() ), uno::UNO_QUERY_THROW ); + ScVbaHyperlinksRef xScSheetHlinks( dynamic_cast< ScVbaHyperlinks* >( xSheetHlinks.get() ) ); + if( !xScSheetHlinks.is() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain hyperlinks implementation object" ) ), uno::Reference< uno::XInterface >() ); + + // create a new local hyperlinks object based on the sheet hyperlinks + ScVbaHyperlinksRef xHlinks( new ScVbaHyperlinks( getParent(), mxContext, xScSheetHlinks, getScRangeList() ) ); + if( aIndex.hasValue() ) + return xHlinks->Item( aIndex, uno::Any() ); + return uno::Any( uno::Reference< excel::XHyperlinks >( xHlinks.get() ) ); +} + +css::uno::Reference< excel::XValidation > SAL_CALL +ScVbaRange::getValidation() throw (css::uno::RuntimeException) +{ + if ( !m_xValidation.is() ) + m_xValidation = new ScVbaValidation( this, mxContext, mxRange ); + return m_xValidation; +} + +namespace { + +sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCell >& rxCell ) throw (uno::RuntimeException) +{ + /* TODO/FIXME: We need an apostroph-prefix property at the cell to + implement this correctly. For now, return an apostroph for every text + cell. + + TODO/FIXME: When Application.TransitionNavigKeys is supported and true, + this function needs to inspect the cell formatting and return different + prefixes according to the horizontal cell alignment. + */ + return (rxCell->getType() == table::CellContentType_TEXT) ? '\'' : 0; +} + +sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCellRange >& rxRange ) throw (uno::RuntimeException) +{ + /* This implementation is able to handle different prefixes (needed if + Application.TransitionNavigKeys is true). The function lclGetPrefixChar + for single cells called from here may return any prefix. If that + function returns an empty prefix (NUL character) or different non-empty + prefixes for two cells, this function returns 0. + */ + sal_Unicode cCurrPrefix = 0; + table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxRange ); + sal_Int32 nEndCol = aRangeAddr.EndColumn - aRangeAddr.StartColumn; + sal_Int32 nEndRow = aRangeAddr.EndRow - aRangeAddr.StartRow; + for( sal_Int32 nRow = 0; nRow <= nEndRow; ++nRow ) + { + for( sal_Int32 nCol = 0; nCol <= nEndCol; ++nCol ) + { + uno::Reference< table::XCell > xCell( rxRange->getCellByPosition( nCol, nRow ), uno::UNO_SET_THROW ); + sal_Unicode cNewPrefix = lclGetPrefixChar( xCell ); + if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) ) + return 0; + cCurrPrefix = cNewPrefix; + } + } + // all cells contain the same prefix - return it + return cCurrPrefix; +} + +sal_Unicode lclGetPrefixChar( const uno::Reference< sheet::XSheetCellRangeContainer >& rxRanges ) throw (uno::RuntimeException) +{ + sal_Unicode cCurrPrefix = 0; + uno::Reference< container::XEnumerationAccess > xRangesEA( rxRanges, uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration > xRangesEnum( xRangesEA->createEnumeration(), uno::UNO_SET_THROW ); + while( xRangesEnum->hasMoreElements() ) + { + uno::Reference< table::XCellRange > xRange( xRangesEnum->nextElement(), uno::UNO_QUERY_THROW ); + sal_Unicode cNewPrefix = lclGetPrefixChar( xRange ); + if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) ) + return 0; + cCurrPrefix = cNewPrefix; + } + // all ranges contain the same prefix - return it + return cCurrPrefix; +} + +inline uno::Any lclGetPrefixVariant( sal_Unicode cPrefixChar ) +{ + return uno::Any( (cPrefixChar == 0) ? ::rtl::OUString() : ::rtl::OUString( cPrefixChar ) ); +} + +} // namespace + +uno::Any SAL_CALL ScVbaRange::getPrefixCharacter() throw (uno::RuntimeException) +{ + /* (1) If Application.TransitionNavigKeys is false, this function returns + an apostroph character if the text cell begins with an apostroph + character (formula return values are not taken into account); otherwise + an empty string. + + (2) If Application.TransitionNavigKeys is true, this function returns + an apostroph character, if the cell is left-aligned; a double-quote + character, if the cell is right-aligned; a circumflex character, if the + cell is centered; a backslash character, if the cell is set to filled; + or an empty string, if nothing of the above. + + If a range or a list of ranges contains texts with leading apostroph + character as well as other cells, this function returns an empty + string. + */ + + if( mxRange.is() ) + return lclGetPrefixVariant( lclGetPrefixChar( mxRange ) ); + if( mxRanges.is() ) + return lclGetPrefixVariant( lclGetPrefixChar( mxRanges ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected empty Range object" ) ), uno::Reference< uno::XInterface >() ); +} + +uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException) +{ + // #FIXME, If the specified range is in a PivotTable report + + // In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception + if( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not get Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() ); + + sal_Bool bShowDetail = sal_False; + + RangeHelper helper( mxRange ); + uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor(); + xSheetCellCursor->collapseToCurrentRegion(); + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW); + table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress(); + + // check if the specified range is a single summary column or row. + table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress(); + if( (thisAddress.StartRow == thisAddress.EndRow && thisAddress.EndRow == aOutlineAddress.EndRow ) || + (thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn )) + { + sal_Bool bColumn =thisAddress.StartRow == thisAddress.EndRow ? sal_False:sal_True; + ScDocument* pDoc = excel::GetDocumentFromRange( mxRange ); + ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(thisAddress.Sheet), sal_True); + const ScOutlineArray* pOutlineArray = bColumn ? pOutlineTable->GetColArray(): pOutlineTable->GetRowArray(); + if( pOutlineArray ) + { + SCCOLROW nPos = bColumn ? (SCCOLROW)(thisAddress.EndColumn-1):(SCCOLROW)(thisAddress.EndRow-1); + ScOutlineEntry* pEntry = pOutlineArray->GetEntryByPos( 0, nPos ); + if( pEntry ) + { + bShowDetail = !pEntry->IsHidden(); + return uno::makeAny( bShowDetail ); + } + } + } + else + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() ); + } + return aNULL(); +} + +void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) throw ( css::uno::RuntimeException) +{ + // #FIXME, If the specified range is in a PivotTable report + + // In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception + if( m_Areas->getCount() > 1 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() ); + + bool bShowDetail = extractBoolFromAny( aShowDetail ); + + RangeHelper helper( mxRange ); + uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor(); + xSheetCellCursor->collapseToCurrentRegion(); + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW); + table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress(); + + // check if the specified range is a single summary column or row. + table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress(); + if( (thisAddress.StartRow == thisAddress.EndRow && thisAddress.EndRow == aOutlineAddress.EndRow ) || + (thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn )) + { + // #FIXME, seems there is a different behavior between MSO and OOo. + // In OOo, the showDetail will show all the level entrys, while only show the first level entry in MSO + uno::Reference< sheet::XSheetOutline > xSheetOutline( helper.getSpreadSheet(), uno::UNO_QUERY_THROW ); + if( bShowDetail ) + xSheetOutline->showDetail( aOutlineAddress ); + else + xSheetOutline->hideDetail( aOutlineAddress ); + } + else + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can not set Range.ShowDetail attribute ")), uno::Reference< uno::XInterface >() ); + } +} + +//09-09-16 add by limingl +::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL +ScVbaRange::getQueryTable() throw (::com::sun::star::uno::RuntimeException) +{ + /* + if (m_pQueryTable == NULL) + { + m_pQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this); //add by limingl + } + //*/ + if (!m_xQueryTable.is()) + { + m_xQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this); //add by limingl + } + + return m_xQueryTable; +} +//end add +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< sheet::XSheetCellRange > xMergeShellCellRange(mxRange->getCellRangeByPosition(0,0,0,0), uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellCursor > xMergeSheetCursor(xMergeShellCellRange->getSpreadsheet()->createCursorByRange( xMergeShellCellRange ), uno::UNO_QUERY_THROW); + if( xMergeSheetCursor.is() ) + { + xMergeSheetCursor->collapseToMergedArea(); + uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress(xMergeSheetCursor, uno::UNO_QUERY_THROW); + if( xMergeCellAddress.is() ) + { + table::CellRangeAddress aCellAddress = xMergeCellAddress->getRangeAddress(); + if( aCellAddress.StartColumn ==0 && aCellAddress.EndColumn==0 && + aCellAddress.StartRow==0 && aCellAddress.EndRow==0) + { + return new ScVbaRange( mxParent,mxContext,mxRange ); + } + else + { + ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ), + static_cast< SCCOL >( aCellAddress.EndColumn ), static_cast< SCROW >( aCellAddress.EndRow ), static_cast< SCTAB >( aCellAddress.Sheet ) ); + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) ); + return new ScVbaRange( mxParent, mxContext,xRange ); + } + } + } + return new ScVbaRange( mxParent, mxContext, mxRange ); +} + +//2008-08-25 add by limingl +//The recordset's member: Recordset.Fields.Item will get a Field obj. +//Field.value is the column value. +::sal_Int32 SAL_CALL +ScVbaRange::CopyFromRecordset( const ::com::sun::star::uno::Any& Data, const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns ) +throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException) +{ + uno::Sequence< uno::Any > aParams; + uno::Sequence< uno::Any > aFieldsParams(1); + uno::Sequence< sal_Int16 > aOutParamIndex; + uno::Sequence< uno::Any > aOutParam; + uno::Reference< uno::XInterface > xIntRes; + uno::Reference< uno::XInterface > xIntFields; + uno::Reference< uno::XInterface > xIntFld; + uno::Any aRet; + uno::Any aPar; + uno::Any aCrrCol; + uno::Any aCrrRow; + sal_Int16 nCrrCol = 0; + sal_Int32 nCrrRow = 0; + sal_Int32 nCol; + sal_Int32 nMaxRows = 0; + sal_Int32 nMaxColumns = 0; + sal_Bool bEof; +// sal_Bool bColName = sal_True; + long lColCnt = 0; + if (MaxColumns.hasValue()) + { + MaxColumns >>= nMaxColumns; + } + + long lMaxCol = nMaxColumns; + + if (MaxRows.hasValue()) + { + MaxRows >>= nMaxRows; + } + + + Data >>= xIntRes; + uno::Reference< script::XInvocation > xInvRes(xIntRes, uno::UNO_QUERY_THROW); + rtl::OUString oMoveNext = rtl::OUString::createFromAscii("MoveNext") ; + rtl::OUString oEof = rtl::OUString::createFromAscii("EOF") ; + rtl::OUString oFields = rtl::OUString::createFromAscii("Fields") ; + + if( !xInvRes->hasMethod(oMoveNext)) + { + return -1; + } + + //Get columns count + aRet = xInvRes->getValue(oFields); + aRet >>= xIntFields; + uno::Reference< script::XInvocation > xInvFields(xIntFields, uno::UNO_QUERY_THROW); + aRet = xInvFields->getValue( rtl::OUString::createFromAscii("Count")) ; + aRet >>= lColCnt; + + //Set the assign column number + if (lMaxCol != 0) + { + if (lColCnt > lMaxCol) + { + lColCnt = lMaxCol; + } + } + + aCrrRow <<= nCrrRow; + aCrrCol <<= nCrrCol; + + + //Get start position + uno::Reference< excel::XRange > xRngStartRow = Rows(uno::Any(sal_Int32(1)) ); + uno::Reference< excel::XRange > xRngPos = xRngStartRow->Columns( uno::Any(sal_Int32(1)) ); + + while(1) + {//travel recordset + //get every column + for (long l = 0; l < lColCnt ; l++) + { + nCol = l; + aPar <<= nCol; + //get every field + aRet = xInvFields->invoke( rtl::OUString::createFromAscii("Item"), uno::Sequence< uno::Any >(&aPar,1) , aOutParamIndex,aOutParam); + aRet >>= xIntFld; + uno::Reference< script::XInvocation > xInvFld(xIntFld, uno::UNO_QUERY_THROW); //Get the Field obj + + //set the field value + aRet = xInvFld->getValue( rtl::OUString::createFromAscii("Value") ); + uno::Reference< excel::XRange > xRngToFill = xRngPos->Offset(aCrrRow,aCrrCol ); + + xRngToFill->setValue(aRet); + nCrrCol++; + aCrrCol <<= nCrrCol; + } + + aRet = xInvRes->invoke(oMoveNext, aParams,aOutParamIndex,aOutParam ); + aRet = xInvRes->getValue(oEof); + aRet >>= bEof; + if (bEof || ( nCrrRow >= nMaxRows && nMaxRows != 0) ) + {//Arrive the end of recordset + break; + } + + nCrrRow++; + aCrrRow <<= nCrrRow; + nCrrCol = 0; + aCrrCol <<= nCrrCol; + } + + return 0; +} +//end add +void SAL_CALL +ScVbaRange::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 ) throw (uno::RuntimeException) +{ + ScDocShell* pShell = NULL; + + sal_Int32 nItems = m_Areas->getCount(); + uno::Sequence< table::CellRangeAddress > printAreas( nItems ); + uno::Reference< sheet::XPrintAreas > xPrintAreas; + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + + RangeHelper thisRange( xRange->getCellRange() ); + table::CellRangeAddress rangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + if ( index == 1 ) + { + ScVbaRange* pRange = getImplementation( xRange ); + // initialise the doc shell and the printareas + pShell = excel::GetDocShellFromRange( pRange->mxRange ); + xPrintAreas.set( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); + } + printAreas[ index - 1 ] = rangeAddress; + } + if ( pShell ) + { + if ( xPrintAreas.is() ) + { + xPrintAreas->setPrintAreas( printAreas ); + uno::Reference< frame::XModel > xModel = pShell->GetModel(); + PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True ); + } + } +} + +void SAL_CALL +ScVbaRange::AutoFill( const uno::Reference< excel::XRange >& Destination, const uno::Any& Type ) throw (uno::RuntimeException) +{ + uno::Reference< excel::XRange > xDest( Destination, uno::UNO_QUERY_THROW ); + ScVbaRange* pRange = getImplementation( xDest ); + RangeHelper destRangeHelper( pRange->mxRange ); + table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress(); + + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + ScRange sourceRange; + ScRange destRange; + + ScUnoConversion::FillScRange( destRange, destAddress ); + ScUnoConversion::FillScRange( sourceRange, thisAddress ); + + + // source is valid +// if ( !sourceRange.In( destRange ) ) +// throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "source not in destination" ) ), uno::Reference< uno::XInterface >() ); + + FillDir eDir = FILL_TO_BOTTOM; + double fStep = 1.0; + + ScRange aRange( destRange ); + ScRange aSourceRange( destRange ); + + // default to include the number of Rows in the source range; + SCCOLROW nSourceCount = ( sourceRange.aEnd.Row() - sourceRange.aStart.Row() ) + 1; + SCCOLROW nCount = 0; + + if ( sourceRange != destRange ) + { + // Find direction of fill, vertical or horizontal + if ( sourceRange.aStart == destRange.aStart ) + { + if ( sourceRange.aEnd.Row() == destRange.aEnd.Row() ) + { + nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() + 1 ); + aSourceRange.aEnd.SetCol( static_cast<SCCOL>( aSourceRange.aStart.Col() + nSourceCount - 1 ) ); + eDir = FILL_TO_RIGHT; + nCount = aRange.aEnd.Col() - aSourceRange.aEnd.Col(); + } + else if ( sourceRange.aEnd.Col() == destRange.aEnd.Col() ) + { + aSourceRange.aEnd.SetRow( static_cast<SCROW>( aSourceRange.aStart.Row() + nSourceCount ) - 1 ); + nCount = aRange.aEnd.Row() - aSourceRange.aEnd.Row(); + eDir = FILL_TO_BOTTOM; + } + } + + else if ( aSourceRange.aEnd == destRange.aEnd ) + { + if ( sourceRange.aStart.Col() == destRange.aStart.Col() ) + { + aSourceRange.aStart.SetRow( static_cast<SCROW>( aSourceRange.aEnd.Row() - nSourceCount + 1 ) ); + nCount = aSourceRange.aStart.Row() - aRange.aStart.Row(); + eDir = FILL_TO_TOP; + fStep = -fStep; + } + else if ( sourceRange.aStart.Row() == destRange.aStart.Row() ) + { + nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() ) + 1; + aSourceRange.aStart.SetCol( static_cast<SCCOL>( aSourceRange.aEnd.Col() - nSourceCount + 1 ) ); + nCount = aSourceRange.aStart.Col() - aRange.aStart.Col(); + eDir = FILL_TO_LEFT; + fStep = -fStep; + } + } + } + ScDocShell* pDocSh= excel::GetDocShellFromRange( mxRange ); + + FillCmd eCmd = FILL_AUTO; + FillDateCmd eDateCmd = FILL_DAY; + +#ifdef VBA_OOBUILD_HACK + double fEndValue = MAXDOUBLE; +#endif + + if ( Type.hasValue() ) + { + sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault; + Type >>= nFillType; + switch ( nFillType ) + { + case excel::XlAutoFillType::xlFillCopy: + eCmd = FILL_SIMPLE; + fStep = 0.0; + break; + case excel::XlAutoFillType::xlFillDays: + eCmd = FILL_DATE; + break; + case excel::XlAutoFillType::xlFillMonths: + eCmd = FILL_DATE; + eDateCmd = FILL_MONTH; + break; + case excel::XlAutoFillType::xlFillWeekdays: + eCmd = FILL_DATE; + eDateCmd = FILL_WEEKDAY; + break; + case excel::XlAutoFillType::xlFillYears: + eCmd = FILL_DATE; + eDateCmd = FILL_YEAR; + break; + case excel::XlAutoFillType::xlGrowthTrend: + eCmd = FILL_GROWTH; + break; + case excel::XlAutoFillType::xlFillFormats: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "xlFillFormat not supported for AutoFill" ) ), uno::Reference< uno::XInterface >() ); + case excel::XlAutoFillType::xlFillValues: + case excel::XlAutoFillType::xlFillSeries: + case excel::XlAutoFillType::xlLinearTrend: + eCmd = FILL_LINEAR; + break; + case excel::XlAutoFillType::xlFillDefault: + default: + eCmd = FILL_AUTO; + break; + } + } + ScDocFunc aFunc(*pDocSh); +#ifdef VBA_OOBUILD_HACK + aFunc.FillAuto( aSourceRange, NULL, eDir, eCmd, eDateCmd, nCount, fStep, fEndValue, TRUE, TRUE ); +#endif +} +sal_Bool SAL_CALL +ScVbaRange::GoalSeek( const uno::Any& Goal, const uno::Reference< excel::XRange >& ChangingCell ) throw (uno::RuntimeException) +{ + ScDocShell* pDocShell = getScDocShell(); + sal_Bool bRes = sal_True; + ScVbaRange* pRange = static_cast< ScVbaRange* >( ChangingCell.get() ); + if ( pDocShell && pRange ) + { + uno::Reference< sheet::XGoalSeek > xGoalSeek( pDocShell->GetModel(), uno::UNO_QUERY_THROW ); + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + RangeHelper changingCellRange( pRange->mxRange ); + table::CellRangeAddress changingCellAddr = changingCellRange.getCellRangeAddressable()->getRangeAddress(); + rtl::OUString sGoal = getAnyAsString( Goal ); + table::CellAddress thisCell( thisAddress.Sheet, thisAddress.StartColumn, thisAddress.StartRow ); + table::CellAddress changingCell( changingCellAddr.Sheet, changingCellAddr.StartColumn, changingCellAddr.StartRow ); + sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, sGoal ); + ChangingCell->setValue( uno::makeAny( res.Result ) ); + + // openoffice behaves differently, result is 0 if the divergence is too great + // but... if it detects 0 is the value it requires then it will use that + // e.g. divergence & result both = 0.0 does NOT mean there is an error + if ( ( res.Divergence != 0.0 ) && ( res.Result == 0.0 ) ) + bRes = sal_False; + } + else + bRes = sal_False; + return bRes; +} + +void +ScVbaRange::Calculate( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + getWorksheet()->Calculate(); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( mbIsRows || mbIsColumns ) + { + if ( column.hasValue() ) + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + uno::Reference< excel::XRange > xRange; + if ( mbIsColumns ) + xRange = Columns( row ); + else + xRange = Rows( row ); + return xRange; + } + return Cells( row, column ); +} + +void +ScVbaRange::AutoOutline( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // #TODO #FIXME needs to check for summary row/col ( whatever they are ) + // not valid for multi Area Addresses + if ( m_Areas->getCount() > 1 ) + DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY); + // So needs to either span an entire Row or a just be a single cell + // ( that contains a summary RowColumn ) + // also the Single cell cause doesn't seem to be handled specially in + // this code ( ported from the helperapi RangeImpl.java, + // RangeRowsImpl.java, RangesImpl.java, RangeSingleCellImpl.java + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + + uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); + xSheetOutline->autoOutline( thisAddress ); +} + +void SAL_CALL +ScVbaRange:: ClearOutline( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->ClearOutline(); + } + return; + } + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); + xSheetOutline->clearOutline(); +} + +void +ScVbaRange::groupUnGroup( bool bUnGroup ) throw ( script::BasicErrorException, uno::RuntimeException ) +{ + if ( m_Areas->getCount() > 1 ) + DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY); + table::TableOrientation nOrient = table::TableOrientation_COLUMNS; + if ( mbIsRows ) + nOrient = table::TableOrientation_ROWS; + RangeHelper thisRange( mxRange ); + table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress(); + uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW ); + if ( bUnGroup ) + xSheetOutline->ungroup( thisAddress, nOrient ); + else + xSheetOutline->group( thisAddress, nOrient ); +} + +void SAL_CALL +ScVbaRange::Group( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + groupUnGroup(); +} +void SAL_CALL +ScVbaRange::Ungroup( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + groupUnGroup(true); +} + +void lcl_mergeCellsOfRange( const uno::Reference< table::XCellRange >& xCellRange, sal_Bool _bMerge = sal_True ) throw ( uno::RuntimeException ) +{ + uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW ); + xMergeable->merge(_bMerge); +} +void SAL_CALL +ScVbaRange::Merge( const uno::Any& Across ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->Merge(Across); + } + return; + } + uno::Reference< table::XCellRange > oCellRange; + sal_Bool bAcross = sal_False; + Across >>= bAcross; + if ( !bAcross ) + lcl_mergeCellsOfRange( mxRange ); + else + { + uno::Reference< excel::XRange > oRangeRowsImpl = Rows( uno::Any() ); + // #TODO #FIXME this seems incredibly lame, this can't be right + for (sal_Int32 i=1; i <= oRangeRowsImpl->getCount();i++) + { + oRangeRowsImpl->Cells( uno::makeAny( i ), uno::Any() )->Merge( uno::makeAny( sal_False ) ); + } + } +} + +void SAL_CALL +ScVbaRange::UnMerge( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + sal_Int32 nItems = m_Areas->getCount(); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->UnMerge(); + } + return; + } + lcl_mergeCellsOfRange( mxRange, sal_False); +} + +uno::Any SAL_CALL +ScVbaRange::getStyle() throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->getStyle(); + } + uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW ); + rtl::OUString sStyleName; + xProps->getPropertyValue(CELLSTYLE) >>= sStyleName; + ScDocShell* pShell = getScDocShell(); + uno::Reference< frame::XModel > xModel( pShell->GetModel() ); + uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext, sStyleName, xModel ); + return uno::makeAny( xStyle ); +} +void SAL_CALL +ScVbaRange::setStyle( const uno::Any& _style ) throw (uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange->setStyle( _style ); + return; + } + uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XStyle > xStyle; + _style >>= xStyle; + xProps->setPropertyValue(CELLSTYLE, uno::makeAny(xStyle->getName())); +} + +uno::Reference< excel::XRange > +ScVbaRange::PreviousNext( bool bIsPrevious ) +{ + ScMarkData markedRange; + ScRange refRange; + RangeHelper thisRange( mxRange ); + + ScUnoConversion::FillScRange( refRange, thisRange.getCellRangeAddressable()->getRangeAddress()); + markedRange. SetMarkArea( refRange ); + short nMove = bIsPrevious ? -1 : 1; + + SCCOL nNewX = refRange.aStart.Col(); + SCROW nNewY = refRange.aStart.Row(); + SCTAB nTab = refRange.aStart.Tab(); + + ScDocument* pDoc = getScDocument(); + pDoc->GetNextPos( nNewX,nNewY, nTab, nMove,0, TRUE,TRUE, markedRange ); + refRange.aStart.SetCol( nNewX ); + refRange.aStart.SetRow( nNewY ); + refRange.aStart.SetTab( nTab ); + refRange.aEnd.SetCol( nNewX ); + refRange.aEnd.SetRow( nNewY ); + refRange.aEnd.SetTab( nTab ); + + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) ); + + return new ScVbaRange( mxParent, mxContext, xRange ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::Next() throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ) , uno::UNO_QUERY_THROW ); + return xRange->Next(); + } + return PreviousNext( false ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::Previous() throw (script::BasicErrorException, uno::RuntimeException) +{ + if ( m_Areas->getCount() > 1 ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xRange->Previous(); + } + return PreviousNext( true ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw ( script::BasicErrorException ) +{ + bool bIsSingleCell = isSingleCellRange(); + bool bIsMultiArea = ( m_Areas->getCount() > 1 ); + ScVbaRange* pRangeToUse = this; + uno::Reference< excel::XRange > xUsedRange( getWorksheet()->getUsedRange() ); + sal_Int32 nType = 0; + if ( !( _oType >>= nType ) ) + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + switch(nType) + { + case excel::XlCellType::xlCellTypeSameFormatConditions: + case excel::XlCellType::xlCellTypeAllValidation: + case excel::XlCellType::xlCellTypeSameValidation: + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + break; + case excel::XlCellType::xlCellTypeBlanks: + case excel::XlCellType::xlCellTypeComments: + case excel::XlCellType::xlCellTypeConstants: + case excel::XlCellType::xlCellTypeFormulas: + case excel::XlCellType::xlCellTypeVisible: + case excel::XlCellType::xlCellTypeLastCell: + { + if ( bIsMultiArea ) + { + // need to process each area, gather the results and + // create a new range from those + std::vector< table::CellRangeAddress > rangeResults; + sal_Int32 nItems = ( m_Areas->getCount() + 1 ); + for ( sal_Int32 index=1; index <= nItems; ++index ) + { + uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW ); + xRange = xRange->SpecialCells( _oType, _oValue); + ScVbaRange* pRange = getImplementation( xRange ); + if ( xRange.is() && pRange ) + { + sal_Int32 nElems = ( pRange->m_Areas->getCount() + 1 ); + for ( sal_Int32 nArea = 1; nArea < nElems; ++nArea ) + { + uno::Reference< excel::XRange > xTmpRange( m_Areas->Item( uno::makeAny( nArea ), uno::Any() ), uno::UNO_QUERY_THROW ); + RangeHelper rHelper( xTmpRange->getCellRange() ); + rangeResults.push_back( rHelper.getCellRangeAddressable()->getRangeAddress() ); + } + } + } + ScRangeList aCellRanges; + std::vector< table::CellRangeAddress >::iterator it = rangeResults.begin(); + std::vector< table::CellRangeAddress >::iterator it_end = rangeResults.end(); + for ( ; it != it_end; ++ it ) + { + ScRange refRange; + ScUnoConversion::FillScRange( refRange, *it ); + aCellRanges.Append( refRange ); + } + // Single range + if ( aCellRanges.First() == aCellRanges.Last() ) + { + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), *aCellRanges.First() ) ); + return new ScVbaRange( mxParent, mxContext, xRange ); + } + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( getScDocShell(), aCellRanges ) ); + + return new ScVbaRange( mxParent, mxContext, xRanges ); + } + else if ( bIsSingleCell ) + { + pRangeToUse = static_cast< ScVbaRange* >( xUsedRange.get() ); + } + + break; + } + default: + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + break; + } + if ( !pRangeToUse ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + return pRangeToUse->SpecialCellsImpl( nType, _oValue ); +} + +sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) throw ( script::BasicErrorException ) +{ + sal_Int32 nType = excel::XlSpecialCellsValue::xlNumbers; + aType >>= nType; + sal_Int32 nRes = sheet::FormulaResult::VALUE; + + switch(nType) + { + case excel::XlSpecialCellsValue::xlErrors: + nRes= sheet::FormulaResult::ERROR; + break; + case excel::XlSpecialCellsValue::xlLogical: + //TODO bc93774: ask NN if this is really an appropriate substitute + nRes = sheet::FormulaResult::VALUE; + break; + case excel::XlSpecialCellsValue::xlNumbers: + nRes = sheet::FormulaResult::VALUE; + break; + case excel::XlSpecialCellsValue::xlTextValues: + nRes = sheet::FormulaResult::STRING; + break; + default: + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + return nRes; +} + +uno::Reference< excel::XRange > +ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw ( script::BasicErrorException ) +{ + uno::Reference< excel::XRange > xRange; + try + { + uno::Reference< sheet::XCellRangesQuery > xQuery( mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XRange > oLocRangeImpl; + uno::Reference< sheet::XSheetCellRanges > xLocSheetCellRanges; + switch(nType) + { + case excel::XlCellType::xlCellTypeAllFormatConditions: + case excel::XlCellType::xlCellTypeSameFormatConditions: + case excel::XlCellType::xlCellTypeAllValidation: + case excel::XlCellType::xlCellTypeSameValidation: + // Shouldn't get here ( should be filtered out by + // ScVbaRange::SpecialCells() + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + break; + case excel::XlCellType::xlCellTypeBlanks: + xLocSheetCellRanges = xQuery->queryEmptyCells(); + break; + case excel::XlCellType::xlCellTypeComments: + xLocSheetCellRanges = xQuery->queryContentCells(sheet::CellFlags::ANNOTATION); + break; + case excel::XlCellType::xlCellTypeConstants: + xLocSheetCellRanges = xQuery->queryContentCells(23); + break; + case excel::XlCellType::xlCellTypeFormulas: + { + sal_Int32 nFormulaResult = lcl_getFormulaResultFlags(_oValue); + xLocSheetCellRanges = xQuery->queryFormulaCells(nFormulaResult); + break; + } + case excel::XlCellType::xlCellTypeLastCell: + xRange = Cells( uno::makeAny( getCount() ), uno::Any() ); + case excel::XlCellType::xlCellTypeVisible: + xLocSheetCellRanges = xQuery->queryVisibleCells(); + break; + default: + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + break; + } + if (xLocSheetCellRanges.is()) + { + xRange = lcl_makeXRangeFromSheetCellRanges( getParent(), mxContext, xLocSheetCellRanges, getScDocShell() ); + } + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_NOCELLSWEREFOUND); + } + return xRange; +} + +void SAL_CALL +ScVbaRange::RemoveSubtotal( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< sheet::XSubTotalCalculatable > xSub( mxRange, uno::UNO_QUERY_THROW ); + xSub->removeSubTotals(); +} + +void SAL_CALL +ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno::Sequence< ::sal_Int32 >& _nTotalList, const uno::Any& aReplace, const uno::Any& PageBreaks, const uno::Any& /*SummaryBelowData*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + sal_Bool bDoReplace = sal_False; + aReplace >>= bDoReplace; + sal_Bool bAddPageBreaks = sal_False; + PageBreaks >>= bAddPageBreaks; + + uno::Reference< sheet::XSubTotalCalculatable> xSub(mxRange, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XSubTotalDescriptor > xSubDesc = xSub->createSubTotalDescriptor(sal_True); + uno::Reference< beans::XPropertySet > xSubDescPropertySet( xSubDesc, uno::UNO_QUERY_THROW ); + xSubDescPropertySet->setPropertyValue(INSERTPAGEBREAKS, uno::makeAny( bAddPageBreaks)); + sal_Int32 nLen = _nTotalList.getLength(); + uno::Sequence< sheet::SubTotalColumn > aColumns( nLen ); + for (int i = 0; i < nLen; i++) + { + aColumns[i].Column = _nTotalList[i] - 1; + switch (_nFunction) + { + case excel::XlConsolidationFunction::xlAverage: + aColumns[i].Function = sheet::GeneralFunction_AVERAGE; + break; + case excel::XlConsolidationFunction::xlCount: + aColumns[i].Function = sheet::GeneralFunction_COUNT; + break; + case excel::XlConsolidationFunction::xlCountNums: + aColumns[i].Function = sheet::GeneralFunction_COUNTNUMS; + break; + case excel::XlConsolidationFunction::xlMax: + aColumns[i].Function = sheet::GeneralFunction_MAX; + break; + case excel::XlConsolidationFunction::xlMin: + aColumns[i].Function = sheet::GeneralFunction_MIN; + break; + case excel::XlConsolidationFunction::xlProduct: + aColumns[i].Function = sheet::GeneralFunction_PRODUCT; + break; + case excel::XlConsolidationFunction::xlStDev: + aColumns[i].Function = sheet::GeneralFunction_STDEV; + break; + case excel::XlConsolidationFunction::xlStDevP: + aColumns[i].Function = sheet::GeneralFunction_STDEVP; + break; + case excel::XlConsolidationFunction::xlSum: + aColumns[i].Function = sheet::GeneralFunction_SUM; + break; + case excel::XlConsolidationFunction::xlUnknown: + aColumns[i].Function = sheet::GeneralFunction_NONE; + break; + case excel::XlConsolidationFunction::xlVar: + aColumns[i].Function = sheet::GeneralFunction_VAR; + break; + case excel::XlConsolidationFunction::xlVarP: + aColumns[i].Function = sheet::GeneralFunction_VARP; + break; + default: + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString()) ; + return; + } + } + xSubDesc->addNew(aColumns, _nGroupBy - 1); + xSub->applySubTotals(xSubDesc, bDoReplace); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +uno::Any SAL_CALL ScVbaRange::AdvancedFilter( sal_Int32 Action, const uno::Any& CriteriaRange, + const uno::Any& CopyToRange, const uno::Any& Unique ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Any aRet; + aRet <<= sal_True; + + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext ); + ScDocument* pDoc = getScDocument(); + if ( !pDoc ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from range" ) ), uno::Reference< uno::XInterface >() ); + } + + // Action + if ( Action != excel::XlFilterAction::xlFilterInPlace && Action != excel::XlFilterAction::xlFilterCopy ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid input parameter" ) ), uno::Reference< uno::XInterface >() ); + } + if ( m_Areas->getCount() > 1 ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid range" ) ), uno::Reference< uno::XInterface >() ); + } + + sal_Bool bCopyOut = ( Action != excel::XlFilterAction::xlFilterInPlace ); + uno::Reference< sheet::XSheetFilterDescriptor > xFilterDesc; + uno::Reference< sheet::XSheetFilterable > xSheetFilter( mxRange, uno::UNO_QUERY_THROW ); + + // CriteriaRange + String aBuiltInCriteria; // Excel Built-In Filter Criteria. + ScRangeData* pData = NULL; + table::CellRangeAddress refParentAddr; + uno::Any aCriteriaRange = CriteriaRange; + formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1; + if ( aCriteriaRange.hasValue() && aCriteriaRange.getValueTypeClass() == uno::TypeClass_STRING ) + { + rtl::OUString rRangeString; + aCriteriaRange >>= rRangeString; + aConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv; + } + else + { + // Get Excel BuiltIn Filter Criteria. + ScRangeName* pRangeNames = pDoc->GetRangeName(); + const USHORT nCount = pRangeNames ? pRangeNames->GetCount() : 0; + for ( USHORT index = 0; index < nCount; index++ ) + { + pData = ( ScRangeData* )( pRangeNames->At( index ) ); + if ( pData && pData->HasType( RT_CRITERIA ) ) + { + pData->GetSymbol( aBuiltInCriteria, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 ); + break; + } + } + aCriteriaRange = aBuiltInCriteria.Len() > 0 ? uno::makeAny( rtl::OUString( aBuiltInCriteria ) ) : aCriteriaRange; + } + if ( aCriteriaRange.hasValue() ) + { + table::CellRangeAddress criteriaRangeAddress = getCellRangeAddressForVBARange( aCriteriaRange, getScDocShell(), aConv ); + ScRange refRange; + ScUnoConversion::FillScRange( refRange, criteriaRangeAddress ); + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) ); + uno::Reference< sheet::XSheetFilterableEx > xCriteria( xRange, uno::UNO_QUERY ); + if ( xCriteria.is() ) + { + xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter ); + } + } + else if ( mxRange.is() ) + { + uno::Reference< sheet::XSheetFilterableEx > xCriteria( mxRange, uno::UNO_QUERY ); + if ( xCriteria.is() ) + { + xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter ); + } + } + + uno::Reference< beans::XPropertySet > xPropertySet( xFilterDesc, uno::UNO_QUERY ); + if ( xPropertySet.is() ) + { + xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_COPYOUT ) ), uno::makeAny( bCopyOut ) ); + } + + // CopyToRange + if ( bCopyOut && CopyToRange.hasValue() && xPropertySet.is() ) + { + formula::FormulaGrammar::AddressConvention aTmpConv = formula::FormulaGrammar::CONV_XL_A1; + if ( CopyToRange.getValueTypeClass() == uno::TypeClass_STRING ) + { + rtl::OUString rRangeString; + CopyToRange >>= rRangeString; + aTmpConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv; + } + ScRange refRange; + ScUnoConversion::FillScRange( refRange, getCellRangeAddressForVBARange( CopyToRange, getScDocShell(), aTmpConv ) ); + uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) ); + uno::Reference< sheet::XCellAddressable > xCellAddr( xRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY_THROW ); + xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OUTPOS ) ), uno::makeAny( xCellAddr->getCellAddress() ) ); + } + + // Unique + if ( xPropertySet.is() ) + { + sal_Bool bUnique = sal_False; + uno::Any aUnique; + try + { + aUnique <<= bUnique; + aUnique = ( xConverter.is() && Unique.hasValue() ) ? xConverter->convertTo( Unique, getCppuType( ( sal_Bool* ) 0 ) ) : aUnique; + } + catch( const uno::Exception& ) + { + } + xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SKIPDUP ) ), aUnique ); + } + + // Do filter. + if ( xFilterDesc.is() ) + { + xSheetFilter->filter( xFilterDesc ); + } + + return aRet; +} + +//Add by minz@cn.ibm.com. Range.PivotTable. +//Returns a PivotTable object that represents the PivotTable report containing the upper-left corner of the specified range. +uno::Reference< excel::XPivotTable > +ScVbaRange::PivotTable() throw (uno::RuntimeException) +{ + uno::Reference< excel::XPivotTable > xDestPVTable; + + uno::Reference< sheet::XSpreadsheet > xSheet; + if ( mxRange.is() ) + { + RangeHelper thisRange( mxRange ); + xSheet = thisRange.getSpreadSheet(); + } + else if ( mxRanges.is() ) + { + uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW ); + uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + RangeHelper thisRange( xRange ); + xSheet = thisRange.getSpreadSheet(); + } + +// RangeHelper thisRange( mxRange ); +// uno::Reference< sheet::XSpreadsheet > xSheet = thisRange.getSpreadSheet(); + uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ; + uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW ); + if ( xIndexAccess.is() ) + { + //get the upper-left cell address + table::CellAddress aAddress = getLeftUpperCellAddress(); + + sal_Int32 nCount = xIndexAccess->getCount(); + for (sal_Int32 i=0; i < nCount; i++) + { + uno::Reference< sheet::XDataPilotTable > xDPTable(xIndexAccess->getByIndex(i), uno::UNO_QUERY); + uno::Reference< sheet::XDataPilotTable2 > xDPTable2(xDPTable, uno::UNO_QUERY); + + //check if the cell is in the pivot table + sheet::DataPilotTablePositionData posData = xDPTable2->getPositionData(aAddress); + table::CellRangeAddress aCellRangeAddress = xDPTable->getOutputRange(); + ScRange aScRange( aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow, aCellRangeAddress.Sheet, + aCellRangeAddress.EndColumn, aCellRangeAddress.EndRow, aCellRangeAddress.Sheet ); + ScAddress aPos( aAddress.Column, aAddress.Row, aAddress.Sheet ); + if( !(posData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE) || aScRange.In( aPos ) ) + { + xDestPVTable = new ScVbaPivotTable( mxContext, xDPTable ); + break; + } + } + } + return xDestPVTable; +} + + +rtl::OUString& +ScVbaRange::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaRange") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaRange::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Range" ) ); + } + return aServiceNames; +} + +sal_Bool SAL_CALL +ScVbaRange::hasError() throw (uno::RuntimeException) +{ + double dResult = sal_False; + uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + uno::Reference< script::XInvocation > xInvoc( xApplication->WorksheetFunction(), uno::UNO_QUERY_THROW ); + + static rtl::OUString FunctionName( RTL_CONSTASCII_USTRINGPARAM("IsError" ) ); + uno::Sequence< uno::Any > Params(1); + uno::Reference< excel::XRange > aRange( this ); + Params[0] = uno::makeAny( aRange ); + uno::Sequence< sal_Int16 > OutParamIndex; + uno::Sequence< uno::Any > OutParam; + xInvoc->invoke( FunctionName, Params, OutParamIndex, OutParam ) >>= dResult; + if ( dResult > 0.0 ) + return sal_True; + return sal_False; +} + +namespace range +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaRange, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "SvVbaRange", + "ooo.vba.excel.Range" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx new file mode 100644 index 000000000000..059d85502f3e --- /dev/null +++ b/sc/source/ui/vba/vbarange.hxx @@ -0,0 +1,312 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_RANGE_HXX +#define SC_VBA_RANGE_HXX + +#include <cppuhelper/implbase4.hxx> +#include <com/sun/star/container/XEnumerationAccess.hpp> + +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <ooo/vba/excel/XFont.hpp> +#include <ooo/vba/excel/XComment.hpp> +#include <ooo/vba/XCollection.hpp> +#include <ooo/vba/excel/XPivotTable.hpp> +#include <ooo/vba/excel/XlPasteType.hdl> +#include <ooo/vba/excel/XlPasteSpecialOperation.hdl> + +#include <comphelper/proparrhlp.hxx> +#include <comphelper/propertycontainer.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/script/XDefaultMethod.hpp> +#include <com/sun/star/script/XDefaultProperty.hpp> +#include <com/sun/star/sheet/FillDateMode.hpp> +#include <com/sun/star/sheet/FillMode.hpp> +#include <com/sun/star/sheet/FillDirection.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include "vbaquerytable.hxx" //09-09-18 add by limingl + +#include "vbaformat.hxx" +#include <formula/grammar.hxx> + +class ScTableSheetsObj; +class ScCellRangesBase; +class ScCellRangeObj; +class ScCellRangesObj; +class ScDocShell; +class ScDocument; +class ScRangeList; + +typedef ScVbaFormat< ov::excel::XRange > ScVbaRange_BASE; + +class ArrayVisitor +{ +public: + virtual void visitNode( sal_Int32 x, sal_Int32 y, const css::uno::Reference< css::table::XCell >& xCell ) = 0; + virtual ~ArrayVisitor(){} +}; + +class ValueSetter : public ArrayVisitor +{ +public: + virtual bool processValue( const css::uno::Any& aValue, const css::uno::Reference< css::table::XCell >& xCell ) = 0; + + +}; + +class ValueGetter : public ArrayVisitor +{ + +public: + virtual void processValue( sal_Int32 x, sal_Int32 y, const css::uno::Any& aValue ) = 0; + virtual const css::uno::Any& getValue() const = 0; +}; + + + +class ScVbaRange : public ScVbaRange_BASE +{ + css::uno::Reference< ov::XCollection > m_Areas; + css::uno::Reference< ov::XCollection > m_Borders; + css::uno::Reference< css::table::XCellRange > mxRange; + css::uno::Reference< css::sheet::XSheetCellRangeContainer > mxRanges; + sal_Bool mbIsRows; + sal_Bool mbIsColumns; + css::uno::Reference< ov::excel::XValidation > m_xValidation; + css::uno::Reference<excel::XQueryTable> m_xQueryTable; //09-09-16 add by limingl + double getCalcColWidth( const css::table::CellRangeAddress& ) throw (css::uno::RuntimeException); + double getCalcRowHeight( const css::table::CellRangeAddress& ) throw (css::uno::RuntimeException); + void visitArray( ArrayVisitor& vistor ); + + css::uno::Reference< ov::excel::XRange > getEntireColumnOrRow( bool bColumn = true ) throw( css::uno::RuntimeException ); + + void fillSeries( css::sheet::FillDirection nFillDirection, css::sheet::FillMode nFillMode, css::sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ) throw( css::uno::RuntimeException ); + + void ClearContents( sal_Int32 nFlags ) throw (css::uno::RuntimeException); + virtual void setValue( const css::uno::Any& aValue, ValueSetter& setter) throw ( css::uno::RuntimeException); + virtual css::uno::Any getValue( ValueGetter& rValueGetter ) throw (css::uno::RuntimeException); + virtual css::uno::Any getFormulaValue( formula::FormulaGrammar::Grammar ) throw (css::uno::RuntimeException); + virtual void setFormulaValue( const css::uno::Any& aValue, formula::FormulaGrammar::Grammar ) throw ( css::uno::RuntimeException); + css::uno::Reference< ov::excel::XRange > getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException ); + ScCellRangeObj* getCellRangeObj( ) throw ( css::uno::RuntimeException ); + ScCellRangesObj* getCellRangesObj() throw ( css::uno::RuntimeException ); + css::uno::Reference< ov::XCollection >& getBorders(); + void groupUnGroup( bool bUnGroup = false ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + css::uno::Reference< ov::excel::XRange > PreviousNext( bool bIsPrevious ); + css::uno::Reference< ov::excel::XRange > SpecialCellsImpl( sal_Int32 nType, const css::uno::Any& _oValue) throw ( css::script::BasicErrorException ); + css::awt::Point getPosition() throw ( css::uno::RuntimeException ); +protected: + virtual ScCellRangesBase* getCellRangesBase() throw ( css::uno::RuntimeException ); + virtual SfxItemSet* getCurrentDataSet( ) throw ( css::uno::RuntimeException ); +public: + ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::table::XCellRange >& xRange, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ) throw ( css::lang::IllegalArgumentException ); + ScVbaRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::sheet::XSheetCellRangeContainer >& xRanges, sal_Bool bIsRows = false, sal_Bool bIsColumns = false ) throw ( css::lang::IllegalArgumentException ); + ScVbaRange( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ) throw ( css::lang::IllegalArgumentException ); + + ScDocument* getScDocument() throw (css::uno::RuntimeException); + ScDocShell* getScDocShell() throw (css::uno::RuntimeException); + + /** Returns the ScVbaRange implementation object for the passed VBA Range object. */ + static ScVbaRange* getImplementation( const css::uno::Reference< ov::excel::XRange >& rxRange ); + + css::uno::Reference< css::frame::XModel > getUnoModel() throw (css::uno::RuntimeException); + static css::uno::Reference< css::frame::XModel > getUnoModel( const css::uno::Reference< ov::excel::XRange >& rxRange ) throw (css::uno::RuntimeException); + + const ScRangeList& getScRangeList() throw (css::uno::RuntimeException); + static const ScRangeList& getScRangeList( const css::uno::Reference< ov::excel::XRange >& rxRange ) throw (css::uno::RuntimeException); + + virtual ~ScVbaRange(); + virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() { return this; } + bool isSingleCellRange(); + + static css::uno::Reference< ov::excel::XRange > getRangeObjectForName( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const rtl::OUString& sRangeName, ScDocShell* pDocSh, + formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( css::uno::RuntimeException ); + css::table::CellAddress getLeftUpperCellAddress(); + + // Attributes + virtual css::uno::Any SAL_CALL getName() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& aValue ) throw ( css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFormula() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFormula( const css::uno::Any& rFormula ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFormulaArray() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFormulaArray(const css::uno::Any& rFormula) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getFormulaR1C1() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFormulaR1C1( const css::uno::Any &rFormula ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getRow() throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getColumn() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + using ScVbaRange_BASE::setNumberFormat; + virtual void SAL_CALL setNumberFormat( const css::uno::Any& rNumberFormat ) throw ( css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getNumberFormat() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setMergeCells( const css::uno::Any& bMerge ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getMergeCells() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setWrapText( const css::uno::Any& bIsWrapped ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getWrapText() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getEntireRow() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getEntireColumn() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XComment > SAL_CALL getComment() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getHidden() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHidden( const css::uno::Any& _hidden ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getColumnWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setColumnWidth( const css::uno::Any& _columnwidth ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getRowHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRowHeight( const css::uno::Any& _rowheight ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getLeft() throw (css::uno::RuntimeException); + + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getWorksheet() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getPageBreak() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPageBreak( const css::uno::Any& _pagebreak ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XValidation > SAL_CALL getValidation() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getPrefixCharacter() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getShowDetail() throw (css::uno::RuntimeException); + virtual void SAL_CALL setShowDetail(const css::uno::Any& aShowDetail) throw (css::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL getQueryTable() throw (::com::sun::star::uno::RuntimeException); //09-09-16 add by limingl + // Methods + sal_Bool IsRows() { return mbIsRows; } + sal_Bool IsColumns() { return mbIsColumns; } + virtual css::uno::Reference< ov::excel::XComment > SAL_CALL AddComment( const css::uno::Any& Text ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Clear() throw (css::uno::RuntimeException); + virtual void SAL_CALL ClearComments() throw (css::uno::RuntimeException); + virtual void SAL_CALL ClearContents() throw (css::uno::RuntimeException); + virtual void SAL_CALL ClearFormats() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL HasFormula() throw (css::uno::RuntimeException); + virtual void SAL_CALL FillLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL FillRight() throw (css::uno::RuntimeException); + virtual void SAL_CALL FillUp() throw (css::uno::RuntimeException); + virtual void SAL_CALL FillDown() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Offset( const css::uno::Any &nRowOffset, const css::uno::Any &nColOffset ) + throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL CurrentRegion() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL CurrentArray() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL Characters( const css::uno::Any& nIndex, const css::uno::Any& nCount ) + throw (css::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL Address( const css::uno::Any& RowAbsolute, const css::uno::Any& ColumnAbsolute, const css::uno::Any& ReferenceStyle, const css::uno::Any& External, const css::uno::Any& RelativeTo ) throw (css::uno::RuntimeException); + + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells( const css::uno::Any &nRow, const css::uno::Any &nCol ) + throw (css::uno::RuntimeException); + virtual void SAL_CALL Select() throw (css::uno::RuntimeException); + virtual void SAL_CALL Activate() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Rows( const css::uno::Any& nIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns( const css::uno::Any &nIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Copy( const css::uno::Any& Destination ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Cut( const css::uno::Any& Destination ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Resize( const css::uno::Any& RowSize, const css::uno::Any& ColumnSize ) + throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XFont > SAL_CALL Font() throw ( css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior( ) throw ( css::script::BasicErrorException, css::uno::RuntimeException) ; + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Range( const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > Range( const css::uno::Any &Cell1, const css::uno::Any &Cell2, bool bForceUseInpuRangeTab ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getCellRange( ) throw (css::uno::RuntimeException); + static css::uno::Any getCellRange( const css::uno::Reference< ov::excel::XRange >& rxRange ) throw (css::uno::RuntimeException); + virtual void SAL_CALL PasteSpecial( const css::uno::Any& Paste, const css::uno::Any& Operation, const css::uno::Any& SkipBlanks, const css::uno::Any& Transpose ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const css::uno::Any& LookAt, const css::uno::Any& SearchOrder, const css::uno::Any& MatchCase, const css::uno::Any& MatchByte, const css::uno::Any& SearchFormat, const css::uno::Any& ReplaceFormat ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Find( const css::uno::Any& What, const css::uno::Any& After, const css::uno::Any& LookIn, const css::uno::Any& LookAt, const css::uno::Any& SearchOrder, const css::uno::Any& SearchDirection, const css::uno::Any& MatchCase, const css::uno::Any& MatchByte, const css::uno::Any& SearchFormat ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Sort( const css::uno::Any& Key1, const css::uno::Any& Order1, const css::uno::Any& Key2, const css::uno::Any& Type, const css::uno::Any& Order2, const css::uno::Any& Key3, const css::uno::Any& Order3, const css::uno::Any& Header, const css::uno::Any& OrderCustom, const css::uno::Any& MatchCase, const css::uno::Any& Orientation, const css::uno::Any& SortMethod, const css::uno::Any& DataOption1, const css::uno::Any& DataOption2, const css::uno::Any& DataOption3 ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL End( ::sal_Int32 Direction ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XCharacters > SAL_CALL characters( const css::uno::Any& Start, const css::uno::Any& Length ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete( const css::uno::Any& Shift ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Areas( const css::uno::Any& ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Borders( const css::uno::Any& ) throw ( css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL BorderAround( const css::uno::Any& LineStyle, + const css::uno::Any& Weight, const css::uno::Any& ColorIndex, const css::uno::Any& Color ) throw (css::uno::RuntimeException); + virtual void SAL_CALL TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier, + const css::uno::Any& ConsecutiveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma, + const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo, + const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& TrailingMinusNumbers ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Hyperlinks( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + + virtual void SAL_CALL AutoFilter( const css::uno::Any& Field, const css::uno::Any& Criteria1, const css::uno::Any& Operator, const css::uno::Any& Criteria2, const css::uno::Any& VisibleDropDown ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Insert( const css::uno::Any& Shift, const css::uno::Any& CopyOrigin ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Autofit() throw (css::uno::RuntimeException); + virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::uno::RuntimeException); + virtual void SAL_CALL AutoFill( const css::uno::Reference< ov::excel::XRange >& Destination, const css::uno::Any& Type ) throw (css::uno::RuntimeException) ; + void SAL_CALL Calculate( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL AutoOutline( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Item( const ::css::uno::Any& row, const css::uno::Any& column ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL ClearOutline( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Ungroup( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Group( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Merge( const css::uno::Any& Across ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL UnMerge( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStyle( const css::uno::Any& _style ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Next() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Previous() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL RemoveSubtotal( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL MergeArea() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Subtotal( ::sal_Int32 GroupBy, ::sal_Int32 Function, const css::uno::Sequence< ::sal_Int32 >& TotalList, const css::uno::Any& Replace, const css::uno::Any& PageBreaks, const css::uno::Any& SummaryBelowData ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL AdvancedFilter( ::sal_Int32 Action, const css::uno::Any& CriteriaRange, const css::uno::Any& CopyToRange, const css::uno::Any& Unique ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + virtual css::uno::Reference< ov::excel::XPivotTable > SAL_CALL PivotTable( ) throw (css::uno::RuntimeException); + + virtual ::sal_Int32 SAL_CALL CopyFromRecordset( const ::com::sun::star::uno::Any& Data, const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns ) throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException); //2008-08-25 add by limingl + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException) + { + return ov::excel::XRange::static_type(0); + + } + virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); + // XDefaultMethod + ::rtl::OUString SAL_CALL getDefaultMethodName( ) throw (css::uno::RuntimeException); + // XDefaultProperty + ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + + +// #TODO completely rewrite ScVbaRange, its become a hackfest +// it needs to be closer to ScCellRangeBase in that the underlying +// object model should probably be a ScRangelst. +// * would be nice to be able to construct a range from an addres only +// * or a list of address ( multi-area ) +// * object should be a lightweight as possible +// * we shouldn't need hacks like this below + static css::uno::Reference< ov::excel::XRange > ApplicationRange( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL GoalSeek( const css::uno::Any& Goal, const css::uno::Reference< ov::excel::XRange >& ChangingCell ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL SpecialCells( const css::uno::Any& _oType, const css::uno::Any& _oValue) throw ( css::script::BasicErrorException ); + // XErrorQuery + virtual ::sal_Bool SAL_CALL hasError( ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif /* SC_VBA_RANGE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaseriescollection.cxx b/sc/source/ui/vba/vbaseriescollection.cxx new file mode 100644 index 000000000000..794f91137092 --- /dev/null +++ b/sc/source/ui/vba/vbaseriescollection.cxx @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaseriescollection.hxx" +#include <ooo/vba/excel/XSeries.hpp> + +#include "vbaglobals.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +ScVbaSeriesCollection::ScVbaSeriesCollection( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : SeriesCollection_BASE( xParent, xContext, uno::Reference< container::XIndexAccess>() ) +{ +} + +// XEnumerationAccess + +uno::Reference< container::XEnumeration > +ScVbaSeriesCollection::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumeration > xEnum; + return xEnum; +} + +// XElementAccess + +uno::Type +ScVbaSeriesCollection::getElementType() throw (uno::RuntimeException) +{ + return excel::XSeries::static_type(0); +} + +uno::Any +ScVbaSeriesCollection::createCollectionObject( const css::uno::Any& rSource ) +{ + return rSource; +} + +rtl::OUString& +ScVbaSeriesCollection::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaSeriesCollection") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaSeriesCollection::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.SeriesCollection") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaseriescollection.hxx b/sc/source/ui/vba/vbaseriescollection.hxx new file mode 100644 index 000000000000..ddffda7ac375 --- /dev/null +++ b/sc/source/ui/vba/vbaseriescollection.hxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_SERIESCOLLECTION_HXX +#define SC_VBA_SERIESCOLLECTION_HXX + +#include <ooo/vba/excel/XSeriesCollection.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> +#include "excelvbahelper.hxx" + + +typedef CollTestImplHelper< ov::excel::XSeriesCollection > SeriesCollection_BASE; + +class ScVbaSeriesCollection : public SeriesCollection_BASE +{ + css::uno::Reference< css::uno::XComponentContext > m_xContext; + +public: + ScVbaSeriesCollection( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // SeriesCollection_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_WINDOW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbasheetobject.cxx b/sc/source/ui/vba/vbasheetobject.cxx new file mode 100644 index 000000000000..dc6c0e26a9ad --- /dev/null +++ b/sc/source/ui/vba/vbasheetobject.cxx @@ -0,0 +1,520 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbasheetobject.hxx" +#include <com/sun/star/awt/TextAlign.hpp> +#include <com/sun/star/container/XIndexContainer.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/script/ScriptEventDescriptor.hpp> +#include <com/sun/star/script/XEventAttacherManager.hpp> +#include <com/sun/star/style/VerticalAlignment.hpp> +#include <ooo/vba/excel/Constants.hpp> +#include <ooo/vba/excel/XlOrientation.hpp> +#include <ooo/vba/excel/XlPlacement.hpp> +#include <rtl/ustrbuf.hxx> +#include <filter/msfilter/msvbahelper.hxx> +#include <oox/helper/helper.hxx> +#include "vbafont.hxx" + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +ScVbaButtonCharacters::ScVbaButtonCharacters( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< beans::XPropertySet >& rxPropSet, + const ScVbaPalette& rPalette, + const uno::Any& rStart, + const uno::Any& rLength ) throw (uno::RuntimeException) : + ScVbaButtonCharacters_BASE( rxParent, rxContext ), + maPalette( rPalette ), + mxPropSet( rxPropSet, uno::UNO_SET_THROW ) +{ + // extract optional start parameter (missing or invalid -> from beginning) + if( !(rStart >>= mnStart) || (mnStart < 1) ) + mnStart = 1; + --mnStart; // VBA is 1-based, rtl string is 0-based + + // extract optional length parameter (missing or invalid -> to end) + if( !(rLength >>= mnLength) || (mnLength < 1) ) + mnLength = SAL_MAX_INT32; +} + +ScVbaButtonCharacters::~ScVbaButtonCharacters() +{ +} + +// XCharacters attributes + +OUString SAL_CALL ScVbaButtonCharacters::getCaption() throw (uno::RuntimeException) +{ + // ignore invalid mnStart and/or mnLength members + OUString aString = getFullString(); + sal_Int32 nStart = ::std::min( mnStart, aString.getLength() ); + sal_Int32 nLength = ::std::min( mnLength, aString.getLength() - nStart ); + return aString.copy( nStart, nLength ); +} + +void SAL_CALL ScVbaButtonCharacters::setCaption( const OUString& rCaption ) throw (uno::RuntimeException) +{ + /* Replace the covered text with the passed text, ignore invalid mnStart + and/or mnLength members. This operation does not affect the mnLength + parameter. If the inserted text is longer than mnLength, the additional + characters are not covered by this object. If the inserted text is + shorter than mnLength, other uncovered characters from the original + string will be covered now, thus may be changed with subsequent + operations. */ + OUString aString = getFullString(); + sal_Int32 nStart = ::std::min( mnStart, aString.getLength() ); + sal_Int32 nLength = ::std::min( mnLength, aString.getLength() - nStart ); + setFullString( aString.replaceAt( nStart, nLength, rCaption ) ); +} + +sal_Int32 SAL_CALL ScVbaButtonCharacters::getCount() throw (uno::RuntimeException) +{ + // always return the total length of the caption + return getFullString().getLength(); +} + +OUString SAL_CALL ScVbaButtonCharacters::getText() throw (uno::RuntimeException) +{ + // Text attribute same as Caption attribute? + return getCaption(); +} + +void SAL_CALL ScVbaButtonCharacters::setText( const OUString& rText ) throw (uno::RuntimeException) +{ + // Text attribute same as Caption attribute? + setCaption( rText ); +} + +uno::Reference< excel::XFont > SAL_CALL ScVbaButtonCharacters::getFont() throw (uno::RuntimeException) +{ + return new ScVbaFont( this, mxContext, maPalette, mxPropSet, 0, true ); +} + +void SAL_CALL ScVbaButtonCharacters::setFont( const uno::Reference< excel::XFont >& /*rxFont*/ ) throw (uno::RuntimeException) +{ + // TODO +} + +// XCharacters methods + +void SAL_CALL ScVbaButtonCharacters::Insert( const OUString& rString ) throw (uno::RuntimeException) +{ + /* The Insert() operation is in fact "replace covered characters", at + least for buttons... It seems there is no easy way to really insert a + substring. This operation does not affect the mnLength parameter. */ + setCaption( rString ); +} + +void SAL_CALL ScVbaButtonCharacters::Delete() throw (uno::RuntimeException) +{ + /* The Delete() operation is nothing else than "replace with empty string". + This does not affect the mnLength parameter, multiple calls of Delete() + will remove characters as long as there are some more covered by this + object. */ + setCaption( OUString() ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButtonCharacters, "ooo.vba.excel.Characters" ) + +// private + +OUString ScVbaButtonCharacters::getFullString() const throw (uno::RuntimeException) +{ + return mxPropSet->getPropertyValue( CREATE_OUSTRING( "Label" ) ).get< OUString >(); +} + +void ScVbaButtonCharacters::setFullString( const OUString& rString ) throw (uno::RuntimeException) +{ + mxPropSet->setPropertyValue( CREATE_OUSTRING( "Label" ), uno::Any( rString ) ); +} + +// ============================================================================ + +ScVbaSheetObjectBase::ScVbaSheetObjectBase( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) : + ScVbaSheetObject_BASE( rxParent, rxContext ), + maPalette( rxModel ), + mxModel( rxModel, uno::UNO_SET_THROW ), + mxShape( rxShape, uno::UNO_SET_THROW ), + mxShapeProps( rxShape, uno::UNO_QUERY_THROW ) +{ +} + +// XSheetObject attributes + +double SAL_CALL ScVbaSheetObjectBase::getLeft() throw (uno::RuntimeException) +{ + return HmmToPoints( mxShape->getPosition().X ); +} + +void SAL_CALL ScVbaSheetObjectBase::setLeft( double fLeft ) throw (uno::RuntimeException) +{ + if( fLeft < 0.0 ) + throw uno::RuntimeException(); + mxShape->setPosition( awt::Point( PointsToHmm( fLeft ), mxShape->getPosition().Y ) ); +} + +double SAL_CALL ScVbaSheetObjectBase::getTop() throw (uno::RuntimeException) +{ + return HmmToPoints( mxShape->getPosition().Y ); +} + +void SAL_CALL ScVbaSheetObjectBase::setTop( double fTop ) throw (uno::RuntimeException) +{ + if( fTop < 0.0 ) + throw uno::RuntimeException(); + mxShape->setPosition( awt::Point( mxShape->getPosition().X, PointsToHmm( fTop ) ) ); +} + +double SAL_CALL ScVbaSheetObjectBase::getWidth() throw (uno::RuntimeException) +{ + return HmmToPoints( mxShape->getSize().Width ); +} + +void SAL_CALL ScVbaSheetObjectBase::setWidth( double fWidth ) throw (uno::RuntimeException) +{ + if( fWidth <= 0.0 ) + throw uno::RuntimeException(); + mxShape->setSize( awt::Size( PointsToHmm( fWidth ), mxShape->getSize().Height ) ); +} + +double SAL_CALL ScVbaSheetObjectBase::getHeight() throw (uno::RuntimeException) +{ + return HmmToPoints( mxShape->getSize().Height ); +} + +void SAL_CALL ScVbaSheetObjectBase::setHeight( double fHeight ) throw (uno::RuntimeException) +{ + if( fHeight <= 0.0 ) + throw uno::RuntimeException(); + mxShape->setSize( awt::Size( mxShape->getSize().Width, PointsToHmm( fHeight ) ) ); +} + +OUString SAL_CALL ScVbaSheetObjectBase::getName() throw (uno::RuntimeException) +{ + return mxShapeProps->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >(); +} + +void SAL_CALL ScVbaSheetObjectBase::setName( const OUString& rName ) throw (uno::RuntimeException) +{ + mxShapeProps->setPropertyValue( CREATE_OUSTRING( "Name" ), uno::Any( rName ) ); +} + +sal_Int32 SAL_CALL ScVbaSheetObjectBase::getPlacement() throw (uno::RuntimeException) +{ + // TODO + return excel::XlPlacement::xlMoveAndSize; +} + +void SAL_CALL ScVbaSheetObjectBase::setPlacement( sal_Int32 /*nPlacement*/ ) throw (uno::RuntimeException) +{ + // TODO +} + +sal_Bool SAL_CALL ScVbaSheetObjectBase::getPrintObject() throw (uno::RuntimeException) +{ + // not supported + return sal_True; +} + +void SAL_CALL ScVbaSheetObjectBase::setPrintObject( sal_Bool /*bPrintObject*/ ) throw (uno::RuntimeException) +{ + // not supported +} + +// private + +void ScVbaSheetObjectBase::setDefaultProperties( sal_Int32 nIndex ) throw (uno::RuntimeException) +{ + OUString aName = ::rtl::OUStringBuffer( implGetBaseName() ).append( sal_Unicode( ' ' ) ).append( nIndex + 1 ).makeStringAndClear(); + setName( aName ); + implSetDefaultProperties(); +} + +void ScVbaSheetObjectBase::implSetDefaultProperties() throw (uno::RuntimeException) +{ +} + +// ============================================================================ + +ScVbaControlObjectBase::ScVbaControlObjectBase( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< container::XIndexContainer >& rxFormIC, + const uno::Reference< drawing::XControlShape >& rxControlShape, + ListenerType eListenerType ) throw (uno::RuntimeException) : + ScVbaControlObject_BASE( rxParent, rxContext, rxModel, uno::Reference< drawing::XShape >( rxControlShape, uno::UNO_QUERY_THROW ) ), + mxFormIC( rxFormIC, uno::UNO_SET_THROW ), + mxControlProps( rxControlShape->getControl(), uno::UNO_QUERY_THROW ) +{ + // set listener and event name to be used for OnAction attribute + switch( eListenerType ) + { + case LISTENER_ACTION: + maListenerType = CREATE_OUSTRING( "XActionListener" ); + maEventMethod = CREATE_OUSTRING( "actionPerformed" ); + break; + case LISTENER_MOUSE: + maListenerType = CREATE_OUSTRING( "XMouseListener" ); + maEventMethod = CREATE_OUSTRING( "mouseReleased" ); + break; + case LISTENER_TEXT: + maListenerType = CREATE_OUSTRING( "XTextListener" ); + maEventMethod = CREATE_OUSTRING( "textChanged" ); + break; + case LISTENER_VALUE: + maListenerType = CREATE_OUSTRING( "XAdjustmentListener" ); + maEventMethod = CREATE_OUSTRING( "adjustmentValueChanged" ); + break; + case LISTENER_CHANGE: + maListenerType = CREATE_OUSTRING( "XChangeListener" ); + maEventMethod = CREATE_OUSTRING( "changed" ); + break; + // no default, to let the compiler complain about missing case + } +} + +// XSheetObject attributes + +OUString SAL_CALL ScVbaControlObjectBase::getName() throw (uno::RuntimeException) +{ + return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >(); +} + +void SAL_CALL ScVbaControlObjectBase::setName( const OUString& rName ) throw (uno::RuntimeException) +{ + mxControlProps->setPropertyValue( CREATE_OUSTRING( "Name" ), uno::Any( rName ) ); +} + +OUString SAL_CALL ScVbaControlObjectBase::getOnAction() throw (uno::RuntimeException) +{ + uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW ); + sal_Int32 nIndex = getModelIndexInForm(); + uno::Sequence< script::ScriptEventDescriptor > aEvents = xEventMgr->getScriptEvents( nIndex ); + if( aEvents.hasElements() ) + { + const script::ScriptEventDescriptor* pEvent = aEvents.getConstArray(); + const script::ScriptEventDescriptor* pEventEnd = pEvent + aEvents.getLength(); + const OUString aScriptType = CREATE_OUSTRING( "Script" ); + for( ; pEvent < pEventEnd; ++pEvent ) + if( (pEvent->ListenerType == maListenerType) && (pEvent->EventMethod == maEventMethod) && (pEvent->ScriptType == aScriptType) ) + return extractMacroName( pEvent->ScriptCode ); + } + return OUString(); +} + +void SAL_CALL ScVbaControlObjectBase::setOnAction( const OUString& rMacroName ) throw (uno::RuntimeException) +{ + uno::Reference< script::XEventAttacherManager > xEventMgr( mxFormIC, uno::UNO_QUERY_THROW ); + sal_Int32 nIndex = getModelIndexInForm(); + + // first, remove a registered event (try/catch just in case implementation throws) + try { xEventMgr->revokeScriptEvent( nIndex, maListenerType, maEventMethod, OUString() ); } catch( uno::Exception& ) {} + + // if a macro name has been passed, try to attach it to the event + if( rMacroName.getLength() > 0 ) + { + VBAMacroResolvedInfo aResolvedMacro = resolveVBAMacro( getSfxObjShell( mxModel ), rMacroName ); + if( !aResolvedMacro.IsResolved() ) + throw uno::RuntimeException(); + script::ScriptEventDescriptor aDescriptor; + aDescriptor.ListenerType = maListenerType; + aDescriptor.EventMethod = maEventMethod; + aDescriptor.ScriptType = CREATE_OUSTRING( "Script" ); + aDescriptor.ScriptCode = makeMacroURL( aResolvedMacro.ResolvedMacro() ); + xEventMgr->registerScriptEvent( nIndex, aDescriptor ); + } +} + +sal_Bool SAL_CALL ScVbaControlObjectBase::getPrintObject() throw (uno::RuntimeException) +{ + return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Printable" ) ).get< sal_Bool >(); +} + +void SAL_CALL ScVbaControlObjectBase::setPrintObject( sal_Bool bPrintObject ) throw (uno::RuntimeException) +{ + mxControlProps->setPropertyValue( CREATE_OUSTRING( "Printable" ), uno::Any( bPrintObject ) ); +} + +// XControlObject attributes + +sal_Bool SAL_CALL ScVbaControlObjectBase::getAutoSize() throw (uno::RuntimeException) +{ + // not supported + return sal_False; +} + +void SAL_CALL ScVbaControlObjectBase::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException) +{ + // not supported +} + +// private + +sal_Int32 ScVbaControlObjectBase::getModelIndexInForm() const throw (uno::RuntimeException) +{ + for( sal_Int32 nIndex = 0, nCount = mxFormIC->getCount(); nIndex < nCount; ++nIndex ) + { + uno::Reference< beans::XPropertySet > xProps( mxFormIC->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + if( mxControlProps.get() == xProps.get() ) + return nIndex; + } + throw uno::RuntimeException(); +} + +// ============================================================================ + +ScVbaButton::ScVbaButton( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< container::XIndexContainer >& rxFormIC, + const uno::Reference< drawing::XControlShape >& rxControlShape ) throw (uno::RuntimeException) : + ScVbaButton_BASE( rxParent, rxContext, rxModel, rxFormIC, rxControlShape, LISTENER_ACTION ) +{ +} + +// XButton attributes + +OUString SAL_CALL ScVbaButton::getCaption() throw (uno::RuntimeException) +{ + return mxControlProps->getPropertyValue( CREATE_OUSTRING( "Label" ) ).get< OUString >(); +} + +void SAL_CALL ScVbaButton::setCaption( const OUString& rCaption ) throw (uno::RuntimeException) +{ + mxControlProps->setPropertyValue( CREATE_OUSTRING( "Label" ), uno::Any( rCaption ) ); +} + +uno::Reference< excel::XFont > SAL_CALL ScVbaButton::getFont() throw (uno::RuntimeException) +{ + return new ScVbaFont( this, mxContext, maPalette, mxControlProps, 0, true ); +} + +void SAL_CALL ScVbaButton::setFont( const uno::Reference< excel::XFont >& /*rxFont*/ ) throw (uno::RuntimeException) +{ + // TODO +} + +sal_Int32 SAL_CALL ScVbaButton::getHorizontalAlignment() throw (uno::RuntimeException) +{ + switch( mxControlProps->getPropertyValue( CREATE_OUSTRING( "Align" ) ).get< sal_Int16 >() ) + { + case awt::TextAlign::LEFT: return excel::Constants::xlLeft; + case awt::TextAlign::RIGHT: return excel::Constants::xlRight; + case awt::TextAlign::CENTER: return excel::Constants::xlCenter; + } + return excel::Constants::xlCenter; +} + +void SAL_CALL ScVbaButton::setHorizontalAlignment( sal_Int32 nAlign ) throw (uno::RuntimeException) +{ + sal_Int32 nAwtAlign = awt::TextAlign::CENTER; + switch( nAlign ) + { + case excel::Constants::xlLeft: nAwtAlign = awt::TextAlign::LEFT; break; + case excel::Constants::xlRight: nAwtAlign = awt::TextAlign::RIGHT; break; + case excel::Constants::xlCenter: nAwtAlign = awt::TextAlign::CENTER; break; + } + // form controls expect short value + mxControlProps->setPropertyValue( CREATE_OUSTRING( "Align" ), uno::Any( static_cast< sal_Int16 >( nAwtAlign ) ) ); +} + +sal_Int32 SAL_CALL ScVbaButton::getVerticalAlignment() throw (uno::RuntimeException) +{ + switch( mxControlProps->getPropertyValue( CREATE_OUSTRING( "VerticalAlign" ) ).get< style::VerticalAlignment >() ) + { + case style::VerticalAlignment_TOP: return excel::Constants::xlTop; + case style::VerticalAlignment_BOTTOM: return excel::Constants::xlBottom; + case style::VerticalAlignment_MIDDLE: return excel::Constants::xlCenter; + default:; + } + return excel::Constants::xlCenter; +} + +void SAL_CALL ScVbaButton::setVerticalAlignment( sal_Int32 nAlign ) throw (uno::RuntimeException) +{ + style::VerticalAlignment eAwtAlign = style::VerticalAlignment_MIDDLE; + switch( nAlign ) + { + case excel::Constants::xlTop: eAwtAlign = style::VerticalAlignment_TOP; break; + case excel::Constants::xlBottom: eAwtAlign = style::VerticalAlignment_BOTTOM; break; + case excel::Constants::xlCenter: eAwtAlign = style::VerticalAlignment_MIDDLE; break; + } + mxControlProps->setPropertyValue( CREATE_OUSTRING( "VerticalAlign" ), uno::Any( eAwtAlign ) ); +} + +sal_Int32 SAL_CALL ScVbaButton::getOrientation() throw (uno::RuntimeException) +{ + // not supported + return excel::XlOrientation::xlHorizontal; +} + +void SAL_CALL ScVbaButton::setOrientation( sal_Int32 /*nOrientation*/ ) throw (uno::RuntimeException) +{ + // not supported +} + +// XButton methods + +uno::Reference< excel::XCharacters > SAL_CALL ScVbaButton::Characters( const uno::Any& rStart, const uno::Any& rLength ) throw (uno::RuntimeException) +{ + return new ScVbaButtonCharacters( this, mxContext, mxControlProps, maPalette, rStart, rLength ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButton, "ooo.vba.excel.Button" ) + +// private + +OUString ScVbaButton::implGetBaseName() const +{ + return CREATE_OUSTRING( "Button" ); +} + +void ScVbaButton::implSetDefaultProperties() throw (uno::RuntimeException) +{ + setCaption( getName() ); +} + +// ============================================================================ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbasheetobject.hxx b/sc/source/ui/vba/vbasheetobject.hxx new file mode 100644 index 000000000000..928c9006e757 --- /dev/null +++ b/sc/source/ui/vba/vbasheetobject.hxx @@ -0,0 +1,223 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_SHEETOBJECT_HXX +#define SC_VBA_SHEETOBJECT_HXX + +#include <memory> +#include <ooo/vba/excel/XButton.hpp> +#include <ooo/vba/excel/XControlObject.hpp> +#include <ooo/vba/excel/XSheetObject.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include "vbapalette.hxx" + +namespace com { namespace sun { namespace star { + namespace container { class XIndexContainer; } + namespace drawing { class XControlShape; } +} } } + +// ============================================================================ + +typedef InheritedHelperInterfaceImpl1< ov::excel::XCharacters > ScVbaButtonCharacters_BASE; + +/** Simple implementation of the Characters symbol for drawing button objects. */ +class ScVbaButtonCharacters : public ScVbaButtonCharacters_BASE +{ +public: + explicit ScVbaButtonCharacters( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::beans::XPropertySet >& rxPropSet, + const ScVbaPalette& rPalette, + const css::uno::Any& rStart, + const css::uno::Any& rLength ) throw (css::uno::RuntimeException); + virtual ~ScVbaButtonCharacters(); + + // XCharacters attributes + virtual ::rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& rCaption ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setText( const ::rtl::OUString& rText ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFont( const css::uno::Reference< ov::excel::XFont >& rxFont ) throw (css::uno::RuntimeException); + + // XCharacters methods + virtual void SAL_CALL Insert( const ::rtl::OUString& rString ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + ::rtl::OUString getFullString() const throw (css::uno::RuntimeException); + void setFullString( const ::rtl::OUString& rString ) throw (css::uno::RuntimeException); + +private: + ScVbaPalette maPalette; + css::uno::Reference< css::beans::XPropertySet > mxPropSet; + sal_Int32 mnStart; + sal_Int32 mnLength; +}; + +// ============================================================================ + +typedef InheritedHelperInterfaceImpl1< ov::excel::XSheetObject > ScVbaSheetObject_BASE; + +/** Base class for drawing objects embedded in sheets. */ +class ScVbaSheetObjectBase : public ScVbaSheetObject_BASE +{ +public: + explicit ScVbaSheetObjectBase( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::frame::XModel >& rxModel, + const css::uno::Reference< css::drawing::XShape >& rxShape ) throw (css::uno::RuntimeException); + + // XSheetObject attributes + virtual double SAL_CALL getLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeft( double fLeft ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTop( double fTop ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( double fWidth ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( double fHeight ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getPlacement() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPlacement( sal_Int32 nPlacement ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getPrintObject() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPrintObject( sal_Bool bPrintObject ) throw (css::uno::RuntimeException); + + /** Sets default properties after a new object has been created. */ + void setDefaultProperties( sal_Int32 nIndex ) throw (css::uno::RuntimeException); + +protected: + /** Derived classes return the base name used for new objects. */ + virtual ::rtl::OUString implGetBaseName() const = 0; + /** Derived classes set default properties for new drawing objects. */ + virtual void implSetDefaultProperties() throw (css::uno::RuntimeException); + +protected: + ScVbaPalette maPalette; + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::drawing::XShape > mxShape; + css::uno::Reference< css::beans::XPropertySet > mxShapeProps; +}; + +// ============================================================================ + +typedef ::cppu::ImplInheritanceHelper1< ScVbaSheetObjectBase, ov::excel::XControlObject > ScVbaControlObject_BASE; + +class ScVbaControlObjectBase : public ScVbaControlObject_BASE +{ +public: + /** Specifies the listener used for OnAction events. */ + enum ListenerType + { + LISTENER_ACTION, /// XActionListener.actionPerformed + LISTENER_MOUSE, /// XMouseListener.mouseReleased + LISTENER_TEXT, /// XTextListener.textChanged + LISTENER_VALUE, /// XAdjustmentListener.adjustmentValueChanged + LISTENER_CHANGE /// XChangeListener.changed + }; + + explicit ScVbaControlObjectBase( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::frame::XModel >& rxModel, + const css::uno::Reference< css::container::XIndexContainer >& rxFormIC, + const css::uno::Reference< css::drawing::XControlShape >& rxControlShape, + ListenerType eListenerType ) throw (css::uno::RuntimeException); + + // XSheetObject attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getOnAction() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOnAction( const ::rtl::OUString& rMacroName ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getPrintObject() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPrintObject( sal_Bool bPrintObject ) throw (css::uno::RuntimeException); + + // XControlObject attributes + virtual sal_Bool SAL_CALL getAutoSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoSize( sal_Bool bAutoSize ) throw (css::uno::RuntimeException); + +protected: + sal_Int32 getModelIndexInForm() const throw (css::uno::RuntimeException); + +protected: + css::uno::Reference< css::container::XIndexContainer > mxFormIC; + css::uno::Reference< css::beans::XPropertySet > mxControlProps; + ::rtl::OUString maListenerType; + ::rtl::OUString maEventMethod; +}; + +// ============================================================================ + +typedef ::cppu::ImplInheritanceHelper1< ScVbaControlObjectBase, ov::excel::XButton > ScVbaButton_BASE; + +class ScVbaButton : public ScVbaButton_BASE +{ +public: + explicit ScVbaButton( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::frame::XModel >& rxModel, + const css::uno::Reference< css::container::XIndexContainer >& rxFormIC, + const css::uno::Reference< css::drawing::XControlShape >& rxControlShape ) throw (css::uno::RuntimeException); + + // XButton attributes + virtual ::rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& rCaption ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFont( const css::uno::Reference< ov::excel::XFont >& rxFont ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getHorizontalAlignment() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHorizontalAlignment( sal_Int32 nAlign ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getVerticalAlignment() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVerticalAlignment( sal_Int32 nAlign ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getOrientation() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOrientation( sal_Int32 nOrientation ) throw (css::uno::RuntimeException); + + // XButton methods + css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters( + const css::uno::Any& rStart, const css::uno::Any& rLength ) throw (css::uno::RuntimeException); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +protected: + virtual ::rtl::OUString implGetBaseName() const; + virtual void implSetDefaultProperties() throw (css::uno::RuntimeException); +}; + +// ============================================================================ + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbasheetobjects.cxx b/sc/source/ui/vba/vbasheetobjects.cxx new file mode 100644 index 000000000000..b05aa82722b8 --- /dev/null +++ b/sc/source/ui/vba/vbasheetobjects.cxx @@ -0,0 +1,537 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbasheetobjects.hxx" +#include <vector> +#include <rtl/math.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexContainer.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/form/FormComponentType.hpp> +#include <com/sun/star/form/XForm.hpp> +#include <com/sun/star/form/XFormComponent.hpp> +#include <com/sun/star/form/XFormsSupplier.hpp> +#include <oox/helper/helper.hxx> +#include "vbasheetobject.hxx" + +using ::rtl::OUString; +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +namespace { + +template< typename Type > +inline bool lclGetProperty( Type& orValue, const uno::Reference< beans::XPropertySet >& rxPropSet, const OUString& rPropName ) +{ + try + { + return rxPropSet->getPropertyValue( rPropName ) >>= orValue; + } + catch( uno::Exception& ) + { + } + return false; +} + +/** Rounds the passed value to a multiple of 0.75 and converts it to 1/100 mm. */ +inline double lclPointsToHmm( const uno::Any& rPoints ) throw (uno::RuntimeException) +{ + return PointsToHmm( ::rtl::math::approxFloor( rPoints.get< double >() / 0.75 ) * 0.75 ); +} + +} // namespace + +// ============================================================================ +// Base implementations +// ============================================================================ + +/** Container for a specific type of drawing object in a spreadsheet. + + Derived classes provide all required functionality specific to the type of + shapes covered by the container. + */ +class ScVbaObjectContainer : public ::cppu::WeakImplHelper1< container::XIndexAccess > +{ +public: + explicit ScVbaObjectContainer( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet, + const uno::Type& rVbaType ) throw (uno::RuntimeException); + + /** Returns the VBA helper interface of the VBA collection object. */ + inline const uno::Reference< XHelperInterface >& getParent() const { return mxParent; } + /** Returns the component context of the VBA collection object. */ + inline const uno::Reference< uno::XComponentContext >& getContext() const { return mxContext; } + /** Returns the VBA type information of the objects in this container. */ + inline const uno::Type& getVbaType() const { return maVbaType; } + + /** Collects all shapes supported by this instance and inserts them into + the internal shape vector. */ + void collectShapes() throw (uno::RuntimeException); + /** Creates and returns a new UNO shape. */ + uno::Reference< drawing::XShape > createShape( const awt::Point& rPos, const awt::Size& rSize ) throw (uno::RuntimeException); + /** Inserts the passed shape into the draw page and into this container, and returns its index in the draw page. */ + sal_Int32 insertShape( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException); + /** Creates and returns a new VBA implementation object for the passed shape. */ + ::rtl::Reference< ScVbaSheetObjectBase > createVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException); + /** Creates and returns a new VBA implementation object for the passed shape in an Any. */ + uno::Any createCollectionObject( const uno::Any& rSource ) throw (uno::RuntimeException); + /** Returns the VBA implementation object with the specified name. */ + uno::Any getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException); + + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException); + + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); + +protected: + /** Derived classes return true, if the passed shape is supported by the instance. */ + virtual bool implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const = 0; + /** Derived classes create and return a new VBA implementation object for the passed shape. */ + virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) = 0; + /** Derived classes return the service name of the UNO shape. */ + virtual OUString implGetShapeServiceName() const = 0; + + /** Returns the shape name via 'Name' property of the UNO shape. May be overwritten. */ + virtual OUString implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException); + /** Is called when a new UNO shape has been created but not yet inserted into the drawing page. */ + virtual void implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException); + /** Is called when a new UNO shape has been inserted into the drawing page. */ + virtual void implOnShapeInserted( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException); + +protected: + uno::Reference< XHelperInterface > mxParent; + uno::Reference< uno::XComponentContext > mxContext; + uno::Reference< frame::XModel > mxModel; + uno::Reference< lang::XMultiServiceFactory > mxFactory; + uno::Reference< drawing::XShapes > mxShapes; + +private: + typedef ::std::vector< uno::Reference< drawing::XShape > > ShapeVector; + const uno::Type maVbaType; + ShapeVector maShapes; +}; + +// ---------------------------------------------------------------------------- + +ScVbaObjectContainer::ScVbaObjectContainer( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet, + const uno::Type& rVbaType ) throw (uno::RuntimeException) : + mxParent( rxParent ), + mxContext( rxContext ), + mxModel( rxModel, uno::UNO_SET_THROW ), + mxFactory( rxModel, uno::UNO_QUERY_THROW ), + maVbaType( rVbaType ) +{ + uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupp( rxSheet, uno::UNO_QUERY_THROW ); + mxShapes.set( xDrawPageSupp->getDrawPage(), uno::UNO_QUERY_THROW ); +} + +void ScVbaObjectContainer::collectShapes() throw (uno::RuntimeException) +{ + maShapes.clear(); + for( sal_Int32 nIndex = 0, nCount = mxShapes->getCount(); nIndex < nCount; ++nIndex ) + { + uno::Reference< drawing::XShape > xShape( mxShapes->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + if( implPickShape( xShape ) ) + maShapes.push_back( xShape ); + } +} + +uno::Reference< drawing::XShape > ScVbaObjectContainer::createShape( const awt::Point& rPos, const awt::Size& rSize ) throw (uno::RuntimeException) +{ + uno::Reference< drawing::XShape > xShape( mxFactory->createInstance( implGetShapeServiceName() ), uno::UNO_QUERY_THROW ); + xShape->setPosition( rPos ); + xShape->setSize( rSize ); + implOnShapeCreated( xShape ); + return xShape; +} + +sal_Int32 ScVbaObjectContainer::insertShape( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) +{ + mxShapes->add( rxShape ); + maShapes.push_back( rxShape ); + implOnShapeInserted( rxShape ); + return mxShapes->getCount() - 1; +} + +::rtl::Reference< ScVbaSheetObjectBase > ScVbaObjectContainer::createVbaObject( + const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) +{ + return implCreateVbaObject( rxShape ); +} + +uno::Any ScVbaObjectContainer::createCollectionObject( const uno::Any& rSource ) throw (uno::RuntimeException) +{ + uno::Reference< drawing::XShape > xShape( rSource, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XSheetObject > xSheetObject( implCreateVbaObject( xShape ) ); + return uno::Any( xSheetObject ); +} + +uno::Any ScVbaObjectContainer::getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException) +{ + for( ShapeVector::iterator aIt = maShapes.begin(), aEnd = maShapes.end(); aIt != aEnd; ++aIt ) + if( rIndex == implGetShapeName( *aIt ) ) + return createCollectionObject( uno::Any( *aIt ) ); + throw uno::RuntimeException(); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScVbaObjectContainer::getCount() throw (uno::RuntimeException) +{ + return static_cast< sal_Int32 >( maShapes.size() ); +} + +uno::Any SAL_CALL ScVbaObjectContainer::getByIndex( sal_Int32 nIndex ) + throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( (0 <= nIndex) && (nIndex < getCount()) ) + return uno::Any( maShapes[ static_cast< size_t >( nIndex ) ] ); + throw lang::IndexOutOfBoundsException(); +} + +// XElementAccess + +uno::Type SAL_CALL ScVbaObjectContainer::getElementType() throw (uno::RuntimeException) +{ + return drawing::XShape::static_type( 0 ); +} + +sal_Bool SAL_CALL ScVbaObjectContainer::hasElements() throw (uno::RuntimeException) +{ + return !maShapes.empty(); +} + +// private + +OUString ScVbaObjectContainer::implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xPropSet( rxShape, uno::UNO_QUERY_THROW ); + return xPropSet->getPropertyValue( CREATE_OUSTRING( "Name" ) ).get< OUString >(); +} + +void ScVbaObjectContainer::implOnShapeCreated( const uno::Reference< drawing::XShape >& /*rxShape*/ ) throw (uno::RuntimeException) +{ +} + +void ScVbaObjectContainer::implOnShapeInserted( const uno::Reference< drawing::XShape >& /*rxShape*/ ) throw (uno::RuntimeException) +{ +} + +// ============================================================================ + +class ScVbaObjectEnumeration : public SimpleEnumerationBase +{ +public: + explicit ScVbaObjectEnumeration( const ScVbaObjectContainerRef& rxContainer ); + virtual uno::Any createCollectionObject( const uno::Any& rSource ); + +private: + ScVbaObjectContainerRef mxContainer; +}; + +// ---------------------------------------------------------------------------- + +ScVbaObjectEnumeration::ScVbaObjectEnumeration( const ScVbaObjectContainerRef& rxContainer ) : + SimpleEnumerationBase( rxContainer->getParent(), rxContainer->getContext(), rxContainer.get() ), + mxContainer( rxContainer ) +{ +} + +uno::Any ScVbaObjectEnumeration::createCollectionObject( const uno::Any& rSource ) +{ + return mxContainer->createCollectionObject( rSource ); +} + +// ============================================================================ + +ScVbaSheetObjectsBase::ScVbaSheetObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (css::uno::RuntimeException) : + ScVbaSheetObjects_BASE( rxContainer->getParent(), rxContainer->getContext(), rxContainer.get() ), + mxContainer( rxContainer ) +{ + mxContainer->collectShapes(); +} + +ScVbaSheetObjectsBase::~ScVbaSheetObjectsBase() +{ +} + +void ScVbaSheetObjectsBase::collectShapes() throw (uno::RuntimeException) +{ + mxContainer->collectShapes(); +} + +// XEnumerationAccess + +uno::Reference< container::XEnumeration > SAL_CALL ScVbaSheetObjectsBase::createEnumeration() throw (uno::RuntimeException) +{ + return new ScVbaObjectEnumeration( mxContainer ); +} + +// XElementAccess + +uno::Type SAL_CALL ScVbaSheetObjectsBase::getElementType() throw (uno::RuntimeException) +{ + return mxContainer->getVbaType(); +} + +// ScVbaCollectionBase + +uno::Any ScVbaSheetObjectsBase::createCollectionObject( const uno::Any& rSource ) +{ + return mxContainer->createCollectionObject( rSource ); +} + +uno::Any ScVbaSheetObjectsBase::getItemByStringIndex( const OUString& rIndex ) throw (uno::RuntimeException) +{ + return mxContainer->getItemByStringIndex( rIndex ); +} + +// ============================================================================ +// Graphic object containers supporting ooo.vba.excel.XGraphicObject +// ============================================================================ + +ScVbaGraphicObjectsBase::ScVbaGraphicObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (uno::RuntimeException) : + ScVbaGraphicObjects_BASE( rxContainer ) +{ +} + +// XGraphicObjects + +uno::Any SAL_CALL ScVbaGraphicObjectsBase::Add( const uno::Any& rLeft, const uno::Any& rTop, const uno::Any& rWidth, const uno::Any& rHeight ) throw (uno::RuntimeException) +{ + /* Extract double values from passed Anys (the lclPointsToHmm() helper + function will throw a RuntimeException on any error), and convert from + points to 1/100 mm. */ + awt::Point aPos( lclPointsToHmm( rLeft ), lclPointsToHmm( rTop ) ); + awt::Size aSize( lclPointsToHmm( rWidth ), lclPointsToHmm( rHeight ) ); + // TODO: translate coordinates for RTL sheets + if( (aPos.X < 0) || (aPos.Y < 0) || (aSize.Width <= 0) || (aSize.Height <= 0) ) + throw uno::RuntimeException(); + + // create the UNO shape + uno::Reference< drawing::XShape > xShape( mxContainer->createShape( aPos, aSize ), uno::UNO_SET_THROW ); + sal_Int32 nIndex = mxContainer->insertShape( xShape ); + + // create and return the VBA object + ::rtl::Reference< ScVbaSheetObjectBase > xVbaObject = mxContainer->createVbaObject( xShape ); + xVbaObject->setDefaultProperties( nIndex ); + return uno::Any( uno::Reference< excel::XSheetObject >( xVbaObject.get() ) ); +} + +// ============================================================================ +// Drawing controls +// ============================================================================ + +class ScVbaControlContainer : public ScVbaObjectContainer +{ +public: + explicit ScVbaControlContainer( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet, + const uno::Type& rVbaType, + const OUString& rModelServiceName, + sal_Int16 nComponentType ) throw (uno::RuntimeException); + +protected: + uno::Reference< container::XIndexContainer > createForm() throw (uno::RuntimeException); + + virtual bool implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const; + virtual OUString implGetShapeServiceName() const; + virtual bool implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const; + virtual OUString implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException); + virtual void implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException); + +protected: + uno::Reference< container::XIndexContainer > mxFormIC; + OUString maModelServiceName; + sal_Int16 mnComponentType; +}; + +// ---------------------------------------------------------------------------- + +ScVbaControlContainer::ScVbaControlContainer( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet, + const uno::Type& rVbaType, + const OUString& rModelServiceName, + sal_Int16 nComponentType ) throw (uno::RuntimeException) : + ScVbaObjectContainer( rxParent, rxContext, rxModel, rxSheet, rVbaType ), + maModelServiceName( rModelServiceName ), + mnComponentType( nComponentType ) +{ +} + +uno::Reference< container::XIndexContainer > ScVbaControlContainer::createForm() throw (uno::RuntimeException) +{ + if( !mxFormIC.is() ) + { + uno::Reference< form::XFormsSupplier > xFormsSupp( mxShapes, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameContainer > xFormsNC( xFormsSupp->getForms(), uno::UNO_SET_THROW ); + OUString aFormName = CREATE_OUSTRING( "Standard" ); + if( xFormsNC->hasByName( aFormName ) ) + { + mxFormIC.set( xFormsNC->getByName( aFormName ), uno::UNO_QUERY_THROW ); + } + else + { + uno::Reference< form::XForm > xForm( mxFactory->createInstance( CREATE_OUSTRING( "com.sun.star.form.component.Form" ) ), uno::UNO_QUERY_THROW ); + xFormsNC->insertByName( aFormName, uno::Any( xForm ) ); + mxFormIC.set( xForm, uno::UNO_QUERY_THROW ); + } + } + return mxFormIC; +} + +bool ScVbaControlContainer::implPickShape( const uno::Reference< drawing::XShape >& rxShape ) const +{ + try + { + uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xModelProps( xControlShape->getControl(), uno::UNO_QUERY_THROW ); + sal_Int16 nClassId = -1; + return lclGetProperty( nClassId, xModelProps, CREATE_OUSTRING( "ClassId" ) ) && + (nClassId == mnComponentType) && implCheckProperties( xModelProps ); + } + catch( uno::Exception& ) + { + } + return false; +} + +OUString ScVbaControlContainer::implGetShapeServiceName() const +{ + return CREATE_OUSTRING( "com.sun.star.drawing.ControlShape" ); +} + +bool ScVbaControlContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& /*rxModelProps*/ ) const +{ + return true; +} + +OUString ScVbaControlContainer::implGetShapeName( const uno::Reference< drawing::XShape >& rxShape ) const throw (uno::RuntimeException) +{ + uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW ); + return uno::Reference< container::XNamed >( xControlShape->getControl(), uno::UNO_QUERY_THROW )->getName(); +} + +void ScVbaControlContainer::implOnShapeCreated( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) +{ + // passed shape must be a control shape + uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW ); + + // create the UNO control model + uno::Reference< form::XFormComponent > xFormComponent( mxFactory->createInstance( maModelServiceName ), uno::UNO_QUERY_THROW ); + uno::Reference< awt::XControlModel > xControlModel( xFormComponent, uno::UNO_QUERY_THROW ); + + // insert the control model into the form and the shape + createForm(); + mxFormIC->insertByIndex( mxFormIC->getCount(), uno::Any( xFormComponent ) ); + xControlShape->setControl( xControlModel ); +} + +// ============================================================================ +// Push button +// ============================================================================ + +class ScVbaButtonContainer : public ScVbaControlContainer +{ +public: + explicit ScVbaButtonContainer( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException); + +protected: + virtual ScVbaSheetObjectBase* implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException); + virtual bool implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const; +}; + +// ---------------------------------------------------------------------------- + +ScVbaButtonContainer::ScVbaButtonContainer( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException) : + ScVbaControlContainer( + rxParent, rxContext, rxModel, rxSheet, + excel::XButton::static_type( 0 ), + CREATE_OUSTRING( "com.sun.star.form.component.CommandButton" ), + form::FormComponentType::COMMANDBUTTON ) +{ +} + +ScVbaSheetObjectBase* ScVbaButtonContainer::implCreateVbaObject( const uno::Reference< drawing::XShape >& rxShape ) throw (uno::RuntimeException) +{ + uno::Reference< drawing::XControlShape > xControlShape( rxShape, uno::UNO_QUERY_THROW ); + return new ScVbaButton( mxParent, mxContext, mxModel, createForm(), xControlShape ); +} + +bool ScVbaButtonContainer::implCheckProperties( const uno::Reference< beans::XPropertySet >& rxModelProps ) const +{ + // do not insert toggle buttons into the 'Buttons' collection + bool bToggle = false; + return lclGetProperty( bToggle, rxModelProps, CREATE_OUSTRING( "Toggle" ) ) && !bToggle; +} + +// ============================================================================ + +ScVbaButtons::ScVbaButtons( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< frame::XModel >& rxModel, + const uno::Reference< sheet::XSpreadsheet >& rxSheet ) throw (uno::RuntimeException) : + ScVbaGraphicObjectsBase( new ScVbaButtonContainer( rxParent, rxContext, rxModel, rxSheet ) ) +{ +} + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaButtons, "ooo.vba.excel.Buttons" ) + +// ============================================================================ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbasheetobjects.hxx b/sc/source/ui/vba/vbasheetobjects.hxx new file mode 100644 index 000000000000..c59ec8882e91 --- /dev/null +++ b/sc/source/ui/vba/vbasheetobjects.hxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef SC_VBA_SHEETOBJECTS_HXX +#define SC_VBA_SHEETOBJECTS_HXX + +#include <ooo/vba/excel/XGraphicObjects.hpp> +#include <vbahelper/vbacollectionimpl.hxx> +#include <rtl/ref.hxx> + +namespace com { namespace sun { namespace star { + namespace container { class XEnumeration; } + namespace frame { class XModel; } + namespace sheet { class XSpreadsheet; } +} } } + +// ============================================================================ + +class ScVbaObjectContainer; +typedef ::rtl::Reference< ScVbaObjectContainer > ScVbaObjectContainerRef; + +// ============================================================================ + +typedef CollTestImplHelper< ov::XCollection > ScVbaSheetObjects_BASE; + +/** Base class for collections containing a specific type of drawing object + embedded in a sheet (worksheet, chart sheet, or dialog sheet). + */ +class ScVbaSheetObjectsBase : public ScVbaSheetObjects_BASE +{ +public: + explicit ScVbaSheetObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (css::uno::RuntimeException); + virtual ~ScVbaSheetObjectsBase(); + + /** Updates the collection by fetching all shapes from the draw page. */ + void collectShapes() throw (css::uno::RuntimeException); + + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + + // ScVbaCollectionBase + virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource ); + virtual css::uno::Any getItemByStringIndex( const ::rtl::OUString& rIndex ) throw (css::uno::RuntimeException); + +protected: + ScVbaObjectContainerRef mxContainer; +}; + +// ============================================================================ + +typedef ::cppu::ImplInheritanceHelper1< ScVbaSheetObjectsBase, ov::excel::XGraphicObjects > ScVbaGraphicObjects_BASE; + +/** Base class for collections containing a specific type of graphic object + from a sheet. + */ +class ScVbaGraphicObjectsBase : public ScVbaGraphicObjects_BASE +{ +public: + explicit ScVbaGraphicObjectsBase( const ScVbaObjectContainerRef& rxContainer ) throw (css::uno::RuntimeException); + + // XGraphicObjects + virtual css::uno::Any SAL_CALL Add( + const css::uno::Any& rLeft, + const css::uno::Any& rTop, + const css::uno::Any& rWidth, + const css::uno::Any& rHeight ) throw (css::uno::RuntimeException); +}; + +// ============================================================================ + +/** Collection containing all button controls from a sheet (not ActiveX controls). */ +class ScVbaButtons : public ScVbaGraphicObjectsBase +{ +public: + explicit ScVbaButtons( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::frame::XModel >& rxModel, + const css::uno::Reference< css::sheet::XSpreadsheet >& rxSheet ) throw (css::uno::RuntimeException); + + VBAHELPER_DECL_XHELPERINTERFACE +}; + +// ============================================================================ + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbastyle.cxx b/sc/source/ui/vba/vbastyle.cxx new file mode 100644 index 000000000000..2594effca2e0 --- /dev/null +++ b/sc/source/ui/vba/vbastyle.cxx @@ -0,0 +1,189 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbastyle.hxx" +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +static rtl::OUString DISPLAYNAME( RTL_CONSTASCII_USTRINGPARAM("DisplayName") ); + + + +uno::Reference< container::XNameAccess > +ScVbaStyle::getStylesNameContainer( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) +{ + uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW); + uno::Reference< container::XNameAccess > xStylesAccess( xStyleSupplier->getStyleFamilies()->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ) ), uno::UNO_QUERY_THROW ); + return xStylesAccess; +} + +uno::Reference< beans::XPropertySet > +lcl_getStyleProps( const rtl::OUString& sStyleName, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException, uno::RuntimeException ) +{ + + uno::Reference< beans::XPropertySet > xStyleProps( ScVbaStyle::getStylesNameContainer( xModel )->getByName( sStyleName ), uno::UNO_QUERY_THROW ); + return xStyleProps; +} + + +void ScVbaStyle::initialise() throw ( uno::RuntimeException ) +{ + if (!mxModel.is() ) + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved")) ); + uno::Reference< lang::XServiceInfo > xServiceInfo( mxPropertySet, uno::UNO_QUERY_THROW ); + if ( !xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CellStyle" ) ) ) ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + mxStyle.set( mxPropertySet, uno::UNO_QUERY_THROW ); + + uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( mxModel, uno::UNO_QUERY_THROW ); + mxStyleFamilyNameContainer.set( ScVbaStyle::getStylesNameContainer( mxModel ), uno::UNO_QUERY_THROW ); + +} + +ScVbaStyle::ScVbaStyle( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const rtl::OUString& sStyleName, const uno::Reference< frame::XModel >& _xModel ) throw ( script::BasicErrorException, uno::RuntimeException ) : ScVbaStyle_BASE( xParent, xContext, lcl_getStyleProps( sStyleName, _xModel ), _xModel, false ), mxModel( _xModel ) +{ + try + { + initialise(); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +ScVbaStyle::ScVbaStyle( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, const uno::Reference< frame::XModel >& _xModel ) throw ( script::BasicErrorException, uno::RuntimeException ) : ScVbaStyle_BASE( xParent, xContext, _xPropertySet, _xModel, false ), mxModel( _xModel ) +{ + try + { + initialise(); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + + +::sal_Bool SAL_CALL +ScVbaStyle::BuiltIn() throw (script::BasicErrorException, uno::RuntimeException) +{ + return !mxStyle->isUserDefined(); + +} +void SAL_CALL +ScVbaStyle::setName( const ::rtl::OUString& Name ) throw (script::BasicErrorException, uno::RuntimeException) +{ + mxStyle->setName(Name); +} + +::rtl::OUString SAL_CALL +ScVbaStyle::getName() throw (script::BasicErrorException, uno::RuntimeException) +{ + return mxStyle->getName(); +} + +void SAL_CALL +ScVbaStyle::setNameLocal( const ::rtl::OUString& NameLocal ) throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + mxPropertySet->setPropertyValue(DISPLAYNAME, uno::makeAny( NameLocal ) ); + } + catch (uno::Exception& e) + { + DebugHelper::exception(e); + } +} + +::rtl::OUString SAL_CALL +ScVbaStyle::getNameLocal() throw (script::BasicErrorException, uno::RuntimeException) +{ + rtl::OUString sName; + try + { + mxPropertySet->getPropertyValue(DISPLAYNAME) >>= sName; + } + catch (uno::Exception e) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() ); + } + return sName; +} + +void SAL_CALL +ScVbaStyle::Delete() throw (script::BasicErrorException, uno::RuntimeException) +{ + try + { + mxStyleFamilyNameContainer->removeByName(mxStyle->getName()); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +void SAL_CALL +ScVbaStyle::setMergeCells( const uno::Any& /*MergeCells*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); +} + +uno::Any SAL_CALL +ScVbaStyle::getMergeCells( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString()); + return uno::Any(); +} + + +rtl::OUString& +ScVbaStyle::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaStyle") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaStyle::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XStyle" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbastyle.hxx b/sc/source/ui/vba/vbastyle.hxx new file mode 100644 index 000000000000..c965146a1703 --- /dev/null +++ b/sc/source/ui/vba/vbastyle.hxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_STYLE_HXX +#define SC_VBA_STYLE_HXX +#include <ooo/vba/excel/XStyle.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include "vbaformat.hxx" + + +typedef ScVbaFormat< ov::excel::XStyle > ScVbaStyle_BASE; + +class ScVbaStyle : public ScVbaStyle_BASE +{ +protected: + css::uno::Reference< css::style::XStyle > mxStyle; + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::container::XNameContainer > mxStyleFamilyNameContainer; + void initialise() throw ( css::uno::RuntimeException ); +public: + ScVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const rtl::OUString& sStyleName, const css::uno::Reference< css::frame::XModel >& _xModel ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + ScVbaStyle( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::beans::XPropertySet >& _xPropertySet, const css::uno::Reference< css::frame::XModel >& _xModel ) throw ( css::script::BasicErrorException, css::uno::RuntimeException ); + virtual ~ScVbaStyle(){} + static css::uno::Reference< css::container::XNameAccess > getStylesNameContainer( const css::uno::Reference< css::frame::XModel >& xModel ) throw( css::uno::RuntimeException ); + virtual css::uno::Reference< ov::XHelperInterface > thisHelperIface() { return this; }; + // XStyle Methods + virtual ::sal_Bool SAL_CALL BuiltIn() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& Name ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getName() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setNameLocal( const ::rtl::OUString& NameLocal ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getNameLocal() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL Delete() throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XFormat + virtual void SAL_CALL setMergeCells( const css::uno::Any& MergeCells ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getMergeCells( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); +/* + // XFormat + virtual css::uno::Reference< ::ooo::vba::excel::XBorders > SAL_CALL Borders( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Reference< ::ooo::vba::excel::XFont > SAL_CALL Font( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Reference< ::ooo::vba::excel::XInterior > SAL_CALL Interior( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setNumberFormat( const css::uno::Any& NumberFormat ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getNumberFormat( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setNumberFormatLocal( const css::uno::Any& NumberFormatLocal ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getNumberFormatLocal( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setIndentLevel( const css::uno::Any& IndentLevel ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getIndentLevel( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setHorizontalAlignment( const css::uno::Any& HorizontalAlignment ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getHorizontalAlignment( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setVerticalAlignment( const css::uno::Any& VerticalAlignment ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getVerticalAlignment( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setOrientation( const css::uno::Any& Orientation ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getOrientation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setShrinkToFit( const css::uno::Any& ShrinkToFit ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getShrinkToFit( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setWrapText( const css::uno::Any& WrapText ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getWrapText( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setLocked( const css::uno::Any& Locked ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getLocked( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setFormulaHidden( const css::uno::Any& FormulaHidden ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; +/ virtual css::uno::Any SAL_CALL getFormulaHidden( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual void SAL_CALL setMergeCells( const css::uno::Any& MergeCells ) throw (css::script::BasicErrorException, css::uno::RuntimeException) = 0; + virtual css::uno::Any SAL_CALL getMergeCells( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) = 0; + virtual void SAL_CALL setReadingOrder( const css::uno::Any& ReadingOrder ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; + virtual css::uno::Any SAL_CALL getReadingOrder( ) throw (css::script::BasicErrorException, css::uno::RuntimeException);; +*/ + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_AXIS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbastyles.cxx b/sc/source/ui/vba/vbastyles.cxx new file mode 100644 index 000000000000..1ffc2af27997 --- /dev/null +++ b/sc/source/ui/vba/vbastyles.cxx @@ -0,0 +1,185 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbastyles.hxx" +#include "vbastyle.hxx" +#include <ooo/vba/excel/XRange.hpp> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +static rtl::OUString SDEFAULTCELLSTYLENAME( RTL_CONSTASCII_USTRINGPARAM("Default") ); +css::uno::Any +lcl_createAPIStyleToVBAObject( const css::uno::Any& aObject, const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) +{ + uno::Reference< beans::XPropertySet > xStyleProps( aObject, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XStyle > xStyle( new ScVbaStyle( xParent, xContext, xStyleProps, xModel ) ); + return uno::makeAny( xStyle ); +} + + +ScVbaStyles::ScVbaStyles( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException ) : ScVbaStyles_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( ScVbaStyle::getStylesNameContainer( xModel ), uno::UNO_QUERY_THROW ) ), mxModel( xModel ), mxParent( xParent ) +{ + try + { + mxMSF.set( mxModel, uno::UNO_QUERY_THROW ); + mxNameContainerCellStyles.set( m_xNameAccess, uno::UNO_QUERY_THROW ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +uno::Sequence< rtl::OUString > +ScVbaStyles::getStyleNames() throw ( uno::RuntimeException ) +{ + return mxNameContainerCellStyles->getElementNames(); +} + + +uno::Any +ScVbaStyles::createCollectionObject(const uno::Any& aObject) +{ + return lcl_createAPIStyleToVBAObject( aObject, mxParent, mxContext, mxModel ); +} + +uno::Type SAL_CALL +ScVbaStyles::getElementType() throw (uno::RuntimeException) +{ + return excel::XStyle::static_type(0); +} + +class EnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference<container::XIndexAccess > m_xIndexAccess; + uno::Reference<XHelperInterface > m_xParent; + uno::Reference<uno::XComponentContext > m_xContext; + uno::Reference<frame::XModel > m_xModel; + + sal_Int32 nIndex; +public: + EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference<XHelperInterface >& xParent, const uno::Reference<uno::XComponentContext >& xContext, const uno::Reference<frame::XModel >& xModel ) : m_xIndexAccess( xIndexAccess ), m_xParent( xParent ), m_xContext( xContext ), m_xModel( xModel ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + return lcl_createAPIStyleToVBAObject( m_xIndexAccess->getByIndex( nIndex++ ), m_xParent, m_xContext, m_xModel ); + throw container::NoSuchElementException(); + } +}; + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaStyles::createEnumeration() throw (uno::RuntimeException) +{ + return new EnumWrapper( m_xIndexAccess, mxParent, mxContext, mxModel ); +} + +uno::Reference< excel::XStyle > SAL_CALL +ScVbaStyles::Add( const ::rtl::OUString& _sName, const uno::Any& _aBasedOn ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< excel::XStyle > aRet; + try + { + rtl::OUString sParentCellStyleName( RTL_CONSTASCII_USTRINGPARAM("Default")); + if ( _aBasedOn.hasValue() ) + { + uno::Reference< excel::XRange > oRange; + if ( _aBasedOn >>= oRange) + { + uno::Reference< excel::XStyle > oStyle( oRange->getStyle(), uno::UNO_QUERY_THROW ); + if ( oStyle.is() ) + { + sParentCellStyleName = oStyle->getName(); + } + else + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString() ); + } + } + else + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); + } + } + + uno::Reference< style::XStyle > xStyle( mxMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.CellStyle"))), uno::UNO_QUERY_THROW ); + + if (!mxNameContainerCellStyles->hasByName(_sName)) + { + mxNameContainerCellStyles->insertByName(_sName, uno::makeAny( xStyle) ); + } + if (!sParentCellStyleName.equals(SDEFAULTCELLSTYLENAME)) + { + xStyle->setParentStyle( sParentCellStyleName ); + } + aRet.set( Item( uno::makeAny( _sName ), uno::Any() ), uno::UNO_QUERY_THROW ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } + return aRet; +} + +void +ScVbaStyles::Delete(const rtl::OUString _sStyleName) throw ( script::BasicErrorException ) +{ + try + { + if (mxNameContainerCellStyles->hasByName( _sStyleName ) ) + mxNameContainerCellStyles->removeByName( _sStyleName ); + } + catch (uno::Exception& ) + { + DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString()); + } +} + +rtl::OUString& +ScVbaStyles::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaStyles") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaStyles::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XStyles" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbastyles.hxx b/sc/source/ui/vba/vbastyles.hxx new file mode 100644 index 000000000000..b9677954463f --- /dev/null +++ b/sc/source/ui/vba/vbastyles.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_STYLES_HXX +#define SC_VBA_STYLES_HXX +#include <ooo/vba/excel/XStyles.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::excel::XStyles > ScVbaStyles_BASE; +class ScVbaStyles: public ScVbaStyles_BASE +{ + css::uno::Reference< css::frame::XModel > mxModel; + // hard ref to parent ( perhaps we should try this in the + // XHelperInterface itself + css::uno::Reference< ov::XHelperInterface > mxParent; + css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; + css::uno::Reference< css::container::XNameContainer > mxNameContainerCellStyles; +public: + ScVbaStyles( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::script::BasicErrorException ); + css::uno::Sequence< rtl::OUString > getStyleNames() throw ( css::uno::RuntimeException ); + void Delete(const rtl::OUString _sStyleName) throw ( css::script::BasicErrorException ); + // XStyles + virtual css::uno::Reference< ov::excel::XStyle > SAL_CALL Add( const ::rtl::OUString& Name, const css::uno::Any& BasedOn ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject(const css::uno::Any&); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbatextboxshape.cxx b/sc/source/ui/vba/vbatextboxshape.cxx new file mode 100644 index 000000000000..558d33111cd4 --- /dev/null +++ b/sc/source/ui/vba/vbatextboxshape.cxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbatextboxshape.hxx" +#include "vbacharacters.hxx" +#include <com/sun/star/text/XSimpleText.hpp> +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaTextBoxShape::ScVbaTextBoxShape( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel ) : TextBoxShapeImpl_BASE( uno::Reference< XHelperInterface >(), xContext, xShape, xShapes, xModel, ScVbaShape::getType( xShape ) ) +{ + m_xTextRange.set( xShape , uno::UNO_QUERY_THROW ); + m_xModel.set( xModel ); +} + +rtl::OUString SAL_CALL +ScVbaTextBoxShape::getText() throw (css::uno::RuntimeException) +{ + return m_xTextRange->getString(); +} + +void SAL_CALL +ScVbaTextBoxShape::setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException) +{ + m_xTextRange->setString( _text ); +} + +uno::Reference< excel::XCharacters > SAL_CALL +ScVbaTextBoxShape::characters( const uno::Any& Start, const uno::Any& Length ) throw (uno::RuntimeException) +{ + ScDocShell* pDocShell = excel::getDocShell( m_xModel ); + ScDocument* pDoc = pDocShell ? pDocShell->GetDocument() : NULL; + + if ( !pDoc ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Failed to access document from shell" ) ), uno::Reference< uno::XInterface >() ); + uno::Reference< text::XSimpleText > xSimple( m_xTextRange, uno::UNO_QUERY_THROW ); + + ScVbaPalette aPalette( pDoc->GetDocumentShell() ); + return new ScVbaCharacters( this, mxContext, aPalette, xSimple, Start, Length, sal_True ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbatextboxshape.hxx b/sc/source/ui/vba/vbatextboxshape.hxx new file mode 100644 index 000000000000..0947bea6868c --- /dev/null +++ b/sc/source/ui/vba/vbatextboxshape.hxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_TEXTBOX_HXX +#define SC_VBA_TEXTBOX_HXX +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/text/XTextRange.hpp> +#include <ooo/vba/msforms/XTextBoxShape.hpp> +#include <vbahelper/vbashape.hxx> +#include "excelvbahelper.hxx" +#include "vbacharacters.hxx" + +typedef cppu::ImplInheritanceHelper1< ScVbaShape, ov::msforms::XTextBoxShape > TextBoxShapeImpl_BASE; + +class ScVbaTextBoxShape : public TextBoxShapeImpl_BASE +{ + css::uno::Reference< css::text::XTextRange > m_xTextRange; + css::uno::Reference< css::frame::XModel > m_xModel; +public: + ScVbaTextBoxShape( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel ); + + // Attributes + virtual rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XCharacters > SAL_CALL characters( const css::uno::Any& Start, const css::uno::Any& Length ) throw (css::uno::RuntimeException); +}; +#endif //SC_VBA_TEXTBOX_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbatextframe.cxx b/sc/source/ui/vba/vbatextframe.cxx new file mode 100644 index 000000000000..c00af2d94775 --- /dev/null +++ b/sc/source/ui/vba/vbatextframe.cxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> +#include <com/sun/star/drawing/TextFitToSizeType.hpp> +#include <com/sun/star/text/XText.hpp> +#include "vbatextframe.hxx" +#include "vbacharacters.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaTextFrame::ScVbaTextFrame( uno::Sequence< uno::Any> const & args, uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : ScVbaTextFrame_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< drawing::XShape >( args, 1, false ) ) +{ +} + +// Methods +uno::Any SAL_CALL +ScVbaTextFrame::Characters() throw (uno::RuntimeException) +{ + uno::Reference< text::XSimpleText > xSimpleText( m_xShape, uno::UNO_QUERY_THROW ); + ScVbaPalette aPalette( SfxObjectShell::Current() ); + uno::Any aStart( sal_Int32( 1 ) ); + uno::Any aLength(sal_Int32( -1 ) ); + return uno::makeAny( uno::Reference< ov::excel::XCharacters >( new ScVbaCharacters( this, mxContext, aPalette, xSimpleText, aStart, aLength, sal_True ) ) ); +} + +rtl::OUString& +ScVbaTextFrame::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaTextFrame") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaTextFrame::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.TextFrame" ) ); + } + return aServiceNames; +} + +namespace textframe +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaTextFrame, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaTextFrame", + "ooo.vba.excel.TextFrame" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbatextframe.hxx b/sc/source/ui/vba/vbatextframe.hxx new file mode 100644 index 000000000000..7e2b6b81ee88 --- /dev/null +++ b/sc/source/ui/vba/vbatextframe.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_TEXTFRAME_HXX +#define SC_VBA_TEXTFRAME_HXX +#include <ooo/vba/excel/XTextFrame.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbatextframe.hxx> + +//typedef InheritedHelperInterfaceImpl1< ov::excel::XTextFrame > ScVbaTextFrame_BASE; +typedef cppu::ImplInheritanceHelper1< VbaTextFrame, ov::excel::XTextFrame > ScVbaTextFrame_BASE; + +class ScVbaTextFrame : public ScVbaTextFrame_BASE +{ +public: + ScVbaTextFrame( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext ) throw ( css::lang::IllegalArgumentException ); + virtual ~ScVbaTextFrame() {} + // Methods + virtual css::uno::Any SAL_CALL Characters( ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; + +#endif//SC_VBA_TEXTFRAME_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbatitle.hxx b/sc/source/ui/vba/vbatitle.hxx new file mode 100644 index 000000000000..5e1594b8786c --- /dev/null +++ b/sc/source/ui/vba/vbatitle.hxx @@ -0,0 +1,166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_TITLE_HXX +#define SC_VBA_TITLE_HXX + +#include <vbahelper/vbahelperinterface.hxx> +#include "excelvbahelper.hxx" +#include "vbainterior.hxx" +#include "vbafont.hxx" +#include "vbapalette.hxx" +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/excel/XTitle.hpp> +#include <ooo/vba/excel/XCharacters.hpp> +#include <basic/sberrors.hxx> +#include <memory> + +template< typename Ifc1 > +class TitleImpl : public InheritedHelperInterfaceImpl< Ifc1 > +{ +typedef InheritedHelperInterfaceImpl< Ifc1 > BaseClass; + +protected: + css::uno::Reference< css::drawing::XShape > xTitleShape; + css::uno::Reference< css::beans::XPropertySet > xShapePropertySet; + std::auto_ptr<ov::ShapeHelper> oShapeHelper; + ScVbaPalette m_Palette; +public: + TitleImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& _xTitleShape ) : BaseClass( xParent, xContext ), xTitleShape( _xTitleShape ) + { + xShapePropertySet.set( xTitleShape, css::uno::UNO_QUERY_THROW ); + oShapeHelper.reset( new ov::ShapeHelper(xTitleShape) ); + } + css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + // #TODO find out what the proper parent should be + // leaving as set by the helperapi for the moment + // #TODO we really need the ScDocument to pass to ScVbaInterior + // otherwise attemps to access the palette will fail + return new ScVbaInterior( BaseClass::mxParent, BaseClass::mxContext, xShapePropertySet ); + } + css::uno::Reference< ov::excel::XFont > SAL_CALL Font( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + // #TODO find out what the proper parent should be + // leaving as set by the helperapi for the moment + return new ScVbaFont( BaseClass::mxParent, BaseClass::mxContext, m_Palette, xShapePropertySet ); + + } + void SAL_CALL setText( const ::rtl::OUString& Text ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + try + { + xShapePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ), css::uno::makeAny( Text )); + } + catch ( css::uno::Exception& ) + { + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + } + ::rtl::OUString SAL_CALL getText( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + ::rtl::OUString sText; + try + { + xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ) ) >>= sText; + } + catch ( css::uno::Exception& ) + { + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return sText; + } + + css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + // #FIXME #TODO the helperapi Characters implementation doesn't + // seem to do very much, need to know how the existing Characters + // impl ( that we use for Range ) can be reused + return css::uno::Reference< ov::excel::XCharacters > (); + } + + void SAL_CALL setTop( double Top ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + oShapeHelper->setTop( Top ); + } + double SAL_CALL getTop( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + return oShapeHelper->getTop(); + } + void SAL_CALL setLeft( double Left ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + oShapeHelper->setLeft( Left ); + } + double SAL_CALL getLeft( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + return oShapeHelper->getLeft(); + } + void SAL_CALL setOrientation( ::sal_Int32 _nOrientation ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + try + { + xShapePropertySet->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation")), css::uno::makeAny(_nOrientation*100)); + } + catch (css::uno::Exception& ) + { + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + } + ::sal_Int32 SAL_CALL getOrientation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + sal_Int32 nSOOrientation = 0; + try + { + xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation"))) >>= nSOOrientation; + } + catch (css::uno::Exception& ) + { + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + return static_cast< sal_Int32 >(nSOOrientation / 100) ; + } +// XHelperInterface + rtl::OUString& getServiceImplName() + { + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("TitleImpl") ); + return sImplName; + } + css::uno::Sequence< rtl::OUString > getServiceNames() + { + static css::uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XTitle" ) ); + } + return aServiceNames; + } +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbavalidation.cxx b/sc/source/ui/vba/vbavalidation.cxx new file mode 100644 index 000000000000..229e8f41c5cd --- /dev/null +++ b/sc/source/ui/vba/vbavalidation.cxx @@ -0,0 +1,346 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbavalidation.hxx" +#include "vbaformatcondition.hxx" +#include <com/sun/star/sheet/XSheetCondition.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> +#include <com/sun/star/sheet/ValidationAlertStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/excel/XlDVType.hpp> +#include <ooo/vba/excel/XlFormatConditionOperator.hpp> +#include <ooo/vba/excel/XlDVAlertStyle.hpp> + +#include "unonames.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +const static rtl::OUString VALIDATION( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_VALIDAT ) ); +const static rtl::OUString IGNOREBLANK( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_IGNOREBL ) ); +const static rtl::OUString SHOWINPUT( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHOWINP ) ); +const static rtl::OUString SHOWERROR( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHOWERR ) ); +const static rtl::OUString ERRORTITLE( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ERRTITLE ) ); +const static rtl::OUString INPUTTITLE( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_INPTITLE ) ); +const static rtl::OUString INPUTMESS( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_INPMESS ) ); +const static rtl::OUString ERRORMESS( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ERRMESS ) ); +const static rtl::OUString STYPE( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_TYPE ) ); +const static rtl::OUString SHOWLIST( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHOWLIST ) ); +const static rtl::OUString ALERTSTYLE( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ERRALSTY ) ); + +void +lcl_setValidationProps( const uno::Reference< table::XCellRange >& xRange, const uno::Reference< beans::XPropertySet >& xProps ) +{ + uno::Reference< beans::XPropertySet > xRangeProps( xRange, uno::UNO_QUERY_THROW ); + xRangeProps->setPropertyValue( VALIDATION , uno::makeAny( xProps ) ); +} + +uno::Reference< beans::XPropertySet > +lcl_getValidationProps( const uno::Reference< table::XCellRange >& xRange ) +{ + uno::Reference< beans::XPropertySet > xProps( xRange, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xValProps; + xValProps.set( xProps->getPropertyValue( VALIDATION ), uno::UNO_QUERY_THROW ); + return xValProps; +} + +::sal_Bool SAL_CALL +ScVbaValidation::getIgnoreBlank() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + sal_Bool bBlank = sal_False; + xProps->getPropertyValue( IGNOREBLANK ) >>= bBlank; + return bBlank; +} + +void SAL_CALL +ScVbaValidation::setIgnoreBlank( ::sal_Bool _ignoreblank ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + xProps->setPropertyValue( IGNOREBLANK, uno::makeAny( _ignoreblank ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::sal_Bool SAL_CALL +ScVbaValidation::getInCellDropdown() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + sal_Int32 nShowList = 0; + xProps->getPropertyValue( SHOWLIST ) >>= nShowList; + return ( nShowList ? sal_True : sal_False ); +} + +void SAL_CALL +ScVbaValidation::setInCellDropdown( ::sal_Bool _incelldropdown ) throw (uno::RuntimeException) +{ + sal_Int32 nDropDown = sal_False; + if ( _incelldropdown ) + nDropDown = 1; + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps(m_xRange) ); + xProps->setPropertyValue( SHOWLIST, uno::makeAny( nDropDown ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::sal_Bool SAL_CALL +ScVbaValidation::getShowInput() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + sal_Bool bShowInput = sal_False; + xProps->getPropertyValue( SHOWINPUT ) >>= bShowInput; + return bShowInput; +} + +void SAL_CALL +ScVbaValidation:: setShowInput( ::sal_Bool _showinput ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps(m_xRange) ); + xProps->setPropertyValue( IGNOREBLANK, uno::makeAny( _showinput ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::sal_Bool SAL_CALL +ScVbaValidation::getShowError() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + sal_Bool bShowError = sal_False; + xProps->getPropertyValue( SHOWERROR ) >>= bShowError; + return bShowError; +} + +void SAL_CALL +ScVbaValidation::setShowError( ::sal_Bool _showerror ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + xProps->setPropertyValue( SHOWERROR, uno::makeAny( _showerror ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::rtl::OUString SAL_CALL +ScVbaValidation::getErrorTitle() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + rtl::OUString sErrorTitle; + xProps->getPropertyValue( ERRORTITLE ) >>= sErrorTitle; + return sErrorTitle; +} + +void +ScVbaValidation::setErrorTitle( const rtl::OUString& _errormessage ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + xProps->setPropertyValue( ERRORTITLE, uno::makeAny( _errormessage ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::rtl::OUString SAL_CALL +ScVbaValidation::getInputMessage() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + rtl::OUString sMsg; + xProps->getPropertyValue( INPUTMESS ) >>= sMsg; + return sMsg; +} + +void SAL_CALL +ScVbaValidation::setInputMessage( const ::rtl::OUString& _inputmessage ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + xProps->setPropertyValue( INPUTMESS, uno::makeAny( _inputmessage ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::rtl::OUString SAL_CALL +ScVbaValidation::getInputTitle() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + rtl::OUString sString; + xProps->getPropertyValue( INPUTTITLE ) >>= sString; + return sString; +} + +void SAL_CALL +ScVbaValidation::setInputTitle( const ::rtl::OUString& _inputtitle ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + xProps->setPropertyValue( INPUTTITLE, uno::makeAny( _inputtitle ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + +::rtl::OUString SAL_CALL +ScVbaValidation::getErrorMessage() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps = lcl_getValidationProps( m_xRange ); + rtl::OUString sString; + xProps->getPropertyValue( ERRORMESS ) >>= sString; + return sString; +} + +void SAL_CALL +ScVbaValidation::setErrorMessage( const ::rtl::OUString& _errormessage ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + xProps->setPropertyValue( ERRORMESS, uno::makeAny( _errormessage ) ); + lcl_setValidationProps( m_xRange, xProps ); +} + + +void SAL_CALL +ScVbaValidation::Delete( ) throw (uno::RuntimeException) +{ + rtl::OUString sBlank; + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + uno::Reference< sheet::XSheetCondition > xCond( xProps, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( IGNOREBLANK, uno::makeAny( sal_True ) ); + xProps->setPropertyValue( SHOWINPUT, uno::makeAny( sal_True ) ); + xProps->setPropertyValue( SHOWERROR, uno::makeAny( sal_True ) ); + xProps->setPropertyValue( ERRORTITLE, uno::makeAny( sBlank ) ); + xProps->setPropertyValue( INPUTMESS, uno::makeAny( sBlank) ); + xProps->setPropertyValue( ALERTSTYLE, uno::makeAny( sheet::ValidationAlertStyle_STOP) ); + xProps->setPropertyValue( STYPE, uno::makeAny( sheet::ValidationType_ANY ) ); + xCond->setFormula1( sBlank ); + xCond->setFormula2( sBlank ); + xCond->setOperator( sheet::ConditionOperator_NONE ); + + lcl_setValidationProps( m_xRange, xProps ); +} + +// Fix the defect that validatation cannot work when the input should be limited between a lower bound and an upper bound +void SAL_CALL +ScVbaValidation::Add( const uno::Any& Type, const uno::Any& AlertStyle, const uno::Any& Operator, const uno::Any& Formula1, const uno::Any& Formula2 ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( lcl_getValidationProps( m_xRange ) ); + uno::Reference< sheet::XSheetCondition > xCond( xProps, uno::UNO_QUERY_THROW ); + + sheet::ValidationType nValType = sheet::ValidationType_ANY; + xProps->getPropertyValue( STYPE ) >>= nValType; + if ( nValType != sheet::ValidationType_ANY ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "validation object already exists" ) ), uno::Reference< uno::XInterface >() ); + sal_Int32 nType = -1; + if ( !Type.hasValue() || !( Type >>= nType ) ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "missing required param" ) ), uno::Reference< uno::XInterface >() ); + + Delete(); // set up defaults + rtl::OUString sFormula1; + Formula1 >>= sFormula1; + rtl::OUString sFormula2; + Formula2 >>= sFormula2; + switch ( nType ) + { + case excel::XlDVType::xlValidateList: + { + // for validate list + // at least formula1 is required + if ( !Formula1.hasValue() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "missing param" ) ), uno::Reference< uno::XInterface >() ); + nValType = sheet::ValidationType_LIST; + xProps->setPropertyValue( STYPE, uno::makeAny(nValType )); + // #TODO validate required params + // #TODO need to correct the ';' delimited formula on get/set + break; + } + case excel::XlDVType::xlValidateWholeNumber: + nValType = sheet::ValidationType_WHOLE; + xProps->setPropertyValue( STYPE, uno::makeAny(nValType )); + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unsupported operation..." ) ), uno::Reference< uno::XInterface >() ); + } + + sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP; + sal_Int32 nVbaAlertStyle = excel::XlDVAlertStyle::xlValidAlertStop; + if ( AlertStyle.hasValue() && ( AlertStyle >>= nVbaAlertStyle ) ) + { + switch( nVbaAlertStyle ) + { + case excel::XlDVAlertStyle::xlValidAlertStop: + // yes I know it's already defaulted but safer to assume + // someone propbably could change the code above + eStyle = sheet::ValidationAlertStyle_STOP; + break; + case excel::XlDVAlertStyle::xlValidAlertWarning: + eStyle = sheet::ValidationAlertStyle_WARNING; + break; + case excel::XlDVAlertStyle::xlValidAlertInformation: + eStyle = sheet::ValidationAlertStyle_INFO; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "bad param..." ) ), uno::Reference< uno::XInterface >() ); + + } + } + + xProps->setPropertyValue( ALERTSTYLE, uno::makeAny( eStyle ) ); + + //2009-11-11 fix the defect that validatation cannot work when the input should be limited between a lower bound and an upper bound + if ( Operator.hasValue() ) + { + css::sheet::ConditionOperator conOperator = ScVbaFormatCondition::retrieveAPIOperator( Operator ); + xCond->setOperator( conOperator ); + } + //2009-11-11 + if ( sFormula1.getLength() ) + xCond->setFormula1( sFormula1 ); + if ( sFormula2.getLength() ) + xCond->setFormula2( sFormula2 ); + + lcl_setValidationProps( m_xRange, xProps ); +} + +::rtl::OUString SAL_CALL +ScVbaValidation::getFormula1() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSheetCondition > xCond( lcl_getValidationProps( m_xRange ), uno::UNO_QUERY_THROW ); + return xCond->getFormula1(); +} + +::rtl::OUString SAL_CALL +ScVbaValidation::getFormula2() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSheetCondition > xCond( lcl_getValidationProps( m_xRange ), uno::UNO_QUERY_THROW ); + return xCond->getFormula2(); +} + +rtl::OUString& +ScVbaValidation::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaValidation") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaValidation::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Validation" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbavalidation.hxx b/sc/source/ui/vba/vbavalidation.hxx new file mode 100644 index 000000000000..6ede46176544 --- /dev/null +++ b/sc/source/ui/vba/vbavalidation.hxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_VALIDATION_HXX +#define SC_VBA_VALIDATION_HXX +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <ooo/vba/excel/XValidation.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1<ov::excel::XValidation > ValidationImpl_BASE; + +class ScVbaValidation : public ValidationImpl_BASE +{ + css::uno::Reference< css::table::XCellRange > m_xRange; + +public: + ScVbaValidation( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::table::XCellRange >& xRange ) : ValidationImpl_BASE( xParent, xContext ), m_xRange( xRange) {} + // Attributes + virtual ::sal_Bool SAL_CALL getIgnoreBlank() throw (css::uno::RuntimeException); + virtual void SAL_CALL setIgnoreBlank( ::sal_Bool _ignoreblank ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getInCellDropdown() throw (css::uno::RuntimeException); + virtual void SAL_CALL setInCellDropdown( ::sal_Bool _incelldropdown ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getShowInput() throw (css::uno::RuntimeException); + virtual void SAL_CALL setShowInput( ::sal_Bool _showinput ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getShowError() throw (css::uno::RuntimeException); + virtual void SAL_CALL setShowError( ::sal_Bool _showerror ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getInputTitle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setInputTitle( const ::rtl::OUString& _inputtitle ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getErrorTitle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setErrorTitle( const ::rtl::OUString& _errortitle ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getInputMessage() throw (css::uno::RuntimeException); + virtual void SAL_CALL setInputMessage( const ::rtl::OUString& _inputmessage ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getErrorMessage() throw (css::uno::RuntimeException); + virtual void SAL_CALL setErrorMessage( const ::rtl::OUString& _errormessage ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getFormula1() throw (css::uno::RuntimeException) ; + virtual ::rtl::OUString SAL_CALL getFormula2() throw (css::uno::RuntimeException); + // Methods + virtual void SAL_CALL Delete( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Add( const css::uno::Any& Type, const css::uno::Any& AlertStyle, const css::uno::Any& Operator, const css::uno::Any& Formula1, const css::uno::Any& Formula2 ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbawindow.cxx b/sc/source/ui/vba/vbawindow.cxx new file mode 100644 index 000000000000..625666b236b9 --- /dev/null +++ b/sc/source/ui/vba/vbawindow.cxx @@ -0,0 +1,861 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> +#include "vbawindow.hxx" +#include "vbaworksheets.hxx" +#include "vbaworksheet.hxx" +#include "vbaglobals.hxx" +#include "vbapane.hxx" +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/view/DocumentZoomType.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <ooo/vba/excel/XlWindowState.hpp> +#include <ooo/vba/excel/XlWindowView.hpp> +#include <ooo/vba/excel/Constants.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XWindow2.hpp> +#include <com/sun/star/awt/PosSize.hpp> + +#include <docsh.hxx> +#include <tabvwsh.hxx> +#include <docuno.hxx> +#include <sc.hrc> +#include <hash_map> +#include <sfx2/viewfrm.hxx> +#include <vcl/wrkwin.hxx> +#include "unonames.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; +using namespace ::ooo::vba::excel::XlWindowState; + +typedef std::hash_map< rtl::OUString, +SCTAB, ::rtl::OUStringHash, +::std::equal_to< ::rtl::OUString > > NameIndexHash; + +typedef std::vector < uno::Reference< sheet::XSpreadsheet > > Sheets; + +typedef ::cppu::WeakImplHelper1< container::XEnumeration + +> Enumeration_BASE; + +typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess + , com::sun::star::container::XIndexAccess + , com::sun::star::container::XNameAccess + > SelectedSheets_BASE; + + +class SelectedSheetsEnum : public Enumeration_BASE +{ +public: + uno::Reference< uno::XComponentContext > m_xContext; + Sheets m_sheets; + uno::Reference< frame::XModel > m_xModel; + Sheets::const_iterator m_it; + + SelectedSheetsEnum( const uno::Reference< uno::XComponentContext >& xContext, const Sheets& sheets, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : m_xContext( xContext ), m_sheets( sheets ), m_xModel( xModel ) + { + m_it = m_sheets.begin(); + } + // XEnumeration + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return m_it != m_sheets.end(); + } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + { + throw container::NoSuchElementException(); + } + // #FIXME needs ThisWorkbook as parent + return uno::makeAny( uno::Reference< excel::XWorksheet > ( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), m_xContext, *(m_it++), m_xModel ) ) ); + } + + +}; + +class SelectedSheetsEnumAccess : public SelectedSheets_BASE +{ + uno::Reference< uno::XComponentContext > m_xContext; + NameIndexHash namesToIndices; + Sheets sheets; + uno::Reference< frame::XModel > m_xModel; +public: + SelectedSheetsEnumAccess( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ):m_xContext( xContext ), m_xModel( xModel ) + { + ScModelObj* pModel = static_cast< ScModelObj* >( m_xModel.get() ); + if ( !pModel ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain current document" ) ), uno::Reference< uno::XInterface >() ); + ScDocShell* pDocShell = (ScDocShell*)pModel->GetEmbeddedObject(); + if ( !pDocShell ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain docshell" ) ), uno::Reference< uno::XInterface >() ); + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + if ( !pViewShell ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain view shell" ) ), uno::Reference< uno::XInterface >() ); + + SCTAB nTabCount = pDocShell->GetDocument()->GetTableCount(); + uno::Sequence<sal_Int32> aSheets( nTabCount ); + SCTAB nIndex = 0; + const ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData(); + sheets.reserve( nTabCount ); + uno::Reference <sheet::XSpreadsheetDocument> xSpreadSheet( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference <container::XIndexAccess> xIndex( xSpreadSheet->getSheets(), uno::UNO_QUERY_THROW ); + for ( SCTAB nTab=0; nTab<nTabCount; nTab++ ) + { + if ( rMarkData.GetTableSelect(nTab) ) + { + uno::Reference< sheet::XSpreadsheet > xSheet( xIndex->getByIndex( nTab ), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); + sheets.push_back( xSheet ); + namesToIndices[ xNamed->getName() ] = nIndex++; + } + } + + } + + //XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new SelectedSheetsEnum( m_xContext, sheets, m_xModel ); + } + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return sheets.size(); + } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 + || static_cast< Sheets::size_type >( Index ) >= sheets.size() ) + throw lang::IndexOutOfBoundsException(); + + return uno::makeAny( sheets[ Index ] ); + } + + //XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return excel::XWorksheet::static_type(0); + } + + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return (sheets.size() > 0); + } + + //XNameAccess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + NameIndexHash::const_iterator it = namesToIndices.find( aName ); + if ( it == namesToIndices.end() ) + throw container::NoSuchElementException(); + return uno::makeAny( sheets[ it->second ] ); + + } + + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + uno::Sequence< ::rtl::OUString > names( namesToIndices.size() ); + ::rtl::OUString* pString = names.getArray(); + NameIndexHash::const_iterator it = namesToIndices.begin(); + NameIndexHash::const_iterator it_end = namesToIndices.end(); + for ( ; it != it_end; ++it, ++pString ) + *pString = it->first; + return names; + } + + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + NameIndexHash::const_iterator it = namesToIndices.find( aName ); + return (it != namesToIndices.end()); + } + + +}; + +ScVbaWindow::ScVbaWindow( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) : WindowImpl_BASE( xParent, xContext, xModel ) +{ + init(); +} + +ScVbaWindow::ScVbaWindow( uno::Sequence< uno::Any > const & args, uno::Reference< uno::XComponentContext > const & xContext ) + : WindowImpl_BASE( args, xContext ) +{ + init(); +} + +void +ScVbaWindow::init() +{ + /* This method is called from the constructor, thus the own refcount is + still zero. The implementation of ActivePane() uses a UNO reference of + this (to set this window as parent of the pane obejct). This requires + the own refcount to be non-zero, otherwise this instance will be + desctructed immediately! */ + osl_incrementInterlockedCount( &m_refCount ); + uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + m_xViewPane.set( xController, uno::UNO_QUERY_THROW ); + m_xViewFreezable.set( xController, uno::UNO_QUERY_THROW ); + m_xViewSplitable.set( xController, uno::UNO_QUERY_THROW ); + m_xPane.set( ActivePane(), uno::UNO_QUERY_THROW ); + m_xDevice.set( xController->getFrame()->getComponentWindow(), uno::UNO_QUERY_THROW ); + osl_decrementInterlockedCount( &m_refCount ); +} + +void +ScVbaWindow::Scroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft, bool bLargeScroll ) throw (uno::RuntimeException) +{ + if( bLargeScroll ) + m_xPane->LargeScroll( Down, Up, ToRight, ToLeft ); + else + m_xPane->SmallScroll( Down, Up, ToRight, ToLeft ); +} + +void SAL_CALL +ScVbaWindow::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) +{ + Scroll( Down, Up, ToRight, ToLeft ); +} + +void SAL_CALL +ScVbaWindow::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) +{ + Scroll( Down, Up, ToRight, ToLeft, true ); +} + +uno::Any SAL_CALL +ScVbaWindow::SelectedSheets( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumerationAccess > xEnumAccess( new SelectedSheetsEnumAccess( mxContext, m_xModel ) ); + // #FIXME needs a workbook as a parent + uno::Reference< excel::XWorksheets > xSheets( new ScVbaWorksheets( uno::Reference< XHelperInterface >(), mxContext, xEnumAccess, m_xModel ) ); + if ( aIndex.hasValue() ) + { + uno::Reference< XCollection > xColl( xSheets, uno::UNO_QUERY_THROW ); + return xColl->Item( aIndex, uno::Any() ); + } + return uno::makeAny( xSheets ); +} + +void SAL_CALL +ScVbaWindow::ScrollWorkbookTabs( const uno::Any& /*Sheets*/, const uno::Any& /*Position*/ ) throw (uno::RuntimeException) +{ +// #TODO #FIXME need some implementation to scroll through the tabs +// but where is this done? +/* + sal_Int32 nSheets = 0; + sal_Int32 nPosition = 0; + throw uno::RuntimeException( rtl::OUString::createFromAscii("No Implemented" ), uno::Reference< uno::XInterface >() ); + sal_Bool bSheets = ( Sheets >>= nSheets ); + sal_Bool bPosition = ( Position >>= nPosition ); + if ( bSheets || bPosition ) // at least one param specified + if ( bSheets ) + ;// use sheets + else if ( bPosition ) + ; //use position +*/ + +} +uno::Reference< beans::XPropertySet > +getPropsFromModel( const uno::Reference< frame::XModel >& xModel ) +{ + uno::Reference< frame::XController > xController = xModel->getCurrentController(); + if ( !xController.is() ) + throw uno::RuntimeException( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM ("No controller for model") ), uno::Reference< uno::XInterface >() ); + return uno::Reference< beans::XPropertySet >( xController->getFrame(), uno::UNO_QUERY ); +} + + +uno::Any SAL_CALL +ScVbaWindow::getCaption() throw (uno::RuntimeException) +{ + static rtl::OUString sCrud(RTL_CONSTASCII_USTRINGPARAM(" - OpenOffice.org Calc" ) ); + static sal_Int32 nCrudLen = sCrud.getLength(); + + uno::Reference< beans::XPropertySet > xProps = getPropsFromModel( m_xModel ); + rtl::OUString sTitle; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) ) >>= sTitle; + sal_Int32 nCrudIndex = sTitle.indexOf( sCrud ); + // adjust title ( by removing crud ) + // sCrud string present + if ( nCrudIndex != -1 ) + { + // and ends with sCrud + if ( ( nCrudLen + nCrudIndex ) == sTitle.getLength() ) + { + sTitle = sTitle.copy( 0, nCrudIndex ); + ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ); + rtl::OUString sName = workbook.getName(); + // rather bizare hack to make sure the name behavior + // is like XL + // if the adjusted title == workbook name, use name + // if the adjusted title != workbook name but ... + // name == title + extension ( .csv, ,odt, .xls ) + // etc. then also use the name + + if ( !sTitle.equals( sName ) ) + { + static rtl::OUString sDot( RTL_CONSTASCII_USTRINGPARAM(".") ); + // starts with title + if ( sName.indexOf( sTitle ) == 0 ) + // extention starts immediately after + if ( sName.match( sDot, sTitle.getLength() ) ) + sTitle = sName; + } + } + } + return uno::makeAny( sTitle ); +} + +void SAL_CALL +ScVbaWindow::setCaption( const uno::Any& _caption ) throw (uno::RuntimeException) +{ + + uno::Reference< beans::XPropertySet > xProps = getPropsFromModel( m_xModel ); + xProps->setPropertyValue( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM ( SC_UNONAME_TITLE ) ) , _caption ); +} + +uno::Any SAL_CALL +ScVbaWindow::getScrollRow() throw (uno::RuntimeException) +{ + sal_Int32 nValue = 0; + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + if ( pViewShell ) + { + ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); + nValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)); + } + + return uno::makeAny( nValue + 1); +} + +void SAL_CALL +ScVbaWindow::setScrollRow( const uno::Any& _scrollrow ) throw (uno::RuntimeException) +{ + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + if ( pViewShell ) + { + sal_Int32 scrollRow = 0; + _scrollrow >>= scrollRow; + ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); + sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosY(WhichV(eWhich)) + 1; + pViewShell->ScrollLines(0, scrollRow - nOldValue); + } +} + +uno::Any SAL_CALL +ScVbaWindow::getScrollColumn() throw (uno::RuntimeException) +{ + sal_Int32 nValue = 0; + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + if ( pViewShell ) + { + ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); + nValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)); + } + + return uno::makeAny( nValue + 1); +} + +void SAL_CALL +ScVbaWindow::setScrollColumn( const uno::Any& _scrollcolumn ) throw (uno::RuntimeException) +{ + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + if ( pViewShell ) + { + sal_Int32 scrollColumn = 0; + _scrollcolumn >>= scrollColumn; + ScSplitPos eWhich = pViewShell->GetViewData()->GetActivePart(); + sal_Int32 nOldValue = pViewShell->GetViewData()->GetPosX(WhichH(eWhich)) + 1; + pViewShell->ScrollLines(scrollColumn - nOldValue, 0); + } +} + +uno::Any SAL_CALL +ScVbaWindow::getWindowState() throw (uno::RuntimeException) +{ + sal_Int32 nwindowState = xlNormal; + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame(); + WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); + if ( pWork ) + { + if ( pWork -> IsMaximized()) + nwindowState = xlMaximized; + else if (pWork -> IsMinimized()) + nwindowState = xlMinimized; + } + return uno::makeAny( nwindowState ); +} + +void SAL_CALL +ScVbaWindow::setWindowState( const uno::Any& _windowstate ) throw (uno::RuntimeException) +{ + sal_Int32 nwindowState = xlMaximized; + _windowstate >>= nwindowState; + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + SfxViewFrame* pViewFrame = pViewShell -> GetViewFrame(); + WorkWindow* pWork = (WorkWindow*) pViewFrame->GetFrame().GetSystemWindow(); + if ( pWork ) + { + if ( nwindowState == xlMaximized) + pWork -> Maximize(); + else if (nwindowState == xlMinimized) + pWork -> Minimize(); + else if (nwindowState == xlNormal) + pWork -> Restore(); + else + throw uno::RuntimeException( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Invalid Parameter" ) ), uno::Reference< uno::XInterface >() ); + } +} + +void +ScVbaWindow::Activate() throw (css::uno::RuntimeException) +{ + ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ); + + workbook.Activate(); +} + +void +ScVbaWindow::Close( const uno::Any& SaveChanges, const uno::Any& FileName, const uno::Any& RouteWorkBook ) throw (uno::RuntimeException) +{ + ScVbaWorkbook workbook( uno::Reference< XHelperInterface >( Application(), uno::UNO_QUERY_THROW ), mxContext, m_xModel ); + workbook.Close(SaveChanges, FileName, RouteWorkBook ); +} + +uno::Reference< excel::XPane > SAL_CALL +ScVbaWindow::ActivePane() throw (script::BasicErrorException, uno::RuntimeException) +{ + return new ScVbaPane( this, mxContext, m_xModel, m_xViewPane ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaWindow::ActiveCell( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + return xApplication->getActiveCell(); +} + +uno::Any SAL_CALL +ScVbaWindow::Selection( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + return xApplication->getSelection(); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaWindow::RangeSelection() throw (script::BasicErrorException, uno::RuntimeException) +{ + /* TODO / FIXME: According to documentation, this method returns the range + selection even if shapes are selected. */ + return uno::Reference< excel::XRange >( Selection(), uno::UNO_QUERY_THROW ); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getDisplayGridlines() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) ); + sal_Bool bGrid = sal_True; + xProps->getPropertyValue( sName ) >>= bGrid; + return bGrid; +} + + +void SAL_CALL +ScVbaWindow::setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHOWGRID ) ); + xProps->setPropertyValue( sName, uno::makeAny( _displaygridlines )); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getDisplayHeadings() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) ); + sal_Bool bHeading = sal_True; + xProps->getPropertyValue( sName ) >>= bHeading; + return bHeading; +} + +void SAL_CALL +ScVbaWindow::setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_COLROWHDR ) ); + xProps->setPropertyValue( sName, uno::makeAny( _bDisplayHeadings )); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getDisplayHorizontalScrollBar() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) ); + sal_Bool bHorizontalScrollBar = sal_True; + xProps->getPropertyValue( sName ) >>= bHorizontalScrollBar; + return bHorizontalScrollBar; +} + +void SAL_CALL +ScVbaWindow::setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_HORSCROLL ) ); + xProps->setPropertyValue( sName, uno::makeAny( _bDisplayHorizontalScrollBar )); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getDisplayOutline() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) ); + sal_Bool bOutline = sal_True; + xProps->getPropertyValue( sName ) >>= bOutline; + return bOutline; +} + +void SAL_CALL +ScVbaWindow::setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_OUTLSYMB ) ); + xProps->setPropertyValue( sName, uno::makeAny( _bDisplayOutline )); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getDisplayVerticalScrollBar() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) ); + sal_Bool bVerticalScrollBar = sal_True; + xProps->getPropertyValue( sName ) >>= bVerticalScrollBar; + return bVerticalScrollBar; +} + +void SAL_CALL +ScVbaWindow::setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_VERTSCROLL ) ); + xProps->setPropertyValue( sName, uno::makeAny( _bDisplayVerticalScrollBar )); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getDisplayWorkbookTabs() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) ); + sal_Bool bWorkbookTabs = sal_True; + xProps->getPropertyValue( sName ) >>= bWorkbookTabs; + return bWorkbookTabs; +} + +void SAL_CALL +ScVbaWindow::setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_SHEETTABS ) ); + xProps->setPropertyValue( sName, uno::makeAny( _bDisplayWorkbookTabs )); +} + +::sal_Bool SAL_CALL +ScVbaWindow::getFreezePanes() throw (uno::RuntimeException) +{ + return m_xViewFreezable->hasFrozenPanes(); +} + +void SAL_CALL +ScVbaWindow::setFreezePanes( ::sal_Bool /*_bFreezePanes*/ ) throw (uno::RuntimeException) +{ + if( m_xViewSplitable->getIsWindowSplit() ) + { + // if there is a split we freeze at the split + sal_Int32 nColumn = getSplitColumn(); + sal_Int32 nRow = getSplitRow(); + m_xViewFreezable->freezeAtPosition( nColumn, nRow ); + } + else + { + // otherwise we freeze in the center of the visible sheet + table::CellRangeAddress aCellRangeAddress = m_xViewPane->getVisibleRange(); + sal_Int32 nColumn = aCellRangeAddress.StartColumn + (( aCellRangeAddress.EndColumn - aCellRangeAddress.StartColumn )/2 ); + sal_Int32 nRow = aCellRangeAddress.StartRow + (( aCellRangeAddress.EndRow - aCellRangeAddress.StartRow )/2 ); + m_xViewFreezable->freezeAtPosition( nColumn, nRow ); + } +} + +::sal_Bool SAL_CALL +ScVbaWindow::getSplit() throw (uno::RuntimeException) +{ + return m_xViewSplitable->getIsWindowSplit(); +} + +void SAL_CALL +ScVbaWindow::setSplit( ::sal_Bool _bSplit ) throw (uno::RuntimeException) +{ + if( !_bSplit ) + { + m_xViewSplitable->splitAtPosition(0,0); + } + else + { + uno::Reference< excel::XRange > xRange = ActiveCell(); + sal_Int32 nRow = xRange->getRow(); + sal_Int32 nColumn = xRange->getColumn(); + m_xViewFreezable->freezeAtPosition( nColumn-1, nRow-1 ); + SplitAtDefinedPosition( sal_True ); + } +} + +sal_Int32 SAL_CALL +ScVbaWindow::getSplitColumn() throw (uno::RuntimeException) +{ + return m_xViewSplitable->getSplitColumn(); +} + +void SAL_CALL +ScVbaWindow::setSplitColumn( sal_Int32 _splitcolumn ) throw (uno::RuntimeException) +{ + if( getSplitColumn() != _splitcolumn ) + { + sal_Bool bFrozen = getFreezePanes(); + sal_Int32 nRow = getSplitRow(); + m_xViewFreezable->freezeAtPosition( _splitcolumn, nRow ); + SplitAtDefinedPosition( !bFrozen ); + } +} + +double SAL_CALL +ScVbaWindow::getSplitHorizontal() throw (uno::RuntimeException) +{ + double fSplitHorizontal = m_xViewSplitable->getSplitHorizontal(); + double fHoriPoints = PixelsToPoints( m_xDevice, fSplitHorizontal, sal_True ); + return fHoriPoints; +} + +void SAL_CALL +ScVbaWindow::setSplitHorizontal( double _splithorizontal ) throw (uno::RuntimeException) +{ + double fHoriPixels = PointsToPixels( m_xDevice, _splithorizontal, sal_True ); + m_xViewSplitable->splitAtPosition( static_cast<sal_Int32>( fHoriPixels ), 0 ); +} + +sal_Int32 SAL_CALL +ScVbaWindow::getSplitRow() throw (uno::RuntimeException) +{ + sal_Int32 nValue = m_xViewSplitable->getSplitRow(); + return nValue ? nValue - 1 : nValue; +} + +void SAL_CALL +ScVbaWindow::setSplitRow( sal_Int32 _splitrow ) throw (uno::RuntimeException) +{ + if( getSplitRow() != _splitrow ) + { + sal_Bool bFrozen = getFreezePanes(); + sal_Int32 nColumn = getSplitColumn(); + m_xViewFreezable->freezeAtPosition( nColumn , _splitrow ); + SplitAtDefinedPosition( !bFrozen ); + } +} + +double SAL_CALL +ScVbaWindow::getSplitVertical() throw (uno::RuntimeException) +{ + double fSplitVertical = m_xViewSplitable->getSplitVertical(); + double fVertiPoints = PixelsToPoints( m_xDevice, fSplitVertical, sal_False ); + return fVertiPoints; +} + +void SAL_CALL +ScVbaWindow::setSplitVertical(double _splitvertical ) throw (uno::RuntimeException) +{ + double fVertiPixels = PointsToPixels( m_xDevice, _splitvertical, sal_False ); + m_xViewSplitable->splitAtPosition( 0, static_cast<sal_Int32>( fVertiPixels ) ); +} + +void ScVbaWindow::SplitAtDefinedPosition(sal_Bool _bUnFreezePane) +{ + sal_Int32 nVertSplit = m_xViewSplitable->getSplitVertical(); + sal_Int32 nHoriSplit = m_xViewSplitable->getSplitHorizontal(); + if( _bUnFreezePane ) + { + m_xViewFreezable->freezeAtPosition(0,0); + } + m_xViewSplitable->splitAtPosition(nHoriSplit, nVertSplit); +} + +uno::Any SAL_CALL +ScVbaWindow::getZoom() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_ZOOMTYPE ) ); + sal_Int16 nZoomType = view::DocumentZoomType::PAGE_WIDTH; + xProps->getPropertyValue( sName ) >>= nZoomType; + if( nZoomType == view::DocumentZoomType::PAGE_WIDTH ) + { + return uno::makeAny( sal_True ); + } + else if( nZoomType == view::DocumentZoomType::BY_VALUE ) + { + sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SC_UNO_ZOOMVALUE)); + sal_Int16 nZoom = 100; + xProps->getPropertyValue( sName ) >>= nZoom; + return uno::makeAny( nZoom ); + } + return uno::Any(); +} + +void SAL_CALL +ScVbaWindow::setZoom( const uno::Any& _zoom ) throw (uno::RuntimeException) +{ + sal_Int16 nZoom = 100; + _zoom >>= nZoom; + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XWorksheet > xActiveSheet = ActiveSheet(); + SCTAB nTab = 0; + if ( !ScVbaWorksheets::nameExists (xSpreadDoc, xActiveSheet->getName(), nTab) ) + throw uno::RuntimeException(); + std::vector< SCTAB > vTabs; + vTabs.push_back( nTab ); + excel::implSetZoom( m_xModel, nZoom, vTabs ); +} + +uno::Reference< excel::XWorksheet > SAL_CALL +ScVbaWindow::ActiveSheet( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + return xApplication->getActiveSheet(); +} + +uno::Any SAL_CALL +ScVbaWindow::getView() throw (uno::RuntimeException) +{ + // not supported now + sal_Int32 nWindowView = excel::XlWindowView::xlNormalView; + return uno::makeAny( nWindowView ); +} + +void SAL_CALL +ScVbaWindow::setView( const uno::Any& _view) throw (uno::RuntimeException) +{ + sal_Int32 nWindowView = excel::XlWindowView::xlNormalView; + _view >>= nWindowView; + USHORT nSlot = FID_NORMALVIEWMODE; + switch ( nWindowView ) + { + case excel::XlWindowView::xlNormalView: + nSlot = FID_NORMALVIEWMODE; + break; + case excel::XlWindowView::xlPageBreakPreview: + nSlot = FID_PAGEBREAKMODE; + break; + default: + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + ScTabViewShell* pViewShell = excel::getBestViewShell( m_xModel ); + if ( pViewShell ) + dispatchExecute( pViewShell, nSlot ); +} + +uno::Reference< excel::XRange > SAL_CALL +ScVbaWindow::getVisibleRange() throw (uno::RuntimeException) +{ + uno::Reference< container::XIndexAccess > xPanesIA( m_xViewPane, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XViewPane > xTopLeftPane( xPanesIA->getByIndex( 0 ), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XPane > xPane( new ScVbaPane( this, mxContext, m_xModel, xTopLeftPane ) ); + return xPane->getVisibleRange(); +} + +sal_Int32 SAL_CALL +ScVbaWindow::PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points ); + double fConvertFactor = (m_xDevice->getInfo().PixelPerMeterX/100000); + return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters ); +} + +sal_Int32 SAL_CALL +ScVbaWindow::PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + sal_Int32 nHundredthsofOneMillimeters = Millimeter::getInHundredthsOfOneMillimeter( _points ); + double fConvertFactor = (m_xDevice->getInfo().PixelPerMeterY/100000); + return static_cast<sal_Int32>(fConvertFactor * nHundredthsofOneMillimeters ); +} + +void SAL_CALL +ScVbaWindow::PrintOut( const css::uno::Any& From, const css::uno::Any&To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + // need test, print current active sheet + PrintOutHelper( excel::getBestViewShell( m_xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True ); +} + +void SAL_CALL +ScVbaWindow::PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + // need test, print preview current active sheet + PrintPreviewHelper( EnableChanges, excel::getBestViewShell( m_xModel ) ); +} + +rtl::OUString& +ScVbaWindow::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWindow") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaWindow::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Window" ) ); + } + return aServiceNames; +} +namespace window +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaWindow, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaWindow", + "ooo.vba.excel.Window" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbawindow.hxx b/sc/source/ui/vba/vbawindow.hxx new file mode 100644 index 000000000000..7daf0ba54c63 --- /dev/null +++ b/sc/source/ui/vba/vbawindow.hxx @@ -0,0 +1,126 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_WINDOW_HXX +#define SC_VBA_WINDOW_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XWindow.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/sheet/XViewPane.hpp> +#include <com/sun/star/sheet/XViewFreezable.hpp> +#include <com/sun/star/sheet/XViewSplitable.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <ooo/vba/excel/XPane.hpp> +#include <com/sun/star/awt/XDevice.hpp> + +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbawindowbase.hxx> +#include "vbaworkbook.hxx" + +typedef cppu::ImplInheritanceHelper1< VbaWindowBase, ov::excel::XWindow > WindowImpl_BASE; + +class ScVbaWindow : public WindowImpl_BASE +{ +private: + css::uno::Reference< css::sheet::XViewPane > m_xViewPane; + css::uno::Reference< css::sheet::XViewFreezable > m_xViewFreezable; + css::uno::Reference< css::sheet::XViewSplitable > m_xViewSplitable; + css::uno::Reference< ov::excel::XPane > m_xPane; + css::uno::Reference< css::awt::XDevice > m_xDevice; + void init(); +protected: + void SplitAtDefinedPosition(sal_Bool _bUnFreezePane); +public: + void Scroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft, bool bLargeScroll = false ) throw (css::uno::RuntimeException); +public: + ScVbaWindow( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ); + ScVbaWindow( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext ); + + // XWindow + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL ActiveCell( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XPane > SAL_CALL ActivePane() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL ActiveSheet( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const css::uno::Any& _caption ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayGridlines() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayGridlines( ::sal_Bool _displaygridlines ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayHeadings() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayHeadings( ::sal_Bool _bDisplayHeadings ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayHorizontalScrollBar() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayHorizontalScrollBar( ::sal_Bool _bDisplayHorizontalScrollBar ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayOutline() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayOutline( ::sal_Bool _bDisplayOutline ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayVerticalScrollBar() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayVerticalScrollBar( ::sal_Bool _bDisplayVerticalScrollBar ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getDisplayWorkbookTabs() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayWorkbookTabs( ::sal_Bool _bDisplayWorkbookTabs ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getFreezePanes() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFreezePanes( ::sal_Bool _bFreezePanes ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getSplit() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSplit( ::sal_Bool _bSplit ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSplitColumn() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setSplitColumn( sal_Int32 _splitcolumn ) throw (css::uno::RuntimeException) ; + virtual double SAL_CALL getSplitHorizontal() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setSplitHorizontal( double _splithorizontal ) throw (css::uno::RuntimeException) ; + virtual sal_Int32 SAL_CALL getSplitRow() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setSplitRow( sal_Int32 _splitrow ) throw (css::uno::RuntimeException) ; + virtual double SAL_CALL getSplitVertical() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setSplitVertical( double _splitvertical ) throw (css::uno::RuntimeException) ; + virtual css::uno::Any SAL_CALL getScrollRow() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setScrollRow( const css::uno::Any& _scrollrow ) throw (css::uno::RuntimeException) ; + virtual css::uno::Any SAL_CALL getScrollColumn() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setScrollColumn( const css::uno::Any& _scrollcolumn ) throw (css::uno::RuntimeException) ; + virtual css::uno::Any SAL_CALL getView() throw (css::uno::RuntimeException); + virtual void SAL_CALL setView( const css::uno::Any& _view ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getVisibleRange() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getWindowState() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWindowState( const css::uno::Any& _windowstate ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getZoom() throw (css::uno::RuntimeException); + virtual void SAL_CALL setZoom( const css::uno::Any& _zoom ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL SmallScroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft ) throw (css::uno::RuntimeException); + virtual void SAL_CALL LargeScroll( const css::uno::Any& Down, const css::uno::Any& Up, const css::uno::Any& ToRight, const css::uno::Any& ToLeft ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL SelectedSheets( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ScrollWorkbookTabs( const css::uno::Any& Sheets, const css::uno::Any& Position ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Activate( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Close( const css::uno::Any& SaveChanges, const css::uno::Any& FileName, const css::uno::Any& RouteWorkBook ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Selection( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL RangeSelection() throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL PointsToScreenPixelsX(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL PointsToScreenPixelsY(sal_Int32 _points) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any&To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL PrintPreview( const css::uno::Any& EnableChanges ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_WINDOW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbawindows.cxx b/sc/source/ui/vba/vbawindows.cxx new file mode 100644 index 000000000000..1456c71af12c --- /dev/null +++ b/sc/source/ui/vba/vbawindows.cxx @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbawindows.hxx" + +#include <hash_map> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <cppuhelper/implbase3.hxx> + +#include <tools/urlobj.hxx> +#include "vbawindow.hxx" +#include "vbaglobals.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +typedef std::hash_map< rtl::OUString, +sal_Int32, ::rtl::OUStringHash, +::std::equal_to< ::rtl::OUString > > NameIndexHash; + + +uno::Reference< XHelperInterface > lcl_createWorkbookHIParent( const uno::Reference< frame::XModel >& xModel, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any& aApplication ) +{ + return new ScVbaWorkbook( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xModel ); +} + +uno::Any ComponentToWindow( const uno::Any& aSource, uno::Reference< uno::XComponentContext > & xContext, const uno::Any& aApplication ) +{ + uno::Reference< frame::XModel > xModel( aSource, uno::UNO_QUERY_THROW ); + uno::Reference< excel::XWindow > xWin( new ScVbaWindow( lcl_createWorkbookHIParent( xModel, xContext, aApplication ), xContext,xModel ) ); + return uno::makeAny( xWin ); +} + +typedef std::vector < uno::Reference< sheet::XSpreadsheetDocument > > Components; +// #TODO more or less the same as class in workwindows ( code sharing needed ) +class WindowComponentEnumImpl : public EnumerationHelper_BASE +{ +protected: + uno::Reference< uno::XComponentContext > m_xContext; + Components m_components; + Components::const_iterator m_it; + +public: + WindowComponentEnumImpl( const uno::Reference< uno::XComponentContext >& xContext, const Components& components ) throw ( uno::RuntimeException ) : m_xContext( xContext ), m_components( components ) + { + m_it = m_components.begin(); + } + + WindowComponentEnumImpl( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException ) : m_xContext( xContext ) + { + uno::Reference< lang::XMultiComponentFactory > xSMgr( + m_xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + uno::Reference< frame::XDesktop > xDesktop + (xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), m_xContext), uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration > mxComponents = xDesktop->getComponents()->createEnumeration(); + while( mxComponents->hasMoreElements() ) + { + uno::Reference< sheet::XSpreadsheetDocument > xNext( mxComponents->nextElement(), uno::UNO_QUERY ); + if ( xNext.is() ) + m_components.push_back( xNext ); + } + m_it = m_components.begin(); + } + // XEnumeration + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return m_it != m_components.end(); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + { + throw container::NoSuchElementException(); + } + return makeAny( *(m_it++) ); + } +}; + +class WindowEnumImpl : public WindowComponentEnumImpl +{ + uno::Any m_aApplication; +public: + WindowEnumImpl(const uno::Reference< uno::XComponentContext >& xContext, const Components& components, const uno::Any& aApplication ):WindowComponentEnumImpl( xContext, components ), m_aApplication( aApplication ){} + WindowEnumImpl( const uno::Reference< uno::XComponentContext >& xContext, const uno::Any& aApplication ): WindowComponentEnumImpl( xContext ), m_aApplication( aApplication ) {} + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + return ComponentToWindow( WindowComponentEnumImpl::nextElement(), m_xContext, m_aApplication ); + } +}; + +typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess + , com::sun::star::container::XIndexAccess + , com::sun::star::container::XNameAccess + > WindowsAccessImpl_BASE; + +class WindowsAccessImpl : public WindowsAccessImpl_BASE +{ + uno::Reference< uno::XComponentContext > m_xContext; + Components m_windows; + NameIndexHash namesToIndices; +public: + WindowsAccessImpl( const uno::Reference< uno::XComponentContext >& xContext ):m_xContext( xContext ) + { + uno::Reference< container::XEnumeration > xEnum = new WindowComponentEnumImpl( m_xContext ); + sal_Int32 nIndex=0; + while( xEnum->hasMoreElements() ) + { + uno::Reference< sheet::XSpreadsheetDocument > xNext( xEnum->nextElement(), uno::UNO_QUERY ); + if ( xNext.is() ) + { + m_windows.push_back( xNext ); + uno::Reference< frame::XModel > xModel( xNext, uno::UNO_QUERY_THROW ); // that the spreadsheetdocument is a xmodel is a given + uno::Reference< XHelperInterface > xTemp; // temporary needed for g++ 3.3.5 + ScVbaWindow window( xTemp, m_xContext, xModel ); + rtl::OUString sCaption; + window.getCaption() >>= sCaption; + namesToIndices[ sCaption ] = nIndex++; + } + } + + } + + //XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new WindowComponentEnumImpl( m_xContext, m_windows ); + } + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return m_windows.size(); + } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 + || static_cast< Components::size_type >( Index ) >= m_windows.size() ) + throw lang::IndexOutOfBoundsException(); + return makeAny( m_windows[ Index ] ); // returns xspreadsheetdoc + } + + //XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return sheet::XSpreadsheetDocument::static_type(0); + } + + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return (m_windows.size() > 0); + } + + //XNameAccess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + NameIndexHash::const_iterator it = namesToIndices.find( aName ); + if ( it == namesToIndices.end() ) + throw container::NoSuchElementException(); + return makeAny( m_windows[ it->second ] ); + + } + + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + uno::Sequence< ::rtl::OUString > names( namesToIndices.size() ); + ::rtl::OUString* pString = names.getArray(); + NameIndexHash::const_iterator it = namesToIndices.begin(); + NameIndexHash::const_iterator it_end = namesToIndices.end(); + for ( ; it != it_end; ++it, ++pString ) + *pString = it->first; + return names; + } + + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + NameIndexHash::const_iterator it = namesToIndices.find( aName ); + return (it != namesToIndices.end()); + } + +}; + + +ScVbaWindows::ScVbaWindows( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess ): ScVbaWindows_BASE( xParent, xContext, xIndexAccess ) +{ +} + +ScVbaWindows::ScVbaWindows( const uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaWindows_BASE( xParent, xContext, uno::Reference< container::XIndexAccess > ( new WindowsAccessImpl( xContext ) ) ) +{ +} +uno::Reference< container::XEnumeration > +ScVbaWindows::createEnumeration() throw (uno::RuntimeException) +{ + return new WindowEnumImpl( mxContext, Application() ); +} + +uno::Any +ScVbaWindows::createCollectionObject( const css::uno::Any& aSource ) +{ + return ComponentToWindow( aSource, mxContext, Application() ); +} + +uno::Type +ScVbaWindows::getElementType() throw (uno::RuntimeException) +{ + return excel::XWindows::static_type(0); +} + + +void SAL_CALL +ScVbaWindows::Arrange( ::sal_Int32 /*ArrangeStyle*/, const uno::Any& /*ActiveWorkbook*/, const uno::Any& /*SyncHorizontal*/, const uno::Any& /*SyncVertical*/ ) throw (uno::RuntimeException) +{ + //#TODO #FIXME see what can be done for an implementation here +} + + +rtl::OUString& +ScVbaWindows::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWindows") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaWindows::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Windows") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbawindows.hxx b/sc/source/ui/vba/vbawindows.hxx new file mode 100644 index 000000000000..71d5f7cd59cb --- /dev/null +++ b/sc/source/ui/vba/vbawindows.hxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_WINDOWS_HXX +#define SC_VBA_WINDOWS_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/excel/XWindows.hpp> + +#include <com/sun/star/uno/XComponentContext.hpp> + +#include "excelvbahelper.hxx" +#include <vbahelper/vbacollectionimpl.hxx> + + +typedef CollTestImplHelper< ov::excel::XWindows > ScVbaWindows_BASE; + +class ScVbaWindows : public ScVbaWindows_BASE +{ +public: + ScVbaWindows( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ); + ScVbaWindows( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext ); + virtual ~ScVbaWindows() {} + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + + // XWindows + virtual void SAL_CALL Arrange( ::sal_Int32 ArrangeStyle, const css::uno::Any& ActiveWorkbook, const css::uno::Any& SyncHorizontal, const css::uno::Any& SyncVertical ) throw (::com::sun::star::uno::RuntimeException); + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_WINDOWS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworkbook.cxx b/sc/source/ui/vba/vbaworkbook.cxx new file mode 100644 index 000000000000..1af4fee63ef3 --- /dev/null +++ b/sc/source/ui/vba/vbaworkbook.cxx @@ -0,0 +1,435 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> +#include <tools/urlobj.hxx> +#include <comphelper/unwrapargs.hxx> + +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/util/XProtectable.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/excel/XlFileFormat.hpp> +#include <ooo/vba/excel/XApplication.hpp> //liuchen 2009-12-16 + +#include "scextopt.hxx" +#include "vbaworksheet.hxx" +#include "vbaworksheets.hxx" +#include "vbaworkbook.hxx" +#include "vbawindows.hxx" +#include "vbastyles.hxx" +#include "excelvbahelper.hxx" +#include "vbapalette.hxx" +#include <osl/file.hxx> +#include <stdio.h> +#include "vbanames.hxx" // Amelia Wang +#include "nameuno.hxx" +#include "docoptio.hxx" +#include "unonames.hxx" + +// Much of the impl. for the equivalend UNO module is +// sc/source/ui/unoobj/docuno.cxx, viewuno.cxx + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class ActiveSheet : public ScVbaWorksheet +{ +protected: + virtual uno::Reference< frame::XModel > getModel() + { + return getCurrentExcelDoc( mxContext ); + } + virtual uno::Reference< sheet::XSpreadsheet > getSheet() + { + uno::Reference< frame::XModel > xModel = getModel(); + uno::Reference< sheet::XSpreadsheet > xSheet; + if ( xModel.is() ) + { + uno::Reference< sheet::XSpreadsheetView > xSpreadsheet( + xModel->getCurrentController(), uno::UNO_QUERY ); + if ( xSpreadsheet.is() ) + xSheet = xSpreadsheet->getActiveSheet(); + } + return xSheet; + } +public: + ActiveSheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : ScVbaWorksheet( xParent, xContext ) {} + +}; + +uno::Sequence< sal_Int32 > ScVbaWorkbook::ColorData; + +void ScVbaWorkbook::initColorData( const uno::Sequence< sal_Int32 >& sColors ) +{ + const sal_Int32* pSource = sColors.getConstArray(); + sal_Int32* pDest = ColorData.getArray(); + const sal_Int32* pEnd = pSource + sColors.getLength(); + for ( ; pSource != pEnd; ++pSource, ++pDest ) + *pDest = *pSource; +} + + +void SAL_CALL +ScVbaWorkbook::ResetColors( ) throw (::script::BasicErrorException, ::uno::RuntimeException) +{ + uno::Reference< container::XIndexAccess > xIndexAccess( ScVbaPalette::getDefaultPalette(), uno::UNO_QUERY_THROW ); + sal_Int32 nLen = xIndexAccess->getCount(); + ColorData.realloc( nLen ); + + uno::Sequence< sal_Int32 > dDefaultColors( nLen ); + sal_Int32* pDest = dDefaultColors.getArray(); + for ( sal_Int32 index=0; index < nLen; ++pDest, ++index ) + xIndexAccess->getByIndex( index ) >>= (*pDest); + initColorData( dDefaultColors ); +} + +::uno::Any SAL_CALL +ScVbaWorkbook::Colors( const ::uno::Any& Index ) throw (::script::BasicErrorException, ::uno::RuntimeException) +{ + uno::Any aRet; + if ( Index.getValue() ) + { + sal_Int32 nIndex = 0; + Index >>= nIndex; + aRet = uno::makeAny( XLRGBToOORGB( ColorData[ --nIndex ] ) ); + } + else + aRet = uno::makeAny( ColorData ); + return aRet; +} + +::sal_Int32 SAL_CALL +ScVbaWorkbook::getFileFormat( ) throw (::uno::RuntimeException) +{ + sal_Int32 aFileFormat = 0; + rtl::OUString aFilterName; + uno::Sequence< beans::PropertyValue > aArgs = getModel()->getArgs(); + + // #FIXME - seems suspect should we not walk through the properties + // to find the FilterName + if (aArgs[0].Name.equalsAscii( "FilterName")) { + aArgs[0].Value >>= aFilterName; + } else { + aArgs[1].Value >>= aFilterName; + } + + if (aFilterName.equalsAscii("Text - txt - csv (StarCalc)")) { + aFileFormat = excel::XlFileFormat::xlCSV; //xlFileFormat. + } + + if (aFilterName.equalsAscii("DBF")) { + aFileFormat = excel::XlFileFormat::xlDBF4; + } + + if (aFilterName.equalsAscii("DIF")) { + aFileFormat = excel::XlFileFormat::xlDIF; + } + + if (aFilterName.equalsAscii("Lotus")) { + aFileFormat = excel::XlFileFormat::xlWK3; + } + + if (aFilterName.equalsAscii("MS Excel 4.0")) { + aFileFormat = excel::XlFileFormat::xlExcel4Workbook; + } + + if (aFilterName.equalsAscii("MS Excel 5.0/95")) { + aFileFormat = excel::XlFileFormat::xlExcel5; + } + + if (aFilterName.equalsAscii("MS Excel 97")) { + aFileFormat = excel::XlFileFormat::xlExcel9795; + } + + if (aFilterName.equalsAscii("HTML (StarCalc)")) { + aFileFormat = excel::XlFileFormat::xlHtml; + } + + if (aFilterName.equalsAscii("calc_StarOffice_XML_Calc_Template")) { + aFileFormat = excel::XlFileFormat::xlTemplate; + } + + if (aFilterName.equalsAscii("StarOffice XML (Calc)")) { + aFileFormat = excel::XlFileFormat::xlWorkbookNormal; + } + if (aFilterName.equalsAscii("calc8")) { + aFileFormat = excel::XlFileFormat::xlWorkbookNormal; + } + + return aFileFormat; +} + +//VBA by minz@cn.ibm.com. Convert Excel fileformat to OO file filter +::rtl::OUString ScVbaWorkbook::convertFileFormat(sal_Int32 aFileFormat) +{ + rtl::OUString aFilterName; + + switch(aFileFormat) + { + case excel::XlFileFormat::xlCSV: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text - txt - csv (StarCalc)" ) ); + break; + case excel::XlFileFormat::xlExcel9795: + aFilterName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MS Excel 97" ) ); + break; + } + + return aFilterName; +} + +void +ScVbaWorkbook::init() +{ + if ( !ColorData.getLength() ) + ResetColors(); +} +ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext) :ScVbaWorkbook_BASE( xParent, xContext ) +{ + //#FIXME this persists the color data per office instance and + // not per workbook instance, need to hook the data into XModel + // ( e.g. we already store the imported palette in there ) + // so we should, + // a) make the class that does that a service + // b) make that service implement XIndexContainer + init(); +} + +ScVbaWorkbook::ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::frame::XModel > xModel ) : ScVbaWorkbook_BASE( xParent, xContext, xModel ) +{ + init(); +} + +ScVbaWorkbook::ScVbaWorkbook( uno::Sequence< uno::Any> const & args, + uno::Reference< uno::XComponentContext> const & xContext ) : ScVbaWorkbook_BASE( args, xContext ) +{ + init(); +} + +uno::Reference< excel::XWorksheet > +ScVbaWorkbook::getActiveSheet() throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW ); + uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xSheetProps( xView->getActiveSheet(), uno::UNO_QUERY_THROW ); + // #162503# return the original document module wrapper object, instead of a new instance + ::rtl::OUString aCodeName; + xSheetProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_CODENAME ) ) ) >>= aCodeName; + ScDocShell* pShell = excel::getDocShell( xModel ); + if( !pShell ) + throw uno::RuntimeException(); + return uno::Reference< excel::XWorksheet >( getUnoDocModule( aCodeName, pShell ), uno::UNO_QUERY_THROW ); +} + +uno::Any SAL_CALL +ScVbaWorkbook::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + return Worksheets( aIndex ); +} + +uno::Any SAL_CALL +ScVbaWorkbook::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getModel() ); + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW ); + uno::Reference<container::XIndexAccess > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xWorkSheets( new ScVbaWorksheets( this, mxContext, xSheets, xModel ) ); + if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) + { + return uno::Any( xWorkSheets ); + } + // pass on to collection + return uno::Any( xWorkSheets->Item( aIndex, uno::Any() ) ); +} +uno::Any SAL_CALL +ScVbaWorkbook::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + + uno::Reference< excel::XWindows > xWindows( new ScVbaWindows( getParent(), mxContext ) ); + if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) + return uno::Any( xWindows ); + return uno::Any( xWindows->Item( aIndex, uno::Any() ) ); +} + +void SAL_CALL +ScVbaWorkbook::Activate() throw (uno::RuntimeException) +{ + VbaDocumentBase::Activate(); +} + +void +ScVbaWorkbook::Protect( const uno::Any &aPassword ) throw (uno::RuntimeException) +{ + VbaDocumentBase::Protect( aPassword ); +} + +::sal_Bool +ScVbaWorkbook::getProtectStructure() throw (uno::RuntimeException) +{ + uno::Reference< util::XProtectable > xProt( getModel(), uno::UNO_QUERY_THROW ); + return xProt->isProtected(); +} + +::sal_Bool SAL_CALL ScVbaWorkbook::getPrecisionAsDisplayed() throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); + ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument(); + return pDoc->GetDocOptions().IsCalcAsShown(); +} + +void SAL_CALL ScVbaWorkbook::setPrecisionAsDisplayed( sal_Bool _precisionAsDisplayed ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); + ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument(); + ScDocOptions aOpt = pDoc->GetDocOptions(); + aOpt.SetCalcAsShown( _precisionAsDisplayed ); + pDoc->SetDocOptions( aOpt ); +} + +void +ScVbaWorkbook::SaveCopyAs( const rtl::OUString& sFileName ) throw ( uno::RuntimeException) +{ + rtl::OUString aURL; + osl::FileBase::getFileURLFromSystemPath( sFileName, aURL ); + uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); + uno::Sequence< beans::PropertyValue > storeProps(1); + storeProps[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); + storeProps[0].Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MS Excel 97" ) ); + xStor->storeToURL( aURL, storeProps ); +} + +//VBA by minz@cn.ibm.com. Add Workbook.SaveAs. +void +ScVbaWorkbook::SaveAs( const rtl::OUString& FileName, const uno::Any& FileFormat, const uno::Any& /*CreateBackup*/ ) throw ( uno::RuntimeException) +{ + rtl::OUString aURL; + osl::FileBase::getFileURLFromSystemPath( FileName, aURL ); + //liuchen 2009-12-16 if the input parameter "FileName" takes the form as "MyFile", we need to get the current directory and combine the current directory and the file name + INetURLObject aFileNameURL( aURL ); + aURL = aFileNameURL.GetMainURL( INetURLObject::NO_DECODE ); + if ( aURL.getLength() == 0 ) + { + uno::Reference< excel::XApplication > xApplication ( Application(),uno::UNO_QUERY_THROW ); + rtl::OUString aPathStr = xApplication->getDefaultFilePath(); + rtl::OUString aPathURLStr; + osl::FileBase::getFileURLFromSystemPath( aPathStr, aPathURLStr ); + INetURLObject aPathURL( aPathURLStr ); + aPathURL.Append( FileName ); + aURL = aPathURL.GetMainURL( INetURLObject::NO_DECODE ); + } + //liuchen 2009-12-16 + uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW ); + + sal_Int32 aFileFormat = excel::XlFileFormat::xlExcel9795; + FileFormat >>= aFileFormat; + + if ( FileName.indexOf('.') == -1 ) + { + if ( aFileFormat == excel::XlFileFormat::xlExcel9795 ) + { + aURL = aURL + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".xls" ) ); + } + else if ( aFileFormat == excel::XlFileFormat::xlCSV ) + { + aURL = aURL + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".csv" ) ); + } + } + + uno::Sequence< beans::PropertyValue > storeProps(1); + storeProps[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) ); + storeProps[0].Value <<= convertFileFormat(aFileFormat); + + xStor->storeAsURL( aURL, storeProps ); +} + +css::uno::Any SAL_CALL +ScVbaWorkbook::Styles( const::uno::Any& Item ) throw (uno::RuntimeException) +{ + // quick look and Styles object doesn't seem to have a valid parent + // or a least the object browser just shows an object that has no + // variables ( therefore... leave as NULL for now ) + uno::Reference< XCollection > dStyles = new ScVbaStyles( uno::Reference< XHelperInterface >(), mxContext, getModel() ); + if ( Item.hasValue() ) + return dStyles->Item( Item, uno::Any() ); + return uno::makeAny( dStyles ); +} + +// Amelia Wang +uno::Any SAL_CALL +ScVbaWorkbook::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getModel() ); + uno::Reference< beans::XPropertySet > xProps( xModel, uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW ); + uno::Reference< XCollection > xNames( new ScVbaNames( this , mxContext , xNamedRanges , xModel )); + if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID ) + { + return uno::Any( xNames ); +} + return uno::Any( xNames->Item( aIndex, uno::Any() ) ); +} + +rtl::OUString& +ScVbaWorkbook::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorkbook") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaWorkbook::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Workbook" ) ); + } + return aServiceNames; +} + +::rtl::OUString SAL_CALL +ScVbaWorkbook::getCodeName() throw (css::uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY_THROW ); + return xModelProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >(); +} + +namespace workbook +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaWorkbook, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaWorkbook", + "ooo.vba.excel.Workbook" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworkbook.hxx b/sc/source/ui/vba/vbaworkbook.hxx new file mode 100644 index 000000000000..6bde08a111ae --- /dev/null +++ b/sc/source/ui/vba/vbaworkbook.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_WORKBOOK_HXX +#define SC_VBA_WORKBOOK_HXX + +#include <com/sun/star/frame/XModel.hpp> +#include <ooo/vba/excel/XWorkbook.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbadocumentbase.hxx> + +class ScModelObj; + +typedef cppu::ImplInheritanceHelper1< VbaDocumentBase, ov::excel::XWorkbook > ScVbaWorkbook_BASE; + +class ScVbaWorkbook : public ScVbaWorkbook_BASE +{ + static css::uno::Sequence< sal_Int32 > ColorData; + void initColorData( const css::uno::Sequence< sal_Int32 >& sColors ); + void init(); + + ::rtl::OUString convertFileFormat(sal_Int32 aFileFormat); +protected: + + ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext); +public: + ScVbaWorkbook( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::frame::XModel > xModel ); + ScVbaWorkbook( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); + virtual ~ScVbaWorkbook() {} + + // Attributes + virtual ::sal_Bool SAL_CALL getProtectStructure() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getActiveSheet() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getPrecisionAsDisplayed() throw (css::uno::RuntimeException); + virtual void SAL_CALL setPrecisionAsDisplayed( sal_Bool _precisionAsDisplayed ) throw (css::uno::RuntimeException); + + // Methods + virtual css::uno::Any SAL_CALL Worksheets( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Sheets( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Activate() throw (css::uno::RuntimeException); + virtual void SAL_CALL Protect( const css::uno::Any & aPassword ) throw (css::uno::RuntimeException); + // Amelia Wang + virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL Styles( const css::uno::Any& Item ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ResetColors( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Colors( const css::uno::Any& Index ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getFileFormat( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SaveCopyAs( const rtl::OUString& Filename ) throw ( css::uno::RuntimeException); + virtual void SAL_CALL SaveAs( const rtl::OUString& FileName, const css::uno::Any& FileFormat, const css::uno::Any& CreateBackup ) throw (css::uno::RuntimeException); + + // code name + virtual ::rtl::OUString SAL_CALL getCodeName() throw ( css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + + virtual css::uno::Reference< css::frame::XModel > getDocModel() { return mxModel; } +}; + +#endif /* SC_VBA_WORKBOOK_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx new file mode 100644 index 000000000000..2d64f50764ba --- /dev/null +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -0,0 +1,370 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <comphelper/processfactory.hxx> + +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase3.hxx> + +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/beans/PropertyVetoException.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/uri/XUriReference.hpp> +#include <com/sun/star/uri/XUriReferenceFactory.hpp> +#include <com/sun/star/script/vba/XVBACompatibility.hpp> +#include <com/sun/star/script/vba/XVBAModuleInfo.hpp> +#include <com/sun/star/script/ModuleInfo.hpp> +#include <com/sun/star/script/ModuleType.hpp> + +#include <sfx2/objsh.hxx> +#include <tools/urlobj.hxx> + +#include "vbaglobals.hxx" +#include "vbaworkbook.hxx" +#include "vbaworkbooks.hxx" +#include <vbahelper/vbahelper.hxx> + +#include <hash_map> +#include <vector> +#include <osl/file.hxx> +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +const sal_Int16 CUSTOM_CHAR = 5; + +void setUpDocumentModules( const uno::Reference< sheet::XSpreadsheetDocument >& xDoc ) +{ + uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY ); + ScDocShell* pShell = excel::getDocShell( xModel ); + if ( pShell ) + { + uno::Reference<script::XLibraryContainer> xLibContainer = pShell->GetBasicContainer(); + uno::Reference<script::vba::XVBACompatibility> xVBACompat( xLibContainer, uno::UNO_QUERY_THROW ); + xVBACompat->setVBACompatibilityMode( sal_True ); + String aPrjName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + pShell->GetBasicManager()->SetName( aPrjName ); + + if( xLibContainer.is() ) + { + if( !xLibContainer->hasByName( aPrjName ) ) + xLibContainer->createLibrary( aPrjName ); + uno::Any aLibAny = xLibContainer->getByName( aPrjName ); + uno::Reference< container::XNameContainer > xLib; + aLibAny >>= xLib; + if( xLib.is() ) + { + uno::Reference< script::vba::XVBAModuleInfo > xVBAModuleInfo( xLib, uno::UNO_QUERY_THROW ); + uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY_THROW); + // bootstrap vbaglobals + xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals"))); + uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY_THROW ); + // set up the module info for the workbook and sheets in the nealy created + // spreadsheet + ScDocument* pDoc = pShell->GetDocument(); + String sCodeName = pDoc->GetCodeName(); + if ( sCodeName.Len() == 0 ) + { + sCodeName = String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") ); + pDoc->SetCodeName( sCodeName ); + } + + std::vector< rtl::OUString > sDocModuleNames; + sDocModuleNames.push_back( sCodeName ); + + uno::Reference<container::XNameAccess > xSheets( xDoc->getSheets(), uno::UNO_QUERY_THROW ); + uno::Sequence< rtl::OUString > sSheets( xSheets->getElementNames() ); + + for ( sal_Int32 index=0; index < sSheets.getLength() ; ++index ) + { + sDocModuleNames.push_back( sSheets[ index ] ); + } + + std::vector<rtl::OUString>::iterator it_end = sDocModuleNames.end(); + + for ( std::vector<rtl::OUString>::iterator it = sDocModuleNames.begin(); it != it_end; ++it ) + { + script::ModuleInfo sModuleInfo; + + sModuleInfo.ModuleObject.set( xVBACodeNamedObjectAccess->getByName( *it ), uno::UNO_QUERY ); + sModuleInfo.ModuleType = script::ModuleType::DOCUMENT; + xVBAModuleInfo->insertModuleInfo( *it, sModuleInfo ); + if( xLib->hasByName( *it ) ) + xLib->replaceByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n") ) ) ); + else + xLib->insertByName( *it, uno::makeAny( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ) ) ); + } + } + } + } +} + +static uno::Any +getWorkbook( uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSpreadsheetDocument > &xDoc, const uno::Reference< XHelperInterface >& xParent ) +{ + // FIXME: fine as long as ScVbaWorkbook is stateless ... + uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY ); + if( !xModel.is() ) + return uno::Any(); + + ScDocShell* pShell = excel::getDocShell( xModel ); + if ( pShell ) + { + String sCodeName = pShell->GetDocument()->GetCodeName(); + uno::Reference< uno::XInterface > xIf = getUnoDocModule( sCodeName, pShell ); + if ( xIf.is() ) + { + OSL_TRACE(" *** Returning Module uno Object *** "); + return uno::makeAny( xIf ); + } + } + + ScVbaWorkbook *pWb = new ScVbaWorkbook( xParent, xContext, xModel ); + return uno::Any( uno::Reference< excel::XWorkbook > (pWb) ); +} + +class WorkBookEnumImpl : public EnumerationHelperImpl +{ + uno::Any m_aApplication; +public: + WorkBookEnumImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Any& aApplication ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_aApplication( aApplication ) {} + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + return getWorkbook( m_xContext, xDoc, m_xParent ); + } + +}; + +ScVbaWorkbooks::ScVbaWorkbooks( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext ) : ScVbaWorkbooks_BASE( xParent, xContext, VbaDocumentsBase::EXCEL_DOCUMENT ) +{ +} +// XEnumerationAccess +uno::Type +ScVbaWorkbooks::getElementType() throw (uno::RuntimeException) +{ + return excel::XWorkbook::static_type(0); +} +uno::Reference< container::XEnumeration > +ScVbaWorkbooks::createEnumeration() throw (uno::RuntimeException) +{ + // #FIXME its possible the WorkBookEnumImpl here doens't reflect + // the state of this object ( although it should ) would be + // safer to create an enumeration based on this objects state + // rather than one effectively based of the desktop component + uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return new WorkBookEnumImpl( mxParent, mxContext, xEnumerationAccess->createEnumeration(), Application() ); +} + +uno::Any +ScVbaWorkbooks::createCollectionObject( const css::uno::Any& aSource ) +{ + uno::Reference< sheet::XSpreadsheetDocument > xDoc( aSource, uno::UNO_QUERY_THROW ); + return getWorkbook( mxContext, xDoc, mxParent ); +} + + +uno::Any SAL_CALL +ScVbaWorkbooks::Add() throw (uno::RuntimeException) +{ + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( VbaDocumentsBase::Add() , uno::UNO_QUERY_THROW ); + + // need to set up the document modules ( and vba mode ) here + setUpDocumentModules( xSpreadDoc ); + if( xSpreadDoc.is() ) + return getWorkbook( mxContext, xSpreadDoc, mxParent ); + return uno::Any(); +} + +void +ScVbaWorkbooks::Close() throw (uno::RuntimeException) +{ + VbaDocumentsBase::Close(); +} + +bool +ScVbaWorkbooks::isTextFile( const rtl::OUString& sType ) +{ + // will return true if the file is + // a) a variant of a text file + // b) a csv file + // c) unknown + // returning true basically means treat this like a csv file + const static rtl::OUString txtType( RTL_CONSTASCII_USTRINGPARAM("writer_Text" ) ); + const static rtl::OUString csvType( RTL_CONSTASCII_USTRINGPARAM("calc_Text_txt_csv_StarCalc" ) ); + const static rtl::OUString encodedTxtType( RTL_CONSTASCII_USTRINGPARAM("writer_Text_encoded" ) ); + return sType.equals( txtType ) || sType.equals( csvType ) || ( sType.getLength() == 0 ) || sType.equals( encodedTxtType ); +} + +bool +ScVbaWorkbooks::isSpreadSheetFile( const rtl::OUString& sType ) +{ + // include calc_QPro etc. ? ( not for the moment anyway ) + if ( sType.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("calc_MS"))) == 0 + || sType.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("calc8"))) == 0 + || sType.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("calc_StarOffice"))) == 0 ) + return true; + return false; +} + +rtl::OUString +ScVbaWorkbooks::getFileFilterType( const rtl::OUString& rFileName ) +{ + uno::Reference< document::XTypeDetection > xTypeDetect( mxContext->getServiceManager()->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection"), mxContext), uno::UNO_QUERY_THROW ); + uno::Sequence< beans::PropertyValue > aMediaDesc(1); + aMediaDesc[ 0 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ("URL" ) ); + aMediaDesc[ 0 ].Value <<= rFileName; + rtl::OUString sType = xTypeDetect->queryTypeByDescriptor( aMediaDesc, sal_True ); + return sType; +} + +// #TODO# #FIXME# can any of the unused params below be used? +uno::Any +ScVbaWorkbooks::Open( const rtl::OUString& rFileName, const uno::Any& /*UpdateLinks*/, const uno::Any& ReadOnly, const uno::Any& Format, const uno::Any& /*Password*/, const uno::Any& /*WriteResPassword*/, const uno::Any& /*IgnoreReadOnlyRecommended*/, const uno::Any& /*Origin*/, const uno::Any& Delimiter, const uno::Any& /*Editable*/, const uno::Any& /*Notify*/, const uno::Any& /*Converter*/, const uno::Any& /*AddToMru*/ ) throw (uno::RuntimeException) +{ + // we need to detect if this is a URL, if not then assume its a file path + rtl::OUString aURL; + INetURLObject aObj; + aObj.SetURL( rFileName ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + if ( bIsURL ) + aURL = rFileName; + else + osl::FileBase::getFileURLFromSystemPath( rFileName, aURL ); + + uno::Sequence< beans::PropertyValue > sProps(0); + sal_Int32 nIndex = 0; + + rtl::OUString sType = getFileFilterType( aURL ); + // A text file means it needs to be processed as a csv file + if ( isTextFile( sType ) ) + { + // Values for format + // 1 Tabs + // 2 Commas + // 3 Spaces + // 4 Semicolons + // 5 Nothing + // 6 Custom character (see the Delimiter argument + // no format means use the current delimiter + sProps.realloc( 3 ); + sProps[ nIndex ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FilterOptions" ) ); + sal_Int16 delims[] = { 0 /*default not used*/, 9/*tab*/, 44/*comma*/, 32/*space*/, 59/*semicolon*/ }; + static rtl::OUString sRestOfFormat( RTL_CONSTASCII_USTRINGPARAM(",34,0,1" ) ); + + rtl::OUString sFormat; + sal_Int16 nFormat = 0; // default indicator + + + if ( Format.hasValue() ) + { + Format >>= nFormat; // val of nFormat overwritten if extracted + // validate param + if ( nFormat < 1 || nFormat > 6 ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Illegal value for Format" ) ), uno::Reference< uno::XInterface >() ); + } + + sal_Int16 nDelim = getCurrentDelim(); + + if ( nFormat > 0 && nFormat < CUSTOM_CHAR ) + { + nDelim = delims[ nFormat ]; + } + else if ( nFormat > CUSTOM_CHAR ) + { + // Need to check Delimiter param + if ( !Delimiter.hasValue() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Expected value for Delimiter" ) ), uno::Reference< uno::XInterface >() ); + rtl::OUString sStr; + Delimiter >>= sStr; + String aUniStr( sStr ); + if ( aUniStr.Len() ) + nDelim = aUniStr.GetChar(0); + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Incorrect value for Delimiter" ) ), uno::Reference< uno::XInterface >() ); + } + + getCurrentDelim() = nDelim; //set new current + + sFormat = rtl::OUString::valueOf( (sal_Int32)nDelim ) + sRestOfFormat; + sProps[ nIndex++ ].Value <<= sFormat; + sProps[ nIndex ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FilterName") ); + sProps[ nIndex++ ].Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Text - txt - csv (StarCalc)") ); + // Ensure WORKAROUND_CSV_TXT_BUG_i60158 gets called in typedetection.cxx so + // csv is forced for deep detected 'writerxxx' types + sProps[ nIndex ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DocumentService") ); + sProps[ nIndex ].Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument") ); + } + else if ( !isSpreadSheetFile( sType ) ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Bad Format")), uno::Reference< uno::XInterface >() ); + + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( VbaDocumentsBase::Open( rFileName, ReadOnly, sProps ), uno::UNO_QUERY_THROW ); + uno::Any aRet = getWorkbook( mxContext, xSpreadDoc, mxParent ); + uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY ); + if ( xWBook.is() ) + xWBook->Activate(); + return aRet; +} + +uno::Any +ScVbaWorkbooks::Open( const rtl::OUString& Filename, const uno::Any& ReadOnly, const uno::Sequence< beans::PropertyValue >& rProps ) throw (css::uno::RuntimeException) +{ + return VbaDocumentsBase::Open( Filename, ReadOnly, rProps ); +} + +rtl::OUString& +ScVbaWorkbooks::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorkbooks") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaWorkbooks::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Workbooks") ); + } + return sNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworkbooks.hxx b/sc/source/ui/vba/vbaworkbooks.hxx new file mode 100644 index 000000000000..6cd6d90fc46b --- /dev/null +++ b/sc/source/ui/vba/vbaworkbooks.hxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_WORKBOOKS_HXX +#define SC_VBA_WORKBOOKS_HXX + + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/excel/XWorkbooks.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <vbahelper/vbadocumentsbase.hxx> +#include "excelvbahelper.hxx" + + +class ScModelObj; + +typedef cppu::ImplInheritanceHelper1< VbaDocumentsBase, ov::excel::XWorkbooks > ScVbaWorkbooks_BASE; + +class ScVbaWorkbooks : public ScVbaWorkbooks_BASE +{ +private: + rtl::OUString getFileFilterType( const rtl::OUString& rString ); + bool isTextFile( const rtl::OUString& rString ); + bool isSpreadSheetFile( const rtl::OUString& rString ); + static sal_Int16& getCurrentDelim(){ static sal_Int16 nDelim = 44; return nDelim; } +public: + ScVbaWorkbooks( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); + virtual ~ScVbaWorkbooks() {} + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // ScVbaWorkbooks_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + + // XWorkbooks + virtual css::uno::Any SAL_CALL Add() throw (css::uno::RuntimeException); + virtual void SAL_CALL Close( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Open( const ::rtl::OUString& Filename, const css::uno::Any& UpdateLinks, const css::uno::Any& ReadOnly, const css::uno::Any& Format, const css::uno::Any& Password, const css::uno::Any& WriteResPassword, const css::uno::Any& IgnoreReadOnlyRecommended, const css::uno::Any& Origin, const css::uno::Any& Delimiter, const css::uno::Any& Editable, const css::uno::Any& Notify, const css::uno::Any& Converter, const css::uno::Any& AddToMru ) throw (css::uno::RuntimeException); + + // VbaDocumentsBase / XDocumentsBase (to avoid warning C4266 for hiding function on wntmsci) + virtual css::uno::Any SAL_CALL Open( const ::rtl::OUString& Filename, const css::uno::Any& ReadOnly, const css::uno::Sequence< css::beans::PropertyValue >& rProps ) throw (css::uno::RuntimeException); +}; + +#endif /* SC_VBA_WORKBOOKS_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx new file mode 100644 index 000000000000..ca00ef9ee495 --- /dev/null +++ b/sc/source/ui/vba/vbaworksheet.cxx @@ -0,0 +1,1112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <vbahelper/helperdecl.hxx> +#include <cppuhelper/queryinterface.hxx> + +#include "vbaworksheet.hxx" + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XIntrospectionAccess.hpp> +#include <com/sun/star/beans/XIntrospection.hpp> +#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> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#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> +#include <com/sun/star/sheet/XSheetPageBreak.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#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> +#include <com/sun/star/form/XFormsSupplier.hpp> +#include <ooo/vba/excel/XlEnableSelection.hpp> +#include <ooo/vba/excel/XWorkbook.hpp> +#include <ooo/vba/XControlProvider.hpp> +#include <ooo/vba/excel/XlSheetVisibility.hpp> + +#include <comphelper/processfactory.hxx> +#include <vbahelper/vbashapes.hxx> + +#include <tools/string.hxx> + +//zhangyun showdataform +#include <sfx2/sfxdlg.hxx> +#include "scabstdlg.hxx" +#include "tabvwsh.hxx" +#include "scitems.hxx" + +#include <svx/svdouno.hxx> +#include <svx/svdpage.hxx> + +#include "cellsuno.hxx" +#include "drwlayer.hxx" +#include "tabprotection.hxx" +#include "scextopt.hxx" +#include "vbaoutline.hxx" +#include "vbarange.hxx" +#include "vbacomments.hxx" +#include "vbachartobjects.hxx" +#include "vbapivottables.hxx" +#include "vbaoleobject.hxx" +#include "vbaoleobjects.hxx" +#include "vbapagesetup.hxx" +#include "vbapagebreaks.hxx" +#include "vbaworksheets.hxx" +#include "vbahyperlinks.hxx" +#include "vbasheetobjects.hxx" +#include "viewuno.hxx" //liuchen 2009-9-2 + +#define STANDARDWIDTH 2267 +#define STANDARDHEIGHT 427 +#define DOESNOTEXIST -1 + +using namespace com::sun::star; +using namespace ooo::vba; + +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 ); + static rtl::OUString aUnderScre( RTL_CONSTASCII_USTRINGPARAM( "_" ) ); + int currentNum =2; + aNewName = aOldName + aUnderScre+ String::CreateFromInt32(currentNum) ; + SCTAB nTab = 0; + while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) ) + { + aNewName = aOldName + aUnderScre + + String::CreateFromInt32(++currentNum) ; + } +} + +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()); + } + } + + uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY); + uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); + if (xNamed.is()) + { + xNamed->setName(aSheetName); + } + } +} + +static uno::Reference<frame::XModel> +openNewDoc(rtl::OUString aSheetName ) +{ + uno::Reference<frame::XModel> xModel; + try + { + uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Reference< uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + uno::Reference<lang::XMultiComponentFactory > xServiceManager( + xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + uno::Reference <frame::XComponentLoader > xComponentLoader( + xServiceManager->createInstanceWithContext( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), + xContext ), uno::UNO_QUERY_THROW ); + + uno::Reference<lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ), + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, + 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; +} + +ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext ) +{ +} + +ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< sheet::XSpreadsheet >& xSheet, + const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel) +{ +} + +ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args, + uno::Reference< uno::XComponentContext> const & xContext ) throw ( lang::IllegalArgumentException ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ) +{ + if ( args.getLength() < 2 ) + 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 ); +} + +ScVbaWorksheet::~ScVbaWorksheet() +{ +} + +::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 ); +} + +::sal_Int32 +ScVbaWorksheet::getVisible() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW ); + uno::Any aValue = xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ) ); + sal_Bool bRet = false; + aValue >>= bRet; + if ( bRet ) + { + return excel::XlSheetVisibility::xlSheetVisible; + } + else + { + return excel::XlSheetVisibility::xlSheetHidden; + } +} + +void +ScVbaWorksheet::setVisible( ::sal_Int32 _Visible ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW ); + + //VBA by minz@cn.ibm.com. + sal_Bool bVisible = true; + switch( _Visible ) + { + case excel::XlSheetVisibility::xlSheetHidden: + case excel::XlSheetVisibility::xlSheetVeryHidden: + bVisible = false; + break; + case excel::XlSheetVisibility::xlSheetVisible: + bVisible = true; + break; + } + uno::Any aValue( bVisible ); + xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ), aValue); +} + +sal_Int16 +ScVbaWorksheet::getIndex() throw (uno::RuntimeException) +{ + return getSheetID() + 1; +} + +sal_Int32 +ScVbaWorksheet::getEnableSelection() throw (uno::RuntimeException) +{ + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW ); + SCTAB nTab = 0; + if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) ) + { + uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); + ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument(); + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab); + sal_Bool bLockedCells = sal_False; + sal_Bool bUnlockedCells = sal_False; + 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 + throw uno::RuntimeException(::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ), + uno::Reference< XInterface >() ); + return excel::XlEnableSelection::xlNoSelection; +} + + +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; + if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) ) + { + uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); + ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument(); + ScTableProtection* pProtect = pDoc->GetTabProtection(nTab); + // default is xlNoSelection + sal_Bool bLockedCells = sal_False; + sal_Bool bUnlockedCells = sal_False; + 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 + throw uno::RuntimeException(::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ), + uno::Reference< XInterface >() ); + +} + +uno::Reference< beans::XPropertySet > ScVbaWorksheet::getFirstDBRangeProperties() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XIndexAccess > xDBRangesIA( xModelProps->getPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DatabaseRanges" ) ) ), uno::UNO_QUERY_THROW ); + + for( sal_Int32 nIndex = 0, nCount = xDBRangesIA->getCount(); nIndex < nCount; ++nIndex ) + { + uno::Reference< sheet::XCellRangeReferrer > xDBRange( xDBRangesIA->getByIndex( nIndex ), uno::UNO_QUERY_THROW ); + // check if the database area is on this sheet + uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( xDBRange->getReferredCells(), uno::UNO_QUERY_THROW ); + if( getSheetID() == xRangeAddr->getRangeAddress().Sheet ) + return uno::Reference< beans::XPropertySet >( xDBRange, uno::UNO_QUERY_THROW ); + } + return uno::Reference< beans::XPropertySet >(); +} + +sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode() throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties(); + sal_Bool bAutoFilterMode = sal_False; + return + xDBRangeProps.is() && + (xDBRangeProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ) ) >>= bAutoFilterMode) && + bAutoFilterMode; +} + +void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties(); + if( xDBRangeProps.is() ) + xDBRangeProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ), uno::Any( bAutoFilterMode ) ); +} + +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); + return new ScVbaRange(this, mxContext, xRange); +} + +uno::Reference< excel::XOutline > +ScVbaWorksheet::Outline( ) throw (uno::RuntimeException) +{ + uno::Reference<sheet::XSheetOutline> xOutline(getSheet(),uno::UNO_QUERY_THROW); + return new ScVbaOutline( this, mxContext, xOutline); +} + +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 ); +} + +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 ); +} + +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) +{ + return sal_False; +} + +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) +{ + 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 ); + } + return sal_False; +} + +sal_Bool +ScVbaWorksheet::getProtectScenarios() throw (uno::RuntimeException) +{ + return sal_False; +} + +void +ScVbaWorksheet::Activate() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XSpreadsheetView > xSpreadsheet( + getModel()->getCurrentController(), uno::UNO_QUERY_THROW ); + xSpreadsheet->setActiveSheet(getSheet()); +} + +//liuchen 2009-9-2, support expand (but not replace) the active sheet +void +ScVbaWorksheet::Select(const css::uno::Any& aReplace) throw (uno::RuntimeException) +{ + sal_Bool bReplace = true; + if (aReplace.hasValue() && aReplace.getValueTypeClass() == uno::TypeClass_BOOLEAN) + { + aReplace >>= bReplace; + } + + uno::Reference< sheet::XSpreadsheetView > xSpreadsheet( + getModel()->getCurrentController(), uno::UNO_QUERY_THROW ); + ScTabViewObj* pTabView = static_cast< ScTabViewObj* >( xSpreadsheet.get() ); + + if (bReplace) + { + pTabView->selectSheet(getSheet(), false); + } + else + { + uno::Reference< sheet::XSpreadsheet > xOldActiveSheet = pTabView->getActiveSheet(); + pTabView->selectSheet(getSheet(), true); + pTabView->selectSheet(xOldActiveSheet, true); + } +} + +void +ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After ) throw (uno::RuntimeException) +{ + uno::Reference<excel::XWorksheet> xSheet; + rtl::OUString aCurrSheetName = getName(); + + 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); + // #FIXME needs worksheet as parent + 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); + Delete(); + } + return ; + } + + uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW ); + SCTAB nDest = 0; + if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) ) + { + 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; + rtl::OUString aCurrSheetName =getName(); + 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); + 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); + } + return; + } + + ScVbaWorksheet* pDestSheet = static_cast< ScVbaWorksheet* >(xSheet.get()); + 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; + SCTAB nDummy=0; + if ( bSheetExists && bDestSheetExists ) + { + sal_Bool bAfter = After.hasValue(); + 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 ); + } + } + // active the 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 ); + xNewSheet->Activate(); +} + + +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(); + excel::implnPaste( mxModel ); +} + +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; + if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab )) + { + return; + } + uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets(); + uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW); + xNameContainer->removeByName(aSheetName); + mxSheet.clear(); + } +} + +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; + if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) ) + return uno::Reference< excel::XWorksheet >(); + nIdx = nIdx + offset; + uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW); + // parent will be the parent of 'this' worksheet + return new ScVbaWorksheet (getParent(), mxContext, xSheet, getModel()); +} + +uno::Reference< excel::XWorksheet > +ScVbaWorksheet::getNext() throw (uno::RuntimeException) +{ + //VBA, minz@cn.ibm.com. catch the exception for index out of bound + try{ + return getSheetAtOffset(static_cast<SCTAB>(1)); + }catch( lang::IndexOutOfBoundsException& /*e*/ ) + { + return NULL; + } +} + +uno::Reference< excel::XWorksheet > +ScVbaWorksheet::getPrevious() throw (uno::RuntimeException) +{ + //VBA, minz@cn.ibm.com. catch the exception for index out of bound + try{ + return getSheetAtOffset(-1); + }catch( lang::IndexOutOfBoundsException& /*e*/ ) + { + return NULL; + } +} + + +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) +{ + uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext +, 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 + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SpellDialog")); + 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 ); + return uno::Reference< excel::XRange >( new ScVbaRange( this, mxContext, xRange ) ); +} + +// 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) +{ + return getSheetRange()->Cells( nRow, nCol ); +} + +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(); + + uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getSheet(), uno::UNO_QUERY_THROW ); //VBA, minz@cn.ibm.com. + mxCharts = new ScVbaChartObjects( this, mxContext, xTableCharts, xDrawPageSupplier ); + } + if ( Index.hasValue() ) + { + uno::Reference< XCollection > xColl( mxCharts, uno::UNO_QUERY_THROW ); + return xColl->Item( Index, uno::Any() ); + } + else + return uno::makeAny( mxCharts ); + +} + +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 ); + + uno::Reference< XCollection > xColl( new ScVbaPivotTables( this, mxContext, xIndexAccess ) ); + if ( Index.hasValue() ) + return xColl->Item( Index, uno::Any() ); + return uno::makeAny( xColl ); +} + +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 ); + uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) ); + if ( Index.hasValue() ) + return xColl->Item( Index, uno::Any() ); + return uno::makeAny( xColl ); +} + +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 ); +} + +uno::Any SAL_CALL +ScVbaWorksheet::Names( const css::uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< excel::XWorkbook > xWorkbook( getParent(), uno::UNO_QUERY_THROW ); + return xWorkbook->Names( aIndex ); +} + +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 ); + + uno::Reference< excel::XOLEObjects >xOleObjects( new ScVbaOLEObjects( this, mxContext, xIndexAccess ) ); + if( Index.hasValue() ) + return xOleObjects->Item( Index, uno::Any() ); + return uno::Any( xOleObjects ); +} + +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 ); + + uno::Reference< msforms::XShapes> xVbaShapes( new ScVbaShapes( this, mxContext, xIndexAccess, getModel() ) ); + if ( aIndex.hasValue() ) + return xVbaShapes->Item( aIndex, uno::Any() ); + return uno::makeAny( xVbaShapes ); +} + +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(); +} + +void SAL_CALL +ScVbaWorksheet::ShowDataForm( ) throw (uno::RuntimeException) +{ +#ifdef VBA_OOBUILD_HACK + uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW ); + ScTabViewShell* pTabViewShell = excel::getBestViewShell( xModel ); + + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + DBG_ASSERT(pFact, "ScAbstractFactory create fail!"); + + AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg( pTabViewShell->GetDialogParent(),RID_SCDLG_DATAFORM, pTabViewShell); + DBG_ASSERT(pDlg, "Dialog create fail!"); + + pDlg->Execute(); +#else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); +#endif +} + +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 +ScVbaWorksheet::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + setDefaultPropByIntrospection( uno::makeAny( getValue( aPropertyName ) ), aValue ); +} +uno::Any SAL_CALL +ScVbaWorksheet::getValue( const ::rtl::OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException) +{ + uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW ); + + uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW ); + uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) ); + return uno::makeAny( xControl ); +} + +::sal_Bool SAL_CALL +ScVbaWorksheet::hasMethod( const ::rtl::OUString& /*aName*/ ) throw (uno::RuntimeException) +{ + return sal_False; +} + +uno::Reference< container::XNameAccess > +ScVbaWorksheet::getFormControls() +{ + uno::Reference< container::XNameAccess > xFormControls; + try + { + 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 + xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW ); + + } + catch( uno::Exception& ) + { + } + return xFormControls; + + } +::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 ); + return sal_False; +} + +uno::Any +ScVbaWorksheet::getControlShape( const ::rtl::OUString& sName ) +{ + // 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 ); + + sal_Int32 nCount = xIndexAccess->getCount(); + for( int index = 0; index < nCount; index++ ) + { + uno::Any aUnoObj = xIndexAccess->getByIndex( index ); + // 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 ); + if( sName.equals( xNamed->getName() )) + { + return aUnoObj; + } + } + } + return uno::Any(); +} + + +rtl::OUString& +ScVbaWorksheet::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorksheet") ); + return sImplName; +} +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 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheet" ) ); + } + return aServiceNames; +} + +rtl::OUString SAL_CALL +ScVbaWorksheet::getCodeName() throw (css::uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW ); + return xSheetProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >(); +} + +sal_Int16 +ScVbaWorksheet::getSheetID() throw (uno::RuntimeException) +{ + uno::Reference< sheet::XCellRangeAddressable > xAddressable( getSheet(), uno::UNO_QUERY_THROW ); //VBA. minz@cn.ibm.com. if ActiveSheet, mxSheet is null. + return xAddressable->getRangeAddress().Sheet; +} + +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; + sal_Bool bCollate = sal_False; + sal_Bool bSelection = sal_False; + sal_Bool bIgnorePrintAreas = sal_False; + 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 ); + PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection ); +} + +namespace worksheet +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaWorksheet, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaWorksheet", + "ooo.vba.excel.Worksheet" ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworksheet.hxx b/sc/source/ui/vba/vbaworksheet.hxx new file mode 100644 index 000000000000..b27bf99fd40a --- /dev/null +++ b/sc/source/ui/vba/vbaworksheet.hxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_WORKSHEET_HXX +#define SC_VBA_WORKSHEET_HXX + +#include <cppuhelper/implbase2.hxx> +#include <comphelper/unwrapargs.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/script/XInvocation.hpp> +#include <ooo/vba/excel/XWorksheet.hpp> +#include <ooo/vba/excel/XComments.hpp> +#include <ooo/vba/excel/XRange.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <ooo/vba/excel/XOutline.hpp> +#include <ooo/vba/excel/XPageSetup.hpp> +#include <ooo/vba/excel/XHPageBreaks.hpp> +#include <ooo/vba/excel/XVPageBreaks.hpp> +#include <com/sun/star/container/XNamed.hpp> + +#include <vbahelper/vbahelperinterface.hxx> +#include "address.hxx" + +namespace ooo { namespace vba { namespace excel { + class XChartObjects; + class XHyperlinks; +} } } + +class ScVbaSheetObjectsBase; + +typedef InheritedHelperInterfaceImpl1< ov::excel::XWorksheet > WorksheetImpl_BASE; + +class ScVbaWorksheet : public WorksheetImpl_BASE +{ + css::uno::Reference< css::sheet::XSpreadsheet > mxSheet; + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< ov::excel::XChartObjects > mxCharts; + css::uno::Reference< ov::excel::XHyperlinks > mxHlinks; + ::rtl::Reference< ScVbaSheetObjectsBase > mxButtons; + + css::uno::Reference< ov::excel::XWorksheet > getSheetAtOffset(SCTAB offset) throw (css::uno::RuntimeException); + css::uno::Reference< ov::excel::XRange > getSheetRange() throw (css::uno::RuntimeException); + + css::uno::Reference< css::container::XNameAccess > getFormControls(); + css::uno::Any getControlShape( const rtl::OUString& sName ); + + css::uno::Reference< css::beans::XPropertySet > getFirstDBRangeProperties() throw (css::uno::RuntimeException); + +protected: + + ScVbaWorksheet( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ); +public: + ScVbaWorksheet( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::sheet::XSpreadsheet >& xSheet, + const css::uno::Reference< css::frame::XModel >& xModel )throw (css::uno::RuntimeException) ; + ScVbaWorksheet( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ) throw ( css::lang::IllegalArgumentException ); + + virtual ~ScVbaWorksheet(); + + virtual css::uno::Reference< css::frame::XModel > getModel() + { return mxModel; } + virtual css::uno::Reference< css::sheet::XSpreadsheet > getSheet() + { return mxSheet; } + + // Attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString &rName ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Int32 _Visible ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getStandardWidth() throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getStandardHeight() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getProtectionMode() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getProtectContents() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getProtectDrawingObjects() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getProtectScenarios() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getUsedRange() throw (css::uno::RuntimeException) ; + virtual css::uno::Any SAL_CALL ChartObjects( const css::uno::Any& Index ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XOutline > SAL_CALL Outline( ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XPageSetup > SAL_CALL PageSetup( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL HPageBreaks( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL VPageBreaks( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getNext() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XWorksheet > SAL_CALL getPrevious() throw (css::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getIndex() throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getEnableSelection() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnableSelection( sal_Int32 nSelection ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getAutoFilterMode() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoFilterMode( sal_Bool bAutoFilterMode ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Activate() throw (css::uno::RuntimeException); + virtual void SAL_CALL Select(const css::uno::Any& aReplace) throw (css::uno::RuntimeException); //liuchen 2009-9-2, add the input parameter to support expand selection + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Range( const css::uno::Any& Cell1, const css::uno::Any& Cell2 ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Move( const css::uno::Any& Before, const css::uno::Any& After ) throw (css::uno::RuntimeException) ; + virtual void SAL_CALL Copy( const css::uno::Any& Before, const css::uno::Any& After ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Paste( const css::uno::Any& Destination, const css::uno::Any& Link ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Protect( const css::uno::Any& Password, const css::uno::Any& DrawingObjects, const css::uno::Any& Contents, const css::uno::Any& Scenarios, const css::uno::Any& UserInterfaceOnly ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Unprotect( const css::uno::Any& Password ) throw (css::uno::RuntimeException); + + virtual void SAL_CALL Calculate( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL CheckSpelling( const css::uno::Any& CustomDictionary,const css::uno::Any& IgnoreUppercase,const css::uno::Any& AlwaysSuggest, const css::uno::Any& SpellingLang ) throw (css::uno::RuntimeException); + // Hacks (?) + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Cells( const css::uno::Any &nRow, const css::uno::Any &nCol ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Rows(const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::excel::XRange > SAL_CALL Columns(const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL Evaluate( const ::rtl::OUString& Name ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL PivotTables( const css::uno::Any& Index ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Comments( const css::uno::Any& Index ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Hyperlinks( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Names( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL OLEObjects( const css::uno::Any& Index ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Shapes( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL Buttons( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL CheckBoxes( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL DropDowns( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL GroupBoxes( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Labels( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL ListBoxes( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL OptionButtons( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL ScrollBars( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Spinners( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + virtual void SAL_CALL setEnableCalculation( ::sal_Bool EnableCalculation ) throw ( css::script::BasicErrorException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getEnableCalculation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual void SAL_CALL ShowDataForm( ) throw (css::uno::RuntimeException); + // XInvocation + virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ) throw (css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) throw (css::beans::UnknownPropertyException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); + // CodeName + virtual rtl::OUString SAL_CALL getCodeName() throw (css::uno::RuntimeException); + sal_Int16 getSheetID() throw (css::uno::RuntimeException); + + virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName, const css::uno::Any& IgnorePrintAreas ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* SC_VBA_WORKSHEET_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworksheets.cxx b/sc/source/ui/vba/vbaworksheets.cxx new file mode 100644 index 000000000000..5263b9a8ea34 --- /dev/null +++ b/sc/source/ui/vba/vbaworksheets.cxx @@ -0,0 +1,504 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaworksheets.hxx" + +#include <sfx2/dispatch.hxx> +#include <sfx2/app.hxx> +#include <sfx2/bindings.hxx> +#include <sfx2/request.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/itemwrapper.hxx> +#include <svl/itemset.hxx> +#include <svl/eitem.hxx> + +#include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase3.hxx> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <ooo/vba/excel/XApplication.hpp> +#include <tools/string.hxx> +#include "tabvwsh.hxx" + +#include "vbaglobals.hxx" +#include "vbaworksheet.hxx" +#include "vbaworkbook.hxx" +#include "unonames.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > SheetEnumeration_BASE; +typedef ::cppu::WeakImplHelper3< container::XNameAccess, container::XIndexAccess, container::XEnumerationAccess > SheetCollectionHelper_BASE; +// a map ( or hashmap ) wont do as we need also to preserve the order +// (as added ) of the items +typedef std::vector< uno::Reference< sheet::XSpreadsheet > > SheetMap; + + +// #FIXME #TODO the implementation of the Sheets collections sucks, +// e.g. there is no support for tracking sheets added/removed from the collection + +uno::Reference< uno::XInterface > +lcl_getModulAsUnoObject( const uno::Reference< sheet::XSpreadsheet >& xSheet, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) +{ + uno::Reference< uno::XInterface > xRet; + if ( !xSheet.is() ) + throw uno::RuntimeException(); + uno::Reference< beans::XPropertySet > xProps( xSheet, uno::UNO_QUERY_THROW ); + rtl::OUString sName; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_CODENAME ) ) ) >>= sName; + + ScDocShell* pShell = excel::getDocShell( xModel ); + + if ( pShell ) + xRet = getUnoDocModule( sName, pShell ); + return xRet; +} + +class WorkSheetsEnumeration : public SheetEnumeration_BASE +{ + SheetMap mSheetMap; + SheetMap::iterator mIt; +public: + WorkSheetsEnumeration( const SheetMap& sMap ) : mSheetMap( sMap ), mIt( mSheetMap.begin() ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( mIt != mSheetMap.end() ); + } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + throw container::NoSuchElementException(); + uno::Reference< sheet::XSpreadsheet > xSheet( *mIt++ ); + return uno::makeAny( xSheet ) ; + } +}; + +class SheetCollectionHelper : public SheetCollectionHelper_BASE +{ + SheetMap mSheetMap; + SheetMap::iterator cachePos; +public: + SheetCollectionHelper( const SheetMap& sMap ) : mSheetMap( sMap ), cachePos(mSheetMap.begin()) {} + // XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) { return sheet::XSpreadsheet::static_type(0); } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) { return ( mSheetMap.size() > 0 ); } + // XNameAcess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasByName(aName) ) + throw container::NoSuchElementException(); + return uno::makeAny( *cachePos ); + } + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + uno::Sequence< rtl::OUString > sNames( mSheetMap.size() ); + rtl::OUString* pString = sNames.getArray(); + SheetMap::iterator it = mSheetMap.begin(); + SheetMap::iterator it_end = mSheetMap.end(); + + for ( ; it != it_end; ++it, ++pString ) + { + uno::Reference< container::XNamed > xName( *it, uno::UNO_QUERY_THROW ); + *pString = xName->getName(); + } + return sNames; + } + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + cachePos = mSheetMap.begin(); + SheetMap::iterator it_end = mSheetMap.end(); + for ( ; cachePos != it_end; ++cachePos ) + { + uno::Reference< container::XNamed > xName( *cachePos, uno::UNO_QUERY_THROW ); + if ( aName.equals( xName->getName() ) ) + break; + } + return ( cachePos != it_end ); + } + + // XElementAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) { return mSheetMap.size(); } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) + { + if ( Index < 0 || Index >= getCount() ) + throw lang::IndexOutOfBoundsException(); + + return uno::makeAny( mSheetMap[ Index ] ); + + } + // XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new WorkSheetsEnumeration( mSheetMap ); + } +}; + +class SheetsEnumeration : public EnumerationHelperImpl +{ + uno::Reference< frame::XModel > m_xModel; +public: + SheetsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_xModel( xModel ) {} + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + uno::Reference< sheet::XSpreadsheet > xSheet( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW ); + uno::Reference< uno::XInterface > xIf = lcl_getModulAsUnoObject( xSheet, m_xModel ); + uno::Any aRet; + if ( !xIf.is() ) + { + // if the Sheet is in a document created by the api unfortunately ( at the + // moment, it actually wont have the special Document modules + uno::Reference< excel::XWorksheet > xNewSheet( new ScVbaWorksheet( m_xParent, m_xContext, xSheet, m_xModel ) ); + aRet <<= xNewSheet; + } + else + aRet <<= xIf; + return aRet; + } + +}; + +ScVbaWorksheets::ScVbaWorksheets( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XIndexAccess >& xSheets, const uno::Reference< frame::XModel >& xModel ): ScVbaWorksheets_BASE( xParent, xContext, xSheets ), mxModel( xModel ), m_xSheets( uno::Reference< sheet::XSpreadsheets >( xSheets, uno::UNO_QUERY ) ) +{ +} + +ScVbaWorksheets::ScVbaWorksheets( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< ::com::sun::star::uno::XComponentContext > & xContext, const uno::Reference< container::XEnumerationAccess >& xEnumAccess, const uno::Reference< frame::XModel >& xModel ): ScVbaWorksheets_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( xEnumAccess, uno::UNO_QUERY ) ), mxModel(xModel) +{ +} + +// XEnumerationAccess +uno::Type +ScVbaWorksheets::getElementType() throw (uno::RuntimeException) +{ + return excel::XWorksheet::static_type(0); +} + +uno::Reference< container::XEnumeration > +ScVbaWorksheets::createEnumeration() throw (uno::RuntimeException) +{ + if ( !m_xSheets.is() ) + { + uno::Reference< container::XEnumerationAccess > xAccess( m_xIndexAccess, uno::UNO_QUERY_THROW ); + return xAccess->createEnumeration(); + } + uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xSheets, uno::UNO_QUERY_THROW ); + return new SheetsEnumeration( this, mxContext, xEnumAccess->createEnumeration(), mxModel ); +} + +uno::Any +ScVbaWorksheets::createCollectionObject( const uno::Any& aSource ) +{ + uno::Reference< sheet::XSpreadsheet > xSheet( aSource, uno::UNO_QUERY ); + uno::Reference< XInterface > xIf = lcl_getModulAsUnoObject( xSheet, mxModel ); + uno::Any aRet; + if ( !xIf.is() ) + { + // if the Sheet is in a document created by the api unfortunately ( at the + // moment, it actually wont have the special Document modules + uno::Reference< excel::XWorksheet > xNewSheet( new ScVbaWorksheet( getParent(), mxContext, xSheet, mxModel ) ); + aRet <<= xNewSheet; + } + else + aRet <<= xIf; + return aRet; +} + +// XWorksheets +uno::Any +ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After, + const uno::Any& Count, const uno::Any& Type ) throw (uno::RuntimeException) +{ + if ( isSelectedSheets() ) + return uno::Any(); // or should we throw? + + rtl::OUString aStringSheet; + sal_Bool bBefore(sal_True); + SCTAB nSheetIndex = 0; + SCTAB nNewSheets = 1, nType = 0; + Count >>= nNewSheets; + Type >>= nType; + SCTAB nCount = 0; + + uno::Reference< excel::XWorksheet > xBeforeAfterSheet; + + if ( Before.hasValue() ) + { + if ( Before >>= xBeforeAfterSheet ) + aStringSheet = xBeforeAfterSheet->getName(); + else + Before >>= aStringSheet; + } + + if (!aStringSheet.getLength() && After.hasValue() ) + { + if ( After >>= xBeforeAfterSheet ) + aStringSheet = xBeforeAfterSheet->getName(); + else + After >>= aStringSheet; + bBefore = sal_False; + } + if (!aStringSheet.getLength()) + { + uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + aStringSheet = xApplication->getActiveWorkbook()->getActiveSheet()->getName(); + bBefore = sal_True; + } + nCount = static_cast< SCTAB >( m_xIndexAccess->getCount() ); + for (SCTAB i=0; i < nCount; i++) + { + uno::Reference< sheet::XSpreadsheet > xSheet(m_xIndexAccess->getByIndex(i), uno::UNO_QUERY); + uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW ); + if (xNamed->getName() == aStringSheet) + { + nSheetIndex = i; + break; + } + } + + if(!bBefore) + nSheetIndex++; + + SCTAB nSheetName = nCount + 1L; + String aStringBase( RTL_CONSTASCII_USTRINGPARAM("Sheet") ); + uno::Any result; + for (SCTAB i=0; i < nNewSheets; i++, nSheetName++) + { + String aStringName = aStringBase; + aStringName += String::CreateFromInt32(nSheetName); + while (m_xNameAccess->hasByName(aStringName)) + { + nSheetName++; + aStringName = aStringBase; + aStringName += String::CreateFromInt32(nSheetName); + } + m_xSheets->insertNewByName(aStringName, nSheetIndex + i); + result = getItemByStringIndex( aStringName ); + } + uno::Reference< excel::XWorksheet > xNewSheet( result, uno::UNO_QUERY ); + if ( xNewSheet.is() ) + xNewSheet->Activate(); + return result; +} + +void +ScVbaWorksheets::Delete() throw (uno::RuntimeException) +{ + // #TODO #INVESTIGATE + // mmm this method could be trouble if the underlying + // uno objects ( the m_xIndexAccess etc ) aren't aware of the + // contents that are deleted + sal_Int32 nElems = getCount(); + for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem ) + { + uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW ); + xSheet->Delete(); + } +} + +bool +ScVbaWorksheets::isSelectedSheets() +{ + return !m_xSheets.is(); +} + +void SAL_CALL +ScVbaWorksheets::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 ) throw (uno::RuntimeException) +{ + sal_Int32 nTo = 0; + sal_Int32 nFrom = 0; + sal_Int16 nCopies = 1; + sal_Bool bCollate = sal_False; + sal_Bool bSelection = sal_False; + From >>= nFrom; + To >>= nTo; + Copies >>= nCopies; + if ( nCopies > 1 ) // Collate only useful when more that 1 copy + Collate >>= bCollate; + + if ( !( nFrom || nTo ) ) + if ( isSelectedSheets() ) + bSelection = sal_True; + + PrintOutHelper( excel::getBestViewShell( mxModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection ); +} + +uno::Any SAL_CALL +ScVbaWorksheets::getVisible() throw (uno::RuntimeException) +{ + sal_Bool bVisible = sal_True; + uno::Reference< container::XEnumeration > xEnum( createEnumeration(), uno::UNO_QUERY_THROW ); + while ( xEnum->hasMoreElements() ) + { + uno::Reference< excel::XWorksheet > xSheet( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + if ( xSheet->getVisible() == sal_False ) + { + bVisible = sal_False; + break; + } + } + return uno::makeAny( bVisible ); +} + +void SAL_CALL +ScVbaWorksheets::setVisible( const uno::Any& _visible ) throw (uno::RuntimeException) +{ + sal_Bool bState = sal_False; + if ( _visible >>= bState ) + { + uno::Reference< container::XEnumeration > xEnum( createEnumeration(), uno::UNO_QUERY_THROW ); + while ( xEnum->hasMoreElements() ) + { + uno::Reference< excel::XWorksheet > xSheet( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + xSheet->setVisible( bState ); + } + } + else + throw uno::RuntimeException( rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "Visible property doesn't support non boolean #FIXME" ) ), uno::Reference< uno::XInterface >() ); +} + +void SAL_CALL +ScVbaWorksheets::Select( const uno::Any& Replace ) throw (uno::RuntimeException) +{ + ScTabViewShell* pViewShell = excel::getBestViewShell( mxModel ); + if ( !pViewShell ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cannot obtain view shell" ) ), uno::Reference< uno::XInterface >() ); + + ScMarkData& rMarkData = pViewShell->GetViewData()->GetMarkData(); + sal_Bool bReplace = sal_True; + Replace >>= bReplace; + // Replace is defaulted to True, meanining this current collection + // becomes the Selection, if it were false then the current selection would + // be extended + bool bSelectSingle = bReplace; + sal_Int32 nElems = getCount(); + for ( sal_Int32 nItem = 1; nItem <= nElems; ++nItem ) + { + uno::Reference< excel::XWorksheet > xSheet( Item( uno::makeAny( nItem ), uno::Any() ), uno::UNO_QUERY_THROW ); + ScVbaWorksheet* pSheet = dynamic_cast< ScVbaWorksheet* >( xSheet.get() ); + if ( pSheet ) + { + if ( bSelectSingle ) + { + rMarkData.SelectOneTable( static_cast< SCTAB >( pSheet->getSheetID() ) ); + bSelectSingle = false; + } + else + rMarkData.SelectTable( static_cast< SCTAB >( pSheet->getSheetID() ), TRUE ); + + } + } + + +} + +//ScVbaCollectionBaseImpl +uno::Any SAL_CALL +ScVbaWorksheets::Item( const uno::Any& Index, const uno::Any& Index2 ) throw (uno::RuntimeException) +{ + if ( Index.getValueTypeClass() == uno::TypeClass_SEQUENCE ) + { + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter(mxContext); + uno::Any aConverted; + aConverted = xConverter->convertTo( Index, getCppuType((uno::Sequence< uno::Any >*)0) ); + SheetMap mSheets; + uno::Sequence< uno::Any > sIndices; + aConverted >>= sIndices; + sal_Int32 nElems = sIndices.getLength(); + for( sal_Int32 index = 0; index < nElems; ++index ) + { + uno::Reference< excel::XWorksheet > xWorkSheet( ScVbaWorksheets_BASE::Item( sIndices[ index ], Index2 ), uno::UNO_QUERY_THROW ); + ScVbaWorksheet* pWorkSheet = dynamic_cast< ScVbaWorksheet* >( xWorkSheet.get() ); + if ( pWorkSheet ) + { + uno::Reference< sheet::XSpreadsheet > xSheet( pWorkSheet->getSheet() , uno::UNO_QUERY_THROW ); + uno::Reference< container::XNamed > xName( xSheet, uno::UNO_QUERY_THROW ); + mSheets.push_back( xSheet ); + } + } + uno::Reference< container::XIndexAccess > xIndexAccess = new SheetCollectionHelper( mSheets ); + uno::Reference< XCollection > xSelectedSheets( new ScVbaWorksheets( this->getParent(), mxContext, xIndexAccess, mxModel ) ); + return uno::makeAny( xSelectedSheets ); + } + return ScVbaWorksheets_BASE::Item( Index, Index2 ); +} + +uno::Any +ScVbaWorksheets::getItemByStringIndex( const rtl::OUString& sIndex ) throw (uno::RuntimeException) +{ + return ScVbaWorksheets_BASE::getItemByStringIndex( sIndex ); +} + +rtl::OUString& +ScVbaWorksheets::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorksheets") ); + return sImplName; +} + +css::uno::Sequence<rtl::OUString> +ScVbaWorksheets::getServiceNames() +{ + static uno::Sequence< rtl::OUString > sNames; + if ( sNames.getLength() == 0 ) + { + sNames.realloc( 1 ); + sNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheets") ); + } + return sNames; +} + +/*static*/ bool ScVbaWorksheets::nameExists( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, const ::rtl::OUString & name, SCTAB& nTab ) throw ( lang::IllegalArgumentException ) +{ + if (!xSpreadDoc.is()) + throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nameExists() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface >(), 1 ); + uno::Reference <container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY ); + if ( xIndex.is() ) + { + SCTAB nCount = static_cast< SCTAB >( xIndex->getCount() ); + for (SCTAB i=0; i < nCount; i++) + { + uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), uno::UNO_QUERY_THROW ); + if (xNamed->getName() == name) + { + nTab = i; + return true; + } + } + } + return false; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbaworksheets.hxx b/sc/source/ui/vba/vbaworksheets.hxx new file mode 100644 index 000000000000..82001c0d77c8 --- /dev/null +++ b/sc/source/ui/vba/vbaworksheets.hxx @@ -0,0 +1,86 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_WORKSHEETS_HXX +#define SC_VBA_WORKSHEETS_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <ooo/vba/excel/XWorksheets.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <vbahelper/vbacollectionimpl.hxx> + +#include "address.hxx" + +class ScModelObj; + + +typedef CollTestImplHelper< ov::excel::XWorksheets > ScVbaWorksheets_BASE; + +class ScVbaWorksheets : public ScVbaWorksheets_BASE +{ + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::sheet::XSpreadsheets > m_xSheets; +protected: + // ScVbaWorksheets_BASE + virtual css::uno::Any getItemByStringIndex( const rtl::OUString& sIndex ) throw (css::uno::RuntimeException); +public: + ScVbaWorksheets( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XIndexAccess >& xSheets, const css::uno::Reference< css::frame::XModel >& xModel ); + ScVbaWorksheets( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > & xContext, const css::uno::Reference< css::container::XEnumerationAccess >& xEnum, const css::uno::Reference< css::frame::XModel >& xModel ); + virtual ~ScVbaWorksheets() {} + + bool isSelectedSheets(); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + + // XWorksheets + virtual css::uno::Any SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( const css::uno::Any& _visible ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Before, const css::uno::Any& After, const css::uno::Any& Count, const css::uno::Any& Type ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL PrintOut( const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName ) throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + virtual void SAL_CALL Select( const css::uno::Any& Replace ) throw (css::uno::RuntimeException); + // ScVbaWorksheets_BASE + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& Index2 ) throw +(css::uno::RuntimeException); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + + static bool nameExists( css::uno::Reference <css::sheet::XSpreadsheetDocument>& xSpreadDoc, const ::rtl::OUString & name, SCTAB& nTab ) throw ( css::lang::IllegalArgumentException ); +}; + +#endif /* SC_VBA_WORKSHEETS_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbawsfunction.cxx b/sc/source/ui/vba/vbawsfunction.cxx new file mode 100644 index 000000000000..b87ec852b9a5 --- /dev/null +++ b/sc/source/ui/vba/vbawsfunction.cxx @@ -0,0 +1,322 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/beans/XIntrospection.hpp> +#include <com/sun/star/beans/XIntrospectionAccess.hpp> +#include <com/sun/star/sheet/XFunctionAccess.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/CellFlags.hpp> +#include <com/sun/star/reflection/XIdlMethod.hpp> +#include <com/sun/star/beans/MethodConcept.hpp> +#include <comphelper/processfactory.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <comphelper/anytostring.hxx> + +#include "vbawsfunction.hxx" +#include "compiler.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +namespace { + +void lclConvertDoubleToBoolean( uno::Any& rAny ) +{ + if( rAny.has< double >() ) + { + double fValue = rAny.get< double >(); + if( fValue == 0.0 ) + rAny <<= false; + else if( fValue == 1.0 ) + rAny <<= true; + // do nothing for other values or types + } +} + +void lclConvertBooleanToDouble( uno::Any& rAny ) +{ + sal_Bool bValue( sal_False ); + if ( rAny >>= bValue ) + { + if ( bValue ) + rAny <<= double( 1.0 ); + else + rAny <<= double( 0.0 ); + } +} + +} // namespace + +ScVbaWSFunction::ScVbaWSFunction( const uno::Reference< XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : + ScVbaWSFunction_BASE( xParent, xContext ) +{ +} + +uno::Reference< beans::XIntrospectionAccess > +ScVbaWSFunction::getIntrospection(void) throw(uno::RuntimeException) +{ + return uno::Reference<beans::XIntrospectionAccess>(); +} + +uno::Any SAL_CALL +ScVbaWSFunction::invoke(const rtl::OUString& FunctionName, const uno::Sequence< uno::Any >& Params, uno::Sequence< sal_Int16 >& /*OutParamIndex*/, uno::Sequence< uno::Any >& /*OutParam*/) throw(lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + // create copy of parameters, replace Excel range objects with UNO range objects + uno::Sequence< uno::Any > aParamTemp( Params ); + if( aParamTemp.hasElements() ) + { + uno::Any* pArray = aParamTemp.getArray(); + uno::Any* pArrayEnd = pArray + aParamTemp.getLength(); + for( ; pArray < pArrayEnd; ++pArray ) + { + switch( pArray->getValueType().getTypeClass() ) + { + case uno::TypeClass_BOOLEAN: + lclConvertBooleanToDouble( *pArray ); + break; + case uno::TypeClass_INTERFACE: + { + uno::Reference< excel::XRange > myRange( *pArray, uno::UNO_QUERY ); + if( myRange.is() ) + *pArray = myRange->getCellRange(); + } + break; + case uno::TypeClass_SEQUENCE: + { + // the sheet.FunctionAccess service doesn't deal with Sequences, only Sequences of Sequence + uno::Type aType = pArray->getValueType(); + if ( aType.equals( getCppuType( (uno::Sequence<sal_Int16>*)0 ) ) ) + { + uno::Sequence< uno::Sequence< sal_Int16 > > aTmp(1); + (*pArray) >>= aTmp[ 0 ]; + (*pArray) <<= aTmp; + } + else if ( aType.equals( getCppuType( (uno::Sequence<sal_Int32>*)0 ) ) ) + { + uno::Sequence< uno::Sequence< sal_Int32 > > aTmp(1); + (*pArray) >>= aTmp[ 0 ]; + (*pArray) <<= aTmp; + } + else if ( aType.equals( getCppuType( (uno::Sequence<double>*)0 ) ) ) + { + uno::Sequence< uno::Sequence< double > > aTmp(1); + (*pArray) >>= aTmp[ 0 ]; + (*pArray) <<= aTmp; + } + else if ( aType.equals( getCppuType( (uno::Sequence<rtl::OUString>*)0 ) ) ) + { + uno::Sequence< uno::Sequence< rtl::OUString > > aTmp(1); + (*pArray) >>= aTmp[ 0 ]; + (*pArray) <<= aTmp; + } + else if ( aType.equals( getCppuType( (uno::Sequence<uno::Any>*)0 ) ) ) + { + uno::Sequence< uno::Sequence<uno::Any > > aTmp(1); + (*pArray) >>= aTmp[ 0 ]; + (*pArray) <<= aTmp; + } + } + break; + default: + break; + } + OSL_TRACE("Param[%d] is %s", (int)(pArray - aParamTemp.getConstArray()), rtl::OUStringToOString( comphelper::anyToString( *pArray ), RTL_TEXTENCODING_UTF8 ).getStr() ); + } + } + + uno::Any aRet; + bool bAsArray = true; + + // special handing for some functions that don't work correctly in FunctionAccess + ScCompiler aCompiler( 0, ScAddress() ); + OpCode eOpCode = aCompiler.GetEnglishOpCode( FunctionName.toAsciiUpperCase() ); + switch( eOpCode ) + { + // ISLOGICAL does not work in array formula mode + case ocIsLogical: + { + if( aParamTemp.getLength() != 1 ) + throw lang::IllegalArgumentException(); + const uno::Any& rParam = aParamTemp[ 0 ]; + if( rParam.has< bool >() ) + { + aRet <<= true; + } + else if( rParam.has< uno::Reference< table::XCellRange > >() ) try + { + uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( rParam, uno::UNO_QUERY_THROW ); + table::CellRangeAddress aRangeAddr = xRangeAddr->getRangeAddress(); + bAsArray = (aRangeAddr.StartColumn != aRangeAddr.EndColumn) || (aRangeAddr.StartRow != aRangeAddr.EndRow); + } + catch( uno::Exception& ) + { + } + } + break; + default:; + } + + if( !aRet.hasValue() ) + { + uno::Reference< lang::XMultiComponentFactory > xSMgr( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + uno::Reference< sheet::XFunctionAccess > xFunctionAccess( xSMgr->createInstanceWithContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.FunctionAccess" ) ), mxContext ), + uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xPropSet( xFunctionAccess, uno::UNO_QUERY_THROW ); + xPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsArrayFunction" ) ), uno::Any( bAsArray ) ); + aRet = xFunctionAccess->callFunction( FunctionName, aParamTemp ); + } + + /* Convert return value from double to to Boolean for some functions that + return Booleans. */ + typedef uno::Sequence< uno::Sequence< uno::Any > > AnySeqSeq; + if( (eOpCode == ocIsEmpty) || (eOpCode == ocIsString) || (eOpCode == ocIsNonString) || (eOpCode == ocIsLogical) || + (eOpCode == ocIsRef) || (eOpCode == ocIsValue) || (eOpCode == ocIsFormula) || (eOpCode == ocIsNA) || + (eOpCode == ocIsErr) || (eOpCode == ocIsError) || (eOpCode == ocIsEven) || (eOpCode == ocIsOdd) || + (eOpCode == ocAnd) || (eOpCode == ocOr) || (eOpCode == ocNot) || (eOpCode == ocTrue) || (eOpCode == ocFalse) ) + { + if( aRet.has< AnySeqSeq >() ) + { + AnySeqSeq aAnySeqSeq = aRet.get< AnySeqSeq >(); + for( sal_Int32 nRow = 0; nRow < aAnySeqSeq.getLength(); ++nRow ) + for( sal_Int32 nCol = 0; nCol < aAnySeqSeq[ nRow ].getLength(); ++nCol ) + lclConvertDoubleToBoolean( aAnySeqSeq[ nRow ][ nCol ] ); + aRet <<= aAnySeqSeq; + } + else + { + lclConvertDoubleToBoolean( aRet ); + } + } + + /* Hack/workaround (?): shorten single-row matrix to simple array, shorten + 1x1 matrix to single value. */ + if( aRet.has< AnySeqSeq >() ) + { + AnySeqSeq aAnySeqSeq = aRet.get< AnySeqSeq >(); + if( aAnySeqSeq.getLength() == 1 ) + { + if( aAnySeqSeq[ 0 ].getLength() == 1 ) + aRet = aAnySeqSeq[ 0 ][ 0 ]; + else + aRet <<= aAnySeqSeq[ 0 ]; + } + } + +#if 0 + // MATCH function should alwayse return a double value, but currently if the first argument is XCellRange, MATCH function returns an array instead of a double value. Don't know why? + // To fix this issue in safe, current solution is to convert this array to a double value just for MATCH function. + String aUpper( FunctionName ); + ScCompiler aCompiler( NULL, ScAddress() ); + OpCode eOp = aCompiler.GetEnglishOpCode( aUpper.ToUpperAscii() ); + if( eOp == ocMatch ) + { + double fVal = 0.0; + if( aRet >>= fVal ) + return aRet; + uno::Sequence< uno::Sequence< uno::Any > > aSequence; + if( !( ( aRet >>= aSequence ) && ( aSequence.getLength() > 0 ) && + ( aSequence[0].getLength() > 0 ) && ( aSequence[0][0] >>= fVal ) ) ) + throw uno::RuntimeException(); + aRet <<= fVal; + } +#endif + + return aRet; +} + +void SAL_CALL +ScVbaWSFunction::setValue(const rtl::OUString& /*PropertyName*/, const uno::Any& /*Value*/) throw(beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + throw beans::UnknownPropertyException(); +} + +uno::Any SAL_CALL +ScVbaWSFunction::getValue(const rtl::OUString& /*PropertyName*/) throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + throw beans::UnknownPropertyException(); +} + +sal_Bool SAL_CALL +ScVbaWSFunction::hasMethod(const rtl::OUString& Name) throw(uno::RuntimeException) +{ + sal_Bool bIsFound = sal_False; + try + { + // the function name contained in the com.sun.star.sheet.FunctionDescription service is alwayse localized. + // but the function name used in WorksheetFunction is a programmatic name (seems English). + // So m_xNameAccess->hasByName( Name ) may fail to find name when a function name has a localized name. + ScCompiler aCompiler( NULL, ScAddress() ); + if( aCompiler.IsEnglishSymbol( Name ) ) + bIsFound = sal_True; + } + catch( uno::Exception& /*e*/ ) + { + // failed to find name + } + return bIsFound; +} + +sal_Bool SAL_CALL +ScVbaWSFunction::hasProperty(const rtl::OUString& /*Name*/) throw(uno::RuntimeException) +{ + return sal_False; +} + +::rtl::OUString SAL_CALL +ScVbaWSFunction::getExactName( const ::rtl::OUString& aApproximateName ) throw (css::uno::RuntimeException) +{ + rtl::OUString sName = aApproximateName.toAsciiUpperCase(); + if ( !hasMethod( sName ) ) + return rtl::OUString(); + return sName; +} + +rtl::OUString& +ScVbaWSFunction::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWSFunction") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaWSFunction::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.WorksheetFunction" ) ); + } + return aServiceNames; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbawsfunction.hxx b/sc/source/ui/vba/vbawsfunction.hxx new file mode 100644 index 000000000000..ff7c68cea6ba --- /dev/null +++ b/sc/source/ui/vba/vbawsfunction.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_INTERIOR_HXX +#define SC_VBA_INTERIOR_HXX + +#include <ooo/vba/excel/XWorksheetFunction.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include "vbarange.hxx" + +#include <com/sun/star/beans/XExactName.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +typedef InheritedHelperInterfaceImpl1< ov::excel::XWorksheetFunction > ScVbaWSFunction_BASE; + +class ScVbaWSFunction : public ScVbaWSFunction_BASE +{ +public: + ScVbaWSFunction( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext); + virtual ~ScVbaWSFunction(){} + + virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection(void) throw(css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL invoke(const rtl::OUString& FunctionName, const css::uno::Sequence< css::uno::Any >& Params, css::uno::Sequence< sal_Int16 >& OutParamIndex, css::uno::Sequence< css::uno::Any >& OutParam) throw(css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual void SAL_CALL setValue(const rtl::OUString& PropertyName, const css::uno::Any& Value) throw(css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue(const rtl::OUString& PropertyName) throw(css::beans::UnknownPropertyException, css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasMethod(const rtl::OUString& Name) throw(css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasProperty(const rtl::OUString& Name) throw(css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getExactName( const ::rtl::OUString& aApproximateName ) throw (css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |