1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _COMPHELPER_OBJECTCONTAINER_HXX_
25 #define _COMPHELPER_OBJECTCONTAINER_HXX_
26 
27 #include <com/sun/star/uno/Reference.h>
28 #include <com/sun/star/uno/Sequence.hxx>
29 #include <com/sun/star/embed/XEmbeddedObject.hpp>
30 #include <com/sun/star/task/XInteractionHandler.hpp>
31 #include <com/sun/star/embed/XStorage.hpp>
32 #include <com/sun/star/io/XInputStream.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/frame/XModel.hpp>
35 #include "comphelper/comphelperdllapi.h"
36 
37 #include <rtl/ustring.hxx>
38 
39 namespace comphelper
40 {
41     class EmbeddedObjectContainer;
42     /** Helper interface to give access to some common object which replace the SfxObjectShell
43     */
44     class SAL_NO_VTABLE IEmbeddedHelper
45     {
46     public:
47         virtual EmbeddedObjectContainer& getEmbeddedObjectContainer() const = 0;
48         virtual com::sun::star::uno::Reference < com::sun::star::embed::XStorage > getStorage() const = 0;
49         virtual ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > getInteractionHandler() const = 0;
50         virtual bool isEnableSetModified() const = 0;
51     };
52 
53 struct EmbedImpl;
54 class COMPHELPER_DLLPUBLIC EmbeddedObjectContainer
55 {
56     EmbedImpl*  pImpl;
57 
58     ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > Get_Impl( const ::rtl::OUString&,
59             const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xCopy);
60 
61 public:
62     // add an embedded object to the container storage
63     sal_Bool            StoreEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::OUString&, sal_Bool );
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 ::rtl::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 	sal_Bool			CommitImageSubStorage();
76 	void				ReleaseImageSubStorage();
77 
78     ::rtl::OUString     CreateUniqueObjectName();
79 
80     // get a list of object names that have been added so far
81     com::sun::star::uno::Sequence < ::rtl::OUString > GetObjectNames();
82 
83     // check for existence of objects at all
84     sal_Bool            HasEmbeddedObjects();
85 
86     // check existence of an object - either by identity or by name
87     sal_Bool            HasEmbeddedObject( const ::rtl::OUString& );
88     sal_Bool            HasEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& );
89     sal_Bool            HasInstantiatedEmbeddedObject( const ::rtl::OUString& );
90 
91     // get the object name of an object - this is the persist name if the object has persistence
92     ::rtl::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 ::rtl::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 >&, ::rtl::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 >&, ::rtl::OUString& );
104 
105     // insert an embedded object into the container - objects persistent representation will be added to the storage
106     sal_Bool            InsertEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::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 >&, ::rtl::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 >&, ::rtl::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 >&, ::rtl::OUString& );
122 
123     // copy an embedded object into the storage
124     sal_Bool CopyEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::OUString& );
125 
126 	// copy an embedded object into the storage, open the new copy and return it
127 	::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > CopyAndGetEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& xObj, /* TODO const ::rtl::OUString& aOrigName,*/ ::rtl::OUString& rName );
128 
129     // move an embedded object from one container to another one
130     sal_Bool MoveEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::OUString& );
131  // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
132 sal_Bool            RemoveEmbeddedObject( const ::rtl::OUString& rName, sal_Bool bClose = sal_True, sal_Bool bKeepToTempStorage = sal_True );
133 sal_Bool            RemoveEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, sal_Bool bClose = sal_True, sal_Bool bKeepToTempStorage = sal_True );
134     // remove an embedded object from the container and from the storage; if object can't be closed
135     //sal_Bool            RemoveEmbeddedObject( const ::rtl::OUString& rName, sal_Bool bClose=sal_True );
136     //sal_Bool            RemoveEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, sal_Bool bClose=sal_True );
137 
138 	// close and remove an embedded object from the container without removing it from the storage
139     sal_Bool            CloseEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& );
140 
141     // move an embedded object to another container (keep the persistent name)
142     sal_Bool            MoveEmbeddedObject( const ::rtl::OUString& rName, EmbeddedObjectContainer& );
143 
144     // get the stored graphical representation for the object
145     com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetGraphicStream( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, ::rtl::OUString* pMediaType=0 );
146 
147     // get the stored graphical representation by the object name
148     com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetGraphicStream( const ::rtl::OUString& aName, ::rtl::OUString* pMediaType=0 );
149 
150     // add a graphical representation for an object
151     sal_Bool            InsertGraphicStream( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream, const ::rtl::OUString& rObjectName, const ::rtl::OUString& rMediaType );
152 
153     // try to add a graphical representation for an object in optimized way (might fail)
154 	sal_Bool			InsertGraphicStreamDirectly( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream, const ::rtl::OUString& rObjectName, const rtl::OUString& rMediaType );
155 
156     // remove a graphical representation for an object
157     sal_Bool            RemoveGraphicStream( const ::rtl::OUString& rObjectName );
158 
159 	// copy the graphical representation from different container
160 	sal_Bool			TryToCopyGraphReplacement( EmbeddedObjectContainer& rSrc,
161 													const ::rtl::OUString& aOrigName,
162 													const ::rtl::OUString& aTargetName );
163 
164     void                CloseEmbeddedObjects();
165     sal_Bool            StoreChildren(sal_Bool _bOasisFormat,sal_Bool _bObjectsOnly);
166     sal_Bool            StoreAsChildren( sal_Bool _bOasisFormat
167                                         ,sal_Bool _bCreateEmbedded
168                                         ,const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& _xStorage);
169 
170     static com::sun::star::uno::Reference< com::sun::star::io::XInputStream > GetGraphicReplacementStream(
171 											sal_Int64 nViewAspect,
172 											const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >&,
173 											::rtl::OUString* pMediaType );
174 
175     /** call setPersistentEntry for each embedded object in the container
176     *
177     * \param _xStorage The storage where to store the objects.
178     * \param _bClearModifedFlag If <TRUE/> then the modified flag will be set to <FALSE/> otherwise nothing happen.
179     * \return <FALSE/> if no error occurred, otherwise <TRUE/>.
180     */
181     sal_Bool             SetPersistentEntries(const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& _xStorage,bool _bClearModifedFlag = true);
182 
183     bool getUserAllowsLinkUpdate() const;
184     void setUserAllowsLinkUpdate(bool bNew);
185 };
186 
187 }
188 
189 #endif
190 
191