diff options
Diffstat (limited to 'vbahelper')
-rw-r--r-- | vbahelper/inc/vbahelper/msvbahelper.hxx | 55 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbaaccesshelper.hxx | 79 | ||||
-rw-r--r-- | vbahelper/inc/vbahelper/vbahelper.hxx | 14 | ||||
-rw-r--r-- | vbahelper/prj/build.lst | 2 | ||||
-rw-r--r-- | vbahelper/prj/d.lst | 1 | ||||
-rw-r--r-- | vbahelper/source/msforms/makefile.mk | 5 | ||||
-rw-r--r-- | vbahelper/source/msforms/vbacontrol.cxx | 4 | ||||
-rw-r--r-- | vbahelper/source/msforms/vbacontrol.hxx | 1 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/makefile.mk | 6 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/msvbahelper.cxx | 381 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbaapplicationbase.cxx | 2 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbacommandbarcontrol.cxx | 2 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbaglobalbase.cxx | 1 | ||||
-rw-r--r-- | vbahelper/source/vbahelper/vbahelper.cxx | 32 | ||||
-rw-r--r-- | vbahelper/util/makefile.mk | 5 |
15 files changed, 121 insertions, 469 deletions
diff --git a/vbahelper/inc/vbahelper/msvbahelper.hxx b/vbahelper/inc/vbahelper/msvbahelper.hxx deleted file mode 100644 index 898c44c349bc..000000000000 --- a/vbahelper/inc/vbahelper/msvbahelper.hxx +++ /dev/null @@ -1,55 +0,0 @@ -/************************************************************************* - * - * 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 _MSVBAHELPER_HXX -#define _MSVBAHELPER_HXX - -#include <sfx2/objsh.hxx> -#include <vbahelper/vbadllapi.h> - -namespace ooo { namespace vba -{ - class VBAHELPER_DLLPUBLIC VBAMacroResolvedInfo - { - SfxObjectShell* mpDocContext; - bool mbFound; - String msResolvedMacro; - public: - VBAMacroResolvedInfo() : mpDocContext(NULL), mbFound( false ){} - void SetResolved( bool bRes ) { mbFound = bRes; } - bool IsResolved() { return mbFound; } - void SetMacroDocContext(SfxObjectShell* pShell ) { mpDocContext = pShell; } - SfxObjectShell* MacroDocContext() { return mpDocContext; } - String ResolvedMacro() { return msResolvedMacro; } - void SetResolvedMacro(const String& sMacro ) { msResolvedMacro = sMacro; } - }; - - VBAHELPER_DLLPUBLIC String makeMacroURL( const String& sMacroName ); - VBAHELPER_DLLPUBLIC VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& sMod, bool bSearchGlobalTemplates = false ); - VBAHELPER_DLLPUBLIC sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArgs, com::sun::star::uno::Any& aRet, const com::sun::star::uno::Any& aCaller ); -} } - -#endif diff --git a/vbahelper/inc/vbahelper/vbaaccesshelper.hxx b/vbahelper/inc/vbahelper/vbaaccesshelper.hxx new file mode 100644 index 000000000000..79bb44ce30a4 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbaaccesshelper.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * 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: vbahelper.hxx,v $ + * $Revision: 1.5.32.1 $ + * + * 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 OOVBAAPI_VBA_ACCESS_HELPER_HXX +#define OOVBAAPI_VBA_ACCESS_HELPER_HXX + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <basic/basmgr.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> +#define VBAHELPER_DLLIMPLEMENTATION +#include <vbahelper/vbadllapi.h> +#include <memory> +namespace css = ::com::sun::star; +namespace ooo +{ + namespace vba + { + + VBAHELPER_DLLPRIVATE inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell ) + { + css::uno::Any aUnoVar; + if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) ) + throw css::lang::IllegalArgumentException(); + css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW ); + return xVBAFactory; + } + + VBAHELPER_DLLPUBLIC inline css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell, const sal_Char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException) + { + OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); + ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); + css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs ); + return xIf; + } + + + VBAHELPER_DLLPRIVATE inline bool isAlienDoc( SfxObjectShell& rDocShell, const char* pMimeType ) + { + bool bRes( false ); + const SfxFilter *pFilt = rDocShell.GetMedium()->GetFilter(); + if ( pFilt && pFilt->IsAlienFormat() ) + bRes = ( pFilt->GetMimeType().CompareToAscii( pMimeType ) == 0 ); + return bRes; + } + VBAHELPER_DLLPUBLIC inline bool isAlienExcelDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); } + VBAHELPER_DLLPUBLIC inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); } + + } // openoffice +} // org + +#endif diff --git a/vbahelper/inc/vbahelper/vbahelper.hxx b/vbahelper/inc/vbahelper/vbahelper.hxx index 315ddb19b7ca..166ad76475d8 100644 --- a/vbahelper/inc/vbahelper/vbahelper.hxx +++ b/vbahelper/inc/vbahelper/vbahelper.hxx @@ -35,17 +35,19 @@ #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/awt/XControl.hpp> #include <com/sun/star/awt/XDevice.hpp> +#include <basic/basmgr.hxx> #include <basic/sberrors.hxx> #include <cppuhelper/implbase1.hxx> #include <com/sun/star/frame/XModel.hpp> #include <sfx2/dispatch.hxx> -//#include <ooo/vba/msforms/XShape.hpp> +#include <sfx2/objsh.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> #include <vcl/pointr.hxx> -#define VBAHELPER_DLLIMPLEMENTATION -#include <vbahelper/vbadllapi.h> #include <memory> -namespace css = ::com::sun::star; +#include "vbaaccesshelper.hxx" +namespace css = ::com::sun::star; namespace ooo { namespace vba @@ -62,8 +64,10 @@ namespace ooo } VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException); VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException); - VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell, const sal_Char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException); + css::uno::Reference< css::frame::XModel > getCurrentDoc( const rtl::OUString& sKey ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); diff --git a/vbahelper/prj/build.lst b/vbahelper/prj/build.lst index 0db5274b7ad3..20001db859c8 100644 --- a/vbahelper/prj/build.lst +++ b/vbahelper/prj/build.lst @@ -1,4 +1,4 @@ -vba vbahelper : oovbaapi basic sfx2 svx cppuhelper vcl comphelper svtools tools sal NULL +vba vbahelper : oovbaapi basic sfx2 svx filter cppuhelper vcl comphelper svtools tools sal NULL vba vbahelper usr1 - all vba_mkout NULL #vba vbahelper\inc nmake - all vba_inc NULL vba vbahelper\source\vbahelper nmake - all vba_vbahelper NULL diff --git a/vbahelper/prj/d.lst b/vbahelper/prj/d.lst index d7b61d1e5a61..d683e97c8b90 100644 --- a/vbahelper/prj/d.lst +++ b/vbahelper/prj/d.lst @@ -8,6 +8,7 @@ mkdir: %_DEST%\inc%_EXT%\basic ..\inc\vbahelper\vbacollectionimpl.hxx %_DEST%\inc%_EXT%\vbahelper\vbacollectionimpl.hxx ..\inc\vbahelper\vbahelper.hxx %_DEST%\inc%_EXT%\vbahelper\vbahelper.hxx +..\inc\vbahelper\vbaaccesshelper.hxx %_DEST%\inc%_EXT%\vbahelper\vbaaccesshelper.hxx ..\inc\vbahelper\helperdecl.hxx %_DEST%\inc%_EXT%\vbahelper\helperdecl.hxx ..\inc\vbahelper\vbahelperinterface.hxx %_DEST%\inc%_EXT%\vbahelper\vbahelperinterface.hxx ..\inc\vbahelper\vbaapplicationbase.hxx %_DEST%\inc%_EXT%\vbahelper\vbaapplicationbase.hxx diff --git a/vbahelper/source/msforms/makefile.mk b/vbahelper/source/msforms/makefile.mk index 9c24c77f8009..7c61e4302b7f 100644 --- a/vbahelper/source/msforms/makefile.mk +++ b/vbahelper/source/msforms/makefile.mk @@ -34,6 +34,11 @@ VISIBILITY_HIDDEN=TRUE # --- Settings ----------------------------------------------------- +.IF "$(ENABLE_VBA)" == "NO" +dummy: + @echo "Nothing to build" +.ENDIF + .INCLUDE : settings.mk SLOFILES=\ diff --git a/vbahelper/source/msforms/vbacontrol.cxx b/vbahelper/source/msforms/vbacontrol.cxx index 8cf00748c278..2ff12b145824 100644 --- a/vbahelper/source/msforms/vbacontrol.cxx +++ b/vbahelper/source/msforms/vbacontrol.cxx @@ -374,10 +374,6 @@ ScVbaControlFactory::ScVbaControlFactory( const uno::Reference< uno::XComponentC { } -ScVbaControl* ScVbaControlFactory::createControl() throw (uno::RuntimeException) -{ - return createControl( m_xModel ); -} ScVbaControl* ScVbaControlFactory::createControl( const uno::Reference< uno::XInterface >& xParent ) throw (uno::RuntimeException) { uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ); diff --git a/vbahelper/source/msforms/vbacontrol.hxx b/vbahelper/source/msforms/vbacontrol.hxx index b0db3c476186..1a8ed063548b 100644 --- a/vbahelper/source/msforms/vbacontrol.hxx +++ b/vbahelper/source/msforms/vbacontrol.hxx @@ -98,7 +98,6 @@ class ScVbaControlFactory public: ScVbaControlFactory( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel ); - ScVbaControl* createControl() throw ( css::uno::RuntimeException ); ScVbaControl* createControl( const css::uno::Reference< css::uno::XInterface >& xParent ) throw ( css::uno::RuntimeException ); private: ScVbaControl* createControl( const css::uno::Reference< css::awt::XControl >&, const css::uno::Reference< css::uno::XInterface >& ) throw ( css::uno::RuntimeException ); diff --git a/vbahelper/source/vbahelper/makefile.mk b/vbahelper/source/vbahelper/makefile.mk index 88f8f53bd5bf..b11b4ffa0a4f 100644 --- a/vbahelper/source/vbahelper/makefile.mk +++ b/vbahelper/source/vbahelper/makefile.mk @@ -33,10 +33,14 @@ ENABLE_EXCEPTIONS := TRUE VISIBILITY_HIDDEN=TRUE # --- Settings ----------------------------------------------------- +.IF "$(ENABLE_VBA)" == "NO" +dummy: + @echo "Nothing to build" +.ENDIF + .INCLUDE : settings.mk SLOFILES=\ - $(SLO)$/msvbahelper.obj \ $(SLO)$/vbahelper.obj \ $(SLO)$/vbapropvalue.obj \ $(SLO)$/vbacommandbars.obj \ diff --git a/vbahelper/source/vbahelper/msvbahelper.cxx b/vbahelper/source/vbahelper/msvbahelper.cxx deleted file mode 100644 index f0d721529b2c..000000000000 --- a/vbahelper/source/vbahelper/msvbahelper.cxx +++ /dev/null @@ -1,381 +0,0 @@ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#define VBAHELPER_DLLIMPLEMENTATION -#include <vbahelper/msvbahelper.hxx> -#include <basic/sbx.hxx> -#include <basic/sbstar.hxx> -#include <basic/basmgr.hxx> -#include <basic/sbmod.hxx> -#include <basic/sbmeth.hxx> -#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> -#include <com/sun/star/document/XDocumentProperties.hpp> -#include <com/sun/star/document/XDocumentInfoSupplier.hpp> -#include <tools/urlobj.hxx> -#include <osl/file.hxx> - -using namespace ::com::sun::star; - -const static rtl::OUString sUrlPart0 = rtl::OUString::createFromAscii( "vnd.sun.star.script:"); -const static rtl::OUString sUrlPart1 = rtl::OUString::createFromAscii( "?language=Basic&location=document"); - -namespace ooo { namespace vba { - -String makeMacroURL( const String& sMacroName ) -{ - return sUrlPart0.concat( sMacroName ).concat( sUrlPart1 ) ; -} - -SfxObjectShell* findShellForUrl( const rtl::OUString& sMacroURLOrPath ) -{ - SfxObjectShell* pFoundShell=NULL; - SfxObjectShell* pShell = SfxObjectShell::GetFirst(); - INetURLObject aObj; - aObj.SetURL( sMacroURLOrPath ); - bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; - rtl::OUString aURL; - if ( bIsURL ) - aURL = sMacroURLOrPath; - else - { - osl::FileBase::getFileURLFromSystemPath( sMacroURLOrPath, aURL ); - aObj.SetURL( aURL ); - } - OSL_TRACE("Trying to find shell for url %s", rtl::OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() ); - while ( pShell ) - { - - uno::Reference< frame::XModel > xModel = pShell->GetModel(); - // are we searching for a template? if so we have to cater for the - // fact that in openoffice a document opened from a template is always - // a new document :/ - if ( xModel.is() ) - { - OSL_TRACE("shell 0x%x has model with url %s and we look for %s", pShell - , rtl::OUStringToOString( xModel->getURL(), RTL_TEXTENCODING_UTF8 ).getStr() - , rtl::OUStringToOString( aURL, RTL_TEXTENCODING_UTF8 ).getStr() - ); - if ( sMacroURLOrPath.endsWithIgnoreAsciiCaseAsciiL( ".dot", 4 ) ) - { - uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( xModel, uno::UNO_QUERY ); - if( xDocInfoSupp.is() ) - { - uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW ); - uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW ); - rtl::OUString sCurrName = xDocProps->getTemplateName(); - if( sMacroURLOrPath.lastIndexOf( sCurrName ) >= 0 ) - { - pFoundShell = pShell; - break; - } - } - } - else - { - if ( aURL.equals( xModel->getURL() ) ) - { - pFoundShell = pShell; - break; - } - } - } - pShell = SfxObjectShell::GetNext( *pShell ); - } - return pFoundShell; -} - -// sMod can be empty ( but we really need the library to search in ) -// if sMod is empty and a macro is found then sMod is updated -bool hasMacro( SfxObjectShell* pShell, const String& sLibrary, String& sMod, const String& sMacro ) -{ - bool bFound = false; - if ( sLibrary.Len() && sMacro.Len() ) - { - OSL_TRACE("** Searching for %s.%s in library %s" - ,rtl::OUStringToOString( sMod, RTL_TEXTENCODING_UTF8 ).getStr() - ,rtl::OUStringToOString( sMacro, RTL_TEXTENCODING_UTF8 ).getStr() - ,rtl::OUStringToOString( sLibrary, RTL_TEXTENCODING_UTF8 ).getStr() ); - BasicManager* pBasicMgr = pShell-> GetBasicManager(); - if ( pBasicMgr ) - { - StarBASIC* pBasic = pBasicMgr->GetLib( sLibrary ); - if ( !pBasic ) - { - USHORT nId = pBasicMgr->GetLibId( sLibrary ); - pBasicMgr->LoadLib( nId ); - pBasic = pBasicMgr->GetLib( sLibrary ); - } - if ( pBasic ) - { - if ( sMod.Len() ) // we wish to find the macro is a specific module - { - SbModule* pModule = pBasic->FindModule( sMod ); - if ( pModule ) - { - SbxArray* pMethods = pModule->GetMethods(); - if ( pMethods ) - { - SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( sMacro, SbxCLASS_METHOD ) ); - if ( pMethod ) - bFound = true; - } - } - } - else if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sMacro, SbxCLASS_METHOD ) ) ) - { - if( SbModule* pModule = pMethod->GetModule() ) - { - sMod = pModule->GetName(); - bFound = true; - } - } - } - } - } - return bFound; -} -void parseMacro( const rtl::OUString& sMacro, String& sContainer, String& sModule, String& sProcedure ) -{ - sal_Int32 nMacroDot = sMacro.lastIndexOf( '.' ); - - if ( nMacroDot != -1 ) - { - sProcedure = sMacro.copy( nMacroDot + 1 ); - - sal_Int32 nContainerDot = sMacro.lastIndexOf( '.', nMacroDot - 1 ); - if ( nContainerDot != -1 ) - { - sModule = sMacro.copy( nContainerDot + 1, nMacroDot - nContainerDot - 1 ); - sContainer = sMacro.copy( 0, nContainerDot ); - } - else - sModule = sMacro.copy( 0, nMacroDot ); - } - else - sProcedure = sMacro; -} - -VBAMacroResolvedInfo resolveVBAMacro( SfxObjectShell* pShell, const rtl::OUString& MacroName, bool bSearchGlobalTemplates ) -{ - VBAMacroResolvedInfo aRes; - if ( !pShell ) - return aRes; - aRes.SetMacroDocContext( pShell ); - // parse the macro name - sal_Int32 nDocSepIndex = MacroName.indexOfAsciiL( "!", 1 ); - String sMacroUrl = MacroName; - - String sContainer; - String sModule; - String sProcedure; - - if( nDocSepIndex > 0 ) - { - // macro specified by document name - // find document shell for document name and call ourselves - // recursively - - // assume for now that the document name is *this* document - String sDocUrlOrPath = MacroName.copy( 0, nDocSepIndex ); - sMacroUrl = MacroName.copy( nDocSepIndex + 1 ); - OSL_TRACE("doc search, current shell is 0x%x", pShell ); - SfxObjectShell* pFoundShell = findShellForUrl( sDocUrlOrPath ); - OSL_TRACE("doc search, after find, found shell is 0x%x", pFoundShell ); - aRes = resolveVBAMacro( pFoundShell, sMacroUrl ); - } - else - { - // macro is contained in 'this' document ( or code imported from a template - // where that template is a global template or perhaps the template this - // document is created from ) - - // macro format = Container.Module.Procedure - parseMacro( MacroName, sContainer, sModule, sProcedure ); - uno::Reference< lang::XMultiServiceFactory> xSF( pShell->GetModel(), uno::UNO_QUERY); - uno::Reference< container::XNameContainer > xPrjNameCache; - if ( xSF.is() ) - xPrjNameCache.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAProjectNameProvider" ) ) ), uno::UNO_QUERY ); - - std::vector< rtl::OUString > sSearchList; - - if ( sContainer.Len() > 0 ) - { - // get the Project associated with the Container - if ( xPrjNameCache.is() ) - { - if ( xPrjNameCache->hasByName( sContainer ) ) - { - rtl::OUString sProject; - xPrjNameCache->getByName( sContainer ) >>= sProject; - sContainer = sProject; - } - } - sSearchList.push_back( sContainer ); // First Lib to search - } - else - { - // Ok, if we have no Container specified then we need to search them in order, this document, template this document created from, global templates, - // get the name of Project/Library for 'this' document - rtl::OUString sThisProject; - BasicManager* pBasicMgr = pShell-> GetBasicManager(); - if ( pBasicMgr ) - { - if ( pBasicMgr->GetName().Len() ) - sThisProject = pBasicMgr->GetName(); - else // cater for the case where VBA is not enabled - sThisProject = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ); - } - sSearchList.push_back( sThisProject ); // First Lib to search - if ( xPrjNameCache.is() ) - { - // is this document created from a template? - uno::Reference< document::XDocumentInfoSupplier > xDocInfoSupp( pShell->GetModel(), uno::UNO_QUERY_THROW ); - uno::Reference< document::XDocumentPropertiesSupplier > xDocPropSupp( xDocInfoSupp->getDocumentInfo(), uno::UNO_QUERY_THROW ); - uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW ); - - rtl::OUString sCreatedFrom = xDocProps->getTemplateURL(); - if ( sCreatedFrom.getLength() ) - { - INetURLObject aObj; - aObj.SetURL( sCreatedFrom ); - bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; - rtl::OUString aURL; - if ( bIsURL ) - aURL = sCreatedFrom; - else - { - osl::FileBase::getFileURLFromSystemPath( sCreatedFrom, aURL ); - aObj.SetURL( aURL ); - } - sCreatedFrom = aObj.GetLastName(); - } - - sal_Int32 nIndex = sCreatedFrom.lastIndexOf( '.' ); - if ( nIndex != -1 ) - sCreatedFrom = sCreatedFrom.copy( 0, nIndex ); - - rtl::OUString sPrj; - if ( sCreatedFrom.getLength() && xPrjNameCache->hasByName( sCreatedFrom ) ) - { - xPrjNameCache->getByName( sCreatedFrom ) >>= sPrj; - // Make sure we don't double up with this project - if ( !sPrj.equals( sThisProject ) ) - sSearchList.push_back( sPrj ); - } - - // get list of global template Names - uno::Sequence< rtl::OUString > sTemplateNames = xPrjNameCache->getElementNames(); - sal_Int32 nLen = sTemplateNames.getLength(); - for ( sal_Int32 index = 0; ( bSearchGlobalTemplates && index < nLen ); ++index ) - { - - if ( !sCreatedFrom.equals( sTemplateNames[ index ] ) ) - { - if ( xPrjNameCache->hasByName( sTemplateNames[ index ] ) ) - { - xPrjNameCache->getByName( sTemplateNames[ index ] ) >>= sPrj; - // Make sure we don't double up with this project - if ( !sPrj.equals( sThisProject ) ) - sSearchList.push_back( sPrj ); - } - } - - } - } - } - std::vector< rtl::OUString >::iterator it_end = sSearchList.end(); - for ( std::vector< rtl::OUString >::iterator it = sSearchList.begin(); it != it_end; ++it ) - { - bool bRes = hasMacro( pShell, *it, sModule, sProcedure ); - if ( bRes ) - { - aRes.SetResolved( true ); - aRes.SetMacroDocContext( pShell ); - sContainer = *it; - break; - } - } - } - aRes.SetResolvedMacro( sProcedure.Insert( '.', 0 ).Insert( sModule, 0).Insert( '.', 0 ).Insert( sContainer, 0 ) ); - - return aRes; -} - -// Treat the args as possible inouts ( convertion at bottom of method ) -sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& /*aRet*/, const uno::Any& aCaller ) -{ - sal_Bool bRes = sal_False; - if ( !pShell ) - return bRes; - rtl::OUString sUrl = makeMacroURL( sMacroName ); - - uno::Sequence< sal_Int16 > aOutArgsIndex; - uno::Sequence< uno::Any > aOutArgs; - - try - { - uno::Reference< script::provider::XScriptProvider > xScriptProvider; - uno::Reference< script::provider::XScriptProviderSupplier > xSPS( pShell->GetModel(), uno::UNO_QUERY_THROW ); - - xScriptProvider.set( xSPS->getScriptProvider(), uno::UNO_QUERY_THROW ); - - uno::Reference< script::provider::XScript > xScript( xScriptProvider->getScript( sUrl ), uno::UNO_QUERY_THROW ); - - if ( aCaller.hasValue() ) - { - uno::Reference< beans::XPropertySet > xProps( xScript, uno::UNO_QUERY ); - if ( xProps.is() ) - { - uno::Sequence< uno::Any > aCallerHack(1); - aCallerHack[ 0 ] = aCaller; - xProps->setPropertyValue( rtl::OUString::createFromAscii( "Caller" ), uno::makeAny( aCallerHack ) ); - } - } - - - xScript->invoke( aArgs, aOutArgsIndex, aOutArgs ); - - sal_Int32 nLen = aOutArgs.getLength(); - // convert any out params to seem like they were inouts - if ( nLen ) - { - for ( sal_Int32 index=0; index < nLen; ++index ) - { - sal_Int32 nOutIndex = aOutArgsIndex[ index ]; - aArgs[ nOutIndex ] = aOutArgs[ index ]; - } - } - - bRes = sal_True; - } - catch ( uno::Exception& e ) - { - bRes = sal_False; - } - return bRes; -} -} } // vba // ooo diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx index 7f8e563cbab6..54b635d2f08d 100644 --- a/vbahelper/source/vbahelper/vbaapplicationbase.cxx +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -34,7 +34,7 @@ #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> #include "vbacommandbars.hxx" -#include <vbahelper/msvbahelper.hxx> +#include <filter/msfilter/msvbahelper.hxx> // start basic includes #include <basic/sbx.hxx> diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx index e081a723db04..a4bb3adc7dbf 100644 --- a/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx +++ b/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx @@ -27,7 +27,7 @@ #include "vbacommandbarcontrol.hxx" #include "vbacommandbarcontrols.hxx" #include <vbahelper/vbahelper.hxx> -#include <vbahelper/msvbahelper.hxx> +#include <filter/msfilter/msvbahelper.hxx> using namespace com::sun::star; using namespace ooo::vba; diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx index 4226a6bfbf53..c7c33b93b1a3 100644 --- a/vbahelper/source/vbahelper/vbaglobalbase.cxx +++ b/vbahelper/source/vbahelper/vbaglobalbase.cxx @@ -85,7 +85,6 @@ VbaGlobalsBase::createInstanceWithArguments( const ::rtl::OUString& ServiceSpeci { uno::Reference< uno::XInterface > xReturn; - if ( hasServiceName( ServiceSpecifier ) ) xReturn = mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( ServiceSpecifier, Arguments, mxContext ); return xReturn; diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx index a99b3fd47e00..a9e72318536d 100644 --- a/vbahelper/source/vbahelper/vbahelper.cxx +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -98,15 +98,6 @@ namespace ooo namespace vba { -uno::Reference< lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell ) -{ - uno::Any aUnoVar; - if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) ) - throw lang::IllegalArgumentException(); - uno::Reference< lang::XMultiServiceFactory > xVBAFactory( aUnoVar, uno::UNO_QUERY_THROW ); - return xVBAFactory; -} - css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException) { OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); @@ -114,13 +105,6 @@ css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShe return getVBAServiceFactory( pShell )->createInstance( sVarName ); } -css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell, const sal_Char* _pAsciiName, const uno::Sequence< uno::Any >& aArgs ) throw ( css::uno::RuntimeException ) -{ - OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); - ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); - uno::Reference< uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs ); - return xIf; -} // helper method to determine if the view ( calc ) is in print-preview mode bool isInPrintPreview( SfxViewFrame* pView ) { @@ -464,6 +448,18 @@ getCurrentDocCtx( const rtl::OUString& ctxName, const uno::Reference< uno::XComp return xModel; } +uno::Reference< frame::XModel > +getThisExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + return getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext" ) ), xContext ); +} + +uno::Reference< frame::XModel > +getThisWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + return getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext" ) ), xContext ); +} + uno::Reference< frame::XModel > getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) { @@ -475,7 +471,7 @@ getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) t } catch( uno::Exception& e ) { - xModel = getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext" ) ), xContext ); + xModel = getThisExcelDoc( xContext ); } return xModel; } @@ -491,7 +487,7 @@ getCurrentWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) th } catch( uno::Exception& e ) { - xModel = getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext" ) ), xContext ); + xModel = getThisWordDoc( xContext ); } return xModel; } diff --git a/vbahelper/util/makefile.mk b/vbahelper/util/makefile.mk index 98adae420ed9..dda4be0cbc81 100644 --- a/vbahelper/util/makefile.mk +++ b/vbahelper/util/makefile.mk @@ -34,6 +34,10 @@ TARGET=vbahelper .INCLUDE : settings.mk +.IF "$(ENABLE_VBA)" == "NO" +dummy: + @echo "Nothing to build" +.ENDIF TARGET_HELPER=vbahelper @@ -56,6 +60,7 @@ SHL1STDLIBS= \ $(SVLLIB) \ $(VCLLIB) \ $(SVTOOLLIB) \ + $(MSFILTERLIB) \ $(TKLIB) SHL1DEPN= |