1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <commonembobj.hxx>
30 #include <com/sun/star/embed/EmbedStates.hpp>
31 #include <com/sun/star/embed/EmbedVerbs.hpp>
32 #include <com/sun/star/embed/XStorage.hpp>
33 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
34 #include <com/sun/star/embed/XInplaceClient.hpp>
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/beans/NamedValue.hpp>
38 #include <cppuhelper/typeprovider.hxx>
39 #include <cppuhelper/interfacecontainer.h>
40 #include <comphelper/mimeconfighelper.hxx>
42 #include "closepreventer.hxx"
43 #include "intercept.hxx"
45 using namespace ::com::sun::star
;
48 uno::Sequence
< beans::PropertyValue
> GetValuableArgs_Impl( const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
49 sal_Bool bCanUseDocumentBaseURL
);
51 //------------------------------------------------------
52 OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
,
53 const uno::Sequence
< beans::NamedValue
>& aObjProps
)
54 : m_pDocHolder( NULL
)
55 , m_pInterfaceContainer( NULL
)
56 , m_bReadOnly( sal_False
)
57 , m_bDisposed( sal_False
)
58 , m_bClosed( sal_False
)
59 , m_nObjectState( -1 )
60 , m_nTargetState( -1 )
61 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
62 , m_xFactory( xFactory
)
64 , m_bEmbeddedScriptSupport( sal_True
)
65 , m_bDocumentRecoverySupport( sal_True
)
66 , m_bWaitSaveCompleted( sal_False
)
67 , m_bIsLink( sal_False
)
68 , m_bLinkHasPassword( sal_False
)
69 , m_bHasClonedSize( sal_False
)
70 , m_nClonedMapUnit( 0 )
72 CommonInit_Impl( aObjProps
);
75 //------------------------------------------------------
76 OCommonEmbeddedObject::OCommonEmbeddedObject(
77 const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
,
78 const uno::Sequence
< beans::NamedValue
>& aObjProps
,
79 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
80 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
81 : m_pDocHolder( NULL
)
82 , m_pInterfaceContainer( NULL
)
83 , m_bReadOnly( sal_False
)
84 , m_bDisposed( sal_False
)
85 , m_bClosed( sal_False
)
86 , m_nObjectState( embed::EmbedStates::LOADED
)
87 , m_nTargetState( -1 )
88 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
89 , m_xFactory( xFactory
)
91 , m_bEmbeddedScriptSupport( sal_True
)
92 , m_bDocumentRecoverySupport( sal_True
)
93 , m_bWaitSaveCompleted( sal_False
)
94 , m_bIsLink( sal_True
)
95 , m_bLinkHasPassword( sal_False
)
96 , m_bHasClonedSize( sal_False
)
97 , m_nClonedMapUnit( 0 )
99 // linked object has no own persistence so it is in loaded state starting from creation
100 LinkInit_Impl( aObjProps
, aMediaDescr
, aObjectDescr
);
103 //------------------------------------------------------
104 void OCommonEmbeddedObject::CommonInit_Impl( const uno::Sequence
< beans::NamedValue
>& aObjectProps
)
106 OSL_ENSURE( m_xFactory
.is(), "No ServiceFactory is provided!\n" );
107 if ( !m_xFactory
.is() )
108 throw uno::RuntimeException();
110 m_pDocHolder
= new DocumentHolder( m_xFactory
, this );
111 m_pDocHolder
->acquire();
113 // parse configuration entries
114 // TODO/LATER: in future UI names can be also provided here
115 for ( sal_Int32 nInd
= 0; nInd
< aObjectProps
.getLength(); nInd
++ )
117 if ( aObjectProps
[nInd
].Name
== "ClassID" )
118 aObjectProps
[nInd
].Value
>>= m_aClassID
;
119 else if ( aObjectProps
[nInd
].Name
== "ObjectDocumentServiceName" )
120 aObjectProps
[nInd
].Value
>>= m_aDocServiceName
;
121 else if ( aObjectProps
[nInd
].Name
== "ObjectDocumentFilterName" )
122 aObjectProps
[nInd
].Value
>>= m_aPresetFilterName
;
123 else if ( aObjectProps
[nInd
].Name
== "ObjectMiscStatus" )
124 aObjectProps
[nInd
].Value
>>= m_nMiscStatus
;
125 else if ( aObjectProps
[nInd
].Name
== "ObjectVerbs" )
126 aObjectProps
[nInd
].Value
>>= m_aObjectVerbs
;
129 if ( m_aClassID
.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
130 throw uno::RuntimeException(); // something goes really wrong
133 m_aAcceptedStates
.realloc( NUM_SUPPORTED_STATES
);
135 m_aAcceptedStates
[0] = embed::EmbedStates::LOADED
;
136 m_aAcceptedStates
[1] = embed::EmbedStates::RUNNING
;
137 m_aAcceptedStates
[2] = embed::EmbedStates::INPLACE_ACTIVE
;
138 m_aAcceptedStates
[3] = embed::EmbedStates::UI_ACTIVE
;
139 m_aAcceptedStates
[4] = embed::EmbedStates::ACTIVE
;
142 // intermediate states
143 // In the following table the first index points to starting state,
144 // the second one to the target state, and the sequence referenced by
145 // first two indexes contains intermediate states, that should be
146 // passed by object to reach the target state.
147 // If the sequence is empty that means that indirect switch from start
148 // state to the target state is forbidden, only if direct switch is possible
149 // the state can be reached.
151 m_pIntermediateStatesSeqs
[0][2].realloc( 1 );
152 m_pIntermediateStatesSeqs
[0][2][0] = embed::EmbedStates::RUNNING
;
154 m_pIntermediateStatesSeqs
[0][3].realloc( 2 );
155 m_pIntermediateStatesSeqs
[0][3][0] = embed::EmbedStates::RUNNING
;
156 m_pIntermediateStatesSeqs
[0][3][1] = embed::EmbedStates::INPLACE_ACTIVE
;
158 m_pIntermediateStatesSeqs
[0][4].realloc( 1 );
159 m_pIntermediateStatesSeqs
[0][4][0] = embed::EmbedStates::RUNNING
;
161 m_pIntermediateStatesSeqs
[1][3].realloc( 1 );
162 m_pIntermediateStatesSeqs
[1][3][0] = embed::EmbedStates::INPLACE_ACTIVE
;
164 m_pIntermediateStatesSeqs
[2][0].realloc( 1 );
165 m_pIntermediateStatesSeqs
[2][0][0] = embed::EmbedStates::RUNNING
;
167 m_pIntermediateStatesSeqs
[3][0].realloc( 2 );
168 m_pIntermediateStatesSeqs
[3][0][0] = embed::EmbedStates::INPLACE_ACTIVE
;
169 m_pIntermediateStatesSeqs
[3][0][1] = embed::EmbedStates::RUNNING
;
171 m_pIntermediateStatesSeqs
[3][1].realloc( 1 );
172 m_pIntermediateStatesSeqs
[3][1][0] = embed::EmbedStates::INPLACE_ACTIVE
;
174 m_pIntermediateStatesSeqs
[4][0].realloc( 1 );
175 m_pIntermediateStatesSeqs
[4][0][0] = embed::EmbedStates::RUNNING
;
178 sal_Int32 nVerbTableSize
= 0;
179 for ( sal_Int32 nVerbInd
= 0; nVerbInd
< m_aObjectVerbs
.getLength(); nVerbInd
++ )
181 if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_PRIMARY
)
183 m_aVerbTable
.realloc( ++nVerbTableSize
);
184 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
185 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
186 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
188 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_SHOW
)
190 m_aVerbTable
.realloc( ++nVerbTableSize
);
191 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
192 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
193 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
195 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_OPEN
)
197 m_aVerbTable
.realloc( ++nVerbTableSize
);
198 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
199 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
200 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::ACTIVE
;
202 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE
)
204 m_aVerbTable
.realloc( ++nVerbTableSize
);
205 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
206 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
207 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::INPLACE_ACTIVE
;
209 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
)
211 m_aVerbTable
.realloc( ++nVerbTableSize
);
212 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
213 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
214 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
216 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_HIDE
)
218 m_aVerbTable
.realloc( ++nVerbTableSize
);
219 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
220 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
221 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::RUNNING
;
226 //------------------------------------------------------
227 void OCommonEmbeddedObject::LinkInit_Impl(
228 const uno::Sequence
< beans::NamedValue
>& aObjectProps
,
229 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
230 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
232 // setPersistance has no effect on own links, so the complete initialization must be done here
234 for ( sal_Int32 nInd
= 0; nInd
< aMediaDescr
.getLength(); nInd
++ )
235 if ( aMediaDescr
[nInd
].Name
== "URL" )
236 aMediaDescr
[nInd
].Value
>>= m_aLinkURL
;
237 else if ( aMediaDescr
[nInd
].Name
== "FilterName" )
238 aMediaDescr
[nInd
].Value
>>= m_aLinkFilterName
;
240 OSL_ENSURE( m_aLinkURL
.getLength() && m_aLinkFilterName
.getLength(), "Filter and URL must be provided!\n" );
242 m_bReadOnly
= sal_True
;
243 if ( m_aLinkFilterName
.getLength() )
245 ::comphelper::MimeConfigurationHelper
aHelper( m_xFactory
);
246 ::rtl::OUString aExportFilterName
= aHelper
.GetExportFilterFromImportFilter( m_aLinkFilterName
);
247 m_bReadOnly
= !( aExportFilterName
.equals( m_aLinkFilterName
) );
250 m_aDocMediaDescriptor
= GetValuableArgs_Impl( aMediaDescr
, sal_False
);
252 uno::Reference
< frame::XDispatchProviderInterceptor
> xDispatchInterceptor
;
253 for ( sal_Int32 nObjInd
= 0; nObjInd
< aObjectDescr
.getLength(); nObjInd
++ )
254 if ( aObjectDescr
[nObjInd
].Name
== "OutplaceDispatchInterceptor" )
256 aObjectDescr
[nObjInd
].Value
>>= xDispatchInterceptor
;
259 else if ( aObjectDescr
[nObjInd
].Name
== "Parent" )
261 aObjectDescr
[nObjInd
].Value
>>= m_xParent
;
264 CommonInit_Impl( aObjectProps
);
266 if ( xDispatchInterceptor
.is() )
267 m_pDocHolder
->SetOutplaceDispatchInterceptor( xDispatchInterceptor
);
270 //------------------------------------------------------
271 OCommonEmbeddedObject::~OCommonEmbeddedObject()
273 if ( m_pInterfaceContainer
|| m_pDocHolder
)
277 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
279 if ( m_pInterfaceContainer
)
281 m_pInterfaceContainer
->disposeAndClear( aSource
);
283 delete m_pInterfaceContainer
;
284 m_pInterfaceContainer
= NULL
;
286 } catch( const uno::Exception
& ) {}
291 m_pDocHolder
->CloseFrame();
293 m_pDocHolder
->CloseDocument( sal_True
, sal_True
);
294 } catch ( const uno::Exception
& ) {}
295 m_pDocHolder
->FreeOffice();
297 m_pDocHolder
->release();
300 } catch( const uno::Exception
& ) {}
304 //------------------------------------------------------
305 void OCommonEmbeddedObject::requestPositioning( const awt::Rectangle
& aRect
)
307 // the method is called in case object is inplace active and the object window was resized
309 OSL_ENSURE( m_xClientSite
.is(), "The client site must be set for inplace active object!\n" );
310 if ( m_xClientSite
.is() )
312 uno::Reference
< embed::XInplaceClient
> xInplaceClient( m_xClientSite
, uno::UNO_QUERY
);
314 OSL_ENSURE( xInplaceClient
.is(), "The client site must support XInplaceClient to allow inplace activation!\n" );
315 if ( xInplaceClient
.is() )
318 xInplaceClient
->changedPlacement( aRect
);
320 catch( const uno::Exception
& )
322 OSL_FAIL( "Exception on request to resize!\n" );
328 //------------------------------------------------------
329 void OCommonEmbeddedObject::PostEvent_Impl( const ::rtl::OUString
& aEventName
)
331 if ( m_pInterfaceContainer
)
333 ::cppu::OInterfaceContainerHelper
* pIC
= m_pInterfaceContainer
->getContainer(
334 ::getCppuType((const uno::Reference
< document::XEventListener
>*)0) );
337 document::EventObject aEvent
;
338 aEvent
.EventName
= aEventName
;
339 aEvent
.Source
= uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >( this ) );
340 // For now all the events are sent as object events
341 // aEvent.Source = ( xSource.is() ? xSource
342 // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
343 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
344 while( aIt
.hasMoreElements() )
348 ((document::XEventListener
*)aIt
.next())->notifyEvent( aEvent
);
350 catch( const uno::RuntimeException
& )
355 // the listener could dispose the object.
363 //------------------------------------------------------
364 uno::Any SAL_CALL
OCommonEmbeddedObject::queryInterface( const uno::Type
& rType
)
365 throw( uno::RuntimeException
)
369 if ( rType
== ::getCppuType( (uno::Reference
< embed::XEmbeddedObject
> const *)0 ))
371 void * p
= static_cast< embed::XEmbeddedObject
* >( this );
372 return uno::Any( &p
, rType
);
375 aReturn
<<= ::cppu::queryInterface(
377 static_cast< embed::XInplaceObject
* >( this ),
378 static_cast< embed::XVisualObject
* >( this ),
379 static_cast< embed::XCommonEmbedPersist
* >( static_cast< embed::XEmbedPersist
* >( this ) ),
380 static_cast< embed::XEmbedPersist
* >( this ),
381 static_cast< embed::XLinkageSupport
* >( this ),
382 static_cast< embed::XStateChangeBroadcaster
* >( this ),
383 static_cast< embed::XClassifiedObject
* >( this ),
384 static_cast< embed::XComponentSupplier
* >( this ),
385 static_cast< util::XCloseable
* >( this ),
386 static_cast< container::XChild
* >( this ),
387 static_cast< chart2::XDefaultSizeTransmitter
* >( this ),
388 static_cast< document::XEventBroadcaster
* >( this ) );
390 if ( aReturn
.hasValue() )
393 return ::cppu::OWeakObject::queryInterface( rType
) ;
397 //------------------------------------------------------
398 void SAL_CALL
OCommonEmbeddedObject::acquire()
401 ::cppu::OWeakObject::acquire() ;
404 //------------------------------------------------------
405 void SAL_CALL
OCommonEmbeddedObject::release()
408 ::cppu::OWeakObject::release() ;
411 //------------------------------------------------------
412 uno::Sequence
< uno::Type
> SAL_CALL
OCommonEmbeddedObject::getTypes()
413 throw( uno::RuntimeException
)
415 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
417 if ( !pTypeCollection
)
419 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
420 if ( !pTypeCollection
)
424 static ::cppu::OTypeCollection
aTypeCollection(
425 ::getCppuType( (const uno::Reference
< lang::XTypeProvider
>*)NULL
),
426 ::getCppuType( (const uno::Reference
< embed::XEmbeddedObject
>*)NULL
),
427 ::getCppuType( (const uno::Reference
< embed::XInplaceObject
>*)NULL
),
428 ::getCppuType( (const uno::Reference
< embed::XCommonEmbedPersist
>*)NULL
),
429 ::getCppuType( (const uno::Reference
< container::XChild
>*)NULL
),
430 ::getCppuType( (const uno::Reference
< embed::XLinkageSupport
>*)NULL
) );
432 pTypeCollection
= &aTypeCollection
;
436 static ::cppu::OTypeCollection
aTypeCollection(
437 ::getCppuType( (const uno::Reference
< lang::XTypeProvider
>*)NULL
),
438 ::getCppuType( (const uno::Reference
< embed::XEmbeddedObject
>*)NULL
),
439 ::getCppuType( (const uno::Reference
< embed::XInplaceObject
>*)NULL
),
440 ::getCppuType( (const uno::Reference
< embed::XCommonEmbedPersist
>*)NULL
),
441 ::getCppuType( (const uno::Reference
< container::XChild
>*)NULL
),
442 ::getCppuType( (const uno::Reference
< embed::XEmbedPersist
>*)NULL
) );
444 pTypeCollection
= &aTypeCollection
;
449 return pTypeCollection
->getTypes() ;
453 //------------------------------------------------------
454 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getImplementationId()
455 throw( uno::RuntimeException
)
457 static ::cppu::OImplementationId
* pID
= NULL
;
461 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() ) ;
464 static ::cppu::OImplementationId
aID( sal_False
) ;
469 return pID
->getImplementationId() ;
472 //------------------------------------------------------
473 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getClassID()
474 throw ( uno::RuntimeException
)
477 throw lang::DisposedException();
482 //------------------------------------------------------
483 ::rtl::OUString SAL_CALL
OCommonEmbeddedObject::getClassName()
484 throw ( uno::RuntimeException
)
487 throw lang::DisposedException();
492 //------------------------------------------------------
493 void SAL_CALL
OCommonEmbeddedObject::setClassInfo(
494 const uno::Sequence
< sal_Int8
>& /*aClassID*/, const ::rtl::OUString
& /*aClassName*/ )
495 throw ( lang::NoSupportException
,
496 uno::RuntimeException
)
498 // the object class info can not be changed explicitly
499 throw lang::NoSupportException(); //TODO:
502 //------------------------------------------------------
503 uno::Reference
< util::XCloseable
> SAL_CALL
OCommonEmbeddedObject::getComponent()
504 throw ( uno::RuntimeException
)
506 ::osl::MutexGuard
aGuard( m_aMutex
);
508 throw lang::DisposedException(); // TODO
511 if ( m_nObjectState
== -1 )
513 // the object is still not loaded
514 throw uno::RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Can't store object without persistence!\n" )),
515 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
518 return uno::Reference
< util::XCloseable
>( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
521 //----------------------------------------------
522 void SAL_CALL
OCommonEmbeddedObject::addStateChangeListener( const uno::Reference
< embed::XStateChangeListener
>& xListener
)
523 throw ( uno::RuntimeException
)
525 ::osl::MutexGuard
aGuard( m_aMutex
);
527 throw lang::DisposedException(); // TODO
529 if ( !m_pInterfaceContainer
)
530 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
532 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< embed::XStateChangeListener
>*)0 ),
536 //----------------------------------------------
537 void SAL_CALL
OCommonEmbeddedObject::removeStateChangeListener(
538 const uno::Reference
< embed::XStateChangeListener
>& xListener
)
539 throw (uno::RuntimeException
)
541 ::osl::MutexGuard
aGuard( m_aMutex
);
542 if ( m_pInterfaceContainer
)
543 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< embed::XStateChangeListener
>*)0 ),
547 //----------------------------------------------
548 void SAL_CALL
OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership
)
549 throw ( util::CloseVetoException
,
550 uno::RuntimeException
)
552 ::osl::MutexGuard
aGuard( m_aMutex
);
554 throw lang::DisposedException(); // TODO
556 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >( this ) );
557 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
559 if ( m_pInterfaceContainer
)
561 ::cppu::OInterfaceContainerHelper
* pContainer
=
562 m_pInterfaceContainer
->getContainer( ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
563 if ( pContainer
!= NULL
)
565 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
566 while (pIterator
.hasMoreElements())
570 ((util::XCloseListener
*)pIterator
.next())->queryClosing( aSource
, bDeliverOwnership
);
572 catch( const uno::RuntimeException
& )
579 pContainer
= m_pInterfaceContainer
->getContainer(
580 ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
581 if ( pContainer
!= NULL
)
583 ::cppu::OInterfaceIteratorHelper
pCloseIterator(*pContainer
);
584 while (pCloseIterator
.hasMoreElements())
588 ((util::XCloseListener
*)pCloseIterator
.next())->notifyClosing( aSource
);
590 catch( const uno::RuntimeException
& )
592 pCloseIterator
.remove();
597 m_pInterfaceContainer
->disposeAndClear( aSource
);
600 m_bDisposed
= sal_True
; // the object is disposed now for outside
602 // it is possible that the document can not be closed, in this case if the argument is false
603 // the exception will be thrown otherwise in addition to exception the object must register itself
604 // as termination listener and listen for document events
608 m_pDocHolder
->CloseFrame();
611 m_pDocHolder
->CloseDocument( bDeliverOwnership
, bDeliverOwnership
);
613 catch( const uno::Exception
& )
615 if ( bDeliverOwnership
)
617 m_pDocHolder
->release();
619 m_bClosed
= sal_True
;
625 m_pDocHolder
->FreeOffice();
627 m_pDocHolder
->release();
631 // TODO: for now the storage will be disposed by the object, but after the document
632 // will use the storage, the storage will be disposed by the document and recreated by the object
633 if ( m_xObjectStorage
.is() )
635 uno::Reference
< lang::XComponent
> xComp( m_xObjectStorage
, uno::UNO_QUERY
);
636 OSL_ENSURE( xComp
.is(), "Storage does not support XComponent!\n" );
642 } catch ( const uno::Exception
& ) {}
645 m_xObjectStorage
.clear();
646 m_xRecoveryStorage
.clear();
649 m_bClosed
= sal_True
; // the closing succeeded
652 //----------------------------------------------
653 void SAL_CALL
OCommonEmbeddedObject::addCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
654 throw ( uno::RuntimeException
)
656 ::osl::MutexGuard
aGuard( m_aMutex
);
658 throw lang::DisposedException(); // TODO
660 if ( !m_pInterfaceContainer
)
661 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
663 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< util::XCloseListener
>*)0 ), xListener
);
666 //----------------------------------------------
667 void SAL_CALL
OCommonEmbeddedObject::removeCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
668 throw (uno::RuntimeException
)
670 ::osl::MutexGuard
aGuard( m_aMutex
);
671 if ( m_pInterfaceContainer
)
672 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< util::XCloseListener
>*)0 ),
676 //------------------------------------------------------
677 void SAL_CALL
OCommonEmbeddedObject::addEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
678 throw ( uno::RuntimeException
)
680 ::osl::MutexGuard
aGuard( m_aMutex
);
682 throw lang::DisposedException(); // TODO
684 if ( !m_pInterfaceContainer
)
685 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
687 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< document::XEventListener
>*)0 ), xListener
);
690 //------------------------------------------------------
691 void SAL_CALL
OCommonEmbeddedObject::removeEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
692 throw ( uno::RuntimeException
)
694 ::osl::MutexGuard
aGuard( m_aMutex
);
695 if ( m_pInterfaceContainer
)
696 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< document::XEventListener
>*)0 ),
700 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */