diff options
Diffstat (limited to 'svtools/source/misc/transfer.cxx')
-rw-r--r-- | svtools/source/misc/transfer.cxx | 153 |
1 files changed, 68 insertions, 85 deletions
diff --git a/svtools/source/misc/transfer.cxx b/svtools/source/misc/transfer.cxx index fcd519398c8e..4b24ed4330fd 100644 --- a/svtools/source/misc/transfer.cxx +++ b/svtools/source/misc/transfer.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,20 +29,12 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svtools.hxx" #ifdef WNT -#include <tools/prewin.h> -#if defined _MSC_VER -#pragma warning(push, 1) -#pragma warning(disable: 4917) -#endif +#include <prewin.h> +#include <postwin.h> #include <shlobj.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif -#include <tools/postwin.h> #endif -#include <vos/mutex.hxx> +#include <osl/mutex.hxx> #include <rtl/memory.h> -#include <rtl/uuid.h> #include <rtl/uri.hxx> #include <tools/debug.hxx> #include <tools/urlobj.hxx> @@ -55,6 +48,7 @@ #include <vcl/svapp.hxx> #include <vcl/window.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/servicehelper.hxx> #include <sot/filelist.hxx> #include <cppuhelper/implbase1.hxx> @@ -154,20 +148,20 @@ const ::rtl::OUString aQuotedParamChars = ::rtl::OUString( RTL_CONSTASCII_USTRIN static ::rtl::OUString ImplGetParameterString( const TransferableObjectDescriptor& rObjDesc ) { - const ::rtl::OUString aChar( ::rtl::OUString::createFromAscii( "\"" ) ); + const ::rtl::OUString aChar( RTL_CONSTASCII_USTRINGPARAM( "\"" )); const ::rtl::OUString aClassName( rObjDesc.maClassName.GetHexName() ); ::rtl::OUString aParams; if( aClassName.getLength() ) { - aParams += ::rtl::OUString::createFromAscii( ";classname=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";classname=\"" )); aParams += aClassName; aParams += aChar; } if( rObjDesc.maTypeName.Len() ) { - aParams += ::rtl::OUString::createFromAscii( ";typename=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";typename=\"" )); aParams += rObjDesc.maTypeName; aParams += aChar; } @@ -187,28 +181,28 @@ static ::rtl::OUString ImplGetParameterString( const TransferableObjectDescripto pToAccept[nChar] = sal_True; } - aParams += ::rtl::OUString::createFromAscii( ";displayname=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";displayname=\"" )); aParams += ::rtl::Uri::encode( rObjDesc.maDisplayName, pToAccept, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8 ); aParams += aChar; } - aParams += ::rtl::OUString::createFromAscii( ";viewaspect=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";viewaspect=\"" )); aParams += ::rtl::OUString::valueOf( static_cast< sal_Int32 >( rObjDesc.mnViewAspect ) ); aParams += aChar; - aParams += ::rtl::OUString::createFromAscii( ";width=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";width=\"" )); aParams += ::rtl::OUString::valueOf( rObjDesc.maSize.Width() ); aParams += aChar; - aParams += ::rtl::OUString::createFromAscii( ";height=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";height=\"" )); aParams += ::rtl::OUString::valueOf( rObjDesc.maSize.Height() ); aParams += aChar; - aParams += ::rtl::OUString::createFromAscii( ";posx=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";posx=\"" )); aParams += ::rtl::OUString::valueOf( rObjDesc.maDragStartPos.X() ); aParams += aChar; - aParams += ::rtl::OUString::createFromAscii( ";posy=\"" ); + aParams += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ";posy=\"" )); aParams += ::rtl::OUString::valueOf( rObjDesc.maDragStartPos.X() ); aParams += aChar; @@ -226,8 +220,7 @@ static void ImplSetParameterString( TransferableObjectDescriptor& rObjDesc, cons { if( xFact.is() ) { - xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii( - "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), + xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.MimeContentTypeFactory" )) ), UNO_QUERY ); } @@ -237,14 +230,14 @@ static void ImplSetParameterString( TransferableObjectDescriptor& rObjDesc, cons if( xMimeType.is() ) { - const ::rtl::OUString aClassNameString( ::rtl::OUString::createFromAscii( "classname" ) ); - const ::rtl::OUString aTypeNameString( ::rtl::OUString::createFromAscii( "typename" ) ); - const ::rtl::OUString aDisplayNameString( ::rtl::OUString::createFromAscii( "displayname" ) ); - const ::rtl::OUString aViewAspectString( ::rtl::OUString::createFromAscii( "viewaspect" ) ); - const ::rtl::OUString aWidthString( ::rtl::OUString::createFromAscii( "width" ) ); - const ::rtl::OUString aHeightString( ::rtl::OUString::createFromAscii( "height" ) ); - const ::rtl::OUString aPosXString( ::rtl::OUString::createFromAscii( "posx" ) ); - const ::rtl::OUString aPosYString( ::rtl::OUString::createFromAscii( "posy" ) ); + const ::rtl::OUString aClassNameString(RTL_CONSTASCII_USTRINGPARAM( "classname" )); + const ::rtl::OUString aTypeNameString(RTL_CONSTASCII_USTRINGPARAM( "typename" )); + const ::rtl::OUString aDisplayNameString(RTL_CONSTASCII_USTRINGPARAM( "displayname" )); + const ::rtl::OUString aViewAspectString(RTL_CONSTASCII_USTRINGPARAM( "viewaspect" )); + const ::rtl::OUString aWidthString(RTL_CONSTASCII_USTRINGPARAM( "width" )); + const ::rtl::OUString aHeightString(RTL_CONSTASCII_USTRINGPARAM( "height" )); + const ::rtl::OUString aPosXString(RTL_CONSTASCII_USTRINGPARAM( "posx" )); + const ::rtl::OUString aPosYString(RTL_CONSTASCII_USTRINGPARAM( "posy" )); if( xMimeType->hasParameter( aClassNameString ) ) { @@ -353,7 +346,7 @@ Any SAL_CALL TransferableHelper::getTransferData( const DataFlavor& rFlavor ) th { if( !maAny.hasValue() || !mpFormats->size() || ( maLastFormat != rFlavor.MimeType ) ) { - const ::vos::OGuard aGuard( Application::GetSolarMutex() ); + const SolarMutexGuard aGuard; maLastFormat = rFlavor.MimeType; maAny = Any(); @@ -470,7 +463,7 @@ Any SAL_CALL TransferableHelper::getTransferData( const DataFlavor& rFlavor ) th Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() throw( RuntimeException ) { - const ::vos::OGuard aGuard( Application::GetSolarMutex() ); + const SolarMutexGuard aGuard; try { @@ -497,7 +490,7 @@ Sequence< DataFlavor > SAL_CALL TransferableHelper::getTransferDataFlavors() thr sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& rFlavor ) throw( RuntimeException ) { - const ::vos::OGuard aGuard( Application::GetSolarMutex() ); + const SolarMutexGuard aGuard; sal_Bool bRet = sal_False; try @@ -529,7 +522,7 @@ sal_Bool SAL_CALL TransferableHelper::isDataFlavorSupported( const DataFlavor& r void SAL_CALL TransferableHelper::lostOwnership( const Reference< XClipboard >&, const Reference< XTransferable >& ) throw( RuntimeException ) { - const ::vos::OGuard aGuard( Application::GetSolarMutex() ); + const SolarMutexGuard aGuard; try { @@ -539,7 +532,7 @@ void SAL_CALL TransferableHelper::lostOwnership( const Reference< XClipboard >&, if( xFact.is() ) { - Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ), UNO_QUERY ); if( xDesktop.is() ) xDesktop->removeTerminateListener( mxTerminateListener ); @@ -565,7 +558,7 @@ void SAL_CALL TransferableHelper::disposing( const EventObject& ) throw( Runtime void SAL_CALL TransferableHelper::dragDropEnd( const DragSourceDropEvent& rDSDE ) throw( RuntimeException ) { - const ::vos::OGuard aGuard( Application::GetSolarMutex() ); + const SolarMutexGuard aGuard; try { @@ -634,7 +627,7 @@ void TransferableHelper::ImplFlush() } catch( const ::com::sun::star::uno::Exception& ) { - DBG_ERROR( "Could not flush clipboard" ); + OSL_FAIL( "Could not flush clipboard" ); } Application::AcquireSolarMutex( nRef ); @@ -819,7 +812,7 @@ sal_Bool TransferableHelper::SetBitmap( const Bitmap& rBitmap, const DataFlavor& sal_Bool TransferableHelper::SetGDIMetaFile( const GDIMetaFile& rMtf, const DataFlavor& ) { - if( rMtf.GetActionCount() ) + if( rMtf.GetActionSize() ) { SvMemoryStream aMemStm( 65535, 65535 ); @@ -950,7 +943,7 @@ sal_Bool TransferableHelper::SetINetBookmark( const INetBookmark& rBmk, case SOT_FORMATSTR_ID_FILECONTENT: { - String aStr( RTL_CONSTASCII_STRINGPARAM( "[InternetShortcut]\x0aURL=" ) ); + String aStr( RTL_CONSTASCII_USTRINGPARAM( "[InternetShortcut]\x0aURL=" ) ); maAny <<= ::rtl::OUString( aStr += rBmk.GetURL() ); } break; @@ -1038,7 +1031,7 @@ sal_Bool TransferableHelper::SetInterface( const ::com::sun::star::uno::Referenc sal_Bool TransferableHelper::WriteObject( SotStorageStreamRef&, void*, sal_uInt32, const DataFlavor& ) { - DBG_ERROR( "TransferableHelper::WriteObject( ... ) not implemented" ); + OSL_FAIL( "TransferableHelper::WriteObject( ... ) not implemented" ); return sal_False; } @@ -1089,7 +1082,7 @@ void TransferableHelper::CopyToClipboard( Window *pWindow ) const if( xFact.is() ) { - Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ), UNO_QUERY ); if( xDesktop.is() ) xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) ); @@ -1126,7 +1119,7 @@ void TransferableHelper::CopyToSelection( Window *pWindow ) const if( xFact.is() ) { - Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ), UNO_QUERY ); + Reference< XDesktop > xDesktop( xFact->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" )) ), UNO_QUERY ); if( xDesktop.is() ) xDesktop->addTerminateListener( pThis->mxTerminateListener = new TerminateListener( *pThis ) ); @@ -1214,23 +1207,14 @@ Reference< XClipboard> TransferableHelper::GetSystemClipboard() return Reference< XClipboard > (); } -// ----------------------------------------------------------------------------- +namespace +{ + class theTransferableHelperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theTransferableHelperUnoTunnelId > {}; +} const Sequence< sal_Int8 >& TransferableHelper::getUnoTunnelId() { - static Sequence< sal_Int8 > aSeq; - - if( !aSeq.getLength() ) - { - static osl::Mutex aCreateMutex; - osl::Guard< osl::Mutex > aGuard( aCreateMutex ); - - aSeq.realloc( 16 ); - rtl_createUuid( reinterpret_cast< sal_uInt8* >( aSeq.getArray() ), 0, sal_True ); - } - - - return aSeq; + return theTransferableHelperUnoTunnelId::get().getSeq(); } // --------------------------------- @@ -1286,7 +1270,7 @@ TransferableClipboardNotifier::TransferableClipboardNotifier( const Reference< X void SAL_CALL TransferableClipboardNotifier::changedContents( const clipboard::ClipboardEvent& event ) throw (RuntimeException) { - ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + SolarMutexGuard aSolarGuard; // the SolarMutex here is necessary, since // - we cannot call mpListener without our own mutex locked // - Rebind respectively InitFormats (called by Rebind) will @@ -1415,11 +1399,10 @@ void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor Reference< XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() ); Reference< XMimeContentTypeFactory > xMimeFact; DataFlavorEx aFlavorEx; - const ::rtl::OUString aCharsetStr( ::rtl::OUString::createFromAscii( "charset" ) ); + const ::rtl::OUString aCharsetStr(RTL_CONSTASCII_USTRINGPARAM( "charset" )); if( xFact.is() ) - xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii( - "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), + xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.MimeContentTypeFactory" )) ), UNO_QUERY ); for( sal_Int32 i = 0; i < rDataFlavorSeq.getLength(); i++ ) @@ -1467,35 +1450,35 @@ void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor aFlavorEx.mnSotId = SOT_FORMATSTR_ID_HTML_NO_COMMENT; rDataFlavorExVector.push_back( aFlavorEx ); } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) ) + else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/plain" )) ) ) { // add, if it is a UTF-8 byte buffer if( xMimeType->hasParameter( aCharsetStr ) ) { const ::rtl::OUString aCharset( xMimeType->getParameterValue( aCharsetStr ) ); - if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) || - xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) ) + if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unicode" )) ) || + xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "utf-16" )) ) ) { rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_STRING; } } } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/rtf" ) ) ) + else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/rtf" )) ) ) { rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = FORMAT_RTF; } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/html" ) ) ) + else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/html" )) ) ) { rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_HTML; } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) ) + else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/uri-list" )) ) ) { rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMAT_FILE_LIST; } - else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice-objectdescriptor-xml" ) ) ) + else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-objectdescriptor-xml" )) ) ) { rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SOT_FORMATSTR_ID_OBJECTDESCRIPTOR; } @@ -1510,7 +1493,7 @@ void TransferableDataHelper::FillDataFlavorExVector( const Sequence< DataFlavor void TransferableDataHelper::InitFormats() { - ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); + SolarMutexGuard aSolarGuard; ::osl::MutexGuard aGuard( mpImpl->maMutex ); mpFormats->clear(); @@ -2144,7 +2127,7 @@ sal_Bool TransferableDataHelper::GetFileList( if( GetSotStorageStream( aFlavor, xStm ) ) { - if( aFlavor.MimeType.indexOf( ::rtl::OUString::createFromAscii( "text/uri-list" ) ) > -1 ) + if( aFlavor.MimeType.indexOf( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/uri-list" )) ) > -1 ) { ByteString aByteString; @@ -2286,28 +2269,27 @@ TransferableDataHelper TransferableDataHelper::CreateFromSystemClipboard( Window DBG_ASSERT( pWindow, "Window pointer is NULL" ); Reference< XClipboard > xClipboard; - TransferableDataHelper aRet; + TransferableDataHelper aRet; if( pWindow ) xClipboard = pWindow->GetClipboard(); if( xClipboard.is() ) - { - try - + { + try { Reference< XTransferable > xTransferable( xClipboard->getContents() ); if( xTransferable.is() ) { aRet = TransferableDataHelper( xTransferable ); - aRet.mxClipboard = xClipboard; - // also copy the clipboard - 99030 - 23.05.2002 - fs@openoffice.org + // also copy the clipboard + aRet.mxClipboard = xClipboard; } - } + } catch( const ::com::sun::star::uno::Exception& ) { - } + } } return aRet; @@ -2362,8 +2344,7 @@ sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer:: try { if( xFact.is() ) - xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString::createFromAscii( - "com.sun.star.datatransfer.MimeContentTypeFactory" ) ), + xMimeFact = Reference< XMimeContentTypeFactory >( xFact->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.datatransfer.MimeContentTypeFactory" )) ), UNO_QUERY ); if( xMimeFact.is() ) @@ -2375,22 +2356,22 @@ sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer:: { if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) ) { - if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "text/plain" ) ) ) + if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/plain" )) ) ) { // special handling for text/plain media types - const ::rtl::OUString aCharsetString( ::rtl::OUString::createFromAscii( "charset" ) ); + const ::rtl::OUString aCharsetString(RTL_CONSTASCII_USTRINGPARAM( "charset" )); if( !xRequestType2->hasParameter( aCharsetString ) || - xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "utf-16" ) ) || - xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "unicode" ) ) ) + xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "utf-16" )) ) || + xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unicode" )) ) ) { bRet = sal_True; } } - else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString::createFromAscii( "application/x-openoffice" ) ) ) + else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice" )) ) ) { // special handling for application/x-openoffice media types - const ::rtl::OUString aFormatString( ::rtl::OUString::createFromAscii( "windows_formatname" ) ); + const ::rtl::OUString aFormatString(RTL_CONSTASCII_USTRINGPARAM( "windows_formatname" )); if( xRequestType1->hasParameter( aFormatString ) && xRequestType2->hasParameter( aFormatString ) && @@ -2412,3 +2393,5 @@ sal_Bool TransferableDataHelper::IsEqual( const ::com::sun::star::datatransfer:: return bRet; } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |