Compare commits

...

3 Commits

Author SHA1 Message Date
Ernestas Kulik
cb7202ac6f gtkselection: Drop gtk_selection_data_get_targets()
As the data isn’t set anywhere with the type “ATOM”, this doesn’t work
as expected and can be replaced by a target atom check.
2018-07-31 23:29:26 +03:00
Ernestas Kulik
ef632da8b6 gtkselection: Drop format field
It’s not used anywhere in a meaningful way and looks safe to rip out and
replace with a hardcoded constant where appropriate.
2018-07-31 23:29:26 +03:00
Ernestas Kulik
0967f6f3fc tests: testdnd: Use G_N_ELEMENTS macro
Wasted some horizontal screen estate, but beats rolling our own thing.
2018-07-31 23:29:26 +03:00
14 changed files with 33 additions and 136 deletions

View File

@@ -355,7 +355,7 @@ gtk_color_button_drag_data_get (GtkWidget *widget,
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
gtk_selection_data_get_target (selection_data), gtk_selection_data_get_target (selection_data),
16, (guchar *)dropped, 8); (guchar *)dropped, 8);
} }
static void static void

View File

@@ -202,7 +202,7 @@ swatch_drag_data_get (GtkWidget *widget,
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
g_intern_static_string ("application/x-color"), g_intern_static_string ("application/x-color"),
16, (guchar *)vals, 8); (guchar *)vals, 8);
} }
static void static void

View File

