diff options
author | Daniel Rentz <dr@openoffice.org> | 2010-07-06 19:34:53 +0200 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2010-07-06 19:34:53 +0200 |
commit | fc135411fa926f4d89e98378d113f597af79e2a2 (patch) | |
tree | d784551b777156395753db4c683af9dabacfe6f6 /sw | |
parent | 3ffd1ec05a64175f404aad0b9e92b2906070c7bd (diff) |
mib17: #i112634# add VBA sheet event handling, based on a patch from Noel Power
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/doc.hxx | 11 | ||||
-rw-r--r--[-rwxr-xr-x] | sw/source/core/doc/doc.cxx | 24 | ||||
-rwxr-xr-x | sw/source/filter/ww8/wrtww8.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/app/docsh2.cxx | 44 | ||||
-rw-r--r-- | sw/source/ui/vba/makefile.mk | 1 | ||||
-rw-r--r-- | sw/source/ui/vba/service.cxx | 9 | ||||
-rwxr-xr-x | sw/source/ui/vba/vbaeventshelper.cxx | 108 | ||||
-rwxr-xr-x | sw/source/ui/vba/vbaeventshelper.hxx | 54 | ||||
-rw-r--r-- | sw/util/makefile.mk | 2 |
9 files changed, 248 insertions, 7 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 10befb703b96..ff6a1f97709e 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -79,6 +79,9 @@ class SwList; #include "comphelper/implementationreference.hxx" #include <com/sun/star/chart2/data/XDataProvider.hpp> #include <com/sun/star/linguistic2/XProofreadingIterator.hpp> +#ifdef FUTURE_VBA +#include <com/sun/star/script/vba/XEventProcessor.hpp> +#endif #include <hash_map> #include <stringhash.hxx> @@ -405,7 +408,9 @@ class SW_DLLPUBLIC SwDoc : // table of forbidden characters of this document vos::ORef<SvxForbiddenCharactersTable> xForbiddenCharsTable; - +#ifdef FUTURE_VBA + com::sun::star::uno::Reference< com::sun::star::script::vba::XEventProcessor > mxVbaEvents; +#endif // --> OD 2007-10-26 #i83479# public: struct lessThanNodeNum @@ -2128,7 +2133,9 @@ public: { return n32DummyCompatabilityOptions2; } - +#ifdef FUTURE_VBA + com::sun::star::uno::Reference< com::sun::star::script::vba::XEventProcessor > GetVbaEventProcessor(); +#endif ::sfx2::IXmlIdRegistry& GetXmlIdRegistry(); ::sw::MetaFieldManager & GetMetaFieldManager(); SfxObjectShell* CreateCopy(bool bCallInitNew) const; diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx index f1ae3e241b1b..6979d13fbb62 100755..100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -119,6 +119,9 @@ #include <osl/diagnose.h> #include <osl/interlck.h> +#ifdef FUTURE_VBA +#include <vbahelper/vbaaccesshelper.hxx> +#endif /* @@@MAINTAINABILITY-HORROR@@@ Probably unwanted dependency on SwDocShell @@ -2721,6 +2724,27 @@ void SwDoc::ChkCondColls() } } +#ifdef FUTURE_VBA +uno::Reference< script::vba::XEventProcessor > +SwDoc::GetVbaEventProcessor() +{ + if( !mxVbaEvents.is() && pDocShell && ooo::vba::isAlienWordDoc( *pDocShell ) ) + { + try + { + uno::Reference< frame::XModel > xModel( pDocShell->GetModel(), uno::UNO_SET_THROW ); + uno::Sequence< uno::Any > aArgs(1); + aArgs[0] <<= xModel; + mxVbaEvents.set( ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.TextEventProcessor" , aArgs ), uno::UNO_QUERY_THROW ); + } + catch( uno::Exception& ) + { + } + } + return mxVbaEvents; +} +#endif + void SwDoc::setExternalData(::sw::tExternalDataType eType, ::sw::tExternalDataPointer pPayload) { diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 2e992335598e..253957dac35b 100755 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3788,9 +3788,11 @@ void WW8AttributeOutput::TableNodeInfoInner( ww8::WW8TableNodeInfoInner::Pointer void MSWordExportBase::OutputStartNode( const SwStartNode & rNode) { +#if 0 #ifdef DEBUG ::std::clog << "<OutWW8_SwStartNode>" << dbg_out(&rNode) << ::std::endl; #endif +#endif ww8::WW8TableNodeInfo::Pointer_t pNodeInfo = mpTableInfo->getTableNodeInfo( &rNode ); diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx index 9cb3caffa7cc..501c070e6d6b 100644 --- a/sw/source/ui/app/docsh2.cxx +++ b/sw/source/ui/app/docsh2.cxx @@ -119,7 +119,10 @@ #include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> #include "com/sun/star/ui/dialogs/TemplateDescription.hpp" - +#ifdef FUTURE_VBA +#include <com/sun/star/script/vba/XEventProcessor.hpp> +#include <com/sun/star/script/vba/EventIdentifier.hpp> +#endif #include <editeng/acorrcfg.hxx> #include <SwStyleNameMapper.hxx> @@ -137,7 +140,6 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star; using ::rtl::OUString; using namespace ::sfx2; - extern BOOL FindPhyStyle( SwDoc& , const String& , SfxStyleFamily ); /*-------------------------------------------------------------------- @@ -188,6 +190,26 @@ void SwDocShell::DoFlushDocInfo() } } +#ifdef FUTURE_VBA +void lcl_processCompatibleSfxHint( const uno::Reference< script::vba::XEventProcessor >& xVbaEvents, const SfxHint& rHint ) +{ + using namespace com::sun::star::script::vba::EventIdentifier; + if ( rHint.ISA( SfxEventHint ) ) + { + uno::Sequence< uno::Any > aArgs; + ULONG nEventId = ((SfxEventHint&)rHint).GetEventId(); + switch( nEventId ) + { + case SFX_EVENT_CREATEDOC: + xVbaEvents->processVbaEvent( DOCUMENT_NEW, aArgs ); + break; + case SFX_EVENT_OPENDOC: + xVbaEvents->processVbaEvent( DOCUMENT_OPEN, aArgs ); + break; + } + } +} +#endif /*-------------------------------------------------------------------- Beschreibung: Benachrichtigung bei geaenderter DocInfo @@ -202,6 +224,12 @@ void SwDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) return ; } +#ifdef FUTURE_VBA + uno::Reference< script::vba::XEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); + if( xVbaEvents.is() ) + lcl_processCompatibleSfxHint( xVbaEvents, rHint ); +#endif + USHORT nAction = 0; if( rHint.ISA(SfxSimpleHint) ) { @@ -283,6 +311,18 @@ USHORT SwDocShell::PrepareClose( BOOL bUI, BOOL bForBrowsing ) if( TRUE == nRet ) //Unbedingt auf TRUE abfragen! (RET_NEWTASK) EndListening( *this ); +#ifdef FUTURE_VBA + if( pDoc && IsInPrepareClose() ) + { + uno::Reference< script::vba::XEventProcessor > xVbaEvents = pDoc->GetVbaEventProcessor(); + if( xVbaEvents.is() ) + { + using namespace com::sun::star::script::vba::EventIdentifier; + uno::Sequence< uno::Any > aArgs; + xVbaEvents->processVbaEvent( DOCUMENT_CLOSE, aArgs ); + } + } +#endif return nRet; } diff --git a/sw/source/ui/vba/makefile.mk b/sw/source/ui/vba/makefile.mk index c09f81320040..b6d0d7994295 100644 --- a/sw/source/ui/vba/makefile.mk +++ b/sw/source/ui/vba/makefile.mk @@ -91,6 +91,7 @@ SLOFILES= \ $(SLO)$/vbapagesetup.obj \ $(SLO)$/vbasection.obj \ $(SLO)$/vbasections.obj \ + $(SLO)$/vbaeventshelper.obj \ # --- Targets ------------------------------------------------------ diff --git a/sw/source/ui/vba/service.cxx b/sw/source/ui/vba/service.cxx index c21e8de37b5e..9f9cbff204dd 100644 --- a/sw/source/ui/vba/service.cxx +++ b/sw/source/ui/vba/service.cxx @@ -52,6 +52,11 @@ namespace wrapformat extern sdecl::ServiceDecl const serviceDecl; } +namespace vbaeventshelper +{ +extern sdecl::ServiceDecl const serviceDecl; +} + extern "C" { void SAL_CALL component_getImplementationEnvironment( @@ -68,7 +73,7 @@ extern "C" // Component registration return component_writeInfoHelper( pServiceManager, pRegistryKey, - globals::serviceDecl, document::serviceDecl, wrapformat::serviceDecl ); + globals::serviceDecl, document::serviceDecl, wrapformat::serviceDecl, vbaeventshelper::serviceDecl ); } void * SAL_CALL component_getFactory( @@ -77,7 +82,7 @@ extern "C" { OSL_TRACE("In component_getFactory for %s", pImplName ); void* pRet = component_getFactoryHelper( - pImplName, pServiceManager, pRegistryKey, globals::serviceDecl, document::serviceDecl, wrapformat::serviceDecl ); + pImplName, pServiceManager, pRegistryKey, globals::serviceDecl, document::serviceDecl, wrapformat::serviceDecl, vbaeventshelper::serviceDecl ); OSL_TRACE("Ret is 0x%x", pRet); return pRet; } diff --git a/sw/source/ui/vba/vbaeventshelper.cxx b/sw/source/ui/vba/vbaeventshelper.cxx new file mode 100755 index 000000000000..66d72315987e --- /dev/null +++ b/sw/source/ui/vba/vbaeventshelper.cxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * 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/script/vba/EventIdentifier.hpp> +#include <vbahelper/helperdecl.hxx> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::script::vba::EventIdentifier; +using namespace ::ooo::vba; + +// ============================================================================ + +SwVbaEventsHelper::SwVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext ) : + VbaEventsHelperBase( aArgs, xContext ) +{ + registerEventHandler( DOCUMENT_NEW, "Document_New", EVENTHANDLER_DOCUMENT ); + registerEventHandler( AUTO_NEW, "AutoNew", EVENTHANDLER_GLOBAL ); + registerEventHandler( DOCUMENT_OPEN, "Document_Open", EVENTHANDLER_DOCUMENT ); + registerEventHandler( AUTO_OPEN, "AutoOpen", EVENTHANDLER_GLOBAL ); + registerEventHandler( DOCUMENT_CLOSE, "Document_Close", EVENTHANDLER_DOCUMENT ); + registerEventHandler( AUTO_CLOSE, "AutoClose", EVENTHANDLER_GLOBAL ); +} + +SwVbaEventsHelper::~SwVbaEventsHelper() +{ +} + +bool SwVbaEventsHelper::implEventsEnabled() throw (uno::RuntimeException) +{ + return true; +} + +bool SwVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& /*rArgs*/ ) throw (uno::RuntimeException) +{ + switch( rInfo.mnEventId ) + { + case DOCUMENT_NEW: + rEventQueue.push_back( AUTO_NEW ); + break; + case DOCUMENT_OPEN: + rEventQueue.push_back( AUTO_OPEN ); + break; + case DOCUMENT_CLOSE: + rEventQueue.push_back( AUTO_CLOSE ); + break; + } + return true; +} + +uno::Sequence< uno::Any > SwVbaEventsHelper::implBuildArgumentList( const EventHandlerInfo& /*rInfo*/, + const uno::Sequence< uno::Any >& /*rArgs*/ ) throw (lang::IllegalArgumentException) +{ + // no event handler expects any arguments + return uno::Sequence< uno::Any >(); +} + +void SwVbaEventsHelper::implPostProcessEvent( EventQueue& /*rEventQueue*/, + const EventHandlerInfo& /*rInfo*/, bool /*bSuccess*/, bool /*bCancel*/ ) throw (uno::RuntimeException) +{ + // nothing to do after any event +} + +::rtl::OUString SwVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& /*rInfo*/, + const uno::Sequence< uno::Any >& /*rArgs*/ ) const throw (lang::IllegalArgumentException) +{ + // TODO: get actual codename from document + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisDocument" ) ); +} + +// ============================================================================ + +namespace vbaeventshelper +{ +namespace sdecl = comphelper::service_decl; +sdecl::class_<SwVbaEventsHelper, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "SwVbaEventsHelper", + "com.sun.star.document.vba.TextEventProcessor" ); +} + +// ============================================================================ diff --git a/sw/source/ui/vba/vbaeventshelper.hxx b/sw/source/ui/vba/vbaeventshelper.hxx new file mode 100755 index 000000000000..af1c06c0341f --- /dev/null +++ b/sw/source/ui/vba/vbaeventshelper.hxx @@ -0,0 +1,54 @@ +/************************************************************************* + * + * 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 SW_VBAEVENTS_HXX +#define SW_VBAEVENTS_HXX + +#include <vbahelper/vbaeventshelperbase.hxx> + +// ============================================================================ + +class SwVbaEventsHelper : public VbaEventsHelperBase +{ +public: + SwVbaEventsHelper( + const css::uno::Sequence< css::uno::Any >& rArgs, + const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + virtual ~SwVbaEventsHelper(); + +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); +}; + +// ============================================================================ + +#endif + diff --git a/sw/util/makefile.mk b/sw/util/makefile.mk index 2907264d89cf..ce1419b34065 100644 --- a/sw/util/makefile.mk +++ b/sw/util/makefile.mk @@ -367,7 +367,7 @@ SHL5STDLIBS= \ $(I18NISOLANGLIB) \ $(EDITENGLIB) \ $(SVXCORELIB) \ - $(SVXMSFILTERLIB) + $(MSFILTERLIB) SHL5DEPN=$(SHL1TARGETN) SHL5LIBS=$(SLB)$/$(TARGET_VBA).lib |