tests: Use accessor functions to access GtkSelectionData

This commit is contained in:
Javier Jardón 2010-12-15 23:47:45 +00:00
parent 67f6a43702
commit 7105e8e907
5 changed files with 34 additions and 27 deletions

View File

@ -377,13 +377,14 @@ target_drag_data_received (GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
gint x, gint x,
gint y, gint y,
GtkSelectionData *data, GtkSelectionData *selection_data,
guint info, guint info,
guint time) guint time)
{ {
if ((data->length >= 0) && (data->format == 8)) if (gtk_selection_data_get_length (selection_data) >= 0 &&
gtk_selection_data_get_format (selection_data) == 8)
{ {
g_print ("Received \"%s\" in trashcan\n", (gchar *)data->data); g_print ("Received \"%s\" in trashcan\n", (gchar *) gtk_selection_data_get_data (selection_data));
gtk_drag_finish (context, TRUE, FALSE, time); gtk_drag_finish (context, TRUE, FALSE, time);
return; return;
} }
@ -396,13 +397,14 @@ label_drag_data_received (GtkWidget *widget,
GdkDragContext *context, GdkDragContext *context,
gint x, gint x,
gint y, gint y,
GtkSelectionData *data, GtkSelectionData *selection_data,
guint info, guint info,
guint time) guint time)
{ {
if ((data->length >= 0) && (data->format == 8)) if (gtk_selection_data_get_length (selection_data) >= 0 &&
gtk_selection_data_get_format (selection_data) == 8)
{ {
g_print ("Received \"%s\" in label\n", (gchar *)data->data); g_print ("Received \"%s\" in label\n", (gchar *) gtk_selection_data_get_data (selection_data));
gtk_drag_finish (context, TRUE, FALSE, time); gtk_drag_finish (context, TRUE, FALSE, time);
return; return;
} }
@ -422,7 +424,7 @@ 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,
selection_data->target, gtk_selection_data_get_target (selection_data),
8, (guchar *) "I'm Data!", 9); 8, (guchar *) "I'm Data!", 9);
} }

View File

@ -8917,19 +8917,19 @@ create_snapshot (GtkWidget *widget)
void void
selection_test_received (GtkWidget *tree_view, selection_test_received (GtkWidget *tree_view,
GtkSelectionData *data) GtkSelectionData *selection_data)
{ {
GtkTreeModel *model; GtkTreeModel *model;
GtkListStore *store; GtkListStore *store;
GdkAtom *atoms; GdkAtom *atoms;
int i, l; int i, l;
if (data->length < 0) if (gtk_selection_data_get_length (selection_data) < 0)
{ {
g_print ("Selection retrieval failed\n"); g_print ("Selection retrieval failed\n");
return; return;
} }
if (data->type != GDK_SELECTION_TYPE_ATOM) if (gtk_selection_data_get_data_type (selection_data) != GDK_SELECTION_TYPE_ATOM)
{ {
g_print ("Selection \"TARGETS\" was not returned as atoms!\n"); g_print ("Selection \"TARGETS\" was not returned as atoms!\n");
return; return;
@ -8943,9 +8943,9 @@ selection_test_received (GtkWidget *tree_view,
/* Add new items to list */ /* Add new items to list */
atoms = (GdkAtom *)data->data; gtk_selection_data_get_targets (selection_data,
&atoms, &l);
l = data->length / sizeof (GdkAtom);
for (i = 0; i < l; i++) for (i = 0; i < l; i++)
{ {
char *name; char *name;

View File

@ -61,7 +61,7 @@ drag_data_received (GtkWidget *widget,
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
if (selection_data->length < 0) if (gtk_selection_data_get_length (selection_data) < 0)
return; return;
pixbuf = gtk_selection_data_get_pixbuf (selection_data); pixbuf = gtk_selection_data_get_pixbuf (selection_data);

View File

@ -134,7 +134,7 @@ on_button_drag_data_received (GtkWidget *widget,
GtkWidget **child; GtkWidget **child;
source = gtk_drag_get_source_widget (context); source = gtk_drag_get_source_widget (context);
child = (void*) data->data; child = (void*) gtk_selection_data_get_data (data);
tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child); tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child);
g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label))); g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));

View File

@ -265,24 +265,28 @@ stringify_span (guchar *data, gint *position)
} }
void void
selection_received (GtkWidget *widget, GtkSelectionData *data) selection_received (GtkWidget *widget, GtkSelectionData *selection_data)
{ {
int position; int position;
int i; int i;
SelType seltype; SelType seltype;
char *str; char *str;
guchar *data;
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
GdkAtom type;
if (data->length < 0) if (gtk_selection_data_get_length (selection_data) < 0)
{ {
g_print("Error retrieving selection\n"); g_print("Error retrieving selection\n");
return; return;
} }
type = gtk_selection_data_get_data_type (selection_data);
seltype = SEL_TYPE_NONE; seltype = SEL_TYPE_NONE;
for (i=0; i<LAST_SEL_TYPE; i++) for (i=0; i<LAST_SEL_TYPE; i++)
{ {
if (seltypes[i] == data->type) if (seltypes[i] == type)
{ {
seltype = i; seltype = i;
break; break;
@ -291,7 +295,7 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
if (seltype == SEL_TYPE_NONE) if (seltype == SEL_TYPE_NONE)
{ {
char *name = gdk_atom_name (data->type); char *name = gdk_atom_name (type);
g_print("Don't know how to handle type: %s\n", g_print("Don't know how to handle type: %s\n",
name?name:"<unknown>"); name?name:"<unknown>");
return; return;
@ -306,38 +310,39 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
gtk_text_buffer_set_text (buffer, "", -1); gtk_text_buffer_set_text (buffer, "", -1);
position = 0; position = 0;
while (position < data->length) while (position < gtk_selection_data_get_length (selection_data))
{ {
data = (guchar *) gtk_selection_data_get_data (selection_data);
switch (seltype) switch (seltype)
{ {
case ATOM: case ATOM:
str = stringify_atom (data->data, &position); str = stringify_atom (data, &position);
break; break;
case COMPOUND_TEXT: case COMPOUND_TEXT:
case STRING: case STRING:
case TEXT: case TEXT:
str = stringify_text (data->data, &position); str = stringify_text (data, &position);
break; break;
case BITMAP: case BITMAP:
case DRAWABLE: case DRAWABLE:
case PIXMAP: case PIXMAP:
case WINDOW: case WINDOW:
case COLORMAP: case COLORMAP:
str = stringify_xid (data->data, &position); str = stringify_xid (data, &position);
break; break;
case INTEGER: case INTEGER:
case PIXEL: case PIXEL:
str = stringify_integer (data->data, &position); str = stringify_integer (data, &position);
break; break;
case SPAN: case SPAN:
str = stringify_span (data->data, &position); str = stringify_span (data, &position);
break; break;
default: default:
{ {
char *name = gdk_atom_name (data->type); char *name = gdk_atom_name (gtk_selection_data_get_data_type (selection_data));
g_print("Can't convert type %s to string\n", g_print("Can't convert type %s to string\n",
name?name:"<unknown>"); name?name:"<unknown>");
position = data->length; position = gtk_selection_data_get_length (selection_data);
continue; continue;
} }
} }