Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/comphelper/embeddedobjectcontainer.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
#ifndef INCLUDED_COMPHELPER_EMBEDDEDOBJECTCONTAINER_HXX
20
#define INCLUDED_COMPHELPER_EMBEDDEDOBJECTCONTAINER_HXX
21
22
#include <comphelper/comphelperdllapi.h>
23
24
#include <rtl/ustring.hxx>
25
#include <memory>
26
#include <optional>
27
28
namespace com::sun::star::beans { struct PropertyValue; }
29
namespace com::sun::star::embed { class XEmbeddedObject; }
30
namespace com::sun::star::embed { class XStorage; }
31
namespace com::sun::star::io { class XInputStream; }
32
namespace com::sun::star::task { class XInteractionHandler; }
33
namespace com::sun::star::uno { class XInterface; }
34
namespace com::sun::star::uno { template <class E> class Sequence; }
35
namespace com::sun::star::uno { template <class interface_type> class Reference; }
36
37
namespace comphelper
38
{
39
    class EmbeddedObjectContainer;
40
41
    /** Helper interface to give access to some common object which replace the SfxObjectShell
42
    */
43
    class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI IEmbeddedHelper
44
    {
45
    public:
46
        virtual EmbeddedObjectContainer& getEmbeddedObjectContainer() const = 0;
47
        virtual css::uno::Reference < css::embed::XStorage > getStorage() const = 0;
48
        virtual css::uno::Reference< css::task::XInteractionHandler > getInteractionHandler() const = 0;
49
        virtual bool isEnableSetModified() const = 0;
50
        virtual OUString getDocumentBaseURL() const = 0;
51
52
    protected:
53
236k
        ~IEmbeddedHelper() {}
54
    };
55
56
struct EmbedImpl;
57
class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer
58
{
59
    std::unique_ptr<EmbedImpl>  pImpl;
60
61
    css::uno::Reference < css::embed::XEmbeddedObject > Get_Impl( const OUString&,
62
            const css::uno::Reference < css::embed::XEmbeddedObject >& xCopy,
63
            OUString const* pBaseURL);
64
65
public:
66
    // add an embedded object to the container storage
67
    bool StoreEmbeddedObject(
68
        const css::uno::Reference<css::embed::XEmbeddedObject>& xObj,
69
        OUString& rName,
70
        bool bCopy,
71
        const OUString& rSrcShellID,
72
        const OUString& rDestShellID );
73
74
    // add an embedded object that has been imported from the container storage - should only be called by filters!
75
    void                AddEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >&, const OUString& rName );
76
77
                        EmbeddedObjectContainer();
78
                        EmbeddedObjectContainer( const css::uno::Reference < css::embed::XStorage >& );
79
                        EmbeddedObjectContainer( const css::uno::Reference < css::embed::XStorage >&,
80
                                                 const css::uno::Reference < css::uno::XInterface >& );
81
                        ~EmbeddedObjectContainer();
82
83
    void                SwitchPersistence( const css::uno::Reference < css::embed::XStorage >& );
84
    bool                CommitImageSubStorage();
85
    void                ReleaseImageSubStorage();
86
87
    OUString        CreateUniqueObjectName();
88
89
    // get a list of object names that have been added so far
90
    css::uno::Sequence < OUString > GetObjectNames() const;
91
92
    // check for existence of objects at all
93
    bool            HasEmbeddedObjects() const;
94
95
    // check existence of an object - either by identity or by name
96
    bool            HasEmbeddedObject( const OUString& );
97
    bool            HasEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >& ) const;
98
    bool            HasInstantiatedEmbeddedObject( const OUString& rName );
99
100
    // get the object name of an object - this is the persist name if the object has persistence
101
    OUString        GetEmbeddedObjectName( const css::uno::Reference < css::embed::XEmbeddedObject >& ) const;
102
103
    // retrieve an embedded object by name that either has been added already or is available in the container storage
104
    css::uno::Reference<css::embed::XEmbeddedObject> GetEmbeddedObject(const OUString& rName, OUString const* pBaseURL = nullptr);
105
106
    // create an object from a ClassId
107
    css::uno::Reference < css::embed::XEmbeddedObject > CreateEmbeddedObject(
108
                        const css::uno::Sequence < sal_Int8 >& rClassId,
109
                        OUString& rNewName,
110
                        std::optional<OUString> oDefaultParentBaseURL = std::nullopt );
111
112
    // insert an embedded object into the container - objects persistent representation will be added to the storage
113
    bool            InsertEmbeddedObject(
114
                        const css::uno::Reference < css::embed::XEmbeddedObject >& xObj,
115
                        OUString& rName,
116
                        OUString const* pTargetShellID = nullptr);
117
118
    // load an embedded object from a MediaDescriptor and insert it into the container
119
    // a new object will be created from the new content and returned
120
    css::uno::Reference < css::embed::XEmbeddedObject > InsertEmbeddedObject(
121
                        const css::uno::Sequence < css::beans::PropertyValue >& aMedium,
122
                        OUString& rName,
123
                        OUString const* pBaseURL = nullptr);
124
125
    // create an embedded link based on a MediaDescriptor and insert it into the container
126
    // a new object will be created from the new content and returned
127
    css::uno::Reference < css::embed::XEmbeddedObject > InsertEmbeddedLink(
128
                        const css::uno::Sequence < css::beans::PropertyValue >& aMedium,
129
                        OUString& rNewName);
130
131
    // create an object from a stream that contains its persistent representation and insert it as usual (usually called from clipboard)
132
    // a new object will be created from the new content and returned
133
    css::uno::Reference < css::embed::XEmbeddedObject > InsertEmbeddedObject(
134
                        const css::uno::Reference < css::io::XInputStream >& xStm,
135
                        OUString& rNewName);
136
137
    // copy an embedded object into the storage, open the new copy and return it
138
    css::uno::Reference <css::embed::XEmbeddedObject> CopyAndGetEmbeddedObject(
139
        EmbeddedObjectContainer& rSrc, const css::uno::Reference <css::embed::XEmbeddedObject>& xObj, OUString& rName,
140
        const OUString& rSrcShellID, const OUString& rDestShellID );
141
142
    // remove an embedded object from the container and from the storage; if object can't be closed
143
    // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
144
    void            RemoveEmbeddedObject( const OUString& rName, bool bKeepToTempStorage = true);
145
    bool            RemoveEmbeddedObject(
146
                        const css::uno::Reference < css::embed::XEmbeddedObject >& xObj,
147
                        bool bKeepToTempStorage = true);
148
149
    // close and remove an embedded object from the container without removing it from the storage
150
    void            CloseEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >& xObj );
151
152
    // move an embedded object to another container (keep the persistent name)
153
    bool            MoveEmbeddedObject( const OUString& rName, EmbeddedObjectContainer& );
154
155
    // get the stored graphical representation for the object
156
    css::uno::Reference < css::io::XInputStream > GetGraphicStream(
157
                    const css::uno::Reference < css::embed::XEmbeddedObject >&,
158
                    OUString* pMediaType=nullptr );
159
160
    // get the stored graphical representation by the object name
161
    css::uno::Reference < css::io::XInputStream > GetGraphicStream( const OUString& aName, OUString* pMediaType=nullptr );
162
163
    // add a graphical representation for an object
164
    bool            InsertGraphicStream(
165
                    const css::uno::Reference < css::io::XInputStream >& rStream,
166
                    const OUString& rObjectName, const OUString& rMediaType );
167
168
    // try to add a graphical representation for an object in optimized way ( might fail )
169
    bool            InsertGraphicStreamDirectly(
170
                    const css::uno::Reference < css::io::XInputStream >& rStream,
171
                    const OUString& rObjectName,
172
                    const OUString& rMediaType );
173
174
    // remove a graphical representation for an object
175
    void            RemoveGraphicStream( const OUString& rObjectName );
176
177
    // copy the graphical representation from different container
178
    bool            TryToCopyGraphReplacement( EmbeddedObjectContainer& rSrc,
179
                                                    const OUString& aOrigName,
180
                                                    const OUString& aTargetName );
181
182
    void            CloseEmbeddedObjects();
183
    bool            StoreChildren(bool _bOasisFormat,bool _bObjectsOnly);
184
    bool            StoreAsChildren( bool _bOasisFormat
185
                                        ,bool _bCreateEmbedded
186
                                        ,bool _bAutoSaveEvent
187
                                        ,const css::uno::Reference < css::embed::XStorage >& _xStorage);
188
189
    static css::uno::Reference< css::io::XInputStream > GetGraphicReplacementStream(
190
                                            sal_Int64 nViewAspect,
191
                                            const css::uno::Reference < css::embed::XEmbeddedObject >&,
192
                                            OUString* pMediaType );
193
194
    /** call setPersistentEntry for each embedded object in the container
195
    *
196
    * @param _xStorage The storage where to store the objects.
197
    * @param _bClearModifiedFlag If <TRUE/> then the modified flag will be set to <FALSE/> otherwise nothing happen.
198
    * @return <FALSE/> if no error occurred, otherwise <TRUE/>.
199
    */
200
    bool             SetPersistentEntries(
201
                        const css::uno::Reference< css::embed::XStorage >& _xStorage,
202
                        bool _bClearModifiedFlag = true);
203
204
    // if DisableActiveContent configuration option is set, this always returns false
205
    bool getUserAllowsLinkUpdate() const;
206
207
    // if DisableActiveContent configuration option is set, this has no effect
208
    void setUserAllowsLinkUpdate(bool bNew);
209
};
210
211
}
212
213
#endif
214
215
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */