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