1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "vbaeventshelper.hxx" 29 #include <com/sun/star/script/ModuleType.hpp> 30 #include <com/sun/star/script/vba/VBAEventId.hpp> 31 #include <vbahelper/helperdecl.hxx> 32 33 using namespace ::com::sun::star; 34 using namespace ::com::sun::star::script::vba::VBAEventId; 35 using namespace ::ooo::vba; 36 37 // ============================================================================ 38 39 SwVbaEventsHelper::SwVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext ) : 40 VbaEventsHelperBase( aArgs, xContext ) 41 { 42 using namespace ::com::sun::star::script::ModuleType; 43 registerEventHandler( DOCUMENT_NEW, DOCUMENT, "Document_New" ); 44 registerEventHandler( AUTO_NEW, NORMAL, "AutoNew" ); 45 registerEventHandler( DOCUMENT_OPEN, DOCUMENT, "Document_Open" ); 46 registerEventHandler( AUTO_OPEN, NORMAL, "AutoOpen" ); 47 registerEventHandler( DOCUMENT_CLOSE, DOCUMENT, "Document_Close" ); 48 registerEventHandler( AUTO_CLOSE, NORMAL, "AutoClose" ); 49 } 50 51 SwVbaEventsHelper::~SwVbaEventsHelper() 52 { 53 } 54 55 bool SwVbaEventsHelper::implPrepareEvent( EventQueue& rEventQueue, 56 const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& /*rArgs*/ ) throw (uno::RuntimeException) 57 { 58 switch( rInfo.mnEventId ) 59 { 60 case DOCUMENT_NEW: 61 rEventQueue.push_back( AUTO_NEW ); 62 break; 63 case DOCUMENT_OPEN: 64 rEventQueue.push_back( AUTO_OPEN ); 65 break; 66 case DOCUMENT_CLOSE: 67 rEventQueue.push_back( AUTO_CLOSE ); 68 break; 69 } 70 return true; 71 } 72 73 uno::Sequence< uno::Any > SwVbaEventsHelper::implBuildArgumentList( const EventHandlerInfo& /*rInfo*/, 74 const uno::Sequence< uno::Any >& /*rArgs*/ ) throw (lang::IllegalArgumentException) 75 { 76 // no event handler expects any arguments 77 return uno::Sequence< uno::Any >(); 78 } 79 80 void SwVbaEventsHelper::implPostProcessEvent( EventQueue& /*rEventQueue*/, 81 const EventHandlerInfo& /*rInfo*/, bool /*bCancel*/ ) throw (uno::RuntimeException) 82 { 83 // nothing to do after any event 84 } 85 86 ::rtl::OUString SwVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& /*rInfo*/, 87 const uno::Sequence< uno::Any >& /*rArgs*/ ) const throw (lang::IllegalArgumentException) 88 { 89 // TODO: get actual codename from document 90 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisDocument" ) ); 91 } 92 93 // ============================================================================ 94 95 namespace vbaeventshelper 96 { 97 namespace sdecl = comphelper::service_decl; 98 sdecl::class_<SwVbaEventsHelper, sdecl::with_args<true> > serviceImpl; 99 extern sdecl::ServiceDecl const serviceDecl( 100 serviceImpl, 101 "SwVbaEventsHelper", 102 "com.sun.star.document.vba.VBATextEventProcessor" ); 103 } 104 105 // ============================================================================ 106