Coverage Report

Created: 2026-02-14 09:37

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