summaryrefslogtreecommitdiff
path: root/sw/source/ui/vba
diff options
context:
space:
mode:
authorDaniel Rentz <dr@openoffice.org>2010-07-06 19:34:53 +0200
committerDaniel Rentz <dr@openoffice.org>2010-07-06 19:34:53 +0200
commitfc135411fa926f4d89e98378d113f597af79e2a2 (patch)
treed784551b777156395753db4c683af9dabacfe6f6 /sw/source/ui/vba
parent3ffd1ec05a64175f404aad0b9e92b2906070c7bd (diff)
mib17: #i112634# add VBA sheet event handling, based on a patch from Noel Power
Diffstat (limited to 'sw/source/ui/vba')
-rw-r--r--sw/source/ui/vba/makefile.mk1
-rw-r--r--sw/source/ui/vba/service.cxx9
-rwxr-xr-xsw/source/ui/vba/vbaeventshelper.cxx108
-rwxr-xr-xsw/source/ui/vba/vbaeventshelper.hxx54
4 files changed, 170 insertions, 2 deletions
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
+