1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef OOX_OLE_VBAMODULE_HXX 29 #define OOX_OLE_VBAMODULE_HXX 30 31 #include <com/sun/star/uno/Reference.hxx> 32 #include <rtl/ustring.hxx> 33 34 namespace com { namespace sun { namespace star { 35 namespace container { class XNameAccess; } 36 namespace container { class XNameContainer; } 37 namespace frame { class XModel; } 38 namespace uno { class XComponentContext; } 39 } } } 40 41 namespace oox { 42 class BinaryInputStream; 43 class StorageBase; 44 } 45 46 namespace oox { 47 namespace ole { 48 49 // ============================================================================ 50 51 class VbaModule 52 { 53 public: 54 explicit VbaModule( 55 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 56 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel, 57 const ::rtl::OUString& rName, 58 rtl_TextEncoding eTextEnc, 59 bool bExecutable ); 60 61 /** Returns the module type (com.sun.star.script.ModuleType constant). */ 62 inline sal_Int32 getType() const { return mnType; } 63 /** Sets the passed module type. */ 64 inline void setType( sal_Int32 nType ) { mnType = nType; } 65 66 /** Returns the name of the module. */ 67 inline const ::rtl::OUString& getName() const { return maName; } 68 /** Returns the stream name of the module. */ 69 inline const ::rtl::OUString& getStreamName() const { return maStreamName; } 70 71 /** Imports all records for this module until the MODULEEND record. */ 72 void importDirRecords( BinaryInputStream& rDirStrm ); 73 74 /** Imports the VBA source code into the passed Basic library. */ 75 void createAndImportModule( 76 StorageBase& rVbaStrg, 77 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib, 78 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const; 79 /** Creates an empty Basic module in the passed Basic library. */ 80 void createEmptyModule( 81 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib, 82 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const; 83 84 private: 85 /** Reads and returns the VBA source code from the passed storage. */ 86 ::rtl::OUString readSourceCode( StorageBase& rVbaStrg ) const; 87 88 /** Creates a new Basic module and inserts it into the passed Basic library. */ 89 void createModule( 90 const ::rtl::OUString& rVBASourceCode, 91 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib, 92 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const; 93 94 private: 95 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > 96 mxContext; /// Component context with service manager. 97 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > 98 mxDocModel; /// Document model used to import/export the VBA project. 99 ::rtl::OUString maName; 100 ::rtl::OUString maStreamName; 101 ::rtl::OUString maDocString; 102 rtl_TextEncoding meTextEnc; 103 sal_Int32 mnType; 104 sal_uInt32 mnOffset; 105 bool mbReadOnly; 106 bool mbPrivate; 107 bool mbExecutable; 108 }; 109 110 // ============================================================================ 111 112 } // namespace ole 113 } // namespace oox 114 115 #endif 116