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