LCOV - code coverage report
Current view: top level - include/oox/ole - vbaproject.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 1 0.0 %
Date: 2014-04-14 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          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 INCLUDED_OOX_OLE_VBAPROJECT_HXX
      21             : #define INCLUDED_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             : #include <oox/ole/vbamodule.hxx>
      29             : 
      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; }
      37             : } } }
      38             : 
      39             : namespace oox { class GraphicHelper; }
      40             : 
      41             : namespace oox {
      42             : namespace ole {
      43             : 
      44             : 
      45             : 
      46             : class OOX_DLLPUBLIC VbaFilterConfig
      47             : {
      48             : public:
      49             :     explicit            VbaFilterConfig(
      50             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
      51             :                             const OUString& rConfigCompName );
      52             :                         ~VbaFilterConfig();
      53             : 
      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;
      60             : 
      61             : private:
      62             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
      63             :                         mxConfigAccess;
      64             : };
      65             : 
      66             : 
      67             : 
      68             : /** Base class for objects that attach a amcro to a specific action.
      69             : 
      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.
      79             : 
      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.
      84             :  */
      85             : class OOX_DLLPUBLIC VbaMacroAttacherBase
      86             : {
      87             : public:
      88             :     explicit            VbaMacroAttacherBase( const OUString& rMacroName );
      89             :     virtual             ~VbaMacroAttacherBase();
      90             : 
      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 );
      95             : 
      96             : private:
      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;
     100             : 
     101             : private:
     102             :     OUString     maMacroName;
     103             : };
     104             : 
     105             : typedef ::boost::shared_ptr< VbaMacroAttacherBase > VbaMacroAttacherRef;
     106             : 
     107             : 
     108             : 
     109             : class OOX_DLLPUBLIC VbaProject : public VbaFilterConfig
     110             : {
     111             : public:
     112             :     explicit            VbaProject(
     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();
     117             : 
     118             :     /** Imports the entire VBA project from the passed storage.
     119             : 
     120             :         @param rVbaPrjStrg  The root storage of the entire VBA project.
     121             :      */
     122             :     void                importVbaProject(
     123             :                             StorageBase& rVbaPrjStrg,
     124             :                             const GraphicHelper& rGraphicHelper,
     125             :                             bool bDefaultColorBgr = true );
     126             : 
     127             :     bool                importVbaProject(
     128             :                             StorageBase& rVbaPrjStrg );
     129             : 
     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 );
     138             : 
     139             :     /** Returns true, if the document contains at least one code module. */
     140             :     bool                hasModules() const;
     141             : 
     142             :     /** Returns true, if the document contains at least one dialog. */
     143             :     bool                hasDialogs() const;
     144             : 
     145           0 :     void                setOleOverridesSink( ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >&  rxOleOverridesSink ){ mxOleOverridesSink = rxOleOverridesSink; }
     146             : 
     147             : protected:
     148             :     /** Registers a dummy module that will be created when the VBA project is
     149             :         imported. */
     150             :     void                addDummyModule( const OUString& rName, sal_Int32 nType );
     151             : 
     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();
     156             : 
     157             : private:
     158             :                         VbaProject( const VbaProject& );
     159             :     VbaProject&         operator=( const VbaProject& );
     160             : 
     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();
     173             : 
     174             :     /** Imports the VBA code modules and forms. */
     175             :     void                importVba(
     176             :                             StorageBase& rVbaPrjStrg,
     177             :                             const GraphicHelper& rGraphicHelper,
     178             :                             bool bDefaultColorBgr );
     179             : 
     180             :     /** Attaches VBA macros to objects registered via registerMacroAttacher(). */
     181             :     void                attachMacros();
     182             : 
     183             :     /** Copies the entire VBA project storage to the passed document model. */
     184             :     void                copyStorage( StorageBase& rVbaPrjStrg );
     185             : 
     186             : private:
     187             :     typedef RefVector< VbaMacroAttacherBase >           MacroAttacherVector;
     188             :     typedef ::std::map< OUString, sal_Int32 >    DummyModuleMap;
     189             : 
     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 >
     202             :                         mxOleOverridesSink;
     203             :     typedef RefMap< rtl::OUString, VbaModule > VbaModuleMap;
     204             :     VbaModuleMap maModules;
     205             :     VbaModuleMap maModulesByStrm;
     206             : };
     207             : 
     208             : 
     209             : 
     210             : } // namespace ole
     211             : } // namespace oox
     212             : 
     213             : #endif
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10