26#include <osl/mutex.hxx>
50#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
51#include <com/sun/star/datatransfer/clipboard/XClipboardNotifier.hpp>
52#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
53#include <com/sun/star/datatransfer/MimeContentTypeFactory.hpp>
54#include <com/sun/star/datatransfer/XMimeContentType.hpp>
55#include <com/sun/star/datatransfer/XTransferable2.hpp>
56#include <com/sun/star/frame/Desktop.hpp>
63#include <rtl/strbuf.hxx>
80using namespace std::literals::string_view_literals;
83#define TOD_SIG1 0x01234567
84#define TOD_SIG2 0x89abcdef
88 const sal_uInt32 nFirstPos = rOStm.
Tell(), nViewAspect = rObjDesc.
mnViewAspect;
102 const sal_uInt32 nLastPos = rOStm.
Tell();
104 rOStm.
Seek( nFirstPos );
106 rOStm.
Seek( nLastPos );
121 if( !aClassName.isEmpty() )
123 aParams +=
";classname=\"" + aClassName +
"\"";
128 aParams +=
";typename=\"" + rObjDesc.
maTypeName +
"\"";
135 static constexpr auto pToAccept = rtl::createUriCharClass(
136 u8
"()<>@,;:/[]?=!#$&'*+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~. ");
138 aParams +=
";displayname=\""
140 rObjDesc.
maDisplayName, pToAccept.data(), rtl_UriEncodeIgnoreEscapes,
141 RTL_TEXTENCODING_UTF8)
145 aParams +=
";viewaspect=\"" + OUString::number(rObjDesc.
mnViewAspect)
146 +
"\";width=\"" + OUString::number(rObjDesc.
maSize.
Width())
147 +
"\";height=\"" + OUString::number(rObjDesc.
maSize.
Height())
157 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
161 Reference< XMimeContentTypeFactory > xMimeFact = MimeContentTypeFactory::create( xContext );
163 Reference< XMimeContentType > xMimeType( xMimeFact->createMimeContentType( rFlavorEx.MimeType ) );
167 static constexpr OUStringLiteral aClassNameString(
u"classname" );
168 static constexpr OUStringLiteral aTypeNameString(
u"typename" );
169 static constexpr OUStringLiteral aDisplayNameString(
u"displayname" );
170 static constexpr OUStringLiteral aViewAspectString(
u"viewaspect" );
171 static constexpr OUStringLiteral aWidthString(
u"width" );
172 static constexpr OUStringLiteral aHeightString(
u"height" );
173 static constexpr OUStringLiteral aPosXString(
u"posx" );
174 static constexpr OUStringLiteral aPosYString(
u"posy" );
176 if( xMimeType->hasParameter( aClassNameString ) )
181 if( xMimeType->hasParameter( aTypeNameString ) )
183 rObjDesc.
maTypeName = xMimeType->getParameterValue( aTypeNameString );
186 if( xMimeType->hasParameter( aDisplayNameString ) )
190 rObjDesc.
maDisplayName = ::rtl::Uri::decode( xMimeType->getParameterValue( aDisplayNameString ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
193 if( xMimeType->hasParameter( aViewAspectString ) )
195 rObjDesc.
mnViewAspect =
static_cast< sal_uInt16
>( xMimeType->getParameterValue( aViewAspectString ).toInt32() );
198 if( xMimeType->hasParameter( aWidthString ) )
200 rObjDesc.
maSize.
setWidth( xMimeType->getParameterValue( aWidthString ).toInt32() );
203 if( xMimeType->hasParameter( aHeightString ) )
205 rObjDesc.
maSize.
setHeight( xMimeType->getParameterValue( aHeightString ).toInt32() );
208 if( xMimeType->hasParameter( aPosXString ) )
210 rObjDesc.
maDragStartPos.
setX( xMimeType->getParameterValue( aPosXString ).toInt32() );
213 if( xMimeType->hasParameter( aPosYString ) )
215 rObjDesc.
maDragStartPos.
setY( xMimeType->getParameterValue( aPosYString ).toInt32() );
219 catch(
const css::uno::Exception& )
253 return "com.sun.star.comp.svt.TransferableHelperTerminateListener";
268 css::uno::Reference<css::frame::XTerminateListener> listener;
295 DataFlavor aSubstFlavor;
306 GetData(aSubstFlavor, rDestDoc);
307 bDone =
maAny.hasValue();
313 GetData(aSubstFlavor, rDestDoc);
320 GetData(aSubstFlavor, rDestDoc);
322 if(
maAny.hasValue() )
332 aReader.
Read( aMtf );
340 maAny <<= Sequence< sal_Int8 >(
static_cast< const sal_Int8*
>( aDstStm.
GetData() ),
351 GetData(aSubstFlavor, rDestDoc);
353 if(
maAny.hasValue() )
363 aReader.
Read( aMtf );
371 maAny <<= Sequence< sal_Int8 >(
static_cast< const sal_Int8*
>( aDstStm.
GetData() ),
380 if( !bDone &&
maAny.hasValue() )
384 if( !
maAny.hasValue() )
387 catch(
const css::uno::Exception& )
391 if( !
maAny.hasValue() )
392 throw UnsupportedFlavorException();
414 catch(
const css::uno::Exception& )
418 return comphelper::containerToSequence<DataFlavor>(
maFormats);
431 catch(
const css::uno::Exception& )
455 Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
463 catch(
const css::uno::Exception& )
480 DragFinished( rDSDE.DropSuccess ? ( rDSDE.DropAction & ~DNDConstants::ACTION_DEFAULT ) : DNDConstants::ACTION_NONE );
483 catch(
const css::uno::Exception& )
514 Reference< XFlushableClipboard > xFlushableClipboard(
mxClipboard, UNO_QUERY );
519 if( xFlushableClipboard.is() )
520 xFlushableClipboard->flushClipboard();
522 catch(
const css::uno::Exception& )
524 OSL_FAIL(
"Could not flush clipboard" );
547 if ((SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId) &&
mxObjDesc)
549 DataFlavor aObjDescFlavor;
552 format.MimeType = aObjDescFlavor.MimeType;
566 aFlavorEx.MimeType = rFlavor.MimeType;
567 aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
568 aFlavorEx.DataType = rFlavor.DataType;
571 if ((SotClipboardFormatId::OBJECTDESCRIPTOR == aFlavorEx.
mnSotId) &&
mxObjDesc)
576 if( SotClipboardFormatId::BITMAP == aFlavorEx.
mnSotId )
581 else if( SotClipboardFormatId::GDIMETAFILE == aFlavorEx.
mnSotId )
600 DataFlavorExVector::iterator aIter(
maFormats.begin());
615 [&](
const DataFlavorEx& data) { return data.mnSotId == nFormat; });
629 return maAny.hasValue();
636 return maAny.hasValue();
646 if(rFlavor.MimeType.equalsIgnoreAsciiCase(
"image/png"))
649 css::uno::Sequence<css::beans::PropertyValue> aFilterData;
653 aFilterData.realloc(aFilterData.getLength() + 1);
654 aFilterData.getArray()[aFilterData.getLength() - 1].Name =
"Compression";
663 aFilterData.getArray()[aFilterData.getLength() - 1].Value <<= 1;
667 aPNGWriter.
write(rBitmapEx);
678 return maAny.hasValue();
689 aWriter.
Write( rMtf );
693 return maAny.hasValue();
712 return maAny.hasValue();
721 rIMap.
Write( aMemStm );
724 return maAny.hasValue();
735 maAny <<= Sequence< sal_Int8 >(
static_cast< const sal_Int8*
>( aMemStm.
GetData() ), aMemStm.
Tell() );
737 return maAny.hasValue();
742 const css::datatransfer::DataFlavor& rFlavor )
744 rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
748 case SotClipboardFormatId::SOLK:
753 OString::number(sURL.getLength())
755 + OString::number(sDesc.getLength())
759 memcpy(
aSeq.getArray(), sOut.getStr(), sOut.getLength());
764 case SotClipboardFormatId::STRING:
765 case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
769 case SotClipboardFormatId::NETSCAPE_BOOKMARK:
772 char* pSeq =
reinterpret_cast< char*
>(
aSeq.getArray() );
783 case SotClipboardFormatId::FILEGRPDESCRIPTOR:
786 FILEGROUPDESCRIPTORW* pFDesc =
reinterpret_cast<FILEGROUPDESCRIPTORW*
>(
aSeq.getArray());
787 FILEDESCRIPTORW& rFDesc1 = pFDesc->fgd[ 0 ];
790 memset( &rFDesc1, 0,
sizeof( rFDesc1 ) );
791 rFDesc1.dwFlags = FD_LINKUI;
794 for(
size_t nChar = 0; (nChar = std::u16string_view(
aStr).find_first_of(
u"\\/:*?\"<>|"sv, nChar)) != std::u16string_view::npos; )
795 aStr.remove(nChar, 1);
797 aStr.insert(0,
"Shortcut to ");
799 wcscpy( rFDesc1.cFileName, o3tl::toW(
aStr.getStr()) );
805 case SotClipboardFormatId::FILECONTENT:
807 maAny <<=
"[InternetShortcut]\x0aURL=" + rBmk.
GetURL();
816 return maAny.hasValue();
821 const css::datatransfer::DataFlavor& rFlavor )
830 return maAny.hasValue();
840 if( pUserObject &&
WriteObject( xStm, pUserObject, nUserObjectId, rFlavor ) )
842 const sal_uInt32 nLen = xStm->TellEnd();
846 xStm->ReadBytes(
aSeq.getArray(), nLen);
854 maAny <<= OUString( reinterpret_cast< const char* >(
aSeq.getConstArray() ), nLen - 1, RTL_TEXTENCODING_UTF8 );
860 return maAny.hasValue();
866 OSL_FAIL(
"TransferableHelper::WriteObject( ... ) not implemented" );
885 if(
HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ) )
886 AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
891 if( rClipboard.is() )
901 Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
906 catch(
const css::uno::Exception& )
913 DBG_ASSERT( pWindow,
"Window pointer is NULL" );
914 Reference< XClipboard > xClipboard;
931 Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
934 rSelection->setContents( pThis, pThis );
936 catch(
const css::uno::Exception& )
949 DBG_ASSERT( pWindow,
"Window pointer is NULL" );
950 Reference< XDragSource > xDragSource( pWindow->
GetDragSource() );
952 if( !xDragSource.is() )
974 DragGestureEvent aEvt;
975 aEvt.DragAction = DNDConstants::ACTION_COPY;
976 aEvt.DragOriginX = aPt.
X();
977 aEvt.DragOriginY = aPt.
Y();
978 aEvt.DragSource = xDragSource;
982 catch(
const css::uno::Exception& )
991 if( xSelection.is() )
992 xSelection->setContents(
nullptr,
nullptr );
997class TransferableClipboardNotifier :
public ::cppu::WeakImplHelper< XClipboardListener >
1000 ::osl::Mutex& mrMutex;
1001 Reference< XClipboardNotifier > mxNotifier;
1006 virtual void SAL_CALL changedContents(
const clipboard::ClipboardEvent& event )
override;
1009 virtual void SAL_CALL
disposing(
const EventObject& Source )
override;
1012 TransferableClipboardNotifier(
const Reference< XClipboard >& _rxClipboard,
TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex );
1015 bool isListening()
const {
return mpListener !=
nullptr; }
1023TransferableClipboardNotifier::TransferableClipboardNotifier(
const Reference< XClipboard >& _rxClipboard,
TransferableDataHelper& _rListener, ::osl::Mutex& _rMutex )
1025 ,mxNotifier( _rxClipboard, UNO_QUERY )
1028 osl_atomic_increment( &m_refCount );
1030 if ( mxNotifier.is() )
1031 mxNotifier->addClipboardListener(
this );
1036 osl_atomic_decrement( &m_refCount );
1040void SAL_CALL TransferableClipboardNotifier::changedContents(
const clipboard::ClipboardEvent& event )
1047 ::osl::MutexGuard aGuard( mrMutex );
1053void SAL_CALL TransferableClipboardNotifier::disposing(
const EventObject& )
1060void TransferableClipboardNotifier::dispose()
1062 ::osl::MutexGuard aGuard( mrMutex );
1064 Reference< XClipboardListener > xKeepMeAlive(
this );
1066 if ( mxNotifier.is() )
1067 mxNotifier->removeClipboardListener(
this );
1090 : mxTransfer(rxTransferable)
1098 : mxTransfer(rDataHelper.mxTransfer)
1099 , mxClipboard(rDataHelper.mxClipboard)
1100 , maFormats(rDataHelper.maFormats)
1107 : mxTransfer(std::move(rDataHelper.mxTransfer))
1108 , mxClipboard(std::move(rDataHelper.mxClipboard))
1109 , maFormats(std::move(rDataHelper.maFormats))
1110 , mxObjDesc(std::move(rDataHelper.mxObjDesc))
1117 if (
this != &rDataHelper )
1119 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1121 const bool bWasClipboardListening =
mxImpl->mxClipboardListener.is();
1123 if (bWasClipboardListening)
1131 if (bWasClipboardListening)
1140 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1142 const bool bWasClipboardListening =
mxImpl->mxClipboardListener.is();
1144 if (bWasClipboardListening)
1147 mxTransfer = std::move(rDataHelper.mxTransfer);
1148 maFormats = std::move(rDataHelper.maFormats);
1149 mxObjDesc = std::move(rDataHelper.mxObjDesc);
1152 if (bWasClipboardListening)
1162 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1173 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1174 Reference< XMimeContentTypeFactory > xMimeFact = MimeContentTypeFactory::create( xContext );
1176 static constexpr OUStringLiteral aCharsetStr(
u"charset" );
1179 for (
auto const& rFlavor : rDataFlavorSeq)
1181 Reference< XMimeContentType > xMimeType;
1185 if( !rFlavor.MimeType.isEmpty() )
1186 xMimeType = xMimeFact->createMimeContentType( rFlavor.MimeType );
1188 catch(
const css::uno::Exception& )
1192 aFlavorEx.MimeType = rFlavor.MimeType;
1193 aFlavorEx.HumanPresentableName = rFlavor.HumanPresentableName;
1194 aFlavorEx.DataType = rFlavor.DataType;
1197 rDataFlavorExVector.push_back( aFlavorEx );
1200 if(SotClipboardFormatId::BMP == aFlavorEx.
mnSotId || SotClipboardFormatId::PNG == aFlavorEx.
mnSotId || SotClipboardFormatId::JPEG == aFlavorEx.
mnSotId)
1204 aFlavorEx.
mnSotId = SotClipboardFormatId::BITMAP;
1205 rDataFlavorExVector.push_back( aFlavorEx );
1208 else if( SotClipboardFormatId::WMF == aFlavorEx.
mnSotId || SotClipboardFormatId::EMF == aFlavorEx.
mnSotId )
1212 aFlavorEx.
mnSotId = SotClipboardFormatId::GDIMETAFILE;
1213 rDataFlavorExVector.push_back( aFlavorEx );
1216 else if ( SotClipboardFormatId::HTML_SIMPLE == aFlavorEx.
mnSotId )
1219 aFlavorEx.
mnSotId = SotClipboardFormatId::HTML_NO_COMMENT;
1220 rDataFlavorExVector.push_back( aFlavorEx );
1222 else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase(
"text/plain" ) )
1225 if( xMimeType->hasParameter( aCharsetStr ) )
1227 if( xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase(
"unicode" ) ||
1228 xMimeType->getParameterValue( aCharsetStr ).equalsIgnoreAsciiCase(
"utf-16" ) )
1230 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::STRING;
1235 else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase(
"text/rtf" ) )
1237 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::RTF;
1239 else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase(
"text/richtext" ) )
1241 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::RICHTEXT;
1243 else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase(
"text/html" ) )
1246 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::HTML;
1248 else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase(
"text/uri-list" ) )
1250 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::FILE_LIST;
1252 else if( xMimeType.is() && xMimeType->getFullMediaType().equalsIgnoreAsciiCase(
"application/x-openoffice-objectdescriptor-xml" ) )
1254 rDataFlavorExVector[ rDataFlavorExVector.size() - 1 ].mnSotId = SotClipboardFormatId::OBJECTDESCRIPTOR;
1258 catch(
const css::uno::Exception& )
1266 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1278 if( SotClipboardFormatId::OBJECTDESCRIPTOR == format.mnSotId )
1289 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1291 [&](
const DataFlavorEx& data) { return data.mnSotId == nFormat; });
1296 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1308 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1314 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1315 DBG_ASSERT(nFormat <
maFormats.size(),
"TransferableDataHelper::GetFormat: invalid format index");
1316 return( ( nFormat <
maFormats.size() ) ?
maFormats[ nFormat ].mnSotId : SotClipboardFormatId::NONE );
1321 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1322 DBG_ASSERT(nFormat <
maFormats.size(),
"TransferableDataHelper::GetFormat: invalid format index");
1335 Reference< XTransferable > xRet;
1344 xRet->getTransferDataFlavors();
1347 catch(
const css::uno::Exception& )
1363 aReturn =
GetAny(aFlavor, rDestDoc);
1370 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
1379 Reference<css::datatransfer::XTransferable2> xTransfer2(
mxTransfer, UNO_QUERY);
1381 if( nRequestFormat != SotClipboardFormatId::NONE )
1386 if( ( nRequestFormat == format.mnSotId ) && !rFlavor.MimeType.equalsIgnoreAsciiCase( format.MimeType ) )
1397 if (xTransfer2.is())
1398 aRet = xTransfer2->getTransferData2(format, rDestDoc);
1403 if( aRet.hasValue() )
1408 if( !aRet.hasValue() )
1419 if (xTransfer2.is())
1420 aRet = xTransfer2->getTransferData2(rFlavor, rDestDoc);
1426 catch(
const css::uno::Exception& )
1446 if( aAny.hasValue() )
1451 if( aAny >>= aOUString )
1456 else if( aAny >>= aSeq )
1459 const char* pChars =
reinterpret_cast< const char*
>(
aSeq.getConstArray() );
1460 sal_Int32 nLen =
aSeq.getLength();
1464 while( nLen && ( 0 == *( pChars + nLen - 1 ) ) )
1467 rStr = OUString( pChars, nLen, osl_getThreadTextEncoding() );
1478 if(SotClipboardFormatId::BITMAP == nFormat)
1509 DataFlavor aSubstFlavor;
1511 bool bSuppressPNG(
false);
1512 bool bSuppressJPEG(
false);
1518 bSuppressJPEG = bRet;
1524 bSuppressPNG = bRet;
1531 bSuppressPNG = bRet;
1532 bSuppressJPEG = bRet;
1537 if(!bSuppressPNG && rFlavor.MimeType.equalsIgnoreAsciiCase(
"image/png"))
1541 rBmpEx = aPNGReader.read();
1543 else if(!bSuppressJPEG && rFlavor.MimeType.equalsIgnoreAsciiCase(
"image/jpeg"))
1548 if (rFilter.
ImportGraphic(aGraphic, u
"", *xStm) == ERRCODE_NONE)
1586 if(MapUnit::MapPixel != aMapMode.GetMapUnit())
1592 if((aSize.Width() > 50000) || (aSize.Height() > 50000))
1620 DataFlavor aSubstFlavor;
1626 aReader.Read( rMtf );
1631 HasFormat( SotClipboardFormatId::EMF ) &&
1645 HasFormat( SotClipboardFormatId::WMF ) &&
1664 if(SotClipboardFormatId::BITMAP == nFormat)
1707 rGraphic = aGraphic;
1718 rGraphic = aBitmapEx;
1768 rIMap.
Read( *xStm );
1806 case SotClipboardFormatId::SOLK:
1807 case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
1812 if( SotClipboardFormatId::UNIFORMRESOURCELOCATOR == nFormat )
1819 OUString
aURL, aDesc;
1820 sal_Int32 nStart = aString.indexOf(
'@' ), nLen = aString.toInt32();
1822 if( !nLen && aString[ 0 ] !=
'0' )
1824 SAL_INFO(
"svtools",
"SOLK: 1. len=0" );
1826 if( nStart == -1 || nLen > aString.getLength() - nStart - 3 )
1828 SAL_INFO(
"svtools",
"SOLK: 1. illegal start or wrong len" );
1830 aURL = aString.copy( nStart + 1, nLen );
1832 aString = aString.replaceAt( 0, nStart + 1 + nLen,
u"" );
1833 nStart = aString.indexOf(
'@' );
1834 nLen = aString.toInt32();
1836 if( !nLen && aString[ 0 ] !=
'0' )
1838 SAL_INFO(
"svtools",
"SOLK: 2. len=0" );
1840 if( nStart == -1 || nLen > aString.getLength() - nStart - 1 )
1842 SAL_INFO(
"svtools",
"SOLK: 2. illegal start or wrong len" );
1844 aDesc = aString.copy( nStart+1, nLen );
1853 case SotClipboardFormatId::NETSCAPE_BOOKMARK:
1857 if (2048 ==
aSeq.getLength())
1859 const char* p1 =
reinterpret_cast< const char*
>(
aSeq.getConstArray() );
1860 const char* p2 =
reinterpret_cast< const char*
>(
aSeq.getConstArray() ) + 1024;
1861 rBmk =
INetBookmark( OUString( p1, strlen(p1), osl_getThreadTextEncoding() ),
1862 OUString( p2, strlen(p2), osl_getThreadTextEncoding() ) );
1869 case SotClipboardFormatId::FILEGRPDESCRIPTOR:
1873 if (
aSeq.getLength())
1875 FILEGROUPDESCRIPTORW
const * pFDesc =
reinterpret_cast<FILEGROUPDESCRIPTORW
const *
>(
aSeq.getConstArray());
1877 if( pFDesc->cItems )
1879 OUString aDesc( o3tl::toU(pFDesc->fgd[ 0 ].cFileName) );
1881 if( ( aDesc.getLength() > 4 ) && aDesc.endsWithIgnoreAsciiCase(
".URL") )
1884 StreamMode::STD_READ ));
1886 if( !pStream || pStream->GetError() )
1888 DataFlavor aFileContentFlavor;
1896 if (
aSeq.getLength())
1904 bool bInA =
false, bInW =
false, bAFound =
false;
1906 while( pStream->ReadLine( aLine ) )
1908 if (aLine.startsWithIgnoreAsciiCase(
"[InternetShortcut", &aLine))
1912 bInW = aLine.equalsIgnoreAsciiCase(
".W]");
1913 bInA = !bAFound && !bInW
1914 && (aLine ==
"]" || aLine.equalsIgnoreAsciiCase(
".A]"));
1916 else if (aLine.startsWith(
"["))
1918 bInA = bInW =
false;
1920 else if ((bInA || bInW) && aLine.startsWithIgnoreAsciiCase(
"URL="))
1922 auto eTextEncoding = bInW ? RTL_TEXTENCODING_UTF7
1923 : osl_getThreadTextEncoding();
1924 rBmk =
INetBookmark( OStringToOUString(aLine.subView(4), eTextEncoding),
1925 aDesc.copy(0, aDesc.getLength() - 4) );
1955 const css::datatransfer::DataFlavor& rFlavor,
1980 for( sal_uInt32
i = 0, nFormatCount =
GetFormatCount(); (
i < nFormatCount ) && !bRet; ++
i )
1982 if( SotClipboardFormatId::FILE_LIST ==
GetFormat(
i ) )
1988 if( aFlavor.MimeType.indexOf(
"text/uri-list" ) > -1 )
1990 OStringBuffer aDiskString;
1992 while( xStm->ReadLine( aDiskString ) )
1993 if( !aDiskString.isEmpty() && aDiskString[0] !=
'#' )
1994 rFileList.
AppendFile( OStringToOUString(aDiskString, RTL_TEXTENCODING_UTF8) );
2012 return Sequence<sal_Int8>();
2019 const Any aAny =
GetAny(rFlavor, rDestDoc);
2020 Sequence<sal_Int8>
aSeq;
2021 if (aAny.hasValue())
2039 if (
aSeq.hasElements())
2042 rxStream->WriteBytes(
aSeq.getConstArray(),
aSeq.getLength() );
2043 rxStream->Seek( 0 );
2046 return aSeq.hasElements();
2053 return Reference<XInputStream>();
2062 if (!
aSeq.hasElements())
2063 return Reference<XInputStream>();
2077 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
2083 return mxImpl->mxClipboardListener->isListening();
2088 ::osl::MutexGuard aGuard(
mxImpl->maMutex);
2090 if (
mxImpl->mxClipboardListener.is())
2092 mxImpl->mxClipboardListener->dispose();
2093 mxImpl->mxClipboardListener.clear();
2101 if( rClipboard.is() )
2105 Reference< XTransferable > xTransferable( rClipboard->getContents() );
2107 if( xTransferable.is() )
2114 catch(
const css::uno::Exception& )
2124 DBG_ASSERT( pWindow,
"Window pointer is NULL" );
2126 Reference< XClipboard > xClipboard;
2139 if( xSelection.is() )
2145 Reference< XTransferable > xTransferable( xSelection->getContents() );
2147 if( xTransferable.is() )
2153 catch(
const css::uno::Exception& )
2162 const css::datatransfer::DataFlavor& rRequestFlavor )
2164 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
2169 Reference< XMimeContentTypeFactory > xMimeFact = MimeContentTypeFactory::create( xContext );
2171 Reference< XMimeContentType > xRequestType1( xMimeFact->createMimeContentType( rInternalFlavor.MimeType ) );
2172 Reference< XMimeContentType > xRequestType2( xMimeFact->createMimeContentType( rRequestFlavor.MimeType ) );
2174 if( xRequestType1.is() && xRequestType2.is() )
2176 if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase( xRequestType2->getFullMediaType() ) )
2178 if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase(
"text/plain" ) )
2181 static constexpr OUStringLiteral aCharsetString(
u"charset" );
2183 if( !xRequestType2->hasParameter( aCharsetString ) ||
2184 xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase(
"utf-16" ) ||
2185 xRequestType2->getParameterValue( aCharsetString ).equalsIgnoreAsciiCase(
"unicode" ) )
2190 else if( xRequestType1->getFullMediaType().equalsIgnoreAsciiCase(
"application/x-openoffice" ) )
2193 static constexpr OUStringLiteral aFormatString(
u"windows_formatname" );
2195 if( xRequestType1->hasParameter( aFormatString ) &&
2196 xRequestType2->hasParameter( aFormatString ) &&
2197 xRequestType1->getParameterValue( aFormatString ).equalsIgnoreAsciiCase( xRequestType2->getParameterValue( aFormatString ) ) )
2207 catch(
const css::uno::Exception& )
2209 bRet = rInternalFlavor.MimeType.equalsIgnoreAsciiCase( rRequestFlavor.MimeType );
BaseContainerNodeSharedPtr & mrParent
Bitmap const & GetBitmap() const
void SetPrefMapMode(const MapMode &rPrefMapMode)
void SetPrefSize(const Size &rPrefSize)
Bitmap GetBitmap(Color aTransparentReplaceColor) const
const MapMode & GetPrefMapMode() const
const Size & GetPrefSize() const
void AppendFile(const OUString &rStr)
static ErrCode Import(SvStream &rIStm, Graphic &rGraphic, ConvertDataFormat nFormat=ConvertDataFormat::Unknown)
static ErrCode Export(SvStream &rOStm, const Graphic &rGraphic, ConvertDataFormat nFormat)
Class to import and export graphic formats.
static GraphicFilter & GetGraphicFilter()
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
const GDIMetaFile & GetGDIMetaFile() const
GraphicType GetType() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
const OUString & GetDescription() const
const OUString & GetURL() const
bool Read(SvStream &rIStm, SotClipboardFormatId nFormat)
void Write(SvStream &rOStm, SotClipboardFormatId nFormat) const
void Write(SvStream &rOStm) const
void Read(SvStream &rIStm)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
static SotClipboardFormatId RegisterFormat(const css::datatransfer::DataFlavor &rFlavor)
OUString GetHexName() const
bool MakeId(std::u16string_view rId)
virtual sal_uInt64 TellEnd() override
SvStream & WriteInt32(sal_Int32 nInt32)
void SetCompressMode(SvStreamCompressFlags nNewMode)
SvStream & WriteUniOrByteString(std::u16string_view rStr, rtl_TextEncoding eDestCharSet)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
void SetVersion(sal_Int32 n)
sal_uInt64 Seek(sal_uInt64 nPos)
sal_uInt64 SeekRel(sal_Int64 nPos)
SvStream & Read(GDIMetaFile &rMetaFile, ImplMetaReadData *pData=nullptr)
SvStream & Write(const GDIMetaFile &rMetaFile)
sal_uInt32 GetFormatCount() const
std::unique_ptr< TransferableObjectDescriptor > mxObjDesc
css::uno::Reference< css::datatransfer::XTransferable > mxTransfer
static bool IsEqual(const css::datatransfer::DataFlavor &rInternalFlavor, const css::datatransfer::DataFlavor &rRequestFlavor)
css::uno::Sequence< sal_Int8 > GetSequence(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetTransferableObjectDescriptor(SotClipboardFormatId nFormat, TransferableObjectDescriptor &rDesc)
static TransferableDataHelper CreateFromPrimarySelection()
static TransferableDataHelper CreateFromClipboard(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard)
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
bool StartClipboardListening()
void StopClipboardListening()
TransferableDataHelper & operator=(const TransferableDataHelper &rDataHelper)
SotClipboardFormatId GetFormat(sal_uInt32 nFormat) const
std::unique_ptr< TransferableDataHelper_Impl > mxImpl
bool GetImageMap(SotClipboardFormatId nFormat, ImageMap &rIMap) const
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetFileList(SotClipboardFormatId nFormat, FileList &rFileList) const
css::uno::Reference< css::io::XInputStream > GetInputStream(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotTempStream > &rStreamRef) const
bool GetGDIMetaFile(SotClipboardFormatId nFormat, GDIMetaFile &rMtf, size_t nMaxActions=0) const
Return as GDI metafile.
void Rebind(const css::uno::Reference< css::datatransfer::XTransferable > &_rxNewData)
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
bool HasFormat(SotClipboardFormatId nFormat) const
bool GetINetImage(SotClipboardFormatId nFormat, INetImage &rINtImg) const
static void FillDataFlavorExVector(const css::uno::Sequence< css::datatransfer::DataFlavor > &rDataFlavorSeq, DataFlavorExVector &rDataFlavorExVector)
css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard
bool GetBitmapEx(SotClipboardFormatId nFormat, BitmapEx &rBmp) const
DataFlavorExVector maFormats
~TransferableDataHelper()
css::datatransfer::DataFlavor GetFormatDataFlavor(sal_uInt32 nFormat) const
bool GetGraphic(SotClipboardFormatId nFormat, Graphic &rGraphic) const
bool GetINetBookmark(SotClipboardFormatId nFormat, INetBookmark &rBmk) const
css::uno::Reference< css::datatransfer::XTransferable > GetXTransferable() const
virtual ~TerminateListener() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
TerminateListener(TransferableHelper &rDropTargetHelper)
virtual void SAL_CALL queryTermination(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &aEvent) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() override
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions)
virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor &rFlavor) override
bool SetGraphic(const Graphic &rGraphic)
virtual void SAL_CALL dragEnter(const css::datatransfer::dnd::DragSourceDragEvent &dsde) override
virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor &rFlavor) override
void CopyToClipboard(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard) const
bool SetTransferableObjectDescriptor(const TransferableObjectDescriptor &rDesc)
bool SetAny(const css::uno::Any &rAny)
virtual void SAL_CALL dragDropEnd(const css::datatransfer::dnd::DragSourceDropEvent &dsde) override
void CopyToSelection(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard) const
bool SetObject(void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor)
void RemoveFormat(SotClipboardFormatId nFormat)
bool SetString(const OUString &rString)
virtual void SAL_CALL dragOver(const css::datatransfer::dnd::DragSourceDragEvent &dsde) override
virtual bool WriteObject(tools::SvRef< SotTempStream > &rxOStm, void *pUserObject, sal_uInt32 nUserObjectId, const css::datatransfer::DataFlavor &rFlavor)
static void ClearPrimarySelection()
virtual css::uno::Any SAL_CALL getTransferData2(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
virtual void SAL_CALL dropActionChanged(const css::datatransfer::dnd::DragSourceDragEvent &dsde) override
virtual void DragFinished(sal_Int8 nDropAction)
VCL_DLLPRIVATE void ImplFlush()
bool SetINetImage(const INetImage &rINtImg, const css::datatransfer::DataFlavor &rFlavor)
void CopyToPrimarySelection() const
bool SetBitmapEx(const BitmapEx &rBitmap, const css::datatransfer::DataFlavor &rFlavor)
bool SetINetBookmark(const INetBookmark &rBmk, const css::datatransfer::DataFlavor &rFlavor)
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
bool HasFormat(SotClipboardFormatId nFormat)
void PrepareOLE(const TransferableObjectDescriptor &rObjDesc)
void AddFormat(SotClipboardFormatId nFormat)
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc)=0
std::unique_ptr< TransferableObjectDescriptor > mxObjDesc
virtual void AddSupportedFormats()=0
virtual sal_Bool SAL_CALL isComplex() override
bool SetImageMap(const ImageMap &rIMap)
css::uno::Reference< css::frame::XTerminateListener > mxTerminateListener
virtual void SAL_CALL dragExit(const css::datatransfer::dnd::DragSourceEvent &dse) override
virtual void ObjectReleased()
bool SetGDIMetaFile(const GDIMetaFile &rMtf)
css::uno::Reference< css::datatransfer::clipboard::XClipboard > mxClipboard
virtual void SAL_CALL lostOwnership(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &xClipboard, const css::uno::Reference< css::datatransfer::XTransferable > &xTrans) override
DataFlavorExVector maFormats
void readGraphic(Graphic &rGraphic)
void writeGraphic(const Graphic &rGraphic)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
void setParameters(css::uno::Sequence< css::beans::PropertyValue > const &rParameters)
bool write(const BitmapEx &rBitmap)
bool IsMouseCaptured() const
Point GetPointerPosPixel()
css::uno::Reference< css::datatransfer::dnd::XDragSource > GetDragSource()
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard()
#define DBG_ASSERT(sCon, aError)
::std::vector< DataFlavorEx > DataFlavorExVector
SvStream & ReadFileList(SvStream &rIStm, FileList &rFileList)
SvStream & WriteSvGlobalName(SvStream &rOStr, const SvGlobalName &rObj)
Sequence< sal_Int8 > aSeq
#define SAL_INFO(area, stream)
Reference< XComponentContext > getProcessComponentContext()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
#define STREAM_SEEK_TO_BEGIN
SotClipboardFormatId mnSotId
TransferableDataHelper_Impl()
rtl::Reference< TransferableClipboardNotifier > mxClipboardListener
Reference< XClipboard > GetSystemPrimarySelection()
static void ImplSetParameterString(TransferableObjectDescriptor &rObjDesc, const DataFlavorEx &rFlavorEx)
SvStream & WriteTransferableObjectDescriptor(SvStream &rOStm, const TransferableObjectDescriptor &rObjDesc)
static OUString ImplGetParameterString(const TransferableObjectDescriptor &rObjDesc)
bool ConvertGDIMetaFileToWMF(const GDIMetaFile &rMTF, SvStream &rTargetStream, FilterConfigItem const *pConfigItem, bool bPlaceable)