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 0 : 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 0 : ~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( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString&, bool );
62 :
63 : // add an embedded object that has been imported from the container storage - should only be called by filters!
64 : void AddEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, const OUString& );
65 :
66 : EmbeddedObjectContainer();
67 : EmbeddedObjectContainer( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& );
68 : EmbeddedObjectContainer( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >&,
69 : const com::sun::star::uno::Reference < com::sun::star::uno::XInterface >& );
70 : ~EmbeddedObjectContainer();
71 :
72 : void SwitchPersistence( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& );
73 : bool CommitImageSubStorage();
74 : void ReleaseImageSubStorage();
75 :
76 : OUString CreateUniqueObjectName();
77 :
78 : // get a list of object names that have been added so far
79 : com::sun::star::uno::Sequence < OUString > GetObjectNames();
80 :
81 : // check for existence of objects at all
82 : bool HasEmbeddedObjects();
83 :
84 : // check existence of an object - either by identity or by name
85 : bool HasEmbeddedObject( const OUString& );
86 : bool HasEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& );
87 : bool HasInstantiatedEmbeddedObject( const OUString& );
88 :
89 : // get the object name of an object - this is the persist name if the object has persistence
90 : OUString GetEmbeddedObjectName( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& );
91 :
92 : // retrieve an embedded object by name that either has been added already or is available in the container storage
93 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject > GetEmbeddedObject( const OUString& );
94 :
95 : // create an object from a ClassId
96 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >
97 : CreateEmbeddedObject( const com::sun::star::uno::Sequence < sal_Int8 >&, OUString& );
98 :
99 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >
100 : CreateEmbeddedObject( const com::sun::star::uno::Sequence < sal_Int8 >&,
101 : const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >&, OUString& );
102 :
103 : // insert an embedded object into the container - objects persistent representation will be added to the storage
104 : bool InsertEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString& );
105 :
106 : // load an embedded object from a MediaDescriptor and insert it into the container
107 : // a new object will be created from the new content and returned
108 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >
109 : InsertEmbeddedObject( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, OUString& );
110 :
111 : // create an embedded link based on a MediaDescriptor and insert it into the container
112 : // a new object will be created from the new content and returned
113 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >
114 : InsertEmbeddedLink( const ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue >&, OUString& );
115 :
116 : // create an object from a stream that contains its persistent representation and insert it as usual (usually called from clipboard)
117 : // a new object will be created from the new content and returned
118 : ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >
119 : InsertEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >&, OUString& );
120 :
121 : // copy an embedded object into the storage, open the new copy and return it
122 : ::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 OUString& aOrigName,*/ OUString& rName );
123 :
124 : // move an embedded object from one container to another one
125 : bool MoveEmbeddedObject( EmbeddedObjectContainer& rSrc, const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, OUString& );
126 :
127 : // remove an embedded object from the container and from the storage; if object can't be closed
128 : // #i119941, bKeepToTempStorage: use to specify whether store the removed object to temporary storage+
129 : bool RemoveEmbeddedObject( const OUString& rName, bool bClose = true, bool bKeepToTempStorage = true );
130 : bool RemoveEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >&, bool bClose = true, bool bKeepToTempStorage = true );
131 :
132 : // close and remove an embedded object from the container without removing it from the storage
133 : bool CloseEmbeddedObject( const ::com::sun::star::uno::Reference < ::com::sun::star::embed::XEmbeddedObject >& );
134 :
135 : // move an embedded object to another container (keep the persistent name)
136 : bool MoveEmbeddedObject( const OUString& rName, EmbeddedObjectContainer& );
137 :
138 : // get the stored representation for the object
139 : 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 );
140 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetObjectStream( const OUString& aName, OUString* pMediaType );
141 :
142 : // get the stored graphical representation for the object
143 : 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 );
144 :
145 : // get the stored graphical representation by the object name
146 : com::sun::star::uno::Reference < com::sun::star::io::XInputStream > GetGraphicStream( const OUString& aName, OUString* pMediaType=0 );
147 :
148 : // add a graphical representation for an object
149 : bool InsertGraphicStream( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream, const OUString& rObjectName, const OUString& rMediaType );
150 :
151 : // try to add a graphical representation for an object in optimized way ( might fail )
152 : bool InsertGraphicStreamDirectly( const com::sun::star::uno::Reference < com::sun::star::io::XInputStream >& rStream, const OUString& rObjectName, const OUString& rMediaType );
153 :
154 : // remove a graphical representation for an object
155 : bool RemoveGraphicStream( const OUString& rObjectName );
156 :
157 : // copy the graphical representation from different container
158 : bool TryToCopyGraphReplacement( EmbeddedObjectContainer& rSrc,
159 : const OUString& aOrigName,
160 : const OUString& aTargetName );
161 :
162 : void CloseEmbeddedObjects();
163 : bool StoreChildren(bool _bOasisFormat,bool _bObjectsOnly);
164 : bool StoreAsChildren( bool _bOasisFormat
165 : ,bool _bCreateEmbedded
166 : ,const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& _xStorage);
167 :
168 : static com::sun::star::uno::Reference< com::sun::star::io::XInputStream > GetGraphicReplacementStream(
169 : sal_Int64 nViewAspect,
170 : const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >&,
171 : OUString* pMediaType );
172 :
173 : /** call setPersistentEntry for each embedded object in the container
174 : *
175 : * \param _xStorage The storeage where to store the objects.
176 : * \param _bClearModifedFlag If <TRUE/> then the modified flag will be set to <FALSE/> otherwise nothing happen.
177 : * \return <FALSE/> if no error occurred, otherwise <TRUE/>.
178 : */
179 : bool SetPersistentEntries(const com::sun::star::uno::Reference< com::sun::star::embed::XStorage >& _xStorage,bool _bClearModifedFlag = true);
180 : };
181 :
182 : }
183 :
184 : #endif
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|