Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/oox/ole/olehelper.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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#ifndef INCLUDED_OOX_OLE_OLEHELPER_HXX
21
#define INCLUDED_OOX_OLE_OLEHELPER_HXX
22
23
#include <com/sun/star/uno/Reference.hxx>
24
#include <filter/msfilter/msocximex.hxx>
25
#include <oox/dllapi.h>
26
#include <oox/helper/binarystreambase.hxx>
27
#include <oox/helper/graphichelper.hxx>
28
#include <rtl/ref.hxx>
29
#include <rtl/ustring.hxx>
30
#include <sal/types.h>
31
#include <memory>
32
33
namespace com::sun::star {
34
    namespace awt { class XControlModel; }
35
    namespace awt { struct Size; }
36
    namespace form { class XFormComponent; }
37
    namespace frame { class XModel; }
38
    namespace io { class XOutputStream; }
39
    namespace uno { class XComponentContext; }
40
}
41
42
class SotStorage;
43
class SotStorageStream;
44
class SvGlobalName;
45
46
namespace oox {
47
    class BinaryInputStream;
48
    class BinaryOutputStream;
49
}
50
51
namespace oox::ole {
52
    class ControlModelBase;
53
    class EmbeddedControl;
54
55
56
0
#define OLE_GUID_STDFONT "{0BE35203-8F91-11CE-9DE3-00AA004BB851}"
57
0
#define OLE_GUID_STDPIC  "{0BE35204-8F91-11CE-9DE3-00AA004BB851}"
58
59
60
const sal_uInt16 OLE_STDFONT_NORMAL     = 400;
61
const sal_uInt16 OLE_STDFONT_BOLD       = 700;
62
63
const sal_uInt8 OLE_STDFONT_ITALIC      = 0x02;
64
const sal_uInt8 OLE_STDFONT_UNDERLINE   = 0x04;
65
const sal_uInt8 OLE_STDFONT_STRIKE      = 0x08;
66
67
/** Stores data about a StdFont font structure. */
68
struct StdFontInfo
69
{
70
    OUString     maName;         ///< Font name.
71
    sal_uInt32          mnHeight;       ///< Font height (1/10,000 points).
72
    sal_uInt16          mnWeight;       ///< Font weight (normal/bold).
73
    sal_uInt16          mnCharSet;      ///< Font charset.
74
    sal_uInt8           mnFlags;        ///< Font flags.
75
76
    explicit            StdFontInfo();
77
    explicit            StdFontInfo(
78
                            OUString aName,
79
                            sal_uInt32 nHeight );
80
};
81
82
83
/** Stores data about a StdHlink hyperlink. */
84
struct StdHlinkInfo
85
{
86
    OUString     maTarget;
87
    OUString     maLocation;
88
    OUString     maDisplay;
89
};
90
91
92
/** Static helper functions for OLE import/export. */
93
namespace OleHelper
94
{
95
    /** Returns the UNO RGB color from the passed encoded OLE color.
96
97
        @param bDefaultColorBgr
98
            True = OLE default color type is treated as BGR color.
99
            False = OLE default color type is treated as palette color.
100
     */
101
    OOX_DLLPUBLIC ::Color decodeOleColor(
102
                            const GraphicHelper& rGraphicHelper,
103
                            sal_uInt32 nOleColor,
104
                            bool bDefaultColorBgr );
105
106
    /** Returns the OLE color from the passed UNO RGB color.
107
     */
108
    OOX_DLLPUBLIC sal_uInt32   encodeOleColor( sal_Int32 nRgbColor );
109
0
    inline sal_uInt32          encodeOleColor( Color nRgbColor ) { return encodeOleColor(sal_Int32(nRgbColor)); }
110
111
    /** Imports a GUID from the passed binary stream and returns its string
112
        representation (in uppercase characters).
113
     */
114
    OOX_DLLPUBLIC OUString importGuid( BinaryInputStream& rInStrm );
115
    OOX_DLLPUBLIC void exportGuid( BinaryOutputStream& rOutStrm, const SvGlobalName& rId );
116
117
    /** Imports an OLE StdFont font structure from the current position of the
118
        passed binary stream.
119
     */
120
    OOX_DLLPUBLIC bool         importStdFont(
121
                            StdFontInfo& orFontInfo,
122
                            BinaryInputStream& rInStrm,
123
                            bool bWithGuid );
124
125
    /** Imports an OLE StdPic picture from the current position of the passed
126
        binary stream.
127
     */
128
    OOX_DLLPUBLIC bool         importStdPic(
129
                            StreamDataSequence& orGraphicData,
130
                            BinaryInputStream& rInStrm );
131
}
132
133
class OOX_DLLPUBLIC OleFormCtrlExportHelper final
134
{
135
    std::unique_ptr<::oox::ole::EmbeddedControl> mpControl;
136
    ::oox::ole::ControlModelBase* mpModel;
137
    ::oox::GraphicHelper maGrfHelper;
138
    css::uno::Reference< css::frame::XModel > mxDocModel;
139
    css::uno::Reference< css::awt::XControlModel > mxControlModel;
140
141
    OUString maName;
142
    OUString maTypeName;
143
    OUString maFullName;
144
    OUString maGUID;
145
public:
146
    OleFormCtrlExportHelper( const css::uno::Reference< css::uno::XComponentContext >& rxCtx, const css::uno::Reference< css::frame::XModel >& xDocModel, const css::uno::Reference< css::awt::XControlModel >& xModel );
147
    ~OleFormCtrlExportHelper();
148
149
    std::u16string_view getGUID() const
150
0
    {
151
0
        std::u16string_view sResult;
152
0
        if ( maGUID.getLength() > 2 )
153
0
            sResult = maGUID.subView(1, maGUID.getLength() - 2 );
154
0
        return sResult;
155
0
    }
156
0
    const OUString& getFullName() const { return maFullName; }
157
0
    const OUString& getTypeName() const { return maTypeName; }
158
0
    const OUString& getName() const { return maName; }
159
0
    bool isValid() const { return mpModel != nullptr; }
160
    void exportName( const css::uno::Reference< css::io::XOutputStream >& rxOut );
161
    void exportCompObj( const css::uno::Reference< css::io::XOutputStream >& rxOut );
162
    void exportControl( const css::uno::Reference< css::io::XOutputStream >& rxOut, const css::awt::Size& rSize, bool bAutoClose = false );
163
};
164
165
// ideally it would be great to get rid of SvxMSConvertOCXControls
166
// however msfilter/source/msfilter/svdfppt.cxx still uses
167
// SvxMSConvertOCXControls as a base class, unfortunately oox depends on
168
// msfilter. Probably the solution would be to move the svdfppt.cxx
169
// implementation into the sd module itself.
170
class OOX_DLLPUBLIC MSConvertOCXControls : public SvxMSConvertOCXControls
171
{
172
    css::uno::Reference< css::uno::XComponentContext > mxCtx;
173
    ::oox::GraphicHelper maGrfHelper;
174
175
protected:
176
    bool importControlFromStream( ::oox::BinaryInputStream& rInStrm,
177
                                  css::uno::Reference< css::form::XFormComponent > & rxFormComp,
178
                                  std::u16string_view rGuidString );
179
    bool importControlFromStream( ::oox::BinaryInputStream& rInStrm,
180
                                  css::uno::Reference< css::form::XFormComponent > & rxFormComp,
181
                                  const OUString& rGuidString,
182
                                  sal_Int32 nSize );
183
public:
184
    MSConvertOCXControls( const css::uno::Reference< css::frame::XModel >& rxModel );
185
    virtual ~MSConvertOCXControls() override;
186
    bool ReadOCXStorage( rtl::Reference<SotStorage> const & rSrc1, css::uno::Reference< css::form::XFormComponent > & rxFormComp );
187
    bool ReadOCXCtlsStream(rtl::Reference<SotStorageStream> const & rSrc1, css::uno::Reference< css::form::XFormComponent > & rxFormComp,
188
                                   sal_Int32 nPos, sal_Int32 nSize );
189
    static bool WriteOCXStream( const css::uno::Reference< css::frame::XModel >& rxModel, rtl::Reference<SotStorage> const &rSrc1, const css::uno::Reference< css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString &rName);
190
    static bool WriteOCXExcelKludgeStream( const css::uno::Reference< css::frame::XModel >& rxModel, const css::uno::Reference< css::io::XOutputStream >& xOutStrm, const css::uno::Reference< css::awt::XControlModel > &rControlModel, const css::awt::Size& rSize,OUString &rName);
191
};
192
193
194
} // namespace oox::ole
195
196
#endif
197
198
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */