2008-07-01 22:57:50 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
2006-03-21 16:50:47 +00:00
|
|
|
|
* Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-03-21 16:50:47 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2010-12-09 04:07:00 +00:00
|
|
|
|
#include "gdk/gdk.h"
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
#include "gtkdnd.h"
|
2015-11-22 04:26:08 +00:00
|
|
|
|
#include "gtkdndprivate.h"
|
2006-03-21 16:50:47 +00:00
|
|
|
|
#include "gtkicontheme.h"
|
2011-02-08 07:55:25 +00:00
|
|
|
|
#include "gtkimageprivate.h"
|
2006-03-21 16:50:47 +00:00
|
|
|
|
#include "gtkinvisible.h"
|
|
|
|
|
#include "gtkmain.h"
|
|
|
|
|
#include "gtkwindow.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtkquartz.h"
|
|
|
|
|
#include "gdk/quartz/gdkquartz.h"
|
2010-12-22 14:45:44 +00:00
|
|
|
|
#include "gtkselectionprivate.h"
|
2012-12-11 00:51:31 +00:00
|
|
|
|
#include "gtksettings.h"
|
2015-11-25 19:27:21 +00:00
|
|
|
|
#include "gtkiconhelperprivate.h"
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
|
|
|
|
|
typedef struct _GtkDragDestInfo GtkDragDestInfo;
|
|
|
|
|
typedef struct _GtkDragFindData GtkDragFindData;
|
|
|
|
|
|
|
|
|
|
static void gtk_drag_find_widget (GtkWidget *widget,
|
|
|
|
|
GtkDragFindData *data);
|
|
|
|
|
static void gtk_drag_dest_site_destroy (gpointer data);
|
|
|
|
|
static void gtk_drag_dest_leave (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
guint time);
|
|
|
|
|
static GtkDragDestInfo *gtk_drag_get_dest_info (GdkDragContext *context,
|
|
|
|
|
gboolean create);
|
|
|
|
|
static void gtk_drag_source_site_destroy (gpointer data);
|
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
static GtkDragSourceInfo *gtk_drag_get_source_info (GdkDragContext *context,
|
|
|
|
|
gboolean create);
|
|
|
|
|
|
2015-07-27 13:33:32 +00:00
|
|
|
|
static void gtk_drag_drop_finished (GtkDragSourceInfo *info,
|
|
|
|
|
GtkDragResult result);
|
2015-05-31 18:52:35 +00:00
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
extern GdkDragContext *gdk_quartz_drag_source_context (); /* gdk/quartz/gdkdnd-quartz.c */
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
struct _GtkDragSourceInfo
|
|
|
|
|
{
|
2009-09-30 13:07:37 +00:00
|
|
|
|
GtkWidget *source_widget;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
GtkTargetList *target_list; /* Targets for drag data */
|
|
|
|
|
GdkDragAction possible_actions; /* Actions allowed by source */
|
|
|
|
|
GdkDragContext *context; /* drag context */
|
2009-09-30 13:07:37 +00:00
|
|
|
|
NSEvent *nsevent; /* what started it */
|
2006-03-21 16:50:47 +00:00
|
|
|
|
gint hot_x, hot_y; /* Hot spot for drag */
|
2015-07-24 13:09:48 +00:00
|
|
|
|
cairo_surface_t *icon_surface;
|
2009-09-30 13:07:37 +00:00
|
|
|
|
gboolean success;
|
|
|
|
|
gboolean delete;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkDragDestInfo
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *widget; /* Widget in which drag is in */
|
|
|
|
|
GdkDragContext *context; /* Drag context */
|
|
|
|
|
guint dropped : 1; /* Set after we receive a drop */
|
|
|
|
|
gint drop_x, drop_y; /* Position of drop */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@interface GtkDragSourceOwner : NSObject {
|
|
|
|
|
GtkDragSourceInfo *info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GtkDragSourceOwner
|
|
|
|
|
-(void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString *)type
|
|
|
|
|
{
|
|
|
|
|
GtkSelectionData selection_data;
|
|
|
|
|
|
2017-11-15 17:13:31 +00:00
|
|
|
|
selection_data.selection = NULL;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
selection_data.data = NULL;
|
2008-05-25 15:11:11 +00:00
|
|
|
|
selection_data.length = -1;
|
2012-12-30 16:09:22 +00:00
|
|
|
|
selection_data.target = gdk_quartz_pasteboard_type_to_atom_libgtk_only (type);
|
2011-07-03 23:40:03 +00:00
|
|
|
|
selection_data.display = gdk_display_get_default ();
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
if (gtk_target_list_find (info->target_list,
|
2017-11-16 21:50:37 +00:00
|
|
|
|
selection_data.target))
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
2008-08-11 13:36:15 +00:00
|
|
|
|
g_signal_emit_by_name (info->widget, "drag-data-get",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
info->context,
|
|
|
|
|
&selection_data,
|
|
|
|
|
time);
|
|
|
|
|
|
2008-05-25 15:11:11 +00:00
|
|
|
|
if (selection_data.length >= 0)
|
|
|
|
|
_gtk_quartz_set_selection_data_for_pasteboard (sender, &selection_data);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
g_free (selection_data.data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (id)initWithInfo:(GtkDragSourceInfo *)anInfo
|
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
|
{
|
|
|
|
|
info = anInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_get_data: (method)
|
|
|
|
|
* @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.
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_get_data (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
GdkAtom target,
|
|
|
|
|
guint32 time)
|
|
|
|
|
{
|
2007-11-01 08:45:30 +00:00
|
|
|
|
id <NSDraggingInfo> dragging_info;
|
|
|
|
|
NSPasteboard *pasteboard;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GtkSelectionData *selection_data;
|
|
|
|
|
GtkDragDestInfo *info;
|
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
|
2007-11-01 08:45:30 +00:00
|
|
|
|
dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
|
|
|
|
|
pasteboard = [dragging_info draggingPasteboard];
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
info = gtk_drag_get_dest_info (context, FALSE);
|
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
|
|
|
|
|
selection_data = _gtk_quartz_get_selection_data_from_pasteboard (pasteboard,
|
|
|
|
|
target, 0);
|
|
|
|
|
|
|
|
|
|
if (site && site->target_list)
|
|
|
|
|
{
|
|
|
|
|
guint target_info;
|
|
|
|
|
|
|
|
|
|
if (gtk_target_list_find (site->target_list,
|
|
|
|
|
selection_data->target,
|
|
|
|
|
&target_info))
|
|
|
|
|
{
|
|
|
|
|
if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
|
|
|
|
|
selection_data->length >= 0)
|
|
|
|
|
g_signal_emit_by_name (widget,
|
2008-08-11 13:36:15 +00:00
|
|
|
|
"drag-data-received",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
context, info->drop_x, info->drop_y,
|
|
|
|
|
selection_data,
|
|
|
|
|
target_info, time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit_by_name (widget,
|
2008-08-11 13:36:15 +00:00
|
|
|
|
"drag-data-received",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
context, info->drop_x, info->drop_y,
|
|
|
|
|
selection_data,
|
|
|
|
|
0, time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (site && site->flags & GTK_DEST_DEFAULT_DROP)
|
|
|
|
|
{
|
|
|
|
|
gtk_drag_finish (context,
|
|
|
|
|
(selection_data->length >= 0),
|
2010-12-22 14:45:44 +00:00
|
|
|
|
(gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
|
2006-03-21 16:50:47 +00:00
|
|
|
|
time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_finish (GdkDragContext *context,
|
|
|
|
|
gboolean success,
|
|
|
|
|
gboolean del,
|
|
|
|
|
guint32 time)
|
|
|
|
|
{
|
2009-09-30 13:07:37 +00:00
|
|
|
|
GtkDragSourceInfo *info;
|
|
|
|
|
GdkDragContext* source_context = gdk_quartz_drag_source_context ();
|
|
|
|
|
|
|
|
|
|
if (source_context)
|
|
|
|
|
{
|
|
|
|
|
info = gtk_drag_get_source_info (source_context, FALSE);
|
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
info->success = success;
|
|
|
|
|
info->delete = del;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_dest_info_destroy (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestInfo *info = data;
|
|
|
|
|
|
|
|
|
|
g_free (info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkDragDestInfo *
|
|
|
|
|
gtk_drag_get_dest_info (GdkDragContext *context,
|
|
|
|
|
gboolean create)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestInfo *info;
|
|
|
|
|
static GQuark info_quark = 0;
|
|
|
|
|
if (!info_quark)
|
|
|
|
|
info_quark = g_quark_from_static_string ("gtk-dest-info");
|
|
|
|
|
|
|
|
|
|
info = g_object_get_qdata (G_OBJECT (context), info_quark);
|
|
|
|
|
if (!info && create)
|
|
|
|
|
{
|
|
|
|
|
info = g_new (GtkDragDestInfo, 1);
|
|
|
|
|
info->widget = NULL;
|
|
|
|
|
info->context = context;
|
|
|
|
|
info->dropped = FALSE;
|
|
|
|
|
g_object_set_qdata_full (G_OBJECT (context), info_quark,
|
|
|
|
|
info, gtk_drag_dest_info_destroy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GQuark dest_info_quark = 0;
|
|
|
|
|
|
|
|
|
|
static GtkDragSourceInfo *
|
|
|
|
|
gtk_drag_get_source_info (GdkDragContext *context,
|
|
|
|
|
gboolean create)
|
|
|
|
|
{
|
|
|
|
|
GtkDragSourceInfo *info;
|
2006-08-08 21:18:09 +00:00
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
if (!dest_info_quark)
|
|
|
|
|
dest_info_quark = g_quark_from_static_string ("gtk-source-info");
|
|
|
|
|
|
|
|
|
|
info = g_object_get_qdata (G_OBJECT (context), dest_info_quark);
|
|
|
|
|
if (!info && create)
|
|
|
|
|
{
|
|
|
|
|
info = g_new0 (GtkDragSourceInfo, 1);
|
|
|
|
|
info->context = context;
|
|
|
|
|
g_object_set_qdata (G_OBJECT (context), dest_info_quark, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_clear_source_info (GdkDragContext *context)
|
|
|
|
|
{
|
|
|
|
|
g_object_set_qdata (G_OBJECT (context), dest_info_quark, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_get_source_widget: (method)
|
|
|
|
|
* @context: a (destination side) drag context
|
2014-11-30 21:57:22 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none):
|
2012-07-16 22:09:28 +00:00
|
|
|
|
*/
|
2009-09-30 13:07:37 +00:00
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_drag_get_source_widget (GdkDragContext *context)
|
|
|
|
|
{
|
|
|
|
|
GtkDragSourceInfo *info;
|
|
|
|
|
GdkDragContext* real_source_context = gdk_quartz_drag_source_context();
|
|
|
|
|
|
|
|
|
|
if (!real_source_context)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
info = gtk_drag_get_source_info (real_source_context, FALSE);
|
|
|
|
|
if (!info)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return info->source_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_highlight: (method)
|
|
|
|
|
* @widget: a widget to highlight
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_highlight (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2016-03-20 22:09:45 +00:00
|
|
|
|
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_DROP_ACTIVE, FALSE);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_unhighlight: (method)
|
|
|
|
|
* @widget: a widget to remove the highlight from.
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_unhighlight (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2016-03-20 22:09:45 +00:00
|
|
|
|
gtk_widget_unset_state_flags (widget, GTK_STATE_FLAG_DROP_ACTIVE);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NSWindow *
|
|
|
|
|
get_toplevel_nswindow (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
|
2010-09-13 14:39:55 +00:00
|
|
|
|
GdkWindow *window = gtk_widget_get_window (toplevel);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2010-09-13 14:39:55 +00:00
|
|
|
|
if (gtk_widget_is_toplevel (toplevel) && window)
|
|
|
|
|
return [gdk_quartz_window_get_nsview (window) window];
|
2006-03-21 16:50:47 +00:00
|
|
|
|
else
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
register_types (GtkWidget *widget, GtkDragDestSite *site)
|
|
|
|
|
{
|
|
|
|
|
if (site->target_list)
|
|
|
|
|
{
|
|
|
|
|
NSWindow *nswindow = get_toplevel_nswindow (widget);
|
2010-01-01 19:39:57 +00:00
|
|
|
|
NSSet *types;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
|
|
|
|
|
|
if (!nswindow)
|
|
|
|
|
return;
|
|
|
|
|
|
2006-07-19 18:55:27 +00:00
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
2006-03-21 16:50:47 +00:00
|
|
|
|
types = _gtk_quartz_target_list_to_pasteboard_types (site->target_list);
|
|
|
|
|
|
2010-01-01 19:39:57 +00:00
|
|
|
|
[nswindow registerForDraggedTypes:[types allObjects]];
|
2009-12-30 13:18:33 +00:00
|
|
|
|
|
|
|
|
|
[types release];
|
2006-03-21 16:50:47 +00:00
|
|
|
|
[pool release];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_dest_realized (GtkWidget *widget,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site = user_data;
|
|
|
|
|
|
|
|
|
|
register_types (widget, site);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_dest_hierarchy_changed (GtkWidget *widget,
|
|
|
|
|
GtkWidget *previous_toplevel,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site = user_data;
|
|
|
|
|
|
|
|
|
|
register_types (widget, site);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_dest_site_destroy (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site = data;
|
|
|
|
|
|
|
|
|
|
if (site->target_list)
|
|
|
|
|
gtk_target_list_unref (site->target_list);
|
|
|
|
|
|
|
|
|
|
g_free (site);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_set: (method)
|
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
|
* @flags: which types of default drag behavior to use
|
2014-02-09 22:24:06 +00:00
|
|
|
|
* @targets: (allow-none) (array length=n_targets): a pointer to an array of #GtkTargetEntrys
|
2012-07-16 22:09:28 +00:00
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_set (GtkWidget *widget,
|
|
|
|
|
GtkDestDefaults flags,
|
|
|
|
|
const GtkTargetEntry *targets,
|
|
|
|
|
gint n_targets,
|
|
|
|
|
GdkDragAction actions)
|
|
|
|
|
{
|
2006-08-08 21:18:09 +00:00
|
|
|
|
GtkDragDestSite *old_site, *site;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2006-08-08 21:18:09 +00:00
|
|
|
|
old_site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
site = g_new (GtkDragDestSite, 1);
|
|
|
|
|
site->flags = flags;
|
|
|
|
|
site->have_drag = FALSE;
|
|
|
|
|
if (targets)
|
|
|
|
|
site->target_list = gtk_target_list_new (targets, n_targets);
|
|
|
|
|
else
|
|
|
|
|
site->target_list = NULL;
|
|
|
|
|
site->actions = actions;
|
|
|
|
|
|
2006-08-08 21:18:09 +00:00
|
|
|
|
if (old_site)
|
|
|
|
|
site->track_motion = old_site->track_motion;
|
|
|
|
|
else
|
|
|
|
|
site->track_motion = FALSE;
|
|
|
|
|
|
2010-01-22 20:08:11 +00:00
|
|
|
|
gtk_drag_dest_unset (widget);
|
|
|
|
|
|
2010-03-02 06:16:02 +00:00
|
|
|
|
if (gtk_widget_get_realized (widget))
|
2006-03-21 16:50:47 +00:00
|
|
|
|
gtk_drag_dest_realized (widget, site);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (widget, "realize",
|
|
|
|
|
G_CALLBACK (gtk_drag_dest_realized), site);
|
2008-08-11 09:17:49 +00:00
|
|
|
|
g_signal_connect (widget, "hierarchy-changed",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_unset: (method)
|
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_unset (GtkWidget *widget)
|
|
|
|
|
{
|
2006-08-07 01:49:11 +00:00
|
|
|
|
GtkDragDestSite *old_site;
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2006-08-07 01:49:11 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (widget), I_("gtk-drag-dest"), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_get_target_list: (method)
|
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GtkTargetList*
|
|
|
|
|
gtk_drag_dest_get_target_list (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
|
|
|
|
|
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
|
|
|
|
|
return site ? site->target_list : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_set_target_list: (method)
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* @widget: a #GtkWidget that’s a drag destination
|
2012-07-16 22:09:28 +00:00
|
|
|
|
* @target_list: (allow-none): list of droppable targets, or %NULL for none
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_set_target_list (GtkWidget *widget,
|
|
|
|
|
GtkTargetList *target_list)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
|
|
|
|
|
if (!site)
|
|
|
|
|
{
|
|
|
|
|
g_warning ("Can't set a target list on a widget until you've called gtk_drag_dest_set() "
|
|
|
|
|
"to make the widget into a drag destination");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (target_list)
|
|
|
|
|
gtk_target_list_ref (target_list);
|
|
|
|
|
|
|
|
|
|
if (site->target_list)
|
|
|
|
|
gtk_target_list_unref (site->target_list);
|
|
|
|
|
|
|
|
|
|
site->target_list = target_list;
|
|
|
|
|
|
|
|
|
|
register_types (widget, site);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_add_text_targets: (method)
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* @widget: a #GtkWidget that’s a drag destination
|
2012-07-16 22:09:28 +00:00
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_add_text_targets (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkTargetList *target_list;
|
|
|
|
|
|
|
|
|
|
target_list = gtk_drag_dest_get_target_list (widget);
|
|
|
|
|
if (target_list)
|
|
|
|
|
gtk_target_list_ref (target_list);
|
|
|
|
|
else
|
|
|
|
|
target_list = gtk_target_list_new (NULL, 0);
|
|
|
|
|
gtk_target_list_add_text_targets (target_list, 0);
|
|
|
|
|
gtk_drag_dest_set_target_list (widget, target_list);
|
|
|
|
|
gtk_target_list_unref (target_list);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_add_image_targets: (method)
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* @widget: a #GtkWidget that’s a drag destination
|
2012-07-16 22:09:28 +00:00
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_add_image_targets (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkTargetList *target_list;
|
|
|
|
|
|
|
|
|
|
target_list = gtk_drag_dest_get_target_list (widget);
|
|
|
|
|
if (target_list)
|
|
|
|
|
gtk_target_list_ref (target_list);
|
|
|
|
|
else
|
|
|
|
|
target_list = gtk_target_list_new (NULL, 0);
|
|
|
|
|
gtk_target_list_add_image_targets (target_list, 0, FALSE);
|
|
|
|
|
gtk_drag_dest_set_target_list (widget, target_list);
|
|
|
|
|
gtk_target_list_unref (target_list);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_add_uri_targets: (method)
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* @widget: a #GtkWidget that’s a drag destination
|
2012-07-16 22:09:28 +00:00
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_add_uri_targets (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkTargetList *target_list;
|
|
|
|
|
|
|
|
|
|
target_list = gtk_drag_dest_get_target_list (widget);
|
|
|
|
|
if (target_list)
|
|
|
|
|
gtk_target_list_ref (target_list);
|
|
|
|
|
else
|
|
|
|
|
target_list = gtk_target_list_new (NULL, 0);
|
|
|
|
|
gtk_target_list_add_uri_targets (target_list, 0);
|
|
|
|
|
gtk_drag_dest_set_target_list (widget, target_list);
|
|
|
|
|
gtk_target_list_unref (target_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_find_widget (GtkWidget *widget,
|
|
|
|
|
GtkDragFindData *data)
|
|
|
|
|
{
|
|
|
|
|
GtkAllocation new_allocation;
|
|
|
|
|
gint allocation_to_window_x = 0;
|
|
|
|
|
gint allocation_to_window_y = 0;
|
|
|
|
|
gint x_offset = 0;
|
|
|
|
|
gint y_offset = 0;
|
|
|
|
|
|
2010-03-02 04:19:28 +00:00
|
|
|
|
if (data->found || !gtk_widget_get_mapped (widget) || !gtk_widget_get_sensitive (widget))
|
2006-03-21 16:50:47 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
|
*/
|
2010-09-13 14:39:55 +00:00
|
|
|
|
gtk_widget_get_allocation (widget, &new_allocation);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2010-09-13 14:39:55 +00:00
|
|
|
|
if (gtk_widget_get_parent (widget))
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
gint tx, ty;
|
2010-09-13 14:39:55 +00:00
|
|
|
|
GdkWindow *window = gtk_widget_get_window (widget);
|
|
|
|
|
GdkWindow *parent_window;
|
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
|
|
parent_window = gtk_widget_get_window (gtk_widget_get_parent (widget));
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
/* Compute the offset from allocation-relative to
|
|
|
|
|
* window-relative coordinates.
|
|
|
|
|
*/
|
2010-09-13 14:39:55 +00:00
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
allocation_to_window_x = allocation.x;
|
|
|
|
|
allocation_to_window_y = allocation.y;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2010-01-04 06:49:26 +00:00
|
|
|
|
if (gtk_widget_get_has_window (widget))
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_allocation.x = 0 + allocation_to_window_x;
|
|
|
|
|
new_allocation.y = 0 + allocation_to_window_y;
|
|
|
|
|
|
2010-09-13 14:39:55 +00:00
|
|
|
|
while (window && window != parent_window)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
GdkRectangle window_rect = { 0, 0, 0, 0 };
|
|
|
|
|
|
2010-09-20 14:46:48 +00:00
|
|
|
|
window_rect.width = gdk_window_get_width (window);
|
|
|
|
|
window_rect.height = gdk_window_get_height (window);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
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 (!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
|
|
|
|
|
*/
|
|
|
|
|
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
|
2008-08-12 14:37:03 +00:00
|
|
|
|
* ::drag-motion/::drag-drop callbacks change the widget hierarchy.
|
2006-03-21 16:50:47 +00:00
|
|
|
|
*/
|
|
|
|
|
gtk_container_forall (GTK_CONTAINER (widget), prepend_and_ref_widget, &children);
|
|
|
|
|
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
|
|
|
|
|
{
|
2010-01-07 15:47:35 +00:00
|
|
|
|
if (!new_data.found && gtk_widget_is_drawable (tmp_list->data))
|
2006-03-21 16:50:47 +00:00
|
|
|
|
gtk_drag_find_widget (tmp_list->data, &new_data);
|
|
|
|
|
g_object_unref (tmp_list->data);
|
|
|
|
|
}
|
|
|
|
|
g_slist_free (children);
|
|
|
|
|
|
|
|
|
|
data->found = new_data.found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If not, and this widget is registered as a drop site, check to
|
2008-08-12 14:37:03 +00:00
|
|
|
|
* emit "drag-motion" to check if we are actually in
|
2006-03-21 16:50:47 +00:00
|
|
|
|
* a drop site.
|
|
|
|
|
*/
|
|
|
|
|
if (!data->found &&
|
|
|
|
|
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);
|
2008-08-12 14:37:03 +00:00
|
|
|
|
/* If so, send a "drag-leave" to the last widget */
|
2006-03-21 16:50:47 +00:00
|
|
|
|
if (data->found)
|
|
|
|
|
{
|
|
|
|
|
if (data->info->widget && data->info->widget != widget)
|
|
|
|
|
{
|
|
|
|
|
gtk_drag_dest_leave (data->info->widget, data->context, data->time);
|
|
|
|
|
}
|
|
|
|
|
data->info->widget = widget;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_dest_leave (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
guint time)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
|
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
g_return_if_fail (site != NULL);
|
|
|
|
|
|
|
|
|
|
if ((site->flags & GTK_DEST_DEFAULT_HIGHLIGHT) && site->have_drag)
|
|
|
|
|
gtk_drag_unhighlight (widget);
|
|
|
|
|
|
2006-08-08 21:18:09 +00:00
|
|
|
|
if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag ||
|
|
|
|
|
site->track_motion)
|
2008-08-11 13:36:15 +00:00
|
|
|
|
g_signal_emit_by_name (widget, "drag-leave", context, time);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
site->have_drag = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_drag_dest_motion (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
guint time)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
GdkDragAction action = 0;
|
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
g_return_val_if_fail (site != NULL, FALSE);
|
|
|
|
|
|
2006-08-08 21:18:09 +00:00
|
|
|
|
if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
2010-12-22 14:45:44 +00:00
|
|
|
|
if (gdk_drag_context_get_suggested_action (context) & site->actions)
|
|
|
|
|
action = gdk_drag_context_get_suggested_action (context);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
if (action && gtk_drag_dest_find_target (widget, context, NULL))
|
|
|
|
|
{
|
|
|
|
|
if (!site->have_drag)
|
|
|
|
|
{
|
|
|
|
|
site->have_drag = TRUE;
|
|
|
|
|
if (site->flags & GTK_DEST_DEFAULT_HIGHLIGHT)
|
|
|
|
|
gtk_drag_highlight (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gdk_drag_status (context, action, time);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gdk_drag_status (context, 0, time);
|
2006-08-08 21:18:09 +00:00
|
|
|
|
if (!site->track_motion)
|
|
|
|
|
return TRUE;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-11 13:36:15 +00:00
|
|
|
|
g_signal_emit_by_name (widget, "drag-motion",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
context, x, y, time, &retval);
|
|
|
|
|
|
|
|
|
|
return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_drag_dest_drop (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
guint time)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
GtkDragDestInfo *info;
|
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
g_return_val_if_fail (site != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
info = gtk_drag_get_dest_info (context, FALSE);
|
|
|
|
|
g_return_val_if_fail (info != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
info->drop_x = x;
|
|
|
|
|
info->drop_y = y;
|
|
|
|
|
|
|
|
|
|
if (site->flags & GTK_DEST_DEFAULT_DROP)
|
|
|
|
|
{
|
|
|
|
|
GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
|
|
|
|
|
|
2017-11-15 17:13:31 +00:00
|
|
|
|
if (target == NULL)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_drag_finish (context, FALSE, FALSE, time);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_drag_get_data (widget, context, target, time);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-11 13:36:15 +00:00
|
|
|
|
g_signal_emit_by_name (widget, "drag-drop",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
context, x, y, time, &retval);
|
|
|
|
|
|
|
|
|
|
return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval;
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_set_track_motion: (method)
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* @widget: a #GtkWidget that’s a drag destination
|
2012-07-16 22:09:28 +00:00
|
|
|
|
* @track_motion: whether to accept all targets
|
|
|
|
|
*/
|
2006-03-27 11:34:43 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_dest_set_track_motion (GtkWidget *widget,
|
|
|
|
|
gboolean track_motion)
|
|
|
|
|
{
|
2006-08-08 21:18:09 +00:00
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
|
2006-03-27 11:34:43 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2006-08-08 21:18:09 +00:00
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (site != NULL);
|
|
|
|
|
|
|
|
|
|
site->track_motion = track_motion != FALSE;
|
2006-03-27 11:34:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_get_track_motion: (method)
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* @widget: a #GtkWidget that’s a drag destination
|
2012-07-16 22:09:28 +00:00
|
|
|
|
*/
|
2006-03-27 11:34:43 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_drag_dest_get_track_motion (GtkWidget *widget)
|
|
|
|
|
{
|
2006-08-08 21:18:09 +00:00
|
|
|
|
GtkDragDestSite *site;
|
|
|
|
|
|
2006-03-27 11:34:43 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
|
|
|
|
2006-08-08 21:18:09 +00:00
|
|
|
|
site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
|
|
|
|
|
|
|
|
|
|
if (site)
|
|
|
|
|
return site->track_motion;
|
2006-03-27 11:34:43 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
void
|
|
|
|
|
_gtk_drag_dest_handle_event (GtkWidget *toplevel,
|
|
|
|
|
GdkEvent *event)
|
|
|
|
|
{
|
|
|
|
|
GtkDragDestInfo *info;
|
|
|
|
|
GdkDragContext *context;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (toplevel != NULL);
|
|
|
|
|
g_return_if_fail (event != NULL);
|
|
|
|
|
|
|
|
|
|
context = event->dnd.context;
|
|
|
|
|
|
|
|
|
|
info = gtk_drag_get_dest_info (context, TRUE);
|
|
|
|
|
|
|
|
|
|
/* Find the widget for the event */
|
|
|
|
|
switch (event->type)
|
|
|
|
|
{
|
|
|
|
|
case GDK_DRAG_ENTER:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GDK_DRAG_LEAVE:
|
|
|
|
|
if (info->widget)
|
|
|
|
|
{
|
|
|
|
|
gtk_drag_dest_leave (info->widget, context, event->dnd.time);
|
|
|
|
|
info->widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GDK_DRAG_MOTION:
|
|
|
|
|
case GDK_DROP_START:
|
|
|
|
|
{
|
|
|
|
|
GtkDragFindData data;
|
|
|
|
|
gint tx, ty;
|
|
|
|
|
|
|
|
|
|
if (event->type == GDK_DROP_START)
|
|
|
|
|
{
|
|
|
|
|
info->dropped = TRUE;
|
|
|
|
|
/* We send a leave here so that the widget unhighlights
|
|
|
|
|
* properly.
|
|
|
|
|
*/
|
|
|
|
|
if (info->widget)
|
|
|
|
|
{
|
|
|
|
|
gtk_drag_dest_leave (info->widget, context, event->dnd.time);
|
|
|
|
|
info->widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-13 14:39:55 +00:00
|
|
|
|
gdk_window_get_position (gtk_widget_get_window (toplevel), &tx, &ty);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
if (info->widget && !data.found)
|
|
|
|
|
{
|
|
|
|
|
gtk_drag_dest_leave (info->widget, context, event->dnd.time);
|
|
|
|
|
info->widget = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Send a reply.
|
|
|
|
|
*/
|
|
|
|
|
if (event->type == GDK_DRAG_MOTION)
|
|
|
|
|
{
|
|
|
|
|
if (!data.found)
|
|
|
|
|
gdk_drag_status (context, 0, event->dnd.time);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_dest_find_target: (method)
|
|
|
|
|
* @widget: drag destination widget
|
|
|
|
|
* @context: drag context
|
|
|
|
|
* @target_list: (allow-none): list of droppable targets, or %NULL to use
|
|
|
|
|
* gtk_drag_dest_get_target_list (@widget).
|
2014-11-30 21:57:22 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none):
|
2012-07-16 22:09:28 +00:00
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GdkAtom
|
|
|
|
|
gtk_drag_dest_find_target (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
GtkTargetList *target_list)
|
|
|
|
|
{
|
2007-11-01 08:45:30 +00:00
|
|
|
|
id <NSDraggingInfo> dragging_info;
|
|
|
|
|
NSPasteboard *pasteboard;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GtkWidget *source_widget;
|
|
|
|
|
GList *tmp_target;
|
|
|
|
|
GList *tmp_source = NULL;
|
|
|
|
|
GList *source_targets;
|
|
|
|
|
|
2017-11-15 17:13:31 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
|
|
|
|
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2007-11-01 08:45:30 +00:00
|
|
|
|
dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
|
|
|
|
|
pasteboard = [dragging_info draggingPasteboard];
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
source_widget = gtk_drag_get_source_widget (context);
|
|
|
|
|
|
|
|
|
|
if (target_list == NULL)
|
|
|
|
|
target_list = gtk_drag_dest_get_target_list (widget);
|
|
|
|
|
|
|
|
|
|
if (target_list == NULL)
|
2017-11-15 17:13:31 +00:00
|
|
|
|
return NULL;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
source_targets = _gtk_quartz_pasteboard_types_to_atom_list ([pasteboard types]);
|
|
|
|
|
tmp_target = target_list->list;
|
|
|
|
|
while (tmp_target)
|
|
|
|
|
{
|
|
|
|
|
GtkTargetPair *pair = tmp_target->data;
|
|
|
|
|
tmp_source = source_targets;
|
|
|
|
|
while (tmp_source)
|
|
|
|
|
{
|
|
|
|
|
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)))
|
|
|
|
|
{
|
|
|
|
|
g_list_free (source_targets);
|
|
|
|
|
return pair->target;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tmp_source = tmp_source->next;
|
|
|
|
|
}
|
|
|
|
|
tmp_target = tmp_target->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (source_targets);
|
2017-11-15 17:13:31 +00:00
|
|
|
|
return NULL;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_drag_begin_idle (gpointer arg)
|
|
|
|
|
{
|
2009-12-30 13:18:33 +00:00
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 13:07:37 +00:00
|
|
|
|
GdkDragContext* context = (GdkDragContext*) arg;
|
|
|
|
|
GtkDragSourceInfo* info = gtk_drag_get_source_info (context, FALSE);
|
|
|
|
|
NSWindow *nswindow;
|
|
|
|
|
NSPasteboard *pasteboard;
|
|
|
|
|
GtkDragSourceOwner *owner;
|
|
|
|
|
NSPoint point;
|
2010-01-01 19:39:57 +00:00
|
|
|
|
NSSet *types;
|
2010-01-01 19:54:27 +00:00
|
|
|
|
NSImage *drag_image;
|
2009-09-30 13:07:37 +00:00
|
|
|
|
|
|
|
|
|
g_assert (info != NULL);
|
|
|
|
|
|
|
|
|
|
pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
|
|
|
|
|
owner = [[GtkDragSourceOwner alloc] initWithInfo:info];
|
|
|
|
|
|
2010-01-01 19:39:57 +00:00
|
|
|
|
types = _gtk_quartz_target_list_to_pasteboard_types (info->target_list);
|
|
|
|
|
|
|
|
|
|
[pasteboard declareTypes:[types allObjects] owner:owner];
|
|
|
|
|
|
2010-01-01 19:54:27 +00:00
|
|
|
|
[owner release];
|
2010-01-01 19:39:57 +00:00
|
|
|
|
[types release];
|
2009-09-30 13:07:37 +00:00
|
|
|
|
|
|
|
|
|
if ((nswindow = get_toplevel_nswindow (info->source_widget)) == NULL)
|
2012-01-31 00:12:27 +00:00
|
|
|
|
return G_SOURCE_REMOVE;
|
2009-09-30 13:07:37 +00:00
|
|
|
|
|
|
|
|
|
/* Ref the context. It's unreffed when the drag has been aborted */
|
|
|
|
|
g_object_ref (info->context);
|
|
|
|
|
|
|
|
|
|
/* FIXME: If the event isn't a mouse event, use the global cursor position instead */
|
|
|
|
|
point = [info->nsevent locationInWindow];
|
|
|
|
|
|
2015-07-24 13:09:48 +00:00
|
|
|
|
drag_image = _gtk_quartz_create_image_from_surface (info->icon_surface);
|
|
|
|
|
|
2011-11-07 22:25:08 +00:00
|
|
|
|
if (drag_image == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (info->context);
|
2012-01-31 00:12:27 +00:00
|
|
|
|
return G_SOURCE_REMOVE;
|
2011-11-07 22:25:08 +00:00
|
|
|
|
}
|
2010-01-01 19:54:27 +00:00
|
|
|
|
|
2011-11-07 21:18:14 +00:00
|
|
|
|
point.x -= info->hot_x;
|
2015-07-24 11:57:35 +00:00
|
|
|
|
point.y -= [drag_image size].height - info->hot_y;
|
2010-10-19 11:26:06 +00:00
|
|
|
|
|
2010-01-01 19:54:27 +00:00
|
|
|
|
[nswindow dragImage:drag_image
|
2009-09-30 13:07:37 +00:00
|
|
|
|
at:point
|
2012-04-22 15:11:38 +00:00
|
|
|
|
offset:NSZeroSize
|
2009-09-30 13:07:37 +00:00
|
|
|
|
event:info->nsevent
|
|
|
|
|
pasteboard:pasteboard
|
|
|
|
|
source:nswindow
|
|
|
|
|
slideBack:YES];
|
|
|
|
|
|
|
|
|
|
[info->nsevent release];
|
2010-01-01 19:54:27 +00:00
|
|
|
|
[drag_image release];
|
2009-09-30 13:07:37 +00:00
|
|
|
|
|
2009-12-30 13:18:33 +00:00
|
|
|
|
[pool release];
|
|
|
|
|
|
2012-01-31 00:12:27 +00:00
|
|
|
|
return G_SOURCE_REMOVE;
|
2009-09-30 13:07:37 +00:00
|
|
|
|
}
|
2011-09-25 01:19:56 +00:00
|
|
|
|
/* Fake protocol to let us call GdkNSView gdkWindow without including
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* gdk/GdkNSView.h (which we can’t because it pulls in the internal-only
|
2011-09-25 01:19:56 +00:00
|
|
|
|
* gdkwindow.h).
|
|
|
|
|
*/
|
|
|
|
|
@protocol GdkNSView
|
|
|
|
|
- (GdkWindow *)gdkWindow;
|
|
|
|
|
@end
|
2009-09-30 13:07:37 +00:00
|
|
|
|
|
2015-11-22 04:08:34 +00:00
|
|
|
|
GdkDragContext *
|
2006-03-21 16:50:47 +00:00
|
|
|
|
gtk_drag_begin_internal (GtkWidget *widget,
|
2015-12-17 17:02:13 +00:00
|
|
|
|
GtkImageDefinition *icon,
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GtkTargetList *target_list,
|
|
|
|
|
GdkDragAction actions,
|
|
|
|
|
gint button,
|
2015-12-17 17:02:13 +00:00
|
|
|
|
const GdkEvent *event,
|
|
|
|
|
int x,
|
|
|
|
|
int y)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
|
|
|
|
GtkDragSourceInfo *info;
|
2011-07-14 12:22:38 +00:00
|
|
|
|
GdkDevice *pointer;
|
2011-09-25 01:19:56 +00:00
|
|
|
|
GdkWindow *window;
|
2011-11-20 17:24:56 +00:00
|
|
|
|
GdkDragContext *context;
|
2011-09-25 01:19:56 +00:00
|
|
|
|
NSWindow *nswindow = get_toplevel_nswindow (widget);
|
|
|
|
|
NSPoint point = {0, 0};
|
|
|
|
|
double time = (double)g_get_real_time ();
|
|
|
|
|
NSEvent *nsevent;
|
|
|
|
|
NSTimeInterval nstime;
|
|
|
|
|
|
2013-10-10 22:34:08 +00:00
|
|
|
|
if ((x != -1 && y != -1) || event)
|
2011-09-25 01:19:56 +00:00
|
|
|
|
{
|
2013-10-10 22:34:08 +00:00
|
|
|
|
GdkWindow *window;
|
|
|
|
|
gdouble dx, dy;
|
|
|
|
|
if (x != -1 && y != -1)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
|
|
|
|
|
window = gtk_widget_get_window (toplevel);
|
|
|
|
|
gtk_widget_translate_coordinates (widget, toplevel, x, y, &x, &y);
|
|
|
|
|
gdk_window_get_root_coords (gtk_widget_get_window (toplevel), x, y,
|
|
|
|
|
&x, &y);
|
|
|
|
|
dx = (gdouble)x;
|
|
|
|
|
dy = (gdouble)y;
|
|
|
|
|
}
|
|
|
|
|
else if (event)
|
|
|
|
|
{
|
|
|
|
|
if (gdk_event_get_coords (event, &dx, &dy))
|
|
|
|
|
{
|
|
|
|
|
/* We need to translate (x, y) to coordinates relative to the
|
|
|
|
|
* toplevel GdkWindow, which should be the GdkWindow backing
|
|
|
|
|
* nswindow. Then, we convert to the NSWindow coordinate system.
|
|
|
|
|
*/
|
|
|
|
|
window = event->any.window;
|
2016-10-25 07:54:37 +00:00
|
|
|
|
GdkWindow *toplevel = gdk_window_get_toplevel (window);
|
2013-10-10 22:34:08 +00:00
|
|
|
|
|
|
|
|
|
while (window != toplevel)
|
|
|
|
|
{
|
|
|
|
|
double old_x = dx;
|
|
|
|
|
double old_y = dy;
|
2012-04-22 15:11:38 +00:00
|
|
|
|
|
2013-10-10 22:34:08 +00:00
|
|
|
|
gdk_window_coords_to_parent (window, old_x, old_y,
|
|
|
|
|
&dx, &dy);
|
2016-10-25 07:54:37 +00:00
|
|
|
|
window = gdk_window_get_parent (window);
|
2013-10-10 22:34:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
time = (double)gdk_event_get_time (event);
|
|
|
|
|
}
|
|
|
|
|
point.x = dx;
|
|
|
|
|
point.y = gdk_window_get_height (window) - dy;
|
2011-09-25 01:19:56 +00:00
|
|
|
|
}
|
2011-11-20 17:27:28 +00:00
|
|
|
|
|
2011-09-25 01:19:56 +00:00
|
|
|
|
nstime = [[NSDate dateWithTimeIntervalSince1970: time / 1000] timeIntervalSinceReferenceDate];
|
|
|
|
|
nsevent = [NSEvent mouseEventWithType: NSLeftMouseDown
|
2011-11-20 17:27:28 +00:00
|
|
|
|
location: point
|
|
|
|
|
modifierFlags: 0
|
|
|
|
|
timestamp: nstime
|
|
|
|
|
windowNumber: [nswindow windowNumber]
|
|
|
|
|
context: [nswindow graphicsContext]
|
|
|
|
|
eventNumber: 0
|
|
|
|
|
clickCount: 1
|
|
|
|
|
pressure: 0.0 ];
|
2011-09-25 01:19:56 +00:00
|
|
|
|
|
|
|
|
|
window = [(id<GdkNSView>)[nswindow contentView] gdkWindow];
|
2011-11-20 17:27:28 +00:00
|
|
|
|
g_return_val_if_fail (nsevent != NULL, NULL);
|
2011-09-25 01:19:56 +00:00
|
|
|
|
|
2013-10-11 17:40:26 +00:00
|
|
|
|
context = gdk_drag_begin (window, g_list_copy (target_list->list));
|
2011-11-20 17:27:28 +00:00
|
|
|
|
g_return_val_if_fail (context != NULL, NULL);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
info = gtk_drag_get_source_info (context, TRUE);
|
2011-09-25 01:19:56 +00:00
|
|
|
|
info->nsevent = nsevent;
|
|
|
|
|
[info->nsevent retain];
|
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
info->source_widget = g_object_ref (widget);
|
2008-06-26 12:44:10 +00:00
|
|
|
|
info->widget = g_object_ref (widget);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
info->target_list = target_list;
|
|
|
|
|
gtk_target_list_ref (target_list);
|
|
|
|
|
|
|
|
|
|
info->possible_actions = actions;
|
2011-11-20 17:27:28 +00:00
|
|
|
|
|
2008-08-11 13:36:15 +00:00
|
|
|
|
g_signal_emit_by_name (widget, "drag-begin", info->context);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
/* Ensure that we have an icon before we start the drag; the
|
|
|
|
|
* application may have set one in ::drag_begin, or it may
|
|
|
|
|
* not have set one.
|
|
|
|
|
*/
|
2015-12-17 17:02:13 +00:00
|
|
|
|
if (!info->icon_surface && icon)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
2015-12-17 17:02:13 +00:00
|
|
|
|
switch (gtk_image_definition_get_storage_type (icon))
|
2011-11-20 17:27:28 +00:00
|
|
|
|
{
|
2015-12-17 17:02:13 +00:00
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
|
|
|
|
gtk_drag_set_icon_pixbuf (context,
|
|
|
|
|
gtk_image_definition_get_pixbuf (icon),
|
|
|
|
|
-2, -2);
|
|
|
|
|
break;
|
|
|
|
|
case GTK_IMAGE_ICON_NAME:
|
|
|
|
|
gtk_drag_set_icon_name (context,
|
|
|
|
|
gtk_image_definition_get_icon_name (icon),
|
|
|
|
|
-2, -2);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2011-11-20 17:27:28 +00:00
|
|
|
|
}
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 17:02:13 +00:00
|
|
|
|
/* no image def or no supported type -> set the default */
|
|
|
|
|
if (!info->icon_surface)
|
|
|
|
|
gtk_drag_set_icon_default (context);
|
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
/* drag will begin in an idle handler to avoid nested run loops */
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
g_idle_add_full (G_PRIORITY_HIGH_IDLE, gtk_drag_begin_idle, context, NULL);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2011-07-14 12:22:38 +00:00
|
|
|
|
pointer = gdk_drag_context_get_device (info->context);
|
|
|
|
|
gdk_device_ungrab (pointer, 0);
|
2009-09-30 13:07:37 +00:00
|
|
|
|
|
|
|
|
|
return context;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-30 21:57:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_begin_with_coordinates: (method)
|
|
|
|
|
* @widget:
|
|
|
|
|
* @targets:
|
|
|
|
|
* @actions:
|
|
|
|
|
* @button:
|
|
|
|
|
* @event:
|
|
|
|
|
* @x:
|
|
|
|
|
* @y:
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer none):
|
|
|
|
|
*/
|
2013-10-10 22:34:08 +00:00
|
|
|
|
GdkDragContext *
|
|
|
|
|
gtk_drag_begin_with_coordinates (GtkWidget *widget,
|
|
|
|
|
GtkTargetList *targets,
|
|
|
|
|
GdkDragAction actions,
|
|
|
|
|
gint button,
|
|
|
|
|
GdkEvent *event,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (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, x, y);
|
|
|
|
|
}
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
|
2015-05-31 18:52:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_cancel:
|
|
|
|
|
* @context: a #GdkDragContext, as e.g. returned by gtk_drag_begin_with_coordinates()
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_drag_cancel (GdkDragContext *context)
|
|
|
|
|
{
|
|
|
|
|
GtkDragSourceInfo *info;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
|
|
|
|
|
|
|
|
info = gtk_drag_get_source_info (context, FALSE);
|
|
|
|
|
if (info != NULL)
|
2015-07-27 13:33:32 +00:00
|
|
|
|
gtk_drag_drop_finished (info, GTK_DRAG_RESULT_ERROR);
|
2015-05-31 18:52:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2014-11-30 21:57:22 +00:00
|
|
|
|
* gtk_drag_set_icon_widget: (method)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
* @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.
|
|
|
|
|
* @hot_x: the X offset within @widget of the hotspot.
|
|
|
|
|
* @hot_y: the Y offset within @widget of the hotspot.
|
|
|
|
|
*
|
|
|
|
|
* Changes the icon for a widget to a given widget. GTK+
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* will not destroy the icon, so if you don’t want
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* it to persist, you should connect to the “drag-end”
|
2006-03-21 16:50:47 +00:00
|
|
|
|
* signal and destroy it yourself.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_drag_set_icon_widget (GdkDragContext *context,
|
|
|
|
|
GtkWidget *widget,
|
|
|
|
|
gint hot_x,
|
|
|
|
|
gint hot_y)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
|
|
g_warning ("gtk_drag_set_icon_widget is not supported on Mac OS X");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_icon_stock_pixbuf (GdkDragContext *context,
|
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
|
gint hot_x,
|
|
|
|
|
gint hot_y)
|
|
|
|
|
{
|
|
|
|
|
GtkDragSourceInfo *info;
|
2015-07-24 13:09:48 +00:00
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
cairo_t *cr;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
info = gtk_drag_get_source_info (context, FALSE);
|
|
|
|
|
|
2016-10-23 11:12:00 +00:00
|
|
|
|
g_object_ref (pixbuf);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2015-07-24 13:09:48 +00:00
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
|
|
|
|
|
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);
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
|
|
cairo_surface_set_device_offset (surface, -hot_x, -hot_y);
|
|
|
|
|
gtk_drag_set_icon_surface (context, surface);
|
|
|
|
|
cairo_surface_destroy (surface);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-01 16:42:09 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_drag_set_icon_definition (GdkDragContext *context,
|
|
|
|
|
GtkImageDefinition *def,
|
|
|
|
|
gint hot_x,
|
|
|
|
|
gint hot_y)
|
|
|
|
|
{
|
|
|
|
|
switch (gtk_image_definition_get_storage_type (def))
|
|
|
|
|
{
|
|
|
|
|
case GTK_IMAGE_EMPTY:
|
|
|
|
|
gtk_drag_set_icon_default (context);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_IMAGE_PIXBUF:
|
|
|
|
|
gtk_drag_set_icon_pixbuf (context,
|
|
|
|
|
gtk_image_definition_get_pixbuf (def),
|
|
|
|
|
hot_x, hot_y);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_IMAGE_ICON_NAME:
|
|
|
|
|
gtk_drag_set_icon_name (context,
|
|
|
|
|
gtk_image_definition_get_icon_name (def),
|
|
|
|
|
hot_x, hot_y);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_warning ("FIXME: setting drag icon of type %u not implemented, using default.", gtk_image_definition_get_storage_type (def));
|
|
|
|
|
gtk_drag_set_icon_default (context);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_set_icon_pixbuf:
|
|
|
|
|
* @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.
|
|
|
|
|
* @hot_x: the X offset within @widget of the hotspot.
|
|
|
|
|
* @hot_y: the Y offset within @widget of the hotspot.
|
|
|
|
|
*
|
|
|
|
|
* Sets @pixbuf as the icon for a given drag.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_drag_set_icon_pixbuf (GdkDragContext *context,
|
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
|
gint hot_x,
|
|
|
|
|
gint hot_y)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
|
|
|
|
|
2016-10-23 11:12:00 +00:00
|
|
|
|
set_icon_stock_pixbuf (context, pixbuf, hot_x, hot_y);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-17 08:07:29 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 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_surface (GdkDragContext *context,
|
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
|
{
|
2010-10-19 11:26:39 +00:00
|
|
|
|
double x_offset, y_offset;
|
2015-07-24 13:09:48 +00:00
|
|
|
|
GtkDragSourceInfo *info;
|
2010-10-17 08:07:29 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
|
|
|
g_return_if_fail (surface != NULL);
|
|
|
|
|
|
2010-10-19 11:26:39 +00:00
|
|
|
|
cairo_surface_get_device_offset (surface, &x_offset, &y_offset);
|
2015-07-24 13:09:48 +00:00
|
|
|
|
info = gtk_drag_get_source_info (context, FALSE);
|
|
|
|
|
cairo_surface_reference (surface);
|
2010-10-17 08:07:29 +00:00
|
|
|
|
|
2015-07-24 13:09:48 +00:00
|
|
|
|
if (info->icon_surface)
|
|
|
|
|
cairo_surface_destroy (info->icon_surface);
|
|
|
|
|
|
|
|
|
|
info->icon_surface = surface;
|
|
|
|
|
info->hot_x = -x_offset;
|
|
|
|
|
info->hot_y = -y_offset;
|
2010-10-17 08:07:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_set_icon_name:
|
|
|
|
|
* @context: the context for a drag. (This must be called
|
|
|
|
|
* with a context for the source side of a drag)
|
|
|
|
|
* @icon_name: name of icon to use
|
|
|
|
|
* @hot_x: the X offset of the hotspot within the icon
|
|
|
|
|
* @hot_y: the Y offset of the hotspot within the icon
|
|
|
|
|
*
|
|
|
|
|
* Sets the icon for a given drag from a named themed icon. See
|
|
|
|
|
* the docs for #GtkIconTheme for more details. Note that the
|
|
|
|
|
* size of the icon depends on the icon theme (the icon is
|
|
|
|
|
* loaded at the symbolic size #GTK_ICON_SIZE_DND), thus
|
|
|
|
|
* @hot_x and @hot_y have to be used with care.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_drag_set_icon_name (GdkDragContext *context,
|
|
|
|
|
const gchar *icon_name,
|
|
|
|
|
gint hot_x,
|
|
|
|
|
gint hot_y)
|
|
|
|
|
{
|
2017-10-31 01:59:06 +00:00
|
|
|
|
GdkDisplay *display;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
gint width, height, icon_size;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
|
|
|
g_return_if_fail (icon_name != NULL);
|
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
display = gdk_window_get_display (gdk_drag_context_get_source_window (context));
|
|
|
|
|
g_return_if_fail (display != NULL);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2015-12-01 19:12:45 +00:00
|
|
|
|
gtk_icon_size_lookup (GTK_ICON_SIZE_DND, &width, &height);
|
|
|
|
|
icon_size = MAX (width, height);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2017-10-31 01:59:06 +00:00
|
|
|
|
icon_theme = gtk_icon_theme_get_for_display (display);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
|
|
|
|
|
icon_size, 0, NULL);
|
|
|
|
|
if (pixbuf)
|
2016-10-23 11:12:00 +00:00
|
|
|
|
set_icon_stock_pixbuf (context, pixbuf, hot_x, hot_y);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
else
|
|
|
|
|
g_warning ("Cannot load drag icon from icon name %s", icon_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-11-30 21:57:22 +00:00
|
|
|
|
* gtk_drag_set_icon_default: (method)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
* @context: the context for a drag. (This must be called
|
|
|
|
|
with a context for the source side of a drag)
|
|
|
|
|
*
|
|
|
|
|
* Sets the icon for a particular drag to the default
|
|
|
|
|
* icon.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gtk_drag_set_icon_default (GdkDragContext *context)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
|
|
|
|
|
|
2013-06-24 23:28:53 +00:00
|
|
|
|
gtk_drag_set_icon_name (context, "text-x-generic", -2, -2);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
|
|
|
|
|
{
|
2011-09-25 00:32:21 +00:00
|
|
|
|
NSPasteboard *pasteboard;
|
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
|
|
2015-07-24 13:09:48 +00:00
|
|
|
|
if (info->icon_surface)
|
|
|
|
|
cairo_surface_destroy (info->icon_surface);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
2008-08-11 13:36:15 +00:00
|
|
|
|
g_signal_emit_by_name (info->widget, "drag-end",
|
2006-03-21 16:50:47 +00:00
|
|
|
|
info->context);
|
|
|
|
|
|
2009-09-30 13:07:37 +00:00
|
|
|
|
if (info->source_widget)
|
|
|
|
|
g_object_unref (info->source_widget);
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
if (info->widget)
|
|
|
|
|
g_object_unref (info->widget);
|
|
|
|
|
|
|
|
|
|
gtk_target_list_unref (info->target_list);
|
|
|
|
|
|
2011-09-25 00:32:21 +00:00
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
|
|
/* Empty the pasteboard, so that it will not accidentally access
|
|
|
|
|
* info->context after it has been destroyed.
|
|
|
|
|
*/
|
|
|
|
|
pasteboard = [NSPasteboard pasteboardWithName: NSDragPboard];
|
|
|
|
|
[pasteboard declareTypes: nil owner: nil];
|
|
|
|
|
|
2011-09-25 01:19:56 +00:00
|
|
|
|
[pool release];
|
2011-09-25 00:32:21 +00:00
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
gtk_drag_clear_source_info (info->context);
|
|
|
|
|
g_object_unref (info->context);
|
|
|
|
|
|
|
|
|
|
g_free (info);
|
2011-09-25 00:32:21 +00:00
|
|
|
|
info = NULL;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-05-25 15:11:11 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
drag_drop_finished_idle_cb (gpointer data)
|
|
|
|
|
{
|
2015-07-26 06:10:47 +00:00
|
|
|
|
GtkDragSourceInfo* info = (GtkDragSourceInfo*) data;
|
|
|
|
|
if (info->success)
|
|
|
|
|
gtk_drag_source_info_destroy (data);
|
2012-01-31 00:12:27 +00:00
|
|
|
|
return G_SOURCE_REMOVE;
|
2008-05-25 15:11:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-21 16:50:47 +00:00
|
|
|
|
static void
|
2015-07-26 06:10:47 +00:00
|
|
|
|
gtk_drag_drop_finished (GtkDragSourceInfo *info,
|
|
|
|
|
GtkDragResult result)
|
2006-03-21 16:50:47 +00:00
|
|
|
|
{
|
2015-07-26 06:10:47 +00:00
|
|
|
|
gboolean success = (result == GTK_DRAG_RESULT_SUCCESS);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
g_signal_emit_by_name (info->source_widget, "drag-failed",
|
2015-07-27 13:33:32 +00:00
|
|
|
|
info->context, result, &success);
|
2015-07-26 06:10:47 +00:00
|
|
|
|
|
|
|
|
|
if (success && info->delete)
|
2009-09-30 13:07:37 +00:00
|
|
|
|
g_signal_emit_by_name (info->source_widget, "drag-data-delete",
|
|
|
|
|
info->context);
|
|
|
|
|
|
2008-05-25 15:11:11 +00:00
|
|
|
|
/* Workaround for the fact that the NS API blocks until the drag is
|
|
|
|
|
* over. This way the context is still valid when returning from
|
|
|
|
|
* drag_begin, even if it will still be quite useless. See bug #501588.
|
|
|
|
|
*/
|
|
|
|
|
g_idle_add (drag_drop_finished_idle_cb, info);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*************************************************************
|
|
|
|
|
* _gtk_drag_source_handle_event:
|
|
|
|
|
* Called from widget event handling code on Drag events
|
|
|
|
|
* for drag sources.
|
|
|
|
|
*
|
|
|
|
|
* arguments:
|
|
|
|
|
* toplevel: Toplevel widget that received the event
|
|
|
|
|
* event:
|
|
|
|
|
* results:
|
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gtk_drag_source_handle_event (GtkWidget *widget,
|
|
|
|
|
GdkEvent *event)
|
|
|
|
|
{
|
|
|
|
|
GtkDragSourceInfo *info;
|
|
|
|
|
GdkDragContext *context;
|
2015-07-26 06:10:47 +00:00
|
|
|
|
GtkDragResult result;
|
2006-03-21 16:50:47 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (widget != NULL);
|
|
|
|
|
g_return_if_fail (event != NULL);
|
|
|
|
|
|
|
|
|
|
context = event->dnd.context;
|
|
|
|
|
info = gtk_drag_get_source_info (context, FALSE);
|
|
|
|
|
if (!info)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (event->type)
|
|
|
|
|
{
|
|
|
|
|
case GDK_DROP_FINISHED:
|
2015-07-26 06:10:47 +00:00
|
|
|
|
result = (gdk_drag_context_get_dest_window (context) != NULL) ? GTK_DRAG_RESULT_SUCCESS : GTK_DRAG_RESULT_NO_TARGET;
|
|
|
|
|
gtk_drag_drop_finished (info, result);
|
2006-03-21 16:50:47 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 22:09:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_drag_check_threshold: (method)
|
|
|
|
|
* @widget: a #GtkWidget
|
|
|
|
|
* @start_x: X coordinate of start of drag
|
|
|
|
|
* @start_y: Y coordinate of start of drag
|
|
|
|
|
* @current_x: current X coordinate
|
|
|
|
|
* @current_y: current Y coordinate
|
|
|
|
|
*/
|
2006-03-21 16:50:47 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_drag_check_threshold (GtkWidget *widget,
|
|
|
|
|
gint start_x,
|
|
|
|
|
gint start_y,
|
|
|
|
|
gint current_x,
|
|
|
|
|
gint current_y)
|
|
|
|
|
{
|
|
|
|
|
gint drag_threshold;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
|
|
|
|
|
|
|
|
g_object_get (gtk_widget_get_settings (widget),
|
|
|
|
|
"gtk-dnd-drag-threshold", &drag_threshold,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
return (ABS (current_x - start_x) > drag_threshold ||
|
|
|
|
|
ABS (current_y - start_y) > drag_threshold);
|
|
|
|
|
}
|