Branch data Line data Source code
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 OOX_OLE_VBAPROJECT_HXX
21 : : #define OOX_OLE_VBAPROJECT_HXX
22 : :
23 : : #include <map>
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 : :
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; }
36 : : } } }
37 : :
38 : : namespace oox { class GraphicHelper; }
39 : :
40 : : namespace oox {
41 : : namespace ole {
42 : :
43 : : // ============================================================================
44 : :
45 : : class OOX_DLLPUBLIC VbaFilterConfig
46 : : {
47 : : public:
48 : : explicit VbaFilterConfig(
49 : : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
50 : : const ::rtl::OUString& rConfigCompName );
51 : : ~VbaFilterConfig();
52 : :
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;
59 : :
60 : : private:
61 : : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
62 : : mxConfigAccess;
63 : : };
64 : :
65 : : // ============================================================================
66 : :
67 : : /** Base class for objects that attach a amcro to a specific action.
68 : :
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.
78 : :
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.
83 : : */
84 : : class OOX_DLLPUBLIC VbaMacroAttacherBase
85 : : {
86 : : public:
87 : : explicit VbaMacroAttacherBase( const ::rtl::OUString& rMacroName );
88 : : virtual ~VbaMacroAttacherBase();
89 : :
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 );
94 : :
95 : : private:
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 ::rtl::OUString& rScriptUrl ) = 0;
99 : :
100 : : private:
101 : : ::rtl::OUString maMacroName;
102 : : };
103 : :
104 : : typedef ::boost::shared_ptr< VbaMacroAttacherBase > VbaMacroAttacherRef;
105 : :
106 : : // ============================================================================
107 : :
108 : : class OOX_DLLPUBLIC VbaProject : public VbaFilterConfig
109 : : {
110 : : public:
111 : : explicit VbaProject(
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 ::rtl::OUString& rConfigCompName );
115 : : virtual ~VbaProject();
116 : :
117 : : /** Imports the entire VBA project from the passed storage.
118 : :
119 : : @param rVbaPrjStrg The root storage of the entire VBA project.
120 : : */
121 : : void importVbaProject(
122 : : StorageBase& rVbaPrjStrg,
123 : : const GraphicHelper& rGraphicHelper,
124 : : bool bDefaultColorBgr = true );
125 : :
126 : : bool importVbaProject(
127 : : StorageBase& rVbaPrjStrg );
128 : :
129 : : /** Registers a macro atatcher object. For details, see description of the
130 : : VbaMacroAttacherBase class. */
131 : : void registerMacroAttacher( const VbaMacroAttacherRef& rxAttacher );
132 : :
133 : : /** Returns true, if the document contains at least one code module. */
134 : : bool hasModules() const;
135 : :
136 : : /** Returns true, if the document contains at least one dialog. */
137 : : bool hasDialogs() const;
138 : :
139 : 13 : void setOleOverridesSink( ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxOleOverridesSink ){ mxOleOverridesSink = rxOleOverridesSink; }
140 : :
141 : : protected:
142 : : /** Registers a dummy module that will be created when the VBA project is
143 : : imported. */
144 : : void addDummyModule( const ::rtl::OUString& rName, sal_Int32 nType );
145 : :
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();
150 : :
151 : : private:
152 : : VbaProject( const VbaProject& );
153 : : VbaProject& operator=( const VbaProject& );
154 : :
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();
167 : :
168 : : /** Imports the VBA code modules and forms. */
169 : : void importVba(
170 : : StorageBase& rVbaPrjStrg,
171 : : const GraphicHelper& rGraphicHelper,
172 : : bool bDefaultColorBgr );
173 : :
174 : : /** Attaches VBA macros to objects registered via registerMacroAttacher(). */
175 : : void attachMacros();
176 : :
177 : : /** Copies the entire VBA project storage to the passed document model. */
178 : : void copyStorage( StorageBase& rVbaPrjStrg );
179 : :
180 : : private:
181 : : typedef RefVector< VbaMacroAttacherBase > MacroAttacherVector;
182 : : typedef ::std::map< ::rtl::OUString, sal_Int32 > DummyModuleMap;
183 : :
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 : : ::rtl::OUString maPrjName; ///< Name of the VBA project.
195 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
196 : : mxOleOverridesSink;
197 : : };
198 : :
199 : : // ============================================================================
200 : :
201 : : } // namespace ole
202 : : } // namespace oox
203 : :
204 : : #endif
205 : :
206 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|