LibreOffice Module sw (master)  1
vbaeventshelper.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include "vbaeventshelper.hxx"
23 #include <com/sun/star/script/ModuleType.hpp>
24 #include <com/sun/star/script/vba/VBAEventId.hpp>
26 
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::script::vba::VBAEventId;
29 
30 SwVbaEventsHelper::SwVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& /*xContext*/ ) :
31  VbaEventsHelperBase( aArgs )
32 {
33  using namespace ::com::sun::star::script::ModuleType;
34  registerEventHandler( DOCUMENT_NEW, DOCUMENT, "Document_New" );
35  registerEventHandler( AUTO_NEW, NORMAL, "AutoNew" );
36  registerEventHandler( DOCUMENT_OPEN, DOCUMENT, "Document_Open" );
37  registerEventHandler( AUTO_OPEN, NORMAL, "AutoOpen" );
38  registerEventHandler( DOCUMENT_CLOSE, DOCUMENT, "Document_Close" );
39  registerEventHandler( AUTO_CLOSE, NORMAL, "AutoClose" );
40 }
41 
43 {
44 }
45 
47  const EventHandlerInfo& rInfo, const uno::Sequence< uno::Any >& /*rArgs*/ )
48 {
49  switch( rInfo.mnEventId )
50  {
51  case DOCUMENT_NEW:
52  rEventQueue.emplace_back(AUTO_NEW );
53  break;
54  case DOCUMENT_OPEN:
55  rEventQueue.emplace_back(AUTO_OPEN );
56  break;
57  case DOCUMENT_CLOSE:
58  rEventQueue.emplace_back(AUTO_CLOSE );
59  break;
60  }
61  return true;
62 }
63 
64 uno::Sequence< uno::Any > SwVbaEventsHelper::implBuildArgumentList( const EventHandlerInfo& /*rInfo*/,
65  const uno::Sequence< uno::Any >& /*rArgs*/ )
66 {
67  // no event handler expects any arguments
68  return uno::Sequence< uno::Any >();
69 }
70 
72  const EventHandlerInfo& /*rInfo*/, bool /*bCancel*/ )
73 {
74  // nothing to do after any event
75 }
76 
77 OUString SwVbaEventsHelper::implGetDocumentModuleName( const EventHandlerInfo& /*rInfo*/,
78  const uno::Sequence< uno::Any >& /*rArgs*/ ) const
79 {
80  // TODO: get actual codename from document
81  return "ThisDocument";
82 }
83 
84  // XServiceInfo
86 {
87  return "SwVbaEventsHelper";
88 }
89 sal_Bool SwVbaEventsHelper::supportsService( const OUString& ServiceName )
90 {
91  return cppu::supportsService(this, ServiceName);
92 }
93 css::uno::Sequence< OUString > SwVbaEventsHelper::getSupportedServiceNames()
94 {
95  return { "com.sun.star.document.vba.VBATextEventProcessor" };
96 }
97 
98 
99 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
101  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
102 {
103  return cppu::acquire(new SwVbaEventsHelper(args, context));
104 }
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~SwVbaEventsHelper() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
virtual void implPostProcessEvent(EventQueue &rEventQueue, const EventHandlerInfo &rInfo, bool bCancel) override
DOCUMENT
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList(const EventHandlerInfo &rInfo, const css::uno::Sequence< css::uno::Any > &rArgs) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Writer_SwVbaEventsHelper_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
unsigned char sal_Bool
SwVbaEventsHelper(const css::uno::Sequence< css::uno::Any > &rArgs, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
NORMAL
virtual OUString implGetDocumentModuleName(const EventHandlerInfo &rInfo, const css::uno::Sequence< css::uno::Any > &rArgs) const override
void registerEventHandler(sal_Int32 nEventId, sal_Int32 nModuleType, const char *pcMacroName, sal_Int32 nCancelIndex=-1, const css::uno::Any &rUserData=css::uno::Any())
::std::deque< EventQueueEntry > EventQueue
virtual bool implPrepareEvent(EventQueue &rEventQueue, const EventHandlerInfo &rInfo, const css::uno::Sequence< css::uno::Any > &rArgs) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override