1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_OLE_VBAMODULE_HXX 25 #define OOX_OLE_VBAMODULE_HXX 26 27 #include <com/sun/star/uno/Reference.hxx> 28 #include <rtl/ustring.hxx> 29 30 namespace com { namespace sun { namespace star { 31 namespace container { class XNameAccess; } 32 namespace container { class XNameContainer; } 33 namespace frame { class XModel; } 34 namespace uno { class XComponentContext; } 35 } } } 36 37 namespace oox { 38 class BinaryInputStream; 39 class StorageBase; 40 } 41 42 namespace oox { 43 namespace ole { 44 45 // ============================================================================ 46 47 class VbaModule 48 { 49 public: 50 explicit VbaModule( 51 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, 52 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel, 53 const ::rtl::OUString& rName, 54 rtl_TextEncoding eTextEnc, 55 bool bExecutable ); 56 57 /** Returns the module type (com.sun.star.script.ModuleType constant). */ getType() const58 inline sal_Int32 getType() const { return mnType; } 59 /** Sets the passed module type. */ setType(sal_Int32 nType)60 inline void setType( sal_Int32 nType ) { mnType = nType; } 61 62 /** Returns the name of the module. */ getName() const63 inline const ::rtl::OUString& getName() const { return maName; } 64 /** Returns the stream name of the module. */ getStreamName() const65 inline const ::rtl::OUString& getStreamName() const { return maStreamName; } 66 67 /** Imports all records for this module until the MODULEEND record. */ 68 void importDirRecords( BinaryInputStream& rDirStrm ); 69 70 /** Imports the VBA source code into the passed Basic library. */ 71 void createAndImportModule( 72 StorageBase& rVbaStrg, 73 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib, 74 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const; 75 /** Creates an empty Basic module in the passed Basic library. */ 76 void createEmptyModule( 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 80 private: 81 /** Reads and returns the VBA source code from the passed storage. */ 82 ::rtl::OUString readSourceCode( StorageBase& rVbaStrg ) const; 83 84 /** Creates a new Basic module and inserts it into the passed Basic library. */ 85 void createModule( 86 const ::rtl::OUString& rVBASourceCode, 87 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& rxBasicLib, 88 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& rxDocObjectNA ) const; 89 90 private: 91 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > 92 mxContext; /// Component context with service manager. 93 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > 94 mxDocModel; /// Document model used to import/export the VBA project. 95 ::rtl::OUString maName; 96 ::rtl::OUString maStreamName; 97 ::rtl::OUString maDocString; 98 rtl_TextEncoding meTextEnc; 99 sal_Int32 mnType; 100 sal_uInt32 mnOffset; 101 bool mbReadOnly; 102 bool mbPrivate; 103 bool mbExecutable; 104 }; 105 106 // ============================================================================ 107 108 } // namespace ole 109 } // namespace oox 110 111 #endif 112