Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/embeddedobj/source/inc/commonembobj.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
#pragma once
21
22
#include <com/sun/star/uno/Sequence.hxx>
23
#include <com/sun/star/uno/Reference.hxx>
24
#include <com/sun/star/container/XChild.hpp>
25
#include <com/sun/star/document/XStorageBasedDocument.hpp>
26
#include <com/sun/star/embed/XEmbeddedObject.hpp>
27
#include <com/sun/star/embed/XEmbedPersist2.hpp>
28
#include <com/sun/star/embed/XLinkageSupport.hpp>
29
#include <com/sun/star/embed/XInplaceObject.hpp>
30
#include <com/sun/star/awt/XWindow.hpp>
31
#include <com/sun/star/awt/Rectangle.hpp>
32
#include <com/sun/star/util/XCloseable.hpp>
33
#include <com/sun/star/chart2/XDefaultSizeTransmitter.hpp>
34
#include <com/sun/star/io/XTempFile.hpp>
35
#include <com/sun/star/lang/XServiceInfo.hpp>
36
#include <com/sun/star/lang/XInitialization.hpp>
37
#include <cppuhelper/weak.hxx>
38
#include <embeddedobj/embeddedupdate.hxx>
39
#include <rtl/ref.hxx>
40
#include <map>
41
#include <memory>
42
#include <svtools/filechangedchecker.hxx>
43
#include <unotools/resmgr.hxx>
44
45
namespace com::sun::star {
46
    namespace embed {
47
        class XStorage;
48
    }
49
    namespace beans {
50
        struct PropertyValue;
51
        struct NamedValue;
52
    }
53
}
54
55
namespace comphelper {
56
    class OMultiTypeInterfaceContainerHelper2;
57
}
58
59
namespace comphelper {
60
    class NamedValueCollection;
61
}
62
63
#define NUM_SUPPORTED_STATES 5
64
// #define NUM_SUPPORTED_VERBS 5
65
66
#include "docholder.hxx"
67
68
/**
69
 * Represents an OLE object that has native data and we loaded that data into a
70
 * document model successfully.
71
 */
72
class OCommonEmbeddedObject : public css::embed::XEmbeddedObject
73
                            , public ::embeddedobj::EmbeddedUpdate
74
                            , public css::embed::XEmbedPersist2
75
                            , public css::embed::XLinkageSupport
76
                            , public css::embed::XInplaceObject
77
                            , public css::container::XChild
78
                            , public css::chart2::XDefaultSizeTransmitter
79
                            , public css::lang::XServiceInfo
80
                            , public css::lang::XInitialization
81
                            , public css::lang::XTypeProvider
82
                            , public ::cppu::OWeakObject
83
{
84
protected:
85
    ::osl::Mutex    m_aMutex;
86
87
    rtl::Reference<embeddedobj::DocumentHolder> m_xDocHolder;
88
89
    std::unique_ptr<::comphelper::OMultiTypeInterfaceContainerHelper2> m_pInterfaceContainer;
90
91
    bool m_bReadOnly;
92
93
    bool m_bDisposed;
94
    bool m_bClosed;
95
96
    sal_Int32 m_nObjectState;
97
    sal_Int32 m_nTargetState; // should be -1 except during state changing
98
    sal_Int32 m_nUpdateMode;
99
100
    css::uno::Reference< css::uno::XComponentContext > m_xContext;
101
102
    css::uno::Sequence< css::beans::PropertyValue > m_aDocMediaDescriptor;
103
104
    css::uno::Sequence< sal_Int8 > m_aClassID;
105
    OUString m_aClassName;
106
107
    OUString m_aDocServiceName;
108
    OUString m_aPresetFilterName;
109
110
    sal_Int64 m_nMiscStatus;
111
112
    css::uno::Sequence< css::embed::VerbDescriptor > m_aObjectVerbs;
113
114
    std::map< sal_Int32, sal_Int32 > m_aVerbTable;
115
116
    css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite;
117
118
    OUString m_aContainerName;
119
    OUString m_aDefaultParentBaseURL;
120
    OUString m_aModuleName;
121
    bool        m_bEmbeddedScriptSupport;
122
    bool        m_bDocumentRecoverySupport;
123
124
    // following information will be used between SaveAs and SaveCompleted
125
    bool m_bWaitSaveCompleted;
126
    OUString m_aNewEntryName;
127
    css::uno::Reference< css::embed::XStorage > m_xNewParentStorage;
128
    css::uno::Reference< css::embed::XStorage > m_xNewObjectStorage;
129
    css::uno::Sequence< css::beans::PropertyValue > m_aNewDocMediaDescriptor;
130
131
    css::uno::Reference< css::awt::XWindow > m_xClientWindow; // ???
132
    css::awt::Rectangle m_aOwnRectangle;
133
    css::awt::Rectangle m_aClipRectangle;
134
135
    bool m_bIsLinkURL;
136
    bool m_bLinkTempFileChanged;
137
    ::std::unique_ptr< FileChangedChecker > m_pLinkFile;
138
    bool m_bOleUpdate;
139
    bool m_bInHndFunc;
140
141
    // embedded object related stuff
142
    OUString m_aEntryName;
143
    css::uno::Reference< css::embed::XStorage > m_xParentStorage;
144
    css::uno::Reference< css::embed::XStorage > m_xObjectStorage;
145
    css::uno::Reference< css::embed::XStorage > m_xRecoveryStorage;
146
147
    // link related stuff
148
    OUString m_aLinkURL;
149
    OUString m_aLinkFilterName;
150
    bool        m_bLinkHasPassword;
151
    OUString m_aLinkPassword;
152
153
    // tdf#141529 hold a cc of a linked OLE
154
    css::uno::Reference < css::io::XTempFile > m_aLinkTempFile;
155
156
    css::uno::Reference< css::uno::XInterface > m_xParent;
157
158
    bool m_bHasClonedSize; // the object has cached size
159
    css::awt::Size m_aClonedSize;
160
    sal_Int32 m_nClonedMapUnit;
161
    css::awt::Size m_aDefaultSizeForChart_In_100TH_MM;//#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this member
162
163
private:
164
    void CommonInit_Impl( const css::uno::Sequence< css::beans::NamedValue >& aObjectProps );
165
166
    void LinkInit_Impl( const css::uno::Sequence< css::beans::NamedValue >& aObjectProps,
167
                        const css::uno::Sequence< css::beans::PropertyValue >& aMediaDescr,
168
                        const css::uno::Sequence< css::beans::PropertyValue >& aObjectDescr );
169
170
171
    void SwitchOwnPersistence(
172
                const css::uno::Reference< css::embed::XStorage >& xNewParentStorage,
173
                const css::uno::Reference< css::embed::XStorage >& xNewObjectStorage,
174
                const OUString& aNewName );
175
176
    void SwitchOwnPersistence(
177
                const css::uno::Reference< css::embed::XStorage >& xNewParentStorage,
178
                const OUString& aNewName );
179
180
0
    const OUString& GetDocumentServiceName() const { return m_aDocServiceName; }
181
0
    const OUString& GetPresetFilterName() const { return m_aPresetFilterName; }
182
183
    css::uno::Reference< css::io::XInputStream >
184
        StoreDocumentToTempStream_Impl( sal_Int32 nStorageFormat,
185
                                        const OUString& aBaseURL,
186
                                        const OUString& aHierarchName );
187
188
    sal_Int32 ConvertVerbToState_Impl( sal_Int32 nVerb );
189
190
    void Deactivate();
191
192
    // when State = CopyTempToLink        -> the user pressed the save button
193
    //                                       when change in embedded part then copy to the linked-file
194
    //              CopyLinkToTemp        -> the user pressed the refresh button
195
    //                                       when change in linked-file then copy to the embedded part (temp-file)
196
    //              CopyLinkToTempInit    -> create the temp file
197
    //              CopyLinkToTempRefresh -> when save and Link change but not temp then update temp
198
    enum class CopyBackToOLELink {NoCopy, CopyTempToLink, CopyLinkToTemp, CopyLinkToTempInit, CopyLinkToTempRefresh};
199
200
    void handleLinkedOLE( CopyBackToOLELink eState );
201
202
    void StateChangeNotification_Impl( bool bBeforeChange, sal_Int32 nOldState, sal_Int32 nNewState,::osl::ResettableMutexGuard& _rGuard );
203
204
    void SwitchStateTo_Impl( sal_Int32 nNextState );
205
206
    css::uno::Sequence< sal_Int32 > const & GetIntermediateStatesSequence_Impl( sal_Int32 nNewState );
207
208
    OUString GetFilterName( sal_Int32 nVersion ) const;
209
    css::uno::Reference< css::util::XCloseable > LoadDocumentFromStorage_Impl();
210
211
    css::uno::Reference< css::util::XCloseable > LoadLink_Impl();
212
213
    css::uno::Reference< css::util::XCloseable > InitNewDocument_Impl();
214
215
    void StoreDocToStorage_Impl(
216
        const css::uno::Reference<css::embed::XStorage>& xStorage,
217
        const css::uno::Sequence<css::beans::PropertyValue>& rMediaArgs,
218
        const css::uno::Sequence<css::beans::PropertyValue>& rObjArgs,
219
        sal_Int32 nStorageVersion,
220
        const OUString& aHierarchName,
221
        bool bAttachToStorage );
222
223
    void SwitchDocToStorage_Impl(
224
            const css::uno::Reference< css::document::XStorageBasedDocument >& xDoc,
225
            const css::uno::Reference< css::embed::XStorage >& xStorage );
226
227
    void FillDefaultLoadArgs_Impl(
228
            const css::uno::Reference< css::embed::XStorage >& i_rxStorage,
229
                  ::comphelper::NamedValueCollection& o_rLoadArgs
230
        ) const;
231
232
    void EmbedAndReparentDoc_Impl(
233
            const css::uno::Reference< css::util::XCloseable >& i_rxDocument
234
        ) const;
235
236
    css::uno::Reference< css::util::XCloseable > CreateDocFromMediaDescr_Impl(
237
                        const css::uno::Sequence< css::beans::PropertyValue >& aMedDescr );
238
239
    css::uno::Reference< css::util::XCloseable > CreateTempDocFromLink_Impl();
240
241
    OUString GetBaseURL_Impl() const;
242
    static OUString GetBaseURLFrom_Impl(
243
                    const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
244
                    const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs );
245
246
    int ShowMsgDialog(TranslateId Msg, const OUString& sFileName);
247
248
    bool getAllowLinkUpdate() const;
249
250
protected:
251
    void SetInplaceActiveState();
252
253
public:
254
    OCommonEmbeddedObject(
255
        css::uno::Reference< css::uno::XComponentContext > xContext,
256
        const css::uno::Sequence< css::beans::NamedValue >& aObjectProps );
257
258
    // no persistence for linked objects, so the descriptors are provided in constructor
259
    OCommonEmbeddedObject(
260
        css::uno::Reference< css::uno::XComponentContext > xContext,
261
        const css::uno::Sequence< css::beans::NamedValue >& aObjectProps,
262
        const css::uno::Sequence< css::beans::PropertyValue >& aMediaDescr,
263
        const css::uno::Sequence< css::beans::PropertyValue >& aObjectDescr );
264
265
    virtual ~OCommonEmbeddedObject() override;
266
267
    void SaveObject_Impl();
268
269
    void requestPositioning( const css::awt::Rectangle& aRect );
270
271
    // not a real listener and should not be
272
    void PostEvent_Impl( const OUString& aEventName );
273
274
0
    OUString const & getContainerName() const { return m_aContainerName; }
275
// XInterface
276
277
    virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& rType ) override ;
278
279
    virtual void SAL_CALL acquire()
280
        noexcept override;
281
282
    virtual void SAL_CALL release()
283
        noexcept override;
284
285
// XEmbeddedObject
286
287
    virtual void SAL_CALL changeState( sal_Int32 nNewState ) override;
288
289
    virtual css::uno::Sequence< sal_Int32 > SAL_CALL getReachableStates() override;
290
291
    virtual sal_Int32 SAL_CALL getCurrentState() override;
292
293
    virtual void SAL_CALL doVerb( sal_Int32 nVerbID ) override;
294
295
    virtual css::uno::Sequence< css::embed::VerbDescriptor > SAL_CALL getSupportedVerbs() override;
296
297
    virtual void SAL_CALL setClientSite(
298
                const css::uno::Reference< css::embed::XEmbeddedClient >& xClient ) override;
299
300
    virtual css::uno::Reference< css::embed::XEmbeddedClient > SAL_CALL getClientSite() override;
301
302
    virtual void SAL_CALL update() override;
303
304
    virtual void SAL_CALL setUpdateMode( sal_Int32 nMode ) override;
305
306
    virtual sal_Int64 SAL_CALL getStatus( sal_Int64 nAspect ) override;
307
308
    virtual void SAL_CALL setContainerName( const OUString& sName ) override;
309
310
// EmbeddedUpdate
311
312
    virtual void SetOleState(bool bIsOleUpdate) override;
313
314
315
// XVisualObject
316
317
    virtual void SAL_CALL setVisualAreaSize( sal_Int64 nAspect, const css::awt::Size& aSize ) override;
318
319
    virtual css::awt::Size SAL_CALL getVisualAreaSize( sal_Int64 nAspect ) override;
320
321
    virtual css::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation( ::sal_Int64 nAspect ) override;
