/* -*- 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 .
*/
uno::Sequence< sal_Int32 > OleEmbeddedObject::GetIntermediateVerbsSequence_Impl( sal_Int32 nNewState )
{
SAL_WARN_IF( m_nObjectState == embed::EmbedStates::LOADED, "embeddedobj.ole", "Loaded object is switched to running state without verbs using!" );
// actually there will be only one verb if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE )
{ return { embed::EmbedVerbs::MS_OLEVERB_OPEN };
}
return uno::Sequence< sal_Int32 >();
} #endif
void OleEmbeddedObject::MoveListeners()
{ if ( !m_pInterfaceContainer ) return;
// let the model behave as embedded one
uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW );
uno::Sequence< beans::PropertyValue > aSeq{ comphelper::makePropertyValue(
u"SetEmbedded"_ustr, true) };
xModel->attachResource( OUString(), aSeq );
// load the model from the stream
uno::Sequence< beans::PropertyValue > aArgs{
comphelper::makePropertyValue(u"HierarchicalDocumentName"_ustr, m_aEntryName),
comphelper::makePropertyValue(u"ReadOnly"_ustr, true),
comphelper::makePropertyValue(u"FilterName"_ustr, m_aFilterName),
comphelper::makePropertyValue(u"URL"_ustr, u"private:stream"_ustr),
comphelper::makePropertyValue(u"InputStream"_ustr, xStream->getInputStream())
};
xSeekable->seek( 0 );
xLoadable->load( aArgs );
// the model is successfully loaded, create a new storage and store the model to the storage
uno::Reference< embed::XStorage > xTmpStorage = CreateTemporarySubstorage( aStorageName );
xStorDoc->storeToStorage( xTmpStorage, uno::Sequence< beans::PropertyValue >() );
xDocument->close( true );
uno::Reference< beans::XPropertySet > xStorProps( xTmpStorage, uno::UNO_QUERY_THROW );
OUString aMediaType;
xStorProps->getPropertyValue(u"MediaType"_ustr) >>= aMediaType;
xTmpStorage->dispose();
// look for the related embedded object factory
::comphelper::MimeConfigurationHelper aConfigHelper( m_xContext );
OUString aEmbedFactory; if ( !aMediaType.isEmpty() )
aEmbedFactory = aConfigHelper.GetFactoryNameByMediaType( aMediaType );
if ( aEmbedFactory.isEmpty() ) throw uno::RuntimeException(u"Failed to get OLE embedded object factory"_ustr);
// now the object should be adjusted to become the wrapper
nStep = 1;
uno::Reference< lang::XComponent > xComp( m_xObjectStream, uno::UNO_QUERY_THROW );
xComp->dispose();
m_xObjectStream.clear();
m_nObjectState = -1;
void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
{ if ( officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()
&& nNewState != embed::EmbedStates::LOADED ) throw embed::UnreachableStateException(); // 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->changeState( nNewState ); return;
} // end wrapping related part ====================
::osl::ResettableMutexGuard aGuard( m_aMutex );
if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
// in case the object is already in requested state if ( m_nObjectState == nNewState ) return;
#ifdef _WIN32 if ( m_pOleComponent )
{ if ( m_nTargetState != -1 )
{ // means that the object is currently trying to reach the target state throw embed::StateChangeInProgressException( OUString(),
uno::Reference< uno::XInterface >(),
m_nTargetState );
}
try
{ if ( nNewState == embed::EmbedStates::LOADED )
{ // This means just closing of the current object // If component can not be closed the object stays in loaded state // and it holds reference to "incomplete" component // If the object is switched to running state later // the component will become "complete"
// the loaded state must be set before, because of notifications!
m_nObjectState = nNewState;
StateChangeNotification_Impl( false, nOldState, m_nObjectState, aGuard );
} elseif ( nNewState == embed::EmbedStates::RUNNING || nNewState == embed::EmbedStates::ACTIVE )
{ if ( m_nObjectState == embed::EmbedStates::LOADED )
{ // if the target object is in loaded state and a different state is specified // as a new one the object first must be switched to running state.
// the component can exist already in nonrunning state // it can be created during loading to detect type of object
CreateOleComponentAndLoad_Impl( m_pOleComponent );
// so now the object is either switched from Active to Running state or viceversa // the notification about object state change will be done asynchronously if ( m_nObjectState == embed::EmbedStates::RUNNING && nNewState == embed::EmbedStates::ACTIVE )
{ // execute OPEN verb, if object does not reach active state it is an object's problem
ExecUnlocked([p = m_pOleComponent]()
{ p->ExecuteVerb(embed::EmbedVerbs::MS_OLEVERB_OPEN); },
aGuard);
// some objects do not allow to set the size even in running state if ( m_pOleComponent && m_bHasSizeToSet )
{ try {
ExecUnlocked([p = m_pOleComponent, s = m_aSizeToSet,
a = m_nAspectToSet]() { p->SetExtent(s, a); },
aGuard);
m_bHasSizeToSet = false;
} catch( uno::Exception& ) {}
}
uno::Sequence< sal_Int32 > SAL_CALL OleEmbeddedObject::getReachableStates()
{ // 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->getReachableStates();
} // end wrapping related part ====================
::osl::ResettableMutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
#ifdef _WIN32 if ( m_pOleComponent )
{ if ( m_nObjectState == embed::EmbedStates::LOADED )
{ // the list of supported verbs can be retrieved only when object is in running state throw embed::NeedsRunningStateException(); // TODO:
}
// the list of states can only be guessed based on standard verbs, // since there is no way to detect what additional verbs do // Pass m_pOleComponent to the lambda by copy, to make sure it doesn't depend on possible // destruction of 'this', while the lock is unset return GetReachableStatesList_Impl(
ExecUnlocked([p = m_pOleComponent] { return p->GetVerbList(); }, aGuard));
} else #endif
{ return uno::Sequence< sal_Int32 >();
}
}
sal_Int32 SAL_CALL OleEmbeddedObject::getCurrentState()
{ // 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->getCurrentState();
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
// TODO: Shouldn't we ask object? ( I guess no ) return m_nObjectState;
}
//various stream names that can contain the real document contents for //this object in a straightforward direct way staticconst std::u16string_view aStreamNames[] =
{
u"CONTENTS",
u"Package",
u"EmbeddedOdf",
u"WordDocument",
u"Workbook",
u"PowerPoint Document"
};
//Dump the objects content to a tempfile, just the "CONTENTS" stream if //there is one for non-compound documents, otherwise the whole content. //On success a file is returned which must be removed by the caller
OUString lcl_ExtractObject(const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::io::XStream >& xObjectStream)
{
OUString sUrl;
// the solution is only active for Unix systems #ifndef _WIN32
lcl_GetExtractedStream(sUrl, xContext, xObjectStream); #else
(void) xContext;
(void) xObjectStream; #endif return sUrl;
}
void SAL_CALL OleEmbeddedObject::doVerb( sal_Int32 nVerbID )
{ // 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->doVerb(embed::EmbedVerbs::MS_OLEVERB_OPEN); // open content in the window not in-place return;
} // end wrapping related part ====================
::osl::ResettableMutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
// TODO/LATER detect target state here and do a notification // StateChangeNotification_Impl( sal_True, nOldState, nNewState ); if ( m_nObjectState == embed::EmbedStates::LOADED )
{ // if the target object is in loaded state // it must be switched to running state to execute verb
ExecUnlocked([this]() { changeState(embed::EmbedStates::RUNNING); }, aGuard);
}
try { if ( !m_pOleComponent ) throw uno::RuntimeException("Null reference to OLE component");
// ==== the STAMPIT related solution =============================
m_aVerbExecutionController.StartControlExecution();
ExecUnlocked(
[nVerbID, p = m_pOleComponent, name = m_aContainerName]()
{
p->ExecuteVerb(nVerbID);
p->SetHostName(name);
},
aGuard);
// ==== the STAMPIT related solution ============================= bool bModifiedOnExecution = m_aVerbExecutionController.EndControlExecution_WasModified();
// this workaround is implemented for STAMPIT object // if object was modified during verb execution it is saved here if ( bModifiedOnExecution && m_pOleComponent->IsDirty() )
SaveObject_Impl();
} catch( uno::Exception& )
{ // ==== the STAMPIT related solution =============================
m_aVerbExecutionController.EndControlExecution_WasModified();
// the workaround verb to show the object in case no server is available
// if it is possible, the object will be converted to OOo format if ( !m_bTriedConversion )
{
m_bTriedConversion = true; if ( TryToConvertToOOo( m_xObjectStream ) )
{
aGuard.clear();
changeState( embed::EmbedStates::ACTIVE ); return;
}
}
// it may be the OLE Storage, try to extract stream if ( !m_xOwnView.is() && m_xObjectStream.is() && m_aFilterName == "Text" )
{
uno::Reference< io::XStream > xStream = lcl_ExtractObjectStream( m_xContext, m_xObjectStream );
if (!m_xOwnView.is() || !m_xOwnView->Open())
{ //Make a RO copy and see if the OS can find something to at //least display the content for us if (m_aTempDumpURL.isEmpty())
m_aTempDumpURL = lcl_ExtractObject(m_xContext, m_xObjectStream);
if (m_aTempDumpURL.isEmpty()) throw embed::UnreachableStateException();
uno::Sequence< embed::VerbDescriptor > SAL_CALL OleEmbeddedObject::getSupportedVerbs()
{ // 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->getSupportedVerbs();
} // end wrapping related part ====================
osl::ClearableMutexGuard aGuard(m_aMutex); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) ); #ifdef _WIN32 if ( m_pOleComponent )
{ // registry could be used in this case // if ( m_nObjectState == embed::EmbedStates::LOADED ) // { // // the list of supported verbs can be retrieved only when object is in running state // throw embed::NeedsRunningStateException(); // TODO: // }
aGuard.clear(); return m_pOleComponent->GetVerbList();
} else #endif
{ // tdf#140079 Claim support for the OleEmbeddedObject::doVerb -9 fallback. // So in SfxViewFrame::GetState_Impl in case SID_OBJECT hasVerbs is not // empty, so that the doVerb attempt with -9 fallback is attempted
uno::Sequence<embed::VerbDescriptor> aRet(1);
aRet.getArray()[0].VerbID = -9; return aRet;
}
}
void SAL_CALL OleEmbeddedObject::setClientSite( const uno::Reference< embed::XEmbeddedClient >& xClient )
{ // 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->setClientSite( xClient ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_xClientSite != xClient)
{ if ( m_nObjectState != embed::EmbedStates::LOADED && m_nObjectState != embed::EmbedStates::RUNNING ) throw embed::WrongStateException(
u"The client site can not be set currently!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
m_xClientSite = xClient;
}
}
uno::Reference< embed::XEmbeddedClient > SAL_CALL OleEmbeddedObject::getClientSite()
{ // 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->getClientSite();
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
return m_xClientSite;
}
void SAL_CALL OleEmbeddedObject::update()
{ // 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->update(); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
if ( m_nUpdateMode == embed::EmbedUpdateModes::EXPLICIT_UPDATE )
{ // TODO: update view representation
} else
{ // the object must be up to date
SAL_WARN_IF( m_nUpdateMode != embed::EmbedUpdateModes::ALWAYS_UPDATE, "embeddedobj.ole", "Unknown update mode!" );
}
}
void SAL_CALL OleEmbeddedObject::setUpdateMode( sal_Int32 nMode )
{ // 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->setUpdateMode( nMode ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object has no persistence!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
sal_Int64 SAL_CALL OleEmbeddedObject::getStatus( sal_Int64
nAspect
)
{ // 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->getStatus( nAspect );
} // end wrapping related part ====================
osl::ResettableMutexGuard aGuard(m_aMutex); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
if ( m_nObjectState == -1 ) throw embed::WrongStateException( u"The object must be in running state!"_ustr, static_cast< ::cppu::OWeakObject* >(this) );
// this implementation needs size to be provided after object loading/creating to work in optimal way return ( nResult | embed::EmbedMisc::EMBED_NEEDSSIZEONLOAD );
}
void SAL_CALL OleEmbeddedObject::setContainerName( const OUString& sName )
{ // 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->setContainerName( sName ); return;
} // end wrapping related part ====================
::osl::MutexGuard aGuard( m_aMutex ); if ( m_bDisposed ) throw lang::DisposedException(); // TODO
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.