2010-10-27 13:03:58 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-07-16 17:32:30 +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-04-14 17:31:33 +02:00
|
|
|
|
2013-10-23 19:17:28 +02:00
|
|
|
#ifndef INCLUDED_OOX_OLE_VBAPROJECT_HXX
|
|
|
|
#define INCLUDED_OOX_OLE_VBAPROJECT_HXX
|
2010-04-14 17:31:33 +02:00
|
|
|
|
2016-05-11 22:02:58 -07:00
|
|
|
#include <functional>
|
2010-11-02 15:59:53 +00:00
|
|
|
#include <map>
|
2016-05-11 22:02:58 -07:00
|
|
|
|
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
2013-11-09 14:10:44 -06:00
|
|
|
#include <oox/dllapi.h>
|
2016-05-11 22:02:58 -07:00
|
|
|
#include <oox/helper/refmap.hxx>
|
|
|
|
#include <oox/helper/refvector.hxx>
|
|
|
|
#include <rtl/ustring.hxx>
|
|
|
|
#include <sal/types.h>
|
2010-04-14 17:31:33 +02:00
|
|
|
|
|
|
|
namespace com { namespace sun { namespace star {
|
|
|
|
namespace container { class XNameContainer; }
|
|
|
|
namespace frame { class XModel; }
|
|
|
|
namespace script { class XLibraryContainer; }
|
2010-08-26 18:37:44 +02:00
|
|
|
namespace script { namespace vba { class XVBAMacroResolver; } }
|
2010-08-30 16:10:01 +02:00
|
|
|
namespace uno { class XComponentContext; }
|
2016-05-11 22:02:58 -07:00
|
|
|
namespace uno { class XInterface; }
|
2010-04-14 17:31:33 +02:00
|
|
|
} } }
|
|
|
|
|
2016-05-11 22:02:58 -07:00
|
|
|
namespace oox {
|
|
|
|
class GraphicHelper;
|
|
|
|
class StorageBase;
|
|
|
|
}
|
2010-04-14 17:31:33 +02:00
|
|
|
|
|
|
|
namespace oox {
|
|
|
|
namespace ole {
|
|
|
|
|
2016-05-11 22:02:58 -07:00
|
|
|
class VbaModule;
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2012-03-16 12:28:31 +00:00
|
|
|
class OOX_DLLPUBLIC VbaFilterConfig
|
2010-04-14 17:31:33 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit VbaFilterConfig(
|
2015-10-22 16:38:52 +02:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rConfigCompName );
|
2010-04-14 17:31:33 +02:00
|
|
|
~VbaFilterConfig();
|
|
|
|
|
|
|
|
/** Returns true, if the VBA source code and forms should be imported. */
|
|
|
|
bool isImportVba() const;
|
|
|
|
/** Returns true, if the VBA source code should be imported executable. */
|
|
|
|
bool isImportVbaExecutable() const;
|
|
|
|
/** Returns true, if the VBA source code and forms should be exported. */
|
|
|
|
bool isExportVba() const;
|
|
|
|
|
|
|
|
private:
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::uno::XInterface >
|
2010-04-14 17:31:33 +02:00
|
|
|
mxConfigAccess;
|
|
|
|
};
|
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2015-06-15 19:44:53 +02:00
|
|
|
/** Base class for objects that attach a macro to a specific action.
|
2010-08-26 18:37:44 +02:00
|
|
|
|
|
|
|
Purpose is to collect objects that need to attach a VBA macro to an action.
|
|
|
|
The VBA project will be loaded at a very late point of the document import
|
|
|
|
process, because it depends on an initialized core document model (e.g.
|
|
|
|
spreadsheet codenames). Some objects that want to attach a VBA macro to an
|
|
|
|
action (e.g. mouse click action for drawing shapes) are loaded long before
|
|
|
|
the VBA project. The drawback is that in most cases macros are specified
|
|
|
|
without module name, or the VBA project name is part of the macro name.
|
|
|
|
In the former case, all code modules have to be scanned for the macro to be
|
|
|
|
able to create a valid script URL.
|
|
|
|
|
|
|
|
The import code will register these requests to attach a VBA macro with an
|
|
|
|
instance of a class derived from this base class. The derived class will
|
|
|
|
store all information needed to finally attach the macro to the action,
|
|
|
|
once the VBA project has been imported.
|
|
|
|
*/
|
2012-03-16 12:28:31 +00:00
|
|
|
class OOX_DLLPUBLIC VbaMacroAttacherBase
|
2010-08-26 18:37:44 +02:00
|
|
|
{
|
|
|
|
public:
|
2013-04-07 12:06:47 +02:00
|
|
|
explicit VbaMacroAttacherBase( const OUString& rMacroName );
|
2010-08-26 18:37:44 +02:00
|
|
|
virtual ~VbaMacroAttacherBase();
|
|
|
|
|
|
|
|
/** Resolves the internal macro name to the related macro URL, and attaches
|
|
|
|
the macro to the object. */
|
|
|
|
void resolveAndAttachMacro(
|
2015-10-22 16:38:52 +02:00
|
|
|
const css::uno::Reference< css::script::vba::XVBAMacroResolver >& rxResolver );
|
2010-08-26 18:37:44 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
/** Called after the VBA project has been imported. Derived classes will
|
|
|
|
attach the passed script to the object represented by this instance. */
|
2013-04-07 12:06:47 +02:00
|
|
|
virtual void attachMacro( const OUString& rScriptUrl ) = 0;
|
2010-08-26 18:37:44 +02:00
|
|
|
|
|
|
|
private:
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString maMacroName;
|
2010-08-26 18:37:44 +02:00
|
|
|
};
|
|
|
|
|
2015-02-19 08:40:27 +00:00
|
|
|
typedef std::shared_ptr< VbaMacroAttacherBase > VbaMacroAttacherRef;
|
2010-08-26 18:37:44 +02:00
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2011-03-02 11:20:45 +00:00
|
|
|
class OOX_DLLPUBLIC VbaProject : public VbaFilterConfig
|
2010-04-14 17:31:33 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit VbaProject(
|
2015-10-22 16:38:52 +02:00
|
|
|
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
|
|
|
|
const css::uno::Reference< css::frame::XModel >& rxDocModel,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& rConfigCompName );
|
2010-04-14 17:31:33 +02:00
|
|
|
virtual ~VbaProject();
|
|
|
|
|
|
|
|
/** Imports the entire VBA project from the passed storage.
|
|
|
|
|
|
|
|
@param rVbaPrjStrg The root storage of the entire VBA project.
|
|
|
|
*/
|
|
|
|
void importVbaProject(
|
|
|
|
StorageBase& rVbaPrjStrg,
|
2016-03-02 16:39:41 +02:00
|
|
|
const GraphicHelper& rGraphicHelper );
|
2010-04-14 17:31:33 +02:00
|
|
|
|
2011-09-06 17:32:53 +01:00
|
|
|
bool importVbaProject(
|
2011-09-05 10:45:21 +01:00
|
|
|
StorageBase& rVbaPrjStrg );
|
|
|
|
|
2013-06-04 15:24:29 +01:00
|
|
|
/** Reads vba module related information from the project streams */
|
|
|
|
void readVbaModules( StorageBase& rVbaPrjStrg );
|
|
|
|
/** Imports (and creates) vba modules and user forms from the vba project records previously read.
|
|
|
|
Note: ( expects that readVbaModules was already called ) */
|
2017-04-04 14:13:00 +02:00
|
|
|
void importModulesAndForms( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper );
|
2013-06-04 15:24:29 +01:00
|
|
|
/** Registers a macro attacher object. For details, see description of the
|
2010-08-26 18:37:44 +02:00
|
|
|
VbaMacroAttacherBase class. */
|
|
|
|
void registerMacroAttacher( const VbaMacroAttacherRef& rxAttacher );
|
|
|
|
|
2016-10-27 19:31:50 +03:00
|
|
|
/** Attaches VBA macros to objects registered via registerMacroAttacher(). */
|
|
|
|
void attachMacros();
|
|
|
|
|
2015-10-22 16:38:52 +02:00
|
|
|
void setOleOverridesSink( css::uno::Reference< css::container::XNameContainer >& rxOleOverridesSink ){ mxOleOverridesSink = rxOleOverridesSink; }
|
2010-11-02 15:59:53 +00:00
|
|
|
|
2010-08-09 17:05:10 +02:00
|
|
|
protected:
|
|
|
|
/** Registers a dummy module that will be created when the VBA project is
|
|
|
|
imported. */
|
2013-04-07 12:06:47 +02:00
|
|
|
void addDummyModule( const OUString& rName, sal_Int32 nType );
|
2010-08-09 17:05:10 +02:00
|
|
|
|
2010-08-26 18:37:44 +02:00
|
|
|
/** Called when the import process of the VBA project has been started. */
|
|
|
|
virtual void prepareImport();
|
2010-08-09 17:05:10 +02:00
|
|
|
|
2010-04-14 17:31:33 +02:00
|
|
|
private:
|
2015-10-12 15:25:41 +02:00
|
|
|
VbaProject( const VbaProject& ) = delete;
|
|
|
|
VbaProject& operator=( const VbaProject& ) = delete;
|
2010-04-14 17:31:33 +02:00
|
|
|
|
|
|
|
/** Returns the Basic or dialog library container. */
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::script::XLibraryContainer >
|
2010-04-14 17:31:33 +02:00
|
|
|
getLibraryContainer( sal_Int32 nPropId );
|
2017-04-04 14:13:00 +02:00
|
|
|
/** Opens a Basic or dialog library, creates missing if not found. */
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::container::XNameContainer >
|
2017-04-04 14:13:00 +02:00
|
|
|
openLibrary( sal_Int32 nPropId );
|
2010-04-14 17:31:33 +02:00
|
|
|
/** Creates and returns the Basic library of the document used for import. */
|
2016-07-18 09:22:27 +02:00
|
|
|
css::uno::Reference< css::container::XNameContainer > const &
|
2010-04-14 17:31:33 +02:00
|
|
|
createBasicLibrary();
|
|
|
|
/** Creates and returns the dialog library of the document used for import. */
|
2016-07-18 09:22:27 +02:00
|
|
|
css::uno::Reference< css::container::XNameContainer > const &
|
2010-04-14 17:31:33 +02:00
|
|
|
createDialogLibrary();
|
2010-08-09 17:05:10 +02:00
|
|
|
|
2010-04-14 17:31:33 +02:00
|
|
|
/** Imports the VBA code modules and forms. */
|
2010-11-02 15:59:53 +00:00
|
|
|
void importVba(
|
|
|
|
StorageBase& rVbaPrjStrg,
|
2016-09-29 12:43:17 +02:00
|
|
|
const GraphicHelper& rGraphicHelper );
|
2010-11-02 15:59:53 +00:00
|
|
|
|
2010-04-14 17:31:33 +02:00
|
|
|
/** Copies the entire VBA project storage to the passed document model. */
|
|
|
|
void copyStorage( StorageBase& rVbaPrjStrg );
|
|
|
|
|
|
|
|
private:
|
2010-08-26 18:37:44 +02:00
|
|
|
typedef RefVector< VbaMacroAttacherBase > MacroAttacherVector;
|
2013-04-07 12:06:47 +02:00
|
|
|
typedef ::std::map< OUString, sal_Int32 > DummyModuleMap;
|
2010-11-02 15:59:53 +00:00
|
|
|
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext >
|
2012-06-26 09:43:30 +02:00
|
|
|
mxContext; ///< Component context with service manager.
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::frame::XModel >
|
2012-06-26 09:43:30 +02:00
|
|
|
mxDocModel; ///< Document model used to import/export the VBA project.
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::container::XNameContainer >
|
2012-06-26 09:43:30 +02:00
|
|
|
mxBasicLib; ///< The Basic library of the document used for import.
|
2015-10-22 16:38:52 +02:00
|
|
|
css::uno::Reference< css::container::XNameContainer >
|
2012-06-26 09:43:30 +02:00
|
|
|
mxDialogLib; ///< The dialog library of the document used for import.
|
|
|
|
MacroAttacherVector maMacroAttachers; ///< Objects that want to attach a VBA macro to an action.
|
|
|
|
DummyModuleMap maDummyModules; ///< Additional empty modules created on import.
|
2015-10-22 16:38:52 +02:00
|
|
|
OUString maPrjName; ///< Name of the VBA project.
|
|
|
|
css::uno::Reference< css::container::XNameContainer >
|
2010-11-02 15:59:53 +00:00
|
|
|
mxOleOverridesSink;
|
2013-06-04 15:24:29 +01:00
|
|
|
typedef RefMap< rtl::OUString, VbaModule > VbaModuleMap;
|
2015-10-22 16:38:52 +02:00
|
|
|
VbaModuleMap maModules;
|
|
|
|
VbaModuleMap maModulesByStrm;
|
2010-04-14 17:31:33 +02:00
|
|
|
};
|
|
|
|
|
2014-02-25 19:06:16 +01:00
|
|
|
|
2010-04-14 17:31:33 +02:00
|
|
|
} // namespace ole
|
|
|
|
} // namespace oox
|
|
|
|
|
|
|
|
#endif
|
2010-10-27 13:03:58 +01:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|