@@ -166,7 +166,6 @@ gtk_drag_get_data_finish (GtkDragGetData *data,
sdata.target = data->mime_type; sdata.target = data->mime_type;
sdata.type = data->mime_type; sdata.type = data->mime_type;
sdata.format = 8;
sdata.length = size; sdata.length = size;
sdata.data = bytes; sdata.data = bytes;
sdata.display = gtk_widget_get_display (data->widget); sdata.display = gtk_widget_get_display (data->widget);

View File

@@ -444,7 +444,6 @@ gtk_link_button_drag_data_get_cb (GtkWidget *widget,
uri = g_strdup_printf ("%s\r\n", priv->uri); uri = g_strdup_printf ("%s\r\n", priv->uri);
gtk_selection_data_set (selection, gtk_selection_data_set (selection,
gtk_selection_data_get_target (selection), gtk_selection_data_get_target (selection),
8,
(guchar *) uri, (guchar *) uri,
strlen (uri)); strlen (uri));

View File

@@ -3212,14 +3212,13 @@ gtk_notebook_drag_data_get (GtkWidget *widget,
{ {
gtk_selection_data_set (data, gtk_selection_data_set (data,
target, target,
8,
(void*) &priv->detached_tab->child, (void*) &priv->detached_tab->child,
sizeof (gpointer)); sizeof (gpointer));
priv->rootwindow_drop = FALSE; priv->rootwindow_drop = FALSE;
} }
else if (target == g_intern_static_string ("application/x-rootwindow-drop")) else if (target == g_intern_static_string ("application/x-rootwindow-drop"))
{ {
gtk_selection_data_set (data, target, 8, NULL, 0); gtk_selection_data_set (data, target, NULL, 0);
priv->rootwindow_drop = TRUE; priv->rootwindow_drop = TRUE;
} }
} }

View File

@@ -1964,7 +1964,6 @@ drag_data_get_callback (GtkWidget *widget,
{ {
gtk_selection_data_set (data, gtk_selection_data_set (data,
target, target,
8,
(void*)&sidebar->drag_row, (void*)&sidebar->drag_row,
sizeof (gpointer)); sizeof (gpointer));
} }

View File

@@ -193,7 +193,7 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
const char *utf8_string = [s UTF8String]; const char *utf8_string = [s UTF8String];
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
target, 8, target,
(guchar *)utf8_string, strlen (utf8_string)); (guchar *)utf8_string, strlen (utf8_string));
} }
} }
@@ -211,7 +211,7 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
color[2] = 0xffff * [nscolor blueComponent]; color[2] = 0xffff * [nscolor blueComponent];
color[3] = 0xffff * [nscolor alphaComponent]; color[3] = 0xffff * [nscolor alphaComponent];
gtk_selection_data_set (selection_data, target, 16, (guchar *)color, 8); gtk_selection_data_set (selection_data, target, (guchar *)color, 8);
} }
else if (target == g_intern_static_string ("text/uri-list")) else if (target == g_intern_static_string ("text/uri-list"))
{ {
@@ -265,7 +265,7 @@ _gtk_quartz_get_selection_data_from_pasteboard (NSPasteboard *pasteboard,
if (data) if (data)
{ {
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
target, 8, target,
[data bytes], [data length]); [data bytes], [data length]);
} }
} }
@@ -279,12 +279,10 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard *pasteboard,
{ {
NSString *type; NSString *type;
GdkDisplay *display; GdkDisplay *display;
gint format;
const guchar *data; const guchar *data;
NSUInteger length; NSUInteger length;
display = gtk_selection_data_get_display (selection_data); display = gtk_selection_data_get_display (selection_data);
format = gtk_selection_data_get_format (selection_data);
data = gtk_selection_data_get_data (selection_data); data = gtk_selection_data_get_data (selection_data);
length = gtk_selection_data_get_length (selection_data); length = gtk_selection_data_get_length (selection_data);

View File

@@ -299,22 +299,6 @@ gtk_selection_data_get_data_type (const GtkSelectionData *selection_data)
return selection_data->type; return selection_data->type;
} }
/**
* gtk_selection_data_get_format:
* @selection_data: a pointer to a #GtkSelectionData-struct.
*
* Retrieves the format of the selection.
*
* Returns: the format of the selection.
**/
gint
gtk_selection_data_get_format (const GtkSelectionData *selection_data)
{
g_return_val_if_fail (selection_data != NULL, 0);
return selection_data->format;
}
/** /**
* gtk_selection_data_get_data: (skip) * gtk_selection_data_get_data: (skip)
* @selection_data: a pointer to a * @selection_data: a pointer to a
@@ -388,7 +372,6 @@ gtk_selection_data_get_display (const GtkSelectionData *selection_data)
* gtk_selection_data_set: * gtk_selection_data_set:
* @selection_data: a pointer to a #GtkSelectionData-struct. * @selection_data: a pointer to a #GtkSelectionData-struct.
* @type: the type of selection data * @type: the type of selection data
* @format: format (number of bits in a unit)
* @data: (array length=length): pointer to the data (will be copied) * @data: (array length=length): pointer to the data (will be copied)
* @length: length of the data * @length: length of the data
* *
@@ -399,7 +382,6 @@ gtk_selection_data_get_display (const GtkSelectionData *selection_data)
void void
gtk_selection_data_set (GtkSelectionData *selection_data, gtk_selection_data_set (GtkSelectionData *selection_data,
GdkAtom type, GdkAtom type,
gint format,
const guchar *data, const guchar *data,
gint length) gint length)
{ {
@@ -408,7 +390,6 @@ gtk_selection_data_set (GtkSelectionData *selection_data,
g_free (selection_data->data); g_free (selection_data->data);
selection_data->type = type; selection_data->type = type;
selection_data->format = format;
if (data) if (data)
{ {
@@ -442,7 +423,7 @@ selection_set_string (GtkSelectionData *selection_data,
{ {
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
g_intern_static_string ("STRING"), g_intern_static_string ("STRING"),
8, (guchar *) latin1, strlen (latin1)); (guchar *) latin1, strlen (latin1));
g_free (latin1); g_free (latin1);
return TRUE; return TRUE;
@@ -462,16 +443,15 @@ selection_set_compound_text (GtkSelectionData *selection_data,
gchar *tmp; gchar *tmp;
guchar *text; guchar *text;
GdkAtom encoding; GdkAtom encoding;
gint format;
gint new_length; gint new_length;
if (GDK_IS_X11_DISPLAY (selection_data->display)) if (GDK_IS_X11_DISPLAY (selection_data->display))
{ {
tmp = g_strndup (str, len); tmp = g_strndup (str, len);
if (gdk_x11_display_utf8_to_compound_text (selection_data->display, tmp, if (gdk_x11_display_utf8_to_compound_text (selection_data->display, tmp,
&encoding, &format, &text, &new_length)) &encoding, NULL, &text, &new_length))
{ {
gtk_selection_data_set (selection_data, encoding, format, text, new_length); gtk_selection_data_set (selection_data, encoding, text, new_length);
gdk_x11_free_compound_text (text); gdk_x11_free_compound_text (text);
result = TRUE; result = TRUE;
@@ -578,7 +558,7 @@ selection_set_text_plain (GtkSelectionData *selection_data,
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
selection_data->target, selection_data->target,
8, (guchar *) result, strlen (result)); (guchar *) result, strlen (result));
g_free (result); g_free (result);
return TRUE; return TRUE;
@@ -661,7 +641,7 @@ gtk_selection_data_set_text (GtkSelectionData *selection_data,
{ {
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
utf8_atom, utf8_atom,
8, (guchar *)str, len); (guchar *)str, len);
return TRUE; return TRUE;
} }
else if (selection_data->target == g_intern_static_string ("STRING")) else if (selection_data->target == g_intern_static_string ("STRING"))
@@ -715,7 +695,7 @@ gtk_selection_data_get_text (const GtkSelectionData *selection_data)
gint i; gint i;
gint count = gdk_text_property_to_utf8_list_for_display (selection_data->display, gint count = gdk_text_property_to_utf8_list_for_display (selection_data->display,
selection_data->type, selection_data->type,
selection_data->format, 8,
selection_data->data, selection_data->data,
selection_data->length, selection_data->length,
&list); &list);
@@ -784,7 +764,7 @@ gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data,
NULL); NULL);
if (result) if (result)
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
atom, 8, (guchar *)str, len); atom, (guchar *)str, len);
g_free (type); g_free (type);
g_free (str); g_free (str);
g_strfreev (mimes); g_strfreev (mimes);
@@ -963,7 +943,7 @@ gtk_selection_data_set_uris (GtkSelectionData *selection_data,
{ {
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
text_uri_list_atom, text_uri_list_atom,
8, (guchar *)result, length); (guchar *)result, length);
g_free (result); g_free (result);
@@ -1001,7 +981,7 @@ gtk_selection_data_get_uris (const GtkSelectionData *selection_data)
gchar **list; gchar **list;
gint count = gdk_text_property_to_utf8_list_for_display (selection_data->display, gint count = gdk_text_property_to_utf8_list_for_display (selection_data->display,
utf8_atom, utf8_atom,
selection_data->format, 8,
selection_data->data, selection_data->data,
selection_data->length, selection_data->length,
&list); &list);
@@ -1014,52 +994,6 @@ gtk_selection_data_get_uris (const GtkSelectionData *selection_data)
return result; return result;
} }
/**
* gtk_selection_data_get_targets:
* @selection_data: a #GtkSelectionData object
* @targets: (out) (array length=n_atoms) (transfer container):
* location to store an array of targets. The result stored
* here must be freed with g_free().
* @n_atoms: location to store number of items in @targets.
*
* Gets the contents of @selection_data as an array of targets.
* This can be used to interpret the results of getting
* the standard TARGETS target that is always supplied for
* any selection.
*
* Returns: %TRUE if @selection_data contains a valid
* array of targets, otherwise %FALSE.
**/
gboolean
gtk_selection_data_get_targets (const GtkSelectionData *selection_data,
GdkAtom **targets,
gint *n_atoms)
{
g_return_val_if_fail (selection_data != NULL, FALSE);
if (selection_data->length >= 0 &&
selection_data->format == 32 &&
selection_data->type == g_intern_static_string ("ATOM"))
{
if (targets)
*targets = g_memdup (selection_data->data, selection_data->length);
if (n_atoms)
*n_atoms = selection_data->length / sizeof (GdkAtom);
return TRUE;
}
else
{
if (targets)
*targets = NULL;
if (n_atoms)
*n_atoms = -1;
return FALSE;
}
}
/** /**
* gtk_targets_include_text: * gtk_targets_include_text:
* @targets: (array length=n_targets): an array of #GdkAtoms * @targets: (array length=n_targets): an array of #GdkAtoms
@@ -1117,21 +1051,15 @@ gtk_targets_include_text (GdkAtom *targets,
gboolean gboolean
gtk_selection_data_targets_include_text (const GtkSelectionData *selection_data) gtk_selection_data_targets_include_text (const GtkSelectionData *selection_data)
{ {
GdkAtom *targets; GdkAtom target;
gint n_targets;
gboolean result = FALSE;
g_return_val_if_fail (selection_data != NULL, FALSE); g_return_val_if_fail (selection_data != NULL, FALSE);
init_atoms (); init_atoms ();
if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) target = gtk_selection_data_get_target (selection_data);
{
result = gtk_targets_include_text (targets, n_targets);
g_free (targets);
}
return result; return gtk_targets_include_text (&target, 1);
} }
/** /**
@@ -1190,21 +1118,15 @@ gboolean
gtk_selection_data_targets_include_image (const GtkSelectionData *selection_data, gtk_selection_data_targets_include_image (const GtkSelectionData *selection_data,
gboolean writable) gboolean writable)
{ {
GdkAtom *targets; GdkAtom target;
gint n_targets;
gboolean result = FALSE;
g_return_val_if_fail (selection_data != NULL, FALSE); g_return_val_if_fail (selection_data != NULL, FALSE);
init_atoms (); init_atoms ();
if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) target = gtk_selection_data_get_target (selection_data);
{
result = gtk_targets_include_image (targets, n_targets, writable);
g_free (targets);
}
return result; return gtk_targets_include_image (&target, 1, writable);
} }
/** /**
@@ -1258,21 +1180,15 @@ gtk_targets_include_uri (GdkAtom *targets,
gboolean gboolean
gtk_selection_data_targets_include_uri (const GtkSelectionData *selection_data) gtk_selection_data_targets_include_uri (const GtkSelectionData *selection_data)
{ {
GdkAtom *targets; GdkAtom target;
gint n_targets;
gboolean result = FALSE;
g_return_val_if_fail (selection_data != NULL, FALSE); g_return_val_if_fail (selection_data != NULL, FALSE);
init_atoms (); init_atoms ();
if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets)) target = gtk_selection_data_get_target (selection_data);
{
result = gtk_targets_include_uri (targets, n_targets);
g_free (targets);
}
return result; return gtk_targets_include_uri (&target, 1);
} }
/** /**

View File

@@ -49,8 +49,6 @@ GdkAtom gtk_selection_data_get_target (const GtkSelectionData *selectio
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
GdkAtom gtk_selection_data_get_data_type (const GtkSelectionData *selection_data); GdkAtom gtk_selection_data_get_data_type (const GtkSelectionData *selection_data);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gint gtk_selection_data_get_format (const GtkSelectionData *selection_data);
GDK_AVAILABLE_IN_ALL
const guchar *gtk_selection_data_get_data (const GtkSelectionData *selection_data); const guchar *gtk_selection_data_get_data (const GtkSelectionData *selection_data);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gint gtk_selection_data_get_length (const GtkSelectionData *selection_data); gint gtk_selection_data_get_length (const GtkSelectionData *selection_data);
@@ -65,7 +63,6 @@ GdkDisplay *gtk_selection_data_get_display (const GtkSelectionData *selectio
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
void gtk_selection_data_set (GtkSelectionData *selection_data, void gtk_selection_data_set (GtkSelectionData *selection_data,
GdkAtom type, GdkAtom type,
gint format,
const guchar *data, const guchar *data,
gint length); gint length);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
@@ -90,10 +87,6 @@ gboolean gtk_selection_data_set_uris (GtkSelectionData *selection_data,
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gchar **gtk_selection_data_get_uris (const GtkSelectionData *selection_data); gchar **gtk_selection_data_get_uris (const GtkSelectionData *selection_data);
GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_data_get_targets (const GtkSelectionData *selection_data,
GdkAtom **targets,
gint *n_atoms);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_selection_data_targets_include_text (const GtkSelectionData *selection_data); gboolean gtk_selection_data_targets_include_text (const GtkSelectionData *selection_data);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL

View File

@@ -40,7 +40,6 @@ struct _GtkSelectionData
/*< private >*/ /*< private >*/
GdkAtom target; GdkAtom target;
GdkAtom type; GdkAtom type;
gint format;
guchar *data; guchar *data;
gint length; gint length;
GdkDisplay *display; GdkDisplay *display;

View File

@@ -7653,7 +7653,6 @@ gtk_text_view_drag_data_get (GtkWidget *widget,
{ {
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
g_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"), g_intern_static_string ("GTK_TEXT_BUFFER_CONTENTS"),
8, /* bytes */
(void*)&buffer, (void*)&buffer,
sizeof (buffer)); sizeof (buffer));
} }

View File

@@ -293,7 +293,6 @@ gtk_tree_set_row_drag_data (GtkSelectionData *selection_data,
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
g_intern_static_string ("GTK_TREE_MODEL_ROW"), g_intern_static_string ("GTK_TREE_MODEL_ROW"),
8, /* bytes */
(void*)trd, (void*)trd,
struct_size); struct_size);

View File

@@ -295,8 +295,6 @@ static const char *target_table[] = {
"application/x-rootwindow-drop" "application/x-rootwindow-drop"
}; };
static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
void void
target_drag_leave (GtkWidget *widget, target_drag_leave (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
@@ -386,8 +384,7 @@ target_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data) GtkSelectionData *selection_data)
{ {
if (gtk_selection_data_get_length (selection_data) >= 0 && if (gtk_selection_data_get_length (selection_data) >= 0)
gtk_selection_data_get_format (selection_data) == 8)
{ {
GdkDragAction action = gdk_drop_get_actions (drop); GdkDragAction action = gdk_drop_get_actions (drop);
g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data)); g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data));
@@ -404,8 +401,7 @@ label_drag_data_received (GtkWidget *widget,
GdkDrop *drop, GdkDrop *drop,
GtkSelectionData *selection_data) GtkSelectionData *selection_data)
{ {
if (gtk_selection_data_get_length (selection_data) >= 0 && if (gtk_selection_data_get_length (selection_data) >= 0)
gtk_selection_data_get_format (selection_data) == 8)
{ {
GdkDragAction action = action_make_unique (gdk_drop_get_actions (drop)); GdkDragAction action = action_make_unique (gdk_drop_get_actions (drop));
g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data)); g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data));
@@ -426,8 +422,8 @@ source_drag_data_get (GtkWidget *widget,
g_print ("I was dropped on the rootwin\n"); g_print ("I was dropped on the rootwin\n");
else else
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
gtk_selection_data_get_target (selection_data), gtk_selection_data_get_target (selection_data),
8, (guchar *) "I'm Data!", 9); (guchar *) "I'm Data!", 9);
} }
/* The following is a rather elaborate example demonstrating/testing /* The following is a rather elaborate example demonstrating/testing
@@ -503,7 +499,8 @@ popup_cb (gpointer data)
gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE); gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
grid = gtk_grid_new (); grid = gtk_grid_new ();
targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */ /* no rootwin */
targets = gdk_content_formats_new (target_table, G_N_ELEMENTS (target_table) - 1);
for (i=0; i<3; i++) for (i=0; i<3; i++)
for (j=0; j<3; j++) for (j=0; j<3; j++)
@@ -610,7 +607,8 @@ main (int argc, char **argv)
label = gtk_label_new ("Drop Here\n"); label = gtk_label_new ("Drop Here\n");
targets = gdk_content_formats_new (target_table, n_targets - 1); /* no rootwin */ /* no rootwin */
targets = gdk_content_formats_new (target_table, G_N_ELEMENTS (target_table) - 1);
gtk_drag_dest_set (label, gtk_drag_dest_set (label,
GTK_DEST_DEFAULT_ALL, GTK_DEST_DEFAULT_ALL,
targets, targets,
@@ -662,7 +660,7 @@ main (int argc, char **argv)
button = gtk_button_new_with_label ("Drag Here\n"); button = gtk_button_new_with_label ("Drag Here\n");
targets = gdk_content_formats_new (target_table, n_targets); targets = gdk_content_formats_new (target_table, G_N_ELEMENTS (target_table));
gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK, gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
targets, targets,
GDK_ACTION_COPY | GDK_ACTION_MOVE); GDK_ACTION_COPY | GDK_ACTION_MOVE);

View File

@@ -33,7 +33,6 @@ drag_data_get (GtkWidget *widget,
{ {
gtk_selection_data_set (selection_data, gtk_selection_data_set (selection_data,
g_intern_static_string ("GTK_LIST_BOX_ROW"), g_intern_static_string ("GTK_LIST_BOX_ROW"),
32,
(const guchar *)&widget, (const guchar *)&widget,
sizeof (gpointer)); sizeof (gpointer));
} }