1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30cdf0e10cSrcweir #ifdef WNT 31cdf0e10cSrcweir #include <tools/prewin.h> 32cdf0e10cSrcweir #if defined _MSC_VER 33cdf0e10cSrcweir #pragma warning(push, 1) 34cdf0e10cSrcweir #pragma warning(disable: 4917) 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir #include <shlobj.h> 37cdf0e10cSrcweir #if defined _MSC_VER 38cdf0e10cSrcweir #pragma warning(pop) 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir #include <tools/postwin.h> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #include <vos/mutex.hxx> 43cdf0e10cSrcweir #include <rtl/memory.h> 44cdf0e10cSrcweir #include <rtl/uuid.h> 45cdf0e10cSrcweir #include <rtl/uri.hxx> 46cdf0e10cSrcweir #include <tools/debug.hxx> 47cdf0e10cSrcweir #include <tools/urlobj.hxx> 48cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 49cdf0e10cSrcweir #include <sot/exchange.hxx> 50cdf0e10cSrcweir #include <sot/storage.hxx> 51cdf0e10cSrcweir #include <vcl/bitmap.hxx> 52cdf0e10cSrcweir #include <vcl/gdimtf.hxx> 53cdf0e10cSrcweir #include <vcl/graph.hxx> 54cdf0e10cSrcweir #include <vcl/cvtgrf.hxx> 55cdf0e10cSrcweir #include <vcl/svapp.hxx> 56cdf0e10cSrcweir #include <vcl/window.hxx> 57cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 58cdf0e10cSrcweir #include <sot/filelist.hxx> 59cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 60cdf0e10cSrcweir 61cdf0e10cSrcweir #include <comphelper/seqstream.hxx> 62cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp> 63cdf0e10cSrcweir #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> 64cdf0e10cSrcweir #include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp> 65cdf0e10cSrcweir #include <com/sun/star/datatransfer/XMimeContentType.hpp> 66cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp> 67cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 68cdf0e10cSrcweir 69cdf0e10cSrcweir #include "svl/urlbmk.hxx" 70cdf0e10cSrcweir #include "inetimg.hxx" 71cdf0e10cSrcweir #include <svtools/wmf.hxx> 72cdf0e10cSrcweir #include <svtools/imap.hxx> 73cdf0e10cSrcweir #include <svtools/transfer.hxx> 74cdf0e10cSrcweir #include <cstdio> 75cdf0e10cSrcweir 76cdf0e10cSrcweir // -------------- 77cdf0e10cSrcweir // - Namespaces - 78cdf0e10cSrcweir // -------------- 79cdf0e10cSrcweir 80cdf0e10cSrcweir using namespace ::com::sun::star::uno; 81cdf0e10cSrcweir using namespace ::com::sun::star::lang; 82cdf0e10cSrcweir using namespace ::com::sun::star::frame; 83cdf0e10cSrcweir using namespace ::com::sun::star::io; 84cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer; 85cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::clipboard; 86cdf0e10cSrcweir using namespace ::com::sun::star::datatransfer::dnd; 87cdf0e10cSrcweir 88cdf0e10cSrcweir // -------------------------------- 89cdf0e10cSrcweir // - TransferableObjectDescriptor - 90cdf0e10cSrcweir // -------------------------------- 91cdf0e10cSrcweir 92cdf0e10cSrcweir #define TOD_SIG1 0x01234567 93cdf0e10cSrcweir #define TOD_SIG2 0x89abcdef 94cdf0e10cSrcweir 95cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, TransferableObjectDescriptor& rObjDesc ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir sal_uInt32 nSize, nViewAspect, nSig1, nSig2; 98cdf0e10cSrcweir 99cdf0e10cSrcweir rIStm >> nSize; 100cdf0e10cSrcweir rIStm >> rObjDesc.maClassName; 101cdf0e10cSrcweir rIStm >> nViewAspect; 102cdf0e10cSrcweir rIStm >> rObjDesc.maSize.Width(); 103cdf0e10cSrcweir rIStm >> rObjDesc.maSize.Height(); 104cdf0e10cSrcweir rIStm >> rObjDesc.maDragStartPos.X(); 105cdf0e10cSrcweir rIStm >> rObjDesc.maDragStartPos.Y(); 106cdf0e10cSrcweir rIStm.ReadByteString( rObjDesc.maTypeName, gsl_getSystemTextEncoding() ); 107cdf0e10cSrcweir rIStm.ReadByteString( rObjDesc.maDisplayName, gsl_getSystemTextEncoding() ); 108cdf0e10cSrcweir rIStm >> nSig1 >> nSig2; 109cdf0e10cSrcweir 110cdf0e10cSrcweir rObjDesc.mnViewAspect = static_cast< sal_uInt16 >( nViewAspect ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir // don't use width/height info from external objects 113cdf0e10cSrcweir if( ( TOD_SIG1 != nSig1 ) || ( TOD_SIG2 != nSig2 ) ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir rObjDesc.maSize.Width() = 0; 116cdf0e10cSrcweir rObjDesc.maSize.Height() = 0; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir return rIStm; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir // ----------------------------------------------------------------------------- 123cdf0e10cSrcweir 124cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const TransferableObjectDescriptor& rObjDesc ) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir const sal_uInt32 nFirstPos = rOStm.Tell(), nViewAspect = rObjDesc.mnViewAspect; 127cdf0e10cSrcweir const sal_uInt32 nSig1 = TOD_SIG1, nSig2 = TOD_SIG2; 128cdf0e10cSrcweir 129cdf0e10cSrcweir rOStm.SeekRel( 4 ); 130cdf0e10cSrcweir rOStm << rObjDesc.maClassName; 131cdf0e10cSrcweir rOStm << nViewAspect; 132cdf0e10cSrcweir rOStm << rObjDesc.maSize.Width(); 133cdf0e10cSrcweir rOStm << rObjDesc.maSize.Height(); 134cdf0e10cSrcweir rOStm << rObjDesc.maDragStartPos.X(); 135cdf0e10cSrcweir rOStm << rObjDesc.maDragStartPos.Y(); 136cdf0e10cSrcweir rOStm.WriteByteString( rObjDesc.maTypeName, gsl_getSystemTextEncoding() ); 137cdf0e10cSrcweir rOStm.WriteByteString( rObjDesc.maDisplayName, gsl_getSystemTextEncoding() ); 138cdf0e10cSrcweir rOStm << nSig1 << nSig2; 139cdf0e10cSrcweir 140cdf0e10cSrcweir const sal_uInt32 nLastPos = rOStm.Tell(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir rOStm.Seek( nFirstPos ); 143cdf0e10cSrcweir rOStm << ( nLastPos - nFirstPos ); 144cdf0e10cSrcweir rOStm.Seek( nLastPos ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir return rOStm; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ----------------------------------------------------------------------------- 150cdf0e10cSrcweir // the reading of the parameter is done using the special service ::com::sun::star::datatransfer::MimeContentType, 151cdf0e10cSrcweir // a similar approach should be implemented for creation of the mimetype string; 152cdf0e10cSrcweir // for now the set of acceptable characters has to be hardcoded, in future it should be part of the service that creates the mimetype 153*8178a74eSMathias Bauer const ::rtl::OUString aQuotedParamChars = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "()<>@,;:/[]?=!#$&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~. " ) ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir static ::rtl::OUString ImplGetParameterString( const TransferableObjectDescriptor& rObjDesc ) 156cdf0e10cSrcweir { 157cdf0e10cSrcweir const ::rtl::OUString aChar( ::rtl::OUString::createFromAscii( "\"" ) ); 158cdf0e10cSrcweir const ::rtl::OUString aClassName( rObjDesc.maClassName.GetHexName() ); 159cdf0e10cSrcweir ::rtl::OUString aParams; 160cdf0e10cSrcweir 161cdf0e10cSrcweir if( aClassName.getLength() ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";classname=\"" ); 164cdf0e10cSrcweir aParams += aClassName; 165cdf0e10cSrcweir aParams += aChar; 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir if( rObjDesc.maTypeName.Len() ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";typename=\"" ); 171cdf0e10cSrcweir aParams += rObjDesc.maTypeName; 172cdf0e10cSrcweir aParams += aChar; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir if( rObjDesc.maDisplayName.Len() ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // the display name might contain unacceptable characters, encode all of them 178cdf0e10cSrcweir // this seems to be the only parameter currently that might contain such characters 179cdf0e10cSrcweir sal_Bool pToAccept[128]; 180cdf0e10cSrcweir for ( sal_Int32 nBInd = 0; nBInd < 128; nBInd++ ) 181cdf0e10cSrcweir pToAccept[nBInd] = sal_False; 182cdf0e10cSrcweir 183cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < aQuotedParamChars.getLength(); nInd++ ) 184cdf0e10cSrcweir { 185cdf0e10cSrcweir sal_Unicode nChar = aQuotedParamChars.getStr()[nInd]; 186cdf0e10cSrcweir if ( nChar < 128 ) 187cdf0e10cSrcweir pToAccept[nChar] = sal_True; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";displayname=\"" ); 191cdf0e10cSrcweir aParams += ::rtl::Uri::encode( rObjDesc.maDisplayName, pToAccept, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8 ); 192cdf0e10cSrcweir aParams += aChar; 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";viewaspect=\"" ); 196cdf0e10cSrcweir aParams += ::rtl::OUString::valueOf( static_cast< sal_Int32 >( rObjDesc.mnViewAspect ) ); 197cdf0e10cSrcweir aParams += aChar; 198cdf0e10cSrcweir 199cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";width=\"" ); 200cdf0e10cSrcweir aParams += ::rtl::OUString::valueOf( rObjDesc.maSize.Width() ); 201cdf0e10cSrcweir aParams += aChar; 202cdf0e10cSrcweir 203cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";height=\"" ); 204cdf0e10cSrcweir aParams += ::rtl::OUString::valueOf( rObjDesc.maSize.Height() ); 205cdf0e10cSrcweir aParams += aChar; 206cdf0e10cSrcweir 207cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";posx=\"" ); 208cdf0e10cSrcweir aParams += ::rtl::OUString::valueOf( rObjDesc.maDragStartPos.X() ); 209cdf0e10cSrcweir aParams += aChar; 210cdf0e10cSrcweir 211cdf0e10cSrcweir aParams += ::rtl::OUString::createFromAscii( ";posy=\"" ); 212cdf0e10cSrcweir aParams += ::rtl::OUString::valueOf( rObjDesc.maDragStartPos.X() ); 213cdf0e10cSrcweir aParams += aChar; 214cdf0e10cSrcweir 215cdf0e10cSrcweir return aParams; 216cdf0e10cSrcweir } 217cdf0e10cSrcweir 218cdf0e10cSrcweir // ----------------------------------------------------------------------------- 219cdf0e10cSrcweir 220cdf0e10cSrcweir static void ImplSetParameterString( TransferableObjectDescriptor& rObjDesc, const DataFlavorEx& rFlavorEx ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); 223cdf0e10cSrcweir Reference< XMimeContentTypeFactory > xMimeFact; 224cdf0e10cSrcweir 225cdf0e10cSrcweir try 226cdf0e10cSrcweir { 227cdf0e10cSrcweir if( xFact.is() ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii( 230cdf0e10cSrcweir "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), 231cdf0e10cSrcweir UNO_QUERY ); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir if( xMimeFact.is() ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir Reference< XMimeContentType > xMimeType( xMimeFact->createMimeContentType( rFlavorEx.MimeType ) ); 237cdf0e10cSrcweir 238cdf0e10cSrcweir if( xMimeType.is() ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir const ::rtl::OUString aClassNameString( ::rtl::OUString::createFromAscii( "classname" ) ); 241cdf0e10cSrcweir const ::rtl::OUString aTypeNameString( ::rtl::OUString::createFromAscii( "typename" ) ); 242cdf0e10cSrcweir const ::rtl::OUString aDisplayNameString( ::rtl::OUString::createFromAscii( "displayname" ) ); 243cdf0e10cSrcweir const ::rtl::OUString aViewAspectString( ::rtl::OUString::createFromAscii( "viewaspect" ) ); 244cdf0e10cSrcweir const ::rtl::OUString aWidthString( ::rtl::OUString::createFromAscii( "width" ) ); 245cdf0e10cSrcweir const ::rtl::OUString aHeightString( ::rtl::OUString::createFromAscii( "height" ) ); 246cdf0e10cSrcweir const ::rtl::OUString aPosXString( ::rtl::OUString::createFromAscii( "posx" ) ); 247cdf0e10cSrcweir const ::rtl::OUString aPosYString( ::rtl::OUString::createFromAscii( "posy" ) ); 248cdf0e10cSrcweir 249cdf0e10cSrcweir if( xMimeType->hasParameter( aClassNameString ) ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir rObjDesc.maClassName.MakeId( xMimeType->getParameterValue( aClassNameString ) ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir if( xMimeType->hasParameter( aTypeNameString ) ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir rObjDesc.maTypeName = xMimeType->getParameterValue( aTypeNameString ); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir if( xMimeType->hasParameter( aDisplayNameString ) ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir // the display name might contain unacceptable characters, in this case they should be encoded 262cdf0e10cSrcweir // this seems to be the only parameter currently that might contain such characters 263cdf0e10cSrcweir rObjDesc.maDisplayName = ::rtl::Uri::decode( xMimeType->getParameterValue( aDisplayNameString ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir if( xMimeType->hasParameter( aViewAspectString ) ) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir rObjDesc.mnViewAspect = static_cast< sal_uInt16 >( xMimeType->getParameterValue( aViewAspectString ).toInt32() ); 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir if( xMimeType->hasParameter( aWidthString ) ) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir rObjDesc.maSize.Width() = xMimeType->getParameterValue( aWidthString ).toInt32(); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir if( xMimeType->hasParameter( aHeightString ) ) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir rObjDesc.maSize.Height() = xMimeType->getParameterValue( aHeightString ).toInt32(); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir if( xMimeType->hasParameter( aPosXString ) ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir rObjDesc.maDragStartPos.X() = xMimeType->getParameterValue( aPosXString ).toInt32(); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir 286cdf0e10cSrcweir if( xMimeType->hasParameter( aPosYString ) ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir rObjDesc.maDragStartPos.Y() = xMimeType->getParameterValue( aPosYString ).toInt32(); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir } 293cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir } 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir // ----------------------------------------- 299cdf0e10cSrcweir // - TransferableHelper::TerminateListener - 300cdf0e10cSrcweir // ----------------------------------------- 301cdf0e10cSrcweir 302cdf0e10cSrcweir TransferableHelper::TerminateListener::TerminateListener( TransferableHelper& rTransferableHelper ) : 303cdf0e10cSrcweir mrParent( rTransferableHelper ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir // ----------------------------------------------------------------------------- 308cdf0e10cSrcweir 309cdf0e10cSrcweir TransferableHelper::TerminateListener::~TerminateListener() 310cdf0e10cSrcweir { 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir // ----------------------------------------------------------------------------- 314cdf0e10cSrcweir 315cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::disposing( const EventObject& ) throw( RuntimeException ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir } 318cdf0e10cSrcweir 319cdf0e10cSrcweir // ----------------------------------------------------------------------------- 320cdf0e10cSrcweir 321cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::queryTermination( const EventObject& ) throw( TerminationVetoException, RuntimeException ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir // ----------------------------------------------------------------------------- 326cdf0e10cSrcweir 327cdf0e10cSrcweir void SAL_CALL TransferableHelper::TerminateListener::notifyTermination( const EventObject& ) throw( RuntimeException ) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir mrParent.ImplFlush(); 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir // ---------------------- 333cdf0e10cSrcweir // - TransferableHelper - 334cdf0e10cSrcweir // ---------------------- 335cdf0e10cSrcweir 336cdf0e10cSrcweir TransferableHelper::TransferableHelper() : 337cdf0e10cSrcweir mpFormats( new DataFlavorExVector ), 338cdf0e10cSrcweir mpObjDesc( NULL ) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir } 341cdf0e10cSrcweir 342cdf0e10cSrcweir // ----------------------------------------------------------------------------- 343cdf0e10cSrcweir 344cdf0e10cSrcweir TransferableHelper::~TransferableHelper() 345cdf0e10cSrcweir { 346cdf0e10cSrcweir delete mpObjDesc; 347cdf0e10cSrcweir delete mpFormats; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir // ----------------------------------------------------------------------------- 351cdf0e10cSrcweir 352cdf0e10cSrcweir Any SAL_CALL TransferableHelper::getTransferData( const DataFlavor& rFlavor ) throw( UnsupportedFlavorException, IOException, RuntimeException ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir if( !maAny.hasValue() || !mpFormats->size() || ( maLastFormat != rFlavor.MimeType ) ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 357cdf0e10cSrcweir 358cdf0e10cSrcweir maLastFormat = rFlavor.MimeType; 359cdf0e10cSrcweir maAny = Any(); 360cdf0e10cSrcweir 361cdf0e10cSrcweir try 362cdf0e10cSrcweir { 363cdf0e10cSrcweir DataFlavor aSubstFlavor; 364cdf0e10cSrcweir sal_Bool bDone = sal_False; 365cdf0e10cSrcweir 366cdf0e10cSrcweir // add formats if not already done 367cdf0e10cSrcweir if( !mpFormats->size() ) 368cdf0e10cSrcweir AddSupportedFormats(); 369cdf0e10cSrcweir 370cdf0e10cSrcweir // check alien formats first and try to get a substitution format 371cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( FORMAT_STRING, aSubstFlavor ) && 372cdf0e10cSrcweir TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) ) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir GetData( aSubstFlavor ); 375cdf0e10cSrcweir bDone = maAny.hasValue(); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir else if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_BMP, aSubstFlavor ) && 378cdf0e10cSrcweir TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) && 379cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( FORMAT_BITMAP, aSubstFlavor ) ) 380cdf0e10cSrcweir { 381cdf0e10cSrcweir GetData( aSubstFlavor ); 382cdf0e10cSrcweir bDone = sal_True; 383cdf0e10cSrcweir } 384cdf0e10cSrcweir else if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EMF, aSubstFlavor ) && 385cdf0e10cSrcweir TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) && 386cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( FORMAT_GDIMETAFILE, aSubstFlavor ) ) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir GetData( aSubstFlavor ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir if( maAny.hasValue() ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 393cdf0e10cSrcweir 394cdf0e10cSrcweir if( maAny >>= aSeq ) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir SvMemoryStream* pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC ); 397cdf0e10cSrcweir GDIMetaFile aMtf; 398cdf0e10cSrcweir 399cdf0e10cSrcweir *pSrcStm >> aMtf; 400cdf0e10cSrcweir delete pSrcStm; 401cdf0e10cSrcweir 402cdf0e10cSrcweir Graphic aGraphic( aMtf ); 403cdf0e10cSrcweir SvMemoryStream aDstStm( 65535, 65535 ); 404cdf0e10cSrcweir 405cdf0e10cSrcweir if( GraphicConverter::Export( aDstStm, aGraphic, CVT_EMF ) == ERRCODE_NONE ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir maAny <<= ( aSeq = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aDstStm.GetData() ), 408cdf0e10cSrcweir aDstStm.Seek( STREAM_SEEK_TO_END ) ) ); 409cdf0e10cSrcweir bDone = sal_True; 410cdf0e10cSrcweir } 411cdf0e10cSrcweir } 412cdf0e10cSrcweir } 413cdf0e10cSrcweir } 414cdf0e10cSrcweir else if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_WMF, aSubstFlavor ) && 415cdf0e10cSrcweir TransferableDataHelper::IsEqual( aSubstFlavor, rFlavor ) && 416cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( FORMAT_GDIMETAFILE, aSubstFlavor ) ) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir GetData( aSubstFlavor ); 419cdf0e10cSrcweir 420cdf0e10cSrcweir if( maAny.hasValue() ) 421cdf0e10cSrcweir { 422cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 423cdf0e10cSrcweir 424cdf0e10cSrcweir if( maAny >>= aSeq ) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir SvMemoryStream* pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC ); 427cdf0e10cSrcweir GDIMetaFile aMtf; 428cdf0e10cSrcweir 429cdf0e10cSrcweir *pSrcStm >> aMtf; 430cdf0e10cSrcweir delete pSrcStm; 431cdf0e10cSrcweir 432cdf0e10cSrcweir SvMemoryStream aDstStm( 65535, 65535 ); 433cdf0e10cSrcweir 434cdf0e10cSrcweir // taking wmf without file header 435cdf0e10cSrcweir if ( ConvertGDIMetaFileToWMF( aMtf, aDstStm, NULL, sal_False ) ) 436cdf0e10cSrcweir { 437cdf0e10cSrcweir maAny <<= ( aSeq = Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aDstStm.GetData() ), 438cdf0e10cSrcweir aDstStm.Seek( STREAM_SEEK_TO_END ) ) ); 439cdf0e10cSrcweir bDone = sal_True; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir } 442cdf0e10cSrcweir } 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir // reset Any if substitute doesn't work 446cdf0e10cSrcweir if( !bDone && maAny.hasValue() ) 447cdf0e10cSrcweir maAny = Any(); 448cdf0e10cSrcweir 449cdf0e10cSrcweir // if any is not yet filled, use standard format 450cdf0e10cSrcweir if( !maAny.hasValue() ) 451cdf0e10cSrcweir GetData( rFlavor ); 452cdf0e10cSrcweir 453cdf0e10cSrcweir #ifdef DEBUG 454cdf0e10cSrcweir if( maAny.hasValue() && ::com::sun::star::uno::TypeClass_STRING != maAny.getValueType().getTypeClass() ) 455cdf0e10cSrcweir fprintf( stderr, "TransferableHelper delivers sequence of data [ %s ]\n", ByteString( String( rFlavor.MimeType), RTL_TEXTENCODING_ASCII_US ).GetBuffer() ); 456cdf0e10cSrcweir #endif 457cdf0e10cSrcweir } 458cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir if( !maAny.hasValue() ) 463cdf0e10cSrcweir throw UnsupportedFlavorException(); 464cdf0e10cSrcweir } 465cdf0e10cSrcweir 466cdf0e10cSrcweir return maAny; 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir // ----------------------------------------------------------------------------- 470cdf0e10cSrcweir 471cdf0e10cSrcweir Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() throw( RuntimeException ) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 474cdf0e10cSrcweir 475cdf0e10cSrcweir try 476cdf0e10cSrcweir { 477cdf0e10cSrcweir if( !mpFormats->size() ) 478cdf0e10cSrcweir AddSupportedFormats(); 479cdf0e10cSrcweir } 480cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 481cdf0e10cSrcweir { 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir Sequence< DataFlavor > aRet( mpFormats->size() ); 485cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 486cdf0e10cSrcweir sal_uInt32 nCurPos = 0; 487cdf0e10cSrcweir 488cdf0e10cSrcweir while( aIter != aEnd ) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir aRet[ nCurPos++ ] = *aIter++; 491cdf0e10cSrcweir } 492cdf0e10cSrcweir 493cdf0e10cSrcweir return aRet; 494cdf0e10cSrcweir } 495cdf0e10cSrcweir 496cdf0e10cSrcweir // ----------------------------------------------------------------------------- 497cdf0e10cSrcweir 498cdf0e10cSrcweir sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& rFlavor ) throw( RuntimeException ) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 501cdf0e10cSrcweir sal_Bool bRet = sal_False; 502cdf0e10cSrcweir 503cdf0e10cSrcweir try 504cdf0e10cSrcweir { 505cdf0e10cSrcweir if( !mpFormats->size() ) 506cdf0e10cSrcweir AddSupportedFormats(); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir } 511cdf0e10cSrcweir 512cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 513cdf0e10cSrcweir 514cdf0e10cSrcweir while( aIter != aEnd ) 515cdf0e10cSrcweir { 516cdf0e10cSrcweir if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) ) 517cdf0e10cSrcweir { 518cdf0e10cSrcweir aIter = aEnd; 519cdf0e10cSrcweir bRet = sal_True; 520cdf0e10cSrcweir } 521cdf0e10cSrcweir else 522cdf0e10cSrcweir aIter++; 523cdf0e10cSrcweir } 524cdf0e10cSrcweir 525cdf0e10cSrcweir return bRet; 526cdf0e10cSrcweir } 527cdf0e10cSrcweir 528cdf0e10cSrcweir // ----------------------------------------------------------------------------- 529cdf0e10cSrcweir 530cdf0e10cSrcweir void SAL_CALL TransferableHelper::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) throw( RuntimeException ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 533cdf0e10cSrcweir 534cdf0e10cSrcweir try 535cdf0e10cSrcweir { 536cdf0e10cSrcweir if( mxTerminateListener.is() ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); 539cdf0e10cSrcweir 540cdf0e10cSrcweir if( xFact.is() ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); 543cdf0e10cSrcweir 544cdf0e10cSrcweir if( xDesktop.is() ) 545cdf0e10cSrcweir xDesktop->removeTerminateListener( mxTerminateListener ); 546cdf0e10cSrcweir } 547cdf0e10cSrcweir 548cdf0e10cSrcweir mxTerminateListener = Reference< XTerminateListener >(); 549cdf0e10cSrcweir } 550cdf0e10cSrcweir 551cdf0e10cSrcweir ObjectReleased(); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir } 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir // ----------------------------------------------------------------------------- 559cdf0e10cSrcweir 560cdf0e10cSrcweir void SAL_CALL TransferableHelper::disposing( const EventObject& ) throw( RuntimeException ) 561cdf0e10cSrcweir { 562cdf0e10cSrcweir } 563cdf0e10cSrcweir 564cdf0e10cSrcweir // ----------------------------------------------------------------------------- 565cdf0e10cSrcweir 566cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragDropEnd( const DragSourceDropEvent& rDSDE ) throw( RuntimeException ) 567cdf0e10cSrcweir { 568cdf0e10cSrcweir const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 569cdf0e10cSrcweir 570cdf0e10cSrcweir try 571cdf0e10cSrcweir { 572cdf0e10cSrcweir DragFinished( rDSDE.DropSuccess ? ( rDSDE.DropAction & ~DNDConstants::ACTION_DEFAULT ) : DNDConstants::ACTION_NONE ); 573cdf0e10cSrcweir ObjectReleased(); 574cdf0e10cSrcweir } 575cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 576cdf0e10cSrcweir { 577cdf0e10cSrcweir } 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir // ----------------------------------------------------------------------------- 581cdf0e10cSrcweir 582cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragEnter( const DragSourceDragEvent& ) throw( RuntimeException ) 583cdf0e10cSrcweir { 584cdf0e10cSrcweir } 585cdf0e10cSrcweir 586cdf0e10cSrcweir // ----------------------------------------------------------------------------- 587cdf0e10cSrcweir 588cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragExit( const DragSourceEvent& ) throw( RuntimeException ) 589cdf0e10cSrcweir { 590cdf0e10cSrcweir } 591cdf0e10cSrcweir 592cdf0e10cSrcweir // ----------------------------------------------------------------------------- 593cdf0e10cSrcweir 594cdf0e10cSrcweir void SAL_CALL TransferableHelper::dragOver( const DragSourceDragEvent& ) throw( RuntimeException ) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir // ----------------------------------------------------------------------------- 599cdf0e10cSrcweir 600cdf0e10cSrcweir void SAL_CALL TransferableHelper::dropActionChanged( const DragSourceDragEvent& ) throw( RuntimeException ) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir } 603cdf0e10cSrcweir 604cdf0e10cSrcweir // ----------------------------------------------------------------------------- 605cdf0e10cSrcweir 606cdf0e10cSrcweir sal_Int64 SAL_CALL TransferableHelper::getSomething( const Sequence< sal_Int8 >& rId ) throw( RuntimeException ) 607cdf0e10cSrcweir { 608cdf0e10cSrcweir sal_Int64 nRet; 609cdf0e10cSrcweir 610cdf0e10cSrcweir if( ( rId.getLength() == 16 ) && 611cdf0e10cSrcweir ( 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) ) ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir nRet = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir else 616cdf0e10cSrcweir nRet = 0; 617cdf0e10cSrcweir 618cdf0e10cSrcweir return nRet; 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir // ----------------------------------------------------------------------------- 622cdf0e10cSrcweir 623cdf0e10cSrcweir void TransferableHelper::ImplFlush() 624cdf0e10cSrcweir { 625cdf0e10cSrcweir if( mxClipboard.is() ) 626cdf0e10cSrcweir { 627cdf0e10cSrcweir Reference< XFlushableClipboard > xFlushableClipboard( mxClipboard, UNO_QUERY ); 628cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 629cdf0e10cSrcweir 630cdf0e10cSrcweir try 631cdf0e10cSrcweir { 632cdf0e10cSrcweir if( xFlushableClipboard.is() ) 633cdf0e10cSrcweir xFlushableClipboard->flushClipboard(); 634cdf0e10cSrcweir } 635cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 636cdf0e10cSrcweir { 637cdf0e10cSrcweir DBG_ERROR( "Could not flush clipboard" ); 638cdf0e10cSrcweir } 639cdf0e10cSrcweir 640cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 641cdf0e10cSrcweir } 642cdf0e10cSrcweir } 643cdf0e10cSrcweir 644cdf0e10cSrcweir // ----------------------------------------------------------------------------- 645cdf0e10cSrcweir 646cdf0e10cSrcweir void TransferableHelper::AddFormat( SotFormatStringId nFormat ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir DataFlavor aFlavor; 649cdf0e10cSrcweir 650cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) ) 651cdf0e10cSrcweir AddFormat( aFlavor ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir 654cdf0e10cSrcweir // ----------------------------------------------------------------------------- 655cdf0e10cSrcweir 656cdf0e10cSrcweir void TransferableHelper::AddFormat( const DataFlavor& rFlavor ) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 659cdf0e10cSrcweir sal_Bool bAdd = sal_True; 660cdf0e10cSrcweir 661cdf0e10cSrcweir while( aIter != aEnd ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) ) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir // update MimeType for SOT_FORMATSTR_ID_OBJECTDESCRIPTOR in every case 666cdf0e10cSrcweir if( ( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId ) && mpObjDesc ) 667cdf0e10cSrcweir { 668cdf0e10cSrcweir DataFlavor aObjDescFlavor; 669cdf0e10cSrcweir 670cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aObjDescFlavor ); 671cdf0e10cSrcweir aIter->MimeType = aObjDescFlavor.MimeType; 672cdf0e10cSrcweir aIter->MimeType += ::ImplGetParameterString( *mpObjDesc ); 673cdf0e10cSrcweir 674cdf0e10cSrcweir #ifdef DEBUG 675cdf0e10cSrcweir fprintf( stderr, "TransferableHelper exchanged objectdescriptor [ %s ]\n", 676cdf0e10cSrcweir ByteString( String( aIter->MimeType), RTL_TEXTENCODING_ASCII_US ).GetBuffer() ); 677cdf0e10cSrcweir #endif 678cdf0e10cSrcweir } 679cdf0e10cSrcweir 680cdf0e10cSrcweir aIter = aEnd; 681cdf0e10cSrcweir bAdd = sal_False; 682cdf0e10cSrcweir } 683cdf0e10cSrcweir else 684cdf0e10cSrcweir aIter++; 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir if( bAdd ) 688cdf0e10cSrcweir { 689cdf0e10cSrcweir DataFlavorEx aFlavorEx; 690cdf0e10cSrcweir DataFlavor aObjDescFlavor; 691cdf0e10cSrcweir 692cdf0e10cSrcweir aFlavorEx.MimeType = rFlavor.MimeType; 693cdf0e10cSrcweir aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName; 694cdf0e10cSrcweir aFlavorEx.DataType = rFlavor.DataType; 695cdf0e10cSrcweir aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor ); 696cdf0e10cSrcweir 697cdf0e10cSrcweir if( ( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aFlavorEx.mnSotId ) && mpObjDesc ) 698cdf0e10cSrcweir aFlavorEx.MimeType += ::ImplGetParameterString( *mpObjDesc ); 699cdf0e10cSrcweir 700cdf0e10cSrcweir mpFormats->push_back( aFlavorEx ); 701cdf0e10cSrcweir 702cdf0e10cSrcweir if( FORMAT_BITMAP == aFlavorEx.mnSotId ) 703cdf0e10cSrcweir { 704cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_BMP ); 705cdf0e10cSrcweir } 706cdf0e10cSrcweir else if( FORMAT_GDIMETAFILE == aFlavorEx.mnSotId ) 707cdf0e10cSrcweir { 708cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_EMF ); 709cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_WMF ); 710cdf0e10cSrcweir } 711cdf0e10cSrcweir } 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir // ----------------------------------------------------------------------------- 715cdf0e10cSrcweir 716cdf0e10cSrcweir void TransferableHelper::RemoveFormat( SotFormatStringId nFormat ) 717cdf0e10cSrcweir { 718cdf0e10cSrcweir DataFlavor aFlavor; 719cdf0e10cSrcweir 720cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) ) 721cdf0e10cSrcweir RemoveFormat( aFlavor ); 722cdf0e10cSrcweir } 723cdf0e10cSrcweir 724cdf0e10cSrcweir // ----------------------------------------------------------------------------- 725cdf0e10cSrcweir 726cdf0e10cSrcweir void TransferableHelper::RemoveFormat( const DataFlavor& rFlavor ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 729cdf0e10cSrcweir 730cdf0e10cSrcweir while( aIter != aEnd ) 731cdf0e10cSrcweir { 732cdf0e10cSrcweir if( TransferableDataHelper::IsEqual( *aIter, rFlavor ) ) 733cdf0e10cSrcweir { 734cdf0e10cSrcweir aIter = mpFormats->erase( aIter ); 735cdf0e10cSrcweir aEnd = mpFormats->end(); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir else 738cdf0e10cSrcweir ++aIter; 739cdf0e10cSrcweir } 740cdf0e10cSrcweir } 741cdf0e10cSrcweir 742cdf0e10cSrcweir // ----------------------------------------------------------------------------- 743cdf0e10cSrcweir 744cdf0e10cSrcweir sal_Bool TransferableHelper::HasFormat( SotFormatStringId nFormat ) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 747cdf0e10cSrcweir sal_Bool bRet = sal_False; 748cdf0e10cSrcweir 749cdf0e10cSrcweir while( aIter != aEnd ) 750cdf0e10cSrcweir { 751cdf0e10cSrcweir if( nFormat == (*aIter).mnSotId ) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir aIter = aEnd; 754cdf0e10cSrcweir bRet = sal_True; 755cdf0e10cSrcweir } 756cdf0e10cSrcweir else 757cdf0e10cSrcweir ++aIter; 758cdf0e10cSrcweir } 759cdf0e10cSrcweir 760cdf0e10cSrcweir return bRet; 761cdf0e10cSrcweir } 762cdf0e10cSrcweir 763cdf0e10cSrcweir // ----------------------------------------------------------------------------- 764cdf0e10cSrcweir 765cdf0e10cSrcweir void TransferableHelper::ClearFormats() 766cdf0e10cSrcweir { 767cdf0e10cSrcweir mpFormats->clear(); 768cdf0e10cSrcweir maAny.clear(); 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir // ----------------------------------------------------------------------------- 772cdf0e10cSrcweir 773cdf0e10cSrcweir sal_Bool TransferableHelper::SetAny( const Any& rAny, const DataFlavor& ) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir maAny = rAny; 776cdf0e10cSrcweir return( maAny.hasValue() ); 777cdf0e10cSrcweir } 778cdf0e10cSrcweir 779cdf0e10cSrcweir // ----------------------------------------------------------------------------- 780cdf0e10cSrcweir 781cdf0e10cSrcweir sal_Bool TransferableHelper::SetString( const ::rtl::OUString& rString, const DataFlavor& rFlavor ) 782cdf0e10cSrcweir { 783cdf0e10cSrcweir DataFlavor aFileFlavor; 784cdf0e10cSrcweir 785cdf0e10cSrcweir if( rString.getLength() && 786cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( FORMAT_FILE, aFileFlavor ) && 787cdf0e10cSrcweir TransferableDataHelper::IsEqual( aFileFlavor, rFlavor ) ) 788cdf0e10cSrcweir { 789cdf0e10cSrcweir const String aString( rString ); 790cdf0e10cSrcweir const ByteString aByteStr( aString, gsl_getSystemTextEncoding() ); 791cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( aByteStr.Len() + 1 ); 792cdf0e10cSrcweir 793cdf0e10cSrcweir rtl_copyMemory( aSeq.getArray(), aByteStr.GetBuffer(), aByteStr.Len() ); 794cdf0e10cSrcweir aSeq[ aByteStr.Len() ] = 0; 795cdf0e10cSrcweir maAny <<= aSeq; 796cdf0e10cSrcweir } 797cdf0e10cSrcweir else 798cdf0e10cSrcweir maAny <<= rString; 799cdf0e10cSrcweir 800cdf0e10cSrcweir return( maAny.hasValue() ); 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir // ----------------------------------------------------------------------------- 804cdf0e10cSrcweir 805cdf0e10cSrcweir sal_Bool TransferableHelper::SetBitmap( const Bitmap& rBitmap, const DataFlavor& ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir if( !rBitmap.IsEmpty() ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir SvMemoryStream aMemStm( 65535, 65535 ); 810cdf0e10cSrcweir 811cdf0e10cSrcweir aMemStm << rBitmap; 812cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); 813cdf0e10cSrcweir } 814cdf0e10cSrcweir 815cdf0e10cSrcweir return( maAny.hasValue() ); 816cdf0e10cSrcweir } 817cdf0e10cSrcweir 818cdf0e10cSrcweir // ----------------------------------------------------------------------------- 819cdf0e10cSrcweir 820cdf0e10cSrcweir sal_Bool TransferableHelper::SetGDIMetaFile( const GDIMetaFile& rMtf, const DataFlavor& ) 821cdf0e10cSrcweir { 822cdf0e10cSrcweir if( rMtf.GetActionCount() ) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir SvMemoryStream aMemStm( 65535, 65535 ); 825cdf0e10cSrcweir 826cdf0e10cSrcweir ( (GDIMetaFile&) rMtf ).Write( aMemStm ); 827cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir return( maAny.hasValue() ); 831cdf0e10cSrcweir } 832cdf0e10cSrcweir 833cdf0e10cSrcweir // ----------------------------------------------------------------------------- 834cdf0e10cSrcweir 835cdf0e10cSrcweir sal_Bool TransferableHelper::SetGraphic( const Graphic& rGraphic, const DataFlavor& ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir if( rGraphic.GetType() != GRAPHIC_NONE ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir SvMemoryStream aMemStm( 65535, 65535 ); 840cdf0e10cSrcweir 841cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 842cdf0e10cSrcweir aMemStm.SetCompressMode( COMPRESSMODE_NATIVE ); 843cdf0e10cSrcweir aMemStm << rGraphic; 844cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); 845cdf0e10cSrcweir } 846cdf0e10cSrcweir 847cdf0e10cSrcweir return( maAny.hasValue() ); 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir // ----------------------------------------------------------------------------- 851cdf0e10cSrcweir 852cdf0e10cSrcweir sal_Bool TransferableHelper::SetImageMap( const ImageMap& rIMap, const ::com::sun::star::datatransfer::DataFlavor& ) 853cdf0e10cSrcweir { 854cdf0e10cSrcweir SvMemoryStream aMemStm( 8192, 8192 ); 855cdf0e10cSrcweir 856cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 857cdf0e10cSrcweir rIMap.Write( aMemStm, String() ); 858cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); 859cdf0e10cSrcweir 860cdf0e10cSrcweir return( maAny.hasValue() ); 861cdf0e10cSrcweir } 862cdf0e10cSrcweir 863cdf0e10cSrcweir // ----------------------------------------------------------------------------- 864cdf0e10cSrcweir 865cdf0e10cSrcweir sal_Bool TransferableHelper::SetTransferableObjectDescriptor( const TransferableObjectDescriptor& rDesc, 866cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& ) 867cdf0e10cSrcweir { 868cdf0e10cSrcweir PrepareOLE( rDesc ); 869cdf0e10cSrcweir 870cdf0e10cSrcweir SvMemoryStream aMemStm( 1024, 1024 ); 871cdf0e10cSrcweir 872cdf0e10cSrcweir aMemStm << rDesc; 873cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Tell() ); 874cdf0e10cSrcweir 875cdf0e10cSrcweir return( maAny.hasValue() ); 876cdf0e10cSrcweir } 877cdf0e10cSrcweir 878cdf0e10cSrcweir // ----------------------------------------------------------------------------- 879cdf0e10cSrcweir 880cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk, 881cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& rFlavor ) 882cdf0e10cSrcweir { 883cdf0e10cSrcweir rtl_TextEncoding eSysCSet = gsl_getSystemTextEncoding(); 884cdf0e10cSrcweir 885cdf0e10cSrcweir switch( SotExchange::GetFormat( rFlavor ) ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir case( SOT_FORMATSTR_ID_SOLK ): 888cdf0e10cSrcweir { 889cdf0e10cSrcweir ByteString sURL( rBmk.GetURL(), eSysCSet ), 890cdf0e10cSrcweir sDesc( rBmk.GetDescription(), eSysCSet ); 891cdf0e10cSrcweir ByteString sOut( ByteString::CreateFromInt32( sURL.Len() )); 892cdf0e10cSrcweir ( sOut += '@' ) += sURL; 893cdf0e10cSrcweir sOut += ByteString::CreateFromInt32( sDesc.Len() ); 894cdf0e10cSrcweir ( sOut += '@' ) += sDesc; 895cdf0e10cSrcweir 896cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( sOut.Len() ); 897cdf0e10cSrcweir memcpy( aSeq.getArray(), sOut.GetBuffer(), sOut.Len() ); 898cdf0e10cSrcweir maAny <<= aSeq; 899cdf0e10cSrcweir } 900cdf0e10cSrcweir break; 901cdf0e10cSrcweir 902cdf0e10cSrcweir case( FORMAT_STRING ): 903cdf0e10cSrcweir maAny <<= ::rtl::OUString( rBmk.GetURL() ); 904cdf0e10cSrcweir break; 905cdf0e10cSrcweir 906cdf0e10cSrcweir case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ): 907cdf0e10cSrcweir { 908cdf0e10cSrcweir ByteString sURL( rBmk.GetURL(), eSysCSet ); 909cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( sURL.Len() ); 910cdf0e10cSrcweir memcpy( aSeq.getArray(), sURL.GetBuffer(), sURL.Len() ); 911cdf0e10cSrcweir maAny <<= aSeq; 912cdf0e10cSrcweir } 913cdf0e10cSrcweir break; 914cdf0e10cSrcweir 915cdf0e10cSrcweir case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ): 916cdf0e10cSrcweir { 917cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( 2048 ); 918cdf0e10cSrcweir 919cdf0e10cSrcweir memset( aSeq.getArray(), 0, 2048 ); 920cdf0e10cSrcweir strcpy( reinterpret_cast< char* >( aSeq.getArray() ), ByteString( rBmk.GetURL(), eSysCSet).GetBuffer() ); 921cdf0e10cSrcweir strcpy( reinterpret_cast< char* >( aSeq.getArray() ) + 1024, ByteString( rBmk.GetDescription(), eSysCSet ).GetBuffer() ); 922cdf0e10cSrcweir 923cdf0e10cSrcweir maAny <<= aSeq; 924cdf0e10cSrcweir } 925cdf0e10cSrcweir break; 926cdf0e10cSrcweir 927cdf0e10cSrcweir #ifdef WNT 928cdf0e10cSrcweir case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 929cdf0e10cSrcweir { 930cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( sizeof( FILEGROUPDESCRIPTOR ) ); 931cdf0e10cSrcweir FILEGROUPDESCRIPTOR* pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getArray(); 932cdf0e10cSrcweir FILEDESCRIPTOR& rFDesc1 = pFDesc->fgd[ 0 ]; 933cdf0e10cSrcweir 934cdf0e10cSrcweir pFDesc->cItems = 1; 935cdf0e10cSrcweir memset( &rFDesc1, 0, sizeof( FILEDESCRIPTOR ) ); 936cdf0e10cSrcweir rFDesc1.dwFlags = FD_LINKUI; 937cdf0e10cSrcweir 938cdf0e10cSrcweir ByteString aStr( rBmk.GetDescription(), eSysCSet ); 939cdf0e10cSrcweir for( sal_uInt16 nChar = 0; nChar < aStr.Len(); ++nChar ) 940cdf0e10cSrcweir if( strchr( "\\/:*?\"<>|", aStr.GetChar( nChar ) ) ) 941cdf0e10cSrcweir aStr.Erase( nChar--, 1 ); 942cdf0e10cSrcweir 943cdf0e10cSrcweir aStr.Insert( "Shortcut to ", 0 ); 944cdf0e10cSrcweir aStr += ".URL"; 945cdf0e10cSrcweir strcpy( rFDesc1.cFileName, aStr.GetBuffer() ); 946cdf0e10cSrcweir 947cdf0e10cSrcweir maAny <<= aSeq; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir break; 950cdf0e10cSrcweir 951cdf0e10cSrcweir case SOT_FORMATSTR_ID_FILECONTENT: 952cdf0e10cSrcweir { 953cdf0e10cSrcweir String aStr( RTL_CONSTASCII_STRINGPARAM( "[InternetShortcut]\x0aURL=" ) ); 954cdf0e10cSrcweir maAny <<= ::rtl::OUString( aStr += rBmk.GetURL() ); 955cdf0e10cSrcweir } 956cdf0e10cSrcweir break; 957cdf0e10cSrcweir #endif 958cdf0e10cSrcweir 959cdf0e10cSrcweir default: 960cdf0e10cSrcweir break; 961cdf0e10cSrcweir } 962cdf0e10cSrcweir 963cdf0e10cSrcweir return( maAny.hasValue() ); 964cdf0e10cSrcweir } 965cdf0e10cSrcweir 966cdf0e10cSrcweir // ----------------------------------------------------------------------------- 967cdf0e10cSrcweir 968cdf0e10cSrcweir sal_Bool TransferableHelper::SetINetImage( const INetImage& rINtImg, 969cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& rFlavor ) 970cdf0e10cSrcweir { 971cdf0e10cSrcweir SvMemoryStream aMemStm( 1024, 1024 ); 972cdf0e10cSrcweir 973cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 974cdf0e10cSrcweir rINtImg.Write( aMemStm, SotExchange::GetFormat( rFlavor ) ); 975cdf0e10cSrcweir 976cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aMemStm.GetData() ), aMemStm.Seek( STREAM_SEEK_TO_END ) ); 977cdf0e10cSrcweir 978cdf0e10cSrcweir return( maAny.hasValue() ); 979cdf0e10cSrcweir } 980cdf0e10cSrcweir 981cdf0e10cSrcweir // ----------------------------------------------------------------------------- 982cdf0e10cSrcweir 983cdf0e10cSrcweir sal_Bool TransferableHelper::SetFileList( const FileList& rFileList, 984cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& ) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir SvMemoryStream aMemStm( 4096, 4096 ); 987cdf0e10cSrcweir 988cdf0e10cSrcweir aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 ); 989cdf0e10cSrcweir aMemStm << rFileList; 990cdf0e10cSrcweir 991cdf0e10cSrcweir maAny <<= Sequence< sal_Int8 >( static_cast< const sal_Int8* >( aMemStm.GetData() ), 992cdf0e10cSrcweir aMemStm.Seek( STREAM_SEEK_TO_END ) ); 993cdf0e10cSrcweir 994cdf0e10cSrcweir return( maAny.hasValue() ); 995cdf0e10cSrcweir } 996cdf0e10cSrcweir 997cdf0e10cSrcweir // ----------------------------------------------------------------------------- 998cdf0e10cSrcweir 999cdf0e10cSrcweir sal_Bool TransferableHelper::SetObject( void* pUserObject, sal_uInt32 nUserObjectId, const DataFlavor& rFlavor ) 1000cdf0e10cSrcweir { 1001cdf0e10cSrcweir SotStorageStreamRef xStm( new SotStorageStream( String() ) ); 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir xStm->SetVersion( SOFFICE_FILEFORMAT_50 ); 1004cdf0e10cSrcweir 1005cdf0e10cSrcweir if( pUserObject && WriteObject( xStm, pUserObject, nUserObjectId, rFlavor ) ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir const sal_uInt32 nLen = xStm->Seek( STREAM_SEEK_TO_END ); 1008cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( nLen ); 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir xStm->Seek( STREAM_SEEK_TO_BEGIN ); 1011cdf0e10cSrcweir xStm->Read( aSeq.getArray(), nLen ); 1012cdf0e10cSrcweir 1013cdf0e10cSrcweir if( nLen && ( SotExchange::GetFormat( rFlavor ) == SOT_FORMAT_STRING ) ) 1014cdf0e10cSrcweir { 1015cdf0e10cSrcweir //JP 24.7.2001: as I know was this only for the writer application and this 1016cdf0e10cSrcweir // writes now UTF16 format into the stream 1017cdf0e10cSrcweir //JP 6.8.2001: and now it writes UTF8 because then exist no problem with 1018cdf0e10cSrcweir // little / big endians! - Bug 88121 1019cdf0e10cSrcweir maAny <<= ::rtl::OUString( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), nLen - 1, RTL_TEXTENCODING_UTF8 ); 1020cdf0e10cSrcweir } 1021cdf0e10cSrcweir else 1022cdf0e10cSrcweir maAny <<= aSeq; 1023cdf0e10cSrcweir } 1024cdf0e10cSrcweir 1025cdf0e10cSrcweir return( maAny.hasValue() ); 1026cdf0e10cSrcweir } 1027cdf0e10cSrcweir 1028cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1029cdf0e10cSrcweir 1030cdf0e10cSrcweir sal_Bool TransferableHelper::SetInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rIf, 1031cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& ) 1032cdf0e10cSrcweir { 1033cdf0e10cSrcweir maAny <<= rIf; 1034cdf0e10cSrcweir return( maAny.hasValue() ); 1035cdf0e10cSrcweir } 1036cdf0e10cSrcweir 1037cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir sal_Bool TransferableHelper::WriteObject( SotStorageStreamRef&, void*, sal_uInt32, const DataFlavor& ) 1040cdf0e10cSrcweir { 1041cdf0e10cSrcweir DBG_ERROR( "TransferableHelper::WriteObject( ... ) not implemented" ); 1042cdf0e10cSrcweir return sal_False; 1043cdf0e10cSrcweir } 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir void TransferableHelper::DragFinished( sal_Int8 ) 1048cdf0e10cSrcweir { 1049cdf0e10cSrcweir } 1050cdf0e10cSrcweir 1051cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1052cdf0e10cSrcweir 1053cdf0e10cSrcweir void TransferableHelper::ObjectReleased() 1054cdf0e10cSrcweir { 1055cdf0e10cSrcweir } 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1058cdf0e10cSrcweir 1059cdf0e10cSrcweir void TransferableHelper::PrepareOLE( const TransferableObjectDescriptor& rObjDesc ) 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir delete mpObjDesc; 1062cdf0e10cSrcweir mpObjDesc = new TransferableObjectDescriptor( rObjDesc ); 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir if( HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) ) 1065cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ); 1066cdf0e10cSrcweir } 1067cdf0e10cSrcweir 1068cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1069cdf0e10cSrcweir 1070cdf0e10cSrcweir void TransferableHelper::CopyToClipboard( Window *pWindow ) const 1071cdf0e10cSrcweir { 1072cdf0e10cSrcweir DBG_ASSERT( pWindow, "Window pointer is NULL" ); 1073cdf0e10cSrcweir Reference< XClipboard > xClipboard; 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir if( pWindow ) 1076cdf0e10cSrcweir xClipboard = pWindow->GetClipboard(); 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir if( xClipboard.is() ) 1079cdf0e10cSrcweir mxClipboard = xClipboard; 1080cdf0e10cSrcweir 1081cdf0e10cSrcweir if( mxClipboard.is() && !mxTerminateListener.is() ) 1082cdf0e10cSrcweir { 1083cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir try 1086cdf0e10cSrcweir { 1087cdf0e10cSrcweir TransferableHelper* pThis = const_cast< TransferableHelper* >( this ); 1088cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); 1089cdf0e10cSrcweir 1090cdf0e10cSrcweir if( xFact.is() ) 1091cdf0e10cSrcweir { 1092cdf0e10cSrcweir Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); 1093cdf0e10cSrcweir 1094cdf0e10cSrcweir if( xDesktop.is() ) 1095cdf0e10cSrcweir xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) ); 1096cdf0e10cSrcweir } 1097cdf0e10cSrcweir 1098cdf0e10cSrcweir mxClipboard->setContents( pThis, pThis ); 1099cdf0e10cSrcweir } 1100cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1101cdf0e10cSrcweir { 1102cdf0e10cSrcweir } 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir } 1107cdf0e10cSrcweir 1108cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1109cdf0e10cSrcweir 1110cdf0e10cSrcweir void TransferableHelper::CopyToSelection( Window *pWindow ) const 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir DBG_ASSERT( pWindow, "Window pointer is NULL" ); 1113cdf0e10cSrcweir Reference< XClipboard > xSelection; 1114cdf0e10cSrcweir 1115cdf0e10cSrcweir if( pWindow ) 1116cdf0e10cSrcweir xSelection = pWindow->GetPrimarySelection(); 1117cdf0e10cSrcweir 1118cdf0e10cSrcweir if( xSelection.is() && !mxTerminateListener.is() ) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 1121cdf0e10cSrcweir 1122cdf0e10cSrcweir try 1123cdf0e10cSrcweir { 1124cdf0e10cSrcweir TransferableHelper* pThis = const_cast< TransferableHelper* >( this ); 1125cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir if( xFact.is() ) 1128cdf0e10cSrcweir { 1129cdf0e10cSrcweir Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir if( xDesktop.is() ) 1132cdf0e10cSrcweir xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) ); 1133cdf0e10cSrcweir } 1134cdf0e10cSrcweir 1135cdf0e10cSrcweir xSelection->setContents( pThis, pThis ); 1136cdf0e10cSrcweir } 1137cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1138cdf0e10cSrcweir { 1139cdf0e10cSrcweir } 1140cdf0e10cSrcweir 1141cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 1142cdf0e10cSrcweir } 1143cdf0e10cSrcweir } 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir void TransferableHelper::StartDrag( Window* pWindow, sal_Int8 nDnDSourceActions, 1148cdf0e10cSrcweir sal_Int32 nDnDPointer, sal_Int32 nDnDImage ) 1149cdf0e10cSrcweir 1150cdf0e10cSrcweir { 1151cdf0e10cSrcweir DBG_ASSERT( pWindow, "Window pointer is NULL" ); 1152cdf0e10cSrcweir Reference< XDragSource > xDragSource( pWindow->GetDragSource() ); 1153cdf0e10cSrcweir 1154cdf0e10cSrcweir if( xDragSource.is() ) 1155cdf0e10cSrcweir { 1156cdf0e10cSrcweir /* 1157cdf0e10cSrcweir * #96792# release mouse before actually starting DnD. 1158cdf0e10cSrcweir * This is necessary for the X11 DnD implementation to work. 1159cdf0e10cSrcweir */ 1160cdf0e10cSrcweir if( pWindow->IsMouseCaptured() ) 1161cdf0e10cSrcweir pWindow->ReleaseMouse(); 1162cdf0e10cSrcweir 1163cdf0e10cSrcweir const Point aPt( pWindow->GetPointerPosPixel() ); 1164cdf0e10cSrcweir 1165cdf0e10cSrcweir // On Mac OS X we are forced to execute 'startDrag' synchronously 1166cdf0e10cSrcweir // contrary to the XDragSource interface specification because 1167cdf0e10cSrcweir // we can receive drag events from the system only in the main 1168cdf0e10cSrcweir // thread 1169cdf0e10cSrcweir #if !defined(QUARTZ) 1170cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 1171cdf0e10cSrcweir #endif 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir try 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir DragGestureEvent aEvt; 1176cdf0e10cSrcweir aEvt.DragAction = DNDConstants::ACTION_COPY; 1177cdf0e10cSrcweir aEvt.DragOriginX = aPt.X(); 1178cdf0e10cSrcweir aEvt.DragOriginY = aPt.Y(); 1179cdf0e10cSrcweir aEvt.DragSource = xDragSource; 1180cdf0e10cSrcweir 1181cdf0e10cSrcweir xDragSource->startDrag( aEvt, nDnDSourceActions, nDnDPointer, nDnDImage, this, this ); 1182cdf0e10cSrcweir } 1183cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1184cdf0e10cSrcweir { 1185cdf0e10cSrcweir } 1186cdf0e10cSrcweir 1187cdf0e10cSrcweir // See above for the reason of this define 1188cdf0e10cSrcweir #if !defined(QUARTZ) 1189cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 1190cdf0e10cSrcweir #endif 1191cdf0e10cSrcweir } 1192cdf0e10cSrcweir } 1193cdf0e10cSrcweir 1194cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1195cdf0e10cSrcweir 1196cdf0e10cSrcweir void TransferableHelper::ClearSelection( Window *pWindow ) 1197cdf0e10cSrcweir { 1198cdf0e10cSrcweir DBG_ASSERT( pWindow, "Window pointer is NULL" ); 1199cdf0e10cSrcweir Reference< XClipboard > xSelection( pWindow->GetPrimarySelection() ); 1200cdf0e10cSrcweir 1201cdf0e10cSrcweir if( xSelection.is() ) 1202cdf0e10cSrcweir xSelection->setContents( NULL, NULL ); 1203cdf0e10cSrcweir } 1204cdf0e10cSrcweir 1205cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir Reference< XClipboard> TransferableHelper::GetSystemClipboard() 1208cdf0e10cSrcweir { 1209cdf0e10cSrcweir Window *pFocusWindow = Application::GetFocusWindow(); 1210cdf0e10cSrcweir 1211cdf0e10cSrcweir if( pFocusWindow ) 1212cdf0e10cSrcweir return pFocusWindow->GetClipboard(); 1213cdf0e10cSrcweir 1214cdf0e10cSrcweir return Reference< XClipboard > (); 1215cdf0e10cSrcweir } 1216cdf0e10cSrcweir 1217cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1218cdf0e10cSrcweir 1219cdf0e10cSrcweir const Sequence< sal_Int8 >& TransferableHelper::getUnoTunnelId() 1220cdf0e10cSrcweir { 1221cdf0e10cSrcweir static Sequence< sal_Int8 > aSeq; 1222cdf0e10cSrcweir 1223cdf0e10cSrcweir if( !aSeq.getLength() ) 1224cdf0e10cSrcweir { 1225cdf0e10cSrcweir static osl::Mutex aCreateMutex; 1226cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( aCreateMutex ); 1227cdf0e10cSrcweir 1228cdf0e10cSrcweir aSeq.realloc( 16 ); 1229cdf0e10cSrcweir rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True ); 1230cdf0e10cSrcweir } 1231cdf0e10cSrcweir 1232cdf0e10cSrcweir 1233cdf0e10cSrcweir return aSeq; 1234cdf0e10cSrcweir } 1235cdf0e10cSrcweir 1236cdf0e10cSrcweir // --------------------------------- 1237cdf0e10cSrcweir // - TransferableClipboardNotifier - 1238cdf0e10cSrcweir // --------------------------------- 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir class TransferableClipboardNotifier : public ::cppu::WeakImplHelper1< XClipboardListener > 1241cdf0e10cSrcweir { 1242cdf0e10cSrcweir private: 1243cdf0e10cSrcweir ::osl::Mutex& mrMutex; 1244cdf0e10cSrcweir Reference< XClipboardNotifier > mxNotifier; 1245cdf0e10cSrcweir TransferableDataHelper* mpListener; 1246cdf0e10cSrcweir 1247cdf0e10cSrcweir protected: 1248cdf0e10cSrcweir // XClipboardListener 1249cdf0e10cSrcweir virtual void SAL_CALL changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException); 1250cdf0e10cSrcweir 1251cdf0e10cSrcweir // XEventListener 1252cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& Source ) throw (RuntimeException); 1253cdf0e10cSrcweir 1254cdf0e10cSrcweir public: 1255cdf0e10cSrcweir TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex ); 1256cdf0e10cSrcweir 1257cdf0e10cSrcweir /// determines whether we're currently listening 1258cdf0e10cSrcweir inline bool isListening() const { return !isDisposed(); } 1259cdf0e10cSrcweir 1260cdf0e10cSrcweir /// determines whether the instance is disposed 1261cdf0e10cSrcweir inline bool isDisposed() const { return mpListener == NULL; } 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir /// makes the instance non-functional 1264cdf0e10cSrcweir void dispose(); 1265cdf0e10cSrcweir }; 1266cdf0e10cSrcweir 1267cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1268cdf0e10cSrcweir 1269cdf0e10cSrcweir TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< XClipboard >& _rxClipboard, TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex ) 1270cdf0e10cSrcweir :mrMutex( _rMutex ) 1271cdf0e10cSrcweir ,mxNotifier( _rxClipboard, UNO_QUERY ) 1272cdf0e10cSrcweir ,mpListener( &_rListener ) 1273cdf0e10cSrcweir { 1274cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 1275cdf0e10cSrcweir { 1276cdf0e10cSrcweir if ( mxNotifier.is() ) 1277cdf0e10cSrcweir mxNotifier->addClipboardListener( this ); 1278cdf0e10cSrcweir else 1279cdf0e10cSrcweir // born dead 1280cdf0e10cSrcweir mpListener = NULL; 1281cdf0e10cSrcweir } 1282cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 1283cdf0e10cSrcweir } 1284cdf0e10cSrcweir 1285cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1286cdf0e10cSrcweir 1287cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException) 1288cdf0e10cSrcweir { 1289cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 1290cdf0e10cSrcweir // the SolarMutex here is necessary, since 1291cdf0e10cSrcweir // - we cannot call mpListener without our own mutex locked 1292cdf0e10cSrcweir // - Rebind respectively InitFormats (called by Rebind) will 1293cdf0e10cSrcweir // try to lock the SolarMutex, too 1294cdf0e10cSrcweir ::osl::MutexGuard aGuard( mrMutex ); 1295cdf0e10cSrcweir if( mpListener ) 1296cdf0e10cSrcweir mpListener->Rebind( event.Contents ); 1297cdf0e10cSrcweir } 1298cdf0e10cSrcweir 1299cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1300cdf0e10cSrcweir 1301cdf0e10cSrcweir void SAL_CALL TransferableClipboardNotifier::disposing( const EventObject& ) throw (RuntimeException) 1302cdf0e10cSrcweir { 1303cdf0e10cSrcweir // clipboard is being disposed. Hmm. Okay, become disfunctional myself. 1304cdf0e10cSrcweir dispose(); 1305cdf0e10cSrcweir } 1306cdf0e10cSrcweir 1307cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1308cdf0e10cSrcweir 1309cdf0e10cSrcweir void TransferableClipboardNotifier::dispose() 1310cdf0e10cSrcweir { 1311cdf0e10cSrcweir ::osl::MutexGuard aGuard( mrMutex ); 1312cdf0e10cSrcweir 1313cdf0e10cSrcweir Reference< XClipboardListener > xKeepMeAlive( this ); 1314cdf0e10cSrcweir 1315cdf0e10cSrcweir if ( mxNotifier.is() ) 1316cdf0e10cSrcweir mxNotifier->removeClipboardListener( this ); 1317cdf0e10cSrcweir mxNotifier.clear(); 1318cdf0e10cSrcweir 1319cdf0e10cSrcweir mpListener = NULL; 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir 1322cdf0e10cSrcweir // ------------------------------- 1323cdf0e10cSrcweir // - TransferableDataHelper_Impl - 1324cdf0e10cSrcweir // ------------------------------- 1325cdf0e10cSrcweir 1326cdf0e10cSrcweir struct TransferableDataHelper_Impl 1327cdf0e10cSrcweir { 1328cdf0e10cSrcweir ::osl::Mutex maMutex; 1329cdf0e10cSrcweir TransferableClipboardNotifier* mpClipboardListener; 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir TransferableDataHelper_Impl() 1332cdf0e10cSrcweir :mpClipboardListener( NULL ) 1333cdf0e10cSrcweir { 1334cdf0e10cSrcweir } 1335cdf0e10cSrcweir }; 1336cdf0e10cSrcweir 1337cdf0e10cSrcweir // -------------------------- 1338cdf0e10cSrcweir // - TransferableDataHelper - 1339cdf0e10cSrcweir // -------------------------- 1340cdf0e10cSrcweir 1341cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper() : 1342cdf0e10cSrcweir mpFormats( new DataFlavorExVector ), 1343cdf0e10cSrcweir mpObjDesc( new TransferableObjectDescriptor ), 1344cdf0e10cSrcweir mpImpl( new TransferableDataHelper_Impl ) 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir } 1347cdf0e10cSrcweir 1348cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1349cdf0e10cSrcweir 1350cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const Reference< ::com::sun::star::datatransfer::XTransferable >& rxTransferable ) : 1351cdf0e10cSrcweir mxTransfer( rxTransferable ), 1352cdf0e10cSrcweir mpFormats( new DataFlavorExVector ), 1353cdf0e10cSrcweir mpObjDesc( new TransferableObjectDescriptor ), 1354cdf0e10cSrcweir mpImpl( new TransferableDataHelper_Impl ) 1355cdf0e10cSrcweir { 1356cdf0e10cSrcweir InitFormats(); 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir 1359cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1360cdf0e10cSrcweir 1361cdf0e10cSrcweir TransferableDataHelper::TransferableDataHelper( const TransferableDataHelper& rDataHelper ) : 1362cdf0e10cSrcweir mxTransfer( rDataHelper.mxTransfer ), 1363cdf0e10cSrcweir mxClipboard( rDataHelper.mxClipboard ), 1364cdf0e10cSrcweir mpFormats( new DataFlavorExVector( *rDataHelper.mpFormats ) ), 1365cdf0e10cSrcweir mpObjDesc( new TransferableObjectDescriptor( *rDataHelper.mpObjDesc ) ), 1366cdf0e10cSrcweir mpImpl( new TransferableDataHelper_Impl ) 1367cdf0e10cSrcweir { 1368cdf0e10cSrcweir } 1369cdf0e10cSrcweir 1370cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1371cdf0e10cSrcweir 1372cdf0e10cSrcweir TransferableDataHelper& TransferableDataHelper::operator=( const TransferableDataHelper& rDataHelper ) 1373cdf0e10cSrcweir { 1374cdf0e10cSrcweir if ( this != &rDataHelper ) 1375cdf0e10cSrcweir { 1376cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1377cdf0e10cSrcweir 1378cdf0e10cSrcweir bool bWasClipboardListening = ( NULL != mpImpl->mpClipboardListener ); 1379cdf0e10cSrcweir 1380cdf0e10cSrcweir if ( bWasClipboardListening ) 1381cdf0e10cSrcweir StopClipboardListening(); 1382cdf0e10cSrcweir 1383cdf0e10cSrcweir mxTransfer = rDataHelper.mxTransfer; 1384cdf0e10cSrcweir delete mpFormats, mpFormats = new DataFlavorExVector( *rDataHelper.mpFormats ); 1385cdf0e10cSrcweir delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor( *rDataHelper.mpObjDesc ); 1386cdf0e10cSrcweir mxClipboard = rDataHelper.mxClipboard; 1387cdf0e10cSrcweir 1388cdf0e10cSrcweir if ( bWasClipboardListening ) 1389cdf0e10cSrcweir StartClipboardListening(); 1390cdf0e10cSrcweir } 1391cdf0e10cSrcweir 1392cdf0e10cSrcweir return *this; 1393cdf0e10cSrcweir } 1394cdf0e10cSrcweir 1395cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1396cdf0e10cSrcweir 1397cdf0e10cSrcweir TransferableDataHelper::~TransferableDataHelper() 1398cdf0e10cSrcweir { 1399cdf0e10cSrcweir StopClipboardListening( ); 1400cdf0e10cSrcweir { 1401cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1402cdf0e10cSrcweir delete mpFormats, mpFormats = NULL; 1403cdf0e10cSrcweir delete mpObjDesc, mpObjDesc = NULL; 1404cdf0e10cSrcweir } 1405cdf0e10cSrcweir delete mpImpl; 1406cdf0e10cSrcweir } 1407cdf0e10cSrcweir 1408cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor >& rDataFlavorSeq, 1411cdf0e10cSrcweir DataFlavorExVector& rDataFlavorExVector ) 1412cdf0e10cSrcweir { 1413cdf0e10cSrcweir try 1414cdf0e10cSrcweir { 1415cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); 1416cdf0e10cSrcweir Reference< XMimeContentTypeFactory > xMimeFact; 1417cdf0e10cSrcweir DataFlavorEx aFlavorEx; 1418cdf0e10cSrcweir const ::rtl::OUString aCharsetStr( ::rtl::OUString::createFromAscii( "charset" ) ); 1419cdf0e10cSrcweir 1420cdf0e10cSrcweir if( xFact.is() ) 1421cdf0e10cSrcweir xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii( 1422cdf0e10cSrcweir "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), 1423cdf0e10cSrcweir UNO_QUERY ); 1424cdf0e10cSrcweir 1425cdf0e10cSrcweir for( sal_Int32 i = 0; i < rDataFlavorSeq.getLength(); i++ ) 1426cdf0e10cSrcweir { 1427cdf0e10cSrcweir const DataFlavor& rFlavor = rDataFlavorSeq[ i ]; 1428cdf0e10cSrcweir Reference< XMimeContentType > xMimeType; 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir try 1431cdf0e10cSrcweir { 1432cdf0e10cSrcweir if( xMimeFact.is() && rFlavor.MimeType.getLength() ) 1433cdf0e10cSrcweir xMimeType = xMimeFact->createMimeContentType( rFlavor.MimeType ); 1434cdf0e10cSrcweir } 1435cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1436cdf0e10cSrcweir { 1437cdf0e10cSrcweir 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir aFlavorEx.MimeType = rFlavor.MimeType; 1441cdf0e10cSrcweir aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName; 1442cdf0e10cSrcweir aFlavorEx.DataType = rFlavor.DataType; 1443cdf0e10cSrcweir aFlavorEx.mnSotId = SotExchange::RegisterFormat( rFlavor ); 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir rDataFlavorExVector.push_back( aFlavorEx ); 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir // add additional formats for special mime types 1448cdf0e10cSrcweir if( SOT_FORMATSTR_ID_BMP == aFlavorEx.mnSotId ) 1449cdf0e10cSrcweir { 1450cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavorEx ) ) 1451cdf0e10cSrcweir { 1452cdf0e10cSrcweir aFlavorEx.mnSotId = SOT_FORMAT_BITMAP; 1453cdf0e10cSrcweir rDataFlavorExVector.push_back( aFlavorEx ); 1454cdf0e10cSrcweir } 1455cdf0e10cSrcweir } 1456cdf0e10cSrcweir else if( SOT_FORMATSTR_ID_WMF == aFlavorEx.mnSotId || SOT_FORMATSTR_ID_EMF == aFlavorEx.mnSotId ) 1457cdf0e10cSrcweir { 1458cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavorEx ) ) 1459cdf0e10cSrcweir { 1460cdf0e10cSrcweir aFlavorEx.mnSotId = SOT_FORMAT_GDIMETAFILE; 1461cdf0e10cSrcweir rDataFlavorExVector.push_back( aFlavorEx ); 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir } 1464cdf0e10cSrcweir else if ( SOT_FORMATSTR_ID_HTML_SIMPLE == aFlavorEx.mnSotId ) 1465cdf0e10cSrcweir { 1466cdf0e10cSrcweir // #104735# HTML_SIMPLE may also be inserted without comments 1467cdf0e10cSrcweir aFlavorEx.mnSotId = SOT_FORMATSTR_ID_HTML_NO_COMMENT; 1468cdf0e10cSrcweir rDataFlavorExVector.push_back( aFlavorEx ); 1469cdf0e10cSrcweir } 1470cdf0e10cSrcweir else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) ) 1471cdf0e10cSrcweir { 1472cdf0e10cSrcweir // add, if it is a UTF-8 byte buffer 1473cdf0e10cSrcweir if( xMimeType->hasParameter( aCharsetStr ) ) 1474cdf0e10cSrcweir { 1475cdf0e10cSrcweir const ::rtl::OUString aCharset( xMimeType->getParameterValue( aCharsetStr ) ); 1476cdf0e10cSrcweir 1477cdf0e10cSrcweir if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) || 1478cdf0e10cSrcweir xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) ) 1479cdf0e10cSrcweir { 1480cdf0e10cSrcweir rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_STRING; 1481cdf0e10cSrcweir 1482cdf0e10cSrcweir } 1483cdf0e10cSrcweir } 1484cdf0e10cSrcweir } 1485cdf0e10cSrcweir else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/rtf" ) ) ) 1486cdf0e10cSrcweir { 1487cdf0e10cSrcweir rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_RTF; 1488cdf0e10cSrcweir } 1489cdf0e10cSrcweir else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/html" ) ) ) 1490cdf0e10cSrcweir 1491cdf0e10cSrcweir { 1492cdf0e10cSrcweir rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_HTML; 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) ) 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMAT_FILE_LIST; 1497cdf0e10cSrcweir } 1498cdf0e10cSrcweir else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice-objectdescriptor-xml" ) ) ) 1499cdf0e10cSrcweir { 1500cdf0e10cSrcweir rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR; 1501cdf0e10cSrcweir } 1502cdf0e10cSrcweir } 1503cdf0e10cSrcweir } 1504cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1505cdf0e10cSrcweir { 1506cdf0e10cSrcweir } 1507cdf0e10cSrcweir } 1508cdf0e10cSrcweir 1509cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1510cdf0e10cSrcweir 1511cdf0e10cSrcweir void TransferableDataHelper::InitFormats() 1512cdf0e10cSrcweir { 1513cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 1514cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1515cdf0e10cSrcweir 1516cdf0e10cSrcweir mpFormats->clear(); 1517cdf0e10cSrcweir delete mpObjDesc, mpObjDesc = new TransferableObjectDescriptor; 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir if( mxTransfer.is() ) 1520cdf0e10cSrcweir { 1521cdf0e10cSrcweir TransferableDataHelper::FillDataFlavorExVector( mxTransfer->getTransferDataFlavors(), *mpFormats ); 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir while( aIter != aEnd ) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir if( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR == aIter->mnSotId ) 1528cdf0e10cSrcweir { 1529cdf0e10cSrcweir ImplSetParameterString( *mpObjDesc, *aIter ); 1530cdf0e10cSrcweir aIter = aEnd; 1531cdf0e10cSrcweir } 1532cdf0e10cSrcweir else 1533cdf0e10cSrcweir ++aIter; 1534cdf0e10cSrcweir } 1535cdf0e10cSrcweir } 1536cdf0e10cSrcweir } 1537cdf0e10cSrcweir 1538cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1539cdf0e10cSrcweir 1540cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( SotFormatStringId nFormat ) const 1541cdf0e10cSrcweir { 1542cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1543cdf0e10cSrcweir 1544cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 1545cdf0e10cSrcweir sal_Bool bRet = sal_False; 1546cdf0e10cSrcweir 1547cdf0e10cSrcweir while( aIter != aEnd ) 1548cdf0e10cSrcweir { 1549cdf0e10cSrcweir if( nFormat == (*aIter++).mnSotId ) 1550cdf0e10cSrcweir { 1551cdf0e10cSrcweir aIter = aEnd; 1552cdf0e10cSrcweir bRet = sal_True; 1553cdf0e10cSrcweir } 1554cdf0e10cSrcweir } 1555cdf0e10cSrcweir 1556cdf0e10cSrcweir return bRet; 1557cdf0e10cSrcweir } 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1560cdf0e10cSrcweir 1561cdf0e10cSrcweir sal_Bool TransferableDataHelper::HasFormat( const DataFlavor& rFlavor ) const 1562cdf0e10cSrcweir { 1563cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1564cdf0e10cSrcweir 1565cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 1566cdf0e10cSrcweir sal_Bool bRet = sal_False; 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir while( aIter != aEnd ) 1569cdf0e10cSrcweir { 1570cdf0e10cSrcweir if( TransferableDataHelper::IsEqual( rFlavor, *aIter++ ) ) 1571cdf0e10cSrcweir { 1572cdf0e10cSrcweir aIter = aEnd; 1573cdf0e10cSrcweir bRet = sal_True; 1574cdf0e10cSrcweir } 1575cdf0e10cSrcweir } 1576cdf0e10cSrcweir 1577cdf0e10cSrcweir return bRet; 1578cdf0e10cSrcweir } 1579cdf0e10cSrcweir 1580cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1581cdf0e10cSrcweir 1582cdf0e10cSrcweir sal_uInt32 TransferableDataHelper::GetFormatCount() const 1583cdf0e10cSrcweir { 1584cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1585cdf0e10cSrcweir return mpFormats->size(); 1586cdf0e10cSrcweir } 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1589cdf0e10cSrcweir 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir SotFormatStringId TransferableDataHelper::GetFormat( sal_uInt32 nFormat ) const 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1594cdf0e10cSrcweir DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" ); 1595cdf0e10cSrcweir return( ( nFormat < mpFormats->size() ) ? (*mpFormats)[ nFormat ].mnSotId : 0 ); 1596cdf0e10cSrcweir } 1597cdf0e10cSrcweir 1598cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1599cdf0e10cSrcweir 1600cdf0e10cSrcweir DataFlavor TransferableDataHelper::GetFormatDataFlavor( sal_uInt32 nFormat ) const 1601cdf0e10cSrcweir { 1602cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1603cdf0e10cSrcweir DBG_ASSERT( nFormat < mpFormats->size(), "TransferableDataHelper::GetFormat: invalid format index" ); 1604cdf0e10cSrcweir 1605cdf0e10cSrcweir DataFlavor aRet; 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir if( nFormat < mpFormats->size() ) 1608cdf0e10cSrcweir aRet = (*mpFormats)[ nFormat ]; 1609cdf0e10cSrcweir 1610cdf0e10cSrcweir return aRet; 1611cdf0e10cSrcweir } 1612cdf0e10cSrcweir 1613cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1614cdf0e10cSrcweir 1615cdf0e10cSrcweir Reference< XTransferable > TransferableDataHelper::GetXTransferable() const 1616cdf0e10cSrcweir { 1617cdf0e10cSrcweir Reference< XTransferable > xRet; 1618cdf0e10cSrcweir 1619cdf0e10cSrcweir if( mxTransfer.is() ) 1620cdf0e10cSrcweir { 1621cdf0e10cSrcweir try 1622cdf0e10cSrcweir { 1623cdf0e10cSrcweir xRet = mxTransfer; 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir // do a dummy call to check, if this interface is valid (nasty) 1626cdf0e10cSrcweir Sequence< DataFlavor > aTestSeq( xRet->getTransferDataFlavors() ); 1627cdf0e10cSrcweir 1628cdf0e10cSrcweir } 1629cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1630cdf0e10cSrcweir { 1631cdf0e10cSrcweir xRet = Reference< XTransferable >(); 1632cdf0e10cSrcweir } 1633cdf0e10cSrcweir } 1634cdf0e10cSrcweir 1635cdf0e10cSrcweir return xRet; 1636cdf0e10cSrcweir } 1637cdf0e10cSrcweir 1638cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1639cdf0e10cSrcweir 1640cdf0e10cSrcweir Any TransferableDataHelper::GetAny( SotFormatStringId nFormat ) const 1641cdf0e10cSrcweir { 1642cdf0e10cSrcweir Any aReturn; 1643cdf0e10cSrcweir 1644cdf0e10cSrcweir DataFlavor aFlavor; 1645cdf0e10cSrcweir if ( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) ) 1646cdf0e10cSrcweir aReturn = GetAny( aFlavor ); 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir return aReturn; 1649cdf0e10cSrcweir } 1650cdf0e10cSrcweir 1651cdf0e10cSrcweir 1652cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir Any TransferableDataHelper::GetAny( const DataFlavor& rFlavor ) const 1655cdf0e10cSrcweir { 1656cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 1657cdf0e10cSrcweir Any aRet; 1658cdf0e10cSrcweir 1659cdf0e10cSrcweir try 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir if( mxTransfer.is() ) 1662cdf0e10cSrcweir { 1663cdf0e10cSrcweir DataFlavorExVector::iterator aIter( mpFormats->begin() ), aEnd( mpFormats->end() ); 1664cdf0e10cSrcweir const SotFormatStringId nRequestFormat = SotExchange::GetFormat( rFlavor ); 1665cdf0e10cSrcweir 1666cdf0e10cSrcweir if( nRequestFormat ) 1667cdf0e10cSrcweir { 1668cdf0e10cSrcweir // try to get alien format first 1669cdf0e10cSrcweir while( aIter != aEnd ) 1670cdf0e10cSrcweir { 1671cdf0e10cSrcweir if( ( nRequestFormat == (*aIter).mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( (*aIter).MimeType ) ) 1672cdf0e10cSrcweir aRet = mxTransfer->getTransferData( *aIter ); 1673cdf0e10cSrcweir 1674cdf0e10cSrcweir if( aRet.hasValue() ) 1675cdf0e10cSrcweir aIter = aEnd; 1676cdf0e10cSrcweir else 1677cdf0e10cSrcweir aIter++; 1678cdf0e10cSrcweir } 1679cdf0e10cSrcweir } 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir if( !aRet.hasValue() ) 1682cdf0e10cSrcweir aRet = mxTransfer->getTransferData( rFlavor ); 1683cdf0e10cSrcweir } 1684cdf0e10cSrcweir } 1685cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 1686cdf0e10cSrcweir { 1687cdf0e10cSrcweir } 1688cdf0e10cSrcweir 1689cdf0e10cSrcweir return aRet; 1690cdf0e10cSrcweir } 1691cdf0e10cSrcweir 1692cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1693cdf0e10cSrcweir 1694cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, String& rStr ) 1695cdf0e10cSrcweir { 1696cdf0e10cSrcweir ::rtl::OUString aOUString; 1697cdf0e10cSrcweir sal_Bool bRet = GetString( nFormat, aOUString ); 1698cdf0e10cSrcweir 1699cdf0e10cSrcweir rStr = aOUString; 1700cdf0e10cSrcweir 1701cdf0e10cSrcweir return bRet; 1702cdf0e10cSrcweir } 1703cdf0e10cSrcweir 1704cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1705cdf0e10cSrcweir 1706cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, String& rStr ) 1707cdf0e10cSrcweir { 1708cdf0e10cSrcweir ::rtl::OUString aOUString; 1709cdf0e10cSrcweir sal_Bool bRet = GetString( rFlavor, aOUString ); 1710cdf0e10cSrcweir 1711cdf0e10cSrcweir rStr = aOUString; 1712cdf0e10cSrcweir 1713cdf0e10cSrcweir return bRet; 1714cdf0e10cSrcweir } 1715cdf0e10cSrcweir 1716cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1717cdf0e10cSrcweir 1718cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( SotFormatStringId nFormat, ::rtl::OUString& rStr ) 1719cdf0e10cSrcweir { 1720cdf0e10cSrcweir DataFlavor aFlavor; 1721cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetString( aFlavor, rStr ) ); 1722cdf0e10cSrcweir } 1723cdf0e10cSrcweir 1724cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetString( const DataFlavor& rFlavor, ::rtl::OUString& rStr ) 1727cdf0e10cSrcweir { 1728cdf0e10cSrcweir Any aAny( GetAny( rFlavor ) ); 1729cdf0e10cSrcweir sal_Bool bRet = sal_False; 1730cdf0e10cSrcweir 1731cdf0e10cSrcweir if( aAny.hasValue() ) 1732cdf0e10cSrcweir { 1733cdf0e10cSrcweir ::rtl::OUString aOUString; 1734cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 1735cdf0e10cSrcweir 1736cdf0e10cSrcweir if( aAny >>= aOUString ) 1737cdf0e10cSrcweir { 1738cdf0e10cSrcweir rStr = aOUString; 1739cdf0e10cSrcweir bRet = sal_True; 1740cdf0e10cSrcweir } 1741cdf0e10cSrcweir else if( aAny >>= aSeq ) 1742cdf0e10cSrcweir { 1743cdf0e10cSrcweir 1744cdf0e10cSrcweir const sal_Char* pChars = reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ); 1745cdf0e10cSrcweir sal_Int32 nLen = aSeq.getLength(); 1746cdf0e10cSrcweir 1747cdf0e10cSrcweir //JP 10.10.2001: 92930 - don't copy the last zero characterinto the string. 1748cdf0e10cSrcweir //DVO 2002-05-27: strip _all_ trailing zeros 1749cdf0e10cSrcweir while( nLen && ( 0 == *( pChars + nLen - 1 ) ) ) 1750cdf0e10cSrcweir --nLen; 1751cdf0e10cSrcweir 1752cdf0e10cSrcweir rStr = ::rtl::OUString( pChars, nLen, gsl_getSystemTextEncoding() ); 1753cdf0e10cSrcweir bRet = sal_True; 1754cdf0e10cSrcweir } 1755cdf0e10cSrcweir } 1756cdf0e10cSrcweir 1757cdf0e10cSrcweir return bRet; 1758cdf0e10cSrcweir } 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1761cdf0e10cSrcweir 1762cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetBitmap( SotFormatStringId nFormat, Bitmap& rBmp ) 1763cdf0e10cSrcweir { 1764cdf0e10cSrcweir DataFlavor aFlavor; 1765cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetBitmap( aFlavor, rBmp ) ); 1766cdf0e10cSrcweir } 1767cdf0e10cSrcweir 1768cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1769cdf0e10cSrcweir 1770cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetBitmap( const DataFlavor& rFlavor, Bitmap& rBmp ) 1771cdf0e10cSrcweir { 1772cdf0e10cSrcweir SotStorageStreamRef xStm; 1773cdf0e10cSrcweir DataFlavor aSubstFlavor; 1774cdf0e10cSrcweir sal_Bool bRet = GetSotStorageStream( rFlavor, xStm ); 1775cdf0e10cSrcweir 1776cdf0e10cSrcweir if( bRet ) 1777cdf0e10cSrcweir { 1778cdf0e10cSrcweir *xStm >> rBmp; 1779cdf0e10cSrcweir bRet = ( xStm->GetError() == ERRCODE_NONE ); 1780cdf0e10cSrcweir 1781cdf0e10cSrcweir /* SJ: #110748# At the moment we are having problems with DDB inserted as DIB. The 1782cdf0e10cSrcweir problem is, that some graphics are inserted much too big because the nXPelsPerMeter 1783cdf0e10cSrcweir and nYPelsPerMeter of the bitmap fileheader isn't including the correct value. 1784cdf0e10cSrcweir Due to this reason the following code assumes that bitmaps with a logical size 1785cdf0e10cSrcweir greater than 50 cm aren't having the correct mapmode set. 1786cdf0e10cSrcweir 1787cdf0e10cSrcweir The following code should be removed if DDBs and DIBs are supported via clipboard 1788cdf0e10cSrcweir properly. 1789cdf0e10cSrcweir */ 1790cdf0e10cSrcweir if ( bRet ) 1791cdf0e10cSrcweir { 1792cdf0e10cSrcweir MapMode aMapMode = rBmp.GetPrefMapMode(); 1793cdf0e10cSrcweir if ( aMapMode.GetMapUnit() != MAP_PIXEL ) 1794cdf0e10cSrcweir { 1795cdf0e10cSrcweir Size aSize = OutputDevice::LogicToLogic( rBmp.GetPrefSize(), aMapMode, MAP_100TH_MM ); 1796cdf0e10cSrcweir if ( ( aSize.Width() > 5000 ) || ( aSize.Height() > 5000 ) ) 1797cdf0e10cSrcweir rBmp.SetPrefMapMode( MAP_PIXEL ); 1798cdf0e10cSrcweir } 1799cdf0e10cSrcweir } 1800cdf0e10cSrcweir } 1801cdf0e10cSrcweir 1802cdf0e10cSrcweir if( !bRet && 1803cdf0e10cSrcweir HasFormat( SOT_FORMATSTR_ID_BMP ) && 1804cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_BMP, aSubstFlavor ) && 1805cdf0e10cSrcweir GetSotStorageStream( aSubstFlavor, xStm ) ) 1806cdf0e10cSrcweir { 1807cdf0e10cSrcweir xStm->ResetError(); 1808cdf0e10cSrcweir *xStm >> rBmp; 1809cdf0e10cSrcweir bRet = ( xStm->GetError() == ERRCODE_NONE ); 1810cdf0e10cSrcweir } 1811cdf0e10cSrcweir 1812cdf0e10cSrcweir return bRet; 1813cdf0e10cSrcweir } 1814cdf0e10cSrcweir 1815cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1816cdf0e10cSrcweir 1817cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( SotFormatStringId nFormat, GDIMetaFile& rMtf ) 1818cdf0e10cSrcweir { 1819cdf0e10cSrcweir DataFlavor aFlavor; 1820cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGDIMetaFile( aFlavor, rMtf ) ); 1821cdf0e10cSrcweir } 1822cdf0e10cSrcweir 1823cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1824cdf0e10cSrcweir 1825cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGDIMetaFile( const DataFlavor& rFlavor, GDIMetaFile& rMtf ) 1826cdf0e10cSrcweir { 1827cdf0e10cSrcweir SotStorageStreamRef xStm; 1828cdf0e10cSrcweir DataFlavor aSubstFlavor; 1829cdf0e10cSrcweir sal_Bool bRet = sal_False; 1830cdf0e10cSrcweir 1831cdf0e10cSrcweir if( GetSotStorageStream( rFlavor, xStm ) ) 1832cdf0e10cSrcweir { 1833cdf0e10cSrcweir *xStm >> rMtf; 1834cdf0e10cSrcweir bRet = ( xStm->GetError() == ERRCODE_NONE ); 1835cdf0e10cSrcweir } 1836cdf0e10cSrcweir 1837cdf0e10cSrcweir if( !bRet && 1838cdf0e10cSrcweir HasFormat( SOT_FORMATSTR_ID_EMF ) && 1839cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_EMF, aSubstFlavor ) && 1840cdf0e10cSrcweir GetSotStorageStream( aSubstFlavor, xStm ) ) 1841cdf0e10cSrcweir { 1842cdf0e10cSrcweir Graphic aGraphic; 1843cdf0e10cSrcweir 1844cdf0e10cSrcweir if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE ) 1845cdf0e10cSrcweir { 1846cdf0e10cSrcweir rMtf = aGraphic.GetGDIMetaFile(); 1847cdf0e10cSrcweir bRet = sal_True; 1848cdf0e10cSrcweir } 1849cdf0e10cSrcweir } 1850cdf0e10cSrcweir 1851cdf0e10cSrcweir if( !bRet && 1852cdf0e10cSrcweir HasFormat( SOT_FORMATSTR_ID_WMF ) && 1853cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_WMF, aSubstFlavor ) && 1854cdf0e10cSrcweir GetSotStorageStream( aSubstFlavor, xStm ) ) 1855cdf0e10cSrcweir { 1856cdf0e10cSrcweir Graphic aGraphic; 1857cdf0e10cSrcweir 1858cdf0e10cSrcweir if( GraphicConverter::Import( *xStm, aGraphic ) == ERRCODE_NONE ) 1859cdf0e10cSrcweir { 1860cdf0e10cSrcweir rMtf = aGraphic.GetGDIMetaFile(); 1861cdf0e10cSrcweir bRet = sal_True; 1862cdf0e10cSrcweir } 1863cdf0e10cSrcweir } 1864cdf0e10cSrcweir 1865cdf0e10cSrcweir return bRet; 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir 1868cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( SotFormatStringId nFormat, Graphic& rGraphic ) 1871cdf0e10cSrcweir { 1872cdf0e10cSrcweir DataFlavor aFlavor; 1873cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetGraphic( aFlavor, rGraphic ) ); 1874cdf0e10cSrcweir } 1875cdf0e10cSrcweir 1876cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetGraphic( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, Graphic& rGraphic ) 1879cdf0e10cSrcweir { 1880cdf0e10cSrcweir DataFlavor aFlavor; 1881cdf0e10cSrcweir sal_Bool bRet = sal_False; 1882cdf0e10cSrcweir 1883cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_BITMAP, aFlavor ) && 1884cdf0e10cSrcweir TransferableDataHelper::IsEqual( aFlavor, rFlavor ) ) 1885cdf0e10cSrcweir { 1886cdf0e10cSrcweir Bitmap aBmp; 1887cdf0e10cSrcweir 1888cdf0e10cSrcweir if( ( bRet = GetBitmap( aFlavor, aBmp ) ) == sal_True ) 1889cdf0e10cSrcweir rGraphic = aBmp; 1890cdf0e10cSrcweir } 1891cdf0e10cSrcweir else if( SotExchange::GetFormatDataFlavor( SOT_FORMAT_GDIMETAFILE, aFlavor ) && 1892cdf0e10cSrcweir TransferableDataHelper::IsEqual( aFlavor, rFlavor ) ) 1893cdf0e10cSrcweir { 1894cdf0e10cSrcweir GDIMetaFile aMtf; 1895cdf0e10cSrcweir 1896cdf0e10cSrcweir if( ( bRet = GetGDIMetaFile( aFlavor, aMtf ) ) == sal_True ) 1897cdf0e10cSrcweir rGraphic = aMtf; 1898cdf0e10cSrcweir } 1899cdf0e10cSrcweir else 1900cdf0e10cSrcweir { 1901cdf0e10cSrcweir SotStorageStreamRef xStm; 1902cdf0e10cSrcweir 1903cdf0e10cSrcweir if( GetSotStorageStream( rFlavor, xStm ) ) 1904cdf0e10cSrcweir { 1905cdf0e10cSrcweir *xStm >> rGraphic; 1906cdf0e10cSrcweir bRet = ( xStm->GetError() == ERRCODE_NONE ); 1907cdf0e10cSrcweir } 1908cdf0e10cSrcweir } 1909cdf0e10cSrcweir 1910cdf0e10cSrcweir return bRet; 1911cdf0e10cSrcweir } 1912cdf0e10cSrcweir 1913cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1914cdf0e10cSrcweir 1915cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( SotFormatStringId nFormat, ImageMap& rIMap ) 1916cdf0e10cSrcweir { 1917cdf0e10cSrcweir DataFlavor aFlavor; 1918cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetImageMap( aFlavor, rIMap ) ); 1919cdf0e10cSrcweir } 1920cdf0e10cSrcweir 1921cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1922cdf0e10cSrcweir 1923cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetImageMap( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, ImageMap& rIMap ) 1924cdf0e10cSrcweir { 1925cdf0e10cSrcweir SotStorageStreamRef xStm; 1926cdf0e10cSrcweir sal_Bool bRet = GetSotStorageStream( rFlavor, xStm ); 1927cdf0e10cSrcweir 1928cdf0e10cSrcweir if( bRet ) 1929cdf0e10cSrcweir { 1930cdf0e10cSrcweir rIMap.Read( *xStm, String() ); 1931cdf0e10cSrcweir bRet = ( xStm->GetError() == ERRCODE_NONE ); 1932cdf0e10cSrcweir } 1933cdf0e10cSrcweir 1934cdf0e10cSrcweir return bRet; 1935cdf0e10cSrcweir } 1936cdf0e10cSrcweir 1937cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1938cdf0e10cSrcweir 1939cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( SotFormatStringId nFormat, TransferableObjectDescriptor& rDesc ) 1940cdf0e10cSrcweir { 1941cdf0e10cSrcweir DataFlavor aFlavor; 1942cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetTransferableObjectDescriptor( aFlavor, rDesc ) ); 1943cdf0e10cSrcweir } 1944cdf0e10cSrcweir 1945cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1946cdf0e10cSrcweir 1947cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetTransferableObjectDescriptor( const ::com::sun::star::datatransfer::DataFlavor&, TransferableObjectDescriptor& rDesc ) 1948cdf0e10cSrcweir { 1949cdf0e10cSrcweir rDesc = *mpObjDesc; 1950cdf0e10cSrcweir return true; 1951cdf0e10cSrcweir } 1952cdf0e10cSrcweir 1953cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1954cdf0e10cSrcweir 1955cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( SotFormatStringId nFormat, INetBookmark& rBmk ) 1956cdf0e10cSrcweir { 1957cdf0e10cSrcweir DataFlavor aFlavor; 1958cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetBookmark( aFlavor, rBmk ) ); 1959cdf0e10cSrcweir } 1960cdf0e10cSrcweir 1961cdf0e10cSrcweir // ----------------------------------------------------------------------------- 1962cdf0e10cSrcweir 1963cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransfer::DataFlavor& rFlavor, INetBookmark& rBmk ) 1964cdf0e10cSrcweir { 1965cdf0e10cSrcweir sal_Bool bRet = sal_False; 1966cdf0e10cSrcweir if( HasFormat( rFlavor )) 1967cdf0e10cSrcweir { 1968cdf0e10cSrcweir const SotFormatStringId nFormat = SotExchange::GetFormat( rFlavor ); 1969cdf0e10cSrcweir switch( nFormat ) 1970cdf0e10cSrcweir { 1971cdf0e10cSrcweir case( SOT_FORMATSTR_ID_SOLK ): 1972cdf0e10cSrcweir case( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR ): 1973cdf0e10cSrcweir { 1974cdf0e10cSrcweir String aString; 1975cdf0e10cSrcweir if( GetString( rFlavor, aString ) ) 1976cdf0e10cSrcweir { 1977cdf0e10cSrcweir if( SOT_FORMATSTR_ID_UNIFORMRESOURCELOCATOR == nFormat ) 1978cdf0e10cSrcweir { 1979cdf0e10cSrcweir rBmk = INetBookmark( aString, aString ); 1980cdf0e10cSrcweir bRet = sal_True; 1981cdf0e10cSrcweir } 1982cdf0e10cSrcweir else 1983cdf0e10cSrcweir { 1984cdf0e10cSrcweir String aURL, aDesc; 1985cdf0e10cSrcweir sal_uInt16 nStart = aString.Search( '@' ), nLen = (sal_uInt16) aString.ToInt32(); 1986cdf0e10cSrcweir 1987cdf0e10cSrcweir if( !nLen && aString.GetChar( 0 ) != '0' ) 1988cdf0e10cSrcweir { 1989cdf0e10cSrcweir DBG_WARNING( "SOLK: 1. len=0" ); 1990cdf0e10cSrcweir } 1991cdf0e10cSrcweir if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 3 ) 1992cdf0e10cSrcweir { 1993cdf0e10cSrcweir DBG_WARNING( "SOLK: 1. illegal start or wrong len" ); 1994cdf0e10cSrcweir } 1995cdf0e10cSrcweir aURL = aString.Copy( nStart + 1, nLen ); 1996cdf0e10cSrcweir 1997cdf0e10cSrcweir aString.Erase( 0, nStart + 1 + nLen ); 1998cdf0e10cSrcweir nStart = aString.Search( '@' ); 1999cdf0e10cSrcweir nLen = (sal_uInt16) aString.ToInt32(); 2000cdf0e10cSrcweir 2001cdf0e10cSrcweir if( !nLen && aString.GetChar( 0 ) != '0' ) 2002cdf0e10cSrcweir { 2003cdf0e10cSrcweir DBG_WARNING( "SOLK: 2. len=0" ); 2004cdf0e10cSrcweir } 2005cdf0e10cSrcweir if( nStart == STRING_NOTFOUND || nLen > aString.Len() - nStart - 1 ) 2006cdf0e10cSrcweir { 2007cdf0e10cSrcweir DBG_WARNING( "SOLK: 2. illegal start or wrong len" ); 2008cdf0e10cSrcweir } 2009cdf0e10cSrcweir aDesc = aString.Copy( nStart+1, nLen ); 2010cdf0e10cSrcweir 2011cdf0e10cSrcweir rBmk = INetBookmark( aURL, aDesc ); 2012cdf0e10cSrcweir bRet = sal_True; 2013cdf0e10cSrcweir } 2014cdf0e10cSrcweir } 2015cdf0e10cSrcweir } 2016cdf0e10cSrcweir break; 2017cdf0e10cSrcweir 2018cdf0e10cSrcweir case( SOT_FORMATSTR_ID_NETSCAPE_BOOKMARK ): 2019cdf0e10cSrcweir { 2020cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 2021cdf0e10cSrcweir 2022cdf0e10cSrcweir if( GetSequence( rFlavor, aSeq ) && ( 2048 == aSeq.getLength() ) ) 2023cdf0e10cSrcweir { 2024cdf0e10cSrcweir rBmk = INetBookmark( String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ), gsl_getSystemTextEncoding() ), 2025cdf0e10cSrcweir String( reinterpret_cast< const sal_Char* >( aSeq.getConstArray() ) + 1024, gsl_getSystemTextEncoding() ) ); 2026cdf0e10cSrcweir bRet = sal_True; 2027cdf0e10cSrcweir } 2028cdf0e10cSrcweir } 2029cdf0e10cSrcweir break; 2030cdf0e10cSrcweir 2031cdf0e10cSrcweir #ifdef WNT 2032cdf0e10cSrcweir case SOT_FORMATSTR_ID_FILEGRPDESCRIPTOR: 2033cdf0e10cSrcweir { 2034cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 2035cdf0e10cSrcweir 2036cdf0e10cSrcweir if( GetSequence( rFlavor, aSeq ) && aSeq.getLength() ) 2037cdf0e10cSrcweir { 2038cdf0e10cSrcweir FILEGROUPDESCRIPTOR* pFDesc = (FILEGROUPDESCRIPTOR*) aSeq.getConstArray(); 2039cdf0e10cSrcweir 2040cdf0e10cSrcweir if( pFDesc->cItems ) 2041cdf0e10cSrcweir { 2042cdf0e10cSrcweir ByteString aDesc( pFDesc->fgd[ 0 ].cFileName ); 2043cdf0e10cSrcweir rtl_TextEncoding eTextEncoding = gsl_getSystemTextEncoding(); 2044cdf0e10cSrcweir 2045cdf0e10cSrcweir if( ( aDesc.Len() > 4 ) && aDesc.Copy( aDesc.Len() - 4 ).EqualsIgnoreCaseAscii( ".URL" ) ) 2046cdf0e10cSrcweir { 2047cdf0e10cSrcweir SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( INetURLObject( String( aDesc, eTextEncoding ) ).GetMainURL( INetURLObject::NO_DECODE ), 2048cdf0e10cSrcweir STREAM_STD_READ ); 2049cdf0e10cSrcweir 2050cdf0e10cSrcweir if( !pStream || pStream->GetError() ) 2051cdf0e10cSrcweir { 2052cdf0e10cSrcweir DataFlavor aFileContentFlavor; 2053cdf0e10cSrcweir 2054cdf0e10cSrcweir aSeq.realloc( 0 ); 2055cdf0e10cSrcweir delete pStream; 2056cdf0e10cSrcweir 2057cdf0e10cSrcweir if( SotExchange::GetFormatDataFlavor( SOT_FORMATSTR_ID_FILECONTENT, aFileContentFlavor ) && 2058cdf0e10cSrcweir GetSequence( aFileContentFlavor, aSeq ) && aSeq.getLength() ) 2059cdf0e10cSrcweir { 2060cdf0e10cSrcweir pStream = new SvMemoryStream( (sal_Char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_STD_READ ); 2061cdf0e10cSrcweir } 2062cdf0e10cSrcweir else 2063cdf0e10cSrcweir pStream = NULL; 2064cdf0e10cSrcweir } 2065cdf0e10cSrcweir 2066cdf0e10cSrcweir if( pStream ) 2067cdf0e10cSrcweir { 2068cdf0e10cSrcweir ByteString aLine; 2069cdf0e10cSrcweir sal_Bool bSttFnd = sal_False; 2070cdf0e10cSrcweir 2071cdf0e10cSrcweir while( pStream->ReadLine( aLine ) ) 2072cdf0e10cSrcweir { 2073cdf0e10cSrcweir if( aLine.EqualsIgnoreCaseAscii( "[InternetShortcut]" ) ) 2074cdf0e10cSrcweir bSttFnd = sal_True; 2075cdf0e10cSrcweir else if( bSttFnd && aLine.Copy( 0, 4 ).EqualsIgnoreCaseAscii( "URL=" ) ) 2076cdf0e10cSrcweir { 2077cdf0e10cSrcweir rBmk = INetBookmark( String( aLine.Erase( 0, 4 ), eTextEncoding ), 2078cdf0e10cSrcweir String( aDesc.Erase( aDesc.Len() - 4 ), eTextEncoding ) ); 2079cdf0e10cSrcweir bRet = sal_True; 2080cdf0e10cSrcweir break; 2081cdf0e10cSrcweir } 2082cdf0e10cSrcweir } 2083cdf0e10cSrcweir 2084cdf0e10cSrcweir delete pStream; 2085cdf0e10cSrcweir } 2086cdf0e10cSrcweir } 2087cdf0e10cSrcweir } 2088cdf0e10cSrcweir } 2089cdf0e10cSrcweir } 2090cdf0e10cSrcweir break; 2091cdf0e10cSrcweir #endif 2092cdf0e10cSrcweir 2093cdf0e10cSrcweir } 2094cdf0e10cSrcweir } 2095cdf0e10cSrcweir return bRet; 2096cdf0e10cSrcweir } 2097cdf0e10cSrcweir 2098cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2099cdf0e10cSrcweir 2100cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage( SotFormatStringId nFormat, 2101cdf0e10cSrcweir INetImage& rINtImg ) 2102cdf0e10cSrcweir { 2103cdf0e10cSrcweir DataFlavor aFlavor; 2104cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetINetImage( aFlavor, rINtImg ) ); 2105cdf0e10cSrcweir } 2106cdf0e10cSrcweir 2107cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2108cdf0e10cSrcweir 2109cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetINetImage( 2110cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& rFlavor, 2111cdf0e10cSrcweir INetImage& rINtImg ) 2112cdf0e10cSrcweir { 2113cdf0e10cSrcweir SotStorageStreamRef xStm; 2114cdf0e10cSrcweir sal_Bool bRet = GetSotStorageStream( rFlavor, xStm ); 2115cdf0e10cSrcweir 2116cdf0e10cSrcweir if( bRet ) 2117cdf0e10cSrcweir bRet = rINtImg.Read( *xStm, SotExchange::GetFormat( rFlavor ) ); 2118cdf0e10cSrcweir return bRet; 2119cdf0e10cSrcweir } 2120cdf0e10cSrcweir 2121cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2122cdf0e10cSrcweir 2123cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList( SotFormatStringId nFormat, 2124cdf0e10cSrcweir FileList& rFileList ) 2125cdf0e10cSrcweir { 2126cdf0e10cSrcweir DataFlavor aFlavor; 2127cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetFileList( aFlavor, rFileList ) ); 2128cdf0e10cSrcweir } 2129cdf0e10cSrcweir 2130cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2131cdf0e10cSrcweir 2132cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetFileList( 2133cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor&, 2134cdf0e10cSrcweir FileList& rFileList ) 2135cdf0e10cSrcweir { 2136cdf0e10cSrcweir SotStorageStreamRef xStm; 2137cdf0e10cSrcweir sal_Bool bRet = sal_False; 2138cdf0e10cSrcweir 2139cdf0e10cSrcweir for( sal_uInt32 i = 0, nFormatCount = GetFormatCount(); ( i < nFormatCount ) && !bRet; ++i ) 2140cdf0e10cSrcweir { 2141cdf0e10cSrcweir if( SOT_FORMAT_FILE_LIST == GetFormat( i ) ) 2142cdf0e10cSrcweir { 2143cdf0e10cSrcweir const DataFlavor aFlavor( GetFormatDataFlavor( i ) ); 2144cdf0e10cSrcweir 2145cdf0e10cSrcweir if( GetSotStorageStream( aFlavor, xStm ) ) 2146cdf0e10cSrcweir { 2147cdf0e10cSrcweir if( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) > -1 ) 2148cdf0e10cSrcweir { 2149cdf0e10cSrcweir ByteString aByteString; 2150cdf0e10cSrcweir 2151cdf0e10cSrcweir while( xStm->ReadLine( aByteString ) ) 2152cdf0e10cSrcweir if( aByteString.Len() && aByteString.GetChar( 0 ) != '#' ) 2153cdf0e10cSrcweir rFileList.AppendFile( String( aByteString, RTL_TEXTENCODING_UTF8 ) ); 2154cdf0e10cSrcweir 2155cdf0e10cSrcweir bRet = sal_True; 2156cdf0e10cSrcweir } 2157cdf0e10cSrcweir else 2158cdf0e10cSrcweir bRet = ( ( *xStm >> rFileList ).GetError() == ERRCODE_NONE ); 2159cdf0e10cSrcweir } 2160cdf0e10cSrcweir } 2161cdf0e10cSrcweir } 2162cdf0e10cSrcweir 2163cdf0e10cSrcweir return bRet; 2164cdf0e10cSrcweir } 2165cdf0e10cSrcweir 2166cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2167cdf0e10cSrcweir 2168cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( SotFormatStringId nFormat, Sequence< sal_Int8 >& rSeq ) 2169cdf0e10cSrcweir { 2170cdf0e10cSrcweir DataFlavor aFlavor; 2171cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSequence( aFlavor, rSeq ) ); 2172cdf0e10cSrcweir } 2173cdf0e10cSrcweir 2174cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2175cdf0e10cSrcweir 2176cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSequence( const DataFlavor& rFlavor, Sequence< sal_Int8 >& rSeq ) 2177cdf0e10cSrcweir { 2178cdf0e10cSrcweir #ifdef DEBUG 2179cdf0e10cSrcweir fprintf( stderr, "TransferableDataHelper requests sequence of data\n" ); 2180cdf0e10cSrcweir #endif 2181cdf0e10cSrcweir 2182cdf0e10cSrcweir const Any aAny( GetAny( rFlavor ) ); 2183cdf0e10cSrcweir return( aAny.hasValue() && ( aAny >>= rSeq ) ); 2184cdf0e10cSrcweir } 2185cdf0e10cSrcweir 2186cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2187cdf0e10cSrcweir 2188cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( SotFormatStringId nFormat, SotStorageStreamRef& rxStream ) 2189cdf0e10cSrcweir { 2190cdf0e10cSrcweir DataFlavor aFlavor; 2191cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetSotStorageStream( aFlavor, rxStream ) ); 2192cdf0e10cSrcweir } 2193cdf0e10cSrcweir 2194cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2195cdf0e10cSrcweir 2196cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetSotStorageStream( const DataFlavor& rFlavor, SotStorageStreamRef& rxStream ) 2197cdf0e10cSrcweir { 2198cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 2199cdf0e10cSrcweir sal_Bool bRet = GetSequence( rFlavor, aSeq ); 2200cdf0e10cSrcweir 2201cdf0e10cSrcweir if( bRet ) 2202cdf0e10cSrcweir { 2203cdf0e10cSrcweir rxStream = new SotStorageStream( String() ); 2204cdf0e10cSrcweir rxStream->Write( aSeq.getConstArray(), aSeq.getLength() ); 2205cdf0e10cSrcweir rxStream->Seek( 0 ); 2206cdf0e10cSrcweir } 2207cdf0e10cSrcweir 2208cdf0e10cSrcweir return bRet; 2209cdf0e10cSrcweir } 2210cdf0e10cSrcweir 2211cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( SotFormatStringId nFormat, Reference < XInputStream >& rxStream ) 2212cdf0e10cSrcweir { 2213cdf0e10cSrcweir DataFlavor aFlavor; 2214cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInputStream( aFlavor, rxStream ) ); 2215cdf0e10cSrcweir } 2216cdf0e10cSrcweir 2217cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2218cdf0e10cSrcweir 2219cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInputStream( const DataFlavor& rFlavor, Reference < XInputStream >& rxStream ) 2220cdf0e10cSrcweir { 2221cdf0e10cSrcweir Sequence< sal_Int8 > aSeq; 2222cdf0e10cSrcweir sal_Bool bRet = GetSequence( rFlavor, aSeq ); 2223cdf0e10cSrcweir 2224cdf0e10cSrcweir if( bRet ) 2225cdf0e10cSrcweir rxStream = new ::comphelper::SequenceInputStream( aSeq ); 2226cdf0e10cSrcweir 2227cdf0e10cSrcweir return bRet; 2228cdf0e10cSrcweir } 2229cdf0e10cSrcweir 2230cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2231cdf0e10cSrcweir 2232cdf0e10cSrcweir 2233cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( SotFormatStringId nFormat, Reference< XInterface >& rIf ) 2234cdf0e10cSrcweir { 2235cdf0e10cSrcweir DataFlavor aFlavor; 2236cdf0e10cSrcweir return( SotExchange::GetFormatDataFlavor( nFormat, aFlavor ) && GetInterface( aFlavor, rIf ) ); 2237cdf0e10cSrcweir } 2238cdf0e10cSrcweir 2239cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2240cdf0e10cSrcweir 2241cdf0e10cSrcweir sal_Bool TransferableDataHelper::GetInterface( const DataFlavor& rFlavor, Reference< XInterface >& rIf ) 2242cdf0e10cSrcweir { 2243cdf0e10cSrcweir const Any aAny( GetAny( rFlavor ) ); 2244cdf0e10cSrcweir return( aAny.hasValue() && ( aAny >>= rIf ) ); 2245cdf0e10cSrcweir } 2246cdf0e10cSrcweir 2247cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2248cdf0e10cSrcweir void TransferableDataHelper::Rebind( const Reference< XTransferable >& _rxNewContent ) 2249cdf0e10cSrcweir { 2250cdf0e10cSrcweir mxTransfer = _rxNewContent; 2251cdf0e10cSrcweir InitFormats(); 2252cdf0e10cSrcweir } 2253cdf0e10cSrcweir 2254cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2255cdf0e10cSrcweir 2256cdf0e10cSrcweir sal_Bool TransferableDataHelper::StartClipboardListening( ) 2257cdf0e10cSrcweir { 2258cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 2259cdf0e10cSrcweir 2260cdf0e10cSrcweir StopClipboardListening( ); 2261cdf0e10cSrcweir 2262cdf0e10cSrcweir mpImpl->mpClipboardListener = new TransferableClipboardNotifier( mxClipboard, *this, mpImpl->maMutex ); 2263cdf0e10cSrcweir mpImpl->mpClipboardListener->acquire(); 2264cdf0e10cSrcweir 2265cdf0e10cSrcweir return mpImpl->mpClipboardListener->isListening(); 2266cdf0e10cSrcweir } 2267cdf0e10cSrcweir 2268cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2269cdf0e10cSrcweir 2270cdf0e10cSrcweir void TransferableDataHelper::StopClipboardListening( ) 2271cdf0e10cSrcweir { 2272cdf0e10cSrcweir ::osl::MutexGuard aGuard( mpImpl->maMutex ); 2273cdf0e10cSrcweir 2274cdf0e10cSrcweir if ( mpImpl->mpClipboardListener ) 2275cdf0e10cSrcweir { 2276cdf0e10cSrcweir mpImpl->mpClipboardListener->dispose(); 2277cdf0e10cSrcweir mpImpl->mpClipboardListener->release(); 2278cdf0e10cSrcweir mpImpl->mpClipboardListener = NULL; 2279cdf0e10cSrcweir } 2280cdf0e10cSrcweir } 2281cdf0e10cSrcweir 2282cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2283cdf0e10cSrcweir 2284cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSystemClipboard( Window * pWindow ) 2285cdf0e10cSrcweir { 2286cdf0e10cSrcweir DBG_ASSERT( pWindow, "Window pointer is NULL" ); 2287cdf0e10cSrcweir 2288cdf0e10cSrcweir Reference< XClipboard > xClipboard; 2289cdf0e10cSrcweir TransferableDataHelper aRet; 2290cdf0e10cSrcweir 2291cdf0e10cSrcweir if( pWindow ) 2292cdf0e10cSrcweir xClipboard = pWindow->GetClipboard(); 2293cdf0e10cSrcweir 2294cdf0e10cSrcweir if( xClipboard.is() ) 2295cdf0e10cSrcweir { 2296cdf0e10cSrcweir try 2297cdf0e10cSrcweir 2298cdf0e10cSrcweir { 2299cdf0e10cSrcweir Reference< XTransferable > xTransferable( xClipboard->getContents() ); 2300cdf0e10cSrcweir 2301cdf0e10cSrcweir if( xTransferable.is() ) 2302cdf0e10cSrcweir { 2303cdf0e10cSrcweir aRet = TransferableDataHelper( xTransferable ); 2304cdf0e10cSrcweir aRet.mxClipboard = xClipboard; 2305cdf0e10cSrcweir // also copy the clipboard - 99030 - 23.05.2002 - fs@openoffice.org 2306cdf0e10cSrcweir } 2307cdf0e10cSrcweir } 2308cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 2309cdf0e10cSrcweir { 2310cdf0e10cSrcweir } 2311cdf0e10cSrcweir } 2312cdf0e10cSrcweir 2313cdf0e10cSrcweir return aRet; 2314cdf0e10cSrcweir } 2315cdf0e10cSrcweir 2316cdf0e10cSrcweir 2317cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2318cdf0e10cSrcweir 2319cdf0e10cSrcweir TransferableDataHelper TransferableDataHelper::CreateFromSelection( Window* pWindow ) 2320cdf0e10cSrcweir { 2321cdf0e10cSrcweir DBG_ASSERT( pWindow, "Window pointer is NULL" ); 2322cdf0e10cSrcweir 2323cdf0e10cSrcweir Reference< XClipboard > xSelection; 2324cdf0e10cSrcweir TransferableDataHelper aRet; 2325cdf0e10cSrcweir 2326cdf0e10cSrcweir if( pWindow ) 2327cdf0e10cSrcweir xSelection = pWindow->GetPrimarySelection(); 2328cdf0e10cSrcweir 2329cdf0e10cSrcweir if( xSelection.is() ) 2330cdf0e10cSrcweir { 2331cdf0e10cSrcweir const sal_uInt32 nRef = Application::ReleaseSolarMutex(); 2332cdf0e10cSrcweir 2333cdf0e10cSrcweir try 2334cdf0e10cSrcweir { 2335cdf0e10cSrcweir Reference< XTransferable > xTransferable( xSelection->getContents() ); 2336cdf0e10cSrcweir 2337cdf0e10cSrcweir if( xTransferable.is() ) 2338cdf0e10cSrcweir { 2339cdf0e10cSrcweir aRet = TransferableDataHelper( xTransferable ); 2340cdf0e10cSrcweir aRet.mxClipboard = xSelection; 2341cdf0e10cSrcweir } 2342cdf0e10cSrcweir } 2343cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 2344cdf0e10cSrcweir { 2345cdf0e10cSrcweir } 2346cdf0e10cSrcweir 2347cdf0e10cSrcweir Application::AcquireSolarMutex( nRef ); 2348cdf0e10cSrcweir } 2349cdf0e10cSrcweir 2350cdf0e10cSrcweir return aRet; 2351cdf0e10cSrcweir } 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir // ----------------------------------------------------------------------------- 2354cdf0e10cSrcweir sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer::DataFlavor& rInternalFlavor, 2355cdf0e10cSrcweir const ::com::sun::star::datatransfer::DataFlavor& rRequestFlavor, 2356cdf0e10cSrcweir sal_Bool ) 2357cdf0e10cSrcweir { 2358cdf0e10cSrcweir Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); 2359cdf0e10cSrcweir Reference< XMimeContentTypeFactory > xMimeFact; 2360cdf0e10cSrcweir sal_Bool bRet = sal_False; 2361cdf0e10cSrcweir 2362cdf0e10cSrcweir try 2363cdf0e10cSrcweir { 2364cdf0e10cSrcweir if( xFact.is() ) 2365cdf0e10cSrcweir xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii( 2366cdf0e10cSrcweir "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), 2367cdf0e10cSrcweir UNO_QUERY ); 2368cdf0e10cSrcweir 2369cdf0e10cSrcweir if( xMimeFact.is() ) 2370cdf0e10cSrcweir { 2371cdf0e10cSrcweir Reference< XMimeContentType > xRequestType1( xMimeFact->createMimeContentType( rInternalFlavor.MimeType ) ); 2372cdf0e10cSrcweir Reference< XMimeContentType > xRequestType2( xMimeFact->createMimeContentType( rRequestFlavor.MimeType ) ); 2373cdf0e10cSrcweir 2374cdf0e10cSrcweir if( xRequestType1.is() && xRequestType2.is() ) 2375cdf0e10cSrcweir { 2376cdf0e10cSrcweir if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) ) 2377cdf0e10cSrcweir { 2378cdf0e10cSrcweir if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) ) 2379cdf0e10cSrcweir { 2380cdf0e10cSrcweir // special handling for text/plain media types 2381cdf0e10cSrcweir const ::rtl::OUString aCharsetString( ::rtl::OUString::createFromAscii( "charset" ) ); 2382cdf0e10cSrcweir 2383cdf0e10cSrcweir if( !xRequestType2->hasParameter( aCharsetString ) || 2384cdf0e10cSrcweir xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) || 2385cdf0e10cSrcweir xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) ) 2386cdf0e10cSrcweir { 2387cdf0e10cSrcweir bRet = sal_True; 2388cdf0e10cSrcweir } 2389cdf0e10cSrcweir } 2390cdf0e10cSrcweir else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice" ) ) ) 2391cdf0e10cSrcweir { 2392cdf0e10cSrcweir // special handling for application/x-openoffice media types 2393cdf0e10cSrcweir const ::rtl::OUString aFormatString( ::rtl::OUString::createFromAscii( "windows_formatname" ) ); 2394cdf0e10cSrcweir 2395cdf0e10cSrcweir if( xRequestType1->hasParameter( aFormatString ) && 2396cdf0e10cSrcweir xRequestType2->hasParameter( aFormatString ) && 2397cdf0e10cSrcweir xRequestType1->getParameterValue( aFormatString ).equalsIgnoreAsciiCase( xRequestType2->getParameterValue( aFormatString ) ) ) 2398cdf0e10cSrcweir { 2399cdf0e10cSrcweir bRet = sal_True; 2400cdf0e10cSrcweir } 2401cdf0e10cSrcweir } 2402cdf0e10cSrcweir else 2403cdf0e10cSrcweir bRet = sal_True; 2404cdf0e10cSrcweir } 2405cdf0e10cSrcweir } 2406cdf0e10cSrcweir } 2407cdf0e10cSrcweir } 2408cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) 2409cdf0e10cSrcweir { 2410cdf0e10cSrcweir bRet = rInternalFlavor.MimeType.equalsIgnoreAsciiCase( rRequestFlavor.MimeType ); 2411cdf0e10cSrcweir } 2412cdf0e10cSrcweir 2413cdf0e10cSrcweir return bRet; 2414cdf0e10cSrcweir } 2415