diff options
author | Benjamin Otte <otte@redhat.com> | 2015-11-22 05:26:08 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-11-25 20:31:27 +0100 |
commit | 415030d25f2552d3937ee3c394c50d22c5382982 (patch) | |
tree | c4cf65729a6db4207e02fc71c6130ce3985b3a1f /gtk/gtkdnd-quartz.c | |
parent | ee3397388ff689a965ed3c9c04ad390605e40232 (diff) | |
download | gtk+-415030d25f2552d3937ee3c394c50d22c5382982.tar.gz |
dnd: Split GtkDragSourceSite into its own file
Diffstat (limited to 'gtk/gtkdnd-quartz.c')
-rw-r--r-- | gtk/gtkdnd-quartz.c | 389 |
1 files changed, 1 insertions, 388 deletions
diff --git a/gtk/gtkdnd-quartz.c b/gtk/gtkdnd-quartz.c index 959f0729c7..eb5fa95dc7 100644 --- a/gtk/gtkdnd-quartz.c +++ b/gtk/gtkdnd-quartz.c @@ -30,6 +30,7 @@ #include "gdk/gdk.h" #include "gtkdnd.h" +#include "gtkdndprivate.h" #include "deprecated/gtkiconfactory.h" #include "gtkicontheme.h" #include "gtkimageprivate.h" @@ -44,7 +45,6 @@ #include "gtksettings.h" #include "gtkiconhelperprivate.h" -typedef struct _GtkDragSourceSite GtkDragSourceSite; typedef struct _GtkDragSourceInfo GtkDragSourceInfo; typedef struct _GtkDragDestSite GtkDragDestSite; typedef struct _GtkDragDestInfo GtkDragDestInfo; @@ -68,26 +68,6 @@ static void gtk_drag_drop_finished (GtkDragSourceInfo *info, extern GdkDragContext *gdk_quartz_drag_source_context (); /* gdk/quartz/gdkdnd-quartz.c */ -struct _GtkDragSourceSite -{ - GdkModifierType start_button_mask; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction actions; /* Possible actions */ - - /* Drag icon */ - GtkImageType icon_type; - union - { - GtkImagePixbufData pixbuf; - GtkImageStockData stock; - GtkImageIconNameData name; - } icon_data; - - /* Stored button press information to detect drag beginning */ - gint state; - gint x, y; -}; - struct _GtkDragSourceInfo { GtkWidget *source_widget; @@ -1405,373 +1385,6 @@ gtk_drag_cancel (GdkDragContext *context) gtk_drag_drop_finished (info, GTK_DRAG_RESULT_ERROR); } -static gboolean -gtk_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - gpointer data) -{ - GtkDragSourceSite *site; - gboolean retval = FALSE; - site = (GtkDragSourceSite *)data; - - switch (event->type) - { - case GDK_BUTTON_PRESS: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) - { - site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1)); - site->x = event->button.x; - site->y = event->button.y; - } - break; - - case GDK_BUTTON_RELEASE: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) - site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1)); - break; - - case GDK_MOTION_NOTIFY: - if (site->state & event->motion.state & site->start_button_mask) - { - /* FIXME: This is really broken and can leave us - * with a stuck grab - */ - int i; - for (i=1; i<6; i++) - { - if (site->state & event->motion.state & - GDK_BUTTON1_MASK << (i - 1)) - break; - } - - if (gtk_drag_check_threshold (widget, site->x, site->y, - event->motion.x, event->motion.y)) - { - site->state = 0; - gtk_drag_begin_internal (widget, site, site->target_list, - site->actions, i, event, -1, -1); - - retval = TRUE; - } - } - break; - - default: /* hit for 2/3BUTTON_PRESS */ - break; - } - - return retval; -} - -/** - * gtk_drag_source_set: (method) - * @widget: a #GtkWidget - * @start_button_mask: the bitmask of buttons that can start the drag - * @targets: (allow-none) (array length=n_targets): the table of targets that the drag will support, - * may be %NULL - * @n_targets: the number of items in @targets - * @actions: the bitmask of possible actions for a drag from this widget - */ -void -gtk_drag_source_set (GtkWidget *widget, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - - gtk_widget_add_events (widget, - gtk_widget_get_events (widget) | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON_MOTION_MASK); - - if (site) - { - if (site->target_list) - gtk_target_list_unref (site->target_list); - } - else - { - site = g_new0 (GtkDragSourceSite, 1); - - site->icon_type = GTK_IMAGE_EMPTY; - - g_signal_connect (widget, "button-press-event", - G_CALLBACK (gtk_drag_source_event_cb), - site); - g_signal_connect (widget, "button-release-event", - G_CALLBACK (gtk_drag_source_event_cb), - site); - g_signal_connect (widget, "motion-notify-event", - G_CALLBACK (gtk_drag_source_event_cb), - site); - - g_object_set_data_full (G_OBJECT (widget), - I_("gtk-site-data"), - site, gtk_drag_source_site_destroy); - } - - site->start_button_mask = start_button_mask; - - site->target_list = gtk_target_list_new (targets, n_targets); - - site->actions = actions; -} - -/** - * gtk_drag_source_unset: (method) - * @widget: a #GtkWidget - */ -void -gtk_drag_source_unset (GtkWidget *widget) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - - if (site) - { - g_signal_handlers_disconnect_by_func (widget, - gtk_drag_source_event_cb, - site); - g_object_set_data (G_OBJECT (widget), I_("gtk-site-data"), NULL); - } -} - -/** - * gtk_drag_source_get_target_list: (method) - * @widget: a #GtkWidget - * - * Returns: (transfer none): - */ -GtkTargetList * -gtk_drag_source_get_target_list (GtkWidget *widget) -{ - GtkDragSourceSite *site; - - g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - - return site ? site->target_list : NULL; - -} - -/** - * gtk_drag_source_set_target_list: (method) - * @widget: a #GtkWidget that’s a drag source - * @target_list: (allow-none): list of draggable targets, or %NULL for none - */ -void -gtk_drag_source_set_target_list (GtkWidget *widget, - GtkTargetList *target_list) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - if (site == NULL) - { - g_warning ("gtk_drag_source_set_target_list() requires the widget " - "to already be a drag source."); - 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; -} - -/** - * gtk_drag_source_add_text_targets: (method) - * @widget: a #GtkWidget that’s is a drag source - * - * Add the text targets supported by #GtkSelection to - * the target list of the drag source. The targets - * are added with @info = 0. If you need another value, - * use gtk_target_list_add_text_targets() and - * gtk_drag_source_set_target_list(). - * - * Since: 2.6 - **/ -void -gtk_drag_source_add_text_targets (GtkWidget *widget) -{ - GtkTargetList *target_list; - - target_list = gtk_drag_source_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_source_set_target_list (widget, target_list); - gtk_target_list_unref (target_list); -} - -/** - * gtk_drag_source_add_image_targets: (method) - * @widget: a #GtkWidget that’s is a drag source - */ -void -gtk_drag_source_add_image_targets (GtkWidget *widget) -{ - GtkTargetList *target_list; - - target_list = gtk_drag_source_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, TRUE); - gtk_drag_source_set_target_list (widget, target_list); - gtk_target_list_unref (target_list); -} - -/** - * gtk_drag_source_add_uri_targets: (method) - * @widget: a #GtkWidget that’s is a drag source - */ -void -gtk_drag_source_add_uri_targets (GtkWidget *widget) -{ - GtkTargetList *target_list; - - target_list = gtk_drag_source_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_source_set_target_list (widget, target_list); - gtk_target_list_unref (target_list); -} - -static void -gtk_drag_source_unset_icon (GtkDragSourceSite *site) -{ - switch (site->icon_type) - { - case GTK_IMAGE_EMPTY: - break; - case GTK_IMAGE_PIXBUF: - g_object_unref (site->icon_data.pixbuf.pixbuf); - break; - case GTK_IMAGE_STOCK: - g_free (site->icon_data.stock.stock_id); - break; - case GTK_IMAGE_ICON_NAME: - g_free (site->icon_data.name.icon_name); - break; - default: - g_assert_not_reached(); - break; - } - site->icon_type = GTK_IMAGE_EMPTY; -} - -static void -gtk_drag_source_site_destroy (gpointer data) -{ - GtkDragSourceSite *site = data; - - if (site->target_list) - gtk_target_list_unref (site->target_list); - - gtk_drag_source_unset_icon (site); - g_free (site); -} - -/** - * gtk_drag_source_set_icon_pixbuf: (method) - * @widget: a #GtkWidget - * @pixbuf: the #GdkPixbuf for the drag icon - */ -void -gtk_drag_source_set_icon_pixbuf (GtkWidget *widget, - GdkPixbuf *pixbuf) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - g_return_if_fail (site != NULL); - g_object_ref (pixbuf); - - gtk_drag_source_unset_icon (site); - - site->icon_type = GTK_IMAGE_PIXBUF; - site->icon_data.pixbuf.pixbuf = pixbuf; -} - -/** - * gtk_drag_source_set_icon_stock: (method) - * @widget: a #GtkWidget - * @stock_id: the ID of the stock icon to use - * - * Sets the icon that will be used for drags from a particular source - * to a stock icon. - **/ -void -gtk_drag_source_set_icon_stock (GtkWidget *widget, - const gchar *stock_id) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (stock_id != NULL); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - g_return_if_fail (site != NULL); - - gtk_drag_source_unset_icon (site); - - site->icon_type = GTK_IMAGE_STOCK; - site->icon_data.stock.stock_id = g_strdup (stock_id); -} - -/** - * gtk_drag_source_set_icon_name: (method) - * @widget: a #GtkWidget - * @icon_name: name of icon to use - * - * Sets the icon that will be used for drags from a particular source - * to a themed icon. See the docs for #GtkIconTheme for more details. - * - * Since: 2.8 - **/ -void -gtk_drag_source_set_icon_name (GtkWidget *widget, - const gchar *icon_name) -{ - GtkDragSourceSite *site; - - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (icon_name != NULL); - - site = g_object_get_data (G_OBJECT (widget), "gtk-site-data"); - g_return_if_fail (site != NULL); - - gtk_drag_source_unset_icon (site); - - site->icon_type = GTK_IMAGE_ICON_NAME; - site->icon_data.name.icon_name = g_strdup (icon_name); -} - /** * gtk_drag_set_icon_widget: (method) |