1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include "gdkconfig.h"
34 #include "gdk/gdkkeysyms.h"
37 #include "gtkiconfactory.h"
38 #include "gtkicontheme.h"
40 #include "gtkinvisible.h"
44 #include "gtkwindow.h"
46 #include "gtkquartz.h"
47 #include "gdk/quartz/gdkquartz.h"
49 typedef struct _GtkDragSourceSite GtkDragSourceSite;
50 typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
51 typedef struct _GtkDragDestSite GtkDragDestSite;
52 typedef struct _GtkDragDestInfo GtkDragDestInfo;
53 typedef struct _GtkDragFindData GtkDragFindData;
55 static void gtk_drag_find_widget (GtkWidget *widget,
56 GtkDragFindData *data);
57 static void gtk_drag_dest_site_destroy (gpointer data);
58 static void gtk_drag_dest_leave (GtkWidget *widget,
59 GdkDragContext *context,
61 static GtkDragDestInfo *gtk_drag_get_dest_info (GdkDragContext *context,
63 static void gtk_drag_source_site_destroy (gpointer data);
65 static GtkDragSourceInfo *gtk_drag_get_source_info (GdkDragContext *context,
68 extern GdkDragContext *gdk_quartz_drag_source_context (); /* gdk/quartz/gdkdnd-quartz.c */
70 struct _GtkDragSourceSite
72 GdkModifierType start_button_mask;
73 GtkTargetList *target_list; /* Targets for drag data */
74 GdkDragAction actions; /* Possible actions */
77 GtkImageType icon_type;
80 GtkImagePixmapData pixmap;
81 GtkImagePixbufData pixbuf;
82 GtkImageStockData stock;
83 GtkImageIconNameData name;
87 GdkColormap *colormap; /* Colormap for drag icon */
89 /* Stored button press information to detect drag beginning */
94 struct _GtkDragSourceInfo
96 GtkWidget *source_widget;
98 GtkTargetList *target_list; /* Targets for drag data */
99 GdkDragAction possible_actions; /* Actions allowed by source */
100 GdkDragContext *context; /* drag context */
101 NSEvent *nsevent; /* what started it */
102 gint hot_x, hot_y; /* Hot spot for drag */
103 GdkPixbuf *icon_pixbuf;
108 struct _GtkDragDestSite
110 GtkDestDefaults flags;
111 GtkTargetList *target_list;
112 GdkDragAction actions;
114 guint track_motion : 1;
117 struct _GtkDragDestInfo
119 GtkWidget *widget; /* Widget in which drag is in */
120 GdkDragContext *context; /* Drag context */
121 guint dropped : 1; /* Set after we receive a drop */
122 gint drop_x, drop_y; /* Position of drop */
125 struct _GtkDragFindData
129 GdkDragContext *context;
130 GtkDragDestInfo *info;
133 gboolean (*callback) (GtkWidget *widget, GdkDragContext *context,
134 gint x, gint y, guint32 time);
139 @interface GtkDragSourceOwner : NSObject {
140 GtkDragSourceInfo *info;
145 @implementation GtkDragSourceOwner
146 -(void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString *)type
149 GtkSelectionData selection_data;
151 selection_data.selection = GDK_NONE;
152 selection_data.data = NULL;
153 selection_data.length = -1;
154 selection_data.target = _gtk_quartz_pasteboard_type_to_atom (type);
156 if (gtk_target_list_find (info->target_list,
157 selection_data.target,
160 g_signal_emit_by_name (info->widget, "drag-data-get",
166 if (selection_data.length >= 0)
167 _gtk_quartz_set_selection_data_for_pasteboard (sender, &selection_data);
169 g_free (selection_data.data);
173 - (id)initWithInfo:(GtkDragSourceInfo *)anInfo
188 gtk_drag_get_data (GtkWidget *widget,
189 GdkDragContext *context,
193 id <NSDraggingInfo> dragging_info;
194 NSPasteboard *pasteboard;
195 GtkSelectionData *selection_data;
196 GtkDragDestInfo *info;
197 GtkDragDestSite *site;
199 dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
200 pasteboard = [dragging_info draggingPasteboard];
202 info = gtk_drag_get_dest_info (context, FALSE);
203 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
205 selection_data = _gtk_quartz_get_selection_data_from_pasteboard (pasteboard,
208 if (site && site->target_list)
212 if (gtk_target_list_find (site->target_list,
213 selection_data->target,
216 if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
217 selection_data->length >= 0)
218 g_signal_emit_by_name (widget,
219 "drag-data-received",
220 context, info->drop_x, info->drop_y,
227 g_signal_emit_by_name (widget,
228 "drag-data-received",
229 context, info->drop_x, info->drop_y,
234 if (site && site->flags & GTK_DEST_DEFAULT_DROP)
236 gtk_drag_finish (context,
237 (selection_data->length >= 0),
238 (context->action == GDK_ACTION_MOVE),
244 gtk_drag_finish (GdkDragContext *context,
249 GtkDragSourceInfo *info;
250 GdkDragContext* source_context = gdk_quartz_drag_source_context ();
254 info = gtk_drag_get_source_info (source_context, FALSE);
257 info->success = success;
264 gtk_drag_dest_info_destroy (gpointer data)
266 GtkDragDestInfo *info = data;
271 static GtkDragDestInfo *
272 gtk_drag_get_dest_info (GdkDragContext *context,
275 GtkDragDestInfo *info;
276 static GQuark info_quark = 0;
278 info_quark = g_quark_from_static_string ("gtk-dest-info");
280 info = g_object_get_qdata (G_OBJECT (context), info_quark);
283 info = g_new (GtkDragDestInfo, 1);
285 info->context = context;
286 info->dropped = FALSE;
287 g_object_set_qdata_full (G_OBJECT (context), info_quark,
288 info, gtk_drag_dest_info_destroy);
294 static GQuark dest_info_quark = 0;
296 static GtkDragSourceInfo *
297 gtk_drag_get_source_info (GdkDragContext *context,
300 GtkDragSourceInfo *info;
302 if (!dest_info_quark)
303 dest_info_quark = g_quark_from_static_string ("gtk-source-info");
305 info = g_object_get_qdata (G_OBJECT (context), dest_info_quark);
308 info = g_new0 (GtkDragSourceInfo, 1);
309 info->context = context;
310 g_object_set_qdata (G_OBJECT (context), dest_info_quark, info);
317 gtk_drag_clear_source_info (GdkDragContext *context)
319 g_object_set_qdata (G_OBJECT (context), dest_info_quark, NULL);
323 gtk_drag_get_source_widget (GdkDragContext *context)
325 GtkDragSourceInfo *info;
326 GdkDragContext* real_source_context = gdk_quartz_drag_source_context();
328 if (!real_source_context)
331 info = gtk_drag_get_source_info (real_source_context, FALSE);
335 return info->source_widget;
338 /*************************************************************
339 * gtk_drag_highlight_expose:
340 * Callback for expose_event for highlighted widgets.
346 *************************************************************/
349 gtk_drag_highlight_expose (GtkWidget *widget,
350 GdkEventExpose *event,
353 gint x, y, width, height;
355 if (gtk_widget_is_drawable (widget))
358 GdkWindow *window = gtk_widget_get_window (widget);
360 if (!gtk_widget_get_has_window (widget))
362 GtkAllocation allocation;
364 gtk_widget_get_allocation (widget, &allocation);
368 width = allocation.width;
369 height = allocation.height;
375 gdk_drawable_get_size (window, &width, &height);
378 gtk_paint_shadow (gtk_widget_get_style (widget), window,
379 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
381 x, y, width, height);
383 cr = gdk_cairo_create (window);
384 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
385 cairo_set_line_width (cr, 1.0);
388 width - 1, height - 1);
396 /*************************************************************
397 * gtk_drag_highlight:
398 * Highlight the given widget in the default manner.
402 *************************************************************/
405 gtk_drag_highlight (GtkWidget *widget)
407 g_return_if_fail (GTK_IS_WIDGET (widget));
409 g_signal_connect_after (widget, "expose-event",
410 G_CALLBACK (gtk_drag_highlight_expose),
413 gtk_widget_queue_draw (widget);
416 /*************************************************************
417 * gtk_drag_unhighlight:
418 * Refresh the given widget to remove the highlight.
422 *************************************************************/
425 gtk_drag_unhighlight (GtkWidget *widget)
427 g_return_if_fail (GTK_IS_WIDGET (widget));
429 g_signal_handlers_disconnect_by_func (widget,
430 gtk_drag_highlight_expose,
433 gtk_widget_queue_draw (widget);
437 get_toplevel_nswindow (GtkWidget *widget)
439 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
440 GdkWindow *window = gtk_widget_get_window (toplevel);
442 if (gtk_widget_is_toplevel (toplevel) && window)
443 return [gdk_quartz_window_get_nsview (window) window];
449 register_types (GtkWidget *widget, GtkDragDestSite *site)
451 if (site->target_list)
453 NSWindow *nswindow = get_toplevel_nswindow (widget);
455 NSAutoreleasePool *pool;
460 pool = [[NSAutoreleasePool alloc] init];
461 types = _gtk_quartz_target_list_to_pasteboard_types (site->target_list);
463 [nswindow registerForDraggedTypes:[types allObjects]];
471 gtk_drag_dest_realized (GtkWidget *widget,
474 GtkDragDestSite *site = user_data;
476 register_types (widget, site);
480 gtk_drag_dest_hierarchy_changed (GtkWidget *widget,
481 GtkWidget *previous_toplevel,
484 GtkDragDestSite *site = user_data;
486 register_types (widget, site);
490 gtk_drag_dest_site_destroy (gpointer data)
492 GtkDragDestSite *site = data;
494 if (site->target_list)
495 gtk_target_list_unref (site->target_list);
501 gtk_drag_dest_set (GtkWidget *widget,
502 GtkDestDefaults flags,
503 const GtkTargetEntry *targets,
505 GdkDragAction actions)
507 GtkDragDestSite *old_site, *site;
509 g_return_if_fail (GTK_IS_WIDGET (widget));
511 old_site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
513 site = g_new (GtkDragDestSite, 1);
515 site->have_drag = FALSE;
517 site->target_list = gtk_target_list_new (targets, n_targets);
519 site->target_list = NULL;
520 site->actions = actions;
523 site->track_motion = old_site->track_motion;
525 site->track_motion = FALSE;
527 gtk_drag_dest_unset (widget);
529 if (gtk_widget_get_realized (widget))
530 gtk_drag_dest_realized (widget, site);
532 g_signal_connect (widget, "realize",
533 G_CALLBACK (gtk_drag_dest_realized), site);
534 g_signal_connect (widget, "hierarchy-changed",
535 G_CALLBACK (gtk_drag_dest_hierarchy_changed), site);
537 g_object_set_data_full (G_OBJECT (widget), I_("gtk-drag-dest"),
538 site, gtk_drag_dest_site_destroy);
542 gtk_drag_dest_set_proxy (GtkWidget *widget,
543 GdkWindow *proxy_window,
544 GdkDragProtocol protocol,
545 gboolean use_coordinates)
547 g_warning ("gtk_drag_dest_set_proxy is not supported on Mac OS X.");
551 gtk_drag_dest_unset (GtkWidget *widget)
553 GtkDragDestSite *old_site;
555 g_return_if_fail (GTK_IS_WIDGET (widget));
557 old_site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
560 g_signal_handlers_disconnect_by_func (widget,
561 gtk_drag_dest_realized,
563 g_signal_handlers_disconnect_by_func (widget,
564 gtk_drag_dest_hierarchy_changed,
568 g_object_set_data (G_OBJECT (widget), I_("gtk-drag-dest"), NULL);
572 gtk_drag_dest_get_target_list (GtkWidget *widget)
574 GtkDragDestSite *site;
576 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
578 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
580 return site ? site->target_list : NULL;
584 gtk_drag_dest_set_target_list (GtkWidget *widget,
585 GtkTargetList *target_list)
587 GtkDragDestSite *site;
589 g_return_if_fail (GTK_IS_WIDGET (widget));
591 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
595 g_warning ("Can't set a target list on a widget until you've called gtk_drag_dest_set() "
596 "to make the widget into a drag destination");
601 gtk_target_list_ref (target_list);
603 if (site->target_list)
604 gtk_target_list_unref (site->target_list);
606 site->target_list = target_list;
608 register_types (widget, site);
612 gtk_drag_dest_add_text_targets (GtkWidget *widget)
614 GtkTargetList *target_list;
616 target_list = gtk_drag_dest_get_target_list (widget);
618 gtk_target_list_ref (target_list);
620 target_list = gtk_target_list_new (NULL, 0);
621 gtk_target_list_add_text_targets (target_list, 0);
622 gtk_drag_dest_set_target_list (widget, target_list);
623 gtk_target_list_unref (target_list);
627 gtk_drag_dest_add_image_targets (GtkWidget *widget)
629 GtkTargetList *target_list;
631 target_list = gtk_drag_dest_get_target_list (widget);
633 gtk_target_list_ref (target_list);
635 target_list = gtk_target_list_new (NULL, 0);
636 gtk_target_list_add_image_targets (target_list, 0, FALSE);
637 gtk_drag_dest_set_target_list (widget, target_list);
638 gtk_target_list_unref (target_list);
642 gtk_drag_dest_add_uri_targets (GtkWidget *widget)
644 GtkTargetList *target_list;
646 target_list = gtk_drag_dest_get_target_list (widget);
648 gtk_target_list_ref (target_list);
650 target_list = gtk_target_list_new (NULL, 0);
651 gtk_target_list_add_uri_targets (target_list, 0);
652 gtk_drag_dest_set_target_list (widget, target_list);
653 gtk_target_list_unref (target_list);
657 prepend_and_ref_widget (GtkWidget *widget,
660 GSList **slist_p = data;
662 *slist_p = g_slist_prepend (*slist_p, g_object_ref (widget));
666 gtk_drag_find_widget (GtkWidget *widget,
667 GtkDragFindData *data)
669 GtkAllocation new_allocation;
670 gint allocation_to_window_x = 0;
671 gint allocation_to_window_y = 0;
675 if (data->found || !gtk_widget_get_mapped (widget) || !gtk_widget_get_sensitive (widget))
678 /* Note that in the following code, we only count the
679 * position as being inside a WINDOW widget if it is inside
680 * widget->window; points that are outside of widget->window
681 * but within the allocation are not counted. This is consistent
682 * with the way we highlight drag targets.
684 * data->x,y are relative to widget->parent->window (if
685 * widget is not a toplevel, widget->window otherwise).
686 * We compute the allocation of widget in the same coordinates,
687 * clipping to widget->window, and all intermediate
688 * windows. If data->x,y is inside that, then we translate
689 * our coordinates to be relative to widget->window and
692 gtk_widget_get_allocation (widget, &new_allocation);
694 if (gtk_widget_get_parent (widget))
697 GdkWindow *window = gtk_widget_get_window (widget);
698 GdkWindow *parent_window;
699 GtkAllocation allocation;
701 parent_window = gtk_widget_get_window (gtk_widget_get_parent (widget));
703 /* Compute the offset from allocation-relative to
704 * window-relative coordinates.
706 gtk_widget_get_allocation (widget, &allocation);
707 allocation_to_window_x = allocation.x;
708 allocation_to_window_y = allocation.y;
710 if (gtk_widget_get_has_window (widget))
712 /* The allocation is relative to the parent window for
713 * window widgets, not to widget->window.
715 gdk_window_get_position (window, &tx, &ty);
717 allocation_to_window_x -= tx;
718 allocation_to_window_y -= ty;
721 new_allocation.x = 0 + allocation_to_window_x;
722 new_allocation.y = 0 + allocation_to_window_y;
724 while (window && window != parent_window)
726 GdkRectangle window_rect = { 0, 0, 0, 0 };
728 gdk_drawable_get_size (window, &window_rect.width, &window_rect.height);
730 gdk_rectangle_intersect (&new_allocation, &window_rect, &new_allocation);
732 gdk_window_get_position (window, &tx, &ty);
733 new_allocation.x += tx;
735 new_allocation.y += ty;
738 window = gdk_window_get_parent (window);
741 if (!window) /* Window and widget heirarchies didn't match. */
745 if (data->toplevel ||
746 ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
747 (data->x < new_allocation.x + new_allocation.width) &&
748 (data->y < new_allocation.y + new_allocation.height)))
750 /* First, check if the drag is in a valid drop site in
751 * one of our children
753 if (GTK_IS_CONTAINER (widget))
755 GtkDragFindData new_data = *data;
756 GSList *children = NULL;
759 new_data.x -= x_offset;
760 new_data.y -= y_offset;
761 new_data.found = FALSE;
762 new_data.toplevel = FALSE;
764 /* need to reference children temporarily in case the
765 * ::drag-motion/::drag-drop callbacks change the widget hierarchy.
767 gtk_container_forall (GTK_CONTAINER (widget), prepend_and_ref_widget, &children);
768 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
770 if (!new_data.found && gtk_widget_is_drawable (tmp_list->data))
771 gtk_drag_find_widget (tmp_list->data, &new_data);
772 g_object_unref (tmp_list->data);
774 g_slist_free (children);
776 data->found = new_data.found;
779 /* If not, and this widget is registered as a drop site, check to
780 * emit "drag-motion" to check if we are actually in
784 g_object_get_data (G_OBJECT (widget), "gtk-drag-dest"))
786 data->found = data->callback (widget,
788 data->x - x_offset - allocation_to_window_x,
789 data->y - y_offset - allocation_to_window_y,
791 /* If so, send a "drag-leave" to the last widget */
794 if (data->info->widget && data->info->widget != widget)
796 gtk_drag_dest_leave (data->info->widget, data->context, data->time);
798 data->info->widget = widget;
805 gtk_drag_dest_leave (GtkWidget *widget,
806 GdkDragContext *context,
809 GtkDragDestSite *site;
811 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
812 g_return_if_fail (site != NULL);
814 if ((site->flags & GTK_DEST_DEFAULT_HIGHLIGHT) && site->have_drag)
815 gtk_drag_unhighlight (widget);
817 if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag ||
819 g_signal_emit_by_name (widget, "drag-leave", context, time);
821 site->have_drag = FALSE;
825 gtk_drag_dest_motion (GtkWidget *widget,
826 GdkDragContext *context,
831 GtkDragDestSite *site;
832 GdkDragAction action = 0;
835 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
836 g_return_val_if_fail (site != NULL, FALSE);
838 if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
840 if (context->suggested_action & site->actions)
841 action = context->suggested_action;
843 if (action && gtk_drag_dest_find_target (widget, context, NULL))
845 if (!site->have_drag)
847 site->have_drag = TRUE;
848 if (site->flags & GTK_DEST_DEFAULT_HIGHLIGHT)
849 gtk_drag_highlight (widget);
852 gdk_drag_status (context, action, time);
856 gdk_drag_status (context, 0, time);
857 if (!site->track_motion)
862 g_signal_emit_by_name (widget, "drag-motion",
863 context, x, y, time, &retval);
865 return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
869 gtk_drag_dest_drop (GtkWidget *widget,
870 GdkDragContext *context,
875 GtkDragDestSite *site;
876 GtkDragDestInfo *info;
879 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
880 g_return_val_if_fail (site != NULL, FALSE);
882 info = gtk_drag_get_dest_info (context, FALSE);
883 g_return_val_if_fail (info != NULL, FALSE);
888 if (site->flags & GTK_DEST_DEFAULT_DROP)
890 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
892 if (target == GDK_NONE)
894 gtk_drag_finish (context, FALSE, FALSE, time);
898 gtk_drag_get_data (widget, context, target, time);
901 g_signal_emit_by_name (widget, "drag-drop",
902 context, x, y, time, &retval);
904 return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval;
908 gtk_drag_dest_set_track_motion (GtkWidget *widget,
909 gboolean track_motion)
911 GtkDragDestSite *site;
913 g_return_if_fail (GTK_IS_WIDGET (widget));
915 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
917 g_return_if_fail (site != NULL);
919 site->track_motion = track_motion != FALSE;
923 gtk_drag_dest_get_track_motion (GtkWidget *widget)
925 GtkDragDestSite *site;
927 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
929 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
932 return site->track_motion;
938 _gtk_drag_dest_handle_event (GtkWidget *toplevel,
941 GtkDragDestInfo *info;
942 GdkDragContext *context;
944 g_return_if_fail (toplevel != NULL);
945 g_return_if_fail (event != NULL);
947 context = event->dnd.context;
949 info = gtk_drag_get_dest_info (context, TRUE);
951 /* Find the widget for the event */
960 gtk_drag_dest_leave (info->widget, context, event->dnd.time);
965 case GDK_DRAG_MOTION:
968 GtkDragFindData data;
971 if (event->type == GDK_DROP_START)
973 info->dropped = TRUE;
974 /* We send a leave here so that the widget unhighlights
979 gtk_drag_dest_leave (info->widget, context, event->dnd.time);
984 gdk_window_get_position (gtk_widget_get_window (toplevel), &tx, &ty);
986 data.x = event->dnd.x_root - tx;
987 data.y = event->dnd.y_root - ty;
988 data.context = context;
991 data.toplevel = TRUE;
992 data.callback = (event->type == GDK_DRAG_MOTION) ?
993 gtk_drag_dest_motion : gtk_drag_dest_drop;
994 data.time = event->dnd.time;
996 gtk_drag_find_widget (toplevel, &data);
998 if (info->widget && !data.found)
1000 gtk_drag_dest_leave (info->widget, context, event->dnd.time);
1001 info->widget = NULL;
1006 if (event->type == GDK_DRAG_MOTION)
1009 gdk_drag_status (context, 0, event->dnd.time);
1014 g_assert_not_reached ();
1021 gtk_drag_dest_find_target (GtkWidget *widget,
1022 GdkDragContext *context,
1023 GtkTargetList *target_list)
1025 id <NSDraggingInfo> dragging_info;
1026 NSPasteboard *pasteboard;
1027 GtkWidget *source_widget;
1029 GList *tmp_source = NULL;
1030 GList *source_targets;
1032 g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE);
1033 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
1034 g_return_val_if_fail (!context->is_source, GDK_NONE);
1036 dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
1037 pasteboard = [dragging_info draggingPasteboard];
1039 source_widget = gtk_drag_get_source_widget (context);
1041 if (target_list == NULL)
1042 target_list = gtk_drag_dest_get_target_list (widget);
1044 if (target_list == NULL)
1047 source_targets = _gtk_quartz_pasteboard_types_to_atom_list ([pasteboard types]);
1048 tmp_target = target_list->list;
1051 GtkTargetPair *pair = tmp_target->data;
1052 tmp_source = source_targets;
1055 if (tmp_source->data == GUINT_TO_POINTER (pair->target))
1057 if ((!(pair->flags & GTK_TARGET_SAME_APP) || source_widget) &&
1058 (!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)))
1060 g_list_free (source_targets);
1061 return pair->target;
1066 tmp_source = tmp_source->next;
1068 tmp_target = tmp_target->next;
1071 g_list_free (source_targets);
1076 gtk_drag_begin_idle (gpointer arg)
1078 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1079 GdkDragContext* context = (GdkDragContext*) arg;
1080 GtkDragSourceInfo* info = gtk_drag_get_source_info (context, FALSE);
1082 NSPasteboard *pasteboard;
1083 GtkDragSourceOwner *owner;
1086 NSImage *drag_image;
1088 g_assert (info != NULL);
1090 pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
1091 owner = [[GtkDragSourceOwner alloc] initWithInfo:info];
1093 types = _gtk_quartz_target_list_to_pasteboard_types (info->target_list);
1095 [pasteboard declareTypes:[types allObjects] owner:owner];
1100 if ((nswindow = get_toplevel_nswindow (info->source_widget)) == NULL)
1103 /* Ref the context. It's unreffed when the drag has been aborted */
1104 g_object_ref (info->context);
1106 /* FIXME: If the event isn't a mouse event, use the global cursor position instead */
1107 point = [info->nsevent locationInWindow];
1109 drag_image = _gtk_quartz_create_image_from_pixbuf (info->icon_pixbuf);
1111 [nswindow dragImage:drag_image
1113 offset:NSMakeSize(0, 0)
1115 pasteboard:pasteboard
1119 [info->nsevent release];
1120 [drag_image release];
1127 static GdkDragContext *
1128 gtk_drag_begin_internal (GtkWidget *widget,
1129 GtkDragSourceSite *site,
1130 GtkTargetList *target_list,
1131 GdkDragAction actions,
1135 GtkDragSourceInfo *info;
1136 GdkDragContext *context;
1139 context = gdk_drag_begin (NULL, NULL);
1140 context->is_source = TRUE;
1142 info = gtk_drag_get_source_info (context, TRUE);
1144 info->source_widget = g_object_ref (widget);
1145 info->widget = g_object_ref (widget);
1146 info->target_list = target_list;
1147 gtk_target_list_ref (target_list);
1149 info->possible_actions = actions;
1151 g_signal_emit_by_name (widget, "drag-begin", info->context);
1153 /* Ensure that we have an icon before we start the drag; the
1154 * application may have set one in ::drag_begin, or it may
1157 if (!info->icon_pixbuf)
1159 if (!site || site->icon_type == GTK_IMAGE_EMPTY)
1160 gtk_drag_set_icon_default (context);
1162 switch (site->icon_type)
1164 case GTK_IMAGE_PIXMAP:
1165 /* This is not supported, so just set a small transparent pixbuf
1166 * since we need to have something.
1169 gtk_drag_set_icon_pixmap (context,
1171 site->icon_data.pixmap.pixmap,
1178 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
1179 gdk_pixbuf_fill (pixbuf, 0xffffff);
1181 gtk_drag_set_icon_pixbuf (context,
1185 g_object_unref (pixbuf);
1188 case GTK_IMAGE_PIXBUF:
1189 gtk_drag_set_icon_pixbuf (context,
1190 site->icon_data.pixbuf.pixbuf,
1193 case GTK_IMAGE_STOCK:
1194 gtk_drag_set_icon_stock (context,
1195 site->icon_data.stock.stock_id,
1198 case GTK_IMAGE_ICON_NAME:
1199 gtk_drag_set_icon_name (context,
1200 site->icon_data.name.icon_name,
1203 case GTK_IMAGE_EMPTY:
1205 g_assert_not_reached();
1210 nswindow = get_toplevel_nswindow (widget);
1211 info->nsevent = [nswindow currentEvent];
1212 [info->nsevent retain];
1214 /* drag will begin in an idle handler to avoid nested run loops */
1216 g_idle_add_full (G_PRIORITY_HIGH_IDLE, gtk_drag_begin_idle, context, NULL);
1218 gdk_pointer_ungrab (0);
1224 gtk_drag_begin (GtkWidget *widget,
1225 GtkTargetList *targets,
1226 GdkDragAction actions,
1230 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1231 g_return_val_if_fail (gtk_widget_get_realized (widget), NULL);
1232 g_return_val_if_fail (targets != NULL, NULL);
1234 return gtk_drag_begin_internal (widget, NULL, targets,
1235 actions, button, event);
1240 gtk_drag_source_event_cb (GtkWidget *widget,
1244 GtkDragSourceSite *site;
1245 gboolean retval = FALSE;
1246 site = (GtkDragSourceSite *)data;
1248 switch (event->type)
1250 case GDK_BUTTON_PRESS:
1251 if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask)
1253 site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1));
1254 site->x = event->button.x;
1255 site->y = event->button.y;
1259 case GDK_BUTTON_RELEASE:
1260 if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask)
1261 site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1));
1264 case GDK_MOTION_NOTIFY:
1265 if (site->state & event->motion.state & site->start_button_mask)
1267 /* FIXME: This is really broken and can leave us
1273 if (site->state & event->motion.state &
1274 GDK_BUTTON1_MASK << (i - 1))
1278 if (gtk_drag_check_threshold (widget, site->x, site->y,
1279 event->motion.x, event->motion.y))
1282 gtk_drag_begin_internal (widget, site, site->target_list,
1291 default: /* hit for 2/3BUTTON_PRESS */
1299 gtk_drag_source_set (GtkWidget *widget,
1300 GdkModifierType start_button_mask,
1301 const GtkTargetEntry *targets,
1303 GdkDragAction actions)
1305 GtkDragSourceSite *site;
1307 g_return_if_fail (GTK_IS_WIDGET (widget));
1309 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1311 gtk_widget_add_events (widget,
1312 gtk_widget_get_events (widget) |
1313 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1314 GDK_BUTTON_MOTION_MASK);
1318 if (site->target_list)
1319 gtk_target_list_unref (site->target_list);
1323 site = g_new0 (GtkDragSourceSite, 1);
1325 site->icon_type = GTK_IMAGE_EMPTY;
1327 g_signal_connect (widget, "button-press-event",
1328 G_CALLBACK (gtk_drag_source_event_cb),
1330 g_signal_connect (widget, "button-release-event",
1331 G_CALLBACK (gtk_drag_source_event_cb),
1333 g_signal_connect (widget, "motion-notify-event",
1334 G_CALLBACK (gtk_drag_source_event_cb),
1337 g_object_set_data_full (G_OBJECT (widget),
1338 I_("gtk-site-data"),
1339 site, gtk_drag_source_site_destroy);
1342 site->start_button_mask = start_button_mask;
1344 site->target_list = gtk_target_list_new (targets, n_targets);
1346 site->actions = actions;
1349 /*************************************************************
1350 * gtk_drag_source_unset
1351 * Unregister this widget as a drag source.
1355 *************************************************************/
1358 gtk_drag_source_unset (GtkWidget *widget)
1360 GtkDragSourceSite *site;
1362 g_return_if_fail (GTK_IS_WIDGET (widget));
1364 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1368 g_signal_handlers_disconnect_by_func (widget,
1369 gtk_drag_source_event_cb,
1371 g_object_set_data (G_OBJECT (widget), I_("gtk-site-data"), NULL);
1376 gtk_drag_source_get_target_list (GtkWidget *widget)
1378 GtkDragSourceSite *site;
1380 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1382 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1384 return site ? site->target_list : NULL;
1389 gtk_drag_source_set_target_list (GtkWidget *widget,
1390 GtkTargetList *target_list)
1392 GtkDragSourceSite *site;
1394 g_return_if_fail (GTK_IS_WIDGET (widget));
1396 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1399 g_warning ("gtk_drag_source_set_target_list() requires the widget "
1400 "to already be a drag source.");
1405 gtk_target_list_ref (target_list);
1407 if (site->target_list)
1408 gtk_target_list_unref (site->target_list);
1410 site->target_list = target_list;
1414 * gtk_drag_source_add_text_targets:
1415 * @widget: a #GtkWidget that's is a drag source
1417 * Add the text targets supported by #GtkSelection to
1418 * the target list of the drag source. The targets
1419 * are added with @info = 0. If you need another value,
1420 * use gtk_target_list_add_text_targets() and
1421 * gtk_drag_source_set_target_list().
1426 gtk_drag_source_add_text_targets (GtkWidget *widget)
1428 GtkTargetList *target_list;
1430 target_list = gtk_drag_source_get_target_list (widget);
1432 gtk_target_list_ref (target_list);
1434 target_list = gtk_target_list_new (NULL, 0);
1435 gtk_target_list_add_text_targets (target_list, 0);
1436 gtk_drag_source_set_target_list (widget, target_list);
1437 gtk_target_list_unref (target_list);
1441 gtk_drag_source_add_image_targets (GtkWidget *widget)
1443 GtkTargetList *target_list;
1445 target_list = gtk_drag_source_get_target_list (widget);
1447 gtk_target_list_ref (target_list);
1449 target_list = gtk_target_list_new (NULL, 0);
1450 gtk_target_list_add_image_targets (target_list, 0, TRUE);
1451 gtk_drag_source_set_target_list (widget, target_list);
1452 gtk_target_list_unref (target_list);
1456 gtk_drag_source_add_uri_targets (GtkWidget *widget)
1458 GtkTargetList *target_list;
1460 target_list = gtk_drag_source_get_target_list (widget);
1462 gtk_target_list_ref (target_list);
1464 target_list = gtk_target_list_new (NULL, 0);
1465 gtk_target_list_add_uri_targets (target_list, 0);
1466 gtk_drag_source_set_target_list (widget, target_list);
1467 gtk_target_list_unref (target_list);
1471 gtk_drag_source_unset_icon (GtkDragSourceSite *site)
1473 switch (site->icon_type)
1475 case GTK_IMAGE_EMPTY:
1477 case GTK_IMAGE_PIXMAP:
1478 if (site->icon_data.pixmap.pixmap)
1479 g_object_unref (site->icon_data.pixmap.pixmap);
1480 if (site->icon_mask)
1481 g_object_unref (site->icon_mask);
1483 case GTK_IMAGE_PIXBUF:
1484 g_object_unref (site->icon_data.pixbuf.pixbuf);
1486 case GTK_IMAGE_STOCK:
1487 g_free (site->icon_data.stock.stock_id);
1489 case GTK_IMAGE_ICON_NAME:
1490 g_free (site->icon_data.name.icon_name);
1493 g_assert_not_reached();
1496 site->icon_type = GTK_IMAGE_EMPTY;
1499 g_object_unref (site->colormap);
1500 site->colormap = NULL;
1504 gtk_drag_source_site_destroy (gpointer data)
1506 GtkDragSourceSite *site = data;
1508 if (site->target_list)
1509 gtk_target_list_unref (site->target_list);
1511 gtk_drag_source_unset_icon (site);
1516 gtk_drag_source_set_icon (GtkWidget *widget,
1517 GdkColormap *colormap,
1521 GtkDragSourceSite *site;
1523 g_return_if_fail (GTK_IS_WIDGET (widget));
1524 g_return_if_fail (GDK_IS_COLORMAP (colormap));
1525 g_return_if_fail (GDK_IS_PIXMAP (pixmap));
1526 g_return_if_fail (!mask || GDK_IS_PIXMAP (mask));
1528 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1529 g_return_if_fail (site != NULL);
1531 g_object_ref (colormap);
1532 g_object_ref (pixmap);
1534 g_object_ref (mask);
1536 gtk_drag_source_unset_icon (site);
1538 site->icon_type = GTK_IMAGE_PIXMAP;
1540 site->icon_data.pixmap.pixmap = pixmap;
1541 site->icon_mask = mask;
1542 site->colormap = colormap;
1546 gtk_drag_source_set_icon_pixbuf (GtkWidget *widget,
1549 GtkDragSourceSite *site;
1551 g_return_if_fail (GTK_IS_WIDGET (widget));
1552 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
1554 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1555 g_return_if_fail (site != NULL);
1556 g_object_ref (pixbuf);
1558 gtk_drag_source_unset_icon (site);
1560 site->icon_type = GTK_IMAGE_PIXBUF;
1561 site->icon_data.pixbuf.pixbuf = pixbuf;
1565 * gtk_drag_source_set_icon_stock:
1566 * @widget: a #GtkWidget
1567 * @stock_id: the ID of the stock icon to use
1569 * Sets the icon that will be used for drags from a particular source
1573 gtk_drag_source_set_icon_stock (GtkWidget *widget,
1574 const gchar *stock_id)
1576 GtkDragSourceSite *site;
1578 g_return_if_fail (GTK_IS_WIDGET (widget));
1579 g_return_if_fail (stock_id != NULL);
1581 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1582 g_return_if_fail (site != NULL);
1584 gtk_drag_source_unset_icon (site);
1586 site->icon_type = GTK_IMAGE_STOCK;
1587 site->icon_data.stock.stock_id = g_strdup (stock_id);
1591 * gtk_drag_source_set_icon_name:
1592 * @widget: a #GtkWidget
1593 * @icon_name: name of icon to use
1595 * Sets the icon that will be used for drags from a particular source
1596 * to a themed icon. See the docs for #GtkIconTheme for more details.
1601 gtk_drag_source_set_icon_name (GtkWidget *widget,
1602 const gchar *icon_name)
1604 GtkDragSourceSite *site;
1606 g_return_if_fail (GTK_IS_WIDGET (widget));
1607 g_return_if_fail (icon_name != NULL);
1609 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1610 g_return_if_fail (site != NULL);
1612 gtk_drag_source_unset_icon (site);
1614 site->icon_type = GTK_IMAGE_ICON_NAME;
1615 site->icon_data.name.icon_name = g_strdup (icon_name);
1620 * gtk_drag_set_icon_widget:
1621 * @context: the context for a drag. (This must be called
1622 with a context for the source side of a drag)
1623 * @widget: a toplevel window to use as an icon.
1624 * @hot_x: the X offset within @widget of the hotspot.
1625 * @hot_y: the Y offset within @widget of the hotspot.
1627 * Changes the icon for a widget to a given widget. GTK+
1628 * will not destroy the icon, so if you don't want
1629 * it to persist, you should connect to the "drag-end"
1630 * signal and destroy it yourself.
1633 gtk_drag_set_icon_widget (GdkDragContext *context,
1638 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1639 g_return_if_fail (context->is_source);
1640 g_return_if_fail (GTK_IS_WIDGET (widget));
1642 g_warning ("gtk_drag_set_icon_widget is not supported on Mac OS X");
1646 set_icon_stock_pixbuf (GdkDragContext *context,
1647 const gchar *stock_id,
1652 GtkDragSourceInfo *info;
1654 info = gtk_drag_get_source_info (context, FALSE);
1658 pixbuf = gtk_widget_render_icon (info->widget, stock_id,
1659 GTK_ICON_SIZE_DND, NULL);
1663 g_warning ("Cannot load drag icon from stock_id %s", stock_id);
1668 g_object_ref (pixbuf);
1670 if (info->icon_pixbuf)
1671 g_object_unref (info->icon_pixbuf);
1672 info->icon_pixbuf = pixbuf;
1673 info->hot_x = hot_x;
1674 info->hot_y = hot_y;
1678 * gtk_drag_set_icon_pixbuf:
1679 * @context: the context for a drag. (This must be called
1680 * with a context for the source side of a drag)
1681 * @pixbuf: the #GdkPixbuf to use as the drag icon.
1682 * @hot_x: the X offset within @widget of the hotspot.
1683 * @hot_y: the Y offset within @widget of the hotspot.
1685 * Sets @pixbuf as the icon for a given drag.
1688 gtk_drag_set_icon_pixbuf (GdkDragContext *context,
1693 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1694 g_return_if_fail (context->is_source);
1695 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
1697 set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
1701 * gtk_drag_set_icon_stock:
1702 * @context: the context for a drag. (This must be called
1703 * with a context for the source side of a drag)
1704 * @stock_id: the ID of the stock icon to use for the drag.
1705 * @hot_x: the X offset within the icon of the hotspot.
1706 * @hot_y: the Y offset within the icon of the hotspot.
1708 * Sets the icon for a given drag from a stock ID.
1711 gtk_drag_set_icon_stock (GdkDragContext *context,
1712 const gchar *stock_id,
1717 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1718 g_return_if_fail (context->is_source);
1719 g_return_if_fail (stock_id != NULL);
1721 set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y);
1725 * gtk_drag_set_icon_pixmap:
1726 * @context: the context for a drag. (This must be called
1727 * with a context for the source side of a drag)
1728 * @colormap: the colormap of the icon
1729 * @pixmap: the image data for the icon
1730 * @mask: the transparency mask for the icon
1731 * @hot_x: the X offset within @pixmap of the hotspot.
1732 * @hot_y: the Y offset within @pixmap of the hotspot.
1734 * Sets @pixmap as the icon for a given drag. GTK+ retains
1735 * references for the arguments, and will release them when
1736 * they are no longer needed. In general, gtk_drag_set_icon_pixbuf()
1737 * will be more convenient to use.
1740 gtk_drag_set_icon_pixmap (GdkDragContext *context,
1741 GdkColormap *colormap,
1749 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1750 g_return_if_fail (context->is_source);
1751 g_return_if_fail (GDK_IS_COLORMAP (colormap));
1752 g_return_if_fail (GDK_IS_PIXMAP (pixmap));
1754 pixbuf = gdk_pixbuf_get_from_drawable (NULL, pixmap, colormap,
1759 gtk_drag_set_icon_pixbuf (context, pixbuf, hot_x, hot_y);
1760 g_object_unref (pixbuf);
1764 * gtk_drag_set_icon_name:
1765 * @context: the context for a drag. (This must be called
1766 * with a context for the source side of a drag)
1767 * @icon_name: name of icon to use
1768 * @hot_x: the X offset of the hotspot within the icon
1769 * @hot_y: the Y offset of the hotspot within the icon
1771 * Sets the icon for a given drag from a named themed icon. See
1772 * the docs for #GtkIconTheme for more details. Note that the
1773 * size of the icon depends on the icon theme (the icon is
1774 * loaded at the symbolic size #GTK_ICON_SIZE_DND), thus
1775 * @hot_x and @hot_y have to be used with care.
1780 gtk_drag_set_icon_name (GdkDragContext *context,
1781 const gchar *icon_name,
1786 GtkSettings *settings;
1787 GtkIconTheme *icon_theme;
1789 gint width, height, icon_size;
1791 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1792 g_return_if_fail (context->is_source);
1793 g_return_if_fail (icon_name != NULL);
1795 screen = gdk_drawable_get_screen (context->source_window);
1796 g_return_if_fail (screen != NULL);
1798 settings = gtk_settings_get_for_screen (screen);
1799 if (gtk_icon_size_lookup_for_settings (settings,
1802 icon_size = MAX (width, height);
1804 icon_size = 32; /* default value for GTK_ICON_SIZE_DND */
1806 icon_theme = gtk_icon_theme_get_for_screen (screen);
1808 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
1809 icon_size, 0, NULL);
1811 set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
1813 g_warning ("Cannot load drag icon from icon name %s", icon_name);
1817 * gtk_drag_set_icon_default:
1818 * @context: the context for a drag. (This must be called
1819 with a context for the source side of a drag)
1821 * Sets the icon for a particular drag to the default
1825 gtk_drag_set_icon_default (GdkDragContext *context)
1827 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1828 g_return_if_fail (context->is_source);
1830 gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2);
1834 gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
1836 if (info->icon_pixbuf)
1837 g_object_unref (info->icon_pixbuf);
1839 g_signal_emit_by_name (info->widget, "drag-end",
1842 if (info->source_widget)
1843 g_object_unref (info->source_widget);
1846 g_object_unref (info->widget);
1848 gtk_target_list_unref (info->target_list);
1850 gtk_drag_clear_source_info (info->context);
1851 g_object_unref (info->context);
1857 drag_drop_finished_idle_cb (gpointer data)
1859 gtk_drag_source_info_destroy (data);
1864 gtk_drag_drop_finished (GtkDragSourceInfo *info)
1866 if (info->success && info->delete)
1867 g_signal_emit_by_name (info->source_widget, "drag-data-delete",
1870 /* Workaround for the fact that the NS API blocks until the drag is
1871 * over. This way the context is still valid when returning from
1872 * drag_begin, even if it will still be quite useless. See bug #501588.
1874 g_idle_add (drag_drop_finished_idle_cb, info);
1877 /*************************************************************
1878 * _gtk_drag_source_handle_event:
1879 * Called from widget event handling code on Drag events
1883 * toplevel: Toplevel widget that received the event
1886 *************************************************************/
1889 _gtk_drag_source_handle_event (GtkWidget *widget,
1892 GtkDragSourceInfo *info;
1893 GdkDragContext *context;
1895 g_return_if_fail (widget != NULL);
1896 g_return_if_fail (event != NULL);
1898 context = event->dnd.context;
1899 info = gtk_drag_get_source_info (context, FALSE);
1903 switch (event->type)
1905 case GDK_DROP_FINISHED:
1906 gtk_drag_drop_finished (info);
1909 g_assert_not_reached ();
1915 gtk_drag_check_threshold (GtkWidget *widget,
1921 gint drag_threshold;
1923 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1925 g_object_get (gtk_widget_get_settings (widget),
1926 "gtk-dnd-drag-threshold", &drag_threshold,
1929 return (ABS (current_x - start_x) > drag_threshold ||
1930 ABS (current_y - start_y) > drag_threshold);