322
323
    virtual sal_Int32 SAL_CALL getMapUnit( sal_Int64 nAspect ) override;
324
325
// XEmbedPersist
326
327
    virtual void SAL_CALL setPersistentEntry(
328
                    const css::uno::Reference< css::embed::XStorage >& xStorage,
329
                    const OUString& sEntName,
330
                    sal_Int32 nEntryConnectionMode,
331
                    const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
332
                    const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
333
334
    virtual void SAL_CALL storeToEntry( const css::uno::Reference< css::embed::XStorage >& xStorage, const OUString& sEntName, const css::uno::Sequence< css::beans::PropertyValue >& lArguments, const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
335
336
    virtual void SAL_CALL storeAsEntry(
337
                const css::uno::Reference< css::embed::XStorage >& xStorage,
338
                const OUString& sEntName,
339
                const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
340
                const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
341
342
    virtual void SAL_CALL saveCompleted( sal_Bool bUseNew ) override;
343
344
    virtual sal_Bool SAL_CALL hasEntry() override;
345
346
    virtual OUString SAL_CALL getEntryName() override;
347
348
// XLinkageSupport
349
350
    virtual void SAL_CALL breakLink( const css::uno::Reference< css::embed::XStorage >& xStorage,
351
                                     const OUString& sEntName ) override;
352
353
    virtual sal_Bool SAL_CALL isLink() override;
354
355
    virtual OUString SAL_CALL getLinkURL() override;
356
357
358
// XCommonEmbedPersist
359
360
    virtual void SAL_CALL storeOwn() override;
361
362
    virtual sal_Bool SAL_CALL isReadonly() override;
363
364
    virtual void SAL_CALL reload(
365
                const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
366
                const css::uno::Sequence< css::beans::PropertyValue >& lObjArgs ) override;
367
368
// XEmbedPersist2
369
370
    virtual sal_Bool SAL_CALL isStored() override;
371
372
// XInplaceObject
373
374
    virtual void SAL_CALL setObjectRectangles( const css::awt::Rectangle& aPosRect,
375
                                          const css::awt::Rectangle& aClipRect ) override;
376
377
    virtual void SAL_CALL enableModeless( sal_Bool bEnable ) override;
378
379
    virtual void SAL_CALL translateAccelerators(
380
                    const css::uno::Sequence< css::awt::KeyEvent >& aKeys ) override;
381
382
// XClassifiedObject
383
384
    virtual css::uno::Sequence< sal_Int8 > SAL_CALL getClassID() override;
385
386
    virtual OUString SAL_CALL getClassName() override;
387
388
    virtual void SAL_CALL setClassInfo(
389
                const css::uno::Sequence< sal_Int8 >& aClassID, const OUString& aClassName ) override;
390
391
392
// XComponentSupplier
393
394
    virtual css::uno::Reference< css::util::XCloseable > SAL_CALL getComponent() override;
395
396
// XStateChangeBroadcaster
397
    virtual void SAL_CALL addStateChangeListener( const css::uno::Reference< css::embed::XStateChangeListener >& xListener ) override;
398
    virtual void SAL_CALL removeStateChangeListener( const css::uno::Reference< css::embed::XStateChangeListener >& xListener ) override;
399
400
// XCloseable
401
402
    virtual void SAL_CALL close( sal_Bool DeliverOwnership ) override;
403
404
    virtual void SAL_CALL addCloseListener(
405
                const css::uno::Reference< css::util::XCloseListener >& Listener ) override;
406
407
    virtual void SAL_CALL removeCloseListener(
408
                const css::uno::Reference< css::util::XCloseListener >& Listener ) override;
409
410
// XEventBroadcaster
411
    virtual void SAL_CALL addEventListener(
412
                const css::uno::Reference< css::document::XEventListener >& Listener ) override;
413
414
    virtual void SAL_CALL removeEventListener(
415
                const css::uno::Reference< css::document::XEventListener >& Listener ) override;
416
417
    // XChild
418
    virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent(  ) override;
419
    virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override;
420
421
    // XDefaultSizeTransmitter
422
    //#i103460# charts do not necessarily have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this method
423
    virtual void SAL_CALL setDefaultSize( const css::awt::Size& rSize_100TH_MM ) override;
424
425
    // XServiceInfo
426
    OUString SAL_CALL getImplementationName() override;
427
    sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
428
    css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
429
430
    // XInitialization
431
    void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
432
433
    // XTypeProvider
434
    css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() override;
435
    css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() override;
436
};
437
438
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */