1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_OOX_OLE_VBAPROJECT_HXX
21 #define INCLUDED_OOX_OLE_VBAPROJECT_HXX
24 #include <com/sun/star/uno/XInterface.hpp>
25 #include <oox/helper/refvector.hxx>
26 #include <oox/helper/storagebase.hxx>
27 #include <oox/dllapi.h>
28 #include <oox/ole/vbamodule.hxx>
30 namespace com
{ namespace sun
{ namespace star
{
31 namespace container
{ class XNameContainer
; }
32 namespace document
{ class XEventsSupplier
; }
33 namespace frame
{ class XModel
; }
34 namespace script
{ class XLibraryContainer
; }
35 namespace script
{ namespace vba
{ class XVBAMacroResolver
; } }
36 namespace uno
{ class XComponentContext
; }
39 namespace oox
{ class GraphicHelper
; }
44 // ============================================================================
46 class OOX_DLLPUBLIC VbaFilterConfig
49 explicit VbaFilterConfig(
50 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
51 const OUString
& rConfigCompName
);
54 /** Returns true, if the VBA source code and forms should be imported. */
55 bool isImportVba() const;
56 /** Returns true, if the VBA source code should be imported executable. */
57 bool isImportVbaExecutable() const;
58 /** Returns true, if the VBA source code and forms should be exported. */
59 bool isExportVba() const;
62 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
66 // ============================================================================
68 /** Base class for objects that attach a amcro to a specific action.
70 Purpose is to collect objects that need to attach a VBA macro to an action.
71 The VBA project will be loaded at a very late point of the document import
72 process, because it depends on an initialized core document model (e.g.
73 spreadsheet codenames). Some objects that want to attach a VBA macro to an
74 action (e.g. mouse click action for drawing shapes) are loaded long before
75 the VBA project. The drawback is that in most cases macros are specified
76 without module name, or the VBA project name is part of the macro name.
77 In the former case, all code modules have to be scanned for the macro to be
78 able to create a valid script URL.
80 The import code will register these requests to attach a VBA macro with an
81 instance of a class derived from this base class. The derived class will
82 store all information needed to finally attach the macro to the action,
83 once the VBA project has been imported.
85 class OOX_DLLPUBLIC VbaMacroAttacherBase
88 explicit VbaMacroAttacherBase( const OUString
& rMacroName
);
89 virtual ~VbaMacroAttacherBase();
91 /** Resolves the internal macro name to the related macro URL, and attaches
92 the macro to the object. */
93 void resolveAndAttachMacro(
94 const ::com::sun::star::uno::Reference
< ::com::sun::star::script::vba::XVBAMacroResolver
>& rxResolver
);
97 /** Called after the VBA project has been imported. Derived classes will
98 attach the passed script to the object represented by this instance. */
99 virtual void attachMacro( const OUString
& rScriptUrl
) = 0;
102 OUString maMacroName
;
105 typedef ::boost::shared_ptr
< VbaMacroAttacherBase
> VbaMacroAttacherRef
;
107 // ============================================================================
109 class OOX_DLLPUBLIC VbaProject
: public VbaFilterConfig
113 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
114 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& rxDocModel
,
115 const OUString
& rConfigCompName
);
116 virtual ~VbaProject();
118 /** Imports the entire VBA project from the passed storage.
120 @param rVbaPrjStrg The root storage of the entire VBA project.
122 void importVbaProject(
123 StorageBase
& rVbaPrjStrg
,
124 const GraphicHelper
& rGraphicHelper
,
125 bool bDefaultColorBgr
= true );
127 bool importVbaProject(
128 StorageBase
& rVbaPrjStrg
);
130 /** Reads vba module related information from the project streams */
131 void readVbaModules( StorageBase
& rVbaPrjStrg
);
132 /** Imports (and creates) vba modules and user forms from the vba project records previously read.
133 Note: ( expects that readVbaModules was already called ) */
134 void importModulesAndForms( StorageBase
& rVbaPrjStrg
, const GraphicHelper
& rGraphicHelper
, bool bDefaultColorBgr
= true );
135 /** Registers a macro attacher object. For details, see description of the
136 VbaMacroAttacherBase class. */
137 void registerMacroAttacher( const VbaMacroAttacherRef
& rxAttacher
);
139 /** Returns true, if the document contains at least one code module. */
140 bool hasModules() const;
142 /** Returns true, if the document contains at least one dialog. */
143 bool hasDialogs() const;
145 void setOleOverridesSink( ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& rxOleOverridesSink
){ mxOleOverridesSink
= rxOleOverridesSink
; }
148 /** Registers a dummy module that will be created when the VBA project is
150 void addDummyModule( const OUString
& rName
, sal_Int32 nType
);
152 /** Called when the import process of the VBA project has been started. */
153 virtual void prepareImport();
154 /** Called when the import process of the VBA project is finished. */
155 virtual void finalizeImport();
158 VbaProject( const VbaProject
& );
159 VbaProject
& operator=( const VbaProject
& );
161 /** Returns the Basic or dialog library container. */
162 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XLibraryContainer
>
163 getLibraryContainer( sal_Int32 nPropId
);
164 /** Opens a Basic or dialog library (creates missing if specified). */
165 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
166 openLibrary( sal_Int32 nPropId
, bool bCreateMissing
);
167 /** Creates and returns the Basic library of the document used for import. */
168 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
169 createBasicLibrary();
170 /** Creates and returns the dialog library of the document used for import. */
171 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
172 createDialogLibrary();
174 /** Imports the VBA code modules and forms. */
176 StorageBase
& rVbaPrjStrg
,
177 const GraphicHelper
& rGraphicHelper
,
178 bool bDefaultColorBgr
);
180 /** Attaches VBA macros to objects registered via registerMacroAttacher(). */
183 /** Copies the entire VBA project storage to the passed document model. */
184 void copyStorage( StorageBase
& rVbaPrjStrg
);
187 typedef RefVector
< VbaMacroAttacherBase
> MacroAttacherVector
;
188 typedef ::std::map
< OUString
, sal_Int32
> DummyModuleMap
;
190 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
191 mxContext
; ///< Component context with service manager.
192 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
193 mxDocModel
; ///< Document model used to import/export the VBA project.
194 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
195 mxBasicLib
; ///< The Basic library of the document used for import.
196 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
197 mxDialogLib
; ///< The dialog library of the document used for import.
198 MacroAttacherVector maMacroAttachers
; ///< Objects that want to attach a VBA macro to an action.
199 DummyModuleMap maDummyModules
; ///< Additional empty modules created on import.
200 OUString maPrjName
; ///< Name of the VBA project.
201 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
203 typedef RefMap
< rtl::OUString
, VbaModule
> VbaModuleMap
;
204 VbaModuleMap maModules
;
205 VbaModuleMap maModulesByStrm
;
208 // ============================================================================
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */