2010-10-27 13:11:31 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-22 16:25:46 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2010-07-06 19:34:53 +02:00
|
|
|
|
2013-10-23 19:18:54 +02:00
|
|
|
#ifndef INCLUDED_VBAHELPER_VBAEVENTSHELPERBASE_HXX
|
|
|
|
#define INCLUDED_VBAHELPER_VBAEVENTSHELPERBASE_HXX
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
#include <deque>
|
2011-03-25 10:40:25 +01:00
|
|
|
#include <map>
|
2015-01-01 19:58:59 +00:00
|
|
|
#include <unordered_map>
|
2011-03-25 10:40:25 +01:00
|
|
|
#include <com/sun/star/document/XEventListener.hpp>
|
|
|
|
#include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
|
|
|
|
#include <com/sun/star/util/XChangesListener.hpp>
|
2015-03-17 12:25:11 +01:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
2013-11-09 15:33:26 -06:00
|
|
|
#include <vbahelper/vbahelper.hxx>
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
namespace com { namespace sun { namespace star {
|
2011-03-25 10:40:25 +01:00
|
|
|
namespace script { namespace vba { class XVBAModuleInfo; } }
|
2010-07-06 19:34:53 +02:00
|
|
|
namespace uno { class XComponentContext; }
|
|
|
|
} } }
|
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2010-07-06 19:34:53 +02:00
|
|
|
|
2015-03-17 12:25:11 +01:00
|
|
|
typedef ::cppu::WeakImplHelper<
|
2011-03-25 10:40:25 +01:00
|
|
|
css::script::vba::XVBAEventProcessor,
|
|
|
|
css::document::XEventListener,
|
2015-03-17 12:25:11 +01:00
|
|
|
css::util::XChangesListener,
|
|
|
|
css::lang::XServiceInfo > VbaEventsHelperBase_BASE;
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
class VBAHELPER_DLLPUBLIC VbaEventsHelperBase : public VbaEventsHelperBase_BASE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
VbaEventsHelperBase(
|
|
|
|
const css::uno::Sequence< css::uno::Any >& rArgs,
|
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& xContext );
|
|
|
|
virtual ~VbaEventsHelperBase();
|
|
|
|
|
2011-03-25 10:40:25 +01:00
|
|
|
// script::vba::XVBAEventProcessor
|
2014-03-27 18:12:18 +01:00
|
|
|
virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
|
|
|
virtual sal_Bool SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::util::VetoException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2010-07-06 19:34:53 +02:00
|
|
|
|
2011-03-25 10:40:25 +01:00
|
|
|
// document::XEventListener
|
2014-03-27 18:12:18 +01:00
|
|
|
virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2011-03-25 10:40:25 +01:00
|
|
|
|
|
|
|
// util::XChangesListener
|
2014-03-27 18:12:18 +01:00
|
|
|
virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& rEvent ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2011-03-25 10:40:25 +01:00
|
|
|
|
|
|
|
// lang::XEventListener
|
2014-03-27 18:12:18 +01:00
|
|
|
virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
2010-07-06 19:34:53 +02:00
|
|
|
|
2015-03-17 12:25:11 +01:00
|
|
|
sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
|
|
|
|
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
|
|
|
|
|
2010-09-15 14:11:13 +02:00
|
|
|
// little helpers ---------------------------------------------------------
|
|
|
|
|
2011-03-25 10:40:25 +01:00
|
|
|
/** Helper to execute event handlers without throwing any exceptions. */
|
|
|
|
void processVbaEventNoThrow( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs );
|
|
|
|
|
2010-09-15 14:11:13 +02:00
|
|
|
/** Throws, if the passed sequence does not contain a value at the specified index. */
|
|
|
|
static inline void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException)
|
|
|
|
{ if( (nIndex < 0) || (nIndex >= rArgs.getLength()) ) throw css::lang::IllegalArgumentException(); }
|
|
|
|
|
|
|
|
/** Throws, if the passed sequence does not contain a value of a specific at the specified index. */
|
|
|
|
template< typename Type >
|
|
|
|
static inline void checkArgumentType( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException)
|
|
|
|
{ checkArgument( rArgs, nIndex ); if( !rArgs[ nIndex ].has< Type >() ) throw css::lang::IllegalArgumentException(); }
|
|
|
|
|
2010-07-06 19:34:53 +02:00
|
|
|
protected:
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
struct EventHandlerInfo
|
|
|
|
{
|
|
|
|
sal_Int32 mnEventId;
|
2011-03-25 10:40:25 +01:00
|
|
|
sal_Int32 mnModuleType;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString maMacroName;
|
2010-07-06 19:34:53 +02:00
|
|
|
sal_Int32 mnCancelIndex;
|
|
|
|
css::uno::Any maUserData;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Registers a supported event handler.
|
|
|
|
|
2010-09-15 14:11:13 +02:00
|
|
|
@param nEventId Event identifier from com.sun.star.script.vba.VBAEventId.
|
2011-03-25 10:40:25 +01:00
|
|
|
@param nModuleType Type of the module containing the event handler.
|
2010-07-06 19:34:53 +02:00
|
|
|
@param pcMacroName Name of the associated VBA event handler macro.
|
|
|
|
@param nCancelIndex 0-based index of Cancel parameter, or -1.
|
|
|
|
@param rUserData User data for free usage in derived implementations. */
|
|
|
|
void registerEventHandler(
|
|
|
|
sal_Int32 nEventId,
|
2011-03-25 10:40:25 +01:00
|
|
|
sal_Int32 nModuleType,
|
2010-07-06 19:34:53 +02:00
|
|
|
const sal_Char* pcMacroName,
|
|
|
|
sal_Int32 nCancelIndex = -1,
|
|
|
|
const css::uno::Any& rUserData = css::uno::Any() );
|
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
struct EventQueueEntry
|
|
|
|
{
|
|
|
|
sal_Int32 mnEventId;
|
|
|
|
css::uno::Sequence< css::uno::Any > maArgs;
|
|
|
|
inline /*implicit*/ EventQueueEntry( sal_Int32 nEventId ) : mnEventId( nEventId ) {}
|
|
|
|
inline EventQueueEntry( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) : mnEventId( nEventId ), maArgs( rArgs ) {}
|
|
|
|
};
|
|
|
|
typedef ::std::deque< EventQueueEntry > EventQueue;
|
|
|
|
|
|
|
|
/** Derived classes do additional prpeparations and return whether the
|
|
|
|
event handler has to be called. */
|
|
|
|
virtual bool implPrepareEvent(
|
|
|
|
EventQueue& rEventQueue,
|
|
|
|
const EventHandlerInfo& rInfo,
|
|
|
|
const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException) = 0;
|
|
|
|
|
|
|
|
/** Derived classes have to return the argument list for the specified VBA event handler. */
|
|
|
|
virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList(
|
|
|
|
const EventHandlerInfo& rInfo,
|
2014-05-27 12:26:48 +02:00
|
|
|
const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException) = 0;
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
/** Derived classes may do additional postprocessing. Called even if the
|
2010-12-04 13:16:21 +09:00
|
|
|
event handler does not exist, or if an error occurred during execution. */
|
2010-07-06 19:34:53 +02:00
|
|
|
virtual void implPostProcessEvent(
|
|
|
|
EventQueue& rEventQueue,
|
|
|
|
const EventHandlerInfo& rInfo,
|
|
|
|
bool bCancel ) throw (css::uno::RuntimeException) = 0;
|
|
|
|
|
|
|
|
/** Derived classes have to return the name of the Basic document module. */
|
2013-04-07 12:06:47 +02:00
|
|
|
virtual OUString implGetDocumentModuleName(
|
2010-07-06 19:34:53 +02:00
|
|
|
const EventHandlerInfo& rInfo,
|
2014-06-02 15:25:11 +01:00
|
|
|
const css::uno::Sequence< css::uno::Any >& rArgs ) const
|
|
|
|
throw (css::lang::IllegalArgumentException,
|
|
|
|
css::uno::RuntimeException) = 0;
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
private:
|
2013-04-07 12:06:47 +02:00
|
|
|
typedef ::std::map< sal_Int32, OUString > ModulePathMap;
|
2011-03-25 10:40:25 +01:00
|
|
|
|
|
|
|
/** Starts listening at the document model. */
|
|
|
|
void startListening();
|
|
|
|
/** Stops listening at the document model. */
|
|
|
|
void stopListening();
|
|
|
|
|
2010-07-06 19:34:53 +02:00
|
|
|
/** Returns the event handler info struct for the specified event, or throws. */
|
|
|
|
const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const throw (css::lang::IllegalArgumentException);
|
|
|
|
|
|
|
|
/** Searches the event handler in the document and returns its full script path. */
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString getEventHandlerPath(
|
2010-07-06 19:34:53 +02:00
|
|
|
const EventHandlerInfo& rInfo,
|
2011-03-25 10:40:25 +01:00
|
|
|
const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException);
|
2010-07-06 19:34:53 +02:00
|
|
|
|
2011-03-25 10:40:25 +01:00
|
|
|
/** On first call, accesses the Basic library containing the VBA source code. */
|
|
|
|
void ensureVBALibrary() throw (css::uno::RuntimeException);
|
|
|
|
|
|
|
|
/** Returns the type of the Basic module with the specified name. */
|
2013-04-07 12:06:47 +02:00
|
|
|
sal_Int32 getModuleType( const OUString& rModuleName ) throw (css::uno::RuntimeException);
|
2011-03-25 10:40:25 +01:00
|
|
|
|
|
|
|
/** Updates the map containing paths to event handlers for a Basic module. */
|
2015-06-27 17:08:20 +01:00
|
|
|
ModulePathMap& updateModulePathMap( const OUString& rModuleName ) throw (css::uno::RuntimeException, std::exception);
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
css::uno::Reference< css::frame::XModel > mxModel;
|
|
|
|
SfxObjectShell* mpShell;
|
|
|
|
|
|
|
|
private:
|
2015-01-01 19:58:59 +00:00
|
|
|
typedef std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap;
|
|
|
|
typedef std::unordered_map< OUString, ModulePathMap, OUStringHash > EventHandlerPathMap;
|
2010-07-06 19:34:53 +02:00
|
|
|
|
2011-03-25 10:40:25 +01:00
|
|
|
EventHandlerInfoMap maEventInfos;
|
|
|
|
EventHandlerPathMap maEventPaths;
|
|
|
|
css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos;
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString maLibraryName;
|
2010-07-06 19:34:53 +02:00
|
|
|
bool mbDisposed;
|
|
|
|
};
|
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2010-07-06 19:34:53 +02:00
|
|
|
|
|
|
|
#endif
|
2010-10-27 13:11:31 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|