Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #ifndef INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
11 : #define INCLUDED_OOX_OLE_AXBINARYWRITER_HXX
12 :
13 : #include <utility>
14 : #include <oox/helper/binaryoutputstream.hxx>
15 : #include <oox/helper/refvector.hxx>
16 :
17 : namespace oox {
18 : namespace ole {
19 :
20 :
21 : /** A wrapper for a binary output stream that supports aligned write operations.
22 :
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.
28 : */
29 0 : class AxAlignedOutputStream : public BinaryOutputStream
30 : {
31 : public:
32 : explicit AxAlignedOutputStream( BinaryOutputStream& rOutStrm );
33 :
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
41 : current position. */
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;
45 :
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;
52 :
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 );
56 :
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 0 : 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 ) ); }
64 :
65 : private:
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
70 : };
71 :
72 : /** A pair of integer values as a property. */
73 : typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
74 :
75 : /** An array of string values as a property. */
76 : typedef ::std::vector< OUString > AxStringArray;
77 :
78 :
79 :
80 : /** Export helper to write simple and complex ActiveX form control properties
81 : to a binary input stream. */
82 0 : class AxBinaryPropertyWriter
83 : {
84 : public:
85 : explicit AxBinaryPropertyWriter( BinaryOutputStream& rOutStrm, bool b64BitPropFlags = false );
86 :
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 0 : void writeIntProperty( DataType& ornValue )
91 0 : { 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 );
101 :
102 : /** Skips the next property clears the respective
103 : flag in the property mask. */
104 0 : void skipProperty() { startNextProperty( true ); }
105 :
106 : /** Final processing, write contents of all complex properties, writes record size */
107 : bool finalizeExport();
108 :
109 : private:
110 : bool ensureValid( bool bCondition = true );
111 : bool startNextProperty( bool bSkip = false );
112 :
113 : private:
114 : /** Base class for complex properties such as string, point, size, GUID, picture. */
115 0 : struct ComplexProperty
116 : {
117 : virtual ~ComplexProperty();
118 : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) = 0;
119 : };
120 :
121 : /** Complex property for a 32-bit value pair, e.g. point or size. */
122 0 : struct PairProperty : public ComplexProperty
123 : {
124 : AxPairData& mrPairData;
125 :
126 0 : explicit PairProperty( AxPairData& rPairData ) :
127 0 : mrPairData( rPairData ) {}
128 : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) SAL_OVERRIDE;
129 : };
130 :
131 : /** Complex property for a string value. */
132 0 : struct StringProperty : public ComplexProperty
133 : {
134 : OUString& mrValue;
135 : sal_uInt32 mnSize;
136 :
137 0 : explicit StringProperty( OUString& rValue, sal_uInt32 nSize ) :
138 0 : mrValue( rValue ), mnSize( nSize ) {}
139 : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) SAL_OVERRIDE;
140 : };
141 :
142 : /** Stream property for a picture or mouse icon. */
143 : struct PictureProperty : public ComplexProperty
144 : {
145 : StreamDataSequence& mrPicData;
146 :
147 : explicit PictureProperty( StreamDataSequence& rPicData ) :
148 : mrPicData( rPicData ) {}
149 : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) SAL_OVERRIDE;
150 : };
151 :
152 : typedef RefVector< ComplexProperty > ComplexPropVector;
153 :
154 : private:
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;
168 : };
169 :
170 :
171 : } // namespace ole
172 : } // namespace oox
173 :
174 : #endif
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|