X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkdnd.c;h=4b974a5ee95c60a1939a5880ec649f5388aabf50;hb=ca2368dba958d6fecf2fce417307bb9cbbe6eb6b;hp=15128c8e08d7f9869d724ca8b943ada6da65f6e8;hpb=4765f37484b28b99b18b8e7c96bc71754cfe9ebd;p=~andy%2Fgtk
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 15128c8e0..4b974a5ee 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -12,9 +12,7 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
/*
@@ -36,12 +34,15 @@
#include
#include
#include "gdk/x11/gdkx.h"
+#ifdef XINPUT_2
+#include
+#endif
#endif
#include "gtkdnd.h"
#include "gtkiconfactory.h"
+#include "gtkiconhelperprivate.h"
#include "gtkicontheme.h"
-#include "gtkimageprivate.h"
#include "gtkinvisible.h"
#include "gtkmain.h"
#include "gtkplug.h"
@@ -49,9 +50,28 @@
#include "gtktooltip.h"
#include "gtkwindow.h"
#include "gtkintl.h"
-#include "gtkdndcursors.h"
#include "gtkselectionprivate.h"
+
+/**
+ * SECTION:gtkdnd
+ * @Short_description: Functions for controlling drag and drop handling
+ * @Title: Drag and Drop
+ *
+ * GTK+ has a rich set of functions for doing inter-process
+ * communication via the drag-and-drop metaphor. GTK+
+ * can do drag-and-drop (DND) via multiple protocols.
+ * The currently supported protocols are the Xdnd and
+ * Motif protocols.
+ *
+ * As well as the functions listed here, applications
+ * may need to use some facilities provided for
+ * Selections.
+ * Also, the Drag and Drop API makes use of signals
+ * in the #GtkWidget class.
+ */
+
+
static GSList *source_widgets = NULL;
typedef struct _GtkDragSourceSite GtkDragSourceSite;
@@ -74,14 +94,7 @@ struct _GtkDragSourceSite
GtkTargetList *target_list; /* Targets for drag data */
GdkDragAction actions; /* Possible actions */
- /* Drag icon */
- GtkImageType icon_type;
- union
- {
- GtkImagePixbufData pixbuf;
- GtkImageStockData stock;
- GtkImageIconNameData name;
- } icon_data;
+ GtkIconHelper *icon_helper;
/* Stored button press information to detect drag beginning */
gint state;
@@ -117,7 +130,7 @@ struct _GtkDragSourceInfo
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;
+ GtkIconHelper *icon_helper;
GdkCursor *drag_cursors[6];
};
@@ -183,7 +196,8 @@ static void gtk_drag_get_event_actions (GdkEvent *event,
GdkDragAction actions,
GdkDragAction *suggested_action,
GdkDragAction *possible_actions);
-static GdkCursor * gtk_drag_get_cursor (GdkDisplay *display,
+static GdkCursor * gtk_drag_get_cursor (GtkWidget *widget,
+ GdkDisplay *display,
GdkDragAction action,
GtkDragSourceInfo *info);
static void gtk_drag_update_cursor (GtkDragSourceInfo *info);
@@ -279,12 +293,11 @@ static gboolean gtk_drag_button_release_cb (GtkWidget *widget,
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);
+static void set_icon_helper (GdkDragContext *context,
+ GtkIconHelper *helper,
+ gint hot_x,
+ gint hot_y,
+ gboolean force_window);
/************************
* Cursor and Icon data *
@@ -293,20 +306,17 @@ static void set_icon_stock_pixbuf (GdkDragContext *context,
static struct {
GdkDragAction action;
const gchar *name;
- const guint8 *data;
GdkPixbuf *pixbuf;
GdkCursor *cursor;
} drag_cursors[] = {
{ 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 },
+ { GDK_ACTION_ASK, "dnd-ask", NULL, NULL },
+ { GDK_ACTION_COPY, "dnd-copy", NULL, NULL },
+ { GDK_ACTION_MOVE, "dnd-move", NULL, NULL },
+ { GDK_ACTION_LINK, "dnd-link", NULL, NULL },
+ { 0 , "dnd-none", NULL, NULL },
};
-static const gint n_drag_cursors = sizeof (drag_cursors) / sizeof (drag_cursors[0]);
-
/*********************
* Utility functions *
*********************/
@@ -350,7 +360,7 @@ gtk_drag_get_ipc_widget_for_screen (GdkScreen *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_window_move (GTK_WINDOW (result), -99, -99);
gtk_widget_show (result);
}
@@ -377,12 +387,7 @@ gtk_drag_get_ipc_widget (GtkWidget *widget)
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)
+#if defined (GDK_WINDOWING_X11)
/*
* We want to handle a handful of keys during DND, e.g. Escape to abort.
@@ -406,6 +411,18 @@ root_key_filter (GdkXEvent *xevent,
if ((ev->type == KeyPress || ev->type == KeyRelease) &&
ev->xkey.root == ev->xkey.window)
ev->xkey.window = (Window)data;
+ else if (ev->type == GenericEvent)
+ {
+ XGenericEventCookie *cookie;
+ XIDeviceEvent *dev;
+
+ cookie = &ev->xcookie;
+ dev = (XIDeviceEvent *) cookie->data;
+
+ if (dev->evtype == XI_KeyPress ||
+ dev->evtype == XI_KeyRelease)
+ dev->event = (Window)data;
+ }
return GDK_FILTER_CONTINUE;
}
@@ -447,8 +464,34 @@ grab_dnd_keys (GtkWidget *widget,
guint i;
GdkWindow *window, *root;
gint keycode;
+#ifdef XINPUT_2
+ gint deviceid;
+ XIGrabModifiers mods;
+ gint num_mods;
+ XIEventMask evmask;
+ unsigned char mask[(XI_LASTEVENT + 7)/8];
+ gboolean using_xi2;
+
+ deviceid = gdk_x11_device_get_id (device);
+
+ if (GDK_IS_X11_DEVICE_MANAGER_XI2 (gdk_display_get_device_manager (gtk_widget_get_display (widget))))
+ using_xi2 = TRUE;
+ else
+ using_xi2 = FALSE;
+#endif
window = gtk_widget_get_window (widget);
+ if (!GDK_IS_X11_WINDOW (window))
+ {
+ gdk_device_grab (device,
+ gtk_widget_get_window (widget),
+ GDK_OWNERSHIP_APPLICATION, FALSE,
+ GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
+ NULL, time);
+ return;
+ }
+
+
root = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
gdk_error_trap_push ();
@@ -456,12 +499,42 @@ grab_dnd_keys (GtkWidget *widget,
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);
+ if (keycode == NoSymbol)
+ continue;
+
+#ifdef XINPUT_2
+ if (using_xi2)
+ {
+ memset (mask, 0, sizeof (mask));
+ XISetMask (mask, XI_KeyPress);
+ XISetMask (mask, XI_KeyRelease);
+
+ evmask.deviceid = deviceid;
+ evmask.mask_len = sizeof (mask);
+ evmask.mask = mask;
+
+ num_mods = 1;
+ mods.modifiers = grab_keys[i].modifiers;
+
+ XIGrabKeycode (GDK_WINDOW_XDISPLAY (window),
+ deviceid,
+ keycode,
+ GDK_WINDOW_XID (root),
+ GrabModeAsync,
+ GrabModeAsync,
+ False,
+ &evmask,
+ num_mods,
+ &mods);
+ }
+ else
+#endif
+ XGrabKey (GDK_WINDOW_XDISPLAY (window),
+ keycode, grab_keys[i].modifiers,
+ GDK_WINDOW_XID (root),
+ FALSE,
+ GrabModeAsync,
+ GrabModeAsync);
}
gdk_flush ();
@@ -478,8 +551,26 @@ ungrab_dnd_keys (GtkWidget *widget,
guint i;
GdkWindow *window, *root;
gint keycode;
+#ifdef XINPUT_2
+ XIGrabModifiers mods;
+ gint num_mods;
+ gint deviceid;
+ gboolean using_xi2;
+
+ deviceid = gdk_x11_device_get_id (device);
+ if (GDK_IS_X11_DEVICE_MANAGER_XI2 (gdk_display_get_device_manager (gtk_widget_get_display (widget))))
+ using_xi2 = TRUE;
+ else
+ using_xi2 = FALSE;
+#endif
window = gtk_widget_get_window (widget);
+ if (!GDK_IS_X11_WINDOW (window))
+ {
+ gdk_device_ungrab (device, time);
+ return;
+ }
+
root = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
gdk_window_remove_filter (NULL, root_key_filter, (gpointer) GDK_WINDOW_XID (window));
@@ -489,16 +580,34 @@ ungrab_dnd_keys (GtkWidget *widget,
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));
+ if (keycode == NoSymbol)
+ continue;
+
+#ifdef XINPUT_2
+ if (using_xi2)
+ {
+ num_mods = 1;
+ mods.modifiers = grab_keys[i].modifiers;
+
+ XIUngrabKeycode (GDK_WINDOW_XDISPLAY (window),
+ deviceid,
+ keycode,
+ GDK_WINDOW_XID (root),
+ num_mods,
+ &mods);
+ }
+ else
+#endif
+ XUngrabKey (GDK_WINDOW_XDISPLAY (window),
+ keycode, grab_keys[i].modifiers,
+ GDK_WINDOW_XID (root));
}
gdk_flush ();
gdk_error_trap_pop_ignored ();
}
-#else /* GDK_WINDOWING_X11 && !XINPUT_2 */
+#else /* !GDK_WINDOWING_X11 */
static void
grab_dnd_keys (GtkWidget *widget,
@@ -633,7 +742,7 @@ gtk_drag_get_event_actions (GdkEvent *event,
break;
}
- if ((button == 2 || button == 3) && (actions & GDK_ACTION_ASK))
+ if ((button == GDK_BUTTON_MIDDLE || button == GDK_BUTTON_SECONDARY) && (actions & GDK_ACTION_ASK))
{
*suggested_action = GDK_ACTION_ASK;
*possible_actions = actions;
@@ -719,8 +828,25 @@ gtk_drag_can_use_rgba_cursor (GdkDisplay *display,
return TRUE;
}
+static void
+ensure_drag_cursor_pixbuf (int i)
+{
+ if (drag_cursors[i].pixbuf == NULL)
+ {
+ char *path = g_strconcat ("/org/gtk/libgtk/cursor/", drag_cursors[i].name, ".png", NULL);
+ GInputStream *stream = g_resources_open_stream (path, 0, NULL);
+ if (stream != NULL)
+ {
+ drag_cursors[i].pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+ g_object_unref (stream);
+ }
+ g_free (path);
+ }
+}
+
static GdkCursor *
-gtk_drag_get_cursor (GdkDisplay *display,
+gtk_drag_get_cursor (GtkWidget *widget,
+ GdkDisplay *display,
GdkDragAction action,
GtkDragSourceInfo *info)
{
@@ -731,7 +857,7 @@ gtk_drag_get_cursor (GdkDisplay *display,
*/
if (!info)
{
- for (i = 0 ; i < n_drag_cursors - 1; i++)
+ for (i = 0 ; i < G_N_ELEMENTS (drag_cursors) - 1; i++)
if (drag_cursors[i].cursor != NULL)
{
g_object_unref (drag_cursors[i].cursor);
@@ -739,14 +865,10 @@ gtk_drag_get_cursor (GdkDisplay *display,
}
}
- for (i = 0 ; i < n_drag_cursors - 1; i++)
+ for (i = 0 ; i < G_N_ELEMENTS (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))
@@ -760,14 +882,17 @@ gtk_drag_get_cursor (GdkDisplay *display,
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);
+ {
+ ensure_drag_cursor_pixbuf (i);
+ drag_cursors[i].cursor = gdk_cursor_new_from_pixbuf (display, drag_cursors[i].pixbuf, 0, 0);
+ }
- if (info && info->icon_pixbuf)
+ if (info && info->icon_helper)
{
gint cursor_width, cursor_height;
gint icon_width, icon_height;
gint width, height;
- GdkPixbuf *cursor_pixbuf, *pixbuf;
+ GdkPixbuf *cursor_pixbuf, *pixbuf, *icon_pixbuf;
gint hot_x, hot_y;
gint icon_x, icon_y, ref_x, ref_y;
@@ -780,15 +905,21 @@ gtk_drag_get_cursor (GdkDisplay *display,
info->drag_cursors[i] = NULL;
}
+ icon_pixbuf = _gtk_icon_helper_ensure_pixbuf (info->icon_helper,
+ gtk_widget_get_style_context (widget));
+
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);
+ icon_width = gdk_pixbuf_get_width (icon_pixbuf);
+ icon_height = gdk_pixbuf_get_height (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);
+ {
+ ensure_drag_cursor_pixbuf (i);
+ cursor_pixbuf = g_object_ref (drag_cursors[i].pixbuf);
+ }
else
{
if (gdk_pixbuf_get_option (cursor_pixbuf, "x_hot"))
@@ -892,7 +1023,7 @@ gtk_drag_get_cursor (GdkDisplay *display,
gdk_pixbuf_fill (pixbuf, 0xff000000);
- gdk_pixbuf_composite (info->icon_pixbuf, pixbuf,
+ gdk_pixbuf_composite (icon_pixbuf, pixbuf,
ref_x - icon_x, ref_y - icon_y,
icon_width, icon_height,
ref_x - icon_x, ref_y - icon_y,
@@ -913,6 +1044,7 @@ gtk_drag_get_cursor (GdkDisplay *display,
}
g_object_unref (cursor_pixbuf);
+ g_object_unref (icon_pixbuf);
if (info->drag_cursors[i] != NULL)
return info->drag_cursors[i];
@@ -930,15 +1062,16 @@ gtk_drag_update_cursor (GtkDragSourceInfo *info)
if (!info->have_grab)
return;
- for (i = 0 ; i < n_drag_cursors - 1; i++)
+ for (i = 0 ; i < G_N_ELEMENTS (drag_cursors) - 1; i++)
if (info->cursor == drag_cursors[i].cursor ||
info->cursor == info->drag_cursors[i])
break;
- if (i == n_drag_cursors)
+ if (i == G_N_ELEMENTS (drag_cursors))
return;
- cursor = gtk_drag_get_cursor (gdk_cursor_get_display (info->cursor),
+ cursor = gtk_drag_get_cursor (info->widget,
+ gdk_cursor_get_display (info->cursor),
drag_cursors[i].action, info);
if (cursor != info->cursor)
@@ -961,12 +1094,22 @@ gtk_drag_update_cursor (GtkDragSourceInfo *info)
/**
* gtk_drag_get_data: (method)
- * @widget: a #GtkWidget
- * @context: drag context
- * @target: format to retrieve the data in.
- * @time_: timestamp of triggering event.
+ * @widget: the widget that will receive the
+ * #GtkWidget::drag-data-received signal.
+ * @context: the drag context
+ * @target: the target (form of the data) to retrieve.
+ * @time_: a timestamp for retrieving the data. This will
+ * generally be the time received in a #GtkWidget::drag-motion"
+ * or #GtkWidget::drag-drop" signal.
*
- * Get the data for a drag or drop
+ * Gets the data associated with a drag. When the data
+ * is received or the retrieval fails, GTK+ will emit a
+ * #GtkWidget::drag-data-received signal. Failure of the retrieval
+ * is indicated by the length field of the @selection_data
+ * signal parameter being negative. However, when gtk_drag_get_data()
+ * is called implicitely because the %GTK_DEST_DEFAULT_DROP was set,
+ * then the widget will not receive notification of failed
+ * drops.
*/
void
gtk_drag_get_data (GtkWidget *widget,
@@ -997,7 +1140,7 @@ gtk_drag_get_data (GtkWidget *widget,
/**
- * gtk_drag_get_source_widget:
+ * gtk_drag_get_source_widget: (method)
* @context: a (destination side) drag context
*
* Determines the source widget for a drag.
@@ -1032,17 +1175,17 @@ gtk_drag_get_source_widget (GdkDragContext *context)
return NULL;
}
-/*************************************************************
- * gtk_drag_finish:
- * Notify the drag source that the transfer of data
- * is complete.
- * arguments:
- * context: The drag context for this drag
- * success: Was the data successfully transferred?
- * time: The timestamp to use when notifying the destination.
- * results:
- *************************************************************/
-
+/**
+ * gtk_drag_finish: (method)
+ * @context: the drag context.
+ * @success: a flag indicating whether the drop was successful
+ * @del: a flag indicating whether the source should delete the
+ * original data. (This should be %TRUE for a move)
+ * @time_: the timestamp from the #GtkWidget::drag-drop signal.
+ *
+ * Informs the drag source that the drop is finished, and
+ * that the data of the drag will no longer be required.
+ */
void
gtk_drag_finish (GdkDragContext *context,
gboolean success,
@@ -1123,11 +1266,14 @@ gtk_drag_highlight_draw (GtkWidget *widget,
return FALSE;
}
- /**
+/**
* gtk_drag_highlight: (method)
- * @widget: a #GtkWidget
+ * @widget: a widget to highlight
*
- * Highlight the given widget in the default manner.
+ * Draws a highlight around a widget. This will attach
+ * handlers to #GtkWidget::draw, so the highlight
+ * will continue to be displayed until gtk_drag_unhighlight()
+ * is called.
*/
void
gtk_drag_highlight (GtkWidget *widget)
@@ -1141,11 +1287,12 @@ gtk_drag_highlight (GtkWidget *widget)
gtk_widget_queue_draw (widget);
}
- /**
+/**
* gtk_drag_unhighlight: (method)
- * @widget: a #GtkWidget
+ * @widget: a widget to remove the highlight from.
*
- * Refresh the given widget to remove the highlight.
+ * Removes a highlight set by gtk_drag_highlight() from
+ * a widget.
*/
void
gtk_drag_unhighlight (GtkWidget *widget)
@@ -1208,22 +1355,22 @@ gtk_drag_dest_set_internal (GtkWidget *widget,
*
* 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
+ * (#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
+ * 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
+ * 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
+ * #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
@@ -1274,13 +1421,14 @@ gtk_drag_dest_set (GtkWidget *widget,
/**
* gtk_drag_dest_set_proxy: (method)
* @widget: a #GtkWidget
- * @proxy_window: window to which forward drag events
- * @protocol: Drag protocol which the dest widget accepts
- * @use_coordinates: If true, send the same coordinates to the
- * destination, because it is a embedded
- * subwindow.
+ * @proxy_window: the window to which to forward drag events
+ * @protocol: the drag protocol which the @proxy_window accepts
+ * (You can use gdk_drag_get_protocol() to determine this)
+ * @use_coordinates: If %TRUE, send the same coordinates to the
+ * destination, because it is an embedded
+ * subwindow.
*
- * Set up this widget to proxy drags elsewhere.
+ * Sets this widget as a proxy for drops to another window.
*/
void
gtk_drag_dest_set_proxy (GtkWidget *widget,
@@ -1310,11 +1458,13 @@ gtk_drag_dest_set_proxy (GtkWidget *widget,
gtk_drag_dest_set_internal (widget, site);
}
- /**
+/**
* gtk_drag_dest_unset: (method)
* @widget: a #GtkWidget
*
- * Unregister this widget as a drag target.
+ * Clears information about a drop destination set with
+ * gtk_drag_dest_set(). The widget will no longer receive
+ * notification of drags.
*/
void
gtk_drag_dest_unset (GtkWidget *widget)
@@ -1479,10 +1629,10 @@ gtk_drag_dest_add_uri_targets (GtkWidget *widget)
* gtk_drag_dest_set_track_motion: (method)
* @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.
+ *
+ * Tells the widget to emit #GtkWidget::drag-motion and
+ * #GtkWidget::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.
@@ -1507,11 +1657,12 @@ gtk_drag_dest_set_track_motion (GtkWidget *widget,
/**
* gtk_drag_dest_get_track_motion: (method)
* @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
+ * emit #GtkWidget::drag-motion signals.
+ *
+ * Return Value: %TRUE if the widget always emits
+ * #GtkWidget::drag-motion events
*
* Since: 2.10
**/
@@ -1878,8 +2029,7 @@ gtk_drag_find_widget (GtkWidget *widget,
g_object_add_weak_pointer (G_OBJECT (parent), (gpointer *) &parent);
}
- g_list_foreach (hierarchy, (GFunc) g_object_unref, NULL);
- g_list_free (hierarchy);
+ g_list_free_full (hierarchy, g_object_unref);
if (found)
return TRUE;
@@ -2284,6 +2434,22 @@ gtk_drag_dest_drop (GtkWidget *widget,
* Source side *
***************/
+static GtkIconHelper *
+gtk_drag_source_site_get_icon_helper (GtkDragSourceSite *site)
+{
+ GtkIconHelper *helper;
+
+ if (site)
+ helper = g_object_ref (site->icon_helper);
+ else
+ helper = _gtk_icon_helper_new ();
+
+ if (_gtk_icon_helper_get_is_empty (helper))
+ _gtk_icon_helper_set_stock_id (helper, GTK_STOCK_DND, GTK_ICON_SIZE_DND);
+
+ return helper;
+}
+
/* Like GtkDragBegin, but also takes a GtkDragSourceSite,
* so that we can set the icon from the source site information
*/
@@ -2312,7 +2478,8 @@ gtk_drag_begin_internal (GtkWidget *widget,
gtk_drag_get_event_actions (event, button, actions,
&suggested_action, &possible_actions);
- cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget),
+ cursor = gtk_drag_get_cursor (widget,
+ gtk_widget_get_display (widget),
suggested_action,
NULL);
@@ -2419,41 +2586,16 @@ gtk_drag_begin_internal (GtkWidget *widget,
* 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_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;
- }
- }
+ if (!info->icon_window && !info->icon_helper)
+ info->icon_helper = gtk_drag_source_site_get_icon_helper (site);
/* We need to composite the icon into the cursor, if we are
* not using an icon window.
*/
- if (info->icon_pixbuf)
+ if (info->icon_helper)
{
- cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget),
+ cursor = gtk_drag_get_cursor (widget,
+ gtk_widget_get_display (widget),
suggested_action,
info);
@@ -2515,18 +2657,18 @@ gtk_drag_begin_internal (GtkWidget *widget,
* 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.
+ * 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
+ * 1. During a #GtkWidget::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.
+ * that you have in your #GtkWidget::button-press-event handler.
*
- * 2. During a motion-notify-event handler, if you want to start a drag
+ * 2. During a #GtkWidget::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.
+ * Pass the @event that you have in your #GtkWidget::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
@@ -2589,8 +2731,7 @@ gtk_drag_source_set (GtkWidget *widget,
else
{
site = g_slice_new0 (GtkDragSourceSite);
-
- site->icon_type = GTK_IMAGE_EMPTY;
+ site->icon_helper = _gtk_icon_helper_new ();
g_signal_connect (widget, "button-press-event",
G_CALLBACK (gtk_drag_source_event_cb),
@@ -2618,7 +2759,7 @@ gtk_drag_source_set (GtkWidget *widget,
* gtk_drag_source_unset: (method)
* @widget: a #GtkWidget
*
- * Unregister this widget as a drag source.
+ * Undoes the effects of gtk_drag_source_set().
*/
void
gtk_drag_source_unset (GtkWidget *widget)
@@ -2778,29 +2919,6 @@ gtk_drag_source_add_uri_targets (GtkWidget *widget)
gtk_target_list_unref (target_list);
}
-static void
-gtk_drag_source_unset_icon (GtkDragSourceSite *site)
-{
- switch (site->icon_type)
- {
- case GTK_IMAGE_EMPTY:
- break;
- case GTK_IMAGE_PIXBUF:
- g_object_unref (site->icon_data.pixbuf.pixbuf);
- break;
- case GTK_IMAGE_STOCK:
- 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();
- break;
- }
- site->icon_type = GTK_IMAGE_EMPTY;
-}
-
/**
* gtk_drag_source_set_icon_pixbuf: (method)
* @widget: a #GtkWidget
@@ -2823,10 +2941,7 @@ gtk_drag_source_set_icon_pixbuf (GtkWidget *widget,
g_return_if_fail (site != NULL);
g_object_ref (pixbuf);
- gtk_drag_source_unset_icon (site);
-
- site->icon_type = GTK_IMAGE_PIXBUF;
- site->icon_data.pixbuf.pixbuf = pixbuf;
+ _gtk_icon_helper_set_pixbuf (site->icon_helper, pixbuf);
}
/**
@@ -2848,11 +2963,8 @@ gtk_drag_source_set_icon_stock (GtkWidget *widget,
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_STOCK;
- site->icon_data.stock.stock_id = g_strdup (stock_id);
+ _gtk_icon_helper_set_stock_id (site->icon_helper, stock_id, GTK_ICON_SIZE_DND);
}
/**
@@ -2877,10 +2989,32 @@ gtk_drag_source_set_icon_name (GtkWidget *widget,
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
g_return_if_fail (site != NULL);
- gtk_drag_source_unset_icon (site);
+ _gtk_icon_helper_set_icon_name (site->icon_helper, icon_name, GTK_ICON_SIZE_DND);
+}
- site->icon_type = GTK_IMAGE_ICON_NAME;
- site->icon_data.name.icon_name = g_strdup (icon_name);
+/**
+ * gtk_drag_source_set_icon_gicon: (method)
+ * @widget: a #GtkWidget
+ * @icon: A #GIcon
+ *
+ * Sets the icon that will be used for drags from a particular source
+ * to @icon. See the docs for #GtkIconTheme for more details.
+ *
+ * Since: 3.2
+ **/
+void
+gtk_drag_source_set_icon_gicon (GtkWidget *widget,
+ GIcon *icon)
+{
+ GtkDragSourceSite *site;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (icon != NULL);
+
+ site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
+ g_return_if_fail (site != NULL);
+
+ _gtk_icon_helper_set_gicon (site->icon_helper, icon, GTK_ICON_SIZE_DND);
}
static void
@@ -2900,6 +3034,7 @@ gtk_drag_get_icon (GtkDragSourceInfo *info,
gint save_hot_x, save_hot_y;
gboolean save_destroy_icon;
GtkWidget *save_icon_window;
+ GtkIconHelper *helper;
/* HACK to get the appropriate icon
*/
@@ -2909,14 +3044,18 @@ gtk_drag_get_icon (GtkDragSourceInfo *info,
save_destroy_icon = info->destroy_icon;
info->icon_window = NULL;
- set_icon_stock_pixbuf (info->context,
- GTK_STOCK_DND, NULL, -2, -2, TRUE);
+
+ helper = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_stock_id (helper, GTK_STOCK_DND, GTK_ICON_SIZE_DND);
+ set_icon_helper (info->context, helper, -2, -2, TRUE);
info->fallback_icon = info->icon_window;
info->icon_window = save_icon_window;
info->hot_x = save_hot_x;
info->hot_y = save_hot_y;
info->destroy_icon = save_destroy_icon;
+
+ g_object_unref (helper);
}
gtk_widget_hide (info->icon_window);
@@ -2986,18 +3125,15 @@ gtk_drag_set_icon_window (GdkDragContext *context,
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;
- }
+ if (widget && info->icon_helper)
+ g_clear_object (&info->icon_helper);
gtk_drag_update_cursor (info);
gtk_drag_update_icon (info);
}
/**
- * gtk_drag_set_icon_widget:
+ * gtk_drag_set_icon_widget: (method)
* @context: the context for a drag. (This must be called
with a context for the source side of a drag)
* @widget: a toplevel window to use as an icon.
@@ -3023,12 +3159,14 @@ gtk_drag_set_icon_widget (GdkDragContext *context,
static void
icon_window_realize (GtkWidget *window,
- GdkPixbuf *pixbuf)
+ GtkIconHelper *helper)
{
cairo_surface_t *surface;
cairo_pattern_t *pattern;
cairo_t *cr;
+ GdkPixbuf *pixbuf;
+ pixbuf = _gtk_icon_helper_ensure_pixbuf (helper, gtk_widget_get_style_context (window));
surface = gdk_window_create_similar_surface (gtk_widget_get_window (window),
CAIRO_CONTENT_COLOR,
gdk_pixbuf_get_width (pixbuf),
@@ -3069,15 +3207,16 @@ icon_window_realize (GtkWidget *window,
cairo_surface_destroy (surface);
}
+
+ g_object_unref (pixbuf);
}
static void
-set_icon_stock_pixbuf (GdkDragContext *context,
- const gchar *stock_id,
- GdkPixbuf *pixbuf,
- gint hot_x,
- gint hot_y,
- gboolean force_window)
+set_icon_helper (GdkDragContext *context,
+ GtkIconHelper *helper,
+ gint hot_x,
+ gint hot_y,
+ gboolean force_window)
{
GtkWidget *window;
gint width, height;
@@ -3085,8 +3224,7 @@ set_icon_stock_pixbuf (GdkDragContext *context,
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);
+ g_return_if_fail (helper != NULL);
screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
@@ -3098,25 +3236,10 @@ set_icon_stock_pixbuf (GdkDragContext *context,
gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
gtk_widget_set_app_paintable (window, TRUE);
- if (stock_id)
- {
- pixbuf = gtk_widget_render_icon_pixbuf (window, stock_id,
- GTK_ICON_SIZE_DND);
-
- if (!pixbuf)
- {
- g_warning ("Cannot load drag icon from stock_id %s", stock_id);
- gtk_widget_destroy (window);
- return;
- }
-
- }
- else
- g_object_ref (pixbuf);
-
display = gdk_window_get_display (gdk_drag_context_get_source_window (context));
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
+ _gtk_icon_helper_get_size (helper,
+ gtk_widget_get_style_context (window),
+ &width, &height);
if (!force_window &&
gtk_drag_can_use_rgba_cursor (display, width + 2, height + 2))
@@ -3127,9 +3250,9 @@ set_icon_stock_pixbuf (GdkDragContext *context,
info = gtk_drag_get_source_info (context, FALSE);
- if (info->icon_pixbuf)
- g_object_unref (info->icon_pixbuf);
- info->icon_pixbuf = pixbuf;
+ if (info->icon_helper)
+ g_object_unref (info->icon_helper);
+ info->icon_helper = g_object_ref (helper);
gtk_drag_set_icon_window (context, NULL, hot_x, hot_y, TRUE);
}
@@ -3139,7 +3262,7 @@ set_icon_stock_pixbuf (GdkDragContext *context,
g_signal_connect_closure (window, "realize",
g_cclosure_new (G_CALLBACK (icon_window_realize),
- pixbuf,
+ g_object_ref (helper),
(GClosureNotify)g_object_unref),
FALSE);
@@ -3148,7 +3271,7 @@ set_icon_stock_pixbuf (GdkDragContext *context,
}
/**
- * gtk_drag_set_icon_pixbuf:
+ * gtk_drag_set_icon_pixbuf: (method)
* @context: the context for a drag. (This must be called
* with a context for the source side of a drag)
* @pixbuf: the #GdkPixbuf to use as the drag icon.
@@ -3163,14 +3286,20 @@ gtk_drag_set_icon_pixbuf (GdkDragContext *context,
gint hot_x,
gint hot_y)
{
+ GtkIconHelper *icon;
+
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
- set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y, FALSE);
+ icon = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_pixbuf (icon, pixbuf);
+ set_icon_helper (context, icon, hot_x, hot_y, FALSE);
+
+ g_object_unref (icon);
}
/**
- * gtk_drag_set_icon_stock:
+ * gtk_drag_set_icon_stock: (method)
* @context: the context for a drag. (This must be called
* with a context for the source side of a drag)
* @stock_id: the ID of the stock icon to use for the drag.
@@ -3185,10 +3314,16 @@ gtk_drag_set_icon_stock (GdkDragContext *context,
gint hot_x,
gint hot_y)
{
+ GtkIconHelper *icon;
+
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (stock_id != NULL);
-
- set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y, FALSE);
+
+ icon = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_stock_id (icon, stock_id, GTK_ICON_SIZE_DND);
+ set_icon_helper (context, icon, hot_x, hot_y, FALSE);
+
+ g_object_unref (icon);
}
/* XXX: This function is in gdk, too. Should it be in Cairo? */
@@ -3229,7 +3364,7 @@ _gtk_cairo_surface_extents (cairo_surface_t *surface,
}
/**
- * gtk_drag_set_icon_surface:
+ * gtk_drag_set_icon_surface: (method)
* @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
@@ -3319,7 +3454,7 @@ gtk_drag_set_icon_surface (GdkDragContext *context,
}
/**
- * gtk_drag_set_icon_name:
+ * gtk_drag_set_icon_name: (method)
* @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
@@ -3340,38 +3475,52 @@ gtk_drag_set_icon_name (GdkDragContext *context,
gint hot_x,
gint hot_y)
{
- GdkScreen *screen;
- GtkSettings *settings;
- GtkIconTheme *icon_theme;
- GdkPixbuf *pixbuf;
- gint width, height, icon_size;
+ GtkIconHelper *icon;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
g_return_if_fail (icon_name != NULL);
- screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
- 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);
+ icon = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_icon_name (icon, icon_name, GTK_ICON_SIZE_DND);
+ set_icon_helper (context, icon, hot_x, hot_y, FALSE);
+
+ g_object_unref (icon);
}
/**
- * gtk_drag_set_icon_default:
+ * gtk_drag_set_icon_gicon: (method)
+ * @context: the context for a drag. (This must be called
+ * with a context for the source side of a drag)
+ * @icon: a #GIcon
+ * @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 the given @icon. See the
+ * documentation for gtk_drag_set_icon_name() for more details about
+ * using icons in drag and drop.
+ *
+ * Since: 3.2
+ **/
+void
+gtk_drag_set_icon_gicon (GdkDragContext *context,
+ GIcon *icon,
+ gint hot_x,
+ gint hot_y)
+{
+ GtkIconHelper *helper;
+
+ g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+ g_return_if_fail (icon != NULL);
+
+ helper = _gtk_icon_helper_new ();
+ _gtk_icon_helper_set_gicon (helper, icon, GTK_ICON_SIZE_DND);
+ set_icon_helper (context, helper, hot_x, hot_y, FALSE);
+
+ g_object_unref (helper);
+}
+
+/**
+ * gtk_drag_set_icon_default: (method)
* @context: the context for a drag. (This must be called
with a context for the source side of a drag)
*
@@ -3443,7 +3592,8 @@ _gtk_drag_source_handle_event (GtkWidget *widget,
}
else if (info->have_grab)
{
- cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget),
+ cursor = gtk_drag_get_cursor (widget,
+ gtk_widget_get_display (widget),
gdk_drag_context_get_selected_action (event->dnd.context),
info);
if (info->cursor != cursor)
@@ -3582,8 +3732,8 @@ gtk_drag_drop_finished (GtkDragSourceInfo *info,
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);
+ set_icon_helper (info->context, info->icon_helper,
+ 0, 0, TRUE);
gtk_drag_update_icon (info);
@@ -3746,7 +3896,7 @@ gtk_drag_source_site_destroy (gpointer data)
if (site->target_list)
gtk_target_list_unref (site->target_list);
- gtk_drag_source_unset_icon (site);
+ g_clear_object (&site->icon_helper);
g_slice_free (GtkDragSourceSite, site);
}
@@ -3879,7 +4029,7 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
{
gint i;
- for (i = 0; i < n_drag_cursors; i++)
+ for (i = 0; i < G_N_ELEMENTS (drag_cursors); i++)
{
if (info->drag_cursors[i] != NULL)
{
@@ -3889,12 +4039,7 @@ gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
}
gtk_drag_remove_icon (info);
-
- if (info->icon_pixbuf)
- {
- g_object_unref (info->icon_pixbuf);
- info->icon_pixbuf = NULL;
- }
+ g_clear_object (&info->icon_helper);
g_signal_handlers_disconnect_by_func (info->ipc_widget,
gtk_drag_grab_broken_event_cb,
@@ -4198,7 +4343,7 @@ gtk_drag_key_cb (GtkWidget *widget,
if (event->type == GDK_KEY_PRESS)
{
switch (event->keyval)
-{
+ {
case GDK_KEY_Escape:
gtk_drag_cancel (info, GTK_DRAG_RESULT_USER_CANCELLED, event->time);
return TRUE;