1*bfd08df8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bfd08df8SAndrew Rist * distributed with this work for additional information 6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance 9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an 15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the 17*bfd08df8SAndrew Rist * specific language governing permissions and limitations 18*bfd08df8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*bfd08df8SAndrew Rist *************************************************************/ 21*bfd08df8SAndrew Rist 22*bfd08df8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 26cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 27cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 28cdf0e10cSrcweir #include <com/sun/star/datatransfer/XTransferable.hpp> 29cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 30cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <rtl/logfile.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <commonembobj.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweir using namespace ::com::sun::star; 39cdf0e10cSrcweir 40cdf0e10cSrcweir void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize ) 41cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 42cdf0e10cSrcweir embed::WrongStateException, 43cdf0e10cSrcweir uno::Exception, 44cdf0e10cSrcweir uno::RuntimeException ) 45cdf0e10cSrcweir { 46cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" ); 47cdf0e10cSrcweir 48cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 49cdf0e10cSrcweir if ( m_bDisposed ) 50cdf0e10cSrcweir throw lang::DisposedException(); // TODO 51cdf0e10cSrcweir 52cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 53cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 54cdf0e10cSrcweir // no representation can be retrieved 55cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 56cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 57cdf0e10cSrcweir 58cdf0e10cSrcweir if ( m_nObjectState == -1 ) 59cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ), 60cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 61cdf0e10cSrcweir 62cdf0e10cSrcweir m_bHasClonedSize = sal_False; 63cdf0e10cSrcweir 64cdf0e10cSrcweir sal_Bool bBackToLoaded = sal_False; 65cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir // the links should be switched back to loaded state for now to avoid locking problems 70cdf0e10cSrcweir bBackToLoaded = m_bIsLink; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir if ( bBackToLoaded ) 76cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir if ( !bSuccess ) 79cdf0e10cSrcweir throw uno::Exception(); // TODO: 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect ) 83cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 84cdf0e10cSrcweir embed::WrongStateException, 85cdf0e10cSrcweir uno::Exception, 86cdf0e10cSrcweir uno::RuntimeException ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" ); 89cdf0e10cSrcweir 90cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 91cdf0e10cSrcweir if ( m_bDisposed ) 92cdf0e10cSrcweir throw lang::DisposedException(); // TODO 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( m_nObjectState == -1 ) 95cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ), 96cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 99cdf0e10cSrcweir 100cdf0e10cSrcweir if ( m_bHasClonedSize ) 101cdf0e10cSrcweir return m_aClonedSize; 102cdf0e10cSrcweir 103cdf0e10cSrcweir sal_Bool bBackToLoaded = sal_False; 104cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir // the links should be switched back to loaded state for now to avoid locking problems 109cdf0e10cSrcweir bBackToLoaded = m_bIsLink; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir awt::Size aResult; 113cdf0e10cSrcweir sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir if ( bBackToLoaded ) 116cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 117cdf0e10cSrcweir 118cdf0e10cSrcweir if ( !bSuccess ) 119cdf0e10cSrcweir throw uno::Exception(); // TODO: 120cdf0e10cSrcweir 121cdf0e10cSrcweir return aResult; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect ) 125cdf0e10cSrcweir throw ( uno::Exception, 126cdf0e10cSrcweir uno::RuntimeException) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 129cdf0e10cSrcweir if ( m_bDisposed ) 130cdf0e10cSrcweir throw lang::DisposedException(); // TODO 131cdf0e10cSrcweir 132cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 133cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 134cdf0e10cSrcweir // no representation can be retrieved 135cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 136cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir if ( m_nObjectState == -1 ) 139cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ), 140cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 141cdf0e10cSrcweir 142cdf0e10cSrcweir if ( m_bHasClonedSize ) 143cdf0e10cSrcweir return m_nClonedMapUnit; 144cdf0e10cSrcweir 145cdf0e10cSrcweir sal_Bool bBackToLoaded = sal_False; 146cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // the links should be switched back to loaded state for now to avoid locking problems 151cdf0e10cSrcweir bBackToLoaded = m_bIsLink; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir if ( bBackToLoaded ) 157cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir if ( nResult < 0 ) 160cdf0e10cSrcweir throw uno::Exception(); // TODO: 161cdf0e10cSrcweir 162cdf0e10cSrcweir return nResult; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect ) 166cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 167cdf0e10cSrcweir embed::WrongStateException, 168cdf0e10cSrcweir uno::Exception, 169cdf0e10cSrcweir uno::RuntimeException ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 174cdf0e10cSrcweir if ( m_bDisposed ) 175cdf0e10cSrcweir throw lang::DisposedException(); // TODO 176cdf0e10cSrcweir 177cdf0e10cSrcweir if ( m_nObjectState == -1 ) 178cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The own object has no persistence!\n" ), 179cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir 182cdf0e10cSrcweir OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" ); 183cdf0e10cSrcweir if ( nAspect == embed::Aspects::MSOLE_ICON ) 184cdf0e10cSrcweir // no representation can be retrieved 185cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Illegal call!\n" ), 186cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 187cdf0e10cSrcweir 188cdf0e10cSrcweir sal_Bool bBackToLoaded = sal_False; 189cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir changeState( embed::EmbedStates::RUNNING ); 192cdf0e10cSrcweir 193cdf0e10cSrcweir // the links should be switched back to loaded state for now to avoid locking problems 194cdf0e10cSrcweir bBackToLoaded = m_bIsLink; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir // TODO: return for the aspect of the document 200cdf0e10cSrcweir embed::VisualRepresentation aVisualRepresentation; 201cdf0e10cSrcweir 202cdf0e10cSrcweir uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 203cdf0e10cSrcweir if( xVisualObject.is()) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect ); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir else 208cdf0e10cSrcweir { 209cdf0e10cSrcweir uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY ); 210cdf0e10cSrcweir if (!xTransferable.is() ) 211cdf0e10cSrcweir throw uno::RuntimeException(); 212cdf0e10cSrcweir 213cdf0e10cSrcweir datatransfer::DataFlavor aDataFlavor( 214cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), 215cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "GDIMetaFile" ), 216cdf0e10cSrcweir ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir if( xTransferable->isDataFlavorSupported( aDataFlavor )) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor ); 221cdf0e10cSrcweir aVisualRepresentation.Flavor = aDataFlavor; 222cdf0e10cSrcweir } 223cdf0e10cSrcweir else 224cdf0e10cSrcweir throw uno::RuntimeException(); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir if ( bBackToLoaded ) 228cdf0e10cSrcweir changeState( embed::EmbedStates::LOADED ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir return aVisualRepresentation; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233