]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkdnd.c
Deprecate widget flag: GTK_WIDGET_MAPPED
[~andy/gtk] / gtk / gtkdnd.c
index f316625066a31959956736c9126d2781f53c655b..5e7d5a4b90d684811c8d9fedbab76afb0c946074 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+
 #include "gdkconfig.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"
 #include "gtkimage.h"
 #include "gtkinvisible.h"
 #include "gtkmain.h"
+#include "gtkplug.h"
 #include "gtkstock.h"
 #include "gtkwindow.h"
+#include "gtkintl.h"
+#include "gtkdndcursors.h"
+#include "gtkalias.h"
 
 static GSList *source_widgets = NULL;
 
@@ -65,6 +82,7 @@ struct _GtkDragSourceSite
     GtkImagePixmapData pixmap;
     GtkImagePixbufData pixbuf;
     GtkImageStockData stock;
+    GtkImageIconNameData name;
   } icon_data;
   GdkBitmap *icon_mask;
 
@@ -89,7 +107,7 @@ struct _GtkDragSourceInfo
   gint button;                   /* mouse button starting drag */
 
   GtkDragStatus      status;     /* drag status */
-  GdkEvent          *last_event;  /* motion event waiting for response */
+  GdkEvent          *last_event;  /* pending event */
 
   gint               start_x, start_y; /* Initial position */
   gint               cur_x, cur_y;     /* Current Position */
@@ -100,11 +118,14 @@ struct _GtkDragSourceInfo
   
   GtkDragDestInfo   *proxy_dest;  /* Set if this is a proxy drag */
 
+  guint              update_idle;      /* Idle function to update the drag */
   guint              drop_timeout;     /* Timeout for aborting drop */
   guint              destroy_icon : 1; /* If true, destroy icon_window
                                        */
   guint              have_grab : 1;    /* Do we still have the pointer grab
-                                        */
+                                       */
+  GdkPixbuf         *icon_pixbuf;
+  GdkCursor         *drag_cursors[6];
 };
 
 struct _GtkDragDestSite 
@@ -114,9 +135,10 @@ struct _GtkDragDestSite
   GdkDragAction      actions;
   GdkWindow         *proxy_window;
   GdkDragProtocol    proxy_protocol;
-  gboolean           do_proxy : 1;
-  gboolean           proxy_coords : 1;
-  gboolean           have_drag : 1;
+  guint              do_proxy : 1;
+  guint              proxy_coords : 1;
+  guint              have_drag : 1;
+  guint              track_motion : 1;
 };
   
 struct _GtkDragDestInfo 
@@ -125,9 +147,9 @@ struct _GtkDragDestInfo
   GdkDragContext    *context;     /* Drag context */
   GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */
   GtkSelectionData  *proxy_data;   /* Set while retrieving proxied data */
-  gboolean           dropped : 1;     /* Set after we receive a drop */
+  guint              dropped : 1;     /* Set after we receive a drop */
   guint32            proxy_drop_time; /* Timestamp for proxied drop */
-  gboolean           proxy_drop_wait : 1; /* Set if we are waiting for a
+  guint              proxy_drop_wait : 1; /* Set if we are waiting for a
                                           * status reply before sending
                                           * a proxied drop on.
                                           */
