fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / embeddedobj / source / msole / xolefactory.cxx
blobdd969e729f4e7a719698583d293de2f3e14510a8
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
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;
46 OUString SAL_CALL OleEmbeddedObjectFactory::impl_staticGetImplementationName()
48 return OUString("com.sun.star.comp.embed.OLEEmbeddedObjectFactory");
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 ) );
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, std::exception)
70 if ( !xStorage.is() )
71 throw lang::IllegalArgumentException( "No parent storage is provided!",
72 static_cast< ::cppu::OWeakObject* >(this),
73 1 );
75 if ( sEntName.isEmpty() )
76 throw lang::IllegalArgumentException( "Empty element name is provided!",
77 static_cast< ::cppu::OWeakObject* >(this),
78 2 );
80 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY );
81 if ( !xNameAccess.is() )
82 throw uno::RuntimeException(); //TODO
84 // detect entry existence
85 if ( !xNameAccess->hasByName( sEntName ) )
86 throw container::NoSuchElementException();
88 if ( !xStorage->isStreamElement( sEntName ) )
90 // if it is not an OLE object throw an exception
91 throw io::IOException(); // TODO:
94 uno::Reference< uno::XInterface > xResult(
95 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, false ) ),
96 uno::UNO_QUERY );
98 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
100 if ( !xPersist.is() )
101 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
103 xPersist->setPersistentEntry( xStorage,
104 sEntName,
105 embed::EntryInitModes::DEFAULT_INIT,
106 aMedDescr,
107 lObjArgs );
109 for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ )
111 if ( lObjArgs[nInd].Name == "CloneFrom" )
115 uno::Reference < embed::XEmbeddedObject > xObj;
116 uno::Reference < embed::XEmbeddedObject > xNew( xResult, uno::UNO_QUERY );
117 lObjArgs[nInd].Value >>= xObj;
118 if ( xObj.is() )
119 xNew->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, xObj->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ) );
121 catch ( const uno::Exception& ) {}
122 break;
126 return xResult;
130 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitFromMediaDescriptor(
131 const uno::Reference< embed::XStorage >& xStorage,
132 const OUString& sEntName,
133 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
134 const uno::Sequence< beans::PropertyValue >& lObjArgs )
135 throw ( lang::IllegalArgumentException,
136 io::IOException,
137 uno::Exception,
138 uno::RuntimeException, std::exception)
140 if ( !xStorage.is() )
141 throw lang::IllegalArgumentException( "No parent storage is provided!",
142 static_cast< ::cppu::OWeakObject* >(this),
143 1 );
145 if ( sEntName.isEmpty() )
146 throw lang::IllegalArgumentException( "Empty element name is provided!",
147 static_cast< ::cppu::OWeakObject* >(this),
148 2 );
150 uno::Reference< uno::XInterface > xResult(
151 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, false ) ),
152 uno::UNO_QUERY );
154 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
156 if ( !xPersist.is() )
157 throw uno::RuntimeException(); // TODO: the interface must be supported ( what about applets? )
159 xPersist->setPersistentEntry( xStorage,
160 sEntName,
161 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
162 aMediaDescr,
163 lObjArgs );
165 return xResult;
169 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceInitNew(
170 const uno::Sequence< sal_Int8 >& aClassID,
171 const OUString& aClassName,
172 const uno::Reference< embed::XStorage >& xStorage,
173 const OUString& sEntName,
174 const uno::Sequence< beans::PropertyValue >& lObjArgs )
175 throw ( lang::IllegalArgumentException,
176 io::IOException,
177 uno::Exception,
178 uno::RuntimeException, std::exception)
180 if ( !xStorage.is() )
181 throw lang::IllegalArgumentException( "No parent storage is provided!",
182 static_cast< ::cppu::OWeakObject* >(this),
183 3 );
185 if ( sEntName.isEmpty() )
186 throw lang::IllegalArgumentException( "Empty element name is provided!",
187 static_cast< ::cppu::OWeakObject* >(this),
188 4 );
190 uno::Reference< uno::XInterface > xResult(
191 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
192 uno::UNO_QUERY );
194 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
196 if ( !xPersist.is() )
197 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
199 xPersist->setPersistentEntry( xStorage,
200 sEntName,
201 embed::EntryInitModes::TRUNCATE_INIT,
202 uno::Sequence< beans::PropertyValue >(),
203 lObjArgs );
205 return xResult;
209 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceLink(
210 const uno::Reference< embed::XStorage >& xStorage,
211 const OUString& sEntName,
212 const uno::Sequence< beans::PropertyValue >& aMediaDescr,
213 const uno::Sequence< beans::PropertyValue >& lObjArgs )
214 throw ( lang::IllegalArgumentException,
215 io::IOException,
216 uno::Exception,
217 uno::RuntimeException, std::exception )
219 if ( !xStorage.is() )
220 throw lang::IllegalArgumentException( "No parent storage is provided!",
221 static_cast< ::cppu::OWeakObject* >(this),
222 1 );
224 if ( sEntName.isEmpty() )
225 throw lang::IllegalArgumentException( "Empty element name is provided!",
226 static_cast< ::cppu::OWeakObject* >(this),
227 2 );
229 uno::Reference< uno::XInterface > xResult(
230 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, true ) ),
231 uno::UNO_QUERY );
233 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
235 if ( !xPersist.is() )
236 throw uno::RuntimeException(); // TODO: the interface must be supported by own document objects
238 xPersist->setPersistentEntry( xStorage,
239 sEntName,
240 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT,
241 aMediaDescr,
242 lObjArgs );
244 return xResult;
248 uno::Reference< uno::XInterface > SAL_CALL OleEmbeddedObjectFactory::createInstanceUserInit(
249 const uno::Sequence< sal_Int8 >& aClassID,
250 const OUString& aClassName,
251 const uno::Reference< embed::XStorage >& xStorage,
252 const OUString& sEntName,
253 sal_Int32 /*nEntryConnectionMode*/,
254 const uno::Sequence< beans::PropertyValue >& /*lArguments*/,
255 const uno::Sequence< beans::PropertyValue >& lObjArgs )
256 throw ( lang::IllegalArgumentException,
257 io::IOException,
258 uno::Exception,
259 uno::RuntimeException, std::exception )
261 // the initialization is completelly controlled by user
262 if ( !xStorage.is() )
263 throw lang::IllegalArgumentException( "No parent storage is provided!",
264 static_cast< ::cppu::OWeakObject* >(this),
265 1 );
267 if ( sEntName.isEmpty() )
268 throw lang::IllegalArgumentException( "Empty element name is provided!",
269 static_cast< ::cppu::OWeakObject* >(this),
270 2 );
272 uno::Reference< uno::XInterface > xResult(
273 static_cast< ::cppu::OWeakObject* > ( new OleEmbeddedObject( m_xFactory, aClassID, aClassName ) ),
274 uno::UNO_QUERY );
276 uno::Reference< embed::XEmbedPersist > xPersist( xResult, uno::UNO_QUERY );
277 if ( xPersist.is() )
279 xPersist->setPersistentEntry( xStorage,
280 sEntName,
281 embed::EntryInitModes::DEFAULT_INIT,
282 uno::Sequence< beans::PropertyValue >(),
283 lObjArgs );
286 else
287 throw uno::RuntimeException(); // TODO:
289 return xResult;
293 OUString SAL_CALL OleEmbeddedObjectFactory::getImplementationName()
294 throw ( uno::RuntimeException, std::exception )
296 return impl_staticGetImplementationName();
299 sal_Bool SAL_CALL OleEmbeddedObjectFactory::supportsService( const OUString& ServiceName )
300 throw ( uno::RuntimeException, std::exception )
302 return cppu::supportsService(this, ServiceName);
306 uno::Sequence< OUString > SAL_CALL OleEmbeddedObjectFactory::getSupportedServiceNames()
307 throw ( uno::RuntimeException, std::exception )
309 return impl_staticGetSupportedServiceNames();
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */