1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_embeddedobj.hxx"
25 #include <com/sun/star/embed/EmbedStates.hpp>
26 #include <com/sun/star/embed/EmbedVerbs.hpp>
27 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
28 #include <com/sun/star/embed/XEmbeddedClient.hpp>
29 #include <com/sun/star/embed/XInplaceClient.hpp>
30 #include <com/sun/star/embed/XWindowSupplier.hpp>
31 #include <com/sun/star/embed/StateChangeInProgressException.hpp>
32 #include <com/sun/star/embed/EmbedStates.hpp>
33 #include <com/sun/star/embed/Aspects.hpp>
34 #include <com/sun/star/embed/EmbedMapUnits.hpp>
35 #include <com/sun/star/embed/EntryInitModes.hpp>
36 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
37 #include <com/sun/star/lang/DisposedException.hpp>
38 
39 #include <cppuhelper/interfacecontainer.h>
40 
41 #include <dummyobject.hxx>
42 
43 
44 using namespace ::com::sun::star;
45 
46 //----------------------------------------------
CheckInit()47 void ODummyEmbeddedObject::CheckInit()
48 {
49 	if ( m_bDisposed )
50 		throw lang::DisposedException();
51 
52 	if ( m_nObjectState == -1 )
53 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object has no persistence!\n" ),
54 										uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
55 }
56 
57 //----------------------------------------------
PostEvent_Impl(const::rtl::OUString & aEventName,const uno::Reference<uno::XInterface> &)58 void ODummyEmbeddedObject::PostEvent_Impl( const ::rtl::OUString& aEventName,
59 											const uno::Reference< uno::XInterface >& /*xSource*/ )
60 {
61 	if ( m_pInterfaceContainer )
62 	{
63 		::cppu::OInterfaceContainerHelper* pIC = m_pInterfaceContainer->getContainer(
64 											::getCppuType((const uno::Reference< document::XEventListener >*)0) );
65 		if( pIC )
66 		{
67 			document::EventObject aEvent;
68 			aEvent.EventName = aEventName;
69 			aEvent.Source = uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) );
70 			// For now all the events are sent as object events
71 			// aEvent.Source = ( xSource.is() ? xSource
72 			//					   : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
73 			::cppu::OInterfaceIteratorHelper aIt( *pIC );
74 			while( aIt.hasMoreElements() )
75         	{
76             	try
77             	{
78                 	((document::XEventListener *)aIt.next())->notifyEvent( aEvent );
79             	}
80             	catch( uno::RuntimeException& )
81             	{
82                 	aIt.remove();
83             	}
84 
85 				// the listener could dispose the object.
86 				if ( m_bDisposed )
87 					return;
88         	}
89 		}
90 	}
91 }
92 
93 //----------------------------------------------
~ODummyEmbeddedObject()94 ODummyEmbeddedObject::~ODummyEmbeddedObject()
95 {
96 }
97 
98 //----------------------------------------------
changeState(sal_Int32 nNewState)99 void SAL_CALL ODummyEmbeddedObject::changeState( sal_Int32 nNewState )
100 		throw ( embed::UnreachableStateException,
101 				embed::WrongStateException,
102 				uno::Exception,
103 				uno::RuntimeException )
104 {
105 	::osl::MutexGuard aGuard( m_aMutex );
106 	CheckInit();
107 
108 	if ( nNewState == embed::EmbedStates::LOADED )
109 		return;
110 
111 	throw embed::UnreachableStateException();
112 }
113 
114 //----------------------------------------------
getReachableStates()115 uno::Sequence< sal_Int32 > SAL_CALL ODummyEmbeddedObject::getReachableStates()
116 		throw ( embed::WrongStateException,
117 				uno::RuntimeException )
118 {
119 	::osl::MutexGuard aGuard( m_aMutex );
120 	CheckInit();
121 
122 	uno::Sequence< sal_Int32 > aResult( 1 );
123 	aResult[0] = embed::EmbedStates::LOADED;
124 
125 	return aResult;
126 }
127 
128 //----------------------------------------------
getCurrentState()129 sal_Int32 SAL_CALL ODummyEmbeddedObject::getCurrentState()
130 		throw ( embed::WrongStateException,
131 				uno::RuntimeException )
132 {
133 	::osl::MutexGuard aGuard( m_aMutex );
134 	CheckInit();
135 
136 	return m_nObjectState;
137 }
138 
139 //----------------------------------------------
doVerb(sal_Int32)140 void SAL_CALL ODummyEmbeddedObject::doVerb( sal_Int32 )
141 		throw ( lang::IllegalArgumentException,
142 				embed::WrongStateException,
143 				embed::UnreachableStateException,
144 				uno::Exception,
145 				uno::RuntimeException )
146 {
147 	::osl::MutexGuard aGuard( m_aMutex );
148 	CheckInit();
149 
150 	// no supported verbs
151 }
152 
153 //----------------------------------------------
getSupportedVerbs()154 uno::Sequence< embed::VerbDescriptor > SAL_CALL ODummyEmbeddedObject::getSupportedVerbs()
155 		throw ( embed::WrongStateException,
156 				uno::RuntimeException )
157 {
158 	::osl::MutexGuard aGuard( m_aMutex );
159 	CheckInit();
160 
161 	return uno::Sequence< embed::VerbDescriptor >();
162 }
163 
164 //----------------------------------------------
setClientSite(const uno::Reference<embed::XEmbeddedClient> & xClient)165 void SAL_CALL ODummyEmbeddedObject::setClientSite(
166 				const uno::Reference< embed::XEmbeddedClient >& xClient )
167 		throw ( embed::WrongStateException,
168 				uno::RuntimeException )
169 {
170 	::osl::MutexGuard aGuard( m_aMutex );
171 	CheckInit();
172 
173 	m_xClientSite = xClient;
174 }
175 
176 //----------------------------------------------
getClientSite()177 uno::Reference< embed::XEmbeddedClient > SAL_CALL ODummyEmbeddedObject::getClientSite()
178 		throw ( embed::WrongStateException,
179 				uno::RuntimeException )
180 {
181 	::osl::MutexGuard aGuard( m_aMutex );
182 	CheckInit();
183 
184 	return m_xClientSite;
185 }
186 
187 //----------------------------------------------
update()188 void SAL_CALL ODummyEmbeddedObject::update()
189 		throw ( embed::WrongStateException,
190 				uno::Exception,
191 				uno::RuntimeException )
192 {
193 	::osl::MutexGuard aGuard( m_aMutex );
194 	CheckInit();
195 }
196 
197 //----------------------------------------------
setUpdateMode(sal_Int32)198 void SAL_CALL ODummyEmbeddedObject::setUpdateMode( sal_Int32 )
199 		throw ( embed::WrongStateException,
200 				uno::RuntimeException )
201 {
202 	::osl::MutexGuard aGuard( m_aMutex );
203 	CheckInit();
204 }
205 
206 //----------------------------------------------
getStatus(sal_Int64)207 sal_Int64 SAL_CALL ODummyEmbeddedObject::getStatus( sal_Int64 )
208 		throw ( embed::WrongStateException,
209 				uno::RuntimeException )
210 {
211 	::osl::MutexGuard aGuard( m_aMutex );
212 	CheckInit();
213 
214 	return 0;
215 }
216 
217 //----------------------------------------------
setContainerName(const::rtl::OUString &)218 void SAL_CALL ODummyEmbeddedObject::setContainerName( const ::rtl::OUString& )
219 		throw ( uno::RuntimeException )
220 {
221 	::osl::MutexGuard aGuard( m_aMutex );
222 	CheckInit();
223 }
224 
225 //----------------------------------------------
setVisualAreaSize(sal_Int64 nAspect,const awt::Size & aSize)226 void SAL_CALL ODummyEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
227 		throw ( lang::IllegalArgumentException,
228 				embed::WrongStateException,
229 				uno::Exception,
230 				uno::RuntimeException )
231 {
232 	::osl::MutexGuard aGuard( m_aMutex );
233 	CheckInit();
234 
235 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
236 	if ( nAspect == embed::Aspects::MSOLE_ICON )
237 		// no representation can be retrieved
238 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
239 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
240 
241 	m_nCachedAspect = nAspect;
242 	m_aCachedSize = aSize;
243 	m_bHasCachedSize = sal_True;
244 }
245 
246 //----------------------------------------------
getVisualAreaSize(sal_Int64 nAspect)247 awt::Size SAL_CALL ODummyEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
248 		throw ( lang::IllegalArgumentException,
249 				embed::WrongStateException,
250 				uno::Exception,
251 				uno::RuntimeException )
252 {
253 	::osl::MutexGuard aGuard( m_aMutex );
254 	CheckInit();
255 
256 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
257 	if ( nAspect == embed::Aspects::MSOLE_ICON )
258 		// no representation can be retrieved
259 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
260 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
261 
262 	if ( !m_bHasCachedSize || m_nCachedAspect != nAspect )
263 		throw embed::NoVisualAreaSizeException(
264 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ),
265 				uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
266 
267 	return m_aCachedSize;
268 }
269 
270 //----------------------------------------------
getMapUnit(sal_Int64 nAspect)271 sal_Int32 SAL_CALL ODummyEmbeddedObject::getMapUnit( sal_Int64 nAspect )
272 		throw ( uno::Exception,
273 				uno::RuntimeException)
274 {
275 	::osl::MutexGuard aGuard( m_aMutex );
276 	CheckInit();
277 
278 	OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
279 	if ( nAspect == embed::Aspects::MSOLE_ICON )
280 		// no representation can be retrieved
281 		throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
282 									uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
283 
284 	return embed::EmbedMapUnits::ONE_100TH_MM;
285 }
286 
287 //----------------------------------------------
getPreferredVisualRepresentation(sal_Int64)288 embed::VisualRepresentation SAL_CALL ODummyEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 )
289 		throw ( lang::IllegalArgumentException,
290 				embed::WrongStateException,
291 				uno::Exception,
292 				uno::RuntimeException )
293 {
294 	::osl::MutexGuard aGuard( m_aMutex );
295 	CheckInit();
296 
297 	// no representation can be retrieved
298 	throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ),
299 								uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
300 }
301 
302 //----------------------------------------------
setPersistentEntry(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,sal_Int32 nEntryConnectionMode,const uno::Sequence<beans::PropertyValue> &,const uno::Sequence<beans::PropertyValue> &)303 void SAL_CALL ODummyEmbeddedObject::setPersistentEntry(
304 					const uno::Reference< embed::XStorage >& xStorage,
305 					const ::rtl::OUString& sEntName,
306 					sal_Int32 nEntryConnectionMode,
307 					const uno::Sequence< beans::PropertyValue >& /* lArguments */,
308 					const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
309 		throw ( lang::IllegalArgumentException,
310 				embed::WrongStateException,
311 				io::IOException,
312 				uno::Exception,
313 				uno::RuntimeException )
314 {
315 	::osl::MutexGuard aGuard( m_aMutex );
316 	if ( m_bDisposed )
317 		throw lang::DisposedException(); // TODO
318 
319 	if ( !xStorage.is() )
320 		throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ),
321 											uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
322 											1 );
323 
324 	if ( !sEntName.getLength() )
325 		throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ),
326 											uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
327 											2 );
328 
329 	if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
330 	  && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) )
331 	{
332 		throw embed::WrongStateException(
333 					::rtl::OUString::createFromAscii( "Can't change persistent representation of activated object!\n" ),
334 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
335 	}
336 
337     if ( m_bWaitSaveCompleted )
338 	{
339 		if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
340 			saveCompleted( ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) );
341 		else
342 			throw embed::WrongStateException(
343 						::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
344 						uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
345 	}
346 
347 	if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT
348 	  || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
349 	{
350 		if ( xStorage->hasByName( sEntName ) )
351 
352 		{
353 			m_xParentStorage = xStorage;
354 			m_aEntryName = sEntName;
355 			m_nObjectState = embed::EmbedStates::LOADED;
356 		}
357 		else
358 			throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong entry is provided!\n" ),
359 								uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
360 								2 );
361 
362 	}
363 	else
364 		throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ),
365 								uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ),
366 								3 );
367 }
368 
369 //------------------------------------------------------
storeToEntry(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> &,const uno::Sequence<beans::PropertyValue> &)370 void SAL_CALL ODummyEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage,
371 							const ::rtl::OUString& sEntName,
372 							const uno::Sequence< beans::PropertyValue >& /* lArguments */,
373 							const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
374 		throw ( lang::IllegalArgumentException,
375 				embed::WrongStateException,
376 				io::IOException,
377 				uno::Exception,
378 				uno::RuntimeException )
379 {
380 	::osl::MutexGuard aGuard( m_aMutex );
381 	CheckInit();
382 
383 	if ( m_bWaitSaveCompleted )
384 		throw embed::WrongStateException(
385 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
386 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
387 
388 	m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
389 }
390 
391 //------------------------------------------------------
storeAsEntry(const uno::Reference<embed::XStorage> & xStorage,const::rtl::OUString & sEntName,const uno::Sequence<beans::PropertyValue> &,const uno::Sequence<beans::PropertyValue> &)392 void SAL_CALL ODummyEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage,
393 							const ::rtl::OUString& sEntName,
394 							const uno::Sequence< beans::PropertyValue >& /* lArguments */,
395 							const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
396 		throw ( lang::IllegalArgumentException,
397 				embed::WrongStateException,
398 				io::IOException,
399 				uno::Exception,
400 				uno::RuntimeException )
401 {
402 	::osl::MutexGuard aGuard( m_aMutex );
403 	CheckInit();
404 
405 	if ( m_bWaitSaveCompleted )
406 		throw embed::WrongStateException(
407 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
408 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
409 
410 	PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAs" ),
411 					uno::Reference< uno::XInterface >( static_cast< cppu::OWeakObject* >( this ) ) );
412 
413 	m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName );
414 
415 	m_bWaitSaveCompleted = sal_True;
416 	m_xNewParentStorage = xStorage;
417     m_aNewEntryName = sEntName;
418 }
419 
420 //------------------------------------------------------
saveCompleted(sal_Bool bUseNew)421 void SAL_CALL ODummyEmbeddedObject::saveCompleted( sal_Bool bUseNew )
422 		throw ( embed::WrongStateException,
423 				uno::Exception,
424 				uno::RuntimeException )
425 {
426 	::osl::MutexGuard aGuard( m_aMutex );
427 	CheckInit();
428 
429 	// it is allowed to call saveCompleted( false ) for nonstored objects
430 	if ( !m_bWaitSaveCompleted && !bUseNew )
431 		return;
432 
433 	OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" );
434 	if ( !m_bWaitSaveCompleted )
435 		throw io::IOException(); // TODO: illegal call
436 
437 	OSL_ENSURE( m_xNewParentStorage.is() , "Internal object information is broken!\n" );
438 	if ( !m_xNewParentStorage.is() )
439 		throw uno::RuntimeException(); // TODO: broken internal information
440 
441 	if ( bUseNew )
442 	{
443 		m_xParentStorage = m_xNewParentStorage;
444 		m_aEntryName = m_aNewEntryName;
445 
446 		PostEvent_Impl( ::rtl::OUString::createFromAscii( "OnSaveAsDone" ),
447 						uno::Reference< uno::XInterface >( static_cast< cppu::OWeakObject* >( this ) ) );
448 	}
449 
450 	m_xNewParentStorage = uno::Reference< embed::XStorage >();
451 	m_aNewEntryName = ::rtl::OUString();
452 	m_bWaitSaveCompleted = sal_False;
453 }
454 
455 //------------------------------------------------------
hasEntry()456 sal_Bool SAL_CALL ODummyEmbeddedObject::hasEntry()
457 		throw ( embed::WrongStateException,
458 				uno::RuntimeException )
459 {
460 	::osl::MutexGuard aGuard( m_aMutex );
461 	CheckInit();
462 
463 	if ( m_bWaitSaveCompleted )
464 		throw embed::WrongStateException(
465 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
466 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
467 
468 	if ( m_aEntryName.getLength() )
469 		return sal_True;
470 
471 	return sal_False;
472 }
473 
474 //------------------------------------------------------
getEntryName()475 ::rtl::OUString SAL_CALL ODummyEmbeddedObject::getEntryName()
476 		throw ( embed::WrongStateException,
477 				uno::RuntimeException )
478 {
479 	::osl::MutexGuard aGuard( m_aMutex );
480 	CheckInit();
481 
482 	if ( m_bWaitSaveCompleted )
483 		throw embed::WrongStateException(
484 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
485 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
486 
487 	return m_aEntryName;
488 }
489 
490 //------------------------------------------------------
storeOwn()491 void SAL_CALL ODummyEmbeddedObject::storeOwn()
492 		throw ( embed::WrongStateException,
493 				io::IOException,
494 				uno::Exception,
495 				uno::RuntimeException )
496 {
497 	::osl::MutexGuard aGuard( m_aMutex );
498 	CheckInit();
499 
500 	if ( m_bWaitSaveCompleted )
501 		throw embed::WrongStateException(
502 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
503 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
504 
505 	// the object can not be activated or changed
506 	return;
507 }
508 
509 //------------------------------------------------------
isReadonly()510 sal_Bool SAL_CALL ODummyEmbeddedObject::isReadonly()
511 		throw ( embed::WrongStateException,
512 				uno::RuntimeException )
513 {
514 	::osl::MutexGuard aGuard( m_aMutex );
515 	CheckInit();
516 
517 	if ( m_bWaitSaveCompleted )
518 		throw embed::WrongStateException(
519 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
520 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
521 
522 	// this object can not be changed
523 	return sal_True;
524 }
525 
526 //------------------------------------------------------
reload(const uno::Sequence<beans::PropertyValue> &,const uno::Sequence<beans::PropertyValue> &)527 void SAL_CALL ODummyEmbeddedObject::reload(
528 				const uno::Sequence< beans::PropertyValue >& /* lArguments */,
529 				const uno::Sequence< beans::PropertyValue >& /* lObjArgs */ )
530 		throw ( lang::IllegalArgumentException,
531 				embed::WrongStateException,
532 				io::IOException,
533 				uno::Exception,
534 				uno::RuntimeException )
535 {
536 	::osl::MutexGuard aGuard( m_aMutex );
537 	CheckInit();
538 
539 	if ( m_bWaitSaveCompleted )
540 		throw embed::WrongStateException(
541 					::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
542 					uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
543 
544 	// nothing to reload
545 }
546 
547 //------------------------------------------------------
getClassID()548 uno::Sequence< sal_Int8 > SAL_CALL ODummyEmbeddedObject::getClassID()
549 		throw ( uno::RuntimeException )
550 {
551 	::osl::MutexGuard aGuard( m_aMutex );
552 	CheckInit();
553 
554 	// currently the class ID is empty
555 	// TODO/LATER: should a special class ID be used in this case?
556 	return uno::Sequence< sal_Int8 >();
557 }
558 
559 //------------------------------------------------------
getClassName()560 ::rtl::OUString SAL_CALL ODummyEmbeddedObject::getClassName()
561 		throw ( uno::RuntimeException )
562 {
563 	::osl::MutexGuard aGuard( m_aMutex );
564 	if ( m_bDisposed )
565 		throw lang::DisposedException(); // TODO
566 
567 	return ::rtl::OUString();
568 }
569 
570 //------------------------------------------------------
setClassInfo(const uno::Sequence<sal_Int8> &,const::rtl::OUString &)571 void SAL_CALL ODummyEmbeddedObject::setClassInfo(
572 				const uno::Sequence< sal_Int8 >& /*aClassID*/, const ::rtl::OUString& /*aClassName*/ )
573 		throw ( lang::NoSupportException,
574 				uno::RuntimeException )
575 {
576 	throw lang::NoSupportException();
577 }
578 
579 //------------------------------------------------------
getComponent()580 uno::Reference< util::XCloseable > SAL_CALL ODummyEmbeddedObject::getComponent()
581 		throw ( uno::RuntimeException )
582 {
583 	::osl::MutexGuard aGuard( m_aMutex );
584 	CheckInit();
585 
586     return uno::Reference< util::XCloseable >();
587 }
588 
589 //----------------------------------------------
addStateChangeListener(const uno::Reference<embed::XStateChangeListener> & xListener)590 void SAL_CALL ODummyEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener )
591 	throw ( uno::RuntimeException )
592 {
593 	::osl::MutexGuard aGuard( m_aMutex );
594 	if ( m_bDisposed )
595 		return;
596 
597 	if ( !m_pInterfaceContainer )
598 		m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
599 
600 	m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< embed::XStateChangeListener >*)0 ),
601 														xListener );
602 }
603 
604 //----------------------------------------------
removeStateChangeListener(const uno::Reference<embed::XStateChangeListener> & xListener)605 void SAL_CALL ODummyEmbeddedObject::removeStateChangeListener(
606 					const uno::Reference< embed::XStateChangeListener >& xListener )
607 	throw (uno::RuntimeException)
608 {
609 	::osl::MutexGuard aGuard( m_aMutex );
610 	if ( m_pInterfaceContainer )
611 		m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< embed::XStateChangeListener >*)0 ),
612 												xListener );
613 }
614 
615 //----------------------------------------------
close(sal_Bool bDeliverOwnership)616 void SAL_CALL ODummyEmbeddedObject::close( sal_Bool bDeliverOwnership )
617 	throw ( util::CloseVetoException,
618 			uno::RuntimeException )
619 {
620 	::osl::MutexGuard aGuard( m_aMutex );
621 	if ( m_bDisposed )
622 		throw lang::DisposedException(); // TODO
623 
624     uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
625     lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
626 
627 	if ( m_pInterfaceContainer )
628 	{
629     	::cppu::OInterfaceContainerHelper* pContainer =
630 			m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
631     	if ( pContainer != NULL )
632 		{
633         	::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
634         	while (pIterator.hasMoreElements())
635         	{
636             	try
637             	{
638                 	((util::XCloseListener*)pIterator.next())->queryClosing( aSource, bDeliverOwnership );
639             	}
640             	catch( uno::RuntimeException& )
641             	{
642                 	pIterator.remove();
643             	}
644         	}
645 		}
646 
647     	pContainer = m_pInterfaceContainer->getContainer(
648 									::getCppuType( ( const uno::Reference< util::XCloseListener >*) NULL ) );
649     	if ( pContainer != NULL )
650 		{
651         	::cppu::OInterfaceIteratorHelper pCloseIterator(*pContainer);
652         	while (pCloseIterator.hasMoreElements())
653         	{
654             	try
655             	{
656                 	((util::XCloseListener*)pCloseIterator.next())->notifyClosing( aSource );
657             	}
658             	catch( uno::RuntimeException& )
659             	{
660                 	pCloseIterator.remove();
661             	}
662         	}
663 		}
664 
665 		m_pInterfaceContainer->disposeAndClear( aSource );
666 	}
667 
668 	m_bDisposed = sal_True; // the object is disposed now for outside
669 }
670 
671 //----------------------------------------------
addCloseListener(const uno::Reference<util::XCloseListener> & xListener)672 void SAL_CALL ODummyEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener )
673 	throw ( uno::RuntimeException )
674 {
675 	::osl::MutexGuard aGuard( m_aMutex );
676 	if ( m_bDisposed )
677 		return;
678 
679 	if ( !m_pInterfaceContainer )
680 		m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
681 
682 	m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ), xListener );
683 }
684 
685 //----------------------------------------------
removeCloseListener(const uno::Reference<util::XCloseListener> & xListener)686 void SAL_CALL ODummyEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener )
687 	throw (uno::RuntimeException)
688 {
689 	::osl::MutexGuard aGuard( m_aMutex );
690 	if ( m_pInterfaceContainer )
691 		m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< util::XCloseListener >*)0 ),
692 												xListener );
693 }
694 
695 //------------------------------------------------------
addEventListener(const uno::Reference<document::XEventListener> & xListener)696 void SAL_CALL ODummyEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener )
697 		throw ( uno::RuntimeException )
698 {
699 	::osl::MutexGuard aGuard( m_aMutex );
700 	if ( m_bDisposed )
701 		return;
702 
703 	if ( !m_pInterfaceContainer )
704 		m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
705 
706 	m_pInterfaceContainer->addInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ), xListener );
707 }
708 
709 //------------------------------------------------------
removeEventListener(const uno::Reference<document::XEventListener> & xListener)710 void SAL_CALL ODummyEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
711 		throw ( uno::RuntimeException )
712 {
713 	::osl::MutexGuard aGuard( m_aMutex );
714 	if ( m_pInterfaceContainer )
715 		m_pInterfaceContainer->removeInterface( ::getCppuType( (const uno::Reference< document::XEventListener >*)0 ),
716 												xListener );
717 }
718 
719