/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: vbaglobals.cxx,v $ * $Revision: 1.4 $ * * 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 * * for a copy of the LGPLv3 License. * ************************************************************************/ #include "helperdecl.hxx" #include "vbaglobals.hxx" #include #include #include #include "vbaapplication.hxx" #include "vbaworksheet.hxx" #include "vbarange.hxx" #include 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 ) :m_xContext( rxContext ) { OSL_TRACE("ScVbaGlobals::ScVbaGlobals()"); mxApplication = uno::Reference< excel::XApplication > ( new ScVbaApplication( m_xContext) ); } ScVbaGlobals::~ScVbaGlobals() { OSL_TRACE("ScVbaGlobals::~ScVbaGlobals"); } // Will throw if singleton can't be accessed uno::Reference< XGlobals > ScVbaGlobals::getGlobalsImpl( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException ) { uno::Reference< XGlobals > xGlobals( xContext->getValueByName( ::rtl::OUString::createFromAscii( "/singletons/ooo.vba.theGlobals") ), uno::UNO_QUERY); if ( !xGlobals.is() ) { throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": Couldn't access Globals" ) ), uno::Reference< XInterface >() ); } return xGlobals; } // ============================================================================= // XGlobals // ============================================================================= uno::Reference ScVbaGlobals::getApplication() throw (uno::RuntimeException) { // OSL_TRACE("In ScVbaGlobals::getApplication"); return mxApplication; } uno::Reference< excel::XWorkbook > SAL_CALL ScVbaGlobals::getActiveWorkbook() throw (uno::RuntimeException) { // OSL_TRACE("In ScVbaGlobals::getActiveWorkbook"); uno::Reference< excel::XWorkbook > xWorkbook( mxApplication->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::XWorksheet > SAL_CALL ScVbaGlobals::getActiveSheet() throw (uno::RuntimeException) { return mxApplication->getActiveSheet(); } uno::Any SAL_CALL ScVbaGlobals::WorkBooks( const uno::Any& aIndex ) throw (uno::RuntimeException) { return uno::Any( mxApplication->Workbooks(aIndex) ); } uno::Any SAL_CALL ScVbaGlobals::WorkSheets(const uno::Any& aIndex) throw (uno::RuntimeException) { return mxApplication->Worksheets( aIndex ); } uno::Any SAL_CALL ScVbaGlobals::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException) { return WorkSheets( aIndex ); } ::uno::Sequence< ::uno::Any > SAL_CALL ScVbaGlobals::getGlobals( ) throw (::uno::RuntimeException) { sal_uInt32 nMax = 0; uno::Sequence< uno::Any > maGlobals(4); maGlobals[ nMax++ ] <<= ScVbaGlobals::getGlobalsImpl(m_xContext); maGlobals[ nMax++ ] <<= mxApplication; uno::Reference< excel::XWorkbook > xWorkbook = mxApplication->getActiveWorkbook(); if( xWorkbook.is() ) { maGlobals[ nMax++ ] <<= xWorkbook; uno::Reference< excel::XWorksheet > xWorksheet = xWorkbook->getActiveSheet(); if( xWorksheet.is() ) maGlobals[ nMax++ ] <<= xWorksheet; } maGlobals.realloc( nMax ); return maGlobals; } 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 ); } namespace globals { namespace sdecl = comphelper::service_decl; sdecl::class_ > serviceImpl; extern sdecl::ServiceDecl const serviceDecl( serviceImpl, "ScVbaGlobals", "ooo.vba.Globals" ); }