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