1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: miscobj.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
34 #include <commonembobj.hxx>
35 #include <com/sun/star/embed/EmbedStates.hpp>
36 #include <com/sun/star/embed/EmbedVerbs.hpp>
37 #include <com/sun/star/embed/XStorage.hpp>
38 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
39 #include <com/sun/star/embed/XInplaceClient.hpp>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/beans/NamedValue.hpp>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <cppuhelper/interfacecontainer.h>
46 #include "closepreventer.hxx"
47 #include "intercept.hxx"
49 using namespace ::com::sun::star
;
52 uno::Sequence
< beans::PropertyValue
> GetValuableArgs_Impl( const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
53 sal_Bool bCanUseDocumentBaseURL
);
55 //------------------------------------------------------
56 OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
,
57 const uno::Sequence
< beans::NamedValue
>& aObjProps
)
58 : m_pDocHolder( NULL
)
59 , m_pInterfaceContainer( NULL
)
60 , m_bReadOnly( sal_False
)
61 , m_bDisposed( sal_False
)
62 , m_bClosed( sal_False
)
63 , m_nObjectState( -1 )
64 , m_nTargetState( -1 )
65 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
66 , m_xFactory( xFactory
)
68 , m_bEmbeddedScriptSupport( sal_True
)
69 , m_bWaitSaveCompleted( sal_False
)
70 , m_bIsLink( sal_False
)
71 , m_bLinkHasPassword( sal_False
)
72 , m_bHasClonedSize( sal_False
)
73 , m_nClonedMapUnit( 0 )
75 CommonInit_Impl( aObjProps
);
78 //------------------------------------------------------
79 OCommonEmbeddedObject::OCommonEmbeddedObject(
80 const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
,
81 const uno::Sequence
< beans::NamedValue
>& aObjProps
,
82 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
83 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
84 : m_pDocHolder( NULL
)
85 , m_pInterfaceContainer( NULL
)
86 , m_bReadOnly( sal_False
)
87 , m_bDisposed( sal_False
)
88 , m_bClosed( sal_False
)
89 , m_nObjectState( embed::EmbedStates::LOADED
)
90 , m_nTargetState( -1 )
91 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
92 , m_xFactory( xFactory
)
94 , m_bEmbeddedScriptSupport( sal_True
)
95 , m_bWaitSaveCompleted( sal_False
)
96 , m_bIsLink( sal_True
)
97 , m_bLinkHasPassword( sal_False
)
98 , m_bHasClonedSize( sal_False
)
99 , m_nClonedMapUnit( 0 )
101 // linked object has no own persistence so it is in loaded state starting from creation
102 LinkInit_Impl( aObjProps
, aMediaDescr
, aObjectDescr
);
105 //------------------------------------------------------
106 void OCommonEmbeddedObject::CommonInit_Impl( const uno::Sequence
< beans::NamedValue
>& aObjectProps
)
108 OSL_ENSURE( m_xFactory
.is(), "No ServiceFactory is provided!\n" );
109 if ( !m_xFactory
.is() )
110 throw uno::RuntimeException();
112 m_pDocHolder
= new DocumentHolder( m_xFactory
, this );
113 m_pDocHolder
->acquire();
115 // parse configuration entries
116 // TODO/LATER: in future UI names can be also provided here
117 for ( sal_Int32 nInd
= 0; nInd
< aObjectProps
.getLength(); nInd
++ )
119 if ( aObjectProps
[nInd
].Name
.equalsAscii( "ClassID" ) )
120 aObjectProps
[nInd
].Value
>>= m_aClassID
;
121 else if ( aObjectProps
[nInd
].Name
.equalsAscii( "ObjectDocumentServiceName" ) )
122 aObjectProps
[nInd
].Value
>>= m_aDocServiceName
;
123 else if ( aObjectProps
[nInd
].Name
.equalsAscii( "ObjectDocumentFilterName" ) )
124 aObjectProps
[nInd
].Value
>>= m_aPresetFilterName
;
125 else if ( aObjectProps
[nInd
].Name
.equalsAscii( "ObjectMiscStatus" ) )
126 aObjectProps
[nInd
].Value
>>= m_nMiscStatus
;
127 else if ( aObjectProps
[nInd
].Name
.equalsAscii( "ObjectVerbs" ) )
128 aObjectProps
[nInd
].Value
>>= m_aObjectVerbs
;
131 if ( m_aClassID
.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
132 throw uno::RuntimeException(); // something goes really wrong
135 m_aAcceptedStates
.realloc( NUM_SUPPORTED_STATES
);
137 m_aAcceptedStates
[0] = embed::EmbedStates::LOADED
;
138 m_aAcceptedStates
[1] = embed::EmbedStates::RUNNING
;
139 m_aAcceptedStates
[2] = embed::EmbedStates::INPLACE_ACTIVE
;
140 m_aAcceptedStates
[3] = embed::EmbedStates::UI_ACTIVE
;
141 m_aAcceptedStates
[4] = embed::EmbedStates::ACTIVE
;
144 // intermediate states
145 // In the following table the first index points to starting state,
146 // the second one to the target state, and the sequence referenced by
147 // first two indexes contains intermediate states, that should be
148 // passed by object to reach the target state.
149 // If the sequence is empty that means that indirect switch from start
150 // state to the target state is forbidden, only if direct switch is possible
151 // the state can be reached.
153 m_pIntermediateStatesSeqs
[0][2].realloc( 1 );
154 m_pIntermediateStatesSeqs
[0][2][0] = embed::EmbedStates::RUNNING
;
156 m_pIntermediateStatesSeqs
[0][3].realloc( 2 );
157 m_pIntermediateStatesSeqs
[0][3][0] = embed::EmbedStates::RUNNING
;
158 m_pIntermediateStatesSeqs
[0][3][1] = embed::EmbedStates::INPLACE_ACTIVE
;
160 m_pIntermediateStatesSeqs
[0][4].realloc( 1 );
161 m_pIntermediateStatesSeqs
[0][4][0] = embed::EmbedStates::RUNNING
;
163 m_pIntermediateStatesSeqs
[1][3].realloc( 1 );
164 m_pIntermediateStatesSeqs
[1][3][0] = embed::EmbedStates::INPLACE_ACTIVE
;
166 m_pIntermediateStatesSeqs
[2][0].realloc( 1 );
167 m_pIntermediateStatesSeqs
[2][0][0] = embed::EmbedStates::RUNNING
;
169 m_pIntermediateStatesSeqs
[3][0].realloc( 2 );
170 m_pIntermediateStatesSeqs
[3][0][0] = embed::EmbedStates::INPLACE_ACTIVE
;
171 m_pIntermediateStatesSeqs
[3][0][1] = embed::EmbedStates::RUNNING
;
173 m_pIntermediateStatesSeqs
[3][1].realloc( 1 );
174 m_pIntermediateStatesSeqs
[3][1][0] = embed::EmbedStates::INPLACE_ACTIVE
;
176 m_pIntermediateStatesSeqs
[4][0].realloc( 1 );
177 m_pIntermediateStatesSeqs
[4][0][0] = embed::EmbedStates::RUNNING
;
180 sal_Int32 nVerbTableSize
= 0;
181 for ( sal_Int32 nVerbInd
= 0; nVerbInd
< m_aObjectVerbs
.getLength(); nVerbInd
++ )
183 if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_PRIMARY
)
185 m_aVerbTable
.realloc( ++nVerbTableSize
);
186 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
187 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
188 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
190 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_SHOW
)
192 m_aVerbTable
.realloc( ++nVerbTableSize
);
193 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
194 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
195 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
197 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_OPEN
)
199 m_aVerbTable
.realloc( ++nVerbTableSize
);
200 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
201 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
202 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::ACTIVE
;
204 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE
)
206 m_aVerbTable
.realloc( ++nVerbTableSize
);
207 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
208 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
209 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::INPLACE_ACTIVE
;
211 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
)
213 m_aVerbTable
.realloc( ++nVerbTableSize
);
214 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
215 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
216 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
218 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_HIDE
)
220 m_aVerbTable
.realloc( ++nVerbTableSize
);
221 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
222 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
223 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::RUNNING
;
228 //------------------------------------------------------
229 void OCommonEmbeddedObject::LinkInit_Impl(
230 const uno::Sequence
< beans::NamedValue
>& aObjectProps
,
231 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
232 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
234 // setPersistance has no effect on own links, so the complete initialization must be done here
236 for ( sal_Int32 nInd
= 0; nInd
< aMediaDescr
.getLength(); nInd
++ )
237 if ( aMediaDescr
[nInd
].Name
.equalsAscii( "URL" ) )
238 aMediaDescr
[nInd
].Value
>>= m_aLinkURL
;
239 else if ( aMediaDescr
[nInd
].Name
.equalsAscii( "FilterName" ) )
240 aMediaDescr
[nInd
].Value
>>= m_aLinkFilterName
;
242 OSL_ENSURE( m_aLinkURL
.getLength() && m_aLinkFilterName
.getLength(), "Filter and URL must be provided!\n" );
244 m_aDocMediaDescriptor
= GetValuableArgs_Impl( aMediaDescr
, sal_False
);
246 uno::Reference
< frame::XDispatchProviderInterceptor
> xDispatchInterceptor
;
247 for ( sal_Int32 nObjInd
= 0; nObjInd
< aObjectDescr
.getLength(); nObjInd
++ )
248 if ( aObjectDescr
[nObjInd
].Name
.equalsAscii( "OutplaceDispatchInterceptor" ) )
250 aObjectDescr
[nObjInd
].Value
>>= xDispatchInterceptor
;
253 else if ( aObjectDescr
[nObjInd
].Name
.equalsAscii( "Parent" ) )
255 aObjectDescr
[nObjInd
].Value
>>= m_xParent
;
258 CommonInit_Impl( aObjectProps
);
260 if ( xDispatchInterceptor
.is() )
261 m_pDocHolder
->SetOutplaceDispatchInterceptor( xDispatchInterceptor
);
264 //------------------------------------------------------
265 OCommonEmbeddedObject::~OCommonEmbeddedObject()
267 if ( m_pInterfaceContainer
|| m_pDocHolder
)
271 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
273 if ( m_pInterfaceContainer
)
275 m_pInterfaceContainer
->disposeAndClear( aSource
);
277 delete m_pInterfaceContainer
;
278 m_pInterfaceContainer
= NULL
;
280 } catch( uno::Exception
& ) {}
285 m_pDocHolder
->CloseFrame();
287 m_pDocHolder
->CloseDocument( sal_True
, sal_True
);
288 } catch ( uno::Exception
& ) {}
289 m_pDocHolder
->FreeOffice();
291 m_pDocHolder
->release();
294 } catch( uno::Exception
& ) {}
298 //------------------------------------------------------
299 void OCommonEmbeddedObject::requestPositioning( const awt::Rectangle
& aRect
)
301 // the method is called in case object is inplace active and the object window was resized
303 OSL_ENSURE( m_xClientSite
.is(), "The client site must be set for inplace active object!\n" );
304 if ( m_xClientSite
.is() )
306 uno::Reference
< embed::XInplaceClient
> xInplaceClient( m_xClientSite
, uno::UNO_QUERY
);
308 OSL_ENSURE( xInplaceClient
.is(), "The client site must support XInplaceClient to allow inplace activation!\n" );
309 if ( xInplaceClient
.is() )
312 xInplaceClient
->changedPlacement( aRect
);
314 catch( uno::Exception
& )
316 OSL_ENSURE( sal_False
, "Exception on request to resize!\n" );
322 //------------------------------------------------------
323 void OCommonEmbeddedObject::PostEvent_Impl( const ::rtl::OUString
& aEventName
,
324 const uno::Reference
< uno::XInterface
>& /*xSource*/ )
326 if ( m_pInterfaceContainer
)
328 ::cppu::OInterfaceContainerHelper
* pIC
= m_pInterfaceContainer
->getContainer(
329 ::getCppuType((const uno::Reference
< document::XEventListener
>*)0) );
332 document::EventObject aEvent
;
333 aEvent
.EventName
= aEventName
;
334 aEvent
.Source
= uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >( this ) );
335 // For now all the events are sent as object events
336 // aEvent.Source = ( xSource.is() ? xSource
337 // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
338 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
339 while( aIt
.hasMoreElements() )
343 ((document::XEventListener
*)aIt
.next())->notifyEvent( aEvent
);
345 catch( uno::RuntimeException
& )
350 // the listener could dispose the object.
358 //------------------------------------------------------
359 uno::Any SAL_CALL
OCommonEmbeddedObject::queryInterface( const uno::Type
& rType
)
360 throw( uno::RuntimeException
)
364 if ( rType
== ::getCppuType( (uno::Reference
< embed::XEmbeddedObject
> const *)0 ))
366 void * p
= static_cast< embed::XEmbeddedObject
* >( this );
367 return uno::Any( &p
, rType
);
370 aReturn
<<= ::cppu::queryInterface(
372 static_cast< embed::XInplaceObject
* >( this ),
373 static_cast< embed::XVisualObject
* >( this ),
374 static_cast< embed::XCommonEmbedPersist
* >( static_cast< embed::XEmbedPersist
* >( this ) ),
375 static_cast< embed::XEmbedPersist
* >( this ),
376 static_cast< embed::XLinkageSupport
* >( this ),
377 static_cast< embed::XStateChangeBroadcaster
* >( this ),
378 static_cast< embed::XClassifiedObject
* >( this ),
379 static_cast< embed::XComponentSupplier
* >( this ),
380 static_cast< util::XCloseable
* >( this ),
381 static_cast< container::XChild
* >( this ),
382 static_cast< chart2::XDefaultSizeTransmitter
* >( this ),
383 static_cast< document::XEventBroadcaster
* >( this ) );
385 if ( aReturn
.hasValue() )
388 return ::cppu::OWeakObject::queryInterface( rType
) ;
392 //------------------------------------------------------
393 void SAL_CALL
OCommonEmbeddedObject::acquire()
396 ::cppu::OWeakObject::acquire() ;
399 //------------------------------------------------------
400 void SAL_CALL
OCommonEmbeddedObject::release()
403 ::cppu::OWeakObject::release() ;
406 //------------------------------------------------------
407 uno::Sequence
< uno::Type
> SAL_CALL
OCommonEmbeddedObject::getTypes()
408 throw( uno::RuntimeException
)
410 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
412 if ( !pTypeCollection
)
414 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
415 if ( !pTypeCollection
)
419 static ::cppu::OTypeCollection
aTypeCollection(
420 ::getCppuType( (const uno::Reference
< lang::XTypeProvider
>*)NULL
),
421 ::getCppuType( (const uno::Reference
< embed::XEmbeddedObject
>*)NULL
),
422 ::getCppuType( (const uno::Reference
< embed::XInplaceObject
>*)NULL
),
423 ::getCppuType( (const uno::Reference
< embed::XCommonEmbedPersist
>*)NULL
),
424 ::getCppuType( (const uno::Reference
< container::XChild
>*)NULL
),
425 ::getCppuType( (const uno::Reference
< embed::XLinkageSupport
>*)NULL
) );
427 pTypeCollection
= &aTypeCollection
;
431 static ::cppu::OTypeCollection
aTypeCollection(
432 ::getCppuType( (const uno::Reference
< lang::XTypeProvider
>*)NULL
),
433 ::getCppuType( (const uno::Reference
< embed::XEmbeddedObject
>*)NULL
),
434 ::getCppuType( (const uno::Reference
< embed::XInplaceObject
>*)NULL
),
435 ::getCppuType( (const uno::Reference
< embed::XCommonEmbedPersist
>*)NULL
),
436 ::getCppuType( (const uno::Reference
< container::XChild
>*)NULL
),
437 ::getCppuType( (const uno::Reference
< embed::XEmbedPersist
>*)NULL
) );
439 pTypeCollection
= &aTypeCollection
;
444 return pTypeCollection
->getTypes() ;
448 //------------------------------------------------------
449 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getImplementationId()
450 throw( uno::RuntimeException
)
452 static ::cppu::OImplementationId
* pID
= NULL
;
456 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() ) ;
459 static ::cppu::OImplementationId
aID( sal_False
) ;
464 return pID
->getImplementationId() ;
467 //------------------------------------------------------
468 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getClassID()
469 throw ( uno::RuntimeException
)
471 ::osl::MutexGuard
aGuard( m_aMutex
);
473 throw lang::DisposedException(); // TODO
478 //------------------------------------------------------
479 ::rtl::OUString SAL_CALL
OCommonEmbeddedObject::getClassName()
480 throw ( uno::RuntimeException
)
482 ::osl::MutexGuard
aGuard( m_aMutex
);
484 throw lang::DisposedException(); // TODO
489 //------------------------------------------------------
490 void SAL_CALL
OCommonEmbeddedObject::setClassInfo(
491 const uno::Sequence
< sal_Int8
>& /*aClassID*/, const ::rtl::OUString
& /*aClassName*/ )
492 throw ( lang::NoSupportException
,
493 uno::RuntimeException
)
495 // the object class info can not be changed explicitly
496 throw lang::NoSupportException(); //TODO:
499 //------------------------------------------------------
500 uno::Reference
< util::XCloseable
> SAL_CALL
OCommonEmbeddedObject::getComponent()
501 throw ( uno::RuntimeException
)
503 ::osl::MutexGuard
aGuard( m_aMutex
);
505 throw lang::DisposedException(); // TODO
508 if ( m_nObjectState
== -1 )
510 // the object is still not loaded
511 throw uno::RuntimeException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ),
512 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
515 // if ( m_bWaitSaveCompleted )
516 // throw embed::WrongStateException(
517 // ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ),
518 // uno::Reference< uno::XInterface >( reinterpret_cast< ::cppu::OWeakObject* >(this) ) );
520 return uno::Reference
< util::XCloseable
>( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
523 //----------------------------------------------
524 void SAL_CALL
OCommonEmbeddedObject::addStateChangeListener( const uno::Reference
< embed::XStateChangeListener
>& xListener
)
525 throw ( uno::RuntimeException
)
527 ::osl::MutexGuard
aGuard( m_aMutex
);
529 throw lang::DisposedException(); // TODO
531 if ( !m_pInterfaceContainer
)
532 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
534 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< embed::XStateChangeListener
>*)0 ),
538 //----------------------------------------------
539 void SAL_CALL
OCommonEmbeddedObject::removeStateChangeListener(
540 const uno::Reference
< embed::XStateChangeListener
>& xListener
)
541 throw (uno::RuntimeException
)
543 ::osl::MutexGuard
aGuard( m_aMutex
);
544 if ( m_pInterfaceContainer
)
545 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< embed::XStateChangeListener
>*)0 ),
549 //----------------------------------------------
550 void SAL_CALL
OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership
)
551 throw ( util::CloseVetoException
,
552 uno::RuntimeException
)
554 ::osl::MutexGuard
aGuard( m_aMutex
);
556 throw lang::DisposedException(); // TODO
558 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >( this ) );
559 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
561 if ( m_pInterfaceContainer
)
563 ::cppu::OInterfaceContainerHelper
* pContainer
=
564 m_pInterfaceContainer
->getContainer( ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
565 if ( pContainer
!= NULL
)
567 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
568 while (pIterator
.hasMoreElements())
572 ((util::XCloseListener
*)pIterator
.next())->queryClosing( aSource
, bDeliverOwnership
);
574 catch( uno::RuntimeException
& )
581 pContainer
= m_pInterfaceContainer
->getContainer(
582 ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
583 if ( pContainer
!= NULL
)
585 ::cppu::OInterfaceIteratorHelper
pCloseIterator(*pContainer
);
586 while (pCloseIterator
.hasMoreElements())
590 ((util::XCloseListener
*)pCloseIterator
.next())->notifyClosing( aSource
);
592 catch( uno::RuntimeException
& )
594 pCloseIterator
.remove();
599 m_pInterfaceContainer
->disposeAndClear( aSource
);
602 m_bDisposed
= sal_True
; // the object is disposed now for outside
604 // it is possible that the document can not be closed, in this case if the argument is false
605 // the exception will be thrown otherwise in addition to exception the object must register itself
606 // as termination listener and listen for document events
610 m_pDocHolder
->CloseFrame();
613 m_pDocHolder
->CloseDocument( bDeliverOwnership
, bDeliverOwnership
);
615 catch( uno::Exception
& )
617 if ( bDeliverOwnership
)
619 m_pDocHolder
->release();
621 m_bClosed
= sal_True
;
627 m_pDocHolder
->FreeOffice();
629 m_pDocHolder
->release();
633 // TODO: for now the storage will be disposed by the object, but after the document
634 // will use the storage, the storage will be disposed by the document and recreated by the object
635 if ( m_xObjectStorage
.is() )
637 uno::Reference
< lang::XComponent
> xComp( m_xObjectStorage
, uno::UNO_QUERY
);
638 OSL_ENSURE( xComp
.is(), "Storage does not support XComponent!\n" );
644 } catch ( uno::Exception
& ) {}
647 m_xObjectStorage
= uno::Reference
< embed::XStorage
>();
650 m_bClosed
= sal_True
; // the closing succeeded
653 //----------------------------------------------
654 void SAL_CALL
OCommonEmbeddedObject::addCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
655 throw ( uno::RuntimeException
)
657 ::osl::MutexGuard
aGuard( m_aMutex
);
659 throw lang::DisposedException(); // TODO
661 if ( !m_pInterfaceContainer
)
662 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
664 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< util::XCloseListener
>*)0 ), xListener
);
667 //----------------------------------------------
668 void SAL_CALL
OCommonEmbeddedObject::removeCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
669 throw (uno::RuntimeException
)
671 ::osl::MutexGuard
aGuard( m_aMutex
);
672 if ( m_pInterfaceContainer
)
673 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< util::XCloseListener
>*)0 ),
677 //------------------------------------------------------
678 void SAL_CALL
OCommonEmbeddedObject::addEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
679 throw ( uno::RuntimeException
)
681 ::osl::MutexGuard
aGuard( m_aMutex
);
683 throw lang::DisposedException(); // TODO
685 if ( !m_pInterfaceContainer
)
686 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
688 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< document::XEventListener
>*)0 ), xListener
);
691 //------------------------------------------------------
692 void SAL_CALL
OCommonEmbeddedObject::removeEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
693 throw ( uno::RuntimeException
)
695 ::osl::MutexGuard
aGuard( m_aMutex
);
696 if ( m_pInterfaceContainer
)
697 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< document::XEventListener
>*)0 ),