[gtk+/gtk-3-22] GDK W32: Preserve the target value for change_property()



commit 56074fbf3c3bdf760b444c7196c9c4aac659eeee
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date:   Sun Nov 26 00:21:22 2017 +0000

    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 fc4dfb0..cb7eaa5 100644
--- a/gdk/win32/gdkdnd-win32.c
+++ b/gdk/win32/gdkdnd-win32.c
@@ -1057,6 +1057,7 @@ idataobject_getdata (LPDATAOBJECT This,
         {
           target = frec->target;
           win32_sel->property_change_transmute = frec->transmute;
+          win32_sel->property_change_target_atom = frec->target;
         }
     }
 
@@ -2130,6 +2131,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));
@@ -2138,6 +2140,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 873d225..a2cd67c 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -3815,6 +3815,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 5fd02a6..ce42d0d 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 ed65087..c3ed6cd 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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]