From 7a9afc3a955bc4d875770a452f35e3feaa1dda46 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 29 May 2018 19:00:10 +0200 Subject: [PATCH] win32: Use new DND event emitters --- gdk/win32/gdkdrag-win32.c | 61 ++++----------------------- gdk/win32/gdkdrop-win32.c | 84 +++++-------------------------------- gdk/win32/gdkevents-win32.c | 11 ++--- 3 files changed, 22 insertions(+), 134 deletions(-) diff --git a/gdk/win32/gdkdrag-win32.c b/gdk/win32/gdkdrag-win32.c index 9d662eba38..2da9700306 100644 --- a/gdk/win32/gdkdrag-win32.c +++ b/gdk/win32/gdkdrag-win32.c @@ -482,17 +482,6 @@ process_dnd_queue (gboolean timed, return FALSE; } -static void -_gdk_display_put_event (GdkDisplay *display, - GdkEvent *event) -{ - g_assert (_win32_main_thread == NULL || - _win32_main_thread == g_thread_self ()); - - gdk_event_set_display (event, display); - gdk_display_put_event (display, event); -} - static gboolean do_drag_drop_response (gpointer user_data) { @@ -1762,20 +1751,9 @@ local_send_leave (GdkDragContext *context, (GDK_WIN32_DRAG_CONTEXT (current_dest_drag)->protocol == GDK_DRAG_PROTO_LOCAL) && (current_dest_drag->source_surface == context->source_surface)) { - tmp_event = gdk_event_new (GDK_DRAG_LEAVE); - - g_set_object (&tmp_event->any.surface, context->dest_surface); - /* Pass ownership of context to the event */ - tmp_event->any.send_event = FALSE; - g_set_object (&tmp_event->dnd.context, current_dest_drag); - tmp_event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */ - gdk_event_set_device (tmp_event, gdk_drag_context_get_device (context)); + gdk_drop_emit_leave_event (GDK_DROP (current_dest_drag), FALSE, GDK_CURRENT_TIME); current_dest_drag = NULL; - - GDK_NOTE (EVENTS, _gdk_win32_print_event (tmp_event)); - _gdk_display_put_event (gdk_device_get_display (gdk_drag_context_get_device (context)), tmp_event); - g_object_unref (tmp_event); } } @@ -1786,7 +1764,6 @@ local_send_motion (GdkDragContext *context, GdkDragAction action, guint32 time) { - GdkEvent *tmp_event; GdkWin32DragContext *context_win32 = GDK_WIN32_DRAG_CONTEXT (context); GDK_NOTE (DND, g_print ("local_send_motion: context=%p (%d,%d) current_dest_drag=%p\n", @@ -1799,27 +1776,15 @@ local_send_motion (GdkDragContext *context, { GdkWin32DragContext *current_dest_drag_win32; - tmp_event = gdk_event_new (GDK_DRAG_MOTION); - g_set_object (&tmp_event->any.surface, current_dest_drag->dest_surface); - tmp_event->any.send_event = FALSE; - g_set_object (&tmp_event->dnd.context, current_dest_drag); - tmp_event->dnd.time = time; - gdk_event_set_device (tmp_event, gdk_drag_context_get_device (current_dest_drag)); - gdk_drag_context_set_actions (current_dest_drag, action, action); - tmp_event->dnd.x_root = x_root; - tmp_event->dnd.y_root = y_root; - current_dest_drag_win32 = GDK_WIN32_DRAG_CONTEXT (current_dest_drag); current_dest_drag_win32->util_data.last_x = x_root; current_dest_drag_win32->util_data.last_y = y_root; context_win32->drag_status = GDK_DRAG_STATUS_MOTION_WAIT; - GDK_NOTE (EVENTS, _gdk_win32_print_event (tmp_event)); - _gdk_display_put_event (gdk_device_get_display (gdk_drag_context_get_device (context)), tmp_event); - g_object_unref (tmp_event); + gdk_drop_emit_motion_event (GDK_DROP (current_dest_drag), FALSE, x_root, y_root, time); } } @@ -1827,8 +1792,6 @@ static void local_send_drop (GdkDragContext *context, guint32 time) { - GdkEvent *tmp_event; - GDK_NOTE (DND, g_print ("local_send_drop: context=%p current_dest_drag=%p\n", context, current_dest_drag)); @@ -1839,25 +1802,15 @@ local_send_drop (GdkDragContext *context, { GdkWin32DragContext *context_win32; - /* Pass ownership of context to the event */ - tmp_event = gdk_event_new (GDK_DROP_START); - g_set_object (&tmp_event->any.surface, current_dest_drag->dest_surface); - tmp_event->any.send_event = FALSE; - g_set_object (&tmp_event->dnd.context, current_dest_drag); - tmp_event->dnd.time = GDK_CURRENT_TIME; - gdk_event_set_device (tmp_event, gdk_drag_context_get_device (current_dest_drag)); - context_win32 = GDK_WIN32_DRAG_CONTEXT (current_dest_drag); - tmp_event->dnd.x_root = context_win32->util_data.last_x; - tmp_event->dnd.y_root = context_win32->util_data.last_y; + + gdk_drop_emit_motion_event (GDK_DROP (current_dest_drag), + FALSE, + context_win32->util_data.last_x, context_win32->util_data.last_y, + GDK_CURRENT_TIME); current_dest_drag = NULL; - - GDK_NOTE (EVENTS, _gdk_win32_print_event (tmp_event)); - _gdk_display_put_event (gdk_device_get_display (gdk_drag_context_get_device (context)), tmp_event); - g_object_unref (tmp_event); } - } void diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c index 391ddae94c..17f0738d88 100644 --- a/gdk/win32/gdkdrop-win32.c +++ b/gdk/win32/gdkdrop-win32.c @@ -319,34 +319,6 @@ drop_effect_for_action (GdkDragAction action) return effect; } -static void -dnd_event_emit (GdkEventType type, - GdkDragContext *context, - gint pt_x, - gint pt_y, - GdkSurface *dnd_surface) -{ - GdkEvent *e; - - g_assert (_win32_main_thread == NULL || - _win32_main_thread == g_thread_self ()); - - e = gdk_event_new (type); - - e->any.send_event = FALSE; - g_set_object (&e->dnd.context, context); - g_set_object (&e->any.surface, dnd_surface); - e->dnd.time = GDK_CURRENT_TIME; - e->dnd.x_root = pt_x; - e->dnd.y_root = pt_y; - - gdk_event_set_device (e, gdk_drag_context_get_device (context)); - - GDK_NOTE (EVENTS, _gdk_win32_print_event (e)); - _gdk_event_emit (e); - g_object_unref (e); -} - static GdkContentFormats * query_targets (LPDATAOBJECT pDataObj, GArray *format_target_map) @@ -452,8 +424,8 @@ idroptarget_dragenter (LPDROPTARGET This, set_data_object (&ctx->data_object, pDataObj); pt_x = pt.x / context_win32->scale + _gdk_offset_x; pt_y = pt.y / context_win32->scale + _gdk_offset_y; - dnd_event_emit (GDK_DRAG_ENTER, context, pt_x, pt_y, context->dest_surface); - dnd_event_emit (GDK_DRAG_MOTION, context, pt_x, pt_y, context->dest_surface); + gdk_drop_emit_enter_event (GDK_DROP (context), TRUE, GDK_CURRENT_TIME); + gdk_drop_emit_motion_event (GDK_DROP (context), TRUE, pt_x, pt_y, GDK_CURRENT_TIME); context_win32->last_key_state = grfKeyState; context_win32->last_x = pt_x; context_win32->last_y = pt_y; @@ -495,7 +467,7 @@ idroptarget_dragover (LPDROPTARGET This, pt_y != context_win32->last_y || grfKeyState != context_win32->last_key_state) { - dnd_event_emit (GDK_DRAG_MOTION, ctx->context, pt_x, pt_y, ctx->context->dest_surface); + gdk_drop_emit_motion_event (GDK_DROP (ctx->context), TRUE, pt_x, pt_y, GDK_CURRENT_TIME); context_win32->last_key_state = grfKeyState; context_win32->last_x = pt_x; context_win32->last_y = pt_y; @@ -515,7 +487,7 @@ idroptarget_dragleave (LPDROPTARGET This) GDK_NOTE (DND, g_print ("idroptarget_dragleave %p S_OK\n", This)); - dnd_event_emit (GDK_DRAG_LEAVE, ctx->context, 0, 0, ctx->context->dest_surface); + gdk_drop_emit_leave_event (GDK_DROP (ctx->context), TRUE, GDK_CURRENT_TIME); g_clear_object (&ctx->context); set_data_object (&ctx->data_object, NULL); @@ -550,7 +522,7 @@ idroptarget_drop (LPDROPTARGET This, gdk_drag_context_get_actions (ctx->context), get_suggested_action (context_win32, grfKeyState)); - dnd_event_emit (GDK_DROP_START, ctx->context, pt_x, pt_y, ctx->context->dest_surface); + gdk_drop_emit_drop_event (GDK_DROP (ctx->context), TRUE, pt_x, pt_y, GDK_CURRENT_TIME); /* Notify OLE of copy or move */ *pdwEffect = drop_effect_for_action (ctx->context->action); @@ -715,7 +687,6 @@ gdk_dropfiles_filter (GdkWin32Display *display, GdkSurface *window; GdkDragContext *context; GdkWin32DropContext *context_win32; - GdkEvent *event; GString *result; HANDLE hdrop; POINT pt; @@ -748,17 +719,6 @@ gdk_dropfiles_filter (GdkWin32Display *display, DragQueryPoint (hdrop, &pt); ClientToScreen (msg->hwnd, &pt); - event = gdk_event_new (GDK_DROP_START); - - event->any.send_event = FALSE; - g_set_object (&event->dnd.context, context); - g_set_object (&event->any.surface, window); - gdk_event_set_display (event, GDK_DISPLAY (display)); - gdk_event_set_device (event, gdk_drag_context_get_device (context)); - event->dnd.x_root = pt.x / context_win32->scale + _gdk_offset_x; - event->dnd.y_root = pt.y / context_win32->scale + _gdk_offset_y; - event->dnd.time = _gdk_win32_get_next_tick (msg->time); - nfiles = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0); result = g_string_new (NULL); @@ -837,15 +797,14 @@ gdk_dropfiles_filter (GdkWin32Display *display, _gdk_dropfiles_store (result->str); g_string_free (result, FALSE); - GDK_NOTE (EVENTS, _gdk_win32_print_event (event)); - _gdk_event_emit (event); - g_object_unref (event); + gdk_drop_emit_drop_event (GDK_DROP (context), + FALSE, + pt.x / context_win32->scale + _gdk_offset_x, + pt.y / context_win32->scale + _gdk_offset_y, + _gdk_win32_get_next_tick (msg->time)); DragFinish (hdrop); - gdk_display_put_event (GDK_DISPLAY (display), event); - g_object_unref (event); - *ret_valp = 0; return GDK_WIN32_MESSAGE_FILTER_REMOVE; @@ -884,17 +843,6 @@ gdk_win32_drop_context_status (GdkDrop *drop, } } -static void -_gdk_display_put_event (GdkDisplay *display, - GdkEvent *event) -{ - g_assert (_win32_main_thread == NULL || - _win32_main_thread == g_thread_self ()); - - gdk_event_set_display (event, display); - gdk_display_put_event (display, event); -} - static void gdk_win32_drop_context_finish (GdkDrop *drop, GdkDragAction action) @@ -1218,7 +1166,6 @@ void _gdk_win32_local_send_enter (GdkDragContext *context, guint32 time) { - GdkEvent *tmp_event; GdkDragContext *new_context; GDK_NOTE (DND, g_print ("local_send_enter: context=%p current_dest_drag=%p\n", @@ -1242,18 +1189,9 @@ _gdk_win32_local_send_enter (GdkDragContext *context, gdk_surface_get_events (new_context->source_surface) | GDK_PROPERTY_CHANGE_MASK); - tmp_event = gdk_event_new (GDK_DRAG_ENTER); - g_set_object (&tmp_event->any.surface, context->dest_surface); - tmp_event->any.send_event = FALSE; - g_set_object (&tmp_event->dnd.context, new_context); - tmp_event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */ - gdk_event_set_device (tmp_event, gdk_drag_context_get_device (context)); - current_dest_drag = new_context; - GDK_NOTE (EVENTS, _gdk_win32_print_event (tmp_event)); - _gdk_display_put_event (gdk_device_get_display (gdk_drag_context_get_device (context)), tmp_event); - g_object_unref (tmp_event); + gdk_drop_emit_enter_event (GDK_DROP (new_context), FALSE, GDK_CURRENT_TIME); } void diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c index e69cd1e372..02bfa9d11e 100644 --- a/gdk/win32/gdkevents-win32.c +++ b/gdk/win32/gdkevents-win32.c @@ -870,13 +870,10 @@ _gdk_win32_print_event (const GdkEvent *event) case GDK_DRAG_LEAVE: case GDK_DRAG_MOTION: case GDK_DROP_START: - if (event->dnd.context != NULL) - g_print ("ctx:%p: %s %s src:%p dest:%p", - event->dnd.context, - _gdk_win32_drag_protocol_to_string (GDK_WIN32_DRAG_CONTEXT (event->dnd.context)->protocol), - event->dnd.context->is_source ? "SOURCE" : "DEST", - event->dnd.context->source_surface == NULL ? NULL : GDK_SURFACE_HWND (event->dnd.context->source_surface), - event->dnd.context->dest_surface == NULL ? NULL : GDK_SURFACE_HWND (event->dnd.context->dest_surface)); + if (event->dnd.drop != NULL) + g_print ("ctx:%p: %s", + event->dnd.drop, + _gdk_win32_drag_protocol_to_string (GDK_WIN32_DRAG_CONTEXT (event->dnd.drop)->protocol)); break; case GDK_SCROLL: g_print ("(%.4g,%.4g) (%.4g,%.4g) %s ",