1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
11 #define INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
14 #include <oox/helper/binaryoutputstream.hxx>
15 #include <oox/helper/refvector.hxx>
21 /** A wrapper for a binary output stream that supports aligned write operations.
23 The implementation does support seeking back the wrapped stream. All
24 seeking operations (tell, seekTo, align) are performed relative to the
25 position of the wrapped stream at construction time of this wrapper.
26 Unlike it's reader class counterpart it is NOT possible to construct this
27 wrapper with an unseekable output stream.
29 class AxAlignedOutputStream
: public BinaryOutputStream
32 explicit AxAlignedOutputStream( BinaryOutputStream
& rOutStrm
);
34 /** Returns the size of the data this stream represents, if the wrapped
35 stream supports the size() operation. */
36 virtual sal_Int64
size() const SAL_OVERRIDE
;
37 /** Return the current relative stream position (relative to position of
38 the wrapped stream at construction time). */
39 virtual sal_Int64
tell() const SAL_OVERRIDE
;
40 /** Seeks the stream to the passed relative position, if it is behind the
42 virtual void seek( sal_Int64 nPos
) SAL_OVERRIDE
;
43 /** Closes the input stream but not the wrapped stream. */
44 virtual void close() SAL_OVERRIDE
;
46 /** Reads nBytes bytes to the passed sequence.
47 @return Number of bytes really read. */
48 virtual void writeData( const StreamDataSequence
& orData
, size_t nAtomSize
= 1 ) SAL_OVERRIDE
;
49 /** Reads nBytes bytes to the (existing) buffer opMem.
50 @return Number of bytes really read. */
51 virtual void writeMemory( const void* pMem
, sal_Int32 nBytes
, size_t nAtomSize
= 1 ) SAL_OVERRIDE
;
53 /** Aligns the stream to a multiple of the passed size (relative to the
54 position of the wrapped stream at construction time). */
55 void align( size_t nSize
);
57 void pad( sal_Int32 nBytes
, size_t nAtomSize
= 1);
59 /** Aligns the stream according to the passed type and reads a value. */
60 template< typename Type
>
61 void writeAligned( Type nVal
) { align( sizeof( Type
) ); writeValue( nVal
); }
62 /** Aligns the stream according to the passed type and skips the size of the type. */
63 template< typename Type
>
64 void padAligned() { align( sizeof( Type
) ); pad( sizeof( Type
) ); }
67 BinaryOutputStream
* mpOutStrm
; ///< The wrapped input stream.
68 sal_Int64 mnStrmPos
; ///< Tracks relative position in the stream.
69 sal_Int64 mnStrmSize
; ///< Size of the wrapped stream data.
70 sal_Int64 mnWrappedBeginPos
; ///< starting pos or wrapped stream
73 /** A pair of integer values as a property. */
74 typedef ::std::pair
< sal_Int32
, sal_Int32
> AxPairData
;
76 /** An array of string values as a property. */
77 typedef ::std::vector
< OUString
> AxStringArray
;
81 /** Export helper to write simple and complex ActiveX form control properties
82 to a binary input stream. */
83 class AxBinaryPropertyWriter
86 explicit AxBinaryPropertyWriter( BinaryOutputStream
& rOutStrm
, bool b64BitPropFlags
= false );
88 /** Write an integer property value to the stream, the
89 respective flag in the property mask is set. */
90 template< typename StreamType
, typename DataType
>
91 void writeIntProperty( DataType
& ornValue
)
92 { if( startNextProperty() ) maOutStrm
.writeAligned
< StreamType
>( ornValue
); }
93 /** Write a boolean property value to the stream, the
94 respective flag in the property mask is set. */
95 void writeBoolProperty( bool orbValue
, bool bReverse
= false );
96 /** Write a pair property the stream, the respective flag in
97 the property mask is set. */
98 void writePairProperty( AxPairData
& orPairData
);
99 /** Write a string property to the stream, the respective flag
100 in the property mask is set. */
101 void writeStringProperty( OUString
& orValue
, bool bCompressed
= true );
103 /** Skips the next property clears the respective
104 flag in the property mask. */
105 void skipProperty() { startNextProperty( true ); }
107 /** Final processing, write contents of all complex properties, writes record size */
108 bool finalizeExport();
111 bool ensureValid( bool bCondition
= true );
112 bool startNextProperty( bool bSkip
= false );
115 /** Base class for complex properties such as string, point, size, GUID, picture. */
116 struct ComplexProperty
118 virtual ~ComplexProperty();
119 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
) = 0;
122 /** Complex property for a 32-bit value pair, e.g. point or size. */
123 struct PairProperty
: public ComplexProperty
125 AxPairData
& mrPairData
;
127 explicit PairProperty( AxPairData
& rPairData
) :
128 mrPairData( rPairData
) {}
129 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
) SAL_OVERRIDE
;
132 /** Complex property for a string value. */
133 struct StringProperty
: public ComplexProperty
138 explicit StringProperty( OUString
& rValue
, sal_uInt32 nSize
) :
139 mrValue( rValue
), mnSize( nSize
) {}
140 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
) SAL_OVERRIDE
;
143 /** Stream property for a picture or mouse icon. */
144 struct PictureProperty
: public ComplexProperty
146 StreamDataSequence
& mrPicData
;
148 explicit PictureProperty( StreamDataSequence
& rPicData
) :
149 mrPicData( rPicData
) {}
150 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
) SAL_OVERRIDE
;
153 typedef RefVector
< ComplexProperty
> ComplexPropVector
;
156 AxAlignedOutputStream maOutStrm
; ///< The input stream to read from.
157 ComplexPropVector maLargeProps
; ///< Stores info for all used large properties.
158 ComplexPropVector maStreamProps
; ///< Stores info for all used stream data properties.
159 AxPairData maDummyPairData
; ///< Dummy pair for unsupported properties.
160 StreamDataSequence maDummyPicData
; ///< Dummy picture for unsupported properties.
161 OUString maDummyString
; ///< Dummy string for unsupported properties.
162 AxStringArray maDummyStringArray
; ///< Dummy string array for unsupported properties.
163 sal_Int16 mnBlockSize
;
164 sal_Int64 mnPropFlagsStart
; ///< pos of Prop flags
165 sal_Int64 mnPropFlags
; ///< Flags specifying existing properties.
166 sal_Int64 mnNextProp
; ///< Next property to read.
167 bool mbValid
; ///< True = stream still valid.
168 bool mb64BitPropFlags
;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */