2004-10-04 18:47:01 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* $RCSfile: embedhlp.cxx,v $
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2007-05-22 18:34:28 +00:00
|
|
|
* $Revision: 1.22 $
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2007-05-22 18:34:28 +00:00
|
|
|
* last change: $Author: vg $ $Date: 2007-05-22 19:34:28 $
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
2005-09-08 15:15:53 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2004-10-04 18:47:01 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 14:09:44 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_svtools.hxx"
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
#include "embedhlp.hxx"
|
2005-04-13 10:22:36 +00:00
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
#include "filter.hxx"
|
|
|
|
#include "svtools.hrc"
|
|
|
|
#include "svtdata.hxx"
|
|
|
|
|
|
|
|
#include <comphelper/embeddedobjectcontainer.hxx>
|
|
|
|
#include <comphelper/seqstream.hxx>
|
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
|
2005-01-31 07:30:35 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UTIL_XMODIFYLISTENER_HPP_
|
|
|
|
#include <com/sun/star/util/XModifyListener.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_UTIL_XMODIFYiBLE_HPP_
|
|
|
|
#include <com/sun/star/util/XModifiable.hpp>
|
|
|
|
#endif
|
2004-10-04 18:47:01 +00:00
|
|
|
#ifndef _COM_SUN_STAR_EMBED_EMBEDSTATES_HPP_
|
|
|
|
#include <com/sun/star/embed/EmbedStates.hpp>
|
|
|
|
#endif
|
2006-03-24 12:06:02 +00:00
|
|
|
#ifndef _COM_SUN_STAR_EMBED_EMBEDMISC_HPP_
|
|
|
|
#include <com/sun/star/embed/EmbedMisc.hpp>
|
|
|
|
#endif
|
2004-10-04 18:47:01 +00:00
|
|
|
#ifndef _COM_SUN_STAR_EMBED_XSTATECHANGELISTENER_HPP_
|
|
|
|
#include <com/sun/star/embed/XStateChangeListener.hpp>
|
|
|
|
#endif
|
2006-10-13 10:27:58 +00:00
|
|
|
#ifndef _COM_SUN_STAR_EMBED_NOVISUALAREASIZEEXCEPTION_HPP_
|
|
|
|
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
|
|
|
|
#endif
|
2005-01-18 14:07:48 +00:00
|
|
|
#ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_
|
|
|
|
#include <com/sun/star/util/XModifiable.hpp>
|
|
|
|
#endif
|
2004-10-04 18:47:01 +00:00
|
|
|
#ifndef _COM_SUN_STAR_DATATRANSFER_XTRANSFERABLE_HPP_
|
|
|
|
#include <com/sun/star/datatransfer/XTransferable.hpp>
|
|
|
|
#endif
|
|
|
|
|
2005-01-31 07:30:35 +00:00
|
|
|
#ifndef _CPPUHELPER_IMPLBASE4_HXX_
|
|
|
|
#include <cppuhelper/implbase4.hxx>
|
|
|
|
#endif
|
|
|
|
|
2005-04-13 10:22:36 +00:00
|
|
|
#ifndef _SV_SVAPP_HXX
|
|
|
|
#include "vcl/svapp.hxx"
|
|
|
|
#endif
|
|
|
|
|
2006-01-20 08:49:36 +00:00
|
|
|
#ifndef _RTL_LOGFILE_HXX_
|
|
|
|
#include <rtl/logfile.hxx>
|
|
|
|
#endif
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
using namespace com::sun::star;
|
|
|
|
|
|
|
|
namespace svt
|
|
|
|
{
|
|
|
|
|
2005-01-31 07:30:35 +00:00
|
|
|
class EmbedEventListener_Impl : public ::cppu::WeakImplHelper4 < embed::XStateChangeListener,
|
2004-10-04 18:47:01 +00:00
|
|
|
document::XEventListener,
|
2005-01-31 07:30:35 +00:00
|
|
|
util::XModifyListener,
|
2004-10-04 18:47:01 +00:00
|
|
|
util::XCloseListener >
|
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
public:
|
2004-10-04 18:47:01 +00:00
|
|
|
EmbeddedObjectRef* pObject;
|
2005-01-31 07:30:35 +00:00
|
|
|
sal_Int32 nState;
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
EmbedEventListener_Impl( EmbeddedObjectRef* p ) :
|
|
|
|
pObject(p)
|
2005-01-31 07:30:35 +00:00
|
|
|
, nState(-1)
|
2004-10-04 18:47:01 +00:00
|
|
|
{}
|
|
|
|
|
2005-01-31 07:30:35 +00:00
|
|
|
static EmbedEventListener_Impl* Create( EmbeddedObjectRef* );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
|
|
|
|
throw (embed::WrongStateException, uno::RuntimeException);
|
|
|
|
virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
|
|
|
|
throw (uno::RuntimeException);
|
2005-01-31 07:30:35 +00:00
|
|
|
virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership )
|
2004-10-04 18:47:01 +00:00
|
|
|
throw (util::CloseVetoException, uno::RuntimeException);
|
2005-01-31 07:30:35 +00:00
|
|
|
virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException);
|
|
|
|
virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
|
|
|
|
virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException );
|
|
|
|
virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
|
2004-10-04 18:47:01 +00:00
|
|
|
};
|
|
|
|
|
2005-01-31 07:30:35 +00:00
|
|
|
EmbedEventListener_Impl* EmbedEventListener_Impl::Create( EmbeddedObjectRef* p )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
EmbedEventListener_Impl* xRet = new EmbedEventListener_Impl( p );
|
2004-10-04 18:47:01 +00:00
|
|
|
xRet->acquire();
|
|
|
|
|
|
|
|
if ( p->GetObject().is() )
|
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
p->GetObject()->addStateChangeListener( xRet );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
uno::Reference < util::XCloseable > xClose( p->GetObject(), uno::UNO_QUERY );
|
|
|
|
DBG_ASSERT( xClose.is(), "Object does not support XCloseable!" );
|
|
|
|
if ( xClose.is() )
|
2005-01-31 07:30:35 +00:00
|
|
|
xClose->addCloseListener( xRet );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
uno::Reference < document::XEventBroadcaster > xBrd( p->GetObject(), uno::UNO_QUERY );
|
|
|
|
if ( xBrd.is() )
|
|
|
|
xBrd->addEventListener( xRet );
|
2005-01-31 07:30:35 +00:00
|
|
|
|
|
|
|
xRet->nState = p->GetObject()->getCurrentState();
|
|
|
|
if ( xRet->nState == embed::EmbedStates::RUNNING )
|
|
|
|
{
|
|
|
|
uno::Reference < util::XModifiable > xMod( p->GetObject()->getComponent(), uno::UNO_QUERY );
|
|
|
|
if ( xMod.is() )
|
|
|
|
// listen for changes in running state (update replacements in case of changes)
|
|
|
|
xMod->addModifyListener( xRet );
|
|
|
|
}
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return xRet;
|
|
|
|
}
|
|
|
|
|
2006-06-19 20:19:36 +00:00
|
|
|
void SAL_CALL EmbedEventListener_Impl::changingState( const lang::EventObject&,
|
|
|
|
::sal_Int32,
|
|
|
|
::sal_Int32 )
|
2004-10-04 18:47:01 +00:00
|
|
|
throw ( embed::WrongStateException,
|
|
|
|
uno::RuntimeException )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-06-19 20:19:36 +00:00
|
|
|
void SAL_CALL EmbedEventListener_Impl::stateChanged( const lang::EventObject&,
|
2004-10-04 18:47:01 +00:00
|
|
|
::sal_Int32 nOldState,
|
|
|
|
::sal_Int32 nNewState )
|
|
|
|
throw ( uno::RuntimeException )
|
|
|
|
{
|
2005-03-15 10:37:21 +00:00
|
|
|
::vos::OGuard aGuard( Application::GetSolarMutex() );
|
2005-01-31 07:30:35 +00:00
|
|
|
nState = nNewState;
|
|
|
|
if ( !pObject )
|
|
|
|
return;
|
|
|
|
|
|
|
|
uno::Reference < util::XModifiable > xMod( pObject->GetObject()->getComponent(), uno::UNO_QUERY );
|
|
|
|
if ( nNewState == embed::EmbedStates::RUNNING )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
|
|
|
// TODO/LATER: container must be set before!
|
|
|
|
// When is this event created? Who sets the new container when it changed?
|
2006-10-13 10:27:58 +00:00
|
|
|
if( ( pObject->GetViewAspect() != embed::Aspects::MSOLE_ICON ) && nOldState != embed::EmbedStates::LOADED )
|
2005-01-31 07:30:35 +00:00
|
|
|
// get new replacement after deactivation
|
|
|
|
pObject->UpdateReplacement();
|
|
|
|
|
2005-11-03 11:02:48 +00:00
|
|
|
if ( xMod.is() && nOldState == embed::EmbedStates::LOADED )
|
|
|
|
// listen for changes (update replacements in case of changes)
|
2005-01-31 07:30:35 +00:00
|
|
|
xMod->addModifyListener( this );
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
2005-11-03 11:02:48 +00:00
|
|
|
else if ( nNewState == embed::EmbedStates::LOADED )
|
2005-01-31 07:30:35 +00:00
|
|
|
{
|
2005-11-03 11:02:48 +00:00
|
|
|
// in loaded state we can't listen
|
2005-01-31 07:30:35 +00:00
|
|
|
if ( xMod.is() )
|
|
|
|
xMod->removeModifyListener( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-19 20:19:36 +00:00
|
|
|
void SAL_CALL EmbedEventListener_Impl::modified( const lang::EventObject& ) throw (uno::RuntimeException)
|
2005-01-31 07:30:35 +00:00
|
|
|
{
|
2005-03-15 10:37:21 +00:00
|
|
|
::vos::OGuard aGuard( Application::GetSolarMutex() );
|
2006-10-13 10:27:58 +00:00
|
|
|
if ( pObject && pObject->GetViewAspect() != embed::Aspects::MSOLE_ICON )
|
2005-11-03 11:02:48 +00:00
|
|
|
{
|
|
|
|
if ( nState == embed::EmbedStates::RUNNING )
|
|
|
|
{
|
|
|
|
// updates only necessary in non-active states
|
|
|
|
pObject->UpdateReplacement();
|
|
|
|
}
|
|
|
|
else if ( nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::INPLACE_ACTIVE )
|
|
|
|
{
|
|
|
|
// in case the object is inplace or UI active the replacement image should be updated on demand
|
|
|
|
pObject->UpdateReplacementOnDemand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL EmbedEventListener_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
|
|
|
|
{
|
2005-03-15 10:37:21 +00:00
|
|
|
::vos::OGuard aGuard( Application::GetSolarMutex() );
|
|
|
|
|
2005-04-27 08:15:35 +00:00
|
|
|
#if 0
|
2004-10-04 18:47:01 +00:00
|
|
|
if ( pObject && aEvent.EventName.equalsAscii("OnSaveDone") || aEvent.EventName.equalsAscii("OnSaveAsDone") )
|
|
|
|
{
|
|
|
|
// TODO/LATER: container must be set before!
|
|
|
|
// When is this event created? Who sets the new container when it changed?
|
|
|
|
pObject->UpdateReplacement();
|
|
|
|
}
|
2005-04-27 08:15:35 +00:00
|
|
|
else
|
2004-10-04 18:47:01 +00:00
|
|
|
#endif
|
2006-10-13 10:27:58 +00:00
|
|
|
if ( pObject && aEvent.EventName.equalsAscii("OnVisAreaChanged") && pObject->GetViewAspect() != embed::Aspects::MSOLE_ICON )
|
2005-04-27 08:15:35 +00:00
|
|
|
{
|
|
|
|
pObject->UpdateReplacement();
|
|
|
|
}
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 20:19:36 +00:00
|
|
|
void SAL_CALL EmbedEventListener_Impl::queryClosing( const lang::EventObject& Source, ::sal_Bool )
|
2004-10-04 18:47:01 +00:00
|
|
|
throw ( util::CloseVetoException, uno::RuntimeException)
|
|
|
|
{
|
|
|
|
// An embedded object can be shared between several objects (f.e. for undo purposes)
|
|
|
|
// the object will not be closed before the last "customer" is destroyed
|
|
|
|
// Now the EmbeddedObjectRef helper class works like a "lock" on the object
|
2005-01-31 07:30:35 +00:00
|
|
|
if ( pObject && pObject->IsLocked() && Source.Source == pObject->GetObject() )
|
2004-10-04 18:47:01 +00:00
|
|
|
throw util::CloseVetoException();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL EmbedEventListener_Impl::notifyClosing( const lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException)
|
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
if ( pObject && Source.Source == pObject->GetObject() )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
|
|
|
pObject->Clear();
|
|
|
|
pObject = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SAL_CALL EmbedEventListener_Impl::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException )
|
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
if ( pObject && aEvent.Source == pObject->GetObject() )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
|
|
|
pObject->Clear();
|
|
|
|
pObject = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct EmbeddedObjectRef_Impl
|
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
EmbedEventListener_Impl* xListener;
|
2004-10-04 18:47:01 +00:00
|
|
|
::rtl::OUString aPersistName;
|
|
|
|
::rtl::OUString aMediaType;
|
|
|
|
comphelper::EmbeddedObjectContainer* pContainer;
|
|
|
|
Graphic* pGraphic;
|
2006-03-24 12:06:02 +00:00
|
|
|
Graphic* pHCGraphic;
|
2004-10-04 18:47:01 +00:00
|
|
|
sal_Int64 nViewAspect;
|
|
|
|
BOOL bIsLocked;
|
2005-11-03 11:02:48 +00:00
|
|
|
sal_Bool bNeedUpdate;
|
2004-10-04 18:47:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::Construct_Impl()
|
|
|
|
{
|
|
|
|
mpImp = new EmbeddedObjectRef_Impl;
|
|
|
|
mpImp->pContainer = 0;
|
|
|
|
mpImp->pGraphic = 0;
|
2006-03-24 12:06:02 +00:00
|
|
|
mpImp->pHCGraphic = 0;
|
2004-10-04 18:47:01 +00:00
|
|
|
mpImp->nViewAspect = embed::Aspects::MSOLE_CONTENT;
|
|
|
|
mpImp->bIsLocked = FALSE;
|
2005-11-03 11:02:48 +00:00
|
|
|
mpImp->bNeedUpdate = sal_False;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EmbeddedObjectRef::EmbeddedObjectRef()
|
|
|
|
{
|
|
|
|
Construct_Impl();
|
|
|
|
}
|
|
|
|
|
|
|
|
EmbeddedObjectRef::EmbeddedObjectRef( const NS_UNO::Reference < NS_EMBED::XEmbeddedObject >& xObj, sal_Int64 nAspect )
|
|
|
|
{
|
|
|
|
Construct_Impl();
|
|
|
|
mpImp->nViewAspect = nAspect;
|
|
|
|
mxObj = xObj;
|
|
|
|
mpImp->xListener = EmbedEventListener_Impl::Create( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
EmbeddedObjectRef::EmbeddedObjectRef( const EmbeddedObjectRef& rObj )
|
|
|
|
{
|
|
|
|
mpImp = new EmbeddedObjectRef_Impl;
|
|
|
|
mpImp->pContainer = rObj.mpImp->pContainer;
|
|
|
|
mpImp->nViewAspect = rObj.mpImp->nViewAspect;
|
|
|
|
mpImp->bIsLocked = rObj.mpImp->bIsLocked;
|
|
|
|
mxObj = rObj.mxObj;
|
|
|
|
mpImp->xListener = EmbedEventListener_Impl::Create( this );
|
|
|
|
mpImp->aPersistName = rObj.mpImp->aPersistName;
|
|
|
|
mpImp->aMediaType = rObj.mpImp->aMediaType;
|
2005-11-03 11:02:48 +00:00
|
|
|
mpImp->bNeedUpdate = rObj.mpImp->bNeedUpdate;
|
2004-10-04 18:47:01 +00:00
|
|
|
|
2005-11-03 11:02:48 +00:00
|
|
|
if ( rObj.mpImp->pGraphic && !rObj.mpImp->bNeedUpdate )
|
2004-10-04 18:47:01 +00:00
|
|
|
mpImp->pGraphic = new Graphic( *rObj.mpImp->pGraphic );
|
|
|
|
else
|
|
|
|
mpImp->pGraphic = 0;
|
2006-03-24 12:06:02 +00:00
|
|
|
|
|
|
|
mpImp->pHCGraphic = 0;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EmbeddedObjectRef::~EmbeddedObjectRef()
|
|
|
|
{
|
|
|
|
delete mpImp->pGraphic;
|
2006-03-24 12:06:02 +00:00
|
|
|
if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic );
|
2004-10-04 18:47:01 +00:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
EmbeddedObjectRef& EmbeddedObjectRef::operator = ( const EmbeddedObjectRef& rObj )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( !mxObj.is(), "Never assign an already assigned object!" );
|
|
|
|
|
|
|
|
delete mpImp->pGraphic;
|
2006-03-24 12:06:02 +00:00
|
|
|
if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic );
|
2004-10-04 18:47:01 +00:00
|
|
|
Clear();
|
|
|
|
|
|
|
|
mpImp->nViewAspect = rObj.mpImp->nViewAspect;
|
|
|
|
mpImp->bIsLocked = rObj.mpImp->bIsLocked;
|
|
|
|
mxObj = rObj.mxObj;
|
|
|
|
mpImp->xListener = EmbedEventListener_Impl::Create( this );
|
|
|
|
mpImp->pContainer = rObj.mpImp->pContainer;
|
|
|
|
mpImp->aPersistName = rObj.mpImp->aPersistName;
|
|
|
|
mpImp->aMediaType = rObj.mpImp->aMediaType;
|
2005-11-03 11:02:48 +00:00
|
|
|
mpImp->bNeedUpdate = rObj.mpImp->bNeedUpdate;
|
2004-10-04 18:47:01 +00:00
|
|
|
|
2005-11-03 11:02:48 +00:00
|
|
|
if ( rObj.mpImp->pGraphic && !rObj.mpImp->bNeedUpdate )
|
2004-10-04 18:47:01 +00:00
|
|
|
mpImp->pGraphic = new Graphic( *rObj.mpImp->pGraphic );
|
|
|
|
else
|
|
|
|
mpImp->pGraphic = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
void EmbeddedObjectRef::Assign( const NS_UNO::Reference < NS_EMBED::XEmbeddedObject >& xObj, sal_Int64 nAspect )
|
|
|
|
{
|
|
|
|
DBG_ASSERT( !mxObj.is(), "Never assign an already assigned object!" );
|
|
|
|
|
|
|
|
Clear();
|
|
|
|
mpImp->nViewAspect = nAspect;
|
|
|
|
mxObj = xObj;
|
|
|
|
mpImp->xListener = EmbedEventListener_Impl::Create( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::Clear()
|
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
if ( mxObj.is() && mpImp->xListener )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
mxObj->removeStateChangeListener( mpImp->xListener );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
uno::Reference < util::XCloseable > xClose( mxObj, uno::UNO_QUERY );
|
|
|
|
if ( xClose.is() )
|
2005-01-31 07:30:35 +00:00
|
|
|
xClose->removeCloseListener( mpImp->xListener );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
uno::Reference < document::XEventBroadcaster > xBrd( mxObj, uno::UNO_QUERY );
|
|
|
|
if ( xBrd.is() )
|
2005-01-31 07:30:35 +00:00
|
|
|
xBrd->removeEventListener( mpImp->xListener );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
if ( mpImp->bIsLocked )
|
|
|
|
{
|
|
|
|
if ( xClose.is() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2004-11-26 15:14:55 +00:00
|
|
|
mxObj->changeState( embed::EmbedStates::LOADED );
|
2004-10-04 18:47:01 +00:00
|
|
|
xClose->close( sal_True );
|
|
|
|
}
|
|
|
|
catch ( util::CloseVetoException& )
|
|
|
|
{
|
|
|
|
// there's still someone who needs the object!
|
|
|
|
}
|
2006-12-19 13:03:38 +00:00
|
|
|
catch ( uno::Exception& )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( sal_False, "Error on switching of the object to loaded state and closing!\n" );
|
|
|
|
}
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-31 07:30:35 +00:00
|
|
|
if ( mpImp->xListener )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
2005-01-31 07:30:35 +00:00
|
|
|
mpImp->xListener->pObject = 0;
|
2005-06-09 13:52:51 +00:00
|
|
|
mpImp->xListener->release();
|
2004-10-04 18:47:01 +00:00
|
|
|
mpImp->xListener = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mxObj = 0;
|
2005-11-03 11:02:48 +00:00
|
|
|
mpImp->bNeedUpdate = sal_False;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
2006-12-19 13:03:38 +00:00
|
|
|
|
|
|
|
mpImp->pContainer = 0;
|
|
|
|
mpImp->bIsLocked = FALSE;
|
|
|
|
mpImp->bNeedUpdate = sal_False;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::AssignToContainer( comphelper::EmbeddedObjectContainer* pContainer, const ::rtl::OUString& rPersistName )
|
|
|
|
{
|
|
|
|
mpImp->pContainer = pContainer;
|
|
|
|
mpImp->aPersistName = rPersistName;
|
|
|
|
|
2005-11-03 11:02:48 +00:00
|
|
|
if ( mpImp->pGraphic && !mpImp->bNeedUpdate && pContainer )
|
2004-10-04 18:47:01 +00:00
|
|
|
SetGraphicToContainer( *mpImp->pGraphic, *pContainer, mpImp->aPersistName, ::rtl::OUString() );
|
|
|
|
}
|
|
|
|
|
2005-05-11 10:57:56 +00:00
|
|
|
comphelper::EmbeddedObjectContainer* EmbeddedObjectRef::GetContainer() const
|
|
|
|
{
|
|
|
|
return mpImp->pContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
::rtl::OUString EmbeddedObjectRef::GetPersistName() const
|
|
|
|
{
|
|
|
|
return mpImp->aPersistName;
|
|
|
|
}
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
MapUnit EmbeddedObjectRef::GetMapUnit() const
|
|
|
|
{
|
2006-10-13 10:27:58 +00:00
|
|
|
if ( mpImp->nViewAspect == embed::Aspects::MSOLE_CONTENT )
|
|
|
|
return VCLUnoHelper::UnoEmbed2VCLMapUnit( mxObj->getMapUnit( mpImp->nViewAspect ) );
|
|
|
|
else
|
|
|
|
// TODO/LATER: currently only CONTENT aspect requires communication with the object
|
|
|
|
return MAP_100TH_MM;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int64 EmbeddedObjectRef::GetViewAspect() const
|
|
|
|
{
|
|
|
|
return mpImp->nViewAspect;
|
|
|
|
}
|
|
|
|
|
2006-10-13 10:27:58 +00:00
|
|
|
void EmbeddedObjectRef::SetViewAspect( sal_Int64 nAspect )
|
|
|
|
{
|
|
|
|
mpImp->nViewAspect = nAspect;
|
|
|
|
}
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
void EmbeddedObjectRef::Lock( BOOL bLock )
|
|
|
|
{
|
|
|
|
mpImp->bIsLocked = bLock;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL EmbeddedObjectRef::IsLocked() const
|
|
|
|
{
|
|
|
|
return mpImp->bIsLocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::GetReplacement( BOOL bUpdate )
|
|
|
|
{
|
|
|
|
if ( bUpdate )
|
|
|
|
{
|
|
|
|
DELETEZ( mpImp->pGraphic );
|
|
|
|
mpImp->aMediaType = ::rtl::OUString();
|
|
|
|
mpImp->pGraphic = new Graphic;
|
2006-03-24 12:06:02 +00:00
|
|
|
if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic );
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
else if ( !mpImp->pGraphic )
|
|
|
|
mpImp->pGraphic = new Graphic;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DBG_ERROR("No update, but replacement exists already!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SvStream* pGraphicStream = GetGraphicStream( bUpdate );
|
|
|
|
if ( pGraphicStream )
|
|
|
|
{
|
|
|
|
GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
|
2007-05-22 18:34:28 +00:00
|
|
|
if( mpImp->pGraphic )
|
|
|
|
pGF->ImportGraphic( *mpImp->pGraphic, String(), *pGraphicStream, GRFILTER_FORMAT_DONTKNOW );
|
2004-10-04 18:47:01 +00:00
|
|
|
delete pGraphicStream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Graphic* EmbeddedObjectRef::GetGraphic( ::rtl::OUString* pMediaType ) const
|
|
|
|
{
|
2005-11-03 11:02:48 +00:00
|
|
|
if ( mpImp->bNeedUpdate )
|
|
|
|
// bNeedUpdate will be set to false while retrieving new replacement
|
|
|
|
const_cast < EmbeddedObjectRef* >(this)->GetReplacement( sal_True );
|
|
|
|
else if ( !mpImp->pGraphic )
|
2004-10-04 18:47:01 +00:00
|
|
|
const_cast < EmbeddedObjectRef* >(this)->GetReplacement( FALSE );
|
2005-11-03 11:02:48 +00:00
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
if ( mpImp->pGraphic && pMediaType )
|
|
|
|
*pMediaType = mpImp->aMediaType;
|
|
|
|
return mpImp->pGraphic;
|
|
|
|
}
|
|
|
|
|
2006-10-13 10:27:58 +00:00
|
|
|
Size EmbeddedObjectRef::GetSize( MapMode* pTargetMapMode ) const
|
|
|
|
{
|
|
|
|
MapMode aSourceMapMode( MAP_100TH_MM );
|
|
|
|
Size aResult;
|
|
|
|
|
|
|
|
if ( mpImp->nViewAspect == embed::Aspects::MSOLE_ICON )
|
|
|
|
{
|
|
|
|
Graphic* pGraphic = GetGraphic();
|
|
|
|
if ( pGraphic )
|
|
|
|
{
|
|
|
|
aSourceMapMode = pGraphic->GetPrefMapMode();
|
|
|
|
aResult = pGraphic->GetPrefSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aResult = Size( 2500, 2500 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
awt::Size aSize;
|
|
|
|
|
|
|
|
if ( mxObj.is() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
aSize = mxObj->getVisualAreaSize( mpImp->nViewAspect );
|
|
|
|
}
|
|
|
|
catch( embed::NoVisualAreaSizeException& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
catch( uno::Exception& )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( sal_False, "Something went wrong on getting of the size of the object!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
aSourceMapMode = VCLUnoHelper::UnoEmbed2VCLMapUnit( mxObj->getMapUnit( mpImp->nViewAspect ) );
|
|
|
|
}
|
|
|
|
catch( uno::Exception )
|
|
|
|
{
|
|
|
|
OSL_ENSURE( sal_False, "Can not get the map mode!" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !aSize.Height && !aSize.Width )
|
|
|
|
{
|
|
|
|
aSize.Width = 5000;
|
|
|
|
aSize.Height = 5000;
|
|
|
|
}
|
|
|
|
|
|
|
|
aResult = Size( aSize.Width, aSize.Height );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( pTargetMapMode )
|
|
|
|
aResult = OutputDevice::LogicToLogic( aResult, aSourceMapMode, *pTargetMapMode );
|
|
|
|
|
|
|
|
return aResult;
|
|
|
|
}
|
|
|
|
|
2006-03-24 12:06:02 +00:00
|
|
|
Graphic* EmbeddedObjectRef::GetHCGraphic() const
|
|
|
|
{
|
|
|
|
if ( !mpImp->pHCGraphic )
|
|
|
|
{
|
|
|
|
uno::Reference< io::XInputStream > xInStream;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// if the object needs size on load, that means that it is not our object
|
|
|
|
// currently the HC mode is supported only for OOo own objects so the following
|
|
|
|
// check is used as an optimization
|
|
|
|
// TODO/LATER: shouldn't there be a special status flag to detect alien implementation?
|
|
|
|
if ( mpImp->nViewAspect == embed::Aspects::MSOLE_CONTENT
|
|
|
|
&& mxObj.is() && !( mxObj->getStatus( mpImp->nViewAspect ) & embed::EmbedMisc::EMBED_NEEDSSIZEONLOAD ) )
|
|
|
|
{
|
|
|
|
// TODO/LATER: optimization, it makes no sence to do it for OLE objects
|
|
|
|
if ( mxObj->getCurrentState() == embed::EmbedStates::LOADED )
|
|
|
|
mxObj->changeState( embed::EmbedStates::RUNNING );
|
|
|
|
|
|
|
|
// TODO: return for the aspect of the document
|
|
|
|
embed::VisualRepresentation aVisualRepresentation;
|
|
|
|
uno::Reference< datatransfer::XTransferable > xTransferable( mxObj->getComponent(), uno::UNO_QUERY );
|
|
|
|
if ( !xTransferable.is() )
|
|
|
|
throw uno::RuntimeException();
|
|
|
|
|
|
|
|
datatransfer::DataFlavor aDataFlavor(
|
|
|
|
::rtl::OUString::createFromAscii(
|
|
|
|
"application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
|
|
|
|
::rtl::OUString::createFromAscii( "GDIMetaFile" ),
|
|
|
|
::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
|
|
|
|
|
|
|
|
uno::Sequence < sal_Int8 > aSeq;
|
|
|
|
if ( ( xTransferable->getTransferData( aDataFlavor ) >>= aSeq ) && aSeq.getLength() )
|
|
|
|
xInStream = new ::comphelper::SequenceInputStream( aSeq );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch ( uno::Exception& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( xInStream.is() )
|
|
|
|
{
|
|
|
|
SvStream* pStream = NULL;
|
|
|
|
pStream = ::utl::UcbStreamHelper::CreateStream( xInStream );
|
|
|
|
if ( pStream )
|
|
|
|
{
|
|
|
|
if ( !pStream->GetError() )
|
|
|
|
{
|
|
|
|
GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
|
|
|
|
Graphic* pGraphic = new Graphic();
|
|
|
|
if ( pGF->ImportGraphic( *pGraphic, String(), *pStream, GRFILTER_FORMAT_DONTKNOW ) == 0 )
|
|
|
|
mpImp->pHCGraphic = pGraphic;
|
|
|
|
else
|
|
|
|
delete pGraphic;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pStream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return mpImp->pHCGraphic;
|
|
|
|
}
|
|
|
|
|
2006-10-13 10:27:58 +00:00
|
|
|
void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream >& xInGrStream,
|
|
|
|
const ::rtl::OUString& rMediaType )
|
|
|
|
{
|
|
|
|
if ( mpImp->pGraphic )
|
|
|
|
delete mpImp->pGraphic;
|
|
|
|
mpImp->pGraphic = new Graphic();
|
|
|
|
mpImp->aMediaType = rMediaType;
|
|
|
|
if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic );
|
|
|
|
|
|
|
|
SvStream* pGraphicStream = ::utl::UcbStreamHelper::CreateStream( xInGrStream );
|
|
|
|
|
|
|
|
if ( pGraphicStream )
|
|
|
|
{
|
|
|
|
GraphicFilter* pGF = GraphicFilter::GetGraphicFilter();
|
|
|
|
pGF->ImportGraphic( *mpImp->pGraphic, String(), *pGraphicStream, GRFILTER_FORMAT_DONTKNOW );
|
|
|
|
|
|
|
|
if ( mpImp->pContainer )
|
|
|
|
{
|
|
|
|
pGraphicStream->Seek( 0 );
|
|
|
|
uno::Reference< io::XInputStream > xInSeekGrStream = new ::utl::OSeekableInputStreamWrapper( pGraphicStream );
|
|
|
|
|
|
|
|
mpImp->pContainer->InsertGraphicStream( xInSeekGrStream, mpImp->aPersistName, rMediaType );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pGraphicStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
mpImp->bNeedUpdate = sal_False;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
void EmbeddedObjectRef::SetGraphic( const Graphic& rGraphic, const ::rtl::OUString& rMediaType )
|
|
|
|
{
|
|
|
|
if ( mpImp->pGraphic )
|
|
|
|
delete mpImp->pGraphic;
|
|
|
|
mpImp->pGraphic = new Graphic( rGraphic );
|
|
|
|
mpImp->aMediaType = rMediaType;
|
2006-03-24 12:06:02 +00:00
|
|
|
if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
if ( mpImp->pContainer )
|
|
|
|
SetGraphicToContainer( rGraphic, *mpImp->pContainer, mpImp->aPersistName, rMediaType );
|
2005-11-03 11:02:48 +00:00
|
|
|
|
|
|
|
mpImp->bNeedUpdate = sal_False;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SvStream* EmbeddedObjectRef::GetGraphicStream( BOOL bUpdate ) const
|
|
|
|
{
|
2006-01-20 08:49:36 +00:00
|
|
|
RTL_LOGFILE_CONTEXT( aLog, "svtools (mv76033) svt::EmbeddedObjectRef::GetGraphicStream" );
|
2004-10-04 18:47:01 +00:00
|
|
|
DBG_ASSERT( bUpdate || mpImp->pContainer, "Can't retrieve current graphic!" );
|
|
|
|
uno::Reference < io::XInputStream > xStream;
|
|
|
|
if ( mpImp->pContainer && !bUpdate )
|
2004-11-26 15:14:55 +00:00
|
|
|
{
|
2006-01-20 08:49:36 +00:00
|
|
|
RTL_LOGFILE_CONTEXT_TRACE( aLog, "getting stream from container" );
|
2004-10-04 18:47:01 +00:00
|
|
|
// try to get graphic stream from container storage
|
|
|
|
xStream = mpImp->pContainer->GetGraphicStream( mxObj, &mpImp->aMediaType );
|
2004-11-26 15:14:55 +00:00
|
|
|
if ( xStream.is() )
|
|
|
|
{
|
|
|
|
const sal_Int32 nConstBufferSize = 32000;
|
|
|
|
SvStream *pStream = new SvMemoryStream( 32000, 32000 );
|
|
|
|
sal_Int32 nRead=0;
|
|
|
|
uno::Sequence < sal_Int8 > aSequence ( nConstBufferSize );
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nRead = xStream->readBytes ( aSequence, nConstBufferSize );
|
|
|
|
pStream->Write( aSequence.getConstArray(), nRead );
|
|
|
|
}
|
|
|
|
while ( nRead == nConstBufferSize );
|
|
|
|
pStream->Seek(0);
|
|
|
|
return pStream;
|
|
|
|
}
|
|
|
|
}
|
2004-10-04 18:47:01 +00:00
|
|
|
|
|
|
|
if ( !xStream.is() )
|
|
|
|
{
|
2006-01-20 08:49:36 +00:00
|
|
|
RTL_LOGFILE_CONTEXT_TRACE( aLog, "getting stream from object" );
|
2004-10-04 18:47:01 +00:00
|
|
|
// update wanted or no stream in container storage available
|
2005-01-18 14:07:48 +00:00
|
|
|
xStream = GetGraphicReplacementStream( mpImp->nViewAspect, mxObj, &mpImp->aMediaType );
|
2004-10-04 18:47:01 +00:00
|
|
|
|
2005-01-18 14:07:48 +00:00
|
|
|
if ( xStream.is() )
|
|
|
|
{
|
2004-10-04 18:47:01 +00:00
|
|
|
if ( mpImp->pContainer )
|
|
|
|
mpImp->pContainer->InsertGraphicStream( xStream, mpImp->aPersistName, mpImp->aMediaType );
|
2005-01-18 14:07:48 +00:00
|
|
|
|
2005-11-03 11:02:48 +00:00
|
|
|
SvStream* pResult = ::utl::UcbStreamHelper::CreateStream( xStream );
|
|
|
|
if ( pResult && bUpdate )
|
|
|
|
mpImp->bNeedUpdate = sal_False;
|
|
|
|
|
|
|
|
return pResult;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::DrawPaintReplacement( const Rectangle &rRect, const String &rText, OutputDevice *pOut )
|
|
|
|
{
|
|
|
|
MapMode aMM( MAP_APPFONT );
|
|
|
|
Size aAppFontSz = pOut->LogicToLogic( Size( 0, 8 ), &aMM, NULL );
|
|
|
|
Font aFnt( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Helvetica" ) ), aAppFontSz );
|
|
|
|
aFnt.SetTransparent( TRUE );
|
|
|
|
aFnt.SetColor( Color( COL_LIGHTRED ) );
|
|
|
|
aFnt.SetWeight( WEIGHT_BOLD );
|
|
|
|
aFnt.SetFamily( FAMILY_SWISS );
|
|
|
|
|
|
|
|
pOut->Push();
|
|
|
|
pOut->SetBackground();
|
|
|
|
pOut->SetFont( aFnt );
|
|
|
|
|
|
|
|
Point aPt;
|
|
|
|
// Nun den Text so skalieren, dass er in das Rect passt.
|
|
|
|
// Wir fangen mit der Defaultsize an und gehen 1-AppFont runter
|
|
|
|
for( USHORT i = 8; i > 2; i-- )
|
|
|
|
{
|
|
|
|
aPt.X() = (rRect.GetWidth() - pOut->GetTextWidth( rText )) / 2;
|
|
|
|
aPt.Y() = (rRect.GetHeight() - pOut->GetTextHeight()) / 2;
|
|
|
|
|
|
|
|
BOOL bTiny = FALSE;
|
|
|
|
if( aPt.X() < 0 ) bTiny = TRUE, aPt.X() = 0;
|
|
|
|
if( aPt.Y() < 0 ) bTiny = TRUE, aPt.Y() = 0;
|
|
|
|
if( bTiny )
|
|
|
|
{
|
|
|
|
// heruntergehen bei kleinen Bildern
|
|
|
|
aFnt.SetSize( Size( 0, aAppFontSz.Height() * i / 8 ) );
|
|
|
|
pOut->SetFont( aFnt );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bitmap aBmp( SvtResId( BMP_PLUGIN ) );
|
|
|
|
long nHeight = rRect.GetHeight() - pOut->GetTextHeight();
|
|
|
|
long nWidth = rRect.GetWidth();
|
|
|
|
if( nHeight > 0 )
|
|
|
|
{
|
|
|
|
aPt.Y() = nHeight;
|
|
|
|
Point aP = rRect.TopLeft();
|
|
|
|
Size aBmpSize = aBmp.GetSizePixel();
|
|
|
|
// Bitmap einpassen
|
|
|
|
if( nHeight * 10 / nWidth
|
|
|
|
> aBmpSize.Height() * 10 / aBmpSize.Width() )
|
|
|
|
{
|
|
|
|
// nach der Breite ausrichten
|
|
|
|
// Proportion beibehalten
|
|
|
|
long nH = nWidth * aBmpSize.Height() / aBmpSize.Width();
|
|
|
|
// zentrieren
|
|
|
|
aP.Y() += (nHeight - nH) / 2;
|
|
|
|
nHeight = nH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// nach der H"ohe ausrichten
|
|
|
|
// Proportion beibehalten
|
|
|
|
long nW = nHeight * aBmpSize.Width() / aBmpSize.Height();
|
|
|
|
// zentrieren
|
|
|
|
aP.X() += (nWidth - nW) / 2;
|
|
|
|
nWidth = nW;
|
|
|
|
}
|
|
|
|
|
|
|
|
pOut->DrawBitmap( aP, Size( nWidth, nHeight ), aBmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
pOut->IntersectClipRegion( rRect );
|
|
|
|
aPt += rRect.TopLeft();
|
|
|
|
pOut->DrawText( aPt, rText );
|
|
|
|
pOut->Pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::DrawShading( const Rectangle &rRect, OutputDevice *pOut )
|
|
|
|
{
|
|
|
|
GDIMetaFile * pMtf = pOut->GetConnectMetaFile();
|
|
|
|
if( pMtf && pMtf->IsRecord() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
pOut->Push();
|
|
|
|
pOut->SetLineColor( Color( COL_BLACK ) );
|
|
|
|
|
|
|
|
Size aPixSize = pOut->LogicToPixel( rRect.GetSize() );
|
|
|
|
aPixSize.Width() -= 1;
|
|
|
|
aPixSize.Height() -= 1;
|
|
|
|
Point aPixViewPos = pOut->LogicToPixel( rRect.TopLeft() );
|
|
|
|
INT32 nMax = aPixSize.Width() + aPixSize.Height();
|
|
|
|
for( INT32 i = 5; i < nMax; i += 5 )
|
|
|
|
{
|
|
|
|
Point a1( aPixViewPos ), a2( aPixViewPos );
|
|
|
|
if( i > aPixSize.Width() )
|
|
|
|
a1 += Point( aPixSize.Width(), i - aPixSize.Width() );
|
|
|
|
else
|
|
|
|
a1 += Point( i, 0 );
|
|
|
|
if( i > aPixSize.Height() )
|
|
|
|
a2 += Point( i - aPixSize.Height(), aPixSize.Height() );
|
|
|
|
else
|
|
|
|
a2 += Point( 0, i );
|
|
|
|
|
|
|
|
pOut->DrawLine( pOut->PixelToLogic( a1 ), pOut->PixelToLogic( a2 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
pOut->Pop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-11-26 15:14:55 +00:00
|
|
|
BOOL EmbeddedObjectRef::TryRunningState()
|
|
|
|
{
|
|
|
|
return TryRunningState( mxObj );
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL EmbeddedObjectRef::TryRunningState( const uno::Reference < embed::XEmbeddedObject >& xEmbObj )
|
2004-10-04 18:47:01 +00:00
|
|
|
{
|
2006-04-26 13:22:22 +00:00
|
|
|
if ( !xEmbObj.is() )
|
|
|
|
return FALSE;
|
|
|
|
|
2004-10-04 18:47:01 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( xEmbObj->getCurrentState() == embed::EmbedStates::LOADED )
|
|
|
|
xEmbObj->changeState( embed::EmbedStates::RUNNING );
|
|
|
|
}
|
|
|
|
catch ( uno::Exception& )
|
|
|
|
{
|
2004-11-26 15:14:55 +00:00
|
|
|
return FALSE;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
2004-11-26 15:14:55 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2004-10-04 18:47:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmbeddedObjectRef::SetGraphicToContainer( const Graphic& rGraphic,
|
|
|
|
comphelper::EmbeddedObjectContainer& aContainer,
|
|
|
|
const ::rtl::OUString& aName,
|
|
|
|
const ::rtl::OUString& aMediaType )
|
|
|
|
{
|
|
|
|
SvMemoryStream aStream;
|
2005-01-31 07:30:35 +00:00
|
|
|
aStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT );
|
2004-10-04 18:47:01 +00:00
|
|
|
if ( rGraphic.ExportNative( aStream ) )
|
|
|
|
{
|
|
|
|
aStream.Seek( 0 );
|
|
|
|
|
|
|
|
uno::Reference < io::XInputStream > xStream = new ::utl::OSeekableInputStreamWrapper( aStream );
|
|
|
|
aContainer.InsertGraphicStream( xStream, aName, aMediaType );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
OSL_ENSURE( sal_False, "Export of graphic is failed!\n" );
|
|
|
|
}
|
|
|
|
|
2005-01-18 14:07:48 +00:00
|
|
|
sal_Bool EmbeddedObjectRef::ObjectIsModified( const uno::Reference< embed::XEmbeddedObject >& xObj )
|
|
|
|
throw( uno::Exception )
|
|
|
|
{
|
|
|
|
sal_Bool bResult = sal_False;
|
|
|
|
|
|
|
|
sal_Int32 nState = xObj->getCurrentState();
|
|
|
|
if ( nState != embed::EmbedStates::LOADED && nState != embed::EmbedStates::RUNNING )
|
|
|
|
{
|
|
|
|
// the object is active so if the model is modified the replacement
|
|
|
|
// should be retrieved from the object
|
|
|
|
uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
|
|
|
|
if ( xModifiable.is() )
|
|
|
|
bResult = xModifiable->isModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference< io::XInputStream > EmbeddedObjectRef::GetGraphicReplacementStream(
|
|
|
|
sal_Int64 nViewAspect,
|
|
|
|
const uno::Reference< embed::XEmbeddedObject >& xObj,
|
|
|
|
::rtl::OUString* pMediaType )
|
|
|
|
throw()
|
|
|
|
{
|
|
|
|
uno::Reference< io::XInputStream > xInStream;
|
|
|
|
if ( xObj.is() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2005-01-31 08:25:43 +00:00
|
|
|
// retrieving of the visual representation can switch object to running state
|
2005-01-18 14:07:48 +00:00
|
|
|
embed::VisualRepresentation aRep = xObj->getPreferredVisualRepresentation( nViewAspect );
|
|
|
|
if ( pMediaType )
|
|
|
|
*pMediaType = aRep.Flavor.MimeType;
|
|
|
|
|
|
|
|
uno::Sequence < sal_Int8 > aSeq;
|
|
|
|
aRep.Data >>= aSeq;
|
|
|
|
xInStream = new ::comphelper::SequenceInputStream( aSeq );
|
|
|
|
}
|
|
|
|
catch ( uno::Exception& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return xInStream;
|
|
|
|
}
|
|
|
|
|
2005-11-03 11:02:48 +00:00
|
|
|
void EmbeddedObjectRef::UpdateReplacementOnDemand()
|
|
|
|
{
|
|
|
|
DELETEZ( mpImp->pGraphic );
|
|
|
|
mpImp->bNeedUpdate = sal_True;
|
2006-03-24 12:06:02 +00:00
|
|
|
if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic );
|
2005-11-03 11:02:48 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 20:19:36 +00:00
|
|
|
}
|