1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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";
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
,
68 uno::RuntimeException
, std::exception
)
71 throw lang::IllegalArgumentException( "No parent storage is provided!",
72 static_cast< ::cppu::OWeakObject
* >(this),
75 if ( sEntName
.isEmpty() )
76 throw lang::IllegalArgumentException( "Empty element name is provided!",
77 static_cast< ::cppu::OWeakObject
* >(this),
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 ) ),
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
,
105 embed::EntryInitModes::DEFAULT_INIT
,
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
;
119 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
121 catch ( const uno::Exception
& ) {}
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
,
138 uno::RuntimeException
, std::exception
)
140 if ( !xStorage
.is() )
141 throw lang::IllegalArgumentException( "No parent storage is provided!",
142 static_cast< ::cppu::OWeakObject
* >(this),
145 if ( sEntName
.isEmpty() )
146 throw lang::IllegalArgumentException( "Empty element name is provided!",
147 static_cast< ::cppu::OWeakObject
* >(this),
150 uno::Reference
< uno::XInterface
> xResult(
151 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, false ) ),
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
,
161 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
178 uno::RuntimeException
, std::exception
)
180 if ( !xStorage
.is() )
181 throw lang::IllegalArgumentException( "No parent storage is provided!",
182 static_cast< ::cppu::OWeakObject
* >(this),
185 if ( sEntName
.isEmpty() )
186 throw lang::IllegalArgumentException( "Empty element name is provided!",
187 static_cast< ::cppu::OWeakObject
* >(this),
190 uno::Reference
< uno::XInterface
> xResult(
191 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
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
,
201 embed::EntryInitModes::TRUNCATE_INIT
,
202 uno::Sequence
< beans::PropertyValue
>(),
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
,
217 uno::RuntimeException
, std::exception
)
219 if ( !xStorage
.is() )
220 throw lang::IllegalArgumentException( "No parent storage is provided!",
221 static_cast< ::cppu::OWeakObject
* >(this),
224 if ( sEntName
.isEmpty() )
225 throw lang::IllegalArgumentException( "Empty element name is provided!",
226 static_cast< ::cppu::OWeakObject
* >(this),
229 uno::Reference
< uno::XInterface
> xResult(
230 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, true ) ),
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
,
240 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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),
267 if ( sEntName
.isEmpty() )
268 throw lang::IllegalArgumentException( "Empty element name is provided!",
269 static_cast< ::cppu::OWeakObject
* >(this),
272 uno::Reference
< uno::XInterface
> xResult(
273 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
276 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
279 xPersist
->setPersistentEntry( xStorage
,
281 embed::EntryInitModes::DEFAULT_INIT
,
282 uno::Sequence
< beans::PropertyValue
>(),
287 throw uno::RuntimeException(); // TODO:
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: */