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>
19 // ============================================================================
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;
37 /** Return the current relative stream position (relative to position of
38 the wrapped stream at construction time). */
39 virtual sal_Int64
tell() const;
40 /** Seeks the stream to the passed relative position, if it is behind the
42 virtual void seek( sal_Int64 nPos
);
43 /** Closes the input stream but not the wrapped stream. */
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 );
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 );
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);
58 /** Aligns the stream according to the passed type and reads a value. */
59 template< typename Type
>
60 void writeAligned( Type nVal
) { align( sizeof( Type
) ); writeValue( nVal
); }
61 /** Aligns the stream according to the passed type and skips the size of the type. */
62 template< typename Type
>
63 void padAligned() { align( sizeof( Type
) ); pad( sizeof( Type
) ); }
66 BinaryOutputStream
* mpOutStrm
; ///< The wrapped input stream.
67 sal_Int64 mnStrmPos
; ///< Tracks relative position in the stream.
68 sal_Int64 mnStrmSize
; ///< Size of the wrapped stream data.
69 sal_Int64 mnWrappedBeginPos
; ///< starting pos or wrapped stream
72 /** A pair of integer values as a property. */
73 typedef ::std::pair
< sal_Int32
, sal_Int32
> AxPairData
;
75 /** An array of string values as a property. */
76 typedef ::std::vector
< OUString
> AxStringArray
;
78 // ============================================================================
80 /** Export helper to write simple and complex ActiveX form control properties
81 to a binary input stream. */
82 class AxBinaryPropertyWriter
85 explicit AxBinaryPropertyWriter( BinaryOutputStream
& rOutStrm
, bool b64BitPropFlags
= false );
87 /** Write an integer property value to the stream, the
88 respective flag in the property mask is set. */
89 template< typename StreamType
, typename DataType
>
90 void writeIntProperty( DataType
& ornValue
)
91 { if( startNextProperty() ) maOutStrm
.writeAligned
< StreamType
>( ornValue
); }
92 /** Write a boolean property value to the stream, the
93 respective flag in the property mask is set. */
94 void writeBoolProperty( bool orbValue
, bool bReverse
= false );
95 /** Write a pair property the stream, the respective flag in
96 the property mask is set. */
97 void writePairProperty( AxPairData
& orPairData
);
98 /** Write a string property to the stream, the respective flag
99 in the property mask is set. */
100 void writeStringProperty( OUString
& orValue
, bool bCompressed
= true );
102 /** Skips the next property clears the respective
103 flag in the property mask. */
104 void skipProperty() { startNextProperty( true ); }
106 /** Final processing, write contents of all complex properties, writes record size */
107 bool finalizeExport();
110 bool ensureValid( bool bCondition
= true );
111 bool startNextProperty( bool bSkip
= false );
114 /** Base class for complex properties such as string, point, size, GUID, picture. */
115 struct ComplexProperty
117 virtual ~ComplexProperty();
118 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
) = 0;
121 /** Complex property for a 32-bit value pair, e.g. point or size. */
122 struct PairProperty
: public ComplexProperty
124 AxPairData
& mrPairData
;
126 explicit PairProperty( AxPairData
& rPairData
) :
127 mrPairData( rPairData
) {}
128 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
);
131 /** Complex property for a string value. */
132 struct StringProperty
: public ComplexProperty
137 explicit StringProperty( OUString
& rValue
, sal_uInt32 nSize
) :
138 mrValue( rValue
), mnSize( nSize
) {}
139 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
);
142 /** Stream property for a picture or mouse icon. */
143 struct PictureProperty
: public ComplexProperty
145 StreamDataSequence
& mrPicData
;
147 explicit PictureProperty( StreamDataSequence
& rPicData
) :
148 mrPicData( rPicData
) {}
149 virtual bool writeProperty( AxAlignedOutputStream
& rOutStrm
);
152 typedef RefVector
< ComplexProperty
> ComplexPropVector
;
155 AxAlignedOutputStream maOutStrm
; ///< The input stream to read from.
156 ComplexPropVector maLargeProps
; ///< Stores info for all used large properties.
157 ComplexPropVector maStreamProps
; ///< Stores info for all used stream data properties.
158 AxPairData maDummyPairData
; ///< Dummy pair for unsupported properties.
159 StreamDataSequence maDummyPicData
; ///< Dummy picture for unsupported properties.
160 OUString maDummyString
; ///< Dummy string for unsupported properties.
161 AxStringArray maDummyStringArray
; ///< Dummy string array for unsupported properties.
162 sal_Int16 mnBlockSize
;
163 sal_Int64 mnPropFlagsStart
; ///< pos of Prop flags
164 sal_Int64 mnPropFlags
; ///< Flags specifying existing properties.
165 sal_Int64 mnNextProp
; ///< Next property to read.
166 bool mbValid
; ///< True = stream still valid.
167 bool mb64BitPropFlags
;
170 // ============================================================================
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */