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

Re: Patch GtkSelection 2.16



On Sat, Jan 17, 2009 at 8:38 PM, muppet <scott asofyet org> wrote:
>
> For extra points, you could golf the code a little bit with these
> definitions up before the first MODULE:
>
>    #if ! GTK_CHECK_VERSION (2, 15, 0) /* FIXME 2.16 */
>    # define gtk_selection_data_get_selection (d)  ((d)->selection)
>    #endif
>    #if ! GTK_CHECK_VERSION (2, 14, 0)
>    # define gtk_selection_data_get_target (d)  ((d)->target)
>    # define gtk_selection_data_get_data_type (d)  ((d)->data_type)
>    # define gtk_selection_data_get_format (d)  ((d)->format)
>    ...
>    #endif
>
> and unconditionally use the accessors in the switch.
>

This patch goes for the extra points.

-- 
Emmanuel Rodriguez
Index: xs/GtkSelection.xs
===================================================================
--- xs/GtkSelection.xs	(revision 2111)
+++ xs/GtkSelection.xs	(working copy)
@@ -21,6 +21,21 @@
 
 #include "gtk2perl.h"
 
+
+#if !GTK_CHECK_VERSION (2, 15, 0) /* FIXME 2.16.0 */
+#  define gtk_selection_data_get_selection (d) ((d)->selection)
+#endif /* 2.16 */
+
+#if !GTK_CHECK_VERSION (2, 14, 0)
+#  define gtk_selection_data_get_target (d)    ((d)->target)
+#  define gtk_selection_data_get_data_type (d) ((d)->type)
+#  define gtk_selection_data_get_data (d)      ((d)->data)
+#  define gtk_selection_data_get_format (d)    ((d)->format)
+#  define gtk_selection_data_get_length (d)    ((d)->length)
+#  define gtk_selection_data_get_display (d)   ((d)->display)
+#endif /* 2.14 */
+
+
 SV *
 newSVGtkTargetEntry (GtkTargetEntry * e)
 {
@@ -395,7 +410,7 @@
 
 MODULE = Gtk2::Selection	PACKAGE = Gtk2::SelectionData	PREFIX = gtk_selection_data_
 
-=for apidoc Gtk2::SelectionData::selection __hide__
+=for apidoc Gtk2::SelectionData::selection_ __hide__
 =cut
 
 =for apidoc Gtk2::SelectionData::target __hide__
@@ -422,7 +437,7 @@
 # const guchar *gtk_selection_data_get_data (GtkSelectionData *selection_data, gint *length);
 # GdkDisplay *gtk_selection_data_get_display (GtkSelectionData *selection_data);
 SV *
-get_selection (d)
+get_selection_ (d)
 	GtkSelectionData * d
     ALIAS:
 	Gtk2::SelectionData::selection     = 1
@@ -442,64 +457,35 @@
 	switch (ix) {
 	    case 0:
 	    case 1:
-		/* selection doesn't have an accessor yet. */
-		RETVAL = newSVGdkAtom (d->selection);
+		RETVAL = newSVGdkAtom (gtk_selection_data_get_selection (d));
 		break;
 	    case 2:
 	    case 3:
-#if GTK_CHECK_VERSION (2, 14, 0)
 		RETVAL = newSVGdkAtom (gtk_selection_data_get_target (d));
-#else
-		RETVAL = newSVGdkAtom (d->target);
-#endif /* 2.14 */
 		break;
 	    case 4:
 	    case 5:
-#if GTK_CHECK_VERSION (2, 14, 0)
 		RETVAL = newSVGdkAtom (gtk_selection_data_get_data_type (d));
-#else
-		RETVAL = newSVGdkAtom (d->type);
-#endif /* 2.14 */
 		break;
 	    case 6:
 	    case 7:
-#if GTK_CHECK_VERSION (2, 14, 0)
 		RETVAL = newSViv (gtk_selection_data_get_format (d));
-#else
-		RETVAL = newSViv (d->format);
-#endif /* 2.14 */
 		break;
 	    case 8:
 	    case 9:
-#if GTK_CHECK_VERSION (2, 14, 0)
-	    {
-		gint length = gtk_selection_data_get_length (d);
-		const guchar *data = gtk_selection_data_get_data (d);
-		RETVAL = newSVpv ((const gchar *) data, length);
-	    }
-#else
-		RETVAL = newSVpv ((char*)d->data, d->length);
-#endif /* 2.14 */
+		RETVAL = newSVpv (
+			(const gchar *) gtk_selection_data_get_data (d),
+			gtk_selection_data_get_length (d)
+		);
 		break;
 	    case 10:
 	    case 11:
-#if GTK_CHECK_VERSION (2, 14, 0)
-	    {
-		gint length = gtk_selection_data_get_length (d);
-		RETVAL = newSViv (length);
-	    }
-#else
-		RETVAL = newSViv (d->length);
-#endif /* 2.14 */
+		RETVAL = newSViv (gtk_selection_data_get_length (d));
 		break;
 #if GTK_CHECK_VERSION(2, 2, 0)
 	    case 12:
 	    case 13:
-#if GTK_CHECK_VERSION (2, 14, 0)
 		RETVAL = newSVGdkDisplay (gtk_selection_data_get_display (d));
-#else
-		RETVAL = newSVGdkDisplay (d->display);
-#endif /* 2.14 */
 		break;
 #endif /* 2.2 */
 	    default:
@@ -639,3 +625,9 @@
 gboolean gtk_selection_data_targets_include_uri (GtkSelectionData *selection_data) 
 
 #endif /* 2.10 */
+
+#if GTK_CHECK_VERSION (2, 15, 0) /* FIXME 2.16.0 */
+
+GdkAtom gtk_selection_data_get_selection (GtkSelectionData *selection_data);
+
+#endif /* 2.16 */
Index: t/GtkClipboard.t
===================================================================
--- t/GtkClipboard.t	(revision 2111)
+++ t/GtkClipboard.t	(working copy)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 # vim: set ft=perl :
-use Gtk2::TestHelper tests => 115,
+use Gtk2::TestHelper tests => 119,
 	at_least_version => [2, 2, 0, "GtkClipboard didn't exist in 2.0.x"];
 
 # $Id$
@@ -149,6 +149,22 @@
 	});
 }
 
+SKIP: {
+	skip "new 2.16 stuff", 4
+		unless Gtk2->CHECK_VERSION (2, 15, 0);
+
+	my $pixbuf = Gtk2::Gdk::Pixbuf->new ("rgb", FALSE, 8, 23, 42);
+	$clipboard->set_image ($pixbuf);
+	is ($clipboard->wait_is_image_available, TRUE);
+
+	my $contents = $clipboard->wait_for_contents(Gtk2::Gdk::Atom->intern('image/png'));
+	isa_ok ($contents, "Gtk2::SelectionData");
+	
+	my $atom = $contents->get_selection;
+	isa_ok ($atom, 'Gtk2::Gdk::Atom');
+	is ($atom->name, 'PRIMARY');
+}
+
 run_main;
 
 #print "----------------------------------\n";


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