1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_COMPHELPER_EMBEDDEDOBJECTCONTAINER_HXX
20 #define INCLUDED_COMPHELPER_EMBEDDEDOBJECTCONTAINER_HXX
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/uno/Sequence.h>
24 #include <comphelper/comphelperdllapi.h>
26 #include <rtl/ustring.hxx>
29 namespace com::sun::star::beans
{ struct PropertyValue
; }
30 namespace com::sun::star::embed
{ class XEmbeddedObject
; }
31 namespace com::sun::star::embed
{ class XStorage
; }
32 namespace com::sun::star::io
{ class XInputStream
; }
33 namespace com::sun::star::task
{ class XInteractionHandler
; }
34 namespace com::sun::star::uno
{ class XInterface
; }
38 class EmbeddedObjectContainer
;
39 /** Helper interface to give access to some common object which replace the SfxObjectShell
41 class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI IEmbeddedHelper
44 virtual EmbeddedObjectContainer
& getEmbeddedObjectContainer() const = 0;
45 virtual css::uno::Reference
< css::embed::XStorage
> getStorage() const = 0;
46 virtual css::uno::Reference
< css::task::XInteractionHandler
> getInteractionHandler() const = 0;
47 virtual bool isEnableSetModified() const = 0;
48 virtual OUString
getDocumentBaseURL() const = 0;
55 class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer
57 std::unique_ptr
<EmbedImpl
> pImpl
;
59 css::uno::Reference
< css::embed::XEmbeddedObject
> Get_Impl( const OUString
&,
60 const css::uno::Reference
< css::embed::XEmbeddedObject
>& xCopy
,
61 OUString
const* pBaseURL
);
64 // add an embedded object to the container storage
65 bool StoreEmbeddedObject(
66 const css::uno::Reference
<css::embed::XEmbeddedObject
>& xObj
, OUString
& rName
, bool bCopy
,
67 const OUString
& rSrcShellID
, const OUString
& rDestShellID
);
69 // add an embedded object that has been imported from the container storage - should only be called by filters!
70 void AddEmbeddedObject( const css::uno::Reference
< css::embed::XEmbeddedObject
>&, const OUString
& );
72 EmbeddedObjectContainer();
73 EmbeddedObjectContainer( const css::uno::Reference
< css::embed::XStorage
>& );
74 EmbeddedObjectContainer( const css::uno::Reference
< css::embed::XStorage
>&,
75 const css::uno::Reference
< css::uno::XInterface
>& );
76 ~EmbeddedObjectContainer();
78 void SwitchPersistence( const css::uno::Reference
< css::embed::XStorage
>& );
79 bool CommitImageSubStorage();
80 void ReleaseImageSubStorage();
82 OUString
CreateUniqueObjectName();
84 // get a list of object names that have been added so far
85 css::uno::Sequence
< OUString
> GetObjectNames() const;
87 // check for existence of objects at all
88 bool HasEmbeddedObjects() const;
90 // check existence of an object - either by identity or by name
91 bool HasEmbeddedObject( const OUString
& );
92 bool HasEmbeddedObject( const css::uno::Reference
< css::embed::XEmbeddedObject
>& ) const;
93 bool HasInstantiatedEmbeddedObject( const OUString
& );
95 // get the object name of an object - this is the persist name if the object has persistence
96 OUString
GetEmbeddedObjectName( const css::uno::Reference
< css::embed::XEmbeddedObject
>& ) const;
98 // retrieve an embedded object by name that either has been added already or is available in the container storage
99 css::uno::Reference
<css::embed::XEmbeddedObject
> GetEmbeddedObject(const OUString
&, OUString
const* pBaseURL
= nullptr);
101 // create an object from a ClassId
102 css::uno::Reference
< css::embed::XEmbeddedObject
>
103 CreateEmbeddedObject( const css::uno::Sequence
< sal_Int8
>&, OUString
&,
104 OUString
const* pBaseURL
= nullptr );
106 css::uno::Reference
< css::embed::XEmbeddedObject
>
107 CreateEmbeddedObject( const css::uno::Sequence
< sal_Int8
>&,
108 const css::uno::Sequence
< css::beans::PropertyValue
>&, OUString
&,
109 OUString
const* pBaseURL
= nullptr );
111 // insert an embedded object into the container - objects persistent representation will be added to the storage
112 bool InsertEmbeddedObject( const css::uno::Reference
< css::embed::XEmbeddedObject
>&, OUString
& );
114 // load an embedded object from a MediaDescriptor and insert it into the container
115 // a new object will be created from the new content and returned
116 css::uno::Reference
< css::embed::XEmbeddedObject
>
117 InsertEmbeddedObject( const css::uno::Sequence
< css::beans::PropertyValue
>&, OUString
& rName
, OUString
const* pBaseURL
= nullptr);
119 // create an embedded link based on a MediaDescriptor and insert it into the container
120 // a new object will be created from the new content and returned
121 css::uno::Reference
< css::embed::XEmbeddedObject
>
122 InsertEmbeddedLink( const css::uno::Sequence
< css::beans::PropertyValue
>&, OUString
& );
124 // create an object from a stream that contains its persistent representation and insert it as usual (usually called from clipboard)
125 // a new object will be created from the new content and returned
126 css::uno::Reference
< css::embed::XEmbeddedObject
>
127 InsertEmbeddedObject( const css::uno::Reference
< css::io::XInputStream
>&, OUString
& );
129 // copy an embedded object into the storage, open the new copy and return it
130 css::uno::Reference
<css::embed::XEmbeddedObject
> CopyAndGetEmbeddedObject(
131 EmbeddedObjectContainer
& rSrc
, const css::uno::Reference
<css::embed::XEmbeddedObject
>& xObj
, OUString
& rName
,
132 const OUString
& rSrcShellID
, const OUString
& rDestShellID
);
134 // remove an embedded object from the container and from the storage; if object can't be closed
135 // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
136 void RemoveEmbeddedObject( const OUString
& rName
, bool bKeepToTempStorage
= true);
137 bool RemoveEmbeddedObject( const css::uno::Reference
< css::embed::XEmbeddedObject
>&, bool bKeepToTempStorage
= true);
139 // close and remove an embedded object from the container without removing it from the storage
140 void CloseEmbeddedObject( const css::uno::Reference
< css::embed::XEmbeddedObject
>& );
142 // move an embedded object to another container (keep the persistent name)
143 bool MoveEmbeddedObject( const OUString
& rName
, EmbeddedObjectContainer
& );
145 // get the stored graphical representation for the object
146 css::uno::Reference
< css::io::XInputStream
> GetGraphicStream( const css::uno::Reference
< css::embed::XEmbeddedObject
>&, OUString
* pMediaType
=nullptr );
148 // get the stored graphical representation by the object name
149 css::uno::Reference
< css::io::XInputStream
> GetGraphicStream( const OUString
& aName
, OUString
* pMediaType
=nullptr );
151 // add a graphical representation for an object
152 bool InsertGraphicStream( const css::uno::Reference
< css::io::XInputStream
>& rStream
, const OUString
& rObjectName
, const OUString
& rMediaType
);
154 // try to add a graphical representation for an object in optimized way ( might fail )
155 bool InsertGraphicStreamDirectly( const css::uno::Reference
< css::io::XInputStream
>& rStream
, const OUString
& rObjectName
, const OUString
& rMediaType
);
157 // remove a graphical representation for an object
158 void RemoveGraphicStream( const OUString
& rObjectName
);
160 // copy the graphical representation from different container
161 bool TryToCopyGraphReplacement( EmbeddedObjectContainer
& rSrc
,
162 const OUString
& aOrigName
,
163 const OUString
& aTargetName
);
165 void CloseEmbeddedObjects();
166 bool StoreChildren(bool _bOasisFormat
,bool _bObjectsOnly
);
167 bool StoreAsChildren( bool _bOasisFormat
168 ,bool _bCreateEmbedded
169 ,bool _bAutoSaveEvent
170 ,const css::uno::Reference
< css::embed::XStorage
>& _xStorage
);
172 static css::uno::Reference
< css::io::XInputStream
> GetGraphicReplacementStream(
173 sal_Int64 nViewAspect
,
174 const css::uno::Reference
< css::embed::XEmbeddedObject
>&,
175 OUString
* pMediaType
);
177 /** call setPersistentEntry for each embedded object in the container
179 * \param _xStorage The storage where to store the objects.
180 * \param _bClearModifiedFlag If <TRUE/> then the modified flag will be set to <FALSE/> otherwise nothing happen.
181 * \return <FALSE/> if no error occurred, otherwise <TRUE/>.
183 bool SetPersistentEntries(const css::uno::Reference
< css::embed::XStorage
>& _xStorage
,bool _bClearModifiedFlag
= true);
185 // if DisableActiveContent configuration option is set, this always returns false
186 bool getUserAllowsLinkUpdate() const;
188 // if DisableActiveContent configuration option is set, this has no effect
189 void setUserAllowsLinkUpdate(bool bNew
);
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */