2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-09-27 13:52:10 +01:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2003-10-27 12:05:38 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/embed/Aspects.hpp>
|
|
|
|
#include <com/sun/star/embed/EmbedStates.hpp>
|
2017-02-06 17:08:38 +01:00
|
|
|
#include <com/sun/star/embed/WrongStateException.hpp>
|
2003-10-27 12:05:38 +00:00
|
|
|
#include <com/sun/star/datatransfer/XTransferable.hpp>
|
|
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|
|
|
#include <com/sun/star/lang/DisposedException.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
#include <commonembobj.hxx>
|
2018-07-27 09:42:16 +02:00
|
|
|
#include <sal/log.hxx>
|
2003-10-27 12:05:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
2004-05-10 16:51:36 +00:00
|
|
|
void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
|
2003-10-27 12:05:38 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
if ( m_bDisposed )
|
|
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
|
2013-05-27 00:22:20 +03:00
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
|
2006-10-13 10:30:08 +00:00
|
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
|
|
// no representation can be retrieved
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "Illegal call!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2006-10-13 10:30:08 +00:00
|
|
|
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == -1 )
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "The own object has no persistence!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2004-05-10 16:51:36 +00:00
|
|
|
|
2014-04-17 11:39:18 +02:00
|
|
|
m_bHasClonedSize = false;
|
2007-05-22 18:35:35 +00:00
|
|
|
|
2014-04-17 11:39:18 +02:00
|
|
|
bool bBackToLoaded = false;
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == embed::EmbedStates::LOADED )
|
2009-04-23 13:48:24 +00:00
|
|
|
{
|
2015-06-23 09:12:15 +01:00
|
|
|
changeState( embed::EmbedStates::RUNNING );
|
|
|
|
|
|
|
|
// the links should be switched back to loaded state for now to avoid locking problems
|
2021-04-08 10:30:15 +02:00
|
|
|
bBackToLoaded = m_bIsLinkURL;
|
2009-04-23 13:48:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 13:35:32 +02:00
|
|
|
bool bSuccess = m_xDocHolder->SetExtent( nAspect, aSize );
|
2009-04-23 13:48:24 +00:00
|
|
|
|
|
|
|
if ( bBackToLoaded )
|
|
|
|
changeState( embed::EmbedStates::LOADED );
|
|
|
|
|
|
|
|
if ( !bSuccess )
|
2017-09-30 17:32:50 +02:00
|
|
|
throw uno::Exception("SetExtent failed", nullptr); // TODO:
|
2003-10-27 12:05:38 +00:00
|
|
|
}
|
|
|
|
|
2004-05-10 16:51:36 +00:00
|
|
|
awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
|
2003-10-27 12:05:38 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
if ( m_bDisposed )
|
|
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == -1 )
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "The own object has no persistence!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2003-10-27 12:05:38 +00:00
|
|
|
|
2013-05-27 00:22:20 +03:00
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
|
2006-10-13 10:30:08 +00:00
|
|
|
|
2007-08-02 16:05:22 +00:00
|
|
|
if ( m_bHasClonedSize )
|
|
|
|
return m_aClonedSize;
|
2007-05-22 18:35:35 +00:00
|
|
|
|
2014-04-17 11:39:18 +02:00
|
|
|
bool bBackToLoaded = false;
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == embed::EmbedStates::LOADED )
|
2009-04-23 13:48:24 +00:00
|
|
|
{
|
2005-01-31 08:01:49 +00:00
|
|
|
changeState( embed::EmbedStates::RUNNING );
|
|
|
|
|
2009-04-23 13:48:24 +00:00
|
|
|
// the links should be switched back to loaded state for now to avoid locking problems
|
2021-04-08 10:30:15 +02:00
|
|
|
bBackToLoaded = m_bIsLinkURL;
|
2009-04-23 13:48:24 +00:00
|
|
|
}
|
|
|
|
|
2004-05-10 16:51:36 +00:00
|
|
|
awt::Size aResult;
|
2017-01-20 13:35:32 +02:00
|
|
|
bool bSuccess = m_xDocHolder->GetExtent( nAspect, &aResult );
|
2009-04-23 13:48:24 +00:00
|
|
|
|
|
|
|
if ( bBackToLoaded )
|
|
|
|
changeState( embed::EmbedStates::LOADED );
|
|
|
|
|
|
|
|
if ( !bSuccess )
|
2017-09-30 17:32:50 +02:00
|
|
|
throw uno::Exception("GetExtent failed", nullptr); // TODO:
|
2009-04-23 13:48:24 +00:00
|
|
|
|
2004-05-10 16:51:36 +00:00
|
|
|
return aResult;
|
2003-10-27 12:05:38 +00:00
|
|
|
}
|
|
|
|
|
2004-10-04 18:50:21 +00:00
|
|
|
sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
|
2003-10-27 12:05:38 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
if ( m_bDisposed )
|
|
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
|
2013-05-27 00:22:20 +03:00
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
|
2006-10-13 10:30:08 +00:00
|
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
|
|
// no representation can be retrieved
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "Illegal call!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2006-10-13 10:30:08 +00:00
|
|
|
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == -1 )
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "The own object has no persistence!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2003-10-27 12:05:38 +00:00
|
|
|
|
2007-08-02 16:05:22 +00:00
|
|
|
if ( m_bHasClonedSize )
|
|
|
|
return m_nClonedMapUnit;
|
2007-05-22 18:35:35 +00:00
|
|
|
|
2014-04-17 11:39:18 +02:00
|
|
|
bool bBackToLoaded = false;
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == embed::EmbedStates::LOADED )
|
2009-04-23 13:48:24 +00:00
|
|
|
{
|
2015-06-23 09:12:15 +01:00
|
|
|
changeState( embed::EmbedStates::RUNNING );
|
|
|
|
|
|
|
|
// the links should be switched back to loaded state for now to avoid locking problems
|
2021-04-08 10:30:15 +02:00
|
|
|
bBackToLoaded = m_bIsLinkURL;
|
2009-04-23 13:48:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 13:35:32 +02:00
|
|
|
sal_Int32 nResult = m_xDocHolder->GetMapUnit( nAspect );
|
2009-04-23 13:48:24 +00:00
|
|
|
|
|
|
|
if ( bBackToLoaded )
|
|
|
|
changeState( embed::EmbedStates::LOADED );
|
|
|
|
|
2004-10-04 18:50:21 +00:00
|
|
|
if ( nResult < 0 )
|
2017-09-30 17:32:50 +02:00
|
|
|
throw uno::Exception("result " + OUString::number(nResult), nullptr); // TODO:
|
2004-05-10 16:51:36 +00:00
|
|
|
|
|
|
|
return nResult;
|
2003-10-27 12:05:38 +00:00
|
|
|
}
|
|
|
|
|
2006-10-13 10:30:08 +00:00
|
|
|
embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
|
2003-10-27 12:05:38 +00:00
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( m_aMutex );
|
|
|
|
if ( m_bDisposed )
|
|
|
|
throw lang::DisposedException(); // TODO
|
|
|
|
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == -1 )
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "The own object has no persistence!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2005-01-31 08:01:49 +00:00
|
|
|
|
2006-10-13 10:30:08 +00:00
|
|
|
|
2013-05-27 00:22:20 +03:00
|
|
|
SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
|
2006-10-13 10:30:08 +00:00
|
|
|
if ( nAspect == embed::Aspects::MSOLE_ICON )
|
|
|
|
// no representation can be retrieved
|
2014-05-26 14:29:07 +02:00
|
|
|
throw embed::WrongStateException( "Illegal call!",
|
2014-05-26 15:26:03 +02:00
|
|
|
static_cast< ::cppu::OWeakObject* >(this) );
|
2006-10-13 10:30:08 +00:00
|
|
|
|
2014-04-17 11:39:18 +02:00
|
|
|
bool bBackToLoaded = false;
|
2005-01-31 08:01:49 +00:00
|
|
|
if ( m_nObjectState == embed::EmbedStates::LOADED )
|
2009-04-23 13:48:24 +00:00
|
|
|
{
|
2016-09-16 14:36:38 +02:00
|
|
|
// restore original VisualAreaSize, because writer objects set
|
|
|
|
// themselves to a default size OLESIZE
|
2016-09-13 15:26:41 +01:00
|
|
|
awt::Size aOrigSize = getVisualAreaSize(nAspect);
|
|
|
|
changeState(embed::EmbedStates::RUNNING);
|
2017-06-26 14:35:24 +01:00
|
|
|
const bool bIsChart = GetDocumentServiceName() == "com.sun.star.chart2.ChartDocument";
|
2018-06-28 13:27:16 +02:00
|
|
|
// tdf#108643 unless it's a chart, cause those are weird (#i103460#)
|
2017-06-26 14:35:24 +01:00
|
|
|
if (!bIsChart && aOrigSize != getVisualAreaSize(nAspect))
|
2016-09-13 15:26:41 +01:00
|
|
|
setVisualAreaSize(nAspect, aOrigSize);
|
2005-01-31 08:01:49 +00:00
|
|
|
|
2009-04-23 13:48:24 +00:00
|
|
|
// the links should be switched back to loaded state for now to avoid locking problems
|
2021-04-08 10:30:15 +02:00
|
|
|
bBackToLoaded = m_bIsLinkURL;
|
2009-04-23 13:48:24 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 13:35:32 +02:00
|
|
|
SAL_WARN_IF( !m_xDocHolder->GetComponent().is(), "embeddedobj.common", "Running or Active object has no component!" );
|
2004-10-04 18:50:21 +00:00
|
|
|
|
|
|
|
// TODO: return for the aspect of the document
|
|
|
|
embed::VisualRepresentation aVisualRepresentation;
|
|
|
|
|
2017-01-20 13:35:32 +02:00
|
|
|
uno::Reference< embed::XVisualObject > xVisualObject( m_xDocHolder->GetComponent(), uno::UNO_QUERY );
|
2007-05-22 18:35:35 +00:00
|
|
|
if( xVisualObject.is())
|
|
|
|
{
|
|
|
|
aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-14 16:10:56 +01:00
|
|
|
uno::Reference< datatransfer::XTransferable > xTransferable( m_xDocHolder->GetComponent(), uno::UNO_QUERY_THROW );
|
2007-05-22 18:35:35 +00:00
|
|
|
|
|
|
|
datatransfer::DataFlavor aDataFlavor(
|
2017-01-30 16:38:54 +02:00
|
|
|
"application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"",
|
|
|
|
"GDIMetaFile",
|
2015-04-01 08:39:02 +02:00
|
|
|
cppu::UnoType<uno::Sequence< sal_Int8 >>::get() );
|
2007-05-22 18:35:35 +00:00
|
|
|
|
2017-09-21 11:06:43 +02:00
|
|
|
if( !xTransferable->isDataFlavorSupported( aDataFlavor ))
|
2007-05-22 18:35:35 +00:00
|
|
|
throw uno::RuntimeException();
|
2017-09-21 11:06:43 +02:00
|
|
|
aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
|
|
|
|
aVisualRepresentation.Flavor = aDataFlavor;
|
2007-05-22 18:35:35 +00:00
|
|
|
}
|
2004-10-04 18:50:21 +00:00
|
|
|
|
2009-04-23 13:48:24 +00:00
|
|
|
if ( bBackToLoaded )
|
|
|
|
changeState( embed::EmbedStates::LOADED );
|
|
|
|
|
2004-10-04 18:50:21 +00:00
|
|
|
return aVisualRepresentation;
|
2003-10-27 12:05:38 +00:00
|
|
|
}
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|