@@ -184,8 +206,11 @@ static void          gtk_drag_get_event_actions (GdkEvent        *event,
                                                 GdkDragAction   *suggested_action,
                                                 GdkDragAction   *possible_actions);
 static GdkCursor *   gtk_drag_get_cursor         (GdkDisplay     *display,
-                                                 GdkDragAction   action);
-static GtkWidget    *gtk_drag_get_ipc_widget     (GdkScreen     *screen);
+                                                 GdkDragAction   action,
+                                                 GtkDragSourceInfo *info);
+static void          gtk_drag_update_cursor      (GtkDragSourceInfo *info);
+static GtkWidget    *gtk_drag_get_ipc_widget            (GtkWidget *widget);
+static GtkWidget    *gtk_drag_get_ipc_widget_for_screen (GdkScreen *screen);
 static void          gtk_drag_release_ipc_widget (GtkWidget      *widget);
 
 static gboolean      gtk_drag_highlight_expose   (GtkWidget      *widget,
@@ -194,7 +219,7 @@ static gboolean      gtk_drag_highlight_expose   (GtkWidget      *widget,
 
 static void     gtk_drag_selection_received     (GtkWidget        *widget,
                                                 GtkSelectionData *selection_data,
-                                                guint32           time,
+                                                guint             time,
                                                 gpointer          data);
 static void     gtk_drag_find_widget            (GtkWidget        *widget,
                                                 GtkDragFindData  *data);
@@ -233,12 +258,13 @@ 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 gint gtk_drag_source_event_cb           (GtkWidget         *widget,
+static gboolean gtk_drag_source_event_cb       (GtkWidget         *widget,
                                                GdkEvent          *event,
                                                gpointer           data);
 static void gtk_drag_source_site_destroy       (gpointer           data);
@@ -247,114 +273,57 @@ static void gtk_drag_selection_get             (GtkWidget         *widget,
                                                guint              sel_info,
                                                guint32            time,
                                                gpointer           data);
-static gint gtk_drag_anim_timeout              (gpointer           data);
+static gboolean gtk_drag_anim_timeout          (gpointer           data);
 static void gtk_drag_remove_icon               (GtkDragSourceInfo *info);
 static void gtk_drag_source_info_destroy       (GtkDragSourceInfo *info);
+static void gtk_drag_add_update_idle           (GtkDragSourceInfo *info);
+
 static void gtk_drag_update                    (GtkDragSourceInfo *info,
                                                GdkScreen         *screen,
                                                gint               x_root,
                                                gint               y_root,
                                                GdkEvent          *event);
-static gint gtk_drag_motion_cb                 (GtkWidget         *widget, 
+static gboolean gtk_drag_motion_cb             (GtkWidget         *widget, 
                                                GdkEventMotion    *event, 
                                                gpointer           data);
-static gint gtk_drag_key_cb                    (GtkWidget         *widget, 
+static gboolean gtk_drag_key_cb                (GtkWidget         *widget, 
                                                GdkEventKey       *event, 
                                                gpointer           data);
-static gint gtk_drag_button_release_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);
-static gint gtk_drag_abort_timeout             (gpointer           data);
+static gboolean gtk_drag_abort_timeout         (gpointer           data);
+
+static void     set_icon_stock_pixbuf          (GdkDragContext    *context,
+                                               const gchar       *stock_id,
+                                               GdkPixbuf         *pixbuf,
+                                               gint               hot_x,
+                                               gint               hot_y,
+                                               gboolean           force_window);
 
 /************************
  * Cursor and Icon data *
  ************************/
 
-#define action_ask_width 16
-#define action_ask_height 16
-static const guchar action_ask_bits[] = {
-  0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x76, 0xf8, 0xb6, 0xf7, 
-  0xd6, 0xec, 0x66, 0xdb, 0x66, 0xdb, 0x96, 0xec, 0x76, 0xf7, 0x76, 0xfb, 
-  0xf6, 0xfc, 0x72, 0xfb, 0x7a, 0xfb, 0xf8, 0xfc, };
-
-#define action_ask_mask_width 16
-#define action_ask_mask_height 16
-static const guchar action_ask_mask_bits[] = {
-  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x8f, 0x07, 0xcf, 0x0f, 
-  0xef, 0x1f, 0xff, 0x3c, 0xff, 0x3c, 0x6f, 0x1f, 0x8f, 0x0f, 0x8f, 0x07, 
-  0x0f, 0x03, 0x8f, 0x07, 0x87, 0x07, 0x07, 0x03, };
-
-#define action_copy_width 16
-#define action_copy_height 16
-static const guchar action_copy_bits[] = {
-  0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x76, 0xfb, 0x76, 0xfb, 
-  0x76, 0xfb, 0x06, 0x83, 0xf6, 0xbf, 0xf6, 0xbf, 0x06, 0x83, 0x76, 0xfb, 
-  0x76, 0xfb, 0x72, 0xfb, 0x7a, 0xf8, 0xf8, 0xff, };
-
-#define action_copy_mask_width 16
-#define action_copy_mask_height 16
-static const guchar action_copy_mask_bits[] = {
-  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x8f, 0x07, 0x8f, 0x07, 
-  0x8f, 0x07, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x8f, 0x07, 
-  0x8f, 0x07, 0x8f, 0x07, 0x87, 0x07, 0x07, 0x00, };
-
-#define action_move_width 16
-#define action_move_height 16
-static const guchar action_move_bits[] = {
-  0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x96, 0xff, 0x26, 0xff, 
-  0xc6, 0xf8, 0xd6, 0xe3, 0x96, 0x8f, 0xb6, 0xbf, 0x36, 0xc3, 0x76, 0xfb, 
-  0x76, 0xfa, 0xf2, 0xfa, 0xfa, 0xf8, 0xf8, 0xff, };
-
-#define action_move_mask_width 16
-#define action_move_mask_height 16
-static const guchar action_move_mask_bits[] = {
-  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x6f, 0x00, 0xff, 0x00, 
-  0xff, 0x07, 0xef, 0x1f, 0xef, 0x7f, 0xcf, 0x7f, 0xcf, 0x3f, 0x8f, 0x07, 
-  0x8f, 0x07, 0x0f, 0x07, 0x07, 0x07, 0x07, 0x00, };
-
-#define action_link_width 16
-#define action_link_height 16
-static const guchar action_link_bits[] = {
-  0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x36, 0xf8, 0xd6, 0xf7, 
-  0x66, 0xec, 0xa6, 0xe8, 0x26, 0xdf, 0xe6, 0xbd, 0xd6, 0xa7, 0xb6, 0xa8, 
-  0xb6, 0xb1, 0x72, 0xdf, 0xfa, 0xe0, 0xf8, 0xff, };
-
-#define action_link_mask_width 16
-#define action_link_mask_height 16
-static const guchar action_link_mask_bits[] = {
-  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xcf, 0x07, 0xef, 0x0f, 
-  0xff, 0x1f, 0x7f, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xef, 0x7f, 0xcf, 0x77, 
-  0xcf, 0x7f, 0x8f, 0x3f, 0x07, 0x1f, 0x07, 0x00, };
-
-#define action_none_width 16
-#define action_none_height 16
-static const guchar action_none_bits[] = {
-  0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0xf6, 0xff, 0xf6, 0xff, 
-  0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 
-  0xf6, 0xff, 0xf2, 0xff, 0xfa, 0xff, 0xf8, 0xff, };
-
-#define action_none_mask_width 16
-#define action_none_mask_height 16
-static const guchar action_none_mask_bits[] = {
-  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00, 
-  0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 
-  0x0f, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x07, 0x00, };
-
-#define CURSOR_WIDTH 16
-#define CURSOR_HEIGHT 16
-
 static struct {
   GdkDragAction action;
-  const guchar *bits;
-  const guchar *mask;
+  const gchar  *name;
+  const guint8 *data;
+  GdkPixbuf    *pixbuf;
   GdkCursor    *cursor;
 } drag_cursors[] = {
-  { GDK_ACTION_DEFAULT, 0 },
-  { GDK_ACTION_ASK,   action_ask_bits,  action_ask_mask_bits,  NULL },
-  { GDK_ACTION_COPY,  action_copy_bits, action_copy_mask_bits, NULL },
-  { GDK_ACTION_MOVE,  action_move_bits, action_move_mask_bits, NULL },
-  { GDK_ACTION_LINK,  action_link_bits, action_link_mask_bits, NULL },
-  { 0              ,  action_none_bits, action_none_mask_bits, NULL },
+  { GDK_ACTION_DEFAULT, NULL },
+  { GDK_ACTION_ASK,   "dnd-ask",  dnd_cursor_ask,  NULL, NULL },
+  { GDK_ACTION_COPY,  "dnd-copy", dnd_cursor_copy, NULL, NULL },
+  { GDK_ACTION_MOVE,  "dnd-move", dnd_cursor_move, NULL, NULL },
+  { GDK_ACTION_LINK,  "dnd-link", dnd_cursor_link, NULL, NULL },
+  { 0              ,  "dnd-none", dnd_cursor_none, NULL, NULL },
 };
 
 static const gint n_drag_cursors = sizeof (drag_cursors) / sizeof (drag_cursors[0]);
@@ -369,7 +338,7 @@ set_can_change_screen (GtkWidget *widget,
 {
   can_change_screen = can_change_screen != FALSE;
   
-  g_object_set_data (G_OBJECT (widget), "gtk-dnd-can-change-screen",
+  g_object_set_data (G_OBJECT (widget), I_("gtk-dnd-can-change-screen"),
                     GUINT_TO_POINTER (can_change_screen));
 }
 
@@ -380,17 +349,8 @@ get_can_change_screen (GtkWidget *widget)
 
 }
 
-/*************************************************************
- * gtk_drag_get_ipc_widget:
- *     Return a invisible, off-screen, override-redirect
- *     widget for IPC.
- *   arguments:
- *     
- *   results:
- *************************************************************/
-
 static GtkWidget *
-gtk_drag_get_ipc_widget (GdkScreen *screen)
+gtk_drag_get_ipc_widget_for_screen (GdkScreen *screen)
 {
   GtkWidget *result;
   GSList *drag_widgets = g_object_get_data (G_OBJECT (screen), 
@@ -402,19 +362,176 @@ gtk_drag_get_ipc_widget (GdkScreen *screen)
       result = drag_widgets->data;
       drag_widgets = drag_widgets->next;
       g_object_set_data (G_OBJECT (screen),
-                        "gtk-dnd-ipc-widgets",
+                        I_("gtk-dnd-ipc-widgets"),
                         drag_widgets);
       g_slist_free_1 (tmp);
     }
   else
     {
-      result = gtk_invisible_new_for_screen (screen);
+      result = gtk_window_new (GTK_WINDOW_POPUP);
+      gtk_window_set_screen (GTK_WINDOW (result), screen);
+      gtk_window_resize (GTK_WINDOW (result), 1, 1);
+      gtk_window_move (GTK_WINDOW (result), -100, -100);
       gtk_widget_show (result);
+    }  
+
+  return result;
+}
+
+static GtkWidget *
+gtk_drag_get_ipc_widget (GtkWidget *widget)
+{
+  GtkWidget *result;
+  GtkWidget *toplevel;
+
+  result = gtk_drag_get_ipc_widget_for_screen (gtk_widget_get_screen (widget));
+  
+  toplevel = gtk_widget_get_toplevel (widget);
+  
+  if (GTK_IS_WINDOW (toplevel))
+    {
+      if (GTK_WINDOW (toplevel)->group)
+       gtk_window_group_add_window (GTK_WINDOW (toplevel)->group, 
+                                     GTK_WINDOW (result));
     }
 
   return result;
 }
 
+
+#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 ()
@@ -426,12 +543,16 @@ gtk_drag_get_ipc_widget (GdkScreen *screen)
 static void
 gtk_drag_release_ipc_widget (GtkWidget *widget)
 {
+  GtkWindow *window = GTK_WINDOW (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);
   g_object_set_data (G_OBJECT (screen),
-                    "gtk-dnd-ipc-widgets",
+                    I_("gtk-dnd-ipc-widgets"),
                     drag_widgets);
 }
 
@@ -568,19 +689,61 @@ gtk_drag_get_event_actions (GdkEvent *event,
       else if (actions & GDK_ACTION_LINK)
        *suggested_action = GDK_ACTION_LINK;
     }
+}
+
+static gboolean
+gtk_drag_can_use_rgba_cursor (GdkDisplay *display, 
+                             gint        width,
+                             gint        height)
+{
+  guint max_width, max_height;
   
-  return;
+  if (!gdk_display_supports_cursor_color (display))
+    return FALSE;
+
+  if (!gdk_display_supports_cursor_alpha (display))
+    return FALSE;
+
+  gdk_display_get_maximal_cursor_size (display, 
+                                       &max_width,
+                                       &max_height);
+  if (width > max_width || height > max_height)
+    {
+       /* can't use rgba cursor (too large) */
+      return FALSE;
+    }
+
+  return TRUE;
 }
 
 static GdkCursor *
-gtk_drag_get_cursor (GdkDisplay   *display,
-                    GdkDragAction action)
+gtk_drag_get_cursor (GdkDisplay        *display,
+                    GdkDragAction      action,
+                    GtkDragSourceInfo *info)
 {
   gint i;
-  
+
+  /* reconstruct the cursors for each new drag (thus !info),
+   * to catch cursor theme changes 
+   */ 
+  if (!info)
+    {
+      for (i = 0 ; i < n_drag_cursors - 1; i++)
+       if (drag_cursors[i].cursor != NULL)
+         {
+           gdk_cursor_unref (drag_cursors[i].cursor);
+           drag_cursors[i].cursor = NULL;
+         }
+    }
   for (i = 0 ; i < n_drag_cursors - 1; i++)
     if (drag_cursors[i].action == action)
       break;
+
+  if (drag_cursors[i].pixbuf == NULL)
+    drag_cursors[i].pixbuf = 
+      gdk_pixbuf_new_from_inline (-1, drag_cursors[i].data, FALSE, NULL);
+
   if (drag_cursors[i].cursor != NULL)
     {
       if (display != gdk_cursor_get_display (drag_cursors[i].cursor))
@@ -589,29 +752,203 @@ gtk_drag_get_cursor (GdkDisplay   *display,
          drag_cursors[i].cursor = NULL;
        }
     }
-
+  
   if (drag_cursors[i].cursor == NULL)
-    {
-      GdkColor bg = { 0, 0xffff, 0xffff, 0xffff };
-      GdkColor fg = { 0, 0x0000, 0x0000, 0x0000 };
-      GdkScreen *screen = gdk_display_get_default_screen (display);
-      GdkWindow *window = gdk_screen_get_root_window (screen);
+    drag_cursors[i].cursor = gdk_cursor_new_from_name (display, drag_cursors[i].name);
+  
+  if (drag_cursors[i].cursor == NULL)
+    drag_cursors[i].cursor = gdk_cursor_new_from_pixbuf (display, drag_cursors[i].pixbuf, 0, 0);
 
-      GdkPixmap *pixmap = 
-       gdk_bitmap_create_from_data (window, (gchar *)drag_cursors[i].bits, CURSOR_WIDTH, CURSOR_HEIGHT);
+  if (info && info->icon_pixbuf) 
+    {
+      gint cursor_width, cursor_height;
+      gint icon_width, icon_height;
+      gint width, height;
+      GdkPixbuf *cursor_pixbuf, *pixbuf;
+      gint hot_x, hot_y;
+      gint icon_x, icon_y, ref_x, ref_y;
 
-      GdkPixmap *mask = 
-       gdk_bitmap_create_from_data (window, (gchar *)drag_cursors[i].mask, CURSOR_WIDTH, CURSOR_HEIGHT);
+      if (info->drag_cursors[i] != NULL)
+        {
+          if (display == gdk_cursor_get_display (info->drag_cursors[i]))
+           return info->drag_cursors[i];
+         
+         gdk_cursor_unref (info->drag_cursors[i]);
+         info->drag_cursors[i] = NULL;
+        }
+
+      icon_x = info->hot_x;
+      icon_y = info->hot_y;
+      icon_width = gdk_pixbuf_get_width (info->icon_pixbuf);
+      icon_height = gdk_pixbuf_get_height (info->icon_pixbuf);
+
+      hot_x = hot_y = 0;
+      cursor_pixbuf = gdk_cursor_get_image (drag_cursors[i].cursor);
+      if (!cursor_pixbuf)
+       cursor_pixbuf = g_object_ref (drag_cursors[i].pixbuf);
+      else
+       {
+         if (gdk_pixbuf_get_option (cursor_pixbuf, "x_hot"))
+           hot_x = atoi (gdk_pixbuf_get_option (cursor_pixbuf, "x_hot"));
+         
+         if (gdk_pixbuf_get_option (cursor_pixbuf, "y_hot"))
+           hot_y = atoi (gdk_pixbuf_get_option (cursor_pixbuf, "y_hot"));
+
+#if 0    
+         /* The code below is an attempt to let cursor themes
+          * determine the attachment of the icon to enable things
+          * like the following:
+          *
+          *    +-----+
+           *    |     |
+           *    |     ||
+           *    +-----+|
+           *        ---+
+           * 
+           * It does not work since Xcursor doesn't allow to attach
+           * any additional information to cursors in a retrievable
+           * way  (there are comments, but no way to get at them
+           * short of searching for the actual cursor file).
+           * If this code ever gets used, the icon_window placement
+           * must be changed to recognize these placement options
+           * as well. Note that this code ignores info->hot_x/y.
+           */ 
+         for (j = 0; j < 10; j++)
+           {
+             const gchar *opt;
+             gchar key[32];
+             gchar **toks;
+             GtkAnchorType icon_anchor;
+
+             g_snprintf (key, 32, "comment%d", j);
+             opt = gdk_pixbuf_get_option (cursor_pixbuf, key);
+             if (opt && g_str_has_prefix ("icon-attach:", opt))
+               {
+                 toks = g_strsplit (opt + strlen ("icon-attach:"), "'", -1);
+                 if (g_strv_length (toks) != 3)
+                   {
+                     g_strfreev (toks);
+                     break;
+                   }
+                 icon_anchor = atoi (toks[0]);
+                 icon_x = atoi (toks[1]);
+                 icon_y = atoi (toks[2]);
+                 
+                 switch (icon_anchor)
+                   {
+                   case GTK_ANCHOR_NORTH:
+                   case GTK_ANCHOR_CENTER:
+                   case GTK_ANCHOR_SOUTH:
+                     icon_x += icon_width / 2;
+                     break;
+                   case GTK_ANCHOR_NORTH_EAST:
+                   case GTK_ANCHOR_EAST:
+                   case GTK_ANCHOR_SOUTH_EAST:
+                     icon_x += icon_width;
+                     break;
+                   default: ;
+                   }
+                 
+                 switch (icon_anchor)
+                   {
+                   case GTK_ANCHOR_WEST:
+                   case GTK_ANCHOR_CENTER:
+                   case GTK_ANCHOR_EAST:
+                     icon_y += icon_height / 2;
+                     break;
+                   case GTK_ANCHOR_SOUTH_WEST:
+                   case GTK_ANCHOR_SOUTH:
+                   case GTK_ANCHOR_SOUTH_EAST:
+                     icon_x += icon_height;
+                     break;
+                   default: ;
+                   }
 
-      drag_cursors[i].cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, 0, 0);
+                 g_strfreev (toks);
+                 break;
+               }
+           }
+#endif
+       }
 
-      g_object_unref (pixmap);
-      g_object_unref (mask);
+      cursor_width = gdk_pixbuf_get_width (cursor_pixbuf);
+      cursor_height = gdk_pixbuf_get_height (cursor_pixbuf);
+      
+      ref_x = MAX (hot_x, icon_x);
+      ref_y = MAX (hot_y, icon_y);
+      width = ref_x + MAX (cursor_width - hot_x, icon_width - icon_x);
+      height = ref_y + MAX (cursor_height - hot_y, icon_height - icon_y);
+         
+      if (gtk_drag_can_use_rgba_cursor (display, width, height))
+       {
+         /* Composite cursor and icon so that both hotspots
+          * end up at (ref_x, ref_y)
+          */
+         pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
+                                  width, height); 
+         
+         gdk_pixbuf_fill (pixbuf, 0xff000000);
+         
+         gdk_pixbuf_composite (info->icon_pixbuf, pixbuf,
+                               ref_x - icon_x, ref_y - icon_y, 
+                               icon_width, icon_height,
+                               ref_x - icon_x, ref_y - icon_y, 
+                               1.0, 1.0, 
+                               GDK_INTERP_BILINEAR, 255);
+         
+         gdk_pixbuf_composite (cursor_pixbuf, pixbuf,
+                               ref_x - hot_x, ref_y - hot_y, 
+                               cursor_width, cursor_height,
+                               ref_x - hot_x, ref_y - hot_y,
+                               1.0, 1.0, 
+                               GDK_INTERP_BILINEAR, 255);
+         
+         info->drag_cursors[i] = 
+           gdk_cursor_new_from_pixbuf (display, pixbuf, ref_x, ref_y);
+         
+         g_object_unref (pixbuf);
+       }
+      
+      g_object_unref (cursor_pixbuf);
+      
+      if (info->drag_cursors[i] != NULL)
+       return info->drag_cursors[i];
     }
-
   return drag_cursors[i].cursor;
 }
 
+static void
+gtk_drag_update_cursor (GtkDragSourceInfo *info)
+{
+  GdkCursor *cursor;
+  gint i;
+
+  if (!info->have_grab)
+    return;
+
+  for (i = 0 ; i < n_drag_cursors - 1; i++)
+    if (info->cursor == drag_cursors[i].cursor ||
+       info->cursor == info->drag_cursors[i])
+      break;
+  
+  if (i == n_drag_cursors)
+    return;
+
+  cursor = gtk_drag_get_cursor (gdk_cursor_get_display (info->cursor), 
+                               drag_cursors[i].action, info);
+  
+  if (cursor != info->cursor)
+    {
+      gdk_pointer_grab (info->ipc_widget->window, FALSE,
+                       GDK_POINTER_MOTION_MASK |
+                       GDK_BUTTON_RELEASE_MASK,
+                       NULL,
+                       cursor, info->grab_time);
+      info->cursor = cursor;
+    }
+}
+
 /********************
  * Destination side *
  ********************/
@@ -639,15 +976,15 @@ gtk_drag_get_data (GtkWidget      *widget,
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
   g_return_if_fail (!context->is_source);
 
-  selection_widget = gtk_drag_get_ipc_widget (gtk_widget_get_screen (widget));
+  selection_widget = gtk_drag_get_ipc_widget (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), "drag-context", context);
+  g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context);
 
   gtk_selection_convert (selection_widget,
                         gdk_drag_get_selection (context),
@@ -718,24 +1055,23 @@ gtk_drag_finish (GdkDragContext *context,
 
   if (success && del)
     {
-      target = gdk_atom_intern ("DELETE", FALSE);
+      target = gdk_atom_intern_static_string ("DELETE");
     }
   else if (context->protocol == GDK_DRAG_PROTO_MOTIF)
     {
-      target = gdk_atom_intern (success ? 
-                                 "XmTRANSFER_SUCCESS" : 
-                                 "XmTRANSFER_FAILURE",
-                               FALSE);
+      target = gdk_atom_intern_static_string (success ? 
+                                             "XmTRANSFER_SUCCESS" : 
+                                             "XmTRANSFER_FAILURE");
     }
 
   if (target != GDK_NONE)
     {
-      GtkWidget *selection_widget = gtk_drag_get_ipc_widget (gdk_drawable_get_screen (context->source_window));
+      GtkWidget *selection_widget = gtk_drag_get_ipc_widget_for_screen (gdk_drawable_get_screen (context->source_window));
 
       g_object_ref (context);
       
-      g_object_set_data (G_OBJECT (selection_widget), "drag-context", context);
-      g_signal_connect (selection_widget, "selection_received",
+      g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context);
+      g_signal_connect (selection_widget, "selection-received",
                        G_CALLBACK (gtk_drag_selection_received),
                        NULL);
       
@@ -766,9 +1102,11 @@ gtk_drag_highlight_expose (GtkWidget      *widget,
 {
   gint x, y, width, height;
   
-  if (GTK_WIDGET_DRAWABLE (widget))
+  if (gtk_widget_is_drawable (widget))
     {
-      if (GTK_WIDGET_NO_WINDOW (widget))
+      cairo_t *cr;
+      
+      if (!gtk_widget_get_has_window (widget))
        {
          x = widget->allocation.x;
          y = widget->allocation.y;
@@ -784,13 +1122,17 @@ 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);
-      
-      gdk_draw_rectangle (widget->window,
-                         widget->style->black_gc,
-                         FALSE,
-                         x, y, width - 1, height - 1);
+
+      cr = gdk_cairo_create (widget->window);
+      cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
+      cairo_set_line_width (cr, 1.0);
+      cairo_rectangle (cr,
+                      x + 0.5, y + 0.5,
+                      width - 1, height - 1);
+      cairo_stroke (cr);
+      cairo_destroy (cr);
     }
 
   return FALSE;
@@ -809,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);
 
@@ -854,6 +1196,8 @@ gtk_drag_dest_set_internal (GtkWidget       *widget,
       g_signal_handlers_disconnect_by_func (widget,
                                            gtk_drag_dest_hierarchy_changed,
                                            old_site);
+
+      site->track_motion = old_site->track_motion;
     }
 
   if (GTK_WIDGET_REALIZED (widget))
@@ -861,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), "gtk-drag-dest",
+  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;
   
@@ -903,6 +1284,7 @@ gtk_drag_dest_set   (GtkWidget            *widget,
   site->actions = actions;
   site->do_proxy = FALSE;
   site->proxy_window = NULL;
+  site->track_motion = FALSE;
 
   gtk_drag_dest_set_internal (widget, site);
 }
@@ -943,6 +1325,7 @@ gtk_drag_dest_set_proxy (GtkWidget      *widget,
   site->do_proxy = TRUE;
   site->proxy_protocol = protocol;
   site->proxy_coords = use_coordinates;
+  site->track_motion = FALSE;
 
   gtk_drag_dest_set_internal (widget, site);
 }
@@ -958,9 +1341,23 @@ gtk_drag_dest_set_proxy (GtkWidget      *widget,
 void 
 gtk_drag_dest_unset (GtkWidget *widget)
 {
+  GtkDragDestSite *old_site;
+
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_object_set_data (G_OBJECT (widget), "gtk-drag-dest", NULL);
+  old_site = g_object_get_data (G_OBJECT (widget),
+                                "gtk-drag-dest");
+  if (old_site)
+    {
+      g_signal_handlers_disconnect_by_func (widget,
+                                            gtk_drag_dest_realized,
+                                            old_site);
+      g_signal_handlers_disconnect_by_func (widget,
+                                            gtk_drag_dest_hierarchy_changed,
+                                            old_site);
+    }
+
+  g_object_set_data (G_OBJECT (widget), I_("gtk-drag-dest"), NULL);
 }
 
 /**
@@ -987,7 +1384,7 @@ gtk_drag_dest_get_target_list (GtkWidget *widget)
 /**
  * gtk_drag_dest_set_target_list:
  * @widget: a #GtkWidget that's a drag destination
- * @target_list: list of droppable targets, or %NULL for none
+ * @target_list: (allow-none): list of droppable targets, or %NULL for none
  * 
  * Sets the target types that this widget can accept from drag-and-drop.
  * The widget must first be made into a drag destination with
@@ -1003,9 +1400,10 @@ gtk_drag_dest_set_target_list (GtkWidget      *widget,
   
   site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
   
-  if (site == NULL)
+  if (!site)
     {
-      g_warning ("can't set a target list on a widget until you've called gtk_drag_dest_set() to make the widget into a drag destination");
+      g_warning ("Can't set a target list on a widget until you've called gtk_drag_dest_set() "
+                 "to make the widget into a drag destination");
       return;
     }
 
@@ -1018,6 +1416,141 @@ gtk_drag_dest_set_target_list (GtkWidget      *widget,
   site->target_list = target_list;
 }
 
+/**
+ * gtk_drag_dest_add_text_targets:
+ * @widget: a #GtkWidget that's a drag destination
+ *
+ * Add the text targets supported by #GtkSelection to
+ * the target list of the drag destination. The targets
+ * are added with @info = 0. If you need another value, 
+ * use gtk_target_list_add_text_targets() and
+ * gtk_drag_dest_set_target_list().
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_drag_dest_add_text_targets (GtkWidget *widget)
+{
+  GtkTargetList *target_list;
+
+  target_list = gtk_drag_dest_get_target_list (widget);
+  if (target_list)
+    gtk_target_list_ref (target_list);
+  else
+    target_list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_text_targets (target_list, 0);
+  gtk_drag_dest_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+}
+
+/**
+ * gtk_drag_dest_add_image_targets:
+ * @widget: a #GtkWidget that's a drag destination
+ *
+ * Add the image targets supported by #GtkSelection to
+ * the target list of the drag destination. The targets
+ * are added with @info = 0. If you need another value, 
+ * use gtk_target_list_add_image_targets() and
+ * gtk_drag_dest_set_target_list().
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_drag_dest_add_image_targets (GtkWidget *widget)
+{
+  GtkTargetList *target_list;
+
+  target_list = gtk_drag_dest_get_target_list (widget);
+  if (target_list)
+    gtk_target_list_ref (target_list);
+  else
+    target_list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_image_targets (target_list, 0, FALSE);
+  gtk_drag_dest_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+}
+
+/**
+ * gtk_drag_dest_add_uri_targets:
+ * @widget: a #GtkWidget that's a drag destination
+ *
+ * Add the URI targets supported by #GtkSelection to
+ * the target list of the drag destination. The targets
+ * are added with @info = 0. If you need another value, 
+ * use gtk_target_list_add_uri_targets() and
+ * gtk_drag_dest_set_target_list().
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_drag_dest_add_uri_targets (GtkWidget *widget)
+{
+  GtkTargetList *target_list;
+
+  target_list = gtk_drag_dest_get_target_list (widget);
+  if (target_list)
+    gtk_target_list_ref (target_list);
+  else
+    target_list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_uri_targets (target_list, 0);
+  gtk_drag_dest_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+}
+
+/**
+ * gtk_drag_dest_set_track_motion:
+ * @widget: a #GtkWidget that's a drag destination
+ * @track_motion: whether to accept all targets
+ * 
+ * Tells the widget to emit ::drag-motion and ::drag-leave
+ * events regardless of the targets and the %GTK_DEST_DEFAULT_MOTION
+ * flag. 
+ *
+ * This may be used when a widget wants to do generic
+ * actions regardless of the targets that the source offers.
+ *
+ * Since: 2.10
+ **/
+void
+gtk_drag_dest_set_track_motion (GtkWidget *widget,
+                               gboolean   track_motion)
+{
+  GtkDragDestSite *site;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
+  
+  g_return_if_fail (site != NULL);
+
+  site->track_motion = track_motion != FALSE;
+}
+
+/**
+ * gtk_drag_dest_get_track_motion:
+ * @widget: a #GtkWidget that's a drag destination
+ * 
+ * Returns whether the widget has been configured to always
+ * emit ::drag-motion signals.
+ * 
+ * Return Value: %TRUE if the widget always emits ::drag-motion events
+ *
+ * Since: 2.10
+ **/
+gboolean
+gtk_drag_dest_get_track_motion (GtkWidget *widget)
+{
+  GtkDragDestSite *site;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
+
+  site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
+
+  if (site)
+    return site->track_motion;
+
+  return FALSE;
+}
 
 /*************************************************************
  * _gtk_drag_dest_handle_event:
@@ -1077,7 +1610,18 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
              }
          }
 
-       gdk_window_get_origin (toplevel->window, &tx, &ty);
+#ifdef GDK_WINDOWING_X11
+       /* Hackaround for: http://bugzilla.gnome.org/show_bug.cgi?id=136112
+        *
+        * Currently gdk_window_get_position doesn't provide reliable
+        * information for embedded windows, so we call the much more
+        * expensive gdk_window_get_origin().
+        */
+       if (GTK_IS_PLUG (toplevel))
+         gdk_window_get_origin (toplevel->window, &tx, &ty);
+       else
+#endif /* GDK_WINDOWING_X11 */
+         gdk_window_get_position (toplevel->window, &tx, &ty);
 
        data.x = event->dnd.x_root - tx;
        data.y = event->dnd.y_root - ty;
@@ -1088,7 +1632,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
        data.callback = (event->type == GDK_DRAG_MOTION) ?
          gtk_drag_dest_motion : gtk_drag_dest_drop;
        data.time = event->dnd.time;
-       
+
        gtk_drag_find_widget (toplevel, &data);
 
        if (info->widget && !data.found)
@@ -1122,7 +1666,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
  * gtk_drag_dest_find_target:
  * @widget: drag destination widget
  * @context: drag context
- * @target_list: list of droppable targets, or %NULL to use
+ * @target_list: (allow-none): list of droppable targets, or %NULL to use
  *    gtk_drag_dest_get_target_list (@widget).
  * 
  * Looks for a match between @context->targets and the
@@ -1167,7 +1711,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;
@@ -1183,7 +1729,7 @@ gtk_drag_dest_find_target (GtkWidget      *widget,
 static void
 gtk_drag_selection_received (GtkWidget        *widget,
                             GtkSelectionData *selection_data,
-                            guint32           time,
+                            guint             time,
                             gpointer          data)
 {
   GdkDragContext *context;
@@ -1207,12 +1753,12 @@ gtk_drag_selection_received (GtkWidget        *widget,
       return;
     }
 
-  if (selection_data->target == gdk_atom_intern ("DELETE", FALSE))
+  if (selection_data->target == gdk_atom_intern_static_string ("DELETE"))
     {
       gtk_drag_finish (context, TRUE, FALSE, time);
     }
-  else if ((selection_data->target == gdk_atom_intern ("XmTRANSFER_SUCCESS", FALSE)) ||
-          (selection_data->target == gdk_atom_intern ("XmTRANSFER_FAILURE", FALSE)))
+  else if ((selection_data->target == gdk_atom_intern_static_string ("XmTRANSFER_SUCCESS")) ||
+          (selection_data->target == gdk_atom_intern_static_string ("XmTRANSFER_FAILURE")))
     {
       /* Do nothing */
     }
@@ -1233,7 +1779,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);
@@ -1242,7 +1788,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);
@@ -1264,7 +1810,7 @@ gtk_drag_selection_received (GtkWidget        *widget,
                                        gtk_drag_selection_received,
                                        data);
   
-  g_object_set_data (G_OBJECT (widget), "drag-context", NULL);
+  g_object_set_data (G_OBJECT (widget), I_("drag-context"), NULL);
   g_object_unref (context);
 
   gtk_drag_release_ipc_widget (widget);
@@ -1298,7 +1844,7 @@ gtk_drag_find_widget (GtkWidget       *widget,
   gint x_offset = 0;
   gint y_offset = 0;
 
-  if (data->found || !GTK_WIDGET_MAPPED (widget) || !GTK_WIDGET_SENSITIVE (widget))
+  if (data->found || !gtk_widget_get_mapped (widget) || !gtk_widget_get_sensitive (widget))
     return;
 
   /* Note that in the following code, we only count the
@@ -1328,7 +1874,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.
@@ -1383,12 +1929,12 @@ 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)
            {
-             if (!new_data.found && GTK_WIDGET_DRAWABLE (tmp_list->data))
+             if (!new_data.found && gtk_widget_is_drawable (tmp_list->data))
                gtk_drag_find_widget (tmp_list->data, &new_data);
              g_object_unref (tmp_list->data);
            }
@@ -1398,7 +1944,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 &&
@@ -1409,7 +1955,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)
@@ -1439,14 +1985,14 @@ gtk_drag_proxy_begin (GtkWidget       *widget,
       dest_info->proxy_source = NULL;
     }
   
-  ipc_widget = gtk_drag_get_ipc_widget (gtk_widget_get_screen (widget));
+  ipc_widget = gtk_drag_get_ipc_widget (widget);
   context = gdk_drag_begin (ipc_widget->window,
                            dest_info->context->targets);
 
   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;
@@ -1460,7 +2006,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);
   
@@ -1533,7 +2079,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);
 }
 
@@ -1543,7 +2089,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);
 }
 
@@ -1592,9 +2138,9 @@ gtk_drag_dest_leave (GtkWidget      *widget,
       if ((site->flags & GTK_DEST_DEFAULT_HIGHLIGHT) && site->have_drag)
        gtk_drag_unhighlight (widget);
 
-      if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag)
-       g_signal_emit_by_name (widget, "drag_leave",
-                              context, time);
+      if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag ||
+         site->track_motion)
+       g_signal_emit_by_name (widget, "drag-leave", context, time);
       
       site->have_drag = FALSE;
     }
@@ -1663,7 +2209,7 @@ gtk_drag_dest_motion (GtkWidget        *widget,
       return TRUE;
     }
 
-  if (site->flags & GTK_DEST_DEFAULT_MOTION)
+  if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
     {
       if (context->suggested_action & site->actions)
        action = context->suggested_action;
@@ -1671,7 +2217,7 @@ gtk_drag_dest_motion (GtkWidget        *widget,
        {
          gint i;
          
-         for (i=0; i<8; i++)
+         for (i = 0; i < 8; i++)
            {
              if ((site->actions & (1 << i)) &&
                  (context->actions & (1 << i)))
@@ -1681,7 +2227,7 @@ gtk_drag_dest_motion (GtkWidget        *widget,
                }
            }
        }
-      
+
       if (action && gtk_drag_dest_find_target (widget, context, NULL))
        {
          if (!site->have_drag)
@@ -1690,17 +2236,18 @@ gtk_drag_dest_motion (GtkWidget      *widget,
              if (site->flags & GTK_DEST_DEFAULT_HIGHLIGHT)
                gtk_drag_highlight (widget);
            }
-         
+
          gdk_drag_status (context, action, time);
        }
       else
        {
          gdk_drag_status (context, 0, time);
-         return TRUE;
+         if (!site->track_motion)
+           return TRUE;
        }
     }
 
-  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;
@@ -1791,17 +2338,17 @@ gtk_drag_dest_drop (GtkWidget        *widget,
       if (site->flags & GTK_DEST_DEFAULT_DROP)
        {
          GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
-      
+
          if (target == GDK_NONE)
            {
              gtk_drag_finish (context, FALSE, FALSE, time);
              return TRUE;
            }
-         else
+         else 
            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;
@@ -1812,24 +2359,16 @@ gtk_drag_dest_drop (GtkWidget        *widget,
  * Source side *
  ***************/
 
-/*************************************************************
- * gtk_drag_begin: Start a drag operation
- *     
- *   arguments:
- *     widget:   Widget from which drag starts
- *     handlers: List of handlers to supply the data for the drag
- *     button:   Button user used to start drag
- *     time:     Time of event starting drag
- *
- *   results:
- *************************************************************/
-
-GdkDragContext *
-gtk_drag_begin (GtkWidget         *widget,
-               GtkTargetList     *target_list,
-               GdkDragAction      actions,
-               gint               button,
-               GdkEvent          *event)
+/* Like GtkDragBegin, but also takes a GtkDragSourceSite,
+ * so that we can set the icon from the source site information
+ */
+static GdkDragContext *
+gtk_drag_begin_internal (GtkWidget         *widget,
+                        GtkDragSourceSite *site,
+                        GtkTargetList     *target_list,
+                        GdkDragAction      actions,
+                        gint               button,
+                        GdkEvent          *event)
 {
   GtkDragSourceInfo *info;
   GList *targets = NULL;
@@ -1838,14 +2377,36 @@ gtk_drag_begin (GtkWidget         *widget,
   GdkDragAction possible_actions, suggested_action;
   GdkDragContext *context;
   GtkWidget *ipc_widget;
-
-  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
-  g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL);
-  g_return_val_if_fail (target_list != NULL, NULL);
-
+  GdkCursor *cursor;
+  ipc_widget = gtk_drag_get_ipc_widget (widget);
+  
+  gtk_drag_get_event_actions (event, button, actions,
+                             &suggested_action, &possible_actions);
+  
+  cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget), 
+                               suggested_action,
+                               NULL);
+  
   if (event)
     time = gdk_event_get_time (event);
 
+  if (gdk_pointer_grab (ipc_widget->window, FALSE,
+                       GDK_POINTER_MOTION_MASK |
+                       GDK_BUTTON_RELEASE_MASK, NULL,
+                       cursor, time) != GDK_GRAB_SUCCESS)
+    {
+      gtk_drag_release_ipc_widget (ipc_widget);
+      return NULL;
+    }
+
+  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
+   */
+  gtk_grab_add (ipc_widget);
+  
   tmp_list = g_list_last (target_list->list);
   while (tmp_list)
     {
@@ -1855,7 +2416,6 @@ gtk_drag_begin (GtkWidget         *widget,
       tmp_list = tmp_list->prev;
     }
 
-  ipc_widget = gtk_drag_get_ipc_widget (gtk_widget_get_screen (widget));
   source_widgets = g_slist_prepend (source_widgets, ipc_widget);
 
   context = gdk_drag_begin (ipc_widget->window, targets);
@@ -1864,29 +2424,24 @@ gtk_drag_begin (GtkWidget         *widget,
   info = gtk_drag_get_source_info (context, TRUE);
   
   info->ipc_widget = ipc_widget;
-  g_object_set_data (G_OBJECT (info->ipc_widget), "gtk-info", info);
+  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;
   info->target_list = target_list;
   gtk_target_list_ref (target_list);
 
   info->possible_actions = actions;
 
-  info->cursor = NULL;
   info->status = GTK_DRAG_STATUS_DRAG;
   info->last_event = NULL;
   info->selections = NULL;
   info->icon_window = NULL;
   info->destroy_icon = FALSE;
 
-  gtk_drag_get_event_actions (event, info->button, actions,
-                             &suggested_action, &possible_actions);
-
-  info->cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget), suggested_action);
-
-  /* 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)
@@ -1901,48 +2456,128 @@ gtk_drag_begin (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
+   * not have set one.
+   */
+  if (!info->icon_window && !info->icon_pixbuf)
+    {
+      if (!site || site->icon_type == GTK_IMAGE_EMPTY)
+       gtk_drag_set_icon_default (context);
+      else
+       switch (site->icon_type)
+         {
+         case GTK_IMAGE_PIXMAP:
+           gtk_drag_set_icon_pixmap (context,
+                                     site->colormap,
+                                     site->icon_data.pixmap.pixmap,
+                                     site->icon_mask,
+                                     -2, -2);
+           break;
+         case GTK_IMAGE_PIXBUF:
+           gtk_drag_set_icon_pixbuf (context,
+                                     site->icon_data.pixbuf.pixbuf,
+                                     -2, -2);
+           break;
+         case GTK_IMAGE_STOCK:
+           gtk_drag_set_icon_stock (context,
+                                    site->icon_data.stock.stock_id,
+                                    -2, -2);
+           break;
+         case GTK_IMAGE_ICON_NAME:
+           gtk_drag_set_icon_name (context,
+                                   site->icon_data.name.icon_name,
+                                   -2, -2);
+           break;
+         case GTK_IMAGE_EMPTY:
+         default:
+           g_assert_not_reached();
+           break;
+         }
+    }
+
+  /* We need to composite the icon into the cursor, if we are
+   * not using an icon window.
+   */
+  if (info->icon_pixbuf)  
+    {
+      cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget), 
+                                   suggested_action,
+                                   info);
   
+      if (cursor != info->cursor)
+        {
+         gdk_pointer_grab (widget->window, FALSE,
+                           GDK_POINTER_MOTION_MASK |
+                           GDK_BUTTON_RELEASE_MASK,
+                           NULL,
+                           cursor, time);
+          info->cursor = cursor;
+        }
+    }
+    
   if (event && event->type == GDK_MOTION_NOTIFY)
     gtk_drag_motion_cb (info->ipc_widget, (GdkEventMotion *)event, info);
+  else
+    gtk_drag_update (info, info->cur_screen, info->cur_x, info->cur_y, event);
 
   info->start_x = info->cur_x;
   info->start_y = info->cur_y;
 
-  g_signal_connect (info->ipc_widget, "button_release_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, "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);
 
-  /* We use a GTK grab here to override any grabs that the widget
-   * we are dragging from might have held
-   */
-  gtk_grab_add (info->ipc_widget);
-  if (gdk_pointer_grab (info->ipc_widget->window, FALSE,
-                       GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
-                       GDK_BUTTON_RELEASE_MASK, NULL,
-                       info->cursor, time) == 0)
-    {
-      if (gdk_keyboard_grab (info->ipc_widget->window, FALSE, time) != 0)
-       {
-         gtk_drag_cancel (info, time);
-         return NULL;
-       }
-    }
-
   info->have_grab = TRUE;
   info->grab_time = time;
 
   return info->context;
 }
 
+/**
+ * gtk_drag_begin:
+ * @widget: the source widget.
+ * @targets: The targets (data formats) in which the
+ *    source can provide the data.
+ * @actions: A bitmask of the allowed drag actions for this drag.
+ * @button: The button the user clicked to start the drag.
+ * @event: The event that triggered the start of the drag.
+ * 
+ * Initiates a drag on the source side. The function
+ * only needs to be used when the application is
+ * starting drags itself, and is not needed when
+ * gtk_drag_source_set() is used.
+ * 
+ * Return value: the context for this drag.
+ **/
+GdkDragContext *
+gtk_drag_begin (GtkWidget         *widget,
+               GtkTargetList     *targets,
+               GdkDragAction      actions,
+               gint               button,
+               GdkEvent          *event)
+{
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+  g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL);
+  g_return_val_if_fail (targets != NULL, NULL);
+
+  return gtk_drag_begin_internal (widget, NULL, targets,
+                                 actions, button, event);
+}
+
 /*************************************************************
  * gtk_drag_source_set:
  *     Register a drop site, and possibly add default behaviors.
@@ -1984,27 +2619,26 @@ 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_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);
       
       g_object_set_data_full (G_OBJECT (widget),
-                             "gtk-site-data"
+                             I_("gtk-site-data")
                              site, gtk_drag_source_site_destroy);
     }
 
   site->start_button_mask = start_button_mask;
 
-  if (targets)
-    site->target_list = gtk_target_list_new (targets, n_targets);
-  else
-    site->target_list = NULL;
+  site->target_list = gtk_target_list_new (targets, n_targets);
 
   site->actions = actions;
-
 }
 
 /*************************************************************
@@ -2029,13 +2663,150 @@ gtk_drag_source_unset (GtkWidget        *widget)
       g_signal_handlers_disconnect_by_func (widget,
                                            gtk_drag_source_event_cb,
                                            site);
-      g_signal_handlers_disconnect_by_func (widget,
-                                           gtk_drag_source_event_cb,
-                                           site);
-      g_object_set_data (G_OBJECT (widget), "gtk-site-data", NULL);
+      g_object_set_data (G_OBJECT (widget), I_("gtk-site-data"), NULL);
     }
 }
 
+/**
+ * gtk_drag_source_get_target_list:
+ * @widget: a #GtkWidget
+ *
+ * Gets the list of targets this widget can provide for
+ * drag-and-drop.
+ *
+ * Return value: the #GtkTargetList, or %NULL if none
+ *
+ * Since: 2.4
+ **/
+GtkTargetList *
+gtk_drag_source_get_target_list (GtkWidget *widget)
+{
+  GtkDragSourceSite *site;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
+
+  return site ? site->target_list : NULL;
+}
+
+/**
+ * gtk_drag_source_set_target_list:
+ * @widget: a #GtkWidget that's a drag source
+ * @target_list: (allow-none): list of draggable targets, or %NULL for none
+ *
+ * Changes the target types that this widget offers for drag-and-drop.
+ * The widget must first be made into a drag source with
+ * gtk_drag_source_set().
+ *
+ * Since: 2.4
+ **/
+void
+gtk_drag_source_set_target_list (GtkWidget     *widget,
+                                 GtkTargetList *target_list)
+{
+  GtkDragSourceSite *site;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
+  if (site == NULL)
+    {
+      g_warning ("gtk_drag_source_set_target_list() requires the widget "
+                "to already be a drag source.");
+      return;
+    }
+
+  if (target_list)
+    gtk_target_list_ref (target_list);
+
+  if (site->target_list)
+    gtk_target_list_unref (site->target_list);
+
+  site->target_list = target_list;
+}
+
+/**
+ * gtk_drag_source_add_text_targets:
+ * @widget: a #GtkWidget that's is a drag source
+ *
+ * Add the text targets supported by #GtkSelection to
+ * the target list of the drag source.  The targets
+ * are added with @info = 0. If you need another value, 
+ * use gtk_target_list_add_text_targets() and
+ * gtk_drag_source_set_target_list().
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_drag_source_add_text_targets (GtkWidget *widget)
+{
+  GtkTargetList *target_list;
+
+  target_list = gtk_drag_source_get_target_list (widget);
+  if (target_list)
+    gtk_target_list_ref (target_list);
+  else
+    target_list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_text_targets (target_list, 0);
+  gtk_drag_source_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+}
+
+/**
+ * gtk_drag_source_add_image_targets:
+ * @widget: a #GtkWidget that's is a drag source
+ *
+ * Add the writable image targets supported by #GtkSelection to
+ * the target list of the drag source. The targets
+ * are added with @info = 0. If you need another value, 
+ * use gtk_target_list_add_image_targets() and
+ * gtk_drag_source_set_target_list().
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_drag_source_add_image_targets (GtkWidget *widget)
+{
+  GtkTargetList *target_list;
+
+  target_list = gtk_drag_source_get_target_list (widget);
+  if (target_list)
+    gtk_target_list_ref (target_list);
+  else
+    target_list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_image_targets (target_list, 0, TRUE);
+  gtk_drag_source_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+}
+
+/**
+ * gtk_drag_source_add_uri_targets:
+ * @widget: a #GtkWidget that's is a drag source
+ *
+ * Add the URI targets supported by #GtkSelection to
+ * the target list of the drag source.  The targets
+ * are added with @info = 0. If you need another value, 
+ * use gtk_target_list_add_uri_targets() and
+ * gtk_drag_source_set_target_list().
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_drag_source_add_uri_targets (GtkWidget *widget)
+{
+  GtkTargetList *target_list;
+
+  target_list = gtk_drag_source_get_target_list (widget);
+  if (target_list)
+    gtk_target_list_ref (target_list);
+  else
+    target_list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_uri_targets (target_list, 0);
+  gtk_drag_source_set_target_list (widget, target_list);
+  gtk_target_list_unref (target_list);
+}
+
 static void
 gtk_drag_source_unset_icon (GtkDragSourceSite *site)
 {
@@ -2053,7 +2824,10 @@ gtk_drag_source_unset_icon (GtkDragSourceSite *site)
       g_object_unref (site->icon_data.pixbuf.pixbuf);
       break;
     case GTK_IMAGE_STOCK:
-      g_free (G_OBJECT (site->icon_data.stock.stock_id));
+      g_free (site->icon_data.stock.stock_id);
+      break;
+    case GTK_IMAGE_ICON_NAME:
+      g_free (site->icon_data.name.icon_name);
       break;
     default:
       g_assert_not_reached();
@@ -2071,10 +2845,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.
  **/
@@ -2162,6 +2936,34 @@ gtk_drag_source_set_icon_stock (GtkWidget   *widget,
   site->icon_data.stock.stock_id = g_strdup (stock_id);
 }
 
+/**
+ * gtk_drag_source_set_icon_name:
+ * @widget: a #GtkWidget
+ * @icon_name: name of icon to use
+ * 
+ * Sets the icon that will be used for drags from a particular source
+ * to a themed icon. See the docs for #GtkIconTheme for more details.
+ *
+ * Since: 2.8
+ **/
+void 
+gtk_drag_source_set_icon_name (GtkWidget   *widget,
+                              const gchar *icon_name)
+{
+  GtkDragSourceSite *site;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (icon_name != NULL);
+
+  site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
+  g_return_if_fail (site != NULL);
+
+  gtk_drag_source_unset_icon (site);
+
+  site->icon_type = GTK_IMAGE_ICON_NAME;
+  site->icon_data.name.icon_name = g_strdup (icon_name);
+}
+
 static void
 gtk_drag_get_icon (GtkDragSourceInfo *info,
                   GtkWidget        **icon_window,
@@ -2188,7 +2990,16 @@ gtk_drag_get_icon (GtkDragSourceInfo *info,
          save_destroy_icon = info->destroy_icon;
 
          info->icon_window = NULL;
-         gtk_drag_set_icon_default (info->context);
+         if (!default_icon_pixmap)
+           set_icon_stock_pixbuf (info->context, 
+                                  GTK_STOCK_DND, NULL, -2, -2, TRUE);
+         else
+           gtk_drag_set_icon_pixmap (info->context, 
+                                     default_icon_colormap, 
+                                     default_icon_pixmap, 
+                                     default_icon_mask,
+                                     default_icon_hot_x,
+                                     default_icon_hot_y);
          info->fallback_icon = info->icon_window;
          
          info->icon_window = save_icon_window;
@@ -2237,8 +3048,8 @@ gtk_drag_update_icon (GtkDragSourceInfo *info)
       gtk_window_move (GTK_WINDOW (icon_window), 
                       info->cur_x - hot_x, 
                       info->cur_y - hot_y);
-      
-      if (GTK_WIDGET_VISIBLE (icon_window))
+
+      if (gtk_widget_get_visible (icon_window))
        gdk_window_raise (icon_window->window);
       else
        gtk_widget_show (icon_window);
@@ -2255,16 +3066,30 @@ gtk_drag_set_icon_window (GdkDragContext *context,
   GtkDragSourceInfo *info;
 
   info = gtk_drag_get_source_info (context, FALSE);
+  if (info == NULL)
+    {
+      if (destroy_on_release)
+       gtk_widget_destroy (widget);
+      return;
+    }
+
   gtk_drag_remove_icon (info);
 
   if (widget)
-    gtk_widget_ref (widget);
+    g_object_ref (widget);  
   
   info->icon_window = widget;
   info->hot_x = hot_x;
   info->hot_y = hot_y;
   info->destroy_icon = destroy_on_release;
+
+  if (widget && info->icon_pixbuf)
+    {
+      g_object_unref (info->icon_pixbuf);
+      info->icon_pixbuf = NULL;
+    }
+
+  gtk_drag_update_cursor (info);
   gtk_drag_update_icon (info);
 }
 
@@ -2278,7 +3103,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 
@@ -2300,20 +3125,19 @@ icon_window_realize (GtkWidget *window,
 {
   GdkPixmap *pixmap;
   GdkPixmap *mask;
-  
+
   gdk_pixbuf_render_pixmap_and_mask_for_colormap (pixbuf,
                                                  gtk_widget_get_colormap (window),
                                                  &pixmap, &mask, 128);
   
   gdk_window_set_back_pixmap (window->window, pixmap, FALSE);
-  
-  if (mask)
-    gtk_widget_shape_combine_mask (window, mask, 0, 0);
-
   g_object_unref (pixmap);
-
+  
   if (mask)
-    g_object_unref (mask);
+    {
+      gtk_widget_shape_combine_mask (window, mask, 0, 0);
+      g_object_unref (mask);
+    }
 }
 
 static void
@@ -2321,28 +3145,31 @@ set_icon_stock_pixbuf (GdkDragContext    *context,
                       const gchar       *stock_id,
                       GdkPixbuf         *pixbuf,
                       gint               hot_x,
-                      gint               hot_y)
+                      gint               hot_y,
+                      gboolean           force_window)
 {
   GtkWidget *window;
   gint width, height;
   GdkScreen *screen;
+  GdkDisplay *display;
 
   g_return_if_fail (context != NULL);
   g_return_if_fail (pixbuf != NULL || stock_id != NULL);
   g_return_if_fail (pixbuf == NULL || stock_id == NULL);
-  
+
   screen = gdk_drawable_get_screen (context->source_window);
 
   /* Push a NULL colormap to guard against gtk_widget_push_colormap() */
   gtk_widget_push_colormap (NULL);
   window = gtk_window_new (GTK_WINDOW_POPUP);
+  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, TRUE);
   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)
     {
       pixbuf = gtk_widget_render_icon (window, stock_id,
@@ -2358,21 +3185,38 @@ set_icon_stock_pixbuf (GdkDragContext    *context,
     }
   else
     g_object_ref (pixbuf);
-  
+
+  display = gdk_drawable_get_display (context->source_window);
   width = gdk_pixbuf_get_width (pixbuf);
-  height = gdk_pixbuf_get_width (pixbuf);
+  height = gdk_pixbuf_get_height (pixbuf);
+
+  if (!force_window &&
+      gtk_drag_can_use_rgba_cursor (display, width + 2, height + 2))
+    {
+      GtkDragSourceInfo *info;
 
-  gtk_widget_set_size_request (window,
-                              gdk_pixbuf_get_width (pixbuf),
-                              gdk_pixbuf_get_height (pixbuf));
+      gtk_widget_destroy (window);
+
+      info = gtk_drag_get_source_info (context, FALSE);
+
+      if (info->icon_pixbuf)
+       g_object_unref (info->icon_pixbuf);
+      info->icon_pixbuf = pixbuf;
+
+      gtk_drag_set_icon_window (context, NULL, hot_x, hot_y, TRUE);
+    }
+  else
+    {
+      gtk_widget_set_size_request (window, width, height);
 
-  g_signal_connect_closure (window, "realize",
-                           g_cclosure_new (G_CALLBACK (icon_window_realize),
-                                           pixbuf,
-                                           (GClosureNotify)g_object_unref),
-                           FALSE);
+      g_signal_connect_closure (window, "realize",
+                               g_cclosure_new (G_CALLBACK (icon_window_realize),
+                                               pixbuf,
+                                               (GClosureNotify)g_object_unref),
+                               FALSE);
                    
-  gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
+      gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
+   }
 }
 
 /**
@@ -2394,8 +3238,8 @@ gtk_drag_set_icon_pixbuf  (GdkDragContext *context,
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
   g_return_if_fail (context->is_source);
   g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
-  
-  set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
+
+  set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y, FALSE);
 }
 
 /**
@@ -2406,7 +3250,7 @@ gtk_drag_set_icon_pixbuf  (GdkDragContext *context,
  * @hot_x: the X offset within the icon of the hotspot.
  * @hot_y: the Y offset within the icon of the hotspot.
  * 
- * Sets the the icon for a given drag from a stock ID.
+ * Sets the icon for a given drag from a stock ID.
  **/
 void 
 gtk_drag_set_icon_stock  (GdkDragContext *context,
@@ -2418,7 +3262,7 @@ gtk_drag_set_icon_stock  (GdkDragContext *context,
   g_return_if_fail (context->is_source);
   g_return_if_fail (stock_id != NULL);
   
-  set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y);
+  set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y, FALSE);
 }
 
 /**
@@ -2427,7 +3271,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: (allow-none): 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.
  * 
@@ -2464,6 +3308,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 (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);
@@ -2482,6 +3327,59 @@ gtk_drag_set_icon_pixmap (GdkDragContext    *context,
   gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
 }
 
+/**
+ * gtk_drag_set_icon_name:
+ * @context: the context for a drag. (This must be called 
+ *            with a context for the source side of a drag)
+ * @icon_name: name of icon to use
+ * @hot_x: the X offset of the hotspot within the icon
+ * @hot_y: the Y offset of the hotspot within the icon
+ * 
+ * Sets the icon for a given drag from a named themed icon. See
+ * the docs for #GtkIconTheme for more details. Note that the
+ * size of the icon depends on the icon theme (the icon is
+ * loaded at the symbolic size #GTK_ICON_SIZE_DND), thus 
+ * @hot_x and @hot_y have to be used with care.
+ *
+ * Since: 2.8
+ **/
+void 
+gtk_drag_set_icon_name (GdkDragContext *context,
+                       const gchar    *icon_name,
+                       gint            hot_x,
+                       gint            hot_y)
+{
+  GdkScreen *screen;
+  GtkSettings *settings;
+  GtkIconTheme *icon_theme;
+  GdkPixbuf *pixbuf;
+  gint width, height, icon_size;
+
+  g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+  g_return_if_fail (context->is_source);
+  g_return_if_fail (icon_name != NULL);
+
+  screen = gdk_drawable_get_screen (context->source_window);
+  g_return_if_fail (screen != NULL);
+
+  settings = gtk_settings_get_for_screen (screen);
+  if (gtk_icon_size_lookup_for_settings (settings,
+                                        GTK_ICON_SIZE_DND,
+                                        &width, &height))
+    icon_size = MAX (width, height);
+  else 
+    icon_size = 32; /* default value for GTK_ICON_SIZE_DND */ 
+
+  icon_theme = gtk_icon_theme_get_for_screen (screen);
+
+  pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
+                                    icon_size, 0, NULL);
+  if (pixbuf)
+    set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y, FALSE);
+  else
+    g_warning ("Cannot load drag icon from icon name %s", icon_name);
+}
+
 /**
  * gtk_drag_set_icon_default:
  * @context: the context for a drag. (This must be called 
@@ -2491,7 +3389,7 @@ gtk_drag_set_icon_pixmap (GdkDragContext    *context,
  * icon.
  **/
 void 
-gtk_drag_set_icon_default (GdkDragContext    *context)
+gtk_drag_set_icon_default (GdkDragContext *context)
 {
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
   g_return_if_fail (context->is_source);
@@ -2517,8 +3415,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,
@@ -2611,31 +3510,25 @@ _gtk_drag_source_handle_event (GtkWidget *widget,
        else if (info->have_grab)
          {
            cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget),
-                                         event->dnd.context->action);
+                                         event->dnd.context->action,
+                                         info);
            if (info->cursor != cursor)
              {
                gdk_pointer_grab (widget->window, FALSE,
                                  GDK_POINTER_MOTION_MASK |
-                                 GDK_POINTER_MOTION_HINT_MASK |
                                  GDK_BUTTON_RELEASE_MASK,
                                  NULL,
                                  cursor, info->grab_time);
                info->cursor = cursor;
              }
            
-           if (info->last_event)
-             {
-               gtk_drag_update (info,
-                                info->cur_screen, info->cur_x, info->cur_y,
-                                info->last_event);
-               info->last_event = NULL;
-             }
+           gtk_drag_add_update_idle (info);
          }
       }
       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 ();
