1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMapUnits.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <rtl/logfile.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <oleembobj.hxx> 41*cdf0e10cSrcweir #include <olecomponent.hxx> 42*cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx> 43*cdf0e10cSrcweir #include <comphelper/seqstream.hxx> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::com::sun::star; 46*cdf0e10cSrcweir using namespace ::comphelper; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir embed::VisualRepresentation OleEmbeddedObject::GetVisualRepresentationInNativeFormat_Impl( 49*cdf0e10cSrcweir const uno::Reference< io::XStream > xCachedVisRepr ) 50*cdf0e10cSrcweir throw ( uno::Exception ) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir embed::VisualRepresentation aVisualRepr; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // TODO: detect the format in the future for now use workaround 55*cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = xCachedVisRepr->getInputStream(); 56*cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeekable( xCachedVisRepr, uno::UNO_QUERY ); 57*cdf0e10cSrcweir if ( !xInStream.is() || !xSeekable.is() ) 58*cdf0e10cSrcweir throw uno::RuntimeException(); 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aSeq( 2 ); 61*cdf0e10cSrcweir xInStream->readBytes( aSeq, 2 ); 62*cdf0e10cSrcweir xSeekable->seek( 0 ); 63*cdf0e10cSrcweir if ( aSeq.getLength() == 2 && aSeq[0] == 'B' && aSeq[1] == 'M' ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir // it's a bitmap 66*cdf0e10cSrcweir aVisualRepr.Flavor = datatransfer::DataFlavor( 67*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ), 68*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Bitmap" ), 69*cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir else 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir // it's a metafile 74*cdf0e10cSrcweir aVisualRepr.Flavor = datatransfer::DataFlavor( 75*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ), 76*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Windows Metafile" ), 77*cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir sal_Int32 nStreamLength = (sal_Int32)xSeekable->getLength(); 81*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aRepresent( nStreamLength ); 82*cdf0e10cSrcweir xInStream->readBytes( aRepresent, nStreamLength ); 83*cdf0e10cSrcweir aVisualRepr.Data <<= aRepresent; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir return aVisualRepr; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) 89*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 90*cdf0e10cSrcweir embed::WrongStateException, 91*cdf0e10cSrcweir uno::Exception, 92*cdf0e10cSrcweir uno::RuntimeException ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::setVisualAreaSize" ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // begin wrapping related part ==================== 97*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 98*cdf0e10cSrcweir if ( xWrappedObject.is() ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 101*cdf0e10cSrcweir xWrappedObject->setVisualAreaSize( nAspect, aSize ); 102*cdf0e10cSrcweir return; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir // end wrapping related part ==================== 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 107*cdf0e10cSrcweir if ( m_bDisposed ) 108*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 111*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 112*cdf0e10cSrcweir // no representation can be retrieved 113*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 114*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 117*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ), 118*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir #ifdef WNT 121*cdf0e10cSrcweir // RECOMPOSE_ON_RESIZE misc flag means that the object has to be switched to running state on resize. 122*cdf0e10cSrcweir // SetExtent() is called only for objects that require it, 123*cdf0e10cSrcweir // it should not be called for MSWord documents to workaround problem i49369 124*cdf0e10cSrcweir // If cached size is not set, that means that this is the size initialization, so there is no need to set the real size 125*cdf0e10cSrcweir sal_Bool bAllowToSetExtent = 126*cdf0e10cSrcweir ( ( getStatus( nAspect ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) 127*cdf0e10cSrcweir && !MimeConfigurationHelper::ClassIDsEqual( m_aClassID, MimeConfigurationHelper::GetSequenceClassID( 0x00020906L, 0x0000, 0x0000, 128*cdf0e10cSrcweir 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 ) ) 129*cdf0e10cSrcweir && m_bHasCachedSize ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED && bAllowToSetExtent ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir aGuard.clear(); 134*cdf0e10cSrcweir try { 135*cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir catch( uno::Exception& ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir OSL_ENSURE( sal_False, "The object should not be resized without activation!\n" ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir aGuard.reset(); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if ( m_pOleComponent && m_nObjectState != embed::EmbedStates::LOADED && bAllowToSetExtent ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir awt::Size aSizeToSet = aSize; 147*cdf0e10cSrcweir aGuard.clear(); 148*cdf0e10cSrcweir try { 149*cdf0e10cSrcweir m_pOleComponent->SetExtent( aSizeToSet, nAspect ); // will throw an exception in case of failure 150*cdf0e10cSrcweir m_bHasSizeToSet = sal_False; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir catch( uno::Exception& ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir // some objects do not allow to set the size even in running state 155*cdf0e10cSrcweir m_bHasSizeToSet = sal_True; 156*cdf0e10cSrcweir m_aSizeToSet = aSizeToSet; 157*cdf0e10cSrcweir m_nAspectToSet = nAspect; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir aGuard.reset(); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir #endif 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir // cache the values 164*cdf0e10cSrcweir m_bHasCachedSize = sal_True; 165*cdf0e10cSrcweir m_aCachedSize = aSize; 166*cdf0e10cSrcweir m_nCachedAspect = nAspect; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir awt::Size SAL_CALL OleEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect ) 170*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 171*cdf0e10cSrcweir embed::WrongStateException, 172*cdf0e10cSrcweir uno::Exception, 173*cdf0e10cSrcweir uno::RuntimeException ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getVisualAreaSize" ); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // begin wrapping related part ==================== 178*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 179*cdf0e10cSrcweir if ( xWrappedObject.is() ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 182*cdf0e10cSrcweir return xWrappedObject->getVisualAreaSize( nAspect ); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir // end wrapping related part ==================== 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 187*cdf0e10cSrcweir if ( m_bDisposed ) 188*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 191*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 192*cdf0e10cSrcweir // no representation can be retrieved 193*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 194*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 197*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ), 198*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir awt::Size aResult; 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir #ifdef WNT 203*cdf0e10cSrcweir // TODO/LATER: Support different aspects 204*cdf0e10cSrcweir if ( m_pOleComponent && !m_bHasSizeToSet && nAspect == embed::Aspects::MSOLE_CONTENT ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir try 207*cdf0e10cSrcweir { 208*cdf0e10cSrcweir // the cached size updated every time the object is stored 209*cdf0e10cSrcweir if ( m_bHasCachedSize ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir aResult = m_aCachedSize; 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir else 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir // there is no internal cache 216*cdf0e10cSrcweir awt::Size aSize; 217*cdf0e10cSrcweir aGuard.clear(); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir sal_Bool bSuccess = sal_False; 220*cdf0e10cSrcweir if ( getCurrentState() == embed::EmbedStates::LOADED ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Loaded object has no cached size!\n" ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // try to switch the object to RUNNING state and request the value again 225*cdf0e10cSrcweir try { 226*cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir catch( uno::Exception ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir throw embed::NoVisualAreaSizeException( 231*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ), 232*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir try 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir // first try to get size using replacement image 239*cdf0e10cSrcweir aSize = m_pOleComponent->GetExtent( nAspect ); // will throw an exception in case of failure 240*cdf0e10cSrcweir bSuccess = sal_True; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir catch( uno::Exception& ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir if ( !bSuccess ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir try 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // second try the cached replacement image 251*cdf0e10cSrcweir aSize = m_pOleComponent->GetCachedExtent( nAspect ); // will throw an exception in case of failure 252*cdf0e10cSrcweir bSuccess = sal_True; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir catch( uno::Exception& ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if ( !bSuccess ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir try 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir // third try the size reported by the object 264*cdf0e10cSrcweir aSize = m_pOleComponent->GetReccomendedExtent( nAspect ); // will throw an exception in case of failure 265*cdf0e10cSrcweir bSuccess = sal_True; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir catch( uno::Exception& ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir if ( !bSuccess ) 273*cdf0e10cSrcweir throw embed::NoVisualAreaSizeException( 274*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ), 275*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir aGuard.reset(); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir m_aCachedSize = aSize; 280*cdf0e10cSrcweir m_nCachedAspect = nAspect; 281*cdf0e10cSrcweir m_bHasCachedSize = sal_True; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir aResult = m_aCachedSize; 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir catch ( embed::NoVisualAreaSizeException& ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir throw; 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir catch ( uno::Exception& ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir throw embed::NoVisualAreaSizeException( 293*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ), 294*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir else 298*cdf0e10cSrcweir #endif 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir // return cached value 301*cdf0e10cSrcweir if ( m_bHasCachedSize ) 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir OSL_ENSURE( nAspect == m_nCachedAspect, "Unexpected aspect is requested!\n" ); 304*cdf0e10cSrcweir aResult = m_aCachedSize; 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir else 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir throw embed::NoVisualAreaSizeException( 309*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No size available!\n" ) ), 310*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir return aResult; 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL OleEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect ) 318*cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 319*cdf0e10cSrcweir embed::WrongStateException, 320*cdf0e10cSrcweir uno::Exception, 321*cdf0e10cSrcweir uno::RuntimeException ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::getPreferredVisualRepresentation" ); 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir // begin wrapping related part ==================== 326*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 327*cdf0e10cSrcweir if ( xWrappedObject.is() ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 330*cdf0e10cSrcweir return xWrappedObject->getPreferredVisualRepresentation( nAspect ); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir // end wrapping related part ==================== 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 335*cdf0e10cSrcweir if ( m_bDisposed ) 336*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 339*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 340*cdf0e10cSrcweir // no representation can be retrieved 341*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 342*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir // TODO: if the object has cached representation then it should be returned 345*cdf0e10cSrcweir // TODO: if the object has no cached representation and is in loaded state it should switch itself to the running state 346*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 347*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ), 348*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir embed::VisualRepresentation aVisualRepr; 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // TODO: in case of different aspects they must be applied to the mediatype and XTransferable must be used 353*cdf0e10cSrcweir // the cache is used only as a fallback if object is not in loaded state 354*cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() && ( !m_bVisReplInitialized || m_bVisReplInStream ) 355*cdf0e10cSrcweir && m_nObjectState == embed::EmbedStates::LOADED ) 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream, sal_True ); 358*cdf0e10cSrcweir SetVisReplInStream( m_xCachedVisualRepresentation.is() ); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir if ( m_xCachedVisualRepresentation.is() ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir return GetVisualRepresentationInNativeFormat_Impl( m_xCachedVisualRepresentation ); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir #ifdef WNT 366*cdf0e10cSrcweir else if ( m_pOleComponent ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir try 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 371*cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir datatransfer::DataFlavor aDataFlavor( 374*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ), 375*cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Windows Metafile" ), 376*cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir aVisualRepr.Data = m_pOleComponent->getTransferData( aDataFlavor ); 379*cdf0e10cSrcweir aVisualRepr.Flavor = aDataFlavor; 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir uno::Sequence< sal_Int8 > aVisReplSeq; 382*cdf0e10cSrcweir aVisualRepr.Data >>= aVisReplSeq; 383*cdf0e10cSrcweir if ( aVisReplSeq.getLength() ) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir m_xCachedVisualRepresentation = GetNewFilledTempStream_Impl( 386*cdf0e10cSrcweir uno::Reference< io::XInputStream > ( static_cast< io::XInputStream* > ( 387*cdf0e10cSrcweir new ::comphelper::SequenceInputStream( aVisReplSeq ) ) ) ); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir return aVisualRepr; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir catch( uno::Exception& ) 393*cdf0e10cSrcweir {} 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir #endif 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir // the cache is used only as a fallback if object is not in loaded state 398*cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() && ( !m_bVisReplInitialized || m_bVisReplInStream ) ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream ); 401*cdf0e10cSrcweir SetVisReplInStream( m_xCachedVisualRepresentation.is() ); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() ) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir // no representation can be retrieved 407*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 408*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir return GetVisualRepresentationInNativeFormat_Impl( m_xCachedVisualRepresentation ); 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir sal_Int32 SAL_CALL OleEmbeddedObject::getMapUnit( sal_Int64 nAspect ) 415*cdf0e10cSrcweir throw ( uno::Exception, 416*cdf0e10cSrcweir uno::RuntimeException) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir // begin wrapping related part ==================== 419*cdf0e10cSrcweir uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject; 420*cdf0e10cSrcweir if ( xWrappedObject.is() ) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 423*cdf0e10cSrcweir return xWrappedObject->getMapUnit( nAspect ); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir // end wrapping related part ==================== 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 428*cdf0e10cSrcweir if ( m_bDisposed ) 429*cdf0e10cSrcweir throw lang::DisposedException(); // TODO 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 432*cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 433*cdf0e10cSrcweir // no representation can be retrieved 434*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 435*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir if ( m_nObjectState == -1 ) 438*cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object is not loaded!\n" ), 439*cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir return embed::EmbedMapUnits::ONE_100TH_MM; 442*cdf0e10cSrcweir } 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir 445