[Gtk-sharp-list] some drag+drop fixups

Dan Winship danw@novell.com
Fri, 15 Oct 2004 15:35:37 -0400


--=-MLOmmEBISkFXxmmYbBZU
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Currently if you use Gtk.Drag.Begin(), it will cause a crash almost
right away, because gtk_drag_begin() expects the TargetList you pass to
stay valid, and the currently-generated C# version ends up passing it a
pointer to a local variable. This patch fixes it a little bit, in that
now the pointer it passes to gtk_drag_begin() is provided by the caller,
so it's the callers' responsibility to make sure that the pointer stays
valid. Still not very nice, but I'm not sure if Gtk# has any logic for
dealing with refcounted non-GObject structures...

(Gtk.Drag.Begin() is currently unusable, so this fix is allowed under
the ABI rules. (TestDnd.cs and F-Spot use Gtk.Drag.SourceSet(), which
does work, instead of Gtk.Drag.Begin().))

The other part of the patch adds overloaded Gtk.TargetList.New and
Gtk.TargetList.AddTable methods. The existing ones are broken (they need
to have the "array" flag set on their "targets" parameters), but it's
possible to misuse the existing API and pass a single TargetEntry and
nentries==1, and it will work. So I left the gapi-generated versions as
they are and added overloads that properly accept arrays (and don't
require you to redundantly specify the array length).

-- Dan


--=-MLOmmEBISkFXxmmYbBZU
Content-Disposition: attachment; filename=drag.diff
Content-Type: text/x-patch; name=drag.diff; charset=utf-8
Content-Transfer-Encoding: 7bit

Index: ChangeLog
===================================================================
RCS file: /cvs/public/gtk-sharp/ChangeLog,v
retrieving revision 1.922
diff -u -r1.922 ChangeLog
--- ChangeLog	7 Oct 2004 15:44:00 -0000	1.922
+++ ChangeLog	15 Oct 2004 18:10:07 -0000
@@ -1,3 +1,14 @@
+2004-10-15  Dan Winship  <danw@novell.com>
+
+	* gtk/Gtk.metadata: Make Gtk.Drag.Begin more usable (but still
+	sorta broken).
+
+	* gtk/TargetList.custom: Overload Gtk.TargetList.New and
+	Gtk.TargetList.AddTable to backward-compatibly fix a
+	workaroundable bug in the current gapi-generated ones
+
+	* gtk/Makefile.am (customs): add TargetList.custom
+
 2004-10-07  Mike Kestner  <mkestner@ximian.com>
 
 	* gdk/Makefile.am : add missing custom file.
Index: gtk/Gtk.metadata
===================================================================
RCS file: /cvs/public/gtk-sharp/gtk/Gtk.metadata,v
retrieving revision 1.76
diff -u -r1.76 Gtk.metadata
--- gtk/Gtk.metadata	5 Oct 2004 14:09:05 -0000	1.76
+++ gtk/Gtk.metadata	15 Oct 2004 18:10:07 -0000
@@ -25,6 +25,7 @@
   <attr path="/api/namespace/class[@cname='GtkAccel_']/method[@name='GroupsFromObject']" name="hidden">1</attr>
   <attr path="/api/namespace/class[@cname='GtkAccelerator_']/method[@name='GetDefaultModMask']/return-type" name="type">GdkModifierType</attr>
   <attr path="/api/namespace/class[@cname='GtkCtree_']" name="hidden">1</attr>
+  <attr path="/api/namespace/class[@cname='GtkDrag_']/method[@name='Begin']/*/*[@name='targets']" name="pass_as">ref</attr>
   <attr path="/api/namespace/class[@cname='GtkDrag_']/method[@name='DestSet']/*/*[@name='targets']" name="array">1</attr>
   <attr path="/api/namespace/class[@cname='GtkDrag_']/method[@name='DestSet']/*/*[@name='targets']" name="null_ok">1</attr>
   <attr path="/api/namespace/class[@cname='GtkDrag_']/method[@name='SourceSet']/*/*[@name='targets']" name="array">1</attr>
Index: gtk/Makefile.am
===================================================================
RCS file: /cvs/public/gtk-sharp/gtk/Makefile.am,v
retrieving revision 1.23
diff -u -r1.23 Makefile.am
--- gtk/Makefile.am	24 Sep 2004 15:58:05 -0000	1.23
+++ gtk/Makefile.am	15 Oct 2004 18:10:07 -0000
@@ -73,6 +73,7 @@
 	Style.custom			\
 	Table.custom			\
 	TargetEntry.custom		\
+	TargetList.custom		\
 	TextBuffer.custom		\
 	TextChildAnchor.custom		\
 	TextIter.custom			\
Index: gtk/TargetList.custom
===================================================================
RCS file: gtk/TargetList.custom
diff -N gtk/TargetList.custom
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gtk/TargetList.custom	15 Oct 2004 18:10:07 -0000
@@ -0,0 +1,31 @@
+// TargetList.custom - customizations for Gtk.TargetList
+//
+// Copyright (c) 2004  Novell, Inc.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of version 2 of the Lesser GNU General 
+// Public License as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+		[DllImport("libgtk-win32-2.0-0.dll")]
+		static extern IntPtr gtk_target_list_new(Gtk.TargetEntry[] targets, uint ntargets);
+
+		public static TargetList New(Gtk.TargetEntry[] targets) {
+			return TargetList.New (gtk_target_list_new(targets, (uint)targets.Length));
+		}
+
+		[DllImport("libgtk-win32-2.0-0.dll")]
+		static extern void gtk_target_list_add_table(ref Gtk.TargetList raw, Gtk.TargetEntry[] targets, uint ntargets);
+
+		public void AddTable(Gtk.TargetEntry[] targets) {
+			gtk_target_list_add_table(ref this, targets, (uint)targets.Length);
+		}

--=-MLOmmEBISkFXxmmYbBZU--