Actually, I think it's necessary to clear a newly created
GtkSelectionData struct to zeros too (something I didn't change).

Program below gets a segv from the current code.  I think the "data"
pointer in a GtkSelectionData is a malloced block or NULL.
gtk_selection_data_set() does g_free() on the old before copying and
storing the new.

Dunno if anything special should be initialized in the other fields, I
couldn't find the actual code within gtk that does a normal call out to
a treesource *drag_data_get() interface func.

package MyObject;
use strict;
use warnings;
use Gtk2;

use Glib::Object::Subclass
  Glib::Object::,
  interfaces => [ 'Gtk2::TreeModel',
                  'Gtk2::TreeDragSource' ];

sub DRAG_DATA_GET {
  my ($self, $path, $sel) = @_;
  my $target = Gtk2::Gdk::Atom->intern ('UTF8_STRING');
  my $text = 'hello world';
  $sel->set ($target, 8, $text);
  return 1;
}

package Main;
use strict;
use warnings;

my $obj = MyObject->new;
my $path = Gtk2::TreePath->new_from_indices (0);
my $sel = $obj->drag_data_get ($path);

print $sel,"\n";
exit 0;

--- GtkTreeDnd.xs	12 Jul 2005 08:39:21 +1000	1.9
+++ GtkTreeDnd.xs	13 Jul 2008 20:21:24 +1000	
@@ -136,20 +136,32 @@
 	GtkTreeDragSource *drag_source
 	GtkTreePath *path
 
+=for apidoc
+Get selection data from a drag source.  The data is written to
+$selection_data, or if $selection_data is not given then to a newly
+created Gtk2::SelectionData object.  On success the return is the
+given or new object, or on failure the return is undef.
+=cut
 ### gboolean gtk_tree_drag_source_drag_data_get (GtkTreeDragSource *drag_source, GtkTreePath *path, GtkSelectionData *selection_data)
-GtkSelectionData_copy *
-gtk_tree_drag_source_drag_data_get (drag_source, path)
-	GtkTreeDragSource *drag_source
-	GtkTreePath *path
+void
+gtk_tree_drag_source_drag_data_get (GtkTreeDragSource *drag_source, GtkTreePath *path, GtkSelectionData *selection_data = NULL)
     PREINIT:
-	GtkSelectionData selection_data;
-    CODE:
-	if (!gtk_tree_drag_source_drag_data_get (drag_source, path, 
-	                                         &selection_data))
-		XSRETURN_UNDEF;
-	RETVAL = &selection_data;
-    OUTPUT:
-	RETVAL
+	SV *ret = &PL_sv_undef;
+    PPCODE:
+	if (selection_data) {
+		if (gtk_tree_drag_source_drag_data_get (drag_source, path,
+		                                        selection_data))
+			ret = ST(2);
+	} else {
+		GtkSelectionData new_selection_data;
+		memset (&new_selection_data, '\0', sizeof(new_selection_data));
+		new_selection_data.target
+		  = gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW");
+		if (gtk_tree_drag_source_drag_data_get (drag_source, path,
+		                                        &new_selection_data))
+			ret = sv_2mortal (newSVGtkSelectionData_copy (&new_selection_data));
+	}
+	PUSHs (ret);
 
 MODULE = Gtk2::TreeDnd	PACKAGE = Gtk2::TreeDragDest	PREFIX = gtk_tree_drag_dest_
 
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to