dnd: Remove x/y coordinates from drag-data-received

This is in preparation of using input streams to show that these
coordinates aren't needed most of the time and can otherwise be saved
during GtkWidget::drag-drop.
This commit is contained in:
Benjamin Otte 2017-12-05 04:06:20 +01:00
parent 6f00c1b626
commit 4658d7ea54
22 changed files with 119 additions and 108 deletions

View File

@ -148,8 +148,6 @@ drag_data_get (GtkWidget *widget,
static void
drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint32 time,
gpointer data)

View File

@ -30,6 +30,8 @@
#include "gdkpipeiostreamprivate.h"
#include "gdktexture.h"
#include <gobject/gvaluecollector.h>
/**
* SECTION:gdkclipboard
* @Short_description: Share data between applications for Copy-and-Paste
@ -1233,7 +1235,88 @@ gdk_clipboard_set_content (GdkClipboard *clipboard,
}
/**
* gdk_clipboard_set_text:
* gdk_clipboard_set:
* @clipboard: a #GdkClipboard
* @type: type of value to set
* @...: value contents conforming to @type
*
* Sets the clipboard to contain the value collected from the given
* varargs.
**/
void
gdk_clipboard_set (GdkClipboard *clipboard,
GType type,
...)
{
va_list args;
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
va_start (args, type);
gdk_clipboard_set_valist (clipboard, type, args);
va_end (args);
}
/**
* gdk_clipboard_set_valist: (skip)
* @clipboard: a #GdkClipboard
* @type: type of value to set
* @args: varargs containing the value of @type
*
* Sets the clipboard to contain the value collected from the given
* @args.
**/
void
gdk_clipboard_set_valist (GdkClipboard *clipboard,
GType type,
va_list args)
{
GValue value = G_VALUE_INIT;
char *error;
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
G_VALUE_COLLECT_INIT (&value, type,
args, G_VALUE_NOCOPY_CONTENTS,
&error);
if (error)
{
g_warning ("%s: %s", G_STRLOC, error);
g_free (error);
/* we purposely leak the value here, it might not be
* in a sane state if an error condition occoured
*/
return;
}
gdk_clipboard_set_value (clipboard, &value);
g_value_unset (&value);
}
/**
* gdk_clipboard_set_value: (rename-to gdk_clipboard_set)
* @clipboard: a #GdkClipboard
* @value: a #GValue to set
*
* Sets the @clipboard to contain the given @value.
**/
void
gdk_clipboard_set_value (GdkClipboard *clipboard,
const GValue *value)
{
GdkContentProvider *provider;
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
g_return_if_fail (G_IS_VALUE (value));
provider = gdk_content_provider_new_for_value (value);
gdk_clipboard_set_content (clipboard, provider);
g_object_unref (provider);
}
/**
* gdk_clipboard_set_text: (skip)
* @clipboard: a #GdkClipboard
* @text: Text to put into the clipboard
*
@ -1243,22 +1326,13 @@ void
gdk_clipboard_set_text (GdkClipboard *clipboard,
const char *text)
{
GdkContentProvider *provider;
GValue value = G_VALUE_INIT;
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, text);
provider = gdk_content_provider_new_for_value (&value);
g_value_unset (&value);
gdk_clipboard_set_content (clipboard, provider);
g_object_unref (provider);
gdk_clipboard_set (clipboard, G_TYPE_STRING, text);
}
/**
* gdk_clipboard_set_texture:
* gdk_clipboard_set_texture: (skip)
* @clipboard: a #GdkClipboard
* @texture: a #GdkTexture to put into the clipboard
*
@ -1268,18 +1342,9 @@ void
gdk_clipboard_set_texture (GdkClipboard *clipboard,
GdkTexture *texture)
{
GdkContentProvider *provider;
GValue value = G_VALUE_INIT;
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
g_return_if_fail (GDK_IS_TEXTURE (texture));
g_value_init (&value, GDK_TYPE_TEXTURE);
g_value_set_object (&value, texture);
provider = gdk_content_provider_new_for_value (&value);
g_value_unset (&value);
gdk_clipboard_set_content (clipboard, provider);
g_object_unref (provider);
gdk_clipboard_set (clipboard, GDK_TYPE_TEXTURE, texture);
}

View File

@ -103,6 +103,17 @@ GDK_AVAILABLE_IN_3_94
gboolean gdk_clipboard_set_content (GdkClipboard *clipboard,
GdkContentProvider *provider);
GDK_AVAILABLE_IN_3_94
void gdk_clipboard_set (GdkClipboard *clipboard,
GType type,
...);
GDK_AVAILABLE_IN_3_94
void gdk_clipboard_set_valist (GdkClipboard *clipboard,
GType type,
va_list args);
GDK_AVAILABLE_IN_3_94
void gdk_clipboard_set_value (GdkClipboard *clipboard,
const GValue *value);
GDK_AVAILABLE_IN_3_94
void gdk_clipboard_set_text (GdkClipboard *clipboard,
const char *text);
GDK_AVAILABLE_IN_3_94

View File

@ -307,8 +307,6 @@ static void gtk_calendar_drag_data_get (GtkWidget *widget,
guint time);
static void gtk_calendar_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time);
static gboolean gtk_calendar_drag_motion (GtkWidget *widget,
@ -2980,8 +2978,6 @@ gtk_calendar_drag_drop (GtkWidget *widget,
static void
gtk_calendar_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time)
{

View File

@ -210,8 +210,6 @@ swatch_drag_data_get (GtkWidget *widget,
static void
swatch_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time)
{

View File

@ -83,7 +83,6 @@ struct _GtkDragDestInfo
{
GtkWidget *widget; /* Widget in which drag is in */
GdkDragContext *context; /* Drag context */
gint drop_x, drop_y; /* Position of drop */
};
#define DROP_ABORT_TIME 300000
@ -594,14 +593,12 @@ gtk_drag_selection_received (GtkWidget *widget,
gpointer data)
{
GdkDragContext *context;
GtkDragDestInfo *info;
GtkWidget *drop_widget;
GdkAtom target;
drop_widget = data;
context = g_object_get_data (G_OBJECT (widget), "drag-context");
info = gtk_drag_get_dest_info (context, FALSE);
target = gtk_selection_data_get_target (selection_data);
if (target == gdk_atom_intern_static_string ("DELETE"))
@ -622,7 +619,7 @@ gtk_drag_selection_received (GtkWidget *widget,
gtk_selection_data_get_length (selection_data) >= 0)
g_signal_emit_by_name (drop_widget,
"drag-data-received",
context, info->drop_x, info->drop_y,
context,
selection_data,
time);
}
@ -631,7 +628,7 @@ gtk_drag_selection_received (GtkWidget *widget,
{
g_signal_emit_by_name (drop_widget,
"drag-data-received",
context, info->drop_x, info->drop_y,
context,
selection_data,
time);
}
@ -924,9 +921,6 @@ gtk_drag_dest_drop (GtkWidget *widget,
info = gtk_drag_get_dest_info (context, FALSE);
g_return_val_if_fail (info != NULL, FALSE);
info->drop_x = x;
info->drop_y = y;
if (site->flags & GTK_DEST_DEFAULT_DROP)
{
GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL);

View File

@ -225,6 +225,7 @@ struct _GtkEntryPrivate
gint dnd_position; /* In chars, -1 == no DND cursor */
gint drag_start_x;
gint drag_start_y;
gint drop_position; /* where the drop should happen */
gint insert_pos;
gint selection_bound;
gint scroll_offset;
@ -453,8 +454,6 @@ static void gtk_entry_drag_leave (GtkWidget *widget,
guint time);
static void gtk_entry_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time);
static void gtk_entry_drag_data_get (GtkWidget *widget,
@ -8918,7 +8917,10 @@ gtk_entry_drag_drop (GtkWidget *widget,
target = gtk_drag_dest_find_target (widget, context, NULL);
if (target != NULL)
gtk_drag_get_data (widget, context, target, time);
{
priv->drop_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
gtk_drag_get_data (widget, context, target, time);
}
else
gtk_drag_finish (context, FALSE, FALSE, time);
@ -8992,8 +8994,6 @@ gtk_entry_drag_motion (GtkWidget *widget,
static void
gtk_entry_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time)
{
@ -9006,19 +9006,16 @@ gtk_entry_drag_data_received (GtkWidget *widget,
if (str && priv->editable)
{
gint new_position;
gint sel1, sel2;
gint length = -1;
if (priv->truncate_multiline)
length = truncate_multiline (str);
new_position = gtk_entry_find_position (entry, x + priv->scroll_offset);
if (!gtk_editable_get_selection_bounds (editable, &sel1, &sel2) ||
new_position < sel1 || new_position > sel2)
priv->drop_position < sel1 || priv->drop_position > sel2)
{
gtk_editable_insert_text (editable, str, length, &new_position);
gtk_editable_insert_text (editable, str, length, &priv->drop_position);
}
else
{

View File

@ -253,8 +253,6 @@ static void gtk_file_chooser_button_finalize (GObject *ob
static void gtk_file_chooser_button_destroy (GtkWidget *widget);
static void gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint drag_time);
static void gtk_file_chooser_button_show (GtkWidget *widget);
@ -1212,8 +1210,6 @@ dnd_select_folder_get_info_cb (GCancellable *cancellable,
static void
gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint drag_time)
{
@ -1225,7 +1221,6 @@ gtk_file_chooser_button_drag_data_received (GtkWidget *widget,
if (GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->drag_data_received != NULL)
GTK_WIDGET_CLASS (gtk_file_chooser_button_parent_class)->drag_data_received (widget,
context,
x, y,
data,
drag_time);

View File

@ -1937,8 +1937,6 @@ out:
static void
file_list_drag_data_received_cb (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time_,
gpointer user_data)

View File

@ -299,8 +299,6 @@ static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
guint time);
static void gtk_icon_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time);
static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
@ -6464,8 +6462,6 @@ gtk_icon_view_drag_drop (GtkWidget *widget,
static void
gtk_icon_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time)
{

View File

@ -81,7 +81,6 @@ VOID:OBJECT,FLAGS
VOID:OBJECT,INT
VOID:OBJECT,INT,OBJECT
VOID:OBJECT,INT,INT
VOID:OBJECT,INT,INT,BOXED,UINT
VOID:OBJECT,OBJECT
VOID:OBJECT,POINTER
VOID:OBJECT,POINTER,INT

View File

@ -405,8 +405,6 @@ static void gtk_notebook_drag_data_get (GtkWidget *widget,
guint time);
static void gtk_notebook_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint time);
static void gtk_notebook_direction_changed (GtkWidget *widget,
@ -523,9 +521,7 @@ static gboolean focus_child_in (GtkNotebook *notebook,
static void stop_scrolling (GtkNotebook *notebook);
static void do_detach_tab (GtkNotebook *from,
GtkNotebook *to,
GtkWidget *child,
gint x,
gint y);
GtkWidget *child);
/* GtkBuildable */
static void gtk_notebook_buildable_init (GtkBuildableIface *iface);
@ -2980,7 +2976,7 @@ gtk_notebook_drag_end (GtkWidget *widget,
priv->detached_tab->child, x, y, &dest_notebook);
if (dest_notebook)
do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
do_detach_tab (notebook, dest_notebook, priv->detached_tab->child);
priv->rootwindow_drop = FALSE;
}
@ -3030,7 +3026,7 @@ gtk_notebook_drag_failed (GtkWidget *widget,
priv->detached_tab->child, x, y, &dest_notebook);
if (dest_notebook)
do_detach_tab (notebook, dest_notebook, priv->detached_tab->child, 0, 0);
do_detach_tab (notebook, dest_notebook, priv->detached_tab->child);
return TRUE;
}
@ -3171,6 +3167,7 @@ gtk_notebook_drag_drop (GtkWidget *widget,
gint y,
guint time)
{
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GdkAtom target, tab_target;
target = gtk_drag_dest_find_target (widget, context, NULL);
@ -3178,6 +3175,8 @@ gtk_notebook_drag_drop (GtkWidget *widget,
if (target == tab_target)
{
notebook->priv->mouse_x = x;
notebook->priv->mouse_y = y;
gtk_drag_get_data (widget, context, target, time);
return TRUE;
}
@ -3209,11 +3208,9 @@ gtk_notebook_detach_tab (GtkNotebook *notebook,
}
static void
do_detach_tab (GtkNotebook *from,
GtkNotebook *to,
GtkWidget *child,
gint x,
gint y)
do_detach_tab (GtkNotebook *from,
GtkNotebook *to,
GtkWidget *child)
{
GtkNotebookPrivate *to_priv = to->priv;
GtkWidget *tab_label, *menu_label;
@ -3243,9 +3240,6 @@ do_detach_tab (GtkNotebook *from,
gtk_notebook_detach_tab (from, child);
to_priv->mouse_x = x;
to_priv->mouse_y = y;
element = get_drop_position (to);
page_num = g_list_position (to_priv->children, element);
gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
@ -3298,8 +3292,6 @@ gtk_notebook_drag_data_get (GtkWidget *widget,
static void
gtk_notebook_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint time)
{
@ -3315,7 +3307,7 @@ gtk_notebook_drag_data_received (GtkWidget *widget,
{
child = (void*) gtk_selection_data_get_data (data);
do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child, x, y);
do_detach_tab (GTK_NOTEBOOK (source_widget), notebook, *child);
gtk_drag_finish (context, TRUE, FALSE, time);
}
else
@ -7130,8 +7122,6 @@ gtk_notebook_get_tab_detachable (GtkNotebook *notebook,
* static void
* on_drag_data_received (GtkWidget *widget,
* GdkDragContext *context,
* gint x,
* gint y,
* GtkSelectionData *data,
* guint time,
* gpointer user_data)

View File

@ -457,8 +457,6 @@ static gboolean gtk_text_view_drag_drop (GtkWidget *widget,
guint time);
static void gtk_text_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time);
@ -8081,8 +8079,6 @@ insert_text_data (GtkTextView *text_view,
static void
gtk_text_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time)
{

View File

@ -651,8 +651,6 @@ static gboolean gtk_tree_view_drag_drop (GtkWidget *widget,
guint time);
static void gtk_tree_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time);
@ -7806,9 +7804,6 @@ gtk_tree_view_drag_drop (GtkWidget *widget,
static void
gtk_tree_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
/* coordinates relative to the widget */
gint x,
gint y,
GtkSelectionData *selection_data,
guint time)
{

View File

@ -2951,11 +2951,9 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkWidgetClass, drag_data_received),
NULL, NULL,
_gtk_marshal_VOID__OBJECT_INT_INT_BOXED_UINT,
G_TYPE_NONE, 5,
_gtk_marshal_VOID__OBJECT_BOXED_UINT,
G_TYPE_NONE, 3,
GDK_TYPE_DRAG_CONTEXT,
G_TYPE_INT,
G_TYPE_INT,
GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE,
G_TYPE_UINT);

View File

@ -425,8 +425,6 @@ struct _GtkWidgetClass
guint time_);
void (* drag_data_received) (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint time_);
gboolean (* drag_failed) (GtkWidget *widget,

View File

@ -367,8 +367,6 @@ target_drag_drop (GtkWidget *widget,
void
target_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time)
@ -387,8 +385,6 @@ target_drag_data_received (GtkWidget *widget,
void
label_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time)

View File

@ -181,8 +181,6 @@ image_drag_data_get (GtkWidget *widget,
static void
image_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint32 time,
gpointer data)

View File

@ -47,8 +47,6 @@ drag_data_get (GtkWidget *widget,
static void
drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint32 time,

View File

@ -51,8 +51,6 @@ drag_data_get (GtkWidget *widget,
static void
drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint32 time,
gpointer data)

View File

@ -123,8 +123,6 @@ remove_in_idle (gpointer data)
static void
on_button_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint time,
gpointer user_data)

View File

@ -91,7 +91,6 @@ get_dragsource (void)
static void
drag_data_received (GtkWidget *widget,
GdkDragContext *context,
gint x, gint y,
GtkSelectionData *selda,
guint time,
gpointer dada)