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/lang/NoSupportException.hpp>
28 #include <com/sun/star/beans/NamedValue.hpp>
30 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
31 #include <com/sun/star/io/TempFile.hpp>
32 #include <comphelper/multicontainer2.hxx>
33 #include <comphelper/storagehelper.hxx>
35 #include <cppuhelper/queryinterface.hxx>
36 #include <comphelper/mimeconfighelper.hxx>
39 #include <vcl/weld.hxx>
40 #include <vcl/stdtext.hxx>
41 #include <strings.hrc>
42 #include <osl/file.hxx>
43 #include <comphelper/DirectoryHelper.hxx>
45 #include <vcl/svapp.hxx>
46 #include <comphelper/diagnose_ex.hxx>
47 #include <cppuhelper/supportsservice.hxx>
48 #include <comphelper/sequenceashashmap.hxx>
50 #include "persistence.hxx"
54 using namespace ::com::sun::star
;
57 OCommonEmbeddedObject::OCommonEmbeddedObject( uno::Reference
< uno::XComponentContext
> xContext
,
58 const uno::Sequence
< beans::NamedValue
>& aObjProps
)
59 : m_bReadOnly( false )
60 , m_bDisposed( false )
62 , m_nObjectState( -1 )
63 , m_nTargetState( -1 )
64 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
65 , m_xContext(std::move( xContext
))
67 , m_bEmbeddedScriptSupport( true )
68 , m_bDocumentRecoverySupport( true )
69 , m_bWaitSaveCompleted( false )
70 , m_bIsLinkURL( false )
71 , m_bLinkTempFileChanged( false )
73 , m_bOleUpdate( false )
74 , m_bInHndFunc( false )
75 , m_bLinkHasPassword( false )
77 , m_bHasClonedSize( false )
78 , m_nClonedMapUnit( 0 )
80 CommonInit_Impl( aObjProps
);
84 OCommonEmbeddedObject::OCommonEmbeddedObject(
85 uno::Reference
< uno::XComponentContext
> xContext
,
86 const uno::Sequence
< beans::NamedValue
>& aObjProps
,
87 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
88 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
89 : m_bReadOnly( false )
90 , m_bDisposed( false )
92 , m_nObjectState( embed::EmbedStates::LOADED
)
93 , m_nTargetState( -1 )
94 , m_nUpdateMode ( embed::EmbedUpdateModes::ALWAYS_UPDATE
)
95 , m_xContext(std::move( xContext
))
97 , m_bEmbeddedScriptSupport( true )
98 , m_bDocumentRecoverySupport( true )
99 , m_bWaitSaveCompleted( false )
100 , m_bIsLinkURL( true )
101 , m_bLinkTempFileChanged( false )
103 , m_bOleUpdate( false )
104 , m_bInHndFunc( false )
105 , m_bLinkHasPassword( false )
107 , m_bHasClonedSize( false )
108 , m_nClonedMapUnit( 0 )
110 // linked object has no own persistence so it is in loaded state starting from creation
111 LinkInit_Impl( aObjProps
, aMediaDescr
, aObjectDescr
);
115 void OCommonEmbeddedObject::CommonInit_Impl( const uno::Sequence
< beans::NamedValue
>& aObjectProps
)
117 OSL_ENSURE( m_xContext
.is(), "No ServiceFactory is provided!" );
118 if ( !m_xContext
.is() )
119 throw uno::RuntimeException();
121 m_xDocHolder
= new DocumentHolder( m_xContext
, this );
123 // parse configuration entries
124 // TODO/LATER: in future UI names can be also provided here
125 for ( beans::NamedValue
const & prop
: aObjectProps
)
127 if ( prop
.Name
== "ClassID" )
128 prop
.Value
>>= m_aClassID
;
129 else if ( prop
.Name
== "ObjectDocumentServiceName" )
130 prop
.Value
>>= m_aDocServiceName
;
131 else if ( prop
.Name
== "ObjectDocumentFilterName" )
132 prop
.Value
>>= m_aPresetFilterName
;
133 else if ( prop
.Name
== "ObjectMiscStatus" )
134 prop
.Value
>>= m_nMiscStatus
;
135 else if ( prop
.Name
== "ObjectVerbs" )
136 prop
.Value
>>= m_aObjectVerbs
;
139 if ( m_aClassID
.getLength() != 16 /*|| !m_aDocServiceName.getLength()*/ )
140 throw uno::RuntimeException(); // something goes really wrong
143 for ( auto const & verb
: std::as_const(m_aObjectVerbs
) )
145 if ( verb
.VerbID
== embed::EmbedVerbs::MS_OLEVERB_PRIMARY
)
147 m_aVerbTable
.insert( { verb
.VerbID
, embed::EmbedStates::UI_ACTIVE
} );
149 else if ( verb
.VerbID
== embed::EmbedVerbs::MS_OLEVERB_SHOW
)
151 m_aVerbTable
.insert( { verb
.VerbID
, embed::EmbedStates::UI_ACTIVE
} );
153 else if ( verb
.VerbID
== embed::EmbedVerbs::MS_OLEVERB_OPEN
)
155 m_aVerbTable
.insert( { verb
.VerbID
, embed::EmbedStates::ACTIVE
} );
157 else if ( verb
.VerbID
== embed::EmbedVerbs::MS_OLEVERB_IPACTIVATE
)
159 m_aVerbTable
.insert( { verb
.VerbID
, embed::EmbedStates::INPLACE_ACTIVE
} );
161 else if ( verb
.VerbID
== embed::EmbedVerbs::MS_OLEVERB_UIACTIVATE
)
163 m_aVerbTable
.insert( { verb
.VerbID
, embed::EmbedStates::UI_ACTIVE
} );
165 else if ( verb
.VerbID
== embed::EmbedVerbs::MS_OLEVERB_HIDE
)
167 m_aVerbTable
.insert( { verb
.VerbID
, embed::EmbedStates::RUNNING
} );
173 void OCommonEmbeddedObject::LinkInit_Impl(
174 const uno::Sequence
< beans::NamedValue
>& aObjectProps
,
175 const uno::Sequence
< beans::PropertyValue
>& aMediaDescr
,
176 const uno::Sequence
< beans::PropertyValue
>& aObjectDescr
)
178 // setPersistance has no effect on own links, so the complete initialization must be done here
180 for ( beans::PropertyValue
const & prop
: aMediaDescr
)
181 if ( prop
.Name
== "URL" )
182 prop
.Value
>>= m_aLinkURL
;
183 else if ( prop
.Name
== "FilterName" )
184 prop
.Value
>>= m_aLinkFilterName
;
186 OSL_ENSURE( m_aLinkURL
.getLength() && m_aLinkFilterName
.getLength(), "Filter and URL must be provided!" );
189 if ( m_aLinkFilterName
.getLength() )
191 ::comphelper::MimeConfigurationHelper
aHelper( m_xContext
);
192 OUString aExportFilterName
= aHelper
.GetExportFilterFromImportFilter( m_aLinkFilterName
);
193 m_bReadOnly
= aExportFilterName
!= m_aLinkFilterName
;
196 if(m_bIsLinkURL
&& !m_bReadOnly
)
198 // tdf#141529 we have a linked OLE object. To prevent the original OLE
199 // data to be changed each time the OLE gets changed (at deactivate), copy it to
200 // a temporary file. That file will be changed on activated OLE changes then.
201 // The moment the original gets changed itself will now be associated with the
202 // file/document embedding the OLE being changed (see other additions to the
205 // open OLE original data as read input file
206 if ( comphelper::DirectoryHelper::fileExists( m_aLinkURL
) )
208 // create temporary file
209 m_aLinkTempFile
= io::TempFile::create( m_xContext
);
211 m_pLinkFile
.reset( new FileChangedChecker( m_aLinkURL
) );
212 handleLinkedOLE( CopyBackToOLELink::CopyLinkToTempInit
);
216 if(m_aLinkTempFile
.is())
218 uno::Sequence
< beans::PropertyValue
> aAlternativeMediaDescr(aMediaDescr
.getLength());
219 auto aAlternativeMediaDescrRange
= asNonConstRange(aAlternativeMediaDescr
);
221 for ( sal_Int32
a(0); a
< aMediaDescr
.getLength(); a
++ )
223 const beans::PropertyValue
& rSource(aMediaDescr
[a
]);
224 beans::PropertyValue
& rDestination(aAlternativeMediaDescrRange
[a
]);
226 rDestination
.Name
= rSource
.Name
;
227 if(rSource
.Name
== "URL")
228 rDestination
.Value
<<= m_aLinkTempFile
->getUri();
230 rDestination
.Value
= rSource
.Value
;
233 m_aDocMediaDescriptor
= GetValuableArgs_Impl( aAlternativeMediaDescr
, false );
237 m_aDocMediaDescriptor
= GetValuableArgs_Impl( aMediaDescr
, false );
240 uno::Reference
< frame::XDispatchProviderInterceptor
> xDispatchInterceptor
;
241 for ( beans::PropertyValue
const & prop
: aObjectDescr
)
242 if ( prop
.Name
== "OutplaceDispatchInterceptor" )
244 prop
.Value
>>= xDispatchInterceptor
;
247 else if ( prop
.Name
== "Parent" )
249 prop
.Value
>>= m_xParent
;
252 CommonInit_Impl( aObjectProps
);
254 if ( xDispatchInterceptor
.is() )
255 m_xDocHolder
->SetOutplaceDispatchInterceptor( xDispatchInterceptor
);
259 OCommonEmbeddedObject::~OCommonEmbeddedObject()
261 if ( !(m_pInterfaceContainer
|| m_xDocHolder
.is()) )
264 osl_atomic_increment(&m_refCount
);
265 if ( m_pInterfaceContainer
)
268 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
269 m_pInterfaceContainer
->disposeAndClear( aSource
);
270 } catch( const uno::Exception
& ) {}
271 m_pInterfaceContainer
.reset();
275 if ( m_xDocHolder
.is() )
277 m_xDocHolder
->CloseFrame();
279 m_xDocHolder
->CloseDocument( true, true );
280 } catch ( const uno::Exception
& ) {}
281 m_xDocHolder
->FreeOffice();
283 m_xDocHolder
.clear();
285 } catch( const uno::Exception
& ) {}
289 void OCommonEmbeddedObject::requestPositioning( const awt::Rectangle
& aRect
)
291 // the method is called in case object is inplace active and the object window was resized
293 OSL_ENSURE( m_xClientSite
.is(), "The client site must be set for inplace active object!" );
294 if ( !m_xClientSite
.is() )
297 uno::Reference
< embed::XInplaceClient
> xInplaceClient( m_xClientSite
, uno::UNO_QUERY
);
299 OSL_ENSURE( xInplaceClient
.is(), "The client site must support XInplaceClient to allow inplace activation!" );
300 if ( xInplaceClient
.is() )
303 xInplaceClient
->changedPlacement( aRect
);
305 catch( const uno::Exception
& )
307 TOOLS_WARN_EXCEPTION( "embeddedobj", "Exception on request to resize!" );
313 void OCommonEmbeddedObject::PostEvent_Impl( const OUString
& aEventName
)
315 if ( !m_pInterfaceContainer
)
318 comphelper::OInterfaceContainerHelper2
* pIC
= m_pInterfaceContainer
->getContainer(
319 cppu::UnoType
<document::XEventListener
>::get());
323 document::EventObject aEvent
;
324 aEvent
.EventName
= aEventName
;
325 aEvent
.Source
.set( static_cast< ::cppu::OWeakObject
* >( this ) );
326 // For now all the events are sent as object events
327 // aEvent.Source = ( xSource.is() ? xSource
328 // : uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ) );
329 comphelper::OInterfaceIteratorHelper2
aIt( *pIC
);
330 while( aIt
.hasMoreElements() )
334 static_cast<document::XEventListener
*>(aIt
.next())->notifyEvent( aEvent
);
336 catch( const uno::RuntimeException
& )
341 // the listener could dispose the object.
348 int OCommonEmbeddedObject::ShowMsgDialog(TranslateId Msg
, const OUString
& sFileName
)
350 std::locale aResLocale
= Translate::Create( "emo" );
351 OUString aMsg
= Translate::get( Msg
, aResLocale
);
352 OUString aBtn
= Translate::get( BTN_OVERWRITE_TEXT
, aResLocale
);
353 OUString aTemp
= sFileName
;
355 osl::FileBase::getSystemPathFromFileURL( sFileName
, aTemp
);
357 aMsg
= aMsg
.replaceFirst( "%{filename}", aTemp
);
358 weld::Window
* pParent
= Application::GetFrameWeld(m_xClientWindow
);
360 std::unique_ptr
<weld::MessageDialog
> xQueryBox (Application::CreateMessageDialog( pParent
,
361 VclMessageType::Warning
, VclButtonsType::NONE
, aMsg
) );
362 xQueryBox
->add_button( aBtn
, RET_YES
);
363 xQueryBox
->add_button( GetStandardText( StandardButtonType::Cancel
), RET_CANCEL
);
364 xQueryBox
->set_default_response( RET_CANCEL
);
366 return xQueryBox
->run();
370 void OCommonEmbeddedObject::handleLinkedOLE( CopyBackToOLELink eState
)
372 // do not refresh and autosave at the same time
373 // when refresh all, then get both Link and Ole Update, in this case ignore OLE-refresh
374 if ( m_bInHndFunc
|| m_bOleUpdate
|| !m_aLinkTempFile
.is() )
379 bool bLnkFileChg
= m_pLinkFile
->hasFileChanged( false );
380 bool bTmpFileChg
= m_bLinkTempFileChanged
;
383 if ( eState
!= CopyBackToOLELink::CopyLinkToTempInit
&& !bLnkFileChg
&& !bTmpFileChg
)
386 eState
= CopyBackToOLELink::NoCopy
;
388 else if ( ( eState
== CopyBackToOLELink::CopyTempToLink
) && bLnkFileChg
&& !bTmpFileChg
)
390 // Save pressed, but the Link-file is changed, but not the temp-file
391 // in this case update the object with new link data
392 eState
= CopyBackToOLELink::CopyLinkToTempRefresh
;
394 else if ( ( eState
== CopyBackToOLELink::CopyTempToLink
) && bLnkFileChg
&& bTmpFileChg
)
396 // Save pressed, but the Link-file is changed, question to user for overwrite
397 if ( ShowMsgDialog(STR_OVERWRITE_LINK
, m_aLinkURL
) == RET_CANCEL
)
398 eState
= CopyBackToOLELink::NoCopy
;
400 else if ( ( eState
== CopyBackToOLELink::CopyLinkToTemp
) && bTmpFileChg
)
402 // Refresh pressed, but the Temp-file is changed, question to user for overwrite
403 // it is not important it has bLnkFileChg, always overwrite the temp-file
404 if ( ShowMsgDialog( STR_OVERWRITE_TEMP
, m_aLinkURL
) == RET_CANCEL
)
405 eState
= CopyBackToOLELink::NoCopy
;
408 auto writeFile
= [ this ]( const OUString
& SrcName
, const OUString
& DesName
)
410 uno::Reference
< ucb::XSimpleFileAccess2
> xWriteAccess( ucb::SimpleFileAccess::create( m_xContext
) );
411 uno::Reference
< ucb::XSimpleFileAccess
> xReadAccess( ucb::SimpleFileAccess::create( m_xContext
) );
415 uno::Reference
< io::XInputStream
> xInStream( xReadAccess
->openFileRead (SrcName
) );
417 // This is *needed* since OTempFileService calls OTempFileService::readBytes which
418 // ensures the SvStream mpStream gets/is opened, *but* also sets the mnCachedPos from
419 // OTempFileService which still points to the end-of-file (from write-cc'ing).
420 uno::Reference
< io::XSeekable
> xSeek( xInStream
, uno::UNO_QUERY_THROW
);
423 xWriteAccess
->writeFile( DesName
, xInStream
);
424 m_bLinkTempFileChanged
= false;
425 // store the new timestamp
426 m_pLinkFile
->hasFileChanged();
428 catch ( const uno::Exception
& ex
)
431 osl::FileBase::getSystemPathFromFileURL( SrcName
, aMsg
);
432 aMsg
= ex
.Message
+ "\n\n" + aMsg
;
433 weld::Window
* pParent
= Application::GetFrameWeld(m_xClientWindow
);
434 std::unique_ptr
<weld::MessageDialog
> xQueryBox( Application::CreateMessageDialog( pParent
,
435 VclMessageType::Error
, VclButtonsType::Ok
, aMsg
) );
443 case CopyBackToOLELink::NoCopy
:
445 case CopyBackToOLELink::CopyLinkToTemp
: // copy Link-File to Temp-File (Refresh)
446 case CopyBackToOLELink::CopyLinkToTempInit
: //create temp file
447 writeFile( m_aLinkURL
, m_aLinkTempFile
->getUri() );
449 case CopyBackToOLELink::CopyTempToLink
: // copy Temp-File to Link-File (Save)
450 // tdf#141529 if we have a changed copy of the original OLE data we now
451 // need to write it back 'over' the original OLE data
452 writeFile( m_aLinkTempFile
->getUri(), m_aLinkURL
);
454 case CopyBackToOLELink::CopyLinkToTempRefresh
: // need a Refresh not save
461 m_bInHndFunc
= false;
465 uno::Any SAL_CALL
OCommonEmbeddedObject::queryInterface( const uno::Type
& rType
)
469 if ( rType
== cppu::UnoType
<embed::XEmbeddedObject
>::get() )
471 void * p
= static_cast< embed::XEmbeddedObject
* >( this );
472 return uno::Any( &p
, rType
);
474 else if (rType
== cppu::UnoType
<embed::XEmbedPersist2
>::get())
476 void* p
= static_cast<embed::XEmbedPersist2
*>(this);
477 return uno::Any(&p
, rType
);
479 else if (rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
481 void* p
= static_cast<lang::XServiceInfo
*>(this);
482 return uno::Any(&p
, rType
);
484 else if (rType
== cppu::UnoType
<lang::XInitialization
>::get())
486 void* p
= static_cast<lang::XInitialization
*>(this);
487 return uno::Any(&p
, rType
);
489 else if (rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
491 void* p
= static_cast<lang::XTypeProvider
*>(this);
492 return uno::Any(&p
, rType
);
495 aReturn
= ::cppu::queryInterface(
497 static_cast< embed::XInplaceObject
* >( this ),
498 static_cast< embed::XVisualObject
* >( this ),
499 static_cast< embed::XCommonEmbedPersist
* >( static_cast< embed::XEmbedPersist
* >( this ) ),
500 static_cast< embed::XEmbedPersist
* >( this ),
501 static_cast< embed::XLinkageSupport
* >( this ),
502 static_cast< embed::XStateChangeBroadcaster
* >( this ),
503 static_cast< embed::XClassifiedObject
* >( this ),
504 static_cast< embed::XComponentSupplier
* >( this ),
505 static_cast< util::XCloseable
* >( this ),
506 static_cast< container::XChild
* >( this ),
507 static_cast< chart2::XDefaultSizeTransmitter
* >( this ),
508 static_cast< document::XEventBroadcaster
* >( this ) );
510 if ( aReturn
.hasValue() )
513 return ::cppu::OWeakObject::queryInterface( rType
) ;
518 void SAL_CALL
OCommonEmbeddedObject::acquire()
521 ::cppu::OWeakObject::acquire() ;
525 void SAL_CALL
OCommonEmbeddedObject::release()
528 ::cppu::OWeakObject::release() ;
532 uno::Sequence
< sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getClassID()
535 throw lang::DisposedException();
540 OUString SAL_CALL
OCommonEmbeddedObject::getClassName()
543 throw lang::DisposedException();
548 void SAL_CALL
OCommonEmbeddedObject::setClassInfo(
549 const uno::Sequence
< sal_Int8
>& /*aClassID*/, const OUString
& /*aClassName*/ )
551 // the object class info can not be changed explicitly
552 throw lang::NoSupportException(); //TODO:
556 uno::Reference
< util::XCloseable
> SAL_CALL
OCommonEmbeddedObject::getComponent()
558 SolarMutexGuard aGuard
;
560 throw lang::DisposedException(); // TODO
563 if ( m_nObjectState
== -1 )
565 // the object is still not loaded
566 throw uno::RuntimeException( "Can't store object without persistence!",
567 static_cast< ::cppu::OWeakObject
* >(this) );
570 return m_xDocHolder
->GetComponent();
574 void SAL_CALL
OCommonEmbeddedObject::addStateChangeListener( const uno::Reference
< embed::XStateChangeListener
>& xListener
)
576 SolarMutexGuard aGuard
;
578 throw lang::DisposedException(); // TODO
580 if ( !m_pInterfaceContainer
)
581 m_pInterfaceContainer
.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex
));
583 m_pInterfaceContainer
->addInterface( cppu::UnoType
<embed::XStateChangeListener
>::get(),
588 void SAL_CALL
OCommonEmbeddedObject::removeStateChangeListener(
589 const uno::Reference
< embed::XStateChangeListener
>& xListener
)
591 SolarMutexGuard aGuard
;
592 if ( m_pInterfaceContainer
)
593 m_pInterfaceContainer
->removeInterface( cppu::UnoType
<embed::XStateChangeListener
>::get(),
598 void SAL_CALL
OCommonEmbeddedObject::close( sal_Bool bDeliverOwnership
)
600 SolarMutexGuard aGuard
;
602 throw lang::DisposedException(); // TODO
604 uno::Reference
< uno::XInterface
> xSelfHold( static_cast< ::cppu::OWeakObject
* >( this ) );
605 lang::EventObject
aSource( static_cast< ::cppu::OWeakObject
* >( this ) );
607 if ( m_pInterfaceContainer
)
609 comphelper::OInterfaceContainerHelper2
* pContainer
=
610 m_pInterfaceContainer
->getContainer( cppu::UnoType
<util::XCloseListener
>::get());
611 if ( pContainer
!= nullptr )
613 comphelper::OInterfaceIteratorHelper2
pIterator(*pContainer
);
614 while (pIterator
.hasMoreElements())
618 static_cast<util::XCloseListener
*>(pIterator
.next())->queryClosing( aSource
, bDeliverOwnership
);
620 catch( const uno::RuntimeException
& )
627 pContainer
= m_pInterfaceContainer
->getContainer(
628 cppu::UnoType
<util::XCloseListener
>::get());
629 if ( pContainer
!= nullptr )
631 comphelper::OInterfaceIteratorHelper2
pCloseIterator(*pContainer
);
632 while (pCloseIterator
.hasMoreElements())
636 static_cast<util::XCloseListener
*>(pCloseIterator
.next())->notifyClosing( aSource
);
638 catch( const uno::RuntimeException
& )
640 pCloseIterator
.remove();
645 m_pInterfaceContainer
->disposeAndClear( aSource
);
646 m_pInterfaceContainer
.reset();
649 m_bDisposed
= true; // the object is disposed now for outside
651 // it is possible that the document can not be closed, in this case if the argument is false
652 // the exception will be thrown otherwise in addition to exception the object must register itself
653 // as termination listener and listen for document events
655 if ( m_xDocHolder
.is() )
657 m_xDocHolder
->CloseFrame();
660 m_xDocHolder
->CloseDocument( bDeliverOwnership
, bDeliverOwnership
);
662 catch( const uno::Exception
& )
664 if ( bDeliverOwnership
)
666 m_xDocHolder
.clear();
673 m_xDocHolder
->FreeOffice();
675 m_xDocHolder
.clear();
678 // TODO: for now the storage will be disposed by the object, but after the document
679 // will use the storage, the storage will be disposed by the document and recreated by the object
680 if ( m_xObjectStorage
.is() )
683 m_xObjectStorage
->dispose();
684 } catch ( const uno::Exception
& ) {}
686 m_xObjectStorage
.clear();
687 m_xRecoveryStorage
.clear();
690 m_bClosed
= true; // the closing succeeded
694 void SAL_CALL
OCommonEmbeddedObject::addCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
696 SolarMutexGuard aGuard
;
698 throw lang::DisposedException(); // TODO
700 if ( !m_pInterfaceContainer
)
701 m_pInterfaceContainer
.reset(new comphelper::OMultiTypeInterfaceContainerHelper2(m_aMutex
));
703 m_pInterfaceContainer
->addInterface( cppu::UnoType
<util::XCloseListener
>::get(), xListener
);
707 void SAL_CALL
OCommonEmbeddedObject::removeCloseListener( const uno::Reference
< util::XCloseListener
>& xListener
)
709 SolarMutexGuard aGuard
;
710 if ( m_pInterfaceContainer
)
711 m_pInterfaceContainer
->removeInterface( cppu::UnoType
<util::XCloseListener
>::get(),
716 void SAL_CALL
OCommonEmbeddedObject::addEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
718 SolarMutexGuard aGuard
;
720 throw lang::DisposedException(); // TODO
722 if ( !m_pInterfaceContainer
)
723 m_pInterfaceContainer
.reset(new comphelper::OMultiTypeInterfaceContainerHelper2(m_aMutex
));
725 m_pInterfaceContainer
->addInterface( cppu::UnoType
<document::XEventListener
>::get(), xListener
);
729 void SAL_CALL
OCommonEmbeddedObject::removeEventListener( const uno::Reference
< document::XEventListener
>& xListener
)
731 SolarMutexGuard aGuard
;
732 if ( m_pInterfaceContainer
)
733 m_pInterfaceContainer
->removeInterface( cppu::UnoType
<document::XEventListener
>::get(),
737 OUString SAL_CALL
OCommonEmbeddedObject::getImplementationName()
739 return "com.sun.star.comp.embed.OCommonEmbeddedObject";
742 sal_Bool SAL_CALL
OCommonEmbeddedObject::supportsService(const OUString
& ServiceName
)
744 return cppu::supportsService(this, ServiceName
);
747 uno::Sequence
<OUString
> SAL_CALL
OCommonEmbeddedObject::getSupportedServiceNames()
749 return { "com.sun.star.comp.embed.OCommonEmbeddedObject" };
752 uno::Sequence
<uno::Type
> SAL_CALL
OCommonEmbeddedObject::getTypes()
754 static const uno::Sequence
<uno::Type
> aTypes
{
755 cppu::UnoType
<embed::XEmbeddedObject
>::get(),
756 cppu::UnoType
<embed::XEmbedPersist2
>::get(),
757 cppu::UnoType
<embed::XLinkageSupport
>::get(),
758 cppu::UnoType
<embed::XInplaceObject
>::get(),
759 cppu::UnoType
<container::XChild
>::get(),
760 cppu::UnoType
<chart2::XDefaultSizeTransmitter
>::get(),
761 cppu::UnoType
<lang::XServiceInfo
>::get(),
762 cppu::UnoType
<lang::XInitialization
>::get(),
763 cppu::UnoType
<lang::XTypeProvider
>::get(),
768 uno::Sequence
<sal_Int8
> SAL_CALL
OCommonEmbeddedObject::getImplementationId()
770 return uno::Sequence
<sal_Int8
>();
773 void SAL_CALL
OCommonEmbeddedObject::initialize(const uno::Sequence
<uno::Any
>& rArguments
)
775 if (!rArguments
.hasElements())
780 comphelper::SequenceAsHashMap
aMap(rArguments
[0]);
781 auto it
= aMap
.find("ReadOnly");
782 if (it
!= aMap
.end())
784 it
->second
>>= m_bReadOnly
;
788 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */