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
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";
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
,
68 uno::RuntimeException
)
70 SAL_INFO( "embeddedobj.ole", "embeddedobj (mv76033) OleEmbeddedObjectFactory::createInstanceInitFromEntry" );
73 throw lang::IllegalArgumentException( OUString( "No parent storage is provided!\n" ),
74 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ),
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) ),
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
) ),
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
,
107 embed::EntryInitModes::DEFAULT_INIT
,
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
;
121 xNew
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, xObj
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
) );
123 catch ( const uno::Exception
& ) {}
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
,
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) ),
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) ),
154 uno::Reference
< uno::XInterface
> xResult(
155 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_False
) ),
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
,
165 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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) ),
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) ),
196 uno::Reference
< uno::XInterface
> xResult(
197 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
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
,
207 embed::EntryInitModes::TRUNCATE_INIT
,
208 uno::Sequence
< beans::PropertyValue
>(),
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
,
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) ),
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) ),
239 uno::Reference
< uno::XInterface
> xResult(
240 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, sal_True
) ),
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
,
250 embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT
,
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
,
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) ),
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) ),
284 uno::Reference
< uno::XInterface
> xResult(
285 static_cast< ::cppu::OWeakObject
* > ( new OleEmbeddedObject( m_xFactory
, aClassID
, aClassName
) ),
288 uno::Reference
< embed::XEmbedPersist
> xPersist( xResult
, uno::UNO_QUERY
);
291 xPersist
->setPersistentEntry( xStorage
,
293 embed::EntryInitModes::DEFAULT_INIT
,
294 uno::Sequence
< beans::PropertyValue
>(),
299 throw uno::RuntimeException(); // TODO:
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: */