forked from amazingfate/loongoffice
As seen in the following call stacks:
Main thread
sal3!osl_acquireMutex+0x49 [libre-office-git-repo\sal\osl\w32\mutex.cxx @ 65]
emboleobj!osl::Mutex::acquire+0x9 [libre-office-git-repo\include\osl\mutex.hxx @ 63]
emboleobj!osl::Guard<osl::Mutex>::{ctor}+0x9 [libre-office-git-repo\include\osl\mutex.hxx @ 144]
emboleobj!OleEmbeddedObject::getCurrentState+0x68 [libre-office-git-repo\embeddedobj\source\msole\oleembed.cxx @ 643]
sfxlo!SfxInPlaceClient::IsObjectUIActive+0x23 [libre-office-git-repo\sfx2\source\view\ipclient.cxx @ 847]
sfxlo!SfxViewShell::GetUIActiveClient+0x5b [libre-office-git-repo\sfx2\source\view\viewsh.cxx @ 2521]
sfxlo!SfxDispatcher::FindServer_+0x282 [libre-office-git-repo\sfx2\source\control\dispatch.cxx @ 1627]
sfxlo!SfxDispatcher::GetShellAndSlot_Impl+0x2f [libre-office-git-repo\sfx2\source\control\dispatch.cxx @ 703]
sfxlo!SfxDispatcher::QueryState+0x5b [libre-office-git-repo\sfx2\source\control\dispatch.cxx @ 1979]
swlo!SwView::CheckReadonlyState+0x64 [libre-office-git-repo\sw\source\uibase\uiview\view.cxx @ 627]
swlo!SwView::TimeoutHdl+0x76 [libre-office-git-repo\sw\source\uibase\uiview\view.cxx @ 608]
vcllo!Scheduler::CallbackTaskScheduling+0x130e [libre-office-git-repo\vcl\source\app\scheduler.cxx @ 511]
vclplug_winlo!WinSalTimer::ImplHandleElapsedTimer+0x2e [libre-office-git-repo\vcl\win\app\saltimer.cxx @ 167]
vclplug_winlo!ImplSalYield+0x14f [libre-office-git-repo\vcl\win\app\salinst.cxx @ 525]
vclplug_winlo!WinSalInstance::DoYield+0xad [libre-office-git-repo\vcl\win\app\salinst.cxx @ 581]
vcllo!ImplYield+0x367 [libre-office-git-repo\vcl\source\app\svapp.cxx @ 393]
vcllo!Application::Execute+0xfa [libre-office-git-repo\vcl\source\app\svapp.cxx @ 369]
sofficeapp!desktop::Desktop::Main+0x173f [libre-office-git-repo\desktop\source\app\app.cxx @ 1605]
vcllo!ImplSVMain+0xda [libre-office-git-repo\vcl\source\app\svmain.cxx @ 229]
sofficeapp!soffice_main+0xf3 [libre-office-git-repo\desktop\source\app\sofficemain.cxx @ 94]
Request thread
sal3!osl_acquireMutex+0x49 [libre-office-git-repo\sal\osl\w32\mutex.cxx @ 65]
vclplug_winlo!osl::Mutex::acquire+0xa [libre-office-git-repo\include\osl\mutex.hxx @ 63]
vclplug_winlo!SalYieldMutex::doAcquire+0x91 [libre-office-git-repo\vcl\win\app\salinst.cxx @ 148]
emboleobj!SolarMutexReleaser::{dtor}+0xc [libre-office-git-repo\include\vcl\svapp.hxx @ 1425]
emboleobj!OleComponent::GetExtent+0x102 [libre-office-git-repo\embeddedobj\source\msole\olecomponent.cxx @ 1134]
emboleobj!OleEmbeddedObject::getVisualAreaSize+0x23f [libre-office-git-repo\embeddedobj\source\msole\olevisual.cxx @ 227]
emboleobj!OleEmbeddedObject::saveCompleted+0x406 [libre-office-git-repo\embeddedobj\source\msole\olepersist.cxx @ 1603]
comphelper!comphelper::EmbeddedObjectContainer::StoreEmbeddedObject+0x49b [libre-office-git-repo\comphelper\source\container\embeddedobjectcontainer.cxx @ 501]
comphelper!comphelper::EmbeddedObjectContainer::InsertEmbeddedObject+0x6f [libre-office-git-repo\comphelper\source\container\embeddedobjectcontainer.cxx @ 518]
comphelper!comphelper::EmbeddedObjectContainer::RemoveEmbeddedObject+0x388 [libre-office-git-repo\comphelper\source\container\embeddedobjectcontainer.cxx @ 945]
comphelper!comphelper::EmbeddedObjectContainer::RemoveEmbeddedObject+0x46 [libre-office-git-repo\comphelper\source\container\embeddedobjectcontainer.cxx @ 831]
swlo!SwOLENode::SavePersistentData+0x20b [libre-office-git-repo\sw\source\core\ole\ndole.cxx @ 403]
swlo!SwNodes::ChgNode+0x411 [libre-office-git-repo\sw\source\core\docnode\nodes.cxx @ 214]
swlo!SwNodes::MoveNodes+0x18e6 [libre-office-git-repo\sw\source\core\docnode\nodes.cxx @ 868]
swlo!SwUndoSaveContent::MoveToUndoNds+0x1c1 [libre-office-git-repo\sw\source\core\undo\undobj.cxx @ 784]
swlo!SwUndoSaveSection::SaveSection+0x559 [libre-office-git-repo\sw\source\core\undo\undobj.cxx @ 1325]
swlo!SwUndoSaveSection::SaveSection+0x55 [libre-office-git-repo\sw\source\core\undo\undobj.cxx @ 1278]
swlo!SwUndoFlyBase::DelFly+0x127 [libre-office-git-repo\sw\source\core\undo\undobj1.cxx @ 232]
swlo!SwUndoDelLayFormat::SwUndoDelLayFormat+0x64 [libre-office-git-repo\sw\source\core\undo\undobj1.cxx @ 429]
swlo!std::make_unique+0x22 [C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\memory @ 3382]
swlo!sw::DocumentLayoutManager::DelLayoutFormat+0x283 [libre-office-git-repo\sw\source\core\doc\DocumentLayoutManager.cxx @ 242]
swlo!SwTextNode::DestroyAttr+0x82 [libre-office-git-repo\sw\source\core\txtnode\thints.cxx @ 1204]
swlo!SwTextNode::EraseText+0x18f [libre-office-git-repo\sw\source\core\txtnode\ndtxt.cxx @ 2813]
swlo!SwTextNode::DeleteAttributes+0x115 [libre-office-git-repo\sw\source\core\txtnode\thints.cxx @ 1863]
swlo!SwXFrame::dispose+0xdb [libre-office-git-repo\sw\source\core\unocore\unoframe.cxx @ 2692]
mscx_uno!`anonymous namespace'::cpp_call+0x710 [libre-office-git-repo\bridges\source\cpp_uno\msvc_win32_x86-64\uno2cpp.cxx @ 214]
mscx_uno!unoInterfaceProxyDispatch+0x2fa [libre-office-git-repo\bridges\source\cpp_uno\msvc_win32_x86-64\uno2cpp.cxx @ 430]
binaryurplo!binaryurp::IncomingRequest::execute_throw+0x635 [libre-office-git-repo\binaryurp\source\incomingrequest.cxx @ 239]
binaryurplo!binaryurp::IncomingRequest::execute+0xbf [libre-office-git-repo\binaryurp\source\incomingrequest.cxx @ 79]
binaryurplo!request+0x1c [libre-office-git-repo\binaryurp\source\reader.cxx @ 84]
cppu3!cppu_threadpool::JobQueue::enter+0x21e [libre-office-git-repo\cppu\source\threadpool\jobqueue.cxx @ 101]
cppu3!cppu_threadpool::ORequestThread::run+0xa0 [libre-office-git-repo\cppu\source\threadpool\thread.cxx @ 169]
As seen, the request thread has OleEmbeddedObject::saveCompleted
and OleEmbeddedObject::getVisualAreaSize on the stack; both acquire
OleEmbeddedObject's mutex; but only getVisualAreaSize releases it
for the call of OleComponent::GetExtent. The latter releases solar
mutex, at which time, the main thread (locking the solar mutex)
attempts to call OleEmbeddedObject::getCurrentState, which needs
the object's mutex, which is still locked in the request thread.
Avoid this, by passing the lock object to the implementation of
getVisualAreaSize from saveCompleted.
Change-Id: Ie44a20a8c89000e0e951e024c2bfde93cf2cc3f6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174891
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
444 lines
17 KiB
C++
444 lines
17 KiB
C++
/* -*- 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 .
|
|
*/
|
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
|
#include <com/sun/star/embed/EmbedStates.hpp>
|
|
#include <com/sun/star/embed/EmbedMapUnits.hpp>
|
|
#include <com/sun/star/embed/EmbedMisc.hpp>
|
|
#include <com/sun/star/embed/Aspects.hpp>
|
|
#include <com/sun/star/embed/WrongStateException.hpp>
|
|
#include <com/sun/star/io/XSeekable.hpp>
|
|
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
|
|
|
|
#include <oleembobj.hxx>
|
|
#if defined (_WIN32)
|
|
#include <comphelper/mimeconfighelper.hxx>
|
|
#endif
|
|
#include <comphelper/seqstream.hxx>
|
|
#include <filter/msfilter/classids.hxx>
|
|
#include <sal/log.hxx>
|
|
|
|
#if defined(_WIN32)
|
|
#include "olecomponent.hxx"
|
|
#include <comphelper/diagnose_ex.hxx>
|
|
#endif
|
|
|
|
using namespace ::com::sun::star;
|
|
using namespace ::comphelper;
|
|
|
|
embed::VisualRepresentation OleEmbeddedObject::GetVisualRepresentationInNativeFormat_Impl(
|
|
const uno::Reference< io::XStream >& xCachedVisRepr )
|
|
{
|
|
embed::VisualRepresentation aVisualRepr;
|
|
|
|
// TODO: detect the format in the future for now use workaround
|
|
uno::Reference< io::XInputStream > xInStream = xCachedVisRepr->getInputStream();
|
|
if ( !xInStream.is() )
|
|
throw uno::RuntimeException();
|
|
uno::Reference< io::XSeekable > xSeekable( xCachedVisRepr, uno::UNO_QUERY_THROW );
|
|
|
|
uno::Sequence< sal_Int8 > aSeq( 2 );
|
|
xInStream->readBytes( aSeq, 2 );
|
|
xSeekable->seek( 0 );
|
|
if ( aSeq.getLength() == 2 && aSeq[0] == 'B' && aSeq[1] == 'M' )
|
|
{
|
|
// it's a bitmap
|
|
aVisualRepr.Flavor = datatransfer::DataFlavor(
|
|
u"application/x-openoffice-bitmap;windows_formatname=\"Bitmap\""_ustr,
|
|
u"Bitmap"_ustr,
|
|
cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
|
|
}
|
|
else
|
|
{
|
|
// it's a metafile
|
|
aVisualRepr.Flavor = datatransfer::DataFlavor(
|
|
u"application/x-openoffice-wmf;windows_formatname=\"Image WMF\""_ustr,
|
|
u"Windows Metafile"_ustr,
|
|
cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
|
|
}
|
|
|
|
sal_Int32 nStreamLength = static_cast<sal_Int32>(xSeekable->getLength());
|
|
uno::Sequence< sal_Int8 > aRepresent( nStreamLength );
|
|
xInStream->readBytes( aRepresent, nStreamLength );
|
|
aVisualRepr.Data <<= aRepresent;
|
|
|
|
return aVisualRepr;
|
|
}
|
|
|
|
void SAL_CALL OleEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
|
|
{
|
|
// 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->setVisualAreaSize( nAspect, aSize );
|
|
return;
|
|
}
|
|
// end wrapping related part ====================
|
|
|
|
::osl::ResettableMutexGuard aGuard( m_aMutex );
|
|
if ( m_bDisposed )
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.ole", "For iconified objects no graphical replacement is required!" );
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
// no representation can be retrieved
|
|
throw embed::WrongStateException( u"Illegal call!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
if ( m_nObjectState == -1 )
|
|
throw embed::WrongStateException( u"The object is not loaded!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
#ifdef _WIN32
|
|
// RECOMPOSE_ON_RESIZE misc flag means that the object has to be switched to running state on resize.
|
|
// SetExtent() is called only for objects that require it,
|
|
// it should not be called for MSWord documents to workaround problem i49369
|
|
// If cached size is not set, that means that this is the size initialization, so there is no need to set the real size
|
|
bool bAllowToSetExtent =
|
|
( ( getStatus( nAspect ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE )
|
|
&& !MimeConfigurationHelper::ClassIDsEqual(m_aClassID, MimeConfigurationHelper::GetSequenceClassID(MSO_WW8_CLASSID))
|
|
&& m_bHasCachedSize );
|
|
|
|
if ( m_nObjectState == embed::EmbedStates::LOADED && bAllowToSetExtent )
|
|
{
|
|
aGuard.clear();
|
|
try {
|
|
changeState( embed::EmbedStates::RUNNING );
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
SAL_WARN( "embeddedobj.ole", "The object should not be resized without activation!" );
|
|
}
|
|
aGuard.reset();
|
|
}
|
|
|
|
if ( m_pOleComponent && m_nObjectState != embed::EmbedStates::LOADED && bAllowToSetExtent )
|
|
{
|
|
awt::Size aSizeToSet = aSize;
|
|
aGuard.clear();
|
|
try {
|
|
m_pOleComponent->SetExtent( aSizeToSet, nAspect ); // will throw an exception in case of failure
|
|
m_bHasSizeToSet = false;
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
// some objects do not allow to set the size even in running state
|
|
m_bHasSizeToSet = true;
|
|
m_aSizeToSet = aSizeToSet;
|
|
m_nAspectToSet = nAspect;
|
|
}
|
|
aGuard.reset();
|
|
}
|
|
#endif
|
|
|
|
// cache the values
|
|
m_bHasCachedSize = true;
|
|
m_aCachedSize = aSize;
|
|
m_nCachedAspect = nAspect;
|
|
}
|
|
|
|
awt::Size OleEmbeddedObject::getVisualAreaSize_impl(sal_Int64 nAspect,
|
|
osl::ResettableMutexGuard& guard)
|
|
{
|
|
// begin wrapping related part ====================
|
|
uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
|
|
if ( xWrappedObject.is() )
|
|
{
|
|
osl::ResettableMutexGuardScopedReleaser area(guard);
|
|
// the object was converted to OOo embedded object, the current implementation is now only a wrapper
|
|
return xWrappedObject->getVisualAreaSize( nAspect );
|
|
}
|
|
// end wrapping related part ====================
|
|
|
|
if ( m_bDisposed )
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.ole", "For iconified objects no graphical replacement is required!" );
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
// no representation can be retrieved
|
|
throw embed::WrongStateException( u"Illegal call!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
if ( m_nObjectState == -1 )
|
|
throw embed::WrongStateException( u"The object is not loaded!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
awt::Size aResult;
|
|
|
|
#ifdef _WIN32
|
|
// TODO/LATER: Support different aspects
|
|
if ( m_pOleComponent && !m_bHasSizeToSet && nAspect == embed::Aspects::MSOLE_CONTENT )
|
|
{
|
|
try
|
|
{
|
|
// the cached size updated every time the object is stored
|
|
if ( m_bHasCachedSize )
|
|
{
|
|
aResult = m_aCachedSize;
|
|
}
|
|
else
|
|
{
|
|
// there is no internal cache
|
|
awt::Size aSize;
|
|
|
|
{ // => unguarded
|
|
osl::ResettableMutexGuardScopedReleaser area(guard);
|
|
|
|
bool bBackToLoaded = false;
|
|
|
|
bool bSuccess = false;
|
|
if ( getCurrentState() == embed::EmbedStates::LOADED )
|
|
{
|
|
SAL_WARN( "embeddedobj.ole", "Loaded object has no cached size!" );
|
|
|
|
// try to switch the object to RUNNING state and request the value again
|
|
try {
|
|
changeState( embed::EmbedStates::RUNNING );
|
|
// the links should be switched back to loaded state to avoid too
|
|
// many open MathType instances
|
|
bBackToLoaded = true;
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
throw embed::NoVisualAreaSizeException(
|
|
"No size available!",
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
// first try to get size using replacement image
|
|
aSize = m_pOleComponent->GetExtent( nAspect ); // will throw an exception in case of failure
|
|
bSuccess = true;
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
TOOLS_WARN_EXCEPTION("embeddedobj.ole", "OleEmbeddedObject::getVisualAreaSize: GetExtent() failed:");
|
|
}
|
|
|
|
if (bBackToLoaded)
|
|
{
|
|
try
|
|
{
|
|
changeState(embed::EmbedStates::LOADED);
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
TOOLS_WARN_EXCEPTION("embeddedobj.ole", "ignoring ");
|
|
}
|
|
}
|
|
|
|
if ( !bSuccess )
|
|
{
|
|
try
|
|
{
|
|
// second try the cached replacement image
|
|
aSize = m_pOleComponent->GetCachedExtent( nAspect ); // will throw an exception in case of failure
|
|
bSuccess = true;
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
TOOLS_WARN_EXCEPTION("embeddedobj.ole", "OleEmbeddedObject::getVisualAreaSize: GetCachedExtent() failed:");
|
|
}
|
|
}
|
|
|
|
if ( !bSuccess )
|
|
{
|
|
try
|
|
{
|
|
// third try the size reported by the object
|
|
aSize = m_pOleComponent->GetRecommendedExtent( nAspect ); // will throw an exception in case of failure
|
|
bSuccess = true;
|
|
}
|
|
catch( const uno::Exception& )
|
|
{
|
|
TOOLS_WARN_EXCEPTION("embeddedobj.ole", "OleEmbeddedObject::getVisualAreaSize: GetRecommendedExtent() failed:");
|
|
}
|
|
}
|
|
|
|
if ( !bSuccess )
|
|
throw embed::NoVisualAreaSizeException(
|
|
"No size available!",
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
} // <= unguarded
|
|
|
|
m_aCachedSize = aSize;
|
|
m_nCachedAspect = nAspect;
|
|
m_bHasCachedSize = true;
|
|
|
|
aResult = m_aCachedSize;
|
|
}
|
|
}
|
|
catch ( const embed::NoVisualAreaSizeException& )
|
|
{
|
|
throw;
|
|
}
|
|
catch ( const uno::Exception& )
|
|
{
|
|
throw embed::NoVisualAreaSizeException(
|
|
"No size available!",
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
// return cached value
|
|
if ( !m_bHasCachedSize )
|
|
{
|
|
throw embed::NoVisualAreaSizeException(
|
|
u"No size available!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
}
|
|
SAL_WARN_IF( nAspect != m_nCachedAspect, "embeddedobj.ole", "Unexpected aspect is requested!" );
|
|
aResult = m_aCachedSize;
|
|
}
|
|
|
|
return aResult;
|
|
}
|
|
|
|
awt::Size SAL_CALL OleEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
|
|
{
|
|
osl::ResettableMutexGuard aGuard(m_aMutex);
|
|
return getVisualAreaSize_impl(nAspect, aGuard);
|
|
}
|
|
|
|
embed::VisualRepresentation SAL_CALL OleEmbeddedObject::getPreferredVisualRepresentation( 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->getPreferredVisualRepresentation( nAspect );
|
|
}
|
|
// end wrapping related part ====================
|
|
|
|
osl::ResettableMutexGuard aGuard(m_aMutex);
|
|
if ( m_bDisposed )
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.ole", "For iconified objects no graphical replacement is required!" );
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
// no representation can be retrieved
|
|
throw embed::WrongStateException( u"Illegal call!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
// TODO: if the object has cached representation then it should be returned
|
|
// TODO: if the object has no cached representation and is in loaded state it should switch itself to the running state
|
|
if ( m_nObjectState == -1 )
|
|
throw embed::WrongStateException( u"The object is not loaded!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
// TODO: in case of different aspects they must be applied to the mediatype and XTransferable must be used
|
|
// the cache is used only as a fallback if object is not in loaded state
|
|
if ( !m_xCachedVisualRepresentation.is() && ( !m_bVisReplInitialized || m_bVisReplInStream )
|
|
&& m_nObjectState == embed::EmbedStates::LOADED )
|
|
{
|
|
m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream, aGuard, true );
|
|
SetVisReplInStream( m_xCachedVisualRepresentation.is() );
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
if ( !m_xCachedVisualRepresentation.is() && m_pOleComponent )
|
|
{
|
|
try
|
|
{
|
|
datatransfer::DataFlavor aDataFlavor(
|
|
"application/x-openoffice-wmf;windows_formatname=\"Image WMF\"",
|
|
"Windows Metafile",
|
|
cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
|
|
|
|
embed::VisualRepresentation aVisualRepr;
|
|
{
|
|
osl::ResettableMutexGuardScopedReleaser clearedMutex(aGuard);
|
|
if ( m_nObjectState == embed::EmbedStates::LOADED )
|
|
changeState( embed::EmbedStates::RUNNING );
|
|
aVisualRepr.Data = m_pOleComponent->getTransferData(aDataFlavor);
|
|
}
|
|
aVisualRepr.Flavor = aDataFlavor;
|
|
|
|
uno::Sequence< sal_Int8 > aVisReplSeq;
|
|
aVisualRepr.Data >>= aVisReplSeq;
|
|
if ( aVisReplSeq.getLength() )
|
|
{
|
|
m_xCachedVisualRepresentation = GetNewFilledTempStream_Impl(
|
|
uno::Reference< io::XInputStream >(
|
|
new ::comphelper::SequenceInputStream(aVisReplSeq)));
|
|
}
|
|
|
|
return aVisualRepr;
|
|
}
|
|
catch( const uno::Exception& )
|
|
{}
|
|
}
|
|
#endif
|
|
|
|
// the cache is used only as a fallback if object is not in loaded state
|
|
if ( !m_xCachedVisualRepresentation.is() && ( !m_bVisReplInitialized || m_bVisReplInStream ) )
|
|
{
|
|
m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream, aGuard );
|
|
SetVisReplInStream( m_xCachedVisualRepresentation.is() );
|
|
}
|
|
|
|
if ( !m_xCachedVisualRepresentation.is() )
|
|
{
|
|
// no representation can be retrieved
|
|
throw embed::WrongStateException( u"Illegal call!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
}
|
|
|
|
return GetVisualRepresentationInNativeFormat_Impl( m_xCachedVisualRepresentation );
|
|
}
|
|
|
|
sal_Int32 SAL_CALL OleEmbeddedObject::getMapUnit( 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->getMapUnit( nAspect );
|
|
}
|
|
// end wrapping related part ====================
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
if ( m_bDisposed )
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.ole", "For iconified objects no graphical replacement is required!" );
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
// no representation can be retrieved
|
|
throw embed::WrongStateException( u"Illegal call!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
if ( m_nObjectState == -1 )
|
|
throw embed::WrongStateException( u"The object is not loaded!"_ustr,
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
|
|
|
return embed::EmbedMapUnits::ONE_100TH_MM;
|
|
}
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|