20#include <config_vclplug.h>
22#include <osl/mutex.hxx>
29#include <com/sun/star/datatransfer/clipboard/LokClipboard.hpp>
30#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
31#include <com/sun/star/datatransfer/dnd/XDropTargetDragContext.hpp>
32#include <com/sun/star/datatransfer/dnd/XDragGestureRecognizer.hpp>
33#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
34#include <com/sun/star/uno/DeploymentException.hpp>
48DragSourceHelper::DragGestureListener::DragGestureListener( DragSourceHelper& rDragSourceHelper ) :
54DragSourceHelper::DragGestureListener::~DragGestureListener()
59void SAL_CALL DragSourceHelper::DragGestureListener::disposing(
const EventObject& )
64void SAL_CALL DragSourceHelper::DragGestureListener::dragGestureRecognized(
const DragGestureEvent& rDGE )
68 const Point aPtPixel( rDGE.DragOriginX, rDGE.DragOriginY );
69 mrParent.StartDrag( rDGE.DragAction, aPtPixel );
73DragSourceHelper::DragSourceHelper(
vcl::Window* pWindow ) :
74 mxDragGestureRecognizer( pWindow->GetDragGestureRecognizer() )
76 if( mxDragGestureRecognizer.is() )
78 mxDragGestureListener =
new DragSourceHelper::DragGestureListener( *
this );
79 mxDragGestureRecognizer->addDragGestureListener( mxDragGestureListener );
84void DragSourceHelper::dispose()
86 Reference<XDragGestureRecognizer> xTmp;
88 std::scoped_lock aGuard( maMutex );
89 xTmp = std::move(mxDragGestureRecognizer);
92 xTmp->removeDragGestureListener( mxDragGestureListener );
95DragSourceHelper::~DragSourceHelper()
106DropTargetHelper::DropTargetListener::DropTargetListener( DropTargetHelper& rDropTargetHelper ) :
112DropTargetHelper::DropTargetListener::~DropTargetListener()
117void SAL_CALL DropTargetHelper::DropTargetListener::disposing(
const EventObject& )
122void SAL_CALL DropTargetHelper::DropTargetListener::drop(
const DropTargetDropEvent& rDTDE )
129 ExecuteDropEvent aExecuteEvt( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT,
Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE );
131 aExecuteEvt.mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 );
135 aAcceptEvent.
mnAction = aExecuteEvt.mnAction;
136 aAcceptEvent.
maPosPixel = aExecuteEvt.maPosPixel;
137 static_cast<DropTargetEvent&
>(
const_cast<DropTargetDragEvent&
>( aAcceptEvent.
maDragEvent )) = rDTDE;
138 const_cast<DropTargetDragEvent&
>( aAcceptEvent.
maDragEvent ).DropAction = rDTDE.DropAction;
139 const_cast<DropTargetDragEvent&
>( aAcceptEvent.
maDragEvent ).LocationX = rDTDE.LocationX;
140 const_cast<DropTargetDragEvent&
>( aAcceptEvent.
maDragEvent ).LocationY = rDTDE.LocationY;
141 const_cast<DropTargetDragEvent&
>( aAcceptEvent.
maDragEvent ).SourceActions = rDTDE.SourceActions;
143 aAcceptEvent.
mbDefault = aExecuteEvt.mbDefault;
147 if( DNDConstants::ACTION_NONE != nRet )
149 rDTDE.Context->acceptDrop( nRet );
151 if( aExecuteEvt.mbDefault )
152 aExecuteEvt.mnAction = nRet;
154 nRet =
mrParent.ExecuteDrop( aExecuteEvt );
157 rDTDE.Context->dropComplete( DNDConstants::ACTION_NONE != nRet );
159 mpLastDragOverEvent.reset();
161 catch(
const css::uno::Exception& )
167void SAL_CALL DropTargetHelper::DropTargetListener::dragEnter(
const DropTargetDragEnterEvent& rDTDEE )
173 mrParent.ImplBeginDrag( rDTDEE.SupportedDataFlavors );
175 catch(
const css::uno::Exception& )
183void SAL_CALL DropTargetHelper::DropTargetListener::dragOver(
const DropTargetDragEvent& rDTDE )
189 mpLastDragOverEvent.reset(
new AcceptDropEvent( rDTDE.DropAction & ~DNDConstants::ACTION_DEFAULT,
Point( rDTDE.LocationX, rDTDE.LocationY ), rDTDE ) );
190 mpLastDragOverEvent->mbDefault = ( ( rDTDE.DropAction & DNDConstants::ACTION_DEFAULT ) != 0 );
194 if( DNDConstants::ACTION_NONE == nRet )
195 rDTDE.Context->rejectDrag();
197 rDTDE.Context->acceptDrag( nRet );
199 catch(
const css::uno::Exception& )
205void SAL_CALL DropTargetHelper::DropTargetListener::dragExit(
const DropTargetEvent& )
211 if( mpLastDragOverEvent )
213 mpLastDragOverEvent->mbLeaving =
true;
214 mrParent.AcceptDrop( *mpLastDragOverEvent );
215 mpLastDragOverEvent.reset();
220 catch(
const css::uno::Exception& )
226void SAL_CALL DropTargetHelper::DropTargetListener::dropActionChanged(
const DropTargetDragEvent& )
231DropTargetHelper::DropTargetHelper(
vcl::Window* pWindow ) :
232 mxDropTarget( pWindow->GetDropTarget() )
238DropTargetHelper::DropTargetHelper(
const Reference< XDropTarget >& rxDropTarget ) :
239 mxDropTarget( rxDropTarget )
245void DropTargetHelper::dispose()
247 Reference< XDropTarget > xTmp;
249 std::scoped_lock aGuard( maMutex );
250 xTmp = std::move(mxDropTarget);
253 xTmp->removeDropTargetListener( mxDropTargetListener );
256DropTargetHelper::~DropTargetHelper()
262void DropTargetHelper::ImplConstruct()
264 if( mxDropTarget.is() )
266 mxDropTargetListener =
new DropTargetHelper::DropTargetListener( *
this );
267 mxDropTarget->addDropTargetListener( mxDropTargetListener );
268 mxDropTarget->setActive(
true );
273void DropTargetHelper::ImplBeginDrag(
const Sequence< DataFlavor >& rSupportedDataFlavors )
280void DropTargetHelper::ImplEndDrag()
288 return DNDConstants::ACTION_NONE;
294 return DNDConstants::ACTION_NONE;
300 return std::any_of(maFormats.begin(), maFormats.end(),
301 [&](
const DataFlavorEx& data) { return data.mnSotId == nFormat; });
309struct TDataCntnrEntry_Impl
346 const css::datatransfer::DataFlavor& rFlavor,
const OUString& )
352 for (
auto const& format :
pImpl->aFmtList)
354 if( nFmtId == format.nId )
356 bFnd =
SetAny( format.aAny );
365 case SotClipboardFormatId::STRING:
366 case SotClipboardFormatId::SOLK:
367 case SotClipboardFormatId::NETSCAPE_BOOKMARK:
368 case SotClipboardFormatId::FILECONTENT:
369 case SotClipboardFormatId::FILEGRPDESCRIPTOR:
370 case SotClipboardFormatId::UNIFORMRESOURCELOCATOR:
371 if(
pImpl->moBookmk )
384 pImpl->moBookmk = rBkmk;
386 AddFormat( SotClipboardFormatId::STRING );
388 AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK );
389 AddFormat( SotClipboardFormatId::FILECONTENT );
390 AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR );
391 AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR );
400 TDataCntnrEntry_Impl aEntry;
401 aEntry.nId = nFormatId;
405 aEntry.aAny <<=
aSeq;
406 pImpl->aFmtList.push_back( aEntry );
413 const OString& rStr )
415 CopyAnyData( nFormatId, rStr.getStr(), rStr.getLength() );
421 if( !rStr.isEmpty() )
423 TDataCntnrEntry_Impl aEntry;
425 aEntry.aAny <<= rStr;
426 pImpl->aFmtList.push_back( aEntry );
434 CopyString( SotClipboardFormatId::STRING, rStr );
440 return !
pImpl->aFmtList.empty() ||
441 pImpl->moBookmk.has_value();
449 pImpl->aFinishedLnk = rLnk;
456 pImpl->aFinishedLnk.Call( nDropAction );
470 if (!data->m_xSystemClipboard.is())
474 data->m_xSystemClipboard = css::datatransfer::clipboard::SystemClipboard::create(
477 catch (DeploymentException
const &) {}
479 return data->m_xSystemClipboard;
481 Reference<XClipboard> xClipboard;
490 xClipboard = css::datatransfer::clipboard::LokClipboard::create(
496 xClipboard = css::datatransfer::clipboard::SystemClipboard::create(
500 catch (DeploymentException
const &) {}
507 Reference<XClipboard> xSelection;
514 Sequence< Any >
args{
Any(OUString(
"PRIMARY")) };
515 xSelection.set(xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
516 "com.sun.star.datatransfer.clipboard.SystemClipboard",
args, xContext), UNO_QUERY_THROW);
518 static Reference< XClipboard > s_xSelection(
519 xContext->getServiceManager()->createInstanceWithContext(
520 "com.sun.star.datatransfer.clipboard.GenericClipboard", xContext), UNO_QUERY);
521 xSelection = s_xSelection;
BaseContainerNodeSharedPtr & mrParent
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions, const Link< sal_Int8, void > &rCallback)
virtual ~TransferDataContainer() override
void CopyAnyData(SotClipboardFormatId nFormatId, const char *pData, sal_uLong nLen)
void CopyINetBookmark(const INetBookmark &rBkmk)
virtual void DragFinished(sal_Int8 nDropAction) override
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
std::unique_ptr< TransferDataContainer_Impl > pImpl
virtual void AddSupportedFormats() override
void CopyString(const OUString &rStr)
void CopyByteString(SotClipboardFormatId nFormatId, const OString &rStr)
static void FillDataFlavorExVector(const css::uno::Sequence< css::datatransfer::DataFlavor > &rDataFlavorSeq, DataFlavorExVector &rDataFlavorExVector)
void StartDrag(vcl::Window *pWindow, sal_Int8 nDragSourceActions)
bool SetAny(const css::uno::Any &rAny)
bool SetINetBookmark(const INetBookmark &rBmk, const css::datatransfer::DataFlavor &rFlavor)
void AddFormat(SotClipboardFormatId nFormat)
#define DBG_TESTSOLARMUTEX()
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
Reference< XComponentContext > getProcessComponentContext()
const css::datatransfer::dnd::DropTargetDragEvent maDragEvent
std::vector< TDataCntnrEntry_Impl > aFmtList
TransferDataContainer_Impl()
Link< sal_Int8, void > aFinishedLnk
std::optional< INetBookmark > moBookmk
ImplSVData * ImplGetSVData()
Reference< XClipboard > GetSystemPrimarySelection()
Reference< XClipboard > GetSystemClipboard()