Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / oox / ole / axbinarywriter.hxx
blobc8b1bdb29158092062850f2fc43ee3bdf56840ce
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/.
8 */
10 #ifndef INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
11 #define INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
13 #include <cstddef>
14 #include <utility>
16 #include <oox/helper/binaryoutputstream.hxx>
17 #include <oox/helper/binarystreambase.hxx>
18 #include <oox/helper/refvector.hxx>
19 #include <rtl/ustring.hxx>
20 #include <sal/types.h>
22 namespace oox {
23 namespace ole {
26 /** A wrapper for a binary output stream that supports aligned write operations.
28 The implementation does support seeking back the wrapped stream. All
29 seeking operations (tell, seekTo, align) are performed relative to the
30 position of the wrapped stream at construction time of this wrapper.
31 Unlike it's reader class counterpart it is NOT possible to construct this
32 wrapper with an unseekable output stream.
34 class AxAlignedOutputStream : public BinaryOutputStream
36 public:
37 explicit AxAlignedOutputStream( BinaryOutputStream& rOutStrm );
39 /** Returns the size of the data this stream represents, if the wrapped
40 stream supports the size() operation. */
41 virtual sal_Int64 size() const override;
42 /** Return the current relative stream position (relative to position of
43 the wrapped stream at construction time). */
44 virtual sal_Int64 tell() const override;
45 /** Seeks the stream to the passed relative position, if it is behind the
46 current position. */
47 virtual void seek( sal_Int64 nPos ) override;
48 /** Closes the input stream but not the wrapped stream. */
49 virtual void close() override;
51 /** Reads nBytes bytes to the passed sequence.
52 @return Number of bytes really read. */
53 virtual void writeData( const StreamDataSequence& orData, size_t nAtomSize = 1 ) override;
54 /** Reads nBytes bytes to the (existing) buffer opMem.
55 @return Number of bytes really read. */
56 virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 ) override;
58 /** Aligns the stream to a multiple of the passed size (relative to the
59 position of the wrapped stream at construction time). */
60 void align( size_t nSize );
62 void pad( sal_Int32 nBytes );
64 /** Aligns the stream according to the passed type and reads a value. */
65 template< typename Type >
66 void writeAligned( Type nVal ) { align( sizeof( Type ) ); writeValue( nVal ); }
68 private:
69 BinaryOutputStream* mpOutStrm; ///< The wrapped input stream.
70 sal_Int64 mnStrmPos; ///< Tracks relative position in the stream.
71 sal_Int64 mnStrmSize; ///< Size of the wrapped stream data.
72 sal_Int64 mnWrappedBeginPos; ///< starting pos or wrapped stream
75 /** A pair of integer values as a property. */
76 typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
78 /** Export helper to write simple and complex ActiveX form control properties
79 to a binary input stream. */
80 class AxBinaryPropertyWriter
82 public:
83 explicit AxBinaryPropertyWriter( BinaryOutputStream& rOutStrm, bool b64BitPropFlags = false );
85 /** Write an integer property value to the stream, the
86 respective flag in the property mask is set. */
87 template< typename StreamType, typename DataType >
88 void writeIntProperty( DataType ornValue )
89 { if( startNextProperty() ) maOutStrm.writeAligned< StreamType >( ornValue ); }
90 /** Write a boolean property value to the stream, the
91 respective flag in the property mask is set. */
92 void writeBoolProperty( bool orbValue );
93 /** Write a pair property the stream, the respective flag in
94 the property mask is set. */
95 void writePairProperty( AxPairData& orPairData );
96 /** Write a string property to the stream, the respective flag
97 in the property mask is set. */
98 void writeStringProperty( OUString& orValue );
100 /** Skips the next property clears the respective
101 flag in the property mask. */
102 void skipProperty() { startNextProperty( true ); }
104 /** Final processing, write contents of all complex properties, writes record size */
105 void finalizeExport();
107 private:
108 bool ensureValid();
109 bool startNextProperty( bool bSkip = false );
111 private:
112 /** Base class for complex properties such as string, point, size, GUID, picture. */
113 struct ComplexProperty
115 virtual ~ComplexProperty();
116 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) = 0;
119 /** Complex property for a 32-bit value pair, e.g. point or size. */
120 struct PairProperty : public ComplexProperty
122 AxPairData& mrPairData;
124 explicit PairProperty( AxPairData& rPairData ) :
125 mrPairData( rPairData ) {}
126 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
129 /** Complex property for a string value. */
130 struct StringProperty : public ComplexProperty
132 OUString& mrValue;
133 sal_uInt32 mnSize;
135 explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
136 mrValue( rValue ), mnSize( nSize ) {}
137 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
140 /** Stream property for a picture or mouse icon. */
141 struct PictureProperty : public ComplexProperty
143 virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) override;
146 typedef RefVector< ComplexProperty > ComplexPropVector;
148 private:
149 AxAlignedOutputStream maOutStrm; ///< The input stream to read from.
150 ComplexPropVector maLargeProps; ///< Stores info for all used large properties.
151 ComplexPropVector maStreamProps; ///< Stores info for all used stream data properties.
152 sal_Int16 mnBlockSize;
153 sal_Int64 mnPropFlagsStart; ///< pos of Prop flags
154 sal_Int64 mnPropFlags; ///< Flags specifying existing properties.
155 sal_Int64 mnNextProp; ///< Next property to read.
156 bool mbValid; ///< True = stream still valid.
157 bool mb64BitPropFlags;
161 } // namespace ole
162 } // namespace oox
164 #endif
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */