xref: /trunk/main/filter/source/msfilter/msvbasic.hxx (revision 8c733e3e)
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 _MSVBASIC_HXX
25 #define _MSVBASIC_HXX
26 
27 #include <tools/solar.h>
28 #include <tools/debug.hxx>
29 #include <sot/storage.hxx>
30 #include <tools/dynary.hxx>
31 #include <vector>
32 #include <map>
33 
34 /* class VBA:
35  * The VBA class provides a set of methods to handle Visual Basic For
36  * Applications streams, the constructor is given the root ole2 stream
37  * of the document, Open reads the VBA project file and figures out
38  * the number of VBA streams, and the offset of the data within them.
39  * Decompress decompresses a particular numbered stream, NoStreams returns
40  * this number, and StreamName can give you the streams name. Decompress
41  * will return a string with the decompressed data. The optional extra
42  * argument will be set if not NULL to 1 in the case of a string overflow,
43  * if I can figure out how to do that.
44  *
45  * Otherwise it is possible to inherit from VBA and implement a Output
46  * member which gets called with each 4096 output sized block.
47  *
48  * cmc
49  * */
50 
51 DECLARE_DYNARRAY(StringArray,String *)
52 
53 // #117718# define internal types to distinguish between
54 // module types, form, class & normal
55 // #i37965# DR 2004-12-03: add "Document", used in Excel for macros attached to sheet
56 
57 // #117718# define map to hold types of module
58 //
59 typedef sal_Int32 ModType;
60 typedef ::std::map< UniString,
61 	ModType > ModuleTypeHash;
62 
63 class VBA_Impl
64 {
65 public:
66 	VBA_Impl(SvStorage &rIn, bool bCmmntd = true);
67 	~VBA_Impl();
68 	// 0 for failure, 1 for success
69 	bool Open( const String &rToplevel, const String &rSublevel);
70 	const StringArray & Decompress(sal_uInt16 nIndex, int *pOverflow=0);
GetNoStreams() const71 	sal_uInt16 GetNoStreams() const { return nOffsets; }
GetStreamName(sal_uInt16 nIndex) const72 	const String &GetStreamName(sal_uInt16 nIndex) const
73 	{
74 		DBG_ASSERT( nIndex < nOffsets, "Index out of range" );
75 		return pOffsets[ nIndex ].sName;
76 	}
77 	// I'm the method that would be made virtual to make this class
78 	// useful elsewhere
79 	void Output(int len, const sal_uInt8 *data);
80 	//
81 	// #117718# member map of module names to types of module
82 	ModType GetModuleType( const UniString& rModuleName );
83 	std::vector<String> maReferences;
84 private:
85 	struct VBAOffset_Impl
86 	{
87 		String sName;
88 		sal_uInt32 nOffset;
89 	};
90 
91 	// #117718# member map of module names to types of module
92 	ModuleTypeHash mhModHash;
93 	SvStorageRef xVBA;
94 	StringArray aVBAStrings;
95 	String sComment;
96 	SvStorageRef xStor;
97 	VBAOffset_Impl *pOffsets;
98 	sal_uInt16 nOffsets;
99 	enum Limits {nWINDOWLEN = 4096};
100 	sal_uInt8 aHistory[nWINDOWLEN];
101 	rtl_TextEncoding meCharSet;
102 	bool bCommented;
103 	bool mbMac;
104 	int nLines;
105 
106 	// 0 for failure, anything else for success
107 	int ReadVBAProject(const SvStorageRef &rxVBAStorage);
108 	int DecompressVBA(int index, SvStorageStreamRef &rxVBAStream);
109 	sal_uInt8 ReadPString(SvStorageStreamRef &xVBAProject, bool bIsUnicode);
110 };
111 
112 #endif
113 
114 /* vim: set noet sw=4 ts=4: */
115