1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "vbaeventshelper.hxx" 25 #include <com/sun/star/script/ModuleType.hpp> 26 #include <com/sun/star/script/vba/VBAEventId.hpp> 27 #include <vbahelper/helperdecl.hxx> 28 29 using namespace ::com::sun::star; 30 using namespace ::com::sun::star::script::vba::VBAEventId; 31 using namespace ::ooo::vba; 32 33 // ============================================================================ 34 35 SwVbaEventsHelper::SwVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext ) : 36 VbaEventsHelperBase( aArgs, xContext ) 37 { 38 using namespace ::com::sun::star::script::ModuleType; 39 registerEventHandler( DOCUMENT_NEW, DOCUMENT, "Document_New" ); 40 registerEventHandler( AUTO_NEW, NORMAL, "AutoNew" ); 41 registerEventHandler( DOCUMENT_OPEN, DOCUMENT, "Document_Open" ); 42 registerEventHandler( AUTO_OPEN, NORMAL, "AutoOpen" ); 43 registerEventHandler( DOCUMENT_CLOSE, DOCUMENT, "Document_Close" ); 44 registerEventHandler( AUTO_CLOSE, NORMAL, "AutoClose" ); 45 } 46 47 SwVbaEventsHelper::~SwVbaEventsHelper() 48 { 49 } 50 51 bool SwVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, 52 const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& /*rArgs*/ ) throw (uno::RuntimeException) 53 { 54 switch( rInfo.mnEventId ) 55 { 56 case DOCUMENT_NEW: 57 rEventQueue.push_back( AUTO_NEW ); 58 break; 59 case DOCUMENT_OPEN: 60 rEventQueue.push_back( AUTO_OPEN ); 61 break; 62 case DOCUMENT_CLOSE: 63 rEventQueue.push_back( AUTO_CLOSE ); 64 break; 65 } 66 return true; 67 } 68 69 uno::Sequence< uno::Any > SwVbaEventsHelper::implBuildArgumentList( const EventHandlerInfo& /*rInfo*/, 70 const uno::Sequence< uno::Any >& /*rArgs*/ ) throw (lang::IllegalArgumentException) 71 { 72 // no event handler expects any arguments 73 return uno::Sequence< uno::Any >(); 74 } 75 76 void SwVbaEventsHelper::implPostProcessEvent( EventQueue& /*rEventQueue*/, 77 const EventHandlerInfo& /*rInfo*/, bool /*bCancel*/ ) throw (uno::RuntimeException) 78 { 79 // nothing to do after any event 80 } 81 82 ::rtl::OUString SwVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& /*rInfo*/, 83 const uno::Sequence< uno::Any >& /*rArgs*/ ) const throw (lang::IllegalArgumentException) 84 { 85 // TODO: get actual codename from document 86 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisDocument" ) ); 87 } 88 89 // ============================================================================ 90 91 namespace vbaeventshelper 92 { 93 namespace sdecl = comphelper::service_decl; 94 sdecl::class_<SwVbaEventsHelper, sdecl::with_args<true> > serviceImpl; 95 extern sdecl::ServiceDecl const serviceDecl( 96 serviceImpl, 97 "SwVbaEventsHelper", 98 "com.sun.star.document.vba.VBATextEventProcessor" ); 99 } 100 101 // ============================================================================ 102