Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / comphelper / embeddedobjectcontainer.hxx
blobaf548adbb578120759ddcc04e3c4eaa91e330024
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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.hxx>
24 #include <com/sun/star/embed/XEmbeddedObject.hpp>
25 #include <com/sun/star/task/XInteractionHandler.hpp>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <com/sun/star/io/XInputStream.hpp>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <comphelper/comphelperdllapi.h>
32 #include <rtl/ustring.hxx>
33 #include <memory>
35 namespace comphelper
37 class EmbeddedObjectContainer;
38 /** Helper interface to give access to some common object which replace the SfxObjectShell
40 class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI IEmbeddedHelper
42 public:
43 virtual EmbeddedObjectContainer& getEmbeddedObjectContainer() const = 0;
44 virtual css::uno::Reference < css::embed::XStorage > getStorage() const = 0;
45 virtual css::uno::Reference< css::task::XInteractionHandler > getInteractionHandler() const = 0;
46 virtual bool isEnableSetModified() const = 0;
47 virtual OUString getDocumentBaseURL() const = 0;
49 protected:
50 ~IEmbeddedHelper() {}
53 struct EmbedImpl;
54 class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer
56 std::unique_ptr<EmbedImpl> pImpl;
58 css::uno::Reference < css::embed::XEmbeddedObject > Get_Impl( const OUString&,
59 const css::uno::Reference < css::embed::XEmbeddedObject >& xCopy,
60 OUString const* pBaseURL);
62 public:
63 // add an embedded object to the container storage
64 bool StoreEmbeddedObject(
65 const css::uno::Reference<css::embed::XEmbeddedObject>& xObj, OUString& rName, bool bCopy,
66 const OUString& rSrcShellID, const OUString& rDestShellID );
68 // add an embedded object that has been imported from the container storage - should only be called by filters!
69 void AddEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >&, const OUString& );
71 EmbeddedObjectContainer();
72 EmbeddedObjectContainer( const css::uno::Reference < css::embed::XStorage >& );
73 EmbeddedObjectContainer( const css::uno::Reference < css::embed::XStorage >&,
74 const css::uno::Reference < css::uno::XInterface >& );
75 ~EmbeddedObjectContainer();
77 void SwitchPersistence( const css::uno::Reference < css::embed::XStorage >& );
78 bool CommitImageSubStorage();
79 void ReleaseImageSubStorage();
81 OUString CreateUniqueObjectName();
83 // get a list of object names that have been added so far
84 css::uno::Sequence < OUString > GetObjectNames();
86 // check for existence of objects at all
87 bool HasEmbeddedObjects();
89 // check existence of an object - either by identity or by name
90 bool HasEmbeddedObject( const OUString& );
91 bool HasEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >& );
92 bool HasInstantiatedEmbeddedObject( const OUString& );
94 // get the object name of an object - this is the persist name if the object has persistence
95 OUString GetEmbeddedObjectName( const css::uno::Reference < css::embed::XEmbeddedObject >& );
97 // retrieve an embedded object by name that either has been added already or is available in the container storage
98 css::uno::Reference<css::embed::XEmbeddedObject> GetEmbeddedObject(const OUString&, OUString const* pBaseURL = nullptr);
100 // create an object from a ClassId
101 css::uno::Reference < css::embed::XEmbeddedObject >
102 CreateEmbeddedObject( const css::uno::Sequence < sal_Int8 >&, OUString&,
103 OUString const* pBaseURL = nullptr );
105 css::uno::Reference < css::embed::XEmbeddedObject >
106 CreateEmbeddedObject( const css::uno::Sequence < sal_Int8 >&,
107 const css::uno::Sequence < css::beans::PropertyValue >&, OUString&,
108 OUString const* pBaseURL = nullptr );
110 // insert an embedded object into the container - objects persistent representation will be added to the storage
111 bool InsertEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >&, OUString& );
113 // load an embedded object from a MediaDescriptor and insert it into the container
114 // a new object will be created from the new content and returned
115 css::uno::Reference < css::embed::XEmbeddedObject >
116 InsertEmbeddedObject( const css::uno::Sequence < css::beans::PropertyValue >&, OUString& rName, OUString const* pBaseURL = nullptr);
118 // create an embedded link based on 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 >
121 InsertEmbeddedLink( const css::uno::Sequence < css::beans::PropertyValue >&, OUString& );
123 // create an object from a stream that contains its persistent representation and insert it as usual (usually called from clipboard)
124 // a new object will be created from the new content and returned
125 css::uno::Reference < css::embed::XEmbeddedObject >
126 InsertEmbeddedObject( const css::uno::Reference < css::io::XInputStream >&, OUString& );
128 // copy an embedded object into the storage, open the new copy and return it
129 css::uno::Reference <css::embed::XEmbeddedObject> CopyAndGetEmbeddedObject(
130 EmbeddedObjectContainer& rSrc, const css::uno::Reference <css::embed::XEmbeddedObject>& xObj, OUString& rName,
131 const OUString& rSrcShellID, const OUString& rDestShellID );
133 // move an embedded object from one container to another one
134 bool MoveEmbeddedObject( EmbeddedObjectContainer& rSrc, const css::uno::Reference < css::embed::XEmbeddedObject >&, OUString& );
136 // remove an embedded object from the container and from the storage; if object can't be closed
137 // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
138 bool RemoveEmbeddedObject( const OUString& rName, bool bKeepToTempStorage = true);
139 bool RemoveEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >&, bool bKeepToTempStorage = true);
141 // close and remove an embedded object from the container without removing it from the storage
142 bool CloseEmbeddedObject( const css::uno::Reference < css::embed::XEmbeddedObject >& );
144 // move an embedded object to another container (keep the persistent name)
145 bool MoveEmbeddedObject( const OUString& rName, EmbeddedObjectContainer& );
147 // get the stored graphical representation for the object
148 css::uno::Reference < css::io::XInputStream > GetGraphicStream( const css::uno::Reference < css::embed::XEmbeddedObject >&, OUString* pMediaType=nullptr );
150 // get the stored graphical representation by the object name
151 css::uno::Reference < css::io::XInputStream > GetGraphicStream( const OUString& aName, OUString* pMediaType=nullptr );
153 // add a graphical representation for an object
154 bool InsertGraphicStream( const css::uno::Reference < css::io::XInputStream >& rStream, const OUString& rObjectName, const OUString& rMediaType );
156 // try to add a graphical representation for an object in optimized way ( might fail )
157 bool InsertGraphicStreamDirectly( const css::uno::Reference < css::io::XInputStream >& rStream, const OUString& rObjectName, const OUString& rMediaType );
159 // remove a graphical representation for an object
160 bool RemoveGraphicStream( const OUString& rObjectName );
162 // copy the graphical representation from different container
163 bool TryToCopyGraphReplacement( EmbeddedObjectContainer& rSrc,
164 const OUString& aOrigName,
165 const OUString& aTargetName );
167 void CloseEmbeddedObjects();
168 bool StoreChildren(bool _bOasisFormat,bool _bObjectsOnly);
169 bool StoreAsChildren( bool _bOasisFormat
170 ,bool _bCreateEmbedded
171 ,const css::uno::Reference < css::embed::XStorage >& _xStorage);
173 static css::uno::Reference< css::io::XInputStream > GetGraphicReplacementStream(
174 sal_Int64 nViewAspect,
175 const css::uno::Reference < css::embed::XEmbeddedObject >&,
176 OUString* pMediaType );
178 /** call setPersistentEntry for each embedded object in the container
180 * \param _xStorage The storage where to store the objects.
181 * \param _bClearModifedFlag If <TRUE/> then the modified flag will be set to <FALSE/> otherwise nothing happen.
182 * \return <FALSE/> if no error occurred, otherwise <TRUE/>.
184 bool SetPersistentEntries(const css::uno::Reference< css::embed::XStorage >& _xStorage,bool _bClearModifedFlag = true);
186 bool getUserAllowsLinkUpdate() const;
187 void setUserAllowsLinkUpdate(bool bNew);
192 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */