148123e16SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 348123e16SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 448123e16SAndrew Rist * or more contributor license agreements. See the NOTICE file 548123e16SAndrew Rist * distributed with this work for additional information 648123e16SAndrew Rist * regarding copyright ownership. The ASF licenses this file 748123e16SAndrew Rist * to you under the Apache License, Version 2.0 (the 848123e16SAndrew Rist * "License"); you may not use this file except in compliance 948123e16SAndrew Rist * with the License. You may obtain a copy of the License at 1048123e16SAndrew Rist * 1148123e16SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1248123e16SAndrew Rist * 1348123e16SAndrew Rist * Unless required by applicable law or agreed to in writing, 1448123e16SAndrew Rist * software distributed under the License is distributed on an 1548123e16SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1648123e16SAndrew Rist * KIND, either express or implied. See the License for the 1748123e16SAndrew Rist * specific language governing permissions and limitations 1848123e16SAndrew Rist * under the License. 1948123e16SAndrew Rist * 2048123e16SAndrew Rist *************************************************************/ 2148123e16SAndrew Rist 2248123e16SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dtrans.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //------------------------------------------------------------------------ 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir //------------------------------------------------------------------------ 30cdf0e10cSrcweir #include <sal/types.h> 31cdf0e10cSrcweir #include <rtl/process.h> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #ifndef _DOWRAPPERTRANSFERABLE_HXX_ 34cdf0e10cSrcweir #include "DOTransferable.hxx" 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir #include "..\misc\ImplHelper.hxx" 37cdf0e10cSrcweir #include "..\misc\WinClip.hxx" 38cdf0e10cSrcweir #include "DTransHelper.hxx" 39cdf0e10cSrcweir #include "..\misc\ImplHelper.hxx" 40cdf0e10cSrcweir #include "TxtCnvtHlp.hxx" 41cdf0e10cSrcweir #include "MimeAttrib.hxx" 42cdf0e10cSrcweir #include "FmtFilter.hxx" 43cdf0e10cSrcweir #include "Fetc.hxx" 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir #if(_MSC_VER < 1300) && !defined(__MINGW32__) 47cdf0e10cSrcweir #include <olestd.h> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir 50cdf0e10cSrcweir #define STR2(x) #x 51cdf0e10cSrcweir #define STR(x) STR2(x) 52cdf0e10cSrcweir #define PRAGMA_MSG( msg ) message( __FILE__ "(" STR(__LINE__) "): " #msg ) 53cdf0e10cSrcweir 54cdf0e10cSrcweir //------------------------------------------------------------------------ 55cdf0e10cSrcweir // namespace directives 56cdf0e10cSrcweir //------------------------------------------------------------------------ 57cdf0e10cSrcweir 58cdf0e10cSrcweir using namespace rtl; 59cdf0e10cSrcweir using namespace std; 60cdf0e10cSrcweir using namespace osl; 61cdf0e10cSrcweir using namespace cppu; 62cdf0e10cSrcweir using namespace com::sun::star::uno; 63cdf0e10cSrcweir using namespace com::sun::star::datatransfer; 64cdf0e10cSrcweir using namespace com::sun::star::io; 65cdf0e10cSrcweir using namespace com::sun::star::lang; 66cdf0e10cSrcweir using namespace com::sun::star::container; 67cdf0e10cSrcweir 68cdf0e10cSrcweir //------------------------------------------------------------------------ 69cdf0e10cSrcweir // 70cdf0e10cSrcweir //------------------------------------------------------------------------ 71cdf0e10cSrcweir 72cdf0e10cSrcweir namespace 73cdf0e10cSrcweir { 74cdf0e10cSrcweir const Type CPPUTYPE_SEQINT8 = getCppuType( ( Sequence< sal_Int8 >* )0 ); 75cdf0e10cSrcweir const Type CPPUTYPE_OUSTRING = getCppuType( (OUString*)0 ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir inline 78cdf0e10cSrcweir sal_Bool isValidFlavor( const DataFlavor& aFlavor ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir return ( aFlavor.MimeType.getLength( ) && 81cdf0e10cSrcweir ( ( aFlavor.DataType == CPPUTYPE_SEQINT8 ) || 82cdf0e10cSrcweir ( aFlavor.DataType == CPPUTYPE_OUSTRING ) ) ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir } // end namespace 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir //------------------------------------------------------------------------ 89cdf0e10cSrcweir // ctor 90cdf0e10cSrcweir //------------------------------------------------------------------------ 91cdf0e10cSrcweir 92cdf0e10cSrcweir CDOTransferable::CDOTransferable( 93cdf0e10cSrcweir const Reference< XMultiServiceFactory >& ServiceManager, IDataObjectPtr rDataObject ) : 94cdf0e10cSrcweir m_rDataObject( rDataObject ), 95cdf0e10cSrcweir m_SrvMgr( ServiceManager ), 96cdf0e10cSrcweir m_DataFormatTranslator( m_SrvMgr ), 97cdf0e10cSrcweir m_bUnicodeRegistered( sal_False ), 98cdf0e10cSrcweir m_TxtFormatOnClipboard( CF_INVALID ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir //------------------------------------------------------------------------ 103cdf0e10cSrcweir // 104cdf0e10cSrcweir //------------------------------------------------------------------------ 105cdf0e10cSrcweir 106cdf0e10cSrcweir Any SAL_CALL CDOTransferable::getTransferData( const DataFlavor& aFlavor ) 107cdf0e10cSrcweir throw( UnsupportedFlavorException, IOException, RuntimeException ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir OSL_ASSERT( isValidFlavor( aFlavor ) ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 112cdf0e10cSrcweir 113cdf0e10cSrcweir //------------------------------------------------ 114cdf0e10cSrcweir // convert dataflavor to formatetc 115cdf0e10cSrcweir //------------------------------------------------ 116cdf0e10cSrcweir 117cdf0e10cSrcweir CFormatEtc fetc = m_DataFormatTranslator.getFormatEtcFromDataFlavor( aFlavor ); 118cdf0e10cSrcweir OSL_ASSERT( CF_INVALID != fetc.getClipformat() ); 119cdf0e10cSrcweir 120cdf0e10cSrcweir //------------------------------------------------ 121cdf0e10cSrcweir // get the data from clipboard in a byte stream 122cdf0e10cSrcweir //------------------------------------------------ 123cdf0e10cSrcweir 124cdf0e10cSrcweir ByteSequence_t clipDataStream; 125cdf0e10cSrcweir 126cdf0e10cSrcweir try 127cdf0e10cSrcweir { 128cdf0e10cSrcweir clipDataStream = getClipboardData( fetc ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir catch( UnsupportedFlavorException& ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir if ( m_DataFormatTranslator.isUnicodeTextFormat( fetc.getClipformat( ) ) && 133cdf0e10cSrcweir m_bUnicodeRegistered ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir OUString aUnicodeText = synthesizeUnicodeText( ); 136cdf0e10cSrcweir Any aAny = makeAny( aUnicodeText ); 137cdf0e10cSrcweir return aAny; 138cdf0e10cSrcweir } 139*739826ffSArmin Le Grand else if(CF_DIBV5 == fetc.getClipformat()) 140*739826ffSArmin Le Grand { 141*739826ffSArmin Le Grand // #123407# CF_DIBV5 has priority; if the try to fetch this failed, 142*739826ffSArmin Le Grand // check CF_DIB availability as an alternative 143*739826ffSArmin Le Grand fetc.setClipformat(CF_DIB); 144*739826ffSArmin Le Grand 145*739826ffSArmin Le Grand try 146*739826ffSArmin Le Grand { 147*739826ffSArmin Le Grand clipDataStream = getClipboardData( fetc ); 148*739826ffSArmin Le Grand } 149*739826ffSArmin Le Grand catch( UnsupportedFlavorException& ) 150*739826ffSArmin Le Grand { 151*739826ffSArmin Le Grand throw; // pass through, tried all possibilities 152*739826ffSArmin Le Grand } 153*739826ffSArmin Le Grand } 154cdf0e10cSrcweir else 155cdf0e10cSrcweir throw; // pass through exception 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir //------------------------------------------------ 159cdf0e10cSrcweir // return the data as any 160cdf0e10cSrcweir //------------------------------------------------ 161cdf0e10cSrcweir 162cdf0e10cSrcweir return byteStreamToAny( clipDataStream, aFlavor.DataType ); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir //------------------------------------------------------------------------ 166cdf0e10cSrcweir // getTransferDataFlavors 167cdf0e10cSrcweir //------------------------------------------------------------------------ 168cdf0e10cSrcweir 169cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL CDOTransferable::getTransferDataFlavors( ) 170cdf0e10cSrcweir throw( RuntimeException ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return m_FlavorList; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir //------------------------------------------------------------------------ 176cdf0e10cSrcweir // isDataFlavorSupported 177cdf0e10cSrcweir // returns true if we find a DataFlavor with the same MimeType and 178cdf0e10cSrcweir // DataType 179cdf0e10cSrcweir //------------------------------------------------------------------------ 180cdf0e10cSrcweir 181cdf0e10cSrcweir sal_Bool SAL_CALL CDOTransferable::isDataFlavorSupported( const DataFlavor& aFlavor ) 182cdf0e10cSrcweir throw( RuntimeException ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir OSL_ASSERT( isValidFlavor( aFlavor ) ); 185cdf0e10cSrcweir 186cdf0e10cSrcweir for ( sal_Int32 i = 0; i < m_FlavorList.getLength( ); i++ ) 187cdf0e10cSrcweir if ( compareDataFlavors( aFlavor, m_FlavorList[i] ) ) 188cdf0e10cSrcweir return sal_True; 189cdf0e10cSrcweir 190cdf0e10cSrcweir return sal_False; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir //------------------------------------------------------------------------ 194cdf0e10cSrcweir // helper function 195cdf0e10cSrcweir // the list of datafalvors currently on the clipboard will be initialized 196cdf0e10cSrcweir // only once; if the client of this Transferable will hold a reference 197cdf0e10cSrcweir // to it und the underlying clipboard content changes, the client does 198cdf0e10cSrcweir // possible operate on a invalid list 199cdf0e10cSrcweir // if there is only text on the clipboard we will also offer unicode text 200cdf0e10cSrcweir // an synthesize this format on the fly if requested, to accomplish this 201cdf0e10cSrcweir // we save the first offered text format which we will later use for the 202cdf0e10cSrcweir // conversion 203cdf0e10cSrcweir //------------------------------------------------------------------------ 204cdf0e10cSrcweir 205cdf0e10cSrcweir void SAL_CALL CDOTransferable::initFlavorList( ) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir IEnumFORMATETCPtr pEnumFormatEtc; 208cdf0e10cSrcweir HRESULT hr = m_rDataObject->EnumFormatEtc( DATADIR_GET, &pEnumFormatEtc ); 209cdf0e10cSrcweir if ( SUCCEEDED( hr ) ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir pEnumFormatEtc->Reset( ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir FORMATETC fetc; 214cdf0e10cSrcweir while ( S_FALSE != pEnumFormatEtc->Next( 1, &fetc, NULL ) ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir // we use locales only to determine the 217cdf0e10cSrcweir // charset if there is text on the cliboard 218cdf0e10cSrcweir // we don't offer this format 219cdf0e10cSrcweir if ( CF_LOCALE == fetc.cfFormat ) 220cdf0e10cSrcweir continue; 221cdf0e10cSrcweir 222cdf0e10cSrcweir DataFlavor aFlavor = formatEtcToDataFlavor( fetc ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir // if text or oemtext is offered we also pretend to have unicode text 225cdf0e10cSrcweir if ( m_DataFormatTranslator.isOemOrAnsiTextFormat( fetc.cfFormat ) && 226cdf0e10cSrcweir !m_bUnicodeRegistered ) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir addSupportedFlavor( aFlavor ); 229cdf0e10cSrcweir 230cdf0e10cSrcweir m_TxtFormatOnClipboard = fetc.cfFormat; 231cdf0e10cSrcweir m_bUnicodeRegistered = sal_True; 232cdf0e10cSrcweir 233cdf0e10cSrcweir // register unicode text as accompany format 234cdf0e10cSrcweir aFlavor = formatEtcToDataFlavor( 235cdf0e10cSrcweir m_DataFormatTranslator.getFormatEtcForClipformat( CF_UNICODETEXT ) ); 236cdf0e10cSrcweir addSupportedFlavor( aFlavor ); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else if ( (CF_UNICODETEXT == fetc.cfFormat) && !m_bUnicodeRegistered ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir addSupportedFlavor( aFlavor ); 241cdf0e10cSrcweir m_bUnicodeRegistered = sal_True; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir else 244cdf0e10cSrcweir addSupportedFlavor( aFlavor ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir // see MSDN IEnumFORMATETC 247cdf0e10cSrcweir CoTaskMemFree( fetc.ptd ); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir //------------------------------------------------------------------------ 253cdf0e10cSrcweir // 254cdf0e10cSrcweir //------------------------------------------------------------------------ 255cdf0e10cSrcweir 256cdf0e10cSrcweir inline 257cdf0e10cSrcweir void SAL_CALL CDOTransferable::addSupportedFlavor( const DataFlavor& aFlavor ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir // we ignore all formats that couldn't be translated 260cdf0e10cSrcweir if ( aFlavor.MimeType.getLength( ) ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir OSL_ASSERT( isValidFlavor( aFlavor ) ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir m_FlavorList.realloc( m_FlavorList.getLength( ) + 1 ); 265cdf0e10cSrcweir m_FlavorList[m_FlavorList.getLength( ) - 1] = aFlavor; 266cdf0e10cSrcweir } 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir //------------------------------------------------------------------------ 270cdf0e10cSrcweir // helper function 271cdf0e10cSrcweir //------------------------------------------------------------------------ 272cdf0e10cSrcweir 273cdf0e10cSrcweir //inline 274cdf0e10cSrcweir DataFlavor SAL_CALL CDOTransferable::formatEtcToDataFlavor( const FORMATETC& aFormatEtc ) 275cdf0e10cSrcweir { 276cdf0e10cSrcweir DataFlavor aFlavor; 277cdf0e10cSrcweir LCID lcid = 0; 278cdf0e10cSrcweir 279cdf0e10cSrcweir // for non-unicode text format we must provid a locale to get 280cdf0e10cSrcweir // the character-set of the text, if there is no locale on the 281cdf0e10cSrcweir // clipboard we assume the text is in a charset appropriate for 282cdf0e10cSrcweir // the current thread locale 283cdf0e10cSrcweir if ( (CF_TEXT == aFormatEtc.cfFormat) || (CF_OEMTEXT == aFormatEtc.cfFormat) ) 284cdf0e10cSrcweir lcid = getLocaleFromClipboard( ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir return m_DataFormatTranslator.getDataFlavorFromFormatEtc( aFormatEtc, lcid ); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir //------------------------------------------------------------------------ 290cdf0e10cSrcweir // returns the current locale on clipboard; if there is no locale on 291cdf0e10cSrcweir // clipboard the function returns the current thread locale 292cdf0e10cSrcweir //------------------------------------------------------------------------ 293cdf0e10cSrcweir 294cdf0e10cSrcweir LCID SAL_CALL CDOTransferable::getLocaleFromClipboard( ) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir LCID lcid = GetThreadLocale( ); 297cdf0e10cSrcweir 298cdf0e10cSrcweir try 299cdf0e10cSrcweir { 300cdf0e10cSrcweir CFormatEtc fetc = m_DataFormatTranslator.getFormatEtcForClipformat( CF_LOCALE ); 301cdf0e10cSrcweir ByteSequence_t aLCIDSeq = getClipboardData( fetc ); 302cdf0e10cSrcweir lcid = *(reinterpret_cast<LCID*>( aLCIDSeq.getArray( ) ) ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir // because of a Win95/98 Bug; there the high word 305cdf0e10cSrcweir // of a locale has the same value as the 306cdf0e10cSrcweir // low word e.g. 0x07040704 that's not right 307cdf0e10cSrcweir // correct is 0x00000704 308cdf0e10cSrcweir lcid &= 0x0000FFFF; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir catch(...) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir // we take the default locale 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir return lcid; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir 318cdf0e10cSrcweir //------------------------------------------------------------------------ 319cdf0e10cSrcweir // i think it's not necessary to call ReleaseStgMedium 320cdf0e10cSrcweir // in case of failures because nothing should have been 321cdf0e10cSrcweir // allocated etc. 322cdf0e10cSrcweir //------------------------------------------------------------------------ 323cdf0e10cSrcweir 324cdf0e10cSrcweir CDOTransferable::ByteSequence_t SAL_CALL CDOTransferable::getClipboardData( CFormatEtc& aFormatEtc ) 325cdf0e10cSrcweir { 326cdf0e10cSrcweir STGMEDIUM stgmedium; 327cdf0e10cSrcweir HRESULT hr = m_rDataObject->GetData( aFormatEtc, &stgmedium ); 328cdf0e10cSrcweir 329cdf0e10cSrcweir // in case of failure to get a WMF metafile handle, try to get a memory block 330cdf0e10cSrcweir if( FAILED( hr ) && 331cdf0e10cSrcweir ( CF_METAFILEPICT == aFormatEtc.getClipformat() ) && 332cdf0e10cSrcweir ( TYMED_MFPICT == aFormatEtc.getTymed() ) ) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir CFormatEtc aTempFormat( aFormatEtc ); 335cdf0e10cSrcweir aTempFormat.setTymed( TYMED_HGLOBAL ); 336cdf0e10cSrcweir hr = m_rDataObject->GetData( aTempFormat, &stgmedium ); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir if ( FAILED( hr ) ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir OSL_ASSERT( (hr != E_INVALIDARG) && 342cdf0e10cSrcweir (hr != DV_E_DVASPECT) && 343cdf0e10cSrcweir (hr != DV_E_LINDEX) && 344cdf0e10cSrcweir (hr != DV_E_TYMED) ); 345cdf0e10cSrcweir 346cdf0e10cSrcweir if ( DV_E_FORMATETC == hr ) 347cdf0e10cSrcweir throw UnsupportedFlavorException( ); 348cdf0e10cSrcweir else if ( STG_E_MEDIUMFULL == hr ) 349cdf0e10cSrcweir throw IOException( ); 350cdf0e10cSrcweir else 351cdf0e10cSrcweir throw RuntimeException( ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir ByteSequence_t byteStream; 355cdf0e10cSrcweir 356cdf0e10cSrcweir try 357cdf0e10cSrcweir { 358cdf0e10cSrcweir if ( CF_ENHMETAFILE == aFormatEtc.getClipformat() ) 359cdf0e10cSrcweir byteStream = WinENHMFPictToOOMFPict( stgmedium.hEnhMetaFile ); 360cdf0e10cSrcweir else if (CF_HDROP == aFormatEtc.getClipformat()) 361cdf0e10cSrcweir byteStream = CF_HDROPToFileList(stgmedium.hGlobal); 362cdf0e10cSrcweir else if ( CF_BITMAP == aFormatEtc.getClipformat() ) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir byteStream = WinBITMAPToOOBMP(stgmedium.hBitmap); 365cdf0e10cSrcweir if( aFormatEtc.getTymed() == TYMED_GDI && 366cdf0e10cSrcweir ! stgmedium.pUnkForRelease ) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir DeleteObject(stgmedium.hBitmap); 369cdf0e10cSrcweir } 370cdf0e10cSrcweir } 371cdf0e10cSrcweir else 372cdf0e10cSrcweir { 373cdf0e10cSrcweir clipDataToByteStream( aFormatEtc.getClipformat( ), stgmedium, byteStream ); 374cdf0e10cSrcweir 375cdf0e10cSrcweir // format conversion if necessary 37645fd3b9aSArmin Le Grand if(CF_DIBV5 == aFormatEtc.getClipformat() || CF_DIB == aFormatEtc.getClipformat()) 37745fd3b9aSArmin Le Grand { 37845fd3b9aSArmin Le Grand byteStream = WinDIBToOOBMP(byteStream); 37945fd3b9aSArmin Le Grand } 38045fd3b9aSArmin Le Grand else if(CF_METAFILEPICT == aFormatEtc.getClipformat()) 38145fd3b9aSArmin Le Grand { 38245fd3b9aSArmin Le Grand byteStream = WinMFPictToOOMFPict(byteStream); 38345fd3b9aSArmin Le Grand } 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir ReleaseStgMedium( &stgmedium ); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir catch( CStgTransferHelper::CStgTransferException& ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir ReleaseStgMedium( &stgmedium ); 391cdf0e10cSrcweir throw IOException( ); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir return byteStream; 395cdf0e10cSrcweir } 396cdf0e10cSrcweir 397cdf0e10cSrcweir //------------------------------------------------------------------------ 398cdf0e10cSrcweir // 399cdf0e10cSrcweir //------------------------------------------------------------------------ 400cdf0e10cSrcweir 401cdf0e10cSrcweir OUString SAL_CALL CDOTransferable::synthesizeUnicodeText( ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir ByteSequence_t aTextSequence; 404cdf0e10cSrcweir CFormatEtc fetc; 405cdf0e10cSrcweir LCID lcid = getLocaleFromClipboard( ); 406cdf0e10cSrcweir sal_uInt32 cpForTxtCnvt = 0; 407cdf0e10cSrcweir 408cdf0e10cSrcweir if ( CF_TEXT == m_TxtFormatOnClipboard ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir fetc = m_DataFormatTranslator.getFormatEtcForClipformat( CF_TEXT ); 411cdf0e10cSrcweir aTextSequence = getClipboardData( fetc ); 412cdf0e10cSrcweir 413cdf0e10cSrcweir // determine the codepage used for text conversion 414cdf0e10cSrcweir cpForTxtCnvt = getWinCPFromLocaleId( lcid, LOCALE_IDEFAULTANSICODEPAGE ).toInt32( ); 415cdf0e10cSrcweir } 416cdf0e10cSrcweir else if ( CF_OEMTEXT == m_TxtFormatOnClipboard ) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir fetc = m_DataFormatTranslator.getFormatEtcForClipformat( CF_OEMTEXT ); 419cdf0e10cSrcweir aTextSequence = getClipboardData( fetc ); 420cdf0e10cSrcweir 421cdf0e10cSrcweir // determine the codepage used for text conversion 422cdf0e10cSrcweir cpForTxtCnvt = getWinCPFromLocaleId( lcid, LOCALE_IDEFAULTCODEPAGE ).toInt32( ); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir else 425cdf0e10cSrcweir OSL_ASSERT( sal_False ); 426cdf0e10cSrcweir 427cdf0e10cSrcweir CStgTransferHelper stgTransferHelper; 428cdf0e10cSrcweir 429cdf0e10cSrcweir // convert the text 430cdf0e10cSrcweir MultiByteToWideCharEx( cpForTxtCnvt, 431cdf0e10cSrcweir reinterpret_cast<char*>( aTextSequence.getArray( ) ), 432cdf0e10cSrcweir sal::static_int_cast<sal_uInt32>(-1), // Huh ? 433cdf0e10cSrcweir stgTransferHelper, 434cdf0e10cSrcweir sal_False); 435cdf0e10cSrcweir 436cdf0e10cSrcweir CRawHGlobalPtr ptrHGlob(stgTransferHelper); 437cdf0e10cSrcweir sal_Unicode* pWChar = reinterpret_cast<sal_Unicode*>(ptrHGlob.GetMemPtr()); 438cdf0e10cSrcweir 439cdf0e10cSrcweir return OUString(pWChar); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir //------------------------------------------------------------------------ 443cdf0e10cSrcweir // 444cdf0e10cSrcweir //------------------------------------------------------------------------ 445cdf0e10cSrcweir 446cdf0e10cSrcweir void CDOTransferable::clipDataToByteStream( CLIPFORMAT cf, STGMEDIUM stgmedium, ByteSequence_t& aByteSequence ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir CStgTransferHelper memTransferHelper; 449cdf0e10cSrcweir 450cdf0e10cSrcweir switch( stgmedium.tymed ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir case TYMED_HGLOBAL: 453cdf0e10cSrcweir memTransferHelper.init( stgmedium.hGlobal ); 454cdf0e10cSrcweir break; 455cdf0e10cSrcweir 456cdf0e10cSrcweir case TYMED_MFPICT: 457cdf0e10cSrcweir memTransferHelper.init( stgmedium.hMetaFilePict ); 458cdf0e10cSrcweir break; 459cdf0e10cSrcweir 460cdf0e10cSrcweir case TYMED_ENHMF: 461cdf0e10cSrcweir memTransferHelper.init( stgmedium.hEnhMetaFile ); 462cdf0e10cSrcweir break; 463cdf0e10cSrcweir 464cdf0e10cSrcweir case TYMED_ISTREAM: 465cdf0e10cSrcweir #ifdef _MSC_VER 466cdf0e10cSrcweir #pragma PRAGMA_MSG( Has to be implemented ) 467cdf0e10cSrcweir #endif 468cdf0e10cSrcweir break; 469cdf0e10cSrcweir 470cdf0e10cSrcweir default: 471cdf0e10cSrcweir throw UnsupportedFlavorException( ); 472cdf0e10cSrcweir break; 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir int nMemSize = memTransferHelper.memSize( cf ); 476cdf0e10cSrcweir aByteSequence.realloc( nMemSize ); 477cdf0e10cSrcweir memTransferHelper.read( aByteSequence.getArray( ), nMemSize ); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir 480cdf0e10cSrcweir //------------------------------------------------------------------------ 481cdf0e10cSrcweir // 482cdf0e10cSrcweir //------------------------------------------------------------------------ 483cdf0e10cSrcweir 484cdf0e10cSrcweir inline 485cdf0e10cSrcweir Any CDOTransferable::byteStreamToAny( ByteSequence_t& aByteStream, const Type& aRequestedDataType ) 486cdf0e10cSrcweir { 487cdf0e10cSrcweir Any aAny; 488cdf0e10cSrcweir 489cdf0e10cSrcweir if ( aRequestedDataType == CPPUTYPE_OUSTRING ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir OUString str = byteStreamToOUString( aByteStream ); 492cdf0e10cSrcweir aAny = makeAny( str ); 493cdf0e10cSrcweir } 494cdf0e10cSrcweir else 495cdf0e10cSrcweir aAny = makeAny( aByteStream ); 496cdf0e10cSrcweir 497cdf0e10cSrcweir return aAny; 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir //------------------------------------------------------------------------ 501cdf0e10cSrcweir // 502cdf0e10cSrcweir //------------------------------------------------------------------------ 503cdf0e10cSrcweir 504cdf0e10cSrcweir inline 505cdf0e10cSrcweir OUString CDOTransferable::byteStreamToOUString( ByteSequence_t& aByteStream ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir sal_Int32 nWChars; 508cdf0e10cSrcweir sal_Int32 nMemSize = aByteStream.getLength( ); 509cdf0e10cSrcweir 510cdf0e10cSrcweir // if there is a trailing L"\0" substract 1 from length 511cdf0e10cSrcweir if ( 0 == aByteStream[ aByteStream.getLength( ) - 2 ] && 512cdf0e10cSrcweir 0 == aByteStream[ aByteStream.getLength( ) - 1 ] ) 513cdf0e10cSrcweir nWChars = static_cast< sal_Int32 >( nMemSize / sizeof( sal_Unicode ) ) - 1; 514cdf0e10cSrcweir else 515cdf0e10cSrcweir nWChars = static_cast< sal_Int32 >( nMemSize / sizeof( sal_Unicode ) ); 516cdf0e10cSrcweir 517cdf0e10cSrcweir return OUString( reinterpret_cast< sal_Unicode* >( aByteStream.getArray( ) ), nWChars ); 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir //------------------------------------------------------------------------ 521cdf0e10cSrcweir // 522cdf0e10cSrcweir //------------------------------------------------------------------------ 523cdf0e10cSrcweir 524cdf0e10cSrcweir sal_Bool SAL_CALL CDOTransferable::compareDataFlavors( 525cdf0e10cSrcweir const DataFlavor& lhs, const DataFlavor& rhs ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir if ( !m_rXMimeCntFactory.is( ) ) 528cdf0e10cSrcweir { 529cdf0e10cSrcweir m_rXMimeCntFactory = Reference< XMimeContentTypeFactory >( m_SrvMgr->createInstance( 530cdf0e10cSrcweir OUString::createFromAscii( "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), UNO_QUERY ); 531cdf0e10cSrcweir } 532cdf0e10cSrcweir OSL_ASSERT( m_rXMimeCntFactory.is( ) ); 533cdf0e10cSrcweir 534cdf0e10cSrcweir sal_Bool bRet = sal_False; 535cdf0e10cSrcweir 536cdf0e10cSrcweir try 537cdf0e10cSrcweir { 538cdf0e10cSrcweir Reference< XMimeContentType > xLhs( m_rXMimeCntFactory->createMimeContentType( lhs.MimeType ) ); 539cdf0e10cSrcweir Reference< XMimeContentType > xRhs( m_rXMimeCntFactory->createMimeContentType( rhs.MimeType ) ); 540cdf0e10cSrcweir 541cdf0e10cSrcweir if ( cmpFullMediaType( xLhs, xRhs ) ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir bRet = cmpAllContentTypeParameter( xLhs, xRhs ); 544cdf0e10cSrcweir } 545cdf0e10cSrcweir } 546cdf0e10cSrcweir catch( IllegalArgumentException& ) 547cdf0e10cSrcweir { 548cdf0e10cSrcweir OSL_ENSURE( sal_False, "Invalid content type detected" ); 549cdf0e10cSrcweir bRet = sal_False; 550cdf0e10cSrcweir } 551cdf0e10cSrcweir 552cdf0e10cSrcweir return bRet; 553cdf0e10cSrcweir } 554cdf0e10cSrcweir 555cdf0e10cSrcweir //------------------------------------------------------------------------ 556cdf0e10cSrcweir // 557cdf0e10cSrcweir //------------------------------------------------------------------------ 558cdf0e10cSrcweir 559cdf0e10cSrcweir sal_Bool SAL_CALL CDOTransferable::cmpFullMediaType( 560cdf0e10cSrcweir const Reference< XMimeContentType >& xLhs, const Reference< XMimeContentType >& xRhs ) const 561cdf0e10cSrcweir { 562cdf0e10cSrcweir return xLhs->getFullMediaType().equalsIgnoreAsciiCase( xRhs->getFullMediaType( ) ); 563cdf0e10cSrcweir } 564cdf0e10cSrcweir 565cdf0e10cSrcweir //------------------------------------------------------------------------ 566cdf0e10cSrcweir // 567cdf0e10cSrcweir //------------------------------------------------------------------------ 568cdf0e10cSrcweir 569cdf0e10cSrcweir sal_Bool SAL_CALL CDOTransferable::cmpAllContentTypeParameter( 570cdf0e10cSrcweir const Reference< XMimeContentType >& xLhs, const Reference< XMimeContentType >& xRhs ) const 571cdf0e10cSrcweir { 572cdf0e10cSrcweir Sequence< OUString > xLhsFlavors = xLhs->getParameters( ); 573cdf0e10cSrcweir Sequence< OUString > xRhsFlavors = xRhs->getParameters( ); 574cdf0e10cSrcweir sal_Bool bRet = sal_True; 575cdf0e10cSrcweir 576cdf0e10cSrcweir try 577cdf0e10cSrcweir { 578cdf0e10cSrcweir if ( xLhsFlavors.getLength( ) == xRhsFlavors.getLength( ) ) 579cdf0e10cSrcweir { 580cdf0e10cSrcweir OUString pLhs; 581cdf0e10cSrcweir OUString pRhs; 582cdf0e10cSrcweir 583cdf0e10cSrcweir for ( sal_Int32 i = 0; i < xLhsFlavors.getLength( ); i++ ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir pLhs = xLhs->getParameterValue( xLhsFlavors[i] ); 586cdf0e10cSrcweir pRhs = xRhs->getParameterValue( xLhsFlavors[i] ); 587cdf0e10cSrcweir 588cdf0e10cSrcweir if ( !pLhs.equalsIgnoreAsciiCase( pRhs ) ) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir bRet = sal_False; 591cdf0e10cSrcweir break; 592cdf0e10cSrcweir } 593cdf0e10cSrcweir } 594cdf0e10cSrcweir } 595cdf0e10cSrcweir else 596cdf0e10cSrcweir bRet = sal_False; 597cdf0e10cSrcweir } 598cdf0e10cSrcweir catch( NoSuchElementException& ) 599cdf0e10cSrcweir { 600cdf0e10cSrcweir bRet = sal_False; 601cdf0e10cSrcweir } 602cdf0e10cSrcweir catch( IllegalArgumentException& ) 603cdf0e10cSrcweir { 604cdf0e10cSrcweir bRet = sal_False; 605cdf0e10cSrcweir } 606cdf0e10cSrcweir 607cdf0e10cSrcweir return bRet; 608cdf0e10cSrcweir } 609cdf0e10cSrcweir 610cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL CDOTransferable::getData( const Sequence< sal_Int8>& aProcessId ) 611cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir Any retVal; 614cdf0e10cSrcweir 615cdf0e10cSrcweir sal_uInt8 * arProcCaller= (sal_uInt8*)(sal_Int8*) aProcessId.getConstArray(); 616cdf0e10cSrcweir sal_uInt8 arId[16]; 617cdf0e10cSrcweir rtl_getGlobalProcessId(arId); 618cdf0e10cSrcweir if( ! memcmp( arId, arProcCaller,16)) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir if (m_rDataObject.is()) 621cdf0e10cSrcweir { 622cdf0e10cSrcweir IDataObject* pObj= m_rDataObject.get(); 623cdf0e10cSrcweir pObj->AddRef(); 624cdf0e10cSrcweir retVal.setValue( &pObj, getCppuType((sal_uInt32*)0)); 625cdf0e10cSrcweir } 626cdf0e10cSrcweir } 627cdf0e10cSrcweir return retVal; 628cdf0e10cSrcweir } 629cdf0e10cSrcweir 630