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