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