Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / source / msole / xolefactory.cxx
blob6545bdb6b895c48c4b5ada4b5c10b6e015954319
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 .
20 #include <com/sun/star/embed/ElementModes.hpp>
21 #include <com/sun/star/embed/EntryInitModes.hpp>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/embed/Aspects.hpp>
27 #include "xolefactory.hxx"
28 #include "oleembobj.hxx"
30 #include <cppuhelper/supportsservice.hxx>
32 using namespace ::com::sun::star;
34 // TODO: do not create OLE objects that represent OOo documents
36 //-------------------------------------------------------------------------
37 uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::impl_staticGetSupportedServiceNames()
39 uno::Sequence< OUString > aRet(2);
40 aRet[0] = "com.sun.star.embed.OLEEmbeddedObjectFactory";
41 aRet[1] = "com.sun.star.comp.embed.OLEEmbeddedObjectFactory";
42 return aRet;
45 //-------------------------------------------------------------------------
46 OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
48 return OUString("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
51 //-------------------------------------------------------------------------
52 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::impl_staticCreateSelfInstance(
53 const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
55 return uno::Reference< uno::XInterface >( *new OleEmbeddedObjectFactory( xServiceManager ) );
58 //-------------------------------------------------------------------------
59 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromEntry(
60 const uno::Reference< embed::XStorage >& xStorage,
61 const OUString& sEntName,
62 const uno::Sequence< beans::PropertyValue >& aMedDescr,
63 const uno::Sequence< beans::PropertyValue >& lObjArgs )
64 throw ( lang::IllegalArgumentException,
65 container::NoSuchElementException,
66 io::IOException,
67 uno::Exception,
68 uno::RuntimeException)
70 SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
72 if ( !xStorage.is() )
73 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
74 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
75 1 );
77 if ( sEntName.isEmpty() )
78 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
79 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
80 2 );
82 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
83 if ( !xNameAccess.is() )
84 throw uno::RuntimeException(); //TODO
86 // detect entry existence
87 if ( !xNameAccess->hasByName( sEntName ) )
88 throw container::NoSuchElementException();
90 if ( !xStorage->isStreamElement( sEntName ) )
92 // if it is not an OLE object throw an exception
93 throw io::IOException(); // TODO:
96 uno::Reference< uno::XInterface > xResult(
97 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
98 uno::UNO_QUERY );
100 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
102 if ( !xPersist.is() )
103 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
105 xPersist->setPersistentEntry( xStorage,
106 sEntName,
107 embed::EntryInitModes::DEFAULT_INIT,
108 aMedDescr,
109 lObjArgs );
111 for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
113 if ( lObjArgs[nInd].Name == "CloneFrom" )
117 uno::Reference < embed::XEmbeddedObject > xObj;
118 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
119 lObjArgs[nInd].Value >>= xObj;
120 if ( xObj.is() )
121 xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
123 catch ( const uno::Exception& ) {}
124 break;
128 return xResult;
131 //-------------------------------------------------------------------------
132 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
133 const uno::Reference< embed::XStorage >& xStorage,
134 const OUString& sEntName,
135 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
136 const uno::Sequence< beans::PropertyValue >& lObjArgs )
137 throw ( lang::IllegalArgumentException,
138 io::IOException,
139 uno::Exception,
140 uno::RuntimeException)
142 SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor" );
144 if ( !xStorage.is() )
145 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
146 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
147 1 );
149 if ( sEntName.isEmpty() )
150 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
151 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
152 2 );
154 uno::Reference< uno::XInterface > xResult(
155 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_False ) ),
156 uno::UNO_QUERY );
158 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
160 if ( !xPersist.is() )
161 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
163 xPersist->setPersistentEntry( xStorage,
164 sEntName,
165 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
166 aMediaDescr,
167 lObjArgs );
169 return xResult;
172 //-------------------------------------------------------------------------
173 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
174 const uno::Sequence< sal_Int8 >& aClassID,
175 const OUString& aClassName,
176 const uno::Reference< embed::XStorage >& xStorage,
177 const OUString& sEntName,
178 const uno::Sequence< beans::PropertyValue >& lObjArgs )
179 throw ( lang::IllegalArgumentException,
180 io::IOException,
181 uno::Exception,
182 uno::RuntimeException)
184 SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitNew" );
186 if ( !xStorage.is() )
187 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
188 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
189 3 );
191 if ( sEntName.isEmpty() )
192 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
193 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
194 4 );
196 uno::Reference< uno::XInterface > xResult(
197 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
198 uno::UNO_QUERY );
200 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
202 if ( !xPersist.is() )
203 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
205 xPersist->setPersistentEntry( xStorage,
206 sEntName,
207 embed::EntryInitModes::TRUNCATE_INIT,
208 uno::Sequence< beans::PropertyValue >(),
209 lObjArgs );
211 return xResult;
214 //-------------------------------------------------------------------------
215 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
216 const uno::Reference< embed::XStorage >& xStorage,
217 const OUString& sEntName,
218 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
219 const uno::Sequence< beans::PropertyValue >& lObjArgs )
220 throw ( lang::IllegalArgumentException,
221 io::IOException,
222 uno::Exception,
223 uno::RuntimeException )
225 SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceLink" );
227 if ( !xStorage.is() )
228 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
229 uno::Reference< uno::XInterface >(
230 static_cast< ::cppu::OWeakObject* >(this) ),
231 1 );
233 if ( sEntName.isEmpty() )
234 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
235 uno::Reference< uno::XInterface >(
236 static_cast< ::cppu::OWeakObject* >(this) ),
237 2 );
239 uno::Reference< uno::XInterface > xResult(
240 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, sal_True ) ),
241 uno::UNO_QUERY );
243 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
245 if ( !xPersist.is() )
246 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
248 xPersist->setPersistentEntry( xStorage,
249 sEntName,
250 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
251 aMediaDescr,
252 lObjArgs );
254 return xResult;
257 //-------------------------------------------------------------------------
258 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
259 const uno::Sequence< sal_Int8 >& aClassID,
260 const OUString& aClassName,
261 const uno::Reference< embed::XStorage >& xStorage,
262 const OUString& sEntName,
263 sal_Int32 /*nEntryConnectionMode*/,
264 const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
265 const uno::Sequence< beans::PropertyValue >& lObjArgs )
266 throw ( lang::IllegalArgumentException,
267 io::IOException,
268 uno::Exception,
269 uno::RuntimeException )
271 SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceUserInit" );
273 // the initialization is completelly controlled by user
274 if ( !xStorage.is() )
275 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
276 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
277 1 );
279 if ( sEntName.isEmpty() )
280 throw lang::IllegalArgumentException( OUString( "Empty element name is provided!\n" ),
281 uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
282 2 );
284 uno::Reference< uno::XInterface > xResult(
285 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
286 uno::UNO_QUERY );
288 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
289 if ( xPersist.is() )
291 xPersist->setPersistentEntry( xStorage,
292 sEntName,
293 embed::EntryInitModes::DEFAULT_INIT,
294 uno::Sequence< beans::PropertyValue >(),
295 lObjArgs );
298 else
299 throw uno::RuntimeException(); // TODO:
301 return xResult;
304 //-------------------------------------------------------------------------
305 OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
306 throw ( uno::RuntimeException )
308 return impl_staticGetImplementationName();
311 sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const OUString& ServiceName )
312 throw ( uno::RuntimeException )
314 return cppu::supportsService(this, ServiceName);
317 //-------------------------------------------------------------------------
318 uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
319 throw ( uno::RuntimeException )
321 return impl_staticGetSupportedServiceNames();
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */