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 OOX_OLE_VBAPROJECT_HXX
21 #define 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"
29 namespace com
{ namespace sun
{ namespace star
{
30 namespace container
{ class XNameContainer
; }
31 namespace document
{ class XEventsSupplier
; }
32 namespace frame
{ class XModel
; }
33 namespace script
{ class XLibraryContainer
; }
34 namespace script
{ namespace vba
{ class XVBAMacroResolver
; } }
35 namespace uno
{ class XComponentContext
; }
38 namespace oox
{ class GraphicHelper
; }
43 // ============================================================================
45 class OOX_DLLPUBLIC VbaFilterConfig
48 explicit VbaFilterConfig(
49 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
50 const OUString
& rConfigCompName
);
53 /** Returns true, if the VBA source code and forms should be imported. */
54 bool isImportVba() const;
55 /** Returns true, if the VBA source code should be imported executable. */
56 bool isImportVbaExecutable() const;
57 /** Returns true, if the VBA source code and forms should be exported. */
58 bool isExportVba() const;
61 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
65 // ============================================================================
67 /** Base class for objects that attach a amcro to a specific action.
69 Purpose is to collect objects that need to attach a VBA macro to an action.
70 The VBA project will be loaded at a very late point of the document import
71 process, because it depends on an initialized core document model (e.g.
72 spreadsheet codenames). Some objects that want to attach a VBA macro to an
73 action (e.g. mouse click action for drawing shapes) are loaded long before
74 the VBA project. The drawback is that in most cases macros are specified
75 without module name, or the VBA project name is part of the macro name.
76 In the former case, all code modules have to be scanned for the macro to be
77 able to create a valid script URL.
79 The import code will register these requests to attach a VBA macro with an
80 instance of a class derived from this base class. The derived class will
81 store all information needed to finally attach the macro to the action,
82 once the VBA project has been imported.
84 class OOX_DLLPUBLIC VbaMacroAttacherBase
87 explicit VbaMacroAttacherBase( const OUString
& rMacroName
);
88 virtual ~VbaMacroAttacherBase();
90 /** Resolves the internal macro name to the related macro URL, and attaches
91 the macro to the object. */
92 void resolveAndAttachMacro(
93 const ::com::sun::star::uno::Reference
< ::com::sun::star::script::vba::XVBAMacroResolver
>& rxResolver
);
96 /** Called after the VBA project has been imported. Derived classes will
97 attach the passed script to the object represented by this instance. */
98 virtual void attachMacro( const OUString
& rScriptUrl
) = 0;
101 OUString maMacroName
;
104 typedef ::boost::shared_ptr
< VbaMacroAttacherBase
> VbaMacroAttacherRef
;
106 // ============================================================================
108 class OOX_DLLPUBLIC VbaProject
: public VbaFilterConfig
112 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,
113 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& rxDocModel
,
114 const OUString
& rConfigCompName
);
115 virtual ~VbaProject();
117 /** Imports the entire VBA project from the passed storage.
119 @param rVbaPrjStrg The root storage of the entire VBA project.
121 void importVbaProject(
122 StorageBase
& rVbaPrjStrg
,
123 const GraphicHelper
& rGraphicHelper
,
124 bool bDefaultColorBgr
= true );
126 bool importVbaProject(
127 StorageBase
& rVbaPrjStrg
);
129 /** Registers a macro atatcher object. For details, see description of the
130 VbaMacroAttacherBase class. */
131 void registerMacroAttacher( const VbaMacroAttacherRef
& rxAttacher
);
133 /** Returns true, if the document contains at least one code module. */
134 bool hasModules() const;
136 /** Returns true, if the document contains at least one dialog. */
137 bool hasDialogs() const;
139 void setOleOverridesSink( ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>& rxOleOverridesSink
){ mxOleOverridesSink
= rxOleOverridesSink
; }
142 /** Registers a dummy module that will be created when the VBA project is
144 void addDummyModule( const OUString
& rName
, sal_Int32 nType
);
146 /** Called when the import process of the VBA project has been started. */
147 virtual void prepareImport();
148 /** Called when the import process of the VBA project is finished. */
149 virtual void finalizeImport();
152 VbaProject( const VbaProject
& );
153 VbaProject
& operator=( const VbaProject
& );
155 /** Returns the Basic or dialog library container. */
156 ::com::sun::star::uno::Reference
< ::com::sun::star::script::XLibraryContainer
>
157 getLibraryContainer( sal_Int32 nPropId
);
158 /** Opens a Basic or dialog library (creates missing if specified). */
159 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
160 openLibrary( sal_Int32 nPropId
, bool bCreateMissing
);
161 /** Creates and returns the Basic library of the document used for import. */
162 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
163 createBasicLibrary();
164 /** Creates and returns the dialog library of the document used for import. */
165 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
166 createDialogLibrary();
168 /** Imports the VBA code modules and forms. */
170 StorageBase
& rVbaPrjStrg
,
171 const GraphicHelper
& rGraphicHelper
,
172 bool bDefaultColorBgr
);
174 /** Attaches VBA macros to objects registered via registerMacroAttacher(). */
177 /** Copies the entire VBA project storage to the passed document model. */
178 void copyStorage( StorageBase
& rVbaPrjStrg
);
181 typedef RefVector
< VbaMacroAttacherBase
> MacroAttacherVector
;
182 typedef ::std::map
< OUString
, sal_Int32
> DummyModuleMap
;
184 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>
185 mxContext
; ///< Component context with service manager.
186 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>
187 mxDocModel
; ///< Document model used to import/export the VBA project.
188 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
189 mxBasicLib
; ///< The Basic library of the document used for import.
190 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
191 mxDialogLib
; ///< The dialog library of the document used for import.
192 MacroAttacherVector maMacroAttachers
; ///< Objects that want to attach a VBA macro to an action.
193 DummyModuleMap maDummyModules
; ///< Additional empty modules created on import.
194 OUString maPrjName
; ///< Name of the VBA project.
195 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameContainer
>
199 // ============================================================================
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */