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
OwnRelease()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:
ComSmart()71 ComSmart()
72 : m_pInterface( NULL )
73 {}
74
ComSmart(const ComSmart<T> & rObj)75 ComSmart( const ComSmart<T>& rObj )
76 : m_pInterface( rObj.m_pInterface )
77 {
78 if ( m_pInterface != NULL )
79 m_pInterface->AddRef();
80 }
81
ComSmart(T * pInterface)82 ComSmart( T* pInterface )
83 : m_pInterface( pInterface )
84 {
85 if ( m_pInterface != NULL )
86 m_pInterface->AddRef();
87 }
88
~ComSmart()89 ~ComSmart()
90 {
91 OwnRelease();
92 }
93
operator =(const ComSmart<T> & rObj)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
operator =(T * pInterface)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
operator T*() const118 operator T*() const
119 {
120 return m_pInterface;
121 }
122
operator *() const123 T& operator*() const
124 {
125 return *m_pInterface;
126 }
127
operator &()128 T** operator&()
129 {
130 OwnRelease();
131
132 m_pInterface = NULL;
133
134 return &m_pInterface;
135 }
136
operator ->() const137 T* operator->() const
138 {
139 return m_pInterface;
140 }
141
operator ==(const ComSmart<T> & rObj) const142 BOOL operator==( const ComSmart<T>& rObj ) const
143 {
144 return ( m_pInterface == rObj.m_pInterface );
145 }
146
operator !=(const ComSmart<T> & rObj) const147 BOOL operator!=( const ComSmart<T>& rObj ) const
148 {
149 return ( m_pInterface != rObj.m_pInterface );
150 }
151
operator ==(const T * pInterface) const152 BOOL operator==( const T* pInterface ) const
153 {
154 return ( m_pInterface == pInterface );
155 }
156
operator !=(const T * pInterface) const157 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
OleComponentNative_ImplOleComponentNative_Impl190 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 //----------------------------------------------
GetAspectFromFlavor(const datatransfer::DataFlavor & aFlavor)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 //----------------------------------------------
GetFlavorSuffixFromAspect(DWORD nAsp)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 //----------------------------------------------
OpenIStorageFromURL_Impl(const::rtl::OUString & aURL,IStorage ** ppIStorage)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 happened
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 //----------------------------------------------
ConvertDataForFlavor(const STGMEDIUM & aMedium,const datatransfer::DataFlavor & aFlavor,uno::Any & aResult)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 //----------------------------------------------
GraphicalFlavor(const datatransfer::DataFlavor & aFlavor)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 //----------------------------------------------
GetClassIDFromSequence_Impl(uno::Sequence<sal_Int8> aSeq,CLSID & aResult)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 //----------------------------------------------
WinAccToVcl_Impl(const sal_Unicode * pStr)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 //----------------------------------------------
OleComponent(const uno::Reference<lang::XMultiServiceFactory> & xFactory,OleEmbeddedObject * pUnoOleObject)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 successfully 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 //----------------------------------------------
~OleComponent()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 //----------------------------------------------
AddSupportedFormat(const FORMATETC & aFormatEtc)487 void OleComponentNative_Impl::AddSupportedFormat( const FORMATETC& aFormatEtc )
488 {
489 FORMATETC* pFormatToInsert = new FORMATETC( aFormatEtc );
490 m_aFormatsList.push_back( pFormatToInsert );
491 }
492
493 //----------------------------------------------
GetSupportedFormatForAspect(sal_uInt32 nRequestedAspect)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 //----------------------------------------------
Dispose()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 //----------------------------------------------
disconnectEmbeddedObject()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 //----------------------------------------------
CreateNewIStorage_Impl()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 happened
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 //----------------------------------------------
GetFlavorsForAspects(sal_uInt32 nSupportedAspects)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 //----------------------------------------------
RetrieveObjectDataFlavors_Impl()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 //----------------------------------------------
InitializeObject_Impl()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 really 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 //----------------------------------------------
LoadEmbeddedObject(const::rtl::OUString & aTempURL)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 //----------------------------------------------
CreateObjectFromClipboard()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 //----------------------------------------------
CreateNewEmbeddedObject(const uno::Sequence<sal_Int8> & aSeqCLSID)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 //----------------------------------------------
CreateObjectFromData(const uno::Reference<datatransfer::XTransferable> &)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 //----------------------------------------------
CreateObjectFromFile(const::rtl::OUString & aFileURL)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 happened
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 //----------------------------------------------
CreateLinkFromFile(const::rtl::OUString & aFileURL)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 happened
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 //----------------------------------------------
InitEmbeddedCopyOfLink(OleComponent * pOleLinkComponent)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 //----------------------------------------------
RunObject()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 //----------------------------------------------
CalculateWithFactor(const awt::Size & aSize,const awt::Size & aMultiplier,const awt::Size & aDivisor)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 //----------------------------------------------
CloseObject()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 //----------------------------------------------
GetVerbList()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 //----------------------------------------------
ExecuteVerb(sal_Int32 nVerbID)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 //----------------------------------------------
SetHostName(const::rtl::OUString &,const::rtl::OUString &)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 //----------------------------------------------
SetExtent(const awt::Size & aVisAreaSize,sal_Int64 nAspect)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 //----------------------------------------------
GetExtent(sal_Int64 nAspect)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 // i113605, to release storge medium
1209 if ( SUCCEEDED( hr ) )
1210 ::ReleaseStgMedium(&aMedium);
1211 }
1212 }
1213
1214 if ( !bGotSize )
1215 throw lang::IllegalArgumentException();
1216
1217 return aSize;
1218 }
1219
1220 //----------------------------------------------
GetCachedExtent(sal_Int64 nAspect)1221 awt::Size OleComponent::GetCachedExtent( sal_Int64 nAspect )
1222 {
1223 if ( !m_pNativeImpl->m_pOleObject )
1224 throw embed::WrongStateException(); // TODO: the object is in wrong state
1225
1226 DWORD nMSAspect = ( DWORD )nAspect; // first 32 bits are for MS aspects
1227 SIZEL aSize;
1228
1229 HRESULT hr = m_pNativeImpl->m_pViewObject2->GetExtent( nMSAspect, -1, NULL, &aSize );
1230
1231 if ( FAILED( hr ) )
1232 {
1233 // TODO/LATER: is it correct?
1234 // if there is no appropriate cache for the aspect, OLE_E_BLANK error code is returned
1235 // if ( hr == OLE_E_BLANK )
1236 // throw lang::IllegalArgumentException();
1237 //else
1238 // throw io::IOException(); // TODO
1239
1240 throw lang::IllegalArgumentException();
1241 }
1242
1243 return awt::Size( aSize.cx, aSize.cy );
1244 }
1245
1246 //----------------------------------------------
GetReccomendedExtent(sal_Int64 nAspect)1247 awt::Size OleComponent::GetReccomendedExtent( sal_Int64 nAspect )
1248 {
1249 if ( !m_pNativeImpl->m_pOleObject )
1250 throw embed::WrongStateException(); // TODO: the object is in wrong state
1251
1252 DWORD nMSAspect = ( DWORD )nAspect; // first 32 bits are for MS aspects
1253 SIZEL aSize;
1254 HRESULT hr = m_pNativeImpl->m_pOleObject->GetExtent( nMSAspect, &aSize );
1255 if ( FAILED( hr ) )
1256 throw lang::IllegalArgumentException();
1257
1258 return awt::Size( aSize.cx, aSize.cy );
1259 }
1260
1261 //----------------------------------------------
GetMiscStatus(sal_Int64 nAspect)1262 sal_Int64 OleComponent::GetMiscStatus( sal_Int64 nAspect )
1263 {
1264 if ( !m_pNativeImpl->m_pOleObject )
1265 throw embed::WrongStateException(); // TODO: the object is in wrong state
1266
1267 sal_uInt32 nResult;
1268 m_pNativeImpl->m_pOleObject->GetMiscStatus( ( DWORD )nAspect, ( DWORD* )&nResult );
1269 return ( sal_Int64 )nResult; // first 32 bits are for MS flags
1270 }
1271
1272 //----------------------------------------------
GetCLSID()1273 uno::Sequence< sal_Int8 > OleComponent::GetCLSID()
1274 {
1275 if ( !m_pNativeImpl->m_pOleObject )
1276 throw embed::WrongStateException(); // TODO: the object is in wrong state
1277
1278 GUID aCLSID;
1279 HRESULT hr = m_pNativeImpl->m_pOleObject->GetUserClassID( &aCLSID );
1280 if ( FAILED( hr ) )
1281 throw io::IOException(); // TODO:
1282
1283 return MimeConfigurationHelper::GetSequenceClassID( aCLSID.Data1, aCLSID.Data2, aCLSID.Data3,
1284 aCLSID.Data4[0], aCLSID.Data4[1],
1285 aCLSID.Data4[2], aCLSID.Data4[3],
1286 aCLSID.Data4[4], aCLSID.Data4[5],
1287 aCLSID.Data4[6], aCLSID.Data4[7] );
1288 }
1289
1290 //----------------------------------------------
IsDirty()1291 sal_Bool OleComponent::IsDirty()
1292 {
1293 if ( !m_pNativeImpl->m_pOleObject )
1294 throw embed::WrongStateException(); // TODO: the object is in wrong state
1295
1296 if ( IsWorkaroundActive() )
1297 return sal_True;
1298
1299 ComSmart< IPersistStorage > pPersistStorage;
1300 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IPersistStorage, (void**)&pPersistStorage );
1301 if ( FAILED( hr ) || !pPersistStorage )
1302 throw io::IOException(); // TODO
1303
1304 hr = pPersistStorage->IsDirty();
1305 return ( hr != S_FALSE );
1306 }
1307
1308 //----------------------------------------------
StoreOwnTmpIfNecessary()1309 void OleComponent::StoreOwnTmpIfNecessary()
1310 {
1311 if ( !m_pNativeImpl->m_pOleObject )
1312 throw embed::WrongStateException(); // TODO: the object is in wrong state
1313
1314 ComSmart< IPersistStorage > pPersistStorage;
1315 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IPersistStorage, (void**)&pPersistStorage );
1316 if ( FAILED( hr ) || !pPersistStorage )
1317 throw io::IOException(); // TODO
1318
1319 if ( m_bWorkaroundActive || pPersistStorage->IsDirty() != S_FALSE )
1320 {
1321 hr = OleSave( pPersistStorage, m_pNativeImpl->m_pIStorage, TRUE );
1322 if ( FAILED( hr ) )
1323 {
1324 // Till now was required only for AcrobatReader7.0.8
1325 GUID aCLSID;
1326 hr = m_pNativeImpl->m_pOleObject->GetUserClassID( &aCLSID );
1327 if ( FAILED( hr ) )
1328 throw io::IOException(); // TODO
1329
1330 hr = WriteClassStg( m_pNativeImpl->m_pIStorage, aCLSID );
1331 if ( FAILED( hr ) )
1332 throw io::IOException(); // TODO
1333
1334 // the result of the following call is not checked because some objects, for example AcrobatReader7.0.8
1335 // return error even in case the saving was done correctly
1336 hr = pPersistStorage->Save( m_pNativeImpl->m_pIStorage, TRUE );
1337
1338 // another workaround for AcrobatReader7.0.8 object, this object might think that it is not changed
1339 // when it has been created from file, although it must be saved
1340 m_bWorkaroundActive = sal_True;
1341 }
1342
1343 hr = m_pNativeImpl->m_pIStorage->Commit( STGC_DEFAULT );
1344 if ( FAILED( hr ) )
1345 throw io::IOException(); // TODO
1346
1347 hr = pPersistStorage->SaveCompleted( NULL );
1348 if ( FAILED( hr ) && hr != E_UNEXPECTED )
1349 throw io::IOException(); // TODO
1350
1351 // STATSTG aStat;
1352 // m_pNativeImpl->m_pIStorage->Stat( &aStat, STATFLAG_NONAME );
1353 }
1354 }
1355
1356 //----------------------------------------------
SaveObject_Impl()1357 sal_Bool OleComponent::SaveObject_Impl()
1358 {
1359 sal_Bool bResult = sal_False;
1360 OleEmbeddedObject* pLockObject = NULL;
1361
1362 {
1363 osl::MutexGuard aGuard( m_aMutex );
1364 if ( m_pUnoOleObject )
1365 {
1366 pLockObject = m_pUnoOleObject;
1367 pLockObject->acquire();
1368 }
1369 }
1370
1371 if ( pLockObject )
1372 {
1373 bResult = pLockObject->SaveObject_Impl();
1374 pLockObject->release();
1375 }
1376
1377 return bResult;
1378 }
1379
1380 //----------------------------------------------
OnShowWindow_Impl(bool bShow)1381 sal_Bool OleComponent::OnShowWindow_Impl( bool bShow )
1382 {
1383 sal_Bool bResult = sal_False;
1384 OleEmbeddedObject* pLockObject = NULL;
1385
1386 {
1387 osl::MutexGuard aGuard( m_aMutex );
1388
1389 if ( m_pUnoOleObject )
1390 {
1391 pLockObject = m_pUnoOleObject;
1392 pLockObject->acquire();
1393 }
1394 }
1395
1396 if ( pLockObject )
1397 {
1398 bResult = pLockObject->OnShowWindow_Impl( bShow );
1399 pLockObject->release();
1400 }
1401
1402 return bResult;
1403 }
1404
1405 //----------------------------------------------
OnViewChange_Impl(sal_uInt32 dwAspect)1406 void OleComponent::OnViewChange_Impl( sal_uInt32 dwAspect )
1407 {
1408 // TODO: check if it is enough or may be saving notifications are required for Visio2000
1409 ::rtl::Reference< OleEmbeddedObject > xLockObject;
1410
1411 {
1412 osl::MutexGuard aGuard( m_aMutex );
1413 if ( m_pUnoOleObject )
1414 xLockObject = m_pUnoOleObject;
1415 }
1416
1417 if ( xLockObject.is() )
1418 {
1419 uno::Reference < awt::XRequestCallback > xRequestCallback(
1420 m_xFactory->createInstance(
1421 ::rtl::OUString::createFromAscii("com.sun.star.awt.AsyncCallback") ),
1422 uno::UNO_QUERY );
1423 xRequestCallback->addCallback( new MainThreadNotificationRequest( xLockObject, OLECOMP_ONVIEWCHANGE, dwAspect ), uno::Any() );
1424 }
1425 }
1426
1427 //----------------------------------------------
OnClose_Impl()1428 void OleComponent::OnClose_Impl()
1429 {
1430 ::rtl::Reference< OleEmbeddedObject > xLockObject;
1431
1432 {
1433 osl::MutexGuard aGuard( m_aMutex );
1434 if ( m_pUnoOleObject )
1435 xLockObject = m_pUnoOleObject;
1436 }
1437
1438 if ( xLockObject.is() )
1439 {
1440 uno::Reference < awt::XRequestCallback > xRequestCallback(
1441 m_xFactory->createInstance(
1442 ::rtl::OUString::createFromAscii("com.sun.star.awt.AsyncCallback") ),
1443 uno::UNO_QUERY );
1444 xRequestCallback->addCallback( new MainThreadNotificationRequest( xLockObject, OLECOMP_ONCLOSE ), uno::Any() );
1445 }
1446 }
1447
1448 // XCloseable
1449 //----------------------------------------------
close(sal_Bool bDeliverOwnership)1450 void SAL_CALL OleComponent::close( sal_Bool bDeliverOwnership )
1451 throw ( util::CloseVetoException,
1452 uno::RuntimeException )
1453 {
1454 ::osl::MutexGuard aGuard( m_aMutex );
1455 if ( m_bDisposed )
1456 throw lang::DisposedException(); // TODO
1457
1458 uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >( this ) );
1459 lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >( this ) );
1460
1461 if ( m_pInterfaceContainer )
1462 {
1463 ::cppu::OInterfaceContainerHelper* pContainer =
1464 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XCloseListener >* ) NULL ) );
1465 if ( pContainer != NULL )
1466 {
1467 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
1468 while ( pIterator.hasMoreElements() )
1469 {
1470 try
1471 {
1472 ( (util::XCloseListener* )pIterator.next() )->queryClosing( aSource, bDeliverOwnership );
1473 }
1474 catch( uno::RuntimeException& )
1475 {
1476 pIterator.remove();
1477 }
1478 }
1479 }
1480
1481 pContainer = m_pInterfaceContainer->getContainer(
1482 ::getCppuType( ( const uno::Reference< util::XCloseListener >* ) NULL ) );
1483 if ( pContainer != NULL )
1484 {
1485 ::cppu::OInterfaceIteratorHelper pCloseIterator( *pContainer );
1486 while ( pCloseIterator.hasMoreElements() )
1487 {
1488 try
1489 {
1490 ( (util::XCloseListener* )pCloseIterator.next() )->notifyClosing( aSource );
1491 }
1492 catch( uno::RuntimeException& )
1493 {
1494 pCloseIterator.remove();
1495 }
1496 }
1497 }
1498 }
1499
1500 Dispose();
1501 }
1502
1503 //----------------------------------------------
addCloseListener(const uno::Reference<util::XCloseListener> & xListener)1504 void SAL_CALL OleComponent::addCloseListener( const uno::Reference< util::XCloseListener >& xListener )
1505 throw ( uno::RuntimeException )
1506 {
1507 ::osl::MutexGuard aGuard( m_aMutex );
1508 if ( m_bDisposed )
1509 throw lang::DisposedException(); // TODO
1510
1511 if ( !m_pInterfaceContainer )
1512 m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
1513
1514 m_pInterfaceContainer->addInterface( ::getCppuType( ( const uno::Reference< util::XCloseListener >* )0 ), xListener );
1515 }
1516
1517 //----------------------------------------------
removeCloseListener(const uno::Reference<util::XCloseListener> & xListener)1518 void SAL_CALL OleComponent::removeCloseListener( const uno::Reference< util::XCloseListener >& xListener )
1519 throw ( uno::RuntimeException )
1520 {
1521 ::osl::MutexGuard aGuard( m_aMutex );
1522 if ( m_bDisposed )
1523 throw lang::DisposedException(); // TODO
1524
1525 if ( m_pInterfaceContainer )
1526 m_pInterfaceContainer->removeInterface( ::getCppuType( ( const uno::Reference< util::XCloseListener >* )0 ),
1527 xListener );
1528 }
1529
1530 // XTransferable
1531 //----------------------------------------------
getTransferData(const datatransfer::DataFlavor & aFlavor)1532 uno::Any SAL_CALL OleComponent::getTransferData( const datatransfer::DataFlavor& aFlavor )
1533 throw ( datatransfer::UnsupportedFlavorException,
1534 io::IOException,
1535 uno::RuntimeException )
1536 {
1537 ::osl::MutexGuard aGuard( m_aMutex );
1538 if ( m_bDisposed )
1539 throw lang::DisposedException(); // TODO
1540
1541 if ( !m_pNativeImpl->m_pOleObject )
1542 throw embed::WrongStateException(); // TODO: the object is in wrong state
1543
1544 uno::Any aResult;
1545 sal_Bool bSupportedFlavor = sal_False;
1546
1547 if ( m_pNativeImpl->GraphicalFlavor( aFlavor ) )
1548 {
1549 DWORD nRequestedAspect = GetAspectFromFlavor( aFlavor );
1550 // if own icon is set and icon aspect is requested the own icon can be returned directly
1551
1552 ComSmart< IDataObject > pDataObject;
1553 HRESULT hr = m_pNativeImpl->m_pObj->QueryInterface( IID_IDataObject, (void**)&pDataObject );
1554 if ( FAILED( hr ) || !pDataObject )
1555 throw io::IOException(); // TODO: transport error code
1556
1557 // The following optimization does not make much sense currently just because
1558 // only one aspect is supported, and only three formats for the aspect are supported
1559 // and moreover it is not guarantied that the once returned format will be supported further
1560 // example - i52106
1561 // TODO/LATER: bring the optimization back when other aspects are supported
1562
1563 // FORMATETC* pFormatEtc = m_pNativeImpl->GetSupportedFormatForAspect( nRequestedAspect );
1564 // if ( pFormatEtc )
1565 // {
1566 // STGMEDIUM aMedium;
1567 // hr = pDataObject->GetData( pFormatEtc, &aMedium );
1568 // if ( SUCCEEDED( hr ) )
1569 // bSupportedFlavor = m_pNativeImpl->ConvertDataForFlavor( aMedium, aFlavor, aResult );
1570 // }
1571 // else
1572 {
1573 // the supported format of the application is still not found, find one
1574 for ( sal_Int32 nInd = 0; nInd < FORMATS_NUM; nInd++ )
1575 {
1576 STGMEDIUM aMedium;
1577 FORMATETC aFormat = pFormatTemplates[nInd];
1578 aFormat.dwAspect = nRequestedAspect;
1579
1580 hr = pDataObject->GetData( &aFormat, &aMedium );
1581 if ( SUCCEEDED( hr ) )
1582 {
1583 bSupportedFlavor = m_pNativeImpl->ConvertDataForFlavor( aMedium, aFlavor, aResult );
1584 ::ReleaseStgMedium(&aMedium); // i113605, to release storge medium
1585 if ( bSupportedFlavor )
1586 {
1587 // TODO/LATER: bring the optimization back when other aspects are supported
1588 // m_pNativeImpl->AddSupportedFormat( aFormat );
1589 break;
1590 }
1591 }
1592 }
1593 }
1594
1595 // If the replacement could not be retrieved, the cached representaion should be used
1596 // currently it is not necessary to retrieve it here, so it is implemented in the object itself
1597 }
1598 // TODO: Investigate if there is already the format name
1599 // and whether this format is really required
1600 else if ( aFlavor.DataType == getCppuType( ( const uno::Reference< io::XInputStream >* ) 0 )
1601 && aFlavor.MimeType.equalsAscii( "application/x-openoffice-contentstream" ) )
1602 {
1603 // allow to retrieve stream-representation of the object persistence
1604 bSupportedFlavor = sal_True;
1605 uno::Reference < io::XStream > xTempFileStream(
1606 m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ),
1607 uno::UNO_QUERY );
1608
1609 if ( !xTempFileStream.is() )
1610 throw uno::RuntimeException(); // TODO
1611
1612 uno::Reference< io::XOutputStream > xTempOutStream = xTempFileStream->getOutputStream();
1613 uno::Reference< io::XInputStream > xTempInStream = xTempFileStream->getInputStream();
1614 if ( xTempOutStream.is() && xTempInStream.is() )
1615 {
1616 OSL_ENSURE( m_pUnoOleObject, "Unexpected object absence!" );
1617 if ( !m_pUnoOleObject )
1618 throw uno::RuntimeException();
1619
1620 m_pUnoOleObject->StoreObjectToStream( xTempOutStream );
1621
1622 xTempOutStream->closeOutput();
1623 xTempOutStream = uno::Reference< io::XOutputStream >();
1624 }
1625 else
1626 throw io::IOException(); // TODO:
1627
1628 aResult <<= xTempInStream;
1629 }
1630
1631 if ( !bSupportedFlavor )
1632 throw datatransfer::UnsupportedFlavorException();
1633
1634 return aResult;
1635 }
1636
1637 //----------------------------------------------
getTransferDataFlavors()1638 uno::Sequence< datatransfer::DataFlavor > SAL_CALL OleComponent::getTransferDataFlavors()
1639 throw ( uno::RuntimeException )
1640 {
1641 ::osl::MutexGuard aGuard( m_aMutex );
1642 if ( m_bDisposed )
1643 throw lang::DisposedException(); // TODO
1644
1645 if ( !m_pNativeImpl->m_pOleObject )
1646 throw embed::WrongStateException(); // TODO: the object is in wrong state
1647
1648 RetrieveObjectDataFlavors_Impl();
1649
1650 return m_aDataFlavors;
1651 }
1652
1653 //----------------------------------------------
isDataFlavorSupported(const datatransfer::DataFlavor & aFlavor)1654 sal_Bool SAL_CALL OleComponent::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor )
1655 throw ( uno::RuntimeException )
1656 {
1657 ::osl::MutexGuard aGuard( m_aMutex );
1658 if ( m_bDisposed )
1659 throw lang::DisposedException(); // TODO
1660
1661 if ( !m_pNativeImpl->m_pOleObject )
1662 throw embed::WrongStateException(); // TODO: the object is in wrong state
1663
1664 if ( !m_aDataFlavors.getLength() )
1665 {
1666 RetrieveObjectDataFlavors_Impl();
1667 }
1668
1669 for ( sal_Int32 nInd = 0; nInd < m_aDataFlavors.getLength(); nInd++ )
1670 if ( m_aDataFlavors[nInd].MimeType.equals( aFlavor.MimeType ) && m_aDataFlavors[nInd].DataType == aFlavor.DataType )
1671 return sal_True;
1672
1673 return sal_False;
1674 }
1675
dispose()1676 void SAL_CALL OleComponent::dispose() throw (::com::sun::star::uno::RuntimeException)
1677 {
1678 try
1679 {
1680 close( sal_True );
1681 }
1682 catch ( uno::Exception& )
1683 {
1684 }
1685 }
1686
addEventListener(const uno::Reference<lang::XEventListener> & xListener)1687 void SAL_CALL OleComponent::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
1688 throw ( uno::RuntimeException )
1689 {
1690 ::osl::MutexGuard aGuard( m_aMutex );
1691 if ( m_bDisposed )
1692 throw lang::DisposedException(); // TODO
1693
1694 if ( !m_pInterfaceContainer )
1695 m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
1696
1697 m_pInterfaceContainer->addInterface( ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener );
1698 }
1699
1700 //----------------------------------------------
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)1701 void SAL_CALL OleComponent::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
1702 throw ( uno::RuntimeException )
1703 {
1704 ::osl::MutexGuard aGuard( m_aMutex );
1705 if ( m_bDisposed )
1706 throw lang::DisposedException(); // TODO
1707
1708 if ( m_pInterfaceContainer )
1709 m_pInterfaceContainer->removeInterface( ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ),
1710 xListener );
1711 }
1712
getSomething(const::com::sun::star::uno::Sequence<sal_Int8> & aIdentifier)1713 sal_Int64 SAL_CALL OleComponent::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException)
1714 {
1715 try
1716 {
1717 uno::Sequence < sal_Int8 > aCLSID = GetCLSID();
1718 if ( MimeConfigurationHelper::ClassIDsEqual( aIdentifier, aCLSID ) )
1719 return (sal_Int64) (IUnknown*) m_pNativeImpl->m_pObj;
1720
1721 // compatibility hack for old versions: CLSID was used in wrong order (SvGlobalName order)
1722 sal_Int32 nLength = aIdentifier.getLength();
1723 if ( nLength == 16 )
1724 {
1725 for ( sal_Int32 n=8; n<16; n++ )
1726 if ( aIdentifier[n] != aCLSID[n] )
1727 return 0;
1728 if ( aIdentifier[7] == aCLSID[6] &&
1729 aIdentifier[6] == aCLSID[7] &&
1730 aIdentifier[5] == aCLSID[4] &&
1731 aIdentifier[4] == aCLSID[5] &&
1732 aIdentifier[3] == aCLSID[0] &&
1733 aIdentifier[2] == aCLSID[1] &&
1734 aIdentifier[1] == aCLSID[2] &&
1735 aIdentifier[0] == aCLSID[3] )
1736 return (sal_Int64) (IUnknown*) m_pNativeImpl->m_pObj;
1737 }
1738 }
1739 catch ( uno::Exception& )
1740 {
1741 }
1742
1743 return 0;
1744 }
1745
isModified()1746 sal_Bool SAL_CALL OleComponent::isModified() throw (::com::sun::star::uno::RuntimeException)
1747 {
1748 return m_bModified;
1749 }
1750
setModified(sal_Bool bModified)1751 void SAL_CALL OleComponent::setModified( sal_Bool bModified )
1752 throw (::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
1753 {
1754 m_bModified = bModified;
1755
1756 if ( bModified && m_pInterfaceContainer )
1757 {
1758 ::cppu::OInterfaceContainerHelper* pContainer =
1759 m_pInterfaceContainer->getContainer( ::getCppuType( ( const uno::Reference< util::XModifyListener >* ) NULL ) );
1760 if ( pContainer != NULL )
1761 {
1762 ::cppu::OInterfaceIteratorHelper pIterator( *pContainer );
1763 while ( pIterator.hasMoreElements() )
1764 {
1765 try
1766 {
1767 lang::EventObject aEvent( (util::XModifiable*) this );
1768 ((util::XModifyListener*)pIterator.next())->modified( aEvent );
1769 }
1770 catch( uno::RuntimeException& )
1771 {
1772 pIterator.remove();
1773 }
1774 }
1775 }
1776 }
1777 }
1778
addModifyListener(const com::sun::star::uno::Reference<com::sun::star::util::XModifyListener> & xListener)1779 void SAL_CALL OleComponent::addModifyListener( const com::sun::star::uno::Reference < com::sun::star::util::XModifyListener >& xListener ) throw(::com::sun::star::uno::RuntimeException)
1780 {
1781 ::osl::MutexGuard aGuard( m_aMutex );
1782 if ( m_bDisposed )
1783 throw lang::DisposedException(); // TODO
1784
1785 if ( !m_pInterfaceContainer )
1786 m_pInterfaceContainer = new ::cppu::OMultiTypeInterfaceContainerHelper( m_aMutex );
1787
1788 m_pInterfaceContainer->addInterface( ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), xListener );
1789 }
1790
removeModifyListener(const com::sun::star::uno::Reference<com::sun::star::util::XModifyListener> & xListener)1791 void SAL_CALL OleComponent::removeModifyListener( const com::sun::star::uno::Reference < com::sun::star::util::XModifyListener >& xListener) throw(::com::sun::star::uno::RuntimeException)
1792 {
1793 ::osl::MutexGuard aGuard( m_aMutex );
1794 if ( m_bDisposed )
1795 throw lang::DisposedException(); // TODO
1796
1797 if ( m_pInterfaceContainer )
1798 m_pInterfaceContainer->removeInterface( ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ),
1799 xListener );
1800 }
1801
1802