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