bump product version to 4.1.6.2
[LibreOffice.git] / include / oox / ole / axbinaryreader.hxx
blobb6a937d14c4c2a4023d1457cb25e717864328309
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef OOX_OLE_AXBINARYREADER_HXX
21 #define OOX_OLE_AXBINARYREADER_HXX
23 #include <utility>
24 #include "oox/helper/binaryinputstream.hxx"
25 #include "oox/helper/refvector.hxx"
26 #include "oox/ole/axfontdata.hxx"
28 namespace oox {
29 namespace ole {
31 // ============================================================================
33 /** A wrapper for a binary input stream that supports aligned read operations.
35 The implementation does not support seeking back the wrapped stream. All
36 seeking operations (tell, seekTo, align) are performed relative to the
37 position of the wrapped stream at construction time of this wrapper. It is
38 possible to construct this wrapper with an unseekable input stream without
39 loosing any functionality.
41 class AxAlignedInputStream : public BinaryInputStream
43 public:
44 explicit AxAlignedInputStream( BinaryInputStream& rInStrm );
46 /** Returns the size of the data this stream represents, if the wrapped
47 stream supports the size() operation. */
48 virtual sal_Int64 size() const;
49 /** Return the current relative stream position (relative to position of
50 the wrapped stream at construction time). */
51 virtual sal_Int64 tell() const;
52 /** Seeks the stream to the passed relative position, if it is behind the
53 current position. */
54 virtual void seek( sal_Int64 nPos );
55 /** Closes the input stream but not the wrapped stream. */
56 virtual void close();
58 /** Reads nBytes bytes to the passed sequence.
59 @return Number of bytes really read. */
60 virtual sal_Int32 readData( StreamDataSequence& orData, sal_Int32 nBytes, size_t nAtomSize = 1 );
61 /** Reads nBytes bytes to the (existing) buffer opMem.
62 @return Number of bytes really read. */
63 virtual sal_Int32 readMemory( void* opMem, sal_Int32 nBytes, size_t nAtomSize = 1 );
64 /** Seeks the stream forward by the passed number of bytes. */
65 virtual void skip( sal_Int32 nBytes, size_t nAtomSize = 1 );
67 /** Aligns the stream to a multiple of the passed size (relative to the
68 position of the wrapped stream at construction time). */
69 void align( size_t nSize );
71 /** Aligns the stream according to the passed type and reads a value. */
72 template< typename Type >
73 inline Type readAligned() { align( sizeof( Type ) ); return readValue< Type >(); }
74 /** Aligns the stream according to the passed type and skips the size of the type. */
75 template< typename Type >
76 inline void skipAligned() { align( sizeof( Type ) ); skip( sizeof( Type ) ); }
78 private:
79 BinaryInputStream* mpInStrm; ///< The wrapped input stream.
80 sal_Int64 mnStrmPos; ///< Tracks relative position in the stream.
81 sal_Int64 mnStrmSize; ///< Size of the wrapped stream data.
84 // ============================================================================
86 /** A pair of integer values as a property. */
87 typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
89 /** An array of string values as a property. */
90 typedef ::std::vector< OUString > AxArrayString;
92 // ============================================================================
94 /** Import helper to read simple and complex ActiveX form control properties
95 from a binary input stream. */
96 class AxBinaryPropertyReader
98 public:
99 explicit AxBinaryPropertyReader( BinaryInputStream& rInStrm, bool b64BitPropFlags = false );
101 /** Reads the next integer property value from the stream, if the
102 respective flag in the property mask is set. */
103 template< typename StreamType, typename DataType >
104 inline void readIntProperty( DataType& ornValue )
105 { if( startNextProperty() ) ornValue = maInStrm.readAligned< StreamType >(); }
106 /** Reads the next boolean property value from the stream, if the
107 respective flag in the property mask is set. */
108 void readBoolProperty( bool& orbValue, bool bReverse = false );
109 /** Reads the next pair property from the stream, if the respective flag in
110 the property mask is set. */
111 void readPairProperty( AxPairData& orPairData );
112 /** Reads the next string property from the stream, if the respective flag
113 in the property mask is set. */
114 void readStringProperty( OUString& orValue );
115 /** Reads ArrayString, an array of fmString ( compressed or uncompressed )
116 is read from the stream and inserted into rStrings */
117 void readArrayStringProperty( std::vector< OUString >& rStrings );
118 /** Reads the next GUID property from the stream, if the respective flag
119 in the property mask is set. The GUID will be enclosed in braces. */
120 void readGuidProperty( OUString& orGuid );
121 /** Reads the next font property from the stream, if the respective flag in
122 the property mask is set. */
123 void readFontProperty( AxFontData& orFontData );
124 /** Reads the next picture property from the stream, if the respective flag
125 in the property mask is set. */
126 void readPictureProperty( StreamDataSequence& orPicData );
128 /** Skips the next integer property value in the stream, if the respective
129 flag in the property mask is set. */
130 template< typename StreamType >
131 inline void skipIntProperty() { if( startNextProperty() ) maInStrm.skipAligned< StreamType >(); }
132 /** Skips the next boolean property value in the stream, if the respective
133 flag in the property mask is set. */
134 inline void skipBoolProperty() { startNextProperty(); }
135 /** Skips the next pair property in the stream, if the respective flag in
136 the property mask is set. */
137 void skipPairProperty() { readPairProperty( maDummyPairData ); }
138 /** Skips the next string property in the stream, if the respective flag in
139 the property mask is set. */
140 inline void skipStringProperty() { readStringProperty( maDummyString ); }
141 /** Skips the next ArrayString property in the stream, if the respective flag in
142 the property mask is set. */
143 inline void skipArrayStringProperty() { readArrayStringProperty( maDummyArrayString ); }
144 /** Skips the next GUID property in the stream, if the respective flag in
145 the property mask is set. */
146 inline void skipGuidProperty() { readGuidProperty( maDummyString ); }
147 /** Skips the next font property in the stream, if the respective flag in
148 the property mask is set. */
149 inline void skipFontProperty() { readFontProperty( maDummyFontData ); }
150 /** Skips the next picture property in the stream, if the respective flag
151 in the property mask is set. */
152 inline void skipPictureProperty() { readPictureProperty( maDummyPicData ); }
153 /** Has to be called for undefined properties. If the respective flag in
154 the mask is set, the property import cannot be finished successfully. */
155 inline void skipUndefinedProperty() { ensureValid( !startNextProperty() ); }
157 /** Final processing, reads contents of all complex properties. */
158 bool finalizeImport();
160 private:
161 bool ensureValid( bool bCondition = true );
162 bool startNextProperty();
164 private:
165 /** Base class for complex properties such as string, point, size, GUID, picture. */
166 struct ComplexProperty
168 virtual ~ComplexProperty();
169 virtual bool readProperty( AxAlignedInputStream& rInStrm ) = 0;
172 /** Complex property for a 32-bit value pair, e.g. point or size. */
173 struct PairProperty : public ComplexProperty
175 AxPairData& mrPairData;
177 inline explicit PairProperty( AxPairData& rPairData ) :
178 mrPairData( rPairData ) {}
179 virtual bool readProperty( AxAlignedInputStream& rInStrm );
182 /** Complex property for a string value. */
183 struct StringProperty : public ComplexProperty
185 OUString& mrValue;
186 sal_uInt32 mnSize;
188 inline explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
189 mrValue( rValue ), mnSize( nSize ) {}
190 virtual bool readProperty( AxAlignedInputStream& rInStrm );
193 /** Complex property for an array of strings. */
194 struct ArrayStringProperty : public ComplexProperty
196 AxArrayString& mrArray;
197 sal_uInt32 mnSize;
198 inline explicit ArrayStringProperty( AxArrayString& rArray, sal_uInt32 nSize ) :
199 mrArray( rArray ), mnSize( nSize ) {}
200 virtual bool readProperty( AxAlignedInputStream& rInStrm );
203 /** Complex property for a GUID value. */
204 struct GuidProperty : public ComplexProperty
206 OUString& mrGuid;
208 inline explicit GuidProperty( OUString& rGuid ) :
209 mrGuid( rGuid ) {}
210 virtual bool readProperty( AxAlignedInputStream& rInStrm );
213 /** Stream property for a font structure. */
214 struct FontProperty : public ComplexProperty
216 AxFontData& mrFontData;
218 inline explicit FontProperty( AxFontData& rFontData ) :
219 mrFontData( rFontData ) {}
220 virtual bool readProperty( AxAlignedInputStream& rInStrm );
223 /** Stream property for a picture or mouse icon. */
224 struct PictureProperty : public ComplexProperty
226 StreamDataSequence& mrPicData;
228 inline explicit PictureProperty( StreamDataSequence& rPicData ) :
229 mrPicData( rPicData ) {}
230 virtual bool readProperty( AxAlignedInputStream& rInStrm );
233 typedef RefVector< ComplexProperty > ComplexPropVector;
235 private:
236 AxAlignedInputStream maInStrm; ///< The input stream to read from.
237 ComplexPropVector maLargeProps; ///< Stores info for all used large properties.
238 ComplexPropVector maStreamProps; ///< Stores info for all used stream data properties.
239 AxPairData maDummyPairData; ///< Dummy pair for unsupported properties.
240 AxFontData maDummyFontData; ///< Dummy font for unsupported properties.
241 StreamDataSequence maDummyPicData; ///< Dummy picture for unsupported properties.
242 OUString maDummyString; ///< Dummy string for unsupported properties.
243 AxArrayString maDummyArrayString; ///< Dummy strings for unsupported ArrayString properties.
244 sal_Int64 mnPropFlags; ///< Flags specifying existing properties.
245 sal_Int64 mnNextProp; ///< Next property to read.
246 sal_Int64 mnPropsEnd; ///< End position of simple/large properties.
247 bool mbValid; ///< True = stream still valid.
250 // ============================================================================
252 } // namespace ole
253 } // namespace oox
255 #endif
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */