]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkdnd.c
Deprecate flag macros for toplevel, state, no window and composite child
[~andy/gtk] / gtk / gtkdnd.c
index 71376c6d54485277997933594c1aed693b708935..bdd3ab9e72ac120dd01abc46e61c98226cb650cd 100644 (file)
@@ -24,7 +24,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <stdlib.h>
 #include <string.h>
 
 #include "gdk/gdkkeysyms.h"
 
+#ifdef GDK_WINDOWING_X11
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+#include "gdk/x11/gdkx.h"
+#endif
+
 #include "gtkdnd.h"
 #include "gtkiconfactory.h"
 #include "gtkicontheme.h"
@@ -252,9 +258,10 @@ static void gtk_drag_source_release_selections (GtkDragSourceInfo *info,
 static void gtk_drag_drop                      (GtkDragSourceInfo *info,
                                                guint32            time);
 static void gtk_drag_drop_finished             (GtkDragSourceInfo *info,
-                                               gboolean           success,
+                                               GtkDragResult      result,
                                                guint              time);
 static void gtk_drag_cancel                    (GtkDragSourceInfo *info,
+                                               GtkDragResult      result,
                                                guint32            time);
 
 static gboolean gtk_drag_source_event_cb       (GtkWidget         *widget,
@@ -285,6 +292,9 @@ static gboolean gtk_drag_key_cb                (GtkWidget         *widget,
 static gboolean gtk_drag_grab_broken_event_cb  (GtkWidget          *widget,
                                                GdkEventGrabBroken *event,
                                                gpointer            data);
+static void     gtk_drag_grab_notify_cb        (GtkWidget         *widget,
+                                               gboolean           was_grabbed,
+                                               gpointer           data);
 static gboolean gtk_drag_button_release_cb     (GtkWidget         *widget, 
                                                GdkEventButton    *event, 
                                                gpointer           data);
@@ -389,6 +399,139 @@ gtk_drag_get_ipc_widget (GtkWidget *widget)
 }
 
 
+#ifdef GDK_WINDOWING_X11
+
+/*
+ * We want to handle a handful of keys during DND, e.g. Escape to abort.
+ * Grabbing the keyboard has the unfortunate side-effect of preventing
+ * useful things such as using Alt-Tab to cycle between windows or
+ * switching workspaces. Therefore, we just grab the few keys we are
+ * interested in. Note that we need to put the grabs on the root window
+ * in order for them to still work when the focus is moved to another
+ * app/workspace.
+ *
+ * GDK needs a little help to successfully deliver root key events...
+ */
+
+static GdkFilterReturn
+root_key_filter (GdkXEvent *xevent,
+                 GdkEvent  *event,
+                 gpointer   data)
+{
+  XEvent *ev = (XEvent *)xevent;
+
+  if ((ev->type == KeyPress || ev->type == KeyRelease) &&
+      ev->xkey.root == ev->xkey.window)
+    ev->xkey.window = (Window)data;
+
+  return GDK_FILTER_CONTINUE;
+}
+
+typedef struct {
+  gint keysym;
+  gint modifiers;
+} GrabKey;
+
+static GrabKey grab_keys[] = {
+  { XK_Escape, 0 },
+  { XK_space, 0 },
+  { XK_KP_Space, 0 },
+  { XK_Return, 0 },
+  { XK_KP_Enter, 0 },
+  { XK_Up, 0 },
+  { XK_Up, Mod1Mask },
+  { XK_Down, 0 },
+  { XK_Down, Mod1Mask },
+  { XK_Left, 0 },
+  { XK_Left, Mod1Mask },
+  { XK_Right, 0 },
+  { XK_Right, Mod1Mask },
+  { XK_KP_Up, 0 },
+  { XK_KP_Up, Mod1Mask },
+  { XK_KP_Down, 0 },
+  { XK_KP_Down, Mod1Mask },
+  { XK_KP_Left, 0 },
+  { XK_KP_Left, Mod1Mask },
+  { XK_KP_Right, 0 },
+  { XK_KP_Right, Mod1Mask }
+};
+
+static void
+grab_dnd_keys (GtkWidget *widget,
+               guint32    time)
+{
+  guint i;
+  GdkWindow *window, *root;
+  gint keycode;
+
+  window = widget->window;
+  root = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
+
+  gdk_error_trap_push ();
+
+  for (i = 0; i < G_N_ELEMENTS (grab_keys); ++i)
+    {
+      keycode = XKeysymToKeycode (GDK_WINDOW_XDISPLAY (window), grab_keys[i].keysym);
+      XGrabKey (GDK_WINDOW_XDISPLAY (window),
+               keycode, grab_keys[i].modifiers,
+               GDK_WINDOW_XID (root),
+               FALSE,
+               GrabModeAsync,
+               GrabModeAsync);
+    }
+
+  gdk_flush ();
+  gdk_error_trap_pop ();
+
+  gdk_window_add_filter (NULL, root_key_filter, (gpointer) GDK_WINDOW_XID (window));
+}
+
+static void
+ungrab_dnd_keys (GtkWidget *widget,
+                 guint32    time)
+{
+  guint i;
+  GdkWindow *window, *root;
+  gint keycode;
+
+  window = widget->window;
+  root = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
+
+  gdk_window_remove_filter (NULL, root_key_filter, (gpointer) GDK_WINDOW_XID (window));
+
+  gdk_error_trap_push ();
+
+  for (i = 0; i < G_N_ELEMENTS (grab_keys); ++i)
+    {
+      keycode = XKeysymToKeycode (GDK_WINDOW_XDISPLAY (window), grab_keys[i].keysym);
+      XUngrabKey (GDK_WINDOW_XDISPLAY (window),
+                 keycode, grab_keys[i].modifiers,
+                  GDK_WINDOW_XID (root));
+    }
+
+  gdk_flush ();
+  gdk_error_trap_pop ();
+}
+
+#else
+
+static void
+grab_dnd_keys (GtkWidget *widget,
+               guint32    time)
+{
+  gdk_keyboard_grab (widget->window, FALSE, time);
+}
+
+static void
+ungrab_dnd_keys (GtkWidget *widget,
+                 guint32    time)
+{
+  gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), time);
+}
+
+#endif
+
+
 /***************************************************************
  * gtk_drag_release_ipc_widget:
  *     Releases widget retrieved with gtk_drag_get_ipc_widget ()
@@ -404,6 +547,7 @@ gtk_drag_release_ipc_widget (GtkWidget *widget)
   GdkScreen *screen = gtk_widget_get_screen (widget);
   GSList *drag_widgets = g_object_get_data (G_OBJECT (screen),
                                            "gtk-dnd-ipc-widgets");
+  ungrab_dnd_keys (widget, GDK_CURRENT_TIME);
   if (window->group)
     gtk_window_group_remove_window (window->group, window);
   drag_widgets = g_slist_prepend (drag_widgets, widget);
@@ -837,7 +981,7 @@ gtk_drag_get_data (GtkWidget      *widget,
   g_object_ref (context);
   g_object_ref (widget);
   
-  g_signal_connect (selection_widget, "selection_received",
+  g_signal_connect (selection_widget, "selection-received",
                    G_CALLBACK (gtk_drag_selection_received), widget);
 
   g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context);
@@ -927,7 +1071,7 @@ gtk_drag_finish (GdkDragContext *context,
       g_object_ref (context);
       
       g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context);
-      g_signal_connect (selection_widget, "selection_received",
+      g_signal_connect (selection_widget, "selection-received",
                        G_CALLBACK (gtk_drag_selection_received),
                        NULL);
       
@@ -962,7 +1106,7 @@ gtk_drag_highlight_expose (GtkWidget      *widget,
     {
       cairo_t *cr;
       
-      if (GTK_WIDGET_NO_WINDOW (widget))
+      if (!gtk_widget_get_has_window (widget))
        {
          x = widget->allocation.x;
          y = widget->allocation.y;
@@ -978,7 +1122,7 @@ gtk_drag_highlight_expose (GtkWidget      *widget,
       
       gtk_paint_shadow (widget->style, widget->window,
                        GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                       NULL, widget, "dnd",
+                       &event->area, widget, "dnd",
                        x, y, width, height);
 
       cr = gdk_cairo_create (widget->window);
@@ -1007,7 +1151,7 @@ gtk_drag_highlight (GtkWidget  *widget)
 {
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_signal_connect_after (widget, "expose_event",
+  g_signal_connect_after (widget, "expose-event",
                          G_CALLBACK (gtk_drag_highlight_expose),
                          NULL);
 
@@ -1061,32 +1205,69 @@ gtk_drag_dest_set_internal (GtkWidget       *widget,
 
   g_signal_connect (widget, "realize",
                    G_CALLBACK (gtk_drag_dest_realized), site);
-  g_signal_connect (widget, "hierarchy_changed",
+  g_signal_connect (widget, "hierarchy-changed",
                    G_CALLBACK (gtk_drag_dest_hierarchy_changed), site);
 
   g_object_set_data_full (G_OBJECT (widget), I_("gtk-drag-dest"),
                          site, gtk_drag_dest_site_destroy);
 }
-                           
 
-/*************************************************************
+/**
  * gtk_drag_dest_set:
- *     Register a drop site, and possibly add default behaviors.
- *   arguments:
- *     widget:    
- *     flags:     Which types of default drag behavior to use
- *     targets:   Table of targets that can be accepted
- *     n_targets: Number of of entries in targets
- *     actions:   
- *   results:
- *************************************************************/
-
-void 
-gtk_drag_dest_set   (GtkWidget            *widget,
-                    GtkDestDefaults       flags,
-                    const GtkTargetEntry *targets,
-                    gint                  n_targets,
-                    GdkDragAction         actions)
+ * @widget: a #GtkWidget
+ * @flags: which types of default drag behavior to use
+ * @targets: a pointer to an array of #GtkTargetEntry<!-- -->s indicating
+ * the drop types that this @widget will accept. Later you can access the list
+ * with gtk_drag_dest_get_target_list() and gtk_drag_dest_find_target().
+ * @n_targets: the number of entries in @targets.
+ * @actions: a bitmask of possible actions for a drop onto this @widget.
+ *
+ * Sets a widget as a potential drop destination, and adds default behaviors.
+ *
+ * The default behaviors listed in @flags have an effect similar
+ * to installing default handlers for the widget's drag-and-drop signals
+ * (#GtkWidget:drag-motion, #GtkWidget:drag-drop, ...). They all exist
+ * for convenience. When passing #GTK_DEST_DEFAULT_ALL for instance it is
+ * sufficient to connect to the widget's #GtkWidget::drag-data-received
+ * signal to get primitive, but consistent drag-and-drop support.
+ *
+ * Things become more complicated when you try to preview the dragged data,
+ * as described in the documentation for #GtkWidget:drag-motion. The default
+ * behaviors described by @flags make some assumptions, that can conflict
+ * with your own signal handlers. For instance #GTK_DEST_DEFAULT_DROP causes
+ * invokations of gdk_drag_status() in the context of #GtkWidget:drag-motion,
+ * and invokations of gtk_drag_finish() in #GtkWidget:drag-data-received.
+ * Especially the later is dramatic, when your own #GtkWidget:drag-motion
+ * handler calls gtk_drag_get_data() to inspect the dragged data.
+ *
+ * There's no way to set a default action here, you can use the
+ * #GtkWidget:drag-motion callback for that. Here's an example which selects
+ * the action to use depending on whether the control key is pressed or not:
+ * |[
+ * static void
+ * drag_motion (GtkWidget *widget,
+ *              GdkDragContext *context,
+ *              gint x,
+ *              gint y,
+ *              guint time)
+ * {
+ *   GdkModifierType mask;
+ *
+ *   gdk_window_get_pointer (gtk_widget_get_window (widget),
+ *                           NULL, NULL, &mask);
+ *   if (mask & GDK_CONTROL_MASK)
+ *     gdk_drag_status (context, GDK_ACTION_COPY, time);
+ *   else
+ *     gdk_drag_status (context, GDK_ACTION_MOVE, time);
+ * }
+ * ]|
+ */
+void
+gtk_drag_dest_set (GtkWidget            *widget,
+                  GtkDestDefaults       flags,
+                  const GtkTargetEntry *targets,
+                  gint                  n_targets,
+                  GdkDragAction         actions)
 {
   GtkDragDestSite *site;
   
@@ -1516,7 +1697,9 @@ gtk_drag_dest_find_target (GtkWidget      *widget,
          if (tmp_source->data == GUINT_TO_POINTER (pair->target))
            {
              if ((!(pair->flags & GTK_TARGET_SAME_APP) || source_widget) &&
-                 (!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)))
+                 (!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)) &&
+                  (!(pair->flags & GTK_TARGET_OTHER_APP) || !source_widget) &&
+                  (!(pair->flags & GTK_TARGET_OTHER_WIDGET) || (source_widget != widget)))
                return pair->target;
              else
                break;
@@ -1582,7 +1765,7 @@ gtk_drag_selection_received (GtkWidget        *widget,
              if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
                  selection_data->length >= 0)
                g_signal_emit_by_name (drop_widget,
-                                      "drag_data_received",
+                                      "drag-data-received",
                                       context, info->drop_x, info->drop_y,
                                       selection_data,
                                       target_info, time);
@@ -1591,7 +1774,7 @@ gtk_drag_selection_received (GtkWidget        *widget,
       else
        {
          g_signal_emit_by_name (drop_widget,
-                                "drag_data_received",
+                                "drag-data-received",
                                 context, info->drop_x, info->drop_y,
                                 selection_data,
                                 0, time);
@@ -1677,7 +1860,7 @@ gtk_drag_find_widget (GtkWidget       *widget,
       allocation_to_window_x = widget->allocation.x;
       allocation_to_window_y = widget->allocation.y;
 
-      if (!GTK_WIDGET_NO_WINDOW (widget))
+      if (gtk_widget_get_has_window (widget))
        {
          /* The allocation is relative to the parent window for
           * window widgets, not to widget->window.
@@ -1732,7 +1915,7 @@ gtk_drag_find_widget (GtkWidget       *widget,
          new_data.toplevel = FALSE;
          
          /* need to reference children temporarily in case the
-          * ::drag_motion/::drag_drop callbacks change the widget heirarchy.
+          * ::drag-motion/::drag-drop callbacks change the widget hierarchy.
           */
          gtk_container_forall (GTK_CONTAINER (widget), prepend_and_ref_widget, &children);
          for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
@@ -1747,7 +1930,7 @@ gtk_drag_find_widget (GtkWidget       *widget,
        }
 
       /* If not, and this widget is registered as a drop site, check to
-       * emit "drag_motion" to check if we are actually in
+       * emit "drag-motion" to check if we are actually in
        * a drop site.
        */
       if (!data->found &&
@@ -1758,7 +1941,7 @@ gtk_drag_find_widget (GtkWidget       *widget,
                                        data->x - x_offset - allocation_to_window_x,
                                        data->y - y_offset - allocation_to_window_y,
                                        data->time);
-         /* If so, send a "drag_leave" to the last widget */
+         /* If so, send a "drag-leave" to the last widget */
          if (data->found)
            {
              if (data->info->widget && data->info->widget != widget)
@@ -1795,7 +1978,7 @@ gtk_drag_proxy_begin (GtkWidget       *widget,
   source_info = gtk_drag_get_source_info (context, TRUE);
 
   source_info->ipc_widget = ipc_widget;
-  source_info->widget = gtk_widget_ref (widget);
+  source_info->widget = g_object_ref (widget);
 
   source_info->target_list = gtk_target_list_new (NULL, 0);
   tmp_list = dest_info->context->targets;
@@ -1809,7 +1992,7 @@ gtk_drag_proxy_begin (GtkWidget       *widget,
   source_info->proxy_dest = dest_info;
   
   g_signal_connect (ipc_widget,
-                   "selection_get",
+                   "selection-get",
                    G_CALLBACK (gtk_drag_selection_get),
                    source_info);
   
@@ -1882,7 +2065,7 @@ gtk_drag_dest_realized (GtkWidget *widget)
 {
   GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
 
-  if (GTK_WIDGET_TOPLEVEL (toplevel))
+  if (gtk_widget_is_toplevel (toplevel))
     gdk_window_register_dnd (toplevel->window);
 }
 
@@ -1892,7 +2075,7 @@ gtk_drag_dest_hierarchy_changed (GtkWidget *widget,
 {
   GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
 
-  if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_WIDGET_REALIZED (toplevel))
+  if (gtk_widget_is_toplevel (toplevel) && GTK_WIDGET_REALIZED (toplevel))
     gdk_window_register_dnd (toplevel->window);
 }
 
@@ -1943,7 +2126,7 @@ gtk_drag_dest_leave (GtkWidget      *widget,
 
       if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag ||
          site->track_motion)
-       g_signal_emit_by_name (widget, "drag_leave", context, time);
+       g_signal_emit_by_name (widget, "drag-leave", context, time);
       
       site->have_drag = FALSE;
     }
@@ -2050,7 +2233,7 @@ gtk_drag_dest_motion (GtkWidget        *widget,
        }
     }
 
-  g_signal_emit_by_name (widget, "drag_motion",
+  g_signal_emit_by_name (widget, "drag-motion",
                         context, x, y, time, &retval);
 
   return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
@@ -2151,7 +2334,7 @@ gtk_drag_dest_drop (GtkWidget          *widget,
            gtk_drag_get_data (widget, context, target, time);
        }
 
-      g_signal_emit_by_name (widget, "drag_drop",
+      g_signal_emit_by_name (widget, "drag-drop",
                             context, x, y, time, &retval);
 
       return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval;
@@ -2203,8 +2386,8 @@ gtk_drag_begin_internal (GtkWidget         *widget,
       return NULL;
     }
 
-  gdk_keyboard_grab (ipc_widget->window, FALSE, time);
-    
+  grab_dnd_keys (ipc_widget, time);
+
   /* We use a GTK grab here to override any grabs that the widget
    * we are dragging from might have held
    */
@@ -2229,7 +2412,7 @@ gtk_drag_begin_internal (GtkWidget         *widget,
   info->ipc_widget = ipc_widget;
   g_object_set_data (G_OBJECT (info->ipc_widget), I_("gtk-info"), info);
 
-  info->widget = gtk_widget_ref (widget);
+  info->widget = g_object_ref (widget);
   
   info->button = button;
   info->cursor = cursor;
@@ -2244,7 +2427,7 @@ gtk_drag_begin_internal (GtkWidget         *widget,
   info->icon_window = NULL;
   info->destroy_icon = FALSE;
 
-  /* Set cur_x, cur_y here so if the "drag_begin" signal shows
+  /* Set cur_x, cur_y here so if the "drag-begin" signal shows
    * the drag icon, it will be in the right place
    */
   if (event && event->type == GDK_MOTION_NOTIFY)
@@ -2259,7 +2442,7 @@ gtk_drag_begin_internal (GtkWidget         *widget,
                               &info->cur_screen, &info->cur_x, &info->cur_y, NULL);
     }
 
-  g_signal_emit_by_name (widget, "drag_begin", info->context);
+  g_signal_emit_by_name (widget, "drag-begin", info->context);
 
   /* Ensure that we have an icon before we start the drag; the
    * application may have set one in ::drag_begin, or it may
@@ -2329,17 +2512,19 @@ gtk_drag_begin_internal (GtkWidget         *widget,
   info->start_x = info->cur_x;
   info->start_y = info->cur_y;
 
-  g_signal_connect (info->ipc_widget, "grab_broken_event",
+  g_signal_connect (info->ipc_widget, "grab-broken-event",
                    G_CALLBACK (gtk_drag_grab_broken_event_cb), info);
-  g_signal_connect (info->ipc_widget, "button_release_event",
+  g_signal_connect (info->ipc_widget, "grab-notify",
+                   G_CALLBACK (gtk_drag_grab_notify_cb), info);
+  g_signal_connect (info->ipc_widget, "button-release-event",
                    G_CALLBACK (gtk_drag_button_release_cb), info);
-  g_signal_connect (info->ipc_widget, "motion_notify_event",
+  g_signal_connect (info->ipc_widget, "motion-notify-event",
                    G_CALLBACK (gtk_drag_motion_cb), info);
-  g_signal_connect (info->ipc_widget, "key_press_event",
+  g_signal_connect (info->ipc_widget, "key-press-event",
                    G_CALLBACK (gtk_drag_key_cb), info);
-  g_signal_connect (info->ipc_widget, "key_release_event",
+  g_signal_connect (info->ipc_widget, "key-release-event",
                    G_CALLBACK (gtk_drag_key_cb), info);
-  g_signal_connect (info->ipc_widget, "selection_get",
+  g_signal_connect (info->ipc_widget, "selection-get",
                    G_CALLBACK (gtk_drag_selection_get), info);
 
   info->have_grab = TRUE;
@@ -2420,13 +2605,13 @@ gtk_drag_source_set (GtkWidget            *widget,
 
       site->icon_type = GTK_IMAGE_EMPTY;
       
-      g_signal_connect (widget, "button_press_event",
+      g_signal_connect (widget, "button-press-event",
                        G_CALLBACK (gtk_drag_source_event_cb),
                        site);
-      g_signal_connect (widget, "button_release_event",
+      g_signal_connect (widget, "button-release-event",
                        G_CALLBACK (gtk_drag_source_event_cb),
                        site);
-      g_signal_connect (widget, "motion_notify_event",
+      g_signal_connect (widget, "motion-notify-event",
                        G_CALLBACK (gtk_drag_source_event_cb),
                        site);
       
@@ -2646,10 +2831,10 @@ gtk_drag_source_unset_icon (GtkDragSourceSite *site)
  * @widget: a #GtkWidget
  * @colormap: the colormap of the icon
  * @pixmap: the image data for the icon
- * @mask: the transparency mask for an image.
- * 
+ * @mask: (allow-none): the transparency mask for an image.
+ *
  * Sets the icon that will be used for drags from a particular widget
- * from a pixmap/mask. GTK+ retains references for the arguments, and 
+ * from a pixmap/mask. GTK+ retains references for the arguments, and
  * will release them when they are no longer needed.
  * Use gtk_drag_source_set_icon_pixbuf() instead.
  **/
@@ -2877,7 +3062,7 @@ gtk_drag_set_icon_window (GdkDragContext *context,
   gtk_drag_remove_icon (info);
 
   if (widget)
-    gtk_widget_ref (widget);  
+    g_object_ref (widget);  
   
   info->icon_window = widget;
   info->hot_x = hot_x;
@@ -2904,7 +3089,7 @@ gtk_drag_set_icon_window (GdkDragContext *context,
  * 
  * Changes the icon for a widget to a given widget. GTK+
  * will not destroy the icon, so if you don't want
- * it to persist, you should connect to the "drag_end" 
+ * it to persist, you should connect to the "drag-end" 
  * signal and destroy it yourself.
  **/
 void 
@@ -2969,7 +3154,7 @@ set_icon_stock_pixbuf (GdkDragContext    *context,
   gtk_widget_pop_colormap ();
 
   gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
-  gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
+  gtk_widget_set_app_paintable (window, TRUE);
 
   if (stock_id)
     {
@@ -3072,7 +3257,7 @@ gtk_drag_set_icon_stock  (GdkDragContext *context,
  *            with a  context for the source side of a drag)
  * @colormap: the colormap of the icon 
  * @pixmap: the image data for the icon 
- * @mask: the transparency mask for the icon
+ * @mask: the transparency mask for the icon or %NULL for none.
  * @hot_x: the X offset within @pixmap of the hotspot.
  * @hot_y: the Y offset within @pixmap of the hotspot.
  * 
@@ -3109,7 +3294,7 @@ gtk_drag_set_icon_pixmap (GdkDragContext    *context,
   gtk_widget_push_colormap (colormap);
 
   window = gtk_window_new (GTK_WINDOW_POPUP);
-  gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_DND);
+  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DND);
   gtk_window_set_screen (GTK_WINDOW (window), screen);
   set_can_change_screen (window, FALSE);
   gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
@@ -3216,8 +3401,9 @@ gtk_drag_set_icon_default (GdkDragContext *context)
  * 
  * Changes the default drag icon. GTK+ retains references for the
  * arguments, and will release them when they are no longer needed.
- * This function is obsolete. The default icon should now be changed
- * via the stock system by changing the stock pixbuf for #GTK_STOCK_DND.
+ *
+ * Deprecated: Change the default drag icon via the stock system by 
+ *     changing the stock pixbuf for #GTK_STOCK_DND instead.
  **/
 void 
 gtk_drag_set_default_icon (GdkColormap   *colormap,
@@ -3328,7 +3514,7 @@ _gtk_drag_source_handle_event (GtkWidget *widget,
       break;
       
     case GDK_DROP_FINISHED:
-      gtk_drag_drop_finished (info, TRUE, event->dnd.time);
+      gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, event->dnd.time);
       break;
     default:
       g_assert_not_reached ();
@@ -3408,9 +3594,12 @@ gtk_drag_source_check_selection (GtkDragSourceInfo *info,
 
 static void
 gtk_drag_drop_finished (GtkDragSourceInfo *info,
-                       gboolean           success,
+                       GtkDragResult      result,
                        guint              time)
 {
+  gboolean success;
+
+  success = (result == GTK_DRAG_RESULT_SUCCESS);
   gtk_drag_source_release_selections (info, time); 
 
   if (info->proxy_dest)
@@ -3422,6 +3611,10 @@ gtk_drag_drop_finished (GtkDragSourceInfo *info,
     }
   else
     {
+      if (!success)
+       g_signal_emit_by_name (info->widget, "drag-failed",
+                              info->context, result, &success);
+
       if (success)
        {
          gtk_drag_source_info_destroy (info);
@@ -3448,7 +3641,7 @@ gtk_drag_drop_finished (GtkDragSourceInfo *info,
           * to respond really late, we still are OK.
           */
          gtk_drag_clear_source_info (info->context);
-         g_timeout_add (ANIM_STEP_TIME, gtk_drag_anim_timeout, anim);
+         gdk_threads_add_timeout (ANIM_STEP_TIME, gtk_drag_anim_timeout, anim);
        }
     }
 }
@@ -3507,18 +3700,18 @@ gtk_drag_drop (GtkDragSourceInfo *info,
              selection_data.data = NULL;
              selection_data.length = -1;
              
-             g_signal_emit_by_name (info->widget, "drag_data_get",
+             g_signal_emit_by_name (info->widget, "drag-data-get",
                                     info->context, &selection_data,
                                     pair->info,
                                     time);
              
              /* FIXME: Should we check for length >= 0 here? */
-             gtk_drag_drop_finished (info, TRUE, time);
+             gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, time);
              return;
            }
          tmp_list = tmp_list->next;
        }
-      gtk_drag_drop_finished (info, FALSE, time);
+      gtk_drag_drop_finished (info, GTK_DRAG_RESULT_NO_TARGET, time);
     }
   else
     {
@@ -3526,7 +3719,7 @@ gtk_drag_drop (GtkDragSourceInfo *info,
        gtk_widget_hide (info->icon_window);
        
       gdk_drag_drop (info->context, time);
-      info->drop_timeout = g_timeout_add (DROP_ABORT_TIME,
+      info->drop_timeout = gdk_threads_add_timeout (DROP_ABORT_TIME,
                                          gtk_drag_abort_timeout,
                                          info);
     }
@@ -3625,16 +3818,16 @@ gtk_drag_selection_get (GtkWidget        *widget,
     {
     case TARGET_DELETE:
       g_signal_emit_by_name (info->widget,
-                            "drag_data_delete", 
+                            "drag-data-delete", 
                             info->context);
       gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
       break;
     case TARGET_MOTIF_SUCCESS:
-      gtk_drag_drop_finished (info, TRUE, time);
+      gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, time);
       gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
       break;
     case TARGET_MOTIF_FAILURE:
-      gtk_drag_drop_finished (info, FALSE, time);
+      gtk_drag_drop_finished (info, GTK_DRAG_RESULT_NO_TARGET, time);
       gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
       break;
     default:
@@ -3657,7 +3850,7 @@ gtk_drag_selection_get (GtkWidget        *widget,
                                    selection_data->target, 
                                    &target_info))
            {
-             g_signal_emit_by_name (info->widget, "drag_data_get",
+             g_signal_emit_by_name (info->widget, "drag-data-get",
                                     info->context,
                                     selection_data,
                                     target_info,
@@ -3675,8 +3868,6 @@ gtk_drag_anim_timeout (gpointer data)
   gint x, y;
   gboolean retval;
 
-  GDK_THREADS_ENTER ();
-  
   if (anim->step == anim->n_steps)
     {
       gtk_drag_source_info_destroy (anim->info);
@@ -3706,8 +3897,6 @@ gtk_drag_anim_timeout (gpointer data)
       retval = TRUE;
     }
 
-  GDK_THREADS_LEAVE ();
-
   return retval;
 }
 
@@ -3748,19 +3937,17 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
   gtk_drag_remove_icon (info);
 
   if (info->icon_pixbuf)
-    g_object_unref (info->icon_pixbuf);
-
-  if (!info->proxy_dest)
-    g_signal_emit_by_name (info->widget, "drag_end", 
-                          info->context);
-
-  if (info->widget)
-    g_object_unref (info->widget);
-
+    {
+      g_object_unref (info->icon_pixbuf);
+      info->icon_pixbuf = NULL;
+    }
 
   g_signal_handlers_disconnect_by_func (info->ipc_widget,
                                        gtk_drag_grab_broken_event_cb,
                                        info);
+  g_signal_handlers_disconnect_by_func (info->ipc_widget,
+                                       gtk_drag_grab_notify_cb,
+                                       info);
   g_signal_handlers_disconnect_by_func (info->ipc_widget,
                                        gtk_drag_button_release_cb,
                                        info);
@@ -3774,6 +3961,12 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
                                        gtk_drag_selection_get,
                                        info);
 
+  if (!info->proxy_dest)
+    g_signal_emit_by_name (info->widget, "drag-end", info->context);
+
+  if (info->widget)
+    g_object_unref (info->widget);
+
   gtk_selection_remove_all (info->ipc_widget);
   g_object_set_data (G_OBJECT (info->ipc_widget), I_("gtk-info"), NULL);
   source_widgets = g_slist_remove (source_widgets, info->ipc_widget);
@@ -3787,6 +3980,9 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
   if (info->drop_timeout)
     g_source_remove (info->drop_timeout);
 
+  if (info->update_idle)
+    g_source_remove (info->update_idle);
+
   g_free (info);
 }
 
@@ -3802,8 +3998,6 @@ gtk_drag_update_idle (gpointer data)
   GdkDragAction possible_actions;
   guint32 time;
 
-  GDK_THREADS_ENTER ();
-
   info->update_idle = 0;
     
   if (info->last_event)
@@ -3837,19 +4031,17 @@ gtk_drag_update_idle (gpointer data)
 
     }
 
-  GDK_THREADS_LEAVE ();
-
   return FALSE;
 }
 
 static void
 gtk_drag_add_update_idle (GtkDragSourceInfo *info)
 {
-  /* We use an idle lowerthan GDK_PRIORITY_REDRAW so that exposes
+  /* We use an idle lower than GDK_PRIORITY_REDRAW so that exposes
    * from the last move can catch up before we move again.
    */
   if (!info->update_idle)
-    info->update_idle = g_idle_add_full (GDK_PRIORITY_REDRAW + 5,
+    info->update_idle = gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW + 5,
                                         gtk_drag_update_idle,
                                         info,
                                         NULL);
@@ -3918,13 +4110,12 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time)
   
   info->have_grab = FALSE;
   
-  gdk_display_pointer_ungrab (display, time);
-  gdk_display_keyboard_ungrab (display, time);
-  gtk_grab_remove (info->ipc_widget);
-
   g_signal_handlers_disconnect_by_func (info->ipc_widget,
                                        gtk_drag_grab_broken_event_cb,
                                        info);
+  g_signal_handlers_disconnect_by_func (info->ipc_widget,
+                                       gtk_drag_grab_notify_cb,
+                                       info);
   g_signal_handlers_disconnect_by_func (info->ipc_widget,
                                        gtk_drag_button_release_cb,
                                        info);
@@ -3935,6 +4126,10 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time)
                                        gtk_drag_key_cb,
                                        info);
 
+  gdk_display_pointer_ungrab (display, time);
+  ungrab_dnd_keys (info->ipc_widget, time);
+  gtk_grab_remove (info->ipc_widget);
+
   /* Send on a release pair to the original 
    * widget to convince it to release its grab. We need to
    * call gtk_propagate_event() here, instead of 
@@ -3970,16 +4165,16 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time)
  *************************************************************/
 
 static void
-gtk_drag_cancel (GtkDragSourceInfo *info, guint32 time)
+gtk_drag_cancel (GtkDragSourceInfo *info, GtkDragResult result, guint32 time)
 {
   gtk_drag_end (info, time);
   gdk_drag_abort (info->context, time);
-  gtk_drag_drop_finished (info, FALSE, time);
+  gtk_drag_drop_finished (info, result, time);
 }
 
 /*************************************************************
  * gtk_drag_motion_cb:
- *     "motion_notify_event" callback during drag.
+ *     "motion-notify-event" callback during drag.
  *   arguments:
  *     
  *   results:
@@ -4012,7 +4207,7 @@ gtk_drag_motion_cb (GtkWidget      *widget,
 
 /*************************************************************
  * gtk_drag_key_cb:
- *     "key_press/release_event" callback during drag.
+ *     "key-press/release-event" callback during drag.
  *   arguments:
  *     
  *   results:
@@ -4039,11 +4234,12 @@ gtk_drag_key_cb (GtkWidget         *widget,
       switch (event->keyval)
        {
        case GDK_Escape:
-         gtk_drag_cancel (info, event->time);
+         gtk_drag_cancel (info, GTK_DRAG_RESULT_USER_CANCELLED, event->time);
          return TRUE;
 
        case GDK_space:
        case GDK_Return:
+        case GDK_ISO_Enter:
        case GDK_KP_Enter:
        case GDK_KP_Space:
          gtk_drag_end (info, event->time);
@@ -4113,13 +4309,31 @@ gtk_drag_grab_broken_event_cb (GtkWidget          *widget,
       || event->grab_window == info->ipc_widget->window)
     return FALSE;
 
-  gtk_drag_cancel (info, gtk_get_current_event_time ());
+  gtk_drag_cancel (info, GTK_DRAG_RESULT_GRAB_BROKEN, gtk_get_current_event_time ());
   return TRUE;
 }
 
+static void
+gtk_drag_grab_notify_cb (GtkWidget        *widget,
+                        gboolean          was_grabbed,
+                        gpointer          data)
+{
+  GtkDragSourceInfo *info = (GtkDragSourceInfo *)data;
+
+  if (!was_grabbed)
+    {
+      /* We have to block callbacks to avoid recursion here, because
+        gtk_drag_cancel calls gtk_grab_remove (via gtk_drag_end) */
+      g_signal_handlers_block_by_func (widget, gtk_drag_grab_notify_cb, data);
+      gtk_drag_cancel (info, GTK_DRAG_RESULT_GRAB_BROKEN, gtk_get_current_event_time ());
+      g_signal_handlers_unblock_by_func (widget, gtk_drag_grab_notify_cb, data);
+    }
+}
+
+
 /*************************************************************
  * gtk_drag_button_release_cb:
- *     "button_release_event" callback during drag.
+ *     "button-release-event" callback during drag.
  *   arguments:
  *     
  *   results:
@@ -4142,7 +4356,7 @@ gtk_drag_button_release_cb (GtkWidget      *widget,
     }
   else
     {
-      gtk_drag_cancel (info, event->time);
+      gtk_drag_cancel (info, GTK_DRAG_RESULT_NO_TARGET, event->time);
     }
 
   return TRUE;
@@ -4154,15 +4368,11 @@ gtk_drag_abort_timeout (gpointer data)
   GtkDragSourceInfo *info = data;
   guint32 time = GDK_CURRENT_TIME;
 
-  GDK_THREADS_ENTER ();
-
   if (info->proxy_dest)
     time = info->proxy_dest->proxy_drop_time;
 
   info->drop_timeout = 0;
-  gtk_drag_drop_finished (info, FALSE, time);
-  
-  GDK_THREADS_LEAVE ();
+  gtk_drag_drop_finished (info, GTK_DRAG_RESULT_TIMEOUT_EXPIRED, time);
   
   return FALSE;
 }