#include "config.h"
+#include <math.h>
#include <stdlib.h>
#include <string.h>
-#include "gdkconfig.h"
-
-#include "gdk/gdkkeysyms.h"
+#include "gdk/gdk.h"
#ifdef GDK_WINDOWING_X11
#include <X11/Xlib.h>
#include "gtkwindow.h"
#include "gtkintl.h"
#include "gtkdndcursors.h"
+#include "gtkselectionprivate.h"
static GSList *source_widgets = NULL;
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;
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
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,
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));
}
GdkWindow *window, *root;
gint keycode;
- window = widget->window;
+ window = gtk_widget_get_window (widget);
root = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
gdk_error_trap_push ();
GdkWindow *window, *root;
gint keycode;
- window = widget->window;
+ 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));
GdkDevice *device,
guint32 time)
{
- gdk_device_grab (device, widget->window,
+ gdk_device_grab (device,
+ gtk_widget_get_window (widget),
GDK_OWNERSHIP_APPLICATION, FALSE,
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
NULL, time);
ungrab_dnd_keys (widget, keyboard, GDK_CURRENT_TIME);
}
- if (window->group)
- gtk_window_group_remove_window (window->group, window);
+ 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"),
GdkDevice *pointer;
pointer = gdk_drag_context_get_device (info->context);
- gdk_device_grab (pointer, info->ipc_widget->window,
+ 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);
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (!context->is_source);
selection_widget = gtk_drag_get_ipc_widget (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)
{
GSList *tmp_list;
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
- g_return_val_if_fail (!context->is_source, NULL);
tmp_list = source_widgets;
while (tmp_list)
{
GtkWidget *ipc_widget = tmp_list->data;
-
- if (ipc_widget->window == context->source_window)
+
+ if (gtk_widget_get_window (ipc_widget) == gdk_drag_context_get_source_window (context))
{
GtkDragSourceInfo *info;
info = g_object_get_data (G_OBJECT (ipc_widget), "gtk-info");
GdkAtom target = GDK_NONE;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (!context->is_source);
if (success && del)
{
target = gdk_atom_intern_static_string ("DELETE");
}
- else if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ else if (gdk_drag_context_get_protocol (context) == GDK_DRAG_PROTO_MOTIF)
{
target = gdk_atom_intern_static_string (success ?
"XmTRANSFER_SUCCESS" :
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 (gdk_drag_context_get_source_window (context)));
g_object_ref (context);
}
/*************************************************************
- * gtk_drag_highlight_expose:
+ * gtk_drag_highlight_draw:
* Callback for expose_event for highlighted widgets.
* arguments:
* widget:
*************************************************************/
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_is_drawable (widget))
- {
- cairo_t *cr;
-
- if (!gtk_widget_get_has_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,
- &event->area, 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;
}
{
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);
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);
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;
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;
case GDK_DRAG_MOTION:
case GDK_DROP_START:
{
+ GdkWindow *window;
gint tx, ty;
gboolean found;
}
}
+ window = gtk_widget_get_window (toplevel);
+
#ifdef GDK_WINDOWING_X11
/* Hackaround for: http://bugzilla.gnome.org/show_bug.cgi?id=136112
*
* 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);
+ gdk_window_get_position (window, &tx, &ty);
found = gtk_drag_find_widget (toplevel,
context,
else if (event->type == GDK_DROP_START && !info->proxy_source)
{
gdk_drop_reply (context, found, event->dnd.time);
- if ((context->protocol == GDK_DRAG_PROTO_MOTIF) && !found)
+ if ((gdk_drag_context_get_protocol (context) == GDK_DRAG_PROTO_MOTIF) && !found)
gtk_drag_finish (context, FALSE, FALSE, event->dnd.time);
}
}
* @context: drag context
* @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
+ *
+ * Looks for a match between the supported targets of @context and the
* @dest_target_list, returning the first matching target, otherwise
* returning %GDK_NONE. @dest_target_list should usually be the return
* value from gtk_drag_dest_get_target_list(), but some widgets may
* 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
+ *
+ * Return value: first target that the source offers and the dest can
+ * accept, or %GDK_NONE
**/
GdkAtom
gtk_drag_dest_find_target (GtkWidget *widget,
g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE);
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
- g_return_val_if_fail (!context->is_source, GDK_NONE);
source_widget = gtk_drag_get_source_widget (context);
while (tmp_target)
{
GtkTargetPair *pair = tmp_target->data;
- tmp_source = context->targets;
+ tmp_source = gdk_drag_context_list_targets (context);
while (tmp_source)
{
if (tmp_source->data == GUINT_TO_POINTER (pair->target))
GdkDragContext *context;
GtkDragDestInfo *info;
GtkWidget *drop_widget;
+ GdkAtom target;
drop_widget = data;
info = gtk_drag_get_dest_info (context, FALSE);
if (info->proxy_data &&
- info->proxy_data->target == selection_data->target)
+ gtk_selection_data_get_target (info->proxy_data) == gtk_selection_data_get_target (selection_data))
{
gtk_selection_data_set (info->proxy_data,
- selection_data->type,
- selection_data->format,
- selection_data->data,
- selection_data->length);
+ gtk_selection_data_get_data_type (selection_data),
+ gtk_selection_data_get_format (selection_data),
+ gtk_selection_data_get_data (selection_data),
+ gtk_selection_data_get_length (selection_data));
gtk_main_quit ();
return;
}
- if (selection_data->target == gdk_atom_intern_static_string ("DELETE"))
+ target = gtk_selection_data_get_target (selection_data);
+ if (target == gdk_atom_intern_static_string ("DELETE"))
{
gtk_drag_finish (context, TRUE, FALSE, time);
}
- else if ((selection_data->target == gdk_atom_intern_static_string ("XmTRANSFER_SUCCESS")) ||
- (selection_data->target == gdk_atom_intern_static_string ("XmTRANSFER_FAILURE")))
+ else if ((target == gdk_atom_intern_static_string ("XmTRANSFER_SUCCESS")) ||
+ (target == gdk_atom_intern_static_string ("XmTRANSFER_FAILURE")))
{
/* Do nothing */
}
guint target_info;
if (gtk_target_list_find (site->target_list,
- selection_data->target,
+ target,
&target_info))
{
if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
- selection_data->length >= 0)
+ gtk_selection_data_get_length (selection_data) >= 0)
g_signal_emit_by_name (drop_widget,
"drag-data-received",
context, info->drop_x, info->drop_y,
{
gtk_drag_finish (context,
- (selection_data->length >= 0),
- (context->action == GDK_ACTION_MOVE),
+ (gtk_selection_data_get_length (selection_data) >= 0),
+ (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
time);
}
}
static void
-gtk_drag_proxy_begin (GtkWidget *widget,
+gtk_drag_proxy_begin (GtkWidget *widget,
GtkDragDestInfo *dest_info,
guint32 time)
{
}
ipc_widget = gtk_drag_get_ipc_widget (widget);
- context = gdk_drag_begin (ipc_widget->window,
- dest_info->context->targets);
+ context = gdk_drag_begin (gtk_widget_get_window (ipc_widget),
+ gdk_drag_context_list_targets (dest_info->context));
source_info = gtk_drag_get_source_info (context, TRUE);
source_info->widget = g_object_ref (widget);
source_info->target_list = gtk_target_list_new (NULL, 0);
- tmp_list = dest_info->context->targets;
+ tmp_list = gdk_drag_context_list_targets (dest_info->context);
while (tmp_list)
{
- gtk_target_list_add (source_info->target_list,
+ gtk_target_list_add (source_info->target_list,
GDK_POINTER_TO_ATOM (tmp_list->data), 0, 0);
tmp_list = tmp_list->next;
}
static void
gtk_drag_dest_info_destroy (gpointer data)
{
- GtkDragDestInfo *info = data;
-
- g_free (info);
+ g_slice_free (GtkDragDestInfo, data);
}
static GtkDragDestInfo *
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;
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel))
- gdk_window_register_dnd (toplevel->window);
+ gdk_window_register_dnd (gtk_widget_get_window (toplevel));
}
static void
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
if (gtk_widget_is_toplevel (toplevel) && gtk_widget_get_realized (toplevel))
- gdk_window_register_dnd (toplevel->window);
+ gdk_window_register_dnd (gtk_widget_get_window (toplevel));
}
static void
if (site->target_list)
gtk_target_list_unref (site->target_list);
- g_free (site);
+ g_slice_free (GtkDragDestSite, site);
}
/*
{
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);
dest_window, proto,
current_event->dnd.x_root,
current_event->dnd.y_root,
- context->suggested_action,
- context->actions, time);
+ gdk_drag_context_get_suggested_action (context),
+ gdk_drag_context_get_actions (context),
+ time);
if (!site->proxy_window && dest_window)
g_object_unref (dest_window);
if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
{
- if (context->suggested_action & site->actions)
- action = context->suggested_action;
+ if (gdk_drag_context_get_suggested_action (context) & site->actions)
+ action = gdk_drag_context_get_suggested_action (context);
else
{
gint i;
for (i = 0; i < 8; i++)
{
if ((site->actions & (1 << i)) &&
- (context->actions & (1 << i)))
+ (gdk_drag_context_get_actions (context) & (1 << i)))
{
action = (1 << i);
break;
if (site->do_proxy)
{
if (info->proxy_source ||
- (info->context->protocol == GDK_DRAG_PROTO_ROOTWIN))
+ (gdk_drag_context_get_protocol (info->context) == GDK_DRAG_PROTO_ROOTWIN))
{
gtk_drag_drop (info->proxy_source, time);
}
{
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);
dest_window, proto,
current_event->dnd.x_root,
current_event->dnd.y_root,
- context->suggested_action,
- context->actions, time);
+ gdk_drag_context_get_suggested_action (context),
+ gdk_drag_context_get_actions (context),
+ time);
if (!site->proxy_window && dest_window)
g_object_unref (dest_window);
GtkWidget *ipc_widget;
GdkCursor *cursor;
GdkDevice *pointer, *keyboard;
+ GdkWindow *ipc_window;
pointer = keyboard = NULL;
ipc_widget = gtk_drag_get_ipc_widget (widget);
pointer = gdk_event_get_device (event);
- if (pointer->source == GDK_SOURCE_KEYBOARD)
+ if (gdk_device_get_source (pointer) == GDK_SOURCE_KEYBOARD)
{
keyboard = pointer;
pointer = gdk_device_get_associated_device (keyboard);
if (!pointer)
return NULL;
- if (gdk_device_grab (pointer, ipc_widget->window,
+ 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,
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);
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,
if (cursor != info->cursor)
{
- gdk_device_grab (pointer, widget->window,
+ gdk_device_grab (pointer, gtk_widget_get_window (widget),
GDK_OWNERSHIP_APPLICATION, FALSE,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
* @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
* 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:
+ * 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.
+ * 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.
+ * 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.
- *
+ * (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 *
}
else
{
- site = g_new0 (GtkDragSourceSite, 1);
+ site = g_slice_new0 (GtkDragSourceSite);
site->icon_type = GTK_IMAGE_EMPTY;
*************************************************************/
void
-gtk_drag_source_unset (GtkWidget *widget)
+gtk_drag_source_unset (GtkWidget *widget)
{
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;
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: (allow-none): the transparency mask for an image.
- *
- * Sets the icon that will be used for drags from a particular widget
- * from a pixmap/mask. GTK+ retains references for the arguments, and
- * 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;
}
/**
info->cur_y - hot_y);
if (gtk_widget_get_visible (icon_window))
- gdk_window_raise (icon_window->window);
+ gdk_window_raise (gtk_widget_get_window (icon_window));
else
gtk_widget_show (icon_window);
}
gint hot_y)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (GTK_IS_WIDGET (widget));
gtk_drag_set_icon_window (context, widget, hot_x, hot_y, FALSE);
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);
}
}
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 (gdk_drag_context_get_source_window (context));
- /* 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 (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)
{
else
g_object_ref (pixbuf);
- display = gdk_drawable_get_display (context->source_window);
+ display = gdk_window_get_display (gdk_drag_context_get_source_window (context));
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
gint hot_y)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y, FALSE);
gint hot_y)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (stock_id != NULL);
set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y, 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: (allow-none): the transparency mask for the icon or %NULL for none.
- * @hot_x: the X offset within @pixmap of the hotspot.
- * @hot_y: the Y offset within @pixmap of the hotspot.
- *
- * 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);
- 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_cairo_surface_extents (surface, &extents);
- gtk_widget_push_colormap (colormap);
+
+ screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
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;
+
+ 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, hot_x, hot_y, TRUE);
+ gtk_drag_set_icon_window (context, window, extents.x, extents.y, TRUE);
}
/**
gint width, height, icon_size;
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
g_return_if_fail (icon_name != NULL);
- screen = gdk_drawable_get_screen (context->source_window);
+ 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);
gtk_drag_set_icon_default (GdkDragContext *context)
{
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
- g_return_if_fail (context->is_source);
gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2);
}
{
if (info->proxy_dest->proxy_drop_wait)
{
- gboolean result = context->action != 0;
+ gboolean result = gdk_drag_context_get_selected_action (context) != 0;
/* Aha - we can finally pass the MOTIF DROP on... */
gdk_drop_reply (info->proxy_dest->context, result, info->proxy_dest->proxy_drop_time);
else
{
gdk_drag_status (info->proxy_dest->context,
- event->dnd.context->action,
+ gdk_drag_context_get_selected_action (event->dnd.context),
event->dnd.time);
}
}
else if (info->have_grab)
{
cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget),
- event->dnd.context->action,
+ gdk_drag_context_get_selected_action (event->dnd.context),
info);
if (info->cursor != cursor)
{
GdkDevice *pointer;
pointer = gdk_drag_context_get_device (context);
- gdk_device_grab (pointer, widget->window,
+ 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);
tmp_list = tmp_list->next;
}
- if (info->context->protocol == GDK_DRAG_PROTO_MOTIF)
+ if (gdk_drag_context_get_protocol (info->context) == GDK_DRAG_PROTO_MOTIF)
{
gtk_selection_add_target (info->ipc_widget,
selection,
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);
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.
*/
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;
gtk_drag_drop (GtkDragSourceInfo *info,
guint32 time)
{
- if (info->context->protocol == GDK_DRAG_PROTO_ROOTWIN)
+ if (gdk_drag_context_get_protocol (info->context) == GDK_DRAG_PROTO_ROOTWIN)
{
GtkSelectionData selection_data;
GList *tmp_list;
gtk_target_list_unref (site->target_list);
gtk_drag_source_unset_icon (site);
- g_free (site);
+ g_slice_free (GtkDragSourceSite, site);
}
static void
info->proxy_dest->proxy_data = selection_data;
gtk_drag_get_data (info->widget,
info->proxy_dest->context,
- selection_data->target,
+ gtk_selection_data_get_target (selection_data),
time);
gtk_main ();
info->proxy_dest->proxy_data = NULL;
else
{
if (gtk_target_list_find (info->target_list,
- selection_data->target,
+ gtk_selection_data_get_target (selection_data),
&target_info))
{
g_signal_emit_by_name (info->widget, "drag-data-get",
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;
&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);
{
switch (event->keyval)
{
- case GDK_Escape:
+ 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_ISO_Enter:
- 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;
}
* 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_DRAG_RESULT_GRAB_BROKEN, gtk_get_current_event_time ());
if (event->button != info->button)
return FALSE;
- if ((info->context->action != 0) && (info->context->dest_window != NULL))
+ if ((gdk_drag_context_get_selected_action (info->context) != 0) &&
+ (gdk_drag_context_get_dest_window (info->context) != NULL))
{
gtk_drag_end (info, event->time);
gtk_drag_drop (info, event->time);