X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkdnd.c;h=84e651d668bceb72adc12bb2205ccd4bdaacea57;hb=2dde04140df9cbe7302247b326d41639680b5953;hp=939f5f2cde6afc9950aaaf34a0ec889d10707d2e;hpb=721c3bc10182cacf1a98baddde3c94e59797ddb7;p=~andy%2Fgtk diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 939f5f2cd..84e651d66 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -24,8 +24,9 @@ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ -#include +#include "config.h" +#include #include #include @@ -33,6 +34,12 @@ #include "gdk/gdkkeysyms.h" +#ifdef GDK_WINDOWING_X11 +#include +#include +#include "gdk/x11/gdkx.h" +#endif + #include "gtkdnd.h" #include "gtkiconfactory.h" #include "gtkicontheme.h" @@ -41,10 +48,10 @@ #include "gtkmain.h" #include "gtkplug.h" #include "gtkstock.h" +#include "gtktooltip.h" #include "gtkwindow.h" #include "gtkintl.h" #include "gtkdndcursors.h" -#include "gtkalias.h" static GSList *source_widgets = NULL; @@ -53,7 +60,6 @@ typedef struct _GtkDragSourceInfo GtkDragSourceInfo; typedef struct _GtkDragDestSite GtkDragDestSite; typedef struct _GtkDragDestInfo GtkDragDestInfo; typedef struct _GtkDragAnim GtkDragAnim; -typedef struct _GtkDragFindData GtkDragFindData; typedef enum @@ -73,14 +79,10 @@ struct _GtkDragSourceSite GtkImageType icon_type; union { - GtkImagePixmapData pixmap; GtkImagePixbufData pixbuf; GtkImageStockData stock; GtkImageIconNameData name; } icon_data; - GdkBitmap *icon_mask; - - GdkColormap *colormap; /* Colormap for drag icon */ /* Stored button press information to detect drag beginning */ gint state; @@ -114,40 +116,38 @@ struct _GtkDragSourceInfo 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 - */ + 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 +struct _GtkDragDestSite { GtkDestDefaults flags; GtkTargetList *target_list; GdkDragAction actions; GdkWindow *proxy_window; GdkDragProtocol proxy_protocol; - guint do_proxy : 1; + guint do_proxy : 1; guint proxy_coords : 1; - guint have_drag : 1; + guint have_drag : 1; guint track_motion : 1; }; - -struct _GtkDragDestInfo + +struct _GtkDragDestInfo { - GtkWidget *widget; /* Widget in which drag is in */ - GdkDragContext *context; /* Drag context */ - GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */ - GtkSelectionData *proxy_data; /* Set while retrieving proxied data */ - guint dropped : 1; /* Set after we receive a drop */ - guint32 proxy_drop_time; /* Timestamp for proxied drop */ + GtkWidget *widget; /* Widget in which drag is in */ + GdkDragContext *context; /* Drag context */ + GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */ + GtkSelectionData *proxy_data; /* Set while retrieving proxied data */ + guint32 proxy_drop_time; /* Timestamp for proxied drop */ guint proxy_drop_wait : 1; /* Set if we are waiting for a - * status reply before sending - * a proxied drop on. - */ - gint drop_x, drop_y; /* Position of drop */ + * status reply before sending + * a proxied drop on. + */ + guint dropped : 1; /* Set after we receive a drop */ + gint drop_x, drop_y; /* Position of drop */ }; #define DROP_ABORT_TIME 300000 @@ -164,18 +164,11 @@ struct _GtkDragAnim gint n_steps; }; -struct _GtkDragFindData -{ - gint x; - gint y; - GdkDragContext *context; - GtkDragDestInfo *info; - gboolean found; - gboolean toplevel; - gboolean (*callback) (GtkWidget *widget, GdkDragContext *context, - gint x, gint y, guint32 time); - guint32 time; -}; +typedef gboolean (* GtkDragDestCallback) (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint32 time); /* Enumeration for some targets we handle internally */ @@ -185,14 +178,6 @@ enum { TARGET_DELETE }; -/* Drag icons */ - -static GdkPixmap *default_icon_pixmap = NULL; -static GdkPixmap *default_icon_mask = NULL; -static GdkColormap *default_icon_colormap = NULL; -static gint default_icon_hot_x; -static gint default_icon_hot_y; - /* Forward declarations */ static void gtk_drag_get_event_actions (GdkEvent *event, gint button, @@ -207,16 +192,17 @@ 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, - GdkEventExpose *event, - gpointer data); - static void gtk_drag_selection_received (GtkWidget *widget, GtkSelectionData *selection_data, guint time, gpointer data); -static void gtk_drag_find_widget (GtkWidget *widget, - GtkDragFindData *data); +static gboolean gtk_drag_find_widget (GtkWidget *widget, + GdkDragContext *context, + GtkDragDestInfo *info, + gint x, + gint y, + guint32 time, + GtkDragDestCallback callback); static void gtk_drag_proxy_begin (GtkWidget *widget, GtkDragDestInfo *dest_info, guint32 time); @@ -252,9 +238,10 @@ static void gtk_drag_source_release_selections (GtkDragSourceInfo *info, static void gtk_drag_drop (GtkDragSourceInfo *info, guint32 time); static void gtk_drag_drop_finished (GtkDragSourceInfo *info, - gboolean success, + GtkDragResult result, guint time); static void gtk_drag_cancel (GtkDragSourceInfo *info, + GtkDragResult result, guint32 time); static gboolean gtk_drag_source_event_cb (GtkWidget *widget, @@ -383,14 +370,159 @@ gtk_drag_get_ipc_widget (GtkWidget *widget) if (GTK_IS_WINDOW (toplevel)) { - if (GTK_WINDOW (toplevel)->group) - gtk_window_group_add_window (GTK_WINDOW (toplevel)->group, + if (gtk_window_has_group (GTK_WINDOW (toplevel))) + gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), GTK_WINDOW (result)); } return result; } +/* FIXME: modifying the XEvent window as in root_key_filter() isn't + * going to work with XGE/XI2, since the actual event to handle would + * be allocated/freed before GDK gets to translate the event. + * Active grabs on the keyboard are used instead at the moment... + */ +#if defined (GDK_WINDOWING_X11) && !defined (XINPUT_2) + +/* + * 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, + GdkDevice *device, + guint32 time) +{ + guint i; + GdkWindow *window, *root; + gint keycode; + + window = gtk_widget_get_window (widget); + 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, + GdkDevice *device, + guint32 time) +{ + guint i; + GdkWindow *window, *root; + gint keycode; + + window = gtk_widget_get_window (widget); + 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 /* GDK_WINDOWING_X11 && !XINPUT_2 */ + +static void +grab_dnd_keys (GtkWidget *widget, + GdkDevice *device, + guint32 time) +{ + gdk_device_grab (device, + gtk_widget_get_window (widget), + GDK_OWNERSHIP_APPLICATION, FALSE, + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, + NULL, time); +} + +static void +ungrab_dnd_keys (GtkWidget *widget, + GdkDevice *device, + guint32 time) +{ + gdk_device_ungrab (device, time); +} + +#endif /* GDK_WINDOWING_X11 */ + /*************************************************************** * gtk_drag_release_ipc_widget: @@ -405,10 +537,23 @@ gtk_drag_release_ipc_widget (GtkWidget *widget) { GtkWindow *window = GTK_WINDOW (widget); GdkScreen *screen = gtk_widget_get_screen (widget); + GdkDragContext *context = g_object_get_data (G_OBJECT (widget), "drag-context"); GSList *drag_widgets = g_object_get_data (G_OBJECT (screen), "gtk-dnd-ipc-widgets"); - if (window->group) - gtk_window_group_remove_window (window->group, window); + GdkDevice *pointer, *keyboard; + + if (context) + { + pointer = gdk_drag_context_get_device (context); + keyboard = gdk_device_get_associated_device (pointer); + + if (keyboard) + ungrab_dnd_keys (widget, keyboard, GDK_CURRENT_TIME); + } + + if (gtk_window_has_group (window)) + gtk_window_group_remove_window (gtk_window_get_group (window), + window); drag_widgets = g_slist_prepend (drag_widgets, widget); g_object_set_data (G_OBJECT (screen), I_("gtk-dnd-ipc-widgets"), @@ -799,11 +944,14 @@ gtk_drag_update_cursor (GtkDragSourceInfo *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); + GdkDevice *pointer; + + pointer = gdk_drag_context_get_device (info->context); + gdk_device_grab (pointer, + gtk_widget_get_window (info->ipc_widget), + GDK_OWNERSHIP_APPLICATION, FALSE, + GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, + cursor, info->grab_time); info->cursor = cursor; } } @@ -840,7 +988,7 @@ gtk_drag_get_data (GtkWidget *widget, g_object_ref (context); g_object_ref (widget); - g_signal_connect (selection_widget, "selection_received", + g_signal_connect (selection_widget, "selection-received", G_CALLBACK (gtk_drag_selection_received), widget); g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context); @@ -852,17 +1000,16 @@ gtk_drag_get_data (GtkWidget *widget, } -/************************************************************* +/** * gtk_drag_get_source_widget: - * Get the widget the was the source of this drag, if - * the drag originated from this application. - * arguments: - * context: The drag context for this drag - * results: - * The source widget, or NULL if the drag originated from - * a different application. - *************************************************************/ - + * @context: a (destination side) drag context + * + * Determines the source widget for a drag. + * + * Return value: (transfer none): if the drag is occurring + * within a single application, a pointer to the source widget. + * Otherwise, %NULL. + */ GtkWidget * gtk_drag_get_source_widget (GdkDragContext *context) { @@ -875,8 +1022,8 @@ gtk_drag_get_source_widget (GdkDragContext *context) while (tmp_list) { GtkWidget *ipc_widget = tmp_list->data; - - if (ipc_widget->window == context->source_window) + + if (gtk_widget_get_window (ipc_widget) == context->source_window) { GtkDragSourceInfo *info; info = g_object_get_data (G_OBJECT (ipc_widget), "gtk-info"); @@ -925,12 +1072,12 @@ gtk_drag_finish (GdkDragContext *context, if (target != GDK_NONE) { - GtkWidget *selection_widget = gtk_drag_get_ipc_widget_for_screen (gdk_drawable_get_screen (context->source_window)); + GtkWidget *selection_widget = gtk_drag_get_ipc_widget_for_screen (gdk_window_get_screen (context->source_window)); g_object_ref (context); g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context); - g_signal_connect (selection_widget, "selection_received", + g_signal_connect (selection_widget, "selection-received", G_CALLBACK (gtk_drag_selection_received), NULL); @@ -945,7 +1092,7 @@ gtk_drag_finish (GdkDragContext *context, } /************************************************************* - * gtk_drag_highlight_expose: + * gtk_drag_highlight_draw: * Callback for expose_event for highlighted widgets. * arguments: * widget: @@ -955,44 +1102,24 @@ gtk_drag_finish (GdkDragContext *context, *************************************************************/ static gboolean -gtk_drag_highlight_expose (GtkWidget *widget, - GdkEventExpose *event, - gpointer data) +gtk_drag_highlight_draw (GtkWidget *widget, + cairo_t *cr, + gpointer data) { - gint x, y, width, height; - - if (GTK_WIDGET_DRAWABLE (widget)) - { - cairo_t *cr; - - if (GTK_WIDGET_NO_WINDOW (widget)) - { - x = widget->allocation.x; - y = widget->allocation.y; - width = widget->allocation.width; - height = widget->allocation.height; - } - else - { - x = 0; - y = 0; - gdk_drawable_get_size (widget->window, &width, &height); - } - - gtk_paint_shadow (widget->style, widget->window, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - NULL, widget, "dnd", - x, y, width, height); - - 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); - } + int width = gtk_widget_get_allocated_width (widget); + int height = gtk_widget_get_allocated_height (widget); + + gtk_paint_shadow (gtk_widget_get_style (widget), cr, + GTK_STATE_NORMAL, GTK_SHADOW_OUT, + widget, "dnd", + 0, 0, width, height); + + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */ + cairo_set_line_width (cr, 1.0); + cairo_rectangle (cr, + 0.5, 0.5, + width - 1, height - 1); + cairo_stroke (cr); return FALSE; } @@ -1010,8 +1137,8 @@ gtk_drag_highlight (GtkWidget *widget) { g_return_if_fail (GTK_IS_WIDGET (widget)); - g_signal_connect_after (widget, "expose_event", - G_CALLBACK (gtk_drag_highlight_expose), + g_signal_connect_after (widget, "draw", + G_CALLBACK (gtk_drag_highlight_draw), NULL); gtk_widget_queue_draw (widget); @@ -1031,7 +1158,7 @@ gtk_drag_unhighlight (GtkWidget *widget) g_return_if_fail (GTK_IS_WIDGET (widget)); g_signal_handlers_disconnect_by_func (widget, - gtk_drag_highlight_expose, + gtk_drag_highlight_draw, NULL); gtk_widget_queue_draw (widget); @@ -1059,43 +1186,81 @@ gtk_drag_dest_set_internal (GtkWidget *widget, site->track_motion = old_site->track_motion; } - if (GTK_WIDGET_REALIZED (widget)) + if (gtk_widget_get_realized (widget)) gtk_drag_dest_realized (widget); g_signal_connect (widget, "realize", G_CALLBACK (gtk_drag_dest_realized), site); - g_signal_connect (widget, "hierarchy_changed", + g_signal_connect (widget, "hierarchy-changed", G_CALLBACK (gtk_drag_dest_hierarchy_changed), site); g_object_set_data_full (G_OBJECT (widget), I_("gtk-drag-dest"), site, gtk_drag_dest_site_destroy); } - -/************************************************************* +/** * gtk_drag_dest_set: - * Register a drop site, and possibly add default behaviors. - * arguments: - * widget: - * flags: Which types of default drag behavior to use - * targets: Table of targets that can be accepted - * n_targets: Number of of entries in targets - * actions: - * results: - *************************************************************/ - -void -gtk_drag_dest_set (GtkWidget *widget, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) + * @widget: a #GtkWidget + * @flags: which types of default drag behavior to use + * @targets: (allow-none) (array length=n_targets): a pointer to an array of #GtkTargetEntrys + * indicating the drop types that this @widget will accept, or %NULL. + * 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; g_return_if_fail (GTK_IS_WIDGET (widget)); - site = g_new (GtkDragDestSite, 1); + site = g_slice_new0 (GtkDragDestSite); site->flags = flags; site->have_drag = FALSE; @@ -1135,7 +1300,7 @@ gtk_drag_dest_set_proxy (GtkWidget *widget, g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (!proxy_window || GDK_IS_WINDOW (proxy_window)); - site = g_new (GtkDragDestSite, 1); + site = g_slice_new (GtkDragDestSite); site->flags = 0; site->have_drag = FALSE; @@ -1163,8 +1328,22 @@ 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)); + 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); } @@ -1192,7 +1371,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 @@ -1402,8 +1581,9 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, case GDK_DRAG_MOTION: case GDK_DROP_START: { - GtkDragFindData data; + GdkWindow *window; gint tx, ty; + gboolean found; if (event->type == GDK_DROP_START) { @@ -1418,6 +1598,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, } } + window = gtk_widget_get_window (toplevel); + #ifdef GDK_WINDOWING_X11 /* Hackaround for: http://bugzilla.gnome.org/show_bug.cgi?id=136112 * @@ -1426,24 +1608,22 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, * expensive gdk_window_get_origin(). */ if (GTK_IS_PLUG (toplevel)) - gdk_window_get_origin (toplevel->window, &tx, &ty); + gdk_window_get_origin (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; - data.context = context; - data.info = info; - data.found = FALSE; - data.toplevel = TRUE; - 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); + gdk_window_get_position (window, &tx, &ty); - if (info->widget && !data.found) + found = gtk_drag_find_widget (toplevel, + context, + info, + event->dnd.x_root - tx, + event->dnd.y_root - ty, + event->dnd.time, + (event->type == GDK_DRAG_MOTION) ? + gtk_drag_dest_motion : + gtk_drag_dest_drop); + + if (info->widget && !found) { gtk_drag_dest_leave (info->widget, context, event->dnd.time); info->widget = NULL; @@ -1453,13 +1633,13 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, */ if (event->type == GDK_DRAG_MOTION) { - if (!data.found) + if (!found) gdk_drag_status (context, 0, event->dnd.time); } else if (event->type == GDK_DROP_START && !info->proxy_source) { - gdk_drop_reply (context, data.found, event->dnd.time); - if ((context->protocol == GDK_DRAG_PROTO_MOTIF) && !data.found) + gdk_drop_reply (context, found, event->dnd.time); + if ((context->protocol == GDK_DRAG_PROTO_MOTIF) && !found) gtk_drag_finish (context, FALSE, FALSE, event->dnd.time); } } @@ -1474,9 +1654,9 @@ _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 * @dest_target_list, returning the first matching target, otherwise * returning %GDK_NONE. @dest_target_list should usually be the return @@ -1484,7 +1664,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, * have different valid targets for different parts of the widget; in * that case, they will have to implement a drag_motion handler that * passes the correct target list to this function. - * + * * Return value: first target that the source offers and the dest can accept, or %GDK_NONE **/ GdkAtom @@ -1519,7 +1699,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; @@ -1585,7 +1767,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); @@ -1594,7 +1776,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); @@ -1622,156 +1804,105 @@ gtk_drag_selection_received (GtkWidget *widget, gtk_drag_release_ipc_widget (widget); } -static void -prepend_and_ref_widget (GtkWidget *widget, - gpointer data) -{ - GSList **slist_p = data; - - *slist_p = g_slist_prepend (*slist_p, g_object_ref (widget)); -} - /************************************************************* * gtk_drag_find_widget: - * Recursive callback used to locate widgets for + * Function used to locate widgets for * DRAG_MOTION and DROP_START events. - * arguments: - * - * results: *************************************************************/ -static void -gtk_drag_find_widget (GtkWidget *widget, - GtkDragFindData *data) +static gboolean +gtk_drag_find_widget (GtkWidget *widget, + GdkDragContext *context, + GtkDragDestInfo *info, + gint x, + gint y, + guint32 time, + GtkDragDestCallback callback) { - GtkAllocation new_allocation; - gint allocation_to_window_x = 0; - gint allocation_to_window_y = 0; - gint x_offset = 0; - gint y_offset = 0; + if (!gtk_widget_get_mapped (widget) || + !gtk_widget_get_sensitive (widget)) + return FALSE; - if (data->found || !GTK_WIDGET_MAPPED (widget) || !GTK_WIDGET_SENSITIVE (widget)) - return; + /* Get the widget at the pointer coordinates and travel up + * the widget hierarchy from there. + */ + widget = _gtk_widget_find_at_coords (gtk_widget_get_window (widget), + x, y, &x, &y); + if (!widget) + return FALSE; - /* Note that in the following code, we only count the - * position as being inside a WINDOW widget if it is inside - * widget->window; points that are outside of widget->window - * but within the allocation are not counted. This is consistent - * with the way we highlight drag targets. - * - * data->x,y are relative to widget->parent->window (if - * widget is not a toplevel, widget->window otherwise). - * We compute the allocation of widget in the same coordinates, - * clipping to widget->window, and all intermediate - * windows. If data->x,y is inside that, then we translate - * our coordinates to be relative to widget->window and - * recurse. - */ - new_allocation = widget->allocation; - - if (widget->parent) + while (widget) { - gint tx, ty; - GdkWindow *window = widget->window; - - /* Compute the offset from allocation-relative to - * window-relative coordinates. - */ - allocation_to_window_x = widget->allocation.x; - allocation_to_window_y = widget->allocation.y; - - if (!GTK_WIDGET_NO_WINDOW (widget)) - { - /* The allocation is relative to the parent window for - * window widgets, not to widget->window. - */ - gdk_window_get_position (window, &tx, &ty); - - allocation_to_window_x -= tx; - allocation_to_window_y -= ty; - } + GtkWidget *parent; + GList *hierarchy = NULL; + gboolean found = FALSE; - new_allocation.x = 0 + allocation_to_window_x; - new_allocation.y = 0 + allocation_to_window_y; - - while (window && window != widget->parent->window) - { - GdkRectangle window_rect = { 0, 0, 0, 0 }; - - gdk_drawable_get_size (window, &window_rect.width, &window_rect.height); - - gdk_rectangle_intersect (&new_allocation, &window_rect, &new_allocation); - - gdk_window_get_position (window, &tx, &ty); - new_allocation.x += tx; - x_offset += tx; - new_allocation.y += ty; - y_offset += ty; - - window = gdk_window_get_parent (window); - } + if (!gtk_widget_get_mapped (widget) || + !gtk_widget_get_sensitive (widget)) + return FALSE; - if (!window) /* Window and widget heirarchies didn't match. */ - return; - } - - if (data->toplevel || - ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) && - (data->x < new_allocation.x + new_allocation.width) && - (data->y < new_allocation.y + new_allocation.height))) - { - /* First, check if the drag is in a valid drop site in - * one of our children + /* need to reference the entire hierarchy temporarily in case the + * ::drag-motion/::drag-drop callbacks change the widget hierarchy. */ - if (GTK_IS_CONTAINER (widget)) - { - GtkDragFindData new_data = *data; - GSList *children = NULL; - GSList *tmp_list; - - new_data.x -= x_offset; - new_data.y -= y_offset; - new_data.found = FALSE; - new_data.toplevel = FALSE; - - /* need to reference children temporarily in case the - * ::drag_motion/::drag_drop callbacks change the widget heirarchy. - */ - 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)) - gtk_drag_find_widget (tmp_list->data, &new_data); - g_object_unref (tmp_list->data); - } - g_slist_free (children); - - data->found = new_data.found; - } + for (parent = widget; + parent; + parent = gtk_widget_get_parent (parent)) + { + hierarchy = g_list_prepend (hierarchy, g_object_ref (parent)); + } - /* If not, and this widget is registered as a drop site, check to - * emit "drag_motion" to check if we are actually in - * a drop site. + /* If the current widget is registered as a drop site, check to + * emit "drag-motion" to check if we are actually in a drop + * site. */ - if (!data->found && - g_object_get_data (G_OBJECT (widget), "gtk-drag-dest")) + if (g_object_get_data (G_OBJECT (widget), "gtk-drag-dest")) { - data->found = data->callback (widget, - data->context, - 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 (data->found) + found = callback (widget, context, x, y, time); + + /* If so, send a "drag-leave" to the last widget */ + if (found) { - if (data->info->widget && data->info->widget != widget) + if (info->widget && info->widget != widget) { - gtk_drag_dest_leave (data->info->widget, data->context, data->time); + gtk_drag_dest_leave (info->widget, context, time); } - data->info->widget = widget; + + info->widget = widget; } } + + if (!found) + { + /* Get the parent before unreffing the hierarchy because + * invoking the callback might have destroyed the widget + */ + parent = gtk_widget_get_parent (widget); + + /* The parent might be going away when unreffing the + * hierarchy, so also protect againt that + */ + if (parent) + g_object_add_weak_pointer (G_OBJECT (parent), (gpointer *) &parent); + } + + g_list_foreach (hierarchy, (GFunc) g_object_unref, NULL); + g_list_free (hierarchy); + + if (found) + return TRUE; + + if (parent) + g_object_remove_weak_pointer (G_OBJECT (parent), (gpointer *) &parent); + else + return FALSE; + + if (!gtk_widget_translate_coordinates (widget, parent, x, y, &x, &y)) + return FALSE; + + widget = parent; } + + return FALSE; } static void @@ -1792,13 +1923,13 @@ gtk_drag_proxy_begin (GtkWidget *widget, } ipc_widget = gtk_drag_get_ipc_widget (widget); - context = gdk_drag_begin (ipc_widget->window, + context = gdk_drag_begin (gtk_widget_get_window (ipc_widget), 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; @@ -1812,7 +1943,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); @@ -1822,9 +1953,7 @@ gtk_drag_proxy_begin (GtkWidget *widget, static void gtk_drag_dest_info_destroy (gpointer data) { - GtkDragDestInfo *info = data; - - g_free (info); + g_slice_free (GtkDragDestInfo, data); } static GtkDragDestInfo * @@ -1839,15 +1968,10 @@ gtk_drag_get_dest_info (GdkDragContext *context, info = g_object_get_qdata (G_OBJECT (context), info_quark); if (!info && create) { - info = g_new (GtkDragDestInfo, 1); - info->widget = NULL; + info = g_slice_new0 (GtkDragDestInfo); info->context = context; - info->proxy_source = NULL; - info->proxy_data = NULL; - info->dropped = FALSE; - info->proxy_drop_wait = FALSE; g_object_set_qdata_full (G_OBJECT (context), info_quark, - info, gtk_drag_dest_info_destroy); + info, gtk_drag_dest_info_destroy); } return info; @@ -1885,8 +2009,8 @@ gtk_drag_dest_realized (GtkWidget *widget) { GtkWidget *toplevel = gtk_widget_get_toplevel (widget); - if (GTK_WIDGET_TOPLEVEL (toplevel)) - gdk_window_register_dnd (toplevel->window); + if (gtk_widget_is_toplevel (toplevel)) + gdk_window_register_dnd (gtk_widget_get_window (toplevel)); } static void @@ -1895,8 +2019,8 @@ gtk_drag_dest_hierarchy_changed (GtkWidget *widget, { GtkWidget *toplevel = gtk_widget_get_toplevel (widget); - if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_WIDGET_REALIZED (toplevel)) - gdk_window_register_dnd (toplevel->window); + if (gtk_widget_is_toplevel (toplevel) && gtk_widget_get_realized (toplevel)) + gdk_window_register_dnd (gtk_widget_get_window (toplevel)); } static void @@ -1910,7 +2034,7 @@ gtk_drag_dest_site_destroy (gpointer data) if (site->target_list) gtk_target_list_unref (site->target_list); - g_free (site); + g_slice_free (GtkDragDestSite, site); } /* @@ -1946,7 +2070,7 @@ gtk_drag_dest_leave (GtkWidget *widget, if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag || site->track_motion) - g_signal_emit_by_name (widget, "drag_leave", context, time); + g_signal_emit_by_name (widget, "drag-leave", context, time); site->have_drag = FALSE; } @@ -1989,7 +2113,7 @@ gtk_drag_dest_motion (GtkWidget *widget, { gdk_drag_find_window_for_screen (info->proxy_source->context, NULL, - gdk_drawable_get_screen (current_event->dnd.window), + gdk_window_get_screen (current_event->dnd.window), current_event->dnd.x_root, current_event->dnd.y_root, &dest_window, &proto); @@ -2053,7 +2177,7 @@ gtk_drag_dest_motion (GtkWidget *widget, } } - g_signal_emit_by_name (widget, "drag_motion", + g_signal_emit_by_name (widget, "drag-motion", context, x, y, time, &retval); return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval; @@ -2111,7 +2235,7 @@ gtk_drag_dest_drop (GtkWidget *widget, { gdk_drag_find_window_for_screen (info->proxy_source->context, NULL, - gdk_drawable_get_screen (current_event->dnd.window), + gdk_window_get_screen (current_event->dnd.window), current_event->dnd.x_root, current_event->dnd.y_root, &dest_window, &proto); @@ -2154,7 +2278,7 @@ gtk_drag_dest_drop (GtkWidget *widget, gtk_drag_get_data (widget, context, target, time); } - g_signal_emit_by_name (widget, "drag_drop", + g_signal_emit_by_name (widget, "drag-drop", context, x, y, time, &retval); return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval; @@ -2184,7 +2308,10 @@ gtk_drag_begin_internal (GtkWidget *widget, GdkDragContext *context; GtkWidget *ipc_widget; GdkCursor *cursor; - + GdkDevice *pointer, *keyboard; + GdkWindow *ipc_window; + + pointer = keyboard = NULL; ipc_widget = gtk_drag_get_ipc_widget (widget); gtk_drag_get_event_actions (event, button, actions, @@ -2195,24 +2322,53 @@ gtk_drag_begin_internal (GtkWidget *widget, NULL); if (event) - time = gdk_event_get_time (event); + { + time = gdk_event_get_time (event); + if (time == GDK_CURRENT_TIME) + time = gtk_get_current_event_time (); + + pointer = gdk_event_get_device (event); + + if (gdk_device_get_source (pointer) == GDK_SOURCE_KEYBOARD) + { + keyboard = pointer; + pointer = gdk_device_get_associated_device (keyboard); + } + else + keyboard = gdk_device_get_associated_device (pointer); + } + else + { + GdkDeviceManager *device_manager; + + device_manager = gdk_display_get_device_manager (gtk_widget_get_display (widget)); + pointer = gdk_device_manager_get_client_pointer (device_manager); + keyboard = gdk_device_get_associated_device (pointer); + } + + if (!pointer) + return NULL; - if (gdk_pointer_grab (ipc_widget->window, FALSE, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, NULL, - cursor, time) != GDK_GRAB_SUCCESS) + ipc_window = gtk_widget_get_window (ipc_widget); + + if (gdk_device_grab (pointer, ipc_window, + GDK_OWNERSHIP_APPLICATION, FALSE, + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_RELEASE_MASK, + cursor, time) != GDK_GRAB_SUCCESS) { gtk_drag_release_ipc_widget (ipc_widget); return NULL; } - gdk_keyboard_grab (ipc_widget->window, FALSE, time); - + if (keyboard) + grab_dnd_keys (ipc_widget, keyboard, 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); - + gtk_device_grab_add (ipc_widget, pointer, FALSE); + tmp_list = g_list_last (target_list->list); while (tmp_list) { @@ -2224,7 +2380,8 @@ gtk_drag_begin_internal (GtkWidget *widget, source_widgets = g_slist_prepend (source_widgets, ipc_widget); - context = gdk_drag_begin (ipc_widget->window, targets); + context = gdk_drag_begin (ipc_window, targets); + gdk_drag_context_set_device (context, pointer); g_list_free (targets); info = gtk_drag_get_source_info (context, TRUE); @@ -2232,7 +2389,7 @@ gtk_drag_begin_internal (GtkWidget *widget, info->ipc_widget = ipc_widget; g_object_set_data (G_OBJECT (info->ipc_widget), I_("gtk-info"), info); - info->widget = gtk_widget_ref (widget); + info->widget = g_object_ref (widget); info->button = button; info->cursor = cursor; @@ -2247,7 +2404,7 @@ gtk_drag_begin_internal (GtkWidget *widget, info->icon_window = NULL; info->destroy_icon = FALSE; - /* Set cur_x, cur_y here so if the "drag_begin" signal shows + /* Set cur_x, cur_y here so if the "drag-begin" signal shows * the drag icon, it will be in the right place */ if (event && event->type == GDK_MOTION_NOTIFY) @@ -2256,13 +2413,13 @@ gtk_drag_begin_internal (GtkWidget *widget, info->cur_x = event->motion.x_root; info->cur_y = event->motion.y_root; } - else + else { - gdk_display_get_pointer (gtk_widget_get_display (widget), - &info->cur_screen, &info->cur_x, &info->cur_y, NULL); + gdk_display_get_device_state (gtk_widget_get_display (widget), pointer, + &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 @@ -2275,13 +2432,6 @@ gtk_drag_begin_internal (GtkWidget *widget, 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, @@ -2315,11 +2465,11 @@ gtk_drag_begin_internal (GtkWidget *widget, if (cursor != info->cursor) { - gdk_pointer_grab (widget->window, FALSE, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, time); + gdk_device_grab (pointer, gtk_widget_get_window (widget), + GDK_OWNERSHIP_APPLICATION, FALSE, + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_RELEASE_MASK, + cursor, time); info->cursor = cursor; } } @@ -2332,19 +2482,19 @@ gtk_drag_begin_internal (GtkWidget *widget, info->start_x = info->cur_x; info->start_y = info->cur_y; - g_signal_connect (info->ipc_widget, "grab_broken_event", + g_signal_connect (info->ipc_widget, "grab-broken-event", G_CALLBACK (gtk_drag_grab_broken_event_cb), info); - g_signal_connect (info->ipc_widget, "grab_notify", + 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_signal_connect (info->ipc_widget, "button-release-event", G_CALLBACK (gtk_drag_button_release_cb), info); - g_signal_connect (info->ipc_widget, "motion_notify_event", + g_signal_connect (info->ipc_widget, "motion-notify-event", G_CALLBACK (gtk_drag_motion_cb), info); - g_signal_connect (info->ipc_widget, "key_press_event", + g_signal_connect (info->ipc_widget, "key-press-event", G_CALLBACK (gtk_drag_key_cb), info); - g_signal_connect (info->ipc_widget, "key_release_event", + g_signal_connect (info->ipc_widget, "key-release-event", G_CALLBACK (gtk_drag_key_cb), info); - g_signal_connect (info->ipc_widget, "selection_get", + g_signal_connect (info->ipc_widget, "selection-get", G_CALLBACK (gtk_drag_selection_get), info); info->have_grab = TRUE; @@ -2361,12 +2511,35 @@ gtk_drag_begin_internal (GtkWidget *widget, * @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. - * + * + * The @event is used to retrieve the timestamp that will be used internally to + * grab the pointer. If @event is #NULL, then GDK_CURRENT_TIME will be used. + * However, you should try to pass a real event in all cases, since that can be + * used by GTK+ to get information about the start position of the drag, for + * example if the @event is a GDK_MOTION_NOTIFY. + * + * Generally there are three cases when you want to start a drag by hand by + * calling this function: + * + * 1. During a button-press-event handler, if you want to start a drag + * immediately when the user presses the mouse button. Pass the @event + * that you have in your button-press-event handler. + * + * 2. During a motion-notify-event handler, if you want to start a drag + * when the mouse moves past a certain threshold distance after a button-press. + * Pass the @event that you have in your motion-notify-event handler. + * + * 3. During a timeout handler, if you want to start a drag after the mouse + * button is held down for some time. Try to save the last event that you got + * from the mouse, using gdk_event_copy(), and pass it to this function + * (remember to free the event with gdk_event_free() when you are done). + * If you can really not pass a real event, pass #NULL instead. + * * Return value: the context for this drag. **/ GdkDragContext * @@ -2377,26 +2550,26 @@ gtk_drag_begin (GtkWidget *widget, 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 (gtk_widget_get_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. - * arguments: - * widget: - * start_button_mask: Mask of allowed buttons to start drag - * targets: Table of targets for this source - * n_targets: - * actions: Actions allowed for this source - * results: - *************************************************************/ - -void + * @widget: a #GtkWidget + * @start_button_mask: the bitmask of buttons that can start the drag + * @targets: (allow-none) (array length=n_targets): the table of targets that the drag will support, + * may be %NULL + * @n_targets: the number of items in @targets + * @actions: the bitmask of possible actions for a drag from this widget + * + * Sets up a widget so that GTK+ will start a drag operation when the user + * clicks and drags on the widget. The widget must have a window. + */ +void gtk_drag_source_set (GtkWidget *widget, GdkModifierType start_button_mask, const GtkTargetEntry *targets, @@ -2421,17 +2594,17 @@ gtk_drag_source_set (GtkWidget *widget, } else { - site = g_new0 (GtkDragSourceSite, 1); + site = g_slice_new0 (GtkDragSourceSite); site->icon_type = GTK_IMAGE_EMPTY; - g_signal_connect (widget, "button_press_event", + g_signal_connect (widget, "button-press-event", G_CALLBACK (gtk_drag_source_event_cb), site); - g_signal_connect (widget, "button_release_event", + g_signal_connect (widget, "button-release-event", G_CALLBACK (gtk_drag_source_event_cb), site); - g_signal_connect (widget, "motion_notify_event", + g_signal_connect (widget, "motion-notify-event", G_CALLBACK (gtk_drag_source_event_cb), site); @@ -2456,7 +2629,7 @@ gtk_drag_source_set (GtkWidget *widget, *************************************************************/ void -gtk_drag_source_unset (GtkWidget *widget) +gtk_drag_source_unset (GtkWidget *widget) { GtkDragSourceSite *site; @@ -2499,7 +2672,7 @@ gtk_drag_source_get_target_list (GtkWidget *widget) /** * gtk_drag_source_set_target_list: * @widget: a #GtkWidget that's a drag source - * @target_list: list of draggable targets, or %NULL for none + * @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 @@ -2620,12 +2793,6 @@ gtk_drag_source_unset_icon (GtkDragSourceSite *site) { case GTK_IMAGE_EMPTY: break; - case GTK_IMAGE_PIXMAP: - if (site->icon_data.pixmap.pixmap) - g_object_unref (site->icon_data.pixmap.pixmap); - if (site->icon_mask) - g_object_unref (site->icon_mask); - break; case GTK_IMAGE_PIXBUF: g_object_unref (site->icon_data.pixbuf.pixbuf); break; @@ -2640,52 +2807,6 @@ gtk_drag_source_unset_icon (GtkDragSourceSite *site) break; } site->icon_type = GTK_IMAGE_EMPTY; - - if (site->colormap) - g_object_unref (site->colormap); - site->colormap = NULL; -} - -/** - * gtk_drag_source_set_icon: - * @widget: a #GtkWidget - * @colormap: the colormap of the icon - * @pixmap: the image data for the icon - * @mask: 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 - * will release them when they are no longer needed. - * Use gtk_drag_source_set_icon_pixbuf() instead. - **/ -void -gtk_drag_source_set_icon (GtkWidget *widget, - GdkColormap *colormap, - GdkPixmap *pixmap, - GdkBitmap *mask) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - g_return_if_fail (GDK_IS_PIXMAP (pixmap)); - g_return_if_fail (!mask || GDK_IS_PIXMAP (mask)); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - g_return_if_fail (site != NULL); - - g_object_ref (colormap); - g_object_ref (pixmap); - if (mask) - g_object_ref (mask); - - gtk_drag_source_unset_icon (site); - - site->icon_type = GTK_IMAGE_PIXMAP; - - site->icon_data.pixmap.pixmap = pixmap; - site->icon_mask = mask; - site->colormap = colormap; } /** @@ -2796,16 +2917,8 @@ gtk_drag_get_icon (GtkDragSourceInfo *info, save_destroy_icon = info->destroy_icon; info->icon_window = NULL; - 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); + set_icon_stock_pixbuf (info->context, + GTK_STOCK_DND, NULL, -2, -2, TRUE); info->fallback_icon = info->icon_window; info->icon_window = save_icon_window; @@ -2819,16 +2932,8 @@ gtk_drag_get_icon (GtkDragSourceInfo *info, *icon_window = info->fallback_icon; gtk_window_set_screen (GTK_WINDOW (*icon_window), info->cur_screen); - if (!default_icon_pixmap) - { - *hot_x = -2; - *hot_y = -2; - } - else - { - *hot_x = default_icon_hot_x; - *hot_y = default_icon_hot_y; - } + *hot_x = -2; + *hot_y = -2; } else { @@ -2855,8 +2960,8 @@ gtk_drag_update_icon (GtkDragSourceInfo *info) info->cur_x - hot_x, info->cur_y - hot_y); - if (GTK_WIDGET_VISIBLE (icon_window)) - gdk_window_raise (icon_window->window); + if (gtk_widget_get_visible (icon_window)) + gdk_window_raise (gtk_widget_get_window (icon_window)); else gtk_widget_show (icon_window); } @@ -2882,7 +2987,7 @@ gtk_drag_set_icon_window (GdkDragContext *context, gtk_drag_remove_icon (info); if (widget) - gtk_widget_ref (widget); + g_object_ref (widget); info->icon_window = widget; info->hot_x = hot_x; @@ -2909,7 +3014,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 @@ -2929,20 +3034,49 @@ static void icon_window_realize (GtkWidget *window, GdkPixbuf *pixbuf) { - 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); - g_object_unref (pixmap); - - if (mask) + cairo_surface_t *surface; + cairo_pattern_t *pattern; + cairo_t *cr; + + surface = gdk_window_create_similar_surface (gtk_widget_get_window (window), + CAIRO_CONTENT_COLOR, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf)); + + cr = cairo_create (surface); + cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA); + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + cairo_paint (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE); + cairo_paint (cr); + cairo_pop_group_to_source (cr); + cairo_paint (cr); + cairo_destroy (cr); + + pattern = cairo_pattern_create_for_surface (surface); + gdk_window_set_background_pattern (gtk_widget_get_window (window), pattern); + cairo_pattern_destroy (pattern); + + cairo_surface_destroy (surface); + + if (gdk_pixbuf_get_has_alpha (pixbuf)) { - gtk_widget_shape_combine_mask (window, mask, 0, 0); - g_object_unref (mask); + cairo_region_t *region; + + surface = cairo_image_surface_create (CAIRO_FORMAT_A1, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf)); + + cr = cairo_create (surface); + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); + + region = gdk_cairo_region_create_from_surface (surface); + gtk_widget_shape_combine_region (window, region); + cairo_region_destroy (region); + + cairo_surface_destroy (surface); } } @@ -2963,23 +3097,20 @@ set_icon_stock_pixbuf (GdkDragContext *context, 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); + screen = gdk_window_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, - GTK_ICON_SIZE_DND, NULL); + pixbuf = gtk_widget_render_icon_pixbuf (window, stock_id, + GTK_ICON_SIZE_DND); if (!pixbuf) { @@ -2992,7 +3123,7 @@ set_icon_stock_pixbuf (GdkDragContext *context, else g_object_ref (pixbuf); - display = gdk_drawable_get_display (context->source_window); + display = gdk_window_get_display (context->source_window); width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); @@ -3071,66 +3202,132 @@ gtk_drag_set_icon_stock (GdkDragContext *context, set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y, FALSE); } +/* XXX: This function is in gdk, too. Should it be in Cairo? */ +static gboolean +_gtk_cairo_surface_extents (cairo_surface_t *surface, + GdkRectangle *extents) +{ + double x1, x2, y1, y2; + cairo_t *cr; + + g_return_val_if_fail (surface != NULL, FALSE); + g_return_val_if_fail (extents != NULL, FALSE); + + cr = cairo_create (surface); + cairo_clip_extents (cr, &x1, &y1, &x2, &y2); + + x1 = floor (x1); + y1 = floor (y1); + x2 = ceil (x2); + y2 = ceil (y2); + x2 -= x1; + y2 -= y1; + + if (x1 < G_MININT || x1 > G_MAXINT || + y1 < G_MININT || y1 > G_MAXINT || + x2 > G_MAXINT || y2 > G_MAXINT) + { + extents->x = extents->y = extents->width = extents->height = 0; + return FALSE; + } + + extents->x = x1; + extents->y = y1; + extents->width = x2; + extents->height = y2; + + return TRUE; +} + /** - * gtk_drag_set_icon_pixmap: - * @context: the context for a drag. (This must be called - * 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 - * @hot_x: the X offset within @pixmap of the hotspot. - * @hot_y: the Y offset within @pixmap of the hotspot. - * - * Sets @pixmap as the icon for a given drag. GTK+ retains + * gtk_drag_set_icon_surface: + * @context: the context for a drag. (This must be called + * with a context for the source side of a drag) + * @surface: the surface to use as icon + * + * Sets @surface as the icon for a given drag. GTK+ retains * references for the arguments, and will release them when - * they are no longer needed. In general, gtk_drag_set_icon_pixbuf() - * will be more convenient to use. + * they are no longer needed. + * + * To position the surface relative to the mouse, use + * cairo_surface_set_device_offset() on @surface. The mouse + * cursor will be positioned at the (0,0) coordinate of the + * surface. **/ void -gtk_drag_set_icon_pixmap (GdkDragContext *context, - GdkColormap *colormap, - GdkPixmap *pixmap, - GdkBitmap *mask, - gint hot_x, - gint hot_y) +gtk_drag_set_icon_surface (GdkDragContext *context, + cairo_surface_t *surface) { GtkWidget *window; GdkScreen *screen; - gint width, height; + GdkRectangle extents; + cairo_pattern_t *pattern; g_return_if_fail (GDK_IS_DRAG_CONTEXT (context)); g_return_if_fail (context->is_source); - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - g_return_if_fail (GDK_IS_PIXMAP (pixmap)); - g_return_if_fail (!mask || GDK_IS_PIXMAP (mask)); + g_return_if_fail (surface != NULL); + + _gtk_cairo_surface_extents (surface, &extents); - screen = gdk_colormap_get_screen (colormap); - - g_return_if_fail (gdk_drawable_get_screen (pixmap) == screen); - g_return_if_fail (!mask || gdk_drawable_get_screen (mask) == screen); - - gdk_drawable_get_size (pixmap, &width, &height); - gtk_widget_push_colormap (colormap); + screen = gdk_window_get_screen (context->source_window); 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); - gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); + 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 (window, TRUE); - gtk_widget_set_size_request (window, width, height); + gtk_widget_set_size_request (window, extents.width, extents.height); gtk_widget_realize (window); - gdk_window_set_back_pixmap (window->window, pixmap, FALSE); - - if (mask) - gtk_widget_shape_combine_mask (window, mask, 0, 0); + if (cairo_surface_get_content (surface) != CAIRO_CONTENT_COLOR) + { + cairo_surface_t *saturated; + cairo_region_t *region; + cairo_t *cr; - gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE); + region = gdk_cairo_region_create_from_surface (surface); + cairo_region_translate (region, -extents.x, -extents.y); + + gtk_widget_shape_combine_region (window, region); + cairo_region_destroy (region); + + /* Need to saturate the colors, so it doesn't look like semi-transparent + * pixels were painted on black. */ + saturated = gdk_window_create_similar_surface (gtk_widget_get_window (window), + CAIRO_CONTENT_COLOR, + extents.width, + extents.height); + + cr = cairo_create (saturated); + cairo_push_group_with_content (cr, CAIRO_CONTENT_COLOR_ALPHA); + cairo_set_source_surface (cr, surface, -extents.x, -extents.y); + cairo_paint (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_SATURATE); + cairo_paint (cr); + cairo_pop_group_to_source (cr); + cairo_paint (cr); + cairo_destroy (cr); + + pattern = cairo_pattern_create_for_surface (saturated); + + cairo_surface_destroy (saturated); + } + else + { + cairo_matrix_t matrix; + + pattern = cairo_pattern_create_for_surface (surface); + cairo_matrix_init_translate (&matrix, extents.x, extents.y); + cairo_pattern_set_matrix (pattern, &matrix); + } + + gdk_window_set_background_pattern (gtk_widget_get_window (window), pattern); + + gtk_drag_set_icon_window (context, window, extents.x, extents.y, TRUE); } /** @@ -3165,7 +3362,7 @@ gtk_drag_set_icon_name (GdkDragContext *context, g_return_if_fail (context->is_source); g_return_if_fail (icon_name != NULL); - screen = gdk_drawable_get_screen (context->source_window); + screen = gdk_window_get_screen (context->source_window); g_return_if_fail (screen != NULL); settings = gtk_settings_get_for_screen (screen); @@ -3200,63 +3397,9 @@ gtk_drag_set_icon_default (GdkDragContext *context) g_return_if_fail (GDK_IS_DRAG_CONTEXT (context)); g_return_if_fail (context->is_source); - if (!default_icon_pixmap) - gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2); - else - gtk_drag_set_icon_pixmap (context, - default_icon_colormap, - default_icon_pixmap, - default_icon_mask, - default_icon_hot_x, - default_icon_hot_y); -} - -/** - * gtk_drag_set_default_icon: - * @colormap: the colormap of the icon - * @pixmap: the image data for the icon - * @mask: the transparency mask for an image. - * @hot_x: The X offset within @widget of the hotspot. - * @hot_y: The Y offset within @widget of the hotspot. - * - * 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. - **/ -void -gtk_drag_set_default_icon (GdkColormap *colormap, - GdkPixmap *pixmap, - GdkBitmap *mask, - gint hot_x, - gint hot_y) -{ - g_return_if_fail (GDK_IS_COLORMAP (colormap)); - g_return_if_fail (GDK_IS_PIXMAP (pixmap)); - g_return_if_fail (!mask || GDK_IS_PIXMAP (mask)); - - if (default_icon_colormap) - g_object_unref (default_icon_colormap); - if (default_icon_pixmap) - g_object_unref (default_icon_pixmap); - if (default_icon_mask) - g_object_unref (default_icon_mask); - - default_icon_colormap = colormap; - g_object_ref (colormap); - - default_icon_pixmap = pixmap; - g_object_ref (pixmap); - - default_icon_mask = mask; - if (mask) - g_object_ref (mask); - - default_icon_hot_x = hot_x; - default_icon_hot_y = hot_y; + gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2); } - /************************************************************* * _gtk_drag_source_handle_event: * Called from widget event handling code on Drag events @@ -3319,11 +3462,13 @@ _gtk_drag_source_handle_event (GtkWidget *widget, info); if (info->cursor != cursor) { - gdk_pointer_grab (widget->window, FALSE, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, info->grab_time); + GdkDevice *pointer; + + pointer = gdk_drag_context_get_device (context); + gdk_device_grab (pointer, gtk_widget_get_window (widget), + GDK_OWNERSHIP_APPLICATION, FALSE, + GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, + cursor, info->grab_time); info->cursor = cursor; } @@ -3333,7 +3478,7 @@ _gtk_drag_source_handle_event (GtkWidget *widget, break; case GDK_DROP_FINISHED: - gtk_drag_drop_finished (info, TRUE, event->dnd.time); + gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, event->dnd.time); break; default: g_assert_not_reached (); @@ -3413,9 +3558,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) @@ -3427,19 +3575,23 @@ 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); } else - { - GtkDragAnim *anim = g_new (GtkDragAnim, 1); - anim->info = info; - anim->step = 0; - - anim->n_steps = MAX (info->cur_x - info->start_x, - info->cur_y - info->start_y) / ANIM_STEP_LENGTH; - anim->n_steps = CLAMP (anim->n_steps, ANIM_MIN_STEPS, ANIM_MAX_STEPS); + { + GtkDragAnim *anim = g_slice_new0 (GtkDragAnim); + anim->info = info; + anim->step = 0; + + anim->n_steps = MAX (info->cur_x - info->start_x, + info->cur_y - info->start_y) / ANIM_STEP_LENGTH; + anim->n_steps = CLAMP (anim->n_steps, ANIM_MIN_STEPS, ANIM_MAX_STEPS); info->cur_screen = gtk_widget_get_screen (info->widget); @@ -3448,7 +3600,7 @@ gtk_drag_drop_finished (GtkDragSourceInfo *info, 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. */ @@ -3468,7 +3620,7 @@ gtk_drag_source_release_selections (GtkDragSourceInfo *info, while (tmp_list) { GdkAtom selection = GDK_POINTER_TO_ATOM (tmp_list->data); - if (gdk_selection_owner_get_for_display (display, selection) == info->ipc_widget->window) + if (gdk_selection_owner_get_for_display (display, selection) == gtk_widget_get_window (info->ipc_widget)) gtk_selection_owner_set_for_display (display, NULL, selection, time); tmp_list = tmp_list->next; @@ -3512,18 +3664,18 @@ gtk_drag_drop (GtkDragSourceInfo *info, selection_data.data = NULL; selection_data.length = -1; - g_signal_emit_by_name (info->widget, "drag_data_get", + g_signal_emit_by_name (info->widget, "drag-data-get", info->context, &selection_data, pair->info, time); /* FIXME: Should we check for length >= 0 here? */ - gtk_drag_drop_finished (info, TRUE, time); + gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, time); return; } tmp_list = tmp_list->next; } - gtk_drag_drop_finished (info, FALSE, time); + gtk_drag_drop_finished (info, GTK_DRAG_RESULT_NO_TARGET, time); } else { @@ -3609,7 +3761,7 @@ gtk_drag_source_site_destroy (gpointer data) gtk_target_list_unref (site->target_list); gtk_drag_source_unset_icon (site); - g_free (site); + g_slice_free (GtkDragSourceSite, site); } static void @@ -3630,16 +3782,16 @@ gtk_drag_selection_get (GtkWidget *widget, { case TARGET_DELETE: g_signal_emit_by_name (info->widget, - "drag_data_delete", + "drag-data-delete", info->context); gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0); break; case TARGET_MOTIF_SUCCESS: - gtk_drag_drop_finished (info, TRUE, time); + gtk_drag_drop_finished (info, GTK_DRAG_RESULT_SUCCESS, time); gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0); break; case TARGET_MOTIF_FAILURE: - gtk_drag_drop_finished (info, FALSE, time); + gtk_drag_drop_finished (info, GTK_DRAG_RESULT_NO_TARGET, time); gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0); break; default: @@ -3662,7 +3814,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, @@ -3676,34 +3828,38 @@ gtk_drag_selection_get (GtkWidget *widget, static gboolean gtk_drag_anim_timeout (gpointer data) { - GtkDragAnim *anim = data; + GtkDragAnim *anim; + GtkDragSourceInfo *info; gint x, y; gboolean retval; + anim = data; + info = anim->info; + if (anim->step == anim->n_steps) { gtk_drag_source_info_destroy (anim->info); - g_free (anim); + g_slice_free (GtkDragAnim, anim); retval = FALSE; } else { - x = (anim->info->start_x * (anim->step + 1) + - anim->info->cur_x * (anim->n_steps - anim->step - 1)) / anim->n_steps; - y = (anim->info->start_y * (anim->step + 1) + - anim->info->cur_y * (anim->n_steps - anim->step - 1)) / anim->n_steps; - if (anim->info->icon_window) - { - GtkWidget *icon_window; - gint 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); - } - + x = (info->start_x * (anim->step + 1) + + info->cur_x * (anim->n_steps - anim->step - 1)) / anim->n_steps; + y = (info->start_y * (anim->step + 1) + + info->cur_y * (anim->n_steps - anim->step - 1)) / anim->n_steps; + if (info->icon_window) + { + GtkWidget *icon_window; + gint hot_x, hot_y; + + gtk_drag_get_icon (info, &icon_window, &hot_x, &hot_y); + gtk_window_move (GTK_WINDOW (icon_window), + x - hot_x, + y - hot_y); + } + anim->step++; retval = TRUE; @@ -3774,8 +3930,7 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info) info); if (!info->proxy_dest) - g_signal_emit_by_name (info->widget, "drag_end", - info->context); + g_signal_emit_by_name (info->widget, "drag-end", info->context); if (info->widget) g_object_unref (info->widget); @@ -3793,6 +3948,9 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info) if (info->drop_timeout) g_source_remove (info->drop_timeout); + if (info->update_idle) + g_source_remove (info->update_idle); + g_free (info); } @@ -3819,7 +3977,7 @@ gtk_drag_update_idle (gpointer data) &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->icon_window ? gtk_widget_get_window (info->icon_window) : NULL, info->cur_screen, info->cur_x, info->cur_y, &dest_window, &protocol); @@ -3847,7 +4005,7 @@ gtk_drag_update_idle (gpointer data) static void gtk_drag_add_update_idle (GtkDragSourceInfo *info) { - /* We use an idle lowerthan GDK_PRIORITY_REDRAW so that exposes + /* We use an idle lower than GDK_PRIORITY_REDRAW so that exposes * from the last move can catch up before we move again. */ if (!info->update_idle) @@ -3904,7 +4062,14 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time) { GdkEvent *send_event; GtkWidget *source_widget = info->widget; - GdkDisplay *display = gtk_widget_get_display (source_widget); + GdkDevice *pointer, *keyboard; + + pointer = gdk_drag_context_get_device (info->context); + keyboard = gdk_device_get_associated_device (pointer); + + /* Prevent ungrab before grab (see bug 623865) */ + if (info->grab_time == GDK_CURRENT_TIME) + time = GDK_CURRENT_TIME; if (info->update_idle) { @@ -3936,9 +4101,9 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time) gtk_drag_key_cb, info); - gdk_display_pointer_ungrab (display, time); - gdk_display_keyboard_ungrab (display, time); - gtk_grab_remove (info->ipc_widget); + gdk_device_ungrab (pointer, time); + ungrab_dnd_keys (info->ipc_widget, keyboard, time); + gtk_device_grab_remove (info->ipc_widget, pointer); /* Send on a release pair to the original * widget to convince it to release its grab. We need to @@ -3956,7 +4121,7 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time) send_event->button.axes = NULL; send_event->button.state = 0; send_event->button.button = info->button; - send_event->button.device = gdk_display_get_core_pointer (display); + send_event->button.device = pointer; send_event->button.x_root = 0; send_event->button.y_root = 0; @@ -3975,16 +4140,16 @@ gtk_drag_end (GtkDragSourceInfo *info, guint32 time) *************************************************************/ static void -gtk_drag_cancel (GtkDragSourceInfo *info, guint32 time) +gtk_drag_cancel (GtkDragSourceInfo *info, GtkDragResult result, guint32 time) { gtk_drag_end (info, time); gdk_drag_abort (info->context, time); - gtk_drag_drop_finished (info, FALSE, time); + gtk_drag_drop_finished (info, result, time); } /************************************************************* * gtk_drag_motion_cb: - * "motion_notify_event" callback during drag. + * "motion-notify-event" callback during drag. * arguments: * * results: @@ -4002,22 +4167,23 @@ gtk_drag_motion_cb (GtkWidget *widget, if (event->is_hint) { GdkDisplay *display = gtk_widget_get_display (widget); - - gdk_display_get_pointer (display, &screen, &x_root, &y_root, NULL); + + gdk_display_get_device_state (display, event->device, + &screen, &x_root, &y_root, NULL); event->x_root = x_root; event->y_root = y_root; } else screen = gdk_event_get_screen ((GdkEvent *)event); - gtk_drag_update (info, screen, event->x_root, event->y_root, (GdkEvent *)event); + gtk_drag_update (info, screen, event->x_root, event->y_root, (GdkEvent *) event); return TRUE; } /************************************************************* * gtk_drag_key_cb: - * "key_press/release_event" callback during drag. + * "key-press/release-event" callback during drag. * arguments: * * results: @@ -4034,44 +4200,47 @@ gtk_drag_key_cb (GtkWidget *widget, GtkDragSourceInfo *info = (GtkDragSourceInfo *)data; GdkModifierType state; GdkWindow *root_window; + GdkDevice *pointer; gint dx, dy; dx = dy = 0; state = event->state & gtk_accelerator_get_default_mod_mask (); + pointer = gdk_device_get_associated_device (gdk_event_get_device ((GdkEvent *) event)); if (event->type == GDK_KEY_PRESS) { switch (event->keyval) { - case GDK_Escape: - gtk_drag_cancel (info, event->time); + case GDK_KEY_Escape: + gtk_drag_cancel (info, GTK_DRAG_RESULT_USER_CANCELLED, event->time); return TRUE; - case GDK_space: - case GDK_Return: - case GDK_KP_Enter: - case GDK_KP_Space: + case GDK_KEY_space: + case GDK_KEY_Return: + case GDK_KEY_ISO_Enter: + case GDK_KEY_KP_Enter: + case GDK_KEY_KP_Space: gtk_drag_end (info, event->time); gtk_drag_drop (info, event->time); return TRUE; - case GDK_Up: - case GDK_KP_Up: + case GDK_KEY_Up: + case GDK_KEY_KP_Up: dy = (state & GDK_MOD1_MASK) ? -BIG_STEP : -SMALL_STEP; break; - case GDK_Down: - case GDK_KP_Down: + case GDK_KEY_Down: + case GDK_KEY_KP_Down: dy = (state & GDK_MOD1_MASK) ? BIG_STEP : SMALL_STEP; break; - case GDK_Left: - case GDK_KP_Left: + case GDK_KEY_Left: + case GDK_KEY_KP_Left: dx = (state & GDK_MOD1_MASK) ? -BIG_STEP : -SMALL_STEP; break; - case GDK_Right: - case GDK_KP_Right: + case GDK_KEY_Right: + case GDK_KEY_KP_Right: dx = (state & GDK_MOD1_MASK) ? BIG_STEP : SMALL_STEP; break; } @@ -4085,16 +4254,16 @@ gtk_drag_key_cb (GtkWidget *widget, * that would be overkill. */ root_window = gtk_widget_get_root_window (widget); - gdk_window_get_pointer (root_window, NULL, NULL, &state); + gdk_window_get_device_position (root_window, pointer, 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); + gdk_display_warp_device (gtk_widget_get_display (widget), pointer, + 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); @@ -4114,11 +4283,11 @@ gtk_drag_grab_broken_event_cb (GtkWidget *widget, * example, when changing the drag cursor. */ if (event->implicit - || event->grab_window == info->widget->window - || event->grab_window == info->ipc_widget->window) + || event->grab_window == gtk_widget_get_window (info->widget) + || event->grab_window == gtk_widget_get_window (info->ipc_widget)) return FALSE; - gtk_drag_cancel (info, gtk_get_current_event_time ()); + gtk_drag_cancel (info, GTK_DRAG_RESULT_GRAB_BROKEN, gtk_get_current_event_time ()); return TRUE; } @@ -4128,13 +4297,16 @@ gtk_drag_grab_notify_cb (GtkWidget *widget, gpointer data) { GtkDragSourceInfo *info = (GtkDragSourceInfo *)data; + GdkDevice *pointer; - if (!was_grabbed) + pointer = gdk_drag_context_get_device (info->context); + + if (gtk_widget_device_is_shadowed (widget, pointer)) { /* 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_get_current_event_time ()); + 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); } } @@ -4142,7 +4314,7 @@ gtk_drag_grab_notify_cb (GtkWidget *widget, /************************************************************* * gtk_drag_button_release_cb: - * "button_release_event" callback during drag. + * "button-release-event" callback during drag. * arguments: * * results: @@ -4165,7 +4337,7 @@ gtk_drag_button_release_cb (GtkWidget *widget, } else { - gtk_drag_cancel (info, event->time); + gtk_drag_cancel (info, GTK_DRAG_RESULT_NO_TARGET, event->time); } return TRUE; @@ -4181,7 +4353,7 @@ gtk_drag_abort_timeout (gpointer data) time = info->proxy_dest->proxy_drop_time; info->drop_timeout = 0; - gtk_drag_drop_finished (info, FALSE, time); + gtk_drag_drop_finished (info, GTK_DRAG_RESULT_TIMEOUT_EXPIRED, time); return FALSE; } @@ -4218,6 +4390,3 @@ 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"