Skip to content

Commit ff81ed9

Browse files
rbernonjulliard
authored andcommitted
winex11: Keep the IDropTarget pointer on the data object.
1 parent 5f80ce2 commit ff81ed9

File tree

1 file changed

+35
-55
lines changed

1 file changed

+35
-55
lines changed

dlls/winex11.drv/xdnd.c

+35-55
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
WINE_DEFAULT_DEBUG_CHANNEL(xdnd);
3333

3434
static IDataObject *xdnd_data_object;
35-
static IDropTarget *xdnd_drop_target;
36-
37-
static void X11DRV_XDND_FreeDragDropOp(void);
3835

3936
static CRITICAL_SECTION xdnd_cs;
4037
static CRITICAL_SECTION_DEBUG critsect_debug =
@@ -91,6 +88,7 @@ struct data_object
9188
HWND target_hwnd; /* the last window the mouse was over */
9289
POINT target_pos;
9390
DWORD target_effect;
91+
IDropTarget *drop_target;
9492

9593
struct format_entry *entries_end;
9694
struct format_entry entries[];
@@ -270,8 +268,21 @@ static ULONG WINAPI data_object_Release( IDataObject *iface )
270268
{
271269
struct data_object *object = data_object_from_IDataObject( iface );
272270
ULONG ref = InterlockedDecrement( &object->refcount );
271+
273272
TRACE( "object %p decreasing refcount to %lu.\n", object, ref );
274-
if (!ref) free( object );
273+
274+
if (!ref)
275+
{
276+
if (object->drop_target)
277+
{
278+
HRESULT hr = IDropTarget_DragLeave( object->drop_target );
279+
if (FAILED(hr)) WARN( "IDropTarget_DragLeave returned %#lx\n", hr );
280+
IDropTarget_Release( object->drop_target );
281+
}
282+
283+
free( object );
284+
}
285+
275286
return ref;
276287
}
277288

@@ -557,46 +568,46 @@ NTSTATUS WINAPI x11drv_dnd_position_event( void *arg, ULONG size )
557568
object->target_pos = params->point;
558569
targetWindow = window_from_point_dnd( UlongToHandle( params->hwnd ), object->target_pos );
559570

560-
if (!xdnd_drop_target || object->target_hwnd != targetWindow)
571+
if (!object->drop_target || object->target_hwnd != targetWindow)
561572
{
562573
/* Notify OLE of DragEnter. Result determines if we accept */
563574
HWND dropTargetWindow;
564575

565-
if (xdnd_drop_target)
576+
if (object->drop_target)
566577
{
567-
hr = IDropTarget_DragLeave( xdnd_drop_target );
578+
hr = IDropTarget_DragLeave( object->drop_target );
568579
if (FAILED(hr)) WARN( "IDropTarget_DragLeave returned %#lx\n", hr );
569-
IDropTarget_Release( xdnd_drop_target );
570-
xdnd_drop_target = NULL;
580+
IDropTarget_Release( object->drop_target );
581+
object->drop_target = NULL;
571582
}
572583

573584
dropTargetWindow = targetWindow;
574-
do { xdnd_drop_target = get_droptarget_pointer( dropTargetWindow ); }
575-
while (!xdnd_drop_target && !!(dropTargetWindow = GetParent( dropTargetWindow )));
585+
do { object->drop_target = get_droptarget_pointer( dropTargetWindow ); }
586+
while (!object->drop_target && !!(dropTargetWindow = GetParent( dropTargetWindow )));
576587
object->target_hwnd = targetWindow;
577588

578-
if (xdnd_drop_target)
589+
if (object->drop_target)
579590
{
580591
DWORD effect_ignore = effect;
581-
hr = IDropTarget_DragEnter( xdnd_drop_target, &object->IDataObject_iface,
592+
hr = IDropTarget_DragEnter( object->drop_target, &object->IDataObject_iface,
582593
MK_LBUTTON, pointl, &effect_ignore );
583594
if (hr == S_OK) TRACE( "the application accepted the drop (effect = %ld)\n", effect_ignore );
584595
else
585596
{
586597
WARN( "IDropTarget_DragEnter returned %#lx\n", hr );
587-
IDropTarget_Release( xdnd_drop_target );
588-
xdnd_drop_target = NULL;
598+
IDropTarget_Release( object->drop_target );
599+
object->drop_target = NULL;
589600
}
590601
}
591602
}
592-
else if (xdnd_drop_target)
603+
else if (object->drop_target)
593604
{
594-
hr = IDropTarget_DragOver( xdnd_drop_target, MK_LBUTTON, pointl, &effect );
605+
hr = IDropTarget_DragOver( object->drop_target, MK_LBUTTON, pointl, &effect );
595606
if (hr == S_OK) object->target_effect = effect;
596607
else WARN( "IDropTarget_DragOver returned %#lx\n", hr );
597608
}
598609

599-
if (xdnd_drop_target && object->target_effect != DROPEFFECT_NONE)
610+
if (object->drop_target && object->target_effect != DROPEFFECT_NONE)
600611
accept = 1;
601612
else
602613
{
@@ -629,12 +640,12 @@ NTSTATUS WINAPI x11drv_dnd_drop_event( void *args, ULONG size )
629640
effect = object->target_effect;
630641

631642
/* Notify OLE of Drop */
632-
if (xdnd_drop_target && effect != DROPEFFECT_NONE)
643+
if (object->drop_target && effect != DROPEFFECT_NONE)
633644
{
634645
POINTL pointl = {object->target_pos.x, object->target_pos.y};
635646
HRESULT hr;
636647

637-
hr = IDropTarget_Drop( xdnd_drop_target, &object->IDataObject_iface,
648+
hr = IDropTarget_Drop( object->drop_target, &object->IDataObject_iface,
638649
MK_LBUTTON, pointl, &effect );
639650
if (hr == S_OK)
640651
{
@@ -655,12 +666,12 @@ NTSTATUS WINAPI x11drv_dnd_drop_event( void *args, ULONG size )
655666
drop_file = FALSE;
656667
}
657668
}
658-
else if (xdnd_drop_target)
669+
else if (object->drop_target)
659670
{
660-
HRESULT hr = IDropTarget_DragLeave( xdnd_drop_target );
671+
HRESULT hr = IDropTarget_DragLeave( object->drop_target );
661672
if (FAILED(hr)) WARN( "IDropTarget_DragLeave returned %#lx\n", hr );
662-
IDropTarget_Release( xdnd_drop_target );
663-
xdnd_drop_target = NULL;
673+
IDropTarget_Release( object->drop_target );
674+
object->drop_target = NULL;
664675
}
665676

666677
if (drop_file)
@@ -709,18 +720,7 @@ NTSTATUS WINAPI x11drv_dnd_leave_event( void *params, ULONG size )
709720

710721
TRACE("DND Operation canceled\n");
711722

712-
/* Notify OLE of DragLeave */
713-
if (xdnd_drop_target)
714-
{
715-
HRESULT hr = IDropTarget_DragLeave( xdnd_drop_target );
716-
if (FAILED(hr)) WARN( "IDropTarget_DragLeave returned %#lx\n", hr );
717-
IDropTarget_Release( xdnd_drop_target );
718-
xdnd_drop_target = NULL;
719-
}
720-
721723
if ((object = get_data_object( TRUE ))) IDataObject_Release( &object->IDataObject_iface );
722-
723-
X11DRV_XDND_FreeDragDropOp();
724724
return STATUS_SUCCESS;
725725
}
726726

@@ -734,8 +734,6 @@ NTSTATUS WINAPI x11drv_dnd_enter_event( void *args, ULONG size )
734734
struct dnd_enter_event_params *params = args;
735735
IDataObject *object, *previous;
736736

737-
X11DRV_XDND_FreeDragDropOp(); /* Clear previously cached data */
738-
739737
if (FAILED(data_object_create( formats_size, params->entries, &object ))) return STATUS_NO_MEMORY;
740738

741739
EnterCriticalSection( &xdnd_cs );
@@ -748,24 +746,6 @@ NTSTATUS WINAPI x11drv_dnd_enter_event( void *args, ULONG size )
748746
}
749747

750748

751-
/**************************************************************************
752-
* X11DRV_XDND_FreeDragDropOp
753-
*/
754-
static void X11DRV_XDND_FreeDragDropOp(void)
755-
{
756-
TRACE("\n");
757-
758-
EnterCriticalSection(&xdnd_cs);
759-
760-
if (xdnd_drop_target)
761-
{
762-
IDropTarget_Release( xdnd_drop_target );
763-
xdnd_drop_target = NULL;
764-
}
765-
766-
LeaveCriticalSection(&xdnd_cs);
767-
}
768-
769749
NTSTATUS WINAPI x11drv_dnd_post_drop( void *args, ULONG size )
770750
{
771751
UINT drop_size = size - offsetof(struct dnd_post_drop_params, drop);

0 commit comments

Comments
 (0)