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/.
35 #include "gtkiconfactory.h"
36 #include "gtkicontheme.h"
37 #include "gtkimageprivate.h"
38 #include "gtkinvisible.h"
42 #include "gtkwindow.h"
44 #include "gtkquartz.h"
45 #include "gdk/quartz/gdkquartz.h"
46 #include "gtkselectionprivate.h"
48 typedef struct _GtkDragSourceSite GtkDragSourceSite;
49 typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
50 typedef struct _GtkDragDestSite GtkDragDestSite;
51 typedef struct _GtkDragDestInfo GtkDragDestInfo;
52 typedef struct _GtkDragFindData GtkDragFindData;
54 static void gtk_drag_find_widget (GtkWidget *widget,
55 GtkDragFindData *data);
56 static void gtk_drag_dest_site_destroy (gpointer data);
57 static void gtk_drag_dest_leave (GtkWidget *widget,
58 GdkDragContext *context,
60 static GtkDragDestInfo *gtk_drag_get_dest_info (GdkDragContext *context,
62 static void gtk_drag_source_site_destroy (gpointer data);
64 static GtkDragSourceInfo *gtk_drag_get_source_info (GdkDragContext *context,
67 extern GdkDragContext *gdk_quartz_drag_source_context (); /* gdk/quartz/gdkdnd-quartz.c */
69 struct _GtkDragSourceSite
71 GdkModifierType start_button_mask;
72 GtkTargetList *target_list; /* Targets for drag data */
73 GdkDragAction actions; /* Possible actions */
76 GtkImageType icon_type;
79 GtkImagePixbufData pixbuf;
80 GtkImageStockData stock;
81 GtkImageIconNameData name;
84 /* Stored button press information to detect drag beginning */
89 struct _GtkDragSourceInfo
91 GtkWidget *source_widget;
93 GtkTargetList *target_list; /* Targets for drag data */
94 GdkDragAction possible_actions; /* Actions allowed by source */
95 GdkDragContext *context; /* drag context */
96 NSEvent *nsevent; /* what started it */
97 gint hot_x, hot_y; /* Hot spot for drag */
98 GdkPixbuf *icon_pixbuf;
103 struct _GtkDragDestSite
105 GtkDestDefaults flags;
106 GtkTargetList *target_list;
107 GdkDragAction actions;
109 guint track_motion : 1;
112 struct _GtkDragDestInfo
114 GtkWidget *widget; /* Widget in which drag is in */
115 GdkDragContext *context; /* Drag context */
116 guint dropped : 1; /* Set after we receive a drop */
117 gint drop_x, drop_y; /* Position of drop */
120 struct _GtkDragFindData
124 GdkDragContext *context;
125 GtkDragDestInfo *info;
128 gboolean (*callback) (GtkWidget *widget, GdkDragContext *context,
129 gint x, gint y, guint32 time);
134 @interface GtkDragSourceOwner : NSObject {
135 GtkDragSourceInfo *info;
140 @implementation GtkDragSourceOwner
141 -(void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSString *)type
144 GtkSelectionData selection_data;
146 selection_data.selection = GDK_NONE;
147 selection_data.data = NULL;
148 selection_data.length = -1;
149 selection_data.target = _gtk_quartz_pasteboard_type_to_atom (type);
150 selection_data.display = gdk_display_get_default ();
152 if (gtk_target_list_find (info->target_list,
153 selection_data.target,
156 g_signal_emit_by_name (info->widget, "drag-data-get",
162 if (selection_data.length >= 0)
163 _gtk_quartz_set_selection_data_for_pasteboard (sender, &selection_data);
165 g_free (selection_data.data);
169 - (id)initWithInfo:(GtkDragSourceInfo *)anInfo
184 gtk_drag_get_data (GtkWidget *widget,
185 GdkDragContext *context,
189 id <NSDraggingInfo> dragging_info;
190 NSPasteboard *pasteboard;
191 GtkSelectionData *selection_data;
192 GtkDragDestInfo *info;
193 GtkDragDestSite *site;
195 dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
196 pasteboard = [dragging_info draggingPasteboard];
198 info = gtk_drag_get_dest_info (context, FALSE);
199 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
201 selection_data = _gtk_quartz_get_selection_data_from_pasteboard (pasteboard,
204 if (site && site->target_list)
208 if (gtk_target_list_find (site->target_list,
209 selection_data->target,
212 if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
213 selection_data->length >= 0)
214 g_signal_emit_by_name (widget,
215 "drag-data-received",
216 context, info->drop_x, info->drop_y,
223 g_signal_emit_by_name (widget,
224 "drag-data-received",
225 context, info->drop_x, info->drop_y,
230 if (site && site->flags & GTK_DEST_DEFAULT_DROP)
232 gtk_drag_finish (context,
233 (selection_data->length >= 0),
234 (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
240 gtk_drag_finish (GdkDragContext *context,
245 GtkDragSourceInfo *info;
246 GdkDragContext* source_context = gdk_quartz_drag_source_context ();
250 info = gtk_drag_get_source_info (source_context, FALSE);
253 info->success = success;
260 gtk_drag_dest_info_destroy (gpointer data)
262 GtkDragDestInfo *info = data;
267 static GtkDragDestInfo *
268 gtk_drag_get_dest_info (GdkDragContext *context,
271 GtkDragDestInfo *info;
272 static GQuark info_quark = 0;
274 info_quark = g_quark_from_static_string ("gtk-dest-info");
276 info = g_object_get_qdata (G_OBJECT (context), info_quark);
279 info = g_new (GtkDragDestInfo, 1);
281 info->context = context;
282 info->dropped = FALSE;
283 g_object_set_qdata_full (G_OBJECT (context), info_quark,
284 info, gtk_drag_dest_info_destroy);
290 static GQuark dest_info_quark = 0;
292 static GtkDragSourceInfo *
293 gtk_drag_get_source_info (GdkDragContext *context,
296 GtkDragSourceInfo *info;
298 if (!dest_info_quark)
299 dest_info_quark = g_quark_from_static_string ("gtk-source-info");
301 info = g_object_get_qdata (G_OBJECT (context), dest_info_quark);
304 info = g_new0 (GtkDragSourceInfo, 1);
305 info->context = context;
306 g_object_set_qdata (G_OBJECT (context), dest_info_quark, info);
313 gtk_drag_clear_source_info (GdkDragContext *context)
315 g_object_set_qdata (G_OBJECT (context), dest_info_quark, NULL);
319 gtk_drag_get_source_widget (GdkDragContext *context)
321 GtkDragSourceInfo *info;
322 GdkDragContext* real_source_context = gdk_quartz_drag_source_context();
324 if (!real_source_context)
327 info = gtk_drag_get_source_info (real_source_context, FALSE);
331 return info->source_widget;
334 /*************************************************************
335 * gtk_drag_highlight_draw:
336 * Callback for expose_event for highlighted widgets.
342 *************************************************************/
345 gtk_drag_highlight_draw (GtkWidget *widget,
349 int width = gtk_widget_get_allocated_width (widget);
350 int height = gtk_widget_get_allocated_height (widget);
351 GtkStyleContext *context = gtk_widget_get_style_context (widget);
353 gtk_style_context_save (context);
354 gtk_style_context_add_class (context, GTK_STYLE_CLASS_DND);
356 gtk_render_frame (context, cr, 0, 0, width, height);
358 gtk_style_context_restore (context);
360 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
361 cairo_set_line_width (cr, 1.0);
364 width - 1, height - 1);
370 /*************************************************************
371 * gtk_drag_highlight:
372 * Highlight the given widget in the default manner.
376 *************************************************************/
379 gtk_drag_highlight (GtkWidget *widget)
381 g_return_if_fail (GTK_IS_WIDGET (widget));
383 g_signal_connect_after (widget, "draw",
384 G_CALLBACK (gtk_drag_highlight_draw),
387 gtk_widget_queue_draw (widget);
390 /*************************************************************
391 * gtk_drag_unhighlight:
392 * Refresh the given widget to remove the highlight.
396 *************************************************************/
399 gtk_drag_unhighlight (GtkWidget *widget)
401 g_return_if_fail (GTK_IS_WIDGET (widget));
403 g_signal_handlers_disconnect_by_func (widget,
404 gtk_drag_highlight_draw,
407 gtk_widget_queue_draw (widget);
411 get_toplevel_nswindow (GtkWidget *widget)
413 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
414 GdkWindow *window = gtk_widget_get_window (toplevel);
416 if (gtk_widget_is_toplevel (toplevel) && window)
417 return [gdk_quartz_window_get_nsview (window) window];
423 register_types (GtkWidget *widget, GtkDragDestSite *site)
425 if (site->target_list)
427 NSWindow *nswindow = get_toplevel_nswindow (widget);
429 NSAutoreleasePool *pool;
434 pool = [[NSAutoreleasePool alloc] init];
435 types = _gtk_quartz_target_list_to_pasteboard_types (site->target_list);
437 [nswindow registerForDraggedTypes:[types allObjects]];
445 gtk_drag_dest_realized (GtkWidget *widget,
448 GtkDragDestSite *site = user_data;
450 register_types (widget, site);
454 gtk_drag_dest_hierarchy_changed (GtkWidget *widget,
455 GtkWidget *previous_toplevel,
458 GtkDragDestSite *site = user_data;
460 register_types (widget, site);
464 gtk_drag_dest_site_destroy (gpointer data)
466 GtkDragDestSite *site = data;
468 if (site->target_list)
469 gtk_target_list_unref (site->target_list);
475 gtk_drag_dest_set (GtkWidget *widget,
476 GtkDestDefaults flags,
477 const GtkTargetEntry *targets,
479 GdkDragAction actions)
481 GtkDragDestSite *old_site, *site;
483 g_return_if_fail (GTK_IS_WIDGET (widget));
485 old_site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
487 site = g_new (GtkDragDestSite, 1);
489 site->have_drag = FALSE;
491 site->target_list = gtk_target_list_new (targets, n_targets);
493 site->target_list = NULL;
494 site->actions = actions;
497 site->track_motion = old_site->track_motion;
499 site->track_motion = FALSE;
501 gtk_drag_dest_unset (widget);
503 if (gtk_widget_get_realized (widget))
504 gtk_drag_dest_realized (widget, site);
506 g_signal_connect (widget, "realize",
507 G_CALLBACK (gtk_drag_dest_realized), site);
508 g_signal_connect (widget, "hierarchy-changed",
509 G_CALLBACK (gtk_drag_dest_hierarchy_changed), site);
511 g_object_set_data_full (G_OBJECT (widget), I_("gtk-drag-dest"),
512 site, gtk_drag_dest_site_destroy);
516 gtk_drag_dest_set_proxy (GtkWidget *widget,
517 GdkWindow *proxy_window,
518 GdkDragProtocol protocol,
519 gboolean use_coordinates)
521 g_warning ("gtk_drag_dest_set_proxy is not supported on Mac OS X.");
525 gtk_drag_dest_unset (GtkWidget *widget)
527 GtkDragDestSite *old_site;
529 g_return_if_fail (GTK_IS_WIDGET (widget));
531 old_site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
534 g_signal_handlers_disconnect_by_func (widget,
535 gtk_drag_dest_realized,
537 g_signal_handlers_disconnect_by_func (widget,
538 gtk_drag_dest_hierarchy_changed,
542 g_object_set_data (G_OBJECT (widget), I_("gtk-drag-dest"), NULL);
546 gtk_drag_dest_get_target_list (GtkWidget *widget)
548 GtkDragDestSite *site;
550 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
552 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
554 return site ? site->target_list : NULL;
558 gtk_drag_dest_set_target_list (GtkWidget *widget,
559 GtkTargetList *target_list)
561 GtkDragDestSite *site;
563 g_return_if_fail (GTK_IS_WIDGET (widget));
565 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
569 g_warning ("Can't set a target list on a widget until you've called gtk_drag_dest_set() "
570 "to make the widget into a drag destination");
575 gtk_target_list_ref (target_list);
577 if (site->target_list)
578 gtk_target_list_unref (site->target_list);
580 site->target_list = target_list;
582 register_types (widget, site);
586 gtk_drag_dest_add_text_targets (GtkWidget *widget)
588 GtkTargetList *target_list;
590 target_list = gtk_drag_dest_get_target_list (widget);
592 gtk_target_list_ref (target_list);
594 target_list = gtk_target_list_new (NULL, 0);
595 gtk_target_list_add_text_targets (target_list, 0);
596 gtk_drag_dest_set_target_list (widget, target_list);
597 gtk_target_list_unref (target_list);
601 gtk_drag_dest_add_image_targets (GtkWidget *widget)
603 GtkTargetList *target_list;
605 target_list = gtk_drag_dest_get_target_list (widget);
607 gtk_target_list_ref (target_list);
609 target_list = gtk_target_list_new (NULL, 0);
610 gtk_target_list_add_image_targets (target_list, 0, FALSE);
611 gtk_drag_dest_set_target_list (widget, target_list);
612 gtk_target_list_unref (target_list);
616 gtk_drag_dest_add_uri_targets (GtkWidget *widget)
618 GtkTargetList *target_list;
620 target_list = gtk_drag_dest_get_target_list (widget);
622 gtk_target_list_ref (target_list);
624 target_list = gtk_target_list_new (NULL, 0);
625 gtk_target_list_add_uri_targets (target_list, 0);
626 gtk_drag_dest_set_target_list (widget, target_list);
627 gtk_target_list_unref (target_list);
631 prepend_and_ref_widget (GtkWidget *widget,
634 GSList **slist_p = data;
636 *slist_p = g_slist_prepend (*slist_p, g_object_ref (widget));
640 gtk_drag_find_widget (GtkWidget *widget,
641 GtkDragFindData *data)
643 GtkAllocation new_allocation;
644 gint allocation_to_window_x = 0;
645 gint allocation_to_window_y = 0;
649 if (data->found || !gtk_widget_get_mapped (widget) || !gtk_widget_get_sensitive (widget))
652 /* Note that in the following code, we only count the
653 * position as being inside a WINDOW widget if it is inside
654 * widget->window; points that are outside of widget->window
655 * but within the allocation are not counted. This is consistent
656 * with the way we highlight drag targets.
658 * data->x,y are relative to widget->parent->window (if
659 * widget is not a toplevel, widget->window otherwise).
660 * We compute the allocation of widget in the same coordinates,
661 * clipping to widget->window, and all intermediate
662 * windows. If data->x,y is inside that, then we translate
663 * our coordinates to be relative to widget->window and
666 gtk_widget_get_allocation (widget, &new_allocation);
668 if (gtk_widget_get_parent (widget))
671 GdkWindow *window = gtk_widget_get_window (widget);
672 GdkWindow *parent_window;
673 GtkAllocation allocation;
675 parent_window = gtk_widget_get_window (gtk_widget_get_parent (widget));
677 /* Compute the offset from allocation-relative to
678 * window-relative coordinates.
680 gtk_widget_get_allocation (widget, &allocation);
681 allocation_to_window_x = allocation.x;
682 allocation_to_window_y = allocation.y;
684 if (gtk_widget_get_has_window (widget))
686 /* The allocation is relative to the parent window for
687 * window widgets, not to widget->window.
689 gdk_window_get_position (window, &tx, &ty);
691 allocation_to_window_x -= tx;
692 allocation_to_window_y -= ty;
695 new_allocation.x = 0 + allocation_to_window_x;
696 new_allocation.y = 0 + allocation_to_window_y;
698 while (window && window != parent_window)
700 GdkRectangle window_rect = { 0, 0, 0, 0 };
702 window_rect.width = gdk_window_get_width (window);
703 window_rect.height = gdk_window_get_height (window);
705 gdk_rectangle_intersect (&new_allocation, &window_rect, &new_allocation);
707 gdk_window_get_position (window, &tx, &ty);
708 new_allocation.x += tx;
710 new_allocation.y += ty;
713 window = gdk_window_get_parent (window);
716 if (!window) /* Window and widget heirarchies didn't match. */
720 if (data->toplevel ||
721 ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
722 (data->x < new_allocation.x + new_allocation.width) &&
723 (data->y < new_allocation.y + new_allocation.height)))
725 /* First, check if the drag is in a valid drop site in
726 * one of our children
728 if (GTK_IS_CONTAINER (widget))
730 GtkDragFindData new_data = *data;
731 GSList *children = NULL;
734 new_data.x -= x_offset;
735 new_data.y -= y_offset;
736 new_data.found = FALSE;
737 new_data.toplevel = FALSE;
739 /* need to reference children temporarily in case the
740 * ::drag-motion/::drag-drop callbacks change the widget hierarchy.
742 gtk_container_forall (GTK_CONTAINER (widget), prepend_and_ref_widget, &children);
743 for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
745 if (!new_data.found && gtk_widget_is_drawable (tmp_list->data))
746 gtk_drag_find_widget (tmp_list->data, &new_data);
747 g_object_unref (tmp_list->data);
749 g_slist_free (children);
751 data->found = new_data.found;
754 /* If not, and this widget is registered as a drop site, check to
755 * emit "drag-motion" to check if we are actually in
759 g_object_get_data (G_OBJECT (widget), "gtk-drag-dest"))
761 data->found = data->callback (widget,
763 data->x - x_offset - allocation_to_window_x,
764 data->y - y_offset - allocation_to_window_y,
766 /* If so, send a "drag-leave" to the last widget */
769 if (data->info->widget && data->info->widget != widget)
771 gtk_drag_dest_leave (data->info->widget, data->context, data->time);
773 data->info->widget = widget;
780 gtk_drag_dest_leave (GtkWidget *widget,
781 GdkDragContext *context,
784 GtkDragDestSite *site;
786 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
787 g_return_if_fail (site != NULL);
789 if ((site->flags & GTK_DEST_DEFAULT_HIGHLIGHT) && site->have_drag)
790 gtk_drag_unhighlight (widget);
792 if (!(site->flags & GTK_DEST_DEFAULT_MOTION) || site->have_drag ||
794 g_signal_emit_by_name (widget, "drag-leave", context, time);
796 site->have_drag = FALSE;
800 gtk_drag_dest_motion (GtkWidget *widget,
801 GdkDragContext *context,
806 GtkDragDestSite *site;
807 GdkDragAction action = 0;
810 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
811 g_return_val_if_fail (site != NULL, FALSE);
813 if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
815 if (gdk_drag_context_get_suggested_action (context) & site->actions)
816 action = gdk_drag_context_get_suggested_action (context);
818 if (action && gtk_drag_dest_find_target (widget, context, NULL))
820 if (!site->have_drag)
822 site->have_drag = TRUE;
823 if (site->flags & GTK_DEST_DEFAULT_HIGHLIGHT)
824 gtk_drag_highlight (widget);
827 gdk_drag_status (context, action, time);
831 gdk_drag_status (context, 0, time);
832 if (!site->track_motion)
837 g_signal_emit_by_name (widget, "drag-motion",
838 context, x, y, time, &retval);
840 return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
844 gtk_drag_dest_drop (GtkWidget *widget,
845 GdkDragContext *context,
850 GtkDragDestSite *site;
851 GtkDragDestInfo *info;
854 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
855 g_return_val_if_fail (site != NULL, FALSE);
857 info = gtk_drag_get_dest_info (context, FALSE);
858 g_return_val_if_fail (info != NULL, FALSE);
863 if (site->flags & GTK_DEST_DEFAULT_DROP)
865 GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);
867 if (target == GDK_NONE)
869 gtk_drag_finish (context, FALSE, FALSE, time);
873 gtk_drag_get_data (widget, context, target, time);
876 g_signal_emit_by_name (widget, "drag-drop",
877 context, x, y, time, &retval);
879 return (site->flags & GTK_DEST_DEFAULT_DROP) ? TRUE : retval;
883 gtk_drag_dest_set_track_motion (GtkWidget *widget,
884 gboolean track_motion)
886 GtkDragDestSite *site;
888 g_return_if_fail (GTK_IS_WIDGET (widget));
890 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
892 g_return_if_fail (site != NULL);
894 site->track_motion = track_motion != FALSE;
898 gtk_drag_dest_get_track_motion (GtkWidget *widget)
900 GtkDragDestSite *site;
902 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
904 site = g_object_get_data (G_OBJECT (widget), "gtk-drag-dest");
907 return site->track_motion;
913 _gtk_drag_dest_handle_event (GtkWidget *toplevel,
916 GtkDragDestInfo *info;
917 GdkDragContext *context;
919 g_return_if_fail (toplevel != NULL);
920 g_return_if_fail (event != NULL);
922 context = event->dnd.context;
924 info = gtk_drag_get_dest_info (context, TRUE);
926 /* Find the widget for the event */
935 gtk_drag_dest_leave (info->widget, context, event->dnd.time);
940 case GDK_DRAG_MOTION:
943 GtkDragFindData data;
946 if (event->type == GDK_DROP_START)
948 info->dropped = TRUE;
949 /* We send a leave here so that the widget unhighlights
954 gtk_drag_dest_leave (info->widget, context, event->dnd.time);
959 gdk_window_get_position (gtk_widget_get_window (toplevel), &tx, &ty);
961 data.x = event->dnd.x_root - tx;
962 data.y = event->dnd.y_root - ty;
963 data.context = context;
966 data.toplevel = TRUE;
967 data.callback = (event->type == GDK_DRAG_MOTION) ?
968 gtk_drag_dest_motion : gtk_drag_dest_drop;
969 data.time = event->dnd.time;
971 gtk_drag_find_widget (toplevel, &data);
973 if (info->widget && !data.found)
975 gtk_drag_dest_leave (info->widget, context, event->dnd.time);
981 if (event->type == GDK_DRAG_MOTION)
984 gdk_drag_status (context, 0, event->dnd.time);
989 g_assert_not_reached ();
996 gtk_drag_dest_find_target (GtkWidget *widget,
997 GdkDragContext *context,
998 GtkTargetList *target_list)
1000 id <NSDraggingInfo> dragging_info;
1001 NSPasteboard *pasteboard;
1002 GtkWidget *source_widget;
1004 GList *tmp_source = NULL;
1005 GList *source_targets;
1007 g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE);
1008 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
1010 dragging_info = gdk_quartz_drag_context_get_dragging_info_libgtk_only (context);
1011 pasteboard = [dragging_info draggingPasteboard];
1013 source_widget = gtk_drag_get_source_widget (context);
1015 if (target_list == NULL)
1016 target_list = gtk_drag_dest_get_target_list (widget);
1018 if (target_list == NULL)
1021 source_targets = _gtk_quartz_pasteboard_types_to_atom_list ([pasteboard types]);
1022 tmp_target = target_list->list;
1025 GtkTargetPair *pair = tmp_target->data;
1026 tmp_source = source_targets;
1029 if (tmp_source->data == GUINT_TO_POINTER (pair->target))
1031 if ((!(pair->flags & GTK_TARGET_SAME_APP) || source_widget) &&
1032 (!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)))
1034 g_list_free (source_targets);
1035 return pair->target;
1040 tmp_source = tmp_source->next;
1042 tmp_target = tmp_target->next;
1045 g_list_free (source_targets);
1050 gtk_drag_begin_idle (gpointer arg)
1052 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1053 GdkDragContext* context = (GdkDragContext*) arg;
1054 GtkDragSourceInfo* info = gtk_drag_get_source_info (context, FALSE);
1056 NSPasteboard *pasteboard;
1057 GtkDragSourceOwner *owner;
1060 NSImage *drag_image;
1062 g_assert (info != NULL);
1064 pasteboard = [NSPasteboard pasteboardWithName:NSDragPboard];
1065 owner = [[GtkDragSourceOwner alloc] initWithInfo:info];
1067 types = _gtk_quartz_target_list_to_pasteboard_types (info->target_list);
1069 [pasteboard declareTypes:[types allObjects] owner:owner];
1074 if ((nswindow = get_toplevel_nswindow (info->source_widget)) == NULL)
1077 /* Ref the context. It's unreffed when the drag has been aborted */
1078 g_object_ref (info->context);
1080 /* FIXME: If the event isn't a mouse event, use the global cursor position instead */
1081 point = [info->nsevent locationInWindow];
1083 drag_image = _gtk_quartz_create_image_from_pixbuf (info->icon_pixbuf);
1084 if (drag_image == NULL)
1086 g_object_unref (info->context);
1090 point.x -= info->hot_x;
1091 point.y -= info->hot_y;
1093 [nswindow dragImage:drag_image
1095 offset:NSMakeSize(0, 0)
1097 pasteboard:pasteboard
1101 [info->nsevent release];
1102 [drag_image release];
1108 /* Fake protocol to let us call GdkNSView gdkWindow without including
1109 * gdk/GdkNSView.h (which we can't because it pulls in the internal-only
1113 - (GdkWindow *)gdkWindow;
1116 static GdkDragContext *
1117 gtk_drag_begin_internal (GtkWidget *widget,
1118 GtkDragSourceSite *site,
1119 GtkTargetList *target_list,
1120 GdkDragAction actions,
1124 GtkDragSourceInfo *info;
1127 GdkDragContext *context;
1128 NSWindow *nswindow = get_toplevel_nswindow (widget);
1129 NSPoint point = {0, 0};
1131 double time = (double)g_get_real_time ();
1133 NSTimeInterval nstime;
1137 if (gdk_event_get_coords (event, &x, &y))
1142 time = (double)gdk_event_get_time (event);
1145 nstime = [[NSDate dateWithTimeIntervalSince1970: time / 1000] timeIntervalSinceReferenceDate];
1146 nsevent = [NSEvent mouseEventWithType: NSLeftMouseDown
1150 windowNumber: [nswindow windowNumber]
1151 context: [nswindow graphicsContext]
1156 window = [(id<GdkNSView>)[nswindow contentView] gdkWindow];
1157 g_return_val_if_fail (nsevent != NULL, NULL);
1159 context = gdk_drag_begin (window, NULL);
1160 g_return_val_if_fail (context != NULL, NULL);
1162 info = gtk_drag_get_source_info (context, TRUE);
1163 info->nsevent = nsevent;
1164 [info->nsevent retain];
1166 info->source_widget = g_object_ref (widget);
1167 info->widget = g_object_ref (widget);
1168 info->target_list = target_list;
1169 gtk_target_list_ref (target_list);
1171 info->possible_actions = actions;
1173 g_signal_emit_by_name (widget, "drag-begin", info->context);
1175 /* Ensure that we have an icon before we start the drag; the
1176 * application may have set one in ::drag_begin, or it may
1179 if (!info->icon_pixbuf)
1181 if (!site || site->icon_type == GTK_IMAGE_EMPTY)
1182 gtk_drag_set_icon_default (context);
1185 switch (site->icon_type)
1187 case GTK_IMAGE_PIXBUF:
1188 gtk_drag_set_icon_pixbuf (context,
1189 site->icon_data.pixbuf.pixbuf,
1192 case GTK_IMAGE_STOCK:
1193 gtk_drag_set_icon_stock (context,
1194 site->icon_data.stock.stock_id,
1197 case GTK_IMAGE_ICON_NAME:
1198 gtk_drag_set_icon_name (context,
1199 site->icon_data.name.icon_name,
1202 case GTK_IMAGE_EMPTY:
1204 g_assert_not_reached();
1210 /* drag will begin in an idle handler to avoid nested run loops */
1212 g_idle_add_full (G_PRIORITY_HIGH_IDLE, gtk_drag_begin_idle, context, NULL);
1214 pointer = gdk_drag_context_get_device (info->context);
1215 gdk_device_ungrab (pointer, 0);
1221 gtk_drag_begin (GtkWidget *widget,
1222 GtkTargetList *targets,
1223 GdkDragAction actions,
1227 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1228 g_return_val_if_fail (gtk_widget_get_realized (widget), NULL);
1229 g_return_val_if_fail (targets != NULL, NULL);
1231 return gtk_drag_begin_internal (widget, NULL, targets,
1232 actions, button, event);
1237 gtk_drag_source_event_cb (GtkWidget *widget,
1241 GtkDragSourceSite *site;
1242 gboolean retval = FALSE;
1243 site = (GtkDragSourceSite *)data;
1245 switch (event->type)
1247 case GDK_BUTTON_PRESS:
1248 if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask)
1250 site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1));
1251 site->x = event->button.x;
1252 site->y = event->button.y;
1256 case GDK_BUTTON_RELEASE:
1257 if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask)
1258 site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1));
1261 case GDK_MOTION_NOTIFY:
1262 if (site->state & event->motion.state & site->start_button_mask)
1264 /* FIXME: This is really broken and can leave us
1270 if (site->state & event->motion.state &
1271 GDK_BUTTON1_MASK << (i - 1))
1275 if (gtk_drag_check_threshold (widget, site->x, site->y,
1276 event->motion.x, event->motion.y))
1279 gtk_drag_begin_internal (widget, site, site->target_list,
1288 default: /* hit for 2/3BUTTON_PRESS */
1296 gtk_drag_source_set (GtkWidget *widget,
1297 GdkModifierType start_button_mask,
1298 const GtkTargetEntry *targets,
1300 GdkDragAction actions)
1302 GtkDragSourceSite *site;
1304 g_return_if_fail (GTK_IS_WIDGET (widget));
1306 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1308 gtk_widget_add_events (widget,
1309 gtk_widget_get_events (widget) |
1310 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1311 GDK_BUTTON_MOTION_MASK);
1315 if (site->target_list)
1316 gtk_target_list_unref (site->target_list);
1320 site = g_new0 (GtkDragSourceSite, 1);
1322 site->icon_type = GTK_IMAGE_EMPTY;
1324 g_signal_connect (widget, "button-press-event",
1325 G_CALLBACK (gtk_drag_source_event_cb),
1327 g_signal_connect (widget, "button-release-event",
1328 G_CALLBACK (gtk_drag_source_event_cb),
1330 g_signal_connect (widget, "motion-notify-event",
1331 G_CALLBACK (gtk_drag_source_event_cb),
1334 g_object_set_data_full (G_OBJECT (widget),
1335 I_("gtk-site-data"),
1336 site, gtk_drag_source_site_destroy);
1339 site->start_button_mask = start_button_mask;
1341 site->target_list = gtk_target_list_new (targets, n_targets);
1343 site->actions = actions;
1346 /*************************************************************
1347 * gtk_drag_source_unset
1348 * Unregister this widget as a drag source.
1352 *************************************************************/
1355 gtk_drag_source_unset (GtkWidget *widget)
1357 GtkDragSourceSite *site;
1359 g_return_if_fail (GTK_IS_WIDGET (widget));
1361 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1365 g_signal_handlers_disconnect_by_func (widget,
1366 gtk_drag_source_event_cb,
1368 g_object_set_data (G_OBJECT (widget), I_("gtk-site-data"), NULL);
1373 gtk_drag_source_get_target_list (GtkWidget *widget)
1375 GtkDragSourceSite *site;
1377 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1379 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1381 return site ? site->target_list : NULL;
1386 gtk_drag_source_set_target_list (GtkWidget *widget,
1387 GtkTargetList *target_list)
1389 GtkDragSourceSite *site;
1391 g_return_if_fail (GTK_IS_WIDGET (widget));
1393 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1396 g_warning ("gtk_drag_source_set_target_list() requires the widget "
1397 "to already be a drag source.");
1402 gtk_target_list_ref (target_list);
1404 if (site->target_list)
1405 gtk_target_list_unref (site->target_list);
1407 site->target_list = target_list;
1411 * gtk_drag_source_add_text_targets:
1412 * @widget: a #GtkWidget that's is a drag source
1414 * Add the text targets supported by #GtkSelection to
1415 * the target list of the drag source. The targets
1416 * are added with @info = 0. If you need another value,
1417 * use gtk_target_list_add_text_targets() and
1418 * gtk_drag_source_set_target_list().
1423 gtk_drag_source_add_text_targets (GtkWidget *widget)
1425 GtkTargetList *target_list;
1427 target_list = gtk_drag_source_get_target_list (widget);
1429 gtk_target_list_ref (target_list);
1431 target_list = gtk_target_list_new (NULL, 0);
1432 gtk_target_list_add_text_targets (target_list, 0);
1433 gtk_drag_source_set_target_list (widget, target_list);
1434 gtk_target_list_unref (target_list);
1438 gtk_drag_source_add_image_targets (GtkWidget *widget)
1440 GtkTargetList *target_list;
1442 target_list = gtk_drag_source_get_target_list (widget);
1444 gtk_target_list_ref (target_list);
1446 target_list = gtk_target_list_new (NULL, 0);
1447 gtk_target_list_add_image_targets (target_list, 0, TRUE);
1448 gtk_drag_source_set_target_list (widget, target_list);
1449 gtk_target_list_unref (target_list);
1453 gtk_drag_source_add_uri_targets (GtkWidget *widget)
1455 GtkTargetList *target_list;
1457 target_list = gtk_drag_source_get_target_list (widget);
1459 gtk_target_list_ref (target_list);
1461 target_list = gtk_target_list_new (NULL, 0);
1462 gtk_target_list_add_uri_targets (target_list, 0);
1463 gtk_drag_source_set_target_list (widget, target_list);
1464 gtk_target_list_unref (target_list);
1468 gtk_drag_source_unset_icon (GtkDragSourceSite *site)
1470 switch (site->icon_type)
1472 case GTK_IMAGE_EMPTY:
1474 case GTK_IMAGE_PIXBUF:
1475 g_object_unref (site->icon_data.pixbuf.pixbuf);
1477 case GTK_IMAGE_STOCK:
1478 g_free (site->icon_data.stock.stock_id);
1480 case GTK_IMAGE_ICON_NAME:
1481 g_free (site->icon_data.name.icon_name);
1484 g_assert_not_reached();
1487 site->icon_type = GTK_IMAGE_EMPTY;
1491 gtk_drag_source_site_destroy (gpointer data)
1493 GtkDragSourceSite *site = data;
1495 if (site->target_list)
1496 gtk_target_list_unref (site->target_list);
1498 gtk_drag_source_unset_icon (site);
1503 gtk_drag_source_set_icon_pixbuf (GtkWidget *widget,
1506 GtkDragSourceSite *site;
1508 g_return_if_fail (GTK_IS_WIDGET (widget));
1509 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
1511 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1512 g_return_if_fail (site != NULL);
1513 g_object_ref (pixbuf);
1515 gtk_drag_source_unset_icon (site);
1517 site->icon_type = GTK_IMAGE_PIXBUF;
1518 site->icon_data.pixbuf.pixbuf = pixbuf;
1522 * gtk_drag_source_set_icon_stock:
1523 * @widget: a #GtkWidget
1524 * @stock_id: the ID of the stock icon to use
1526 * Sets the icon that will be used for drags from a particular source
1530 gtk_drag_source_set_icon_stock (GtkWidget *widget,
1531 const gchar *stock_id)
1533 GtkDragSourceSite *site;
1535 g_return_if_fail (GTK_IS_WIDGET (widget));
1536 g_return_if_fail (stock_id != NULL);
1538 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1539 g_return_if_fail (site != NULL);
1541 gtk_drag_source_unset_icon (site);
1543 site->icon_type = GTK_IMAGE_STOCK;
1544 site->icon_data.stock.stock_id = g_strdup (stock_id);
1548 * gtk_drag_source_set_icon_name:
1549 * @widget: a #GtkWidget
1550 * @icon_name: name of icon to use
1552 * Sets the icon that will be used for drags from a particular source
1553 * to a themed icon. See the docs for #GtkIconTheme for more details.
1558 gtk_drag_source_set_icon_name (GtkWidget *widget,
1559 const gchar *icon_name)
1561 GtkDragSourceSite *site;
1563 g_return_if_fail (GTK_IS_WIDGET (widget));
1564 g_return_if_fail (icon_name != NULL);
1566 site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
1567 g_return_if_fail (site != NULL);
1569 gtk_drag_source_unset_icon (site);
1571 site->icon_type = GTK_IMAGE_ICON_NAME;
1572 site->icon_data.name.icon_name = g_strdup (icon_name);
1577 * gtk_drag_set_icon_widget:
1578 * @context: the context for a drag. (This must be called
1579 with a context for the source side of a drag)
1580 * @widget: a toplevel window to use as an icon.
1581 * @hot_x: the X offset within @widget of the hotspot.
1582 * @hot_y: the Y offset within @widget of the hotspot.
1584 * Changes the icon for a widget to a given widget. GTK+
1585 * will not destroy the icon, so if you don't want
1586 * it to persist, you should connect to the "drag-end"
1587 * signal and destroy it yourself.
1590 gtk_drag_set_icon_widget (GdkDragContext *context,
1595 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1596 g_return_if_fail (GTK_IS_WIDGET (widget));
1598 g_warning ("gtk_drag_set_icon_widget is not supported on Mac OS X");
1602 set_icon_stock_pixbuf (GdkDragContext *context,
1603 const gchar *stock_id,
1608 GtkDragSourceInfo *info;
1610 info = gtk_drag_get_source_info (context, FALSE);
1614 pixbuf = gtk_widget_render_icon_pixbuf (info->widget, stock_id,
1619 g_warning ("Cannot load drag icon from stock_id %s", stock_id);
1624 g_object_ref (pixbuf);
1626 if (info->icon_pixbuf)
1627 g_object_unref (info->icon_pixbuf);
1628 info->icon_pixbuf = pixbuf;
1629 info->hot_x = hot_x;
1630 info->hot_y = hot_y;
1634 * gtk_drag_set_icon_pixbuf:
1635 * @context: the context for a drag. (This must be called
1636 * with a context for the source side of a drag)
1637 * @pixbuf: the #GdkPixbuf to use as the drag icon.
1638 * @hot_x: the X offset within @widget of the hotspot.
1639 * @hot_y: the Y offset within @widget of the hotspot.
1641 * Sets @pixbuf as the icon for a given drag.
1644 gtk_drag_set_icon_pixbuf (GdkDragContext *context,
1649 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1650 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
1652 set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
1656 * gtk_drag_set_icon_stock:
1657 * @context: the context for a drag. (This must be called
1658 * with a context for the source side of a drag)
1659 * @stock_id: the ID of the stock icon to use for the drag.
1660 * @hot_x: the X offset within the icon of the hotspot.
1661 * @hot_y: the Y offset within the icon of the hotspot.
1663 * Sets the icon for a given drag from a stock ID.
1666 gtk_drag_set_icon_stock (GdkDragContext *context,
1667 const gchar *stock_id,
1672 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1673 g_return_if_fail (stock_id != NULL);
1675 set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y);
1679 /* XXX: This function is in gdk, too. Should it be in Cairo? */
1681 _gtk_cairo_surface_extents (cairo_surface_t *surface,
1682 GdkRectangle *extents)
1684 double x1, x2, y1, y2;
1687 g_return_val_if_fail (surface != NULL, FALSE);
1688 g_return_val_if_fail (extents != NULL, FALSE);
1690 cr = cairo_create (surface);
1691 cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
1700 if (x1 < G_MININT || x1 > G_MAXINT ||
1701 y1 < G_MININT || y1 > G_MAXINT ||
1702 x2 > G_MAXINT || y2 > G_MAXINT)
1704 extents->x = extents->y = extents->width = extents->height = 0;
1710 extents->width = x2;
1711 extents->height = y2;
1717 * gtk_drag_set_icon_surface:
1718 * @context: the context for a drag. (This must be called
1719 * with a context for the source side of a drag)
1720 * @surface: the surface to use as icon
1722 * Sets @surface as the icon for a given drag. GTK+ retains
1723 * references for the arguments, and will release them when
1724 * they are no longer needed.
1726 * To position the surface relative to the mouse, use
1727 * cairo_surface_set_device_offset() on @surface. The mouse
1728 * cursor will be positioned at the (0,0) coordinate of the
1732 gtk_drag_set_icon_surface (GdkDragContext *context,
1733 cairo_surface_t *surface)
1736 GdkRectangle extents;
1737 double x_offset, y_offset;
1739 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1740 g_return_if_fail (surface != NULL);
1742 _gtk_cairo_surface_extents (surface, &extents);
1743 cairo_surface_get_device_offset (surface, &x_offset, &y_offset);
1745 pixbuf = gdk_pixbuf_get_from_surface (surface,
1746 extents.x, extents.y,
1747 extents.width, extents.height);
1748 gtk_drag_set_icon_pixbuf (context, pixbuf, -x_offset, -y_offset);
1749 g_object_unref (pixbuf);
1753 * gtk_drag_set_icon_name:
1754 * @context: the context for a drag. (This must be called
1755 * with a context for the source side of a drag)
1756 * @icon_name: name of icon to use
1757 * @hot_x: the X offset of the hotspot within the icon
1758 * @hot_y: the Y offset of the hotspot within the icon
1760 * Sets the icon for a given drag from a named themed icon. See
1761 * the docs for #GtkIconTheme for more details. Note that the
1762 * size of the icon depends on the icon theme (the icon is
1763 * loaded at the symbolic size #GTK_ICON_SIZE_DND), thus
1764 * @hot_x and @hot_y have to be used with care.
1769 gtk_drag_set_icon_name (GdkDragContext *context,
1770 const gchar *icon_name,
1775 GtkSettings *settings;
1776 GtkIconTheme *icon_theme;
1778 gint width, height, icon_size;
1780 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1781 g_return_if_fail (icon_name != NULL);
1783 screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
1784 g_return_if_fail (screen != NULL);
1786 settings = gtk_settings_get_for_screen (screen);
1787 if (gtk_icon_size_lookup_for_settings (settings,
1790 icon_size = MAX (width, height);
1792 icon_size = 32; /* default value for GTK_ICON_SIZE_DND */
1794 icon_theme = gtk_icon_theme_get_for_screen (screen);
1796 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
1797 icon_size, 0, NULL);
1799 set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
1801 g_warning ("Cannot load drag icon from icon name %s", icon_name);
1805 * gtk_drag_set_icon_default:
1806 * @context: the context for a drag. (This must be called
1807 with a context for the source side of a drag)
1809 * Sets the icon for a particular drag to the default
1813 gtk_drag_set_icon_default (GdkDragContext *context)
1815 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
1817 gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2);
1821 gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
1823 NSPasteboard *pasteboard;
1824 NSAutoreleasePool *pool;
1826 if (info->icon_pixbuf)
1827 g_object_unref (info->icon_pixbuf);
1829 g_signal_emit_by_name (info->widget, "drag-end",
1832 if (info->source_widget)
1833 g_object_unref (info->source_widget);
1836 g_object_unref (info->widget);
1838 gtk_target_list_unref (info->target_list);
1840 pool = [[NSAutoreleasePool alloc] init];
1842 /* Empty the pasteboard, so that it will not accidentally access
1843 * info->context after it has been destroyed.
1845 pasteboard = [NSPasteboard pasteboardWithName: NSDragPboard];
1846 [pasteboard declareTypes: nil owner: nil];
1850 gtk_drag_clear_source_info (info->context);
1851 g_object_unref (info->context);
1858 drag_drop_finished_idle_cb (gpointer data)
1860 gtk_drag_source_info_destroy (data);
1865 gtk_drag_drop_finished (GtkDragSourceInfo *info)
1867 if (info->success && info->delete)
1868 g_signal_emit_by_name (info->source_widget, "drag-data-delete",
1871 /* Workaround for the fact that the NS API blocks until the drag is
1872 * over. This way the context is still valid when returning from
1873 * drag_begin, even if it will still be quite useless. See bug #501588.
1875 g_idle_add (drag_drop_finished_idle_cb, info);
1878 /*************************************************************
1879 * _gtk_drag_source_handle_event:
1880 * Called from widget event handling code on Drag events
1884 * toplevel: Toplevel widget that received the event
1887 *************************************************************/
1890 _gtk_drag_source_handle_event (GtkWidget *widget,
1893 GtkDragSourceInfo *info;
1894 GdkDragContext *context;
1896 g_return_if_fail (widget != NULL);
1897 g_return_if_fail (event != NULL);
1899 context = event->dnd.context;
1900 info = gtk_drag_get_source_info (context, FALSE);
1904 switch (event->type)
1906 case GDK_DROP_FINISHED:
1907 gtk_drag_drop_finished (info);
1910 g_assert_not_reached ();
1916 gtk_drag_check_threshold (GtkWidget *widget,
1922 gint drag_threshold;
1924 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
1926 g_object_get (gtk_widget_get_settings (widget),
1927 "gtk-dnd-drag-threshold", &drag_threshold,
1930 return (ABS (current_x - start_x) > drag_threshold ||
1931 ABS (current_y - start_y) > drag_threshold);