1*22e87013SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*22e87013SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*22e87013SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*22e87013SAndrew Rist  * distributed with this work for additional information
6*22e87013SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*22e87013SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*22e87013SAndrew Rist  * "License"); you may not use this file except in compliance
9*22e87013SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*22e87013SAndrew Rist  *
11*22e87013SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*22e87013SAndrew Rist  *
13*22e87013SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*22e87013SAndrew Rist  * software distributed under the License is distributed on an
15*22e87013SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*22e87013SAndrew Rist  * KIND, either express or implied.  See the License for the
17*22e87013SAndrew Rist  * specific language governing permissions and limitations
18*22e87013SAndrew Rist  * under the License.
19*22e87013SAndrew Rist  *
20*22e87013SAndrew Rist  *************************************************************/
21*22e87013SAndrew Rist 
22*22e87013SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifndef _MSVBASIC_HXX
27cdf0e10cSrcweir #define _MSVBASIC_HXX
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/solar.h>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <sot/storage.hxx>
32cdf0e10cSrcweir #include <tools/dynary.hxx>
33cdf0e10cSrcweir #include <vector>
34cdf0e10cSrcweir #include <map>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir /* class VBA:
37cdf0e10cSrcweir  * The VBA class provides a set of methods to handle Visual Basic For
38cdf0e10cSrcweir  * Applications streams, the constructor is given the root ole2 stream
39cdf0e10cSrcweir  * of the document, Open reads the VBA project file and figures out
40cdf0e10cSrcweir  * the number of VBA streams, and the offset of the data within them.
41cdf0e10cSrcweir  * Decompress decompresses a particular numbered stream, NoStreams returns
42cdf0e10cSrcweir  * this number, and StreamName can give you the streams name. Decompress
43cdf0e10cSrcweir  * will return a string with the decompressed data. The optional extra
44cdf0e10cSrcweir  * argument will be set if not NULL to 1 in the case of a string overflow,
45cdf0e10cSrcweir  * if I can figure out how to do that.
46cdf0e10cSrcweir  *
47cdf0e10cSrcweir  * Otherwise it is possible to inherit from VBA and implement a Output
48cdf0e10cSrcweir  * member which gets called with each 4096 output sized block.
49cdf0e10cSrcweir  *
50cdf0e10cSrcweir  * cmc
51cdf0e10cSrcweir  * */
52cdf0e10cSrcweir 
53cdf0e10cSrcweir DECLARE_DYNARRAY(StringArray,String *)
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // #117718# define internal types to distinguish between
56cdf0e10cSrcweir // module types, form, class & normal
57cdf0e10cSrcweir // #i37965# DR 2004-12-03: add "Document", used in Excel for macros attached to sheet
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // #117718# define map to hold types of module
60cdf0e10cSrcweir //
61cdf0e10cSrcweir typedef sal_Int32 ModType;
62cdf0e10cSrcweir typedef ::std::map< UniString,
63cdf0e10cSrcweir     ModType > ModuleTypeHash;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir class VBA_Impl
66cdf0e10cSrcweir {
67cdf0e10cSrcweir public:
68cdf0e10cSrcweir     VBA_Impl(SvStorage &rIn, bool bCmmntd = true);
69cdf0e10cSrcweir     ~VBA_Impl();
70cdf0e10cSrcweir     //0 for failure, 1 for success
71cdf0e10cSrcweir     bool Open( const String &rToplevel, const String &rSublevel);
72cdf0e10cSrcweir     const StringArray & Decompress(sal_uInt16 nIndex, int *pOverflow=0);
GetNoStreams() const73cdf0e10cSrcweir     sal_uInt16 GetNoStreams() const { return nOffsets; }
GetStreamName(sal_uInt16 nIndex) const74cdf0e10cSrcweir     const String &GetStreamName(sal_uInt16 nIndex) const
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         DBG_ASSERT( nIndex < nOffsets, "Index out of range" );
77cdf0e10cSrcweir         return pOffsets[ nIndex ].sName;
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     //I'm the method that would be made virtual to make this class
80cdf0e10cSrcweir     //useful elsewhere
81cdf0e10cSrcweir     void Output(int len, const sal_uInt8 *data);
82cdf0e10cSrcweir     //
83cdf0e10cSrcweir     // #117718# member map of module names to types of module
84cdf0e10cSrcweir     ModType GetModuleType( const UniString& rModuleName );
85cdf0e10cSrcweir     std::vector<String> maReferences;
86cdf0e10cSrcweir private:
87cdf0e10cSrcweir     struct VBAOffset_Impl
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         String sName;
90cdf0e10cSrcweir         sal_uInt32 nOffset;
91cdf0e10cSrcweir     };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     // #117718# member map of module names to types of module
94cdf0e10cSrcweir     ModuleTypeHash mhModHash;
95cdf0e10cSrcweir     SvStorageRef xVBA;
96cdf0e10cSrcweir     StringArray aVBAStrings;
97cdf0e10cSrcweir     String sComment;
98cdf0e10cSrcweir     SvStorageRef xStor;
99cdf0e10cSrcweir     VBAOffset_Impl *pOffsets;
100cdf0e10cSrcweir     sal_uInt16 nOffsets;
101cdf0e10cSrcweir     enum Limits {nWINDOWLEN = 4096};
102cdf0e10cSrcweir     sal_uInt8 aHistory[nWINDOWLEN];
103cdf0e10cSrcweir     rtl_TextEncoding meCharSet;
104cdf0e10cSrcweir     bool bCommented;
105cdf0e10cSrcweir     bool mbMac;
106cdf0e10cSrcweir     int nLines;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     //0 for failure, anything else for success
109cdf0e10cSrcweir     int ReadVBAProject(const SvStorageRef &rxVBAStorage);
110cdf0e10cSrcweir     int DecompressVBA(int index, SvStorageStreamRef &rxVBAStream);
111cdf0e10cSrcweir     sal_uInt8 ReadPString(SvStorageStreamRef &xVBAProject, bool bIsUnicode);
112cdf0e10cSrcweir };
113cdf0e10cSrcweir 
114cdf0e10cSrcweir #endif
115cdf0e10cSrcweir 
116cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
117