From 5e2e0af8b4a39b3174aef4de964d9655d1c7b6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Sun, 26 Nov 2017 00:21:22 +0000 Subject: [PATCH] GDK W32: Preserve the target value for change_property() We need to know the target atom value to know when we need to do something with side-effects (since side-effects are expressed via special target values). Previously, the code side-stepped that by looking at the data type (which was rather unique for the one side-effect target that we supported, signalled by the TARGETS target), but for the DELETE target that seems to be no longer an option, hence the new field to carry this information past the convert_selection() routine. This prevents GDK from throwing a warning when trying to convert a DELETE target, which has no format or data objects set. The side-effects for the DELETE target happen earlier, in GTK layer. By the point it gets to change_property(), it's a no-op. https://bugzilla.gnome.org/show_bug.cgi?id=786509 --- gdk/win32/gdkdnd-win32.c | 3 +++ gdk/win32/gdkevents-win32.c | 1 + gdk/win32/gdkselection-win32.c | 22 +++++++++++++++++++--- gdk/win32/gdkselection-win32.h | 2 ++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/gdk/win32/gdkdnd-win32.c b/gdk/win32/gdkdnd-win32.c index 39e0b74906..3e4b2e6f60 100644 --- a/gdk/win32/gdkdnd-win32.c +++ b/gdk/win32/gdkdnd-win32.c @@ -1069,6 +1069,7 @@ idataobject_getdata (LPDATAOBJECT This, { target = frec->target; win32_sel->property_change_transmute = frec->transmute; + win32_sel->property_change_target_atom = frec->target; } } @@ -2108,6 +2109,7 @@ _gdk_win32_dnd_do_dragdrop (void) /* Delete dnd selection after successful move */ if (hr == DRAGDROP_S_DROP && dwEffect == DROPEFFECT_MOVE) { + GdkWin32Selection *win32_sel = _gdk_win32_selection_get (); GdkEvent tmp_event; memset (&tmp_event, 0, sizeof (tmp_event)); @@ -2116,6 +2118,7 @@ _gdk_win32_dnd_do_dragdrop (void) tmp_event.selection.send_event = FALSE; tmp_event.selection.selection = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND); tmp_event.selection.target = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE); + win32_sel->property_change_target_atom = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE); tmp_event.selection.property = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND); g_set_object (&tmp_event.selection.requestor, drag_ctx->source_window); tmp_event.selection.time = GDK_CURRENT_TIME; /* ??? */ diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c index 601ca036c8..4df73d56e6 100644 --- a/gdk/win32/gdkevents-win32.c +++ b/gdk/win32/gdkevents-win32.c @@ -3821,6 +3821,7 @@ gdk_event_translate (MSG *msg, property_change_data = g_new0 (STGMEDIUM, 1); win32_sel->property_change_data = property_change_data; win32_sel->property_change_format = msg->wParam; + win32_sel->property_change_target_atom = target; fixup_event (event); GDK_NOTE (EVENTS, g_print (" (calling _gdk_event_emit)")); diff --git a/gdk/win32/gdkselection-win32.c b/gdk/win32/gdkselection-win32.c index 879b90d0b9..f53eae3e4b 100644 --- a/gdk/win32/gdkselection-win32.c +++ b/gdk/win32/gdkselection-win32.c @@ -357,6 +357,7 @@ gdk_win32_selection_init (GdkWin32Selection *win32_selection) win32_selection->dnd_data_object_target = NULL; win32_selection->property_change_format = 0; win32_selection->property_change_data = NULL; + win32_selection->property_change_target_atom = 0; atoms = g_array_sized_new (FALSE, TRUE, sizeof (GdkAtom), GDK_WIN32_ATOM_INDEX_LAST); g_array_set_size (atoms, GDK_WIN32_ATOM_INDEX_LAST); @@ -894,6 +895,7 @@ send_targets_request (guint time) tmp_event.selection.property = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION); tmp_event.selection.requestor = owner; tmp_event.selection.time = time; + win32_sel->property_change_target_atom = _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS); gdk_event_put (&tmp_event); win32_sel->targets_request_pending = TRUE; @@ -2325,8 +2327,10 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel, gint nelements) { if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_GDK_SELECTION) && - type == GDK_SELECTION_TYPE_ATOM) /* implies target == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS) */ + win32_sel->property_change_target_atom == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_TARGETS)) { + win32_sel->property_change_target_atom = 0; + if (win32_sel->clipboard_opened_for == INVALID_HANDLE_VALUE && OpenClipboard (GDK_WINDOW_HWND (window))) { @@ -2345,11 +2349,22 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel, open_clipboard_timeout (NULL); } } + else if (property == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_OLE2_DND) && + mode == GDK_PROP_MODE_REPLACE && + win32_sel->property_change_target_atom == _gdk_win32_selection_atom (GDK_WIN32_ATOM_INDEX_DELETE)) + { + /* no-op on Windows */ + win32_sel->property_change_target_atom = 0; + } else if (mode == GDK_PROP_MODE_REPLACE && - (win32_sel->property_change_data == NULL || + (win32_sel->property_change_target_atom == 0 || + win32_sel->property_change_data == NULL || win32_sel->property_change_format == 0)) { - g_warning ("Setting selection property with 0x%p == NULL or 0x%x == 0", win32_sel->property_change_data, win32_sel->property_change_format); + g_warning ("Setting selection property with 0x%p == NULL or 0x%x == 0 or 0x%p == 0", + win32_sel->property_change_data, + win32_sel->property_change_format, + win32_sel->property_change_target_atom); } else if (mode == GDK_PROP_MODE_REPLACE && win32_sel->property_change_data != NULL && @@ -2396,6 +2411,7 @@ _gdk_win32_selection_property_change (GdkWin32Selection *win32_sel, win32_sel->property_change_format = 0; win32_sel->property_change_data = 0; + win32_sel->property_change_target_atom = 0; } else { diff --git a/gdk/win32/gdkselection-win32.h b/gdk/win32/gdkselection-win32.h index 23dac73762..a71655460c 100644 --- a/gdk/win32/gdkselection-win32.h +++ b/gdk/win32/gdkselection-win32.h @@ -167,6 +167,8 @@ struct _GdkWin32Selection LPSTGMEDIUM property_change_data; /* Carries the transmute field of the GdkSelTargetFormat from from idataobject_getdata() to property_change() */ gboolean property_change_transmute; + /* Carries the target atom from GDK_SELECTION_REQUEST issuer to property_change() */ + GdkAtom property_change_target_atom; /* TRUE when we are emptying the clipboard ourselves */ gboolean ignore_destroy_clipboard;