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/lang/IllegalArgumentException.hpp> 27 #include <com/sun/star/lang/DisposedException.hpp> 28 #include <com/sun/star/embed/WrongStateException.hpp> 29 #include <com/sun/star/embed/UnreachableStateException.hpp> 30 #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 31 #include <com/sun/star/beans/XPropertySet.hpp> 32 #include <com/sun/star/io/XTruncate.hpp> 33 #include <com/sun/star/awt/XRequestCallback.hpp> 34 35 #include <platform.h> 36 #include <cppuhelper/interfacecontainer.h> 37 #include <comphelper/mimeconfighelper.hxx> 38 #include <comphelper/storagehelper.hxx> 39 #include <osl/file.hxx> 40 #include <rtl/ref.hxx> 41 42 #include <olecomponent.hxx> 43 #include <olewrapclient.hxx> 44 #include <advisesink.hxx> 45 #include <oleembobj.hxx> 46 #include <mtnotification.hxx> 47 48 using namespace ::com::sun::star; 49 using namespace ::comphelper; 50 #define MAX_ENUM_ELE 20 51 #define FORMATS_NUM 3 52 53 // ============ class ComSmart ===================== 54 namespace { 55 56 template< class T > class ComSmart 57 { 58 T* m_pInterface; 59 60 void OwnRelease() 61 { 62 if ( m_pInterface ) 63 { 64 T* pInterface = m_pInterface; 65 m_pInterface = NULL; 66 pInterface->Release(); 67 } 68 } 69 70 public: 71 ComSmart() 72 : m_pInterface( NULL ) 73 {} 74 75 ComSmart( const ComSmart<T>& rObj ) 76 : m_pInterface( rObj.m_pInterface ) 77 { 78 if ( m_pInterface != NULL ) 79 m_pInterface->AddRef(); 80 } 81 82 ComSmart( T* pInterface ) 83 : m_pInterface( pInterface ) 84 { 85 if ( m_pInterface != NULL ) 86 m_pInterface->AddRef(); 87 } 88 89 ~ComSmart() 90 { 91 OwnRelease(); 92 } 93 94 ComSmart& operator=( const ComSmart<T>& rObj ) 95 { 96 OwnRelease(); 97 98 m_pInterface = rObj.m_pInterface; 99 100 if ( m_pInterface != NULL ) 101 m_pInterface->AddRef(); 102 103 return *this; 104 } 105 106 ComSmart<T>& operator=( T* pInterface ) 107 { 108 OwnRelease(); 109 110 m_pInterface = pInterface; 111 112 if ( m_pInterface != NULL ) 113 m_pInterface->AddRef(); 114 115 return *this; 116 } 117 118 operator T*() const 119 { 120 return m_pInterface; 121 } 122 123 T& operator*() const 124 { 125 return *m_pInterface; 126 } 127 128 T** operator&() 129 { 130 OwnRelease(); 131 132 m_pInterface = NULL; 133 134 return &m_pInterface; 135 } 136 137 T* operator->() const 138 { 139 return m_pInterface; 140 } 141 142 BOOL operator==( const ComSmart<T>& rObj ) const 143 { 144 return ( m_pInterface == rObj.m_pInterface ); 145 } 146 147 BOOL operator!=( const ComSmart<T>& rObj ) const 148 { 149 return ( m_pInterface != rObj.m_pInterface ); 150 } 151 152 BOOL operator==( const T* pInterface ) const 153 { 154 return ( m_pInterface == pInterface ); 155 } 156 157 BOOL operator!=( const T* pInterface ) const 158 { 159 return ( m_pInterface != pInterface ); 160 } 161 }; 162 163 } 164 165 // ============ class ComSmart ===================== 166 167 sal_Bool ConvertBufferToFormat( void* pBuf, 168 sal_uInt32 nBufSize, 169 const ::rtl::OUString& aFormatShortName, 170 uno::Any& aResult ); 171 172 ::rtl::OUString GetNewTempFileURL_Impl( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) throw( io::IOException ); 173 174 typedef ::std::vector< FORMATETC* > FormatEtcList; 175 176 FORMATETC pFormatTemplates[FORMATS_NUM] = { 177 { CF_ENHMETAFILE, NULL, 0, -1, TYMED_ENHMF }, 178 { CF_METAFILEPICT, NULL, 0, -1, TYMED_MFPICT }, 179 { CF_BITMAP, NULL, 0, -1, TYMED_GDI } }; 180 181 182 struct OleComponentNative_Impl { 183 ComSmart< IUnknown > m_pObj; 184 ComSmart< IOleObject > m_pOleObject; 185 ComSmart< IViewObject2 > m_pViewObject2; 186 ComSmart< IStorage > m_pIStorage; 187 FormatEtcList m_aFormatsList; 188 uno::Sequence< datatransfer::DataFlavor > m_aSupportedGraphFormats; 189 190 OleComponentNative_Impl() 191 { 192 // TODO: Extend format list 193 m_aSupportedGraphFormats.realloc( 5 ); 194 195 m_aSupportedGraphFormats[0] = datatransfer::DataFlavor( 196 ::rtl::OUString::createFromAscii( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"" ), 197 ::rtl::OUString::createFromAscii( "Windows Enhanced Metafile" ), 198 getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); 199 200 m_aSupportedGraphFormats[1] = datatransfer::DataFlavor( 201 ::rtl::OUString::createFromAscii( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"" ), 202 ::rtl::OUString::createFromAscii( "Windows Metafile" ), 203 getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); 204 205 m_aSupportedGraphFormats[2] = datatransfer::DataFlavor( 206 ::rtl::OUString::createFromAscii( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"" ), 207 ::rtl::OUString::createFromAscii( "Bitmap" ), 208 getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); 209 210 m_aSupportedGraphFormats[3] = datatransfer::DataFlavor( 211 ::rtl::OUString::createFromAscii( "image/png" ), 212 ::rtl::OUString::createFromAscii( "PNG" ), 213 getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); 214 215 m_aSupportedGraphFormats[0] = datatransfer::DataFlavor( 216 ::rtl::OUString::createFromAscii( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ), 217 ::rtl::OUString::createFromAscii( "GDIMetafile" ), 218 getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); 219 } 220 221 void AddSupportedFormat( const FORMATETC& aFormatEtc ); 222 223 FORMATETC* GetSupportedFormatForAspect( sal_uInt32 nRequestedAspect ); 224 225 sal_Bool ConvertDataForFlavor( const STGMEDIUM& aMedium, 226 const datatransfer::DataFlavor& aFlavor, 227 uno::Any& aResult ); 228 229 sal_Bool GraphicalFlavor( const datatransfer::DataFlavor& aFlavor ); 230 231 uno::Sequence< datatransfer::DataFlavor > GetFlavorsForAspects( sal_uInt32 nSupportedAspects ); 232 }; 233 234 //---------------------------------------------- 235 DWORD GetAspectFromFlavor( const datatransfer::DataFlavor& aFlavor ) 236 { 237 if ( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( ";Aspect=THUMBNAIL" ) ) != -1 ) 238 return DVASPECT_THUMBNAIL; 239 else if ( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( ";Aspect=ICON" ) ) != -1 ) 240 return DVASPECT_ICON; 241 else if ( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( ";Aspect=DOCPRINT" ) ) != -1 ) 242 return DVASPECT_DOCPRINT; 243 else 244 return DVASPECT_CONTENT; 245 } 246 247 //---------------------------------------------- 248 ::rtl::OUString GetFlavorSuffixFromAspect( DWORD nAsp ) 249 { 250 ::rtl::OUString aResult; 251 252 if ( nAsp == DVASPECT_THUMBNAIL ) 253 aResult = ::rtl::OUString::createFromAscii( ";Aspect=THUMBNAIL" ); 254 else if ( nAsp == DVASPECT_ICON ) 255 aResult = ::rtl::OUString::createFromAscii( ";Aspect=ICON" ); 256 else if ( nAsp == DVASPECT_DOCPRINT ) 257 aResult = ::rtl::OUString::createFromAscii( ";Aspect=DOCPRINT" ); 258 259 // no suffix for DVASPECT_CONTENT 260 261 return aResult; 262 } 263 264 //---------------------------------------------- 265 HRESULT OpenIStorageFromURL_Impl( const ::rtl::OUString& aURL, IStorage** ppIStorage ) 266 { 267 OSL_ENSURE( ppIStorage, "The pointer must not be empty!" ); 268 269 ::rtl::OUString aFilePath; 270 if ( !ppIStorage || ::osl::FileBase::getSystemPathFromFileURL( aURL, aFilePath ) != ::osl::FileBase::E_None ) 271 throw uno::RuntimeException(); // TODO: something dangerous happend 272 273 return StgOpenStorage( reinterpret_cast<LPCWSTR>(aFilePath.getStr()), 274 NULL, 275 STGM_READWRITE | STGM_TRANSACTED, // | STGM_DELETEONRELEASE, 276 NULL, 277 0, 278 ppIStorage ); 279 } 280 281 //---------------------------------------------- 282 sal_Bool OleComponentNative_Impl::ConvertDataForFlavor( const STGMEDIUM& aMedium, 283 const datatransfer::DataFlavor& aFlavor, 284 uno::Any& aResult ) 285 { 286 sal_Bool bAnyIsReady = sal_False; 287 288 // try to convert data from Medium format to specified Flavor format 289 if ( aFlavor.DataType == getCppuType( ( const uno::Sequence< sal_Int8 >* ) 0 ) ) 290 { 291 // first the GDI-metafile must be generated 292 293 unsigned char* pBuf = NULL; 294 sal_uInt32 nBufSize = 0; 295 ::rtl::OUString aFormat; 296 297 if ( aMedium.tymed == TYMED_MFPICT ) // Win Metafile 298 { 299 aFormat = ::rtl::OUString::createFromAscii("image/x-wmf"); 300 METAFILEPICT* pMF = ( METAFILEPICT* )GlobalLock( aMedium.hMetaFilePict ); 301 if ( pMF ) 302 { 303 nBufSize = GetMetaFileBitsEx( pMF->hMF, 0, NULL ) + 22; 304 pBuf = new unsigned char[nBufSize]; 305 306 307 // TODO/LATER: the unit size must be calculated correctly 308 *( (long* )pBuf ) = 0x9ac6cdd7L; 309 *( (short* )( pBuf+6 )) = ( SHORT ) 0; 310 *( (short* )( pBuf+8 )) = ( SHORT ) 0; 311 *( (short* )( pBuf+10 )) = ( SHORT ) pMF->xExt; 312 *( (short* )( pBuf+12 )) = ( SHORT ) pMF->yExt; 313 *( (short* )( pBuf+14 )) = ( USHORT ) 2540; 314 315 316 if ( nBufSize && nBufSize == GetMetaFileBitsEx( pMF->hMF, nBufSize - 22, pBuf + 22 ) ) 317 { 318 if ( aFlavor.MimeType.matchAsciiL( "application/x-openoffice-wmf;windows_formatname=\"Image WMF\"", 57 ) ) 319 { 320 aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf, nBufSize ); 321 bAnyIsReady = sal_True; 322 } 323 } 324 325 GlobalUnlock( aMedium.hMetaFilePict ); 326 } 327 } 328 else if ( aMedium.tymed == TYMED_ENHMF ) // Enh Metafile 329 { 330 aFormat = ::rtl::OUString::createFromAscii("image/x-emf"); 331 nBufSize = GetEnhMetaFileBits( aMedium.hEnhMetaFile, 0, NULL ); 332 pBuf = new unsigned char[nBufSize]; 333 if ( nBufSize && nBufSize == GetEnhMetaFileBits( aMedium.hEnhMetaFile, nBufSize, pBuf ) ) 334 { 335 if ( aFlavor.MimeType.matchAsciiL( "application/x-openoffice-emf;windows_formatname=\"Image EMF\"", 57 ) ) 336 { 337 aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf, nBufSize ); 338 bAnyIsReady = sal_True; 339 } 340 } 341 } 342 else if ( aMedium.tymed == TYMED_GDI ) // Bitmap 343 { 344 aFormat = ::rtl::OUString::createFromAscii("image/x-MS-bmp"); 345 nBufSize = GetBitmapBits( aMedium.hBitmap, 0, NULL ); 346 pBuf = new unsigned char[nBufSize]; 347 if ( nBufSize && nBufSize == sal::static_int_cast< ULONG >( GetBitmapBits( aMedium.hBitmap, nBufSize, pBuf ) ) ) 348 { 349 if ( aFlavor.MimeType.matchAsciiL( "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"", 54 ) ) 350 { 351 aResult <<= uno::Sequence< sal_Int8 >( ( sal_Int8* )pBuf, nBufSize ); 352 bAnyIsReady = sal_True; 353 } 354 } 355 } 356 357 if ( pBuf && !bAnyIsReady ) 358 { 359 for ( sal_Int32 nInd = 0; nInd < m_aSupportedGraphFormats.getLength(); nInd++ ) 360 if ( aFlavor.MimeType.match( m_aSupportedGraphFormats[nInd].MimeType ) 361 && aFlavor.DataType == m_aSupportedGraphFormats[nInd].DataType 362 && aFlavor.DataType == getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ) 363 { 364 bAnyIsReady = ConvertBufferToFormat( ( void* )pBuf, nBufSize, aFormat, aResult ); 365 break; 366 } 367 } 368 369 delete[] pBuf; 370 } 371 372 return bAnyIsReady; 373 } 374 375 //---------------------------------------------- 376 sal_Bool OleComponentNative_Impl::GraphicalFlavor( const datatransfer::DataFlavor& aFlavor ) 377 { 378 // Actually all the required graphical formats must be supported 379 for ( sal_Int32 nInd = 0; nInd < m_aSupportedGraphFormats.getLength(); nInd++ ) 380 if ( aFlavor.MimeType.match( m_aSupportedGraphFormats[nInd].MimeType ) 381 && aFlavor.DataType == m_aSupportedGraphFormats[nInd].DataType ) 382 return sal_True; 383 384 return sal_False; 385 } 386 387 //---------------------------------------------- 388 sal_Bool GetClassIDFromSequence_Impl( uno::Sequence< sal_Int8 > aSeq, CLSID& aResult ) 389 { 390 if ( aSeq.getLength() == 16 ) 391 { 392 aResult.Data1 = ( ( ( ( ( ( sal_uInt8 )aSeq[0] << 8 ) + ( sal_uInt8 )aSeq[1] ) << 8 ) + ( sal_uInt8 )aSeq[2] ) << 8 ) + ( sal_uInt8 )aSeq[3]; 393 aResult.Data2 = ( ( sal_uInt8 )aSeq[4] << 8 ) + ( sal_uInt8 )aSeq[5]; 394 aResult.Data3 = ( ( sal_uInt8 )aSeq[6] << 8 ) + ( sal_uInt8 )aSeq[7]; 395 for( int nInd = 0; nInd < 8; nInd++ ) 396 aResult.Data4[nInd] = ( sal_uInt8 )aSeq[nInd+8]; 397 398 return sal_True; 399 } 400 401 return sal_False; 402 } 403 404 //---------------------------------------------- 405 ::rtl::OUString WinAccToVcl_Impl( const sal_Unicode* pStr ) 406 { 407 ::rtl::OUString aResult; 408 409 if( pStr ) 410 { 411 while ( *pStr ) 412 { 413 if ( *pStr == '&' ) 414 { 415 aResult += ::rtl::OUString::createFromAscii( "~" ); 416 while( *( ++pStr ) == '&' ); 417 } 418 else 419 { 420 aResult += ::rtl::OUString( pStr, 1 ); 421 pStr++; 422 } 423 } 424 } 425 426 return aResult; 427 } 428 429 //---------------------------------------------- 430 OleComponent::OleComponent( const uno::Reference< lang::XMultiServiceFactory >& xFactory, OleEmbeddedObject* pUnoOleObject ) 431 : m_pInterfaceContainer( NULL ) 432 , m_bDisposed( sal_False ) 433 , m_bModified( sal_False ) 434 , m_pNativeImpl( new OleComponentNative_Impl() ) 435 , m_xFactory( xFactory ) 436 , m_pOleWrapClientSite( NULL ) 437 , m_pImplAdviseSink( NULL ) 438 , m_pUnoOleObject( pUnoOleObject ) 439 , m_nOLEMiscFlags( 0 ) 440 , m_nAdvConn( 0 ) 441 , m_bOleInitialized( sal_False ) 442 , m_bWorkaroundActive( sal_False ) 443 { 444 OSL_ENSURE( m_pUnoOleObject, "No owner object is provided!" ); 445 446 HRESULT hr = OleInitialize( NULL ); 447 OSL_ENSURE( hr == S_OK || hr == S_FALSE, "The ole can not be successfuly initialized\n" ); 448 if ( hr == S_OK || hr == S_FALSE ) 449 m_bOleInitialized = sal_True; 450 451 m_pOleWrapClientSite = new OleWrapperClientSite( ( OleComponent* )this ); 452 m_pOleWrapClientSite->AddRef(); 453 454 m_pImplAdviseSink = new OleWrapperAdviseSink( ( OleComponent* )this ); 455 m_pImplAdviseSink->AddRef(); 456 457 } 458 459 //---------------------------------------------- 460 OleComponent::~OleComponent() 461 { 462 OSL_ENSURE( !m_pOleWrapClientSite && !m_pImplAdviseSink && !m_pInterfaceContainer && !m_bOleInitialized, 463 "The object was not closed successfully! DISASTER is possible!" ); 464 465 if ( m_pOleWrapClientSite || m_pImplAdviseSink || m_pInterfaceContainer || m_bOleInitialized ) 466 { 467 ::osl::MutexGuard aGuard( m_aMutex ); 468 m_refCount++; 469 try { 470 Dispose(); 471 } catch( uno::Exception& ) {} 472 } 473 474 for ( FormatEtcList::iterator aIter = m_pNativeImpl->m_aFormatsList.begin(); 475 aIter != m_pNativeImpl->m_aFormatsList.end(); 476 aIter++ ) 477 { 478 delete (*aIter); 479 (*aIter) = NULL; 480 } 481 m_pNativeImpl->m_aFormatsList.clear(); 482 483 delete m_pNativeImpl; 484 } 485 486 //---------------------------------------------- 487 void OleComponentNative_Impl::AddSupportedFormat( const FORMATETC& aFormatEtc ) 488 { 489 FORMATETC* pFormatToInsert = new FORMATETC( aFormatEtc ); 490 m_aFormatsList.push_back( pFormatToInsert ); 491 } 492 493 //---------------------------------------------- 494 FORMATETC* OleComponentNative_Impl::GetSupportedFormatForAspect( sal_uInt32 nRequestedAspect ) 495 { 496 for ( FormatEtcList::iterator aIter = m_aFormatsList.begin(); 497 aIter != m_aFormatsList.end(); 498 aIter++ ) 499 if ( (*aIter) && (*aIter)->dwAspect == nRequestedAspect ) 500 return (*aIter); 501 502 return NULL; 503 } 504 505 //---------------------------------------------- 506 void OleComponent::Dispose() 507 { 508 // the mutex must be locked before this method is called 509 if ( m_bDisposed ) 510 return; 511 512 CloseObject(); 513 514 if ( m_pOleWrapClientSite ) 515 { 516 m_pOleWrapClientSite->disconnectOleComponent(); 517 m_pOleWrapClientSite->Release(); 518 m_pOleWrapClientSite = NULL; 519 } 520 521 if ( m_pImplAdviseSink ) 522 { 523 m_pImplAdviseSink->disconnectOleComponent(); 524 m_pImplAdviseSink->Release(); 525 m_pImplAdviseSink = NULL; 526 } 527 528 if ( m_pInterfaceContainer ) 529 { 530 lang::EventObject aEvent( static_cast< ::cppu::OWeakObject* >( this ) ); 531 m_pInterfaceContainer->disposeAndClear( aEvent ); 532 533 delete m_pInterfaceContainer; 534 m_pInterfaceContainer = NULL; 535 } 536 537 if ( m_bOleInitialized ) 538 { 539 // since the disposing can happen not only from main thread but also from a clipboard 540 // the deinitialization might lead to a disaster, SO7 does not deinitialize OLE at all 541 // so currently the same approach is selected as workaround 542 // OleUninitialize(); 543 m_bOleInitialized = sal_False; 544 } 545 546 m_bDisposed = sal_True; 547 } 548 549 //---------------------------------------------- 550 void OleComponent::disconnectEmbeddedObject() 551 { 552 // must not be called from destructor of UNO OLE object!!! 553 osl::MutexGuard aGuard( m_aMutex ); 554 m_pUnoOleObject = NULL; 555 } 556 557 //---------------------------------------------- 558 void OleComponent::CreateNewIStorage_Impl() 559 { 560 // TODO: in future a global memory could be used instead of file. 561 562 // write the stream to the temporary file 563 ::rtl::OUString aTempURL; 564 565 OSL_ENSURE( m_pUnoOleObject, "Unexpected object absence!" ); 566 if ( m_pUnoOleObject ) 567 aTempURL = m_pUnoOleObject->CreateTempURLEmpty_Impl(); 568 else 569 aTempURL = GetNewTempFileURL_Impl( m_xFactory ); 570 571 if ( !aTempURL.getLength() ) 572 throw uno::RuntimeException(); // TODO 573 574 // open an IStorage based on the temporary file 575 ::rtl::OUString aTempFilePath; 576 if ( ::osl::FileBase::getSystemPathFromFileURL( aTempURL, aTempFilePath ) != ::osl::FileBase::E_None ) 577 throw uno::RuntimeException(); // TODO: something dangerous happend 578 579 HRESULT hr = StgCreateDocfile( reinterpret_cast<LPCWSTR>(aTempFilePath.getStr()), STGM_CREATE | STGM_READWRITE | STGM_TRANSACTED | STGM_DELETEONRELEASE, 0, &m_pNativeImpl->m_pIStorage ); 580 if ( FAILED( hr ) || !m_pNativeImpl->m_pIStorage ) 581 throw io::IOException(); // TODO: transport error code? 582 } 583 584 //---------------------------------------------- 585 uno::Sequence< datatransfer::DataFlavor > OleComponentNative_Impl::GetFlavorsForAspects( sal_uInt32 nSupportedAspects ) 586 { 587 uno::Sequence< datatransfer::DataFlavor > aResult; 588 for ( sal_uInt32 nAsp = 1; nAsp <= 8; nAsp *= 2 ) 589 if ( ( nSupportedAspects & nAsp ) == nAsp ) 590 { 591 ::rtl::OUString aAspectSuffix = GetFlavorSuffixFromAspect( nAsp ); 592 593 sal_Int32 nLength = aResult.getLength(); 594 aResult.realloc( nLength + m_aSupportedGraphFormats.getLength() ); 595 596 for ( sal_Int32 nInd = 0; nInd < m_aSupportedGraphFormats.getLength(); nInd++ ) 597 { 598 aResult[nLength + nInd].MimeType = m_aSupportedGraphFormats[nInd].MimeType + aAspectSuffix; 599 aResult[nLength + nInd].HumanPresentableName = m_aSupportedGraphFormats[nInd].HumanPresentableName; 600 aResult[nLength + nInd].DataType = m_aSupportedGraphFormats[nInd].DataType; 601 } 602 } 603 604 return aResult; 605 } 606 607 //---------------------------------------------- 608 void OleComponent::RetrieveObjectDataFlavors_Impl() 609 { 610 if ( !m_pNativeImpl->m_pOleObject ) 611 throw embed::WrongStateException(); // TODO: the object is in wrong state 612 613 if ( !m_aDataFlavors.getLength() ) 614 { 615 ComSmart< IDataObject > pDataObject; 616 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject ); 617 if ( SUCCEEDED( hr ) && pDataObject ) 618 { 619 ComSmart< IEnumFORMATETC > pFormatEnum; 620 hr = pDataObject->EnumFormatEtc( DATADIR_GET, &pFormatEnum ); 621 if ( SUCCEEDED( hr ) && pFormatEnum ) 622 { 623 FORMATETC pElem[ MAX_ENUM_ELE ]; 624 ULONG nNum = 0; 625 626 // if it is possible to retrieve at least one supported graphical format for an aspect 627 // this format can be converted to other supported formats 628 sal_uInt32 nSupportedAspects = 0; 629 do 630 { 631 HRESULT hr = pFormatEnum->Next( MAX_ENUM_ELE, pElem, &nNum ); 632 if( hr == S_OK || hr == S_FALSE ) 633 { 634 for( sal_uInt32 nInd = 0; nInd < FORMATS_NUM; nInd++ ) 635 { 636 if ( pElem[nInd].cfFormat == pFormatTemplates[nInd].cfFormat 637 && pElem[nInd].tymed == pFormatTemplates[nInd].tymed ) 638 nSupportedAspects |= pElem[nInd].dwAspect; 639 } 640 } 641 else 642 break; 643 } 644 while( nNum == MAX_ENUM_ELE ); 645 646 m_aDataFlavors = m_pNativeImpl->GetFlavorsForAspects( nSupportedAspects ); 647 } 648 } 649 650 if ( !m_aDataFlavors.getLength() ) 651 { 652 // TODO: 653 // for any reason the object could not provide this information 654 // try to get access to the cached representation 655 } 656 } 657 } 658 659 //---------------------------------------------- 660 sal_Bool OleComponent::InitializeObject_Impl() 661 // There will be no static objects! 662 { 663 if ( !m_pNativeImpl->m_pObj ) 664 return sal_False; 665 666 // the linked object will be detected here 667 ComSmart< IOleLink > pOleLink; 668 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IOleLink, (void**)&pOleLink ); 669 OSL_ENSURE( m_pUnoOleObject, "Unexpected object absence!" ); 670 if ( m_pUnoOleObject ) 671 m_pUnoOleObject->SetObjectIsLink_Impl( sal_Bool( pOleLink != NULL ) ); 672 673 674 hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IViewObject2, (void**)&m_pNativeImpl->m_pViewObject2 ); 675 if ( FAILED( hr ) || !m_pNativeImpl->m_pViewObject2 ) 676 return sal_False; 677 678 // not realy needed for now, since object is updated on saving 679 // m_pNativeImpl->m_pViewObject2->SetAdvise( DVASPECT_CONTENT, 0, m_pImplAdviseSink ); 680 681 // remove all the caches 682 IOleCache* pIOleCache = NULL; 683 if ( SUCCEEDED( m_pNativeImpl->m_pObj->QueryInterface( IID_IOleCache, (void**)&pIOleCache ) ) && pIOleCache ) 684 { 685 IEnumSTATDATA* pEnumSD = NULL; 686 HRESULT hr = pIOleCache->EnumCache( &pEnumSD ); 687 688 if ( SUCCEEDED( hr ) && pEnumSD ) 689 { 690 pEnumSD->Reset(); 691 STATDATA aSD; 692 DWORD nNum; 693 while( SUCCEEDED( pEnumSD->Next( 1, &aSD, &nNum ) ) && nNum == 1 ) 694 hr = pIOleCache->Uncache( aSD.dwConnection ); 695 } 696 697 // No IDataObject implementation, caching must be used instead 698 DWORD nConn; 699 FORMATETC aFormat = { 0, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT }; 700 hr = pIOleCache->Cache( &aFormat, ADVFCACHE_ONSAVE, &nConn ); 701 702 pIOleCache->Release(); 703 pIOleCache = NULL; 704 } 705 706 hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IOleObject, (void**)&m_pNativeImpl->m_pOleObject ); 707 if ( FAILED( hr ) || !m_pNativeImpl->m_pOleObject ) 708 return sal_False; // Static objects are not supported, they should be inserted as graphics 709 710 m_pNativeImpl->m_pOleObject->GetMiscStatus( DVASPECT_CONTENT, ( DWORD* )&m_nOLEMiscFlags ); 711 // TODO: use other misc flags also 712 // the object should have drawable aspect even in case it supports only iconic representation 713 // if ( m_nOLEMiscFlags & OLEMISC_ONLYICONIC ) 714 715 m_pNativeImpl->m_pOleObject->SetClientSite( m_pOleWrapClientSite ); 716 717 // the only need in this registration is workaround for close notification 718 m_pNativeImpl->m_pOleObject->Advise( m_pImplAdviseSink, ( DWORD* )&m_nAdvConn ); 719 m_pNativeImpl->m_pViewObject2->SetAdvise( DVASPECT_CONTENT, 0, m_pImplAdviseSink ); 720 721 OleSetContainedObject( m_pNativeImpl->m_pOleObject, TRUE ); 722 723 return sal_True; 724 } 725 726 //---------------------------------------------- 727 void OleComponent::LoadEmbeddedObject( const ::rtl::OUString& aTempURL ) 728 { 729 if ( !aTempURL.getLength() ) 730 throw lang::IllegalArgumentException(); // TODO 731 732 if ( m_pNativeImpl->m_pIStorage ) 733 throw io::IOException(); // TODO the object is already initialized or wrong initialization is done 734 735 // open an IStorage based on the temporary file 736 HRESULT hr = OpenIStorageFromURL_Impl( aTempURL, &m_pNativeImpl->m_pIStorage ); 737 738 if ( FAILED( hr ) || !m_pNativeImpl->m_pIStorage ) 739 throw io::IOException(); // TODO: transport error code? 740 741 hr = OleLoad( m_pNativeImpl->m_pIStorage, IID_IUnknown, NULL, (void**)&m_pNativeImpl->m_pObj ); 742 if ( FAILED( hr ) || !m_pNativeImpl->m_pObj ) 743 { 744 // STATSTG aStat; 745 // m_pNativeImpl->m_pIStorage->Stat( &aStat, STATFLAG_NONAME ); 746 throw uno::RuntimeException(); 747 } 748 749 if ( !InitializeObject_Impl() ) 750 throw uno::RuntimeException(); // TODO 751 } 752 753 //---------------------------------------------- 754 void OleComponent::CreateObjectFromClipboard() 755 { 756 if ( m_pNativeImpl->m_pIStorage ) 757 throw io::IOException(); // TODO:the object is already initialized 758 759 CreateNewIStorage_Impl(); 760 if ( !m_pNativeImpl->m_pIStorage ) 761 throw uno::RuntimeException(); // TODO 762 763 IDataObject * pDO = NULL; 764 HRESULT hr = OleGetClipboard( &pDO ); 765 if( SUCCEEDED( hr ) && pDO ) 766 { 767 hr = OleQueryCreateFromData( pDO ); 768 if( S_OK == GetScode( hr ) ) 769 { 770 hr = OleCreateFromData( pDO, 771 IID_IUnknown, 772 OLERENDER_DRAW, // OLERENDER_FORMAT 773 NULL, // &aFormat, 774 NULL, 775 m_pNativeImpl->m_pIStorage, 776 (void**)&m_pNativeImpl->m_pObj ); 777 } 778 else 779 { 780 // Static objects are not supported 781 pDO->Release(); 782 } 783 } 784 785 if ( FAILED( hr ) || !m_pNativeImpl->m_pObj ) 786 throw uno::RuntimeException(); 787 788 if ( !InitializeObject_Impl() ) 789 throw uno::RuntimeException(); // TODO 790 } 791 792 //---------------------------------------------- 793 void OleComponent::CreateNewEmbeddedObject( const uno::Sequence< sal_Int8 >& aSeqCLSID ) 794 { 795 CLSID aClsID; 796 797 if ( !GetClassIDFromSequence_Impl( aSeqCLSID, aClsID ) ) 798 throw lang::IllegalArgumentException(); // TODO 799 800 if ( m_pNativeImpl->m_pIStorage ) 801 throw io::IOException(); // TODO:the object is already initialized 802 803 CreateNewIStorage_Impl(); 804 if ( !m_pNativeImpl->m_pIStorage ) 805 throw uno::RuntimeException(); // TODO 806 807 // FORMATETC aFormat = { CF_METAFILEPICT, NULL, nAspect, -1, TYMED_MFPICT }; // for OLE..._DRAW should be NULL 808 809 HRESULT hr = OleCreate( aClsID, 810 IID_IUnknown, 811 OLERENDER_DRAW, // OLERENDER_FORMAT 812 NULL, // &aFormat, 813 NULL, 814 m_pNativeImpl->m_pIStorage, 815 (void**)&m_pNativeImpl->m_pObj ); 816 817 if ( FAILED( hr ) || !m_pNativeImpl->m_pObj ) 818 throw uno::RuntimeException(); // TODO 819 820 if ( !InitializeObject_Impl() ) 821 throw uno::RuntimeException(); // TODO 822 823 // TODO: getExtent??? 824 } 825 826 //---------------------------------------------- 827 void OleComponent::CreateObjectFromData( const uno::Reference< datatransfer::XTransferable >& ) 828 // Static objects are not supported, they should be inserted as graphics 829 { 830 // TODO: May be this call is useless since there are no static objects 831 // and nonstatic objects will be created based on OLEstorage ( stream ). 832 // ??? 833 834 // OleQueryCreateFromData... 835 } 836 837 //---------------------------------------------- 838 void OleComponent::CreateObjectFromFile( const ::rtl::OUString& aFileURL ) 839 { 840 if ( m_pNativeImpl->m_pIStorage ) 841 throw io::IOException(); // TODO:the object is already initialized 842 843 CreateNewIStorage_Impl(); 844 if ( !m_pNativeImpl->m_pIStorage ) 845 throw uno::RuntimeException(); // TODO: 846 847 ::rtl::OUString aFilePath; 848 if ( ::osl::FileBase::getSystemPathFromFileURL( aFileURL, aFilePath ) != ::osl::FileBase::E_None ) 849 throw uno::RuntimeException(); // TODO: something dangerous happend 850 851 HRESULT hr = OleCreateFromFile( CLSID_NULL, 852 reinterpret_cast<LPCWSTR>(aFilePath.getStr()), 853 IID_IUnknown, 854 OLERENDER_DRAW, // OLERENDER_FORMAT 855 NULL, 856 NULL, 857 m_pNativeImpl->m_pIStorage, 858 (void**)&m_pNativeImpl->m_pObj ); 859 860 if ( FAILED( hr ) || !m_pNativeImpl->m_pObj ) 861 throw uno::RuntimeException(); // TODO 862 863 if ( !InitializeObject_Impl() ) 864 throw uno::RuntimeException(); // TODO 865 } 866 867 //---------------------------------------------- 868 void OleComponent::CreateLinkFromFile( const ::rtl::OUString& aFileURL ) 869 { 870 if ( m_pNativeImpl->m_pIStorage ) 871 throw io::IOException(); // TODO:the object is already initialized 872 873 CreateNewIStorage_Impl(); 874 if ( !m_pNativeImpl->m_pIStorage ) 875 throw uno::RuntimeException(); // TODO: 876 877 ::rtl::OUString aFilePath; 878 if ( ::osl::FileBase::getSystemPathFromFileURL( aFileURL, aFilePath ) != ::osl::FileBase::E_None ) 879 throw uno::RuntimeException(); // TODO: something dangerous happend 880 881 HRESULT hr = OleCreateLinkToFile( reinterpret_cast<LPCWSTR>(aFilePath.getStr()), 882 IID_IUnknown, 883 OLERENDER_DRAW, // OLERENDER_FORMAT 884 NULL, 885 NULL, 886 m_pNativeImpl->m_pIStorage, 887 (void**)&m_pNativeImpl->m_pObj ); 888 889 if ( FAILED( hr ) || !m_pNativeImpl->m_pObj ) 890 throw uno::RuntimeException(); // TODO 891 892 if ( !InitializeObject_Impl() ) 893 throw uno::RuntimeException(); // TODO 894 } 895 896 //---------------------------------------------- 897 void OleComponent::InitEmbeddedCopyOfLink( OleComponent* pOleLinkComponent ) 898 { 899 if ( !pOleLinkComponent || !pOleLinkComponent->m_pNativeImpl->m_pObj ) 900 throw lang::IllegalArgumentException(); // TODO 901 902 if ( m_pNativeImpl->m_pIStorage ) 903 throw io::IOException(); // TODO:the object is already initialized 904 905 ComSmart< IDataObject > pDataObject; 906 HRESULT hr = pOleLinkComponent->m_pNativeImpl->m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject ); 907 if ( SUCCEEDED( hr ) && pDataObject && SUCCEEDED( OleQueryCreateFromData( pDataObject ) ) ) 908 { 909 // the object must be already disconnected from the temporary URL 910 CreateNewIStorage_Impl(); 911 if ( !m_pNativeImpl->m_pIStorage ) 912 throw uno::RuntimeException(); // TODO: 913 914 hr = OleCreateFromData( pDataObject, 915 IID_IUnknown, 916 OLERENDER_DRAW, 917 NULL, 918 NULL, 919 m_pNativeImpl->m_pIStorage, 920 (void**)&m_pNativeImpl->m_pObj ); 921 } 922 923 if ( !m_pNativeImpl->m_pObj ) 924 { 925 ComSmart< IOleLink > pOleLink; 926 hr = pOleLinkComponent->m_pNativeImpl->m_pObj->QueryInterface( IID_IOleLink, (void**)&pOleLink ); 927 if ( FAILED( hr ) || !pOleLink ) 928 throw io::IOException(); // TODO: the object doesn't support IOleLink 929 930 ComSmart< IMoniker > pMoniker; 931 hr = pOleLink->GetSourceMoniker( &pMoniker ); 932 if ( FAILED( hr ) || !pMoniker ) 933 throw io::IOException(); // TODO: can not retrieve moniker 934 935 // In case of file moniker life is easy : ) 936 DWORD aMonType = 0; 937 hr = pMoniker->IsSystemMoniker( &aMonType ); 938 if ( SUCCEEDED( hr ) && aMonType == MKSYS_FILEMONIKER ) 939 { 940 ComSmart< IMalloc > pMalloc; 941 CoGetMalloc( 1, &pMalloc ); // if fails there will be a memory leak 942 OSL_ENSURE( pMalloc, "CoGetMalloc() failed!" ); 943 944 LPOLESTR pOleStr = NULL; 945 hr = pOleLink->GetSourceDisplayName( &pOleStr ); 946 if ( SUCCEEDED( hr ) && pOleStr ) 947 { 948 ::rtl::OUString aFilePath( ( sal_Unicode* )pOleStr ); 949 if ( pMalloc ) 950 pMalloc->Free( ( void* )pOleStr ); 951 952 hr = OleCreateFromFile( CLSID_NULL, 953 reinterpret_cast<LPCWSTR>(aFilePath.getStr()), 954 IID_IUnknown, 955 OLERENDER_DRAW, // OLERENDER_FORMAT 956 NULL, 957 NULL, 958 m_pNativeImpl->m_pIStorage, 959 (void**)&m_pNativeImpl->m_pObj ); 960 } 961 } 962 963 // in case of other moniker types the only way is to get storage 964 if ( !m_pNativeImpl->m_pObj ) 965 { 966 ComSmart< IBindCtx > pBindCtx; 967 hr = CreateBindCtx( 0, ( LPBC FAR* )&pBindCtx ); 968 if ( SUCCEEDED( hr ) && pBindCtx ) 969 { 970 ComSmart< IStorage > pObjectStorage; 971 hr = pMoniker->BindToStorage( pBindCtx, NULL, IID_IStorage, (void**)&pObjectStorage ); 972 if ( SUCCEEDED( hr ) && pObjectStorage ) 973 { 974 hr = pObjectStorage->CopyTo( 0, NULL, NULL, m_pNativeImpl->m_pIStorage ); 975 if ( SUCCEEDED( hr ) ) 976 hr = OleLoad( m_pNativeImpl->m_pIStorage, IID_IUnknown, NULL, (void**)&m_pNativeImpl->m_pObj ); 977 } 978 } 979 } 980 } 981 982 // If object could not be created the only way is to use graphical representation 983 if ( FAILED( hr ) || !m_pNativeImpl->m_pObj ) 984 throw uno::RuntimeException(); // TODO 985 986 if ( !InitializeObject_Impl() ) 987 throw uno::RuntimeException(); // TODO 988 } 989 990 //---------------------------------------------- 991 void OleComponent::RunObject() 992 { 993 OSL_ENSURE( m_pNativeImpl->m_pOleObject, "The pointer can not be set to NULL here!\n" ); 994 if ( !m_pNativeImpl->m_pOleObject ) 995 throw embed::WrongStateException(); // TODO: the object is in wrong state 996 997 if ( !OleIsRunning( m_pNativeImpl->m_pOleObject ) ) 998 { 999 HRESULT hr = S_OK; 1000 try 1001 { 1002 hr = OleRun( m_pNativeImpl->m_pObj ); 1003 } 1004 catch( ... ) 1005 { 1006 int i = 0; 1007 i++; 1008 } 1009 1010 if ( FAILED( hr ) ) 1011 { 1012 if ( hr == REGDB_E_CLASSNOTREG ) 1013 throw embed::UnreachableStateException(); // the object server is not installed 1014 else 1015 throw io::IOException(); 1016 } 1017 } 1018 } 1019 1020 //---------------------------------------------- 1021 awt::Size OleComponent::CalculateWithFactor( const awt::Size& aSize, 1022 const awt::Size& aMultiplier, 1023 const awt::Size& aDivisor ) 1024 { 1025 awt::Size aResult; 1026 1027 sal_Int64 nWidth = (sal_Int64)aSize.Width * (sal_Int64)aMultiplier.Width / (sal_Int64)aDivisor.Width; 1028 sal_Int64 nHeight = (sal_Int64)aSize.Height * (sal_Int64)aMultiplier.Height / (sal_Int64)aDivisor.Height; 1029 OSL_ENSURE( nWidth < SAL_MAX_INT32 && nWidth > SAL_MIN_INT32 1030 && nHeight < SAL_MAX_INT32 && nHeight > SAL_MIN_INT32, 1031 "Unacceptable result size!" ); 1032 1033 aResult.Width = (sal_Int32)nWidth; 1034 aResult.Height = (sal_Int32)nHeight; 1035 1036 return aResult; 1037 } 1038 1039 //---------------------------------------------- 1040 void OleComponent::CloseObject() 1041 { 1042 if ( m_pNativeImpl->m_pOleObject && OleIsRunning( m_pNativeImpl->m_pOleObject ) ) 1043 m_pNativeImpl->m_pOleObject->Close( OLECLOSE_NOSAVE ); // must be saved before 1044 } 1045 1046 //---------------------------------------------- 1047 uno::Sequence< embed::VerbDescriptor > OleComponent::GetVerbList() 1048 { 1049 if ( !m_pNativeImpl->m_pOleObject ) 1050 throw embed::WrongStateException(); // TODO: the object is in wrong state 1051 1052 if( !m_aVerbList.getLength() ) 1053 { 1054 ComSmart< IEnumOLEVERB > pEnum; 1055 if( SUCCEEDED( m_pNativeImpl->m_pOleObject->EnumVerbs( &pEnum ) ) ) 1056 { 1057 OLEVERB szEle[ MAX_ENUM_ELE ]; 1058 ULONG nNum = 0; 1059 sal_Int32 nSeqSize = 0; 1060 1061 do 1062 { 1063 HRESULT hr = pEnum->Next( MAX_ENUM_ELE, szEle, &nNum ); 1064 if( hr == S_OK || hr == S_FALSE ) 1065 { 1066 m_aVerbList.realloc( nSeqSize += nNum ); 1067 for( sal_uInt32 nInd = 0; nInd < nNum; nInd++ ) 1068 { 1069 m_aVerbList[nSeqSize-nNum+nInd].VerbID = szEle[ nInd ].lVerb; 1070 m_aVerbList[nSeqSize-nNum+nInd].VerbName = WinAccToVcl_Impl( reinterpret_cast<const sal_Unicode*>(szEle[ nInd ].lpszVerbName) ); 1071 m_aVerbList[nSeqSize-nNum+nInd].VerbFlags = szEle[ nInd ].fuFlags; 1072 m_aVerbList[nSeqSize-nNum+nInd].VerbAttributes = szEle[ nInd ].grfAttribs; 1073 } 1074 } 1075 else 1076 break; 1077 } 1078 while( nNum == MAX_ENUM_ELE ); 1079 } 1080 } 1081 1082 return m_aVerbList; 1083 } 1084 1085 //---------------------------------------------- 1086 void OleComponent::ExecuteVerb( sal_Int32 nVerbID ) 1087 { 1088 if ( !m_pNativeImpl->m_pOleObject ) 1089 throw embed::WrongStateException(); // TODO 1090 1091 HRESULT hr = OleRun( m_pNativeImpl->m_pOleObject ); 1092 if ( FAILED( hr ) ) 1093 throw io::IOException(); // TODO: a specific exception that transport error code can be thrown here 1094 1095 // TODO: probably extents should be set here and stored in aRect 1096 // TODO: probably the parent window also should be set 1097 hr = m_pNativeImpl->m_pOleObject->DoVerb( nVerbID, NULL, m_pOleWrapClientSite, 0, NULL, NULL ); 1098 1099 if ( FAILED( hr ) ) 1100 throw io::IOException(); // TODO 1101 1102 // TODO/LATER: the real names should be used here 1103 m_pNativeImpl->m_pOleObject->SetHostNames( L"app name", L"untitled" ); 1104 } 1105 1106 //---------------------------------------------- 1107 void OleComponent::SetHostName( const ::rtl::OUString&, 1108 const ::rtl::OUString& ) 1109 { 1110 if ( !m_pNativeImpl->m_pOleObject ) 1111 throw embed::WrongStateException(); // TODO: the object is in wrong state 1112 1113 // TODO: use aContName and aEmbDocName in m_pNativeImpl->m_pOleObject->SetHostNames() 1114 } 1115 1116 //---------------------------------------------- 1117 void OleComponent::SetExtent( const awt::Size& aVisAreaSize, sal_Int64 nAspect ) 1118 { 1119 if ( !m_pNativeImpl->m_pOleObject ) 1120 throw embed::WrongStateException(); // TODO: the object is in wrong state 1121 1122 DWORD nMSAspect = ( DWORD )nAspect; // first 32 bits are for MS aspects 1123 1124 SIZEL aSize = { aVisAreaSize.Width, aVisAreaSize.Height }; 1125 HRESULT hr = m_pNativeImpl->m_pOleObject->SetExtent( nMSAspect, &aSize ); 1126 1127 if ( FAILED( hr ) ) 1128 { 1129 // TODO/LATER: is it correct? In future user code probably should be ready for the exception. 1130 // if the object is running but not activated, RPC_E_SERVER_DIED error code is returned by OLE package 1131 // in this case just do nothing 1132 // Also Visio returns E_FAIL on resize if it is in running state 1133 // if ( hr != RPC_E_SERVER_DIED ) 1134 throw io::IOException(); // TODO 1135 } 1136 } 1137 1138 //---------------------------------------------- 1139 awt::Size OleComponent::GetExtent( sal_Int64 nAspect ) 1140 { 1141 if ( !m_pNativeImpl->m_pOleObject ) 1142 throw embed::WrongStateException(); // TODO: the object is in wrong state 1143 1144 DWORD nMSAspect = ( DWORD )nAspect; // first 32 bits are for MS aspects 1145 awt::Size aSize; 1146 sal_Bool bGotSize = sal_False; 1147 1148 if ( nMSAspect == DVASPECT_CONTENT ) 1149 { 1150 // Try to get the size from the replacement image first 1151 ComSmart< IDataObject > pDataObject; 1152 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject ); 1153 if ( SUCCEEDED( hr ) || pDataObject ) 1154 { 1155 STGMEDIUM aMedium; 1156 FORMATETC aFormat = pFormatTemplates[1]; // use windows metafile format 1157 aFormat.dwAspect = nMSAspect; 1158 1159 hr = pDataObject->GetData( &aFormat, &aMedium ); 1160 if ( SUCCEEDED( hr ) && aMedium.tymed == TYMED_MFPICT ) // Win Metafile 1161 { 1162 METAFILEPICT* pMF = ( METAFILEPICT* )GlobalLock( aMedium.hMetaFilePict ); 1163 if ( pMF ) 1164 { 1165 // the object uses 0.01 mm as unit, so the metafile size should be converted to object unit 1166 sal_Int64 nMult = 1; 1167 sal_Int64 nDiv = 1; 1168 switch( pMF->mm ) 1169 { 1170 case MM_HIENGLISH: 1171 nMult = 254; 1172 nDiv = 100; 1173 break; 1174 1175 case MM_LOENGLISH: 1176 nMult = 254; 1177 nDiv = 10; 1178 break; 1179 1180 case MM_LOMETRIC: 1181 nMult = 10; 1182 break; 1183 1184 case MM_TWIPS: 1185 nMult = 254; 1186 nDiv = 144; 1187 break; 1188 1189 case MM_ISOTROPIC: 1190 case MM_ANISOTROPIC: 1191 case MM_HIMETRIC: 1192 // do nothing 1193 break; 1194 } 1195 1196 sal_Int64 nX = ( (sal_Int64)abs( pMF->xExt ) ) * nMult / nDiv; 1197 sal_Int64 nY = ( (sal_Int64)abs( pMF->yExt ) ) * nMult / nDiv; 1198 if ( nX < SAL_MAX_INT32 && nY < SAL_MAX_INT32 ) 1199 { 1200 aSize.Width = ( sal_Int32 )nX; 1201 aSize.Height = ( sal_Int32 )nY; 1202 bGotSize = sal_True; 1203 } 1204 else 1205 OSL_ENSURE( sal_False, "Unexpected size is provided!" ); 1206 } 1207 } 1208 } 1209 } 1210 1211 if ( !bGotSize ) 1212 throw lang::IllegalArgumentException(); 1213 1214 return aSize; 1215 } 1216 1217 //---------------------------------------------- 1218 awt::Size OleComponent::GetCachedExtent( sal_Int64 nAspect ) 1219 { 1220 if ( !m_pNativeImpl->m_pOleObject ) 1221 throw embed::WrongStateException(); // TODO: the object is in wrong state 1222 1223 DWORD nMSAspect = ( DWORD )nAspect; // first 32 bits are for MS aspects 1224 SIZEL aSize; 1225 1226 HRESULT hr = m_pNativeImpl->m_pViewObject2->GetExtent( nMSAspect, -1, NULL, &aSize ); 1227 1228 if ( FAILED( hr ) ) 1229 { 1230 // TODO/LATER: is it correct? 1231 // if there is no appropriate cache for the aspect, OLE_E_BLANK error code is returned 1232 // if ( hr == OLE_E_BLANK ) 1233 // throw lang::IllegalArgumentException(); 1234 //else 1235 // throw io::IOException(); // TODO 1236 1237 throw lang::IllegalArgumentException(); 1238 } 1239 1240 return awt::Size( aSize.cx, aSize.cy ); 1241 } 1242 1243 //---------------------------------------------- 1244 awt::Size OleComponent::GetReccomendedExtent( sal_Int64 nAspect ) 1245 { 1246 if ( !m_pNativeImpl->m_pOleObject ) 1247 throw embed::WrongStateException(); // TODO: the object is in wrong state 1248 1249 DWORD nMSAspect = ( DWORD )nAspect; // first 32 bits are for MS aspects 1250 SIZEL aSize; 1251 HRESULT hr = m_pNativeImpl->m_pOleObject->GetExtent( nMSAspect, &aSize ); 1252 if ( FAILED( hr ) ) 1253 throw lang::IllegalArgumentException(); 1254 1255 return awt::Size( aSize.cx, aSize.cy ); 1256 } 1257 1258 //---------------------------------------------- 1259 sal_Int64 OleComponent::GetMiscStatus( sal_Int64 nAspect ) 1260 { 1261 if ( !m_pNativeImpl->m_pOleObject ) 1262 throw embed::WrongStateException(); // TODO: the object is in wrong state 1263 1264 sal_uInt32 nResult; 1265 m_pNativeImpl->m_pOleObject->GetMiscStatus( ( DWORD )nAspect, ( DWORD* )&nResult ); 1266 return ( sal_Int64 )nResult; // first 32 bits are for MS flags 1267 } 1268 1269 //---------------------------------------------- 1270 uno::Sequence< sal_Int8 > OleComponent::GetCLSID() 1271 { 1272 if ( !m_pNativeImpl->m_pOleObject ) 1273 throw embed::WrongStateException(); // TODO: the object is in wrong state 1274 1275 GUID aCLSID; 1276 HRESULT hr = m_pNativeImpl->m_pOleObject->GetUserClassID( &aCLSID ); 1277 if ( FAILED( hr ) ) 1278 throw io::IOException(); // TODO: 1279 1280 return MimeConfigurationHelper::GetSequenceClassID( aCLSID.Data1, aCLSID.Data2, aCLSID.Data3, 1281 aCLSID.Data4[0], aCLSID.Data4[1], 1282 aCLSID.Data4[2], aCLSID.Data4[3], 1283 aCLSID.Data4[4], aCLSID.Data4[5], 1284 aCLSID.Data4[6], aCLSID.Data4[7] ); 1285 } 1286 1287 //---------------------------------------------- 1288 sal_Bool OleComponent::IsDirty() 1289 { 1290 if ( !m_pNativeImpl->m_pOleObject ) 1291 throw embed::WrongStateException(); // TODO: the object is in wrong state 1292 1293 if ( IsWorkaroundActive() ) 1294 return sal_True; 1295 1296 ComSmart< IPersistStorage > pPersistStorage; 1297 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IPersistStorage, (void**)&pPersistStorage ); 1298 if ( FAILED( hr ) || !pPersistStorage ) 1299 throw io::IOException(); // TODO 1300 1301 hr = pPersistStorage->IsDirty(); 1302 return ( hr != S_FALSE ); 1303 } 1304 1305 //---------------------------------------------- 1306 void OleComponent::StoreOwnTmpIfNecessary() 1307 { 1308 if ( !m_pNativeImpl->m_pOleObject ) 1309 throw embed::WrongStateException(); // TODO: the object is in wrong state 1310 1311 ComSmart< IPersistStorage > pPersistStorage; 1312 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IPersistStorage, (void**)&pPersistStorage ); 1313 if ( FAILED( hr ) || !pPersistStorage ) 1314 throw io::IOException(); // TODO 1315 1316 if ( m_bWorkaroundActive || pPersistStorage->IsDirty() != S_FALSE ) 1317 { 1318 hr = OleSave( pPersistStorage, m_pNativeImpl->m_pIStorage, TRUE ); 1319 if ( FAILED( hr ) ) 1320 { 1321 // Till now was required only for AcrobatReader7.0.8 1322 GUID aCLSID; 1323 hr = m_pNativeImpl->m_pOleObject->GetUserClassID( &aCLSID ); 1324 if ( FAILED( hr ) ) 1325 throw io::IOException(); // TODO 1326 1327 hr = WriteClassStg( m_pNativeImpl->m_pIStorage, aCLSID ); 1328 if ( FAILED( hr ) ) 1329 throw io::IOException(); // TODO 1330 1331 // the result of the following call is not checked because some objects, for example AcrobatReader7.0.8 1332 // return error even in case the saving was done correctly 1333 hr = pPersistStorage->Save( m_pNativeImpl->m_pIStorage, TRUE ); 1334 1335 // another workaround for AcrobatReader7.0.8 object, this object might think that it is not changed 1336 // when it has been created from file, although it must be saved 1337 m_bWorkaroundActive = sal_True; 1338 } 1339 1340 hr = m_pNativeImpl->m_pIStorage->Commit( STGC_DEFAULT ); 1341 if ( FAILED( hr ) ) 1342 throw io::IOException(); // TODO 1343 1344 hr = pPersistStorage->SaveCompleted( NULL ); 1345 if ( FAILED( hr ) && hr != E_UNEXPECTED ) 1346 throw io::IOException(); // TODO 1347 1348 // STATSTG aStat; 1349 // m_pNativeImpl->m_pIStorage->Stat( &aStat, STATFLAG_NONAME ); 1350 } 1351 } 1352 1353 //---------------------------------------------- 1354 sal_Bool OleComponent::SaveObject_Impl() 1355 { 1356 sal_Bool bResult = sal_False; 1357 OleEmbeddedObject* pLockObject = NULL; 1358 1359 { 1360 osl::MutexGuard aGuard( m_aMutex ); 1361 if ( m_pUnoOleObject ) 1362 { 1363 pLockObject = m_pUnoOleObject; 1364 pLockObject->acquire(); 1365 } 1366 } 1367 1368 if ( pLockObject ) 1369 { 1370 bResult = pLockObject->SaveObject_Impl(); 1371 pLockObject->release(); 1372 } 1373 1374 return bResult; 1375 } 1376 1377 //---------------------------------------------- 1378 sal_Bool OleComponent::OnShowWindow_Impl( bool bShow ) 1379 { 1380 sal_Bool bResult = sal_False; 1381 OleEmbeddedObject* pLockObject = NULL; 1382 1383 { 1384 osl::MutexGuard aGuard( m_aMutex ); 1385 1386 if ( m_pUnoOleObject ) 1387 { 1388 pLockObject = m_pUnoOleObject; 1389 pLockObject->acquire(); 1390 } 1391 } 1392 1393 if ( pLockObject ) 1394 { 1395 bResult = pLockObject->OnShowWindow_Impl( bShow ); 1396 pLockObject->release(); 1397 } 1398 1399 return bResult; 1400 } 1401 1402 //---------------------------------------------- 1403 void OleComponent::OnViewChange_Impl( sal_uInt32 dwAspect ) 1404 { 1405 // TODO: check if it is enough or may be saving notifications are required for Visio2000 1406 ::rtl::Reference< OleEmbeddedObject > xLockObject; 1407 1408 { 1409 osl::MutexGuard aGuard( m_aMutex ); 1410 if ( m_pUnoOleObject ) 1411 xLockObject = m_pUnoOleObject; 1412 } 1413 1414 if ( xLockObject.is() ) 1415 { 1416 uno::Reference < awt::XRequestCallback > xRequestCallback( 1417 m_xFactory->createInstance( 1418 ::rtl::OUString::createFromAscii("com.sun.star.awt.AsyncCallback") ), 1419 uno::UNO_QUERY ); 1420 xRequestCallback->addCallback( new MainThreadNotificationRequest( xLockObject, OLECOMP_ONVIEWCHANGE, dwAspect ), uno::Any() ); 1421 } 1422 } 1423 1424 //---------------------------------------------- 1425 void OleComponent::OnClose_Impl() 1426 { 1427 ::rtl::Reference< OleEmbeddedObject > xLockObject; 1428 1429 { 1430 osl::MutexGuard aGuard( m_aMutex ); 1431 if ( m_pUnoOleObject ) 1432 xLockObject = m_pUnoOleObject; 1433 } 1434 1435 if ( xLockObject.is() ) 1436 { 1437 uno::Reference < awt::XRequestCallback > xRequestCallback( 1438 m_xFactory->createInstance( 1439 ::rtl::OUString::createFromAscii("com.sun.star.awt.AsyncCallback") ), 1440 uno::UNO_QUERY ); 1441 xRequestCallback->addCallback( new MainThreadNotificationRequest( xLockObject, OLECOMP_ONCLOSE ), uno::Any() ); 1442 } 1443 } 1444 1445 // XCloseable 1446 //---------------------------------------------- 1447 void SAL_CALL OleComponent::close( sal_Bool bDeliverOwnership ) 1448 throw ( util::CloseVetoException, 1449 uno::RuntimeException ) 1450 { 1451 ::osl::MutexGuard aGuard( m_aMutex ); 1452 if ( m_bDisposed ) 1453 throw lang::DisposedException(); // TODO 1454 1455 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) ); 1456 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) ); 1457 1458 if ( m_pInterfaceContainer ) 1459 { 1460 ::cppu::OInterfaceContainerHelper* pContainer = 1461 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >* ) NULL ) ); 1462 if ( pContainer != NULL ) 1463 { 1464 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); 1465 while ( pIterator.hasMoreElements() ) 1466 { 1467 try 1468 { 1469 ( (util::XCloseListener* )pIterator.next() )->queryClosing( aSource, bDeliverOwnership ); 1470 } 1471 catch( uno::RuntimeException& ) 1472 { 1473 pIterator.remove(); 1474 } 1475 } 1476 } 1477 1478 pContainer = m_pInterfaceContainer->getContainer( 1479 ::getCppuType( ( const uno::Reference< util::XCloseListener >* ) NULL ) ); 1480 if ( pContainer != NULL ) 1481 { 1482 ::cppu::OInterfaceIteratorHelper pCloseIterator( *pContainer ); 1483 while ( pCloseIterator.hasMoreElements() ) 1484 { 1485 try 1486 { 1487 ( (util::XCloseListener* )pCloseIterator.next() )->notifyClosing( aSource ); 1488 } 1489 catch( uno::RuntimeException& ) 1490 { 1491 pCloseIterator.remove(); 1492 } 1493 } 1494 } 1495 } 1496 1497 Dispose(); 1498 } 1499 1500 //---------------------------------------------- 1501 void SAL_CALL OleComponent::addCloseListener( const uno::Reference< util::XCloseListener >& xListener ) 1502 throw ( uno::RuntimeException ) 1503 { 1504 ::osl::MutexGuard aGuard( m_aMutex ); 1505 if ( m_bDisposed ) 1506 throw lang::DisposedException(); // TODO 1507 1508 if ( !m_pInterfaceContainer ) 1509 m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); 1510 1511 m_pInterfaceContainer->addInterface( ::getCppuType( ( const uno::Reference< util::XCloseListener >* )0 ), xListener ); 1512 } 1513 1514 //---------------------------------------------- 1515 void SAL_CALL OleComponent::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener ) 1516 throw ( uno::RuntimeException ) 1517 { 1518 ::osl::MutexGuard aGuard( m_aMutex ); 1519 if ( m_bDisposed ) 1520 throw lang::DisposedException(); // TODO 1521 1522 if ( m_pInterfaceContainer ) 1523 m_pInterfaceContainer->removeInterface( ::getCppuType( ( const uno::Reference< util::XCloseListener >* )0 ), 1524 xListener ); 1525 } 1526 1527 // XTransferable 1528 //---------------------------------------------- 1529 uno::Any SAL_CALL OleComponent::getTransferData( const datatransfer::DataFlavor& aFlavor ) 1530 throw ( datatransfer::UnsupportedFlavorException, 1531 io::IOException, 1532 uno::RuntimeException ) 1533 { 1534 ::osl::MutexGuard aGuard( m_aMutex ); 1535 if ( m_bDisposed ) 1536 throw lang::DisposedException(); // TODO 1537 1538 if ( !m_pNativeImpl->m_pOleObject ) 1539 throw embed::WrongStateException(); // TODO: the object is in wrong state 1540 1541 uno::Any aResult; 1542 sal_Bool bSupportedFlavor = sal_False; 1543 1544 if ( m_pNativeImpl->GraphicalFlavor( aFlavor ) ) 1545 { 1546 DWORD nRequestedAspect = GetAspectFromFlavor( aFlavor ); 1547 // if own icon is set and icon aspect is requested the own icon can be returned directly 1548 1549 ComSmart< IDataObject > pDataObject; 1550 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject ); 1551 if ( FAILED( hr ) || !pDataObject ) 1552 throw io::IOException(); // TODO: transport error code 1553 1554 // The following optimization does not make much sence currently just because 1555 // only one aspect is supported, and only three formats for the aspect are supported 1556 // and moreover it is not guarantied that the once returned format will be supported further 1557 // example - i52106 1558 // TODO/LATER: bring the optimization back when other aspects are supported 1559 1560 // FORMATETC* pFormatEtc = m_pNativeImpl->GetSupportedFormatForAspect( nRequestedAspect ); 1561 // if ( pFormatEtc ) 1562 // { 1563 // STGMEDIUM aMedium; 1564 // hr = pDataObject->GetData( pFormatEtc, &aMedium ); 1565 // if ( SUCCEEDED( hr ) ) 1566 // bSupportedFlavor = m_pNativeImpl->ConvertDataForFlavor( aMedium, aFlavor, aResult ); 1567 // } 1568 // else 1569 { 1570 // the supported format of the application is still not found, find one 1571 for ( sal_Int32 nInd = 0; nInd < FORMATS_NUM; nInd++ ) 1572 { 1573 STGMEDIUM aMedium; 1574 FORMATETC aFormat = pFormatTemplates[nInd]; 1575 aFormat.dwAspect = nRequestedAspect; 1576 1577 hr = pDataObject->GetData( &aFormat, &aMedium ); 1578 if ( SUCCEEDED( hr ) ) 1579 { 1580 bSupportedFlavor = m_pNativeImpl->ConvertDataForFlavor( aMedium, aFlavor, aResult ); 1581 if ( bSupportedFlavor ) 1582 { 1583 // TODO/LATER: bring the optimization back when other aspects are supported 1584 // m_pNativeImpl->AddSupportedFormat( aFormat ); 1585 break; 1586 } 1587 } 1588 } 1589 } 1590 1591 // If the replacement could not be retrieved, the cached representaion should be used 1592 // currently it is not necessary to retrieve it here, so it is implemented in the object itself 1593 } 1594 // TODO: Investigate if there is already the format name 1595 // and whether this format is really required 1596 else if ( aFlavor.DataType == getCppuType( ( const uno::Reference< io::XInputStream >* ) 0 ) 1597 && aFlavor.MimeType.equalsAscii( "application/x-openoffice-contentstream" ) ) 1598 { 1599 // allow to retrieve stream-representation of the object persistence 1600 bSupportedFlavor = sal_True; 1601 uno::Reference < io::XStream > xTempFileStream( 1602 m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 1603 uno::UNO_QUERY ); 1604 1605 if ( !xTempFileStream.is() ) 1606 throw uno::RuntimeException(); // TODO 1607 1608 uno::Reference< io::XOutputStream > xTempOutStream = xTempFileStream->getOutputStream(); 1609 uno::Reference< io::XInputStream > xTempInStream = xTempFileStream->getInputStream(); 1610 if ( xTempOutStream.is() && xTempInStream.is() ) 1611 { 1612 OSL_ENSURE( m_pUnoOleObject, "Unexpected object absence!" ); 1613 if ( !m_pUnoOleObject ) 1614 throw uno::RuntimeException(); 1615 1616 m_pUnoOleObject->StoreObjectToStream( xTempOutStream ); 1617 1618 xTempOutStream->closeOutput(); 1619 xTempOutStream = uno::Reference< io::XOutputStream >(); 1620 } 1621 else 1622 throw io::IOException(); // TODO: 1623 1624 aResult <<= xTempInStream; 1625 } 1626 1627 if ( !bSupportedFlavor ) 1628 throw datatransfer::UnsupportedFlavorException(); 1629 1630 return aResult; 1631 } 1632 1633 //---------------------------------------------- 1634 uno::Sequence< datatransfer::DataFlavor > SAL_CALL OleComponent::getTransferDataFlavors() 1635 throw ( uno::RuntimeException ) 1636 { 1637 ::osl::MutexGuard aGuard( m_aMutex ); 1638 if ( m_bDisposed ) 1639 throw lang::DisposedException(); // TODO 1640 1641 if ( !m_pNativeImpl->m_pOleObject ) 1642 throw embed::WrongStateException(); // TODO: the object is in wrong state 1643 1644 RetrieveObjectDataFlavors_Impl(); 1645 1646 return m_aDataFlavors; 1647 } 1648 1649 //---------------------------------------------- 1650 sal_Bool SAL_CALL OleComponent::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor ) 1651 throw ( uno::RuntimeException ) 1652 { 1653 ::osl::MutexGuard aGuard( m_aMutex ); 1654 if ( m_bDisposed ) 1655 throw lang::DisposedException(); // TODO 1656 1657 if ( !m_pNativeImpl->m_pOleObject ) 1658 throw embed::WrongStateException(); // TODO: the object is in wrong state 1659 1660 if ( !m_aDataFlavors.getLength() ) 1661 { 1662 RetrieveObjectDataFlavors_Impl(); 1663 } 1664 1665 for ( sal_Int32 nInd = 0; nInd < m_aDataFlavors.getLength(); nInd++ ) 1666 if ( m_aDataFlavors[nInd].MimeType.equals( aFlavor.MimeType ) && m_aDataFlavors[nInd].DataType == aFlavor.DataType ) 1667 return sal_True; 1668 1669 return sal_False; 1670 } 1671 1672 void SAL_CALL OleComponent::dispose() throw (::com::sun::star::uno::RuntimeException) 1673 { 1674 try 1675 { 1676 close( sal_True ); 1677 } 1678 catch ( uno::Exception& ) 1679 { 1680 } 1681 } 1682 1683 void SAL_CALL OleComponent::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) 1684 throw ( uno::RuntimeException ) 1685 { 1686 ::osl::MutexGuard aGuard( m_aMutex ); 1687 if ( m_bDisposed ) 1688 throw lang::DisposedException(); // TODO 1689 1690 if ( !m_pInterfaceContainer ) 1691 m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); 1692 1693 m_pInterfaceContainer->addInterface( ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener ); 1694 } 1695 1696 //---------------------------------------------- 1697 void SAL_CALL OleComponent::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) 1698 throw ( uno::RuntimeException ) 1699 { 1700 ::osl::MutexGuard aGuard( m_aMutex ); 1701 if ( m_bDisposed ) 1702 throw lang::DisposedException(); // TODO 1703 1704 if ( m_pInterfaceContainer ) 1705 m_pInterfaceContainer->removeInterface( ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), 1706 xListener ); 1707 } 1708 1709 sal_Int64 SAL_CALL OleComponent::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException) 1710 { 1711 try 1712 { 1713 uno::Sequence < sal_Int8 > aCLSID = GetCLSID(); 1714 if ( MimeConfigurationHelper::ClassIDsEqual( aIdentifier, aCLSID ) ) 1715 return (sal_Int64) (IUnknown*) m_pNativeImpl->m_pObj; 1716 1717 // compatibility hack for old versions: CLSID was used in wrong order (SvGlobalName order) 1718 sal_Int32 nLength = aIdentifier.getLength(); 1719 if ( nLength == 16 ) 1720 { 1721 for ( sal_Int32 n=8; n<16; n++ ) 1722 if ( aIdentifier[n] != aCLSID[n] ) 1723 return 0; 1724 if ( aIdentifier[7] == aCLSID[6] && 1725 aIdentifier[6] == aCLSID[7] && 1726 aIdentifier[5] == aCLSID[4] && 1727 aIdentifier[4] == aCLSID[5] && 1728 aIdentifier[3] == aCLSID[0] && 1729 aIdentifier[2] == aCLSID[1] && 1730 aIdentifier[1] == aCLSID[2] && 1731 aIdentifier[0] == aCLSID[3] ) 1732 return (sal_Int64) (IUnknown*) m_pNativeImpl->m_pObj; 1733 } 1734 } 1735 catch ( uno::Exception& ) 1736 { 1737 } 1738 1739 return 0; 1740 } 1741 1742 sal_Bool SAL_CALL OleComponent::isModified() throw (::com::sun::star::uno::RuntimeException) 1743 { 1744 return m_bModified; 1745 } 1746 1747 void SAL_CALL OleComponent::setModified( sal_Bool bModified ) 1748 throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException) 1749 { 1750 m_bModified = bModified; 1751 1752 if ( bModified && m_pInterfaceContainer ) 1753 { 1754 ::cppu::OInterfaceContainerHelper* pContainer = 1755 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XModifyListener >* ) NULL ) ); 1756 if ( pContainer != NULL ) 1757 { 1758 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); 1759 while ( pIterator.hasMoreElements() ) 1760 { 1761 try 1762 { 1763 lang::EventObject aEvent( (util::XModifiable*) this ); 1764 ((util::XModifyListener*)pIterator.next())->modified( aEvent ); 1765 } 1766 catch( uno::RuntimeException& ) 1767 { 1768 pIterator.remove(); 1769 } 1770 } 1771 } 1772 } 1773 } 1774 1775 void SAL_CALL OleComponent::addModifyListener( const com::sun::star::uno::Reference < com::sun::star::util::XModifyListener >& xListener ) throw(::com::sun::star::uno::RuntimeException) 1776 { 1777 ::osl::MutexGuard aGuard( m_aMutex ); 1778 if ( m_bDisposed ) 1779 throw lang::DisposedException(); // TODO 1780 1781 if ( !m_pInterfaceContainer ) 1782 m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex ); 1783 1784 m_pInterfaceContainer->addInterface( ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), xListener ); 1785 } 1786 1787 void SAL_CALL OleComponent::removeModifyListener( const com::sun::star::uno::Reference < com::sun::star::util::XModifyListener >& xListener) throw(::com::sun::star::uno::RuntimeException) 1788 { 1789 ::osl::MutexGuard aGuard( m_aMutex ); 1790 if ( m_bDisposed ) 1791 throw lang::DisposedException(); // TODO 1792 1793 if ( m_pInterfaceContainer ) 1794 m_pInterfaceContainer->removeInterface( ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), 1795 xListener ); 1796 } 1797 1798