LibreOffice Module oox (master) 1
vbaproject.cxx
Go to the documentation of this file.
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
21
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/document/XStorageBasedDocument.hpp>
24#include <com/sun/star/embed/ElementModes.hpp>
25#include <com/sun/star/embed/XTransactedObject.hpp>
26#include <com/sun/star/frame/XModel.hpp>
27#include <com/sun/star/lang/XMultiServiceFactory.hpp>
28#include <com/sun/star/script/ModuleType.hpp>
29#include <com/sun/star/script/XLibraryContainer.hpp>
30#include <com/sun/star/script/vba/XVBACompatibility.hpp>
31#include <com/sun/star/script/vba/XVBAMacroResolver.hpp>
32#include <com/sun/star/uno/XComponentContext.hpp>
36#include <osl/diagnose.h>
37#include <rtl/tencinfo.h>
38#include <sal/log.hxx>
45#include <oox/ole/vbahelper.hxx>
47#include <oox/ole/vbamodule.hxx>
48#include <oox/token/properties.hxx>
49#include <utility>
50
51namespace oox::ole {
52
53using namespace ::com::sun::star;
54using namespace ::com::sun::star::container;
55using namespace ::com::sun::star::document;
56using namespace ::com::sun::star::embed;
57using namespace ::com::sun::star::frame;
58using namespace ::com::sun::star::io;
59using namespace ::com::sun::star::lang;
60using namespace ::com::sun::star::script;
61using namespace ::com::sun::star::script::vba;
62using namespace ::com::sun::star::uno;
63
64using ::comphelper::ConfigurationHelper;
65
66namespace {
67
68bool lclReadConfigItem( const Reference< XInterface >& rxConfigAccess, const OUString& rItemName )
69{
70 // some applications do not support all configuration items, assume 'false' in this case
71 try
72 {
73 Any aItem = ConfigurationHelper::readRelativeKey( rxConfigAccess, "Filter/Import/VBA", rItemName );
74 return aItem.has< bool >() && aItem.get< bool >();
75 }
76 catch(const Exception& )
77 {
78 }
79 return false;
80}
81
82} // namespace
83
84VbaFilterConfig::VbaFilterConfig( const Reference< XComponentContext >& rxContext, std::u16string_view rConfigCompName )
85{
86 OSL_ENSURE( rxContext.is(), "VbaFilterConfig::VbaFilterConfig - missing component context" );
87 if( rxContext.is() ) try
88 {
89 OSL_ENSURE( !rConfigCompName.empty(), "VbaFilterConfig::VbaFilterConfig - invalid configuration component name" );
90 OUString aConfigPackage = OUString::Concat("org.openoffice.Office.") + rConfigCompName;
91 mxConfigAccess = ConfigurationHelper::openConfig( rxContext, aConfigPackage, comphelper::EConfigurationModes::ReadOnly );
92 }
93 catch(const Exception& )
94 {
95 TOOLS_WARN_EXCEPTION("oox", "");
96 }
97 OSL_ENSURE( mxConfigAccess.is(), "VbaFilterConfig::VbaFilterConfig - cannot open configuration" );
98}
99
101{
102}
103
105{
106 return lclReadConfigItem( mxConfigAccess, "Load" );
107}
108
110{
111 return lclReadConfigItem( mxConfigAccess, "Executable" );
112}
113
115{
116 return lclReadConfigItem( mxConfigAccess, "Save" );
117}
118
120 maMacroName(std::move( aMacroName ))
121{
122 OSL_ENSURE( !maMacroName.isEmpty(), "VbaMacroAttacherBase::VbaMacroAttacherBase - empty macro name" );
123}
124
126{
127}
128
129void VbaMacroAttacherBase::resolveAndAttachMacro( const Reference< XVBAMacroResolver >& rxResolver )
130{
131 try
132 {
133 attachMacro( rxResolver->resolveVBAMacroToScriptURL( maMacroName ) );
134 }
135 catch(const Exception& )
136 {
137 TOOLS_WARN_EXCEPTION("oox", "");
138 }
139}
140
141VbaProject::VbaProject( const Reference< XComponentContext >& rxContext,
142 const Reference< XModel >& rxDocModel, std::u16string_view rConfigCompName ) :
143 VbaFilterConfig( rxContext, rConfigCompName ),
144 mxContext( rxContext ),
145 mxDocModel( rxDocModel ),
146 maPrjName( "Standard" )
147{
148 OSL_ENSURE( mxContext.is(), "VbaProject::VbaProject - missing component context" );
149 OSL_ENSURE( mxDocModel.is(), "VbaProject::VbaProject - missing document model" );
150}
151
153{
154}
155
157{
158 // create GraphicHelper
159 Reference< css::frame::XFrame > xFrame;
160 if ( mxDocModel.is() )
161 {
162 Reference< css::frame::XController > xController = mxDocModel->getCurrentController();
163 xFrame = xController.is() ? xController->getFrame() : nullptr;
164 }
165 StorageRef noStorage;
166 // if the GraphicHelper tries to use noStorage it will of course crash
167 // but... this shouldn't happen as there is no reason for GraphicHelper
168 // to do that when importing VBA projects
169 GraphicHelper grfHlp( mxContext, xFrame, noStorage );
170 importVbaProject( rVbaPrjStrg, grfHlp );
171 // return true if something has been imported
172 return (mxBasicLib.is() && mxBasicLib->hasElements()) ||
173 (mxDialogLib.is() && mxDialogLib->hasElements());
174}
175
176void VbaProject::importVbaProject( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper )
177{
178 if( rVbaPrjStrg.isStorage() )
179 {
180 // load the code modules and forms
181 if( isImportVba() )
182 importVba( rVbaPrjStrg, rGraphicHelper );
183 // copy entire storage into model
184 if( isExportVba() )
185 copyStorage( rVbaPrjStrg );
186 }
187}
188
189void VbaProject::importVbaData(const uno::Reference<io::XInputStream>& xInputStream)
190{
191 uno::Reference<document::XStorageBasedDocument> xStorageBasedDoc(mxDocModel, uno::UNO_QUERY);
192 uno::Reference<embed::XStorage> xDocStorage = xStorageBasedDoc->getDocumentStorage();
193 {
194 const sal_Int32 nOpenMode = ElementModes::SEEKABLE | ElementModes::WRITE | ElementModes::TRUNCATE;
195 uno::Reference<io::XOutputStream> xDocStream(xDocStorage->openStreamElement("_MS_VBA_Macros_XML", nOpenMode), uno::UNO_QUERY);
196 comphelper::OStorageHelper::CopyInputToOutput(xInputStream, xDocStream);
197 }
198 uno::Reference<embed::XTransactedObject>(xDocStorage, uno::UNO_QUERY_THROW)->commit();
199}
200
202{
203 OSL_ENSURE( rxAttacher, "VbaProject::registerMacroAttacher - unexpected empty reference" );
204 maMacroAttachers.push_back( rxAttacher );
205}
206
207// protected ------------------------------------------------------------------
208
209void VbaProject::addDummyModule( const OUString& rName, sal_Int32 nType )
210{
211 OSL_ENSURE( !rName.isEmpty(), "VbaProject::addDummyModule - missing module name" );
212 maDummyModules[ rName ] = nType;
213}
214
216{
217}
218
219// private --------------------------------------------------------------------
220
221Reference< XLibraryContainer > VbaProject::getLibraryContainer( sal_Int32 nPropId )
222{
223 PropertySet aDocProp( mxDocModel );
224 Reference< XLibraryContainer > xLibContainer( aDocProp.getAnyProperty( nPropId ), UNO_QUERY );
225 return xLibContainer;
226}
227
228Reference< XNameContainer > VbaProject::openLibrary( sal_Int32 nPropId )
229{
230 Reference< XNameContainer > xLibrary;
231 try
232 {
233 Reference< XLibraryContainer > xLibContainer( getLibraryContainer( nPropId ), UNO_SET_THROW );
234 if( !xLibContainer->hasByName( maPrjName ) )
235 xLibContainer->createLibrary( maPrjName );
236 xLibrary.set( xLibContainer->getByName( maPrjName ), UNO_QUERY_THROW );
237 }
238 catch(const Exception& )
239 {
240 TOOLS_WARN_EXCEPTION("oox", "");
241 }
242 OSL_ENSURE( xLibrary.is(), "VbaProject::openLibrary - cannot create library" );
243 return xLibrary;
244}
245
246Reference< XNameContainer > const & VbaProject::createBasicLibrary()
247{
248 if( !mxBasicLib.is() )
249 mxBasicLib = openLibrary( PROP_BasicLibraries );
250 return mxBasicLib;
251}
252
253Reference< XNameContainer > const & VbaProject::createDialogLibrary()
254{
255 if( !mxDialogLib.is() )
256 mxDialogLib = openLibrary( PROP_DialogLibraries );
257 return mxDialogLib;
258}
259
260void VbaProject::importVba( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper )
261{
262 readVbaModules( rVbaPrjStrg );
263 importModulesAndForms(rVbaPrjStrg, rGraphicHelper );
264 // attach macros to registered objects
265 attachMacros();
266}
267
269{
270 StorageRef xVbaStrg = rVbaPrjStrg.openSubStorage( "VBA", false );
271 OSL_ENSURE( xVbaStrg, "VbaProject::readVbaModules - cannot open 'VBA' substorage" );
272 if( !xVbaStrg )
273 return;
274
275 /* Read the 'VBA/dir' stream which contains general settings of the VBA
276 project such as the text encoding used throughout several streams, and
277 a list of all code modules.
278 */
279 BinaryXInputStream aInStrm( xVbaStrg->openInputStream( "dir" ), true );
280 // VbaInputStream implements decompression
281 VbaInputStream aDirStrm( aInStrm );
282 OSL_ENSURE( !aDirStrm.isEof(), "VbaProject::importVba - cannot open 'dir' stream" );
283 if( aDirStrm.isEof() )
284 return;
285
286 // virtual call, derived classes may do some preparations
288
289 // read all records of the directory
290 rtl_TextEncoding eTextEnc = RTL_TEXTENCODING_MS_1252;
291 sal_uInt16 nModuleCount = 0;
292 bool bExecutable = isImportVbaExecutable();
293
294 sal_uInt16 nRecId = 0;
295 StreamDataSequence aRecData;
296 while( VbaHelper::readDirRecord( nRecId, aRecData, aDirStrm ) && (nRecId != VBA_ID_PROJECTEND) )
297 {
298 // create record stream object from imported record data
299 SequenceInputStream aRecStrm( aRecData );
300 sal_Int32 nRecSize = aRecData.getLength();
301 switch( nRecId )
302 {
304 {
305 OSL_ENSURE( nRecSize == 2, "VbaProject::importVba - invalid record size" );
306 OSL_ENSURE( maModules.empty(), "VbaProject::importVba - unexpected PROJECTCODEPAGE record" );
307 rtl_TextEncoding eNewTextEnc = rtl_getTextEncodingFromWindowsCodePage( aRecStrm.readuInt16() );
308 OSL_ENSURE( eNewTextEnc != RTL_TEXTENCODING_DONTKNOW, "VbaProject::importVba - unknown text encoding" );
309 if( eNewTextEnc != RTL_TEXTENCODING_DONTKNOW )
310 eTextEnc = eNewTextEnc;
311 }
312 break;
314 {
315 OUString aPrjName = aRecStrm.readCharArrayUC( nRecSize, eTextEnc );
316 OSL_ENSURE( !aPrjName.isEmpty(), "VbaProject::importVba - invalid project name" );
317 if( !aPrjName.isEmpty() )
318 maPrjName = aPrjName;
319 }
320 break;
322 OSL_ENSURE( nRecSize == 2, "VbaProject::importVba - invalid record size" );
323 OSL_ENSURE( maModules.empty(), "VbaProject::importVba - unexpected PROJECTMODULES record" );
324 nModuleCount = aRecStrm.readuInt16();
325 break;
327 {
328 OUString aName = aRecStrm.readCharArrayUC( nRecSize, eTextEnc );
329 OSL_ENSURE( !aName.isEmpty(), "VbaProject::importVba - invalid module name" );
330 OSL_ENSURE( !maModules.has( aName ), "VbaProject::importVba - multiple modules with the same name" );
332 rxModule = std::make_shared<VbaModule>( mxContext, mxDocModel, aName, eTextEnc, bExecutable );
333 // read all remaining records until the MODULEEND record
334 rxModule->importDirRecords( aDirStrm );
335 OSL_ENSURE( !maModulesByStrm.has( rxModule->getStreamName() ), "VbaProject::importVba - multiple modules with the same stream name" );
336 maModulesByStrm[ rxModule->getStreamName() ] = rxModule;
337 }
338 break;
339 }
340 }
341 SAL_WARN_IF( nModuleCount != maModules.size(), "oox", "VbaProject::importVba - invalid module count" );
342
343 /* The directory does not contain the real type of the modules, it
344 distinguishes only between 'procedural' and 'document' (the latter
345 includes class and form modules). Now, the exact type of all modules
346 will be read from the 'PROJECT' stream. It consists of text lines in
347 'key=value' format which list the code modules by type.
348
349 - The line 'document=<modulename>/&HXXXXXXXX' declares document
350 modules. These are attached to the Word document (usually called
351 'ThisDocument'), the Excel workbook (usually called
352 'ThisWorkbook'), or single Excel worksheets or chartsheets (usually
353 called 'SheetX' or 'ChartX', X being a decimal number). Of course,
354 users may rename all these modules. The slash character separates
355 an automation server version number (hexadecimal 'XXXXXXXX') from
356 the module name.
357 - The line 'Module=<modulename>' declares common procedural code
358 modules.
359 - The line 'Class=<modulename>' declares a class module.
360 - The line 'BaseClass=<modulename>' declares a code module attached
361 to a user form with the same name.
362 */
363 BinaryXInputStream aPrjStrm( rVbaPrjStrg.openInputStream( "PROJECT" ), true );
364 OSL_ENSURE( !aPrjStrm.isEof(), "VbaProject::importVba - cannot open 'PROJECT' stream" );
365 // do not exit if this stream does not exist, but proceed to load the modules below
366 if( !aPrjStrm.isEof() )
367 {
368 TextInputStream aPrjTextStrm( mxContext, aPrjStrm, eTextEnc );
369 OUString aKey, aValue;
370 bool bExitLoop = false;
371 while( !bExitLoop && !aPrjTextStrm.isEof() )
372 {
373 // read a text line from the stream
374 OUString aLine = aPrjTextStrm.readLine().trim();
375 sal_Int32 nLineLen = aLine.getLength();
376 // exit if a subsection starts (section name is given in brackets)
377 bExitLoop = (nLineLen >= 2) && (aLine[ 0 ] == '[') && (aLine[ nLineLen - 1 ] == ']');
378 if( !bExitLoop && VbaHelper::extractKeyValue( aKey, aValue, aLine ) )
379 {
380 sal_Int32 nType = ModuleType::UNKNOWN;
381 if( aKey.equalsIgnoreAsciiCase( "Document" ) )
382 {
383 nType = ModuleType::DOCUMENT;
384 // strip automation server version from module names
385 sal_Int32 nSlashPos = aValue.indexOf( '/' );
386 if( nSlashPos >= 0 )
387 aValue = aValue.copy( 0, nSlashPos );
388 }
389 else if( aKey.equalsIgnoreAsciiCase( "Module" ) )
390 nType = ModuleType::NORMAL;
391 else if( aKey.equalsIgnoreAsciiCase( "Class" ) )
392 nType = ModuleType::CLASS;
393 else if( aKey.equalsIgnoreAsciiCase( "BaseClass" ) )
394 nType = ModuleType::FORM;
395
396 if( (nType != ModuleType::UNKNOWN) && !aValue.isEmpty() )
397 {
398 OSL_ENSURE( maModules.has( aValue ), "VbaProject::importVba - module not found" );
399 if( VbaModule* pModule = maModules.get( aValue ).get() )
400 pModule->setType( nType );
401 }
402 }
403 }
404 }
405
406 if( maModules.empty() )
407 return;
408
409 try
410 {
411 /* Set library container to VBA compatibility mode. This will create
412 the VBA Globals object and store it in the Basic manager of the
413 document. */
414 try
415 {
416 Reference< XVBACompatibility > xVBACompat( getLibraryContainer( PROP_BasicLibraries ), UNO_QUERY_THROW );
417 xVBACompat->setVBACompatibilityMode( true );
418 xVBACompat->setProjectName( maPrjName );
419
420 uno::Reference<beans::XPropertySet> xProps(xVBACompat, uno::UNO_QUERY_THROW);
421 xProps->setPropertyValue("VBATextEncoding", uno::Any(eTextEnc));
422 }
423 catch(const Exception& )
424 {
425 }
426 }
427 catch(const Exception& )
428 {
429 TOOLS_WARN_EXCEPTION("oox", "");
430 }
431}
432
433void VbaProject::importModulesAndForms( StorageBase& rVbaPrjStrg, const GraphicHelper& rGraphicHelper )
434{
435 StorageRef xVbaStrg = rVbaPrjStrg.openSubStorage( "VBA", false );
436 OSL_ENSURE( xVbaStrg, "VbaProject::importModulesAndForms - cannot open 'VBA' substorage" );
437 if( !xVbaStrg )
438 return;
439 rtl_TextEncoding eTextEnc = RTL_TEXTENCODING_MS_1252;
440 bool bExecutable = isImportVbaExecutable();
441
442 // create empty dummy modules
443 VbaModuleMap aDummyModules;
444 for (auto const& dummyModule : maDummyModules)
445 {
446 OSL_ENSURE( !maModules.has( dummyModule.first ) && !aDummyModules.has( dummyModule.first ), "VbaProject::importVba - multiple modules with the same name" );
447 VbaModuleMap::mapped_type& rxModule = aDummyModules[ dummyModule.first ];
448 rxModule = std::make_shared<VbaModule>( mxContext, mxDocModel, dummyModule.first, eTextEnc, bExecutable );
449 rxModule->setType( dummyModule.second );
450 }
451
452 /* Now it is time to load the source code. All modules will be inserted
453 into the Basic library of the document specified by the 'maPrjName'
454 member. Do not create the Basic library, if there are no modules
455 specified. */
456 if( !maModules.empty() || !aDummyModules.empty() ) try
457 {
458 // get the model factory and the basic library
459 Reference< XMultiServiceFactory > xModelFactory( mxDocModel, UNO_QUERY_THROW );
460 Reference< XNameContainer > xBasicLib( createBasicLibrary(), UNO_SET_THROW );
461
462 // try to get access to document objects related to code modules
463 Reference< XNameAccess > xDocObjectNA;
464 try
465 {
466 xDocObjectNA.set( xModelFactory->createInstance( "ooo.vba.VBAObjectModuleObjectProvider" ), UNO_QUERY );
467 }
468 catch(const Exception& )
469 {
470 // not all documents support this
471 }
472
473 if( xBasicLib.is() )
474 {
475 // #TODO cater for mxOleOverridesSink, like I used to before
476 // call Basic source code import for each module, std::[c]ref enforces pass-by-ref
478 ::std::ref( *xVbaStrg ), ::std::cref( xBasicLib ),
479 ::std::cref( xDocObjectNA ) );
480
481 // create empty dummy modules
483 ::std::cref( xBasicLib ), ::std::cref( xDocObjectNA ) );
484 }
485 }
486 catch(const Exception& )
487 {
488 }
489
490 /* Load the forms. The file format specification requires that a module
491 must exist for every form. We are a bit more tolerant and scan the
492 project storage for all form substorages. This may 'repair' broken VBA
493 storages that misses to mention a module for an existing form. */
494 ::std::vector< OUString > aElements;
495 rVbaPrjStrg.getElementNames( aElements );
496 for (auto const& elem : aElements)
497 {
498 // try to open the element as storage
499 if( elem != "VBA" )
500 {
501 StorageRef xSubStrg = rVbaPrjStrg.openSubStorage( elem, false );
502 if( xSubStrg ) try
503 {
504 // resolve module name from storage name (which equals the module stream name)
505 VbaModule* pModule = maModulesByStrm.get( elem ).get();
506 OSL_ENSURE( pModule && (pModule->getType() == ModuleType::FORM),
507 "VbaProject::importVba - form substorage without form module" );
508 OUString aModuleName;
509 if( pModule )
510 aModuleName = pModule->getName();
511
512 // create and import the form
513 Reference< XNameContainer > xDialogLib( createDialogLibrary(), UNO_SET_THROW );
514 VbaUserForm aForm( mxContext, mxDocModel, rGraphicHelper, true/*bDefaultColorBgr*/ );
515 aForm.importForm( xDialogLib, *xSubStrg, aModuleName, eTextEnc );
516 }
517 catch(const Exception& )
518 {
519 TOOLS_WARN_EXCEPTION("oox", "");
520 }
521 }
522 }
523}
524
526{
527 if( maMacroAttachers.empty() || !mxContext.is() )
528 return;
529
530 try
531 {
533
534 Reference< XMultiComponentFactory > xFactory( mxContext->getServiceManager(), UNO_SET_THROW );
535 Sequence< Any > aArgs{ Any(mxDocModel), Any(maPrjName) };
536 Reference< XVBAMacroResolver > xResolver( xFactory->createInstanceWithArgumentsAndContext(
537 "com.sun.star.script.vba.VBAMacroResolver", aArgs, mxContext ), UNO_QUERY_THROW );
539
540 }
541 catch(const Exception& )
542 {
543 TOOLS_WARN_EXCEPTION("oox", "");
544 }
545}
546
548{
549 if( !mxContext.is() )
550 return;
551
552 try
553 {
554 Reference< XStorageBasedDocument > xStorageBasedDoc( mxDocModel, UNO_QUERY_THROW );
555 Reference< XStorage > xDocStorage( xStorageBasedDoc->getDocumentStorage(), UNO_SET_THROW );
556 {
557 const sal_Int32 nOpenMode = ElementModes::SEEKABLE | ElementModes::WRITE | ElementModes::TRUNCATE;
558 Reference< XStream > xDocStream( xDocStorage->openStreamElement( "_MS_VBA_Macros", nOpenMode ), UNO_SET_THROW );
559 OleStorage aDestStorage( mxContext, xDocStream, false );
560 rVbaPrjStrg.copyStorageToStorage( aDestStorage );
561 aDestStorage.commit();
562 }
563 Reference< XTransactedObject >( xDocStorage, UNO_QUERY_THROW )->commit();
564 }
565 catch(const Exception& )
566 {
567 }
568}
569
570} // namespace oox
571
572/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
OUString readCharArrayUC(sal_Int32 nChars, rtl_TextEncoding eTextEnc)
Reads a byte character array and returns a Unicode string.
bool isEof() const
Returns true, if the stream position is invalid (EOF).
Wraps a UNO input stream and provides convenient access functions.
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
A wrapper for a UNO property set.
Definition: propertyset.hxx:58
css::uno::Any getAnyProperty(sal_Int32 nPropId) const
Gets the specified property from the property set.
Definition: propertyset.cxx:62
bool has(key_type nKey) const
Returns true, if the object associated to the passed key exists.
Definition: refmap.hxx:52
mapped_type get(key_type nKey) const
Returns a reference to the object associated to the passed key, or an empty reference on error.
Definition: refmap.hxx:60
container_type::mapped_type mapped_type
Definition: refmap.hxx:45
void forEachMem(FuncType pFunc) const
Calls the passed member function of ObjType on every contained object, automatically skips all elemen...
Definition: refmap.hxx:77
void forEachMem(FuncType pFunc) const
Calls the passed member function of ObjType on every contained object, automatically skips all elemen...
Definition: refvector.hxx:69
Wraps a StreamDataSequence and provides convenient access functions.
Base class for storage access implementations.
Definition: storagebase.hxx:52
void getElementNames(::std::vector< OUString > &orElementNames) const
Fills the passed vector with the names of all direct elements of this storage.
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName)
Opens and returns the specified input stream from the storage.
void commit()
Commits the changes to the storage and all substorages.
void copyStorageToStorage(StorageBase &rDestStrg)
Copies all streams of this storage and of all substorages to the passed destination.
bool isStorage() const
Returns true, if the object represents a valid storage.
Definition: storagebase.cxx:90
StorageRef openSubStorage(const OUString &rStorageName, bool bCreateMissing)
Opens and returns the specified sub storage from the storage.
bool isEof() const
Returns true, if no more text is available in the stream.
OUString readLine()
Reads a text line from the stream.
Implements stream access for binary OLE storages.
Definition: olestorage.hxx:44
VbaFilterConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, std::u16string_view rConfigCompName)
Definition: vbaproject.cxx:84
css::uno::Reference< css::uno::XInterface > mxConfigAccess
Definition: vbaproject.hxx:70
bool isExportVba() const
Returns true, if the VBA source code and forms should be exported.
Definition: vbaproject.cxx:114
bool isImportVba() const
Returns true, if the VBA source code and forms should be imported.
Definition: vbaproject.cxx:104
bool isImportVbaExecutable() const
Returns true, if the VBA source code should be imported executable.
Definition: vbaproject.cxx:109
A non-seekable input stream that implements run-length decompression.
void resolveAndAttachMacro(const css::uno::Reference< css::script::vba::XVBAMacroResolver > &rxResolver)
Resolves the internal macro name to the related macro URL, and attaches the macro to the object.
Definition: vbaproject.cxx:129
VbaMacroAttacherBase(OUString aMacroName)
Definition: vbaproject.cxx:119
virtual void attachMacro(const OUString &rScriptUrl)=0
Called after the VBA project has been imported.
void createAndImportModule(StorageBase &rVbaStrg, const css::uno::Reference< css::container::XNameContainer > &rxBasicLib, const css::uno::Reference< css::container::XNameAccess > &rxDocObjectNA)
Imports the VBA source code into the passed Basic library.
Definition: vbamodule.cxx:130
const OUString & getName() const
Returns the name of the module.
Definition: vbamodule.hxx:70
sal_Int32 getType() const
Returns the module type (com.sun.star.script.ModuleType constant).
Definition: vbamodule.hxx:65
void createEmptyModule(const css::uno::Reference< css::container::XNameContainer > &rxBasicLib, const css::uno::Reference< css::container::XNameAccess > &rxDocObjectNA) const
Creates an empty Basic module in the passed Basic library.
Definition: vbamodule.cxx:154
css::uno::Reference< css::uno::XComponentContext > mxContext
Component context with service manager.
Definition: vbaproject.hxx:189
VbaProject(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XModel > &rxDocModel, std::u16string_view rConfigCompName)
DummyModuleMap maDummyModules
Additional empty modules created on import.
Definition: vbaproject.hxx:197
OUString maPrjName
Name of the VBA project.
Definition: vbaproject.hxx:198
void addDummyModule(const OUString &rName, sal_Int32 nType)
Registers a dummy module that will be created when the VBA project is imported.
Definition: vbaproject.cxx:209
void registerMacroAttacher(const VbaMacroAttacherRef &rxAttacher)
Registers a macro attacher object.
Definition: vbaproject.cxx:201
css::uno::Reference< css::script::XLibraryContainer > getLibraryContainer(sal_Int32 nPropId)
Returns the Basic or dialog library container.
Definition: vbaproject.cxx:221
css::uno::Reference< css::container::XNameContainer > mxBasicLib
The Basic library of the document used for import.
Definition: vbaproject.hxx:193
css::uno::Reference< css::container::XNameContainer > const & createBasicLibrary()
Creates and returns the Basic library of the document used for import.
Definition: vbaproject.cxx:246
css::uno::Reference< css::container::XNameContainer > mxDialogLib
The dialog library of the document used for import.
Definition: vbaproject.hxx:195
VbaModuleMap maModulesByStrm
Definition: vbaproject.hxx:203
css::uno::Reference< css::frame::XModel > mxDocModel
Document model used to import/export the VBA project.
Definition: vbaproject.hxx:191
void attachMacros()
Attaches VBA macros to objects registered via registerMacroAttacher().
Definition: vbaproject.cxx:525
void copyStorage(StorageBase &rVbaPrjStrg)
Copies the entire VBA project storage to the passed document model.
Definition: vbaproject.cxx:547
MacroAttacherVector maMacroAttachers
Objects that want to attach a VBA macro to an action.
Definition: vbaproject.hxx:196
void readVbaModules(StorageBase &rVbaPrjStrg)
Reads vba module related information from the project streams.
Definition: vbaproject.cxx:268
void importVbaProject(StorageBase &rVbaPrjStrg, const GraphicHelper &rGraphicHelper)
Imports the entire VBA project from the passed storage.
Definition: vbaproject.cxx:176
void importModulesAndForms(StorageBase &rVbaPrjStrg, const GraphicHelper &rGraphicHelper)
Imports (and creates) vba modules and user forms from the vba project records previously read.
Definition: vbaproject.cxx:433
void importVbaData(const css::uno::Reference< css::io::XInputStream > &xInputStream)
Imports VBA data for a VBA project, e.g. word/vbaData.xml.
Definition: vbaproject.cxx:189
css::uno::Reference< css::container::XNameContainer > const & createDialogLibrary()
Creates and returns the dialog library of the document used for import.
Definition: vbaproject.cxx:253
virtual void prepareImport()
Called when the import process of the VBA project has been started.
Definition: vbaproject.cxx:215
VbaModuleMap maModules
Definition: vbaproject.hxx:202
void importVba(StorageBase &rVbaPrjStrg, const GraphicHelper &rGraphicHelper)
Imports the VBA code modules and forms.
Definition: vbaproject.cxx:260
css::uno::Reference< css::container::XNameContainer > openLibrary(sal_Int32 nPropId)
Opens a Basic or dialog library, creates missing if not found.
Definition: vbaproject.cxx:228
void importForm(const css::uno::Reference< css::container::XNameContainer > &rxDialogLib, StorageBase &rVbaFormStrg, const OUString &rModuleName, rtl_TextEncoding eTextEnc)
Imports the form and its embedded controls, and inserts the form with all its controls into the passe...
Definition: vbacontrol.cxx:791
#define TOOLS_WARN_EXCEPTION(area, stream)
uno::Reference< uno::XComponentContext > mxContext
Reference< XSingleServiceFactory > xFactory
OUString aName
#define SAL_WARN_IF(condition, area, stream)
@ Exception
COMPHELPER_DLLPUBLIC void notifyMacroEventRead(const css::uno::Reference< css::frame::XModel > &_rxDocument)
bool readDirRecord(sal_uInt16 &rnRecId, StreamDataSequence &rRecData, BinaryInputStream &rInStrm)
Reads the next record from the VBA directory stream 'dir'.
Definition: vbahelper.cxx:29
bool extractKeyValue(OUString &rKey, OUString &rValue, std::u16string_view rKeyValue)
Extracts a key/value pair from a string separated by an equality sign.
Definition: vbahelper.cxx:45
const sal_uInt16 VBA_ID_PROJECTNAME
Definition: vbahelper.hxx:50
std::shared_ptr< VbaMacroAttacherBase > VbaMacroAttacherRef
Definition: vbaproject.hxx:111
const sal_uInt16 VBA_ID_MODULENAME
Definition: vbahelper.hxx:38
const sal_uInt16 VBA_ID_PROJECTCODEPAGE
Definition: vbahelper.hxx:47
const sal_uInt16 VBA_ID_PROJECTEND
Definition: vbahelper.hxx:48
const sal_uInt16 VBA_ID_PROJECTMODULES
Definition: vbahelper.hxx:49
std::shared_ptr< StorageBase > StorageRef
Definition: storagebase.hxx:42
css::uno::Sequence< sal_Int8 > StreamDataSequence
QPRO_FUNC_TYPE nType
Reference< XController > xController
Reference< XFrame > xFrame