@@ -2689,17 +3582,17 @@ gtk_drag_source_check_selection (GtkDragSourceInfo *info,
     {
       gtk_selection_add_target (info->ipc_widget,
                                selection,
-                               gdk_atom_intern ("XmTRANSFER_SUCCESS", FALSE),
+                               gdk_atom_intern_static_string ("XmTRANSFER_SUCCESS"),
                                TARGET_MOTIF_SUCCESS);
       gtk_selection_add_target (info->ipc_widget,
                                selection,
-                               gdk_atom_intern ("XmTRANSFER_FAILURE", FALSE),
+                               gdk_atom_intern_static_string ("XmTRANSFER_FAILURE"),
                                TARGET_MOTIF_FAILURE);
     }
 
   gtk_selection_add_target (info->ipc_widget,
                            selection,
-                           gdk_atom_intern ("DELETE", FALSE),
+                           gdk_atom_intern_static_string ("DELETE"),
                            TARGET_DELETE);
 }
 
@@ -2715,9 +3608,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)
@@ -2729,6 +3625,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);
@@ -2744,13 +3644,18 @@ gtk_drag_drop_finished (GtkDragSourceInfo *info,
          anim->n_steps = CLAMP (anim->n_steps, ANIM_MIN_STEPS, ANIM_MAX_STEPS);
 
          info->cur_screen = gtk_widget_get_screen (info->widget);
+
+         if (!info->icon_window)
+           set_icon_stock_pixbuf (info->context, NULL, info->icon_pixbuf, 
+                                  0, 0, TRUE);
+
          gtk_drag_update_icon (info);
          
          /* Mark the context as dead, so if the destination decides
           * 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);
        }
     }
 }
@@ -2791,32 +3696,36 @@ gtk_drag_drop (GtkDragSourceInfo *info,
     {
       GtkSelectionData selection_data;
       GList *tmp_list;
-      GdkAtom target = gdk_atom_intern ("application/x-rootwin-drop", FALSE);
+      /* GTK+ traditionally has used application/x-rootwin-drop, but the
+       * XDND spec specifies x-rootwindow-drop.
+       */
+      GdkAtom target1 = gdk_atom_intern_static_string ("application/x-rootwindow-drop");
+      GdkAtom target2 = gdk_atom_intern_static_string ("application/x-rootwin-drop");
       
       tmp_list = info->target_list->list;
       while (tmp_list)
        {
          GtkTargetPair *pair = tmp_list->data;
          
-         if (pair->target == target)
+         if (pair->target == target1 || pair->target == target2)
            {
              selection_data.selection = GDK_NONE;
-             selection_data.target = target;
+             selection_data.target = pair->target;
              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
     {
@@ -2824,7 +3733,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);
     }
@@ -2834,7 +3743,7 @@ gtk_drag_drop (GtkDragSourceInfo *info,
  * Source side callbacks.
  */
 
-static gint
+static gboolean
 gtk_drag_source_event_cb (GtkWidget      *widget,
                          GdkEvent       *event,
                          gpointer        data)
@@ -2876,45 +3785,10 @@ gtk_drag_source_event_cb (GtkWidget      *widget,
          if (gtk_drag_check_threshold (widget, site->x, site->y,
                                        event->motion.x, event->motion.y))
            {
-             GtkDragSourceInfo *info;
-             GdkDragContext *context;
-             
              site->state = 0;
-             context = gtk_drag_begin (widget, site->target_list,
-                                       site->actions, 
-                                       i, event);
-
-             info = gtk_drag_get_source_info (context, FALSE);
-
-             if (!info->icon_window)
-               {
-                 switch (site->icon_type)
-                   {
-                   case GTK_IMAGE_EMPTY:
-                     gtk_drag_set_icon_default (context);
-                     break;
-                   case GTK_IMAGE_PIXMAP:
-                     gtk_drag_set_icon_pixmap (context,
-                                               site->colormap,
-                                               site->icon_data.pixmap.pixmap,
-                                               site->icon_mask,
-                                               -2, -2);
-                     break;
-                   case GTK_IMAGE_PIXBUF:
-                     gtk_drag_set_icon_pixbuf (context,
-                                               site->icon_data.pixbuf.pixbuf,
-                                               -2, -2);
-                     break;
-                   case GTK_IMAGE_STOCK:
-                     gtk_drag_set_icon_stock (context,
-                                              site->icon_data.stock.stock_id,
-                                              -2, -2);
-                     break;
-                   default:
-                     g_assert_not_reached();
-                     break;
-                   }
-               }
+             gtk_drag_begin_internal (widget, site, site->target_list,
+                                      site->actions, 
+                                      i, event);
 
              retval = TRUE;
            }
@@ -2952,22 +3826,22 @@ gtk_drag_selection_get (GtkWidget        *widget,
   guint target_info;
 
   if (!null_atom)
-    null_atom = gdk_atom_intern ("NULL", FALSE);
+    null_atom = gdk_atom_intern_static_string ("NULL");
 
   switch (sel_info)
     {
     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:
@@ -2990,7 +3864,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,
@@ -3001,15 +3875,13 @@ gtk_drag_selection_get (GtkWidget        *widget,
     }
 }
 
-static gint
+static gboolean
 gtk_drag_anim_timeout (gpointer data)
 {
   GtkDragAnim *anim = data;
   gint x, y;
   gboolean retval;
 
-  GDK_THREADS_ENTER ();
-
   if (anim->step == anim->n_steps)
     {
       gtk_drag_source_info_destroy (anim->info);
@@ -3028,8 +3900,7 @@ gtk_drag_anim_timeout (gpointer data)
          GtkWidget *icon_window;
          gint hot_x, hot_y;
          
-         gtk_drag_get_icon (anim->info, &icon_window, &hot_x, &hot_y);
-         
+         gtk_drag_get_icon (anim->info, &icon_window, &hot_x, &hot_y);   
          gtk_window_move (GTK_WINDOW (icon_window), 
                           x - hot_x, 
                           y - hot_y);
@@ -3040,8 +3911,6 @@ gtk_drag_anim_timeout (gpointer data)
       retval = TRUE;
     }
 
-  GDK_THREADS_LEAVE ();
-
   return retval;
 }
 
@@ -3068,16 +3937,31 @@ gtk_drag_remove_icon (GtkDragSourceInfo *info)
 static void
 gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
 {
-  gtk_drag_remove_icon (info);
+  gint i;
 
-  if (!info->proxy_dest)
-    g_signal_emit_by_name (info->widget, "drag_end", 
-                          info->context);
+  for (i = 0; i < n_drag_cursors; i++)
+    {
+      if (info->drag_cursors[i] != NULL)
+        {
+          gdk_cursor_unref (info->drag_cursors[i]);
+          info->drag_cursors[i] = NULL;
+        }
+    }
 
-  if (info->widget)
-    g_object_unref (info->widget);
+  gtk_drag_remove_icon (info);
 
+  if (info->icon_pixbuf)
+    {
+      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);
@@ -3091,8 +3975,14 @@ 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), "gtk-info", NULL);
+  g_object_set_data (G_OBJECT (info->ipc_widget), I_("gtk-info"), NULL);
   source_widgets = g_slist_remove (source_widgets, info->ipc_widget);
   gtk_drag_release_ipc_widget (info->ipc_widget);
 
@@ -3104,20 +3994,84 @@ 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);
 }
 
-/*************************************************************
- * gtk_drag_update:
- *     Function to update the status of the drag when the
- *     cursor moves or the modifier changes
- *   arguments:
- *     info: DragSourceInfo for the drag
- *     x_root, y_root: position of darg
- *     event: The event that triggered this call
- *   results:
- *************************************************************/
+static gboolean
+gtk_drag_update_idle (gpointer data)
+{
+  GtkDragSourceInfo *info = data;
+  GdkWindow *dest_window;
+  GdkDragProtocol protocol;
+  GdkAtom selection;
+
+  GdkDragAction action;
+  GdkDragAction possible_actions;
+  guint32 time;
+
+  info->update_idle = 0;
+    
+  if (info->last_event)
+    {
+      time = gtk_drag_get_event_time (info->last_event);
+      gtk_drag_get_event_actions (info->last_event,
+                                 info->button, 
+                                 info->possible_actions,
+                                 &action, &possible_actions);
+      gtk_drag_update_icon (info);
+      gdk_drag_find_window_for_screen (info->context,
+                                      info->icon_window ? info->icon_window->window : NULL,
+                                      info->cur_screen, info->cur_x, info->cur_y,
+                                      &dest_window, &protocol);
+      
+      if (!gdk_drag_motion (info->context, dest_window, protocol,
+                           info->cur_x, info->cur_y, action, 
+                           possible_actions,
+                           time))
+       {
+         gdk_event_free ((GdkEvent *)info->last_event);
+         info->last_event = NULL;
+       }
+  
+      if (dest_window)
+       g_object_unref (dest_window);
+      
+      selection = gdk_drag_get_selection (info->context);
+      if (selection)
+       gtk_drag_source_check_selection (info, selection, time);
+
+    }
+
+  return FALSE;
+}
+
+static void
+gtk_drag_add_update_idle (GtkDragSourceInfo *info)
+{
+  /* 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 = gdk_threads_add_idle_full (GDK_PRIORITY_REDRAW + 5,
+                                        gtk_drag_update_idle,
+                                        info,
+                                        NULL);
+}
 
+/**
+ * gtk_drag_update:
+ * @info: DragSourceInfo for the drag
+ * @screen: new screen
+ * @x_root: new X position 
+ * @y_root: new y position
+ * @event: event received requiring update
+ * 
+ * Updates the status of the drag; called when the
+ * cursor moves or the modifier changes
+ **/
 static void
 gtk_drag_update (GtkDragSourceInfo *info,
                 GdkScreen         *screen,
@@ -3125,54 +4079,18 @@ gtk_drag_update (GtkDragSourceInfo *info,
                 gint               y_root,
                 GdkEvent          *event)
 {
-  GdkDragAction action;
-  GdkDragAction possible_actions;
-  GdkWindow *dest_window;
-  GdkDragProtocol protocol;
-  GdkAtom selection;
-  guint32 time = gtk_drag_get_event_time (event);
-
-  gtk_drag_get_event_actions (event,
-                             info->button, 
-                             info->possible_actions,
-                             &action, &possible_actions);
   info->cur_screen = screen;
   info->cur_x = x_root;
   info->cur_y = y_root;
-
-  gtk_drag_update_icon (info);
-  gdk_drag_find_window_for_screen (info->context,
-                                  info->icon_window ? info->icon_window->window : NULL,
-                                  screen, x_root, y_root,
-                                  &dest_window, &protocol);
-  
-  if (gdk_drag_motion (info->context, dest_window, protocol,
-                      x_root, y_root, action, 
-                      possible_actions,
-                      time))
+  if (info->last_event)
     {
-      if (info->last_event != event) /* Paranoia, should not happen */
-       {
-         if (info->last_event)
-           gdk_event_free ((GdkEvent *)info->last_event);
-         info->last_event = gdk_event_copy ((GdkEvent *)event);
-       }
-    }
-  else
-    {
-      if (info->last_event)
-       {
-         gdk_event_free ((GdkEvent *)info->last_event);
-         info->last_event = NULL;
-       }
+      gdk_event_free ((GdkEvent *)info->last_event);
+      info->last_event = NULL;
     }
-  
-  if (dest_window)
-    g_object_unref (dest_window);
+  if (event)
+    info->last_event = gdk_event_copy ((GdkEvent *)event);
 
-  selection = gdk_drag_get_selection (info->context);
-  if (selection)
-    gtk_drag_source_check_selection (info, selection, time);
+  gtk_drag_add_update_idle (info);
 }
 
 /*************************************************************
@@ -3192,12 +4110,26 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time)
   GtkWidget *source_widget = info->widget;
   GdkDisplay *display = gtk_widget_get_display (source_widget);
 
+  if (info->update_idle)
+    {
+      g_source_remove (info->update_idle);
+      info->update_idle = 0;
+    }
+  
+  if (info->last_event)
+    {
+      gdk_event_free (info->last_event);
+      info->last_event = NULL;
+    }
+  
   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);
@@ -3208,7 +4140,11 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time)
                                        gtk_drag_key_cb,
                                        info);
 
-  /* Send on a release pair to the the original 
+  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 
    * gtk_widget_event() because widget like GtkList may
@@ -3243,22 +4179,22 @@ 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:
  *************************************************************/
 
-static gint
+static gboolean
 gtk_drag_motion_cb (GtkWidget      *widget, 
                    GdkEventMotion *event, 
                    gpointer        data)
@@ -3285,13 +4221,16 @@ 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:
  *************************************************************/
 
-static gint 
+#define BIG_STEP 20
+#define SMALL_STEP 1
+
+static gboolean
 gtk_drag_key_cb (GtkWidget         *widget, 
                 GdkEventKey       *event, 
                 gpointer           data)
@@ -3299,15 +4238,49 @@ gtk_drag_key_cb (GtkWidget         *widget,
   GtkDragSourceInfo *info = (GtkDragSourceInfo *)data;
   GdkModifierType state;
   GdkWindow *root_window;
-  
+  gint dx, dy;
+
+  dx = dy = 0;
+  state = event->state & gtk_accelerator_get_default_mod_mask ();
+
   if (event->type == GDK_KEY_PRESS)
     {
-      if (event->keyval == GDK_Escape)
+      switch (event->keyval)
        {
-         gtk_drag_cancel (info, event->time);
+       case GDK_Escape:
+         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);
+         gtk_drag_drop (info, event->time);
          return TRUE;
+
+       case GDK_Up:
+       case GDK_KP_Up:
+         dy = (state & GDK_MOD1_MASK) ? -BIG_STEP : -SMALL_STEP;
+         break;
+         
+       case GDK_Down:
+       case GDK_KP_Down:
+         dy = (state & GDK_MOD1_MASK) ? BIG_STEP : SMALL_STEP;
+         break;
+         
+       case GDK_Left:
+       case GDK_KP_Left:
+         dx = (state & GDK_MOD1_MASK) ? -BIG_STEP : -SMALL_STEP;
+         break;
+         
+       case GDK_Right:
+       case GDK_KP_Right:
+         dx = (state & GDK_MOD1_MASK) ? BIG_STEP : SMALL_STEP;
+         break;
        }
+      
     }
 
   /* Now send a "motion" so that the modifier state is updated */
@@ -3318,22 +4291,69 @@ gtk_drag_key_cb (GtkWidget         *widget,
    */
   root_window = gtk_widget_get_root_window (widget);
   gdk_window_get_pointer (root_window, NULL, NULL, &state);
-
   event->state = state;
+
+  if (dx != 0 || dy != 0)
+    {
+      info->cur_x += dx;
+      info->cur_y += dy;
+      gdk_display_warp_pointer (gtk_widget_get_display (widget), 
+                               gtk_widget_get_screen (widget), 
+                               info->cur_x, info->cur_y);
+    }
+
   gtk_drag_update (info, info->cur_screen, info->cur_x, info->cur_y, (GdkEvent *)event);
 
   return TRUE;
 }
 
+static gboolean
+gtk_drag_grab_broken_event_cb (GtkWidget          *widget,
+                              GdkEventGrabBroken *event,
+                              gpointer            data)
+{
+  GtkDragSourceInfo *info = (GtkDragSourceInfo *)data;
+
+  /* Don't cancel if we break the implicit grab from the initial button_press.
+   * Also, don't cancel if we re-grab on the widget or on our IPC window, for
+   * example, when changing the drag cursor.
+   */
+  if (event->implicit
+      || event->grab_window == info->widget->window
+      || event->grab_window == info->ipc_widget->window)
+    return FALSE;
+
+  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:
  *************************************************************/
 
-static gint
+static gboolean
 gtk_drag_button_release_cb (GtkWidget      *widget, 
                            GdkEventButton *event, 
                            gpointer        data)
@@ -3350,27 +4370,23 @@ 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;
 }
 
-static gint
+static gboolean
 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;
 }
@@ -3384,7 +4400,7 @@ gtk_drag_abort_timeout (gpointer data)
  * @current_y: current Y coordinate
  * 
  * Checks to see if a mouse drag starting at (@start_x, @start_y) and ending
- * at (@current_x, @current_y) has passed the GTK+ drag threshhold, and thus
+ * at (@current_x, @current_y) has passed the GTK+ drag threshold, and thus
  * should trigger the beginning of a drag-and-drop operation.
  *
  * Return Value: %TRUE if the drag threshold has been passed.
@@ -3407,3 +4423,6 @@ gtk_drag_check_threshold (GtkWidget *widget,
   return (ABS (current_x - start_x) > drag_threshold ||
          ABS (current_y - start_y) > drag_threshold);
 }
+
+#define __GTK_DND_C__
+#include "gtkaliasdef.c"