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 <commonembobj.hxx>
21 #include <com/sun/star/embed/EmbedStates.hpp>
22 #include <com/sun/star/embed/EmbedVerbs.hpp>
23 #include <com/sun/star/embed/XStorage.hpp>
24 #include <com/sun/star/embed/EmbedUpdateModes.hpp>
25 #include <com/sun/star/embed/XInplaceClient.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/beans/NamedValue.hpp>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <cppuhelper/interfacecontainer.h>
31 #include <comphelper/mimeconfighelper.hxx>
32 #include <comphelper/processfactory.hxx>
34 #include "closepreventer.hxx"
35 #include "intercept.hxx"
37 using namespace ::com::sun::star
;
40 uno::Sequence
< beans::PropertyValue
> GetValuableArgs_Impl( const uno::Sequence
< beans::PropertyValue
>& aMedDescr
,
41 sal_Bool bCanUseDocumentBaseURL
);
43 //------------------------------------------------------
44 OCommonEmbeddedObject::OCommonEmbeddedObject( const uno::Reference
< uno::XComponentContext
>& rxContext
,
45 const uno::Sequence
< beans::NamedValue
>& aObjProps
)
46 : m_pDocHolder( NULL
)
47 , m_pInterfaceContainer( NULL
)
48 , m_bReadOnly( sal_False
)
49 , m_bDisposed( sal_False
)
50 , m_bClosed( sal_False
)
51 , m_nObjectState( -1 )
52 , m_nTargetState( -1 )
53 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
54 , m_xContext( rxContext
)
56 , m_bEmbeddedScriptSupport( sal_True
)
57 , m_bDocumentRecoverySupport( sal_True
)
58 , m_bWaitSaveCompleted( sal_False
)
59 , m_bIsLink( sal_False
)
60 , m_bLinkHasPassword( sal_False
)
61 , m_bHasClonedSize( sal_False
)
62 , m_nClonedMapUnit( 0 )
64 CommonInit_Impl( aObjProps
);
67 //------------------------------------------------------
68 OCommonEmbeddedObject::OCommonEmbeddedObject(
69 const uno::Reference
< uno::XComponentContext
>& rxContext
,
70 const uno::Sequence
< beans::NamedValue
>& aObjProps
,
71 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
72 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
73 : m_pDocHolder( NULL
)
74 , m_pInterfaceContainer( NULL
)
75 , m_bReadOnly( sal_False
)
76 , m_bDisposed( sal_False
)
77 , m_bClosed( sal_False
)
78 , m_nObjectState( embed::EmbedStates::LOADED
)
79 , m_nTargetState( -1 )
80 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
81 , m_xContext( rxContext
)
83 , m_bEmbeddedScriptSupport( sal_True
)
84 , m_bDocumentRecoverySupport( sal_True
)
85 , m_bWaitSaveCompleted( sal_False
)
86 , m_bIsLink( sal_True
)
87 , m_bLinkHasPassword( sal_False
)
88 , m_bHasClonedSize( sal_False
)
89 , m_nClonedMapUnit( 0 )
91 // linked object has no own persistence so it is in loaded state starting from creation
92 LinkInit_Impl( aObjProps
, aMediaDescr
, aObjectDescr
);
95 //------------------------------------------------------
96 void OCommonEmbeddedObject::CommonInit_Impl( const uno::Sequence
< beans::NamedValue
>& aObjectProps
)
98 OSL_ENSURE( m_xContext
.is(), "No ServiceFactory is provided!\n" );
99 if ( !m_xContext
.is() )
100 throw uno::RuntimeException();
102 m_pDocHolder
= new DocumentHolder( m_xContext
, this );
103 m_pDocHolder
->acquire();
105 // parse configuration entries
106 // TODO/LATER: in future UI names can be also provided here
107 for ( sal_Int32 nInd
= 0; nInd
< aObjectProps
.getLength(); nInd
++ )
109 if ( aObjectProps
[nInd
].Name
== "ClassID" )
110 aObjectProps
[nInd
].Value
>>= m_aClassID
;
111 else if ( aObjectProps
[nInd
].Name
== "ObjectDocumentServiceName" )
112 aObjectProps
[nInd
].Value
>>= m_aDocServiceName
;
113 else if ( aObjectProps
[nInd
].Name
== "ObjectDocumentFilterName" )
114 aObjectProps
[nInd
].Value
>>= m_aPresetFilterName
;
115 else if ( aObjectProps
[nInd
].Name
== "ObjectMiscStatus" )
116 aObjectProps
[nInd
].Value
>>= m_nMiscStatus
;
117 else if ( aObjectProps
[nInd
].Name
== "ObjectVerbs" )
118 aObjectProps
[nInd
].Value
>>= m_aObjectVerbs
;
121 if ( m_aClassID
.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
122 throw uno::RuntimeException(); // something goes really wrong
125 m_aAcceptedStates
.realloc( NUM_SUPPORTED_STATES
);
127 m_aAcceptedStates
[0] = embed::EmbedStates::LOADED
;
128 m_aAcceptedStates
[1] = embed::EmbedStates::RUNNING
;
129 m_aAcceptedStates
[2] = embed::EmbedStates::INPLACE_ACTIVE
;
130 m_aAcceptedStates
[3] = embed::EmbedStates::UI_ACTIVE
;
131 m_aAcceptedStates
[4] = embed::EmbedStates::ACTIVE
;
134 // intermediate states
135 // In the following table the first index points to starting state,
136 // the second one to the target state, and the sequence referenced by
137 // first two indexes contains intermediate states, that should be
138 // passed by object to reach the target state.
139 // If the sequence is empty that means that indirect switch from start
140 // state to the target state is forbidden, only if direct switch is possible
141 // the state can be reached.
143 m_pIntermediateStatesSeqs
[0][2].realloc( 1 );
144 m_pIntermediateStatesSeqs
[0][2][0] = embed::EmbedStates::RUNNING
;
146 m_pIntermediateStatesSeqs
[0][3].realloc( 2 );
147 m_pIntermediateStatesSeqs
[0][3][0] = embed::EmbedStates::RUNNING
;
148 m_pIntermediateStatesSeqs
[0][3][1] = embed::EmbedStates::INPLACE_ACTIVE
;
150 m_pIntermediateStatesSeqs
[0][4].realloc( 1 );
151 m_pIntermediateStatesSeqs
[0][4][0] = embed::EmbedStates::RUNNING
;
153 m_pIntermediateStatesSeqs
[1][3].realloc( 1 );
154 m_pIntermediateStatesSeqs
[1][3][0] = embed::EmbedStates::INPLACE_ACTIVE
;
156 m_pIntermediateStatesSeqs
[2][0].realloc( 1 );
157 m_pIntermediateStatesSeqs
[2][0][0] = embed::EmbedStates::RUNNING
;
159 m_pIntermediateStatesSeqs
[3][0].realloc( 2 );
160 m_pIntermediateStatesSeqs
[3][0][0] = embed::EmbedStates::INPLACE_ACTIVE
;
161 m_pIntermediateStatesSeqs
[3][0][1] = embed::EmbedStates::RUNNING
;
163 m_pIntermediateStatesSeqs
[3][1].realloc( 1 );
164 m_pIntermediateStatesSeqs
[3][1][0] = embed::EmbedStates::INPLACE_ACTIVE
;
166 m_pIntermediateStatesSeqs
[4][0].realloc( 1 );
167 m_pIntermediateStatesSeqs
[4][0][0] = embed::EmbedStates::RUNNING
;
170 sal_Int32 nVerbTableSize
= 0;
171 for ( sal_Int32 nVerbInd
= 0; nVerbInd
< m_aObjectVerbs
.getLength(); nVerbInd
++ )
173 if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_PRIMARY
)
175 m_aVerbTable
.realloc( ++nVerbTableSize
);
176 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
177 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
178 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
180 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_SHOW
)
182 m_aVerbTable
.realloc( ++nVerbTableSize
);
183 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
184 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
185 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
187 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_OPEN
)
189 m_aVerbTable
.realloc( ++nVerbTableSize
);
190 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
191 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
192 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::ACTIVE
;
194 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE
)
196 m_aVerbTable
.realloc( ++nVerbTableSize
);
197 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
198 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
199 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::INPLACE_ACTIVE
;
201 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
)
203 m_aVerbTable
.realloc( ++nVerbTableSize
);
204 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
205 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
206 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::UI_ACTIVE
;
208 else if ( m_aObjectVerbs
[nVerbInd
].VerbID
== embed::EmbedVerbs::MS_OLEVERB_HIDE
)
210 m_aVerbTable
.realloc( ++nVerbTableSize
);
211 m_aVerbTable
[nVerbTableSize
- 1].realloc( 2 );
212 m_aVerbTable
[nVerbTableSize
- 1][0] = m_aObjectVerbs
[nVerbInd
].VerbID
;
213 m_aVerbTable
[nVerbTableSize
- 1][1] = embed::EmbedStates::RUNNING
;
218 //------------------------------------------------------
219 void OCommonEmbeddedObject::LinkInit_Impl(
220 const uno::Sequence
< beans::NamedValue
>& aObjectProps
,
221 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
222 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
224 // setPersistance has no effect on own links, so the complete initialization must be done here
226 for ( sal_Int32 nInd
= 0; nInd
< aMediaDescr
.getLength(); nInd
++ )
227 if ( aMediaDescr
[nInd
].Name
== "URL" )
228 aMediaDescr
[nInd
].Value
>>= m_aLinkURL
;
229 else if ( aMediaDescr
[nInd
].Name
== "FilterName" )
230 aMediaDescr
[nInd
].Value
>>= m_aLinkFilterName
;
232 OSL_ENSURE( m_aLinkURL
.getLength() && m_aLinkFilterName
.getLength(), "Filter and URL must be provided!\n" );
234 m_bReadOnly
= sal_True
;
235 if ( m_aLinkFilterName
.getLength() )
237 ::comphelper::MimeConfigurationHelper
aHelper( m_xContext
);
238 OUString aExportFilterName
= aHelper
.GetExportFilterFromImportFilter( m_aLinkFilterName
);
239 m_bReadOnly
= !( aExportFilterName
.equals( m_aLinkFilterName
) );
242 m_aDocMediaDescriptor
= GetValuableArgs_Impl( aMediaDescr
, sal_False
);
244 uno::Reference
< frame::XDispatchProviderInterceptor
> xDispatchInterceptor
;
245 for ( sal_Int32 nObjInd
= 0; nObjInd
< aObjectDescr
.getLength(); nObjInd
++ )
246 if ( aObjectDescr
[nObjInd
].Name
== "OutplaceDispatchInterceptor" )
248 aObjectDescr
[nObjInd
].Value
>>= xDispatchInterceptor
;
251 else if ( aObjectDescr
[nObjInd
].Name
== "Parent" )
253 aObjectDescr
[nObjInd
].Value
>>= m_xParent
;
256 CommonInit_Impl( aObjectProps
);
258 if ( xDispatchInterceptor
.is() )
259 m_pDocHolder
->SetOutplaceDispatchInterceptor( xDispatchInterceptor
);
262 //------------------------------------------------------
263 OCommonEmbeddedObject::~OCommonEmbeddedObject()
265 if ( m_pInterfaceContainer
|| m_pDocHolder
)
269 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
271 if ( m_pInterfaceContainer
)
273 m_pInterfaceContainer
->disposeAndClear( aSource
);
275 delete m_pInterfaceContainer
;
276 m_pInterfaceContainer
= NULL
;
278 } catch( const uno::Exception
& ) {}
283 m_pDocHolder
->CloseFrame();
285 m_pDocHolder
->CloseDocument( sal_True
, sal_True
);
286 } catch ( const uno::Exception
& ) {}
287 m_pDocHolder
->FreeOffice();
289 m_pDocHolder
->release();
292 } catch( const uno::Exception
& ) {}
296 //------------------------------------------------------
297 void OCommonEmbeddedObject::requestPositioning( const awt::Rectangle
& aRect
)
299 // the method is called in case object is inplace active and the object window was resized
301 OSL_ENSURE( m_xClientSite
.is(), "The client site must be set for inplace active object!\n" );
302 if ( m_xClientSite
.is() )
304 uno::Reference
< embed::XInplaceClient
> xInplaceClient( m_xClientSite
, uno::UNO_QUERY
);
306 OSL_ENSURE( xInplaceClient
.is(), "The client site must support XInplaceClient to allow inplace activation!\n" );
307 if ( xInplaceClient
.is() )
310 xInplaceClient
->changedPlacement( aRect
);
312 catch( const uno::Exception
& )
314 OSL_FAIL( "Exception on request to resize!\n" );
320 //------------------------------------------------------
321 void OCommonEmbeddedObject::PostEvent_Impl( const OUString
& aEventName
)
323 if ( m_pInterfaceContainer
)
325 ::cppu::OInterfaceContainerHelper
* pIC
= m_pInterfaceContainer
->getContainer(
326 ::getCppuType((const uno::Reference
< document::XEventListener
>*)0) );
329 document::EventObject aEvent
;
330 aEvent
.EventName
= aEventName
;
331 aEvent
.Source
= uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >( this ) );
332 // For now all the events are sent as object events
333 // aEvent.Source = ( xSource.is() ? xSource
334 // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
335 ::cppu::OInterfaceIteratorHelper
aIt( *pIC
);
336 while( aIt
.hasMoreElements() )
340 ((document::XEventListener
*)aIt
.next())->notifyEvent( aEvent
);
342 catch( const uno::RuntimeException
& )
347 // the listener could dispose the object.
355 //------------------------------------------------------
356 uno::Any SAL_CALL
OCommonEmbeddedObject::queryInterface( const uno::Type
& rType
)
357 throw( uno::RuntimeException
)
361 if ( rType
== ::getCppuType( (uno::Reference
< embed::XEmbeddedObject
> const *)0 ))
363 void * p
= static_cast< embed::XEmbeddedObject
* >( this );
364 return uno::Any( &p
, rType
);
367 aReturn
<<= ::cppu::queryInterface(
369 static_cast< embed::XInplaceObject
* >( this ),
370 static_cast< embed::XVisualObject
* >( this ),
371 static_cast< embed::XCommonEmbedPersist
* >( static_cast< embed::XEmbedPersist
* >( this ) ),
372 static_cast< embed::XEmbedPersist
* >( this ),
373 static_cast< embed::XLinkageSupport
* >( this ),
374 static_cast< embed::XStateChangeBroadcaster
* >( this ),
375 static_cast< embed::XClassifiedObject
* >( this ),
376 static_cast< embed::XComponentSupplier
* >( this ),
377 static_cast< util::XCloseable
* >( this ),
378 static_cast< container::XChild
* >( this ),
379 static_cast< chart2::XDefaultSizeTransmitter
* >( this ),
380 static_cast< document::XEventBroadcaster
* >( this ) );
382 if ( aReturn
.hasValue() )
385 return ::cppu::OWeakObject::queryInterface( rType
) ;
389 //------------------------------------------------------
390 void SAL_CALL
OCommonEmbeddedObject::acquire()
393 ::cppu::OWeakObject::acquire() ;
396 //------------------------------------------------------
397 void SAL_CALL
OCommonEmbeddedObject::release()
400 ::cppu::OWeakObject::release() ;
403 //------------------------------------------------------
404 uno::Sequence
< uno::Type
> SAL_CALL
OCommonEmbeddedObject::getTypes()
405 throw( uno::RuntimeException
)
407 static ::cppu::OTypeCollection
* pTypeCollection
= NULL
;
409 if ( !pTypeCollection
)
411 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
412 if ( !pTypeCollection
)
416 static ::cppu::OTypeCollection
aTypeCollection(
417 ::getCppuType( (const uno::Reference
< lang::XTypeProvider
>*)NULL
),
418 ::getCppuType( (const uno::Reference
< embed::XEmbeddedObject
>*)NULL
),
419 ::getCppuType( (const uno::Reference
< embed::XInplaceObject
>*)NULL
),
420 ::getCppuType( (const uno::Reference
< embed::XCommonEmbedPersist
>*)NULL
),
421 ::getCppuType( (const uno::Reference
< container::XChild
>*)NULL
),
422 ::getCppuType( (const uno::Reference
< embed::XLinkageSupport
>*)NULL
) );
424 pTypeCollection
= &aTypeCollection
;
428 static ::cppu::OTypeCollection
aTypeCollection(
429 ::getCppuType( (const uno::Reference
< lang::XTypeProvider
>*)NULL
),
430 ::getCppuType( (const uno::Reference
< embed::XEmbeddedObject
>*)NULL
),
431 ::getCppuType( (const uno::Reference
< embed::XInplaceObject
>*)NULL
),
432 ::getCppuType( (const uno::Reference
< embed::XCommonEmbedPersist
>*)NULL
),
433 ::getCppuType( (const uno::Reference
< container::XChild
>*)NULL
),
434 ::getCppuType( (const uno::Reference
< embed::XEmbedPersist
>*)NULL
) );
436 pTypeCollection
= &aTypeCollection
;
441 return pTypeCollection
->getTypes() ;
445 //------------------------------------------------------
446 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getImplementationId()
447 throw( uno::RuntimeException
)
449 static ::cppu::OImplementationId
* pID
= NULL
;
453 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() ) ;
456 static ::cppu::OImplementationId
aID( sal_False
) ;
461 return pID
->getImplementationId() ;
464 //------------------------------------------------------
465 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getClassID()
466 throw ( uno::RuntimeException
)
469 throw lang::DisposedException();
474 //------------------------------------------------------
475 OUString SAL_CALL
OCommonEmbeddedObject::getClassName()
476 throw ( uno::RuntimeException
)
479 throw lang::DisposedException();
484 //------------------------------------------------------
485 void SAL_CALL
OCommonEmbeddedObject::setClassInfo(
486 const uno::Sequence
< sal_Int8
>& /*aClassID*/, const OUString
& /*aClassName*/ )
487 throw ( lang::NoSupportException
,
488 uno::RuntimeException
)
490 // the object class info can not be changed explicitly
491 throw lang::NoSupportException(); //TODO:
494 //------------------------------------------------------
495 uno::Reference
< util::XCloseable
> SAL_CALL
OCommonEmbeddedObject::getComponent()
496 throw ( uno::RuntimeException
)
498 ::osl::MutexGuard
aGuard( m_aMutex
);
500 throw lang::DisposedException(); // TODO
503 if ( m_nObjectState
== -1 )
505 // the object is still not loaded
506 throw uno::RuntimeException( OUString( "Can't store object without persistence!\n" ),
507 uno::Reference
< uno::XInterface
>( static_cast< ::cppu::OWeakObject
* >(this) ) );
510 return uno::Reference
< util::XCloseable
>( m_pDocHolder
->GetComponent(), uno::UNO_QUERY
);
513 //----------------------------------------------
514 void SAL_CALL
OCommonEmbeddedObject::addStateChangeListener( const uno::Reference
< embed::XStateChangeListener
>& xListener
)
515 throw ( uno::RuntimeException
)
517 ::osl::MutexGuard
aGuard( m_aMutex
);
519 throw lang::DisposedException(); // TODO
521 if ( !m_pInterfaceContainer
)
522 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
524 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< embed::XStateChangeListener
>*)0 ),
528 //----------------------------------------------
529 void SAL_CALL
OCommonEmbeddedObject::removeStateChangeListener(
530 const uno::Reference
< embed::XStateChangeListener
>& xListener
)
531 throw (uno::RuntimeException
)
533 ::osl::MutexGuard
aGuard( m_aMutex
);
534 if ( m_pInterfaceContainer
)
535 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< embed::XStateChangeListener
>*)0 ),
539 //----------------------------------------------
540 void SAL_CALL
OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership
)
541 throw ( util::CloseVetoException
,
542 uno::RuntimeException
)
544 ::osl::MutexGuard
aGuard( m_aMutex
);
546 throw lang::DisposedException(); // TODO
548 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >( this ) );
549 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
551 if ( m_pInterfaceContainer
)
553 ::cppu::OInterfaceContainerHelper
* pContainer
=
554 m_pInterfaceContainer
->getContainer( ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
555 if ( pContainer
!= NULL
)
557 ::cppu::OInterfaceIteratorHelper
pIterator(*pContainer
);
558 while (pIterator
.hasMoreElements())
562 ((util::XCloseListener
*)pIterator
.next())->queryClosing( aSource
, bDeliverOwnership
);
564 catch( const uno::RuntimeException
& )
571 pContainer
= m_pInterfaceContainer
->getContainer(
572 ::getCppuType( ( const uno::Reference
< util::XCloseListener
>*) NULL
) );
573 if ( pContainer
!= NULL
)
575 ::cppu::OInterfaceIteratorHelper
pCloseIterator(*pContainer
);
576 while (pCloseIterator
.hasMoreElements())
580 ((util::XCloseListener
*)pCloseIterator
.next())->notifyClosing( aSource
);
582 catch( const uno::RuntimeException
& )
584 pCloseIterator
.remove();
589 m_pInterfaceContainer
->disposeAndClear( aSource
);
592 m_bDisposed
= sal_True
; // the object is disposed now for outside
594 // it is possible that the document can not be closed, in this case if the argument is false
595 // the exception will be thrown otherwise in addition to exception the object must register itself
596 // as termination listener and listen for document events
600 m_pDocHolder
->CloseFrame();
603 m_pDocHolder
->CloseDocument( bDeliverOwnership
, bDeliverOwnership
);
605 catch( const uno::Exception
& )
607 if ( bDeliverOwnership
)
609 m_pDocHolder
->release();
611 m_bClosed
= sal_True
;
617 m_pDocHolder
->FreeOffice();
619 m_pDocHolder
->release();
623 // TODO: for now the storage will be disposed by the object, but after the document
624 // will use the storage, the storage will be disposed by the document and recreated by the object
625 if ( m_xObjectStorage
.is() )
627 uno::Reference
< lang::XComponent
> xComp( m_xObjectStorage
, uno::UNO_QUERY
);
628 OSL_ENSURE( xComp
.is(), "Storage does not support XComponent!\n" );
634 } catch ( const uno::Exception
& ) {}
637 m_xObjectStorage
.clear();
638 m_xRecoveryStorage
.clear();
641 m_bClosed
= sal_True
; // the closing succeeded
644 //----------------------------------------------
645 void SAL_CALL
OCommonEmbeddedObject::addCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
646 throw ( uno::RuntimeException
)
648 ::osl::MutexGuard
aGuard( m_aMutex
);
650 throw lang::DisposedException(); // TODO
652 if ( !m_pInterfaceContainer
)
653 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
655 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< util::XCloseListener
>*)0 ), xListener
);
658 //----------------------------------------------
659 void SAL_CALL
OCommonEmbeddedObject::removeCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
660 throw (uno::RuntimeException
)
662 ::osl::MutexGuard
aGuard( m_aMutex
);
663 if ( m_pInterfaceContainer
)
664 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< util::XCloseListener
>*)0 ),
668 //------------------------------------------------------
669 void SAL_CALL
OCommonEmbeddedObject::addEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
670 throw ( uno::RuntimeException
)
672 ::osl::MutexGuard
aGuard( m_aMutex
);
674 throw lang::DisposedException(); // TODO
676 if ( !m_pInterfaceContainer
)
677 m_pInterfaceContainer
= new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex
);
679 m_pInterfaceContainer
->addInterface( ::getCppuType( (const uno::Reference
< document::XEventListener
>*)0 ), xListener
);
682 //------------------------------------------------------
683 void SAL_CALL
OCommonEmbeddedObject::removeEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
684 throw ( uno::RuntimeException
)
686 ::osl::MutexGuard
aGuard( m_aMutex
);
687 if ( m_pInterfaceContainer
)
688 m_pInterfaceContainer
->removeInterface( ::getCppuType( (const uno::Reference
< document::XEventListener
>*)0 ),
692 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */