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