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