/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
OleEmbeddedObject::~OleEmbeddedObject()
{
OSL_ENSURE( !m_pInterfaceContainer && !m_pOleComponent && !m_xObjectStream.is(), "The object is not closed! DISASTER is possible!" );
if ( m_pOleComponent || m_pInterfaceContainer || m_xObjectStream.is() )
{ // the component must be cleaned during closing
osl_atomic_increment(&m_refCount); // to avoid crash try {
Dispose();
} catch( const uno::Exception& ) {}
}
if ( !m_aTempURL.isEmpty() )
KillFile_Impl( m_aTempURL, m_xContext );
if ( !m_aTempDumpURL.isEmpty() )
KillFile_Impl( m_aTempDumpURL, m_xContext );
}
m_pOleComponent->removeCloseListener( m_xClosePreventer ); // When releasing the guard below, avoid a case when two threads are doing the same; // store the reference on stack and clear m_pOleComponent in advance
rtl::Reference<OleComponent> pOleComponent(std::move(m_pOleComponent)); try
{
std::optional<osl::ResettableMutexGuardScopedReleaser> oReleaser; if (guard)
oReleaser.emplace(*guard);
pOleComponent->close(false);
} catch( const uno::Exception& )
{
m_pOleComponent = std::move(pOleComponent); // TODO: there should be a special listener to wait for component closing // and to notify object, may be object itself can be such a listener
m_pOleComponent->addCloseListener( m_xClosePreventer ); throw;
}
if ( m_xOwnView.is() )
{
m_xOwnView->Close();
m_xOwnView.clear();
}
if ( m_pOleComponent ) try {
GetRidOfComponent(guard);
} catch( const uno::Exception& )
{
m_bDisposed = true; throw; // TODO: there should be a special listener that will close object when // component is finally closed
}
if ( m_xObjectStream.is() )
{
uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY );
OSL_ENSURE( xComp.is(), "Storage stream doesn't support XComponent!" );
uno::Sequence< sal_Int8 > SAL_CALL OleEmbeddedObject::getClassID()
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper return xWrappedObject->getClassID();
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
return m_aClassID;
}
OUString SAL_CALL OleEmbeddedObject::getClassName()
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper return xWrappedObject->getClassName();
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
return m_aClassName;
}
void SAL_CALL OleEmbeddedObject::setClassInfo( const uno::Sequence< sal_Int8 >& aClassID, const OUString& aClassName )
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->setClassInfo( aClassID, aClassName ); return;
} // end wrapping related part ====================
// the object class info can not be changed explicitly throw lang::NoSupportException(); //TODO:
}
uno::Reference< util::XCloseable > SAL_CALL OleEmbeddedObject::getComponent()
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper return xWrappedObject->getComponent();
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) // || m_nObjectState == embed::EmbedStates::LOADED )
{ // the object is still not running throw uno::RuntimeException( u"The object is not loaded!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
}
assert(!m_pOleComponent.is()); // TODO/LATER: Is it correct??? return uno::Reference< util::XCloseable >(); // throw uno::RuntimeException(); // TODO
}
void SAL_CALL OleEmbeddedObject::addStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener )
{ // begin wrapping related part ==================== if ( m_xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
m_xWrappedObject->addStateChangeListener( xListener ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( !m_pInterfaceContainer )
m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex ));
void SAL_CALL OleEmbeddedObject::removeStateChangeListener( const uno::Reference< embed::XStateChangeListener >& xListener )
{ // begin wrapping related part ==================== if ( m_xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
m_xWrappedObject->removeStateChangeListener( xListener ); return;
} // end wrapping related part ====================
void SAL_CALL OleEmbeddedObject::close( sal_Bool bDeliverOwnership )
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->close( bDeliverOwnership ); return;
} // end wrapping related part ====================
osl::ResettableMutexGuard aGuard(m_aMutex); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
void SAL_CALL OleEmbeddedObject::addCloseListener( const uno::Reference< util::XCloseListener >& xListener )
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->addCloseListener( xListener ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( !m_pInterfaceContainer )
m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex ));
void SAL_CALL OleEmbeddedObject::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener )
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->removeCloseListener( xListener ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_pInterfaceContainer )
m_pInterfaceContainer->removeInterface( cppu::UnoType<util::XCloseListener>::get(),
xListener );
}
void SAL_CALL OleEmbeddedObject::addEventListener( const uno::Reference< document::XEventListener >& xListener )
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->addEventListener( xListener ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( !m_pInterfaceContainer )
m_pInterfaceContainer.reset(new comphelper::OMultiTypeInterfaceContainerHelper2( m_aMutex ));
void SAL_CALL OleEmbeddedObject::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
{ // begin wrapping related part ====================
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->removeEventListener( xListener ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_pInterfaceContainer )
m_pInterfaceContainer->removeInterface( cppu::UnoType<document::XEventListener>::get(),
xListener );
}
// XInplaceObject ( wrapper related implementation )
void SAL_CALL OleEmbeddedObject::setObjectRectangles( const awt::Rectangle& aPosRect, const awt::Rectangle& aClipRect )
{ // begin wrapping related part ====================
uno::Reference< embed::XInplaceObject > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->setObjectRectangles( aPosRect, aClipRect ); return;
} // end wrapping related part ====================
throw embed::WrongStateException();
}
void SAL_CALL OleEmbeddedObject::enableModeless( sal_Bool bEnable )
{ // begin wrapping related part ====================
uno::Reference< embed::XInplaceObject > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->enableModeless( bEnable ); return;
} // end wrapping related part ====================
throw embed::WrongStateException();
}
void SAL_CALL OleEmbeddedObject::translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys )
{ // begin wrapping related part ====================
uno::Reference< embed::XInplaceObject > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->translateAccelerators( aKeys ); return;
} // end wrapping related part ====================
}
// XChild
css::uno::Reference< css::uno::XInterface > SAL_CALL OleEmbeddedObject::getParent()
{ // begin wrapping related part ====================
uno::Reference< container::XChild > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper return xWrappedObject->getParent();
} // end wrapping related part ====================
return m_xParent;
}
void SAL_CALL OleEmbeddedObject::setParent( const css::uno::Reference< css::uno::XInterface >& xParent )
{ // begin wrapping related part ====================
uno::Reference< container::XChild > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); if ( xWrappedObject.is() )
{ // the object was converted to OOo embedded object, the current implementation is now only a wrapper
xWrappedObject->setParent( xParent ); return;
} // end wrapping related part ====================
void OleEmbeddedObject::initialize(const uno::Sequence<uno::Any>& rArguments)
{ if (!rArguments.hasElements()) return;
comphelper::SequenceAsHashMap aValues(rArguments[0]); auto it = aValues.find(u"StreamReadOnly"_ustr); if (it != aValues.end())
it->second >>= m_bStreamReadOnly;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.