[gtk+] tests: Use accessor functions to access GtkSelectionData



commit 7105e8e907cbf22234bbf9297f7cd062d093ea70
Author: Javier Jardón <jjardon gnome org>
Date:   Wed Dec 15 23:47:45 2010 +0000

    tests: Use accessor functions to access GtkSelectionData

 tests/testdnd.c         |   16 +++++++++-------
 tests/testgtk.c         |   10 +++++-----
 tests/testimage.c       |    2 +-
 tests/testnotebookdnd.c |    2 +-
 tests/testselection.c   |   31 ++++++++++++++++++-------------
 5 files changed, 34 insertions(+), 27 deletions(-)
---
diff --git a/tests/testdnd.c b/tests/testdnd.c
index 8777acd..9913564 100644
--- a/tests/testdnd.c
+++ b/tests/testdnd.c
@@ -377,13 +377,14 @@ target_drag_data_received  (GtkWidget          *widget,
 			    GdkDragContext     *context,
 			    gint                x,
 			    gint                y,
-			    GtkSelectionData   *data,
+			    GtkSelectionData   *selection_data,
 			    guint               info,
 			    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);
       return;
     }
@@ -396,13 +397,14 @@ label_drag_data_received  (GtkWidget          *widget,
 			    GdkDragContext     *context,
 			    gint                x,
 			    gint                y,
-			    GtkSelectionData   *data,
+			    GtkSelectionData   *selection_data,
 			    guint               info,
 			    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);
       return;
     }
@@ -422,7 +424,7 @@ source_drag_data_get  (GtkWidget          *widget,
     g_print ("I was dropped on the rootwin\n");
   else
     gtk_selection_data_set (selection_data,
-			    selection_data->target,
+			    gtk_selection_data_get_target (selection_data),
 			    8, (guchar *) "I'm Data!", 9);
 }
   
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 76d6838..dee4802 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -8917,19 +8917,19 @@ create_snapshot (GtkWidget *widget)
 
 void
 selection_test_received (GtkWidget        *tree_view,
-                         GtkSelectionData *data)
+                         GtkSelectionData *selection_data)
 {
   GtkTreeModel *model;
   GtkListStore *store;
   GdkAtom *atoms;
   int i, l;
 
-  if (data->length < 0)
+  if (gtk_selection_data_get_length (selection_data) < 0)
     {
       g_print ("Selection retrieval failed\n");
       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");
       return;
@@ -8943,9 +8943,9 @@ selection_test_received (GtkWidget        *tree_view,
 
   /* 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++)
     {
       char *name;
diff --git a/tests/testimage.c b/tests/testimage.c
index 375a5b8..d44559e 100644
--- a/tests/testimage.c
+++ b/tests/testimage.c
@@ -61,7 +61,7 @@ drag_data_received (GtkWidget        *widget,
 
   GdkPixbuf *pixbuf;
 
-  if (selection_data->length < 0)
+  if (gtk_selection_data_get_length (selection_data) < 0)
     return;
 
   pixbuf = gtk_selection_data_get_pixbuf (selection_data);
diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c
index a20597b..3621b0a 100644
--- a/tests/testnotebookdnd.c
+++ b/tests/testnotebookdnd.c
@@ -134,7 +134,7 @@ on_button_drag_data_received (GtkWidget        *widget,
   GtkWidget **child;
 
   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);
   g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
diff --git a/tests/testselection.c b/tests/testselection.c
index b6b79d3..de4ec6a 100644
--- a/tests/testselection.c
+++ b/tests/testselection.c
@@ -265,24 +265,28 @@ stringify_span (guchar *data, gint *position)
 }
 
 void
-selection_received (GtkWidget *widget, GtkSelectionData *data)
+selection_received (GtkWidget *widget, GtkSelectionData *selection_data)
 {
   int position;
   int i;
   SelType seltype;
   char *str;
+  guchar *data;
   GtkTextBuffer *buffer;
-  
-  if (data->length < 0)
+  GdkAtom type;
+
+  if (gtk_selection_data_get_length (selection_data) < 0)
     {
       g_print("Error retrieving selection\n");
       return;
     }
 
+  type = gtk_selection_data_get_data_type (selection_data);
+
   seltype = SEL_TYPE_NONE;
   for (i=0; i<LAST_SEL_TYPE; i++)
     {
-      if (seltypes[i] == data->type)
+      if (seltypes[i] == type)
 	{
 	  seltype = i;
 	  break;
@@ -291,7 +295,7 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
 
   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",
 	      name?name:"<unknown>");
       return;
@@ -306,38 +310,39 @@ selection_received (GtkWidget *widget, GtkSelectionData *data)
   gtk_text_buffer_set_text (buffer, "", -1);
 
   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)
 	{
 	case ATOM:
-	  str = stringify_atom (data->data, &position);
+	  str = stringify_atom (data, &position);
 	  break;
 	case COMPOUND_TEXT:
 	case STRING:
 	case TEXT:
-	  str = stringify_text (data->data, &position);
+	  str = stringify_text (data, &position);
 	  break;
 	case BITMAP:
 	case DRAWABLE:
 	case PIXMAP:
 	case WINDOW:
 	case COLORMAP:
-	  str = stringify_xid (data->data, &position);
+	  str = stringify_xid (data, &position);
 	  break;
 	case INTEGER:
 	case PIXEL:
-	  str = stringify_integer (data->data, &position);
+	  str = stringify_integer (data, &position);
 	  break;
 	case SPAN:
-	  str = stringify_span (data->data, &position);
+	  str = stringify_span (data, &position);
 	  break;
 	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",
 		    name?name:"<unknown>");
-	    position = data->length;
+	    position = gtk_selection_data_get_length (selection_data);
 	    continue;
 	  }
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]