Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * [ Copyright (C) 2011 Noel Power<noel.power@suse.com> (initial developer) ]
17 : : *
18 : : * All Rights Reserved.
19 : : *
20 : : * For minor contributions see the git repository.
21 : : *
22 : : * Alternatively, the contents of this file may be used under the terms of
23 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : : * instead of those above.
27 : : */
28 : : #ifndef OOX_OLE_AXBINARYWRITER_HXX
29 : : #define OOX_OLE_AXBINARYWRITER_HXX
30 : :
31 : : #include <utility>
32 : : #include "oox/helper/binaryoutputstream.hxx"
33 : : #include "oox/helper/refvector.hxx"
34 : :
35 : : namespace oox {
36 : : namespace ole {
37 : : // ============================================================================
38 : :
39 : : /** A wrapper for a binary output stream that supports aligned write operations.
40 : :
41 : : The implementation does support seeking back the wrapped stream. All
42 : : seeking operations (tell, seekTo, align) are performed relative to the
43 : : position of the wrapped stream at construction time of this wrapper.
44 : : Unlike it's reader class counterpart it is NOT possible to construct this
45 : : wrapper with an unseekable output stream.
46 : : */
47 [ + - ][ + - ]: 6 : class AxAlignedOutputStream : public BinaryOutputStream
[ - + ][ # # ]
48 : : {
49 : : public:
50 : : explicit AxAlignedOutputStream( BinaryOutputStream& rOutStrm );
51 : :
52 : : /** Returns the size of the data this stream represents, if the wrapped
53 : : stream supports the size() operation. */
54 : : virtual sal_Int64 size() const;
55 : : /** Return the current relative stream position (relative to position of
56 : : the wrapped stream at construction time). */
57 : : virtual sal_Int64 tell() const;
58 : : /** Seeks the stream to the passed relative position, if it is behind the
59 : : current position. */
60 : : virtual void seek( sal_Int64 nPos );
61 : : /** Closes the input stream but not the wrapped stream. */
62 : : virtual void close();
63 : :
64 : : /** Reads nBytes bytes to the passed sequence.
65 : : @return Number of bytes really read. */
66 : : virtual void writeData( const StreamDataSequence& orData, size_t nAtomSize = 1 );
67 : : /** Reads nBytes bytes to the (existing) buffer opMem.
68 : : @return Number of bytes really read. */
69 : : virtual void writeMemory( const void* pMem, sal_Int32 nBytes, size_t nAtomSize = 1 );
70 : :
71 : : /** Aligns the stream to a multiple of the passed size (relative to the
72 : : position of the wrapped stream at construction time). */
73 : : void align( size_t nSize );
74 : :
75 : : void pad( sal_Int32 nBytes, size_t nAtomSize = 1);
76 : : /** Aligns the stream according to the passed type and reads an atomar value. */
77 : : template< typename Type >
78 : 57 : inline void writeAligned( Type nVal ) { align( sizeof( Type ) ); writeValue( nVal ); }
79 : : /** Aligns the stream according to the passed type and skips the size of the type. */
80 : : template< typename Type >
81 : : inline void padAligned() { align( sizeof( Type ) ); pad( sizeof( Type ) ); }
82 : :
83 : : private:
84 : : BinaryOutputStream* mpOutStrm; ///< The wrapped input stream.
85 : : sal_Int64 mnStrmPos; ///< Tracks relative position in the stream.
86 : : sal_Int64 mnStrmSize; ///< Size of the wrapped stream data.
87 : : sal_Int64 mnWrappedBeginPos; ///< starting pos or wrapped stream
88 : : };
89 : :
90 : : /** A pair of integer values as a property. */
91 : : typedef ::std::pair< sal_Int32, sal_Int32 > AxPairData;
92 : :
93 : : /** An array of string values as a property. */
94 : : typedef ::std::vector< ::rtl::OUString > AxStringArray;
95 : :
96 : : // ============================================================================
97 : :
98 : : /** Export helper to write simple and complex ActiveX form control properties
99 : : to a binary input stream. */
100 [ + - ]: 6 : class AxBinaryPropertyWriter
101 : : {
102 : : public:
103 : : explicit AxBinaryPropertyWriter( BinaryOutputStream& rOutStrm, bool b64BitPropFlags = false );
104 : :
105 : : /** Write an integer property value to the stream, the
106 : : respective flag in the property mask is set. */
107 : : template< typename StreamType, typename DataType >
108 : 45 : inline void writeIntProperty( DataType& ornValue )
109 [ + - ][ + - ]: 45 : { if( startNextProperty() ) maOutStrm.writeAligned< StreamType >( ornValue ); }
[ + - ][ # # ]
[ + - ][ # # ]
110 : : /** Write a boolean property value to the stream, the
111 : : respective flag in the property mask is set. */
112 : : void writeBoolProperty( bool orbValue, bool bReverse = false );
113 : : /** Write a pair property the stream, the respective flag in
114 : : the property mask is set. */
115 : : void writePairProperty( AxPairData& orPairData );
116 : : /** Write a string property to the stream, the respective flag
117 : : in the property mask is set. */
118 : : void writeStringProperty( ::rtl::OUString& orValue, bool bCompressed = true );
119 : :
120 : : /** Skips the next property clears the respective
121 : : flag in the property mask. */
122 : 60 : inline void skipProperty() { startNextProperty( true ); }
123 : :
124 : : /** Final processing, write contents of all complex properties, writes record size */
125 : : bool finalizeExport();
126 : :
127 : : private:
128 : : bool ensureValid( bool bCondition = true );
129 : : bool startNextProperty( bool bSkip = false );
130 : :
131 : : private:
132 : : /** Base class for complex properties such as string, point, size, GUID, picture. */
133 : 15 : struct ComplexProperty
134 : : {
135 : : virtual ~ComplexProperty();
136 : : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm ) = 0;
137 : : };
138 : :
139 : : /** Complex property for a 32-bit value pair, e.g. point or size. */
140 [ - + ]: 6 : struct PairProperty : public ComplexProperty
141 : : {
142 : : AxPairData& mrPairData;
143 : :
144 : 3 : inline explicit PairProperty( AxPairData& rPairData ) :
145 : 3 : mrPairData( rPairData ) {}
146 : : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm );
147 : : };
148 : :
149 : : /** Complex property for a string value. */
150 [ - + ]: 24 : struct StringProperty : public ComplexProperty
151 : : {
152 : : ::rtl::OUString& mrValue;
153 : : sal_uInt32 mnSize;
154 : :
155 : 12 : inline explicit StringProperty( ::rtl::OUString& rValue, sal_uInt32 nSize ) :
156 : 12 : mrValue( rValue ), mnSize( nSize ) {}
157 : : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm );
158 : : };
159 : :
160 : : /** Stream property for a picture or mouse icon. */
161 : : struct PictureProperty : public ComplexProperty
162 : : {
163 : : StreamDataSequence& mrPicData;
164 : :
165 : : inline explicit PictureProperty( StreamDataSequence& rPicData ) :
166 : : mrPicData( rPicData ) {}
167 : : virtual bool writeProperty( AxAlignedOutputStream& rOutStrm );
168 : : };
169 : :
170 : : typedef RefVector< ComplexProperty > ComplexPropVector;
171 : :
172 : : private:
173 : : AxAlignedOutputStream maOutStrm; ///< The input stream to read from.
174 : : ComplexPropVector maLargeProps; ///< Stores info for all used large properties.
175 : : ComplexPropVector maStreamProps; ///< Stores info for all used stream data properties.
176 : : AxPairData maDummyPairData; ///< Dummy pair for unsupported properties.
177 : : StreamDataSequence maDummyPicData; ///< Dummy picture for unsupported properties.
178 : : ::rtl::OUString maDummyString; ///< Dummy string for unsupported properties.
179 : : AxStringArray maDummyStringArray; ///< Dummy string array for unsupported properties.
180 : : sal_Int16 mnBlockSize;
181 : : sal_Int64 mnPropFlagsStart; ///< pos of Prop flags
182 : : sal_Int64 mnPropFlags; ///< Flags specifying existing properties.
183 : : sal_Int64 mnNextProp; ///< Next property to read.
184 : : sal_Int64 mnPropsEnd; ///< End position of simple/large properties.
185 : : bool mbValid; ///< True = stream still valid.
186 : : bool mb64BitPropFlags;
187 : : };
188 : :
189 : : // ============================================================================
190 : : } // namespace ole
191 : : } // namespace oox
192 : :
193 : : #endif
194 : :
195 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|