LibreOffice Module vbahelper (master) 1
vbaeventshelperbase.hxx
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#ifndef INCLUDED_VBAHELPER_VBAEVENTSHELPERBASE_HXX
21#define INCLUDED_VBAHELPER_VBAEVENTSHELPERBASE_HXX
22
23#include <deque>
24#include <map>
25#include <unordered_map>
26
27#include <com/sun/star/document/XEventListener.hpp>
28#include <com/sun/star/lang/EventObject.hpp>
29#include <com/sun/star/lang/XServiceInfo.hpp>
30#include <com/sun/star/lang/IllegalArgumentException.hpp>
31#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
32#include <com/sun/star/uno/Any.hxx>
33#include <com/sun/star/uno/Reference.hxx>
34#include <com/sun/star/uno/Sequence.hxx>
35#include <com/sun/star/util/XChangesListener.hpp>
37#include <rtl/ustring.hxx>
38#include <sal/types.h>
39#include <vbahelper/vbadllapi.h>
40
41namespace com::sun::star {
42 namespace document { struct EventObject; }
43 namespace frame { class XModel; }
44 namespace script::vba { class XVBAModuleInfo; }
45 namespace uno { class XComponentContext; }
46 namespace util { struct ChangesEvent; }
47}
48
49class SfxObjectShell;
50
51typedef ::cppu::WeakImplHelper<
52 css::script::vba::XVBAEventProcessor,
53 css::document::XEventListener,
54 css::util::XChangesListener,
55 css::lang::XServiceInfo > VbaEventsHelperBase_BASE;
56
58{
59public:
61 const css::uno::Sequence< css::uno::Any >& rArgs );
62 virtual ~VbaEventsHelperBase() override;
63
64 // script::vba::XVBAEventProcessor
65 virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) override;
66 virtual sal_Bool SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) override;
67
68 // document::XEventListener
69 virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) override;
70
71 // util::XChangesListener
72 virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& rEvent ) override;
73
74 // lang::XEventListener
75 virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) override;
76
77 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
78
79 // little helpers ---------------------------------------------------------
80
81 bool hasModule(const OUString& rModuleName);
82
84 void processVbaEventNoThrow( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs );
85
87 static void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex )
88 { if( (nIndex < 0) || (nIndex >= rArgs.getLength()) ) throw css::lang::IllegalArgumentException(); }
89
91 template< typename Type >
92 static void checkArgumentType( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex )
93 { checkArgument( rArgs, nIndex ); if( !rArgs[ nIndex ].has< Type >() ) throw css::lang::IllegalArgumentException(); }
94
95protected:
96
97
99 {
100 sal_Int32 mnEventId;
101 sal_Int32 mnModuleType;
102 OUString maMacroName;
103 sal_Int32 mnCancelIndex;
104 css::uno::Any maUserData;
105 };
106
114 void registerEventHandler(
115 sal_Int32 nEventId,
116 sal_Int32 nModuleType,
117 const char* pcMacroName,
118 sal_Int32 nCancelIndex = -1,
119 const css::uno::Any& rUserData = css::uno::Any() );
120
121
123 {
124 sal_Int32 mnEventId;
125 css::uno::Sequence< css::uno::Any > maArgs;
126 /*implicit*/ EventQueueEntry( sal_Int32 nEventId ) : mnEventId( nEventId ) {}
127 EventQueueEntry( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) : mnEventId( nEventId ), maArgs( rArgs ) {}
128 };
129 typedef ::std::deque< EventQueueEntry > EventQueue;
130
136 virtual bool implPrepareEvent(
137 EventQueue& rEventQueue,
138 const EventHandlerInfo& rInfo,
139 const css::uno::Sequence< css::uno::Any >& rArgs ) = 0;
140
146 virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList(
147 const EventHandlerInfo& rInfo,
148 const css::uno::Sequence< css::uno::Any >& rArgs ) = 0;
149
156 EventQueue& rEventQueue,
157 const EventHandlerInfo& rInfo,
158 bool bCancel ) = 0;
159
166 const EventHandlerInfo& rInfo,
167 const css::uno::Sequence< css::uno::Any >& rArgs ) const = 0;
168
169private:
170 typedef ::std::map< sal_Int32, OUString > ModulePathMap;
171
173 void startListening();
175 void stopListening();
176
182 const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const;
183
190 OUString getEventHandlerPath(
191 const EventHandlerInfo& rInfo,
192 const css::uno::Sequence< css::uno::Any >& rArgs );
193
198 void ensureVBALibrary();
199
204 sal_Int32 getModuleType( const OUString& rModuleName );
205
210 ModulePathMap& updateModulePathMap( const OUString& rModuleName );
211
212protected:
213 css::uno::Reference< css::frame::XModel > mxModel;
215
216private:
217 typedef std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap;
218 typedef std::unordered_map< OUString, ModulePathMap > EventHandlerPathMap;
219
222 css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos;
225};
226
227
228#endif
229
230/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int16 mnEventId
::std::deque< EventQueueEntry > EventQueue
virtual void implPostProcessEvent(EventQueue &rEventQueue, const EventHandlerInfo &rInfo, bool bCancel)=0
Derived classes may do additional postprocessing.
EventHandlerInfoMap maEventInfos
EventHandlerPathMap maEventPaths
virtual bool implPrepareEvent(EventQueue &rEventQueue, const EventHandlerInfo &rInfo, const css::uno::Sequence< css::uno::Any > &rArgs)=0
Derived classes do additional preparations and return whether the event handler has to be called.
std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap
virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList(const EventHandlerInfo &rInfo, const css::uno::Sequence< css::uno::Any > &rArgs)=0
Derived classes have to return the argument list for the specified VBA event handler.
css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos
std::unordered_map< OUString, ModulePathMap > EventHandlerPathMap
::std::map< sal_Int32, OUString > ModulePathMap
virtual OUString implGetDocumentModuleName(const EventHandlerInfo &rInfo, const css::uno::Sequence< css::uno::Any > &rArgs) const =0
Derived classes have to return the name of the Basic document module.
css::uno::Reference< css::frame::XModel > mxModel
static void checkArgumentType(const css::uno::Sequence< css::uno::Any > &rArgs, sal_Int32 nIndex)
static void checkArgument(const css::uno::Sequence< css::uno::Any > &rArgs, sal_Int32 nIndex)
sal_Int32 nIndex
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const Sequence< PropertyValue > maArgs
css::uno::Sequence< css::uno::Any > maArgs
EventQueueEntry(sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any > &rArgs)
unsigned char sal_Bool
#define VBAHELPER_DLLPUBLIC
Definition: vbadllapi.h:28
::cppu::WeakImplHelper< css::script::vba::XVBAEventProcessor, css::document::XEventListener, css::util::XChangesListener, css::lang::XServiceInfo > VbaEventsHelperBase_BASE