15900e8ecSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file 55900e8ecSAndrew Rist * distributed with this work for additional information 65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file 75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the 85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance 95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing, 145900e8ecSAndrew Rist * software distributed under the License is distributed on an 155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the 175900e8ecSAndrew Rist * specific language governing permissions and limitations 185900e8ecSAndrew Rist * under the License. 19cdf0e10cSrcweir * 205900e8ecSAndrew Rist *************************************************************/ 215900e8ecSAndrew Rist 225900e8ecSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svtools.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <svtools/embedhlp.hxx> 28cdf0e10cSrcweir #include <svtools/filter.hxx> 29cdf0e10cSrcweir #include <svtools/svtools.hrc> 30cdf0e10cSrcweir #include <svtools/svtdata.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <comphelper/embeddedobjectcontainer.hxx> 33cdf0e10cSrcweir #include <comphelper/seqstream.hxx> 34cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 35cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 36cdf0e10cSrcweir #include <unotools/streamwrap.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <tools/globname.hxx> 39cdf0e10cSrcweir #include <sot/clsids.hxx> 40cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp> 41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XMODIFYiBLE_HPP_ 42cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 45cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp> 46cdf0e10cSrcweir #include <com/sun/star/embed/XStateChangeListener.hpp> 47cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 48cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 49cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp> 50cdf0e10cSrcweir #include <com/sun/star/chart2/XDefaultSizeTransmitter.hpp> 51cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx> 52cdf0e10cSrcweir #include "vcl/svapp.hxx" 53cdf0e10cSrcweir #include <rtl/logfile.hxx> 54cdf0e10cSrcweir #include <vos/mutex.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir using namespace com::sun::star; 57cdf0e10cSrcweir 58cdf0e10cSrcweir namespace svt 59cdf0e10cSrcweir { 60cdf0e10cSrcweir 61cdf0e10cSrcweir class EmbedEventListener_Impl : public ::cppu::WeakImplHelper4 < embed::XStateChangeListener, 62cdf0e10cSrcweir document::XEventListener, 63cdf0e10cSrcweir util::XModifyListener, 64cdf0e10cSrcweir util::XCloseListener > 65cdf0e10cSrcweir { 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir EmbeddedObjectRef* pObject; 68cdf0e10cSrcweir sal_Int32 nState; 69cdf0e10cSrcweir 70cdf0e10cSrcweir EmbedEventListener_Impl( EmbeddedObjectRef* p ) : 71cdf0e10cSrcweir pObject(p) 72cdf0e10cSrcweir , nState(-1) 73cdf0e10cSrcweir {} 74cdf0e10cSrcweir 75cdf0e10cSrcweir static EmbedEventListener_Impl* Create( EmbeddedObjectRef* ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir virtual void SAL_CALL changingState( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) 78cdf0e10cSrcweir throw (embed::WrongStateException, uno::RuntimeException); 79cdf0e10cSrcweir virtual void SAL_CALL stateChanged( const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) 80cdf0e10cSrcweir throw (uno::RuntimeException); 81cdf0e10cSrcweir virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) 82cdf0e10cSrcweir throw (util::CloseVetoException, uno::RuntimeException); 83cdf0e10cSrcweir virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException); 84cdf0e10cSrcweir virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException ); 85cdf0e10cSrcweir virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException ); 86cdf0e10cSrcweir virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException); 87cdf0e10cSrcweir }; 88cdf0e10cSrcweir 89cdf0e10cSrcweir EmbedEventListener_Impl* EmbedEventListener_Impl::Create( EmbeddedObjectRef* p ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir EmbedEventListener_Impl* xRet = new EmbedEventListener_Impl( p ); 92cdf0e10cSrcweir xRet->acquire(); 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( p->GetObject().is() ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir p->GetObject()->addStateChangeListener( xRet ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir uno::Reference < util::XCloseable > xClose( p->GetObject(), uno::UNO_QUERY ); 99cdf0e10cSrcweir DBG_ASSERT( xClose.is(), "Object does not support XCloseable!" ); 100cdf0e10cSrcweir if ( xClose.is() ) 101cdf0e10cSrcweir xClose->addCloseListener( xRet ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir uno::Reference < document::XEventBroadcaster > xBrd( p->GetObject(), uno::UNO_QUERY ); 104cdf0e10cSrcweir if ( xBrd.is() ) 105cdf0e10cSrcweir xBrd->addEventListener( xRet ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir xRet->nState = p->GetObject()->getCurrentState(); 108cdf0e10cSrcweir if ( xRet->nState == embed::EmbedStates::RUNNING ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir uno::Reference < util::XModifiable > xMod( p->GetObject()->getComponent(), uno::UNO_QUERY ); 111cdf0e10cSrcweir if ( xMod.is() ) 112cdf0e10cSrcweir // listen for changes in running state (update replacements in case of changes) 113cdf0e10cSrcweir xMod->addModifyListener( xRet ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir return xRet; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::changingState( const lang::EventObject&, 121cdf0e10cSrcweir ::sal_Int32, 122cdf0e10cSrcweir ::sal_Int32 ) 123cdf0e10cSrcweir throw ( embed::WrongStateException, 124cdf0e10cSrcweir uno::RuntimeException ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::stateChanged( const lang::EventObject&, 129cdf0e10cSrcweir ::sal_Int32 nOldState, 130cdf0e10cSrcweir ::sal_Int32 nNewState ) 131cdf0e10cSrcweir throw ( uno::RuntimeException ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 134cdf0e10cSrcweir nState = nNewState; 135cdf0e10cSrcweir if ( !pObject ) 136cdf0e10cSrcweir return; 137cdf0e10cSrcweir 138cdf0e10cSrcweir uno::Reference < util::XModifiable > xMod( pObject->GetObject()->getComponent(), uno::UNO_QUERY ); 139cdf0e10cSrcweir if ( nNewState == embed::EmbedStates::RUNNING ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir // TODO/LATER: container must be set before! 142cdf0e10cSrcweir // When is this event created? Who sets the new container when it changed? 143cdf0e10cSrcweir if( ( pObject->GetViewAspect() != embed::Aspects::MSOLE_ICON ) && nOldState != embed::EmbedStates::LOADED && !pObject->IsChart() ) 144cdf0e10cSrcweir // get new replacement after deactivation 145cdf0e10cSrcweir pObject->UpdateReplacement(); 146cdf0e10cSrcweir 147cdf0e10cSrcweir if( pObject->IsChart() && nOldState == embed::EmbedStates::UI_ACTIVE ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir //create a new metafile replacement when leaving the edit mode 150cdf0e10cSrcweir //for buggy documents where the old image looks different from the correct one 151cdf0e10cSrcweir if( xMod.is() && !xMod->isModified() )//in case of modification a new replacement will be requested anyhow 152cdf0e10cSrcweir pObject->UpdateReplacementOnDemand(); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir if ( xMod.is() && nOldState == embed::EmbedStates::LOADED ) 156cdf0e10cSrcweir // listen for changes (update replacements in case of changes) 157cdf0e10cSrcweir xMod->addModifyListener( this ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir else if ( nNewState == embed::EmbedStates::LOADED ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir // in loaded state we can't listen 162cdf0e10cSrcweir if ( xMod.is() ) 163cdf0e10cSrcweir xMod->removeModifyListener( this ); 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::modified( const lang::EventObject& ) throw (uno::RuntimeException) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 170cdf0e10cSrcweir if ( pObject && pObject->GetViewAspect() != embed::Aspects::MSOLE_ICON ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir if ( nState == embed::EmbedStates::RUNNING ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir // updates only necessary in non-active states 175cdf0e10cSrcweir if( pObject->IsChart() ) 176cdf0e10cSrcweir pObject->UpdateReplacementOnDemand(); 177cdf0e10cSrcweir else 178cdf0e10cSrcweir pObject->UpdateReplacement(); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir else if ( nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::INPLACE_ACTIVE ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir // in case the object is inplace or UI active the replacement image should be updated on demand 183cdf0e10cSrcweir pObject->UpdateReplacementOnDemand(); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 191cdf0e10cSrcweir 192cdf0e10cSrcweir #if 0 193cdf0e10cSrcweir if ( pObject && aEvent.EventName.equalsAscii("OnSaveDone") || aEvent.EventName.equalsAscii("OnSaveAsDone") ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir // TODO/LATER: container must be set before! 196cdf0e10cSrcweir // When is this event created? Who sets the new container when it changed? 197cdf0e10cSrcweir pObject->UpdateReplacement(); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir else 200cdf0e10cSrcweir #endif 201cdf0e10cSrcweir if ( pObject && aEvent.EventName.equalsAscii("OnVisAreaChanged") && pObject->GetViewAspect() != embed::Aspects::MSOLE_ICON && !pObject->IsChart() ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir pObject->UpdateReplacement(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::queryClosing( const lang::EventObject& Source, ::sal_Bool ) 208cdf0e10cSrcweir throw ( util::CloseVetoException, uno::RuntimeException) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir // An embedded object can be shared between several objects (f.e. for undo purposes) 211cdf0e10cSrcweir // the object will not be closed before the last "customer" is destroyed 212cdf0e10cSrcweir // Now the EmbeddedObjectRef helper class works like a "lock" on the object 213cdf0e10cSrcweir if ( pObject && pObject->IsLocked() && Source.Source == pObject->GetObject() ) 214cdf0e10cSrcweir throw util::CloseVetoException(); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::notifyClosing( const lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir if ( pObject && Source.Source == pObject->GetObject() ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir pObject->Clear(); 222cdf0e10cSrcweir pObject = 0; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir void SAL_CALL EmbedEventListener_Impl::disposing( const lang::EventObject& aEvent ) throw( uno::RuntimeException ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir if ( pObject && aEvent.Source == pObject->GetObject() ) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir pObject->Clear(); 231cdf0e10cSrcweir pObject = 0; 232cdf0e10cSrcweir } 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir struct EmbeddedObjectRef_Impl 236cdf0e10cSrcweir { 237cdf0e10cSrcweir EmbedEventListener_Impl* xListener; 238cdf0e10cSrcweir ::rtl::OUString aPersistName; 239cdf0e10cSrcweir ::rtl::OUString aMediaType; 240cdf0e10cSrcweir comphelper::EmbeddedObjectContainer* pContainer; 241cdf0e10cSrcweir Graphic* pGraphic; 242cdf0e10cSrcweir Graphic* pHCGraphic; 243cdf0e10cSrcweir sal_Int64 nViewAspect; 244cdf0e10cSrcweir sal_Bool bIsLocked; 245cdf0e10cSrcweir sal_Bool bNeedUpdate; 246cdf0e10cSrcweir 247cdf0e10cSrcweir // #i104867# 248cdf0e10cSrcweir sal_uInt32 mnGraphicVersion; 249cdf0e10cSrcweir awt::Size aDefaultSizeForChart_In_100TH_MM;//#i103460# charts do not necessaryly have an own size within ODF files, in this case they need to use the size settings from the surrounding frame, which is made available with this member 250cdf0e10cSrcweir }; 251cdf0e10cSrcweir 252cdf0e10cSrcweir void EmbeddedObjectRef::Construct_Impl() 253cdf0e10cSrcweir { 254cdf0e10cSrcweir mpImp = new EmbeddedObjectRef_Impl; 255cdf0e10cSrcweir mpImp->pContainer = 0; 256cdf0e10cSrcweir mpImp->pGraphic = 0; 257cdf0e10cSrcweir mpImp->pHCGraphic = 0; 258cdf0e10cSrcweir mpImp->nViewAspect = embed::Aspects::MSOLE_CONTENT; 259cdf0e10cSrcweir mpImp->bIsLocked = sal_False; 260cdf0e10cSrcweir mpImp->bNeedUpdate = sal_False; 261cdf0e10cSrcweir mpImp->mnGraphicVersion = 0; 262cdf0e10cSrcweir mpImp->aDefaultSizeForChart_In_100TH_MM = awt::Size(8000,7000); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir EmbeddedObjectRef::EmbeddedObjectRef() 266cdf0e10cSrcweir { 267cdf0e10cSrcweir Construct_Impl(); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir EmbeddedObjectRef::EmbeddedObjectRef( const NS_UNO::Reference < NS_EMBED::XEmbeddedObject >& xObj, sal_Int64 nAspect ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir Construct_Impl(); 273cdf0e10cSrcweir mpImp->nViewAspect = nAspect; 274cdf0e10cSrcweir mxObj = xObj; 275cdf0e10cSrcweir mpImp->xListener = EmbedEventListener_Impl::Create( this ); 276cdf0e10cSrcweir } 277cdf0e10cSrcweir 278cdf0e10cSrcweir EmbeddedObjectRef::EmbeddedObjectRef( const EmbeddedObjectRef& rObj ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir mpImp = new EmbeddedObjectRef_Impl; 281cdf0e10cSrcweir mpImp->pContainer = rObj.mpImp->pContainer; 282cdf0e10cSrcweir mpImp->nViewAspect = rObj.mpImp->nViewAspect; 283cdf0e10cSrcweir mpImp->bIsLocked = rObj.mpImp->bIsLocked; 284cdf0e10cSrcweir mxObj = rObj.mxObj; 285cdf0e10cSrcweir mpImp->xListener = EmbedEventListener_Impl::Create( this ); 286cdf0e10cSrcweir mpImp->aPersistName = rObj.mpImp->aPersistName; 287cdf0e10cSrcweir mpImp->aMediaType = rObj.mpImp->aMediaType; 288cdf0e10cSrcweir mpImp->bNeedUpdate = rObj.mpImp->bNeedUpdate; 289cdf0e10cSrcweir mpImp->aDefaultSizeForChart_In_100TH_MM = rObj.mpImp->aDefaultSizeForChart_In_100TH_MM; 290cdf0e10cSrcweir 291cdf0e10cSrcweir if ( rObj.mpImp->pGraphic && !rObj.mpImp->bNeedUpdate ) 292cdf0e10cSrcweir mpImp->pGraphic = new Graphic( *rObj.mpImp->pGraphic ); 293cdf0e10cSrcweir else 294cdf0e10cSrcweir mpImp->pGraphic = 0; 295cdf0e10cSrcweir 296cdf0e10cSrcweir mpImp->pHCGraphic = 0; 297cdf0e10cSrcweir mpImp->mnGraphicVersion = 0; 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir EmbeddedObjectRef::~EmbeddedObjectRef() 301cdf0e10cSrcweir { 302cdf0e10cSrcweir delete mpImp->pGraphic; 303cdf0e10cSrcweir if ( mpImp->pHCGraphic ) 304cdf0e10cSrcweir DELETEZ( mpImp->pHCGraphic ); 305cdf0e10cSrcweir Clear(); 3064fa9ac85SHerbert Dürr delete mpImp; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir /* 309cdf0e10cSrcweir EmbeddedObjectRef& EmbeddedObjectRef::operator = ( const EmbeddedObjectRef& rObj ) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir DBG_ASSERT( !mxObj.is(), "Never assign an already assigned object!" ); 312cdf0e10cSrcweir 313cdf0e10cSrcweir delete mpImp->pGraphic; 314cdf0e10cSrcweir if ( mpImp->pHCGraphic ) DELETEZ( mpImp->pHCGraphic ); 315cdf0e10cSrcweir Clear(); 316cdf0e10cSrcweir 317cdf0e10cSrcweir mpImp->nViewAspect = rObj.mpImp->nViewAspect; 318cdf0e10cSrcweir mpImp->bIsLocked = rObj.mpImp->bIsLocked; 319cdf0e10cSrcweir mxObj = rObj.mxObj; 320cdf0e10cSrcweir mpImp->xListener = EmbedEventListener_Impl::Create( this ); 321cdf0e10cSrcweir mpImp->pContainer = rObj.mpImp->pContainer; 322cdf0e10cSrcweir mpImp->aPersistName = rObj.mpImp->aPersistName; 323cdf0e10cSrcweir mpImp->aMediaType = rObj.mpImp->aMediaType; 324cdf0e10cSrcweir mpImp->bNeedUpdate = rObj.mpImp->bNeedUpdate; 325cdf0e10cSrcweir 326cdf0e10cSrcweir if ( rObj.mpImp->pGraphic && !rObj.mpImp->bNeedUpdate ) 327cdf0e10cSrcweir mpImp->pGraphic = new Graphic( *rObj.mpImp->pGraphic ); 328cdf0e10cSrcweir else 329cdf0e10cSrcweir mpImp->pGraphic = 0; 330cdf0e10cSrcweir return *this; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir */ 333cdf0e10cSrcweir void EmbeddedObjectRef::Assign( const NS_UNO::Reference < NS_EMBED::XEmbeddedObject >& xObj, sal_Int64 nAspect ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir DBG_ASSERT( !mxObj.is(), "Never assign an already assigned object!" ); 336cdf0e10cSrcweir 337cdf0e10cSrcweir Clear(); 338cdf0e10cSrcweir mpImp->nViewAspect = nAspect; 339cdf0e10cSrcweir mxObj = xObj; 340cdf0e10cSrcweir mpImp->xListener = EmbedEventListener_Impl::Create( this ); 341cdf0e10cSrcweir 342cdf0e10cSrcweir //#i103460# 343cdf0e10cSrcweir if ( IsChart() ) 344cdf0e10cSrcweir { 345cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::chart2::XDefaultSizeTransmitter > xSizeTransmitter( xObj, uno::UNO_QUERY ); 346cdf0e10cSrcweir DBG_ASSERT( xSizeTransmitter.is(), "Object does not support XDefaultSizeTransmitter -> will cause #i103460#!" ); 347cdf0e10cSrcweir if( xSizeTransmitter.is() ) 348cdf0e10cSrcweir xSizeTransmitter->setDefaultSize( mpImp->aDefaultSizeForChart_In_100TH_MM ); 349cdf0e10cSrcweir } 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir void EmbeddedObjectRef::Clear() 353cdf0e10cSrcweir { 354cdf0e10cSrcweir if ( mxObj.is() && mpImp->xListener ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir mxObj->removeStateChangeListener( mpImp->xListener ); 357cdf0e10cSrcweir 358cdf0e10cSrcweir uno::Reference < util::XCloseable > xClose( mxObj, uno::UNO_QUERY ); 359cdf0e10cSrcweir if ( xClose.is() ) 360cdf0e10cSrcweir xClose->removeCloseListener( mpImp->xListener ); 361cdf0e10cSrcweir 362cdf0e10cSrcweir uno::Reference < document::XEventBroadcaster > xBrd( mxObj, uno::UNO_QUERY ); 363cdf0e10cSrcweir if ( xBrd.is() ) 364cdf0e10cSrcweir xBrd->removeEventListener( mpImp->xListener ); 365cdf0e10cSrcweir 366cdf0e10cSrcweir if ( mpImp->bIsLocked ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir if ( xClose.is() ) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir try 371cdf0e10cSrcweir { 372cdf0e10cSrcweir mxObj->changeState( embed::EmbedStates::LOADED ); 373cdf0e10cSrcweir xClose->close( sal_True ); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir catch ( util::CloseVetoException& ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir // there's still someone who needs the object! 378cdf0e10cSrcweir } 379cdf0e10cSrcweir catch ( uno::Exception& ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir OSL_ENSURE( sal_False, "Error on switching of the object to loaded state and closing!\n" ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir } 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir if ( mpImp->xListener ) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir mpImp->xListener->pObject = 0; 389cdf0e10cSrcweir mpImp->xListener->release(); 390cdf0e10cSrcweir mpImp->xListener = 0; 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir mxObj = 0; 394cdf0e10cSrcweir mpImp->bNeedUpdate = sal_False; 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir mpImp->pContainer = 0; 398cdf0e10cSrcweir mpImp->bIsLocked = sal_False; 399cdf0e10cSrcweir mpImp->bNeedUpdate = sal_False; 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir void EmbeddedObjectRef::AssignToContainer( comphelper::EmbeddedObjectContainer* pContainer, const ::rtl::OUString& rPersistName ) 403cdf0e10cSrcweir { 404cdf0e10cSrcweir mpImp->pContainer = pContainer; 405cdf0e10cSrcweir mpImp->aPersistName = rPersistName; 406cdf0e10cSrcweir 407cdf0e10cSrcweir if ( mpImp->pGraphic && !mpImp->bNeedUpdate && pContainer ) 408cdf0e10cSrcweir SetGraphicToContainer( *mpImp->pGraphic, *pContainer, mpImp->aPersistName, ::rtl::OUString() ); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir comphelper::EmbeddedObjectContainer* EmbeddedObjectRef::GetContainer() const 412cdf0e10cSrcweir { 413cdf0e10cSrcweir return mpImp->pContainer; 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir ::rtl::OUString EmbeddedObjectRef::GetPersistName() const 417cdf0e10cSrcweir { 418cdf0e10cSrcweir return mpImp->aPersistName; 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir MapUnit EmbeddedObjectRef::GetMapUnit() const 422cdf0e10cSrcweir { 423cdf0e10cSrcweir if ( mpImp->nViewAspect == embed::Aspects::MSOLE_CONTENT ) 424cdf0e10cSrcweir return VCLUnoHelper::UnoEmbed2VCLMapUnit( mxObj->getMapUnit( mpImp->nViewAspect ) ); 425cdf0e10cSrcweir else 426cdf0e10cSrcweir // TODO/LATER: currently only CONTENT aspect requires communication with the object 427cdf0e10cSrcweir return MAP_100TH_MM; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir 430cdf0e10cSrcweir sal_Int64 EmbeddedObjectRef::GetViewAspect() const 431cdf0e10cSrcweir { 432cdf0e10cSrcweir return mpImp->nViewAspect; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir void EmbeddedObjectRef::SetViewAspect( sal_Int64 nAspect ) 436cdf0e10cSrcweir { 437cdf0e10cSrcweir mpImp->nViewAspect = nAspect; 438cdf0e10cSrcweir } 439cdf0e10cSrcweir 440cdf0e10cSrcweir void EmbeddedObjectRef::Lock( sal_Bool bLock ) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir mpImp->bIsLocked = bLock; 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir sal_Bool EmbeddedObjectRef::IsLocked() const 446cdf0e10cSrcweir { 447cdf0e10cSrcweir return mpImp->bIsLocked; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir 450cdf0e10cSrcweir void EmbeddedObjectRef::GetReplacement( sal_Bool bUpdate ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir if ( bUpdate ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir DELETEZ( mpImp->pGraphic ); 455cdf0e10cSrcweir mpImp->aMediaType = ::rtl::OUString(); 456cdf0e10cSrcweir mpImp->pGraphic = new Graphic; 457cdf0e10cSrcweir if ( mpImp->pHCGraphic ) 458cdf0e10cSrcweir DELETEZ( mpImp->pHCGraphic ); 459cdf0e10cSrcweir mpImp->mnGraphicVersion++; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir else if ( !mpImp->pGraphic ) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir mpImp->pGraphic = new Graphic; 464cdf0e10cSrcweir mpImp->mnGraphicVersion++; 465cdf0e10cSrcweir } 466cdf0e10cSrcweir else 467cdf0e10cSrcweir { 468cdf0e10cSrcweir DBG_ERROR("No update, but replacement exists already!"); 469cdf0e10cSrcweir return; 470cdf0e10cSrcweir } 471cdf0e10cSrcweir 472cdf0e10cSrcweir SvStream* pGraphicStream = GetGraphicStream( bUpdate ); 473cdf0e10cSrcweir if ( pGraphicStream ) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir GraphicFilter* pGF = GraphicFilter::GetGraphicFilter(); 476cdf0e10cSrcweir if( mpImp->pGraphic ) 477cdf0e10cSrcweir pGF->ImportGraphic( *mpImp->pGraphic, String(), *pGraphicStream, GRFILTER_FORMAT_DONTKNOW ); 478cdf0e10cSrcweir mpImp->mnGraphicVersion++; 479cdf0e10cSrcweir delete pGraphicStream; 480cdf0e10cSrcweir } 481cdf0e10cSrcweir } 482cdf0e10cSrcweir 483cdf0e10cSrcweir Graphic* EmbeddedObjectRef::GetGraphic( ::rtl::OUString* pMediaType ) const 484cdf0e10cSrcweir { 485*2c35faf5SArmin Le Grand try 486*2c35faf5SArmin Le Grand { 487cdf0e10cSrcweir if ( mpImp->bNeedUpdate ) 488cdf0e10cSrcweir // bNeedUpdate will be set to false while retrieving new replacement 489cdf0e10cSrcweir const_cast < EmbeddedObjectRef* >(this)->GetReplacement( sal_True ); 490cdf0e10cSrcweir else if ( !mpImp->pGraphic ) 491cdf0e10cSrcweir const_cast < EmbeddedObjectRef* >(this)->GetReplacement( sal_False ); 492*2c35faf5SArmin Le Grand } 493*2c35faf5SArmin Le Grand catch( uno::Exception& ) 494*2c35faf5SArmin Le Grand { 495*2c35faf5SArmin Le Grand OSL_ENSURE( sal_False, "Something went wrong on getting the graphic!" ); 496*2c35faf5SArmin Le Grand } 497cdf0e10cSrcweir 498cdf0e10cSrcweir if ( mpImp->pGraphic && pMediaType ) 499cdf0e10cSrcweir *pMediaType = mpImp->aMediaType; 500cdf0e10cSrcweir return mpImp->pGraphic; 501cdf0e10cSrcweir } 502cdf0e10cSrcweir 503cdf0e10cSrcweir Size EmbeddedObjectRef::GetSize( MapMode* pTargetMapMode ) const 504cdf0e10cSrcweir { 505cdf0e10cSrcweir MapMode aSourceMapMode( MAP_100TH_MM ); 506cdf0e10cSrcweir Size aResult; 507cdf0e10cSrcweir 508cdf0e10cSrcweir if ( mpImp->nViewAspect == embed::Aspects::MSOLE_ICON ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir Graphic* pGraphic = GetGraphic(); 511cdf0e10cSrcweir if ( pGraphic ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir aSourceMapMode = pGraphic->GetPrefMapMode(); 514cdf0e10cSrcweir aResult = pGraphic->GetPrefSize(); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir else 517cdf0e10cSrcweir aResult = Size( 2500, 2500 ); 518cdf0e10cSrcweir } 519cdf0e10cSrcweir else 520cdf0e10cSrcweir { 521cdf0e10cSrcweir awt::Size aSize; 522cdf0e10cSrcweir 523cdf0e10cSrcweir if ( mxObj.is() ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir try 526cdf0e10cSrcweir { 527cdf0e10cSrcweir aSize = mxObj->getVisualAreaSize( mpImp->nViewAspect ); 528cdf0e10cSrcweir } 529cdf0e10cSrcweir catch( embed::NoVisualAreaSizeException& ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir } 532cdf0e10cSrcweir catch( uno::Exception& ) 533cdf0e10cSrcweir { 534cdf0e10cSrcweir OSL_ENSURE( sal_False, "Something went wrong on getting of the size of the object!" ); 535cdf0e10cSrcweir } 536cdf0e10cSrcweir 537cdf0e10cSrcweir try 538cdf0e10cSrcweir { 539cdf0e10cSrcweir aSourceMapMode = VCLUnoHelper::UnoEmbed2VCLMapUnit( mxObj->getMapUnit( mpImp->nViewAspect ) ); 540cdf0e10cSrcweir } 541cdf0e10cSrcweir catch( uno::Exception ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir OSL_ENSURE( sal_False, "Can not get the map mode!" ); 544cdf0e10cSrcweir } 545cdf0e10cSrcweir } 546cdf0e10cSrcweir 547cdf0e10cSrcweir if ( !aSize.Height && !aSize.Width ) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir aSize.Width = 5000; 550cdf0e10cSrcweir aSize.Height = 5000; 551cdf0e10cSrcweir } 552cdf0e10cSrcweir 553cdf0e10cSrcweir aResult = Size( aSize.Width, aSize.Height ); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir if ( pTargetMapMode ) 557cdf0e10cSrcweir aResult = OutputDevice::LogicToLogic( aResult, aSourceMapMode, *pTargetMapMode ); 558cdf0e10cSrcweir 559cdf0e10cSrcweir return aResult; 560cdf0e10cSrcweir } 561cdf0e10cSrcweir 562cdf0e10cSrcweir Graphic* EmbeddedObjectRef::GetHCGraphic() const 563cdf0e10cSrcweir { 564cdf0e10cSrcweir if ( !mpImp->pHCGraphic ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream; 567cdf0e10cSrcweir try 568cdf0e10cSrcweir { 569cdf0e10cSrcweir // if the object needs size on load, that means that it is not our object 570cdf0e10cSrcweir // currently the HC mode is supported only for OOo own objects so the following 571cdf0e10cSrcweir // check is used as an optimization 572cdf0e10cSrcweir // TODO/LATER: shouldn't there be a special status flag to detect alien implementation? 573cdf0e10cSrcweir if ( mpImp->nViewAspect == embed::Aspects::MSOLE_CONTENT 574cdf0e10cSrcweir && mxObj.is() && !( mxObj->getStatus( mpImp->nViewAspect ) & embed::EmbedMisc::EMBED_NEEDSSIZEONLOAD ) ) 575cdf0e10cSrcweir { 576cdf0e10cSrcweir // TODO/LATER: optimization, it makes no sence to do it for OLE objects 577cdf0e10cSrcweir if ( mxObj->getCurrentState() == embed::EmbedStates::LOADED ) 578cdf0e10cSrcweir mxObj->changeState( embed::EmbedStates::RUNNING ); 579cdf0e10cSrcweir 580cdf0e10cSrcweir // TODO: return for the aspect of the document 581cdf0e10cSrcweir embed::VisualRepresentation aVisualRepresentation; 582cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xTransferable( mxObj->getComponent(), uno::UNO_QUERY ); 583cdf0e10cSrcweir if ( !xTransferable.is() ) 584cdf0e10cSrcweir throw uno::RuntimeException(); 585cdf0e10cSrcweir 586cdf0e10cSrcweir datatransfer::DataFlavor aDataFlavor( 587cdf0e10cSrcweir ::rtl::OUString::createFromAscii( 588cdf0e10cSrcweir "application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), 589cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "GDIMetaFile" ), 590cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 591cdf0e10cSrcweir 592cdf0e10cSrcweir uno::Sequence < sal_Int8 > aSeq; 593cdf0e10cSrcweir if ( ( xTransferable->getTransferData( aDataFlavor ) >>= aSeq ) && aSeq.getLength() ) 594cdf0e10cSrcweir xInStream = new ::comphelper::SequenceInputStream( aSeq ); 595cdf0e10cSrcweir } 596cdf0e10cSrcweir } 597cdf0e10cSrcweir catch ( uno::Exception& ) 598cdf0e10cSrcweir { 599*2c35faf5SArmin Le Grand OSL_ENSURE( sal_False, "Something went wrong on getting the high contrast graphic!" ); 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir if ( xInStream.is() ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir SvStream* pStream = NULL; 605cdf0e10cSrcweir pStream = ::utl::UcbStreamHelper::CreateStream( xInStream ); 606cdf0e10cSrcweir if ( pStream ) 607cdf0e10cSrcweir { 608cdf0e10cSrcweir if ( !pStream->GetError() ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir GraphicFilter* pGF = GraphicFilter::GetGraphicFilter(); 611cdf0e10cSrcweir Graphic* pGraphic = new Graphic(); 612cdf0e10cSrcweir if ( pGF->ImportGraphic( *pGraphic, String(), *pStream, GRFILTER_FORMAT_DONTKNOW ) == 0 ) 613cdf0e10cSrcweir mpImp->pHCGraphic = pGraphic; 614cdf0e10cSrcweir else 615cdf0e10cSrcweir delete pGraphic; 616cdf0e10cSrcweir mpImp->mnGraphicVersion++; 617cdf0e10cSrcweir } 618cdf0e10cSrcweir 619cdf0e10cSrcweir delete pStream; 620cdf0e10cSrcweir } 621cdf0e10cSrcweir } 622cdf0e10cSrcweir } 623cdf0e10cSrcweir 624cdf0e10cSrcweir return mpImp->pHCGraphic; 625cdf0e10cSrcweir } 626cdf0e10cSrcweir 627cdf0e10cSrcweir void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream >& xInGrStream, 628cdf0e10cSrcweir const ::rtl::OUString& rMediaType ) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir if ( mpImp->pGraphic ) 631cdf0e10cSrcweir delete mpImp->pGraphic; 632cdf0e10cSrcweir mpImp->pGraphic = new Graphic(); 633cdf0e10cSrcweir mpImp->aMediaType = rMediaType; 634cdf0e10cSrcweir if ( mpImp->pHCGraphic ) 635cdf0e10cSrcweir DELETEZ( mpImp->pHCGraphic ); 636cdf0e10cSrcweir mpImp->mnGraphicVersion++; 637cdf0e10cSrcweir 638cdf0e10cSrcweir SvStream* pGraphicStream = ::utl::UcbStreamHelper::CreateStream( xInGrStream ); 639cdf0e10cSrcweir 640cdf0e10cSrcweir if ( pGraphicStream ) 641cdf0e10cSrcweir { 642cdf0e10cSrcweir GraphicFilter* pGF = GraphicFilter::GetGraphicFilter(); 643cdf0e10cSrcweir pGF->ImportGraphic( *mpImp->pGraphic, String(), *pGraphicStream, GRFILTER_FORMAT_DONTKNOW ); 644cdf0e10cSrcweir mpImp->mnGraphicVersion++; 645cdf0e10cSrcweir 646cdf0e10cSrcweir if ( mpImp->pContainer ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir pGraphicStream->Seek( 0 ); 649cdf0e10cSrcweir uno::Reference< io::XInputStream > xInSeekGrStream = new ::utl::OSeekableInputStreamWrapper( pGraphicStream ); 650cdf0e10cSrcweir 651cdf0e10cSrcweir mpImp->pContainer->InsertGraphicStream( xInSeekGrStream, mpImp->aPersistName, rMediaType ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir delete pGraphicStream; 655cdf0e10cSrcweir } 656cdf0e10cSrcweir 657cdf0e10cSrcweir mpImp->bNeedUpdate = sal_False; 658cdf0e10cSrcweir 659cdf0e10cSrcweir } 660cdf0e10cSrcweir 661cdf0e10cSrcweir void EmbeddedObjectRef::SetGraphic( const Graphic& rGraphic, const ::rtl::OUString& rMediaType ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir if ( mpImp->pGraphic ) 664cdf0e10cSrcweir delete mpImp->pGraphic; 665cdf0e10cSrcweir mpImp->pGraphic = new Graphic( rGraphic ); 666cdf0e10cSrcweir mpImp->aMediaType = rMediaType; 667cdf0e10cSrcweir if ( mpImp->pHCGraphic ) 668cdf0e10cSrcweir DELETEZ( mpImp->pHCGraphic ); 669cdf0e10cSrcweir mpImp->mnGraphicVersion++; 670cdf0e10cSrcweir 671cdf0e10cSrcweir if ( mpImp->pContainer ) 672cdf0e10cSrcweir SetGraphicToContainer( rGraphic, *mpImp->pContainer, mpImp->aPersistName, rMediaType ); 673cdf0e10cSrcweir 674cdf0e10cSrcweir mpImp->bNeedUpdate = sal_False; 675cdf0e10cSrcweir } 676cdf0e10cSrcweir 677cdf0e10cSrcweir SvStream* EmbeddedObjectRef::GetGraphicStream( sal_Bool bUpdate ) const 678cdf0e10cSrcweir { 679cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "svtools (mv76033) svt::EmbeddedObjectRef::GetGraphicStream" ); 680cdf0e10cSrcweir DBG_ASSERT( bUpdate || mpImp->pContainer, "Can't retrieve current graphic!" ); 681cdf0e10cSrcweir uno::Reference < io::XInputStream > xStream; 682cdf0e10cSrcweir if ( mpImp->pContainer && !bUpdate ) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE( aLog, "getting stream from container" ); 685cdf0e10cSrcweir // try to get graphic stream from container storage 686cdf0e10cSrcweir xStream = mpImp->pContainer->GetGraphicStream( mxObj, &mpImp->aMediaType ); 687cdf0e10cSrcweir if ( xStream.is() ) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir const sal_Int32 nConstBufferSize = 32000; 690cdf0e10cSrcweir SvStream *pStream = new SvMemoryStream( 32000, 32000 ); 691cdf0e10cSrcweir sal_Int32 nRead=0; 692cdf0e10cSrcweir uno::Sequence < sal_Int8 > aSequence ( nConstBufferSize ); 693cdf0e10cSrcweir do 694cdf0e10cSrcweir { 695cdf0e10cSrcweir nRead = xStream->readBytes ( aSequence, nConstBufferSize ); 696cdf0e10cSrcweir pStream->Write( aSequence.getConstArray(), nRead ); 697cdf0e10cSrcweir } 698cdf0e10cSrcweir while ( nRead == nConstBufferSize ); 699cdf0e10cSrcweir pStream->Seek(0); 700cdf0e10cSrcweir return pStream; 701cdf0e10cSrcweir } 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir if ( !xStream.is() ) 705cdf0e10cSrcweir { 706cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_TRACE( aLog, "getting stream from object" ); 707cdf0e10cSrcweir // update wanted or no stream in container storage available 708cdf0e10cSrcweir xStream = GetGraphicReplacementStream( mpImp->nViewAspect, mxObj, &mpImp->aMediaType ); 709cdf0e10cSrcweir 710cdf0e10cSrcweir if ( xStream.is() ) 711cdf0e10cSrcweir { 712cdf0e10cSrcweir if ( mpImp->pContainer ) 713cdf0e10cSrcweir mpImp->pContainer->InsertGraphicStream( xStream, mpImp->aPersistName, mpImp->aMediaType ); 714cdf0e10cSrcweir 715cdf0e10cSrcweir SvStream* pResult = ::utl::UcbStreamHelper::CreateStream( xStream ); 716cdf0e10cSrcweir if ( pResult && bUpdate ) 717cdf0e10cSrcweir mpImp->bNeedUpdate = sal_False; 718cdf0e10cSrcweir 719cdf0e10cSrcweir return pResult; 720cdf0e10cSrcweir } 721cdf0e10cSrcweir } 722cdf0e10cSrcweir 723cdf0e10cSrcweir return NULL; 724cdf0e10cSrcweir } 725cdf0e10cSrcweir 726cdf0e10cSrcweir void EmbeddedObjectRef::DrawPaintReplacement( const Rectangle &rRect, const String &rText, OutputDevice *pOut ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir MapMode aMM( MAP_APPFONT ); 729cdf0e10cSrcweir Size aAppFontSz = pOut->LogicToLogic( Size( 0, 8 ), &aMM, NULL ); 730cdf0e10cSrcweir Font aFnt( String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Helvetica" ) ), aAppFontSz ); 731cdf0e10cSrcweir aFnt.SetTransparent( sal_True ); 732cdf0e10cSrcweir aFnt.SetColor( Color( COL_LIGHTRED ) ); 733cdf0e10cSrcweir aFnt.SetWeight( WEIGHT_BOLD ); 734cdf0e10cSrcweir aFnt.SetFamily( FAMILY_SWISS ); 735cdf0e10cSrcweir 736cdf0e10cSrcweir pOut->Push(); 737cdf0e10cSrcweir pOut->SetBackground(); 738cdf0e10cSrcweir pOut->SetFont( aFnt ); 739cdf0e10cSrcweir 740cdf0e10cSrcweir Point aPt; 741cdf0e10cSrcweir // Nun den Text so skalieren, dass er in das Rect passt. 742cdf0e10cSrcweir // Wir fangen mit der Defaultsize an und gehen 1-AppFont runter 743cdf0e10cSrcweir for( sal_uInt16 i = 8; i > 2; i-- ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir aPt.X() = (rRect.GetWidth() - pOut->GetTextWidth( rText )) / 2; 746cdf0e10cSrcweir aPt.Y() = (rRect.GetHeight() - pOut->GetTextHeight()) / 2; 747cdf0e10cSrcweir 748cdf0e10cSrcweir sal_Bool bTiny = sal_False; 749cdf0e10cSrcweir if( aPt.X() < 0 ) bTiny = sal_True, aPt.X() = 0; 750cdf0e10cSrcweir if( aPt.Y() < 0 ) bTiny = sal_True, aPt.Y() = 0; 751cdf0e10cSrcweir if( bTiny ) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir // heruntergehen bei kleinen Bildern 754cdf0e10cSrcweir aFnt.SetSize( Size( 0, aAppFontSz.Height() * i / 8 ) ); 755cdf0e10cSrcweir pOut->SetFont( aFnt ); 756cdf0e10cSrcweir } 757cdf0e10cSrcweir else 758cdf0e10cSrcweir break; 759cdf0e10cSrcweir } 760cdf0e10cSrcweir 761cdf0e10cSrcweir Bitmap aBmp( SvtResId( BMP_PLUGIN ) ); 762cdf0e10cSrcweir long nHeight = rRect.GetHeight() - pOut->GetTextHeight(); 763cdf0e10cSrcweir long nWidth = rRect.GetWidth(); 764cdf0e10cSrcweir if( nHeight > 0 ) 765cdf0e10cSrcweir { 766cdf0e10cSrcweir aPt.Y() = nHeight; 767cdf0e10cSrcweir Point aP = rRect.TopLeft(); 768cdf0e10cSrcweir Size aBmpSize = aBmp.GetSizePixel(); 769cdf0e10cSrcweir // Bitmap einpassen 770cdf0e10cSrcweir if( nHeight * 10 / nWidth 771cdf0e10cSrcweir > aBmpSize.Height() * 10 / aBmpSize.Width() ) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir // nach der Breite ausrichten 774cdf0e10cSrcweir // Proportion beibehalten 775cdf0e10cSrcweir long nH = nWidth * aBmpSize.Height() / aBmpSize.Width(); 776cdf0e10cSrcweir // zentrieren 777cdf0e10cSrcweir aP.Y() += (nHeight - nH) / 2; 778cdf0e10cSrcweir nHeight = nH; 779cdf0e10cSrcweir } 780cdf0e10cSrcweir else 781cdf0e10cSrcweir { 782cdf0e10cSrcweir // nach der H"ohe ausrichten 783cdf0e10cSrcweir // Proportion beibehalten 784cdf0e10cSrcweir long nW = nHeight * aBmpSize.Width() / aBmpSize.Height(); 785cdf0e10cSrcweir // zentrieren 786cdf0e10cSrcweir aP.X() += (nWidth - nW) / 2; 787cdf0e10cSrcweir nWidth = nW; 788cdf0e10cSrcweir } 789cdf0e10cSrcweir 790cdf0e10cSrcweir pOut->DrawBitmap( aP, Size( nWidth, nHeight ), aBmp ); 791cdf0e10cSrcweir } 792cdf0e10cSrcweir 793cdf0e10cSrcweir pOut->IntersectClipRegion( rRect ); 794cdf0e10cSrcweir aPt += rRect.TopLeft(); 795cdf0e10cSrcweir pOut->DrawText( aPt, rText ); 796cdf0e10cSrcweir pOut->Pop(); 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799cdf0e10cSrcweir void EmbeddedObjectRef::DrawShading( const Rectangle &rRect, OutputDevice *pOut ) 800cdf0e10cSrcweir { 801cdf0e10cSrcweir GDIMetaFile * pMtf = pOut->GetConnectMetaFile(); 802cdf0e10cSrcweir if( pMtf && pMtf->IsRecord() ) 803cdf0e10cSrcweir return; 804cdf0e10cSrcweir 805cdf0e10cSrcweir pOut->Push(); 806cdf0e10cSrcweir pOut->SetLineColor( Color( COL_BLACK ) ); 807cdf0e10cSrcweir 808cdf0e10cSrcweir Size aPixSize = pOut->LogicToPixel( rRect.GetSize() ); 809cdf0e10cSrcweir aPixSize.Width() -= 1; 810cdf0e10cSrcweir aPixSize.Height() -= 1; 811cdf0e10cSrcweir Point aPixViewPos = pOut->LogicToPixel( rRect.TopLeft() ); 812cdf0e10cSrcweir sal_Int32 nMax = aPixSize.Width() + aPixSize.Height(); 813cdf0e10cSrcweir for( sal_Int32 i = 5; i < nMax; i += 5 ) 814cdf0e10cSrcweir { 815cdf0e10cSrcweir Point a1( aPixViewPos ), a2( aPixViewPos ); 816cdf0e10cSrcweir if( i > aPixSize.Width() ) 817cdf0e10cSrcweir a1 += Point( aPixSize.Width(), i - aPixSize.Width() ); 818cdf0e10cSrcweir else 819cdf0e10cSrcweir a1 += Point( i, 0 ); 820cdf0e10cSrcweir if( i > aPixSize.Height() ) 821cdf0e10cSrcweir a2 += Point( i - aPixSize.Height(), aPixSize.Height() ); 822cdf0e10cSrcweir else 823cdf0e10cSrcweir a2 += Point( 0, i ); 824cdf0e10cSrcweir 825cdf0e10cSrcweir pOut->DrawLine( pOut->PixelToLogic( a1 ), pOut->PixelToLogic( a2 ) ); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir 828cdf0e10cSrcweir pOut->Pop(); 829cdf0e10cSrcweir 830cdf0e10cSrcweir } 831cdf0e10cSrcweir 832cdf0e10cSrcweir sal_Bool EmbeddedObjectRef::TryRunningState() 833cdf0e10cSrcweir { 834cdf0e10cSrcweir return TryRunningState( mxObj ); 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir sal_Bool EmbeddedObjectRef::TryRunningState( const uno::Reference < embed::XEmbeddedObject >& xEmbObj ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir if ( !xEmbObj.is() ) 840cdf0e10cSrcweir return sal_False; 841cdf0e10cSrcweir 842cdf0e10cSrcweir try 843cdf0e10cSrcweir { 844cdf0e10cSrcweir if ( xEmbObj->getCurrentState() == embed::EmbedStates::LOADED ) 845cdf0e10cSrcweir xEmbObj->changeState( embed::EmbedStates::RUNNING ); 846cdf0e10cSrcweir } 847cdf0e10cSrcweir catch ( uno::Exception& ) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir return sal_False; 850cdf0e10cSrcweir } 851cdf0e10cSrcweir 852cdf0e10cSrcweir return sal_True; 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir void EmbeddedObjectRef::SetGraphicToContainer( const Graphic& rGraphic, 856cdf0e10cSrcweir comphelper::EmbeddedObjectContainer& aContainer, 857cdf0e10cSrcweir const ::rtl::OUString& aName, 858cdf0e10cSrcweir const ::rtl::OUString& aMediaType ) 859cdf0e10cSrcweir { 860cdf0e10cSrcweir SvMemoryStream aStream; 861cdf0e10cSrcweir aStream.SetVersion( SOFFICE_FILEFORMAT_CURRENT ); 862cdf0e10cSrcweir if ( rGraphic.ExportNative( aStream ) ) 863cdf0e10cSrcweir { 864cdf0e10cSrcweir aStream.Seek( 0 ); 865cdf0e10cSrcweir 866cdf0e10cSrcweir uno::Reference < io::XInputStream > xStream = new ::utl::OSeekableInputStreamWrapper( aStream ); 867cdf0e10cSrcweir aContainer.InsertGraphicStream( xStream, aName, aMediaType ); 868cdf0e10cSrcweir } 869cdf0e10cSrcweir else 870cdf0e10cSrcweir OSL_ENSURE( sal_False, "Export of graphic is failed!\n" ); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir sal_Bool EmbeddedObjectRef::ObjectIsModified( const uno::Reference< embed::XEmbeddedObject >& xObj ) 874cdf0e10cSrcweir throw( uno::Exception ) 875cdf0e10cSrcweir { 876cdf0e10cSrcweir sal_Bool bResult = sal_False; 877cdf0e10cSrcweir 878cdf0e10cSrcweir sal_Int32 nState = xObj->getCurrentState(); 879cdf0e10cSrcweir if ( nState != embed::EmbedStates::LOADED && nState != embed::EmbedStates::RUNNING ) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir // the object is active so if the model is modified the replacement 882cdf0e10cSrcweir // should be retrieved from the object 883cdf0e10cSrcweir uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY ); 884cdf0e10cSrcweir if ( xModifiable.is() ) 885cdf0e10cSrcweir bResult = xModifiable->isModified(); 886cdf0e10cSrcweir } 887cdf0e10cSrcweir 888cdf0e10cSrcweir return bResult; 889cdf0e10cSrcweir } 890cdf0e10cSrcweir 891cdf0e10cSrcweir uno::Reference< io::XInputStream > EmbeddedObjectRef::GetGraphicReplacementStream( 892cdf0e10cSrcweir sal_Int64 nViewAspect, 893cdf0e10cSrcweir const uno::Reference< embed::XEmbeddedObject >& xObj, 894cdf0e10cSrcweir ::rtl::OUString* pMediaType ) 895cdf0e10cSrcweir throw() 896cdf0e10cSrcweir { 897cdf0e10cSrcweir return ::comphelper::EmbeddedObjectContainer::GetGraphicReplacementStream(nViewAspect,xObj,pMediaType); 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir void EmbeddedObjectRef::UpdateReplacementOnDemand() 901cdf0e10cSrcweir { 902cdf0e10cSrcweir DELETEZ( mpImp->pGraphic ); 903cdf0e10cSrcweir mpImp->bNeedUpdate = sal_True; 904cdf0e10cSrcweir if ( mpImp->pHCGraphic ) 905cdf0e10cSrcweir DELETEZ( mpImp->pHCGraphic ); 906cdf0e10cSrcweir mpImp->mnGraphicVersion++; 907cdf0e10cSrcweir 908cdf0e10cSrcweir if( mpImp->pContainer ) 909cdf0e10cSrcweir { 910cdf0e10cSrcweir //remove graphic from container thus a new up to date one is requested on save 911cdf0e10cSrcweir mpImp->pContainer->RemoveGraphicStream( mpImp->aPersistName ); 912cdf0e10cSrcweir } 913cdf0e10cSrcweir } 914cdf0e10cSrcweir 915cdf0e10cSrcweir sal_Bool EmbeddedObjectRef::IsChart() const 916cdf0e10cSrcweir { 917cdf0e10cSrcweir //todo maybe for 3.0: 918cdf0e10cSrcweir //if the changes work good for chart 919cdf0e10cSrcweir //we should apply them for all own ole objects 920cdf0e10cSrcweir 921cdf0e10cSrcweir //#i83708# #i81857# #i79578# request an ole replacement image only if really necessary 922cdf0e10cSrcweir //as this call can be very expensive and does block the user interface as long at it takes 923cdf0e10cSrcweir 924cdf0e10cSrcweir if ( !mxObj.is() ) 925cdf0e10cSrcweir return false; 926cdf0e10cSrcweir 927cdf0e10cSrcweir SvGlobalName aObjClsId( mxObj->getClassID() ); 928cdf0e10cSrcweir if( 929cdf0e10cSrcweir SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId 930cdf0e10cSrcweir || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId 931cdf0e10cSrcweir || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId 932cdf0e10cSrcweir || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId) 933cdf0e10cSrcweir { 934cdf0e10cSrcweir return sal_True; 935cdf0e10cSrcweir } 936cdf0e10cSrcweir 937cdf0e10cSrcweir return sal_False; 938cdf0e10cSrcweir } 939cdf0e10cSrcweir 940cdf0e10cSrcweir // #i104867# 941cdf0e10cSrcweir sal_uInt32 EmbeddedObjectRef::getGraphicVersion() const 942cdf0e10cSrcweir { 943cdf0e10cSrcweir return mpImp->mnGraphicVersion; 944cdf0e10cSrcweir } 945cdf0e10cSrcweir 946cdf0e10cSrcweir void EmbeddedObjectRef::SetDefaultSizeForChart( const Size& rSizeIn_100TH_MM ) 947cdf0e10cSrcweir { 948cdf0e10cSrcweir //#i103460# charts do not necessaryly have an own size within ODF files, 949cdf0e10cSrcweir //for this case they need to use the size settings from the surrounding frame, 950cdf0e10cSrcweir //which is made available with this method 951cdf0e10cSrcweir 952cdf0e10cSrcweir mpImp->aDefaultSizeForChart_In_100TH_MM = awt::Size( rSizeIn_100TH_MM.getWidth(), rSizeIn_100TH_MM.getHeight() ); 953cdf0e10cSrcweir 954cdf0e10cSrcweir ::com::sun::star::uno::Reference < ::com::sun::star::chart2::XDefaultSizeTransmitter > xSizeTransmitter( mxObj, uno::UNO_QUERY ); 955cdf0e10cSrcweir DBG_ASSERT( xSizeTransmitter.is(), "Object does not support XDefaultSizeTransmitter -> will cause #i103460#!" ); 956cdf0e10cSrcweir if( xSizeTransmitter.is() ) 957cdf0e10cSrcweir xSizeTransmitter->setDefaultSize( mpImp->aDefaultSizeForChart_In_100TH_MM ); 958cdf0e10cSrcweir } 959cdf0e10cSrcweir 960cdf0e10cSrcweir } // namespace svt 961cdf0e10cSrcweir 962